mattebox 0.17.2 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/cdn/mattebox.dash-drm.min.js +3 -3
  2. package/dist/cdn/mattebox.dash-ll.min.js +3 -3
  3. package/dist/cdn/mattebox.dash.min.js +2 -2
  4. package/dist/cdn/mattebox.dual-drm.min.js +3 -3
  5. package/dist/cdn/mattebox.dual-ll.min.js +3 -3
  6. package/dist/cdn/mattebox.dual-ts-drm.min.js +3 -3
  7. package/dist/cdn/mattebox.dual-ts.min.js +3 -3
  8. package/dist/cdn/mattebox.dual.min.js +3 -3
  9. package/dist/cdn/mattebox.hls-drm.min.js +3 -3
  10. package/dist/cdn/mattebox.hls-ll.min.js +3 -3
  11. package/dist/cdn/mattebox.hls-ts-drm.min.js +3 -3
  12. package/dist/cdn/mattebox.hls-ts.min.js +3 -3
  13. package/dist/cdn/mattebox.hls.min.js +3 -3
  14. package/dist/cdn/mattebox.kernel.min.js +1 -1
  15. package/dist/cdn/mattebox.min.js +5 -5
  16. package/dist/containers/projection.d.ts +36 -0
  17. package/dist/containers/projection.d.ts.map +1 -0
  18. package/dist/containers/projection.js +68 -0
  19. package/dist/containers/projection.js.map +1 -0
  20. package/dist/containers/webm/cues.d.ts +59 -0
  21. package/dist/containers/webm/cues.d.ts.map +1 -0
  22. package/dist/containers/webm/cues.js +218 -0
  23. package/dist/containers/webm/cues.js.map +1 -0
  24. package/dist/containers/webm/index.d.ts +36 -0
  25. package/dist/containers/webm/index.d.ts.map +1 -0
  26. package/dist/containers/webm/index.js +271 -0
  27. package/dist/containers/webm/index.js.map +1 -0
  28. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.157.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/asyncToGenerator.js +1 -1
  29. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.157.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/defineProperty.js +1 -1
  30. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.157.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/objectSpread2.js +1 -1
  31. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.157.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/objectWithoutProperties.js +1 -1
  32. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.157.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/objectWithoutPropertiesLoose.js +1 -1
  33. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.157.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/toPrimitive.js +1 -1
  34. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.157.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/toPropertyKey.js +1 -1
  35. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.157.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/typeof.js +1 -1
  36. package/dist/es2015/containers/fmp4/fit.js +1 -1
  37. package/dist/es2015/containers/id3.js +1 -1
  38. package/dist/es2015/containers/projection.js +68 -0
  39. package/dist/es2015/containers/scte35.js +1 -1
  40. package/dist/es2015/containers/ts-transmux/h264.js +1 -1
  41. package/dist/es2015/containers/ts-transmux/h265.js +1 -1
  42. package/dist/es2015/containers/ts-transmux/index.js +1 -1
  43. package/dist/es2015/containers/ts-transmux/runner.js +2 -2
  44. package/dist/es2015/containers/ts-transmux/transmux.js +1 -1
  45. package/dist/es2015/containers/webm/cues.js +197 -0
  46. package/dist/es2015/containers/webm/index.js +258 -0
  47. package/dist/es2015/containers/webvtt.js +1 -1
  48. package/dist/es2015/containers/wvtt.js +1 -1
  49. package/dist/es2015/eme/index.js +3 -3
  50. package/dist/es2015/index.js +2 -2
  51. package/dist/es2015/kernel/append-queue.js +1 -1
  52. package/dist/es2015/kernel/dry-run.js +1 -1
  53. package/dist/es2015/kernel/mse.js +1 -1
  54. package/dist/es2015/kernel/prepare.js +2 -2
  55. package/dist/es2015/kernel/reducer.js +33 -4
  56. package/dist/es2015/kernel/refresh.js +1 -1
  57. package/dist/es2015/kernel/rendition-select.js +4 -4
  58. package/dist/es2015/kernel/scheduler.js +1 -1
  59. package/dist/es2015/kernel/timeline.js +1 -1
  60. package/dist/es2015/kernel/trace.js +1 -1
  61. package/dist/es2015/kernel/transport.js +2 -2
  62. package/dist/es2015/presets/define.js +2 -2
  63. package/dist/es2015/presets/full/index.js +6 -3
  64. package/dist/es2015/presets/tiers/dash-ll.js +2 -1
  65. package/dist/es2015/presets/tiers/dash.js +7 -2
  66. package/dist/es2015/presets/tiers/drm.js +4 -2
  67. package/dist/es2015/protocols/dash-cmaf/index.js +12 -6
  68. package/dist/es2015/protocols/dash-cmaf/parse.js +41 -13
  69. package/dist/es2015/protocols/dash-cmaf/periods-runtime.js +1 -1
  70. package/dist/es2015/protocols/dash-cmaf/periods.js +1 -1
  71. package/dist/es2015/protocols/dash-live/index.js +8 -5
  72. package/dist/es2015/protocols/dash-ll/index.js +3 -2
  73. package/dist/es2015/protocols/hls-cmaf/index.js +1 -1
  74. package/dist/es2015/protocols/hls-cmaf/parse.js +6 -4
  75. package/dist/es2015/protocols/hls-cmaf/unavailable.js +1 -1
  76. package/dist/es2015/protocols/hls-live/index.js +1 -1
  77. package/dist/es2015/protocols/hls-ll/parse.js +2 -2
  78. package/dist/es2015/stages/abr/index.js +1 -1
  79. package/dist/es2015/stages/aes-128/index.js +1 -1
  80. package/dist/es2015/stages/chapters/index.js +2 -2
  81. package/dist/es2015/stages/chapters/parse.js +2 -2
  82. package/dist/es2015/stages/codec-probe/index.js +1 -1
  83. package/dist/es2015/stages/content-steering/index.js +1 -1
  84. package/dist/es2015/stages/eme-core/index.js +4 -4
  85. package/dist/es2015/stages/eme-fairplay/index.js +1 -1
  86. package/dist/es2015/stages/eme-wiseplay/index.js +24 -0
  87. package/dist/es2015/stages/hdr/index.js +1 -1
  88. package/dist/es2015/stages/interstitials/breaks.js +1 -1
  89. package/dist/es2015/stages/interstitials/index.js +2 -2
  90. package/dist/es2015/stages/projection/index.js +41 -0
  91. package/dist/es2015/stages/qoe/index.js +1 -1
  92. package/dist/es2015/stages/recovery/index.js +1 -1
  93. package/dist/es2015/stages/rendition-names/index.js +1 -1
  94. package/dist/es2015/stages/text-cea608/decode.js +1 -1
  95. package/dist/es2015/stages/text-cea708/decode.js +2 -2
  96. package/dist/es2015/stages/text-cea708/index.js +1 -1
  97. package/dist/es2015/stages/text-ttml/index.js +1 -1
  98. package/dist/es2015/stages/text-ttml/parse.js +1 -1
  99. package/dist/es2015/stages/thumbnails/index.js +1 -1
  100. package/dist/es2015/stages/timed-metadata/index.js +1 -1
  101. package/dist/es2015/stages/trick-play/index.js +1 -1
  102. package/dist/kernel/reducer.d.ts.map +1 -1
  103. package/dist/kernel/reducer.js +44 -1
  104. package/dist/kernel/reducer.js.map +1 -1
  105. package/dist/presets/full/index.d.ts.map +1 -1
  106. package/dist/presets/full/index.js +5 -2
  107. package/dist/presets/full/index.js.map +1 -1
  108. package/dist/presets/tiers/dash-ll.d.ts.map +1 -1
  109. package/dist/presets/tiers/dash-ll.js +2 -1
  110. package/dist/presets/tiers/dash-ll.js.map +1 -1
  111. package/dist/presets/tiers/dash.d.ts +7 -1
  112. package/dist/presets/tiers/dash.d.ts.map +1 -1
  113. package/dist/presets/tiers/dash.js +3 -2
  114. package/dist/presets/tiers/dash.js.map +1 -1
  115. package/dist/presets/tiers/drm.d.ts +1 -1
  116. package/dist/presets/tiers/drm.d.ts.map +1 -1
  117. package/dist/presets/tiers/drm.js +3 -2
  118. package/dist/presets/tiers/drm.js.map +1 -1
  119. package/dist/protocols/dash-cmaf/index.d.ts +8 -3
  120. package/dist/protocols/dash-cmaf/index.d.ts.map +1 -1
  121. package/dist/protocols/dash-cmaf/index.js +12 -5
  122. package/dist/protocols/dash-cmaf/index.js.map +1 -1
  123. package/dist/protocols/dash-cmaf/parse.d.ts +6 -1
  124. package/dist/protocols/dash-cmaf/parse.d.ts.map +1 -1
  125. package/dist/protocols/dash-cmaf/parse.js +54 -7
  126. package/dist/protocols/dash-cmaf/parse.js.map +1 -1
  127. package/dist/protocols/dash-live/index.d.ts +6 -3
  128. package/dist/protocols/dash-live/index.d.ts.map +1 -1
  129. package/dist/protocols/dash-live/index.js +7 -4
  130. package/dist/protocols/dash-live/index.js.map +1 -1
  131. package/dist/protocols/dash-ll/index.d.ts.map +1 -1
  132. package/dist/protocols/dash-ll/index.js +3 -2
  133. package/dist/protocols/dash-ll/index.js.map +1 -1
  134. package/dist/protocols/hls-cmaf/parse.d.ts.map +1 -1
  135. package/dist/protocols/hls-cmaf/parse.js +8 -0
  136. package/dist/protocols/hls-cmaf/parse.js.map +1 -1
  137. package/dist/stages/drm-shared.d.ts +1 -1
  138. package/dist/stages/drm-shared.js +1 -1
  139. package/dist/stages/eme-core/index.js +2 -2
  140. package/dist/stages/eme-wiseplay/index.d.ts +27 -0
  141. package/dist/stages/eme-wiseplay/index.d.ts.map +1 -0
  142. package/dist/stages/eme-wiseplay/index.js +29 -0
  143. package/dist/stages/eme-wiseplay/index.js.map +1 -0
  144. package/dist/stages/projection/index.d.ts +3 -0
  145. package/dist/stages/projection/index.d.ts.map +1 -0
  146. package/dist/stages/projection/index.js +45 -0
  147. package/dist/stages/projection/index.js.map +1 -0
  148. package/dist/types/ir.d.ts +14 -1
  149. package/dist/types/ir.d.ts.map +1 -1
  150. package/dist/types/kernel.d.ts +3 -1
  151. package/dist/types/kernel.d.ts.map +1 -1
  152. package/dist/types/kernel.js.map +1 -1
  153. package/dist/types/messages.d.ts +13 -1
  154. package/dist/types/messages.d.ts.map +1 -1
  155. package/package.json +2 -2
@@ -0,0 +1,197 @@
1
+ // src/containers/webm/cues.ts
2
+ /** EBML header, RFC 8794 §11.2.1. */
3
+ const EBML_ID = 440786851;
4
+ /** Segment, RFC 9559 §5.1. */
5
+ const SEGMENT_ID = 408125543;
6
+ /** Info, RFC 9559 §5.1.2. */
7
+ const INFO_ID = 357149030;
8
+ /** TimestampScale (formerly TimecodeScale), RFC 9559 §5.1.2.9. */
9
+ const TIMESTAMP_SCALE_ID = 2807729;
10
+ /** Duration, RFC 9559 §5.1.2.10. */
11
+ const DURATION_ID = 17545;
12
+ /** Cues, RFC 9559 §5.1.5. */
13
+ const CUES_ID = 475249515;
14
+ /** CuePoint, RFC 9559 §5.1.5.1. */
15
+ const CUE_POINT_ID = 187;
16
+ /** CueTime, RFC 9559 §5.1.5.1.1. */
17
+ const CUE_TIME_ID = 179;
18
+ /** CueTrackPositions, RFC 9559 §5.1.5.1.2. */
19
+ const CUE_TRACK_POSITIONS_ID = 183;
20
+ /** CueClusterPosition, RFC 9559 §5.1.5.1.2.2. */
21
+ const CUE_CLUSTER_POSITION_ID = 241;
22
+ /** The TimestampScale default: one tick is a millisecond. RFC 9559 §5.1.2.9. */
23
+ const DEFAULT_TIMESTAMP_SCALE = 1e6;
24
+ /**
25
+ * Reads a variable-size integer at `at`, RFC 8794 §4. `marker` keeps the
26
+ * length marker bit, as an Element ID does (§5); without it the value is
27
+ * a data size. Returns null when the bytes end early or the first byte is
28
+ * zero, which no valid VINT starts with.
29
+ */
30
+ function readVint(bytes, at, marker) {
31
+ const first = bytes[at];
32
+ if (first === void 0 || first === 0) return null;
33
+ let length = 1;
34
+ while ((first & 128 >> length - 1) === 0) length += 1;
35
+ if (at + length > bytes.byteLength) return null;
36
+ let value = marker ? first : first & 255 >> length;
37
+ let unknown = value === 255 >> length;
38
+ for (let i = 1; i < length; i += 1) {
39
+ const byte = bytes[at + i];
40
+ if (byte !== 255) unknown = false;
41
+ value = value * 256 + byte;
42
+ }
43
+ return {
44
+ value,
45
+ length,
46
+ unknown: !marker && unknown
47
+ };
48
+ }
49
+ /**
50
+ * Reads the element header at `at`. Its data is clamped to `limit`, so a
51
+ * Segment whose data runs past the bytes fetched still reads as far as
52
+ * they go, as Shaka's EBML parser reads a partial element. An unknown
53
+ * size extends to `limit`.
54
+ */
55
+ function readElement(bytes, at, limit) {
56
+ const id = readVint(bytes, at, true);
57
+ if (id === null) return null;
58
+ const size = readVint(bytes, at + id.length, false);
59
+ if (size === null) return null;
60
+ const start = at + id.length + size.length;
61
+ if (start > limit) return null;
62
+ const declared = size.unknown ? null : size.value;
63
+ const end = declared === null ? limit : Math.min(limit, start + declared);
64
+ return {
65
+ id: id.value,
66
+ start,
67
+ end,
68
+ size: declared
69
+ };
70
+ }
71
+ /** The child elements between `start` and `end`, in order. Stops at the first header it cannot read. */
72
+ function childrenOf(bytes, start, end) {
73
+ const found = [];
74
+ let at = start;
75
+ while (at < end) {
76
+ const element = readElement(bytes, at, end);
77
+ if (element === null) break;
78
+ found.push(element);
79
+ at = element.end;
80
+ }
81
+ return found;
82
+ }
83
+ /** An unsigned integer element, RFC 8794 §7.2: big-endian, zero to eight bytes. */
84
+ function readUint(bytes, element) {
85
+ let value = 0;
86
+ for (let i = element.start; i < element.end; i += 1) value = value * 256 + bytes[i];
87
+ return value;
88
+ }
89
+ /** A float element, RFC 8794 §7.3: zero, four or eight bytes, big-endian IEEE 754. */
90
+ function readFloat(bytes, element) {
91
+ const length = element.end - element.start;
92
+ const view = new DataView(bytes.buffer, bytes.byteOffset + element.start, length);
93
+ if (length === 4) return view.getFloat32(0);
94
+ if (length === 8) return view.getFloat64(0);
95
+ return length === 0 ? 0 : null;
96
+ }
97
+ /**
98
+ * Reads the initialization range: the EBML header, then the Segment
99
+ * header and its Info. Null when the bytes do not start with an EBML
100
+ * header followed by a Segment, or hold no Info.
101
+ */
102
+ function readInit(bytes) {
103
+ const header = readElement(bytes, 0, bytes.byteLength);
104
+ if (header === null || header.id !== EBML_ID) return null;
105
+ const segment = readElement(bytes, header.end, bytes.byteLength);
106
+ if (segment === null || segment.id !== SEGMENT_ID) return null;
107
+ const info = childrenOf(bytes, segment.start, segment.end).find((e) => e.id === INFO_ID);
108
+ if (info === void 0) return null;
109
+ let scale = DEFAULT_TIMESTAMP_SCALE;
110
+ let ticks = null;
111
+ for (const element of childrenOf(bytes, info.start, info.end)) if (element.id === TIMESTAMP_SCALE_ID) scale = readUint(bytes, element) || scale;
112
+ else if (element.id === DURATION_ID) ticks = readFloat(bytes, element);
113
+ const tickSeconds = scale / 1e9;
114
+ return {
115
+ segmentStart: segment.start,
116
+ segmentSize: segment.size,
117
+ tickSeconds,
118
+ duration: ticks === null ? null : ticks * tickSeconds
119
+ };
120
+ }
121
+ /**
122
+ * Reads the Cues element at the start of the index range. Each CuePoint
123
+ * gives its CueTime and the CueClusterPosition of its first
124
+ * CueTrackPositions. A DASH Representation carries one track, so the
125
+ * first is the one. Null when the bytes do not start with Cues.
126
+ */
127
+ function readCues(bytes) {
128
+ const cues = readElement(bytes, 0, bytes.byteLength);
129
+ if (cues === null || cues.id !== CUES_ID) return null;
130
+ const points = [];
131
+ for (const point of childrenOf(bytes, cues.start, cues.end)) {
132
+ if (point.id !== CUE_POINT_ID) continue;
133
+ let time = null;
134
+ let position = null;
135
+ for (const element of childrenOf(bytes, point.start, point.end)) if (element.id === CUE_TIME_ID) time = readUint(bytes, element);
136
+ else if (element.id === CUE_TRACK_POSITIONS_ID && position === null) {
137
+ const cluster = childrenOf(bytes, element.start, element.end).find((e) => e.id === CUE_CLUSTER_POSITION_ID);
138
+ if (cluster !== void 0) position = readUint(bytes, cluster);
139
+ }
140
+ if (time !== null && position !== null) points.push({
141
+ time,
142
+ position
143
+ });
144
+ }
145
+ return points;
146
+ }
147
+ /**
148
+ * Turns the cue points into byte-range segments, one per Cluster. A
149
+ * segment runs from its Cluster to the byte before the next one. The last
150
+ * ends where the Cues start when they follow it, else at the end of the
151
+ * Segment when its size is known, else at the end of the file (an
152
+ * open-ended range). Its duration runs to the Info Duration, as in Shaka
153
+ * Player; without a Duration the index cannot place the last segment and
154
+ * no segment is returned.
155
+ *
156
+ * Several CuePoints can name one Cluster (one per track, or a
157
+ * CueRelativePosition inside it): only the first of them opens a segment.
158
+ */
159
+ function cuesToSegments(init, initRange, points, addressing) {
160
+ var _addressing$presentat;
161
+ if (init.duration === null) return [];
162
+ const base = initRange.start + init.segmentStart;
163
+ const clusters = [];
164
+ for (const point of points) {
165
+ const previous = clusters[clusters.length - 1];
166
+ if (previous !== void 0 && point.position <= previous.position) continue;
167
+ clusters.push(point);
168
+ }
169
+ const pto = (_addressing$presentat = addressing.presentationTimeOffset) !== null && _addressing$presentat !== void 0 ? _addressing$presentat : 0;
170
+ const indexStart = addressing.indexRange.start;
171
+ const segments = [];
172
+ for (let i = 0; i < clusters.length; i += 1) {
173
+ const point = clusters[i];
174
+ const next = clusters[i + 1];
175
+ const start = point.time * init.tickSeconds;
176
+ const end = next === void 0 ? init.duration : next.time * init.tickSeconds;
177
+ const byteStart = base + point.position;
178
+ let byteEnd;
179
+ if (next !== void 0) byteEnd = base + next.position - 1;
180
+ else if (indexStart > byteStart) byteEnd = indexStart - 1;
181
+ else if (init.segmentSize !== null) byteEnd = base + init.segmentSize - 1;
182
+ else byteEnd = Number.POSITIVE_INFINITY;
183
+ if (end <= start) continue;
184
+ segments.push({
185
+ seq: segments.length,
186
+ start: start - pto,
187
+ duration: end - start,
188
+ url: addressing.url,
189
+ byteRange: {
190
+ start: byteStart,
191
+ end: byteEnd
192
+ }
193
+ });
194
+ }
195
+ return segments;
196
+ }
197
+ export { cuesToSegments, readCues, readInit };
@@ -0,0 +1,258 @@
1
+ import { scheduled, tickAfter } from "../../kernel/effects.js";
2
+ import { findRendition } from "../../kernel/presentation.js";
3
+ import { activeRenditions } from "../../kernel/rendition-select.js";
4
+ import { isUnresolved } from "../../kernel/timeline.js";
5
+ import { cuesToSegments, readCues, readInit } from "./cues.js";
6
+ import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
7
+ // src/containers/webm/index.ts
8
+ /**
9
+ * WebM segments in DASH. MSE takes `video/webm` and `audio/webm` as they
10
+ * are (W3C WebM Byte Stream Format,
11
+ * https://www.w3.org/TR/mse-byte-stream-format-webm/), so nothing is
12
+ * rewrapped. The stage does two things:
13
+ *
14
+ * - It provides the `video/webm` and `audio/webm` content handlers, so the
15
+ * DASH adapters keep WebM Representations instead of leaving them out.
16
+ * - It resolves a WebM `SegmentBase`: it fetches the initialization range
17
+ * and the Cues at `indexRange`, and turns them into one byte-range
18
+ * segment per Cluster, as Shaka Player and dash.js do.
19
+ *
20
+ * A `SegmentTemplate` WebM Representation needs no index and plays from
21
+ * the MPD alone. Inert module: exports a factory, registers nothing at
22
+ * import time.
23
+ */
24
+ /** The fetch of a rendition's initialization range: `webm:init:<renditionId>`. */
25
+ const INIT_TOKEN = "webm:init:";
26
+ /** The fetch of a rendition's Cues: `webm:cues:<renditionId>`. */
27
+ const CUES_TOKEN = "webm:cues:";
28
+ /** A failed index's retry: `webm:retry:<renditionId>`. */
29
+ const RETRY_TOKEN = "webm:retry:";
30
+ /** The constraint source that excludes renditions whose index failed. */
31
+ const UNAVAILABLE = "webm:unavailable";
32
+ /** The default wait before a failed index is tried again, as the DASH adapter waits. */
33
+ const RETRY_SECONDS = 15;
34
+ /** The slice before any load. */
35
+ const INITIAL = {
36
+ pending: {},
37
+ asked: {},
38
+ inits: {},
39
+ cues: {},
40
+ failed: {},
41
+ seen: ""
42
+ };
43
+ /** WebM `SegmentBase` addressing not resolved yet, or null for anything else. */
44
+ function asWebm(addressing) {
45
+ return addressing !== void 0 && isUnresolved(addressing) && addressing.format === "webm" ? addressing : null;
46
+ }
47
+ /** Loops a message back into the bus through a zero-delay schedule effect. */
48
+ function feed(message) {
49
+ return scheduled("webm:loopback", message);
50
+ }
51
+ /** A copy of `record` without `key`. */
52
+ function without(record, key) {
53
+ const copy = _objectSpread2({}, record);
54
+ delete copy[key];
55
+ return copy;
56
+ }
57
+ /** The slice with every trace of one rendition's index gone, its in-flight tokens too. */
58
+ function forget(state, renditionId) {
59
+ const pending = _objectSpread2({}, state.pending);
60
+ delete pending[`${INIT_TOKEN}${renditionId}`];
61
+ delete pending[`${CUES_TOKEN}${renditionId}`];
62
+ return _objectSpread2(_objectSpread2({}, state), {}, {
63
+ pending,
64
+ asked: without(state.asked, renditionId),
65
+ inits: without(state.inits, renditionId),
66
+ cues: without(state.cues, renditionId)
67
+ });
68
+ }
69
+ /** The error a WebM index that cannot be read reports. */
70
+ function invalid(renditionId, reason) {
71
+ return {
72
+ category: "media",
73
+ code: "MEDIA_CONTAINER_INVALID",
74
+ fatal: false,
75
+ recoverable: false,
76
+ context: {
77
+ renditionId,
78
+ reason
79
+ }
80
+ };
81
+ }
82
+ /**
83
+ * An index that failed to load or could not be read. The rendition is
84
+ * excluded until its retry, as the DASH adapter does for a `sidx`. When
85
+ * that leaves a media track with no rendition, the load fails.
86
+ */
87
+ function unavailable(state, kernel, renditionId, error, retryMs) {
88
+ var _findRendition;
89
+ const failed = _objectSpread2(_objectSpread2({}, state.failed), {}, { [renditionId]: true });
90
+ const next = _objectSpread2(_objectSpread2({}, forget(state, renditionId)), {}, { failed });
91
+ const effects = [{
92
+ kind: "emit",
93
+ event: "error",
94
+ payload: {
95
+ category: error.category,
96
+ code: error.code,
97
+ fatal: false,
98
+ recoverable: false,
99
+ renditionId
100
+ }
101
+ }];
102
+ const track = kernel.presentation === null ? null : (_findRendition = findRendition(kernel.presentation, renditionId)) === null || _findRendition === void 0 ? void 0 : _findRendition.track;
103
+ const media = (track === null || track === void 0 ? void 0 : track.contentType) === "video" || (track === null || track === void 0 ? void 0 : track.contentType) === "audio";
104
+ if (track != null && media && track.renditions.every((r) => r.id in failed)) return [next, [...effects, feed({
105
+ type: "MANIFEST_FAILED",
106
+ error: _objectSpread2(_objectSpread2({}, error), {}, { fatal: true })
107
+ })]];
108
+ effects.push(feed({
109
+ type: "CONSTRAIN",
110
+ source: UNAVAILABLE,
111
+ constraint: { excludeIds: Object.keys(failed) }
112
+ }));
113
+ if (Number.isFinite(retryMs)) effects.push(tickAfter(`${RETRY_TOKEN}${renditionId}`, retryMs));
114
+ return [next, effects];
115
+ }
116
+ /** The retry of a failed index: the rendition returns to arbitration and is fetched when needed. */
117
+ function retry(state, renditionId) {
118
+ if (!(renditionId in state.failed)) return [state, []];
119
+ const failed = without(state.failed, renditionId);
120
+ return [_objectSpread2(_objectSpread2({}, state), {}, { failed }), [feed({
121
+ type: "CONSTRAIN",
122
+ source: UNAVAILABLE,
123
+ constraint: { excludeIds: Object.keys(failed) }
124
+ })]];
125
+ }
126
+ /**
127
+ * One fetched part of an index. Once both parts of a rendition are read,
128
+ * its segments go to the kernel as a PLAYLIST_REFRESHED, which merges them
129
+ * as it merges a resolved `sidx`.
130
+ */
131
+ function received(state, kernel, token, bytes, retryMs) {
132
+ var _rendition$rendition$;
133
+ const renditionId = state.pending[token];
134
+ let next = _objectSpread2(_objectSpread2({}, state), {}, { pending: without(state.pending, token) });
135
+ const rendition = kernel.presentation === null ? null : findRendition(kernel.presentation, renditionId);
136
+ const addressing = asWebm(rendition === null || rendition === void 0 ? void 0 : rendition.rendition.segments);
137
+ const initRange = rendition === null || rendition === void 0 || (_rendition$rendition$ = rendition.rendition.init) === null || _rendition$rendition$ === void 0 ? void 0 : _rendition$rendition$.byteRange;
138
+ if (addressing === null || initRange === void 0) return [forget(next, renditionId), []];
139
+ const data = new Uint8Array(bytes);
140
+ if (token.startsWith(INIT_TOKEN)) {
141
+ const init = readInit(data);
142
+ if (init === null) return unavailable(next, kernel, renditionId, invalid(renditionId, "no WebM Info"), retryMs);
143
+ next = _objectSpread2(_objectSpread2({}, next), {}, { inits: _objectSpread2(_objectSpread2({}, next.inits), {}, { [renditionId]: init }) });
144
+ } else {
145
+ const cues = readCues(data);
146
+ if (cues === null) return unavailable(next, kernel, renditionId, invalid(renditionId, "no WebM Cues"), retryMs);
147
+ next = _objectSpread2(_objectSpread2({}, next), {}, { cues: _objectSpread2(_objectSpread2({}, next.cues), {}, { [renditionId]: cues }) });
148
+ }
149
+ const init = next.inits[renditionId];
150
+ const cues = next.cues[renditionId];
151
+ if (init === void 0 || cues === void 0) return [next, []];
152
+ const segments = cuesToSegments(init, initRange, cues, addressing);
153
+ if (segments.length === 0) return unavailable(next, kernel, renditionId, invalid(renditionId, "WebM Cues hold no segment"), retryMs);
154
+ return [_objectSpread2(_objectSpread2({}, next), {}, {
155
+ inits: without(next.inits, renditionId),
156
+ cues: without(next.cues, renditionId)
157
+ }), [feed({
158
+ type: "PLAYLIST_REFRESHED",
159
+ trackId: renditionId,
160
+ renditionId,
161
+ mediaSequence: 0,
162
+ segments
163
+ })]];
164
+ }
165
+ /**
166
+ * The renditions whose index the selection needs and this slice has not
167
+ * asked for: the same set the DASH adapter resolves for a `sidx`, the
168
+ * playing video rendition and its ladder neighbours, and every rendition
169
+ * of the active audio and text tracks.
170
+ */
171
+ function needed(state, kernel) {
172
+ const out = [];
173
+ for (const { rendition } of activeRenditions(kernel, [
174
+ "video",
175
+ "audio",
176
+ "text"
177
+ ], kernel.quality.active)) {
178
+ var _rendition$init;
179
+ if (asWebm(rendition.segments) === null || ((_rendition$init = rendition.init) === null || _rendition$init === void 0 ? void 0 : _rendition$init.byteRange) === void 0) continue;
180
+ if (rendition.id in state.asked || rendition.id in state.failed) continue;
181
+ out.push(rendition);
182
+ }
183
+ return out;
184
+ }
185
+ /** The slice reducer. Pure: it reads bytes from facts and answers with effects. */
186
+ const createReduceWebm = (retryMs) => (slice, msg, kernel) => {
187
+ const state = slice !== null && slice !== void 0 ? slice : INITIAL;
188
+ if (msg.type === "LOAD" || msg.type === "UNLOAD" || msg.type === "DETACH") return [INITIAL, []];
189
+ if (msg.type === "TICK" && msg.token.startsWith(RETRY_TOKEN)) return retry(state, msg.token.slice(11));
190
+ if (msg.type === "PLAYLIST_REFRESHED" && msg.renditionId !== void 0) {
191
+ if (msg.renditionId in state.asked) return [forget(state, msg.renditionId), []];
192
+ }
193
+ if (msg.type === "SEGMENT_LOADED" && msg.trackId in state.pending) return received(state, kernel, msg.trackId, msg.bytes, retryMs);
194
+ if (msg.type === "SEGMENT_FAILED" && msg.trackId in state.pending) {
195
+ const renditionId = state.pending[msg.trackId];
196
+ return unavailable(state, kernel, renditionId, msg.error, retryMs);
197
+ }
198
+ if (kernel.lifecycle.phase !== "ready" || kernel.presentation === null) return [state, []];
199
+ const key = `${kernel.quality.version}:${kernel.quality.active}`;
200
+ if (key === state.seen && msg.type !== "RESUME") return [state, []];
201
+ const effects = [];
202
+ const pending = _objectSpread2({}, state.pending);
203
+ const asked = _objectSpread2({}, state.asked);
204
+ for (const rendition of needed(state, kernel)) {
205
+ const addressing = asWebm(rendition.segments);
206
+ const init = rendition.init;
207
+ asked[rendition.id] = true;
208
+ for (const [prefix, url, range] of [[
209
+ INIT_TOKEN,
210
+ init.url,
211
+ init.byteRange
212
+ ], [
213
+ CUES_TOKEN,
214
+ addressing.url,
215
+ addressing.indexRange
216
+ ]]) {
217
+ const token = `${prefix}${rendition.id}`;
218
+ pending[token] = rendition.id;
219
+ effects.push(_objectSpread2(_objectSpread2({
220
+ kind: "fetch",
221
+ token,
222
+ url
223
+ }, range !== void 0 ? { range } : {}), {}, { renditionId: rendition.id }));
224
+ }
225
+ }
226
+ return [_objectSpread2(_objectSpread2({}, state), {}, {
227
+ pending,
228
+ asked,
229
+ seen: key
230
+ }), effects];
231
+ };
232
+ /**
233
+ * The stage factory. Add it beside a DASH adapter:
234
+ * `mattebox({ stages: [dashCmaf(), webm()] })`.
235
+ */
236
+ function webm(options = {}) {
237
+ var _options$unavailableR;
238
+ const retryMs = ((_options$unavailableR = options.unavailableRetrySeconds) !== null && _options$unavailableR !== void 0 ? _options$unavailableR : RETRY_SECONDS) * 1e3;
239
+ return {
240
+ name: "webm",
241
+ provides: [
242
+ "webm",
243
+ {
244
+ contentType: "video",
245
+ mimeType: "video/webm"
246
+ },
247
+ {
248
+ contentType: "audio",
249
+ mimeType: "audio/webm"
250
+ }
251
+ ],
252
+ requires: ["dash-cmaf"],
253
+ install(ctx) {
254
+ ctx.reduce("webm", createReduceWebm(retryMs));
255
+ }
256
+ };
257
+ }
258
+ export { createReduceWebm, webm as default };
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
2
2
  // src/containers/webvtt.ts
3
3
  /** `HH:MM:SS.mmm` or `MM:SS.mmm` to seconds, or null. */
4
4
  function parseTimestamp(text) {
@@ -1,5 +1,5 @@
1
1
  import { fourcc, viewOf } from "./mp4-box/index.js";
2
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
2
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
3
3
  // src/containers/wvtt.ts
4
4
  /** The child boxes of `bytes`, as type and payload. */
5
5
  function boxes(bytes) {
@@ -1,8 +1,8 @@
1
1
  import { fetchWithin } from "../kernel/transport.js";
2
2
  import emeCore from "../stages/eme-core/index.js";
3
- import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectWithoutProperties.js";
4
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
5
- import _asyncToGenerator from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/asyncToGenerator.js";
3
+ import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectWithoutProperties.js";
4
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
5
+ import _asyncToGenerator from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/asyncToGenerator.js";
6
6
  // src/eme/index.ts
7
7
  /**
8
8
  * The engine's DRM on an element the engine does not drive. On Safari a
@@ -12,8 +12,8 @@ import { activeAudio, availableGroups, canSwitchTo, createArbiter, exclusionsOf
12
12
  import { createMseSink } from "./kernel/sinks/mse-sink.js";
13
13
  import { createTrackRegistry } from "./kernel/track-registry.js";
14
14
  import { createTransport } from "./kernel/transport.js";
15
- import _objectSpread2 from "./_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
16
- import _asyncToGenerator from "./_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/asyncToGenerator.js";
15
+ import _objectSpread2 from "./_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
16
+ import _asyncToGenerator from "./_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/asyncToGenerator.js";
17
17
  import { isAudioDescription, isEnhancedSpeech, isOriginal, isSdh, videoKind } from "./kernel/characteristics.js";
18
18
  import { exportTrace, replay } from "./kernel/trace.js";
19
19
  // src/index.ts
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
2
2
  // src/kernel/append-queue.ts
3
3
  function isQuotaError(err) {
4
4
  return err instanceof DOMException && err.name === "QuotaExceededError";
@@ -2,7 +2,7 @@ import { createBus } from "./bus.js";
2
2
  import { createEffectRunner } from "./effects.js";
3
3
  import { createSegmentPreparer } from "./prepare.js";
4
4
  import { createReducer, initialState } from "./reducer.js";
5
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
5
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
6
6
  // src/kernel/dry-run.ts
7
7
  /** The whole run ends here, whatever it has fetched: a preload must not outlive its use. */
8
8
  const LIMIT_MS = 1e4;
@@ -1,6 +1,6 @@
1
1
  import { createAppendQueue } from "./append-queue.js";
2
2
  import { createEvictor } from "./evictor.js";
3
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
3
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
4
4
  // src/kernel/mse.ts
5
5
  function managedMediaSource() {
6
6
  return globalThis.ManagedMediaSource;
@@ -1,5 +1,5 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
2
- import _asyncToGenerator from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/asyncToGenerator.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
2
+ import _asyncToGenerator from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/asyncToGenerator.js";
3
3
  // src/kernel/prepare.ts
4
4
  /**
5
5
  * The boundary meta a transform and the probe receive. The content type
@@ -6,8 +6,8 @@ import { activeAudio, audioGroup, audioInGroup, availableGroups, canSwitchTo, co
6
6
  import { bufferedEndFrom, reachesEnd, schedule } from "./scheduler.js";
7
7
  import { sbIdFor } from "./sinks/mse-sink.js";
8
8
  import { reconciledOffset, segmentAtTime } from "./timeline.js";
9
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
10
- import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectWithoutProperties.js";
9
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
10
+ import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectWithoutProperties.js";
11
11
  // src/kernel/reducer.ts
12
12
  const _excluded = ["pendingInit"];
13
13
  const _excluded2 = ["repeat"];
@@ -642,9 +642,37 @@ function reduceCommand(state, msg, cfg, hooks) {
642
642
  payload: { available }
643
643
  }]];
644
644
  }
645
+ case "SET_PROJECTION": {
646
+ if (state.presentation === null) return reject(state, msg.type, "no source");
647
+ const site = findRendition(state.presentation, msg.renditionId);
648
+ if (site === null) return reject(state, msg.type, `unknown rendition: ${msg.renditionId}`);
649
+ if (site.rendition.projection !== void 0) return reject(state, msg.type, `projection exists: ${msg.renditionId}`);
650
+ const projections = new Map(state.tracks.projections).set(msg.renditionId, msg.projection);
651
+ const presentation = withProjections(state.presentation, projections);
652
+ return [_objectSpread2(_objectSpread2({}, state), {}, {
653
+ presentation,
654
+ tracks: _objectSpread2(_objectSpread2({}, state.tracks), {}, { projections })
655
+ }), [{
656
+ kind: "emit",
657
+ event: "presentation:changed",
658
+ payload: { id: presentation.id }
659
+ }]];
660
+ }
645
661
  }
646
662
  }
647
663
  /**
664
+ * Gives every rendition SET_PROJECTION named its projection, where the
665
+ * presentation states none. A playlist merge hands the reducer the
666
+ * adapter's presentation, which knows nothing of them.
667
+ */
668
+ function withProjections(presentation, projections) {
669
+ if (projections === void 0 || projections.size === 0) return presentation;
670
+ return _objectSpread2(_objectSpread2({}, presentation), {}, { periods: presentation.periods.map((period) => _objectSpread2(_objectSpread2({}, period), {}, { tracks: period.tracks.map((track) => _objectSpread2(_objectSpread2({}, track), {}, { renditions: track.renditions.map((rendition) => {
671
+ const projection = projections.get(rendition.id);
672
+ return projection === void 0 || rendition.projection !== void 0 ? rendition : _objectSpread2(_objectSpread2({}, rendition), {}, { projection });
673
+ }) })) })) });
674
+ }
675
+ /**
648
676
  * Joins the tracks ADD_TRACK added to every period that lacks them. A
649
677
  * playlist merge hands the reducer the adapter's presentation, which knows
650
678
  * nothing of them.
@@ -696,7 +724,7 @@ function behindTrick(tracks, track, previous) {
696
724
  * merged into it. Activates default tracks and reports what changed.
697
725
  */
698
726
  function loadPresentation(state, merged, undecodableIds = /* @__PURE__ */ new Set()) {
699
- const presentation = withAdded(merged, state.tracks.added);
727
+ const presentation = withProjections(withAdded(merged, state.tracks.added), state.tracks.projections);
700
728
  const available = [];
701
729
  for (const period of presentation.periods) for (const track of period.tracks) available.push(track.id);
702
730
  const inflight = new Map(state.scheduling.inflight);
@@ -1441,7 +1469,8 @@ const COMMAND_TYPES = {
1441
1469
  THROUGHPUT_HINT: true,
1442
1470
  RESOLVE_RENDITION: true,
1443
1471
  ABORT_INFLIGHT: true,
1444
- ADD_TRACK: true
1472
+ ADD_TRACK: true,
1473
+ SET_PROJECTION: true
1445
1474
  };
1446
1475
  function isCommand(msg) {
1447
1476
  return msg.type in COMMAND_TYPES;
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
2
2
  // src/kernel/refresh.ts
3
3
  /** The presentation with the refresh merged, or null when it names no rendition the presentation holds. */
4
4
  function applyRefresh(presentation, refresh) {
@@ -1,8 +1,8 @@
1
1
  import { findRendition, findTrackSite } from "./presentation.js";
2
2
  import { bufferedEndFrom } from "./scheduler.js";
3
3
  import { segmentAtTime } from "./timeline.js";
4
- import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectWithoutProperties.js";
5
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
4
+ import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectWithoutProperties.js";
5
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
6
6
  // src/kernel/rendition-select.ts
7
7
  const _excluded = [
8
8
  "maxHeight",
@@ -413,7 +413,7 @@ function planPinApply(input) {
413
413
  kind: "remove",
414
414
  sbId: input.sbId,
415
415
  start: safePoint,
416
- end: Infinity
416
+ end: 1e400
417
417
  });
418
418
  }
419
419
  return {
@@ -428,7 +428,7 @@ function planPinApply(input) {
428
428
  kind: "remove",
429
429
  sbId: input.sbId,
430
430
  start: from,
431
- end: Infinity
431
+ end: 1e400
432
432
  });
433
433
  effects.push({
434
434
  kind: "seekElement",
@@ -1,5 +1,5 @@
1
1
  import { buildEpochs, epochForSeq, epochKey, isIndexed, segmentAtTime, timestampOffsetFor } from "./timeline.js";
2
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
2
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
3
3
  // src/kernel/scheduler.ts
4
4
  const DEFAULT_GAP_TOLERANCE = .25;
5
5
  /**
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
2
2
  // src/kernel/timeline.ts
3
3
  function isIndexed(addressing) {
4
4
  return !Array.isArray(addressing) && addressing.kind === "indexed";
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
2
2
  function isBytes(value) {
3
3
  return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
4
4
  }
@@ -1,5 +1,5 @@
1
- import _asyncToGenerator from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/asyncToGenerator.js";
2
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.157.0/helpers/esm/objectSpread2.js";
1
+ import _asyncToGenerator from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/asyncToGenerator.js";
2
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
3
3
  // src/kernel/transport.ts
4
4
  const DEFAULT_RETRY_POLICY = {
5
5
  maxAttempts: 3,