mattebox 0.13.0 → 0.15.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 (247) hide show
  1. package/README.md +29 -21
  2. package/dist/cdn/mattebox.dash-drm.min.js +3 -3
  3. package/dist/cdn/mattebox.dash-ll.min.js +3 -0
  4. package/dist/cdn/mattebox.dash.min.js +3 -3
  5. package/dist/cdn/mattebox.dual-drm.min.js +3 -3
  6. package/dist/cdn/mattebox.dual-ll.min.js +3 -0
  7. package/dist/cdn/mattebox.dual-ts-drm.min.js +3 -3
  8. package/dist/cdn/mattebox.dual-ts.min.js +3 -3
  9. package/dist/cdn/mattebox.dual.min.js +3 -3
  10. package/dist/cdn/mattebox.hls-drm.min.js +3 -3
  11. package/dist/cdn/mattebox.hls-ll.min.js +3 -0
  12. package/dist/cdn/mattebox.hls-ts-drm.min.js +3 -3
  13. package/dist/cdn/mattebox.hls-ts.min.js +3 -3
  14. package/dist/cdn/mattebox.hls.min.js +3 -3
  15. package/dist/cdn/mattebox.kernel.min.js +1 -1
  16. package/dist/cdn/mattebox.min.js +5 -5
  17. package/dist/containers/fmp4/writer.d.ts +7 -1
  18. package/dist/containers/fmp4/writer.d.ts.map +1 -1
  19. package/dist/containers/fmp4/writer.js +2 -1
  20. package/dist/containers/fmp4/writer.js.map +1 -1
  21. package/dist/containers/mp4-box/index.d.ts +8 -0
  22. package/dist/containers/mp4-box/index.d.ts.map +1 -1
  23. package/dist/containers/mp4-box/index.js +27 -0
  24. package/dist/containers/mp4-box/index.js.map +1 -1
  25. package/dist/containers/ts-transmux/demux.d.ts +2 -0
  26. package/dist/containers/ts-transmux/demux.d.ts.map +1 -1
  27. package/dist/containers/ts-transmux/demux.js +3 -1
  28. package/dist/containers/ts-transmux/demux.js.map +1 -1
  29. package/dist/containers/ts-transmux/h265.d.ts +51 -0
  30. package/dist/containers/ts-transmux/h265.d.ts.map +1 -0
  31. package/dist/containers/ts-transmux/h265.js +182 -0
  32. package/dist/containers/ts-transmux/h265.js.map +1 -0
  33. package/dist/containers/ts-transmux/transmux.d.ts +3 -2
  34. package/dist/containers/ts-transmux/transmux.d.ts.map +1 -1
  35. package/dist/containers/ts-transmux/transmux.js +35 -11
  36. package/dist/containers/ts-transmux/transmux.js.map +1 -1
  37. package/dist/eme/index.d.ts +1 -10
  38. package/dist/eme/index.d.ts.map +1 -1
  39. package/dist/eme/index.js +4 -2
  40. package/dist/eme/index.js.map +1 -1
  41. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/asyncToGenerator.js +1 -1
  42. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/defineProperty.js +1 -1
  43. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/objectSpread2.js +1 -1
  44. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/objectWithoutProperties.js +1 -1
  45. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/objectWithoutPropertiesLoose.js +1 -1
  46. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPrimitive.js +1 -1
  47. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPropertyKey.js +1 -1
  48. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/typeof.js +1 -1
  49. package/dist/es2015/containers/fmp4/writer.js +2 -1
  50. package/dist/es2015/containers/id3.js +1 -1
  51. package/dist/es2015/containers/mp4-box/index.js +24 -1
  52. package/dist/es2015/containers/scte35.js +1 -1
  53. package/dist/es2015/containers/ts-transmux/demux.js +3 -1
  54. package/dist/es2015/containers/ts-transmux/h264.js +1 -1
  55. package/dist/es2015/containers/ts-transmux/h265.js +175 -0
  56. package/dist/es2015/containers/ts-transmux/index.js +1 -1
  57. package/dist/es2015/containers/ts-transmux/runner.js +2 -2
  58. package/dist/es2015/containers/ts-transmux/transmux.js +39 -16
  59. package/dist/es2015/containers/webvtt.js +1 -1
  60. package/dist/es2015/containers/wvtt.js +1 -1
  61. package/dist/es2015/eme/index.js +7 -5
  62. package/dist/es2015/index.js +42 -6
  63. package/dist/es2015/kernel/append-queue.js +1 -1
  64. package/dist/es2015/kernel/context.js +7 -0
  65. package/dist/es2015/kernel/dry-run.js +179 -0
  66. package/dist/es2015/kernel/lifecycle.js +6 -2
  67. package/dist/es2015/kernel/mse.js +1 -1
  68. package/dist/es2015/kernel/prepare.js +3 -3
  69. package/dist/es2015/kernel/reducer.js +105 -33
  70. package/dist/es2015/kernel/refresh.js +2 -2
  71. package/dist/es2015/kernel/rendition-select.js +2 -2
  72. package/dist/es2015/kernel/scheduler.js +31 -6
  73. package/dist/es2015/kernel/timeline.js +1 -1
  74. package/dist/es2015/kernel/trace.js +1 -1
  75. package/dist/es2015/kernel/transport.js +235 -49
  76. package/dist/es2015/presets/dash-ll/index.js +15 -0
  77. package/dist/es2015/presets/define.js +2 -2
  78. package/dist/es2015/presets/dual-ll/index.js +16 -0
  79. package/dist/es2015/presets/full/index.js +8 -8
  80. package/dist/es2015/presets/hls-ll/index.js +14 -0
  81. package/dist/es2015/presets/tiers.js +29 -5
  82. package/dist/es2015/protocols/dash-cmaf/index.js +13 -8
  83. package/dist/es2015/protocols/dash-cmaf/parse.js +129 -41
  84. package/dist/es2015/protocols/dash-cmaf/periods-runtime.js +1 -1
  85. package/dist/es2015/protocols/dash-cmaf/periods.js +1 -1
  86. package/dist/es2015/protocols/dash-live/index.js +75 -21
  87. package/dist/es2015/protocols/dash-ll/index.js +42 -0
  88. package/dist/es2015/protocols/hls-cmaf/index.js +5 -5
  89. package/dist/es2015/protocols/hls-cmaf/lexer.js +7 -1
  90. package/dist/es2015/protocols/hls-cmaf/parse.js +27 -12
  91. package/dist/es2015/protocols/hls-cmaf/unavailable.js +1 -1
  92. package/dist/es2015/protocols/hls-live/index.js +92 -18
  93. package/dist/es2015/protocols/hls-ll/index.js +30 -0
  94. package/dist/es2015/protocols/hls-ll/parse.js +240 -0
  95. package/dist/es2015/stages/abr/index.js +9 -2
  96. package/dist/es2015/stages/aes-128/index.js +1 -1
  97. package/dist/es2015/stages/chapters/index.js +2 -2
  98. package/dist/es2015/stages/chapters/parse.js +2 -2
  99. package/dist/es2015/stages/cmcd/index.js +7 -1
  100. package/dist/es2015/stages/codec-probe/index.js +1 -1
  101. package/dist/es2015/stages/content-steering/index.js +1 -1
  102. package/dist/es2015/stages/eme-core/index.js +193 -42
  103. package/dist/es2015/stages/eme-fairplay/index.js +1 -1
  104. package/dist/es2015/stages/hdr/index.js +1 -1
  105. package/dist/es2015/stages/live-catchup/index.js +221 -0
  106. package/dist/es2015/stages/qoe/index.js +1 -1
  107. package/dist/es2015/stages/recovery/index.js +2 -2
  108. package/dist/es2015/stages/rendition-names/index.js +1 -1
  109. package/dist/es2015/stages/text-cea608/decode.js +1 -1
  110. package/dist/es2015/stages/text-cea708/decode.js +2 -2
  111. package/dist/es2015/stages/text-cea708/index.js +1 -1
  112. package/dist/es2015/stages/text-ttml/images.js +60 -0
  113. package/dist/es2015/stages/text-ttml/index.js +22 -6
  114. package/dist/es2015/stages/text-ttml/parse.js +71 -5
  115. package/dist/es2015/stages/thumbnails/index.js +1 -1
  116. package/dist/es2015/stages/timed-metadata/index.js +1 -1
  117. package/dist/es2015/stages/trick-play/index.js +1 -1
  118. package/dist/index.d.ts.map +1 -1
  119. package/dist/index.js +28 -1
  120. package/dist/index.js.map +1 -1
  121. package/dist/kernel/context.d.ts +4 -6
  122. package/dist/kernel/context.d.ts.map +1 -1
  123. package/dist/kernel/context.js +10 -0
  124. package/dist/kernel/context.js.map +1 -1
  125. package/dist/kernel/dry-run.d.ts +27 -0
  126. package/dist/kernel/dry-run.d.ts.map +1 -0
  127. package/dist/kernel/dry-run.js +198 -0
  128. package/dist/kernel/dry-run.js.map +1 -0
  129. package/dist/kernel/lifecycle.d.ts +5 -7
  130. package/dist/kernel/lifecycle.d.ts.map +1 -1
  131. package/dist/kernel/lifecycle.js +4 -0
  132. package/dist/kernel/lifecycle.js.map +1 -1
  133. package/dist/kernel/prepare.d.ts +3 -0
  134. package/dist/kernel/prepare.d.ts.map +1 -1
  135. package/dist/kernel/prepare.js +2 -1
  136. package/dist/kernel/prepare.js.map +1 -1
  137. package/dist/kernel/reducer.d.ts.map +1 -1
  138. package/dist/kernel/reducer.js +117 -42
  139. package/dist/kernel/reducer.js.map +1 -1
  140. package/dist/kernel/refresh.d.ts.map +1 -1
  141. package/dist/kernel/refresh.js +2 -0
  142. package/dist/kernel/refresh.js.map +1 -1
  143. package/dist/kernel/scheduler.d.ts.map +1 -1
  144. package/dist/kernel/scheduler.js +40 -3
  145. package/dist/kernel/scheduler.js.map +1 -1
  146. package/dist/kernel/transport.d.ts +68 -10
  147. package/dist/kernel/transport.d.ts.map +1 -1
  148. package/dist/kernel/transport.js +232 -37
  149. package/dist/kernel/transport.js.map +1 -1
  150. package/dist/presets/dash-ll/index.d.ts +4 -0
  151. package/dist/presets/dash-ll/index.d.ts.map +1 -0
  152. package/dist/presets/dash-ll/index.js +10 -0
  153. package/dist/presets/dash-ll/index.js.map +1 -0
  154. package/dist/presets/dual-ll/index.d.ts +4 -0
  155. package/dist/presets/dual-ll/index.d.ts.map +1 -0
  156. package/dist/presets/dual-ll/index.js +15 -0
  157. package/dist/presets/dual-ll/index.js.map +1 -0
  158. package/dist/presets/full/index.js +8 -8
  159. package/dist/presets/full/index.js.map +1 -1
  160. package/dist/presets/hls-ll/index.d.ts +4 -0
  161. package/dist/presets/hls-ll/index.d.ts.map +1 -0
  162. package/dist/presets/hls-ll/index.js +9 -0
  163. package/dist/presets/hls-ll/index.js.map +1 -0
  164. package/dist/presets/tiers.d.ts +17 -2
  165. package/dist/presets/tiers.d.ts.map +1 -1
  166. package/dist/presets/tiers.js +26 -2
  167. package/dist/presets/tiers.js.map +1 -1
  168. package/dist/protocols/dash-cmaf/index.d.ts +29 -1
  169. package/dist/protocols/dash-cmaf/index.d.ts.map +1 -1
  170. package/dist/protocols/dash-cmaf/index.js +9 -4
  171. package/dist/protocols/dash-cmaf/index.js.map +1 -1
  172. package/dist/protocols/dash-cmaf/parse.d.ts +8 -2
  173. package/dist/protocols/dash-cmaf/parse.d.ts.map +1 -1
  174. package/dist/protocols/dash-cmaf/parse.js +121 -14
  175. package/dist/protocols/dash-cmaf/parse.js.map +1 -1
  176. package/dist/protocols/dash-live/index.d.ts +22 -0
  177. package/dist/protocols/dash-live/index.d.ts.map +1 -1
  178. package/dist/protocols/dash-live/index.js +77 -18
  179. package/dist/protocols/dash-live/index.js.map +1 -1
  180. package/dist/protocols/dash-ll/index.d.ts +27 -0
  181. package/dist/protocols/dash-ll/index.d.ts.map +1 -0
  182. package/dist/protocols/dash-ll/index.js +35 -0
  183. package/dist/protocols/dash-ll/index.js.map +1 -0
  184. package/dist/protocols/hls-cmaf/index.d.ts +23 -0
  185. package/dist/protocols/hls-cmaf/index.d.ts.map +1 -1
  186. package/dist/protocols/hls-cmaf/index.js +4 -4
  187. package/dist/protocols/hls-cmaf/index.js.map +1 -1
  188. package/dist/protocols/hls-cmaf/lexer.d.ts.map +1 -1
  189. package/dist/protocols/hls-cmaf/lexer.js +7 -0
  190. package/dist/protocols/hls-cmaf/lexer.js.map +1 -1
  191. package/dist/protocols/hls-cmaf/parse.d.ts +28 -2
  192. package/dist/protocols/hls-cmaf/parse.d.ts.map +1 -1
  193. package/dist/protocols/hls-cmaf/parse.js +42 -6
  194. package/dist/protocols/hls-cmaf/parse.js.map +1 -1
  195. package/dist/protocols/hls-live/index.d.ts +65 -0
  196. package/dist/protocols/hls-live/index.d.ts.map +1 -1
  197. package/dist/protocols/hls-live/index.js +115 -16
  198. package/dist/protocols/hls-live/index.js.map +1 -1
  199. package/dist/protocols/hls-ll/index.d.ts +22 -0
  200. package/dist/protocols/hls-ll/index.d.ts.map +1 -0
  201. package/dist/protocols/hls-ll/index.js +32 -0
  202. package/dist/protocols/hls-ll/index.js.map +1 -0
  203. package/dist/protocols/hls-ll/parse.d.ts +45 -0
  204. package/dist/protocols/hls-ll/parse.d.ts.map +1 -0
  205. package/dist/protocols/hls-ll/parse.js +300 -0
  206. package/dist/protocols/hls-ll/parse.js.map +1 -0
  207. package/dist/stages/abr/index.d.ts.map +1 -1
  208. package/dist/stages/abr/index.js +6 -6
  209. package/dist/stages/abr/index.js.map +1 -1
  210. package/dist/stages/cmcd/index.d.ts.map +1 -1
  211. package/dist/stages/cmcd/index.js +12 -3
  212. package/dist/stages/cmcd/index.js.map +1 -1
  213. package/dist/stages/eme-core/index.d.ts +67 -2
  214. package/dist/stages/eme-core/index.d.ts.map +1 -1
  215. package/dist/stages/eme-core/index.js +191 -40
  216. package/dist/stages/eme-core/index.js.map +1 -1
  217. package/dist/stages/live-catchup/index.d.ts +42 -0
  218. package/dist/stages/live-catchup/index.d.ts.map +1 -0
  219. package/dist/stages/live-catchup/index.js +217 -0
  220. package/dist/stages/live-catchup/index.js.map +1 -0
  221. package/dist/stages/recovery/index.d.ts.map +1 -1
  222. package/dist/stages/recovery/index.js +6 -2
  223. package/dist/stages/recovery/index.js.map +1 -1
  224. package/dist/stages/text-ttml/images.d.ts +10 -0
  225. package/dist/stages/text-ttml/images.d.ts.map +1 -0
  226. package/dist/stages/text-ttml/images.js +71 -0
  227. package/dist/stages/text-ttml/images.js.map +1 -0
  228. package/dist/stages/text-ttml/index.d.ts +13 -0
  229. package/dist/stages/text-ttml/index.d.ts.map +1 -1
  230. package/dist/stages/text-ttml/index.js +26 -6
  231. package/dist/stages/text-ttml/index.js.map +1 -1
  232. package/dist/stages/text-ttml/parse.d.ts +5 -2
  233. package/dist/stages/text-ttml/parse.d.ts.map +1 -1
  234. package/dist/stages/text-ttml/parse.js +74 -2
  235. package/dist/stages/text-ttml/parse.js.map +1 -1
  236. package/dist/types/facade.d.ts +15 -3
  237. package/dist/types/facade.d.ts.map +1 -1
  238. package/dist/types/ir.d.ts +36 -0
  239. package/dist/types/ir.d.ts.map +1 -1
  240. package/dist/types/kernel.d.ts +4 -0
  241. package/dist/types/kernel.d.ts.map +1 -1
  242. package/dist/types/kernel.js.map +1 -1
  243. package/dist/types/messages.d.ts +55 -0
  244. package/dist/types/messages.d.ts.map +1 -1
  245. package/dist/types/stage.d.ts +24 -5
  246. package/dist/types/stage.d.ts.map +1 -1
  247. package/package.json +4 -2
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/objectSpread2.js";
2
2
  import { findBox, parseSidx } from "../../containers/mp4-box/index.js";
3
3
  import { base64ToBytes } from "../../kernel/base64.js";
4
4
  import { resolveUrl } from "../../kernel/url.js";
@@ -351,6 +351,10 @@ function tileGridOf(representation, adaptationSet, width, height) {
351
351
  }
352
352
  return null;
353
353
  }
354
+ /** @availabilityTimeOffset in seconds; `INF` is Infinity: every segment that has started. */
355
+ function availabilityOffsetOf(element) {
356
+ return attr(element, "availabilityTimeOffset") === "INF" ? Number.POSITIVE_INFINITY : numberAttr(element, "availabilityTimeOffset");
357
+ }
354
358
  /** Merges SegmentTemplate attributes down Period, AdaptationSet, Representation. */
355
359
  function mergeTemplates(levels) {
356
360
  var _timescale, _startNumber, _pto;
@@ -361,9 +365,11 @@ function mergeTemplates(levels) {
361
365
  let duration = null;
362
366
  let pto = null;
363
367
  let timelineElement = null;
368
+ let ato = null;
369
+ let complete = null;
364
370
  let found = false;
365
371
  for (const level of levels) {
366
- var _attr14, _attr15, _numberAttr4, _numberAttr5, _numberAttr6, _numberAttr7, _children$2;
372
+ var _attr14, _attr15, _numberAttr4, _numberAttr5, _numberAttr6, _numberAttr7, _children$2, _availabilityOffsetOf, _attr16;
367
373
  const template = children(level, "SegmentTemplate")[0];
368
374
  if (template === void 0) continue;
369
375
  found = true;
@@ -374,6 +380,8 @@ function mergeTemplates(levels) {
374
380
  duration = (_numberAttr6 = numberAttr(template, "duration")) !== null && _numberAttr6 !== void 0 ? _numberAttr6 : duration;
375
381
  pto = (_numberAttr7 = numberAttr(template, "presentationTimeOffset")) !== null && _numberAttr7 !== void 0 ? _numberAttr7 : pto;
376
382
  timelineElement = (_children$2 = children(template, "SegmentTimeline")[0]) !== null && _children$2 !== void 0 ? _children$2 : timelineElement;
383
+ ato = (_availabilityOffsetOf = availabilityOffsetOf(template)) !== null && _availabilityOffsetOf !== void 0 ? _availabilityOffsetOf : ato;
384
+ complete = (_attr16 = attr(template, "availabilityTimeComplete")) !== null && _attr16 !== void 0 ? _attr16 : complete;
377
385
  }
378
386
  if (!found) return null;
379
387
  return {
@@ -383,7 +391,9 @@ function mergeTemplates(levels) {
383
391
  startNumber: (_startNumber = startNumber) !== null && _startNumber !== void 0 ? _startNumber : 1,
384
392
  duration,
385
393
  presentationTimeOffset: (_pto = pto) !== null && _pto !== void 0 ? _pto : 0,
386
- timelineElement
394
+ timelineElement,
395
+ availabilityOffset: ato,
396
+ availabilityComplete: complete
387
397
  };
388
398
  }
389
399
  /**
@@ -398,7 +408,7 @@ function mergeTemplates(levels) {
398
408
  * level has a SegmentList.
399
409
  */
400
410
  function segmentListOf(levels, base, periodStart, periodEndUnits) {
401
- var _attr17;
411
+ var _attr18;
402
412
  let timescale = 1;
403
413
  let duration = null;
404
414
  let startNumber = 1;
@@ -431,20 +441,20 @@ function segmentListOf(levels, base, periodStart, periodEndUnits) {
431
441
  else if (urls.length > 1) return "invalid";
432
442
  const segments = [];
433
443
  urls.forEach((url, i) => {
434
- var _times$i, _attr16;
444
+ var _times$i, _attr17;
435
445
  const [time, length] = (_times$i = times[i]) !== null && _times$i !== void 0 ? _times$i : [offset, 0];
436
446
  const range = parseByteRange(attr(url, "mediaRange"));
437
447
  segments.push(_objectSpread2({
438
448
  seq: startNumber + i,
439
449
  start: periodStart + (time - offset) / timescale,
440
450
  duration: length / timescale,
441
- url: resolveUrl((_attr16 = attr(url, "media")) !== null && _attr16 !== void 0 ? _attr16 : "", base)
451
+ url: resolveUrl((_attr17 = attr(url, "media")) !== null && _attr17 !== void 0 ? _attr17 : "", base)
442
452
  }, range !== null ? { byteRange: range } : {}));
443
453
  });
444
454
  const initRange = initialization === null ? null : parseByteRange(attr(initialization, "range"));
445
455
  return {
446
456
  segments,
447
- init: initialization === null ? null : _objectSpread2({ url: resolveUrl((_attr17 = attr(initialization, "sourceURL")) !== null && _attr17 !== void 0 ? _attr17 : "", base) }, initRange !== null ? { byteRange: initRange } : {})
457
+ init: initialization === null ? null : _objectSpread2({ url: resolveUrl((_attr18 = attr(initialization, "sourceURL")) !== null && _attr18 !== void 0 ? _attr18 : "", base) }, initRange !== null ? { byteRange: initRange } : {})
448
458
  };
449
459
  }
450
460
  function parseTimeline(timelineElement, periodEndUnits) {
@@ -483,13 +493,13 @@ function substituteIdentity(template, id, bandwidth) {
483
493
  });
484
494
  }
485
495
  function contentTypeOf(adaptationSet, mimeType) {
486
- var _attr18, _children$5;
496
+ var _attr19, _children$5;
487
497
  const declared = attr(adaptationSet, "contentType");
488
498
  if (declared === "video" || declared === "audio" || declared === "text" || declared === "image" || declared === "metadata") return declared;
489
499
  if (mimeType.startsWith("audio/")) return "audio";
490
500
  if (mimeType.startsWith("image/")) return "image";
491
501
  if (mimeType.startsWith("text/") || mimeType === "application/ttml+xml") return "text";
492
- const codecs = (_attr18 = attr(adaptationSet, "codecs")) !== null && _attr18 !== void 0 ? _attr18 : attr((_children$5 = children(adaptationSet, "Representation")[0]) !== null && _children$5 !== void 0 ? _children$5 : adaptationSet, "codecs");
502
+ const codecs = (_attr19 = attr(adaptationSet, "codecs")) !== null && _attr19 !== void 0 ? _attr19 : attr((_children$5 = children(adaptationSet, "Representation")[0]) !== null && _children$5 !== void 0 ? _children$5 : adaptationSet, "codecs");
493
503
  if (mimeType === "application/mp4" && codecs !== null && /^(stpp|wvtt)/.test(codecs)) return "text";
494
504
  return "video";
495
505
  }
@@ -525,15 +535,15 @@ function periodSpans(elements, mpdDuration) {
525
535
  */
526
536
  function followsOf(adaptationSet) {
527
537
  return children(adaptationSet, "SupplementalProperty").filter((property) => {
528
- var _attr19;
529
- return /^urn:mpeg:dash:period-(continuity|connectivity):2015$/.test((_attr19 = attr(property, "schemeIdUri")) !== null && _attr19 !== void 0 ? _attr19 : "");
530
- }).flatMap((property) => {
531
538
  var _attr20;
532
- return ((_attr20 = attr(property, "value")) !== null && _attr20 !== void 0 ? _attr20 : "").split(/[\s,]+/).filter((v) => v !== "");
539
+ return /^urn:mpeg:dash:period-(continuity|connectivity):2015$/.test((_attr20 = attr(property, "schemeIdUri")) !== null && _attr20 !== void 0 ? _attr20 : "");
540
+ }).flatMap((property) => {
541
+ var _attr21;
542
+ return ((_attr21 = attr(property, "value")) !== null && _attr21 !== void 0 ? _attr21 : "").split(/[\s,]+/).filter((v) => v !== "");
533
543
  });
534
544
  }
535
- function parsePeriod(periodElement, span, index, mpdBase, isLive) {
536
- var _attr29;
545
+ function parsePeriod(periodElement, span, index, mpdBase, isLive, availability) {
546
+ var _attr30;
537
547
  const matching = /* @__PURE__ */ new Map();
538
548
  const periodStart = span.start;
539
549
  const periodDuration = span.duration;
@@ -555,17 +565,17 @@ function parsePeriod(periodElement, span, index, mpdBase, isLive) {
555
565
  const renditions = [];
556
566
  let trackMime = null;
557
567
  for (const representation of children(adaptationSet, "Representation")) {
558
- var _ref2, _attr21, _trackMime, _parseFrameRate2, _numberAttr15, _attr27, _attr28;
568
+ var _ref2, _attr22, _trackMime, _parseFrameRate2, _numberAttr15, _attr28, _attr29;
559
569
  const id = attr(representation, "id");
560
570
  const bandwidth = numberAttr(representation, "bandwidth");
561
571
  if (id === null || bandwidth === null) continue;
562
572
  const repBase = applyBaseUrl(representation, asBase);
563
- const mimeType = (_ref2 = (_attr21 = attr(representation, "mimeType")) !== null && _attr21 !== void 0 ? _attr21 : asMime) !== null && _ref2 !== void 0 ? _ref2 : "video/mp4";
573
+ const mimeType = (_ref2 = (_attr22 = attr(representation, "mimeType")) !== null && _attr22 !== void 0 ? _attr22 : asMime) !== null && _ref2 !== void 0 ? _ref2 : "video/mp4";
564
574
  if (/\/(webm|x-matroska)$/.test(mimeType)) continue;
565
575
  trackMime = (_trackMime = trackMime) !== null && _trackMime !== void 0 ? _trackMime : mimeType;
566
576
  const segmentBase = children(representation, "SegmentBase")[0];
567
577
  if (segmentBase !== void 0) {
568
- var _numberAttr14, _parseFrameRate, _attr22, _attr23;
578
+ var _numberAttr14, _parseFrameRate, _attr23, _attr24;
569
579
  const indexRange = parseByteRange(attr(segmentBase, "indexRange"));
570
580
  if (indexRange === null) continue;
571
581
  const baseTimescale = (_numberAttr14 = numberAttr(segmentBase, "timescale")) !== null && _numberAttr14 !== void 0 ? _numberAttr14 : 1;
@@ -588,10 +598,10 @@ function parsePeriod(periodElement, span, index, mpdBase, isLive) {
588
598
  renditions.push(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
589
599
  id,
590
600
  bitrate: bandwidth,
591
- codecs: (_attr22 = attr(representation, "codecs")) !== null && _attr22 !== void 0 ? _attr22 : asCodecs,
601
+ codecs: (_attr23 = attr(representation, "codecs")) !== null && _attr23 !== void 0 ? _attr23 : asCodecs,
592
602
  mimeType,
593
603
  segments: sidxSegments
594
- }, sidxInit !== null ? { init: sidxInit } : {}), w !== null ? { width: w } : {}), h !== null ? { height: h } : {}), fr !== null ? { frameRate: fr } : {}), videoRangeOf(representation, adaptationSet, (_attr23 = attr(representation, "codecs")) !== null && _attr23 !== void 0 ? _attr23 : asCodecs)), channelsOf(representation, adaptationSet)), supplementalOf(representation, adaptationSet)));
604
+ }, sidxInit !== null ? { init: sidxInit } : {}), w !== null ? { width: w } : {}), h !== null ? { height: h } : {}), fr !== null ? { frameRate: fr } : {}), videoRangeOf(representation, adaptationSet, (_attr24 = attr(representation, "codecs")) !== null && _attr24 !== void 0 ? _attr24 : asCodecs)), channelsOf(representation, adaptationSet)), supplementalOf(representation, adaptationSet)));
595
605
  continue;
596
606
  }
597
607
  const list = segmentListOf([
@@ -601,15 +611,15 @@ function parsePeriod(periodElement, span, index, mpdBase, isLive) {
601
611
  ], repBase, periodStart, (timescale, offset) => periodDuration !== null ? Math.round(offset + periodDuration * timescale) : null);
602
612
  if (list === "invalid") return { error: manifestError(`bad SegmentList in '${id}'`) };
603
613
  if (list !== null) {
604
- var _attr24, _attr25;
614
+ var _attr25, _attr26;
605
615
  const segments = list.segments.map((segment) => segment.duration === 0 && periodDuration !== null ? _objectSpread2(_objectSpread2({}, segment), {}, { duration: periodDuration }) : segment);
606
616
  renditions.push(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
607
617
  id,
608
618
  bitrate: bandwidth,
609
- codecs: (_attr24 = attr(representation, "codecs")) !== null && _attr24 !== void 0 ? _attr24 : asCodecs,
619
+ codecs: (_attr25 = attr(representation, "codecs")) !== null && _attr25 !== void 0 ? _attr25 : asCodecs,
610
620
  mimeType,
611
621
  segments
612
- }, list.init !== null ? { init: list.init } : {}), numberAttr(representation, "width") !== null ? { width: numberAttr(representation, "width") } : {}), numberAttr(representation, "height") !== null ? { height: numberAttr(representation, "height") } : {}), videoRangeOf(representation, adaptationSet, (_attr25 = attr(representation, "codecs")) !== null && _attr25 !== void 0 ? _attr25 : asCodecs)), channelsOf(representation, adaptationSet)), supplementalOf(representation, adaptationSet)));
622
+ }, list.init !== null ? { init: list.init } : {}), numberAttr(representation, "width") !== null ? { width: numberAttr(representation, "width") } : {}), numberAttr(representation, "height") !== null ? { height: numberAttr(representation, "height") } : {}), videoRangeOf(representation, adaptationSet, (_attr26 = attr(representation, "codecs")) !== null && _attr26 !== void 0 ? _attr26 : asCodecs)), channelsOf(representation, adaptationSet)), supplementalOf(representation, adaptationSet)));
613
623
  continue;
614
624
  }
615
625
  const template = mergeTemplates([
@@ -619,11 +629,11 @@ function parsePeriod(periodElement, span, index, mpdBase, isLive) {
619
629
  ]);
620
630
  if (template === null || template.media === null) {
621
631
  if (contentTypeOf(adaptationSet, mimeType) === "text" && periodDuration !== null) {
622
- var _attr26;
632
+ var _attr27;
623
633
  renditions.push({
624
634
  id,
625
635
  bitrate: bandwidth,
626
- codecs: (_attr26 = attr(representation, "codecs")) !== null && _attr26 !== void 0 ? _attr26 : asCodecs,
636
+ codecs: (_attr27 = attr(representation, "codecs")) !== null && _attr27 !== void 0 ? _attr27 : asCodecs,
627
637
  mimeType,
628
638
  segments: [{
629
639
  seq: 0,
@@ -642,7 +652,7 @@ function parsePeriod(periodElement, span, index, mpdBase, isLive) {
642
652
  if (timeline !== null) endSeq = template.startNumber - 1 + timeline.reduce((sum, run) => sum + run.count, 0);
643
653
  else if (template.duration !== null && periodDuration !== null) endSeq = template.startNumber - 1 + Math.ceil(periodDuration * template.timescale / template.duration);
644
654
  else if (template.duration === null) return { error: manifestError(`no addressing for '${id}'`) };
645
- const segments = _objectSpread2({
655
+ const segments = _objectSpread2(_objectSpread2({
646
656
  kind: "indexed",
647
657
  urlTemplate: resolveUrl(substituteIdentity(template.media, id, bandwidth), repBase),
648
658
  startSeq: template.startNumber,
@@ -650,7 +660,7 @@ function parsePeriod(periodElement, span, index, mpdBase, isLive) {
650
660
  timescale: template.timescale,
651
661
  segmentDuration: timeline !== null ? null : template.duration,
652
662
  timeline
653
- }, template.presentationTimeOffset !== 0 ? { presentationTimeOffset: template.presentationTimeOffset } : {});
663
+ }, template.presentationTimeOffset !== 0 ? { presentationTimeOffset: template.presentationTimeOffset } : {}), earlyAvailability(isLive ? availability : null, template));
654
664
  const init = template.initialization !== null ? { url: resolveUrl(substituteIdentity(template.initialization, id, bandwidth), repBase) } : null;
655
665
  const frameRate = (_parseFrameRate2 = parseFrameRate(attr(representation, "frameRate"))) !== null && _parseFrameRate2 !== void 0 ? _parseFrameRate2 : parseFrameRate(attr(adaptationSet, "frameRate"));
656
666
  const width = numberAttr(representation, "width");
@@ -660,10 +670,10 @@ function parsePeriod(periodElement, span, index, mpdBase, isLive) {
660
670
  renditions.push(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
661
671
  id,
662
672
  bitrate: bandwidth,
663
- codecs: (_attr27 = attr(representation, "codecs")) !== null && _attr27 !== void 0 ? _attr27 : asCodecs,
673
+ codecs: (_attr28 = attr(representation, "codecs")) !== null && _attr28 !== void 0 ? _attr28 : asCodecs,
664
674
  mimeType,
665
675
  segments
666
- }, init !== null ? { init } : {}), width !== null ? { width } : {}), height !== null ? { height } : {}), frameRate !== null ? { frameRate } : {}), videoRangeOf(representation, adaptationSet, (_attr28 = attr(representation, "codecs")) !== null && _attr28 !== void 0 ? _attr28 : asCodecs)), tiles !== null ? { tiles } : {}), playoutRate !== null ? { maxPlayoutRate: playoutRate } : {}), channelsOf(representation, adaptationSet)), supplementalOf(representation, adaptationSet)));
676
+ }, init !== null ? { init } : {}), width !== null ? { width } : {}), height !== null ? { height } : {}), frameRate !== null ? { frameRate } : {}), videoRangeOf(representation, adaptationSet, (_attr29 = attr(representation, "codecs")) !== null && _attr29 !== void 0 ? _attr29 : asCodecs)), tiles !== null ? { tiles } : {}), playoutRate !== null ? { maxPlayoutRate: playoutRate } : {}), channelsOf(representation, adaptationSet)), supplementalOf(representation, adaptationSet)));
667
677
  }
668
678
  if (renditions.length === 0) continue;
669
679
  const mimeType = (_trackMime2 = trackMime) !== null && _trackMime2 !== void 0 ? _trackMime2 : "video/mp4";
@@ -714,7 +724,7 @@ function parsePeriod(periodElement, span, index, mpdBase, isLive) {
714
724
  }
715
725
  const events = eventsOf(periodElement, periodStart);
716
726
  return {
717
- id: (_attr29 = attr(periodElement, "id")) !== null && _attr29 !== void 0 ? _attr29 : `p${index}`,
727
+ id: (_attr30 = attr(periodElement, "id")) !== null && _attr30 !== void 0 ? _attr30 : `p${index}`,
718
728
  start: periodStart,
719
729
  duration: periodDuration,
720
730
  tracks,
@@ -723,7 +733,74 @@ function parsePeriod(periodElement, span, index, mpdBase, isLive) {
723
733
  };
724
734
  }
725
735
  /** parse an MPD document into a Presentation. Never throws. */
726
- function parse(text, baseUrl) {
736
+ function earlyAvailability(availability, template) {
737
+ var _template$availabilit, _template$availabilit2;
738
+ if (availability === null) return {};
739
+ const offset = (_template$availabilit = template.availabilityOffset) !== null && _template$availabilit !== void 0 ? _template$availabilit : availability.offset;
740
+ if (offset === null || !(offset > 0)) return {};
741
+ const complete = (_template$availabilit2 = template.availabilityComplete) !== null && _template$availabilit2 !== void 0 ? _template$availabilit2 : availability.complete;
742
+ return _objectSpread2({ availabilityOffset: offset }, complete === "false" ? { chunked: true } : {});
743
+ }
744
+ /** The UTCTiming schemes the dash-live stage can ask (ISO/IEC 23009-1 §5.8.5.7). */
745
+ const UTC_SCHEME = /^urn:mpeg:dash:utc:(http-xsdate|http-iso|http-head|direct):201[24]$/;
746
+ /**
747
+ * The MPD's first UTCTiming, as VHS reads it: the others are never tried.
748
+ * A scheme the engine cannot ask (NTP) counts as none, and dash-live then
749
+ * takes the time from the MPD response. A time server URL is resolved
750
+ * like any other.
751
+ */
752
+ function timeServerOf(mpd, baseUrl) {
753
+ var _attr31, _attr32;
754
+ const timing = children(mpd, "UTCTiming")[0];
755
+ if (timing === void 0) return null;
756
+ const scheme = (_attr31 = attr(timing, "schemeIdUri")) !== null && _attr31 !== void 0 ? _attr31 : "";
757
+ const value = (_attr32 = attr(timing, "value")) !== null && _attr32 !== void 0 ? _attr32 : "";
758
+ if (!UTC_SCHEME.test(scheme) || value === "") return null;
759
+ return {
760
+ scheme,
761
+ value: scheme.includes(":direct:") ? value : resolveUrl(value, baseUrl)
762
+ };
763
+ }
764
+ /** The DVB low-latency scope (ETSI TS 103 285 §10.20.2). */
765
+ const DVB_LOW_LATENCY = "urn:dvb:dash:lowlatency:scope:2019";
766
+ /**
767
+ * The ServiceDescription that applies, as dash.js picks it: the last one
768
+ * scoped to DVB low latency, else the last one without a Scope. One with
769
+ * another Scope is for another client.
770
+ */
771
+ function serviceElementOf(mpd) {
772
+ const services = children(mpd, "ServiceDescription");
773
+ const scoped = services.filter((service) => children(service, "Scope").some((scope) => attr(scope, "schemeIdUri") === DVB_LOW_LATENCY));
774
+ if (scoped.length > 0) return scoped[scoped.length - 1];
775
+ const open = services.filter((service) => children(service, "Scope").length === 0);
776
+ return open[open.length - 1];
777
+ }
778
+ /**
779
+ * The latency and rates a low-latency MPD asks for (ISO/IEC 23009-1 Annex
780
+ * K, ServiceDescription): Latency in milliseconds, PlaybackRate as factors.
781
+ */
782
+ function serviceOf(mpd) {
783
+ const service = serviceElementOf(mpd);
784
+ if (service === void 0) return {};
785
+ const latency = children(service, "Latency")[0];
786
+ const rates = children(service, "PlaybackRate")[0];
787
+ const target = latency !== void 0 ? numberAttr(latency, "target") : null;
788
+ const max = latency !== void 0 ? numberAttr(latency, "max") : null;
789
+ const minRate = rates !== void 0 ? numberAttr(rates, "min") : null;
790
+ const maxRate = rates !== void 0 ? numberAttr(rates, "max") : null;
791
+ return _objectSpread2(_objectSpread2(_objectSpread2({}, target !== null && target > 0 ? { target: target / 1e3 } : {}), max !== null && max > 0 ? { max: max / 1e3 } : {}), minRate !== null && maxRate !== null && minRate > 0 && maxRate >= minRate ? { rate: {
792
+ min: minRate,
793
+ max: maxRate
794
+ } } : {});
795
+ }
796
+ /**
797
+ * `lowLatency` reads what a low-latency MPD adds: segments with an
798
+ * `@availabilityTimeOffset` are requested early, and the hold-back is
799
+ * dash.js's live delay: the ServiceDescription target, else
800
+ * `@suggestedPresentationDelay`, else four `@maxSegmentDuration`, else four
801
+ * `@minBufferTime`.
802
+ */
803
+ function parse(text, baseUrl, lowLatency = false) {
727
804
  var _flat$tracks, _flat$events;
728
805
  let doc;
729
806
  try {
@@ -742,18 +819,27 @@ function parse(text, baseUrl) {
742
819
  const isLive = attr(mpd, "type") === "dynamic";
743
820
  const mpdDuration = parseDuration(attr(mpd, "mediaPresentationDuration"));
744
821
  const mpdBase = applyBaseUrl(mpd, baseUrl);
822
+ const firstBase = children(mpd, "BaseURL")[0];
823
+ const availability = lowLatency ? {
824
+ offset: firstBase === void 0 ? null : availabilityOffsetOf(firstBase),
825
+ complete: firstBase === void 0 ? null : attr(firstBase, "availabilityTimeComplete")
826
+ } : null;
745
827
  let live;
746
828
  if (isLive) {
747
- var _attr30, _attr31, _attr32;
748
- const availabilityStart = Date.parse((_attr30 = attr(mpd, "availabilityStartTime")) !== null && _attr30 !== void 0 ? _attr30 : "");
829
+ var _attr33, _service$target;
830
+ const availabilityStart = Date.parse((_attr33 = attr(mpd, "availabilityStartTime")) !== null && _attr33 !== void 0 ? _attr33 : "");
749
831
  const updatePeriod = parseDuration(attr(mpd, "minimumUpdatePeriod"));
750
832
  const timeShiftDepth = parseDuration(attr(mpd, "timeShiftBufferDepth"));
751
- const holdBack = parseDuration(attr(mpd, "suggestedPresentationDelay"));
752
- const timing = children(mpd, "UTCTiming")[0];
753
- live = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, Number.isFinite(availabilityStart) ? { availabilityStart: availabilityStart / 1e3 } : {}), updatePeriod !== null ? { updatePeriod } : {}), timeShiftDepth !== null ? { timeShiftDepth } : {}), holdBack !== null ? { holdBack } : {}), timing !== void 0 ? { timeServer: {
754
- scheme: (_attr31 = attr(timing, "schemeIdUri")) !== null && _attr31 !== void 0 ? _attr31 : "",
755
- value: (_attr32 = attr(timing, "value")) !== null && _attr32 !== void 0 ? _attr32 : ""
756
- } } : {});
833
+ const service = lowLatency ? serviceOf(mpd) : {};
834
+ const suggested = parseDuration(attr(mpd, "suggestedPresentationDelay"));
835
+ let holdBack = (_service$target = service.target) !== null && _service$target !== void 0 ? _service$target : suggested;
836
+ if (lowLatency && holdBack === null) {
837
+ const longest = parseDuration(attr(mpd, "maxSegmentDuration"));
838
+ const minBuffer = parseDuration(attr(mpd, "minBufferTime"));
839
+ holdBack = longest !== null ? 4 * longest : minBuffer !== null ? 4 * minBuffer : null;
840
+ }
841
+ const timing = timeServerOf(mpd, baseUrl);
842
+ live = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, Number.isFinite(availabilityStart) ? { availabilityStart: availabilityStart / 1e3 } : {}), updatePeriod !== null ? { updatePeriod } : {}), timeShiftDepth !== null ? { timeShiftDepth } : {}), holdBack !== null ? { holdBack } : {}), service.rate !== void 0 ? { playbackRate: service.rate } : {}), service.max !== void 0 ? { maxLatency: service.max } : {}), timing !== null ? { timeServer: timing } : {});
757
843
  }
758
844
  let steering;
759
845
  const steeringElement = children(mpd, "ContentSteering")[0];
@@ -786,7 +872,7 @@ function parse(text, baseUrl) {
786
872
  const parsed = [];
787
873
  for (let i = 0; i < periodElements.length; i += 1) {
788
874
  if (i > 0 && isLive) break;
789
- const result = parsePeriod(periodElements[i], spans[i], i, mpdBase, isLive);
875
+ const result = parsePeriod(periodElements[i], spans[i], i, mpdBase, isLive, availability);
790
876
  if ("error" in result) return {
791
877
  presentation: null,
792
878
  error: result.error
@@ -809,6 +895,8 @@ function parse(text, baseUrl) {
809
895
  context: { reason: "no playable adaptation set" }
810
896
  }
811
897
  };
898
+ const chunked = tracks.some((track) => track.renditions.some((rendition) => !Array.isArray(rendition.segments) && rendition.segments.chunked === true));
899
+ if (live !== void 0 && chunked) live = _objectSpread2(_objectSpread2({}, live), {}, { lowLatency: true });
812
900
  return _objectSpread2({
813
901
  presentation: _objectSpread2(_objectSpread2(_objectSpread2({
814
902
  id: baseUrl,
@@ -837,7 +925,7 @@ function sidxToSegments(sidxBytes, addressing) {
837
925
  if (sidx === null) return [];
838
926
  const timescale = sidx.timescale || addressing.timescale || 1;
839
927
  const pto = (_addressing$presentat = addressing.presentationTimeOffset) !== null && _addressing$presentat !== void 0 ? _addressing$presentat : 0;
840
- let offset = addressing.indexRange.end + 1 + sidx.firstOffset;
928
+ let offset = addressing.indexRange.start + box.start + box.size + sidx.firstOffset;
841
929
  let mediaTime = sidx.earliestPresentationTime;
842
930
  const segments = [];
843
931
  for (let i = 0; i < sidx.references.length; i += 1) {
@@ -1,6 +1,6 @@
1
+ import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/asyncToGenerator.js";
1
2
  import { findRendition } from "../../kernel/presentation.js";
2
3
  import { segmentAt } from "../../kernel/timeline.js";
3
- import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/asyncToGenerator.js";
4
4
  //#region src/protocols/dash-cmaf/periods-runtime.ts
5
5
  /**
6
6
  * What a flattened multi-period presentation needs at playback time, kept
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/objectSpread2.js";
2
2
  import { isIndexed, isUnresolved, segmentAt } from "../../kernel/timeline.js";
3
3
  //#region src/protocols/dash-cmaf/periods.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/objectSpread2.js";
2
2
  import { scheduled, tickAfter } from "../../kernel/effects.js";
3
3
  import { registerLiveNamespace } from "../live-shared.js";
4
4
  import { parse } from "../dash-cmaf/parse.js";
@@ -10,6 +10,13 @@ import { parse } from "../dash-cmaf/parse.js";
10
10
  * LIVE_WINDOW_CHANGED facts and reloads the MPD on minimumUpdatePeriod.
11
11
  * UTCTiming corrects the client clock: a few seconds of drift silently
12
12
  * breaks live playback, which is why the fetch is worth its round trip.
13
+ * The schemes (ISO/IEC 23009-1 §5.8.5.7): `direct` carries the date in its
14
+ * value, `http-head` in the Date header of a HEAD response, and
15
+ * `http-xsdate` and `http-iso` in the body of a GET response. As in VHS,
16
+ * the MPD's first UTCTiming is the only one asked; without one, or when it
17
+ * fails, the Date header of the MPD response stands in, else the client
18
+ * clock counts as right. The clock syncs again when a reload brings a
19
+ * changed MPD.
13
20
  */
14
21
  const MPD_TOKEN = "dash:live:mpd";
15
22
  const UTC_TOKEN = "dash:live:utc";
@@ -38,8 +45,37 @@ const INITIAL = {
38
45
  lastWindowEnd: -1,
39
46
  lastWallClock: null,
40
47
  suspended: false,
41
- failures: 0
48
+ failures: 0,
49
+ mpdSkew: null,
50
+ mpdHash: null
42
51
  };
52
+ /** FNV-1a over the bytes: tells one MPD text from the next. */
53
+ function hashOf(bytes) {
54
+ let hash = 2166136261;
55
+ for (const byte of new Uint8Array(bytes)) hash = Math.imul(hash ^ byte, 16777619);
56
+ return hash >>> 0;
57
+ }
58
+ /**
59
+ * Starts a clock sync against the presentation's time server: a direct
60
+ * date at once, a request for the others, and the MPD's own date without
61
+ * a server or when the direct date does not parse.
62
+ */
63
+ function syncClock(state, server) {
64
+ var _state$mpdSkew;
65
+ if (server === void 0) return [_objectSpread2(_objectSpread2({}, state), {}, { skew: (_state$mpdSkew = state.mpdSkew) !== null && _state$mpdSkew !== void 0 ? _state$mpdSkew : state.skew }), []];
66
+ if (server.scheme.includes(":direct:")) {
67
+ var _state$mpdSkew2;
68
+ const date = Date.parse(server.value);
69
+ if (Number.isFinite(date) && state.lastWallClock !== null) return [_objectSpread2(_objectSpread2({}, state), {}, { skew: date / 1e3 - state.lastWallClock }), []];
70
+ return [_objectSpread2(_objectSpread2({}, state), {}, { skew: (_state$mpdSkew2 = state.mpdSkew) !== null && _state$mpdSkew2 !== void 0 ? _state$mpdSkew2 : state.skew }), []];
71
+ }
72
+ const head = server.scheme.includes(":http-head:");
73
+ return [_objectSpread2(_objectSpread2({}, state), {}, { utcPending: true }), [_objectSpread2({
74
+ kind: "fetch",
75
+ token: UTC_TOKEN,
76
+ url: server.value
77
+ }, head ? { method: "HEAD" } : {})]];
78
+ }
43
79
  /** The window arithmetic; null when it cannot move or is not worth a fact. */
44
80
  function windowUpdate(state, live) {
45
81
  var _state$skew, _live$timeShiftDepth, _live$holdBack;
@@ -107,9 +143,12 @@ function reloadFailed(state, presentation, cause) {
107
143
  tickPending: true
108
144
  }), [tick((_presentation$live$up = presentation.live.updatePeriod) !== null && _presentation$live$up !== void 0 ? _presentation$live$up : 4)]];
109
145
  }
110
- const reduceDashLive = (slice, msg, kernel) => {
146
+ /** The slice reducer. `lowLatency` reloads the MPD as dash-ll reads it. */
147
+ const createReduceDashLive = (lowLatency = false) => (slice, msg, kernel) => {
111
148
  let state = slice !== null && slice !== void 0 ? slice : INITIAL;
112
149
  if ((msg.type === "TIME_UPDATE" || msg.type === "SEGMENT_LOADED") && msg.wallClock !== void 0) state = _objectSpread2(_objectSpread2({}, state), {}, { lastWallClock: msg.wallClock });
150
+ if (msg.type === "SEGMENT_LOADED" && (msg.trackId === "manifest" || msg.trackId === MPD_TOKEN) && msg.serverDate !== void 0 && msg.wallClock !== void 0) state = _objectSpread2(_objectSpread2({}, state), {}, { mpdSkew: msg.serverDate - msg.wallClock });
151
+ if (msg.type === "SEGMENT_LOADED" && msg.trackId === "manifest") state = _objectSpread2(_objectSpread2({}, state), {}, { mpdHash: hashOf(msg.bytes) });
113
152
  if (msg.type === "LOAD") return [_objectSpread2(_objectSpread2({}, INITIAL), {}, { manifestUrl: msg.url }), []];
114
153
  if (msg.type === "UNLOAD" || msg.type === "DETACH") return [INITIAL, []];
115
154
  if (msg.type === "SUSPEND") {
@@ -147,17 +186,10 @@ const reduceDashLive = (slice, msg, kernel) => {
147
186
  if (!drivesWindow(msg.presentation)) return [state, []];
148
187
  const effects = [];
149
188
  let next = state;
150
- const server = msg.presentation.live.timeServer;
151
- if (server !== void 0 && state.skew === null && !state.utcPending) {
152
- if (server.scheme.endsWith(":direct") || server.scheme.endsWith(":direct:2014")) next = _objectSpread2(_objectSpread2({}, next), {}, { skew: null });
153
- else if (server.value !== "") {
154
- effects.push({
155
- kind: "fetch",
156
- token: UTC_TOKEN,
157
- url: server.value
158
- });
159
- next = _objectSpread2(_objectSpread2({}, next), {}, { utcPending: true });
160
- }
189
+ if (state.skew === null && !state.utcPending) {
190
+ const [synced, sync] = syncClock(state, msg.presentation.live.timeServer);
191
+ next = synced;
192
+ effects.push(...sync);
161
193
  }
162
194
  if (!next.tickPending) {
163
195
  var _msg$presentation$liv;
@@ -198,11 +230,23 @@ const reduceDashLive = (slice, msg, kernel) => {
198
230
  url: state.manifestUrl
199
231
  }]];
200
232
  }
201
- if (msg.type === "SEGMENT_FAILED" && msg.trackId === UTC_TOKEN) return [_objectSpread2(_objectSpread2({}, state), {}, { utcPending: false }), []];
233
+ if (msg.type === "SEGMENT_FAILED" && msg.trackId === UTC_TOKEN) {
234
+ var _state$mpdSkew3;
235
+ return [_objectSpread2(_objectSpread2({}, state), {}, {
236
+ skew: (_state$mpdSkew3 = state.mpdSkew) !== null && _state$mpdSkew3 !== void 0 ? _state$mpdSkew3 : state.skew,
237
+ utcPending: false
238
+ }), []];
239
+ }
202
240
  if (msg.type === "SEGMENT_FAILED" && msg.trackId === MPD_TOKEN) return reloadFailed(state, kernel.presentation, msg.error.code);
203
241
  if (msg.type === "SEGMENT_LOADED" && msg.trackId === UTC_TOKEN) {
204
- const serverTime = Date.parse(new TextDecoder().decode(msg.bytes).trim());
205
- if (!Number.isFinite(serverTime) || msg.wallClock === void 0) return [_objectSpread2(_objectSpread2({}, state), {}, { utcPending: false }), []];
242
+ const serverTime = msg.serverDate !== void 0 ? msg.serverDate * 1e3 : Date.parse(new TextDecoder().decode(msg.bytes).trim());
243
+ if (!Number.isFinite(serverTime) || msg.wallClock === void 0) {
244
+ var _state$mpdSkew4;
245
+ return [_objectSpread2(_objectSpread2({}, state), {}, {
246
+ skew: (_state$mpdSkew4 = state.mpdSkew) !== null && _state$mpdSkew4 !== void 0 ? _state$mpdSkew4 : state.skew,
247
+ utcPending: false
248
+ }), []];
249
+ }
206
250
  return [_objectSpread2(_objectSpread2({}, state), {}, {
207
251
  skew: serverTime / 1e3 - msg.wallClock,
208
252
  utcPending: false
@@ -210,10 +254,20 @@ const reduceDashLive = (slice, msg, kernel) => {
210
254
  }
211
255
  if (msg.type === "SEGMENT_LOADED" && msg.trackId === MPD_TOKEN) {
212
256
  if (state.manifestUrl === null) return [state, []];
213
- const result = parse(new TextDecoder().decode(msg.bytes), state.manifestUrl);
257
+ const result = parse(new TextDecoder().decode(msg.bytes), state.manifestUrl, lowLatency);
214
258
  if (result.presentation === null) return reloadFailed(state, kernel.presentation, result.error.code);
215
259
  const effects = [];
216
- let next = _objectSpread2(_objectSpread2({}, state), {}, { failures: 0 });
260
+ const hash = hashOf(msg.bytes);
261
+ let next = _objectSpread2(_objectSpread2({}, state), {}, {
262
+ failures: 0,
263
+ mpdHash: hash
264
+ });
265
+ if (state.mpdHash !== null && hash !== state.mpdHash && !state.utcPending) {
266
+ var _result$presentation$;
267
+ const [synced, sync] = syncClock(next, (_result$presentation$ = result.presentation.live) === null || _result$presentation$ === void 0 ? void 0 : _result$presentation$.timeServer);
268
+ next = synced;
269
+ effects.push(...sync);
270
+ }
217
271
  effects.push(feed({
218
272
  type: "MANIFEST_LOADED",
219
273
  presentation: result.presentation
@@ -240,10 +294,10 @@ function dashLive() {
240
294
  provides: ["dash-live"],
241
295
  requires: ["dash-cmaf"],
242
296
  install(ctx) {
243
- ctx.reduce("dash-live", reduceDashLive);
297
+ ctx.reduce("dash-live", createReduceDashLive());
244
298
  registerLiveNamespace(ctx);
245
299
  }
246
300
  };
247
301
  }
248
302
  //#endregion
249
- export { dashLive as default };
303
+ export { createReduceDashLive, dashLive as default };
@@ -0,0 +1,42 @@
1
+ import { completeChunks } from "../../containers/mp4-box/index.js";
2
+ import { registerLiveNamespace } from "../live-shared.js";
3
+ import { MANIFEST_TYPES, createReduceDash, installDashPeriods } from "../dash-cmaf/index.js";
4
+ import { createReduceDashLive } from "../dash-live/index.js";
5
+ //#region src/protocols/dash-ll/index.ts
6
+ /**
7
+ * Low-latency DASH (DASH-IF IOP low-latency modes, ISO/IEC 23009-1 Annex
8
+ * K): dash-cmaf and dash-live in one stage, reading what a low-latency MPD
9
+ * adds. The ServiceDescription target becomes the hold-back, and segments
10
+ * with an `@availabilityTimeOffset` are requested before they are
11
+ * complete. With `@availabilityTimeComplete="false"` the server sends such
12
+ * a segment as the encoder writes it: the stage registers the CMAF chunk
13
+ * splitter, so each complete `moof` and `mdat` pair appends as it arrives
14
+ * and throughput leaves out the encoder's pauses. An MPD without these
15
+ * plays as dash-cmaf and dash-live play it, so the stage replaces both in
16
+ * a preset.
17
+ *
18
+ * Inert module: exports a factory, registers nothing at import time.
19
+ */
20
+ /** The stage factory. It provides `dash-cmaf` and `dash-live`, so stages that require either compose with it. */
21
+ function dashLl(options = {}) {
22
+ var _options$unavailableR;
23
+ const retryMs = ((_options$unavailableR = options.unavailableRetrySeconds) !== null && _options$unavailableR !== void 0 ? _options$unavailableR : 15) * 1e3;
24
+ return {
25
+ name: "dash-ll",
26
+ provides: [
27
+ "dash-ll",
28
+ "dash-cmaf",
29
+ "dash-live",
30
+ ...MANIFEST_TYPES
31
+ ],
32
+ install(ctx) {
33
+ ctx.reduce("dash", createReduceDash(retryMs, true));
34
+ ctx.reduce("dash-live", createReduceDashLive(true));
35
+ ctx.registerChunkSplitter(completeChunks);
36
+ registerLiveNamespace(ctx);
37
+ return installDashPeriods(ctx);
38
+ }
39
+ };
40
+ }
41
+ //#endregion
42
+ export { dashLl as default };
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/objectSpread2.js";
2
2
  import { scheduled, tickAfter } from "../../kernel/effects.js";
3
3
  import { normalizeMimeType } from "../../kernel/mime.js";
4
4
  import { activeRenditions } from "../../kernel/rendition-select.js";
@@ -112,7 +112,7 @@ function retry(state, kernel, url) {
112
112
  const message = readmitMessage(kernel, LOAD_FAILED, failedRenditions(next, kernel.presentation));
113
113
  return [next, message === null ? [] : [feed(message)]];
114
114
  }
115
- const createReduceHls = (retryMs) => (slice, msg, kernel) => {
115
+ const createReduceHls = (retryMs, parseMedia = parseMediaPlaylist) => (slice, msg, kernel) => {
116
116
  const state = slice !== null && slice !== void 0 ? slice : INITIAL;
117
117
  if (msg.type === "LOAD") return [_objectSpread2(_objectSpread2({}, INITIAL), {}, {
118
118
  manifestUrl: msg.url,
@@ -120,7 +120,7 @@ const createReduceHls = (retryMs) => (slice, msg, kernel) => {
120
120
  }), []];
121
121
  if (msg.type === "UNLOAD" || msg.type === "DETACH") return [INITIAL, []];
122
122
  if (msg.type === "SEGMENT_LOADED" && msg.trackId === "manifest" && state.manifestUrl !== null) {
123
- const fact = manifestFact(msg.bytes, state.manifestUrl, (text) => claims(state, text), parse);
123
+ const fact = manifestFact(msg.bytes, state.manifestUrl, (text) => claims(state, text), (text, url) => parse(text, url, parseMedia));
124
124
  return [state, fact === null ? [] : [feed(fact)]];
125
125
  }
126
126
  if (msg.type === "TICK" && msg.token.startsWith(RETRY_TOKEN)) return retry(state, kernel, msg.token.slice(10));
@@ -131,7 +131,7 @@ const createReduceHls = (retryMs) => (slice, msg, kernel) => {
131
131
  const pending = _objectSpread2({}, state.pending);
132
132
  delete pending[msg.trackId];
133
133
  next = _objectSpread2(_objectSpread2({}, next), {}, { pending });
134
- const media = parseMediaPlaylist(new TextDecoder().decode(msg.bytes), url);
134
+ const media = parseMedia(new TextDecoder().decode(msg.bytes), url);
135
135
  const playlist = media.playlist;
136
136
  const error = playlist === null ? media.error : playlist.endlist && playlist.segments.length === 0 ? {
137
137
  category: "manifest",
@@ -202,4 +202,4 @@ function hlsCmaf(options = {}) {
202
202
  };
203
203
  }
204
204
  //#endregion
205
- export { hlsCmaf as default };
205
+ export { MANIFEST_TYPES, createReduceHls, hlsCmaf as default };
@@ -11,7 +11,13 @@ const ATTRIBUTE_TAGS = /* @__PURE__ */ new Set([
11
11
  "EXT-X-IMAGE-STREAM-INF",
12
12
  "EXT-X-TILES",
13
13
  "EXT-X-CONTENT-STEERING",
14
- "EXT-X-DATERANGE"
14
+ "EXT-X-DATERANGE",
15
+ "EXT-X-SERVER-CONTROL",
16
+ "EXT-X-PART-INF",
17
+ "EXT-X-PART",
18
+ "EXT-X-PRELOAD-HINT",
19
+ "EXT-X-RENDITION-REPORT",
20
+ "EXT-X-SKIP"
15
21
  ]);
16
22
  /**
17
23
  * RFC 8216 §4.2: comma-separated KEY=VALUE pairs where a quoted-string