mattebox 0.16.1 → 0.17.0

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 (111) hide show
  1. package/dist/cdn/mattebox.dash-drm.min.js +3 -3
  2. package/dist/cdn/mattebox.dash-ll.min.js +3 -3
  3. package/dist/cdn/mattebox.dash.min.js +3 -3
  4. package/dist/cdn/mattebox.dual-drm.min.js +3 -3
  5. package/dist/cdn/mattebox.dual-ll.min.js +3 -3
  6. package/dist/cdn/mattebox.dual-ts-drm.min.js +3 -3
  7. package/dist/cdn/mattebox.dual-ts.min.js +3 -3
  8. package/dist/cdn/mattebox.dual.min.js +3 -3
  9. package/dist/cdn/mattebox.hls-drm.min.js +3 -3
  10. package/dist/cdn/mattebox.hls-ll.min.js +3 -3
  11. package/dist/cdn/mattebox.hls-ts-drm.min.js +3 -3
  12. package/dist/cdn/mattebox.hls-ts.min.js +3 -3
  13. package/dist/cdn/mattebox.hls.min.js +3 -3
  14. package/dist/cdn/mattebox.kernel.min.js +1 -1
  15. package/dist/cdn/mattebox.min.js +3 -3
  16. package/dist/containers/emsg.d.ts +16 -0
  17. package/dist/containers/emsg.d.ts.map +1 -1
  18. package/dist/containers/emsg.js +31 -1
  19. package/dist/containers/emsg.js.map +1 -1
  20. package/dist/containers/fmp4/fit.d.ts +6 -0
  21. package/dist/containers/fmp4/fit.d.ts.map +1 -1
  22. package/dist/containers/fmp4/fit.js +49 -0
  23. package/dist/containers/fmp4/fit.js.map +1 -1
  24. package/dist/containers/fmp4/writer.d.ts +12 -0
  25. package/dist/containers/fmp4/writer.d.ts.map +1 -1
  26. package/dist/containers/fmp4/writer.js +33 -1
  27. package/dist/containers/fmp4/writer.js.map +1 -1
  28. package/dist/containers/ts-transmux/index.d.ts.map +1 -1
  29. package/dist/containers/ts-transmux/index.js +44 -2
  30. package/dist/containers/ts-transmux/index.js.map +1 -1
  31. package/dist/containers/ts-transmux/runner.d.ts +2 -2
  32. package/dist/containers/ts-transmux/runner.d.ts.map +1 -1
  33. package/dist/containers/ts-transmux/runner.js +13 -4
  34. package/dist/containers/ts-transmux/runner.js.map +1 -1
  35. package/dist/containers/ts-transmux/serve.d.ts +3 -1
  36. package/dist/containers/ts-transmux/serve.d.ts.map +1 -1
  37. package/dist/containers/ts-transmux/serve.js +4 -2
  38. package/dist/containers/ts-transmux/serve.js.map +1 -1
  39. package/dist/containers/ts-transmux/transmux.d.ts +29 -5
  40. package/dist/containers/ts-transmux/transmux.d.ts.map +1 -1
  41. package/dist/containers/ts-transmux/transmux.js +91 -29
  42. package/dist/containers/ts-transmux/transmux.js.map +1 -1
  43. package/dist/eme/index.d.ts.map +1 -1
  44. package/dist/eme/index.js +2 -0
  45. package/dist/eme/index.js.map +1 -1
  46. package/dist/es2015/containers/emsg.js +28 -2
  47. package/dist/es2015/containers/fmp4/fit.js +51 -2
  48. package/dist/es2015/containers/fmp4/writer.js +31 -2
  49. package/dist/es2015/containers/ts-transmux/index.js +35 -3
  50. package/dist/es2015/containers/ts-transmux/runner.js +8 -5
  51. package/dist/es2015/containers/ts-transmux/serve.js +6 -4
  52. package/dist/es2015/containers/ts-transmux/transmux.js +90 -37
  53. package/dist/es2015/eme/index.js +8 -0
  54. package/dist/es2015/index.js +4 -3
  55. package/dist/es2015/kernel/context.js +6 -0
  56. package/dist/es2015/kernel/dry-run.js +2 -2
  57. package/dist/es2015/kernel/prepare.js +2 -2
  58. package/dist/es2015/kernel/reducer.js +46 -6
  59. package/dist/es2015/protocols/dash-cmaf/parse.js +17 -2
  60. package/dist/es2015/protocols/hls-cmaf/parse.js +58 -2
  61. package/dist/es2015/stages/interstitials/breaks.js +341 -0
  62. package/dist/es2015/stages/interstitials/index.js +750 -0
  63. package/dist/es2015/stages/timed-metadata/index.js +10 -23
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +8 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/kernel/context.d.ts.map +1 -1
  68. package/dist/kernel/context.js +8 -0
  69. package/dist/kernel/context.js.map +1 -1
  70. package/dist/kernel/dry-run.d.ts +2 -0
  71. package/dist/kernel/dry-run.d.ts.map +1 -1
  72. package/dist/kernel/dry-run.js +1 -0
  73. package/dist/kernel/dry-run.js.map +1 -1
  74. package/dist/kernel/prepare.d.ts.map +1 -1
  75. package/dist/kernel/prepare.js +1 -0
  76. package/dist/kernel/prepare.js.map +1 -1
  77. package/dist/kernel/reducer.d.ts.map +1 -1
  78. package/dist/kernel/reducer.js +44 -3
  79. package/dist/kernel/reducer.js.map +1 -1
  80. package/dist/protocols/dash-cmaf/parse.d.ts.map +1 -1
  81. package/dist/protocols/dash-cmaf/parse.js +16 -0
  82. package/dist/protocols/dash-cmaf/parse.js.map +1 -1
  83. package/dist/protocols/hls-cmaf/parse.d.ts.map +1 -1
  84. package/dist/protocols/hls-cmaf/parse.js +75 -4
  85. package/dist/protocols/hls-cmaf/parse.js.map +1 -1
  86. package/dist/stages/interstitials/breaks.d.ts +113 -0
  87. package/dist/stages/interstitials/breaks.d.ts.map +1 -0
  88. package/dist/stages/interstitials/breaks.js +390 -0
  89. package/dist/stages/interstitials/breaks.js.map +1 -0
  90. package/dist/stages/interstitials/index.d.ts +57 -0
  91. package/dist/stages/interstitials/index.d.ts.map +1 -0
  92. package/dist/stages/interstitials/index.js +853 -0
  93. package/dist/stages/interstitials/index.js.map +1 -0
  94. package/dist/stages/timed-metadata/index.d.ts.map +1 -1
  95. package/dist/stages/timed-metadata/index.js +10 -27
  96. package/dist/stages/timed-metadata/index.js.map +1 -1
  97. package/dist/types/facade.d.ts +2 -19
  98. package/dist/types/facade.d.ts.map +1 -1
  99. package/dist/types/ir.d.ts +13 -1
  100. package/dist/types/ir.d.ts.map +1 -1
  101. package/dist/types/kernel.d.ts +6 -0
  102. package/dist/types/kernel.d.ts.map +1 -1
  103. package/dist/types/load.d.ts +28 -0
  104. package/dist/types/load.d.ts.map +1 -0
  105. package/dist/types/load.js +3 -0
  106. package/dist/types/load.js.map +1 -0
  107. package/dist/types/messages.d.ts +4 -0
  108. package/dist/types/messages.d.ts.map +1 -1
  109. package/dist/types/stage.d.ts +10 -0
  110. package/dist/types/stage.d.ts.map +1 -1
  111. package/package.json +1 -1
@@ -3,9 +3,9 @@ import { transmux } from "./transmux.js";
3
3
  /** Answers transmux requests on a Worker's scope. */
4
4
  function serveTransmux(scope) {
5
5
  scope.onmessage = (event) => {
6
- var _event$data$parameter;
6
+ var _event$data$parameter, _event$data$timing;
7
7
  const { id, bytes, presentationStart, wantCaptions, tracks = "all" } = event.data;
8
- const result = transmux(new Uint8Array(bytes), presentationStart, wantCaptions, tracks, (_event$data$parameter = event.data.parameterSets) !== null && _event$data$parameter !== void 0 ? _event$data$parameter : null);
8
+ const result = transmux(new Uint8Array(bytes), presentationStart, wantCaptions, tracks, (_event$data$parameter = event.data.parameterSets) !== null && _event$data$parameter !== void 0 ? _event$data$parameter : null, (_event$data$timing = event.data.timing) !== null && _event$data$timing !== void 0 ? _event$data$timing : null);
9
9
  const out = result.bytes;
10
10
  if (out === null) {
11
11
  scope.postMessage({
@@ -15,7 +15,8 @@ function serveTransmux(scope) {
15
15
  captions: [],
16
16
  metadata: [],
17
17
  droppedAudio: result.droppedAudio,
18
- parameterSets: null
18
+ parameterSets: null,
19
+ anchor: result.anchor
19
20
  }, []);
20
21
  return;
21
22
  }
@@ -28,7 +29,8 @@ function serveTransmux(scope) {
28
29
  captions: result.captions,
29
30
  metadata: result.metadata,
30
31
  droppedAudio: result.droppedAudio,
31
- parameterSets: result.parameterSets
32
+ parameterSets: result.parameterSets,
33
+ anchor: result.anchor
32
34
  }, [buffer]);
33
35
  };
34
36
  }
@@ -2,7 +2,7 @@ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.155.0/helpers
2
2
  import { concat, sequenceNumberFor, writeInitSegment, writeMediaSegment } from "../fmp4/writer.js";
3
3
  import { STREAM_TYPE, demux, unrollTimestamps } from "./demux.js";
4
4
  import { ccTriplesFromSei } from "../sei.js";
5
- import { adtsFragment, parseAdts } from "../adts.js";
5
+ import { SAMPLES_PER_FRAME, adtsFragment, parseAdts } from "../adts.js";
6
6
  import { NAL_TYPE, accessUnitFromNals, nalType, splitNalUnits, spsDimensions, toAccessUnit } from "./h264.js";
7
7
  import { HEVC_NAL_TYPE, hevcAccessUnitFromNals, hevcDecoderConfiguration, hevcNalType, hevcSpsInfo } from "./h265.js";
8
8
  // src/containers/ts-transmux/transmux.ts
@@ -13,10 +13,14 @@ import { HEVC_NAL_TYPE, hevcAccessUnitFromNals, hevcDecoderConfiguration, hevcNa
13
13
  * Worker. A muxed segment produces one init with a video and an audio track
14
14
  * and one media fragment carrying both, so a single SourceBuffer decodes it.
15
15
  *
16
- * Segment timing is anchored to the playlist presentation start, not the raw
17
- * PES timestamps: legacy TS streams begin at an arbitrary PTS, and aligning
18
- * baseMediaDecodeTime to the playlist is what keeps the buffer where the
19
- * scheduler expects it. Sample durations still come from the PES timeline.
16
+ * Segment timing maps the raw PES timestamps onto the presentation through
17
+ * an anchor: one timestamp at one presentation time. Legacy TS streams begin
18
+ * at an arbitrary PTS, so the first segment of a timeline sets the anchor at
19
+ * its playlist start, and every later segment of every rendition is placed
20
+ * from its own timestamps against that anchor. Audio and video renditions
21
+ * whose segments do not start together keep the offset the encoder gave
22
+ * them, as hls.js keeps it with one initPTS per discontinuity. Inside one
23
+ * segment, the video and the audio each start at their own first timestamp.
20
24
  */
21
25
  const VIDEO_TIMESCALE = 9e4;
22
26
  const VIDEO_TRACK_ID = 1;
@@ -24,21 +28,27 @@ const AUDIO_TRACK_ID = 2;
24
28
  /** Fallback duration for a lone trailing video sample: 30 fps in 90 kHz. */
25
29
  const DEFAULT_FRAME_DURATION = 3e3;
26
30
  const PTS_WRAP = Math.pow(2, 33);
31
+ /** The signed distance from `from` to `to` on the 33-bit clock, in 90 kHz units. */
32
+ function wrapDelta(to, from) {
33
+ let delta = (to - from) % PTS_WRAP;
34
+ if (delta > PTS_WRAP / 2) delta -= PTS_WRAP;
35
+ else if (delta < -PTS_WRAP / 2) delta += PTS_WRAP;
36
+ return delta;
37
+ }
38
+ function timeOfAnchor(anchor) {
39
+ return (timestamp) => anchor.time + wrapDelta(timestamp, anchor.pts) / VIDEO_TIMESCALE;
40
+ }
27
41
  /**
28
- * The metadata stream's tags on the presentation timeline. The first video
29
- * DTS (or audio PTS) sits at `presentationStart`, so each tag keeps its
30
- * distance from it, across a 33-bit PTS wrap. The bytes are copied so a Worker posts only the
31
- * tag, not the segment it was cut from.
42
+ * The metadata stream's tags on the presentation timeline, each at its own
43
+ * PTS, across a 33-bit PTS wrap. The bytes are copied so a Worker posts only
44
+ * the tag, not the segment it was cut from.
32
45
  */
33
- function timedTags(streams, presentationStart, anchor) {
46
+ function timedTags(streams, timeOf) {
34
47
  const tags = [];
35
48
  for (const packet of streams.id3) {
36
- if (packet.pts === null || anchor === null) continue;
37
- let delta = (packet.pts - anchor) % PTS_WRAP;
38
- if (delta > PTS_WRAP / 2) delta -= PTS_WRAP;
39
- else if (delta < -PTS_WRAP / 2) delta += PTS_WRAP;
49
+ if (packet.pts === null) continue;
40
50
  tags.push({
41
- time: presentationStart + delta / VIDEO_TIMESCALE,
51
+ time: timeOf(packet.pts),
42
52
  bytes: packet.data.slice()
43
53
  });
44
54
  }
@@ -109,8 +119,8 @@ function frameAccessUnits(packets, syntax) {
109
119
  flush();
110
120
  return framed;
111
121
  }
112
- function buildVideo(packets, presentationStart, wantCaptions, carried) {
113
- var _packets$, _ref, _sps, _ref2, _pps, _ref3, _vps;
122
+ function buildVideo(packets, timeOf, wantCaptions, carried) {
123
+ var _packets$, _ref, _sps, _ref2, _pps, _ref3, _vps, _dts$;
114
124
  if (packets.length === 0) return null;
115
125
  const hevc = ((_packets$ = packets[0]) === null || _packets$ === void 0 ? void 0 : _packets$.streamType) === STREAM_TYPE.h265;
116
126
  const syntax = hevc ? HEVC : AVC;
@@ -130,7 +140,8 @@ function buildVideo(packets, presentationStart, wantCaptions, carried) {
130
140
  if (sps === null || pps === null || hevc && vps === null) return null;
131
141
  const dts = unrollTimestamps(framed.map((f) => f.dts));
132
142
  const pts = unrollTimestamps(framed.map((f) => f.pts));
133
- const base = Math.round(presentationStart * VIDEO_TIMESCALE);
143
+ const start = Math.max(0, timeOf((_dts$ = dts[0]) !== null && _dts$ !== void 0 ? _dts$ : 0));
144
+ const base = Math.round(start * VIDEO_TIMESCALE);
134
145
  const captions = [];
135
146
  if (wantCaptions) {
136
147
  var _pts$;
@@ -140,7 +151,7 @@ function buildVideo(packets, presentationStart, wantCaptions, carried) {
140
151
  if (unit.sei.length === 0) continue;
141
152
  const triples = unit.sei.flatMap((nal) => ccTriplesFromSei(nal, syntax.seiHeader));
142
153
  if (triples.length === 0) continue;
143
- const time = presentationStart + (pts[i] - firstPts) / VIDEO_TIMESCALE;
154
+ const time = start + (pts[i] - firstPts) / VIDEO_TIMESCALE;
144
155
  captions.push({
145
156
  time,
146
157
  triples
@@ -184,26 +195,66 @@ function buildVideo(packets, presentationStart, wantCaptions, carried) {
184
195
  }
185
196
  };
186
197
  }
187
- function buildAudio(packets, presentationStart) {
198
+ function buildAudio(packets, timeOf, presentationStart) {
199
+ var _packets$0$pts, _packets$2;
188
200
  if (packets.length === 0) return null;
189
201
  const adts = parseAdts(concat(...packets.map((p) => p.data)));
190
202
  if (adts.frames.length === 0) return null;
191
- return adtsFragment(adts, AUDIO_TRACK_ID, presentationStart);
203
+ const first = (_packets$0$pts = (_packets$2 = packets[0]) === null || _packets$2 === void 0 ? void 0 : _packets$2.pts) !== null && _packets$0$pts !== void 0 ? _packets$0$pts : null;
204
+ const start = first === null ? presentationStart : timeOf(first);
205
+ if (start >= 0) return adtsFragment(adts, AUDIO_TRACK_ID, start);
206
+ const frame = SAMPLES_PER_FRAME / adts.sampleRate;
207
+ const dropped = Math.ceil(-start / frame - 1e-9);
208
+ if (dropped >= adts.frames.length) return null;
209
+ return adtsFragment(_objectSpread2(_objectSpread2({}, adts), {}, { frames: adts.frames.slice(dropped) }), AUDIO_TRACK_ID, start + dropped * frame);
192
210
  }
193
- function transmux(input, presentationStart = 0, wantCaptions = false, tracks = "all", parameterSets = null) {
194
- var _video$captions, _ref4, _streams$video$, _streams$audio$, _video$parameterSets;
195
- const streams = demux(input);
196
- if (streams.notTransportStream) return {
197
- bytes: null,
198
- notTransportStream: true,
199
- empty: false,
200
- captions: [],
201
- metadata: [],
202
- droppedAudio: false,
203
- parameterSets: null
211
+ /**
212
+ * The anchor a segment is placed by: its timeline's, or a new one that puts
213
+ * the segment's first timestamp at its playlist start, when the timeline
214
+ * has none or the segment drifted past the tolerance.
215
+ */
216
+ function anchorFor(reference, presentationStart, timing) {
217
+ var _timing$anchor, _timing$anchor2;
218
+ if (reference === null) return (_timing$anchor = timing === null || timing === void 0 ? void 0 : timing.anchor) !== null && _timing$anchor !== void 0 ? _timing$anchor : null;
219
+ const fresh = {
220
+ pts: reference,
221
+ time: presentationStart
204
222
  };
205
- const video = tracks === "audio" ? null : buildVideo(streams.video, presentationStart, wantCaptions, parameterSets);
206
- const audio = tracks === "video" ? null : buildAudio(streams.audio, presentationStart);
223
+ const kept = (_timing$anchor2 = timing === null || timing === void 0 ? void 0 : timing.anchor) !== null && _timing$anchor2 !== void 0 ? _timing$anchor2 : null;
224
+ if (kept === null) return fresh;
225
+ const drift = timeOfAnchor(kept)(reference) - presentationStart;
226
+ return Math.abs(drift) > timing.tolerance ? fresh : kept;
227
+ }
228
+ /** The first timestamp of the field `key` among `packets`, or null when none carries one. */
229
+ function firstTimestamp(packets, key) {
230
+ for (const packet of packets) {
231
+ const value = packet[key];
232
+ if (value !== null) return value;
233
+ }
234
+ return null;
235
+ }
236
+ function transmux(input, presentationStart = 0, wantCaptions = false, tracks = "all", parameterSets = null, timing = null) {
237
+ var _video$captions, _video$parameterSets;
238
+ const streams = demux(input);
239
+ if (streams.notTransportStream) {
240
+ var _timing$anchor3;
241
+ return {
242
+ bytes: null,
243
+ notTransportStream: true,
244
+ empty: false,
245
+ captions: [],
246
+ metadata: [],
247
+ droppedAudio: false,
248
+ parameterSets: null,
249
+ anchor: (_timing$anchor3 = timing === null || timing === void 0 ? void 0 : timing.anchor) !== null && _timing$anchor3 !== void 0 ? _timing$anchor3 : null
250
+ };
251
+ }
252
+ const videoFirst = tracks !== "audio" ? firstTimestamp(streams.video, "dts") : null;
253
+ const audioFirst = tracks !== "video" ? firstTimestamp(streams.audio, "pts") : null;
254
+ const anchor = anchorFor(videoFirst === null ? audioFirst : audioFirst === null || wrapDelta(audioFirst, videoFirst) >= 0 ? videoFirst : audioFirst, presentationStart, timing);
255
+ const timeOf = anchor === null ? () => presentationStart : timeOfAnchor(anchor);
256
+ const video = tracks === "audio" ? null : buildVideo(streams.video, timeOf, wantCaptions, parameterSets);
257
+ const audio = tracks === "video" ? null : buildAudio(streams.audio, timeOf, presentationStart);
207
258
  const droppedAudio = tracks === "video" && streams.audio.length > 0;
208
259
  if (video === null && audio === null) return {
209
260
  bytes: null,
@@ -212,7 +263,8 @@ function transmux(input, presentationStart = 0, wantCaptions = false, tracks = "
212
263
  captions: [],
213
264
  metadata: [],
214
265
  droppedAudio,
215
- parameterSets: null
266
+ parameterSets: null,
267
+ anchor
216
268
  };
217
269
  const configs = [];
218
270
  const fragments = [];
@@ -231,9 +283,10 @@ function transmux(input, presentationStart = 0, wantCaptions = false, tracks = "
231
283
  notTransportStream: false,
232
284
  empty: false,
233
285
  captions: (_video$captions = video === null || video === void 0 ? void 0 : video.captions) !== null && _video$captions !== void 0 ? _video$captions : [],
234
- metadata: timedTags(streams, presentationStart, (_ref4 = video !== null ? (_streams$video$ = streams.video[0]) === null || _streams$video$ === void 0 ? void 0 : _streams$video$.dts : (_streams$audio$ = streams.audio[0]) === null || _streams$audio$ === void 0 ? void 0 : _streams$audio$.pts) !== null && _ref4 !== void 0 ? _ref4 : null),
286
+ metadata: timedTags(streams, timeOf),
235
287
  droppedAudio,
236
- parameterSets: (_video$parameterSets = video === null || video === void 0 ? void 0 : video.parameterSets) !== null && _video$parameterSets !== void 0 ? _video$parameterSets : null
288
+ parameterSets: (_video$parameterSets = video === null || video === void 0 ? void 0 : video.parameterSets) !== null && _video$parameterSets !== void 0 ? _video$parameterSets : null,
289
+ anchor
237
290
  };
238
291
  }
239
292
  export { transmux };
@@ -1,4 +1,5 @@
1
1
  import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/objectSpread2.js";
2
+ import _asyncToGenerator from "../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/asyncToGenerator.js";
2
3
  import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/objectWithoutProperties.js";
3
4
  import { fetchWithin } from "../kernel/transport.js";
4
5
  import emeCore from "../stages/eme-core/index.js";
@@ -56,6 +57,13 @@ function attachEme(element, options = {}) {
56
57
  registerChunkSplitter: noop,
57
58
  reduce: noop,
58
59
  dispatch: noop,
60
+ load: noop,
61
+ preload: function() {
62
+ var _ref = _asyncToGenerator(function* () {});
63
+ return function preload() {
64
+ return _ref.apply(this, arguments);
65
+ };
66
+ }(),
59
67
  addRequestHook: () => noop,
60
68
  addResponseHook: () => noop,
61
69
  capabilities: () => [],
@@ -320,10 +320,11 @@ function mattebox(options) {
320
320
  if (phase !== "idle" && phase !== "attaching") bus.dispatch({ type: "UNLOAD" });
321
321
  const kept = seeds.get(absolute);
322
322
  seeds.delete(absolute);
323
- bus.dispatch(_objectSpread2(_objectSpread2({
323
+ bus.emitEvent("lifecycle:loading", _objectSpread2(_objectSpread2({ url: absolute }, (loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.mimeType) !== void 0 ? { mimeType: loadOptions.mimeType } : {}), (loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.start) !== void 0 ? { start: loadOptions.start } : {}));
324
+ bus.dispatch(_objectSpread2(_objectSpread2(_objectSpread2({
324
325
  type: "LOAD",
325
326
  url: absolute
326
- }, (loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.mimeType) !== void 0 ? { mimeType: loadOptions.mimeType } : {}), kept !== void 0 && performance.now() < kept.expires ? { seed: kept.seed } : {}));
327
+ }, (loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.mimeType) !== void 0 ? { mimeType: loadOptions.mimeType } : {}), (loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.start) !== void 0 ? { start: loadOptions.start } : {}), kept !== void 0 && performance.now() < kept.expires ? { seed: kept.seed } : {}));
327
328
  },
328
329
  preload(url, loadOptions) {
329
330
  return _asyncToGenerator(function* () {
@@ -354,7 +355,7 @@ function mattebox(options) {
354
355
  transport,
355
356
  element,
356
357
  seed
357
- }, absolute, _objectSpread2(_objectSpread2({}, (loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.mimeType) !== void 0 ? { mimeType: loadOptions.mimeType } : {}), {}, {
358
+ }, absolute, _objectSpread2(_objectSpread2(_objectSpread2({}, (loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.mimeType) !== void 0 ? { mimeType: loadOptions.mimeType } : {}), (loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.start) !== void 0 ? { start: loadOptions.start } : {}), {}, {
358
359
  segments,
359
360
  keepMs
360
361
  }));
@@ -84,6 +84,12 @@ function createStageContext(deps) {
84
84
  dispatch(cmd) {
85
85
  deps.bus.dispatch(cmd);
86
86
  },
87
+ load(url, options) {
88
+ deps.facade.load(url, options);
89
+ },
90
+ preload(url, options) {
91
+ return deps.facade.preload(url, options);
92
+ },
87
93
  emit(event, payload) {
88
94
  deps.bus.emitEvent(event, payload);
89
95
  },
@@ -168,11 +168,11 @@ function dryRun(deps, url, options) {
168
168
  type: "ATTACH",
169
169
  element: deps.element
170
170
  });
171
- feed(_objectSpread2({
171
+ feed(_objectSpread2(_objectSpread2({
172
172
  type: "LOAD",
173
173
  url,
174
174
  seed: deps.seed
175
- }, options.mimeType !== void 0 ? { mimeType: options.mimeType } : {}));
175
+ }, options.mimeType !== void 0 ? { mimeType: options.mimeType } : {}), options.start !== void 0 ? { start: options.start } : {}));
176
176
  });
177
177
  }
178
178
  export { dryRun };
@@ -8,7 +8,7 @@ import _asyncToGenerator from "../_virtual/_@oxc-project_runtime@0.155.0/helpers
8
8
  */
9
9
  function metaFor(request) {
10
10
  var _request$renditionId, _request$segmentStart, _request$segmentDurat;
11
- return {
11
+ return _objectSpread2({
12
12
  trackId: request.trackId,
13
13
  renditionId: (_request$renditionId = request.renditionId) !== null && _request$renditionId !== void 0 ? _request$renditionId : "",
14
14
  contentType: request.sbId === "sb:audio" ? "audio" : "video",
@@ -16,7 +16,7 @@ function metaFor(request) {
16
16
  start: (_request$segmentStart = request.segmentStart) !== null && _request$segmentStart !== void 0 ? _request$segmentStart : 0,
17
17
  duration: (_request$segmentDurat = request.segmentDuration) !== null && _request$segmentDurat !== void 0 ? _request$segmentDurat : 0,
18
18
  isInit: request.seq < 0
19
- };
19
+ }, request.epoch === void 0 ? {} : { epoch: request.epoch });
20
20
  }
21
21
  /** The bytes as one ArrayBuffer, copied only when the view does not cover its buffer. */
22
22
  function toArrayBuffer(data) {
@@ -14,6 +14,8 @@ const _excluded2 = ["repeat"];
14
14
  const _excluded3 = ["appended"];
15
15
  const _excluded4 = ["initFor"];
16
16
  const _excluded5 = ["serverThroughput"];
17
+ const _excluded6 = ["start"];
18
+ const _excluded7 = ["start"];
17
19
  /**
18
20
  * The default tuning. Every value is overridable through the `config`
19
21
  * parameters of `initialState` and `createReducer`; these are starting
@@ -354,7 +356,12 @@ function reduceCommand(state, msg, cfg, hooks) {
354
356
  }),
355
357
  quality: _objectSpread2(_objectSpread2({}, state.quality), {}, { constraints: new Map(seed.constraints) })
356
358
  });
357
- return [_objectSpread2(_objectSpread2({}, seeded), {}, {
359
+ const start = msg.start;
360
+ const placed = start === void 0 || !Number.isFinite(start) ? seeded : _objectSpread2(_objectSpread2({}, seeded), {}, { playback: _objectSpread2(_objectSpread2({}, seeded.playback), {}, {
361
+ currentTime: Math.max(0, start),
362
+ start
363
+ }) });
364
+ return [_objectSpread2(_objectSpread2({}, placed), {}, {
358
365
  lifecycle: { phase: "loading" },
359
366
  scheduling: _objectSpread2(_objectSpread2({}, state.scheduling), {}, {
360
367
  inflight,
@@ -697,6 +704,11 @@ function loadPresentation(state, merged, undecodableIds = /* @__PURE__ */ new Se
697
704
  event: "tracks:changed",
698
705
  payload: { available }
699
706
  }];
707
+ manifestEffects.push({
708
+ kind: "emit",
709
+ event: "presentation:changed",
710
+ payload: { id: presentation.id }
711
+ });
700
712
  const schemes = presentation.periods.flatMap((period) => period.tracks.flatMap((track) => {
701
713
  var _track$protection$sch, _track$protection;
702
714
  return (_track$protection$sch = (_track$protection = track.protection) === null || _track$protection === void 0 ? void 0 : _track$protection.schemes) !== null && _track$protection$sch !== void 0 ? _track$protection$sch : [];
@@ -710,6 +722,17 @@ function loadPresentation(state, merged, undecodableIds = /* @__PURE__ */ new Se
710
722
  kind: "setDuration",
711
723
  seconds: presentation.duration
712
724
  });
725
+ const start = loaded.playback.start;
726
+ if (start !== void 0 && !presentation.isLive) {
727
+ var _presentation$duratio;
728
+ const to = Math.max(0, Math.min(start, (_presentation$duratio = presentation.duration) !== null && _presentation$duratio !== void 0 ? _presentation$duratio : start));
729
+ const _loaded$playback = loaded.playback, { start: _ } = _loaded$playback, rest = _objectWithoutProperties(_loaded$playback, _excluded6);
730
+ manifestEffects.push({
731
+ kind: "seekElement",
732
+ to
733
+ });
734
+ return [_objectSpread2(_objectSpread2({}, loaded), {}, { playback: _objectSpread2(_objectSpread2({}, rest), {}, { currentTime: to }) }), manifestEffects];
735
+ }
713
736
  return [loaded, manifestEffects];
714
737
  }
715
738
  function reduceFact(state, msg, cfg, hooks) {
@@ -1075,10 +1098,13 @@ function reduceFact(state, msg, cfg, hooks) {
1075
1098
  end: boundary
1076
1099
  }]];
1077
1100
  }
1078
- case "TIME_UPDATE": return driveScheduling(_objectSpread2(_objectSpread2({}, state), {}, { playback: _objectSpread2(_objectSpread2({}, state.playback), {}, {
1079
- currentTime: msg.currentTime,
1080
- buffered: msg.buffered
1081
- }) }), hooks, cfg);
1101
+ case "TIME_UPDATE": {
1102
+ const currentTime = state.playback.start !== void 0 ? state.playback.currentTime : msg.currentTime;
1103
+ return driveScheduling(_objectSpread2(_objectSpread2({}, state), {}, { playback: _objectSpread2(_objectSpread2({}, state.playback), {}, {
1104
+ currentTime,
1105
+ buffered: msg.buffered
1106
+ }) }), hooks, cfg);
1107
+ }
1082
1108
  case "SEEKING": {
1083
1109
  const phase = state.lifecycle.phase === "ended" ? "ready" : state.lifecycle.phase;
1084
1110
  return [_objectSpread2(_objectSpread2({}, state), {}, {
@@ -1130,7 +1156,7 @@ function reduceFact(state, msg, cfg, hooks) {
1130
1156
  start: msg.start,
1131
1157
  end: msg.end
1132
1158
  });
1133
- if (firstWindow && msg.edge > state.playback.currentTime + 1) {
1159
+ if (firstWindow && state.playback.start === void 0 && msg.edge > state.playback.currentTime + 1) {
1134
1160
  const to = edgeStart(msg.start, msg.edge);
1135
1161
  const [scheduled, effects] = driveScheduling(_objectSpread2(_objectSpread2({}, withLive), {}, { playback: _objectSpread2(_objectSpread2({}, withLive.playback), {}, { currentTime: to }) }), hooks, cfg);
1136
1162
  return [scheduled, [
@@ -1142,6 +1168,20 @@ function reduceFact(state, msg, cfg, hooks) {
1142
1168
  ...effects
1143
1169
  ]];
1144
1170
  }
1171
+ const start = state.playback.start;
1172
+ if (firstWindow && start !== void 0) {
1173
+ const to = start >= msg.start && start <= msg.edge ? start : edgeStart(msg.start, msg.edge);
1174
+ const _withLive$playback = withLive.playback, { start: _ } = _withLive$playback, rest = _objectWithoutProperties(_withLive$playback, _excluded7);
1175
+ const [scheduled, effects] = driveScheduling(_objectSpread2(_objectSpread2({}, withLive), {}, { playback: _objectSpread2(_objectSpread2({}, rest), {}, { currentTime: to }) }), hooks, cfg);
1176
+ return [scheduled, [
1177
+ ...spanEffects,
1178
+ {
1179
+ kind: "seekElement",
1180
+ to
1181
+ },
1182
+ ...effects
1183
+ ]];
1184
+ }
1145
1185
  const [scheduled, effects] = driveScheduling(withLive, hooks, cfg);
1146
1186
  return [scheduled, [...spanEffects, ...effects]];
1147
1187
  }
@@ -45,6 +45,19 @@ function numberAttr(element, name) {
45
45
  const parsed = Number(value);
46
46
  return Number.isFinite(parsed) ? parsed : null;
47
47
  }
48
+ /** An element's children by local name, with their attributes, for a body a scheme defines in XML. */
49
+ function elementsOf(parent) {
50
+ const out = [];
51
+ for (const child of parent.children) {
52
+ const attributes = {};
53
+ for (const attribute of child.attributes) attributes[attribute.localName] = attribute.value;
54
+ out.push({
55
+ name: child.localName,
56
+ attributes
57
+ });
58
+ }
59
+ return out;
60
+ }
48
61
  /** @frameRate is "30" or "30000/1001". */
49
62
  function parseFrameRate(value) {
50
63
  if (value === null) return null;
@@ -153,16 +166,18 @@ function eventsOf(periodElement, periodStart) {
153
166
  const value = attr(stream, "value");
154
167
  const timescale = (_numberAttr = numberAttr(stream, "timescale")) !== null && _numberAttr !== void 0 ? _numberAttr : 1;
155
168
  const offset = (_numberAttr2 = numberAttr(stream, "presentationTimeOffset")) !== null && _numberAttr2 !== void 0 ? _numberAttr2 : 0;
169
+ const streamElements = elementsOf(stream).filter((element) => element.name !== "Event");
156
170
  let index = 0;
157
171
  for (const event of children(stream, "Event")) {
158
172
  var _numberAttr3, _ref, _attr6, _event$textContent, _attr7;
159
173
  const time = (_numberAttr3 = numberAttr(event, "presentationTime")) !== null && _numberAttr3 !== void 0 ? _numberAttr3 : 0;
160
174
  const duration = numberAttr(event, "duration");
161
175
  const data = (_ref = (_attr6 = attr(event, "messageData")) !== null && _attr6 !== void 0 ? _attr6 : (_event$textContent = event.textContent) === null || _event$textContent === void 0 ? void 0 : _event$textContent.trim()) !== null && _ref !== void 0 ? _ref : "";
162
- out.push(_objectSpread2(_objectSpread2(_objectSpread2({ scheme }, value !== null ? { value } : {}), {}, {
176
+ const elements = elementsOf(event);
177
+ out.push(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({ scheme }, value !== null ? { value } : {}), {}, {
163
178
  id: (_attr7 = attr(event, "id")) !== null && _attr7 !== void 0 ? _attr7 : `${scheme}:${index}`,
164
179
  start: periodStart + (time - offset) / timescale
165
- }, duration !== null ? { duration: duration / timescale } : {}), data !== "" ? { data } : {}));
180
+ }, duration !== null ? { duration: duration / timescale } : {}), data !== "" ? { data } : {}), {}, { timescale }, elements.length > 0 ? { elements } : {}), streamElements.length > 0 ? { streamElements } : {}));
166
181
  index += 1;
167
182
  }
168
183
  }
@@ -1,5 +1,5 @@
1
1
  import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/objectSpread2.js";
2
- import { byteToHex } from "../../kernel/base64.js";
2
+ import { base64ToBytes, byteToHex, bytesToHex } from "../../kernel/base64.js";
3
3
  import { resolveUrl } from "../../kernel/url.js";
4
4
  import { manifestError } from "../adapter-shared.js";
5
5
  import { dimensions } from "../dimensions.js";
@@ -58,6 +58,33 @@ function dateRangesFrom(tags, anchor) {
58
58
  }
59
59
  return out.sort((a, b) => a.start - b.start);
60
60
  }
61
+ /**
62
+ * The seconds of an `EXT-X-CUE-OUT`, written `30`, `30.0` or `DURATION=30`.
63
+ * The tag is not in RFC 8216; packagers write it in these forms.
64
+ */
65
+ function cueOutDuration(value) {
66
+ const match = /(?:DURATION=)?([0-9.]+)/.exec(value);
67
+ const seconds = match === null ? NaN : Number(match[1]);
68
+ return Number.isFinite(seconds) && seconds > 0 ? seconds : void 0;
69
+ }
70
+ /**
71
+ * A cue-out as a date range: from its segment to the cue-in's segment, or
72
+ * for its duration while no cue-in has come. Its attributes say what the
73
+ * tags said: `CUE-OUT` the duration, `SCTE35-OUT` the section as a
74
+ * hexadecimal sequence, the form a date range carries it in.
75
+ */
76
+ function cueRange(cue, end, anchor) {
77
+ const bytes = cue.splice === void 0 ? null : base64ToBytes(cue.splice.trim());
78
+ const attributes = _objectSpread2({ "CUE-OUT": cue.duration === void 0 ? "" : String(cue.duration) }, bytes !== null ? { "SCTE35-OUT": `0x${bytesToHex(bytes)}` } : {});
79
+ const closes = end !== null && end !== void 0 ? end : cue.duration !== void 0 ? cue.start + cue.duration : void 0;
80
+ return _objectSpread2(_objectSpread2(_objectSpread2({
81
+ id: cue.id,
82
+ start: cue.start
83
+ }, closes !== void 0 ? { end: closes } : {}), cue.duration !== void 0 ? { plannedEnd: cue.start + cue.duration } : {}), {}, {
84
+ startDate: anchor === void 0 ? NaN : anchor.wallClock + (cue.start - anchor.presentationTime),
85
+ attributes
86
+ });
87
+ }
61
88
  /** n@o or n (continuing after the previous range). RFC 8216 §4.3.2.2. */
62
89
  function parseByteRange(value, previousEnd) {
63
90
  const [lengthText, offsetText] = value.split("@");
@@ -189,6 +216,11 @@ function parseMediaLines(lines, baseUrl) {
189
216
  let serverControl = null;
190
217
  let skipped = 0;
191
218
  let removedDateRanges = [];
219
+ let pendingCueOut = null;
220
+ let pendingCueIn = false;
221
+ let pendingSplice = null;
222
+ let openCue = null;
223
+ const cueRanges = [];
192
224
  for (const line of lines) {
193
225
  if (line.kind === "tag") {
194
226
  switch (line.name) {
@@ -219,6 +251,17 @@ function parseMediaLines(lines, baseUrl) {
219
251
  case "EXT-X-DATERANGE":
220
252
  dateRangeTags.push(line.attributes);
221
253
  break;
254
+ case "EXT-X-CUE-OUT": {
255
+ const duration = cueOutDuration(line.value);
256
+ pendingCueOut = duration === void 0 ? {} : { duration };
257
+ break;
258
+ }
259
+ case "EXT-X-CUE-IN":
260
+ pendingCueIn = true;
261
+ break;
262
+ case "EXT-OATCLS-SCTE35":
263
+ pendingSplice = line.value;
264
+ break;
222
265
  case "EXT-X-DISCONTINUITY-SEQUENCE":
223
266
  discontinuitySequence = Number(line.value) || 0;
224
267
  break;
@@ -264,6 +307,17 @@ function parseMediaLines(lines, baseUrl) {
264
307
  presentationTime: start
265
308
  };
266
309
  pendingDate = null;
310
+ if ((pendingCueIn || pendingCueOut !== null) && openCue !== null) {
311
+ cueRanges.push(cueRange(openCue, start, dateAnchor));
312
+ openCue = null;
313
+ }
314
+ if (pendingCueOut !== null) openCue = _objectSpread2(_objectSpread2({
315
+ id: `cue-out-${seq}`,
316
+ start
317
+ }, pendingCueOut.duration !== void 0 ? { duration: pendingCueOut.duration } : {}), pendingSplice !== null ? { splice: pendingSplice } : {});
318
+ pendingCueOut = null;
319
+ pendingCueIn = false;
320
+ pendingSplice = null;
267
321
  if (pendingDiscontinuity) discontinuitySequence += 1;
268
322
  const opensEpoch = segments.length === 0 || pendingDiscontinuity;
269
323
  segments.push(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
@@ -279,6 +333,8 @@ function parseMediaLines(lines, baseUrl) {
279
333
  pendingRange = null;
280
334
  pendingDiscontinuity = false;
281
335
  }
336
+ if (openCue !== null) cueRanges.push(cueRange(openCue, null, dateAnchor));
337
+ const dateRanges = [...dateRangeTags.length > 0 ? dateRangesFrom(dateRangeTags, dateAnchor) : [], ...cueRanges].sort((a, b) => a.start - b.start);
282
338
  return {
283
339
  playlist: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
284
340
  segments,
@@ -288,7 +344,7 @@ function parseMediaLines(lines, baseUrl) {
288
344
  endlist,
289
345
  playlistType,
290
346
  protection
291
- }, dateAnchor !== void 0 ? { dateAnchor } : {}), tiles !== null ? { tiles } : {}), dateRangeTags.length > 0 ? { dateRanges: dateRangesFrom(dateRangeTags, dateAnchor) } : {}), serverControl !== null ? { serverControl } : {}), Number(serverControl === null || serverControl === void 0 ? void 0 : serverControl["HOLD-BACK"]) > 0 ? { holdBack: Number(serverControl === null || serverControl === void 0 ? void 0 : serverControl["HOLD-BACK"]) } : {}), skipped > 0 ? { skipped } : {}), removedDateRanges.length > 0 ? { removedDateRanges } : {}),
347
+ }, dateAnchor !== void 0 ? { dateAnchor } : {}), tiles !== null ? { tiles } : {}), dateRangeTags.length > 0 || cueRanges.length > 0 ? { dateRanges } : {}), serverControl !== null ? { serverControl } : {}), Number(serverControl === null || serverControl === void 0 ? void 0 : serverControl["HOLD-BACK"]) > 0 ? { holdBack: Number(serverControl === null || serverControl === void 0 ? void 0 : serverControl["HOLD-BACK"]) } : {}), skipped > 0 ? { skipped } : {}), removedDateRanges.length > 0 ? { removedDateRanges } : {}),
292
348
  error: null
293
349
  };
294
350
  }