@videojs/spf 10.0.0-beta.9 → 10.0.0-rc.2

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 (556) hide show
  1. package/README.md +19 -38
  2. package/dist/default/core/actors/create-machine-actor.js +89 -0
  3. package/dist/default/core/actors/create-machine-actor.js.map +1 -0
  4. package/dist/default/core/actors/create-transition-actor.js +44 -0
  5. package/dist/default/core/actors/create-transition-actor.js.map +1 -0
  6. package/dist/default/core/composition/create-composition.js +82 -0
  7. package/dist/default/core/composition/create-composition.js.map +1 -0
  8. package/dist/default/core/composition/share-signals.js +34 -0
  9. package/dist/default/core/composition/share-signals.js.map +1 -0
  10. package/dist/default/core/machine.js +25 -0
  11. package/dist/default/core/machine.js.map +1 -0
  12. package/dist/default/core/reactors/create-machine-reactor.js +84 -0
  13. package/dist/default/core/reactors/create-machine-reactor.js.map +1 -0
  14. package/dist/default/core/signals/effect.js +61 -0
  15. package/dist/default/core/signals/effect.js.map +1 -0
  16. package/dist/default/core/signals/primitives.js +50 -0
  17. package/dist/default/core/signals/primitives.js.map +1 -0
  18. package/dist/default/core/signals/when.js +36 -0
  19. package/dist/default/core/signals/when.js.map +1 -0
  20. package/dist/default/core/tasks/delayed-reschedule.js +27 -0
  21. package/dist/default/core/tasks/delayed-reschedule.js.map +1 -0
  22. package/dist/default/core/tasks/task.js +298 -0
  23. package/dist/default/core/tasks/task.js.map +1 -0
  24. package/dist/default/dom.js +9 -0
  25. package/dist/default/hls-audio.js +3 -0
  26. package/dist/default/hls-background-video.js +3 -0
  27. package/dist/default/hls-video.js +4 -0
  28. package/dist/default/hls.js +10 -0
  29. package/dist/default/index.js +22 -0
  30. package/dist/default/index.js.map +1 -0
  31. package/dist/default/media/abr/quality-selection.js +17 -0
  32. package/dist/default/media/abr/quality-selection.js.map +1 -0
  33. package/dist/default/media/buffer/back-buffer.js +42 -0
  34. package/dist/default/media/buffer/back-buffer.js.map +1 -0
  35. package/dist/default/media/buffer/forward-buffer.js +110 -0
  36. package/dist/default/media/buffer/forward-buffer.js.map +1 -0
  37. package/dist/default/media/dom/capabilities.js +61 -0
  38. package/dist/default/media/dom/capabilities.js.map +1 -0
  39. package/dist/default/media/dom/mse/append-segment.js +58 -0
  40. package/dist/default/media/dom/mse/append-segment.js.map +1 -0
  41. package/dist/default/media/dom/mse/buffer-flusher.js +55 -0
  42. package/dist/default/media/dom/mse/buffer-flusher.js.map +1 -0
  43. package/dist/default/media/dom/mse/duration.js +87 -0
  44. package/dist/default/media/dom/mse/duration.js.map +1 -0
  45. package/dist/default/media/dom/mse/end-of-stream.js +17 -0
  46. package/dist/default/media/dom/mse/end-of-stream.js.map +1 -0
  47. package/dist/default/media/dom/mse/mediasource-setup.js +227 -0
  48. package/dist/default/media/dom/mse/mediasource-setup.js.map +1 -0
  49. package/dist/default/media/dom/screen.js +95 -0
  50. package/dist/default/media/dom/screen.js.map +1 -0
  51. package/dist/default/media/dom/text/resolve-vtt-segment.js +50 -0
  52. package/dist/default/media/dom/text/resolve-vtt-segment.js.map +1 -0
  53. package/dist/default/media/dom/text/text-track-slots.js +61 -0
  54. package/dist/default/media/dom/text/text-track-slots.js.map +1 -0
  55. package/dist/default/media/errors.js +60 -0
  56. package/dist/default/media/errors.js.map +1 -0
  57. package/dist/default/media/hls/parse-attributes.js +131 -0
  58. package/dist/default/media/hls/parse-attributes.js.map +1 -0
  59. package/dist/default/media/hls/parse-media-playlist.js +253 -0
  60. package/dist/default/media/hls/parse-media-playlist.js.map +1 -0
  61. package/dist/default/media/hls/parse-multivariant.js +234 -0
  62. package/dist/default/media/hls/parse-multivariant.js.map +1 -0
  63. package/dist/default/media/hls/reload-policy.js +63 -0
  64. package/dist/default/media/hls/reload-policy.js.map +1 -0
  65. package/dist/default/media/hls/resolve-url.js +9 -0
  66. package/dist/default/media/hls/resolve-url.js.map +1 -0
  67. package/dist/default/media/live-window.js +32 -0
  68. package/dist/default/media/live-window.js.map +1 -0
  69. package/dist/default/media/media-tracks/media-tracks.js +96 -0
  70. package/dist/default/media/media-tracks/media-tracks.js.map +1 -0
  71. package/dist/default/media/mp4/box.js +57 -0
  72. package/dist/default/media/mp4/box.js.map +1 -0
  73. package/dist/default/media/mp4/timestamp-origin.js +95 -0
  74. package/dist/default/media/mp4/timestamp-origin.js.map +1 -0
  75. package/dist/default/media/primitives/resolution.js +26 -0
  76. package/dist/default/media/primitives/resolution.js.map +1 -0
  77. package/dist/default/media/primitives/select-tracks.js +97 -0
  78. package/dist/default/media/primitives/select-tracks.js.map +1 -0
  79. package/dist/default/media/text/parse-vtt-timestamp-map.js +40 -0
  80. package/dist/default/media/text/parse-vtt-timestamp-map.js.map +1 -0
  81. package/dist/default/media/text/resolve-vtt-metadata.js +22 -0
  82. package/dist/default/media/text/resolve-vtt-metadata.js.map +1 -0
  83. package/dist/default/media/types/index.js +42 -0
  84. package/dist/default/media/types/index.js.map +1 -0
  85. package/dist/default/media/utils/cdn.js +50 -0
  86. package/dist/default/media/utils/cdn.js.map +1 -0
  87. package/dist/default/media/utils/preload.js +21 -0
  88. package/dist/default/media/utils/preload.js.map +1 -0
  89. package/dist/default/media/utils/track-selection.js +43 -0
  90. package/dist/default/media/utils/track-selection.js.map +1 -0
  91. package/dist/default/media/utils/tracks.js +146 -0
  92. package/dist/default/media/utils/tracks.js.map +1 -0
  93. package/dist/default/media-tracks.js +2 -0
  94. package/dist/default/network/bandwidth-estimator.js +95 -0
  95. package/dist/default/network/bandwidth-estimator.js.map +1 -0
  96. package/dist/default/network/chunked-stream-iterable.js +47 -0
  97. package/dist/default/network/chunked-stream-iterable.js.map +1 -0
  98. package/dist/default/network/ewma.js +68 -0
  99. package/dist/default/network/ewma.js.map +1 -0
  100. package/dist/default/network/fetch.js +108 -0
  101. package/dist/default/network/fetch.js.map +1 -0
  102. package/dist/default/playback/actors/dom/segment-loader.js +233 -0
  103. package/dist/default/playback/actors/dom/segment-loader.js.map +1 -0
  104. package/dist/default/playback/actors/dom/source-buffer.js +139 -0
  105. package/dist/default/playback/actors/dom/source-buffer.js.map +1 -0
  106. package/dist/default/playback/actors/dom/text-tracks.js +46 -0
  107. package/dist/default/playback/actors/dom/text-tracks.js.map +1 -0
  108. package/dist/default/playback/actors/text-track-segment-loader.js +138 -0
  109. package/dist/default/playback/actors/text-track-segment-loader.js.map +1 -0
  110. package/dist/default/playback/adapters/hls-audio/adapter.js +8 -0
  111. package/dist/default/playback/adapters/hls-audio/adapter.js.map +1 -0
  112. package/dist/default/playback/adapters/hls-audio/mixin.js +178 -0
  113. package/dist/default/playback/adapters/hls-audio/mixin.js.map +1 -0
  114. package/dist/default/playback/adapters/hls-background-video/adapter.js +17 -0
  115. package/dist/default/playback/adapters/hls-background-video/adapter.js.map +1 -0
  116. package/dist/default/playback/adapters/hls-background-video/host.js +56 -0
  117. package/dist/default/playback/adapters/hls-background-video/host.js.map +1 -0
  118. package/dist/default/playback/adapters/hls-background-video/mixin.js +191 -0
  119. package/dist/default/playback/adapters/hls-background-video/mixin.js.map +1 -0
  120. package/dist/default/playback/adapters/hls-video/adapter.js +11 -0
  121. package/dist/default/playback/adapters/hls-video/adapter.js.map +1 -0
  122. package/dist/default/playback/adapters/hls-video/error-surface.js +46 -0
  123. package/dist/default/playback/adapters/hls-video/error-surface.js.map +1 -0
  124. package/dist/default/playback/adapters/hls-video/media-tracks.js +125 -0
  125. package/dist/default/playback/adapters/hls-video/media-tracks.js.map +1 -0
  126. package/dist/default/playback/adapters/hls-video/mixin.js +299 -0
  127. package/dist/default/playback/adapters/hls-video/mixin.js.map +1 -0
  128. package/dist/default/playback/behaviors/calculate-presentation-duration.js +33 -0
  129. package/dist/default/playback/behaviors/calculate-presentation-duration.js.map +1 -0
  130. package/dist/default/playback/behaviors/collect-errors.js +98 -0
  131. package/dist/default/playback/behaviors/collect-errors.js.map +1 -0
  132. package/dist/default/playback/behaviors/derive-cdn-priority.js +61 -0
  133. package/dist/default/playback/behaviors/derive-cdn-priority.js.map +1 -0
  134. package/dist/default/playback/behaviors/dom/airplay.js +188 -0
  135. package/dist/default/playback/behaviors/dom/airplay.js.map +1 -0
  136. package/dist/default/playback/behaviors/dom/apply-start-position.js +81 -0
  137. package/dist/default/playback/behaviors/dom/apply-start-position.js.map +1 -0
  138. package/dist/default/playback/behaviors/dom/end-of-stream.js +97 -0
  139. package/dist/default/playback/behaviors/dom/end-of-stream.js.map +1 -0
  140. package/dist/default/playback/behaviors/dom/load-segments.js +169 -0
  141. package/dist/default/playback/behaviors/dom/load-segments.js.map +1 -0
  142. package/dist/default/playback/behaviors/dom/recover-end-stall.js +72 -0
  143. package/dist/default/playback/behaviors/dom/recover-end-stall.js.map +1 -0
  144. package/dist/default/playback/behaviors/dom/seek-to-live-edge.js +113 -0
  145. package/dist/default/playback/behaviors/dom/seek-to-live-edge.js.map +1 -0
  146. package/dist/default/playback/behaviors/dom/setup-buffer-actors.js +181 -0
  147. package/dist/default/playback/behaviors/dom/setup-buffer-actors.js.map +1 -0
  148. package/dist/default/playback/behaviors/dom/setup-mediasource.js +100 -0
  149. package/dist/default/playback/behaviors/dom/setup-mediasource.js.map +1 -0
  150. package/dist/default/playback/behaviors/dom/setup-text-track-actors.js +40 -0
  151. package/dist/default/playback/behaviors/dom/setup-text-track-actors.js.map +1 -0
  152. package/dist/default/playback/behaviors/dom/sync-live-seekable-range.js +25 -0
  153. package/dist/default/playback/behaviors/dom/sync-live-seekable-range.js.map +1 -0
  154. package/dist/default/playback/behaviors/dom/sync-text-tracks.js +109 -0
  155. package/dist/default/playback/behaviors/dom/sync-text-tracks.js.map +1 -0
  156. package/dist/default/playback/behaviors/dom/track-current-time.js +50 -0
  157. package/dist/default/playback/behaviors/dom/track-current-time.js.map +1 -0
  158. package/dist/default/playback/behaviors/dom/track-load-triggers.js +86 -0
  159. package/dist/default/playback/behaviors/dom/track-load-triggers.js.map +1 -0
  160. package/dist/default/playback/behaviors/dom/track-playback-rate.js +35 -0
  161. package/dist/default/playback/behaviors/dom/track-playback-rate.js.map +1 -0
  162. package/dist/default/playback/behaviors/dom/track-player-resolution.js +53 -0
  163. package/dist/default/playback/behaviors/dom/track-player-resolution.js.map +1 -0
  164. package/dist/default/playback/behaviors/dom/track-screen-resolution.js +28 -0
  165. package/dist/default/playback/behaviors/dom/track-screen-resolution.js.map +1 -0
  166. package/dist/default/playback/behaviors/dom/update-mediasource-duration.js +98 -0
  167. package/dist/default/playback/behaviors/dom/update-mediasource-duration.js.map +1 -0
  168. package/dist/default/playback/behaviors/establish-start-media-time.js +187 -0
  169. package/dist/default/playback/behaviors/establish-start-media-time.js.map +1 -0
  170. package/dist/default/playback/behaviors/resolve-presentation.js +76 -0
  171. package/dist/default/playback/behaviors/resolve-presentation.js.map +1 -0
  172. package/dist/default/playback/behaviors/resolve-track.js +134 -0
  173. package/dist/default/playback/behaviors/resolve-track.js.map +1 -0
  174. package/dist/default/playback/behaviors/select-tracks.js +189 -0
  175. package/dist/default/playback/behaviors/select-tracks.js.map +1 -0
  176. package/dist/default/playback/behaviors/setup-failover-monitor.js +61 -0
  177. package/dist/default/playback/behaviors/setup-failover-monitor.js.map +1 -0
  178. package/dist/default/playback/behaviors/sync-preload.js +59 -0
  179. package/dist/default/playback/behaviors/sync-preload.js.map +1 -0
  180. package/dist/default/playback/behaviors/track-switching.js +407 -0
  181. package/dist/default/playback/behaviors/track-switching.js.map +1 -0
  182. package/dist/default/playback/engines/hls/engine-audio-only.js +94 -0
  183. package/dist/default/playback/engines/hls/engine-audio-only.js.map +1 -0
  184. package/dist/default/playback/engines/hls/engine-background-video.js +87 -0
  185. package/dist/default/playback/engines/hls/engine-background-video.js.map +1 -0
  186. package/dist/default/playback/engines/hls/engine.js +144 -0
  187. package/dist/default/playback/engines/hls/engine.js.map +1 -0
  188. package/dist/default/playback/primitives/error-messages.js +42 -0
  189. package/dist/default/playback/primitives/error-messages.js.map +1 -0
  190. package/dist/default/playback/primitives/failover-fetch.js +37 -0
  191. package/dist/default/playback/primitives/failover-fetch.js.map +1 -0
  192. package/dist/default/playback/primitives/head-peek.js +41 -0
  193. package/dist/default/playback/primitives/head-peek.js.map +1 -0
  194. package/dist/default/playback/primitives/live-window.js +63 -0
  195. package/dist/default/playback/primitives/live-window.js.map +1 -0
  196. package/dist/default/playback/primitives/relocation-pipelines.js +191 -0
  197. package/dist/default/playback/primitives/relocation-pipelines.js.map +1 -0
  198. package/dist/default/playback/primitives/report-track-conditions.js +74 -0
  199. package/dist/default/playback/primitives/report-track-conditions.js.map +1 -0
  200. package/dist/default/playback/primitives/segment-load-pipeline.js +96 -0
  201. package/dist/default/playback/primitives/segment-load-pipeline.js.map +1 -0
  202. package/dist/default/playback/primitives/selection-rules.js +115 -0
  203. package/dist/default/playback/primitives/selection-rules.js.map +1 -0
  204. package/dist/default/playback/primitives/text-segment-load-pipeline.js +36 -0
  205. package/dist/default/playback/primitives/text-segment-load-pipeline.js.map +1 -0
  206. package/dist/default/playback/primitives/track-types.js +53 -0
  207. package/dist/default/playback/primitives/track-types.js.map +1 -0
  208. package/dist/dev/core/actors/actor.d.ts +26 -0
  209. package/dist/dev/core/actors/actor.d.ts.map +1 -0
  210. package/dist/dev/core/actors/create-machine-actor.d.ts +119 -0
  211. package/dist/dev/core/actors/create-machine-actor.d.ts.map +1 -0
  212. package/dist/dev/core/actors/create-machine-actor.js +89 -0
  213. package/dist/dev/core/actors/create-machine-actor.js.map +1 -0
  214. package/dist/dev/core/actors/create-transition-actor.d.ts +37 -0
  215. package/dist/dev/core/actors/create-transition-actor.d.ts.map +1 -0
  216. package/dist/dev/core/actors/create-transition-actor.js +44 -0
  217. package/dist/dev/core/actors/create-transition-actor.js.map +1 -0
  218. package/dist/dev/core/composition/create-composition.d.ts +241 -0
  219. package/dist/dev/core/composition/create-composition.d.ts.map +1 -0
  220. package/dist/dev/core/composition/create-composition.js +82 -0
  221. package/dist/dev/core/composition/create-composition.js.map +1 -0
  222. package/dist/dev/core/composition/share-signals.d.ts +39 -0
  223. package/dist/dev/core/composition/share-signals.d.ts.map +1 -0
  224. package/dist/dev/core/composition/share-signals.js +34 -0
  225. package/dist/dev/core/composition/share-signals.js.map +1 -0
  226. package/dist/dev/core/machine.d.ts +21 -0
  227. package/dist/dev/core/machine.d.ts.map +1 -0
  228. package/dist/dev/core/machine.js +25 -0
  229. package/dist/dev/core/machine.js.map +1 -0
  230. package/dist/dev/core/reactors/create-machine-reactor.d.ts +87 -0
  231. package/dist/dev/core/reactors/create-machine-reactor.d.ts.map +1 -0
  232. package/dist/dev/core/reactors/create-machine-reactor.js +84 -0
  233. package/dist/dev/core/reactors/create-machine-reactor.js.map +1 -0
  234. package/dist/dev/core/signals/effect.d.ts +14 -0
  235. package/dist/dev/core/signals/effect.d.ts.map +1 -0
  236. package/dist/dev/core/signals/effect.js +61 -0
  237. package/dist/dev/core/signals/effect.js.map +1 -0
  238. package/dist/dev/core/signals/primitives.d.ts +44 -0
  239. package/dist/dev/core/signals/primitives.d.ts.map +1 -0
  240. package/dist/dev/core/signals/primitives.js +50 -0
  241. package/dist/dev/core/signals/primitives.js.map +1 -0
  242. package/dist/dev/core/signals/when.js +36 -0
  243. package/dist/dev/core/signals/when.js.map +1 -0
  244. package/dist/dev/core/tasks/delayed-reschedule.js +27 -0
  245. package/dist/dev/core/tasks/delayed-reschedule.js.map +1 -0
  246. package/dist/dev/core/tasks/task.d.ts +144 -0
  247. package/dist/dev/core/tasks/task.d.ts.map +1 -0
  248. package/dist/dev/core/tasks/task.js +298 -0
  249. package/dist/dev/core/tasks/task.js.map +1 -0
  250. package/dist/dev/dom.d.ts +9 -0
  251. package/dist/dev/dom.js +9 -0
  252. package/dist/dev/hls-audio.d.ts +3 -0
  253. package/dist/dev/hls-audio.js +3 -0
  254. package/dist/dev/hls-background-video.d.ts +4 -0
  255. package/dist/dev/hls-background-video.js +3 -0
  256. package/dist/dev/hls-video.d.ts +5 -0
  257. package/dist/dev/hls-video.js +4 -0
  258. package/dist/dev/hls.d.ts +11 -0
  259. package/dist/dev/hls.js +10 -0
  260. package/dist/dev/index.d.ts +23 -0
  261. package/dist/dev/index.d.ts.map +1 -0
  262. package/dist/dev/index.js +22 -0
  263. package/dist/dev/index.js.map +1 -0
  264. package/dist/dev/media/abr/quality-selection.d.ts +19 -0
  265. package/dist/dev/media/abr/quality-selection.d.ts.map +1 -0
  266. package/dist/dev/media/abr/quality-selection.js +17 -0
  267. package/dist/dev/media/abr/quality-selection.js.map +1 -0
  268. package/dist/dev/media/buffer/back-buffer.d.ts +9 -0
  269. package/dist/dev/media/buffer/back-buffer.d.ts.map +1 -0
  270. package/dist/dev/media/buffer/back-buffer.js +42 -0
  271. package/dist/dev/media/buffer/back-buffer.js.map +1 -0
  272. package/dist/dev/media/buffer/forward-buffer.d.ts +9 -0
  273. package/dist/dev/media/buffer/forward-buffer.d.ts.map +1 -0
  274. package/dist/dev/media/buffer/forward-buffer.js +110 -0
  275. package/dist/dev/media/buffer/forward-buffer.js.map +1 -0
  276. package/dist/dev/media/dom/capabilities.js +61 -0
  277. package/dist/dev/media/dom/capabilities.js.map +1 -0
  278. package/dist/dev/media/dom/mse/append-segment.d.ts +16 -0
  279. package/dist/dev/media/dom/mse/append-segment.d.ts.map +1 -0
  280. package/dist/dev/media/dom/mse/append-segment.js +58 -0
  281. package/dist/dev/media/dom/mse/append-segment.js.map +1 -0
  282. package/dist/dev/media/dom/mse/buffer-flusher.d.ts +24 -0
  283. package/dist/dev/media/dom/mse/buffer-flusher.d.ts.map +1 -0
  284. package/dist/dev/media/dom/mse/buffer-flusher.js +55 -0
  285. package/dist/dev/media/dom/mse/buffer-flusher.js.map +1 -0
  286. package/dist/dev/media/dom/mse/duration.js +87 -0
  287. package/dist/dev/media/dom/mse/duration.js.map +1 -0
  288. package/dist/dev/media/dom/mse/end-of-stream.js +17 -0
  289. package/dist/dev/media/dom/mse/end-of-stream.js.map +1 -0
  290. package/dist/dev/media/dom/mse/mediasource-setup.js +227 -0
  291. package/dist/dev/media/dom/mse/mediasource-setup.js.map +1 -0
  292. package/dist/dev/media/dom/screen.d.ts +7 -0
  293. package/dist/dev/media/dom/screen.d.ts.map +1 -0
  294. package/dist/dev/media/dom/screen.js +95 -0
  295. package/dist/dev/media/dom/screen.js.map +1 -0
  296. package/dist/dev/media/dom/text/resolve-vtt-segment.d.ts +6 -0
  297. package/dist/dev/media/dom/text/resolve-vtt-segment.d.ts.map +1 -0
  298. package/dist/dev/media/dom/text/resolve-vtt-segment.js +50 -0
  299. package/dist/dev/media/dom/text/resolve-vtt-segment.js.map +1 -0
  300. package/dist/dev/media/dom/text/text-track-slots.d.ts +24 -0
  301. package/dist/dev/media/dom/text/text-track-slots.d.ts.map +1 -0
  302. package/dist/dev/media/dom/text/text-track-slots.js +61 -0
  303. package/dist/dev/media/dom/text/text-track-slots.js.map +1 -0
  304. package/dist/dev/media/errors.d.ts +68 -0
  305. package/dist/dev/media/errors.d.ts.map +1 -0
  306. package/dist/dev/media/errors.js +60 -0
  307. package/dist/dev/media/errors.js.map +1 -0
  308. package/dist/dev/media/hls/parse-attributes.js +131 -0
  309. package/dist/dev/media/hls/parse-attributes.js.map +1 -0
  310. package/dist/dev/media/hls/parse-media-playlist.js +253 -0
  311. package/dist/dev/media/hls/parse-media-playlist.js.map +1 -0
  312. package/dist/dev/media/hls/parse-multivariant.js +234 -0
  313. package/dist/dev/media/hls/parse-multivariant.js.map +1 -0
  314. package/dist/dev/media/hls/reload-policy.js +63 -0
  315. package/dist/dev/media/hls/reload-policy.js.map +1 -0
  316. package/dist/dev/media/hls/resolve-url.js +9 -0
  317. package/dist/dev/media/hls/resolve-url.js.map +1 -0
  318. package/dist/dev/media/live-window.js +32 -0
  319. package/dist/dev/media/live-window.js.map +1 -0
  320. package/dist/dev/media/media-tracks/media-tracks.d.ts +46 -0
  321. package/dist/dev/media/media-tracks/media-tracks.d.ts.map +1 -0
  322. package/dist/dev/media/media-tracks/media-tracks.js +96 -0
  323. package/dist/dev/media/media-tracks/media-tracks.js.map +1 -0
  324. package/dist/dev/media/mp4/box.js +57 -0
  325. package/dist/dev/media/mp4/box.js.map +1 -0
  326. package/dist/dev/media/mp4/timestamp-origin.js +95 -0
  327. package/dist/dev/media/mp4/timestamp-origin.js.map +1 -0
  328. package/dist/dev/media/primitives/resolution.d.ts +22 -0
  329. package/dist/dev/media/primitives/resolution.d.ts.map +1 -0
  330. package/dist/dev/media/primitives/resolution.js +26 -0
  331. package/dist/dev/media/primitives/resolution.js.map +1 -0
  332. package/dist/dev/media/primitives/select-tracks.js +97 -0
  333. package/dist/dev/media/primitives/select-tracks.js.map +1 -0
  334. package/dist/dev/media/text/parse-vtt-timestamp-map.js +40 -0
  335. package/dist/dev/media/text/parse-vtt-timestamp-map.js.map +1 -0
  336. package/dist/dev/media/text/resolve-vtt-metadata.js +22 -0
  337. package/dist/dev/media/text/resolve-vtt-metadata.js.map +1 -0
  338. package/dist/dev/media/types/index.d.ts +306 -0
  339. package/dist/dev/media/types/index.d.ts.map +1 -0
  340. package/dist/dev/media/types/index.js +42 -0
  341. package/dist/dev/media/types/index.js.map +1 -0
  342. package/dist/dev/media/utils/cdn.d.ts +11 -0
  343. package/dist/dev/media/utils/cdn.d.ts.map +1 -0
  344. package/dist/dev/media/utils/cdn.js +50 -0
  345. package/dist/dev/media/utils/cdn.js.map +1 -0
  346. package/dist/dev/media/utils/preload.js +21 -0
  347. package/dist/dev/media/utils/preload.js.map +1 -0
  348. package/dist/dev/media/utils/track-selection.js +43 -0
  349. package/dist/dev/media/utils/track-selection.js.map +1 -0
  350. package/dist/dev/media/utils/tracks.js +146 -0
  351. package/dist/dev/media/utils/tracks.js.map +1 -0
  352. package/dist/dev/media-tracks.d.ts +3 -0
  353. package/dist/dev/media-tracks.js +2 -0
  354. package/dist/dev/network/bandwidth-estimator.d.ts +48 -0
  355. package/dist/dev/network/bandwidth-estimator.d.ts.map +1 -0
  356. package/dist/dev/network/bandwidth-estimator.js +95 -0
  357. package/dist/dev/network/bandwidth-estimator.js.map +1 -0
  358. package/dist/dev/network/chunked-stream-iterable.js +47 -0
  359. package/dist/dev/network/chunked-stream-iterable.js.map +1 -0
  360. package/dist/dev/network/ewma.js +68 -0
  361. package/dist/dev/network/ewma.js.map +1 -0
  362. package/dist/dev/network/fetch.js +108 -0
  363. package/dist/dev/network/fetch.js.map +1 -0
  364. package/dist/dev/playback/actors/dom/segment-loader.d.ts +44 -0
  365. package/dist/dev/playback/actors/dom/segment-loader.d.ts.map +1 -0
  366. package/dist/dev/playback/actors/dom/segment-loader.js +233 -0
  367. package/dist/dev/playback/actors/dom/segment-loader.js.map +1 -0
  368. package/dist/dev/playback/actors/dom/source-buffer.d.ts +45 -0
  369. package/dist/dev/playback/actors/dom/source-buffer.d.ts.map +1 -0
  370. package/dist/dev/playback/actors/dom/source-buffer.js +139 -0
  371. package/dist/dev/playback/actors/dom/source-buffer.js.map +1 -0
  372. package/dist/dev/playback/actors/dom/text-tracks.d.ts +3 -0
  373. package/dist/dev/playback/actors/dom/text-tracks.js +46 -0
  374. package/dist/dev/playback/actors/dom/text-tracks.js.map +1 -0
  375. package/dist/dev/playback/actors/text-track-segment-loader.d.ts +48 -0
  376. package/dist/dev/playback/actors/text-track-segment-loader.d.ts.map +1 -0
  377. package/dist/dev/playback/actors/text-track-segment-loader.js +138 -0
  378. package/dist/dev/playback/actors/text-track-segment-loader.js.map +1 -0
  379. package/dist/dev/playback/actors/text-tracks.d.ts +30 -0
  380. package/dist/dev/playback/actors/text-tracks.d.ts.map +1 -0
  381. package/dist/dev/playback/adapters/hls-audio/adapter.d.ts +11 -0
  382. package/dist/dev/playback/adapters/hls-audio/adapter.d.ts.map +1 -0
  383. package/dist/dev/playback/adapters/hls-audio/adapter.js +8 -0
  384. package/dist/dev/playback/adapters/hls-audio/adapter.js.map +1 -0
  385. package/dist/dev/playback/adapters/hls-audio/mixin.d.ts +52 -0
  386. package/dist/dev/playback/adapters/hls-audio/mixin.d.ts.map +1 -0
  387. package/dist/dev/playback/adapters/hls-audio/mixin.js +178 -0
  388. package/dist/dev/playback/adapters/hls-audio/mixin.js.map +1 -0
  389. package/dist/dev/playback/adapters/hls-background-video/adapter.d.ts +19 -0
  390. package/dist/dev/playback/adapters/hls-background-video/adapter.d.ts.map +1 -0
  391. package/dist/dev/playback/adapters/hls-background-video/adapter.js +17 -0
  392. package/dist/dev/playback/adapters/hls-background-video/adapter.js.map +1 -0
  393. package/dist/dev/playback/adapters/hls-background-video/host.d.ts +34 -0
  394. package/dist/dev/playback/adapters/hls-background-video/host.d.ts.map +1 -0
  395. package/dist/dev/playback/adapters/hls-background-video/host.js +56 -0
  396. package/dist/dev/playback/adapters/hls-background-video/host.js.map +1 -0
  397. package/dist/dev/playback/adapters/hls-background-video/mixin.d.ts +69 -0
  398. package/dist/dev/playback/adapters/hls-background-video/mixin.d.ts.map +1 -0
  399. package/dist/dev/playback/adapters/hls-background-video/mixin.js +191 -0
  400. package/dist/dev/playback/adapters/hls-background-video/mixin.js.map +1 -0
  401. package/dist/dev/playback/adapters/hls-video/adapter.d.ts +11 -0
  402. package/dist/dev/playback/adapters/hls-video/adapter.d.ts.map +1 -0
  403. package/dist/dev/playback/adapters/hls-video/adapter.js +11 -0
  404. package/dist/dev/playback/adapters/hls-video/adapter.js.map +1 -0
  405. package/dist/dev/playback/adapters/hls-video/error-surface.d.ts +17 -0
  406. package/dist/dev/playback/adapters/hls-video/error-surface.d.ts.map +1 -0
  407. package/dist/dev/playback/adapters/hls-video/error-surface.js +46 -0
  408. package/dist/dev/playback/adapters/hls-video/error-surface.js.map +1 -0
  409. package/dist/dev/playback/adapters/hls-video/media-tracks.d.ts +21 -0
  410. package/dist/dev/playback/adapters/hls-video/media-tracks.d.ts.map +1 -0
  411. package/dist/dev/playback/adapters/hls-video/media-tracks.js +125 -0
  412. package/dist/dev/playback/adapters/hls-video/media-tracks.js.map +1 -0
  413. package/dist/dev/playback/adapters/hls-video/mixin.d.ts +62 -0
  414. package/dist/dev/playback/adapters/hls-video/mixin.d.ts.map +1 -0
  415. package/dist/dev/playback/adapters/hls-video/mixin.js +299 -0
  416. package/dist/dev/playback/adapters/hls-video/mixin.js.map +1 -0
  417. package/dist/dev/playback/behaviors/calculate-presentation-duration.d.ts +23 -0
  418. package/dist/dev/playback/behaviors/calculate-presentation-duration.d.ts.map +1 -0
  419. package/dist/dev/playback/behaviors/calculate-presentation-duration.js +33 -0
  420. package/dist/dev/playback/behaviors/calculate-presentation-duration.js.map +1 -0
  421. package/dist/dev/playback/behaviors/collect-errors.d.ts +2 -0
  422. package/dist/dev/playback/behaviors/collect-errors.js +98 -0
  423. package/dist/dev/playback/behaviors/collect-errors.js.map +1 -0
  424. package/dist/dev/playback/behaviors/derive-cdn-priority.js +61 -0
  425. package/dist/dev/playback/behaviors/derive-cdn-priority.js.map +1 -0
  426. package/dist/dev/playback/behaviors/dom/airplay.js +188 -0
  427. package/dist/dev/playback/behaviors/dom/airplay.js.map +1 -0
  428. package/dist/dev/playback/behaviors/dom/apply-start-position.js +81 -0
  429. package/dist/dev/playback/behaviors/dom/apply-start-position.js.map +1 -0
  430. package/dist/dev/playback/behaviors/dom/end-of-stream.js +97 -0
  431. package/dist/dev/playback/behaviors/dom/end-of-stream.js.map +1 -0
  432. package/dist/dev/playback/behaviors/dom/load-segments.d.ts +69 -0
  433. package/dist/dev/playback/behaviors/dom/load-segments.d.ts.map +1 -0
  434. package/dist/dev/playback/behaviors/dom/load-segments.js +169 -0
  435. package/dist/dev/playback/behaviors/dom/load-segments.js.map +1 -0
  436. package/dist/dev/playback/behaviors/dom/recover-end-stall.js +72 -0
  437. package/dist/dev/playback/behaviors/dom/recover-end-stall.js.map +1 -0
  438. package/dist/dev/playback/behaviors/dom/seek-to-live-edge.js +113 -0
  439. package/dist/dev/playback/behaviors/dom/seek-to-live-edge.js.map +1 -0
  440. package/dist/dev/playback/behaviors/dom/setup-buffer-actors.js +181 -0
  441. package/dist/dev/playback/behaviors/dom/setup-buffer-actors.js.map +1 -0
  442. package/dist/dev/playback/behaviors/dom/setup-mediasource.js +100 -0
  443. package/dist/dev/playback/behaviors/dom/setup-mediasource.js.map +1 -0
  444. package/dist/dev/playback/behaviors/dom/setup-text-track-actors.d.ts +28 -0
  445. package/dist/dev/playback/behaviors/dom/setup-text-track-actors.d.ts.map +1 -0
  446. package/dist/dev/playback/behaviors/dom/setup-text-track-actors.js +40 -0
  447. package/dist/dev/playback/behaviors/dom/setup-text-track-actors.js.map +1 -0
  448. package/dist/dev/playback/behaviors/dom/sync-live-seekable-range.js +25 -0
  449. package/dist/dev/playback/behaviors/dom/sync-live-seekable-range.js.map +1 -0
  450. package/dist/dev/playback/behaviors/dom/sync-text-tracks.js +109 -0
  451. package/dist/dev/playback/behaviors/dom/sync-text-tracks.js.map +1 -0
  452. package/dist/dev/playback/behaviors/dom/track-current-time.d.ts +33 -0
  453. package/dist/dev/playback/behaviors/dom/track-current-time.d.ts.map +1 -0
  454. package/dist/dev/playback/behaviors/dom/track-current-time.js +50 -0
  455. package/dist/dev/playback/behaviors/dom/track-current-time.js.map +1 -0
  456. package/dist/dev/playback/behaviors/dom/track-load-triggers.d.ts +41 -0
  457. package/dist/dev/playback/behaviors/dom/track-load-triggers.d.ts.map +1 -0
  458. package/dist/dev/playback/behaviors/dom/track-load-triggers.js +86 -0
  459. package/dist/dev/playback/behaviors/dom/track-load-triggers.js.map +1 -0
  460. package/dist/dev/playback/behaviors/dom/track-playback-rate.d.ts +33 -0
  461. package/dist/dev/playback/behaviors/dom/track-playback-rate.d.ts.map +1 -0
  462. package/dist/dev/playback/behaviors/dom/track-playback-rate.js +35 -0
  463. package/dist/dev/playback/behaviors/dom/track-playback-rate.js.map +1 -0
  464. package/dist/dev/playback/behaviors/dom/track-player-resolution.d.ts +8 -0
  465. package/dist/dev/playback/behaviors/dom/track-player-resolution.d.ts.map +1 -0
  466. package/dist/dev/playback/behaviors/dom/track-player-resolution.js +53 -0
  467. package/dist/dev/playback/behaviors/dom/track-player-resolution.js.map +1 -0
  468. package/dist/dev/playback/behaviors/dom/track-screen-resolution.js +28 -0
  469. package/dist/dev/playback/behaviors/dom/track-screen-resolution.js.map +1 -0
  470. package/dist/dev/playback/behaviors/dom/update-mediasource-duration.js +98 -0
  471. package/dist/dev/playback/behaviors/dom/update-mediasource-duration.js.map +1 -0
  472. package/dist/dev/playback/behaviors/establish-start-media-time.d.ts +32 -0
  473. package/dist/dev/playback/behaviors/establish-start-media-time.d.ts.map +1 -0
  474. package/dist/dev/playback/behaviors/establish-start-media-time.js +187 -0
  475. package/dist/dev/playback/behaviors/establish-start-media-time.js.map +1 -0
  476. package/dist/dev/playback/behaviors/resolve-presentation.d.ts +8 -0
  477. package/dist/dev/playback/behaviors/resolve-presentation.d.ts.map +1 -0
  478. package/dist/dev/playback/behaviors/resolve-presentation.js +76 -0
  479. package/dist/dev/playback/behaviors/resolve-presentation.js.map +1 -0
  480. package/dist/dev/playback/behaviors/resolve-track.js +134 -0
  481. package/dist/dev/playback/behaviors/resolve-track.js.map +1 -0
  482. package/dist/dev/playback/behaviors/select-tracks.d.ts +61 -0
  483. package/dist/dev/playback/behaviors/select-tracks.d.ts.map +1 -0
  484. package/dist/dev/playback/behaviors/select-tracks.js +189 -0
  485. package/dist/dev/playback/behaviors/select-tracks.js.map +1 -0
  486. package/dist/dev/playback/behaviors/setup-failover-monitor.d.ts +11 -0
  487. package/dist/dev/playback/behaviors/setup-failover-monitor.d.ts.map +1 -0
  488. package/dist/dev/playback/behaviors/setup-failover-monitor.js +61 -0
  489. package/dist/dev/playback/behaviors/setup-failover-monitor.js.map +1 -0
  490. package/dist/dev/playback/behaviors/sync-preload.js +59 -0
  491. package/dist/dev/playback/behaviors/sync-preload.js.map +1 -0
  492. package/dist/dev/playback/behaviors/track-switching.d.ts +110 -0
  493. package/dist/dev/playback/behaviors/track-switching.d.ts.map +1 -0
  494. package/dist/dev/playback/behaviors/track-switching.js +407 -0
  495. package/dist/dev/playback/behaviors/track-switching.js.map +1 -0
  496. package/dist/dev/playback/engines/hls/engine-audio-only.d.ts +160 -0
  497. package/dist/dev/playback/engines/hls/engine-audio-only.d.ts.map +1 -0
  498. package/dist/dev/playback/engines/hls/engine-audio-only.js +94 -0
  499. package/dist/dev/playback/engines/hls/engine-audio-only.js.map +1 -0
  500. package/dist/dev/playback/engines/hls/engine-background-video.d.ts +131 -0
  501. package/dist/dev/playback/engines/hls/engine-background-video.d.ts.map +1 -0
  502. package/dist/dev/playback/engines/hls/engine-background-video.js +87 -0
  503. package/dist/dev/playback/engines/hls/engine-background-video.js.map +1 -0
  504. package/dist/dev/playback/engines/hls/engine.d.ts +289 -0
  505. package/dist/dev/playback/engines/hls/engine.d.ts.map +1 -0
  506. package/dist/dev/playback/engines/hls/engine.js +144 -0
  507. package/dist/dev/playback/engines/hls/engine.js.map +1 -0
  508. package/dist/dev/playback/primitives/derive-start-media-time.d.ts +16 -0
  509. package/dist/dev/playback/primitives/derive-start-media-time.d.ts.map +1 -0
  510. package/dist/dev/playback/primitives/error-messages.js +42 -0
  511. package/dist/dev/playback/primitives/error-messages.js.map +1 -0
  512. package/dist/dev/playback/primitives/failover-fetch.js +37 -0
  513. package/dist/dev/playback/primitives/failover-fetch.js.map +1 -0
  514. package/dist/dev/playback/primitives/head-peek.js +41 -0
  515. package/dist/dev/playback/primitives/head-peek.js.map +1 -0
  516. package/dist/dev/playback/primitives/live-window.js +63 -0
  517. package/dist/dev/playback/primitives/live-window.js.map +1 -0
  518. package/dist/dev/playback/primitives/relocation-pipelines.js +191 -0
  519. package/dist/dev/playback/primitives/relocation-pipelines.js.map +1 -0
  520. package/dist/dev/playback/primitives/report-track-conditions.d.ts +8 -0
  521. package/dist/dev/playback/primitives/report-track-conditions.d.ts.map +1 -0
  522. package/dist/dev/playback/primitives/report-track-conditions.js +74 -0
  523. package/dist/dev/playback/primitives/report-track-conditions.js.map +1 -0
  524. package/dist/dev/playback/primitives/segment-load-pipeline.d.ts +2 -0
  525. package/dist/dev/playback/primitives/segment-load-pipeline.js +96 -0
  526. package/dist/dev/playback/primitives/segment-load-pipeline.js.map +1 -0
  527. package/dist/dev/playback/primitives/selection-rules.d.ts +66 -0
  528. package/dist/dev/playback/primitives/selection-rules.d.ts.map +1 -0
  529. package/dist/dev/playback/primitives/selection-rules.js +115 -0
  530. package/dist/dev/playback/primitives/selection-rules.js.map +1 -0
  531. package/dist/dev/playback/primitives/source-buffer-messages.d.ts +40 -0
  532. package/dist/dev/playback/primitives/source-buffer-messages.d.ts.map +1 -0
  533. package/dist/dev/playback/primitives/text-segment-load-pipeline.d.ts +56 -0
  534. package/dist/dev/playback/primitives/text-segment-load-pipeline.d.ts.map +1 -0
  535. package/dist/dev/playback/primitives/text-segment-load-pipeline.js +36 -0
  536. package/dist/dev/playback/primitives/text-segment-load-pipeline.js.map +1 -0
  537. package/dist/dev/playback/primitives/text-track-messages.d.ts +14 -0
  538. package/dist/dev/playback/primitives/text-track-messages.d.ts.map +1 -0
  539. package/dist/dev/playback/primitives/track-types.js +53 -0
  540. package/dist/dev/playback/primitives/track-types.js.map +1 -0
  541. package/package.json +60 -41
  542. package/dist/adapter-25AtMN8s.d.ts +0 -719
  543. package/dist/adapter-25AtMN8s.d.ts.map +0 -1
  544. package/dist/adapter-CflgYzjF.js +0 -3556
  545. package/dist/adapter-CflgYzjF.js.map +0 -1
  546. package/dist/dom/index.d.ts +0 -221
  547. package/dist/dom/index.d.ts.map +0 -1
  548. package/dist/dom/index.js +0 -38
  549. package/dist/dom/index.js.map +0 -1
  550. package/dist/dom/playback-engine/index.d.ts +0 -2
  551. package/dist/dom/playback-engine/index.js +0 -4
  552. package/dist/index.d.ts +0 -13
  553. package/dist/index.d.ts.map +0 -1
  554. package/dist/index.js +0 -3
  555. package/dist/src-DRsS_H80.js +0 -14
  556. package/dist/src-DRsS_H80.js.map +0 -1
@@ -0,0 +1,191 @@
1
+ import { peek, update } from "../../core/signals/primitives.js";
2
+ import { effect } from "../../core/signals/effect.js";
3
+ import { resolveVttSegmentMetadata } from "../../media/text/resolve-vtt-metadata.js";
4
+ import { findTrackById, getTracksByType } from "../../media/utils/tracks.js";
5
+ import { dispatchCuesStep, textStepWiring } from "./text-segment-load-pipeline.js";
6
+ import { dispatchStep, fetchStep } from "./segment-load-pipeline.js";
7
+ import { findMediaTrack, readBaseMediaDecodeTime } from "../../media/mp4/timestamp-origin.js";
8
+ import { peekHead } from "./head-peek.js";
9
+ //#region src/playback/primitives/relocation-pipelines.ts
10
+ /** Assert the relocation state view from the opaque step deps — this module knows the slots the composition provides. */
11
+ function relocationState(deps) {
12
+ return deps.state;
13
+ }
14
+ function containerSlot(deps) {
15
+ return relocationState(deps).mediaContainerData;
16
+ }
17
+ /** Synchronous RMW of the per-type entry — disjoint keys across producers, so no lost update. */
18
+ function writeContainer(slot, trackType, patch) {
19
+ update(slot, (current) => ({
20
+ ...current,
21
+ [trackType]: {
22
+ ...current?.[trackType],
23
+ ...patch
24
+ }
25
+ }));
26
+ }
27
+ /**
28
+ * Resolve once `read()` returns a number. Shared by the A/V stamp (waits for the `derive`d origin — immediate for
29
+ * per-type, the shared-`min` barrier for coordinated) and the text step (waits for the primary A/V origin). No bound:
30
+ * for fMP4 the origin always establishes.
31
+ */
32
+ function awaitDefined(read) {
33
+ return new Promise((resolve) => {
34
+ let stop;
35
+ stop = effect(() => {
36
+ const value = read();
37
+ if (value !== void 0) {
38
+ stop?.();
39
+ resolve(value);
40
+ }
41
+ });
42
+ });
43
+ }
44
+ /**
45
+ * Relocation pipelines for one track type — a plain config `messagePipelines`. Keyed by **track type** (`'video'` /
46
+ * `'audio'`), so ABR rungs of a type share the origin (discover skips once the type's value is present). The steps
47
+ * read/write `state.mediaContainerData[trackType]` via their call-time `deps`; the stamp applies the same `derive` seam
48
+ * the reactor uses (pass the composition's resolved `deriveStartMediaTime` so the buffer offset and the model's
49
+ * `startMediaTime` agree).
50
+ */
51
+ function relocationPipelinesFor(trackType, derive) {
52
+ const handlerType = trackType === "video" ? "vide" : "soun";
53
+ /**
54
+ * Init step: head-peek the buffered media track's `track_id` + `mdhd` timescale into `mediaContainerData[trackType]`.
55
+ * Matching by handler (`vide`/`soun`) skips a muxed `clcp` caption track, and the `track_id` lets `readSegmentOrigin`
56
+ * read _this_ track's `tfdt` rather than the first `traf` in the segment.
57
+ */
58
+ const readInitTrackInfo = async (frame, _signal, deps) => {
59
+ const { op } = frame;
60
+ if (op.type !== "append-init" || !frame.data) return;
61
+ const slot = containerSlot(deps);
62
+ if (peek(slot)?.[trackType]?.timescale !== void 0) return;
63
+ frame.data = await peekHead(frame.data, (bytes) => {
64
+ const track = findMediaTrack(bytes, handlerType);
65
+ if (track === void 0) return false;
66
+ writeContainer(slot, trackType, {
67
+ trackId: track.trackId,
68
+ timescale: track.timescale
69
+ });
70
+ return true;
71
+ });
72
+ };
73
+ /**
74
+ * Media-segment step: head-peek the `tfdt` baseMediaDecodeTime of the media track's `traf` (matched by the `track_id`
75
+ * discovered from the init), recording the segment's 0-based `startTime` with it — the origin is `bmdt/ts −
76
+ * segmentStartTime`, so the first _loaded_ segment need not be the 0th. Without a discovered `track_id` (non-fMP4 /
77
+ * mock init) there's no media track to relocate, so the step no-ops and the append stays native.
78
+ */
79
+ const readSegmentOrigin = async (frame, _signal, deps) => {
80
+ const { op } = frame;
81
+ if (op.type !== "append-segment" || !frame.data) return;
82
+ const slot = containerSlot(deps);
83
+ const container = peek(slot)?.[trackType];
84
+ if (container?.baseMediaDecodeTime !== void 0) return;
85
+ const { trackId } = container ?? {};
86
+ if (trackId === void 0) return;
87
+ const segmentStartTime = op.meta.startTime;
88
+ frame.data = await peekHead(frame.data, (bytes) => {
89
+ const baseMediaDecodeTime = readBaseMediaDecodeTime(bytes, trackId);
90
+ if (baseMediaDecodeTime === void 0) return false;
91
+ writeContainer(slot, trackType, {
92
+ baseMediaDecodeTime,
93
+ segmentStartTime
94
+ });
95
+ return true;
96
+ });
97
+ };
98
+ /**
99
+ * Stamp step — tier-agnostic apply. Relocate by the `derive`d `startMediaTime` for this type (`offset =
100
+ * −startMediaTime`). Applies the **same** `derive` the reactor uses, over the shared `mediaContainerData` slot — so
101
+ * the buffer offset matches the model's stamped `startMediaTime`, and it's robust to `established` + late tracks (the
102
+ * slot persists; the model value may not be re-stamped after the reactor goes sticky). Awaited: per-type resolves at
103
+ * once (own origin discovered earlier in this pipeline); shared-`min` waits until every selected A/V origin is in —
104
+ * the barrier, filled by the other type's discover step. A derived `0` (0-PTS / below threshold) leaves the append
105
+ * native — setting `timestampOffset` at all can ripple.
106
+ */
107
+ const stampStartMediaTime = async (frame, signal, deps) => {
108
+ if (frame.op.type !== "append-segment") return;
109
+ const state = relocationState(deps);
110
+ const own = peek(state.mediaContainerData)?.[trackType];
111
+ if (own?.timescale === void 0 || own.baseMediaDecodeTime === void 0 || own.segmentStartTime === void 0) return;
112
+ const startMediaTime = await awaitDefined(() => {
113
+ const containerData = state.mediaContainerData.get();
114
+ if (!containerData) return void 0;
115
+ return derive(containerData, {
116
+ selectedVideoTrackId: state.selectedVideoTrackId?.get(),
117
+ selectedAudioTrackId: state.selectedAudioTrackId?.get()
118
+ })[trackType];
119
+ });
120
+ if (signal.aborted || startMediaTime === 0) return;
121
+ frame.meta = {
122
+ ...frame.meta ?? frame.op.meta,
123
+ timestampOffset: -startMediaTime
124
+ };
125
+ };
126
+ return () => ({
127
+ remove: [dispatchStep],
128
+ "append-init": [
129
+ fetchStep,
130
+ readInitTrackInfo,
131
+ dispatchStep
132
+ ],
133
+ "append-segment": [
134
+ fetchStep,
135
+ readSegmentOrigin,
136
+ stampStartMediaTime,
137
+ dispatchStep
138
+ ]
139
+ });
140
+ }
141
+ /**
142
+ * Resolve step for the relocation text pipeline. Reuses the injected host resolver (the loader's folded
143
+ * `resolveSegment`, via `textStepWiring`) for cues and fetches the `X-TIMESTAMP-MAP` header in parallel, stashing it on
144
+ * `frame.metadata` for `relocateCuesStep`. Replaces the base `resolveCuesStep` (which fetches cues only) — text's
145
+ * native `<track>` parser discards the header, so the map needs its own raw-bytes fetch.
146
+ */
147
+ const resolveWithMetadataStep = async (frame, signal, deps) => {
148
+ const [cues, metadata] = await Promise.all([textStepWiring(deps).resolveSegment(frame.op.segment.url), resolveVttSegmentMetadata(frame.op.segment.url)]);
149
+ if (signal.aborted) return;
150
+ frame.cues = cues;
151
+ frame.metadata = metadata;
152
+ };
153
+ /**
154
+ * Relocate step — shifts each cue onto the 0-based presentation timeline: `cueFinal = cueNative − startMediaTime`,
155
+ * where `startMediaTime` is the primary A/V track's origin (selected **video**, else **audio** — the single-anchor
156
+ * rule, and defensive like the reactor's optional selection) and `cueNative` folds in the `X-TIMESTAMP-MAP` correction
157
+ * (`mpegts/90000 − local`) for map-bearing VTT (Apple) or is the absolute cue time (no map, e.g. Mux). Text can resolve
158
+ * before A/V establishes, so the origin is awaited; fMP4 always establishes it (0-PTS → 0), and a text-only source (no
159
+ * A/V selected) simply gets offset 0.
160
+ */
161
+ const relocateCuesStep = async (frame, signal, deps) => {
162
+ if (!frame.cues?.length) return;
163
+ const state = deps.state;
164
+ const startMediaTime = await awaitDefined(() => {
165
+ const presentation = state.presentation.get();
166
+ if (!presentation) return void 0;
167
+ const primaryId = state.selectedVideoTrackId.get() ?? state.selectedAudioTrackId.get();
168
+ if (primaryId !== void 0) return findTrackById(presentation, primaryId)?.startMediaTime;
169
+ return getTracksByType(presentation, "video").length > 0 || getTracksByType(presentation, "audio").length > 0 ? void 0 : 0;
170
+ });
171
+ if (signal.aborted) return;
172
+ const { timestampMap } = frame.metadata ?? {};
173
+ const delta = (timestampMap ? timestampMap.mpegts / 9e4 - timestampMap.local : 0) - startMediaTime;
174
+ if (delta !== 0) for (const cue of frame.cues) {
175
+ cue.startTime += delta;
176
+ cue.endTime += delta;
177
+ }
178
+ };
179
+ /**
180
+ * Relocation text pipeline — the text analog of `relocationPipelinesFor(type)`. `resolveWithMetadata` (cues +
181
+ * `X-TIMESTAMP-MAP`) → `relocateCues` (shift by the primary A/V origin) → `dispatchCues`.
182
+ */
183
+ const relocatingTextPipelines = () => [
184
+ resolveWithMetadataStep,
185
+ relocateCuesStep,
186
+ dispatchCuesStep
187
+ ];
188
+ //#endregion
189
+ export { relocatingTextPipelines, relocationPipelinesFor };
190
+
191
+ //# sourceMappingURL=relocation-pipelines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relocation-pipelines.js","names":[],"sources":["../../../../src/playback/primitives/relocation-pipelines.ts"],"sourcesContent":["/**\n * Non-zero-PTS relocation pipelines — the config-supplied, loader-facing half of the `establishStartMediaTime` behavior\n * (`../behaviors/establish-start-media-time`). The reactor there owns the lifecycle and the `derive` coordination seam;\n * this file supplies the `messagePipelines` the segment/text loaders run to _fill and act on_ that behavior's state.\n * It's the relocation analog of `track-switching`'s config-supplied constraint/rule chain — a pluggable strategy handed\n * to the machinery via config, not applied inline — supplied to the loaders rather than applied by the behavior, so the\n * two coordinate through the shared `mediaContainerData` / `startMediaTime` slots alone, never by import.\n *\n * DOM-free: it composes the loader vocabularies (`segment-load-pipeline`, `text-segment-load-pipeline`) through their\n * structural sink seams and shifts cues via the structural `Cue` type, so it names no `SourceBuffer`,\n * `TextTracksActor`, or `VTTCue`. The A/V pipeline is a plain `messagePipelines` array:\n *\n * - `discover` — init `track_id` + `mdhd` timescale for the buffered media track, then that same track's `tfdt`\n * baseMediaDecodeTime, matched by `track_id` so a muxed segment reads the media track's origin, not the first `traf`\n * — writes `state.mediaContainerData`.\n * - `stamp` — reads that track's derived origin back and relocates via `timestampOffset = −startMediaTime`. Steps read\n * composition `state` from their call-time `deps` (no closures, no context).\n *\n * The text half (`relocatingTextPipelines`) is the same idea for the text-segment loader: a `resolveWithMetadata →\n * relocateCues → dispatchCues` pipeline that shifts cues onto the same 0-based timeline, reading the primary A/V\n * track's `startMediaTime` (the reactor's consumed value) via `deps`.\n */\nimport type { StateSignals } from '../../core/composition/create-composition';\nimport { effect } from '../../core/signals/effect';\nimport { peek, type Signal, update } from '../../core/signals/primitives';\nimport { findMediaTrack, type MediaHandlerType, readBaseMediaDecodeTime } from '../../media/mp4/timestamp-origin';\nimport { resolveVttSegmentMetadata, type TextSegmentMetadata } from '../../media/text/resolve-vtt-metadata';\nimport type { Cue, MaybeResolvedPresentation, MediaContainerData } from '../../media/types';\nimport { findTrackById, getTracksByType } from '../../media/utils/tracks';\nimport type { DeriveStartMediaTime } from './derive-start-media-time';\nimport { peekHead } from './head-peek';\nimport { dispatchStep, fetchStep, type LoadStep, type MessagePipelines, type StepDeps } from './segment-load-pipeline';\nimport {\n dispatchCuesStep,\n type TextFrame,\n type TextLoadStep,\n type TextStepDeps,\n textStepWiring,\n} from './text-segment-load-pipeline';\n\n/** The composition slots these steps read — the view asserted from the opaque `deps.state`. */\ninterface RelocationSlots {\n presentation?: MaybeResolvedPresentation;\n mediaContainerData?: Record<string, MediaContainerData>;\n selectedVideoTrackId?: string;\n selectedAudioTrackId?: string;\n}\n\ntype ContainerSlot = Signal<Record<string, MediaContainerData> | undefined>;\n\n/** Assert the relocation state view from the opaque step deps — this module knows the slots the composition provides. */\nfunction relocationState(deps: StepDeps): StateSignals<RelocationSlots> {\n return deps.state as unknown as StateSignals<RelocationSlots>;\n}\n\nfunction containerSlot(deps: StepDeps): ContainerSlot {\n return relocationState(deps).mediaContainerData;\n}\n\n/** Synchronous RMW of the per-type entry — disjoint keys across producers, so no lost update. */\nfunction writeContainer(slot: ContainerSlot, trackType: string, patch: Partial<MediaContainerData>): void {\n update(slot, (current) => ({ ...current, [trackType]: { ...current?.[trackType], ...patch } }));\n}\n\n/**\n * Resolve once `read()` returns a number. Shared by the A/V stamp (waits for the `derive`d origin — immediate for\n * per-type, the shared-`min` barrier for coordinated) and the text step (waits for the primary A/V origin). No bound:\n * for fMP4 the origin always establishes.\n */\nfunction awaitDefined(read: () => number | undefined): Promise<number> {\n return new Promise((resolve) => {\n let stop: (() => void) | undefined;\n\n stop = effect(() => {\n const value = read();\n\n if (value !== undefined) {\n stop?.();\n resolve(value);\n }\n });\n });\n}\n\n/**\n * Relocation pipelines for one track type — a plain config `messagePipelines`. Keyed by **track type** (`'video'` /\n * `'audio'`), so ABR rungs of a type share the origin (discover skips once the type's value is present). The steps\n * read/write `state.mediaContainerData[trackType]` via their call-time `deps`; the stamp applies the same `derive` seam\n * the reactor uses (pass the composition's resolved `deriveStartMediaTime` so the buffer offset and the model's\n * `startMediaTime` agree).\n */\nexport function relocationPipelinesFor(trackType: 'video' | 'audio', derive: DeriveStartMediaTime): MessagePipelines {\n const handlerType: MediaHandlerType = trackType === 'video' ? 'vide' : 'soun';\n\n /**\n * Init step: head-peek the buffered media track's `track_id` + `mdhd` timescale into `mediaContainerData[trackType]`.\n * Matching by handler (`vide`/`soun`) skips a muxed `clcp` caption track, and the `track_id` lets `readSegmentOrigin`\n * read _this_ track's `tfdt` rather than the first `traf` in the segment.\n */\n const readInitTrackInfo: LoadStep = async (frame, _signal, deps) => {\n const { op } = frame;\n if (op.type !== 'append-init' || !frame.data) return;\n\n const slot = containerSlot(deps);\n if (peek(slot)?.[trackType]?.timescale !== undefined) return; // already have it (any rung of this type)\n\n frame.data = await peekHead(frame.data, (bytes) => {\n const track = findMediaTrack(bytes, handlerType);\n if (track === undefined) return false;\n\n writeContainer(slot, trackType, { trackId: track.trackId, timescale: track.timescale });\n return true;\n });\n };\n\n /**\n * Media-segment step: head-peek the `tfdt` baseMediaDecodeTime of the media track's `traf` (matched by the `track_id`\n * discovered from the init), recording the segment's 0-based `startTime` with it — the origin is `bmdt/ts −\n * segmentStartTime`, so the first _loaded_ segment need not be the 0th. Without a discovered `track_id` (non-fMP4 /\n * mock init) there's no media track to relocate, so the step no-ops and the append stays native.\n */\n const readSegmentOrigin: LoadStep = async (frame, _signal, deps) => {\n const { op } = frame;\n if (op.type !== 'append-segment' || !frame.data) return;\n\n const slot = containerSlot(deps);\n const container = peek(slot)?.[trackType];\n if (container?.baseMediaDecodeTime !== undefined) return; // established\n\n const { trackId } = container ?? {};\n if (trackId === undefined) return; // init didn't identify a media track — nothing to match\n\n const segmentStartTime = op.meta.startTime;\n\n frame.data = await peekHead(frame.data, (bytes) => {\n const baseMediaDecodeTime = readBaseMediaDecodeTime(bytes, trackId);\n if (baseMediaDecodeTime === undefined) return false;\n\n writeContainer(slot, trackType, { baseMediaDecodeTime, segmentStartTime });\n return true;\n });\n };\n\n /**\n * Stamp step — tier-agnostic apply. Relocate by the `derive`d `startMediaTime` for this type (`offset =\n * −startMediaTime`). Applies the **same** `derive` the reactor uses, over the shared `mediaContainerData` slot — so\n * the buffer offset matches the model's stamped `startMediaTime`, and it's robust to `established` + late tracks (the\n * slot persists; the model value may not be re-stamped after the reactor goes sticky). Awaited: per-type resolves at\n * once (own origin discovered earlier in this pipeline); shared-`min` waits until every selected A/V origin is in —\n * the barrier, filled by the other type's discover step. A derived `0` (0-PTS / below threshold) leaves the append\n * native — setting `timestampOffset` at all can ripple.\n */\n const stampStartMediaTime: LoadStep = async (frame, signal, deps) => {\n if (frame.op.type !== 'append-segment') return;\n\n const state = relocationState(deps);\n // Liveness guard: if THIS type's own origin wasn't discovered — `readSegmentOrigin`\n // ran earlier in this pipeline and found no `tfdt` (mock / TS / containerless) — the\n // source isn't relocatable, so leave the append native and DON'T wait. Only a\n // discoverable type awaits the derived origin (which for shared-`min` legitimately\n // blocks on the other selected type — the barrier).\n const own = peek(state.mediaContainerData)?.[trackType];\n\n if (own?.timescale === undefined || own.baseMediaDecodeTime === undefined || own.segmentStartTime === undefined) {\n return;\n }\n\n const startMediaTime = await awaitDefined(() => {\n const containerData = state.mediaContainerData.get();\n if (!containerData) return undefined;\n\n return derive(containerData, {\n selectedVideoTrackId: state.selectedVideoTrackId?.get(),\n selectedAudioTrackId: state.selectedAudioTrackId?.get(),\n })[trackType];\n });\n if (signal.aborted || startMediaTime === 0) return;\n\n frame.meta = { ...(frame.meta ?? frame.op.meta), timestampOffset: -startMediaTime };\n };\n\n return () => ({\n remove: [dispatchStep],\n 'append-init': [fetchStep, readInitTrackInfo, dispatchStep],\n 'append-segment': [fetchStep, readSegmentOrigin, stampStartMediaTime, dispatchStep],\n });\n}\n\n// ============================================================================\n// TEXT (cue relocation)\n// ============================================================================\n\n/**\n * Resolve step for the relocation text pipeline. Reuses the injected host resolver (the loader's folded\n * `resolveSegment`, via `textStepWiring`) for cues and fetches the `X-TIMESTAMP-MAP` header in parallel, stashing it on\n * `frame.metadata` for `relocateCuesStep`. Replaces the base `resolveCuesStep` (which fetches cues only) — text's\n * native `<track>` parser discards the header, so the map needs its own raw-bytes fetch.\n */\nconst resolveWithMetadataStep = async <C extends Cue>(\n frame: TextFrame<C>,\n signal: AbortSignal,\n deps: TextStepDeps\n): Promise<void> => {\n const [cues, metadata] = await Promise.all([\n textStepWiring<C>(deps).resolveSegment(frame.op.segment.url),\n resolveVttSegmentMetadata(frame.op.segment.url),\n ]);\n\n if (signal.aborted) return;\n\n frame.cues = cues;\n frame.metadata = metadata;\n};\n\n/**\n * Relocate step — shifts each cue onto the 0-based presentation timeline: `cueFinal = cueNative − startMediaTime`,\n * where `startMediaTime` is the primary A/V track's origin (selected **video**, else **audio** — the single-anchor\n * rule, and defensive like the reactor's optional selection) and `cueNative` folds in the `X-TIMESTAMP-MAP` correction\n * (`mpegts/90000 − local`) for map-bearing VTT (Apple) or is the absolute cue time (no map, e.g. Mux). Text can resolve\n * before A/V establishes, so the origin is awaited; fMP4 always establishes it (0-PTS → 0), and a text-only source (no\n * A/V selected) simply gets offset 0.\n */\nconst relocateCuesStep = async <C extends Cue>(\n frame: TextFrame<C>,\n signal: AbortSignal,\n deps: TextStepDeps\n): Promise<void> => {\n if (!frame.cues?.length) return;\n\n const state = deps.state as unknown as StateSignals<RelocationSlots>;\n const startMediaTime = await awaitDefined(() => {\n const presentation = state.presentation.get();\n if (!presentation) return undefined;\n\n const primaryId = state.selectedVideoTrackId.get() ?? state.selectedAudioTrackId.get();\n\n if (primaryId !== undefined) {\n // A/V selected: use its origin once stamped (undefined until then → keep waiting).\n return findTrackById(presentation, primaryId)?.startMediaTime;\n }\n\n // No A/V selected. Distinguish \"not selected YET\" from \"text-only source\". If the\n // presentation has A/V tracks, one WILL be selected and stamped — wait for it, or the\n // cues get shifted by the full `mapCorrection` (e.g. +10s on Apple X-TIMESTAMP-MAP\n // sources) when text relocation wins the race against A/V selection. Only a genuinely\n // text-only source (no A/V origin ever coming) legitimately relocates by offset 0.\n const hasAv =\n getTracksByType(presentation, 'video').length > 0 || getTracksByType(presentation, 'audio').length > 0;\n\n return hasAv ? undefined : 0;\n });\n\n if (signal.aborted) return;\n\n const { timestampMap } = (frame.metadata as TextSegmentMetadata | undefined) ?? {};\n const mapCorrection = timestampMap ? timestampMap.mpegts / 90000 - timestampMap.local : 0;\n const delta = mapCorrection - startMediaTime;\n\n if (delta !== 0) {\n for (const cue of frame.cues) {\n cue.startTime += delta;\n cue.endTime += delta;\n }\n }\n};\n\n/**\n * Relocation text pipeline — the text analog of `relocationPipelinesFor(type)`. `resolveWithMetadata` (cues +\n * `X-TIMESTAMP-MAP`) → `relocateCues` (shift by the primary A/V origin) → `dispatchCues`.\n */\nexport const relocatingTextPipelines = <C extends Cue>(): TextLoadStep<C>[] => [\n resolveWithMetadataStep,\n relocateCuesStep,\n dispatchCuesStep,\n];\n"],"mappings":";;;;;;;;;;AAmDA,SAAS,gBAAgB,MAA+C;CACtE,OAAO,KAAK;AACd;AAEA,SAAS,cAAc,MAA+B;CACpD,OAAO,gBAAgB,IAAI,CAAC,CAAC;AAC/B;;AAGA,SAAS,eAAe,MAAqB,WAAmB,OAA0C;CACxG,OAAO,OAAO,aAAa;EAAE,GAAG;GAAU,YAAY;GAAE,GAAG,UAAU;GAAY,GAAG;EAAM;CAAE,EAAE;AAChG;;;;;;AAOA,SAAS,aAAa,MAAiD;CACrE,OAAO,IAAI,SAAS,YAAY;EAC9B,IAAI;EAEJ,OAAO,aAAa;GAClB,MAAM,QAAQ,KAAK;GAEnB,IAAI,UAAU,KAAA,GAAW;IACvB,OAAO;IACP,QAAQ,KAAK;GACf;EACF,CAAC;CACH,CAAC;AACH;;;;;;;;AASA,SAAgB,uBAAuB,WAA8B,QAAgD;CACnH,MAAM,cAAgC,cAAc,UAAU,SAAS;;;;;;CAOvE,MAAM,oBAA8B,OAAO,OAAO,SAAS,SAAS;EAClE,MAAM,EAAE,OAAO;EACf,IAAI,GAAG,SAAS,iBAAiB,CAAC,MAAM,MAAM;EAE9C,MAAM,OAAO,cAAc,IAAI;EAC/B,IAAI,KAAK,IAAI,CAAC,GAAG,UAAU,EAAE,cAAc,KAAA,GAAW;EAEtD,MAAM,OAAO,MAAM,SAAS,MAAM,OAAO,UAAU;GACjD,MAAM,QAAQ,eAAe,OAAO,WAAW;GAC/C,IAAI,UAAU,KAAA,GAAW,OAAO;GAEhC,eAAe,MAAM,WAAW;IAAE,SAAS,MAAM;IAAS,WAAW,MAAM;GAAU,CAAC;GACtF,OAAO;EACT,CAAC;CACH;;;;;;;CAQA,MAAM,oBAA8B,OAAO,OAAO,SAAS,SAAS;EAClE,MAAM,EAAE,OAAO;EACf,IAAI,GAAG,SAAS,oBAAoB,CAAC,MAAM,MAAM;EAEjD,MAAM,OAAO,cAAc,IAAI;EAC/B,MAAM,YAAY,KAAK,IAAI,CAAC,GAAG;EAC/B,IAAI,WAAW,wBAAwB,KAAA,GAAW;EAElD,MAAM,EAAE,YAAY,aAAa,CAAC;EAClC,IAAI,YAAY,KAAA,GAAW;EAE3B,MAAM,mBAAmB,GAAG,KAAK;EAEjC,MAAM,OAAO,MAAM,SAAS,MAAM,OAAO,UAAU;GACjD,MAAM,sBAAsB,wBAAwB,OAAO,OAAO;GAClE,IAAI,wBAAwB,KAAA,GAAW,OAAO;GAE9C,eAAe,MAAM,WAAW;IAAE;IAAqB;GAAiB,CAAC;GACzE,OAAO;EACT,CAAC;CACH;;;;;;;;;;CAWA,MAAM,sBAAgC,OAAO,OAAO,QAAQ,SAAS;EACnE,IAAI,MAAM,GAAG,SAAS,kBAAkB;EAExC,MAAM,QAAQ,gBAAgB,IAAI;EAMlC,MAAM,MAAM,KAAK,MAAM,kBAAkB,CAAC,GAAG;EAE7C,IAAI,KAAK,cAAc,KAAA,KAAa,IAAI,wBAAwB,KAAA,KAAa,IAAI,qBAAqB,KAAA,GACpG;EAGF,MAAM,iBAAiB,MAAM,mBAAmB;GAC9C,MAAM,gBAAgB,MAAM,mBAAmB,IAAI;GACnD,IAAI,CAAC,eAAe,OAAO,KAAA;GAE3B,OAAO,OAAO,eAAe;IAC3B,sBAAsB,MAAM,sBAAsB,IAAI;IACtD,sBAAsB,MAAM,sBAAsB,IAAI;GACxD,CAAC,CAAC,CAAC;EACL,CAAC;EACD,IAAI,OAAO,WAAW,mBAAmB,GAAG;EAE5C,MAAM,OAAO;GAAE,GAAI,MAAM,QAAQ,MAAM,GAAG;GAAO,iBAAiB,CAAC;EAAe;CACpF;CAEA,cAAc;EACZ,QAAQ,CAAC,YAAY;EACrB,eAAe;GAAC;GAAW;GAAmB;EAAY;EAC1D,kBAAkB;GAAC;GAAW;GAAmB;GAAqB;EAAY;CACpF;AACF;;;;;;;AAYA,MAAM,0BAA0B,OAC9B,OACA,QACA,SACkB;CAClB,MAAM,CAAC,MAAM,YAAY,MAAM,QAAQ,IAAI,CACzC,eAAkB,IAAI,CAAC,CAAC,eAAe,MAAM,GAAG,QAAQ,GAAG,GAC3D,0BAA0B,MAAM,GAAG,QAAQ,GAAG,CAChD,CAAC;CAED,IAAI,OAAO,SAAS;CAEpB,MAAM,OAAO;CACb,MAAM,WAAW;AACnB;;;;;;;;;AAUA,MAAM,mBAAmB,OACvB,OACA,QACA,SACkB;CAClB,IAAI,CAAC,MAAM,MAAM,QAAQ;CAEzB,MAAM,QAAQ,KAAK;CACnB,MAAM,iBAAiB,MAAM,mBAAmB;EAC9C,MAAM,eAAe,MAAM,aAAa,IAAI;EAC5C,IAAI,CAAC,cAAc,OAAO,KAAA;EAE1B,MAAM,YAAY,MAAM,qBAAqB,IAAI,KAAK,MAAM,qBAAqB,IAAI;EAErF,IAAI,cAAc,KAAA,GAEhB,OAAO,cAAc,cAAc,SAAS,CAAC,EAAE;EAWjD,OAFE,gBAAgB,cAAc,OAAO,CAAC,CAAC,SAAS,KAAK,gBAAgB,cAAc,OAAO,CAAC,CAAC,SAAS,IAExF,KAAA,IAAY;CAC7B,CAAC;CAED,IAAI,OAAO,SAAS;CAEpB,MAAM,EAAE,iBAAkB,MAAM,YAAgD,CAAC;CAEjF,MAAM,SADgB,eAAe,aAAa,SAAS,MAAQ,aAAa,QAAQ,KAC1D;CAE9B,IAAI,UAAU,GACZ,KAAK,MAAM,OAAO,MAAM,MAAM;EAC5B,IAAI,aAAa;EACjB,IAAI,WAAW;CACjB;AAEJ;;;;;AAMA,MAAa,gCAAkE;CAC7E;CACA;CACA;AACF"}
@@ -0,0 +1,74 @@
1
+ import { getMediaPlaylistMetadata } from "../../media/types/index.js";
2
+ import { SVTA_UNSUPPORTED_AUDIO_FORMAT, SVTA_UNSUPPORTED_DRM_SYSTEM, SVTA_UNSUPPORTED_VIDEO_FORMAT } from "../../media/errors.js";
3
+ import { NON_FMP4_CONTAINER_MIMES } from "../../media/hls/parse-media-playlist.js";
4
+ //#region src/playback/primitives/report-track-conditions.ts
5
+ /**
6
+ * The seam `resolve-track` uses to report conditions discovered in a freshly parsed media playlist.
7
+ *
8
+ * Injected rather than baked in so `resolve-track` stays free of format and policy knowledge: it parses and commits,
9
+ * and whatever the composition wants noticed about the result is this function's business. Which conditions matter, and
10
+ * which codes they carry, therefore vary per composition — a provider that never ships MPEG-TS can drop that check, and
11
+ * future playlist-derived notices (LL-HLS or DVR support that's partial rather than absent) attach here without
12
+ * touching the resolver.
13
+ *
14
+ * Reported **per rendition, as it resolves**, which is why these are causes and not verdicts: one rendition being
15
+ * unplayable doesn't make the source unplayable. The verdict is `track-switching`'s, which reports
16
+ * `SVTA_NO_SUPPORTED_{VIDEO,AUDIO}_TRACK` when a type's candidates actually empty. Keeping the two apart is what lets a
17
+ * mixed source — some renditions encrypted or MPEG-TS, others playable — log its causes and still play.
18
+ */
19
+ /** Unsupported-format code per type; text has none — absent captions aren't a failure. */
20
+ const UNSUPPORTED_FORMAT_CODE = {
21
+ video: SVTA_UNSUPPORTED_VIDEO_FORMAT,
22
+ audio: SVTA_UNSUPPORTED_AUDIO_FORMAT
23
+ };
24
+ /**
25
+ * The types a reported cause can legitimately describe: the ones whose candidates `canPlayTrack` actually prunes, via
26
+ * `track-switching`'s `excludeUnplayableTracks` pre-pass.
27
+ *
28
+ * Text is outside it by design — its switching chain runs failed-CDN constraints alone, because an MSE codec probe is
29
+ * the wrong question for a WebVTT rendition (see `track-switching.ts`). So nothing prunes a text rendition, no verdict
30
+ * can follow from one, and a cause reported against it would be an orphan: the adapter's unsupported-feature
31
+ * substitution scans the sequence as a whole, so a lone encrypted subtitle would otherwise recode an unrelated verdict
32
+ * — an all-CDN cooldown among them — as "this engine can't play the source".
33
+ */
34
+ const CAPABILITY_PRUNED_TYPES = /* @__PURE__ */ new Set(["video", "audio"]);
35
+ /**
36
+ * The default: report what makes a rendition unplayable _to this engine_ — a container MSE can't accept, or encryption
37
+ * with no decryption pipeline. Both mirror what `canPlayTrack` prunes on, so a reported cause always has a
38
+ * corresponding exclusion.
39
+ *
40
+ * A condition carries its code and its context, not copy. `data.mimeType` is what preserves the specificity — the
41
+ * format codes cover every non-fMP4 container, so "which one" lives there for a consumer that wants to say, rather than
42
+ * being flattened into an English sentence here.
43
+ *
44
+ * Both carry `trackType`, redundantly for the format codes (1004/1005 are already per type) but not for 4008, which
45
+ * isn't per type — SVTA has one content-protection code for both. Nothing branches on the tag: it's diagnostic context,
46
+ * reaching a developer through the logged sequence and `error.data`, which is why it goes on every condition rather
47
+ * than only where the code can't carry it. `trackId` alongside it is what distinguishes two renditions of the same
48
+ * type.
49
+ */
50
+ function reportUnsupportedTrackConditions(track) {
51
+ if (!CAPABILITY_PRUNED_TYPES.has(track.type)) return [];
52
+ const conditions = [];
53
+ const data = {
54
+ trackType: track.type,
55
+ trackId: track.id
56
+ };
57
+ const formatCode = UNSUPPORTED_FORMAT_CODE[track.type];
58
+ if (formatCode !== void 0 && NON_FMP4_CONTAINER_MIMES.has(track.mimeType)) conditions.push({
59
+ code: formatCode,
60
+ data: {
61
+ ...data,
62
+ mimeType: track.mimeType
63
+ }
64
+ });
65
+ if (getMediaPlaylistMetadata(track)?.encrypted) conditions.push({
66
+ code: SVTA_UNSUPPORTED_DRM_SYSTEM,
67
+ data
68
+ });
69
+ return conditions;
70
+ }
71
+ //#endregion
72
+ export { reportUnsupportedTrackConditions };
73
+
74
+ //# sourceMappingURL=report-track-conditions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report-track-conditions.js","names":[],"sources":["../../../../src/playback/primitives/report-track-conditions.ts"],"sourcesContent":["/**\n * The seam `resolve-track` uses to report conditions discovered in a freshly parsed media playlist.\n *\n * Injected rather than baked in so `resolve-track` stays free of format and policy knowledge: it parses and commits,\n * and whatever the composition wants noticed about the result is this function's business. Which conditions matter, and\n * which codes they carry, therefore vary per composition — a provider that never ships MPEG-TS can drop that check, and\n * future playlist-derived notices (LL-HLS or DVR support that's partial rather than absent) attach here without\n * touching the resolver.\n *\n * Reported **per rendition, as it resolves**, which is why these are causes and not verdicts: one rendition being\n * unplayable doesn't make the source unplayable. The verdict is `track-switching`'s, which reports\n * `SVTA_NO_SUPPORTED_{VIDEO,AUDIO}_TRACK` when a type's candidates actually empty. Keeping the two apart is what lets a\n * mixed source — some renditions encrypted or MPEG-TS, others playable — log its causes and still play.\n */\nimport {\n SVTA_UNSUPPORTED_AUDIO_FORMAT,\n SVTA_UNSUPPORTED_DRM_SYSTEM,\n SVTA_UNSUPPORTED_VIDEO_FORMAT,\n type SvtaError,\n} from '../../media/errors';\nimport { NON_FMP4_CONTAINER_MIMES } from '../../media/hls/parse-media-playlist';\nimport { getMediaPlaylistMetadata, type ResolvedTrack, type TrackType } from '../../media/types';\n\n/** Conditions worth reporting about a just-resolved track. Return an empty array (or omit the seam) to report nothing. */\nexport type ReportUnsupportedTrackConditions = (track: ResolvedTrack) => readonly SvtaError[];\n\n/** Unsupported-format code per type; text has none — absent captions aren't a failure. */\nconst UNSUPPORTED_FORMAT_CODE: Partial<Record<TrackType, number>> = {\n video: SVTA_UNSUPPORTED_VIDEO_FORMAT,\n audio: SVTA_UNSUPPORTED_AUDIO_FORMAT,\n};\n\n/**\n * The types a reported cause can legitimately describe: the ones whose candidates `canPlayTrack` actually prunes, via\n * `track-switching`'s `excludeUnplayableTracks` pre-pass.\n *\n * Text is outside it by design — its switching chain runs failed-CDN constraints alone, because an MSE codec probe is\n * the wrong question for a WebVTT rendition (see `track-switching.ts`). So nothing prunes a text rendition, no verdict\n * can follow from one, and a cause reported against it would be an orphan: the adapter's unsupported-feature\n * substitution scans the sequence as a whole, so a lone encrypted subtitle would otherwise recode an unrelated verdict\n * — an all-CDN cooldown among them — as \"this engine can't play the source\".\n */\nconst CAPABILITY_PRUNED_TYPES: ReadonlySet<TrackType> = new Set<TrackType>(['video', 'audio']);\n\n/**\n * The default: report what makes a rendition unplayable _to this engine_ — a container MSE can't accept, or encryption\n * with no decryption pipeline. Both mirror what `canPlayTrack` prunes on, so a reported cause always has a\n * corresponding exclusion.\n *\n * A condition carries its code and its context, not copy. `data.mimeType` is what preserves the specificity — the\n * format codes cover every non-fMP4 container, so \"which one\" lives there for a consumer that wants to say, rather than\n * being flattened into an English sentence here.\n *\n * Both carry `trackType`, redundantly for the format codes (1004/1005 are already per type) but not for 4008, which\n * isn't per type — SVTA has one content-protection code for both. Nothing branches on the tag: it's diagnostic context,\n * reaching a developer through the logged sequence and `error.data`, which is why it goes on every condition rather\n * than only where the code can't carry it. `trackId` alongside it is what distinguishes two renditions of the same\n * type.\n */\nexport function reportUnsupportedTrackConditions(track: ResolvedTrack): readonly SvtaError[] {\n if (!CAPABILITY_PRUNED_TYPES.has(track.type)) return [];\n\n const conditions: SvtaError[] = [];\n const data = { trackType: track.type, trackId: track.id };\n\n const formatCode = UNSUPPORTED_FORMAT_CODE[track.type];\n\n if (formatCode !== undefined && NON_FMP4_CONTAINER_MIMES.has(track.mimeType)) {\n conditions.push({ code: formatCode, data: { ...data, mimeType: track.mimeType } });\n }\n\n if (getMediaPlaylistMetadata(track)?.encrypted) {\n conditions.push({ code: SVTA_UNSUPPORTED_DRM_SYSTEM, data });\n }\n\n return conditions;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2BA,MAAM,0BAA8D;CAClE,OAAO;CACP,OAAO;AACT;;;;;;;;;;;AAYA,MAAM,0CAAkD,IAAI,IAAe,CAAC,SAAS,OAAO,CAAC;;;;;;;;;;;;;;;;AAiB7F,SAAgB,iCAAiC,OAA4C;CAC3F,IAAI,CAAC,wBAAwB,IAAI,MAAM,IAAI,GAAG,OAAO,CAAC;CAEtD,MAAM,aAA0B,CAAC;CACjC,MAAM,OAAO;EAAE,WAAW,MAAM;EAAM,SAAS,MAAM;CAAG;CAExD,MAAM,aAAa,wBAAwB,MAAM;CAEjD,IAAI,eAAe,KAAA,KAAa,yBAAyB,IAAI,MAAM,QAAQ,GACzE,WAAW,KAAK;EAAE,MAAM;EAAY,MAAM;GAAE,GAAG;GAAM,UAAU,MAAM;EAAS;CAAE,CAAC;CAGnF,IAAI,yBAAyB,KAAK,CAAC,EAAE,WACnC,WAAW,KAAK;EAAE,MAAM;EAA6B;CAAK,CAAC;CAG7D,OAAO;AACT"}
@@ -0,0 +1,96 @@
1
+ import { effect } from "../../core/signals/effect.js";
2
+ //#region src/playback/primitives/segment-load-pipeline.ts
3
+ /**
4
+ * Base-step view of the loader's own wiring. `createSegmentLoaderActor` folds its `sourceBufferActor` + `fetch` into
5
+ * the threaded `config` so base steps read them from the uniform passthrough — present whether the loader runs inside a
6
+ * composition or standalone. `config` is loose (`object`), so assert the shape here (one cast, like relocation's
7
+ * `containerSlot`).
8
+ */
9
+ function stepWiring(deps) {
10
+ return deps.config;
11
+ }
12
+ /**
13
+ * Resolves when the SourceBufferActor snapshot reaches 'idle'. Rejects if the signal is aborted or the actor is
14
+ * destroyed.
15
+ *
16
+ * Used to sequence SourceBufferActor operations without awaiting send() directly — send() is fire-and-forget; callers
17
+ * observe completion via state transition.
18
+ */
19
+ function waitForIdle(snapshot, signal) {
20
+ return new Promise((resolve, reject) => {
21
+ if (snapshot.get().value === "idle") {
22
+ resolve();
23
+ return;
24
+ }
25
+ if (snapshot.get().value === "destroyed") {
26
+ reject(new DOMException("Aborted", "AbortError"));
27
+ return;
28
+ }
29
+ if (signal.aborted) {
30
+ reject(signal.reason);
31
+ return;
32
+ }
33
+ let stop;
34
+ const cleanup = (fn) => {
35
+ stop?.();
36
+ signal.removeEventListener("abort", onAbort);
37
+ fn();
38
+ };
39
+ const onAbort = () => cleanup(() => reject(signal.reason));
40
+ stop = effect(() => {
41
+ const value = snapshot.get().value;
42
+ if (value === "idle") cleanup(resolve);
43
+ else if (value === "destroyed") cleanup(() => reject(new DOMException("Aborted", "AbortError")));
44
+ });
45
+ signal.addEventListener("abort", onAbort, { once: true });
46
+ });
47
+ }
48
+ /**
49
+ * Build the SourceBuffer message a completed frame dispatches. `fetchStep` always precedes `dispatchStep` in append
50
+ * pipelines, so `data` is set by now.
51
+ */
52
+ function toMessage({ op, data, meta }) {
53
+ switch (op.type) {
54
+ case "remove": return op;
55
+ case "append-init": return {
56
+ type: "append-init",
57
+ data,
58
+ meta: op.meta
59
+ };
60
+ case "append-segment": return {
61
+ type: "append-segment",
62
+ data,
63
+ meta: meta ?? op.meta
64
+ };
65
+ }
66
+ }
67
+ /**
68
+ * Fetch this op's bytes into the frame. Init segments need the full body (`minChunkSize: Infinity`) before appending;
69
+ * media segments stream so chunks append as they arrive. Awaiting headers eagerly also starts the HTTP connection (and
70
+ * records the fetch in observers like tests).
71
+ */
72
+ const fetchStep = async (frame, signal, deps) => {
73
+ const { op } = frame;
74
+ if (op.type === "remove") return;
75
+ const { fetch } = stepWiring(deps);
76
+ frame.data = await fetch(op, op.type === "append-init" ? {
77
+ signal,
78
+ minChunkSize: Infinity
79
+ } : { signal });
80
+ };
81
+ /** Dispatch the frame's message to the SourceBufferActor and await its return to idle. */
82
+ const dispatchStep = async (frame, signal, deps) => {
83
+ const { sourceBufferActor } = stepWiring(deps);
84
+ sourceBufferActor.send(toMessage(frame));
85
+ await waitForIdle(sourceBufferActor.snapshot, signal);
86
+ };
87
+ /** Tier 0 default: fetch (for ops that carry bytes) then dispatch. No relocation vocabulary. */
88
+ const DEFAULT_MESSAGE_PIPELINES = () => ({
89
+ remove: [dispatchStep],
90
+ "append-init": [fetchStep, dispatchStep],
91
+ "append-segment": [fetchStep, dispatchStep]
92
+ });
93
+ //#endregion
94
+ export { DEFAULT_MESSAGE_PIPELINES, dispatchStep, fetchStep };
95
+
96
+ //# sourceMappingURL=segment-load-pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segment-load-pipeline.js","names":[],"sources":["../../../../src/playback/primitives/segment-load-pipeline.ts"],"sourcesContent":["/**\n * The v/a segment **load pipeline** — the step vocabulary and base steps a segment loader runs, extracted from the\n * loader actor so the \"what\" (the composable steps) is separable from the \"how\" (the actor's scheduling). A pipeline is\n * a per-op list of {@link LoadStep}s the loader drains in order; the default is `fetch → dispatch`, and a composition\n * can insert its own steps between them (e.g. non-zero-PTS relocation) without the loader knowing.\n *\n * The base steps reach their SourceBuffer sink through the structural {@link AppendSink} seam rather than the concrete\n * actor type — the loader folds the real actor into `config` at construction, and it satisfies the seam by structure —\n * so this module carries no dependency on the actor implementation, and no dependency on the DOM.\n */\nimport type { AnySlotMap } from '../../core/composition/create-composition';\nimport { effect } from '../../core/signals/effect';\nimport type { ReadonlySignal } from '../../core/signals/primitives';\nimport type { AddressableObject } from '../../media/types';\nimport type {\n AppendInitMessage,\n AppendSegmentMessage,\n IndividualSourceBufferMessage,\n RemoveMessage,\n} from './source-buffer-messages';\n\n// ============================================================================\n// SINK SEAM\n// ============================================================================\n\n/**\n * The structural view of a SourceBuffer sink the base steps use — just the ops {@link dispatchStep} needs (`send` + a\n * `snapshot` to await idle). The concrete `SourceBufferActor` satisfies it by structure, so the pipeline names no\n * actor.\n */\nexport interface AppendSink {\n send(message: IndividualSourceBufferMessage): void;\n snapshot: ReadonlySignal<{ value: string }>;\n}\n\n// ============================================================================\n// STEP MODEL\n// ============================================================================\n\n/**\n * A LoadTask is the intent to perform one unit of SegmentLoader work. Unlike SourceBufferMessage, fetch-based tasks\n * carry a URL rather than pre-fetched data — the runner fetches and appends them in sequence.\n *\n * Derived from SourceBufferMessage types by removing `data` and adding a fetch URL via AddressableObject.\n *\n * @todo Rename — \"LoadTask\" risks confusion with the `Task` class used for SourceBufferActor scheduling. These are\n * closer to operation descriptors or messages than tasks in that sense.\n */\nexport type LoadTask =\n | (Omit<AppendInitMessage, 'data'> & AddressableObject)\n | (Omit<AppendSegmentMessage, 'data'> & AddressableObject)\n | RemoveMessage;\n\n/**\n * A {@link LoadTask} mid-reassembly into its append message. `LoadTask` is a message with `data` omitted and a URL\n * added; the pipeline reverses that — `fetchStep` produces `data`, `dispatchStep` reassembles the message. `data` is\n * the omitted payload (kept as the fetched stream — the loader never produces the `ArrayBuffer` arm of `SegmentData` —\n * widened back at dispatch). `meta` overrides `op.meta` for `append-segment` (e.g. a stamped `timestampOffset`); an\n * `append-init` dispatches `op.meta` directly.\n */\nexport interface Frame {\n readonly op: LoadTask;\n data?: AsyncIterable<Uint8Array>;\n meta?: AppendSegmentMessage['meta'];\n}\n\n/**\n * One stage of a message pipeline. Mutates the {@link Frame} in place and may be async; the runner checks\n * `signal.aborted` before each step and passes the actor's {@link StepDeps} on every call, so a stateless step (e.g.\n * {@link fetchStep}) is a plain value, and a step that needs composition signals (relocation's discover/stamp) reads\n * them from `deps` at call time.\n */\nexport type LoadStep = (frame: Frame, signal: AbortSignal, deps: StepDeps) => void | Promise<void>;\n\n/**\n * The uniform passthrough handed to every {@link LoadStep} on every call — the composition triple, nothing more.\n * `state`/`context` are the full composition signal maps; `config` is the threaded config with the loader's own wiring\n * folded in (see {@link stepWiring} + `createSegmentLoaderActor`). All three are typed loose: the loader is a conduit\n * and never reads them; a step asserts the slots it knows are present (composition steps read `state`; base steps read\n * the folded wiring off `config`).\n */\nexport interface StepDeps {\n state: AnySlotMap;\n context: AnySlotMap;\n config: object;\n}\n\n/**\n * Base-step view of the loader's own wiring. `createSegmentLoaderActor` folds its `sourceBufferActor` + `fetch` into\n * the threaded `config` so base steps read them from the uniform passthrough — present whether the loader runs inside a\n * composition or standalone. `config` is loose (`object`), so assert the shape here (one cast, like relocation's\n * `containerSlot`).\n */\nfunction stepWiring(deps: StepDeps): { sourceBufferActor: AppendSink; fetch: FetchBytes } {\n return deps.config as { sourceBufferActor: AppendSink; fetch: FetchBytes };\n}\n\n/**\n * Builds the ordered step list for each message type. Called **once per actor** — its role is per-actor instantiation,\n * so stateful steps (relocation's origin discoverer) get fresh state per source reset; deps arrive at step-call time,\n * not here. The default ({@link DEFAULT_MESSAGE_PIPELINES}) is `fetch → dispatch`; a non-zero-PTS composition returns a\n * map that inserts its own discover/stamp steps between them (see `establishStartMediaTime`), so the loader stays\n * oblivious to relocation and the Tier 0 pipeline carries no relocation vocabulary at all.\n */\nexport type MessagePipelines = () => Record<LoadTask['type'], LoadStep[]>;\n\n// ============================================================================\n// BASE STEPS\n// ============================================================================\n\nexport type FetchBytes = (\n addressable: AddressableObject,\n options?: RequestInit & { minChunkSize?: number }\n) => Promise<AsyncIterable<Uint8Array>>;\n\n/**\n * Resolves when the SourceBufferActor snapshot reaches 'idle'. Rejects if the signal is aborted or the actor is\n * destroyed.\n *\n * Used to sequence SourceBufferActor operations without awaiting send() directly — send() is fire-and-forget; callers\n * observe completion via state transition.\n */\nfunction waitForIdle(snapshot: AppendSink['snapshot'], signal: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (snapshot.get().value === 'idle') {\n resolve();\n return;\n }\n\n if (snapshot.get().value === 'destroyed') {\n reject(new DOMException('Aborted', 'AbortError'));\n return;\n }\n\n if (signal.aborted) {\n reject(signal.reason);\n return;\n }\n\n let stop: (() => void) | undefined;\n\n const cleanup = (fn: () => void) => {\n stop?.();\n signal.removeEventListener('abort', onAbort);\n fn();\n };\n\n const onAbort = () => cleanup(() => reject(signal.reason));\n\n stop = effect(() => {\n const value = snapshot.get().value;\n\n if (value === 'idle') cleanup(resolve);\n else if (value === 'destroyed') cleanup(() => reject(new DOMException('Aborted', 'AbortError')));\n });\n\n signal.addEventListener('abort', onAbort, { once: true });\n });\n}\n\n/**\n * Build the SourceBuffer message a completed frame dispatches. `fetchStep` always precedes `dispatchStep` in append\n * pipelines, so `data` is set by now.\n */\nfunction toMessage({ op, data, meta }: Frame): IndividualSourceBufferMessage {\n switch (op.type) {\n case 'remove':\n return op;\n case 'append-init':\n return { type: 'append-init', data: data!, meta: op.meta };\n case 'append-segment':\n return { type: 'append-segment', data: data!, meta: meta ?? op.meta };\n }\n}\n\n/**\n * Fetch this op's bytes into the frame. Init segments need the full body (`minChunkSize: Infinity`) before appending;\n * media segments stream so chunks append as they arrive. Awaiting headers eagerly also starts the HTTP connection (and\n * records the fetch in observers like tests).\n */\nexport const fetchStep: LoadStep = async (frame, signal, deps) => {\n const { op } = frame;\n if (op.type === 'remove') return; // fetchStep only appears in append pipelines\n\n const { fetch } = stepWiring(deps);\n\n frame.data = await fetch(op, op.type === 'append-init' ? { signal, minChunkSize: Infinity } : { signal });\n};\n\n/** Dispatch the frame's message to the SourceBufferActor and await its return to idle. */\nexport const dispatchStep: LoadStep = async (frame, signal, deps) => {\n const { sourceBufferActor } = stepWiring(deps);\n\n sourceBufferActor.send(toMessage(frame));\n await waitForIdle(sourceBufferActor.snapshot, signal);\n};\n\n/** Tier 0 default: fetch (for ops that carry bytes) then dispatch. No relocation vocabulary. */\nexport const DEFAULT_MESSAGE_PIPELINES: MessagePipelines = () => ({\n remove: [dispatchStep],\n 'append-init': [fetchStep, dispatchStep],\n 'append-segment': [fetchStep, dispatchStep],\n});\n"],"mappings":";;;;;;;;AA6FA,SAAS,WAAW,MAAsE;CACxF,OAAO,KAAK;AACd;;;;;;;;AA2BA,SAAS,YAAY,UAAkC,QAAoC;CACzF,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,IAAI,SAAS,IAAI,CAAC,CAAC,UAAU,QAAQ;GACnC,QAAQ;GACR;EACF;EAEA,IAAI,SAAS,IAAI,CAAC,CAAC,UAAU,aAAa;GACxC,OAAO,IAAI,aAAa,WAAW,YAAY,CAAC;GAChD;EACF;EAEA,IAAI,OAAO,SAAS;GAClB,OAAO,OAAO,MAAM;GACpB;EACF;EAEA,IAAI;EAEJ,MAAM,WAAW,OAAmB;GAClC,OAAO;GACP,OAAO,oBAAoB,SAAS,OAAO;GAC3C,GAAG;EACL;EAEA,MAAM,gBAAgB,cAAc,OAAO,OAAO,MAAM,CAAC;EAEzD,OAAO,aAAa;GAClB,MAAM,QAAQ,SAAS,IAAI,CAAC,CAAC;GAE7B,IAAI,UAAU,QAAQ,QAAQ,OAAO;QAChC,IAAI,UAAU,aAAa,cAAc,OAAO,IAAI,aAAa,WAAW,YAAY,CAAC,CAAC;EACjG,CAAC;EAED,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;CAC1D,CAAC;AACH;;;;;AAMA,SAAS,UAAU,EAAE,IAAI,MAAM,QAA8C;CAC3E,QAAQ,GAAG,MAAX;EACE,KAAK,UACH,OAAO;EACT,KAAK,eACH,OAAO;GAAE,MAAM;GAAqB;GAAO,MAAM,GAAG;EAAK;EAC3D,KAAK,kBACH,OAAO;GAAE,MAAM;GAAwB;GAAO,MAAM,QAAQ,GAAG;EAAK;CACxE;AACF;;;;;;AAOA,MAAa,YAAsB,OAAO,OAAO,QAAQ,SAAS;CAChE,MAAM,EAAE,OAAO;CACf,IAAI,GAAG,SAAS,UAAU;CAE1B,MAAM,EAAE,UAAU,WAAW,IAAI;CAEjC,MAAM,OAAO,MAAM,MAAM,IAAI,GAAG,SAAS,gBAAgB;EAAE;EAAQ,cAAc;CAAS,IAAI,EAAE,OAAO,CAAC;AAC1G;;AAGA,MAAa,eAAyB,OAAO,OAAO,QAAQ,SAAS;CACnE,MAAM,EAAE,sBAAsB,WAAW,IAAI;CAE7C,kBAAkB,KAAK,UAAU,KAAK,CAAC;CACvC,MAAM,YAAY,kBAAkB,UAAU,MAAM;AACtD;;AAGA,MAAa,mCAAqD;CAChE,QAAQ,CAAC,YAAY;CACrB,eAAe,CAAC,WAAW,YAAY;CACvC,kBAAkB,CAAC,WAAW,YAAY;AAC5C"}
@@ -0,0 +1,115 @@
1
+ import { getCodecFamilies, getCodecFamily } from "../../media/utils/tracks.js";
2
+ //#region src/playback/primitives/selection-rules.ts
3
+ /**
4
+ * Apply rules to a candidate list in order; the pick is the first survivor. Two responsibilities the rules don't carry:
5
+ * a rule that returns nothing is skipped (fall-through — a preference never empties the set), and once one survivor
6
+ * remains the chain stops (early-bail — later rules, including the bandwidth ranker, never run, so the effect doesn't
7
+ * subscribe to their signals while the choice is fixed).
8
+ *
9
+ * @param rules - Rules to apply, most authoritative first
10
+ * @param tracks - Candidate tracks
11
+ * @param deps - The behavior's `{ state, context, config }`, passed through to each rule
12
+ * @returns The surviving candidates, pick first
13
+ */
14
+ function applyRules(rules, tracks, deps) {
15
+ let current = tracks;
16
+ for (const rule of rules) {
17
+ const remaining = rule(current, deps);
18
+ if (remaining.length === 0) continue;
19
+ current = remaining;
20
+ if (current.length === 1) break;
21
+ }
22
+ return current;
23
+ }
24
+ /**
25
+ * Apply hard constraints to a candidate list — the pre-pass that runs before the rule chain. A constraint shares a
26
+ * rule's signature but its exclusion is _hard_: it removes the unplayable (a codec the environment can't decode, a CDN
27
+ * in failover cooldown) and a removed track is never attempted. Unlike `applyRules`, this never skips an empty result
28
+ * and never early-bails — every constraint always applies, and an empty survivor set is a real outcome ("nothing
29
+ * playable here"), not a fall-through. Because each constraint only removes, the order they run in can't change which
30
+ * tracks survive — though one that also _reports_ reads the list at its own position, so placement matters.
31
+ *
32
+ * @param constraints - Constraints to apply, in order
33
+ * @param tracks - Candidate tracks
34
+ * @param deps - The behavior's `{ state, context, config }`, passed to each constraint
35
+ * @returns The playable survivors (possibly empty)
36
+ */
37
+ function applyConstraints(constraints, tracks, deps) {
38
+ let current = tracks;
39
+ for (const constraint of constraints) current = constraint(current, deps);
40
+ return current;
41
+ }
42
+ /**
43
+ * Whether two candidate sets hold the same tracks, by id.
44
+ *
45
+ * The `equals` both selection behaviors give their candidate-set `computed`. A live playlist refresh swaps in a new
46
+ * presentation object carrying the same variants, and a constraint's own inputs can churn without changing which tracks
47
+ * survive; in both cases the set is unchanged and the reaction must not re-fire. Compares by id rather than array
48
+ * identity for exactly that.
49
+ */
50
+ function sameCandidateSet(a, b) {
51
+ return a.length === b.length && a.every((track) => b.some((other) => other.id === track.id));
52
+ }
53
+ /**
54
+ * Capability constraint — a _hard_ filter for the {@link applyConstraints} pre-pass. Removes renditions this
55
+ * environment can't decode, probed via the injected `canPlayTrack` (codec → `MediaSource.isTypeSupported`, plus the
56
+ * container and encryption assertions that probe can't make). Constraining here — before selection — means an
57
+ * unplayable variant is pruned upstream and never picked, instead of surviving into the pipeline to fail late at
58
+ * `createSourceBuffer`. That late throw stays as a defensive structural guarantee; with this constraint it should
59
+ * rarely fire.
60
+ *
61
+ * Lives here rather than beside `switchVideoTrack` for the reason this module exists: both the re-evaluating variant
62
+ * and the pinned `selectVideoTrack` apply it, and reaching it through `behaviors/track-switching.ts` would drag the ABR
63
+ * path into a composition that deliberately omits it.
64
+ *
65
+ * Passes everything through when there's no probe (a composition that didn't wire one, or DOM-free tests). When it
66
+ * prunes _every_ track, the empty result is preserved (per `applyConstraints`) — "nothing playable" — which each
67
+ * consuming behavior answers by clearing its selection; reporting the verdict is separate.
68
+ */
69
+ function excludeUnplayableTracks(tracks, { config }) {
70
+ const canPlay = config?.canPlayTrack;
71
+ if (!canPlay) return tracks;
72
+ return tracks.filter((track) => canPlay(track));
73
+ }
74
+ /**
75
+ * The codec families {@link preferCodecFamilies} narrows to when the config carries no `preferredCodecs`: AVC (both its
76
+ * 4CCs) and AAC. The default is deliberate rather than neutral — SPF implements no `SourceBuffer.changeType()`, so on a
77
+ * mixed-codec source the _initial_ family choice is the one ABR lives inside for the whole source (see
78
+ * `stickToSelectedCodecs` in `behaviors/track-switching.ts`), and AVC/AAC is the family pair with the broadest decode
79
+ * support. The cost, equally deliberate: on a ladder whose higher rungs are HEVC-only (a common 4K shape), the default
80
+ * caps quality at the top AVC rung — configure `preferredCodecs` (or pass `[]`) to trade the other way.
81
+ */
82
+ const DEFAULT_PREFERRED_CODECS = [
83
+ "avc1",
84
+ "avc3",
85
+ "mp4a"
86
+ ];
87
+ /**
88
+ * Codec-family preference — a _soft_ filter (scope) for a selection-rule chain; the `hevc-variant-selection` concern
89
+ * from `internal/design/spf/track-switching-model.md`. Narrows to the tracks whose codec families are all in
90
+ * `preferredCodecs` (family-compared, so entries may be 4CCs or full codec strings). Soft-filter semantics: a source
91
+ * with no preferred-family rendition (an HEVC-only ladder under the AVC default) is left unnarrowed, and a track
92
+ * without codecs never matches — on a ladder with no codecs anywhere (DOM-free tests) the rule is inert.
93
+ *
94
+ * `preferredCodecs` defaults to {@link DEFAULT_PREFERRED_CODECS}; explicitly pass `[]` to disable the preference while
95
+ * keeping the rule composed.
96
+ *
97
+ * "All families" rather than "any" so a muxed rendition is judged as the unit it is: `hvc1,mp4a` must not count as
98
+ * preferred just because its audio half matches.
99
+ *
100
+ * Lives here rather than beside `switchVideoTrack` for the module's usual reason: the pinned `selectVideoTrack` variant
101
+ * can compose it without dragging the ABR path in.
102
+ */
103
+ function preferCodecFamilies(tracks, { config }) {
104
+ const preferred = config?.preferredCodecs ?? DEFAULT_PREFERRED_CODECS;
105
+ if (!preferred.length) return tracks;
106
+ const preferredFamilies = new Set(preferred.map(getCodecFamily));
107
+ return tracks.filter((track) => {
108
+ const families = getCodecFamilies(track);
109
+ return !!families && families.every((family) => preferredFamilies.has(family));
110
+ });
111
+ }
112
+ //#endregion
113
+ export { DEFAULT_PREFERRED_CODECS, applyConstraints, applyRules, excludeUnplayableTracks, preferCodecFamilies, sameCandidateSet };
114
+
115
+ //# sourceMappingURL=selection-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection-rules.js","names":[],"sources":["../../../../src/playback/primitives/selection-rules.ts"],"sourcesContent":["/**\n * The selection-rule substrate: the shape of a rule, and the two composers that turn a list of them into a pick.\n *\n * Lives here rather than beside `switchVideoTrack` so both track-selection behaviors can share rules. The simple\n * `selectVideoTrack` variant exists specifically to tree-shake the ABR path out, so importing a composer from\n * `behaviors/track-switching.ts` would drag the bandwidth estimator and quality selection back in with it. Nothing here\n * reaches past pure generics over a candidate list and small media-layer helpers, so either side can reach them\n * freely.\n *\n * See `internal/design/spf/track-switching-model.md` for the model these implement: a hard constraints pre-pass, then\n * an ordered chain of soft narrowing rules and rankers, with the pick as the first survivor.\n */\n\nimport type { CanPlayTrack } from '../../media/types';\nimport { getCodecFamilies, getCodecFamily } from '../../media/utils/tracks';\n\n/**\n * Deps handed to each rule and to `applyRules`, mirroring a behavior's setup deps so a rule reads from the same\n * surfaces a behavior does. `context` is optional — it's threaded through but absent on direct setup calls (and unread\n * by today's rules), so the whole deps object can pass straight through.\n */\nexport interface SelectionRuleDeps<State = unknown, Context = unknown, Config = unknown> {\n state: State;\n context?: Context;\n config: Config;\n}\n\n/**\n * A selection rule narrows or reorders the candidate list. It reads the state, context, and config it needs at apply\n * time (tightly-coupled reads), so a rule's `.get()`s subscribe the running effect to exactly what it consulted.\n * Returning an empty list means \"no match\" — the composer skips it, so a soft filter never narrows the set to nothing.\n * A ranker returns the list with its pick at the head.\n */\nexport type SelectionRule<T, State = unknown, Context = unknown, Config = unknown> = (\n tracks: readonly T[],\n deps: SelectionRuleDeps<State, Context, Config>\n) => readonly T[];\n\n/**\n * Apply rules to a candidate list in order; the pick is the first survivor. Two responsibilities the rules don't carry:\n * a rule that returns nothing is skipped (fall-through — a preference never empties the set), and once one survivor\n * remains the chain stops (early-bail — later rules, including the bandwidth ranker, never run, so the effect doesn't\n * subscribe to their signals while the choice is fixed).\n *\n * @param rules - Rules to apply, most authoritative first\n * @param tracks - Candidate tracks\n * @param deps - The behavior's `{ state, context, config }`, passed through to each rule\n * @returns The surviving candidates, pick first\n */\nexport function applyRules<T, State, Context, Config>(\n rules: readonly SelectionRule<T, State, Context, Config>[],\n tracks: readonly T[],\n deps: SelectionRuleDeps<State, Context, Config>\n): readonly T[] {\n let current = tracks;\n\n for (const rule of rules) {\n const remaining = rule(current, deps);\n if (remaining.length === 0) continue;\n\n current = remaining;\n\n if (current.length === 1) break;\n }\n\n return current;\n}\n\n/**\n * Apply hard constraints to a candidate list — the pre-pass that runs before the rule chain. A constraint shares a\n * rule's signature but its exclusion is _hard_: it removes the unplayable (a codec the environment can't decode, a CDN\n * in failover cooldown) and a removed track is never attempted. Unlike `applyRules`, this never skips an empty result\n * and never early-bails — every constraint always applies, and an empty survivor set is a real outcome (\"nothing\n * playable here\"), not a fall-through. Because each constraint only removes, the order they run in can't change which\n * tracks survive — though one that also _reports_ reads the list at its own position, so placement matters.\n *\n * @param constraints - Constraints to apply, in order\n * @param tracks - Candidate tracks\n * @param deps - The behavior's `{ state, context, config }`, passed to each constraint\n * @returns The playable survivors (possibly empty)\n */\nexport function applyConstraints<T, State, Context, Config>(\n constraints: readonly SelectionRule<T, State, Context, Config>[],\n tracks: readonly T[],\n deps: SelectionRuleDeps<State, Context, Config>\n): readonly T[] {\n let current = tracks;\n\n for (const constraint of constraints) current = constraint(current, deps);\n\n return current;\n}\n\n/**\n * Whether two candidate sets hold the same tracks, by id.\n *\n * The `equals` both selection behaviors give their candidate-set `computed`. A live playlist refresh swaps in a new\n * presentation object carrying the same variants, and a constraint's own inputs can churn without changing which tracks\n * survive; in both cases the set is unchanged and the reaction must not re-fire. Compares by id rather than array\n * identity for exactly that.\n */\nexport function sameCandidateSet<T extends { id: string }>(a: readonly T[], b: readonly T[]): boolean {\n return a.length === b.length && a.every((track) => b.some((other) => other.id === track.id));\n}\n\n/**\n * What {@link excludeUnplayableTracks} reads off the config it is handed.\n *\n * Read through a cast rather than constraining the rule's `Config` generic, the same way `screenResolutionCap` reads\n * `screenResolution` off its state: a rule composes into chains whose config types have nothing else in common, and\n * constraining the generic would make every one of those a weak-type mismatch. Each engine defaults `canPlayTrack` to\n * the DOM-bound probe; unwired means \"no capability filtering\" and the constraint passes everything through.\n */\nexport interface CapabilityConstraintConfig {\n canPlayTrack?: CanPlayTrack;\n}\n\n/**\n * Capability constraint — a _hard_ filter for the {@link applyConstraints} pre-pass. Removes renditions this\n * environment can't decode, probed via the injected `canPlayTrack` (codec → `MediaSource.isTypeSupported`, plus the\n * container and encryption assertions that probe can't make). Constraining here — before selection — means an\n * unplayable variant is pruned upstream and never picked, instead of surviving into the pipeline to fail late at\n * `createSourceBuffer`. That late throw stays as a defensive structural guarantee; with this constraint it should\n * rarely fire.\n *\n * Lives here rather than beside `switchVideoTrack` for the reason this module exists: both the re-evaluating variant\n * and the pinned `selectVideoTrack` apply it, and reaching it through `behaviors/track-switching.ts` would drag the ABR\n * path into a composition that deliberately omits it.\n *\n * Passes everything through when there's no probe (a composition that didn't wire one, or DOM-free tests). When it\n * prunes _every_ track, the empty result is preserved (per `applyConstraints`) — \"nothing playable\" — which each\n * consuming behavior answers by clearing its selection; reporting the verdict is separate.\n */\nexport function excludeUnplayableTracks<T, State, Context, Config>(\n tracks: readonly T[],\n { config }: SelectionRuleDeps<State, Context, Config>\n): readonly T[] {\n const canPlay = (config as CapabilityConstraintConfig | undefined)?.canPlayTrack;\n if (!canPlay) return tracks;\n\n return tracks.filter((track) => canPlay(track as Parameters<CanPlayTrack>[0]));\n}\n\n/**\n * What {@link preferCodecFamilies} reads off the config it is handed — a cast view, for the same reason as\n * {@link CapabilityConstraintConfig}.\n */\nexport interface CodecPreferenceConfig {\n preferredCodecs?: string[];\n}\n\n/**\n * The codec families {@link preferCodecFamilies} narrows to when the config carries no `preferredCodecs`: AVC (both its\n * 4CCs) and AAC. The default is deliberate rather than neutral — SPF implements no `SourceBuffer.changeType()`, so on a\n * mixed-codec source the _initial_ family choice is the one ABR lives inside for the whole source (see\n * `stickToSelectedCodecs` in `behaviors/track-switching.ts`), and AVC/AAC is the family pair with the broadest decode\n * support. The cost, equally deliberate: on a ladder whose higher rungs are HEVC-only (a common 4K shape), the default\n * caps quality at the top AVC rung — configure `preferredCodecs` (or pass `[]`) to trade the other way.\n */\nexport const DEFAULT_PREFERRED_CODECS: readonly string[] = ['avc1', 'avc3', 'mp4a'];\n\n/**\n * Codec-family preference — a _soft_ filter (scope) for a selection-rule chain; the `hevc-variant-selection` concern\n * from `internal/design/spf/track-switching-model.md`. Narrows to the tracks whose codec families are all in\n * `preferredCodecs` (family-compared, so entries may be 4CCs or full codec strings). Soft-filter semantics: a source\n * with no preferred-family rendition (an HEVC-only ladder under the AVC default) is left unnarrowed, and a track\n * without codecs never matches — on a ladder with no codecs anywhere (DOM-free tests) the rule is inert.\n *\n * `preferredCodecs` defaults to {@link DEFAULT_PREFERRED_CODECS}; explicitly pass `[]` to disable the preference while\n * keeping the rule composed.\n *\n * \"All families\" rather than \"any\" so a muxed rendition is judged as the unit it is: `hvc1,mp4a` must not count as\n * preferred just because its audio half matches.\n *\n * Lives here rather than beside `switchVideoTrack` for the module's usual reason: the pinned `selectVideoTrack` variant\n * can compose it without dragging the ABR path in.\n */\nexport function preferCodecFamilies<T, State, Context, Config>(\n tracks: readonly T[],\n { config }: SelectionRuleDeps<State, Context, Config>\n): readonly T[] {\n const preferred = (config as CodecPreferenceConfig | undefined)?.preferredCodecs ?? DEFAULT_PREFERRED_CODECS;\n if (!preferred.length) return tracks;\n\n const preferredFamilies = new Set(preferred.map(getCodecFamily));\n\n return tracks.filter((track) => {\n const families = getCodecFamilies(track as { codecs?: string[] });\n\n return !!families && families.every((family) => preferredFamilies.has(family));\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAiDA,SAAgB,WACd,OACA,QACA,MACc;CACd,IAAI,UAAU;CAEd,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,YAAY,KAAK,SAAS,IAAI;EACpC,IAAI,UAAU,WAAW,GAAG;EAE5B,UAAU;EAEV,IAAI,QAAQ,WAAW,GAAG;CAC5B;CAEA,OAAO;AACT;;;;;;;;;;;;;;AAeA,SAAgB,iBACd,aACA,QACA,MACc;CACd,IAAI,UAAU;CAEd,KAAK,MAAM,cAAc,aAAa,UAAU,WAAW,SAAS,IAAI;CAExE,OAAO;AACT;;;;;;;;;AAUA,SAAgB,iBAA2C,GAAiB,GAA0B;CACpG,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,UAAU,EAAE,MAAM,UAAU,MAAM,OAAO,MAAM,EAAE,CAAC;AAC7F;;;;;;;;;;;;;;;;;AA8BA,SAAgB,wBACd,QACA,EAAE,UACY;CACd,MAAM,UAAW,QAAmD;CACpE,IAAI,CAAC,SAAS,OAAO;CAErB,OAAO,OAAO,QAAQ,UAAU,QAAQ,KAAoC,CAAC;AAC/E;;;;;;;;;AAkBA,MAAa,2BAA8C;CAAC;CAAQ;CAAQ;AAAM;;;;;;;;;;;;;;;;;AAkBlF,SAAgB,oBACd,QACA,EAAE,UACY;CACd,MAAM,YAAa,QAA8C,mBAAmB;CACpF,IAAI,CAAC,UAAU,QAAQ,OAAO;CAE9B,MAAM,oBAAoB,IAAI,IAAI,UAAU,IAAI,cAAc,CAAC;CAE/D,OAAO,OAAO,QAAQ,UAAU;EAC9B,MAAM,WAAW,iBAAiB,KAA8B;EAEhE,OAAO,CAAC,CAAC,YAAY,SAAS,OAAO,WAAW,kBAAkB,IAAI,MAAM,CAAC;CAC/E,CAAC;AACH"}
@@ -0,0 +1,36 @@
1
+ //#region src/playback/primitives/text-segment-load-pipeline.ts
2
+ /**
3
+ * Base-step view of the loader's wiring, folded into `config` by `createTextTrackSegmentLoaderActor` so base steps read
4
+ * it from the uniform passthrough — present in both composition and standalone use. `config` is loose (`object`), so
5
+ * assert the shape here (mirrors the v/a loader's `stepWiring`). The sink is the structural {@link CueSink}, not the
6
+ * concrete actor.
7
+ */
8
+ function textStepWiring(deps) {
9
+ return deps.config;
10
+ }
11
+ /** Resolve the op's cues (via the injected host primitive) into the frame. The text analog of `fetchStep`. */
12
+ const resolveCuesStep = async (frame, signal, deps) => {
13
+ const cues = await textStepWiring(deps).resolveSegment(frame.op.segment.url);
14
+ if (signal.aborted) return;
15
+ frame.cues = cues;
16
+ };
17
+ /** Dispatch the frame's cues to the TextTracksActor as `add-cues`. The text analog of `dispatchStep`. */
18
+ const dispatchCuesStep = (frame, _signal, deps) => {
19
+ const { op } = frame;
20
+ textStepWiring(deps).textTracksActor.send({
21
+ type: "add-cues",
22
+ meta: {
23
+ trackId: op.trackId,
24
+ id: op.segment.id,
25
+ startTime: op.segment.startTime,
26
+ duration: op.segment.duration
27
+ },
28
+ cues: frame.cues ?? []
29
+ });
30
+ };
31
+ /** Tier 0 default: resolve then dispatch. No relocation vocabulary. */
32
+ const DEFAULT_TEXT_MESSAGE_PIPELINES = () => [resolveCuesStep, dispatchCuesStep];
33
+ //#endregion
34
+ export { DEFAULT_TEXT_MESSAGE_PIPELINES, dispatchCuesStep, resolveCuesStep, textStepWiring };
35
+
36
+ //# sourceMappingURL=text-segment-load-pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-segment-load-pipeline.js","names":[],"sources":["../../../../src/playback/primitives/text-segment-load-pipeline.ts"],"sourcesContent":["/**\n * The text-track **load pipeline** — the step vocabulary and base steps a text-segment loader runs, the text mirror of\n * `segment-load-pipeline`. Extracted from the loader actor so the \"what\" (the composable steps) is separable from the\n * \"how\" (scheduling). A pipeline is a flat, ordered list of {@link TextLoadStep}s (text has a single op type, so no\n * per-type `Record`); the default is `resolveCues → dispatchCues`, and a composition can insert its own steps (e.g.\n * non-zero-PTS cue rebase) without the loader knowing.\n *\n * The dispatch step reaches its cue sink through the structural {@link CueSink} seam rather than the concrete\n * `TextTracksActor` type — the loader folds the real actor into `config`, and it satisfies the seam by structure — so\n * this module names no actor and stays DOM-free (generic over the cue type `C`).\n */\nimport type { AnySlotMap } from '../../core/composition/create-composition';\nimport type { Cue, Segment } from '../../media/types';\nimport type { AddCuesMessage } from './text-track-messages';\n\n// ============================================================================\n// SINK SEAM\n// ============================================================================\n\n/**\n * The structural view of a cue sink the base steps use — just the `send` {@link dispatchCuesStep} needs. The concrete\n * `TextTracksActor` satisfies it by structure, so the pipeline names no actor.\n */\nexport interface CueSink<C extends Cue = Cue> {\n send(message: AddCuesMessage<C>): void;\n}\n\n// ============================================================================\n// STEP MODEL\n// ============================================================================\n\n/**\n * Resolves a text-track segment URL into the array of cues it contains.\n *\n * \"Resolve\" because the fn covers both network fetch and parse into the domain model. Host-agnostic — the concrete\n * resolver (e.g. the browser's native VTT resolver) is supplied at engine-assembly time, so this stays DOM-free. A pure\n * `url → cues` primitive (the text analog of the v/a loader's `fetchBytes`); composition-awareness lives in the\n * injected {@link TextLoadStep}s, not here.\n */\nexport type TextTrackSegmentResolver<C extends Cue = Cue> = (url: string) => Promise<C[]>;\n\n/** Internal load-task descriptor — one segment fetch + dispatch unit. */\nexport interface TextLoadTask {\n segment: Segment;\n trackId: string;\n}\n\n/**\n * A text load in mid-pipeline — the text analog of the v/a loader's `Frame`. `resolveCuesStep` fills `cues`;\n * `dispatchCuesStep` sends them. `metadata` is opaque header metadata a resolve step may attach for a later step to\n * read (e.g. relocation stashes the `X-TIMESTAMP-MAP` correlation here for its rebase step). Typed `unknown` so the\n * generic loader stays host-agnostic — the step that reads it knows its concrete shape (mirrors `StepDeps.state`).\n */\nexport interface TextFrame<C extends Cue = Cue> {\n readonly op: TextLoadTask;\n cues?: C[];\n metadata?: unknown;\n}\n\n/**\n * One stage of a text message pipeline — the text analog of the v/a loader's `LoadStep`. Mutates the {@link TextFrame}\n * in place and may be async; the runner checks `signal.aborted` before each step and passes the actor's\n * {@link TextStepDeps} on every call, so a stateless step (`resolveCuesStep`) is a plain value and a step that needs\n * composition signals (relocation's cue rebase) reads them from `deps` at call time.\n */\nexport type TextLoadStep<C extends Cue = Cue> = (\n frame: TextFrame<C>,\n signal: AbortSignal,\n deps: TextStepDeps\n) => void | Promise<void>;\n\n/**\n * The uniform passthrough handed to each {@link TextLoadStep} — the composition triple, the text analog of `StepDeps`.\n * `state`/`context` are the composition signal maps; `config` is the threaded config with the loader's wiring folded in\n * (see {@link textStepWiring} + `createTextTrackSegmentLoaderActor`). Typed loose: composition steps read `state`; base\n * steps read the folded wiring off `config`.\n */\nexport interface TextStepDeps {\n state: AnySlotMap;\n context: AnySlotMap;\n config: object;\n}\n\n/**\n * Base-step view of the loader's wiring, folded into `config` by `createTextTrackSegmentLoaderActor` so base steps read\n * it from the uniform passthrough — present in both composition and standalone use. `config` is loose (`object`), so\n * assert the shape here (mirrors the v/a loader's `stepWiring`). The sink is the structural {@link CueSink}, not the\n * concrete actor.\n */\nexport function textStepWiring<C extends Cue>(\n deps: TextStepDeps\n): { textTracksActor: CueSink<C>; resolveSegment: TextTrackSegmentResolver<C> } {\n return deps.config as { textTracksActor: CueSink<C>; resolveSegment: TextTrackSegmentResolver<C> };\n}\n\n/**\n * Builds the ordered step list, called **once per actor** (mirrors the v/a loader's `MessagePipelines`, but text has a\n * single op type so it's a flat array, not a `Record`). The default ({@link DEFAULT_TEXT_MESSAGE_PIPELINES}) is\n * `resolveCues → dispatchCues`; a non-zero-PTS composition returns a list that inserts a cue-rebase step (see\n * `relocatingTextPipelines`), so the loader stays oblivious to relocation.\n */\nexport type TextMessagePipelines<C extends Cue = Cue> = () => TextLoadStep<C>[];\n\n// ============================================================================\n// BASE STEPS\n// ============================================================================\n\n// Base steps are generic over the cue type `C` (generic arrow consts, not\n// `TextLoadStep<Cue>` values): each touches `C` — `frame.cues: C[]` and the\n// `C`-typed `textStepWiring<C>` — so a `Cue`-typed const wouldn't slot into a\n// `VTTCue` pipeline. A generic function assigns to any `TextLoadStep<C>`.\n\n/** Resolve the op's cues (via the injected host primitive) into the frame. The text analog of `fetchStep`. */\nexport const resolveCuesStep = async <C extends Cue>(\n frame: TextFrame<C>,\n signal: AbortSignal,\n deps: TextStepDeps\n): Promise<void> => {\n const cues = await textStepWiring<C>(deps).resolveSegment(frame.op.segment.url);\n\n if (signal.aborted) return;\n\n frame.cues = cues;\n};\n\n/** Dispatch the frame's cues to the TextTracksActor as `add-cues`. The text analog of `dispatchStep`. */\nexport const dispatchCuesStep = <C extends Cue>(\n frame: TextFrame<C>,\n _signal: AbortSignal,\n deps: TextStepDeps\n): void => {\n const { op } = frame;\n\n textStepWiring<C>(deps).textTracksActor.send({\n type: 'add-cues',\n meta: {\n trackId: op.trackId,\n id: op.segment.id,\n startTime: op.segment.startTime,\n duration: op.segment.duration,\n },\n cues: frame.cues ?? [],\n });\n};\n\n/** Tier 0 default: resolve then dispatch. No relocation vocabulary. */\nexport const DEFAULT_TEXT_MESSAGE_PIPELINES = <C extends Cue>(): TextLoadStep<C>[] => [\n resolveCuesStep,\n dispatchCuesStep,\n];\n"],"mappings":";;;;;;;AAyFA,SAAgB,eACd,MAC8E;CAC9E,OAAO,KAAK;AACd;;AAoBA,MAAa,kBAAkB,OAC7B,OACA,QACA,SACkB;CAClB,MAAM,OAAO,MAAM,eAAkB,IAAI,CAAC,CAAC,eAAe,MAAM,GAAG,QAAQ,GAAG;CAE9E,IAAI,OAAO,SAAS;CAEpB,MAAM,OAAO;AACf;;AAGA,MAAa,oBACX,OACA,SACA,SACS;CACT,MAAM,EAAE,OAAO;CAEf,eAAkB,IAAI,CAAC,CAAC,gBAAgB,KAAK;EAC3C,MAAM;EACN,MAAM;GACJ,SAAS,GAAG;GACZ,IAAI,GAAG,QAAQ;GACf,WAAW,GAAG,QAAQ;GACtB,UAAU,GAAG,QAAQ;EACvB;EACA,MAAM,MAAM,QAAQ,CAAC;CACvB,CAAC;AACH;;AAGA,MAAa,uCAAyE,CACpF,iBACA,gBACF"}