mattebox 0.6.1 → 0.8.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.
- package/dist/cdn/mattebox.dash-drm.min.js +3 -3
- package/dist/cdn/mattebox.dash.min.js +3 -3
- package/dist/cdn/mattebox.dual-drm.min.js +3 -3
- package/dist/cdn/mattebox.dual-ts-drm.min.js +3 -3
- package/dist/cdn/mattebox.dual-ts.min.js +3 -3
- package/dist/cdn/mattebox.dual.min.js +3 -3
- package/dist/cdn/mattebox.hls-drm.min.js +3 -3
- package/dist/cdn/mattebox.hls-ts-drm.min.js +3 -3
- package/dist/cdn/mattebox.hls-ts.min.js +3 -3
- package/dist/cdn/mattebox.hls.min.js +3 -3
- package/dist/cdn/mattebox.kernel.min.js +1 -1
- package/dist/cdn/mattebox.min.js +3 -6
- package/dist/containers/adts.d.ts +10 -0
- package/dist/containers/adts.d.ts.map +1 -1
- package/dist/containers/adts.js +27 -7
- package/dist/containers/adts.js.map +1 -1
- package/dist/containers/codec-probe/index.d.ts +0 -6
- package/dist/containers/codec-probe/index.d.ts.map +1 -1
- package/dist/containers/codec-probe/index.js +14 -23
- package/dist/containers/codec-probe/index.js.map +1 -1
- package/dist/containers/fmp4/fit.d.ts +26 -0
- package/dist/containers/fmp4/fit.d.ts.map +1 -0
- package/dist/containers/fmp4/fit.js +49 -0
- package/dist/containers/fmp4/fit.js.map +1 -0
- package/dist/containers/fmp4/writer.d.ts +7 -0
- package/dist/containers/fmp4/writer.d.ts.map +1 -1
- package/dist/containers/fmp4/writer.js +9 -1
- package/dist/containers/fmp4/writer.js.map +1 -1
- package/dist/containers/id3.d.ts.map +1 -1
- package/dist/containers/id3.js +2 -1
- package/dist/containers/id3.js.map +1 -1
- package/dist/containers/mp4-box/index.d.ts +66 -0
- package/dist/containers/mp4-box/index.d.ts.map +1 -1
- package/dist/containers/mp4-box/index.js +207 -23
- package/dist/containers/mp4-box/index.js.map +1 -1
- package/dist/containers/packed-audio/index.d.ts.map +1 -1
- package/dist/containers/packed-audio/index.js +4 -26
- package/dist/containers/packed-audio/index.js.map +1 -1
- package/dist/containers/sei.d.ts +5 -0
- package/dist/containers/sei.d.ts.map +1 -1
- package/dist/containers/sei.js +5 -2
- package/dist/containers/sei.js.map +1 -1
- package/dist/containers/ts-transmux/demux.d.ts +7 -1
- package/dist/containers/ts-transmux/demux.d.ts.map +1 -1
- package/dist/containers/ts-transmux/demux.js +38 -17
- package/dist/containers/ts-transmux/demux.js.map +1 -1
- package/dist/containers/ts-transmux/h264.d.ts.map +1 -1
- package/dist/containers/ts-transmux/h264.js +1 -17
- package/dist/containers/ts-transmux/h264.js.map +1 -1
- package/dist/containers/ts-transmux/index.d.ts.map +1 -1
- package/dist/containers/ts-transmux/index.js +9 -1
- package/dist/containers/ts-transmux/index.js.map +1 -1
- package/dist/containers/ts-transmux/transmux.d.ts.map +1 -1
- package/dist/containers/ts-transmux/transmux.js +6 -36
- package/dist/containers/ts-transmux/transmux.js.map +1 -1
- package/dist/{stages/text-webvtt/parse.d.ts → containers/webvtt.d.ts} +4 -3
- package/dist/containers/webvtt.d.ts.map +1 -0
- package/dist/{stages/text-webvtt/parse.js → containers/webvtt.js} +1 -1
- package/dist/containers/webvtt.js.map +1 -0
- package/dist/es2015/containers/adts.js +28 -8
- package/dist/es2015/containers/codec-probe/index.js +17 -26
- package/dist/es2015/containers/fmp4/fit.js +46 -0
- package/dist/es2015/containers/fmp4/writer.js +9 -1
- package/dist/es2015/containers/id3.js +2 -2
- package/dist/es2015/containers/mp4-box/index.js +207 -19
- package/dist/es2015/containers/packed-audio/index.js +4 -28
- package/dist/es2015/containers/sei.js +6 -3
- package/dist/es2015/containers/ts-transmux/demux.js +41 -22
- package/dist/es2015/containers/ts-transmux/h264.js +1 -17
- package/dist/es2015/containers/ts-transmux/index.js +6 -3
- package/dist/es2015/containers/ts-transmux/transmux.js +8 -39
- package/dist/es2015/{stages/text-webvtt/parse.js → containers/webvtt.js} +2 -2
- package/dist/es2015/index.js +6 -15
- package/dist/es2015/kernel/base64.js +25 -0
- package/dist/es2015/kernel/effects.js +21 -1
- package/dist/es2015/kernel/mime.js +5 -1
- package/dist/es2015/kernel/presentation.js +24 -0
- package/dist/es2015/kernel/reducer.js +61 -75
- package/dist/es2015/kernel/refresh.js +1 -1
- package/dist/es2015/kernel/rendition-select.js +50 -5
- package/dist/es2015/kernel/sinks/text-track-sink.js +27 -26
- package/dist/es2015/kernel/timeline.js +1 -1
- package/dist/es2015/kernel/track-registry.js +10 -2
- package/dist/es2015/kernel/url.js +12 -0
- package/dist/es2015/presets/full/index.js +9 -3
- package/dist/es2015/protocols/adapter-shared.js +28 -0
- package/dist/es2015/protocols/dash-cmaf/index.js +18 -55
- package/dist/es2015/protocols/dash-cmaf/parse.js +60 -54
- package/dist/es2015/protocols/dash-live/index.js +13 -28
- package/dist/es2015/protocols/dimensions.js +15 -0
- package/dist/es2015/protocols/hls-cmaf/index.js +17 -52
- package/dist/es2015/protocols/hls-cmaf/lexer.js +3 -0
- package/dist/es2015/protocols/hls-cmaf/parse.js +134 -33
- package/dist/es2015/protocols/hls-cmaf/unavailable.js +2 -1
- package/dist/es2015/protocols/hls-live/index.js +24 -52
- package/dist/es2015/stages/abr/index.js +7 -10
- package/dist/es2015/stages/abr-persist/index.js +17 -10
- package/dist/es2015/stages/aes-128/index.js +14 -7
- package/dist/es2015/stages/alt-audio/index.js +24 -12
- package/dist/es2015/stages/chapters/index.js +170 -0
- package/dist/es2015/stages/chapters/parse.js +176 -0
- package/dist/es2015/stages/cmcd/index.js +14 -4
- package/dist/es2015/stages/codec-switch/index.js +2 -5
- package/dist/es2015/stages/content-steering/index.js +12 -15
- package/dist/es2015/stages/eme-cenc/index.js +10 -4
- package/dist/es2015/stages/eme-core/index.js +29 -11
- package/dist/es2015/stages/eme-fairplay/index.js +11 -7
- package/dist/es2015/stages/nal-scan/index.js +30 -140
- package/dist/es2015/stages/recovery/index.js +46 -53
- package/dist/es2015/stages/text-cea608/index.js +3 -17
- package/dist/es2015/stages/text-webvtt/index.js +1 -1
- package/dist/es2015/stages/text-webvtt-segmented/index.js +15 -8
- package/dist/es2015/stages/thumbnails/index.js +212 -42
- package/dist/es2015/stages/trick-play/index.js +463 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -21
- package/dist/index.js.map +1 -1
- package/dist/kernel/base64.d.ts +9 -0
- package/dist/kernel/base64.d.ts.map +1 -0
- package/dist/kernel/base64.js +26 -0
- package/dist/kernel/base64.js.map +1 -0
- package/dist/kernel/effects.d.ts +9 -1
- package/dist/kernel/effects.d.ts.map +1 -1
- package/dist/kernel/effects.js +12 -0
- package/dist/kernel/effects.js.map +1 -1
- package/dist/kernel/lifecycle.js +1 -1
- package/dist/kernel/lifecycle.js.map +1 -1
- package/dist/kernel/mime.d.ts +2 -0
- package/dist/kernel/mime.d.ts.map +1 -1
- package/dist/kernel/mime.js +4 -0
- package/dist/kernel/mime.js.map +1 -1
- package/dist/kernel/presentation.d.ts +20 -0
- package/dist/kernel/presentation.d.ts.map +1 -0
- package/dist/kernel/presentation.js +25 -0
- package/dist/kernel/presentation.js.map +1 -0
- package/dist/kernel/reducer.d.ts +9 -0
- package/dist/kernel/reducer.d.ts.map +1 -1
- package/dist/kernel/reducer.js +72 -84
- package/dist/kernel/reducer.js.map +1 -1
- package/dist/kernel/refresh.d.ts.map +1 -1
- package/dist/kernel/refresh.js +1 -0
- package/dist/kernel/refresh.js.map +1 -1
- package/dist/kernel/rendition-select.d.ts +19 -4
- package/dist/kernel/rendition-select.d.ts.map +1 -1
- package/dist/kernel/rendition-select.js +67 -4
- package/dist/kernel/rendition-select.js.map +1 -1
- package/dist/kernel/sinks/text-track-sink.d.ts +9 -0
- package/dist/kernel/sinks/text-track-sink.d.ts.map +1 -1
- package/dist/kernel/sinks/text-track-sink.js +29 -29
- package/dist/kernel/sinks/text-track-sink.js.map +1 -1
- package/dist/kernel/timeline.d.ts +8 -1
- package/dist/kernel/timeline.d.ts.map +1 -1
- package/dist/kernel/timeline.js +2 -2
- package/dist/kernel/timeline.js.map +1 -1
- package/dist/kernel/track-registry.d.ts.map +1 -1
- package/dist/kernel/track-registry.js +17 -1
- package/dist/kernel/track-registry.js.map +1 -1
- package/dist/kernel/url.d.ts +4 -0
- package/dist/kernel/url.d.ts.map +1 -0
- package/dist/kernel/url.js +11 -0
- package/dist/kernel/url.js.map +1 -0
- package/dist/presets/full/index.d.ts.map +1 -1
- package/dist/presets/full/index.js +8 -2
- package/dist/presets/full/index.js.map +1 -1
- package/dist/protocols/adapter-shared.d.ts +23 -0
- package/dist/protocols/adapter-shared.d.ts.map +1 -0
- package/dist/protocols/adapter-shared.js +23 -0
- package/dist/protocols/adapter-shared.js.map +1 -0
- package/dist/protocols/dash-cmaf/index.d.ts.map +1 -1
- package/dist/protocols/dash-cmaf/index.js +17 -73
- package/dist/protocols/dash-cmaf/index.js.map +1 -1
- package/dist/protocols/dash-cmaf/parse.d.ts +2 -5
- package/dist/protocols/dash-cmaf/parse.d.ts.map +1 -1
- package/dist/protocols/dash-cmaf/parse.js +46 -39
- package/dist/protocols/dash-cmaf/parse.js.map +1 -1
- package/dist/protocols/dash-live/index.d.ts.map +1 -1
- package/dist/protocols/dash-live/index.js +13 -17
- package/dist/protocols/dash-live/index.js.map +1 -1
- package/dist/protocols/dimensions.d.ts +8 -0
- package/dist/protocols/dimensions.d.ts.map +1 -0
- package/dist/protocols/dimensions.js +13 -0
- package/dist/protocols/dimensions.js.map +1 -0
- package/dist/protocols/hls-cmaf/index.d.ts.map +1 -1
- package/dist/protocols/hls-cmaf/index.js +17 -56
- package/dist/protocols/hls-cmaf/index.js.map +1 -1
- package/dist/protocols/hls-cmaf/lexer.d.ts.map +1 -1
- package/dist/protocols/hls-cmaf/lexer.js +3 -0
- package/dist/protocols/hls-cmaf/lexer.js.map +1 -1
- package/dist/protocols/hls-cmaf/parse.d.ts +13 -9
- package/dist/protocols/hls-cmaf/parse.d.ts.map +1 -1
- package/dist/protocols/hls-cmaf/parse.js +146 -22
- package/dist/protocols/hls-cmaf/parse.js.map +1 -1
- package/dist/protocols/hls-cmaf/unavailable.d.ts.map +1 -1
- package/dist/protocols/hls-cmaf/unavailable.js +3 -1
- package/dist/protocols/hls-cmaf/unavailable.js.map +1 -1
- package/dist/protocols/hls-live/index.d.ts.map +1 -1
- package/dist/protocols/hls-live/index.js +17 -52
- package/dist/protocols/hls-live/index.js.map +1 -1
- package/dist/stages/abr/index.d.ts.map +1 -1
- package/dist/stages/abr/index.js +8 -14
- package/dist/stages/abr/index.js.map +1 -1
- package/dist/stages/abr-cap-size/index.d.ts +1 -1
- package/dist/stages/abr-persist/index.d.ts.map +1 -1
- package/dist/stages/abr-persist/index.js +17 -7
- package/dist/stages/abr-persist/index.js.map +1 -1
- package/dist/stages/aes-128/index.d.ts +0 -9
- package/dist/stages/aes-128/index.d.ts.map +1 -1
- package/dist/stages/aes-128/index.js +13 -11
- package/dist/stages/aes-128/index.js.map +1 -1
- package/dist/stages/alt-audio/index.d.ts +16 -0
- package/dist/stages/alt-audio/index.d.ts.map +1 -1
- package/dist/stages/alt-audio/index.js +23 -12
- package/dist/stages/alt-audio/index.js.map +1 -1
- package/dist/stages/chapters/index.d.ts +26 -0
- package/dist/stages/chapters/index.d.ts.map +1 -0
- package/dist/stages/chapters/index.js +156 -0
- package/dist/stages/chapters/index.js.map +1 -0
- package/dist/stages/chapters/parse.d.ts +65 -0
- package/dist/stages/chapters/parse.d.ts.map +1 -0
- package/dist/stages/chapters/parse.js +201 -0
- package/dist/stages/chapters/parse.js.map +1 -0
- package/dist/stages/cmcd/index.d.ts +0 -11
- package/dist/stages/cmcd/index.d.ts.map +1 -1
- package/dist/stages/cmcd/index.js +15 -9
- package/dist/stages/cmcd/index.js.map +1 -1
- package/dist/stages/codec-switch/index.d.ts.map +1 -1
- package/dist/stages/codec-switch/index.js +3 -8
- package/dist/stages/codec-switch/index.js.map +1 -1
- package/dist/stages/content-steering/index.d.ts.map +1 -1
- package/dist/stages/content-steering/index.js +12 -9
- package/dist/stages/content-steering/index.js.map +1 -1
- package/dist/stages/eme-cenc/index.d.ts +0 -7
- package/dist/stages/eme-cenc/index.d.ts.map +1 -1
- package/dist/stages/eme-cenc/index.js +9 -5
- package/dist/stages/eme-cenc/index.js.map +1 -1
- package/dist/stages/eme-core/index.d.ts.map +1 -1
- package/dist/stages/eme-core/index.js +31 -15
- package/dist/stages/eme-core/index.js.map +1 -1
- package/dist/stages/eme-fairplay/index.d.ts +0 -7
- package/dist/stages/eme-fairplay/index.d.ts.map +1 -1
- package/dist/stages/eme-fairplay/index.js +11 -9
- package/dist/stages/eme-fairplay/index.js.map +1 -1
- package/dist/stages/nal-scan/index.d.ts.map +1 -1
- package/dist/stages/nal-scan/index.js +32 -145
- package/dist/stages/nal-scan/index.js.map +1 -1
- package/dist/stages/recovery/index.d.ts.map +1 -1
- package/dist/stages/recovery/index.js +42 -56
- package/dist/stages/recovery/index.js.map +1 -1
- package/dist/stages/text-cea608/index.d.ts +11 -0
- package/dist/stages/text-cea608/index.d.ts.map +1 -1
- package/dist/stages/text-cea608/index.js +3 -23
- package/dist/stages/text-cea608/index.js.map +1 -1
- package/dist/stages/text-webvtt/index.d.ts +12 -0
- package/dist/stages/text-webvtt/index.d.ts.map +1 -1
- package/dist/stages/text-webvtt/index.js +1 -1
- package/dist/stages/text-webvtt/index.js.map +1 -1
- package/dist/stages/text-webvtt-segmented/index.d.ts.map +1 -1
- package/dist/stages/text-webvtt-segmented/index.js +11 -8
- package/dist/stages/text-webvtt-segmented/index.js.map +1 -1
- package/dist/stages/thumbnails/index.d.ts +39 -10
- package/dist/stages/thumbnails/index.d.ts.map +1 -1
- package/dist/stages/thumbnails/index.js +220 -30
- package/dist/stages/thumbnails/index.js.map +1 -1
- package/dist/stages/trick-play/index.d.ts +51 -0
- package/dist/stages/trick-play/index.d.ts.map +1 -0
- package/dist/stages/trick-play/index.js +480 -0
- package/dist/stages/trick-play/index.js.map +1 -0
- package/dist/types/ir.d.ts +40 -1
- package/dist/types/ir.d.ts.map +1 -1
- package/dist/types/kernel.d.ts +2 -0
- package/dist/types/kernel.d.ts.map +1 -1
- package/dist/types/messages.d.ts +12 -1
- package/dist/types/messages.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/stages/text-webvtt/parse.d.ts.map +0 -1
- package/dist/stages/text-webvtt/parse.js.map +0 -1
|
@@ -21,22 +21,30 @@ function malformed(reason, offset) {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
/** A DataView over exactly these bytes, wherever they sit in their buffer. */
|
|
25
|
+
function viewOf(bytes) {
|
|
26
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
26
27
|
}
|
|
28
|
+
/** The four ASCII characters at `at`: a box type, a sample entry format, an ID3 frame id. */
|
|
29
|
+
function fourcc(bytes, at) {
|
|
30
|
+
var _bytes$at, _bytes, _bytes2, _bytes3;
|
|
31
|
+
return String.fromCharCode((_bytes$at = bytes[at]) !== null && _bytes$at !== void 0 ? _bytes$at : 0, (_bytes = bytes[at + 1]) !== null && _bytes !== void 0 ? _bytes : 0, (_bytes2 = bytes[at + 2]) !== null && _bytes2 !== void 0 ? _bytes2 : 0, (_bytes3 = bytes[at + 3]) !== null && _bytes3 !== void 0 ? _bytes3 : 0);
|
|
32
|
+
}
|
|
33
|
+
/** SampleEntry (8 bytes) plus VisualSampleEntry (70 bytes). ISO/IEC 14496-12 §12.1.3. */
|
|
34
|
+
const VISUAL_ENTRY_HEADER = 78;
|
|
27
35
|
/**
|
|
28
36
|
* Walks one level plus known containers, depth-first. The visitor sees
|
|
29
37
|
* every box; returning false stops the walk early without error.
|
|
30
38
|
*/
|
|
31
39
|
function walkBoxes(data, visit) {
|
|
32
|
-
const view =
|
|
40
|
+
const view = viewOf(data);
|
|
33
41
|
function level(start, end, path) {
|
|
34
42
|
let offset = start;
|
|
35
43
|
while (offset < end) {
|
|
36
44
|
if (end - offset < 8) return malformed("truncated box header", offset);
|
|
37
45
|
let size = view.getUint32(offset);
|
|
38
46
|
let headerSize = 8;
|
|
39
|
-
const type = fourcc(
|
|
47
|
+
const type = fourcc(data, offset + 4);
|
|
40
48
|
if (size === 1) {
|
|
41
49
|
if (end - offset < 16) return malformed("truncated 64-bit size", offset);
|
|
42
50
|
const big = view.getBigUint64(offset + 8);
|
|
@@ -102,7 +110,7 @@ function fullBox(payload) {
|
|
|
102
110
|
function parseTfdt(payload) {
|
|
103
111
|
const header = fullBox(payload);
|
|
104
112
|
if (header === null) return null;
|
|
105
|
-
const view =
|
|
113
|
+
const view = viewOf(header.body);
|
|
106
114
|
if (header.version === 1) {
|
|
107
115
|
if (header.body.byteLength < 8) return null;
|
|
108
116
|
return {
|
|
@@ -121,7 +129,7 @@ function parseSidx(payload) {
|
|
|
121
129
|
const header = fullBox(payload);
|
|
122
130
|
if (header === null) return null;
|
|
123
131
|
const body = header.body;
|
|
124
|
-
const view =
|
|
132
|
+
const view = viewOf(body);
|
|
125
133
|
const wide = header.version === 1;
|
|
126
134
|
const fixed = 8 + (wide ? 16 : 8) + 4;
|
|
127
135
|
if (body.byteLength < fixed) return null;
|
|
@@ -160,20 +168,43 @@ function parseSidx(payload) {
|
|
|
160
168
|
* with mdhd timescale). CMAF timing normalization needs it to convert a
|
|
161
169
|
* baseMediaDecodeTime between timescale units and seconds.
|
|
162
170
|
*/
|
|
171
|
+
/** A trak's track_ID (tkhd) and media timescale (mdhd), or null when either is unreadable. */
|
|
172
|
+
function trackInfo(trak) {
|
|
173
|
+
const tkhd = findBox(trak, "tkhd");
|
|
174
|
+
const mdhd = findBox(trak, "mdia/mdhd");
|
|
175
|
+
if (tkhd === null || mdhd === null) return null;
|
|
176
|
+
const trackAt = tkhd.payload[0] === 1 ? 20 : 12;
|
|
177
|
+
const scaleAt = mdhd.payload[0] === 1 ? 20 : 12;
|
|
178
|
+
if (tkhd.payload.byteLength < trackAt + 4 || mdhd.payload.byteLength < scaleAt + 4) return null;
|
|
179
|
+
return {
|
|
180
|
+
trackId: viewOf(tkhd.payload).getUint32(trackAt),
|
|
181
|
+
timescale: viewOf(mdhd.payload).getUint32(scaleAt)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/** Every sample entry of an stsd payload: its format fourcc and the body after the 8-byte box header. */
|
|
185
|
+
function sampleEntries(stsd) {
|
|
186
|
+
const header = fullBox(stsd);
|
|
187
|
+
if (header === null || header.body.byteLength < 4) return [];
|
|
188
|
+
const body = header.body;
|
|
189
|
+
const view = viewOf(body);
|
|
190
|
+
const out = [];
|
|
191
|
+
let at = 4;
|
|
192
|
+
for (let i = 0; i < view.getUint32(0) && at + 8 <= body.byteLength; i += 1) {
|
|
193
|
+
const size = view.getUint32(at);
|
|
194
|
+
if (size < 8 || at + size > body.byteLength) break;
|
|
195
|
+
out.push({
|
|
196
|
+
format: fourcc(body, at + 4),
|
|
197
|
+
body: body.subarray(at + 8, at + size)
|
|
198
|
+
});
|
|
199
|
+
at += size;
|
|
200
|
+
}
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
163
203
|
function trackTimescales(init) {
|
|
164
204
|
const map = /* @__PURE__ */ new Map();
|
|
165
205
|
for (const trak of findBoxes(init, "moov/trak")) {
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
if (tkhd === null || mdhd === null) continue;
|
|
169
|
-
const tkView = new DataView(tkhd.payload.buffer, tkhd.payload.byteOffset, tkhd.payload.byteLength);
|
|
170
|
-
const mdView = new DataView(mdhd.payload.buffer, mdhd.payload.byteOffset, mdhd.payload.byteLength);
|
|
171
|
-
const trackAt = tkhd.payload[0] === 1 ? 20 : 12;
|
|
172
|
-
const scaleAt = mdhd.payload[0] === 1 ? 20 : 12;
|
|
173
|
-
if (tkhd.payload.byteLength < trackAt + 4 || mdhd.payload.byteLength < scaleAt + 4) continue;
|
|
174
|
-
const trackId = tkView.getUint32(trackAt);
|
|
175
|
-
const timescale = mdView.getUint32(scaleAt);
|
|
176
|
-
if (timescale > 0) map.set(trackId, timescale);
|
|
206
|
+
const info = trackInfo(trak.payload);
|
|
207
|
+
if (info !== null && info.timescale > 0) map.set(info.trackId, info.timescale);
|
|
177
208
|
}
|
|
178
209
|
return map;
|
|
179
210
|
}
|
|
@@ -193,7 +224,7 @@ function earliestDecodeTime(segment, timescales) {
|
|
|
193
224
|
const tfdt = findBox(traf.payload, "tfdt");
|
|
194
225
|
const tfhd = findBox(traf.payload, "tfhd");
|
|
195
226
|
if (tfdt === null || tfhd === null || tfhd.payload.byteLength < 8) continue;
|
|
196
|
-
const trackId =
|
|
227
|
+
const trackId = viewOf(tfhd.payload).getUint32(4);
|
|
197
228
|
const timescale = timescales.get(trackId);
|
|
198
229
|
const parsed = parseTfdt(tfdt.payload);
|
|
199
230
|
if (timescale === void 0 || timescale <= 0 || parsed === null) continue;
|
|
@@ -202,5 +233,162 @@ function earliestDecodeTime(segment, timescales) {
|
|
|
202
233
|
}
|
|
203
234
|
return earliest;
|
|
204
235
|
}
|
|
236
|
+
const TFHD_BASE_DATA_OFFSET = 1;
|
|
237
|
+
const TFHD_SAMPLE_DESCRIPTION = 2;
|
|
238
|
+
const TFHD_DEFAULT_DURATION = 8;
|
|
239
|
+
const TFHD_DEFAULT_SIZE = 16;
|
|
240
|
+
const TFHD_DEFAULT_FLAGS = 32;
|
|
241
|
+
const TFHD_DEFAULT_BASE_IS_MOOF = 131072;
|
|
242
|
+
const TRUN_DATA_OFFSET = 1;
|
|
243
|
+
const TRUN_FIRST_SAMPLE_FLAGS = 4;
|
|
244
|
+
const TRUN_DURATION = 256;
|
|
245
|
+
const TRUN_SIZE = 512;
|
|
246
|
+
const TRUN_FLAGS = 1024;
|
|
247
|
+
const TRUN_CTS = 2048;
|
|
248
|
+
/** The trex defaults of an init segment, by track ID. ISO/IEC 14496-12 §8.8.3. */
|
|
249
|
+
function trexDefaults(init) {
|
|
250
|
+
const out = /* @__PURE__ */ new Map();
|
|
251
|
+
const mvex = findBox(init, "moov/mvex");
|
|
252
|
+
for (const trex of mvex === null ? [] : findBoxes(mvex.payload, "trex")) {
|
|
253
|
+
var _fullBox;
|
|
254
|
+
const body = (_fullBox = fullBox(trex.payload)) === null || _fullBox === void 0 ? void 0 : _fullBox.body;
|
|
255
|
+
if (body === void 0 || body.byteLength < 20) continue;
|
|
256
|
+
const v = viewOf(body);
|
|
257
|
+
out.set(v.getUint32(0), {
|
|
258
|
+
duration: v.getUint32(8),
|
|
259
|
+
size: v.getUint32(12),
|
|
260
|
+
flags: v.getUint32(16)
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Every track fragment of a media segment with its samples located. Offsets
|
|
267
|
+
* follow the tfhd base rules: the moof with default-base-is-moof, an
|
|
268
|
+
* explicit base offset, else the end of the previous traf's data. Decode
|
|
269
|
+
* times continue across trafs of one track without a tfdt. A sample may
|
|
270
|
+
* point past the end of `data`; callers check `offset + size`.
|
|
271
|
+
*/
|
|
272
|
+
function fragmentSamples(data, defaults = /* @__PURE__ */ new Map()) {
|
|
273
|
+
const out = [];
|
|
274
|
+
const nextDecode = /* @__PURE__ */ new Map();
|
|
275
|
+
for (const moof of findBoxes(data, "moof")) {
|
|
276
|
+
let previousEnd = moof.start;
|
|
277
|
+
for (const traf of findBoxes(moof.payload, "traf")) {
|
|
278
|
+
var _fallback$duration, _fallback$size, _fallback$flags, _parseTfdt$baseMediaD, _parseTfdt, _ref;
|
|
279
|
+
const tfhdBox = findBox(traf.payload, "tfhd");
|
|
280
|
+
const tfhd = tfhdBox === null ? null : fullBox(tfhdBox.payload);
|
|
281
|
+
if (tfhd === null || tfhd.body.byteLength < 4) continue;
|
|
282
|
+
const tfhdView = viewOf(tfhd.body);
|
|
283
|
+
const trackId = tfhdView.getUint32(0);
|
|
284
|
+
const fallback = defaults.get(trackId);
|
|
285
|
+
let at = 4;
|
|
286
|
+
let base = tfhd.flags & TFHD_DEFAULT_BASE_IS_MOOF ? moof.start : previousEnd;
|
|
287
|
+
if (tfhd.flags & TFHD_BASE_DATA_OFFSET) {
|
|
288
|
+
base = Number(tfhdView.getBigUint64(at));
|
|
289
|
+
at += 8;
|
|
290
|
+
}
|
|
291
|
+
if (tfhd.flags & TFHD_SAMPLE_DESCRIPTION) at += 4;
|
|
292
|
+
let defaultDuration = (_fallback$duration = fallback === null || fallback === void 0 ? void 0 : fallback.duration) !== null && _fallback$duration !== void 0 ? _fallback$duration : 0;
|
|
293
|
+
let defaultSize = (_fallback$size = fallback === null || fallback === void 0 ? void 0 : fallback.size) !== null && _fallback$size !== void 0 ? _fallback$size : 0;
|
|
294
|
+
let defaultFlags = (_fallback$flags = fallback === null || fallback === void 0 ? void 0 : fallback.flags) !== null && _fallback$flags !== void 0 ? _fallback$flags : 0;
|
|
295
|
+
if (tfhd.flags & TFHD_DEFAULT_DURATION) {
|
|
296
|
+
defaultDuration = tfhdView.getUint32(at);
|
|
297
|
+
at += 4;
|
|
298
|
+
}
|
|
299
|
+
if (tfhd.flags & TFHD_DEFAULT_SIZE) {
|
|
300
|
+
defaultSize = tfhdView.getUint32(at);
|
|
301
|
+
at += 4;
|
|
302
|
+
}
|
|
303
|
+
if (tfhd.flags & TFHD_DEFAULT_FLAGS) defaultFlags = tfhdView.getUint32(at);
|
|
304
|
+
const tfdt = findBox(traf.payload, "tfdt");
|
|
305
|
+
const tfdtTime = tfdt === null ? null : (_parseTfdt$baseMediaD = (_parseTfdt = parseTfdt(tfdt.payload)) === null || _parseTfdt === void 0 ? void 0 : _parseTfdt.baseMediaDecodeTime) !== null && _parseTfdt$baseMediaD !== void 0 ? _parseTfdt$baseMediaD : null;
|
|
306
|
+
let decode = (_ref = tfdtTime !== null && tfdtTime !== void 0 ? tfdtTime : nextDecode.get(trackId)) !== null && _ref !== void 0 ? _ref : 0;
|
|
307
|
+
const samples = [];
|
|
308
|
+
let cursor = base;
|
|
309
|
+
for (const trunBox of findBoxes(traf.payload, "trun")) {
|
|
310
|
+
const trun = fullBox(trunBox.payload);
|
|
311
|
+
if (trun === null || trun.body.byteLength < 4) continue;
|
|
312
|
+
const trunView = viewOf(trun.body);
|
|
313
|
+
const count = trunView.getUint32(0);
|
|
314
|
+
let p = 4;
|
|
315
|
+
if (trun.flags & TRUN_DATA_OFFSET) {
|
|
316
|
+
cursor = base + trunView.getInt32(p);
|
|
317
|
+
p += 4;
|
|
318
|
+
}
|
|
319
|
+
let firstFlags = null;
|
|
320
|
+
if (trun.flags & TRUN_FIRST_SAMPLE_FLAGS) {
|
|
321
|
+
firstFlags = trunView.getUint32(p);
|
|
322
|
+
p += 4;
|
|
323
|
+
}
|
|
324
|
+
const entry = 4 * [
|
|
325
|
+
TRUN_DURATION,
|
|
326
|
+
TRUN_SIZE,
|
|
327
|
+
TRUN_FLAGS,
|
|
328
|
+
TRUN_CTS
|
|
329
|
+
].filter((f) => trun.flags & f).length;
|
|
330
|
+
for (let i = 0; i < count && p + entry <= trun.body.byteLength; i += 1) {
|
|
331
|
+
let duration = defaultDuration;
|
|
332
|
+
let size = defaultSize;
|
|
333
|
+
let flags = i === 0 && firstFlags !== null ? firstFlags : defaultFlags;
|
|
334
|
+
let cts = 0;
|
|
335
|
+
if (trun.flags & TRUN_DURATION) {
|
|
336
|
+
duration = trunView.getUint32(p);
|
|
337
|
+
p += 4;
|
|
338
|
+
}
|
|
339
|
+
if (trun.flags & TRUN_SIZE) {
|
|
340
|
+
size = trunView.getUint32(p);
|
|
341
|
+
p += 4;
|
|
342
|
+
}
|
|
343
|
+
if (trun.flags & TRUN_FLAGS) {
|
|
344
|
+
flags = trunView.getUint32(p);
|
|
345
|
+
p += 4;
|
|
346
|
+
}
|
|
347
|
+
if (trun.flags & TRUN_CTS) {
|
|
348
|
+
cts = trun.version === 1 ? trunView.getInt32(p) : trunView.getUint32(p);
|
|
349
|
+
p += 4;
|
|
350
|
+
}
|
|
351
|
+
samples.push({
|
|
352
|
+
offset: cursor,
|
|
353
|
+
size,
|
|
354
|
+
duration,
|
|
355
|
+
cts,
|
|
356
|
+
decodeTime: decode,
|
|
357
|
+
isKeyframe: (flags & 65536) === 0
|
|
358
|
+
});
|
|
359
|
+
cursor += size;
|
|
360
|
+
decode += duration;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
previousEnd = cursor;
|
|
364
|
+
nextDecode.set(trackId, decode);
|
|
365
|
+
out.push({
|
|
366
|
+
trackId,
|
|
367
|
+
baseMediaDecodeTime: tfdtTime,
|
|
368
|
+
samples
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return out;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* The first video track's decoder configuration box, or null for another
|
|
376
|
+
* codec or a protected (encv) entry. ISO/IEC 14496-15 §5.3.3 (avcC) and
|
|
377
|
+
* §8.3.3 (hvcC).
|
|
378
|
+
*/
|
|
379
|
+
function decoderConfigBox(init) {
|
|
380
|
+
for (const stsd of findBoxes(init, "moov/trak/mdia/minf/stbl/stsd")) {
|
|
381
|
+
const entry = sampleEntries(stsd.payload)[0];
|
|
382
|
+
if (entry === void 0 || entry.body.byteLength < 78) continue;
|
|
383
|
+
const hevc = entry.format === "hvc1" || entry.format === "hev1";
|
|
384
|
+
if (!hevc && entry.format !== "avc1" && entry.format !== "avc3") continue;
|
|
385
|
+
const config = findBox(entry.body.subarray(78), hevc ? "hvcC" : "avcC");
|
|
386
|
+
if (config !== null) return {
|
|
387
|
+
format: entry.format,
|
|
388
|
+
description: config.payload
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
205
393
|
//#endregion
|
|
206
|
-
export { earliestDecodeTime, findBox, findBoxes, fullBox, parseSidx, parseTfdt, trackTimescales, walkBoxes };
|
|
394
|
+
export { VISUAL_ENTRY_HEADER, decoderConfigBox, earliestDecodeTime, findBox, findBoxes, fourcc, fragmentSamples, fullBox, parseSidx, parseTfdt, sampleEntries, trackInfo, trackTimescales, trexDefaults, viewOf, walkBoxes };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { concat, sequenceNumberFor, writeInitSegment, writeMediaSegment } from "../fmp4/writer.js";
|
|
1
2
|
import { id3TagLength } from "../id3.js";
|
|
2
|
-
import {
|
|
3
|
-
import { writeInitSegment, writeMediaSegment } from "../fmp4/writer.js";
|
|
3
|
+
import { adtsFragment, parseAdts } from "../adts.js";
|
|
4
4
|
//#region src/containers/packed-audio/index.ts
|
|
5
5
|
const AUDIO_TRACK_ID = 1;
|
|
6
6
|
const PACK_ORDER = 100;
|
|
@@ -14,32 +14,8 @@ function packAudio(data, presentationStart) {
|
|
|
14
14
|
const offset = id3TagLength(data, 0);
|
|
15
15
|
const adts = parseAdts(data.subarray(offset));
|
|
16
16
|
if (adts.frames.length === 0) return null;
|
|
17
|
-
const config =
|
|
18
|
-
|
|
19
|
-
kind: "audio",
|
|
20
|
-
timescale: adts.sampleRate,
|
|
21
|
-
audioObjectType: adts.audioObjectType,
|
|
22
|
-
samplingFrequencyIndex: adts.samplingFrequencyIndex,
|
|
23
|
-
channelConfig: adts.channelConfig
|
|
24
|
-
};
|
|
25
|
-
const samples = adts.frames.map((frame) => ({
|
|
26
|
-
data: frame.data,
|
|
27
|
-
duration: SAMPLES_PER_FRAME,
|
|
28
|
-
cts: 0,
|
|
29
|
-
isKeyframe: true
|
|
30
|
-
}));
|
|
31
|
-
const base = Math.round(presentationStart * adts.sampleRate);
|
|
32
|
-
const sequenceNumber = Math.max(1, Math.round(presentationStart) + 1);
|
|
33
|
-
const init = writeInitSegment([config]);
|
|
34
|
-
const media = writeMediaSegment(sequenceNumber, [{
|
|
35
|
-
trackId: AUDIO_TRACK_ID,
|
|
36
|
-
baseMediaDecodeTime: base,
|
|
37
|
-
samples
|
|
38
|
-
}]);
|
|
39
|
-
const out = new Uint8Array(init.byteLength + media.byteLength);
|
|
40
|
-
out.set(init, 0);
|
|
41
|
-
out.set(media, init.byteLength);
|
|
42
|
-
return out;
|
|
17
|
+
const { config, fragment } = adtsFragment(adts, AUDIO_TRACK_ID, presentationStart);
|
|
18
|
+
return concat(writeInitSegment([config]), writeMediaSegment(sequenceNumberFor(presentationStart), [fragment]));
|
|
43
19
|
}
|
|
44
20
|
function packedAudio() {
|
|
45
21
|
return {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
//#region src/containers/sei.ts
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Strips emulation-prevention bytes (00 00 03 -> 00 00) from a NAL unit
|
|
4
|
+
* past its `start`-byte header, so payload sizes and bit reads come out true.
|
|
5
|
+
*/
|
|
6
|
+
function toRbsp(nal, start = 1) {
|
|
4
7
|
const out = new Uint8Array(nal.byteLength - start);
|
|
5
8
|
let count = 0;
|
|
6
9
|
let zeros = 0;
|
|
@@ -78,4 +81,4 @@ function appendAtscCc(payload, out) {
|
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
//#endregion
|
|
81
|
-
export { ccTriplesFromSei };
|
|
84
|
+
export { ccTriplesFromSei, toRbsp };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { concat } from "../fmp4/writer.js";
|
|
1
2
|
//#region src/containers/ts-transmux/demux.ts
|
|
3
|
+
/** MPEG-TS stream_type values this transmuxer routes. */
|
|
2
4
|
/**
|
|
3
5
|
* MPEG-TS demux: 188-byte packets into PES payloads, grouped by elementary
|
|
4
6
|
* stream. PAT names the PMT, the PMT names the elementary PIDs and their
|
|
@@ -9,7 +11,6 @@
|
|
|
9
11
|
*/
|
|
10
12
|
const PACKET_SIZE = 188;
|
|
11
13
|
const SYNC_BYTE = 71;
|
|
12
|
-
/** MPEG-TS stream_type values this transmuxer routes. */
|
|
13
14
|
const STREAM_TYPE = {
|
|
14
15
|
h264: 27,
|
|
15
16
|
aacAdts: 15,
|
|
@@ -52,7 +53,7 @@ function readTimestamp(data, offset) {
|
|
|
52
53
|
/** Parses one completed PES accumulator into a packet with timestamps. */
|
|
53
54
|
function finishPes(acc) {
|
|
54
55
|
var _buf$, _buf$2;
|
|
55
|
-
const buf =
|
|
56
|
+
const buf = acc.chunks.length === 1 ? acc.chunks[0] : concat(...acc.chunks);
|
|
56
57
|
if (buf.byteLength < 9 || buf[0] !== 0 || buf[1] !== 0 || buf[2] !== 1) return null;
|
|
57
58
|
const headerDataLength = (_buf$ = buf[8]) !== null && _buf$ !== void 0 ? _buf$ : 0;
|
|
58
59
|
const ptsDtsFlags = ((_buf$2 = buf[7]) !== null && _buf$2 !== void 0 ? _buf$2 : 0) >> 6;
|
|
@@ -74,15 +75,38 @@ function finishPes(acc) {
|
|
|
74
75
|
data
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
/**
|
|
79
|
+
* The PMT PID a PAT packet's payload names: pointer_field, then the
|
|
80
|
+
* section, where the first program's PMT PID sits in the last two bytes of
|
|
81
|
+
* the first program entry. ISO/IEC 13818-1 §2.4.4.3.
|
|
82
|
+
*/
|
|
83
|
+
function pmtPidOf(payload) {
|
|
84
|
+
var _payload$, _section$, _section$2;
|
|
85
|
+
const pointer = (_payload$ = payload[0]) !== null && _payload$ !== void 0 ? _payload$ : 0;
|
|
86
|
+
const section = payload.subarray(1 + pointer);
|
|
87
|
+
if (section.byteLength < 13) return null;
|
|
88
|
+
return (((_section$ = section[10]) !== null && _section$ !== void 0 ? _section$ : 0) & 31) << 8 | ((_section$2 = section[11]) !== null && _section$2 !== void 0 ? _section$2 : 0);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The PAT and PMT packets at the start of a transport stream, joined, or
|
|
92
|
+
* null when either is missing. An HLS I-frame byte range starts at the
|
|
93
|
+
* frame, past these tables, so a reader takes them from the start of the
|
|
94
|
+
* same file and puts them in front.
|
|
95
|
+
*/
|
|
96
|
+
function programTables(data) {
|
|
97
|
+
let pat = null;
|
|
98
|
+
let pmtPid = null;
|
|
99
|
+
for (let offset = 0; offset + PACKET_SIZE <= data.byteLength; offset += PACKET_SIZE) {
|
|
100
|
+
var _data5, _data6;
|
|
101
|
+
if (data[offset] !== SYNC_BYTE) return null;
|
|
102
|
+
const pid = (((_data5 = data[offset + 1]) !== null && _data5 !== void 0 ? _data5 : 0) & 31) << 8 | ((_data6 = data[offset + 2]) !== null && _data6 !== void 0 ? _data6 : 0);
|
|
103
|
+
const packet = data.subarray(offset, offset + PACKET_SIZE);
|
|
104
|
+
if (pid === 0 && pat === null) {
|
|
105
|
+
pat = packet;
|
|
106
|
+
pmtPid = pmtPidOf(packet.subarray(4));
|
|
107
|
+
} else if (pat !== null && pid === pmtPid) return concat(pat, packet);
|
|
84
108
|
}
|
|
85
|
-
return
|
|
109
|
+
return null;
|
|
86
110
|
}
|
|
87
111
|
function demux(data) {
|
|
88
112
|
if (!looksLikeTransportStream(data)) return {
|
|
@@ -105,16 +129,16 @@ function demux(data) {
|
|
|
105
129
|
accumulators.delete(pid);
|
|
106
130
|
}
|
|
107
131
|
for (let offset = base; offset + PACKET_SIZE <= data.byteLength; offset += PACKET_SIZE) {
|
|
108
|
-
var
|
|
132
|
+
var _data7, _data8, _data9;
|
|
109
133
|
if (data[offset] !== SYNC_BYTE) {
|
|
110
134
|
let resync = offset + 1;
|
|
111
135
|
while (resync < data.byteLength && data[resync] !== SYNC_BYTE) resync += 1;
|
|
112
136
|
offset = resync - PACKET_SIZE;
|
|
113
137
|
continue;
|
|
114
138
|
}
|
|
115
|
-
const b1 = (
|
|
116
|
-
const b2 = (
|
|
117
|
-
const b3 = (
|
|
139
|
+
const b1 = (_data7 = data[offset + 1]) !== null && _data7 !== void 0 ? _data7 : 0;
|
|
140
|
+
const b2 = (_data8 = data[offset + 2]) !== null && _data8 !== void 0 ? _data8 : 0;
|
|
141
|
+
const b3 = (_data9 = data[offset + 3]) !== null && _data9 !== void 0 ? _data9 : 0;
|
|
118
142
|
const pusi = (b1 & 64) !== 0;
|
|
119
143
|
const pid = (b1 & 31) << 8 | b2;
|
|
120
144
|
const adaptationControl = b3 >> 4 & 3;
|
|
@@ -128,13 +152,8 @@ function demux(data) {
|
|
|
128
152
|
if (payloadOffset >= offset + PACKET_SIZE) continue;
|
|
129
153
|
const payload = data.subarray(payloadOffset, offset + PACKET_SIZE);
|
|
130
154
|
if (pid === 0) {
|
|
131
|
-
var
|
|
132
|
-
|
|
133
|
-
const section = payload.subarray(1 + pointer);
|
|
134
|
-
if (section.byteLength >= 13) {
|
|
135
|
-
var _section$, _section$2;
|
|
136
|
-
pmtPid = (((_section$ = section[10]) !== null && _section$ !== void 0 ? _section$ : 0) & 31) << 8 | ((_section$2 = section[11]) !== null && _section$2 !== void 0 ? _section$2 : 0);
|
|
137
|
-
}
|
|
155
|
+
var _pmtPidOf;
|
|
156
|
+
pmtPid = (_pmtPidOf = pmtPidOf(payload)) !== null && _pmtPidOf !== void 0 ? _pmtPidOf : pmtPid;
|
|
138
157
|
continue;
|
|
139
158
|
}
|
|
140
159
|
if (pid === pmtPid && pusi) {
|
|
@@ -208,4 +227,4 @@ function unrollTimestamps(values) {
|
|
|
208
227
|
return out;
|
|
209
228
|
}
|
|
210
229
|
//#endregion
|
|
211
|
-
export { STREAM_TYPE, demux, looksLikeTransportStream, unrollTimestamps };
|
|
230
|
+
export { STREAM_TYPE, demux, looksLikeTransportStream, programTables, unrollTimestamps };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/defineProperty.js";
|
|
2
|
+
import { toRbsp } from "../sei.js";
|
|
2
3
|
//#region src/containers/ts-transmux/h264.ts
|
|
3
4
|
/**
|
|
4
5
|
* H.264 Annex B to AVCC. The elementary stream separates NAL units with
|
|
@@ -83,23 +84,6 @@ function accessUnitFromNals(nals) {
|
|
|
83
84
|
sei
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
|
-
/** Strips H.264 emulation-prevention bytes (00 00 03 -> 00 00) for RBSP reads. */
|
|
87
|
-
function toRbsp(nal) {
|
|
88
|
-
const out = new Uint8Array(nal.byteLength);
|
|
89
|
-
let count = 0;
|
|
90
|
-
let zeros = 0;
|
|
91
|
-
for (let i = 1; i < nal.byteLength; i += 1) {
|
|
92
|
-
const byte = nal[i];
|
|
93
|
-
if (zeros >= 2 && byte === 3) {
|
|
94
|
-
zeros = 0;
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
out[count] = byte;
|
|
98
|
-
count += 1;
|
|
99
|
-
zeros = byte === 0 ? zeros + 1 : 0;
|
|
100
|
-
}
|
|
101
|
-
return out.subarray(0, count);
|
|
102
|
-
}
|
|
103
87
|
var BitReader = class {
|
|
104
88
|
constructor(data) {
|
|
105
89
|
this.data = data;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/asyncToGenerator.js";
|
|
2
|
-
import { captionsWanted, deliverCaptions } from "../captions.js";
|
|
3
2
|
import { looksLikeTransportStream } from "./demux.js";
|
|
3
|
+
import { captionsWanted, deliverCaptions } from "../captions.js";
|
|
4
4
|
import { createTransmuxRunner } from "./runner.js";
|
|
5
5
|
//#region src/containers/ts-transmux/index.ts
|
|
6
6
|
/** Runs after decrypt-class steps (lower order) and before caption extraction. */
|
|
@@ -30,7 +30,6 @@ function tsTransmux(options = {}) {
|
|
|
30
30
|
order: TRANSMUX_ORDER,
|
|
31
31
|
transform(data, meta) {
|
|
32
32
|
return _asyncToGenerator(function* () {
|
|
33
|
-
var _result$bytes;
|
|
34
33
|
if (meta.contentType !== "video" && meta.contentType !== "audio") return data;
|
|
35
34
|
if (!looksLikeTransportStream(data)) return data;
|
|
36
35
|
const result = yield runner.run(data, meta.start, captionsWanted(), tracksFor(ctx, meta));
|
|
@@ -42,7 +41,11 @@ function tsTransmux(options = {}) {
|
|
|
42
41
|
renditionId: meta.renditionId
|
|
43
42
|
});
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
if (result.bytes === null) {
|
|
45
|
+
if (result.empty) throw new RangeError("transport stream segment holds no media");
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
return result.bytes;
|
|
46
49
|
})();
|
|
47
50
|
}
|
|
48
51
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { parseAdts } from "../adts.js";
|
|
3
|
-
import { writeInitSegment, writeMediaSegment } from "../fmp4/writer.js";
|
|
1
|
+
import { concat, sequenceNumberFor, writeInitSegment, writeMediaSegment } from "../fmp4/writer.js";
|
|
4
2
|
import { demux, unrollTimestamps } from "./demux.js";
|
|
3
|
+
import { ccTriplesFromSei } from "../sei.js";
|
|
4
|
+
import { adtsFragment, parseAdts } from "../adts.js";
|
|
5
5
|
import { NAL_TYPE, accessUnitFromNals, nalType, splitNalUnits, spsDimensions, toAccessUnit } from "./h264.js";
|
|
6
6
|
//#region src/containers/ts-transmux/transmux.ts
|
|
7
7
|
/**
|
|
@@ -21,17 +21,6 @@ const VIDEO_TRACK_ID = 1;
|
|
|
21
21
|
const AUDIO_TRACK_ID = 2;
|
|
22
22
|
/** Fallback duration for a lone trailing video sample: 30 fps in 90 kHz. */
|
|
23
23
|
const DEFAULT_FRAME_DURATION = 3e3;
|
|
24
|
-
function concat(parts) {
|
|
25
|
-
let length = 0;
|
|
26
|
-
for (const part of parts) length += part.byteLength;
|
|
27
|
-
const out = new Uint8Array(length);
|
|
28
|
-
let offset = 0;
|
|
29
|
-
for (const part of parts) {
|
|
30
|
-
out.set(part, offset);
|
|
31
|
-
offset += part.byteLength;
|
|
32
|
-
}
|
|
33
|
-
return out;
|
|
34
|
-
}
|
|
35
24
|
/**
|
|
36
25
|
* Reframes video access units. Access units do not align with PES packet
|
|
37
26
|
* boundaries in the wild: a picture's tail spills into the next PES packet,
|
|
@@ -146,30 +135,9 @@ function buildVideo(packets, presentationStart, wantCaptions) {
|
|
|
146
135
|
}
|
|
147
136
|
function buildAudio(packets, presentationStart) {
|
|
148
137
|
if (packets.length === 0) return null;
|
|
149
|
-
const adts = parseAdts(concat(packets.map((p) => p.data)));
|
|
138
|
+
const adts = parseAdts(concat(...packets.map((p) => p.data)));
|
|
150
139
|
if (adts.frames.length === 0) return null;
|
|
151
|
-
|
|
152
|
-
const samples = adts.frames.map((frame) => ({
|
|
153
|
-
data: frame.data,
|
|
154
|
-
duration: 1024,
|
|
155
|
-
cts: 0,
|
|
156
|
-
isKeyframe: true
|
|
157
|
-
}));
|
|
158
|
-
return {
|
|
159
|
-
config: {
|
|
160
|
-
id: AUDIO_TRACK_ID,
|
|
161
|
-
kind: "audio",
|
|
162
|
-
timescale: adts.sampleRate,
|
|
163
|
-
audioObjectType: adts.audioObjectType,
|
|
164
|
-
samplingFrequencyIndex: adts.samplingFrequencyIndex,
|
|
165
|
-
channelConfig: adts.channelConfig
|
|
166
|
-
},
|
|
167
|
-
fragment: {
|
|
168
|
-
trackId: AUDIO_TRACK_ID,
|
|
169
|
-
baseMediaDecodeTime: base,
|
|
170
|
-
samples
|
|
171
|
-
}
|
|
172
|
-
};
|
|
140
|
+
return adtsFragment(adts, AUDIO_TRACK_ID, presentationStart);
|
|
173
141
|
}
|
|
174
142
|
function transmux(input, presentationStart = 0, wantCaptions = false, tracks = "all") {
|
|
175
143
|
var _video$captions;
|
|
@@ -201,9 +169,10 @@ function transmux(input, presentationStart = 0, wantCaptions = false, tracks = "
|
|
|
201
169
|
configs.push(audio.config);
|
|
202
170
|
fragments.push(audio.fragment);
|
|
203
171
|
}
|
|
204
|
-
const
|
|
172
|
+
const init = writeInitSegment(configs);
|
|
173
|
+
const media = writeMediaSegment(sequenceNumberFor(presentationStart), fragments);
|
|
205
174
|
return {
|
|
206
|
-
bytes: concat(
|
|
175
|
+
bytes: concat(init, media),
|
|
207
176
|
notTransportStream: false,
|
|
208
177
|
empty: false,
|
|
209
178
|
captions: (_video$captions = video === null || video === void 0 ? void 0 : video.captions) !== null && _video$captions !== void 0 ? _video$captions : [],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _objectSpread2 from "
|
|
2
|
-
//#region src/
|
|
1
|
+
import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
|
|
2
|
+
//#region src/containers/webvtt.ts
|
|
3
3
|
/** `HH:MM:SS.mmm` or `MM:SS.mmm` to seconds, or null. */
|
|
4
4
|
function parseTimestamp(text) {
|
|
5
5
|
const match = /^(?:(\d+):)?([0-5]\d):([0-5]\d)\.(\d{3})$/.exec(text.trim());
|
package/dist/es2015/index.js
CHANGED
|
@@ -3,7 +3,8 @@ import { exportTrace, replay } from "./kernel/trace.js";
|
|
|
3
3
|
import { createBus } from "./kernel/bus.js";
|
|
4
4
|
import { createEffectRunner } from "./kernel/effects.js";
|
|
5
5
|
import { normalizeMimeType } from "./kernel/mime.js";
|
|
6
|
-
import {
|
|
6
|
+
import { findTrackSite, isTrick } from "./kernel/presentation.js";
|
|
7
|
+
import { availableGroups, canSwitchTo, createArbiter } from "./kernel/rendition-select.js";
|
|
7
8
|
import { createMseSink } from "./kernel/sinks/mse-sink.js";
|
|
8
9
|
import { createReducer, initialState, resolveConfig } from "./kernel/reducer.js";
|
|
9
10
|
import { createLifecycle } from "./kernel/lifecycle.js";
|
|
@@ -91,9 +92,8 @@ function mattebox(options) {
|
|
|
91
92
|
return sink;
|
|
92
93
|
}
|
|
93
94
|
function contentTypeOfTrack(trackId) {
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
return null;
|
|
95
|
+
var _findTrackSite$track$, _findTrackSite;
|
|
96
|
+
return (_findTrackSite$track$ = (_findTrackSite = findTrackSite(bus.getState().presentation, trackId)) === null || _findTrackSite === void 0 ? void 0 : _findTrackSite.track.contentType) !== null && _findTrackSite$track$ !== void 0 ? _findTrackSite$track$ : null;
|
|
97
97
|
}
|
|
98
98
|
runner.register("emitCues", (effect) => {
|
|
99
99
|
var _cueSinkFor;
|
|
@@ -151,7 +151,7 @@ function mattebox(options) {
|
|
|
151
151
|
if (state.presentation === null) return [];
|
|
152
152
|
const activeId = state.tracks.active.get("video");
|
|
153
153
|
for (const period of state.presentation.periods) for (const track of period.tracks) {
|
|
154
|
-
if (track.contentType !== "video") continue;
|
|
154
|
+
if (track.contentType !== "video" || isTrick(track)) continue;
|
|
155
155
|
if (activeId === void 0 || track.id === activeId) return track.renditions;
|
|
156
156
|
}
|
|
157
157
|
return [];
|
|
@@ -166,16 +166,7 @@ function mattebox(options) {
|
|
|
166
166
|
current: state.quality.active,
|
|
167
167
|
couplings: (_state$presentation$c = (_state$presentation = state.presentation) === null || _state$presentation === void 0 ? void 0 : _state$presentation.couplings) !== null && _state$presentation$c !== void 0 ? _state$presentation$c : [],
|
|
168
168
|
activeTracks: state.tracks.active,
|
|
169
|
-
availableGroups: (
|
|
170
|
-
var _state$presentation$p, _state$presentation2;
|
|
171
|
-
const groups = /* @__PURE__ */ new Set();
|
|
172
|
-
for (const period of (_state$presentation$p = (_state$presentation2 = state.presentation) === null || _state$presentation2 === void 0 ? void 0 : _state$presentation2.periods) !== null && _state$presentation$p !== void 0 ? _state$presentation$p : []) for (const track of period.tracks) {
|
|
173
|
-
if (track.contentType !== "audio" && track.contentType !== "text") continue;
|
|
174
|
-
const colon = track.id.indexOf(":");
|
|
175
|
-
groups.add(`${track.contentType}:${colon === -1 ? track.id : track.id.slice(0, colon)}`);
|
|
176
|
-
}
|
|
177
|
-
return groups;
|
|
178
|
-
})(),
|
|
169
|
+
availableGroups: availableGroups(state),
|
|
179
170
|
telemetry: {
|
|
180
171
|
throughputEwma: state.stats.throughputEwma,
|
|
181
172
|
throughputFastEwma: state.stats.throughputFastEwma,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/kernel/base64.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base64 (RFC 4648 §4) and base64url (§5) over bytes, for manifest pssh
|
|
4
|
+
* boxes and license bodies. One copy for the manifest parsers and the DRM stages.
|
|
5
|
+
*/
|
|
6
|
+
/** Base64 text into bytes, whitespace ignored; null when it is not base64. */
|
|
7
|
+
function base64ToBytes(text) {
|
|
8
|
+
try {
|
|
9
|
+
const binary = atob(text.replace(/\s+/g, ""));
|
|
10
|
+
const bytes = new Uint8Array(binary.length);
|
|
11
|
+
for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
|
|
12
|
+
return bytes;
|
|
13
|
+
} catch (_unused) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Bytes into base64, or into unpadded base64url when `url` is set. */
|
|
18
|
+
function bytesToBase64(bytes, url = false) {
|
|
19
|
+
let binary = "";
|
|
20
|
+
for (const b of bytes) binary += String.fromCharCode(b);
|
|
21
|
+
const text = btoa(binary);
|
|
22
|
+
return url ? text.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "") : text;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { base64ToBytes, bytesToBase64 };
|