mattebox 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/dist/cdn/mattebox.dash-drm.min.js +3 -3
  2. package/dist/cdn/mattebox.dash.min.js +3 -3
  3. package/dist/cdn/mattebox.dual-drm.min.js +3 -3
  4. package/dist/cdn/mattebox.dual-ts-drm.min.js +3 -3
  5. package/dist/cdn/mattebox.dual-ts.min.js +3 -3
  6. package/dist/cdn/mattebox.dual.min.js +3 -3
  7. package/dist/cdn/mattebox.hls-drm.min.js +3 -3
  8. package/dist/cdn/mattebox.hls-ts-drm.min.js +3 -3
  9. package/dist/cdn/mattebox.hls-ts.min.js +3 -3
  10. package/dist/cdn/mattebox.hls.min.js +3 -3
  11. package/dist/cdn/mattebox.kernel.min.js +1 -1
  12. package/dist/cdn/mattebox.min.js +4 -4
  13. package/dist/containers/mp4-box/index.d.ts +9 -7
  14. package/dist/containers/mp4-box/index.d.ts.map +1 -1
  15. package/dist/containers/mp4-box/index.js +20 -28
  16. package/dist/containers/mp4-box/index.js.map +1 -1
  17. package/dist/containers/packed-audio/index.d.ts.map +1 -1
  18. package/dist/containers/packed-audio/index.js +5 -1
  19. package/dist/containers/packed-audio/index.js.map +1 -1
  20. package/dist/containers/ts-transmux/index.d.ts.map +1 -1
  21. package/dist/containers/ts-transmux/index.js +2 -1
  22. package/dist/containers/ts-transmux/index.js.map +1 -1
  23. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/asyncToGenerator.js +1 -1
  24. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/defineProperty.js +1 -1
  25. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectSpread2.js +1 -1
  26. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectWithoutProperties.js +1 -1
  27. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectWithoutPropertiesLoose.js +1 -1
  28. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPrimitive.js +1 -1
  29. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPropertyKey.js +1 -1
  30. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/typeof.js +1 -1
  31. package/dist/es2015/containers/id3.js +1 -1
  32. package/dist/es2015/containers/mp4-box/index.js +19 -22
  33. package/dist/es2015/containers/packed-audio/index.js +2 -5
  34. package/dist/es2015/containers/ts-transmux/h264.js +1 -1
  35. package/dist/es2015/containers/ts-transmux/index.js +3 -6
  36. package/dist/es2015/index.js +40 -27
  37. package/dist/es2015/kernel/append-queue.js +1 -1
  38. package/dist/es2015/kernel/context.js +7 -0
  39. package/dist/es2015/kernel/loader.js +5 -4
  40. package/dist/es2015/kernel/mse.js +48 -74
  41. package/dist/es2015/kernel/prepare.js +77 -0
  42. package/dist/es2015/kernel/reducer.js +284 -73
  43. package/dist/es2015/kernel/refresh.js +35 -0
  44. package/dist/es2015/kernel/rendition-select.js +62 -2
  45. package/dist/es2015/kernel/scheduler.js +23 -5
  46. package/dist/es2015/kernel/timeline.js +22 -1
  47. package/dist/es2015/kernel/trace.js +1 -1
  48. package/dist/es2015/kernel/transport.js +4 -4
  49. package/dist/es2015/presets/define.js +2 -2
  50. package/dist/es2015/presets/tiers.js +7 -6
  51. package/dist/es2015/protocols/dash-cmaf/index.js +136 -55
  52. package/dist/es2015/protocols/dash-cmaf/parse.js +2 -10
  53. package/dist/es2015/protocols/dash-live/index.js +88 -16
  54. package/dist/es2015/protocols/hls-cmaf/index.js +119 -71
  55. package/dist/es2015/protocols/hls-cmaf/parse.js +35 -25
  56. package/dist/es2015/protocols/hls-cmaf/unavailable.js +42 -0
  57. package/dist/es2015/protocols/hls-live/index.js +221 -78
  58. package/dist/es2015/stages/abr/index.js +1 -1
  59. package/dist/es2015/stages/abr-persist/index.js +1 -1
  60. package/dist/es2015/stages/aes-128/index.js +1 -1
  61. package/dist/es2015/stages/alt-audio/index.js +1 -1
  62. package/dist/es2015/stages/cmaf-timing/index.js +24 -39
  63. package/dist/es2015/stages/cmcd/index.js +15 -2
  64. package/dist/es2015/stages/content-steering/index.js +30 -3
  65. package/dist/es2015/stages/eme-core/index.js +2 -2
  66. package/dist/es2015/stages/eme-fairplay/index.js +1 -1
  67. package/dist/es2015/stages/recovery/index.js +1 -1
  68. package/dist/es2015/stages/text-cea608/decode.js +1 -1
  69. package/dist/es2015/stages/text-webvtt/parse.js +1 -1
  70. package/dist/es2015/stages/thumbnails/index.js +1 -1
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +37 -32
  73. package/dist/index.js.map +1 -1
  74. package/dist/kernel/context.d.ts +5 -1
  75. package/dist/kernel/context.d.ts.map +1 -1
  76. package/dist/kernel/context.js +10 -0
  77. package/dist/kernel/context.js.map +1 -1
  78. package/dist/kernel/loader.d.ts.map +1 -1
  79. package/dist/kernel/loader.js +5 -7
  80. package/dist/kernel/loader.js.map +1 -1
  81. package/dist/kernel/mse.d.ts +6 -10
  82. package/dist/kernel/mse.d.ts.map +1 -1
  83. package/dist/kernel/mse.js +45 -76
  84. package/dist/kernel/mse.js.map +1 -1
  85. package/dist/kernel/prepare.d.ts +28 -0
  86. package/dist/kernel/prepare.d.ts.map +1 -0
  87. package/dist/kernel/prepare.js +89 -0
  88. package/dist/kernel/prepare.js.map +1 -0
  89. package/dist/kernel/reducer.d.ts +15 -0
  90. package/dist/kernel/reducer.d.ts.map +1 -1
  91. package/dist/kernel/reducer.js +399 -88
  92. package/dist/kernel/reducer.js.map +1 -1
  93. package/dist/kernel/refresh.d.ts +14 -0
  94. package/dist/kernel/refresh.d.ts.map +1 -0
  95. package/dist/kernel/refresh.js +50 -0
  96. package/dist/kernel/refresh.js.map +1 -0
  97. package/dist/kernel/rendition-select.d.ts +19 -1
  98. package/dist/kernel/rendition-select.d.ts.map +1 -1
  99. package/dist/kernel/rendition-select.js +69 -0
  100. package/dist/kernel/rendition-select.js.map +1 -1
  101. package/dist/kernel/scheduler.d.ts +18 -3
  102. package/dist/kernel/scheduler.d.ts.map +1 -1
  103. package/dist/kernel/scheduler.js +32 -7
  104. package/dist/kernel/scheduler.js.map +1 -1
  105. package/dist/kernel/timeline.d.ts +18 -6
  106. package/dist/kernel/timeline.d.ts.map +1 -1
  107. package/dist/kernel/timeline.js +19 -5
  108. package/dist/kernel/timeline.js.map +1 -1
  109. package/dist/kernel/transport.d.ts.map +1 -1
  110. package/dist/kernel/transport.js +1 -0
  111. package/dist/kernel/transport.js.map +1 -1
  112. package/dist/presets/tiers.d.ts +7 -6
  113. package/dist/presets/tiers.d.ts.map +1 -1
  114. package/dist/presets/tiers.js +7 -6
  115. package/dist/presets/tiers.js.map +1 -1
  116. package/dist/protocols/dash-cmaf/index.d.ts +2 -2
  117. package/dist/protocols/dash-cmaf/index.d.ts.map +1 -1
  118. package/dist/protocols/dash-cmaf/index.js +166 -55
  119. package/dist/protocols/dash-cmaf/index.js.map +1 -1
  120. package/dist/protocols/dash-live/index.d.ts.map +1 -1
  121. package/dist/protocols/dash-live/index.js +83 -11
  122. package/dist/protocols/dash-live/index.js.map +1 -1
  123. package/dist/protocols/hls-cmaf/index.d.ts +3 -2
  124. package/dist/protocols/hls-cmaf/index.d.ts.map +1 -1
  125. package/dist/protocols/hls-cmaf/index.js +140 -82
  126. package/dist/protocols/hls-cmaf/index.js.map +1 -1
  127. package/dist/protocols/hls-cmaf/parse.d.ts +9 -5
  128. package/dist/protocols/hls-cmaf/parse.d.ts.map +1 -1
  129. package/dist/protocols/hls-cmaf/parse.js +50 -47
  130. package/dist/protocols/hls-cmaf/parse.js.map +1 -1
  131. package/dist/protocols/hls-cmaf/unavailable.d.ts +17 -0
  132. package/dist/protocols/hls-cmaf/unavailable.d.ts.map +1 -0
  133. package/dist/protocols/hls-cmaf/unavailable.js +36 -0
  134. package/dist/protocols/hls-cmaf/unavailable.js.map +1 -0
  135. package/dist/protocols/hls-live/index.d.ts +17 -0
  136. package/dist/protocols/hls-live/index.d.ts.map +1 -1
  137. package/dist/protocols/hls-live/index.js +239 -76
  138. package/dist/protocols/hls-live/index.js.map +1 -1
  139. package/dist/stages/aes-128/index.js +2 -2
  140. package/dist/stages/aes-128/index.js.map +1 -1
  141. package/dist/stages/alt-audio/index.d.ts.map +1 -1
  142. package/dist/stages/alt-audio/index.js +5 -3
  143. package/dist/stages/alt-audio/index.js.map +1 -1
  144. package/dist/stages/cmaf-timing/index.d.ts.map +1 -1
  145. package/dist/stages/cmaf-timing/index.js +33 -42
  146. package/dist/stages/cmaf-timing/index.js.map +1 -1
  147. package/dist/stages/cmcd/index.d.ts.map +1 -1
  148. package/dist/stages/cmcd/index.js +15 -3
  149. package/dist/stages/cmcd/index.js.map +1 -1
  150. package/dist/stages/content-steering/index.d.ts.map +1 -1
  151. package/dist/stages/content-steering/index.js +23 -1
  152. package/dist/stages/content-steering/index.js.map +1 -1
  153. package/dist/types/facade.d.ts +12 -0
  154. package/dist/types/facade.d.ts.map +1 -1
  155. package/dist/types/kernel.d.ts +54 -15
  156. package/dist/types/kernel.d.ts.map +1 -1
  157. package/dist/types/kernel.js +2 -1
  158. package/dist/types/kernel.js.map +1 -1
  159. package/dist/types/messages.d.ts +58 -10
  160. package/dist/types/messages.d.ts.map +1 -1
  161. package/dist/types/stage.d.ts +18 -0
  162. package/dist/types/stage.d.ts.map +1 -1
  163. package/package.json +1 -1
@@ -1,7 +1,26 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
2
- import { mergePlaylist, parseMediaPlaylist } from "../hls-cmaf/parse.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
+ import { ladderNeighbours } from "../../kernel/rendition-select.js";
3
+ import { parseMediaPlaylist, refreshFor } from "../hls-cmaf/parse.js";
4
+ import { RELOAD_FAILED, unavailableMessages } from "../hls-cmaf/unavailable.js";
3
5
  import { registerLiveNamespace } from "../live-shared.js";
4
6
  //#region src/protocols/hls-live/index.ts
7
+ /**
8
+ * HLS live: the edge is read, never computed. A slice reducer reloads the
9
+ * active playlists on the TARGETDURATION cadence, reconciles the sliding
10
+ * window as absorb-a-fact-derive-the-diff (seqs stay stable across reloads
11
+ * because they come from MEDIA-SEQUENCE, so replacing the segment list IS
12
+ * the diff for scheduling), and reports the availability window through
13
+ * LIVE_WINDOW_CHANGED facts. EXT-X-ENDLIST converts the presentation to
14
+ * VOD and the reload loop dies with it.
15
+ *
16
+ * One playlist drives the window (the active video rendition, or audio for
17
+ * an audio-only presentation); every other active track's playlist (the
18
+ * audio group's rendition, a segmented subtitle playlist) reloads on the
19
+ * same tick as a companion, the way videojs-http-streaming runs a playlist
20
+ * loader per media type. A companion left stale drains once playback
21
+ * passes the edge it was fetched at, which looks like a live stream dying
22
+ * a minute in.
23
+ */
5
24
  const REFRESH_TOKEN = "hls:live:refresh";
6
25
  const TICK_TOKEN = "hls-live:reload";
7
26
  const INITIAL = {
@@ -12,9 +31,21 @@ const INITIAL = {
12
31
  tickPending: false,
13
32
  inflight: null,
14
33
  lastEndSeq: -1,
15
- awaitingTarget: false
34
+ awaitingTarget: false,
35
+ suspended: false,
36
+ failures: {},
37
+ abandoned: []
16
38
  };
17
39
  /**
40
+ * Failed reloads of one playlist in a row before the loop gives up on it.
41
+ * Each reload already carries the transport's own retries, so this is
42
+ * several rounds of a playlist that does not answer: an expired token, a
43
+ * stream that ended without ENDLIST. The playlist is then abandoned and
44
+ * playback moves off it. Retrying forever only keeps the network busy for
45
+ * a stream that cannot play.
46
+ */
47
+ const FAILURE_LIMIT = 4;
48
+ /**
18
49
  * A two-hour DVR playlist is tens of kilobytes; reloading four of them every
19
50
  * target duration saturates a slow link. The audio and text companions keep
20
51
  * the full cadence because playback consumes them; the other video rungs
@@ -33,6 +64,15 @@ const LADDER_EVERY = 3;
33
64
  function refreshToken(renditionId) {
34
65
  return `${REFRESH_TOKEN}:${renditionId}`;
35
66
  }
67
+ /** A reload of one playlist. The rendition rides along so a failure counts toward steering failover. */
68
+ function reload(target) {
69
+ return {
70
+ kind: "fetch",
71
+ token: refreshToken(target.renditionId),
72
+ url: target.url,
73
+ renditionId: target.renditionId
74
+ };
75
+ }
36
76
  function renditionOfToken(token) {
37
77
  return token.startsWith(`${REFRESH_TOKEN}:`) ? token.slice(17) : null;
38
78
  }
@@ -41,30 +81,46 @@ function findRendition(presentation, renditionId) {
41
81
  return null;
42
82
  }
43
83
  /**
44
- * The active tracks' playlists other than the window rendition's: every
45
- * other video rendition, the audio group rendition, a segmented subtitle
46
- * playlist. The whole video ladder reloads because a switch can only land
47
- * on a rendition whose playlist reaches the playhead; one left at its
48
- * startup window can never be scheduled from, so the switch never happens.
49
- * Renditions without a playlist of their own (muxed audio, a text track in
50
- * a single file) need no reload.
84
+ * The active tracks' playlists other than the window rendition's: the audio
85
+ * group rendition, a segmented subtitle playlist, and the video rungs next
86
+ * to the window rendition. A switch can only land on a rendition whose
87
+ * playlist reaches the playhead, and ABR steps one rung at a time, so the
88
+ * neighbours stay fresh; a longer jump reloads its target at once (the
89
+ * switch branch). Reloading the whole ladder saturates the link on a large
90
+ * multivariant playlist. Renditions without a playlist of their own (muxed
91
+ * audio, a text track in a single file) need no reload, and a playlist
92
+ * shared by several renditions reloads once.
51
93
  */
52
- function companionTargets(presentation, kernel, windowRenditionId) {
53
- const activeIds = new Set([
94
+ function companionTargets(presentation, kernel, window, abandoned) {
95
+ const urls = /* @__PURE__ */ new Set();
96
+ if ((window === null || window === void 0 ? void 0 : window.playlistUrl) !== void 0) urls.add(window.playlistUrl);
97
+ const out = [];
98
+ const add = (rendition, ladder) => {
99
+ const url = rendition.playlistUrl;
100
+ if (url === void 0 || urls.has(url) || abandoned.includes(rendition.id)) return;
101
+ urls.add(url);
102
+ out.push({
103
+ url,
104
+ renditionId: rendition.id,
105
+ ladder
106
+ });
107
+ };
108
+ for (const contentType of [
54
109
  "video",
55
110
  "audio",
56
111
  "text"
57
- ].map((contentType) => kernel.tracks.active.get(contentType)).filter((id) => id !== void 0));
58
- const out = [];
59
- for (const period of presentation.periods) for (const track of period.tracks) {
60
- if (!activeIds.has(track.id)) continue;
61
- for (const rendition of track.renditions) {
62
- if (rendition.id === windowRenditionId || rendition.playlistUrl === void 0) continue;
63
- out.push({
64
- url: rendition.playlistUrl,
65
- renditionId: rendition.id,
66
- ladder: track.contentType === "video"
67
- });
112
+ ]) {
113
+ const trackId = kernel.tracks.active.get(contentType);
114
+ if (trackId === void 0) continue;
115
+ for (const period of presentation.periods) for (const track of period.tracks) {
116
+ if (track.id !== trackId) continue;
117
+ if (contentType !== "video") {
118
+ for (const rendition of track.renditions) add(rendition, false);
119
+ continue;
120
+ }
121
+ if (window === null) continue;
122
+ const neighbours = ladderNeighbours(track.renditions, window.id, kernel.quality.constraints);
123
+ for (const rendition of neighbours) add(rendition, true);
68
124
  }
69
125
  }
70
126
  return out;
@@ -95,7 +151,7 @@ function tick(delaySeconds) {
95
151
  * presentation (a radio or packed-audio DVR stream) has no video track, so
96
152
  * audio drives the window there.
97
153
  */
98
- function windowRendition(presentation, kernel) {
154
+ function windowRendition(presentation, kernel, abandoned) {
99
155
  let fallback = null;
100
156
  for (const contentType of ["video", "audio"]) {
101
157
  for (const period of presentation.periods) for (const track of period.tracks) {
@@ -103,6 +159,7 @@ function windowRendition(presentation, kernel) {
103
159
  for (const rendition of track.renditions) {
104
160
  var _fallback;
105
161
  if (!Array.isArray(rendition.segments) || rendition.segments.length === 0) continue;
162
+ if (abandoned.includes(rendition.id)) continue;
106
163
  if (rendition.id === kernel.quality.active) return rendition;
107
164
  fallback = (_fallback = fallback) !== null && _fallback !== void 0 ? _fallback : rendition;
108
165
  }
@@ -114,7 +171,7 @@ function windowRendition(presentation, kernel) {
114
171
  /**
115
172
  * The window fact for the rendition's current segment list, or null when
116
173
  * the kernel already holds exactly that window: every companion reload
117
- * feeds a MANIFEST_LOADED, and a window that has not moved is not news.
174
+ * feeds a PLAYLIST_REFRESHED, and a window that has not moved is not news.
118
175
  */
119
176
  function windowFact(presentation, rendition, kernel) {
120
177
  var _presentation$live$ho, _presentation$live, _presentation$live$up, _presentation$live2;
@@ -142,18 +199,105 @@ function playlistUrlFor(presentation, renditionId, target) {
142
199
  if ((rendition === null || rendition === void 0 ? void 0 : rendition.playlistUrl) !== void 0) return rendition.playlistUrl;
143
200
  return target !== null && target.renditionId === renditionId ? target.url : null;
144
201
  }
202
+ /** Every rendition whose playlist is `url`. */
203
+ function renditionIdsAt(presentation, url) {
204
+ const ids = [];
205
+ for (const period of presentation.periods) for (const track of period.tracks) for (const rendition of track.renditions) if (rendition.playlistUrl === url) ids.push(rendition.id);
206
+ return ids;
207
+ }
208
+ /**
209
+ * A reload that failed, or answered with a playlist that does not parse.
210
+ * The target tries again soon rather than let the loop die, and every
211
+ * other playlist waits for the next tick, up to FAILURE_LIMIT times in a
212
+ * row. Then the playlist is abandoned: its renditions are excluded, so
213
+ * arbitration moves to another variant (or, for an audio group, to a
214
+ * variant on another group), and the next tick reloads whatever the window
215
+ * rendition is then. The load fails only when nothing is left to move to.
216
+ */
217
+ function reloadFailed(state, kernel, renditionId, error) {
218
+ var _state$failures$rendi, _findRendition;
219
+ const count = ((_state$failures$rendi = state.failures[renditionId]) !== null && _state$failures$rendi !== void 0 ? _state$failures$rendi : 0) + 1;
220
+ const failures = _objectSpread2(_objectSpread2({}, state.failures), {}, { [renditionId]: count });
221
+ const isTarget = state.target !== null && renditionId === state.target.renditionId;
222
+ if (count < FAILURE_LIMIT) {
223
+ if (!isTarget) return [_objectSpread2(_objectSpread2({}, state), {}, { failures }), []];
224
+ if (state.tickPending) return [_objectSpread2(_objectSpread2({}, state), {}, {
225
+ failures,
226
+ inflight: null
227
+ }), []];
228
+ return [_objectSpread2(_objectSpread2({}, state), {}, {
229
+ failures,
230
+ inflight: null,
231
+ tickPending: true
232
+ }), [tick(2)]];
233
+ }
234
+ const presentation = kernel.presentation;
235
+ const url = presentation === null ? null : playlistUrlFor(presentation, renditionId, state.target);
236
+ const sharing = presentation !== null && url !== null && ((_findRendition = findRendition(presentation, renditionId)) === null || _findRendition === void 0 ? void 0 : _findRendition.playlistUrl) !== void 0 ? renditionIdsAt(presentation, url) : [renditionId];
237
+ const abandoned = [.../* @__PURE__ */ new Set([...state.abandoned, ...sharing])];
238
+ const messages = unavailableMessages(kernel, RELOAD_FAILED, abandoned, {
239
+ category: "manifest",
240
+ code: "MANIFEST_REFRESH_FAILED",
241
+ fatal: true,
242
+ recoverable: false,
243
+ context: {
244
+ cause: error.code,
245
+ renditionId,
246
+ attempts: count
247
+ }
248
+ });
249
+ const next = _objectSpread2(_objectSpread2({}, state), {}, {
250
+ failures,
251
+ abandoned,
252
+ companions: state.companions.filter((c) => !abandoned.includes(c.renditionId)),
253
+ inflight: isTarget ? null : state.inflight
254
+ });
255
+ const effects = messages.map(feed);
256
+ const failed = messages.some((m) => m.type === "MANIFEST_FAILED");
257
+ if (isTarget && !failed && !state.tickPending) return [_objectSpread2(_objectSpread2({}, next), {}, { tickPending: true }), [...effects, tick(2)]];
258
+ return [next, effects];
259
+ }
145
260
  const reduceHlsLive = (slice, msg, kernel) => {
146
261
  const state = slice !== null && slice !== void 0 ? slice : INITIAL;
147
262
  if (msg.type === "LOAD") return [_objectSpread2(_objectSpread2({}, INITIAL), {}, { manifestUrl: msg.url }), []];
148
263
  if (msg.type === "UNLOAD" || msg.type === "DETACH") return [INITIAL, []];
149
- if (msg.type === "MANIFEST_LOADED") {
150
- var _rendition$playlistUr, _rendition$id;
151
- if (!msg.presentation.isLive) return [_objectSpread2(_objectSpread2({}, state), {}, {
264
+ if (msg.type === "SUSPEND") {
265
+ const effects = [];
266
+ if (state.tickPending) effects.push({
267
+ kind: "abort",
268
+ token: TICK_TOKEN
269
+ });
270
+ if (state.inflight !== null) effects.push({
271
+ kind: "abort",
272
+ token: refreshToken(state.inflight)
273
+ });
274
+ return [_objectSpread2(_objectSpread2({}, state), {}, {
275
+ tickPending: false,
276
+ inflight: null,
277
+ suspended: true
278
+ }), effects];
279
+ }
280
+ if (msg.type === "RESUME") {
281
+ var _kernel$presentation;
282
+ if (!state.suspended) return [state, []];
283
+ const resumed = _objectSpread2(_objectSpread2({}, state), {}, { suspended: false });
284
+ if (state.target === null || ((_kernel$presentation = kernel.presentation) === null || _kernel$presentation === void 0 ? void 0 : _kernel$presentation.isLive) !== true) return [resumed, []];
285
+ const effects = [reload(state.target)];
286
+ for (const companion of state.companions) effects.push(reload(companion));
287
+ return [_objectSpread2(_objectSpread2({}, resumed), {}, {
288
+ inflight: state.target.renditionId,
289
+ awaitingTarget: true
290
+ }), effects];
291
+ }
292
+ if ((msg.type === "MANIFEST_LOADED" || msg.type === "PLAYLIST_REFRESHED") && kernel.presentation !== null) {
293
+ var _rendition$playlistUr;
294
+ const presentation = kernel.presentation;
295
+ if (!presentation.isLive) return [_objectSpread2(_objectSpread2({}, state), {}, {
152
296
  target: null,
153
297
  companions: [],
154
298
  inflight: null
155
299
  }), []];
156
- const rendition = windowRendition(msg.presentation, kernel);
300
+ const rendition = windowRendition(presentation, kernel, state.abandoned);
157
301
  const effects = [];
158
302
  const url = (_rendition$playlistUr = rendition === null || rendition === void 0 ? void 0 : rendition.playlistUrl) !== null && _rendition$playlistUr !== void 0 ? _rendition$playlistUr : state.manifestUrl;
159
303
  const target = url !== null && rendition !== null ? {
@@ -161,28 +305,24 @@ const reduceHlsLive = (slice, msg, kernel) => {
161
305
  renditionId: rendition.id,
162
306
  ladder: false
163
307
  } : state.target;
164
- const companions = companionTargets(msg.presentation, kernel, (_rendition$id = rendition === null || rendition === void 0 ? void 0 : rendition.id) !== null && _rendition$id !== void 0 ? _rendition$id : null);
308
+ const companions = companionTargets(presentation, kernel, rendition, state.abandoned);
165
309
  const switched = state.target !== null && target !== null && target.renditionId !== state.target.renditionId;
166
310
  let awaitingTarget = state.awaitingTarget;
167
311
  let inflight = state.inflight;
168
312
  if (switched && target !== null) {
169
313
  if (inflight !== target.renditionId) {
170
- effects.push({
171
- kind: "fetch",
172
- token: refreshToken(target.renditionId),
173
- url: target.url
174
- });
314
+ effects.push(reload(target));
175
315
  inflight = target.renditionId;
176
316
  }
177
317
  awaitingTarget = true;
178
318
  } else if (!awaitingTarget && rendition !== null) {
179
- const window = windowFact(msg.presentation, rendition, kernel);
319
+ const window = windowFact(presentation, rendition, kernel);
180
320
  if (window !== null) effects.push(window);
181
321
  }
182
322
  let tickPending = state.tickPending;
183
323
  if (!tickPending && inflight === null && target !== null) {
184
- var _msg$presentation$liv, _msg$presentation$liv2;
185
- effects.push(tick((_msg$presentation$liv = (_msg$presentation$liv2 = msg.presentation.live) === null || _msg$presentation$liv2 === void 0 ? void 0 : _msg$presentation$liv2.updatePeriod) !== null && _msg$presentation$liv !== void 0 ? _msg$presentation$liv : 4));
324
+ var _presentation$live$up2, _presentation$live3;
325
+ effects.push(tick((_presentation$live$up2 = (_presentation$live3 = presentation.live) === null || _presentation$live3 === void 0 ? void 0 : _presentation$live3.updatePeriod) !== null && _presentation$live$up2 !== void 0 ? _presentation$live$up2 : 4));
186
326
  tickPending = true;
187
327
  }
188
328
  return [_objectSpread2(_objectSpread2({}, state), {}, {
@@ -194,30 +334,39 @@ const reduceHlsLive = (slice, msg, kernel) => {
194
334
  }), effects];
195
335
  }
196
336
  if (msg.type === "TICK" && msg.token === TICK_TOKEN) {
197
- var _kernel$presentation;
198
- if (state.target === null || ((_kernel$presentation = kernel.presentation) === null || _kernel$presentation === void 0 ? void 0 : _kernel$presentation.isLive) !== true) return [_objectSpread2(_objectSpread2({}, state), {}, {
337
+ var _kernel$presentation2;
338
+ if (state.suspended || state.target === null || ((_kernel$presentation2 = kernel.presentation) === null || _kernel$presentation2 === void 0 ? void 0 : _kernel$presentation2.isLive) !== true) return [_objectSpread2(_objectSpread2({}, state), {}, {
199
339
  tickPending: false,
200
340
  inflight: null
201
341
  }), []];
342
+ let target = state.target;
343
+ let awaitingTarget = state.awaitingTarget;
344
+ if (state.abandoned.includes(target.renditionId)) {
345
+ const rendition = windowRendition(kernel.presentation, kernel, state.abandoned);
346
+ target = (rendition === null || rendition === void 0 ? void 0 : rendition.playlistUrl) !== void 0 ? {
347
+ url: rendition.playlistUrl,
348
+ renditionId: rendition.id,
349
+ ladder: false
350
+ } : null;
351
+ if (target === null) return [_objectSpread2(_objectSpread2({}, state), {}, {
352
+ tickPending: false,
353
+ inflight: null
354
+ }), []];
355
+ awaitingTarget = true;
356
+ }
202
357
  const effects = [];
203
358
  let inflight = state.inflight;
204
- if (inflight !== state.target.renditionId) {
205
- effects.push({
206
- kind: "fetch",
207
- token: refreshToken(state.target.renditionId),
208
- url: state.target.url
209
- });
210
- inflight = state.target.renditionId;
359
+ if (inflight !== target.renditionId) {
360
+ effects.push(reload(target));
361
+ inflight = target.renditionId;
211
362
  }
212
363
  for (const companion of state.companions) {
213
364
  if (companion.ladder && state.round % LADDER_EVERY !== 0) continue;
214
- effects.push({
215
- kind: "fetch",
216
- token: refreshToken(companion.renditionId),
217
- url: companion.url
218
- });
365
+ effects.push(reload(companion));
219
366
  }
220
367
  return [_objectSpread2(_objectSpread2({}, state), {}, {
368
+ target,
369
+ awaitingTarget,
221
370
  round: state.round + 1,
222
371
  tickPending: false,
223
372
  inflight
@@ -226,15 +375,10 @@ const reduceHlsLive = (slice, msg, kernel) => {
226
375
  if (msg.type === "SEGMENT_FAILED") {
227
376
  const renditionId = renditionOfToken(msg.trackId);
228
377
  if (renditionId === null) return [state, []];
229
- if (state.target === null || renditionId !== state.target.renditionId) return [state, []];
230
- if (state.tickPending) return [_objectSpread2(_objectSpread2({}, state), {}, { inflight: null }), []];
231
- return [_objectSpread2(_objectSpread2({}, state), {}, {
232
- inflight: null,
233
- tickPending: true
234
- }), [tick(2)]];
378
+ return reloadFailed(state, kernel, renditionId, msg.error);
235
379
  }
236
380
  if (msg.type === "SEGMENT_LOADED") {
237
- var _lastSegment$seq;
381
+ var _findRendition2, _lastSegment$seq;
238
382
  const renditionId = renditionOfToken(msg.trackId);
239
383
  if (renditionId === null || kernel.presentation === null) return [state, []];
240
384
  const isTarget = state.target !== null && renditionId === state.target.renditionId;
@@ -243,35 +387,34 @@ const reduceHlsLive = (slice, msg, kernel) => {
243
387
  const text = new TextDecoder().decode(msg.bytes);
244
388
  const media = parseMediaPlaylist(text, url);
245
389
  if (media.playlist === null) {
246
- if (!isTarget) return [state, []];
247
- if (state.tickPending) return [_objectSpread2(_objectSpread2({}, state), {}, { inflight: null }), []];
248
- return [_objectSpread2(_objectSpread2({}, state), {}, {
249
- inflight: null,
250
- tickPending: true
251
- }), [tick(2)]];
390
+ var _media$error;
391
+ return reloadFailed(state, kernel, renditionId, (_media$error = media.error) !== null && _media$error !== void 0 ? _media$error : {
392
+ category: "manifest",
393
+ code: "MANIFEST_PARSE_FAILED",
394
+ fatal: false,
395
+ recoverable: false
396
+ });
252
397
  }
253
- const refreshed = mergePlaylist(kernel.presentation, renditionId, media.playlist);
254
- const effects = [feed({
255
- type: "PLAYLIST_REFRESHED",
256
- trackId: renditionId,
257
- renditionId,
258
- mediaSequence: media.playlist.mediaSequence,
259
- segments: media.playlist.segments
260
- }), feed({
261
- type: "MANIFEST_LOADED",
262
- presentation: refreshed
263
- })];
264
- if (!isTarget) return [state, effects];
398
+ const failures = _objectSpread2({}, state.failures);
399
+ delete failures[renditionId];
400
+ const sharing = ((_findRendition2 = findRendition(kernel.presentation, renditionId)) === null || _findRendition2 === void 0 ? void 0 : _findRendition2.playlistUrl) === void 0 ? [renditionId] : renditionIdsAt(kernel.presentation, url);
401
+ const effects = [];
402
+ for (const id of sharing) {
403
+ const refresh = refreshFor(kernel.presentation, id, media.playlist);
404
+ if (refresh !== null) effects.push(feed(refresh));
405
+ }
406
+ if (!isTarget) return [_objectSpread2(_objectSpread2({}, state), {}, { failures }), effects];
265
407
  const lastSegment = media.playlist.segments[media.playlist.segments.length - 1];
266
408
  const endSeq = (_lastSegment$seq = lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.seq) !== null && _lastSegment$seq !== void 0 ? _lastSegment$seq : -1;
267
409
  const changed = endSeq !== state.lastEndSeq;
268
410
  const cadence = media.playlist.targetDuration || 4;
269
411
  let tickPending = state.tickPending;
270
- if (!media.playlist.endlist && !tickPending) {
412
+ if (!media.playlist.endlist && !tickPending && !state.suspended) {
271
413
  effects.push(tick(changed ? cadence : cadence / 2));
272
414
  tickPending = true;
273
415
  }
274
416
  return [_objectSpread2(_objectSpread2({}, state), {}, {
417
+ failures,
275
418
  lastEndSeq: endSeq,
276
419
  tickPending,
277
420
  inflight: null,
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
2
  import { canSwitchTo } from "../../kernel/rendition-select.js";
3
3
  //#region src/stages/abr/index.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
2
  //#region src/stages/abr-persist/index.ts
3
3
  const INITIAL = {
4
4
  seeded: false,
@@ -1,4 +1,4 @@
1
- import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/asyncToGenerator.js";
1
+ import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/asyncToGenerator.js";
2
2
  //#region src/stages/aes-128/index.ts
3
3
  /** Before the transmux (100) and the codec probe (5), which must read clear bytes. */
4
4
  const DECRYPT_ORDER = 1;
@@ -53,7 +53,7 @@ const reduceAltAudio = (slice, msg, kernel) => {
53
53
  if ((chosen === null || chosen === void 0 ? void 0 : chosen.lang) != null) return [{ preferredLang: chosen.lang }, []];
54
54
  return [state, []];
55
55
  }
56
- if (msg.type === "MANIFEST_LOADED" || msg.type === "SEGMENT_LOADED") {
56
+ if (msg.type === "MANIFEST_LOADED" || msg.type === "PLAYLIST_REFRESHED" || msg.type === "SEGMENT_LOADED") {
57
57
  const group = requiredGroup(kernel);
58
58
  if (group === null) return [state, []];
59
59
  const active = kernel.tracks.active.get("audio");
@@ -1,52 +1,37 @@
1
- import { findBox, normalizeTfdt, trackTimescales } from "../../containers/mp4-box/index.js";
1
+ import { earliestDecodeTime, findBox, trackTimescales } from "../../containers/mp4-box/index.js";
2
2
  //#region src/stages/cmaf-timing/index.ts
3
3
  /**
4
- * cmaf-timing normalizes the decode timeline of native fMP4 segments so a live
5
- * CMAF stream plays. A CMAF live segment's tfdt carries the real broadcast
6
- * clock (often a value in the billions of seconds); appended with the zero
7
- * timestampOffset the kernel derives for fMP4, its frames land far past the
8
- * playhead and nothing ever renders. This stage rewrites each segment's tfdt to
9
- * the presentation start the manifest assigns it, which is the same alignment a
10
- * TS transmux produces for free, so VOD (already near zero) is untouched and
11
- * live is corrected.
4
+ * cmaf-timing reads where a native fMP4 segment's media clock starts, so
5
+ * the kernel can land the segment at the presentation time the manifest
6
+ * gives it. Packagers write whatever clock they like into tfdt: a live
7
+ * broadcast clock in the billions of seconds, an encoder offset of ten
8
+ * seconds into a VOD title, or zero. The bytes are never touched. The
9
+ * kernel settles one timestampOffset per timeline epoch from the first
10
+ * reading, the segment's playlist start minus this decode time, and every
11
+ * buffer applies it, the way videojs-http-streaming derives the offset
12
+ * from its main loader's first segment.
12
13
  *
13
- * It contributes a transform step and the `media-transform` capability, so the
14
- * append path routes through the transform pipeline for a CMAF composition too.
15
- * Timescales come from the init segment's moov; the transform runs after any
16
- * transmux, and a decrypt step never touches the moof header, so an encrypted
17
- * segment is normalized the same way.
14
+ * The probe runs after the transform pipeline, so a decrypted or
15
+ * transmuxed segment is read in its final form. Timescales come from each
16
+ * rendition's init segment moov, or from a self-contained segment that
17
+ * carries its own.
18
18
  */
19
- /** After ts-transmux (100) and any decrypt-class step, before the append. */
20
- const ORDER = 150;
21
19
  function cmafTiming() {
22
20
  return {
23
21
  name: "cmaf-timing",
24
- provides: [
25
- "cmaf-timing",
26
- "media-transform",
27
- "media-time-normalized"
28
- ],
22
+ provides: ["cmaf-timing", "media-time-probe"],
29
23
  install(ctx) {
30
24
  const timescales = /* @__PURE__ */ new Map();
31
- ctx.registerTransform({
32
- name: "cmaf-timing",
33
- order: ORDER,
34
- transform(data, meta) {
35
- if (meta.contentType !== "video" && meta.contentType !== "audio") return data;
36
- if (findBox(data, "moov") !== null) {
37
- const scales = trackTimescales(data);
38
- if (scales.size > 0) timescales.set(meta.contentType, scales);
39
- }
40
- if (findBox(data, "moof") !== null) {
41
- const scales = timescales.get(meta.contentType);
42
- if (scales !== void 0 && scales.size > 0) {
43
- var _;
44
- const fallback = (_ = [...scales.values()][0]) !== null && _ !== void 0 ? _ : 0;
45
- normalizeTfdt(data, meta.start, scales, fallback);
46
- }
47
- }
48
- return data;
25
+ ctx.registerTimeProbe((data, meta) => {
26
+ if (meta.contentType !== "video" && meta.contentType !== "audio") return null;
27
+ if (findBox(data, "moov") !== null) {
28
+ const scales = trackTimescales(data);
29
+ if (scales.size > 0) timescales.set(meta.renditionId, scales);
49
30
  }
31
+ if (findBox(data, "moof") === null) return null;
32
+ const scales = timescales.get(meta.renditionId);
33
+ if (scales === void 0) return null;
34
+ return earliestDecodeTime(data, scales);
50
35
  });
51
36
  }
52
37
  };
@@ -24,9 +24,22 @@ function serialize(keys) {
24
24
  return `${key}=${value}`;
25
25
  }).join(",");
26
26
  }
27
+ /**
28
+ * A version 4 UUID for `sid` (CTA-5004 recommends a UUID). randomUUID
29
+ * exists only in secure contexts, so plain-HTTP pages build one from
30
+ * getRandomValues, which every context has (RFC 9562 §5.4).
31
+ */
32
+ function sessionUuid() {
33
+ if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
34
+ const bytes = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
35
+ bytes[6] = bytes[6] & 15 | 64;
36
+ bytes[8] = bytes[8] & 63 | 128;
37
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
38
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
39
+ }
27
40
  function cmcd(options = {}) {
28
- var _ref, _options$sessionId, _globalThis$crypto, _globalThis$crypto$ra, _options$mode;
29
- const sessionId = (_ref = (_options$sessionId = options.sessionId) !== null && _options$sessionId !== void 0 ? _options$sessionId : (_globalThis$crypto = globalThis.crypto) === null || _globalThis$crypto === void 0 || (_globalThis$crypto$ra = _globalThis$crypto.randomUUID) === null || _globalThis$crypto$ra === void 0 ? void 0 : _globalThis$crypto$ra.call(_globalThis$crypto)) !== null && _ref !== void 0 ? _ref : `mb-${Math.random().toString(36).slice(2)}`;
41
+ var _options$sessionId, _options$mode;
42
+ const sessionId = (_options$sessionId = options.sessionId) !== null && _options$sessionId !== void 0 ? _options$sessionId : sessionUuid();
30
43
  const mode = (_options$mode = options.mode) !== null && _options$mode !== void 0 ? _options$mode : "query";
31
44
  return {
32
45
  name: "cmcd",
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
2
  //#region src/stages/content-steering/index.ts
3
3
  const MANIFEST_TOKEN = "steering:manifest";
4
4
  const RELOAD_TOKEN = "steering:reload";
@@ -14,7 +14,8 @@ const INITIAL = {
14
14
  dead: [],
15
15
  fails: 0,
16
16
  fetchPending: false,
17
- tickPending: false
17
+ tickPending: false,
18
+ suspended: false
18
19
  };
19
20
  /** Loops a message back into the bus through a zero-delay schedule effect. */
20
21
  function feed(message) {
@@ -60,6 +61,32 @@ function choosePathway(slice, known) {
60
61
  const reduceSteering = (slice, msg, kernel) => {
61
62
  const state = slice !== null && slice !== void 0 ? slice : INITIAL;
62
63
  if (msg.type === "LOAD" || msg.type === "UNLOAD" || msg.type === "DETACH") return [INITIAL, []];
64
+ if (msg.type === "SUSPEND") {
65
+ const effects = [];
66
+ if (state.tickPending) effects.push({
67
+ kind: "abort",
68
+ token: RELOAD_TOKEN
69
+ });
70
+ if (state.fetchPending) effects.push({
71
+ kind: "abort",
72
+ token: MANIFEST_TOKEN
73
+ });
74
+ return [_objectSpread2(_objectSpread2({}, state), {}, {
75
+ tickPending: false,
76
+ fetchPending: false,
77
+ suspended: true
78
+ }), effects];
79
+ }
80
+ if (msg.type === "RESUME") {
81
+ if (!state.suspended) return [state, []];
82
+ const resumed = _objectSpread2(_objectSpread2({}, state), {}, { suspended: false });
83
+ if (state.serverUri === null) return [resumed, []];
84
+ return [_objectSpread2(_objectSpread2({}, resumed), {}, { fetchPending: true }), [{
85
+ kind: "fetch",
86
+ token: MANIFEST_TOKEN,
87
+ url: state.serverUri
88
+ }]];
89
+ }
63
90
  if (msg.type === "MANIFEST_LOADED") {
64
91
  const steering = msg.presentation.steering;
65
92
  if (steering === void 0) return [state, []];
@@ -118,7 +145,7 @@ const reduceSteering = (slice, msg, kernel) => {
118
145
  return [next, effects];
119
146
  }
120
147
  if (msg.type === "TICK" && msg.token === RELOAD_TOKEN) {
121
- if (state.serverUri === null) return [_objectSpread2(_objectSpread2({}, state), {}, { tickPending: false }), []];
148
+ if (state.suspended || state.serverUri === null) return [_objectSpread2(_objectSpread2({}, state), {}, { tickPending: false }), []];
122
149
  return [_objectSpread2(_objectSpread2({}, state), {}, {
123
150
  tickPending: false,
124
151
  fetchPending: true
@@ -1,5 +1,5 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
2
- import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/asyncToGenerator.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
+ import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/asyncToGenerator.js";
3
3
  import { keySystemHandlers, normalizeSystemId } from "../drm-shared.js";
4
4
  //#region src/stages/eme-core/index.ts
5
5
  const CLEARKEY = "org.w3.clearkey";
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
2
  import { registerKeySystem } from "../drm-shared.js";
3
3
  //#region src/stages/eme-fairplay/index.ts
4
4
  const FAIRPLAY_SYSTEM_ID = "94ce86fb-07ff-4f43-adb8-93d2fa968ca2";
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
2
  //#region src/stages/recovery/index.ts
3
3
  const DEFAULTS = {
4
4
  excludeAfter: 2,