mattebox 0.6.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 (158) 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 +34 -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 +27 -71
  41. package/dist/es2015/kernel/prepare.js +77 -0
  42. package/dist/es2015/kernel/reducer.js +233 -64
  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 +54 -14
  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 +191 -85
  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 +1 -1
  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 +31 -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 +20 -73
  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 +317 -82
  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 -57
  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 +55 -9
  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 -88
  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 +213 -82
  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/types/kernel.d.ts +39 -13
  151. package/dist/types/kernel.d.ts.map +1 -1
  152. package/dist/types/kernel.js +2 -1
  153. package/dist/types/kernel.js.map +1 -1
  154. package/dist/types/messages.d.ts +50 -10
  155. package/dist/types/messages.d.ts.map +1 -1
  156. package/dist/types/stage.d.ts +18 -0
  157. package/dist/types/stage.d.ts.map +1 -1
  158. package/package.json +1 -1
@@ -55,6 +55,27 @@ function epochForSeq(epochs, seq) {
55
55
  function timestampOffsetFor(epoch) {
56
56
  return epoch.presentationStart - epoch.mediaStart;
57
57
  }
58
+ /**
59
+ * The name every track of a period shares for one epoch: the period alone
60
+ * for the epoch that opens it, the period and the discontinuity's
61
+ * presentation start after that. Sequence numbers are no part of it,
62
+ * because each rendition numbers its own playlist (RFC 8216 §6.2.2 aligns
63
+ * discontinuities across renditions in time, not in sequence). The start
64
+ * is rounded to the second, since each playlist sums its own durations.
65
+ */
66
+ function epochKey(epochs, epoch) {
67
+ return epochs[0] === epoch ? epoch.periodId : `${epoch.periodId}:${Math.round(epoch.presentationStart)}`;
68
+ }
69
+ /**
70
+ * The timestampOffset that lands a segment at its presentation start,
71
+ * given the decode time its bytes report. Manifests promise timing; the
72
+ * bytes tell the truth, so this replaces the epoch prediction the moment
73
+ * a segment lands. Same arithmetic as videojs-http-streaming's segment
74
+ * loader, which subtracts the probed start from the segment's start.
75
+ */
76
+ function reconciledOffset(segmentStart, mediaStart) {
77
+ return segmentStart - mediaStart;
78
+ }
58
79
  /** Materializes one segment from an indexed form. Null outside the window. */
59
80
  function segmentAt(addressing, seq, periodStart = 0) {
60
81
  var _addressing$presentat2;
@@ -124,4 +145,4 @@ function segmentAtTime(addressing, time, periodStart = 0) {
124
145
  return null;
125
146
  }
126
147
  //#endregion
127
- export { buildEpochs, epochForSeq, segmentAt, segmentAtTime, timestampOffsetFor };
148
+ export { buildEpochs, epochForSeq, epochKey, reconciledOffset, segmentAt, segmentAtTime, timestampOffsetFor };
@@ -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
  function isBytes(value) {
3
3
  return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
4
4
  }
@@ -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
  //#region src/kernel/transport.ts
4
4
  const DEFAULT_RETRY_POLICY = {
5
5
  maxAttempts: 3,
@@ -196,12 +196,12 @@ function createTransport(options) {
196
196
  registerHandlers(runner) {
197
197
  runner.register("fetch", (effect) => {
198
198
  var _options$inflight;
199
- const request = (_options$inflight = options.inflight(effect.token)) !== null && _options$inflight !== void 0 ? _options$inflight : {
199
+ const request = (_options$inflight = options.inflight(effect.token)) !== null && _options$inflight !== void 0 ? _options$inflight : _objectSpread2({
200
200
  token: effect.token,
201
201
  trackId: effect.token,
202
202
  seq: -1,
203
203
  url: effect.url
204
- };
204
+ }, effect.renditionId !== void 0 ? { renditionId: effect.renditionId } : {});
205
205
  attempt(effect.token, request, effect.url, effect.range, effect.timeout, 1);
206
206
  return () => cancel(effect.token);
207
207
  });
@@ -1,5 +1,5 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
2
- import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectWithoutProperties.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
+ import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectWithoutProperties.js";
3
3
  import { mattebox } from "../index.js";
4
4
  //#region src/presets/define.ts
5
5
  const _excluded = ["stages", "without"];
@@ -50,12 +50,13 @@ function dashLine() {
50
50
  /**
51
51
  * What every preset carries: adaptive quality with a size cap and bandwidth
52
52
  * memory, recovery, content steering (inert until a manifest asks for it),
53
- * alternate audio with codec switching, WebVTT subtitles, CMAF live timing
54
- * (corrects the broadcast-clock tfdt some live packagers write, leaves VOD
55
- * untouched), program date time from either protocol's anchor, the codec
56
- * probe (types a SourceBuffer whose playlist declares no codecs, which Chrome
57
- * otherwise refuses), and CEA-608 captions from fMP4 video. The caption scan
58
- * costs per NAL unit, not per byte, and only when a segment has H.264 or HEVC.
53
+ * alternate audio with codec switching, WebVTT subtitles, CMAF timing (reads
54
+ * each segment's decode time so the kernel lands it at its playlist time,
55
+ * whatever clock the packager wrote), program date time from either
56
+ * protocol's anchor, the codec probe (types a SourceBuffer whose playlist
57
+ * declares no codecs, which Chrome otherwise refuses), and CEA-608 captions
58
+ * from fMP4 video. The caption scan costs per NAL unit, not per byte, and
59
+ * only when a segment has H.264 or HEVC.
59
60
  */
60
61
  function base() {
61
62
  return [
@@ -1,6 +1,7 @@
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 { normalizeMimeType } from "../../kernel/mime.js";
3
- import { mergeSidx, parse, sidxToSegments } from "./parse.js";
3
+ import { ladderNeighbours } from "../../kernel/rendition-select.js";
4
+ import { parse, sidxToSegments } from "./parse.js";
4
5
  //#region src/protocols/dash-cmaf/index.ts
5
6
  /**
6
7
  * The dash-cmaf protocol adapter as a stage. Inert module: exports a
@@ -12,8 +13,8 @@ import { mergeSidx, parse, sidxToSegments } from "./parse.js";
12
13
  * indexed by a `sidx` box, so the concrete segments are unknown until that box
13
14
  * is fetched. That second phase mirrors HLS's media-playlist fetch: the parse
14
15
  * emits `sidx` addressing, this slice fetches the index byte range under a
15
- * `dash:idx:` token the transport correlates back, parses it, and merges the
16
- * resolved segments into the presentation.
16
+ * `dash:idx:` token the transport correlates back, parses it, and feeds the
17
+ * resolved segments back as a PLAYLIST_REFRESHED the kernel merges.
17
18
  */
18
19
  const INDEX_TOKEN = "dash:idx:";
19
20
  /** The MPD MIME type, ISO 23009-1 §C.2. */
@@ -27,8 +28,12 @@ function asSidx(addressing) {
27
28
  const INITIAL = {
28
29
  manifestUrl: null,
29
30
  mimeType: null,
30
- pending: {}
31
+ pending: {},
32
+ failed: {},
33
+ seen: ""
31
34
  };
35
+ /** The constraint source that excludes renditions whose index failed. */
36
+ const UNAVAILABLE = "dash:unavailable";
32
37
  /**
33
38
  * Whether this adapter owns the manifest bytes. An explicit mimeType
34
39
  * decides alone; without one, an MPD is an XML document and starts with
@@ -42,29 +47,41 @@ function findRendition(presentation, renditionId) {
42
47
  for (const period of presentation.periods) for (const track of period.tracks) for (const rendition of track.renditions) if (rendition.id === renditionId) return rendition;
43
48
  return null;
44
49
  }
50
+ function findTrackOf(presentation, renditionId) {
51
+ for (const period of presentation.periods) for (const track of period.tracks) if (track.renditions.some((r) => r.id === renditionId)) return track;
52
+ return null;
53
+ }
45
54
  /**
46
- * The renditions whose sidx index still needs fetching: every rendition of
47
- * every active track. Resolving only the "chosen" one is not enough, because
48
- * the kernel selects the audio rendition independently (an audio adaptation
49
- * set often has several bitrates) and may pick a different one than this slice
50
- * would; its segments would then stay unresolved and the audio buffer would
51
- * never fill, stalling playback since the element's buffered range is the
52
- * intersection across all source buffers. Resolving them all also means an ABR
53
- * switch finds its target already indexed. The fetches are one small range
54
- * each, so the cost is negligible.
55
+ * The renditions whose sidx index the selection needs and this slice has
56
+ * not asked for: the playing video rendition and its ladder neighbours, and
57
+ * every rendition of the active audio and text tracks. The kernel selects
58
+ * the audio rendition on its own (an audio adaptation set often has several
59
+ * bitrates) and keeps no record of the pick, so all of them resolve; an
60
+ * unresolved one would never fill the audio buffer. The whole video ladder
61
+ * does not: ABR steps one rung at a time, and a longer jump resolves when
62
+ * it happens, while the buffer plays.
55
63
  */
56
- function neededIndexes(kernel) {
64
+ function neededIndexes(state, kernel) {
57
65
  const presentation = kernel.presentation;
58
66
  if (presentation === null) return [];
59
- const activeIds = new Set([
67
+ const asked = new Set(Object.values(state.pending));
68
+ const needed = [];
69
+ for (const contentType of [
60
70
  "video",
61
71
  "audio",
62
72
  "text"
63
- ].map((contentType) => kernel.tracks.active.get(contentType)).filter((id) => id !== void 0));
64
- const needed = [];
65
- for (const period of presentation.periods) for (const track of period.tracks) {
66
- if (!activeIds.has(track.id)) continue;
67
- for (const rendition of track.renditions) if (asSidx(rendition.segments) !== null) needed.push(rendition);
73
+ ]) {
74
+ const trackId = kernel.tracks.active.get(contentType);
75
+ if (trackId === void 0) continue;
76
+ for (const period of presentation.periods) for (const track of period.tracks) {
77
+ if (track.id !== trackId) continue;
78
+ const candidates = contentType === "video" ? ladderNeighbours(track.renditions, kernel.quality.active, kernel.quality.constraints) : track.renditions;
79
+ for (const rendition of candidates) {
80
+ if (asSidx(rendition.segments) === null) continue;
81
+ if (asked.has(rendition.id) || rendition.id in state.failed) continue;
82
+ needed.push(rendition);
83
+ }
84
+ }
68
85
  }
69
86
  return needed;
70
87
  }
@@ -77,13 +94,35 @@ function feed(message) {
77
94
  then: message
78
95
  };
79
96
  }
97
+ /**
98
+ * An index that failed to load or held no segment. The rendition is
99
+ * excluded, so arbitration moves off it and nothing asks for the index
100
+ * again. When that leaves a media track with no rendition at all, the load
101
+ * fails: the stream cannot play, and waiting would only stall.
102
+ */
103
+ function unavailable(state, kernel, renditionId, error) {
104
+ const failed = _objectSpread2(_objectSpread2({}, state.failed), {}, { [renditionId]: true });
105
+ const next = _objectSpread2(_objectSpread2({}, state), {}, { failed });
106
+ const presentation = kernel.presentation;
107
+ if (presentation === null) return [next, []];
108
+ const track = findTrackOf(presentation, renditionId);
109
+ const media = (track === null || track === void 0 ? void 0 : track.contentType) === "video" || (track === null || track === void 0 ? void 0 : track.contentType) === "audio";
110
+ if (track !== null && media && track.renditions.every((r) => r.id in failed)) return [next, [feed({
111
+ type: "MANIFEST_FAILED",
112
+ error: _objectSpread2(_objectSpread2({}, error), {}, { fatal: true })
113
+ })]];
114
+ return [next, [feed({
115
+ type: "CONSTRAIN",
116
+ source: UNAVAILABLE,
117
+ constraint: { excludeIds: Object.keys(failed) }
118
+ })]];
119
+ }
80
120
  const reduceDash = (slice, msg, kernel) => {
81
121
  const state = slice !== null && slice !== void 0 ? slice : INITIAL;
82
- if (msg.type === "LOAD") return [{
122
+ if (msg.type === "LOAD") return [_objectSpread2(_objectSpread2({}, INITIAL), {}, {
83
123
  manifestUrl: msg.url,
84
- mimeType: msg.mimeType === void 0 ? null : normalizeMimeType(msg.mimeType),
85
- pending: {}
86
- }, []];
124
+ mimeType: msg.mimeType === void 0 ? null : normalizeMimeType(msg.mimeType)
125
+ }), []];
87
126
  if (msg.type === "UNLOAD" || msg.type === "DETACH") return [INITIAL, []];
88
127
  if (msg.type === "SEGMENT_LOADED" && msg.trackId === "manifest" && state.manifestUrl !== null) {
89
128
  const text = new TextDecoder().decode(msg.bytes);
@@ -106,43 +145,85 @@ const reduceDash = (slice, msg, kernel) => {
106
145
  presentation: result.presentation
107
146
  })]];
108
147
  }
109
- if (msg.type === "SEGMENT_LOADED" && msg.trackId.startsWith(INDEX_TOKEN)) {
148
+ let next = state;
149
+ if (msg.type === "PLAYLIST_REFRESHED" && msg.renditionId !== void 0) {
150
+ const renditionId = msg.renditionId;
151
+ const token = `${INDEX_TOKEN}${renditionId}`;
152
+ if (token in next.pending) {
153
+ const pending = _objectSpread2({}, next.pending);
154
+ delete pending[token];
155
+ next = _objectSpread2(_objectSpread2({}, next), {}, { pending });
156
+ }
157
+ }
158
+ if (msg.type === "SEGMENT_LOADED" && msg.trackId in state.pending) {
159
+ var _findRendition;
110
160
  const renditionId = state.pending[msg.trackId];
111
- if (renditionId === void 0 || kernel.presentation === null) return [state, []];
112
- const rendition = findRendition(kernel.presentation, renditionId);
161
+ const sidx = kernel.presentation === null ? null : asSidx((_findRendition = findRendition(kernel.presentation, renditionId)) === null || _findRendition === void 0 ? void 0 : _findRendition.segments);
162
+ const segments = sidx === null ? [] : sidxToSegments(new Uint8Array(msg.bytes), sidx);
163
+ if (sidx !== null && segments.length > 0) {
164
+ var _segments$0$seq, _segments$;
165
+ return [state, [feed({
166
+ type: "PLAYLIST_REFRESHED",
167
+ trackId: renditionId,
168
+ renditionId,
169
+ mediaSequence: (_segments$0$seq = (_segments$ = segments[0]) === null || _segments$ === void 0 ? void 0 : _segments$.seq) !== null && _segments$0$seq !== void 0 ? _segments$0$seq : 0,
170
+ segments
171
+ })]];
172
+ }
113
173
  const pending = _objectSpread2({}, state.pending);
114
174
  delete pending[msg.trackId];
115
- const sidx = asSidx(rendition === null || rendition === void 0 ? void 0 : rendition.segments);
116
175
  if (sidx === null) return [_objectSpread2(_objectSpread2({}, state), {}, { pending }), []];
117
- const segments = sidxToSegments(new Uint8Array(msg.bytes), sidx);
118
- if (segments.length === 0) return [_objectSpread2(_objectSpread2({}, state), {}, { pending }), []];
119
- const merged = mergeSidx(kernel.presentation, renditionId, segments);
120
- return [_objectSpread2(_objectSpread2({}, state), {}, { pending }), [feed({
121
- type: "MANIFEST_LOADED",
122
- presentation: merged
123
- })]];
176
+ const error = {
177
+ category: "media",
178
+ code: "MEDIA_CONTAINER_INVALID",
179
+ fatal: false,
180
+ recoverable: false,
181
+ context: {
182
+ renditionId,
183
+ reason: "sidx holds no segment"
184
+ }
185
+ };
186
+ const [failed, failEffects] = unavailable(_objectSpread2(_objectSpread2({}, state), {}, { pending }), kernel, renditionId, error);
187
+ return [failed, [{
188
+ kind: "emit",
189
+ event: "error",
190
+ payload: {
191
+ category: error.category,
192
+ code: error.code,
193
+ fatal: false,
194
+ recoverable: false,
195
+ renditionId
196
+ }
197
+ }, ...failEffects]];
124
198
  }
125
- if ((msg.type === "MANIFEST_LOADED" || msg.type === "TIME_UPDATE" || msg.type === "RESUME") && kernel.lifecycle.phase !== "suspended") {
126
- const needed = neededIndexes(kernel).filter((rendition) => !Object.values(state.pending).includes(rendition.id));
127
- if (needed.length === 0) return [state, []];
128
- const effects = [];
199
+ if (msg.type === "SEGMENT_FAILED" && msg.trackId in state.pending) {
200
+ const renditionId = state.pending[msg.trackId];
129
201
  const pending = _objectSpread2({}, state.pending);
130
- for (const rendition of needed) {
131
- const token = `${INDEX_TOKEN}${rendition.id}`;
132
- if (pending[token] !== void 0) continue;
133
- const sidx = asSidx(rendition.segments);
134
- if (sidx === null) continue;
135
- pending[token] = rendition.id;
136
- effects.push({
137
- kind: "fetch",
138
- token,
139
- url: sidx.url,
140
- range: sidx.indexRange
141
- });
142
- }
143
- return [_objectSpread2(_objectSpread2({}, state), {}, { pending }), effects];
202
+ delete pending[msg.trackId];
203
+ return unavailable(_objectSpread2(_objectSpread2({}, state), {}, { pending }), kernel, renditionId, msg.error);
204
+ }
205
+ if (kernel.lifecycle.phase !== "ready" || kernel.presentation === null) return [next, []];
206
+ const key = `${kernel.quality.version}:${kernel.quality.active}`;
207
+ if (key === next.seen && msg.type !== "RESUME") return [next, []];
208
+ const effects = [];
209
+ const pending = _objectSpread2({}, next.pending);
210
+ for (const rendition of neededIndexes(next, kernel)) {
211
+ const sidx = asSidx(rendition.segments);
212
+ if (sidx === null) continue;
213
+ const token = `${INDEX_TOKEN}${rendition.id}`;
214
+ pending[token] = rendition.id;
215
+ effects.push({
216
+ kind: "fetch",
217
+ token,
218
+ url: sidx.url,
219
+ range: sidx.indexRange,
220
+ renditionId: rendition.id
221
+ });
144
222
  }
145
- return [state, []];
223
+ return [_objectSpread2(_objectSpread2({}, next), {}, {
224
+ pending,
225
+ seen: key
226
+ }), effects];
146
227
  };
147
228
  /**
148
229
  * The stage factory. `mattebox({ stages: [dashCmaf()] })` is all a consumer
@@ -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 { findBox, parseSidx } from "../../containers/mp4-box/index.js";
3
3
  //#region src/protocols/dash-cmaf/parse.ts
4
4
  /**
@@ -479,13 +479,5 @@ function sidxToSegments(sidxBytes, addressing) {
479
479
  }
480
480
  return segments;
481
481
  }
482
- /**
483
- * Immutably swaps a rendition's unresolved sidx addressing for the explicit
484
- * segment list parsed from its index box. Everything else about the
485
- * presentation is already known from the MPD.
486
- */
487
- function mergeSidx(presentation, renditionId, segments) {
488
- return _objectSpread2(_objectSpread2({}, presentation), {}, { periods: presentation.periods.map((period) => _objectSpread2(_objectSpread2({}, period), {}, { tracks: period.tracks.map((track) => track.renditions.some((r) => r.id === renditionId) ? _objectSpread2(_objectSpread2({}, track), {}, { renditions: track.renditions.map((rendition) => rendition.id === renditionId ? _objectSpread2(_objectSpread2({}, rendition), {}, { segments }) : rendition) }) : track) })) });
489
- }
490
482
  //#endregion
491
- export { mergeSidx, parse, parseDuration, sidxToSegments };
483
+ export { parse, parseDuration, sidxToSegments };
@@ -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 { registerLiveNamespace } from "../live-shared.js";
3
3
  import { parse } from "../dash-cmaf/parse.js";
4
4
  //#region src/protocols/dash-live/index.ts
@@ -12,6 +12,14 @@ const DEFAULT_HOLD_BACK = 10;
12
12
  const DEFAULT_TIME_SHIFT = 60;
13
13
  /** Window movement below this is not worth a fact, in seconds. */
14
14
  const WINDOW_QUANTUM = .5;
15
+ /**
16
+ * Failed MPD reloads in a row before the load fails. Each reload already
17
+ * carries the transport's own retries, so this is several update periods
18
+ * of an MPD that does not answer. Without a limit the stream stops moving
19
+ * and nothing says why; retrying forever keeps the network busy for a
20
+ * stream that cannot play.
21
+ */
22
+ const FAILURE_LIMIT = 4;
15
23
  const INITIAL = {
16
24
  manifestUrl: null,
17
25
  skew: null,
@@ -20,7 +28,8 @@ const INITIAL = {
20
28
  clockPending: false,
21
29
  lastWindowEnd: -1,
22
30
  lastWallClock: null,
23
- suspended: false
31
+ suspended: false,
32
+ failures: 0
24
33
  };
25
34
  /** The window arithmetic; null when it cannot move or is not worth a fact. */
26
35
  function windowUpdate(state, live) {
@@ -83,6 +92,33 @@ function clockTick() {
83
92
  }
84
93
  };
85
94
  }
95
+ /**
96
+ * An MPD reload that failed or did not parse. The next reload waits one
97
+ * update period, as a good one would; after FAILURE_LIMIT in a row the
98
+ * load fails.
99
+ */
100
+ function reloadFailed(state, presentation, cause) {
101
+ var _presentation$live$up;
102
+ const failures = state.failures + 1;
103
+ if (failures >= FAILURE_LIMIT) return [_objectSpread2(_objectSpread2({}, state), {}, { failures }), [feed({
104
+ type: "MANIFEST_FAILED",
105
+ error: {
106
+ category: "manifest",
107
+ code: "MANIFEST_REFRESH_FAILED",
108
+ fatal: true,
109
+ recoverable: false,
110
+ context: {
111
+ cause,
112
+ attempts: failures
113
+ }
114
+ }
115
+ })]];
116
+ if (state.tickPending || state.suspended || !drivesWindow(presentation)) return [_objectSpread2(_objectSpread2({}, state), {}, { failures }), []];
117
+ return [_objectSpread2(_objectSpread2({}, state), {}, {
118
+ failures,
119
+ tickPending: true
120
+ }), [tick((_presentation$live$up = presentation.live.updatePeriod) !== null && _presentation$live$up !== void 0 ? _presentation$live$up : 4)]];
121
+ }
86
122
  const reduceDashLive = (slice, msg, kernel) => {
87
123
  let state = slice !== null && slice !== void 0 ? slice : INITIAL;
88
124
  if ((msg.type === "TIME_UPDATE" || msg.type === "SEGMENT_LOADED") && msg.wallClock !== void 0) state = _objectSpread2(_objectSpread2({}, state), {}, { lastWallClock: msg.wallClock });
@@ -174,6 +210,8 @@ const reduceDashLive = (slice, msg, kernel) => {
174
210
  url: state.manifestUrl
175
211
  }]];
176
212
  }
213
+ if (msg.type === "SEGMENT_FAILED" && msg.trackId === UTC_TOKEN) return [_objectSpread2(_objectSpread2({}, state), {}, { utcPending: false }), []];
214
+ if (msg.type === "SEGMENT_FAILED" && msg.trackId === MPD_TOKEN) return reloadFailed(state, kernel.presentation, msg.error.code);
177
215
  if (msg.type === "SEGMENT_LOADED" && msg.trackId === UTC_TOKEN) {
178
216
  const serverTime = Date.parse(new TextDecoder().decode(msg.bytes).trim());
179
217
  if (!Number.isFinite(serverTime) || msg.wallClock === void 0) return [_objectSpread2(_objectSpread2({}, state), {}, { utcPending: false }), []];
@@ -185,19 +223,21 @@ const reduceDashLive = (slice, msg, kernel) => {
185
223
  if (msg.type === "SEGMENT_LOADED" && msg.trackId === MPD_TOKEN) {
186
224
  if (state.manifestUrl === null) return [state, []];
187
225
  const result = parse(new TextDecoder().decode(msg.bytes), state.manifestUrl);
226
+ if (result.presentation === null) {
227
+ var _result$error$code, _result$error;
228
+ return reloadFailed(state, kernel.presentation, (_result$error$code = (_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.code) !== null && _result$error$code !== void 0 ? _result$error$code : "MANIFEST_PARSE_FAILED");
229
+ }
188
230
  const effects = [];
189
- let next = state;
190
- if (result.presentation !== null) {
191
- effects.push(feed({
192
- type: "MANIFEST_LOADED",
193
- presentation: result.presentation
194
- }));
195
- if (result.presentation.isLive && result.presentation.live !== void 0) {
196
- const window = windowUpdate(next, result.presentation.live);
197
- if (window !== null) {
198
- next = window.next;
199
- effects.push(window.fact);
200
- }
231
+ let next = _objectSpread2(_objectSpread2({}, state), {}, { failures: 0 });
232
+ effects.push(feed({
233
+ type: "MANIFEST_LOADED",
234
+ presentation: result.presentation
235
+ }));
236
+ if (result.presentation.isLive && result.presentation.live !== void 0) {
237
+ const window = windowUpdate(next, result.presentation.live);
238
+ if (window !== null) {
239
+ next = window.next;
240
+ effects.push(window.fact);
201
241
  }
202
242
  }
203
243
  return [next, effects];