mattebox 0.6.1 → 0.7.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 (277) hide show
  1. package/dist/cdn/mattebox.dash-drm.min.js +3 -3
  2. package/dist/cdn/mattebox.dash.min.js +3 -3
  3. package/dist/cdn/mattebox.dual-drm.min.js +3 -3
  4. package/dist/cdn/mattebox.dual-ts-drm.min.js +3 -3
  5. package/dist/cdn/mattebox.dual-ts.min.js +3 -3
  6. package/dist/cdn/mattebox.dual.min.js +3 -3
  7. package/dist/cdn/mattebox.hls-drm.min.js +3 -3
  8. package/dist/cdn/mattebox.hls-ts-drm.min.js +3 -3
  9. package/dist/cdn/mattebox.hls-ts.min.js +3 -3
  10. package/dist/cdn/mattebox.hls.min.js +3 -3
  11. package/dist/cdn/mattebox.kernel.min.js +1 -1
  12. package/dist/cdn/mattebox.min.js +3 -6
  13. package/dist/containers/adts.d.ts +10 -0
  14. package/dist/containers/adts.d.ts.map +1 -1
  15. package/dist/containers/adts.js +27 -7
  16. package/dist/containers/adts.js.map +1 -1
  17. package/dist/containers/codec-probe/index.d.ts +0 -6
  18. package/dist/containers/codec-probe/index.d.ts.map +1 -1
  19. package/dist/containers/codec-probe/index.js +14 -23
  20. package/dist/containers/codec-probe/index.js.map +1 -1
  21. package/dist/containers/fmp4/fit.d.ts +26 -0
  22. package/dist/containers/fmp4/fit.d.ts.map +1 -0
  23. package/dist/containers/fmp4/fit.js +49 -0
  24. package/dist/containers/fmp4/fit.js.map +1 -0
  25. package/dist/containers/fmp4/writer.d.ts +7 -0
  26. package/dist/containers/fmp4/writer.d.ts.map +1 -1
  27. package/dist/containers/fmp4/writer.js +9 -1
  28. package/dist/containers/fmp4/writer.js.map +1 -1
  29. package/dist/containers/id3.d.ts.map +1 -1
  30. package/dist/containers/id3.js +2 -1
  31. package/dist/containers/id3.js.map +1 -1
  32. package/dist/containers/mp4-box/index.d.ts +66 -0
  33. package/dist/containers/mp4-box/index.d.ts.map +1 -1
  34. package/dist/containers/mp4-box/index.js +207 -23
  35. package/dist/containers/mp4-box/index.js.map +1 -1
  36. package/dist/containers/packed-audio/index.d.ts.map +1 -1
  37. package/dist/containers/packed-audio/index.js +4 -26
  38. package/dist/containers/packed-audio/index.js.map +1 -1
  39. package/dist/containers/sei.d.ts +5 -0
  40. package/dist/containers/sei.d.ts.map +1 -1
  41. package/dist/containers/sei.js +5 -2
  42. package/dist/containers/sei.js.map +1 -1
  43. package/dist/containers/ts-transmux/demux.d.ts +7 -1
  44. package/dist/containers/ts-transmux/demux.d.ts.map +1 -1
  45. package/dist/containers/ts-transmux/demux.js +38 -17
  46. package/dist/containers/ts-transmux/demux.js.map +1 -1
  47. package/dist/containers/ts-transmux/h264.d.ts.map +1 -1
  48. package/dist/containers/ts-transmux/h264.js +1 -17
  49. package/dist/containers/ts-transmux/h264.js.map +1 -1
  50. package/dist/containers/ts-transmux/index.d.ts.map +1 -1
  51. package/dist/containers/ts-transmux/index.js +9 -1
  52. package/dist/containers/ts-transmux/index.js.map +1 -1
  53. package/dist/containers/ts-transmux/transmux.d.ts.map +1 -1
  54. package/dist/containers/ts-transmux/transmux.js +6 -36
  55. package/dist/containers/ts-transmux/transmux.js.map +1 -1
  56. package/dist/{stages/text-webvtt/parse.d.ts → containers/webvtt.d.ts} +4 -3
  57. package/dist/containers/webvtt.d.ts.map +1 -0
  58. package/dist/{stages/text-webvtt/parse.js → containers/webvtt.js} +1 -1
  59. package/dist/containers/webvtt.js.map +1 -0
  60. package/dist/es2015/containers/adts.js +28 -8
  61. package/dist/es2015/containers/codec-probe/index.js +17 -26
  62. package/dist/es2015/containers/fmp4/fit.js +46 -0
  63. package/dist/es2015/containers/fmp4/writer.js +9 -1
  64. package/dist/es2015/containers/id3.js +2 -2
  65. package/dist/es2015/containers/mp4-box/index.js +207 -19
  66. package/dist/es2015/containers/packed-audio/index.js +4 -28
  67. package/dist/es2015/containers/sei.js +6 -3
  68. package/dist/es2015/containers/ts-transmux/demux.js +41 -22
  69. package/dist/es2015/containers/ts-transmux/h264.js +1 -17
  70. package/dist/es2015/containers/ts-transmux/index.js +6 -3
  71. package/dist/es2015/containers/ts-transmux/transmux.js +8 -39
  72. package/dist/es2015/{stages/text-webvtt/parse.js → containers/webvtt.js} +2 -2
  73. package/dist/es2015/index.js +6 -15
  74. package/dist/es2015/kernel/base64.js +25 -0
  75. package/dist/es2015/kernel/effects.js +21 -1
  76. package/dist/es2015/kernel/mime.js +5 -1
  77. package/dist/es2015/kernel/presentation.js +24 -0
  78. package/dist/es2015/kernel/reducer.js +61 -75
  79. package/dist/es2015/kernel/refresh.js +1 -1
  80. package/dist/es2015/kernel/rendition-select.js +50 -5
  81. package/dist/es2015/kernel/sinks/text-track-sink.js +27 -26
  82. package/dist/es2015/kernel/timeline.js +1 -1
  83. package/dist/es2015/kernel/track-registry.js +10 -2
  84. package/dist/es2015/kernel/url.js +12 -0
  85. package/dist/es2015/presets/full/index.js +9 -3
  86. package/dist/es2015/protocols/adapter-shared.js +28 -0
  87. package/dist/es2015/protocols/dash-cmaf/index.js +18 -55
  88. package/dist/es2015/protocols/dash-cmaf/parse.js +60 -54
  89. package/dist/es2015/protocols/dash-live/index.js +13 -28
  90. package/dist/es2015/protocols/dimensions.js +15 -0
  91. package/dist/es2015/protocols/hls-cmaf/index.js +17 -52
  92. package/dist/es2015/protocols/hls-cmaf/lexer.js +3 -0
  93. package/dist/es2015/protocols/hls-cmaf/parse.js +134 -33
  94. package/dist/es2015/protocols/hls-cmaf/unavailable.js +2 -1
  95. package/dist/es2015/protocols/hls-live/index.js +24 -52
  96. package/dist/es2015/stages/abr/index.js +7 -10
  97. package/dist/es2015/stages/abr-persist/index.js +17 -10
  98. package/dist/es2015/stages/aes-128/index.js +14 -7
  99. package/dist/es2015/stages/alt-audio/index.js +24 -12
  100. package/dist/es2015/stages/chapters/index.js +151 -0
  101. package/dist/es2015/stages/chapters/parse.js +149 -0
  102. package/dist/es2015/stages/cmcd/index.js +14 -4
  103. package/dist/es2015/stages/codec-switch/index.js +2 -5
  104. package/dist/es2015/stages/content-steering/index.js +12 -15
  105. package/dist/es2015/stages/eme-cenc/index.js +10 -4
  106. package/dist/es2015/stages/eme-core/index.js +29 -11
  107. package/dist/es2015/stages/eme-fairplay/index.js +11 -7
  108. package/dist/es2015/stages/nal-scan/index.js +30 -140
  109. package/dist/es2015/stages/recovery/index.js +46 -53
  110. package/dist/es2015/stages/text-cea608/index.js +3 -17
  111. package/dist/es2015/stages/text-webvtt/index.js +1 -1
  112. package/dist/es2015/stages/text-webvtt-segmented/index.js +15 -8
  113. package/dist/es2015/stages/thumbnails/index.js +212 -42
  114. package/dist/es2015/stages/trick-play/index.js +463 -0
  115. package/dist/index.d.ts +6 -0
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +5 -21
  118. package/dist/index.js.map +1 -1
  119. package/dist/kernel/base64.d.ts +9 -0
  120. package/dist/kernel/base64.d.ts.map +1 -0
  121. package/dist/kernel/base64.js +26 -0
  122. package/dist/kernel/base64.js.map +1 -0
  123. package/dist/kernel/effects.d.ts +9 -1
  124. package/dist/kernel/effects.d.ts.map +1 -1
  125. package/dist/kernel/effects.js +12 -0
  126. package/dist/kernel/effects.js.map +1 -1
  127. package/dist/kernel/lifecycle.js +1 -1
  128. package/dist/kernel/lifecycle.js.map +1 -1
  129. package/dist/kernel/mime.d.ts +2 -0
  130. package/dist/kernel/mime.d.ts.map +1 -1
  131. package/dist/kernel/mime.js +4 -0
  132. package/dist/kernel/mime.js.map +1 -1
  133. package/dist/kernel/presentation.d.ts +20 -0
  134. package/dist/kernel/presentation.d.ts.map +1 -0
  135. package/dist/kernel/presentation.js +25 -0
  136. package/dist/kernel/presentation.js.map +1 -0
  137. package/dist/kernel/reducer.d.ts +9 -0
  138. package/dist/kernel/reducer.d.ts.map +1 -1
  139. package/dist/kernel/reducer.js +72 -84
  140. package/dist/kernel/reducer.js.map +1 -1
  141. package/dist/kernel/refresh.d.ts.map +1 -1
  142. package/dist/kernel/refresh.js +1 -0
  143. package/dist/kernel/refresh.js.map +1 -1
  144. package/dist/kernel/rendition-select.d.ts +19 -4
  145. package/dist/kernel/rendition-select.d.ts.map +1 -1
  146. package/dist/kernel/rendition-select.js +67 -4
  147. package/dist/kernel/rendition-select.js.map +1 -1
  148. package/dist/kernel/sinks/text-track-sink.d.ts +9 -0
  149. package/dist/kernel/sinks/text-track-sink.d.ts.map +1 -1
  150. package/dist/kernel/sinks/text-track-sink.js +29 -29
  151. package/dist/kernel/sinks/text-track-sink.js.map +1 -1
  152. package/dist/kernel/timeline.d.ts +8 -1
  153. package/dist/kernel/timeline.d.ts.map +1 -1
  154. package/dist/kernel/timeline.js +2 -2
  155. package/dist/kernel/timeline.js.map +1 -1
  156. package/dist/kernel/track-registry.d.ts.map +1 -1
  157. package/dist/kernel/track-registry.js +17 -1
  158. package/dist/kernel/track-registry.js.map +1 -1
  159. package/dist/kernel/url.d.ts +4 -0
  160. package/dist/kernel/url.d.ts.map +1 -0
  161. package/dist/kernel/url.js +11 -0
  162. package/dist/kernel/url.js.map +1 -0
  163. package/dist/presets/full/index.d.ts.map +1 -1
  164. package/dist/presets/full/index.js +8 -2
  165. package/dist/presets/full/index.js.map +1 -1
  166. package/dist/protocols/adapter-shared.d.ts +23 -0
  167. package/dist/protocols/adapter-shared.d.ts.map +1 -0
  168. package/dist/protocols/adapter-shared.js +23 -0
  169. package/dist/protocols/adapter-shared.js.map +1 -0
  170. package/dist/protocols/dash-cmaf/index.d.ts.map +1 -1
  171. package/dist/protocols/dash-cmaf/index.js +17 -73
  172. package/dist/protocols/dash-cmaf/index.js.map +1 -1
  173. package/dist/protocols/dash-cmaf/parse.d.ts +2 -5
  174. package/dist/protocols/dash-cmaf/parse.d.ts.map +1 -1
  175. package/dist/protocols/dash-cmaf/parse.js +46 -39
  176. package/dist/protocols/dash-cmaf/parse.js.map +1 -1
  177. package/dist/protocols/dash-live/index.d.ts.map +1 -1
  178. package/dist/protocols/dash-live/index.js +13 -17
  179. package/dist/protocols/dash-live/index.js.map +1 -1
  180. package/dist/protocols/dimensions.d.ts +8 -0
  181. package/dist/protocols/dimensions.d.ts.map +1 -0
  182. package/dist/protocols/dimensions.js +13 -0
  183. package/dist/protocols/dimensions.js.map +1 -0
  184. package/dist/protocols/hls-cmaf/index.d.ts.map +1 -1
  185. package/dist/protocols/hls-cmaf/index.js +17 -56
  186. package/dist/protocols/hls-cmaf/index.js.map +1 -1
  187. package/dist/protocols/hls-cmaf/lexer.d.ts.map +1 -1
  188. package/dist/protocols/hls-cmaf/lexer.js +3 -0
  189. package/dist/protocols/hls-cmaf/lexer.js.map +1 -1
  190. package/dist/protocols/hls-cmaf/parse.d.ts +13 -9
  191. package/dist/protocols/hls-cmaf/parse.d.ts.map +1 -1
  192. package/dist/protocols/hls-cmaf/parse.js +146 -22
  193. package/dist/protocols/hls-cmaf/parse.js.map +1 -1
  194. package/dist/protocols/hls-cmaf/unavailable.d.ts.map +1 -1
  195. package/dist/protocols/hls-cmaf/unavailable.js +3 -1
  196. package/dist/protocols/hls-cmaf/unavailable.js.map +1 -1
  197. package/dist/protocols/hls-live/index.d.ts.map +1 -1
  198. package/dist/protocols/hls-live/index.js +17 -52
  199. package/dist/protocols/hls-live/index.js.map +1 -1
  200. package/dist/stages/abr/index.d.ts.map +1 -1
  201. package/dist/stages/abr/index.js +8 -14
  202. package/dist/stages/abr/index.js.map +1 -1
  203. package/dist/stages/abr-cap-size/index.d.ts +1 -1
  204. package/dist/stages/abr-persist/index.d.ts.map +1 -1
  205. package/dist/stages/abr-persist/index.js +17 -7
  206. package/dist/stages/abr-persist/index.js.map +1 -1
  207. package/dist/stages/aes-128/index.d.ts +0 -9
  208. package/dist/stages/aes-128/index.d.ts.map +1 -1
  209. package/dist/stages/aes-128/index.js +13 -11
  210. package/dist/stages/aes-128/index.js.map +1 -1
  211. package/dist/stages/alt-audio/index.d.ts +16 -0
  212. package/dist/stages/alt-audio/index.d.ts.map +1 -1
  213. package/dist/stages/alt-audio/index.js +23 -12
  214. package/dist/stages/alt-audio/index.js.map +1 -1
  215. package/dist/stages/chapters/index.d.ts +20 -0
  216. package/dist/stages/chapters/index.d.ts.map +1 -0
  217. package/dist/stages/chapters/index.js +141 -0
  218. package/dist/stages/chapters/index.js.map +1 -0
  219. package/dist/stages/chapters/parse.d.ts +47 -0
  220. package/dist/stages/chapters/parse.d.ts.map +1 -0
  221. package/dist/stages/chapters/parse.js +168 -0
  222. package/dist/stages/chapters/parse.js.map +1 -0
  223. package/dist/stages/cmcd/index.d.ts +0 -11
  224. package/dist/stages/cmcd/index.d.ts.map +1 -1
  225. package/dist/stages/cmcd/index.js +15 -9
  226. package/dist/stages/cmcd/index.js.map +1 -1
  227. package/dist/stages/codec-switch/index.d.ts.map +1 -1
  228. package/dist/stages/codec-switch/index.js +3 -8
  229. package/dist/stages/codec-switch/index.js.map +1 -1
  230. package/dist/stages/content-steering/index.d.ts.map +1 -1
  231. package/dist/stages/content-steering/index.js +12 -9
  232. package/dist/stages/content-steering/index.js.map +1 -1
  233. package/dist/stages/eme-cenc/index.d.ts +0 -7
  234. package/dist/stages/eme-cenc/index.d.ts.map +1 -1
  235. package/dist/stages/eme-cenc/index.js +9 -5
  236. package/dist/stages/eme-cenc/index.js.map +1 -1
  237. package/dist/stages/eme-core/index.d.ts.map +1 -1
  238. package/dist/stages/eme-core/index.js +31 -15
  239. package/dist/stages/eme-core/index.js.map +1 -1
  240. package/dist/stages/eme-fairplay/index.d.ts +0 -7
  241. package/dist/stages/eme-fairplay/index.d.ts.map +1 -1
  242. package/dist/stages/eme-fairplay/index.js +11 -9
  243. package/dist/stages/eme-fairplay/index.js.map +1 -1
  244. package/dist/stages/nal-scan/index.d.ts.map +1 -1
  245. package/dist/stages/nal-scan/index.js +32 -145
  246. package/dist/stages/nal-scan/index.js.map +1 -1
  247. package/dist/stages/recovery/index.d.ts.map +1 -1
  248. package/dist/stages/recovery/index.js +42 -56
  249. package/dist/stages/recovery/index.js.map +1 -1
  250. package/dist/stages/text-cea608/index.d.ts +11 -0
  251. package/dist/stages/text-cea608/index.d.ts.map +1 -1
  252. package/dist/stages/text-cea608/index.js +3 -23
  253. package/dist/stages/text-cea608/index.js.map +1 -1
  254. package/dist/stages/text-webvtt/index.d.ts +12 -0
  255. package/dist/stages/text-webvtt/index.d.ts.map +1 -1
  256. package/dist/stages/text-webvtt/index.js +1 -1
  257. package/dist/stages/text-webvtt/index.js.map +1 -1
  258. package/dist/stages/text-webvtt-segmented/index.d.ts.map +1 -1
  259. package/dist/stages/text-webvtt-segmented/index.js +11 -8
  260. package/dist/stages/text-webvtt-segmented/index.js.map +1 -1
  261. package/dist/stages/thumbnails/index.d.ts +39 -10
  262. package/dist/stages/thumbnails/index.d.ts.map +1 -1
  263. package/dist/stages/thumbnails/index.js +220 -30
  264. package/dist/stages/thumbnails/index.js.map +1 -1
  265. package/dist/stages/trick-play/index.d.ts +51 -0
  266. package/dist/stages/trick-play/index.d.ts.map +1 -0
  267. package/dist/stages/trick-play/index.js +480 -0
  268. package/dist/stages/trick-play/index.js.map +1 -0
  269. package/dist/types/ir.d.ts +40 -1
  270. package/dist/types/ir.d.ts.map +1 -1
  271. package/dist/types/kernel.d.ts +2 -0
  272. package/dist/types/kernel.d.ts.map +1 -1
  273. package/dist/types/messages.d.ts +12 -1
  274. package/dist/types/messages.d.ts.map +1 -1
  275. package/package.json +1 -1
  276. package/dist/stages/text-webvtt/parse.d.ts.map +0 -1
  277. package/dist/stages/text-webvtt/parse.js.map +0 -1
@@ -1,22 +1,9 @@
1
1
  import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
+ import { resolveUrl } from "../../kernel/url.js";
3
+ import { manifestError } from "../adapter-shared.js";
4
+ import { dimensions } from "../dimensions.js";
2
5
  import { lex } from "./lexer.js";
3
6
  //#region src/protocols/hls-cmaf/parse.ts
4
- function manifestError(reason) {
5
- return {
6
- category: "manifest",
7
- code: "MANIFEST_PARSE_FAILED",
8
- fatal: true,
9
- recoverable: false,
10
- context: { reason }
11
- };
12
- }
13
- function resolve(uri, baseUrl) {
14
- try {
15
- return new URL(uri, baseUrl).href;
16
- } catch (_unused) {
17
- return uri;
18
- }
19
- }
20
7
  /** n@o or n (continuing after the previous range). RFC 8216 §4.3.2.2. */
21
8
  function parseByteRange(value, previousEnd) {
22
9
  const [lengthText, offsetText] = value.split("@");
@@ -39,7 +26,7 @@ function segmentKeyFrom(key, baseUrl) {
39
26
  const iv = key.attributes.IV;
40
27
  return _objectSpread2({
41
28
  method: "AES-128",
42
- uri: resolve(key.attributes.URI, baseUrl)
29
+ uri: resolveUrl(key.attributes.URI, baseUrl)
43
30
  }, iv !== void 0 ? { iv: iv.replace(/^0x/i, "").toLowerCase().padStart(32, "0") } : {});
44
31
  }
45
32
  function protectionFrom(key, baseUrl) {
@@ -50,13 +37,30 @@ function protectionFrom(key, baseUrl) {
50
37
  systemId: (_key$attributes$KEYFO = key.attributes.KEYFORMAT) !== null && _key$attributes$KEYFO !== void 0 ? _key$attributes$KEYFO : null,
51
38
  scheme: method.toLowerCase(),
52
39
  keyId: (_key$attributes$KEYID = key.attributes.KEYID) !== null && _key$attributes$KEYID !== void 0 ? _key$attributes$KEYID : null,
53
- licenseUrl: key.attributes.URI !== void 0 ? resolve(key.attributes.URI, baseUrl) : null,
40
+ licenseUrl: key.attributes.URI !== void 0 ? resolveUrl(key.attributes.URI, baseUrl) : null,
54
41
  initData: null,
55
42
  initDataType: null
56
43
  }] };
57
44
  }
58
45
  const AUDIO_CODECS = /^(mp4a|ac-3|ec-3|opus|flac)/i;
59
46
  /**
47
+ * A tile grid from LAYOUT="CxR" and a tile RESOLUTION, both from the Roku
48
+ * image-playlist specification (EXT-X-IMAGE-STREAM-INF, EXT-X-TILES).
49
+ * DURATION, when present, is the seconds each tile covers.
50
+ */
51
+ function tileGridFrom(attributes) {
52
+ const layout = dimensions(attributes.LAYOUT);
53
+ const size = dimensions(attributes.RESOLUTION);
54
+ if (layout === null || size === null) return null;
55
+ const duration = Number(attributes.DURATION);
56
+ return _objectSpread2({
57
+ columns: layout[0],
58
+ rows: layout[1],
59
+ width: size[0],
60
+ height: size[1]
61
+ }, duration > 0 ? { duration } : {});
62
+ }
63
+ /**
60
64
  * Rewrites the legacy decimal AVC codec form some packagers still emit into
61
65
  * the RFC 6381 hex form MSE demands. `avc1.66.30` (profile 66, level 30) is
62
66
  * accepted by Firefox but rejected by Chrome's isTypeSupported, which is why a
@@ -107,6 +111,7 @@ function parseMediaPlaylist(text, baseUrl) {
107
111
  let playlistType = null;
108
112
  let protection = null;
109
113
  let pendingKey = null;
114
+ let tiles = null;
110
115
  let dateAnchor;
111
116
  let pendingDate = null;
112
117
  let pendingDuration = null;
@@ -146,7 +151,7 @@ function parseMediaPlaylist(text, baseUrl) {
146
151
  const uri = line.attributes.URI;
147
152
  if (uri !== void 0) {
148
153
  const range = line.attributes.BYTERANGE !== void 0 ? parseByteRange(line.attributes.BYTERANGE, null) : null;
149
- init = _objectSpread2({ url: resolve(uri, baseUrl) }, range !== null ? { byteRange: range } : {});
154
+ init = _objectSpread2({ url: resolveUrl(uri, baseUrl) }, range !== null ? { byteRange: range } : {});
150
155
  }
151
156
  break;
152
157
  }
@@ -160,6 +165,9 @@ function parseMediaPlaylist(text, baseUrl) {
160
165
  if (Number.isFinite(parsed)) pendingDate = parsed / 1e3;
161
166
  break;
162
167
  }
168
+ case "EXT-X-TILES":
169
+ var _tiles;
170
+ tiles = (_tiles = tiles) !== null && _tiles !== void 0 ? _tiles : tileGridFrom(line.attributes);
163
171
  }
164
172
  continue;
165
173
  }
@@ -176,7 +184,7 @@ function parseMediaPlaylist(text, baseUrl) {
176
184
  seq,
177
185
  start,
178
186
  duration: pendingDuration,
179
- url: resolve(line.uri, baseUrl)
187
+ url: resolveUrl(line.uri, baseUrl)
180
188
  }, pendingRange !== null ? { byteRange: pendingRange } : {}), pendingDiscontinuity ? { discontinuity: true } : {}), pendingKey !== null ? { key: pendingKey } : {}));
181
189
  previousRangeEnd = pendingRange !== null ? pendingRange.end : previousRangeEnd;
182
190
  start += pendingDuration;
@@ -186,7 +194,7 @@ function parseMediaPlaylist(text, baseUrl) {
186
194
  pendingDiscontinuity = false;
187
195
  }
188
196
  return {
189
- playlist: _objectSpread2({
197
+ playlist: _objectSpread2(_objectSpread2({
190
198
  segments,
191
199
  init,
192
200
  targetDuration,
@@ -194,7 +202,7 @@ function parseMediaPlaylist(text, baseUrl) {
194
202
  endlist,
195
203
  playlistType,
196
204
  protection
197
- }, dateAnchor !== void 0 ? { dateAnchor } : {}),
205
+ }, dateAnchor !== void 0 ? { dateAnchor } : {}), tiles !== null ? { tiles } : {}),
198
206
  error: null
199
207
  };
200
208
  }
@@ -203,6 +211,87 @@ function mediaContentType(type) {
203
211
  if (type === "SUBTITLES") return "text";
204
212
  return null;
205
213
  }
214
+ /**
215
+ * The rendition fields a tag with a URI attribute declares: the Roku
216
+ * EXT-X-IMAGE-STREAM-INF and the RFC 8216 §4.3.4.3 EXT-X-I-FRAME-STREAM-INF.
217
+ * RESOLUTION names the rendition, BANDWIDTH when it is missing.
218
+ */
219
+ function uriStreamRendition(attributes, prefix, baseUrl) {
220
+ var _attributes$RESOLUTIO;
221
+ if (attributes.URI === void 0) return null;
222
+ const size = dimensions(attributes.RESOLUTION);
223
+ return _objectSpread2({
224
+ id: `${prefix}-${(_attributes$RESOLUTIO = attributes.RESOLUTION) !== null && _attributes$RESOLUTIO !== void 0 ? _attributes$RESOLUTIO : attributes.BANDWIDTH}`,
225
+ bitrate: Number(attributes.BANDWIDTH) || 0,
226
+ playlistUrl: resolveUrl(attributes.URI, baseUrl)
227
+ }, size !== null ? {
228
+ width: size[0],
229
+ height: size[1]
230
+ } : {});
231
+ }
232
+ /**
233
+ * Image playlists (Roku EXT-X-IMAGE-STREAM-INF) as one image track, one
234
+ * rendition per playlist. RESOLUTION is the size of one tile. The grid is
235
+ * known here only when the tag carries LAYOUT; otherwise it arrives with the
236
+ * media playlist's EXT-X-TILES. The kernel schedules no image track; the
237
+ * thumbnails stage reads it.
238
+ */
239
+ function imageTrack(streams, baseUrl) {
240
+ const renditions = [];
241
+ for (const { attributes } of streams) {
242
+ var _attributes$CODECS, _attributes$CODECS2;
243
+ const base = uriStreamRendition(attributes, "i", baseUrl);
244
+ if (base === null || renditions.some((r) => r.id === base.id)) continue;
245
+ const tiles = tileGridFrom(attributes);
246
+ renditions.push(_objectSpread2(_objectSpread2({}, base), {}, {
247
+ codecs: (_attributes$CODECS = attributes.CODECS) !== null && _attributes$CODECS !== void 0 ? _attributes$CODECS : null,
248
+ mimeType: /png/i.test((_attributes$CODECS2 = attributes.CODECS) !== null && _attributes$CODECS2 !== void 0 ? _attributes$CODECS2 : "") ? "image/png" : "image/jpeg",
249
+ segments: []
250
+ }, tiles !== null ? { tiles } : {}));
251
+ }
252
+ const first = renditions[0];
253
+ if (first === void 0) return null;
254
+ return {
255
+ id: "image-main",
256
+ contentType: "image",
257
+ mimeType: first.mimeType,
258
+ protection: null,
259
+ renditions
260
+ };
261
+ }
262
+ /**
263
+ * I-frame playlists (RFC 8216 §4.3.4.3) as one video track with role
264
+ * 'trick'. Their media playlists carry EXT-X-I-FRAMES-ONLY and byte ranges
265
+ * into the normal segments. Normal playback never selects the track.
266
+ */
267
+ function trickTrack(streams, baseUrl, protection) {
268
+ const renditions = [];
269
+ for (const { attributes } of streams) {
270
+ const base = uriStreamRendition(attributes, "t", baseUrl);
271
+ if (base === null || renditions.some((r) => r.id === base.id)) continue;
272
+ const pathway = attributes["PATHWAY-ID"];
273
+ renditions.push(_objectSpread2(_objectSpread2({}, base), {}, {
274
+ codecs: splitCodecs(attributes.CODECS).video,
275
+ mimeType: "video/mp4",
276
+ segments: []
277
+ }, pathway !== void 0 ? { pathway } : {}));
278
+ }
279
+ if (renditions.length === 0) return null;
280
+ return {
281
+ id: "video-trick",
282
+ contentType: "video",
283
+ mimeType: "video/mp4",
284
+ role: "trick",
285
+ protection,
286
+ renditions
287
+ };
288
+ }
289
+ /** RFC 8216 §4.3.4.4: DATA-ID is required, with VALUE or URI, and an optional LANGUAGE. */
290
+ function sessionDataFrom(attributes, baseUrl) {
291
+ const id = attributes["DATA-ID"];
292
+ if (id === void 0) return null;
293
+ 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 } : {});
294
+ }
206
295
  /** parse either playlist form into a Presentation. Never throws. */
207
296
  function parse(text, baseUrl) {
208
297
  if (!text.trimStart().startsWith("#EXTM3U")) return {
@@ -263,6 +352,9 @@ function parse(text, baseUrl) {
263
352
  }
264
353
  const mediaEntries = [];
265
354
  const variants = [];
355
+ const imageStreams = [];
356
+ const iframeStreams = [];
357
+ const sessionData = [];
266
358
  let sessionProtection = null;
267
359
  let steering;
268
360
  let pendingStreamInf = null;
@@ -275,22 +367,27 @@ function parse(text, baseUrl) {
275
367
  groupId: (_line$attributes$GROU = line.attributes["GROUP-ID"]) !== null && _line$attributes$GROU !== void 0 ? _line$attributes$GROU : "",
276
368
  name: (_line$attributes$NAME = line.attributes.NAME) !== null && _line$attributes$NAME !== void 0 ? _line$attributes$NAME : "",
277
369
  attributes: line.attributes,
278
- uri: line.attributes.URI !== void 0 ? resolve(line.attributes.URI, baseUrl) : null
370
+ uri: line.attributes.URI !== void 0 ? resolveUrl(line.attributes.URI, baseUrl) : null
279
371
  });
280
372
  } else if (line.name === "EXT-X-STREAM-INF") pendingStreamInf = line;
281
- else if (line.name === "EXT-X-SESSION-KEY") {
373
+ else if (line.name === "EXT-X-IMAGE-STREAM-INF") imageStreams.push(line);
374
+ else if (line.name === "EXT-X-I-FRAME-STREAM-INF") iframeStreams.push(line);
375
+ else if (line.name === "EXT-X-SESSION-DATA") {
376
+ const entry = sessionDataFrom(line.attributes, baseUrl);
377
+ if (entry !== null) sessionData.push(entry);
378
+ } else if (line.name === "EXT-X-SESSION-KEY") {
282
379
  var _protectionFrom2;
283
380
  sessionProtection = (_protectionFrom2 = protectionFrom(line, baseUrl)) !== null && _protectionFrom2 !== void 0 ? _protectionFrom2 : sessionProtection;
284
381
  } else if (line.name === "EXT-X-CONTENT-STEERING") {
285
382
  const serverUri = line.attributes["SERVER-URI"];
286
- if (serverUri !== void 0) steering = _objectSpread2({ serverUri: resolve(serverUri, baseUrl) }, line.attributes["PATHWAY-ID"] !== void 0 ? { defaultPathway: line.attributes["PATHWAY-ID"] } : {});
383
+ if (serverUri !== void 0) steering = _objectSpread2({ serverUri: resolveUrl(serverUri, baseUrl) }, line.attributes["PATHWAY-ID"] !== void 0 ? { defaultPathway: line.attributes["PATHWAY-ID"] } : {});
287
384
  }
288
385
  continue;
289
386
  }
290
387
  if (pendingStreamInf !== null) {
291
388
  variants.push({
292
389
  attributes: pendingStreamInf.attributes,
293
- uri: resolve(line.uri, baseUrl)
390
+ uri: resolveUrl(line.uri, baseUrl)
294
391
  });
295
392
  pendingStreamInf = null;
296
393
  }
@@ -303,9 +400,9 @@ function parse(text, baseUrl) {
303
400
  const audioOnlyVariants = [];
304
401
  const couplings = [];
305
402
  for (const variant of variants) {
403
+ var _dimensions;
306
404
  const bandwidth = Number(variant.attributes.BANDWIDTH) || 0;
307
- const resolution = variant.attributes.RESOLUTION;
308
- const [width, height] = resolution !== void 0 ? resolution.split("x").map((n) => Number(n)) : [];
405
+ const [width, height] = (_dimensions = dimensions(variant.attributes.RESOLUTION)) !== null && _dimensions !== void 0 ? _dimensions : [];
309
406
  const { video, audio } = splitCodecs(variant.attributes.CODECS);
310
407
  if (video === null && audio !== null) {
311
408
  audioOnlyVariants.push(variant);
@@ -324,7 +421,7 @@ function parse(text, baseUrl) {
324
421
  mimeType: "video/mp4",
325
422
  segments: [],
326
423
  playlistUrl: variant.uri
327
- }, pathway !== void 0 ? { pathway } : {}), width !== void 0 && Number.isFinite(width) ? { width } : {}), height !== void 0 && Number.isFinite(height) ? { height } : {}), Number.isFinite(frameRate) ? { frameRate } : {}));
424
+ }, pathway !== void 0 ? { pathway } : {}), width !== void 0 ? { width } : {}), height !== void 0 ? { height } : {}), Number.isFinite(frameRate) ? { frameRate } : {}));
328
425
  const requires = {};
329
426
  if (variant.attributes.AUDIO !== void 0) requires.audio = variant.attributes.AUDIO;
330
427
  if (variant.attributes.SUBTITLES !== void 0) requires.text = variant.attributes.SUBTITLES;
@@ -385,8 +482,12 @@ function parse(text, baseUrl) {
385
482
  playlistUrl: entry.uri
386
483
  }] }));
387
484
  }
485
+ const trick = trickTrack(iframeStreams, baseUrl, sessionProtection);
486
+ if (trick !== null) tracks.push(trick);
487
+ const images = imageTrack(imageStreams, baseUrl);
488
+ if (images !== null) tracks.push(images);
388
489
  return {
389
- presentation: _objectSpread2({
490
+ presentation: _objectSpread2(_objectSpread2({
390
491
  id: baseUrl,
391
492
  isLive: false,
392
493
  periods: [{
@@ -395,7 +496,7 @@ function parse(text, baseUrl) {
395
496
  tracks
396
497
  }],
397
498
  couplings
398
- }, steering !== void 0 ? { steering } : {}),
499
+ }, steering !== void 0 ? { steering } : {}), sessionData.length > 0 ? { sessionData } : {}),
399
500
  error: null
400
501
  };
401
502
  }
@@ -449,13 +550,13 @@ function refreshFor(presentation, renditionId, playlist) {
449
550
  if (knownLast !== void 0 && incomingLast !== void 0 && !playlist.endlist && incomingLast.seq < knownLast.seq) return null;
450
551
  const shift = timelineShift(!playlist.endlist && knownLast === void 0 && sibling.length > 0 ? sibling : previous, playlist.segments);
451
552
  const segments = shift === 0 ? playlist.segments : playlist.segments.map((s) => _objectSpread2(_objectSpread2({}, s), {}, { start: s.start + shift }));
452
- return _objectSpread2(_objectSpread2(_objectSpread2({
553
+ return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
453
554
  type: "PLAYLIST_REFRESHED",
454
555
  trackId: renditionId,
455
556
  renditionId,
456
557
  mediaSequence: playlist.mediaSequence,
457
558
  segments
458
- }, playlist.init !== null ? { init: playlist.init } : {}), {}, {
559
+ }, playlist.init !== null ? { init: playlist.init } : {}), playlist.tiles !== void 0 ? { tiles: playlist.tiles } : {}), {}, {
459
560
  protection: playlist.protection,
460
561
  endlist: playlist.endlist
461
562
  }, playlist.endlist ? {} : { updatePeriod: playlist.targetDuration || 4 }), playlist.dateAnchor !== void 0 ? { dateAnchor: {
@@ -1,4 +1,5 @@
1
1
  import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
+ import { isTrick } from "../../kernel/presentation.js";
2
3
  import { withDeadGroups } from "../../kernel/rendition-select.js";
3
4
  //#region src/protocols/hls-cmaf/unavailable.ts
4
5
  /**
@@ -28,7 +29,7 @@ function unavailableMessages(kernel, source, ids, error) {
28
29
  const excluded = withDeadGroups(presentation, /* @__PURE__ */ new Set([...ids, ...(_kernel$quality$const = (_kernel$quality$const2 = kernel.quality.constraints.get(other)) === null || _kernel$quality$const2 === void 0 ? void 0 : _kernel$quality$const2.excludeIds) !== null && _kernel$quality$const !== void 0 ? _kernel$quality$const : []]));
29
30
  const grouped = presentation.couplings.some((c) => c.requires.audio !== void 0);
30
31
  const activeAudio = kernel.tracks.active.get("audio");
31
- if (presentation.periods.some((period) => period.tracks.some((track) => track.renditions.length > 0 && track.renditions.every((r) => excluded.has(r.id)) && (track.contentType === "video" || track.id === activeAudio && !grouped)))) return [{
32
+ if (presentation.periods.some((period) => period.tracks.some((track) => track.renditions.length > 0 && track.renditions.every((r) => excluded.has(r.id)) && (track.contentType === "video" && !isTrick(track) || track.id === activeAudio && !grouped)))) return [{
32
33
  type: "MANIFEST_FAILED",
33
34
  error: _objectSpread2(_objectSpread2({}, error), {}, { fatal: true })
34
35
  }];
@@ -1,5 +1,7 @@
1
1
  import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
- import { ladderNeighbours } from "../../kernel/rendition-select.js";
2
+ import { scheduled, tickAfter } from "../../kernel/effects.js";
3
+ import { findRendition } from "../../kernel/presentation.js";
4
+ import { activeRenditions } from "../../kernel/rendition-select.js";
3
5
  import { parseMediaPlaylist, refreshFor } from "../hls-cmaf/parse.js";
4
6
  import { RELOAD_FAILED, unavailableMessages } from "../hls-cmaf/unavailable.js";
5
7
  import { registerLiveNamespace } from "../live-shared.js";
@@ -76,10 +78,6 @@ function reload(target) {
76
78
  function renditionOfToken(token) {
77
79
  return token.startsWith(`${REFRESH_TOKEN}:`) ? token.slice(17) : null;
78
80
  }
79
- function findRendition(presentation, renditionId) {
80
- for (const period of presentation.periods) for (const track of period.tracks) for (const rendition of track.renditions) if (rendition.id === renditionId) return rendition;
81
- return null;
82
- }
83
81
  /**
84
82
  * The active tracks' playlists other than the window rendition's: the audio
85
83
  * group rendition, a segmented subtitle playlist, and the video rungs next
@@ -91,7 +89,8 @@ function findRendition(presentation, renditionId) {
91
89
  * audio, a text track in a single file) need no reload, and a playlist
92
90
  * shared by several renditions reloads once.
93
91
  */
94
- function companionTargets(presentation, kernel, window, abandoned) {
92
+ function companionTargets(kernel, window, abandoned) {
93
+ var _window$id;
95
94
  const urls = /* @__PURE__ */ new Set();
96
95
  if ((window === null || window === void 0 ? void 0 : window.playlistUrl) !== void 0) urls.add(window.playlistUrl);
97
96
  const out = [];
@@ -105,45 +104,25 @@ function companionTargets(presentation, kernel, window, abandoned) {
105
104
  ladder
106
105
  });
107
106
  };
108
- for (const contentType of [
107
+ const types = window === null ? [
108
+ "audio",
109
+ "text",
110
+ "image"
111
+ ] : [
109
112
  "video",
110
113
  "audio",
111
- "text"
112
- ]) {
113
- const trackId = kernel.tracks.active.get(contentType);
114
- if (trackId === void 0) continue;
115
- for (const period of presentation.periods) for (const track of period.tracks) {
116
- if (track.id !== trackId) continue;
117
- if (contentType !== "video") {
118
- for (const rendition of track.renditions) add(rendition, false);
119
- continue;
120
- }
121
- if (window === null) continue;
122
- const neighbours = ladderNeighbours(track.renditions, window.id, kernel.quality.constraints);
123
- for (const rendition of neighbours) add(rendition, true);
124
- }
125
- }
114
+ "text",
115
+ "image"
116
+ ];
117
+ 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");
126
118
  return out;
127
119
  }
128
120
  /** Loops a message back into the bus through a zero-delay schedule effect. */
129
121
  function feed(message) {
130
- return {
131
- kind: "schedule",
132
- token: "hls-live:loopback",
133
- delayMs: 0,
134
- then: message
135
- };
122
+ return scheduled("hls-live:loopback", message);
136
123
  }
137
124
  function tick(delaySeconds) {
138
- return {
139
- kind: "schedule",
140
- token: TICK_TOKEN,
141
- delayMs: Math.max(500, delaySeconds * 1e3),
142
- then: {
143
- type: "TICK",
144
- token: TICK_TOKEN
145
- }
146
- };
125
+ return tickAfter(TICK_TOKEN, Math.max(500, delaySeconds * 1e3));
147
126
  }
148
127
  /**
149
128
  * The rendition whose playlist drives the live window: the active video
@@ -195,7 +174,8 @@ function windowFact(presentation, rendition, kernel) {
195
174
  }
196
175
  /** The playlist URL a rendition's reload resolves against. */
197
176
  function playlistUrlFor(presentation, renditionId, target) {
198
- const rendition = findRendition(presentation, renditionId);
177
+ var _findRendition;
178
+ const rendition = (_findRendition = findRendition(presentation, renditionId)) === null || _findRendition === void 0 ? void 0 : _findRendition.rendition;
199
179
  if ((rendition === null || rendition === void 0 ? void 0 : rendition.playlistUrl) !== void 0) return rendition.playlistUrl;
200
180
  return target !== null && target.renditionId === renditionId ? target.url : null;
201
181
  }
@@ -215,7 +195,7 @@ function renditionIdsAt(presentation, url) {
215
195
  * rendition is then. The load fails only when nothing is left to move to.
216
196
  */
217
197
  function reloadFailed(state, kernel, renditionId, error) {
218
- var _state$failures$rendi, _findRendition;
198
+ var _state$failures$rendi, _findRendition2;
219
199
  const count = ((_state$failures$rendi = state.failures[renditionId]) !== null && _state$failures$rendi !== void 0 ? _state$failures$rendi : 0) + 1;
220
200
  const failures = _objectSpread2(_objectSpread2({}, state.failures), {}, { [renditionId]: count });
221
201
  const isTarget = state.target !== null && renditionId === state.target.renditionId;
@@ -233,7 +213,7 @@ function reloadFailed(state, kernel, renditionId, error) {
233
213
  }
234
214
  const presentation = kernel.presentation;
235
215
  const url = presentation === null ? null : playlistUrlFor(presentation, renditionId, state.target);
236
- const sharing = presentation !== null && url !== null && ((_findRendition = findRendition(presentation, renditionId)) === null || _findRendition === void 0 ? void 0 : _findRendition.playlistUrl) !== void 0 ? renditionIdsAt(presentation, url) : [renditionId];
216
+ const sharing = presentation !== null && url !== null && ((_findRendition2 = findRendition(presentation, renditionId)) === null || _findRendition2 === void 0 ? void 0 : _findRendition2.rendition.playlistUrl) !== void 0 ? renditionIdsAt(presentation, url) : [renditionId];
237
217
  const abandoned = [.../* @__PURE__ */ new Set([...state.abandoned, ...sharing])];
238
218
  const messages = unavailableMessages(kernel, RELOAD_FAILED, abandoned, {
239
219
  category: "manifest",
@@ -305,7 +285,7 @@ const reduceHlsLive = (slice, msg, kernel) => {
305
285
  renditionId: rendition.id,
306
286
  ladder: false
307
287
  } : state.target;
308
- const companions = companionTargets(presentation, kernel, rendition, state.abandoned);
288
+ const companions = companionTargets(kernel, rendition, state.abandoned);
309
289
  const switched = state.target !== null && target !== null && target.renditionId !== state.target.renditionId;
310
290
  let awaitingTarget = state.awaitingTarget;
311
291
  let inflight = state.inflight;
@@ -378,7 +358,7 @@ const reduceHlsLive = (slice, msg, kernel) => {
378
358
  return reloadFailed(state, kernel, renditionId, msg.error);
379
359
  }
380
360
  if (msg.type === "SEGMENT_LOADED") {
381
- var _findRendition2, _lastSegment$seq;
361
+ var _findRendition3, _lastSegment$seq;
382
362
  const renditionId = renditionOfToken(msg.trackId);
383
363
  if (renditionId === null || kernel.presentation === null) return [state, []];
384
364
  const isTarget = state.target !== null && renditionId === state.target.renditionId;
@@ -386,18 +366,10 @@ const reduceHlsLive = (slice, msg, kernel) => {
386
366
  if (url === null) return [state, []];
387
367
  const text = new TextDecoder().decode(msg.bytes);
388
368
  const media = parseMediaPlaylist(text, url);
389
- if (media.playlist === null) {
390
- var _media$error;
391
- return reloadFailed(state, kernel, renditionId, (_media$error = media.error) !== null && _media$error !== void 0 ? _media$error : {
392
- category: "manifest",
393
- code: "MANIFEST_PARSE_FAILED",
394
- fatal: false,
395
- recoverable: false
396
- });
397
- }
369
+ if (media.playlist === null) return reloadFailed(state, kernel, renditionId, media.error);
398
370
  const failures = _objectSpread2({}, state.failures);
399
371
  delete failures[renditionId];
400
- const sharing = ((_findRendition2 = findRendition(kernel.presentation, renditionId)) === null || _findRendition2 === void 0 ? void 0 : _findRendition2.playlistUrl) === void 0 ? [renditionId] : renditionIdsAt(kernel.presentation, url);
372
+ const sharing = ((_findRendition3 = findRendition(kernel.presentation, renditionId)) === null || _findRendition3 === void 0 ? void 0 : _findRendition3.rendition.playlistUrl) === void 0 ? [renditionId] : renditionIdsAt(kernel.presentation, url);
401
373
  const effects = [];
402
374
  for (const id of sharing) {
403
375
  const refresh = refreshFor(kernel.presentation, id, media.playlist);
@@ -1,4 +1,6 @@
1
1
  import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
+ import { scheduled } from "../../kernel/effects.js";
3
+ import { findRendition, isTrick } from "../../kernel/presentation.js";
2
4
  import { canSwitchTo } from "../../kernel/rendition-select.js";
3
5
  //#region src/stages/abr/index.ts
4
6
  /**
@@ -55,17 +57,12 @@ function choose(allowed, telemetry, options) {
55
57
  const INITIAL = { emergencyCap: null };
56
58
  /** Loops a command back into the bus through a zero-delay schedule effect. */
57
59
  function feed(message) {
58
- return {
59
- kind: "schedule",
60
- token: "abr:emergency",
61
- delayMs: 0,
62
- then: message
63
- };
60
+ return scheduled("abr:emergency", message);
64
61
  }
65
62
  function activeBitrate(kernel) {
66
- if (kernel.presentation === null || kernel.quality.active === null) return null;
67
- for (const period of kernel.presentation.periods) for (const track of period.tracks) for (const rendition of track.renditions) if (rendition.id === kernel.quality.active) return rendition.bitrate;
68
- return null;
63
+ var _findRendition$rendit, _findRendition;
64
+ const active = kernel.quality.active;
65
+ return active === null ? null : (_findRendition$rendit = (_findRendition = findRendition(kernel.presentation, active)) === null || _findRendition === void 0 ? void 0 : _findRendition.rendition.bitrate) !== null && _findRendition$rendit !== void 0 ? _findRendition$rendit : null;
69
66
  }
70
67
  /** The track ABR steers: video where there is one, else audio. */
71
68
  function leadTrack(kernel) {
@@ -76,7 +73,7 @@ function lowestBitrate(kernel) {
76
73
  var _kernel$presentation$, _kernel$presentation;
77
74
  let lowest = Number.POSITIVE_INFINITY;
78
75
  for (const period of (_kernel$presentation$ = (_kernel$presentation = kernel.presentation) === null || _kernel$presentation === void 0 ? void 0 : _kernel$presentation.periods) !== null && _kernel$presentation$ !== void 0 ? _kernel$presentation$ : []) for (const track of period.tracks) {
79
- if (track.contentType !== "video") continue;
76
+ if (track.contentType !== "video" || isTrick(track)) continue;
80
77
  for (const rendition of track.renditions) lowest = Math.min(lowest, rendition.bitrate);
81
78
  }
82
79
  return Number.isFinite(lowest) ? lowest : 0;
@@ -1,5 +1,17 @@
1
1
  import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
+ import { scheduled } from "../../kernel/effects.js";
2
3
  //#region src/stages/abr-persist/index.ts
4
+ /**
5
+ * Bandwidth memory across sessions, for the startup rendition choice.
6
+ * Storage is injected, never assumed: TV environments and privacy modes
7
+ * break localStorage, so the consumer supplies the get/set pair and this
8
+ * stage stays storage-agnostic.
9
+ *
10
+ * Seeding rides the message loop: a remembered figure loops back as a
11
+ * THROUGHPUT_SAMPLE fact on LOAD, priming both EWMAs before the first real
12
+ * byte. Persisting crosses the pure boundary the only allowed way: the
13
+ * slice emits an event effect and the install-time listener writes.
14
+ */
3
15
  const INITIAL = {
4
16
  seeded: false,
5
17
  lastSaved: 0
@@ -16,16 +28,11 @@ function abrPersist(storage) {
16
28
  const reduce = (slice, msg, kernel) => {
17
29
  const state = slice !== null && slice !== void 0 ? slice : INITIAL;
18
30
  if (msg.type === "LOAD" && !state.seeded && remembered !== null && remembered > 0) {
19
- const effects = [{
20
- kind: "schedule",
21
- token: "abr-persist:seed",
22
- delayMs: 0,
23
- then: {
24
- type: "THROUGHPUT_SAMPLE",
25
- bps: remembered,
26
- trackId: "abr-persist"
27
- }
28
- }];
31
+ const effects = [scheduled("abr-persist:seed", {
32
+ type: "THROUGHPUT_SAMPLE",
33
+ bps: remembered,
34
+ trackId: "abr-persist"
35
+ })];
29
36
  return [_objectSpread2(_objectSpread2({}, state), {}, {
30
37
  seeded: true,
31
38
  lastSaved: remembered
@@ -1,5 +1,15 @@
1
+ import { findRendition } from "../../kernel/presentation.js";
1
2
  import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/asyncToGenerator.js";
2
3
  //#region src/stages/aes-128/index.ts
4
+ /**
5
+ * aes-128 as a stage: full-segment AES-CBC decryption for HLS EXT-X-KEY
6
+ * METHOD=AES-128 (RFC 8216 §4.3.2.4). One transform step, ordered ahead of
7
+ * every container step, so the transmux and the probe only ever see clear
8
+ * bytes. Keys are fetched through the transport's request path and cached
9
+ * by URL; the IV is the playlist's or, absent one, the media sequence
10
+ * number. SAMPLE-AES is not this: it decrypts inside the elementary stream
11
+ * and stays deferred.
12
+ */
3
13
  /** Before the transmux (100) and the codec probe (5), which must read clear bytes. */
4
14
  const DECRYPT_ORDER = 1;
5
15
  /** The 16-byte IV: the explicit hex one, or the sequence number big-endian. */
@@ -16,13 +26,10 @@ function ivFor(key, seq) {
16
26
  return iv;
17
27
  }
18
28
  function findSegment(state, renditionId, seq) {
19
- if (state.presentation === null || renditionId === "") return null;
20
- for (const period of state.presentation.periods) for (const track of period.tracks) for (const rendition of track.renditions) {
21
- var _rendition$segments$f;
22
- if (rendition.id !== renditionId || !Array.isArray(rendition.segments)) continue;
23
- return (_rendition$segments$f = rendition.segments.find((segment) => segment.seq === seq)) !== null && _rendition$segments$f !== void 0 ? _rendition$segments$f : null;
24
- }
25
- return null;
29
+ var _findRendition, _find;
30
+ const segments = (_findRendition = findRendition(state.presentation, renditionId)) === null || _findRendition === void 0 ? void 0 : _findRendition.rendition.segments;
31
+ if (!Array.isArray(segments)) return null;
32
+ return (_find = segments.find((segment) => segment.seq === seq)) !== null && _find !== void 0 ? _find : null;
26
33
  }
27
34
  function aes128() {
28
35
  return {
@@ -1,4 +1,22 @@
1
+ import { scheduled } from "../../kernel/effects.js";
2
+ import { groupOf } from "../../kernel/rendition-select.js";
1
3
  //#region src/stages/alt-audio/index.ts
4
+ /**
5
+ * Alternate audio: a second media pipeline on sb:audio. The kernel already
6
+ * schedules audio tracks generically, so this stage owns selection and
7
+ * sync, not scheduling. Its core job is entanglement #2's other half:
8
+ * switching the video rendition can change the required audio group, and
9
+ * the audio track must follow, as one arbitration outcome.
10
+ *
11
+ * The coupling table carries the group each video rendition requires. This
12
+ * slice watches the active video rendition; when its coupling names an
13
+ * audio group the current audio track is not in, it selects a track in
14
+ * that group — preferring the current language so a group switch does not
15
+ * silently change languages.
16
+ *
17
+ * A user language choice is remembered and re-applied on top of every
18
+ * group switch, so `alt-audio` never fights `engine.tracks.select`.
19
+ */
2
20
  const INITIAL = { preferredLang: null };
3
21
  /** Audio tracks with their group parsed from the `group:name` id convention. */
4
22
  function audioTracks(kernel) {
@@ -7,10 +25,9 @@ function audioTracks(kernel) {
7
25
  for (const period of (_kernel$presentation$ = (_kernel$presentation = kernel.presentation) === null || _kernel$presentation === void 0 ? void 0 : _kernel$presentation.periods) !== null && _kernel$presentation$ !== void 0 ? _kernel$presentation$ : []) for (const track of period.tracks) {
8
26
  var _track$lang;
9
27
  if (track.contentType !== "audio") continue;
10
- const colon = track.id.indexOf(":");
11
28
  out.push({
12
29
  id: track.id,
13
- group: colon === -1 ? track.id : track.id.slice(0, colon),
30
+ group: groupOf(track.id),
14
31
  lang: (_track$lang = track.lang) !== null && _track$lang !== void 0 ? _track$lang : null,
15
32
  isDefault: track.role === "main"
16
33
  });
@@ -34,16 +51,11 @@ function pickInGroup(tracks, group, preferredLang) {
34
51
  }
35
52
  /** Loops a command back into the bus through a zero-delay schedule effect. */
36
53
  function select(trackId) {
37
- return {
38
- kind: "schedule",
39
- token: "alt-audio:select",
40
- delayMs: 0,
41
- then: {
42
- type: "SELECT_TRACK",
43
- trackId,
44
- apply: "soon"
45
- }
46
- };
54
+ return scheduled("alt-audio:select", {
55
+ type: "SELECT_TRACK",
56
+ trackId,
57
+ apply: "soon"
58
+ });
47
59
  }
48
60
  const reduceAltAudio = (slice, msg, kernel) => {
49
61
  const state = slice !== null && slice !== void 0 ? slice : INITIAL;