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 { byteToHex } from "../../kernel/base64.js";
3
3
  import { resolveUrl } from "../../kernel/url.js";
4
4
  import { manifestError } from "../adapter-shared.js";
@@ -163,7 +163,10 @@ function parseMediaPlaylist(text, baseUrl) {
163
163
  playlist: null,
164
164
  error: manifestError("missing #EXTM3U")
165
165
  };
166
- const lines = lex(text);
166
+ return parseMediaLines(lex(text), baseUrl);
167
+ }
168
+ /** A lexed media playlist into segments, for a caller that reads the lines itself too. */
169
+ function parseMediaLines(lines, baseUrl) {
167
170
  const segments = [];
168
171
  let init = null;
169
172
  let targetDuration = 0;
@@ -183,6 +186,9 @@ function parseMediaPlaylist(text, baseUrl) {
183
186
  let previousRangeEnd = null;
184
187
  let start = 0;
185
188
  let seq = 0;
189
+ let serverControl = null;
190
+ let skipped = 0;
191
+ let removedDateRanges = [];
186
192
  for (const line of lines) {
187
193
  if (line.kind === "tag") {
188
194
  switch (line.name) {
@@ -237,6 +243,15 @@ function parseMediaPlaylist(text, baseUrl) {
237
243
  case "EXT-X-TILES":
238
244
  var _tiles;
239
245
  tiles = (_tiles = tiles) !== null && _tiles !== void 0 ? _tiles : tileGridFrom(line.attributes);
246
+ break;
247
+ case "EXT-X-SERVER-CONTROL":
248
+ serverControl = line.attributes;
249
+ break;
250
+ case "EXT-X-SKIP":
251
+ var _line$attributes$RECE;
252
+ skipped = Number(line.attributes["SKIPPED-SEGMENTS"]) || 0;
253
+ seq += skipped;
254
+ removedDateRanges = ((_line$attributes$RECE = line.attributes["RECENTLY-REMOVED-DATERANGES"]) !== null && _line$attributes$RECE !== void 0 ? _line$attributes$RECE : "").split(" ").filter((id) => id !== "");
240
255
  }
241
256
  continue;
242
257
  }
@@ -265,7 +280,7 @@ function parseMediaPlaylist(text, baseUrl) {
265
280
  pendingDiscontinuity = false;
266
281
  }
267
282
  return {
268
- playlist: _objectSpread2(_objectSpread2(_objectSpread2({
283
+ playlist: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
269
284
  segments,
270
285
  init,
271
286
  targetDuration,
@@ -273,7 +288,7 @@ function parseMediaPlaylist(text, baseUrl) {
273
288
  endlist,
274
289
  playlistType,
275
290
  protection
276
- }, dateAnchor !== void 0 ? { dateAnchor } : {}), tiles !== null ? { tiles } : {}), dateRangeTags.length > 0 ? { dateRanges: dateRangesFrom(dateRangeTags, dateAnchor) } : {}),
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 } : {}),
277
292
  error: null
278
293
  };
279
294
  }
@@ -413,14 +428,14 @@ function sessionDataFrom(attributes, baseUrl) {
413
428
  return _objectSpread2(_objectSpread2(_objectSpread2({ id }, attributes.VALUE !== void 0 ? { value: attributes.VALUE } : {}), attributes.URI !== void 0 ? { uri: resolveUrl(attributes.URI, baseUrl) } : {}), attributes.LANGUAGE !== void 0 ? { lang: attributes.LANGUAGE } : {});
414
429
  }
415
430
  /** parse either playlist form into a Presentation. Never throws. */
416
- function parse(text, baseUrl) {
431
+ function parse(text, baseUrl, parseMedia = parseMediaPlaylist) {
417
432
  if (!text.trimStart().startsWith("#EXTM3U")) return {
418
433
  presentation: null,
419
434
  error: manifestError("missing #EXTM3U")
420
435
  };
421
436
  const lines = lex(text);
422
437
  if (!lines.some((line) => line.kind === "tag" && line.name === "EXT-X-STREAM-INF")) {
423
- const media = parseMediaPlaylist(text, baseUrl);
438
+ const media = parseMedia(text, baseUrl);
424
439
  if (media.playlist === null) {
425
440
  var _media$error;
426
441
  return {
@@ -453,7 +468,7 @@ function parse(text, baseUrl) {
453
468
  presentation: _objectSpread2(_objectSpread2(_objectSpread2({
454
469
  id: baseUrl,
455
470
  isLive: !media.playlist.endlist
456
- }, media.playlist.endlist ? { duration } : {}), media.playlist.endlist ? {} : { live: _objectSpread2({ updatePeriod: media.playlist.targetDuration || 4 }, media.playlist.dateAnchor !== void 0 ? { dateAnchor: media.playlist.dateAnchor } : {}) }), {}, {
471
+ }, media.playlist.endlist ? { duration } : {}), media.playlist.endlist ? {} : { live: _objectSpread2(_objectSpread2(_objectSpread2({ updatePeriod: media.playlist.targetDuration || 4 }, media.playlist.holdBack !== void 0 ? { holdBack: media.playlist.holdBack } : {}), media.playlist.lowLatency === true ? { lowLatency: true } : {}), media.playlist.dateAnchor !== void 0 ? { dateAnchor: media.playlist.dateAnchor } : {}) }), {}, {
457
472
  periods: [{
458
473
  id: "p0",
459
474
  start: 0,
@@ -696,12 +711,12 @@ function refreshFor(presentation, renditionId, playlist) {
696
711
  if (newest(candidate) > newest(sibling)) sibling = candidate;
697
712
  }
698
713
  }
699
- const knownLast = Array.isArray(previous) ? previous[previous.length - 1] : void 0;
700
- const incomingLast = playlist.segments[playlist.segments.length - 1];
714
+ const knownLast = Array.isArray(previous) ? previous.filter((s) => s.preload !== true).pop() : void 0;
715
+ const incomingLast = playlist.segments.filter((s) => s.preload !== true).pop();
701
716
  if (knownLast !== void 0 && incomingLast !== void 0 && !playlist.endlist && incomingLast.seq < knownLast.seq) return null;
702
717
  const shift = timelineShift(!playlist.endlist && knownLast === void 0 && sibling.length > 0 ? sibling : previous, playlist.segments);
703
718
  const segments = shift === 0 ? playlist.segments : playlist.segments.map((s) => _objectSpread2(_objectSpread2({}, s), {}, { start: s.start + shift }));
704
- return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
719
+ return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
705
720
  type: "PLAYLIST_REFRESHED",
706
721
  trackId: renditionId,
707
722
  renditionId,
@@ -710,7 +725,7 @@ function refreshFor(presentation, renditionId, playlist) {
710
725
  }, playlist.init !== null ? { init: playlist.init } : {}), playlist.tiles !== void 0 ? { tiles: playlist.tiles } : {}), {}, {
711
726
  protection: playlist.protection,
712
727
  endlist: playlist.endlist
713
- }, playlist.endlist ? {} : { updatePeriod: playlist.targetDuration || 4 }), playlist.dateAnchor !== void 0 ? { dateAnchor: {
728
+ }, playlist.endlist ? {} : { updatePeriod: playlist.targetDuration || 4 }), !playlist.endlist && playlist.holdBack !== void 0 ? { holdBack: playlist.holdBack } : {}), !playlist.endlist ? { lowLatency: playlist.lowLatency === true } : {}), playlist.dateAnchor !== void 0 ? { dateAnchor: {
714
729
  wallClock: playlist.dateAnchor.wallClock,
715
730
  presentationTime: playlist.dateAnchor.presentationTime + shift
716
731
  } } : {}), playlist.dateRanges !== void 0 ? { dateRanges: shift === 0 ? playlist.dateRanges : playlist.dateRanges.map((range) => shiftRange(range, shift)) } : {});
@@ -719,4 +734,4 @@ function shiftRange(range, shift) {
719
734
  return _objectSpread2(_objectSpread2(_objectSpread2({}, range), {}, { start: range.start + shift }, range.end !== void 0 ? { end: range.end + shift } : {}), range.plannedEnd !== void 0 ? { plannedEnd: range.plannedEnd + shift } : {});
720
735
  }
721
736
  //#endregion
722
- export { normalizeAvcCodec, parse, parseMediaPlaylist, refreshFor };
737
+ export { normalizeAvcCodec, parse, parseByteRange, parseMediaLines, parseMediaPlaylist, refreshFor };
@@ -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 { isTrick } from "../../kernel/presentation.js";
3
3
  import { withDeadGroups } from "../../kernel/rendition-select.js";
4
4
  //#region src/protocols/hls-cmaf/unavailable.ts
@@ -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 { findRendition } from "../../kernel/presentation.js";
4
4
  import { activeRenditions } from "../../kernel/rendition-select.js";
@@ -38,7 +38,10 @@ const INITIAL = {
38
38
  awaitingTarget: false,
39
39
  suspended: false,
40
40
  failures: {},
41
- abandoned: []
41
+ abandoned: [],
42
+ blocking: {},
43
+ chained: [],
44
+ reports: {}
42
45
  };
43
46
  /**
44
47
  * Failed reloads of one playlist in a row before the loop gives up on it.
@@ -77,6 +80,11 @@ function reload(target) {
77
80
  renditionId: target.renditionId
78
81
  };
79
82
  }
83
+ /** The URL a reload of `target` asks for: its blocking reload when it has one. */
84
+ function urlFor(state, target) {
85
+ var _state$blocking$targe;
86
+ return (_state$blocking$targe = state.blocking[target.renditionId]) !== null && _state$blocking$targe !== void 0 ? _state$blocking$targe : target.url;
87
+ }
80
88
  function renditionOfToken(token) {
81
89
  return token.startsWith(`${REFRESH_TOKEN}:`) ? token.slice(17) : null;
82
90
  }
@@ -119,6 +127,20 @@ function companionTargets(kernel, window, abandoned) {
119
127
  for (const { contentType, rendition } of activeRenditions(kernel, types, (_window$id = window === null || window === void 0 ? void 0 : window.id) !== null && _window$id !== void 0 ? _window$id : null)) add(rendition, contentType === "video");
120
128
  return out;
121
129
  }
130
+ /**
131
+ * The URL that loads a playlist from a rendition report: the report for
132
+ * that URL, else the last report whose URL begins it, as hls.js matches
133
+ * them, so a playlist URL with extra query parameters still finds its
134
+ * report. The playlist URL itself without either.
135
+ */
136
+ function reportFor(reports, url) {
137
+ var _found;
138
+ const exact = reports[url];
139
+ if (exact !== void 0) return exact;
140
+ let found;
141
+ for (const [reported, reload] of Object.entries(reports)) if (url.startsWith(reported)) found = reload;
142
+ return (_found = found) !== null && _found !== void 0 ? _found : url;
143
+ }
122
144
  /** Loops a message back into the bus through a zero-delay schedule effect. */
123
145
  function feed(message) {
124
146
  return scheduled("hls-live:loopback", message);
@@ -156,8 +178,8 @@ function windowRendition(presentation, kernel, abandoned) {
156
178
  */
157
179
  function windowFact(presentation, rendition, kernel) {
158
180
  var _presentation$live$ho, _presentation$live, _presentation$live$up, _presentation$live2;
159
- const segments = rendition.segments;
160
- if (!Array.isArray(segments) || segments.length === 0) return null;
181
+ if (!Array.isArray(rendition.segments)) return null;
182
+ const segments = rendition.segments.filter((s) => s.preload !== true);
161
183
  const first = segments[0];
162
184
  const last = segments[segments.length - 1];
163
185
  if (first === void 0 || last === void 0) return null;
@@ -201,8 +223,15 @@ function reloadFailed(state, kernel, renditionId, error, retryMs) {
201
223
  const count = ((_state$failures$rendi = state.failures[renditionId]) !== null && _state$failures$rendi !== void 0 ? _state$failures$rendi : 0) + 1;
202
224
  const failures = _objectSpread2(_objectSpread2({}, state.failures), {}, { [renditionId]: count });
203
225
  const isTarget = state.target !== null && renditionId === state.target.renditionId;
226
+ state = _objectSpread2(_objectSpread2({}, state), {}, { chained: state.chained.filter((id) => id !== renditionId) });
204
227
  if (count < FAILURE_LIMIT) {
205
- if (!isTarget) return [_objectSpread2(_objectSpread2({}, state), {}, { failures }), []];
228
+ if (!isTarget) {
229
+ if (state.blocking[renditionId] === void 0 || state.tickPending) return [_objectSpread2(_objectSpread2({}, state), {}, { failures }), []];
230
+ return [_objectSpread2(_objectSpread2({}, state), {}, {
231
+ failures,
232
+ tickPending: true
233
+ }), [tick(2)]];
234
+ }
206
235
  if (state.tickPending) return [_objectSpread2(_objectSpread2({}, state), {}, {
207
236
  failures,
208
237
  inflight: null
@@ -260,7 +289,7 @@ function retry(state, kernel, renditionId) {
260
289
  failures
261
290
  }), message === null ? [] : [feed(message)]];
262
291
  }
263
- const createReduceHlsLive = (retryMs) => (slice, msg, kernel) => {
292
+ const createReduceHlsLive = (retryMs, ll) => (slice, msg, kernel) => {
264
293
  const state = slice !== null && slice !== void 0 ? slice : INITIAL;
265
294
  if (msg.type === "LOAD") return [_objectSpread2(_objectSpread2({}, INITIAL), {}, { manifestUrl: msg.url }), []];
266
295
  if (msg.type === "UNLOAD" || msg.type === "DETACH") return [INITIAL, []];
@@ -274,9 +303,14 @@ const createReduceHlsLive = (retryMs) => (slice, msg, kernel) => {
274
303
  kind: "abort",
275
304
  token: refreshToken(state.inflight)
276
305
  });
306
+ for (const id of state.chained) effects.push({
307
+ kind: "abort",
308
+ token: refreshToken(id)
309
+ });
277
310
  return [_objectSpread2(_objectSpread2({}, state), {}, {
278
311
  tickPending: false,
279
312
  inflight: null,
313
+ chained: [],
280
314
  suspended: true
281
315
  }), effects];
282
316
  }
@@ -314,7 +348,7 @@ const createReduceHlsLive = (retryMs) => (slice, msg, kernel) => {
314
348
  let inflight = state.inflight;
315
349
  if (switched && target !== null) {
316
350
  if (inflight !== target.renditionId) {
317
- effects.push(reload(target));
351
+ effects.push(reload(_objectSpread2(_objectSpread2({}, target), {}, { url: reportFor(state.reports, target.url) })));
318
352
  inflight = target.renditionId;
319
353
  }
320
354
  awaitingTarget = true;
@@ -325,7 +359,7 @@ const createReduceHlsLive = (retryMs) => (slice, msg, kernel) => {
325
359
  let tickPending = state.tickPending;
326
360
  if (!tickPending && inflight === null && target !== null) {
327
361
  var _presentation$live$up2, _presentation$live3;
328
- effects.push(tick((_presentation$live$up2 = (_presentation$live3 = presentation.live) === null || _presentation$live3 === void 0 ? void 0 : _presentation$live3.updatePeriod) !== null && _presentation$live$up2 !== void 0 ? _presentation$live$up2 : 4));
362
+ effects.push(tick(ll === void 0 ? (_presentation$live$up2 = (_presentation$live3 = presentation.live) === null || _presentation$live3 === void 0 ? void 0 : _presentation$live3.updatePeriod) !== null && _presentation$live$up2 !== void 0 ? _presentation$live$up2 : 4 : 0));
329
363
  tickPending = true;
330
364
  }
331
365
  return [_objectSpread2(_objectSpread2({}, state), {}, {
@@ -361,19 +395,24 @@ const createReduceHlsLive = (retryMs) => (slice, msg, kernel) => {
361
395
  const effects = [];
362
396
  let inflight = state.inflight;
363
397
  if (inflight !== target.renditionId) {
364
- effects.push(reload(target));
398
+ effects.push(reload(_objectSpread2(_objectSpread2({}, target), {}, { url: urlFor(state, target) })));
365
399
  inflight = target.renditionId;
366
400
  }
401
+ const blockingTarget = state.blocking[target.renditionId] !== void 0;
402
+ const chained = [...state.chained];
367
403
  for (const companion of state.companions) {
368
- if (companion.ladder && state.round % LADDER_EVERY !== 0) continue;
369
- effects.push(reload(companion));
404
+ if (chained.includes(companion.renditionId)) continue;
405
+ if (companion.ladder && (blockingTarget || state.round % LADDER_EVERY !== 0)) continue;
406
+ effects.push(reload(_objectSpread2(_objectSpread2({}, companion), {}, { url: urlFor(state, companion) })));
407
+ if (state.blocking[companion.renditionId] !== void 0) chained.push(companion.renditionId);
370
408
  }
371
409
  return [_objectSpread2(_objectSpread2({}, state), {}, {
372
410
  target,
373
411
  awaitingTarget,
374
412
  round: state.round + 1,
375
413
  tickPending: false,
376
- inflight
414
+ inflight,
415
+ chained
377
416
  }), effects];
378
417
  }
379
418
  if (msg.type === "SEGMENT_FAILED") {
@@ -382,15 +421,37 @@ const createReduceHlsLive = (retryMs) => (slice, msg, kernel) => {
382
421
  return reloadFailed(state, kernel, renditionId, msg.error, retryMs);
383
422
  }
384
423
  if (msg.type === "SEGMENT_LOADED") {
385
- var _findRendition4, _lastSegment$seq;
424
+ var _site$rendition$segme, _site$rendition$dateR, _media$playlist$skipp, _findRendition4, _lastSegment$seq;
386
425
  const renditionId = renditionOfToken(msg.trackId);
387
426
  if (renditionId === null || kernel.presentation === null) return [state, []];
388
427
  const isTarget = state.target !== null && renditionId === state.target.renditionId;
389
428
  const url = playlistUrlFor(kernel.presentation, renditionId, state.target);
390
429
  if (url === null) return [state, []];
391
430
  const text = new TextDecoder().decode(msg.bytes);
392
- const media = parseMediaPlaylist(text, url);
431
+ const site = findRendition(kernel.presentation, renditionId);
432
+ const media = ll === void 0 ? parseMediaPlaylist(text, url) : ll.parse(text, url, (_site$rendition$segme = site === null || site === void 0 ? void 0 : site.rendition.segments) !== null && _site$rendition$segme !== void 0 ? _site$rendition$segme : [], (_site$rendition$dateR = site === null || site === void 0 ? void 0 : site.rendition.dateRanges) !== null && _site$rendition$dateR !== void 0 ? _site$rendition$dateR : []);
393
433
  if (media.playlist === null) return reloadFailed(state, kernel, renditionId, media.error, retryMs);
434
+ const chained = state.chained.filter((id) => id !== renditionId);
435
+ if (ll !== void 0 && ((_media$playlist$skipp = media.playlist.skipped) !== null && _media$playlist$skipp !== void 0 ? _media$playlist$skipp : 0) > 0) {
436
+ var _ll$next;
437
+ const whole = reload({
438
+ renditionId,
439
+ url: (_ll$next = ll.next(url, media.playlist, false)) !== null && _ll$next !== void 0 ? _ll$next : url
440
+ });
441
+ return [_objectSpread2(_objectSpread2({}, state), {}, { chained: isTarget ? chained : [...chained, renditionId] }), [whole]];
442
+ }
443
+ let blocking = state.blocking;
444
+ let reports = state.reports;
445
+ if (ll !== void 0) {
446
+ const next = ll.next(url, media.playlist, true);
447
+ const updated = _objectSpread2({}, blocking);
448
+ if (next === null) delete updated[renditionId];
449
+ else updated[renditionId] = next;
450
+ blocking = updated;
451
+ reports = _objectSpread2(_objectSpread2({}, reports), ll.reports(media.playlist));
452
+ }
453
+ const nextUrl = blocking[renditionId];
454
+ const chains = nextUrl !== void 0 && !media.playlist.endlist && !state.suspended && (isTarget || state.companions.some((c) => c.renditionId === renditionId && !c.ladder));
394
455
  const failures = _objectSpread2({}, state.failures);
395
456
  delete failures[renditionId];
396
457
  const sharing = ((_findRendition4 = findRendition(kernel.presentation, renditionId)) === null || _findRendition4 === void 0 ? void 0 : _findRendition4.rendition.playlistUrl) === void 0 ? [renditionId] : renditionIdsAt(kernel.presentation, url);
@@ -399,21 +460,34 @@ const createReduceHlsLive = (retryMs) => (slice, msg, kernel) => {
399
460
  const refresh = refreshFor(kernel.presentation, id, media.playlist);
400
461
  if (refresh !== null) effects.push(feed(refresh));
401
462
  }
402
- if (!isTarget) return [_objectSpread2(_objectSpread2({}, state), {}, { failures }), effects];
463
+ if (chains) effects.push(reload({
464
+ renditionId,
465
+ url: nextUrl
466
+ }));
467
+ if (!isTarget) return [_objectSpread2(_objectSpread2({}, state), {}, {
468
+ failures,
469
+ blocking,
470
+ reports,
471
+ chained: chains ? [...chained, renditionId] : chained
472
+ }), effects];
403
473
  const lastSegment = media.playlist.segments[media.playlist.segments.length - 1];
404
474
  const endSeq = (_lastSegment$seq = lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.seq) !== null && _lastSegment$seq !== void 0 ? _lastSegment$seq : -1;
405
475
  const changed = endSeq !== state.lastEndSeq;
406
476
  const cadence = media.playlist.targetDuration || 4;
477
+ const ticks = !chains || state.companions.some((c) => !c.ladder && blocking[c.renditionId] === void 0);
407
478
  let tickPending = state.tickPending;
408
- if (!media.playlist.endlist && !tickPending && !state.suspended) {
479
+ if (ticks && !media.playlist.endlist && !tickPending && !state.suspended) {
409
480
  effects.push(tick(changed ? cadence : cadence / 2));
410
481
  tickPending = true;
411
482
  }
412
483
  return [_objectSpread2(_objectSpread2({}, state), {}, {
413
484
  failures,
485
+ blocking,
486
+ reports,
487
+ chained,
414
488
  lastEndSeq: endSeq,
415
489
  tickPending,
416
- inflight: null,
490
+ inflight: chains ? renditionId : null,
417
491
  awaitingTarget: false
418
492
  }), effects];
419
493
  }
@@ -434,4 +508,4 @@ function hlsLive(options = {}) {
434
508
  };
435
509
  }
436
510
  //#endregion
437
- export { hlsLive as default };
511
+ export { createReduceHlsLive, hlsLive as default };
@@ -0,0 +1,30 @@
1
+ import { MANIFEST_TYPES, createReduceHls } from "../hls-cmaf/index.js";
2
+ import { registerLiveNamespace } from "../live-shared.js";
3
+ import { createReduceHlsLive } from "../hls-live/index.js";
4
+ import { nextReload, parseLowLatency, reportsOf } from "./parse.js";
5
+ //#region src/protocols/hls-ll/index.ts
6
+ /** The stage factory. It provides `hls-cmaf` and `hls-live`, so stages that require either compose with it. */
7
+ function hlsLl(options = {}) {
8
+ var _options$unavailableR;
9
+ const retryMs = ((_options$unavailableR = options.unavailableRetrySeconds) !== null && _options$unavailableR !== void 0 ? _options$unavailableR : 15) * 1e3;
10
+ return {
11
+ name: "hls-ll",
12
+ provides: [
13
+ "hls-ll",
14
+ "hls-cmaf",
15
+ "hls-live",
16
+ ...MANIFEST_TYPES
17
+ ],
18
+ install(ctx) {
19
+ ctx.reduce("hls", createReduceHls(retryMs, parseLowLatency));
20
+ ctx.reduce("hls-live", createReduceHlsLive(retryMs, {
21
+ parse: parseLowLatency,
22
+ next: nextReload,
23
+ reports: reportsOf
24
+ }));
25
+ registerLiveNamespace(ctx);
26
+ }
27
+ };
28
+ }
29
+ //#endregion
30
+ export { hlsLl as default };
@@ -0,0 +1,240 @@
1
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/objectSpread2.js";
2
+ import { resolveUrl } from "../../kernel/url.js";
3
+ import { manifestError } from "../adapter-shared.js";
4
+ import { lex } from "../hls-cmaf/lexer.js";
5
+ import { parseByteRange, parseMediaLines } from "../hls-cmaf/parse.js";
6
+ //#region src/protocols/hls-ll/parse.ts
7
+ /**
8
+ * Low-latency HLS media playlists (RFC 8216bis §4.4.3.7, §4.4.3.8,
9
+ * §4.4.4.9, §4.4.5.2 to §4.4.5.4). The base parser reads the segments; this
10
+ * pass reads the parts, the preload hint, the rendition reports, and the
11
+ * delivery directives for the next reload. Pure.
12
+ *
13
+ * Near the edge each segment that lists its parts is replaced by them in
14
+ * the IR, one entry per part, so the kernel fetches and appends a part as
15
+ * soon as it exists. Servers drop a segment's parts once it is three target
16
+ * durations old (§6.2.2), by then far behind the playhead, and the full
17
+ * segment takes their place. A part's sequence number is its segment's plus
18
+ * the part index over PART_SCALE, so parts sort between segments and keep
19
+ * the same number across reloads.
20
+ */
21
+ /** Parts per segment the numbering leaves room for. */
22
+ const PART_SCALE = 1e3;
23
+ function partFrom(line, baseUrl, previous) {
24
+ const uri = line.attributes.URI;
25
+ const duration = Number(line.attributes.DURATION);
26
+ if (uri === void 0 || !(duration > 0)) return null;
27
+ const url = resolveUrl(uri, baseUrl);
28
+ const rangeText = line.attributes.BYTERANGE;
29
+ const byteRange = rangeText === void 0 ? null : parseByteRange(rangeText, (previous === null || previous === void 0 ? void 0 : previous.url) === url ? previous.end : null);
30
+ return _objectSpread2(_objectSpread2({
31
+ duration,
32
+ url
33
+ }, byteRange !== null ? { byteRange } : {}), {}, {
34
+ independent: line.attributes.INDEPENDENT === "YES",
35
+ gap: line.attributes.GAP === "YES"
36
+ });
37
+ }
38
+ /** EXT-X-DISCONTINUITY-SEQUENCE, 0 without the tag (RFC 8216 §4.3.3.3). */
39
+ function discontinuitySequenceOf(lines) {
40
+ for (const line of lines) if (line.kind === "tag" && line.name === "EXT-X-DISCONTINUITY-SEQUENCE") return Number(line.value) || 0;
41
+ return 0;
42
+ }
43
+ /** The URL with the delivery directives (RFC 8216bis §6.2.5) in their defined order. */
44
+ function withDirectives(url, position, skip) {
45
+ const params = [`_HLS_msn=${position.msn}`];
46
+ if (position.part !== void 0) params.push(`_HLS_part=${position.part}`);
47
+ if (skip !== null) params.push(`_HLS_skip=${skip}`);
48
+ return `${url}${url.includes("?") ? "&" : "?"}${params.join("&")}`;
49
+ }
50
+ /**
51
+ * A delta update's skipped segments, taken from the rendition's previous
52
+ * segments, with the listed ones moved onto the same timeline. Null when
53
+ * the previous segments do not hold every skipped one: the caller then
54
+ * reloads the whole playlist.
55
+ *
56
+ * The date ranges are the previous ones without those the server removed,
57
+ * merged by ID with the listed ones, as hls.js merges them: a `v2` delta
58
+ * leaves out the date ranges the client has.
59
+ */
60
+ function fillSkipped(playlist, skipped, previous, previousRanges) {
61
+ var _playlist$segments$0$, _playlist$segments$;
62
+ if (!Array.isArray(previous)) return null;
63
+ const first = playlist.mediaSequence;
64
+ const listedFrom = first + skipped;
65
+ const kept = previous.filter((s) => s.preload !== true && s.seq >= first && s.seq < listedFrom);
66
+ const have = new Set(kept.map((s) => Math.floor(s.seq)));
67
+ for (let seq = first; seq < listedFrom; seq += 1) if (!have.has(seq)) return null;
68
+ const last = kept[kept.length - 1];
69
+ const listedStart = (_playlist$segments$0$ = (_playlist$segments$ = playlist.segments[0]) === null || _playlist$segments$ === void 0 ? void 0 : _playlist$segments$.start) !== null && _playlist$segments$0$ !== void 0 ? _playlist$segments$0$ : 0;
70
+ const shift = last.start + last.duration - listedStart;
71
+ const anchor = playlist.dateAnchor;
72
+ return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, playlist), {}, { segments: [...kept, ...playlist.segments.map((s) => _objectSpread2(_objectSpread2({}, s), {}, { start: s.start + shift }))] }, anchor !== void 0 ? { dateAnchor: {
73
+ wallClock: anchor.wallClock,
74
+ presentationTime: anchor.presentationTime + shift
75
+ } } : {}), mergedRanges(playlist, previousRanges, shift)), {}, { skipped: 0 });
76
+ }
77
+ /** The delta's date ranges moved by `shift`, over the previous ones it keeps. */
78
+ function mergedRanges(playlist, previousRanges, shift) {
79
+ var _playlist$removedDate, _playlist$dateRanges;
80
+ const removed = new Set((_playlist$removedDate = playlist.removedDateRanges) !== null && _playlist$removedDate !== void 0 ? _playlist$removedDate : []);
81
+ const byId = /* @__PURE__ */ new Map();
82
+ for (const range of previousRanges) if (!removed.has(range.id)) byId.set(range.id, range);
83
+ for (const r of (_playlist$dateRanges = playlist.dateRanges) !== null && _playlist$dateRanges !== void 0 ? _playlist$dateRanges : []) byId.set(r.id, _objectSpread2(_objectSpread2(_objectSpread2({}, r), {}, { start: r.start + shift }, r.end !== void 0 ? { end: r.end + shift } : {}), r.plannedEnd !== void 0 ? { plannedEnd: r.plannedEnd + shift } : {}));
84
+ return byId.size > 0 ? { dateRanges: [...byId.values()] } : {};
85
+ }
86
+ /** The IR entries of one segment's parts, from `start` on. */
87
+ function partEntries(parts, seq, start, first, marksIndependent) {
88
+ const out = [];
89
+ let at = start;
90
+ parts.forEach((part, index) => {
91
+ out.push(_objectSpread2(_objectSpread2(_objectSpread2({}, index === 0 ? first : {}), {}, {
92
+ seq: seq + index / PART_SCALE,
93
+ start: at,
94
+ duration: part.duration,
95
+ url: part.url
96
+ }, part.byteRange !== void 0 ? { byteRange: part.byteRange } : {}), marksIndependent ? { independent: part.independent } : {}));
97
+ at += part.duration;
98
+ });
99
+ return out;
100
+ }
101
+ /**
102
+ * Parses a low-latency media playlist. `previous` is the rendition's
103
+ * segments now, for a delta update. When a delta update cannot be filled,
104
+ * the result keeps `skipped` above 0.
105
+ */
106
+ function parseLowLatency(text, baseUrl, previous = [], previousRanges = []) {
107
+ var _playlist$skipped, _playlist$serverContr;
108
+ if (!text.trimStart().startsWith("#EXTM3U")) return {
109
+ playlist: null,
110
+ error: manifestError("missing #EXTM3U")
111
+ };
112
+ const lines = lex(text);
113
+ const base = parseMediaLines(lines, baseUrl);
114
+ if (base.playlist === null) return base;
115
+ let playlist = base.playlist;
116
+ const skipped = (_playlist$skipped = playlist.skipped) !== null && _playlist$skipped !== void 0 ? _playlist$skipped : 0;
117
+ if (skipped > 0) {
118
+ const filled = fillSkipped(playlist, skipped, previous, previousRanges);
119
+ if (filled === null) return base;
120
+ playlist = filled;
121
+ }
122
+ let partTarget = 0;
123
+ let msn = base.playlist.mediaSequence + skipped;
124
+ let pending = [];
125
+ let lastPart = null;
126
+ let hint = null;
127
+ const partsBySeq = /* @__PURE__ */ new Map();
128
+ const reports = {};
129
+ for (const line of lines) {
130
+ if (line.kind === "uri") {
131
+ if (pending.length > 0) partsBySeq.set(msn, pending);
132
+ pending = [];
133
+ msn += 1;
134
+ continue;
135
+ }
136
+ const attributes = line.attributes;
137
+ switch (line.name) {
138
+ case "EXT-X-PART-INF":
139
+ partTarget = Number(attributes["PART-TARGET"]) || 0;
140
+ break;
141
+ case "EXT-X-PART": {
142
+ const part = partFrom(line, baseUrl, lastPart);
143
+ if (part === null) break;
144
+ pending.push(part);
145
+ lastPart = part.byteRange !== void 0 ? {
146
+ url: part.url,
147
+ end: part.byteRange.end
148
+ } : null;
149
+ break;
150
+ }
151
+ case "EXT-X-PRELOAD-HINT": {
152
+ const uri = attributes.URI;
153
+ if (attributes.TYPE !== "PART" || uri === void 0) break;
154
+ const start = Number(attributes["BYTERANGE-START"]);
155
+ const length = Number(attributes["BYTERANGE-LENGTH"]);
156
+ hint = _objectSpread2({ url: resolveUrl(uri, baseUrl) }, Number.isFinite(start) ? { byteRange: {
157
+ start,
158
+ end: length > 0 ? start + length - 1 : Infinity
159
+ } } : {});
160
+ break;
161
+ }
162
+ case "EXT-X-RENDITION-REPORT": {
163
+ const uri = attributes.URI;
164
+ const last = Number(attributes["LAST-MSN"]);
165
+ if (uri === void 0 || !Number.isFinite(last)) break;
166
+ const part = Number(attributes["LAST-PART"]);
167
+ reports[resolveUrl(uri, baseUrl)] = withDirectives(resolveUrl(uri, baseUrl), _objectSpread2({ msn: last }, Number.isFinite(part) ? { part } : {}), null);
168
+ break;
169
+ }
170
+ }
171
+ }
172
+ const trailing = pending;
173
+ const marksIndependent = [...partsBySeq.values(), trailing].some((parts) => parts.some((p) => p.independent));
174
+ const segments = [];
175
+ for (const segment of playlist.segments) {
176
+ var _parts$reduce;
177
+ const parts = partsBySeq.get(segment.seq);
178
+ const total = (_parts$reduce = parts === null || parts === void 0 ? void 0 : parts.reduce((sum, p) => sum + p.duration, 0)) !== null && _parts$reduce !== void 0 ? _parts$reduce : 0;
179
+ if (parts === void 0 || parts.some((p) => p.gap) || Math.abs(total - segment.duration) > .1 || segment.key !== void 0) {
180
+ segments.push(segment);
181
+ continue;
182
+ }
183
+ const first = _objectSpread2(_objectSpread2({}, segment.discontinuity === true ? { discontinuity: true } : {}), segment.discontinuitySequence !== void 0 ? { discontinuitySequence: segment.discontinuitySequence } : {});
184
+ segments.push(...partEntries(parts, segment.seq, segment.start, first, marksIndependent));
185
+ }
186
+ const lastSegment = playlist.segments[playlist.segments.length - 1];
187
+ const keyed = (lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.key) !== void 0;
188
+ const gapAt = trailing.findIndex((p) => p.gap);
189
+ const usable = keyed ? [] : gapAt === -1 ? trailing : trailing.slice(0, gapAt);
190
+ const edge = lastSegment === void 0 ? 0 : lastSegment.start + lastSegment.duration;
191
+ segments.push(...partEntries(usable, msn, edge, segments.length === 0 ? { discontinuitySequence: discontinuitySequenceOf(lines) } : {}, marksIndependent));
192
+ if (hint !== null && !keyed && gapAt === -1 && !playlist.endlist) {
193
+ var _last$duration;
194
+ const last = segments[segments.length - 1];
195
+ segments.push(_objectSpread2(_objectSpread2(_objectSpread2({
196
+ seq: msn + usable.length / PART_SCALE,
197
+ start: last === void 0 ? edge : last.start + last.duration,
198
+ duration: partTarget || ((_last$duration = last === null || last === void 0 ? void 0 : last.duration) !== null && _last$duration !== void 0 ? _last$duration : 1),
199
+ url: hint.url
200
+ }, hint.byteRange !== void 0 ? { byteRange: hint.byteRange } : {}), marksIndependent ? { independent: false } : {}), {}, { preload: true }));
201
+ }
202
+ const hasParts = partTarget > 0 && (partsBySeq.size > 0 || usable.length > 0);
203
+ const partHoldBack = Number((_playlist$serverContr = playlist.serverControl) === null || _playlist$serverContr === void 0 ? void 0 : _playlist$serverContr["PART-HOLD-BACK"]);
204
+ const holdBack = hasParts ? partHoldBack > 0 ? partHoldBack : 3 * partTarget : playlist.holdBack;
205
+ return {
206
+ playlist: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, playlist), {}, { segments }, holdBack !== void 0 ? { holdBack } : {}), hasParts ? { lowLatency: true } : {}), {}, {
207
+ partTarget,
208
+ next: partTarget > 0 ? {
209
+ msn,
210
+ part: usable.length
211
+ } : { msn },
212
+ reports
213
+ }),
214
+ error: null
215
+ };
216
+ }
217
+ /**
218
+ * The URL of the reload after `playlist`: a blocking request for the next
219
+ * part or segment, with a delta update when the server offers one and
220
+ * `skip` allows it. Null when the server does not hold requests
221
+ * (CAN-BLOCK-RELOAD absent): the playlist then reloads on the target
222
+ * duration cadence. Like hls.js, it asks for `v2` when the server can skip
223
+ * date ranges (CAN-SKIP-DATERANGES=YES), else `YES`.
224
+ */
225
+ function nextReload(url, playlist, skip) {
226
+ const control = playlist.serverControl;
227
+ if ((control === null || control === void 0 ? void 0 : control["CAN-BLOCK-RELOAD"]) !== "YES" || playlist.endlist) return null;
228
+ const next = playlist.next;
229
+ if (next === void 0) return null;
230
+ let request = null;
231
+ if (skip && Number(control["CAN-SKIP-UNTIL"]) > 0) request = control["CAN-SKIP-DATERANGES"] === "YES" ? "v2" : "YES";
232
+ return withDirectives(url, next, request);
233
+ }
234
+ /** The rendition reports of a parsed playlist. */
235
+ function reportsOf(playlist) {
236
+ var _reports;
237
+ return (_reports = playlist.reports) !== null && _reports !== void 0 ? _reports : {};
238
+ }
239
+ //#endregion
240
+ export { nextReload, parseLowLatency, reportsOf, withDirectives };
@@ -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 } from "../../kernel/effects.js";
3
3
  import { findRendition, isTrick } from "../../kernel/presentation.js";
4
4
  import { canSwitchTo } from "../../kernel/rendition-select.js";
@@ -100,7 +100,14 @@ function createEmergencyReducer(options) {
100
100
  if (msg.type === "UNLOAD" || msg.type === "DETACH") return [INITIAL, []];
101
101
  let raw = null;
102
102
  if (msg.type === "THROUGHPUT_SAMPLE") raw = msg.bps;
103
- else if (msg.type === "SEGMENT_LOADED" && msg.seq >= 0 && msg.trackId === leadTrack(kernel) && msg.rtt > 0 && msg.size >= MIN_SAMPLE_BYTES) raw = msg.size * 8e3 / msg.rtt;
103
+ else if (msg.type === "SEGMENT_LOADED" && msg.seq >= 0 && msg.trackId === leadTrack(kernel)) {
104
+ var _msg$transfer;
105
+ const sample = (_msg$transfer = msg.transfer) !== null && _msg$transfer !== void 0 ? _msg$transfer : {
106
+ bytes: msg.size,
107
+ ms: msg.rtt
108
+ };
109
+ if (sample.ms > 0 && sample.bytes >= MIN_SAMPLE_BYTES) raw = sample.bytes * 8e3 / sample.ms;
110
+ }
104
111
  if (raw === null) return [state, []];
105
112
  if (state.emergencyCap === null) {
106
113
  const bitrate = activeBitrate(kernel);
@@ -1,5 +1,5 @@
1
+ import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/asyncToGenerator.js";
1
2
  import { findRendition } from "../../kernel/presentation.js";
2
- import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/asyncToGenerator.js";
3
3
  //#region src/stages/aes-128/index.ts
4
4
  /**
5
5
  * aes-128 as a stage: full-segment AES-CBC decryption for HLS EXT-X-KEY