mattebox 0.2.2 → 0.4.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/README.md +15 -2
- package/dist/cdn/mattebox.dash-drm.min.js +3 -2
- package/dist/cdn/mattebox.dash.min.js +3 -2
- package/dist/cdn/mattebox.dual-drm.min.js +3 -2
- 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 -2
- package/dist/cdn/mattebox.hls-drm.min.js +3 -2
- 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 -2
- package/dist/cdn/mattebox.kernel.min.js +1 -1
- package/dist/cdn/mattebox.min.js +4 -4
- package/dist/containers/sei.d.ts +3 -2
- package/dist/containers/sei.d.ts.map +1 -1
- package/dist/containers/sei.js +7 -4
- package/dist/containers/sei.js.map +1 -1
- package/dist/es2015/containers/sei.js +5 -3
- package/dist/es2015/index.js +1 -1
- package/dist/es2015/kernel/bus.js +8 -6
- package/dist/es2015/kernel/reducer.js +42 -19
- package/dist/es2015/kernel/rendition-select.js +9 -8
- package/dist/es2015/kernel/trace.js +31 -3
- package/dist/es2015/presets/full/index.js +4 -9
- package/dist/es2015/presets/tiers.js +18 -11
- package/dist/es2015/protocols/dash-cmaf/index.js +1 -1
- package/dist/es2015/protocols/hls-cmaf/index.js +1 -1
- package/dist/es2015/stages/alt-audio/index.js +2 -1
- package/dist/es2015/stages/codec-switch/index.js +7 -8
- package/dist/es2015/stages/eme-core/index.js +1 -1
- package/dist/es2015/stages/nal-scan/index.js +197 -92
- package/dist/es2015/stages/text-cea608/index.js +1 -1
- package/dist/kernel/bus.d.ts.map +1 -1
- package/dist/kernel/bus.js +11 -2
- package/dist/kernel/bus.js.map +1 -1
- package/dist/kernel/reducer.d.ts.map +1 -1
- package/dist/kernel/reducer.js +62 -26
- package/dist/kernel/reducer.js.map +1 -1
- package/dist/kernel/rendition-select.d.ts +5 -6
- package/dist/kernel/rendition-select.d.ts.map +1 -1
- package/dist/kernel/rendition-select.js +17 -10
- package/dist/kernel/rendition-select.js.map +1 -1
- package/dist/kernel/trace.d.ts +17 -2
- package/dist/kernel/trace.d.ts.map +1 -1
- package/dist/kernel/trace.js +33 -2
- package/dist/kernel/trace.js.map +1 -1
- package/dist/presets/full/index.d.ts.map +1 -1
- package/dist/presets/full/index.js +4 -9
- package/dist/presets/full/index.js.map +1 -1
- package/dist/presets/tiers.d.ts +10 -7
- package/dist/presets/tiers.d.ts.map +1 -1
- package/dist/presets/tiers.js +19 -9
- package/dist/presets/tiers.js.map +1 -1
- package/dist/stages/alt-audio/index.d.ts.map +1 -1
- package/dist/stages/alt-audio/index.js +3 -1
- package/dist/stages/alt-audio/index.js.map +1 -1
- package/dist/stages/codec-probe/index.d.ts +5 -0
- package/dist/stages/codec-probe/index.d.ts.map +1 -1
- package/dist/stages/codec-probe/index.js.map +1 -1
- package/dist/stages/codec-switch/index.d.ts.map +1 -1
- package/dist/stages/codec-switch/index.js +9 -10
- package/dist/stages/codec-switch/index.js.map +1 -1
- package/dist/stages/eme-core/index.d.ts.map +1 -1
- package/dist/stages/eme-core/index.js +4 -1
- package/dist/stages/eme-core/index.js.map +1 -1
- package/dist/stages/nal-scan/index.d.ts.map +1 -1
- package/dist/stages/nal-scan/index.js +225 -95
- package/dist/stages/nal-scan/index.js.map +1 -1
- package/dist/stages/text-cea608/index.d.ts.map +1 -1
- package/dist/stages/text-cea608/index.js +2 -1
- package/dist/stages/text-cea608/index.js.map +1 -1
- package/dist/types/facade.d.ts +5 -1
- package/dist/types/facade.d.ts.map +1 -1
- package/dist/types/kernel.d.ts +10 -2
- package/dist/types/kernel.d.ts.map +1 -1
- package/dist/types/messages.d.ts +8 -0
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/stage.d.ts +1 -1
- package/package.json +2 -3
|
@@ -1,78 +1,208 @@
|
|
|
1
1
|
import { captionsWanted, deliverCaptions } from "../../containers/captions.js";
|
|
2
|
-
import { findBox, parseTfdt } from "../../containers/mp4-box/index.js";
|
|
2
|
+
import { findBox, findBoxes, fullBox, parseTfdt } from "../../containers/mp4-box/index.js";
|
|
3
3
|
import { ccTriplesFromSei } from "../../containers/sei.js";
|
|
4
4
|
//#region src/stages/nal-scan/index.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* from the fragment's tfdt and trun, and delivers the caption bytes to the
|
|
10
|
-
* same seam ts-transmux uses. It imports mp4-box for the box reads and the
|
|
11
|
-
* shared SEI decoder; it never imports text-cea608.
|
|
12
|
-
*
|
|
13
|
-
* It is not cheap and does not pretend to be: per entanglement #1 it loads
|
|
14
|
-
* only when a caption stage needs an fMP4 SEI source, and it does zero work
|
|
15
|
-
* when no caption consumer is registered.
|
|
6
|
+
* After aes-128 decryption (1), before ts-transmux (100). An MPEG-TS segment
|
|
7
|
+
* has no moof at this point and is skipped, because the transmuxer delivers
|
|
8
|
+
* its own captions.
|
|
16
9
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
10
|
+
const SCAN_ORDER = 50;
|
|
11
|
+
/** SampleEntry (8 bytes) plus VisualSampleEntry (70 bytes). ISO/IEC 14496-12 §12.1.3. */
|
|
12
|
+
const VISUAL_ENTRY_HEADER = 78;
|
|
13
|
+
/** H.264 SEI. ITU-T H.264 Table 7-1. */
|
|
14
|
+
const AVC_SEI = 6;
|
|
15
|
+
/** HEVC prefix and suffix SEI. ITU-T H.265 Table 7-1. */
|
|
16
|
+
const HEVC_PREFIX_SEI = 39;
|
|
17
|
+
const HEVC_SUFFIX_SEI = 40;
|
|
18
|
+
const TFHD_BASE_DATA_OFFSET = 1;
|
|
19
|
+
const TFHD_SAMPLE_DESCRIPTION = 2;
|
|
20
|
+
const TFHD_DEFAULT_DURATION = 8;
|
|
21
|
+
const TFHD_DEFAULT_SIZE = 16;
|
|
22
|
+
const TFHD_DEFAULT_BASE_IS_MOOF = 131072;
|
|
23
|
+
const TRUN_DATA_OFFSET = 1;
|
|
24
|
+
const TRUN_FIRST_SAMPLE_FLAGS = 4;
|
|
25
|
+
const TRUN_DURATION = 256;
|
|
26
|
+
const TRUN_SIZE = 512;
|
|
27
|
+
const TRUN_FLAGS = 1024;
|
|
28
|
+
const TRUN_CTS = 2048;
|
|
29
|
+
function view(bytes) {
|
|
30
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
31
|
+
}
|
|
32
|
+
function fourcc(bytes, at) {
|
|
33
|
+
var _bytes$at, _bytes, _bytes2, _bytes3;
|
|
34
|
+
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);
|
|
35
|
+
}
|
|
36
|
+
/** The format and body of the first stsd sample entry. */
|
|
37
|
+
function sampleEntry(stsd) {
|
|
38
|
+
var _fullBox;
|
|
39
|
+
const body = (_fullBox = fullBox(stsd)) === null || _fullBox === void 0 ? void 0 : _fullBox.body;
|
|
40
|
+
if (body === void 0 || body.byteLength < 12) return null;
|
|
41
|
+
const size = view(body).getUint32(4);
|
|
42
|
+
if (size < 8 || 4 + size > body.byteLength) return null;
|
|
43
|
+
return {
|
|
44
|
+
format: fourcc(body, 8),
|
|
45
|
+
body: body.subarray(12, 4 + size)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** The H.264 and HEVC tracks of an init segment, by track ID. Other codecs carry no SEI. */
|
|
49
|
+
function videoTracks(init) {
|
|
50
|
+
const defaults = /* @__PURE__ */ new Map();
|
|
51
|
+
const mvex = findBox(init, "moov/mvex");
|
|
52
|
+
for (const trex of mvex === null ? [] : findBoxes(mvex.payload, "trex")) {
|
|
53
|
+
var _fullBox2;
|
|
54
|
+
const body = (_fullBox2 = fullBox(trex.payload)) === null || _fullBox2 === void 0 ? void 0 : _fullBox2.body;
|
|
55
|
+
if (body === void 0 || body.byteLength < 16) continue;
|
|
56
|
+
const v = view(body);
|
|
57
|
+
defaults.set(v.getUint32(0), {
|
|
58
|
+
duration: v.getUint32(8),
|
|
59
|
+
size: v.getUint32(12)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const tracks = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const trak of findBoxes(init, "moov/trak")) {
|
|
64
|
+
var _fallback$duration, _fallback$size;
|
|
65
|
+
const tkhd = findBox(trak.payload, "tkhd");
|
|
66
|
+
const mdhd = findBox(trak.payload, "mdia/mdhd");
|
|
67
|
+
const stsd = findBox(trak.payload, "mdia/minf/stbl/stsd");
|
|
68
|
+
const entry = stsd === null ? null : sampleEntry(stsd.payload);
|
|
69
|
+
if (tkhd === null || mdhd === null || entry === null) continue;
|
|
70
|
+
if (entry.body.byteLength < VISUAL_ENTRY_HEADER) continue;
|
|
71
|
+
const children = entry.body.subarray(VISUAL_ENTRY_HEADER);
|
|
72
|
+
let format = entry.format;
|
|
73
|
+
if (format === "encv") {
|
|
74
|
+
const sinf = findBox(children, "sinf");
|
|
75
|
+
const frma = sinf === null ? null : findBox(sinf.payload, "frma");
|
|
76
|
+
if (frma === null || frma.payload.byteLength < 4) continue;
|
|
77
|
+
format = fourcc(frma.payload, 0);
|
|
44
78
|
}
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
79
|
+
const hevc = format === "hvc1" || format === "hev1";
|
|
80
|
+
if (!hevc && format !== "avc1" && format !== "avc3") continue;
|
|
81
|
+
const config = findBox(children, hevc ? "hvcC" : "avcC");
|
|
82
|
+
const lengthAt = hevc ? 21 : 4;
|
|
83
|
+
const lengthSize = config !== null && config.payload.byteLength > lengthAt ? (config.payload[lengthAt] & 3) + 1 : 4;
|
|
84
|
+
const trackAt = tkhd.payload[0] === 1 ? 20 : 12;
|
|
85
|
+
const scaleAt = mdhd.payload[0] === 1 ? 20 : 12;
|
|
86
|
+
if (tkhd.payload.byteLength < trackAt + 4 || mdhd.payload.byteLength < scaleAt + 4) continue;
|
|
87
|
+
const trackId = view(tkhd.payload).getUint32(trackAt);
|
|
88
|
+
const timescale = view(mdhd.payload).getUint32(scaleAt);
|
|
89
|
+
if (timescale === 0) continue;
|
|
90
|
+
const fallback = defaults.get(trackId);
|
|
91
|
+
tracks.set(trackId, {
|
|
92
|
+
timescale,
|
|
93
|
+
hevc,
|
|
94
|
+
lengthSize,
|
|
95
|
+
defaultDuration: (_fallback$duration = fallback === null || fallback === void 0 ? void 0 : fallback.duration) !== null && _fallback$duration !== void 0 ? _fallback$duration : 0,
|
|
96
|
+
defaultSize: (_fallback$size = fallback === null || fallback === void 0 ? void 0 : fallback.size) !== null && _fallback$size !== void 0 ? _fallback$size : 0
|
|
51
97
|
});
|
|
52
98
|
}
|
|
53
|
-
return
|
|
54
|
-
samples,
|
|
55
|
-
defaultDuration: DEFAULT_TIMESCALE / 30
|
|
56
|
-
};
|
|
99
|
+
return tracks;
|
|
57
100
|
}
|
|
58
|
-
/**
|
|
59
|
-
function
|
|
60
|
-
const view = new DataView(sample.buffer, sample.byteOffset, sample.byteLength);
|
|
61
|
-
const sei = [];
|
|
101
|
+
/** Appends the SEI NAL units of one sample to `out`. */
|
|
102
|
+
function seiUnits(sample, track, out) {
|
|
62
103
|
let offset = 0;
|
|
63
|
-
while (offset +
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
offset +=
|
|
67
|
-
if (length === 0 || offset + length > sample.byteLength)
|
|
68
|
-
const
|
|
69
|
-
|
|
104
|
+
while (offset + track.lengthSize <= sample.byteLength) {
|
|
105
|
+
let length = 0;
|
|
106
|
+
for (let i = 0; i < track.lengthSize; i += 1) length = length * 256 + sample[offset + i];
|
|
107
|
+
offset += track.lengthSize;
|
|
108
|
+
if (length === 0 || offset + length > sample.byteLength) return;
|
|
109
|
+
const header = sample[offset];
|
|
110
|
+
const hevcType = header >> 1 & 63;
|
|
111
|
+
if (track.hevc ? hevcType === HEVC_PREFIX_SEI || hevcType === HEVC_SUFFIX_SEI : (header & 31) === AVC_SEI) out.push(sample.subarray(offset, offset + length));
|
|
70
112
|
offset += length;
|
|
71
113
|
}
|
|
72
|
-
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The caption packets of one media segment. A sample's time is the segment's
|
|
117
|
+
* presentation start plus its presentation offset from the first decode time
|
|
118
|
+
* of its track in the segment, the timeline cmaf-timing and the transmuxer
|
|
119
|
+
* produce. The tfdt itself may carry a broadcast clock.
|
|
120
|
+
*/
|
|
121
|
+
function captionPackets(data, tracks, start) {
|
|
122
|
+
const packets = [];
|
|
123
|
+
const firstDecode = /* @__PURE__ */ new Map();
|
|
124
|
+
const nextDecode = /* @__PURE__ */ new Map();
|
|
125
|
+
for (const moof of findBoxes(data, "moof")) {
|
|
126
|
+
let previousEnd = moof.start;
|
|
127
|
+
for (const traf of findBoxes(moof.payload, "traf")) {
|
|
128
|
+
var _track$defaultDuratio, _track$defaultSize, _parseTfdt, _ref, _firstDecode$get;
|
|
129
|
+
const tfhdBox = findBox(traf.payload, "tfhd");
|
|
130
|
+
const tfhd = tfhdBox === null ? null : fullBox(tfhdBox.payload);
|
|
131
|
+
if (tfhd === null || tfhd.body.byteLength < 4) continue;
|
|
132
|
+
const tfhdView = view(tfhd.body);
|
|
133
|
+
const trackId = tfhdView.getUint32(0);
|
|
134
|
+
const track = tracks.get(trackId);
|
|
135
|
+
let at = 4;
|
|
136
|
+
let base = tfhd.flags & TFHD_DEFAULT_BASE_IS_MOOF ? moof.start : previousEnd;
|
|
137
|
+
if (tfhd.flags & TFHD_BASE_DATA_OFFSET) {
|
|
138
|
+
base = Number(tfhdView.getBigUint64(at));
|
|
139
|
+
at += 8;
|
|
140
|
+
}
|
|
141
|
+
if (tfhd.flags & TFHD_SAMPLE_DESCRIPTION) at += 4;
|
|
142
|
+
let defaultDuration = (_track$defaultDuratio = track === null || track === void 0 ? void 0 : track.defaultDuration) !== null && _track$defaultDuratio !== void 0 ? _track$defaultDuratio : 0;
|
|
143
|
+
let defaultSize = (_track$defaultSize = track === null || track === void 0 ? void 0 : track.defaultSize) !== null && _track$defaultSize !== void 0 ? _track$defaultSize : 0;
|
|
144
|
+
if (tfhd.flags & TFHD_DEFAULT_DURATION) {
|
|
145
|
+
defaultDuration = tfhdView.getUint32(at);
|
|
146
|
+
at += 4;
|
|
147
|
+
}
|
|
148
|
+
if (tfhd.flags & TFHD_DEFAULT_SIZE) defaultSize = tfhdView.getUint32(at);
|
|
149
|
+
const tfdt = findBox(traf.payload, "tfdt");
|
|
150
|
+
const tfdtTime = tfdt === null ? void 0 : (_parseTfdt = parseTfdt(tfdt.payload)) === null || _parseTfdt === void 0 ? void 0 : _parseTfdt.baseMediaDecodeTime;
|
|
151
|
+
let decode = (_ref = tfdtTime !== null && tfdtTime !== void 0 ? tfdtTime : nextDecode.get(trackId)) !== null && _ref !== void 0 ? _ref : 0;
|
|
152
|
+
const first = (_firstDecode$get = firstDecode.get(trackId)) !== null && _firstDecode$get !== void 0 ? _firstDecode$get : decode;
|
|
153
|
+
firstDecode.set(trackId, first);
|
|
154
|
+
let cursor = base;
|
|
155
|
+
for (const trunBox of findBoxes(traf.payload, "trun")) {
|
|
156
|
+
const trun = fullBox(trunBox.payload);
|
|
157
|
+
if (trun === null || trun.body.byteLength < 4) continue;
|
|
158
|
+
const trunView = view(trun.body);
|
|
159
|
+
const count = trunView.getUint32(0);
|
|
160
|
+
let p = 4;
|
|
161
|
+
if (trun.flags & TRUN_DATA_OFFSET) {
|
|
162
|
+
cursor = base + trunView.getInt32(p);
|
|
163
|
+
p += 4;
|
|
164
|
+
}
|
|
165
|
+
if (trun.flags & TRUN_FIRST_SAMPLE_FLAGS) p += 4;
|
|
166
|
+
const samples = Math.min(count, data.byteLength);
|
|
167
|
+
for (let i = 0; i < samples; i += 1) {
|
|
168
|
+
let duration = defaultDuration;
|
|
169
|
+
let size = defaultSize;
|
|
170
|
+
let cts = 0;
|
|
171
|
+
if (trun.flags & TRUN_DURATION) {
|
|
172
|
+
duration = trunView.getUint32(p);
|
|
173
|
+
p += 4;
|
|
174
|
+
}
|
|
175
|
+
if (trun.flags & TRUN_SIZE) {
|
|
176
|
+
size = trunView.getUint32(p);
|
|
177
|
+
p += 4;
|
|
178
|
+
}
|
|
179
|
+
if (trun.flags & TRUN_FLAGS) p += 4;
|
|
180
|
+
if (trun.flags & TRUN_CTS) {
|
|
181
|
+
cts = trun.version === 1 ? trunView.getInt32(p) : trunView.getUint32(p);
|
|
182
|
+
p += 4;
|
|
183
|
+
}
|
|
184
|
+
if (track !== void 0) {
|
|
185
|
+
const units = [];
|
|
186
|
+
seiUnits(data.subarray(cursor, cursor + size), track, units);
|
|
187
|
+
const triples = [];
|
|
188
|
+
for (const unit of units) triples.push(...ccTriplesFromSei(unit, track.hevc ? 2 : 1));
|
|
189
|
+
if (triples.length > 0) packets.push({
|
|
190
|
+
time: start + (decode - first + cts) / track.timescale,
|
|
191
|
+
triples
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
cursor += size;
|
|
195
|
+
decode += duration;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
previousEnd = cursor;
|
|
199
|
+
nextDecode.set(trackId, decode);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return packets;
|
|
73
203
|
}
|
|
74
204
|
function nalScan() {
|
|
75
|
-
let
|
|
205
|
+
let tracks = /* @__PURE__ */ new Map();
|
|
76
206
|
return {
|
|
77
207
|
name: "nal-scan",
|
|
78
208
|
provides: ["nal-scan"],
|
|
@@ -80,37 +210,12 @@ function nalScan() {
|
|
|
80
210
|
ctx.registerTransform({
|
|
81
211
|
name: "nal-scan",
|
|
82
212
|
order: SCAN_ORDER,
|
|
83
|
-
transform(data,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
timescale = view.getUint8(0) === 1 ? view.getUint32(20) : view.getUint32(12);
|
|
90
|
-
}
|
|
91
|
-
const mdat = findBox(data, "mdat");
|
|
92
|
-
const trunBox = findBox(data, "moof/traf/trun");
|
|
93
|
-
if (mdat === null || trunBox === null) return data;
|
|
94
|
-
const tfdtBox = findBox(data, "moof/traf/tfdt");
|
|
95
|
-
const base = tfdtBox !== null ? (_parseTfdt$baseMediaD = (_parseTfdt = parseTfdt(tfdtBox.payload)) === null || _parseTfdt === void 0 ? void 0 : _parseTfdt.baseMediaDecodeTime) !== null && _parseTfdt$baseMediaD !== void 0 ? _parseTfdt$baseMediaD : 0 : 0;
|
|
96
|
-
const { samples } = parseTrun(trunBox.payload);
|
|
97
|
-
const packets = [];
|
|
98
|
-
let cursor = 0;
|
|
99
|
-
let decodeTime = base;
|
|
100
|
-
for (const sample of samples) {
|
|
101
|
-
const bytes = mdat.payload.subarray(cursor, cursor + sample.size);
|
|
102
|
-
cursor += sample.size;
|
|
103
|
-
const time = decodeTime / (timescale || DEFAULT_TIMESCALE);
|
|
104
|
-
decodeTime += sample.duration;
|
|
105
|
-
for (const sei of seiOfSample(bytes)) {
|
|
106
|
-
const triples = ccTriplesFromSei(sei);
|
|
107
|
-
if (triples.length > 0) packets.push({
|
|
108
|
-
time,
|
|
109
|
-
triples
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
deliverCaptions(packets);
|
|
213
|
+
transform(data, meta) {
|
|
214
|
+
if (!captionsWanted() || meta.contentType !== "video") return data;
|
|
215
|
+
try {
|
|
216
|
+
if (findBox(data, "moov") !== null) tracks = videoTracks(data);
|
|
217
|
+
if (tracks.size > 0) deliverCaptions(captionPackets(data, tracks, meta.start));
|
|
218
|
+
} catch (_unused) {}
|
|
114
219
|
return data;
|
|
115
220
|
}
|
|
116
221
|
});
|
|
@@ -19,7 +19,7 @@ function textCea608() {
|
|
|
19
19
|
contentType: "text",
|
|
20
20
|
mimeType: "application/cea-608"
|
|
21
21
|
}],
|
|
22
|
-
requires: [["
|
|
22
|
+
requires: [["nal-scan", "ts-transmux"]],
|
|
23
23
|
install(ctx) {
|
|
24
24
|
const decoder = new Cea608Decoder();
|
|
25
25
|
const element = ctx.element;
|
package/dist/kernel/bus.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bus.d.ts","sourceRoot":"","sources":["../../src/kernel/bus.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAW,MAAM,EAAQ,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,oEAAoE;IACpE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,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AG,SAAS,CA8J9D"}
|
package/dist/kernel/bus.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createTraceBuffer, DEFAULT_TRACE_CAPACITY, digest } from './trace.js';
|
|
1
|
+
import { createTraceBuffer, DEFAULT_TRACE_CAPACITY, digest, lighten } from './trace.js';
|
|
2
2
|
export function createBus(options) {
|
|
3
3
|
let reducer = options.reducer;
|
|
4
4
|
const now = options.now ?? (() => globalThis.performance.now());
|
|
@@ -22,7 +22,16 @@ export function createBus(options) {
|
|
|
22
22
|
while (msg !== undefined) {
|
|
23
23
|
const [next, effects] = reducer(state, msg);
|
|
24
24
|
state = next;
|
|
25
|
-
|
|
25
|
+
// Without its bytes, so nothing here keeps the media alive; kept only
|
|
26
|
+
// when a ring was asked for, and handed to whoever listens either way.
|
|
27
|
+
const entry = {
|
|
28
|
+
t: now(),
|
|
29
|
+
msg: lighten(msg),
|
|
30
|
+
effects: effects.map(lighten),
|
|
31
|
+
digest: digest(state),
|
|
32
|
+
};
|
|
33
|
+
traceBuffer.push(entry);
|
|
34
|
+
emitEvent('trace', entry);
|
|
26
35
|
// The sink may re-enter dispatch or absorb; those enqueue and are
|
|
27
36
|
// handled by this same loop, in order.
|
|
28
37
|
effectSink(effects);
|
package/dist/kernel/bus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bus.js","sourceRoot":"","sources":["../../src/kernel/bus.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"bus.js","sourceRoot":"","sources":["../../src/kernel/bus.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AA6CxF,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,C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AE,YAAY,CAAC,CAAC,EAClD,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,EAC9B,KAAK,GAAE,YAAiB,GACvB,OAAO,CAkET"}
|
package/dist/kernel/reducer.js
CHANGED
|
@@ -2,6 +2,7 @@ import { normalizeMimeType } from './mime.js';
|
|
|
2
2
|
import { canSwitchTo, codecFamily, createArbiter, planPinApply } from './rendition-select.js';
|
|
3
3
|
import { bufferedEndFrom, schedule } from './scheduler.js';
|
|
4
4
|
import { sbIdFor } from './sinks/mse-sink.js';
|
|
5
|
+
import { segmentAtTime } from './timeline.js';
|
|
5
6
|
import { DEFAULT_TRACE_CAPACITY } from './trace.js';
|
|
6
7
|
/**
|
|
7
8
|
* The default tuning. Every value is overridable through the `config`
|
|
@@ -166,6 +167,17 @@ function findTrackSite(presentation, trackId) {
|
|
|
166
167
|
}
|
|
167
168
|
return null;
|
|
168
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* The first candidate whose segment list places a boundary around `time`.
|
|
172
|
+
* A flush is planned on segment boundaries, and a rendition selected for
|
|
173
|
+
* the first time may have no segments yet, its media playlist still on its
|
|
174
|
+
* way: planned on it, the flush would start at the playhead itself and
|
|
175
|
+
* leave a segment head under the seek. The rendition playing always has
|
|
176
|
+
* its segments.
|
|
177
|
+
*/
|
|
178
|
+
function segmentedAt(candidates, time, periodStart) {
|
|
179
|
+
return candidates.find((rendition) => rendition !== undefined && segmentAtTime(rendition.segments, time, periodStart) !== null);
|
|
180
|
+
}
|
|
169
181
|
function findRendition(presentation, renditionId) {
|
|
170
182
|
if (presentation === null)
|
|
171
183
|
return null;
|
|
@@ -313,31 +325,49 @@ function reduceCommand(state, msg, cfg, hooks) {
|
|
|
313
325
|
const effects = [];
|
|
314
326
|
let buffers = state.buffers;
|
|
315
327
|
let inflight = state.scheduling.inflight;
|
|
316
|
-
// A media track change mid-stream
|
|
317
|
-
//
|
|
318
|
-
//
|
|
319
|
-
//
|
|
320
|
-
//
|
|
328
|
+
// A media track change mid-stream flushes the old track's buffer
|
|
329
|
+
// ahead, the way a pin does: from the playhead's segment for a
|
|
330
|
+
// viewer's choice, from a boundary ahead for a coupling that follows
|
|
331
|
+
// a video switch, so the old track plays out and nothing runs dry
|
|
332
|
+
// under the playhead. Clearing the whole buffer instead stalls
|
|
333
|
+
// playback until the new track's first segment lands. The element is
|
|
334
|
+
// not nudged for audio: a video decoder holds stale frames, an audio
|
|
335
|
+
// one does not.
|
|
336
|
+
const site = state.presentation === null ? null : findTrackSite(state.presentation, track.id);
|
|
337
|
+
const previousTrack = previous === undefined ? null : findTrack(state.presentation, previous);
|
|
338
|
+
const flushRendition = site === null
|
|
339
|
+
? undefined
|
|
340
|
+
: (segmentedAt([...track.renditions, ...(previousTrack?.renditions ?? [])], state.playback.currentTime, site.period.start) ?? track.renditions[0]);
|
|
321
341
|
if (previous !== undefined &&
|
|
322
342
|
previous !== track.id &&
|
|
323
|
-
(track.contentType === 'audio' || track.contentType === 'video')
|
|
343
|
+
(track.contentType === 'audio' || track.contentType === 'video') &&
|
|
344
|
+
site !== null &&
|
|
345
|
+
flushRendition !== undefined) {
|
|
324
346
|
const sbId = sbIdFor(track.contentType);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
347
|
+
const buffer = state.buffers.get(sbId);
|
|
348
|
+
if (buffer !== undefined) {
|
|
349
|
+
const plan = planPinApply({
|
|
350
|
+
strategy: msg.apply ?? 'now',
|
|
351
|
+
currentTime: state.playback.currentTime,
|
|
352
|
+
ranges: buffer.ranges,
|
|
328
353
|
sbId,
|
|
329
|
-
|
|
330
|
-
|
|
354
|
+
trackId: track.id,
|
|
355
|
+
inflightTokens: [],
|
|
356
|
+
period: site.period,
|
|
357
|
+
rendition: flushRendition,
|
|
358
|
+
tokenSeq: state.scheduling.tokenSeq,
|
|
331
359
|
});
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const next = new Map(state.buffers);
|
|
337
|
-
const { initFor: _initFor, ...rest } = buffer;
|
|
338
|
-
next.set(sbId, rest);
|
|
339
|
-
buffers = next;
|
|
360
|
+
for (const effect of plan.effects) {
|
|
361
|
+
if (effect.kind !== 'seekElement' || track.contentType === 'video') {
|
|
362
|
+
effects.push(effect);
|
|
363
|
+
}
|
|
340
364
|
}
|
|
365
|
+
// Force an init re-fetch for the new track: its initFor no
|
|
366
|
+
// longer matches, so scheduling fetches init before media.
|
|
367
|
+
const next = new Map(state.buffers);
|
|
368
|
+
const { initFor: _initFor, ...rest } = buffer;
|
|
369
|
+
next.set(sbId, rest);
|
|
370
|
+
buffers = next;
|
|
341
371
|
// Drop the old track's in-flight fetches.
|
|
342
372
|
const pruned = new Map(state.scheduling.inflight);
|
|
343
373
|
for (const [token, request] of state.scheduling.inflight) {
|
|
@@ -417,6 +447,9 @@ function reduceCommand(state, msg, cfg, hooks) {
|
|
|
417
447
|
if (request.trackId === site.track.id)
|
|
418
448
|
inflightTokens.push(request.token);
|
|
419
449
|
}
|
|
450
|
+
const active = state.quality.active === null
|
|
451
|
+
? null
|
|
452
|
+
: findRendition(state.presentation, state.quality.active);
|
|
420
453
|
const plan = planPinApply({
|
|
421
454
|
strategy: msg.apply,
|
|
422
455
|
currentTime: state.playback.currentTime,
|
|
@@ -425,7 +458,7 @@ function reduceCommand(state, msg, cfg, hooks) {
|
|
|
425
458
|
trackId: site.track.id,
|
|
426
459
|
inflightTokens,
|
|
427
460
|
period: site.period,
|
|
428
|
-
rendition: site.rendition,
|
|
461
|
+
rendition: segmentedAt([site.rendition, active?.rendition], state.playback.currentTime, site.period.start) ?? site.rendition,
|
|
429
462
|
tokenSeq: state.scheduling.tokenSeq,
|
|
430
463
|
});
|
|
431
464
|
const inflight = new Map(state.scheduling.inflight);
|
|
@@ -633,14 +666,17 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
633
666
|
// practice, and forcing changeType there breaks WebKit. The
|
|
634
667
|
// reducer emits the mechanism; codec-switch's policy governed
|
|
635
668
|
// whether abr proposed the switch at all.
|
|
669
|
+
// A rendition that declares no codecs (a bare media playlist)
|
|
670
|
+
// cannot name a family change. The buffer keeps the type it was
|
|
671
|
+
// opened with, which codec-probe may have read from the init;
|
|
672
|
+
// a changeType back to the bare type fails in Chrome and WebKit.
|
|
636
673
|
const targetSite = findRendition(state.presentation, matched.renditionId);
|
|
637
|
-
const
|
|
674
|
+
const declared = targetSite?.rendition.codecs ?? null;
|
|
675
|
+
const targetCodecs = targetSite === null || declared === null
|
|
638
676
|
? buffer.codecs
|
|
639
|
-
: targetSite.rendition.codecs
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const familyChanged = codecFamily(targetSite?.rendition.codecs ?? null) !==
|
|
643
|
-
codecFamily(bufferCodecString(buffer.codecs));
|
|
677
|
+
: `${targetSite.rendition.mimeType}; codecs="${declared}"`;
|
|
678
|
+
const familyChanged = declared !== null &&
|
|
679
|
+
codecFamily(declared) !== codecFamily(bufferCodecString(buffer.codecs));
|
|
644
680
|
const nextBuffers = new Map(state.buffers);
|
|
645
681
|
if (targetCodecs !== buffer.codecs && familyChanged) {
|
|
646
682
|
effects.push({ kind: 'changeType', sbId: matched.sbId, codecs: targetCodecs });
|