mattebox 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +151 -0
- package/dist/es2015/stages/chapters/parse.js +149 -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 +20 -0
- package/dist/stages/chapters/index.d.ts.map +1 -0
- package/dist/stages/chapters/index.js +141 -0
- package/dist/stages/chapters/index.js.map +1 -0
- package/dist/stages/chapters/parse.d.ts +47 -0
- package/dist/stages/chapters/parse.d.ts.map +1 -0
- package/dist/stages/chapters/parse.js +168 -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
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
|
|
2
|
+
import { findTrackSite } from "../../kernel/presentation.js";
|
|
3
|
+
import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/asyncToGenerator.js";
|
|
4
|
+
import { parseAppleChapters, parseChapterTrack } from "./parse.js";
|
|
5
|
+
//#region src/stages/chapters/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* Chapters: named spans of the presentation, answered through
|
|
8
|
+
* `engine.chapters`. Two sources fill it:
|
|
9
|
+
*
|
|
10
|
+
* - The manifest. An HLS EXT-X-SESSION-DATA entry with DATA-ID
|
|
11
|
+
* `com.apple.hls.chapters` names Apple's JSON chapters document. The
|
|
12
|
+
* stage's reducer fetches it once per load and parses it; the list lives
|
|
13
|
+
* in the stage's slice.
|
|
14
|
+
* - A file the app loads: a WebVTT chapters track, the metadata track this
|
|
15
|
+
* engine defines (JSON cue payloads with an image and data), or Apple's
|
|
16
|
+
* JSON. It wins over the manifest until the next LOAD, UNLOAD, or DETACH.
|
|
17
|
+
*
|
|
18
|
+
* Both fetches go through the transport, so request hooks (auth, cmcd,
|
|
19
|
+
* steering) apply. A load counter in the slice ties the app's list, which
|
|
20
|
+
* lives outside kernel state, to the source loaded when it arrived.
|
|
21
|
+
*/
|
|
22
|
+
/** The session-data id Apple's players read chapters from. */
|
|
23
|
+
const APPLE_CHAPTERS = "com.apple.hls.chapters";
|
|
24
|
+
const FETCH_TOKEN = "chapters:manifest";
|
|
25
|
+
const INITIAL = {
|
|
26
|
+
loads: 0,
|
|
27
|
+
manifestUri: null,
|
|
28
|
+
manifest: null
|
|
29
|
+
};
|
|
30
|
+
/** The active subtitle language picks among a document's titles. */
|
|
31
|
+
function preferredLanguage(kernel) {
|
|
32
|
+
var _findTrackSite$track$, _findTrackSite;
|
|
33
|
+
const textId = kernel.tracks.active.get("text");
|
|
34
|
+
if (textId === void 0) return null;
|
|
35
|
+
return (_findTrackSite$track$ = (_findTrackSite = findTrackSite(kernel.presentation, textId)) === null || _findTrackSite === void 0 ? void 0 : _findTrackSite.track.lang) !== null && _findTrackSite$track$ !== void 0 ? _findTrackSite$track$ : null;
|
|
36
|
+
}
|
|
37
|
+
/** A parse's warnings and the list-changed event, as emit effects. */
|
|
38
|
+
function report(url, result, source) {
|
|
39
|
+
return [...result.warnings.map((warning) => ({
|
|
40
|
+
kind: "emit",
|
|
41
|
+
event: "chapters:warning",
|
|
42
|
+
payload: _objectSpread2({ url }, warning)
|
|
43
|
+
})), {
|
|
44
|
+
kind: "emit",
|
|
45
|
+
event: "chapters:changed",
|
|
46
|
+
payload: {
|
|
47
|
+
count: result.chapters.length,
|
|
48
|
+
source
|
|
49
|
+
}
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
52
|
+
/** Counts source changes, and finds, fetches, and parses the manifest's chapters. */
|
|
53
|
+
const reduceChapters = (slice, msg, kernel) => {
|
|
54
|
+
const state = slice !== null && slice !== void 0 ? slice : INITIAL;
|
|
55
|
+
if (msg.type === "LOAD" || msg.type === "UNLOAD" || msg.type === "DETACH") return [_objectSpread2(_objectSpread2({}, INITIAL), {}, { loads: state.loads + 1 }), [{
|
|
56
|
+
kind: "emit",
|
|
57
|
+
event: "chapters:changed",
|
|
58
|
+
payload: {
|
|
59
|
+
count: 0,
|
|
60
|
+
source: "none"
|
|
61
|
+
}
|
|
62
|
+
}]];
|
|
63
|
+
if (msg.type === "MANIFEST_LOADED") {
|
|
64
|
+
var _msg$presentation$ses;
|
|
65
|
+
const uri = (_msg$presentation$ses = msg.presentation.sessionData) === null || _msg$presentation$ses === void 0 || (_msg$presentation$ses = _msg$presentation$ses.find((d) => d.id === APPLE_CHAPTERS)) === null || _msg$presentation$ses === void 0 ? void 0 : _msg$presentation$ses.uri;
|
|
66
|
+
if (uri === void 0 || uri === state.manifestUri) return [state, []];
|
|
67
|
+
return [_objectSpread2(_objectSpread2({}, state), {}, { manifestUri: uri }), [{
|
|
68
|
+
kind: "fetch",
|
|
69
|
+
token: FETCH_TOKEN,
|
|
70
|
+
url: uri
|
|
71
|
+
}]];
|
|
72
|
+
}
|
|
73
|
+
if (msg.type === "SEGMENT_LOADED" && msg.trackId === FETCH_TOKEN && state.manifestUri !== null) {
|
|
74
|
+
const text = new TextDecoder().decode(msg.bytes);
|
|
75
|
+
const result = parseAppleChapters(text, state.manifestUri, preferredLanguage(kernel));
|
|
76
|
+
return [_objectSpread2(_objectSpread2({}, state), {}, { manifest: result.chapters }), report(state.manifestUri, result, "manifest")];
|
|
77
|
+
}
|
|
78
|
+
if (msg.type === "SEGMENT_FAILED" && msg.trackId === FETCH_TOKEN) return [state, [{
|
|
79
|
+
kind: "emit",
|
|
80
|
+
event: "chapters:warning",
|
|
81
|
+
payload: {
|
|
82
|
+
url: state.manifestUri,
|
|
83
|
+
reason: "fetch-failed"
|
|
84
|
+
}
|
|
85
|
+
}]];
|
|
86
|
+
return [state, []];
|
|
87
|
+
};
|
|
88
|
+
function chapters() {
|
|
89
|
+
return {
|
|
90
|
+
name: "chapters",
|
|
91
|
+
provides: ["chapters"],
|
|
92
|
+
requires: ["transport"],
|
|
93
|
+
install(ctx) {
|
|
94
|
+
ctx.reduce("chapters", reduceChapters);
|
|
95
|
+
let list = null;
|
|
96
|
+
const slice = () => {
|
|
97
|
+
var _ref;
|
|
98
|
+
return (_ref = ctx.getState().chapters) !== null && _ref !== void 0 ? _ref : INITIAL;
|
|
99
|
+
};
|
|
100
|
+
/** The app's list, when it belongs to the source loaded now. */
|
|
101
|
+
const app = () => list !== null && list.loads === slice().loads ? list.chapters : null;
|
|
102
|
+
/**
|
|
103
|
+
* The list in force. A last chapter with no end runs to the end of the
|
|
104
|
+
* presentation, known once a media playlist has loaded.
|
|
105
|
+
*/
|
|
106
|
+
const current = () => {
|
|
107
|
+
var _ref2, _app, _ctx$getState$present;
|
|
108
|
+
const chosen = (_ref2 = (_app = app()) !== null && _app !== void 0 ? _app : slice().manifest) !== null && _ref2 !== void 0 ? _ref2 : [];
|
|
109
|
+
const duration = (_ctx$getState$present = ctx.getState().presentation) === null || _ctx$getState$present === void 0 ? void 0 : _ctx$getState$present.duration;
|
|
110
|
+
if (duration === void 0) return chosen;
|
|
111
|
+
return chosen.map((c) => c.end === Number.POSITIVE_INFINITY ? _objectSpread2(_objectSpread2({}, c), {}, { end: duration }) : c);
|
|
112
|
+
};
|
|
113
|
+
ctx.registerNamespace("chapters", {
|
|
114
|
+
load(url) {
|
|
115
|
+
return _asyncToGenerator(function* () {
|
|
116
|
+
const at = slice().loads;
|
|
117
|
+
const response = yield ctx.request(url, { method: "GET" });
|
|
118
|
+
if (!response.ok) throw new TypeError(`chapters ${url}: HTTP ${response.status}`);
|
|
119
|
+
const text = yield response.text();
|
|
120
|
+
const base = response.url || url;
|
|
121
|
+
let result;
|
|
122
|
+
if (/^?WEBVTT/.test(text)) result = parseChapterTrack(text, base);
|
|
123
|
+
else if (text.trimStart().startsWith("[")) result = parseAppleChapters(text, base, preferredLanguage(ctx.getState()));
|
|
124
|
+
else throw new TypeError(`chapters ${url}: neither WebVTT nor a JSON chapters array`);
|
|
125
|
+
const effects = report(url, result, "app");
|
|
126
|
+
if (at !== slice().loads) return result.chapters.length;
|
|
127
|
+
list = {
|
|
128
|
+
loads: at,
|
|
129
|
+
chapters: result.chapters
|
|
130
|
+
};
|
|
131
|
+
for (const effect of effects) if (effect.kind === "emit") ctx.emit(effect.event, effect.payload);
|
|
132
|
+
return result.chapters.length;
|
|
133
|
+
})();
|
|
134
|
+
},
|
|
135
|
+
at(time) {
|
|
136
|
+
var _current$find;
|
|
137
|
+
return (_current$find = current().find((c) => time >= c.start && time < c.end)) !== null && _current$find !== void 0 ? _current$find : null;
|
|
138
|
+
},
|
|
139
|
+
get all() {
|
|
140
|
+
return current();
|
|
141
|
+
},
|
|
142
|
+
get source() {
|
|
143
|
+
if (app() !== null) return "app";
|
|
144
|
+
return slice().manifest === null ? "none" : "manifest";
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
export { chapters as default };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
|
|
2
|
+
import _objectWithoutProperties from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectWithoutProperties.js";
|
|
3
|
+
import { parseVtt } from "../../containers/webvtt.js";
|
|
4
|
+
import { resolveUrl } from "../../kernel/url.js";
|
|
5
|
+
//#region src/stages/chapters/parse.ts
|
|
6
|
+
/**
|
|
7
|
+
* Chapter files into one record shape. Pure. A WebVTT file serves two
|
|
8
|
+
* sources: a chapters track, whose cue payload is the title, and the
|
|
9
|
+
* metadata track this engine defines, whose cue payload may be a JSON object
|
|
10
|
+
* with a title, an image, and free data. Detection is per cue, so the two
|
|
11
|
+
* mix in one file.
|
|
12
|
+
*/
|
|
13
|
+
const _excluded = [
|
|
14
|
+
"title",
|
|
15
|
+
"lang",
|
|
16
|
+
"image"
|
|
17
|
+
];
|
|
18
|
+
const _excluded2 = [
|
|
19
|
+
"start-time",
|
|
20
|
+
"duration",
|
|
21
|
+
"titles",
|
|
22
|
+
"images"
|
|
23
|
+
];
|
|
24
|
+
function imageOf(value, baseUrl) {
|
|
25
|
+
if (typeof value === "string") return { url: resolveUrl(value, baseUrl) };
|
|
26
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
27
|
+
const { url, width, height } = value;
|
|
28
|
+
if (typeof url !== "string") return void 0;
|
|
29
|
+
return _objectSpread2(_objectSpread2({ url: resolveUrl(url, baseUrl) }, typeof width === "number" ? { width } : {}), typeof height === "number" ? { height } : {});
|
|
30
|
+
}
|
|
31
|
+
/** A JSON cue payload into the record's fields; every other field goes to `data`. */
|
|
32
|
+
function fromJson(object, baseUrl) {
|
|
33
|
+
const { title, lang, image } = object, rest = _objectWithoutProperties(object, _excluded);
|
|
34
|
+
const resolvedImage = imageOf(image, baseUrl);
|
|
35
|
+
return _objectSpread2(_objectSpread2(_objectSpread2({ title: typeof title === "string" ? title : "" }, typeof lang === "string" ? { lang } : {}), resolvedImage !== void 0 ? { image: resolvedImage } : {}), Object.keys(rest).length > 0 ? { data: rest } : {});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sorts by start and truncates an earlier chapter that runs into the next,
|
|
39
|
+
* so chapters partition the timeline. An authored gap stays a gap.
|
|
40
|
+
*/
|
|
41
|
+
function orderChapters(chapters, warnings) {
|
|
42
|
+
const sorted = [...chapters].sort((a, b) => a.start - b.start);
|
|
43
|
+
return sorted.map((chapter, i) => {
|
|
44
|
+
const next = sorted[i + 1];
|
|
45
|
+
if (next === void 0 || chapter.end <= next.start) return chapter;
|
|
46
|
+
warnings.push({
|
|
47
|
+
reason: "overlap",
|
|
48
|
+
id: chapter.id
|
|
49
|
+
});
|
|
50
|
+
return _objectSpread2(_objectSpread2({}, chapter), {}, { end: next.start });
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** A WebVTT chapters or metadata track. URLs resolve against `baseUrl`, the file's own URL. */
|
|
54
|
+
function parseChapterTrack(text, baseUrl) {
|
|
55
|
+
const { cues, skipped } = parseVtt(text);
|
|
56
|
+
const warnings = [];
|
|
57
|
+
for (let i = 0; i < skipped; i += 1) warnings.push({ reason: "malformed-cue" });
|
|
58
|
+
const chapters = [];
|
|
59
|
+
for (const cue of cues) {
|
|
60
|
+
var _cue$text, _cue$id;
|
|
61
|
+
const payload = ((_cue$text = cue.text) !== null && _cue$text !== void 0 ? _cue$text : "").trim();
|
|
62
|
+
const id = (_cue$id = cue.id) !== null && _cue$id !== void 0 ? _cue$id : String(Math.round(cue.start * 1e3));
|
|
63
|
+
let fields = { title: payload };
|
|
64
|
+
if (payload.startsWith("{")) try {
|
|
65
|
+
const parsed = JSON.parse(payload);
|
|
66
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new TypeError("not an object");
|
|
67
|
+
fields = fromJson(parsed, baseUrl);
|
|
68
|
+
} catch (_unused) {
|
|
69
|
+
warnings.push({
|
|
70
|
+
reason: "bad-json",
|
|
71
|
+
id
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
chapters.push(_objectSpread2({
|
|
75
|
+
id,
|
|
76
|
+
start: cue.start,
|
|
77
|
+
end: cue.end
|
|
78
|
+
}, fields));
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
chapters: orderChapters(chapters, warnings),
|
|
82
|
+
warnings
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The title in `preferred`, else the language-neutral `und` one, else the
|
|
87
|
+
* first. Apple's JSON gives one title per BCP 47 tag.
|
|
88
|
+
*/
|
|
89
|
+
function pickTitle(titles, preferred) {
|
|
90
|
+
var _ref, _ref2, _titles$find;
|
|
91
|
+
const base = (tag) => tag.toLowerCase().split("-")[0];
|
|
92
|
+
return (_ref = (_ref2 = preferred === null ? void 0 : (_titles$find = titles.find((t) => t.language.toLowerCase() === preferred.toLowerCase())) !== null && _titles$find !== void 0 ? _titles$find : titles.find((t) => base(t.language) === base(preferred))) !== null && _ref2 !== void 0 ? _ref2 : titles.find((t) => t.language === "und")) !== null && _ref !== void 0 ? _ref : titles[0];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Apple's JSON chapters document (HTTP Live Streaming, "Providing
|
|
96
|
+
* JavaScript Object Notation (JSON) chapters"): an array of entries with a
|
|
97
|
+
* required `start-time` and optional `duration`, `chapter`, `titles`,
|
|
98
|
+
* `images`, and `metadata`. Without `duration` a chapter ends at the next
|
|
99
|
+
* one's start; the last one runs to the end of the presentation (Infinity
|
|
100
|
+
* here). The first image becomes `image`; every title, image, and metadata
|
|
101
|
+
* item stays under `data`. Image URLs resolve against the document.
|
|
102
|
+
*/
|
|
103
|
+
function parseAppleChapters(text, baseUrl, preferredLanguage = null) {
|
|
104
|
+
const warnings = [];
|
|
105
|
+
let parsed;
|
|
106
|
+
try {
|
|
107
|
+
parsed = JSON.parse(text);
|
|
108
|
+
} catch (_unused2) {
|
|
109
|
+
return {
|
|
110
|
+
chapters: [],
|
|
111
|
+
warnings: [{ reason: "bad-json" }]
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (!Array.isArray(parsed)) return {
|
|
115
|
+
chapters: [],
|
|
116
|
+
warnings: [{ reason: "bad-json" }]
|
|
117
|
+
};
|
|
118
|
+
const entries = parsed.filter((entry) => {
|
|
119
|
+
const ok = typeof entry === "object" && entry !== null && typeof entry["start-time"] === "number";
|
|
120
|
+
if (!ok) warnings.push({ reason: "malformed-cue" });
|
|
121
|
+
return ok;
|
|
122
|
+
});
|
|
123
|
+
const starts = entries.map((entry) => entry["start-time"]).sort((a, b) => a - b);
|
|
124
|
+
return {
|
|
125
|
+
chapters: orderChapters(entries.map((entry, index) => {
|
|
126
|
+
var _starts$find, _title$title;
|
|
127
|
+
const start = entry["start-time"];
|
|
128
|
+
const duration = typeof entry.duration === "number" ? entry.duration : null;
|
|
129
|
+
const end = duration !== null ? start + duration : (_starts$find = starts.find((s) => s > start)) !== null && _starts$find !== void 0 ? _starts$find : Number.POSITIVE_INFINITY;
|
|
130
|
+
const titles = Array.isArray(entry.titles) ? entry.titles.filter((t) => typeof t === "object" && t !== null && typeof t.language === "string" && typeof t.title === "string") : [];
|
|
131
|
+
const title = pickTitle(titles, preferredLanguage);
|
|
132
|
+
const images = Array.isArray(entry.images) ? entry.images.filter((i) => typeof i === "object" && i !== null).filter((i) => typeof i.url === "string").map((i) => _objectSpread2(_objectSpread2({}, i), {}, { url: resolveUrl(i.url, baseUrl) })) : [];
|
|
133
|
+
const first = images[0];
|
|
134
|
+
const { "start-time": _start, duration: _duration, titles: _titles, images: _images } = entry, rest = _objectWithoutProperties(entry, _excluded2);
|
|
135
|
+
const data = _objectSpread2(_objectSpread2(_objectSpread2({}, rest), titles.length > 0 ? { titles } : {}), images.length > 0 ? { images } : {});
|
|
136
|
+
const width = first === null || first === void 0 ? void 0 : first["pixel-width"];
|
|
137
|
+
const height = first === null || first === void 0 ? void 0 : first["pixel-height"];
|
|
138
|
+
return _objectSpread2(_objectSpread2(_objectSpread2({
|
|
139
|
+
id: typeof entry.chapter === "number" ? String(entry.chapter) : String(index + 1),
|
|
140
|
+
start,
|
|
141
|
+
end,
|
|
142
|
+
title: (_title$title = title === null || title === void 0 ? void 0 : title.title) !== null && _title$title !== void 0 ? _title$title : ""
|
|
143
|
+
}, title !== void 0 ? { lang: title.language } : {}), first !== void 0 ? { image: _objectSpread2(_objectSpread2({ url: first.url }, typeof width === "number" ? { width } : {}), typeof height === "number" ? { height } : {}) } : {}), Object.keys(data).length > 0 ? { data } : {});
|
|
144
|
+
}), warnings),
|
|
145
|
+
warnings
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
export { orderChapters, parseAppleChapters, parseChapterTrack };
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
import { findRendition } from "../../kernel/presentation.js";
|
|
1
2
|
//#region src/stages/cmcd/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Common Media Client Data (CTA-5004). The engine already exposes the seam
|
|
5
|
+
* this needs: a request hook that sees every outgoing segment and manifest
|
|
6
|
+
* URL. This stage reads playback state through the stage context and appends
|
|
7
|
+
* the CMCD keys a CDN reads to understand the session, as either a query
|
|
8
|
+
* argument or request headers.
|
|
9
|
+
*
|
|
10
|
+
* It computes nothing the kernel does not already track: the active rendition
|
|
11
|
+
* bitrate, the measured throughput EWMA, and the buffer ahead of the playhead
|
|
12
|
+
* from the media element. No new kernel state, no new effect.
|
|
13
|
+
*/
|
|
2
14
|
/** The CMCD object type, inferred from the URL the request is fetching. */
|
|
3
15
|
function objectType(url) {
|
|
4
16
|
if (/\.(m3u8|mpd)(\?|$)/i.test(url)) return "m";
|
|
@@ -54,10 +66,8 @@ function cmcd(options = {}) {
|
|
|
54
66
|
};
|
|
55
67
|
if (options.contentId !== void 0) keys.cid = options.contentId;
|
|
56
68
|
const activeId = state.quality.active;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (rendition !== void 0) keys.br = Math.round(rendition.bitrate / 1e3);
|
|
60
|
-
}
|
|
69
|
+
const active = activeId === null ? null : findRendition(state.presentation, activeId);
|
|
70
|
+
if (active !== null) keys.br = Math.round(active.rendition.bitrate / 1e3);
|
|
61
71
|
const mtp = state.stats.throughputEwma;
|
|
62
72
|
if (mtp > 0) keys.mtp = Math.round(mtp / 1e3 / 100) * 100;
|
|
63
73
|
const el = ctx.element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { typeString } from "../../kernel/mime.js";
|
|
1
2
|
import { canSwitchTo } from "../../kernel/rendition-select.js";
|
|
2
3
|
//#region src/stages/codec-switch/index.ts
|
|
3
4
|
/**
|
|
@@ -15,17 +16,13 @@ import { canSwitchTo } from "../../kernel/rendition-select.js";
|
|
|
15
16
|
* lies; until a runtime call site exists this policy reasons over the IR's
|
|
16
17
|
* declared strings, which is already a real improvement.
|
|
17
18
|
*/
|
|
18
|
-
/** A full MSE type string for a rendition, mime plus codecs. */
|
|
19
|
-
function typeString(rendition) {
|
|
20
|
-
return rendition.codecs === null ? rendition.mimeType : `${rendition.mimeType}; codecs="${rendition.codecs}"`;
|
|
21
|
-
}
|
|
22
19
|
/** Whether the runtime can bridge two types without tearing the buffer down. */
|
|
23
20
|
function changeTypeSupported(target) {
|
|
24
21
|
var _globalThis$SourceBuf;
|
|
25
22
|
const MediaSourceCtor = typeof MediaSource !== "undefined" ? MediaSource : globalThis.ManagedMediaSource;
|
|
26
23
|
if (MediaSourceCtor === void 0) return false;
|
|
27
24
|
if (typeof ((_globalThis$SourceBuf = globalThis.SourceBuffer) === null || _globalThis$SourceBuf === void 0 || (_globalThis$SourceBuf = _globalThis$SourceBuf.prototype) === null || _globalThis$SourceBuf === void 0 ? void 0 : _globalThis$SourceBuf.changeType) !== "function") return false;
|
|
28
|
-
return MediaSourceCtor.isTypeSupported(typeString(target));
|
|
25
|
+
return MediaSourceCtor.isTypeSupported(typeString(target.mimeType, target.codecs));
|
|
29
26
|
}
|
|
30
27
|
function createPolicy() {
|
|
31
28
|
return (current, target) => {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
|
|
2
|
+
import { scheduled, tickAfter } from "../../kernel/effects.js";
|
|
2
3
|
//#region src/stages/content-steering/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Content steering: pathway switching from a steering manifest, plus
|
|
6
|
+
* failover when the active pathway starts failing. The two manifest
|
|
7
|
+
* families normalize into one model at parse time — HLS pathways are
|
|
8
|
+
* variant clones (renditions carry a pathway id), DASH pathways are
|
|
9
|
+
* BaseURL choices (the steering bases map) — so one stage serves both:
|
|
10
|
+
* rendition pathways apply through a 'steering' constraint, base pathways
|
|
11
|
+
* through a transport request hook rewriting URL prefixes.
|
|
12
|
+
*/
|
|
3
13
|
const MANIFEST_TOKEN = "steering:manifest";
|
|
4
14
|
const RELOAD_TOKEN = "steering:reload";
|
|
5
15
|
const PATHWAY_EVENT = "steering:pathway";
|
|
@@ -19,12 +29,7 @@ const INITIAL = {
|
|
|
19
29
|
};
|
|
20
30
|
/** Loops a message back into the bus through a zero-delay schedule effect. */
|
|
21
31
|
function feed(message) {
|
|
22
|
-
return
|
|
23
|
-
kind: "schedule",
|
|
24
|
-
token: "steering:loopback",
|
|
25
|
-
delayMs: 0,
|
|
26
|
-
then: message
|
|
27
|
-
};
|
|
32
|
+
return scheduled("steering:loopback", message);
|
|
28
33
|
}
|
|
29
34
|
function pathwaysOf(kernel) {
|
|
30
35
|
var _kernel$presentation$, _kernel$presentation, _kernel$presentation$2, _kernel$presentation2;
|
|
@@ -131,15 +136,7 @@ const reduceSteering = (slice, msg, kernel) => {
|
|
|
131
136
|
}
|
|
132
137
|
if (!next.tickPending) {
|
|
133
138
|
var _parsed$TTL;
|
|
134
|
-
effects.push(
|
|
135
|
-
kind: "schedule",
|
|
136
|
-
token: RELOAD_TOKEN,
|
|
137
|
-
delayMs: ((_parsed$TTL = parsed.TTL) !== null && _parsed$TTL !== void 0 ? _parsed$TTL : DEFAULT_TTL) * 1e3,
|
|
138
|
-
then: {
|
|
139
|
-
type: "TICK",
|
|
140
|
-
token: RELOAD_TOKEN
|
|
141
|
-
}
|
|
142
|
-
});
|
|
139
|
+
effects.push(tickAfter(RELOAD_TOKEN, ((_parsed$TTL = parsed.TTL) !== null && _parsed$TTL !== void 0 ? _parsed$TTL : DEFAULT_TTL) * 1e3));
|
|
143
140
|
next = _objectSpread2(_objectSpread2({}, next), {}, { tickPending: true });
|
|
144
141
|
}
|
|
145
142
|
return [next, effects];
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
import { base64ToBytes } from "../../kernel/base64.js";
|
|
1
2
|
import { registerKeySystem } from "../drm-shared.js";
|
|
2
3
|
//#region src/stages/eme-cenc/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Widevine and PlayReady over Common Encryption. Neither drives EME
|
|
6
|
+
* itself: each registers a key-system handler that eme-core negotiates and
|
|
7
|
+
* runs. The system-id UUIDs the dash parser already extracts, and the
|
|
8
|
+
* skd/pssh the hls parser stores, select the branch; the shaping here is
|
|
9
|
+
* the request body and the response unwrap each server expects.
|
|
10
|
+
*/
|
|
3
11
|
const WIDEVINE_SYSTEM_ID = "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed";
|
|
4
12
|
const PLAYREADY_SYSTEM_ID = "9a04f079-9840-4286-ab92-e65be0885f95";
|
|
5
13
|
/** Pulls the license blob out of a PlayReady SOAP response, or passes bytes through. */
|
|
6
14
|
function unwrapPlayReadyResponse(response) {
|
|
15
|
+
var _base64ToBytes;
|
|
7
16
|
const text = new TextDecoder().decode(response);
|
|
8
17
|
if (!text.includes("<License>")) return response;
|
|
9
18
|
const match = /<License>([\s\S]*?)<\/License>/.exec(text);
|
|
10
19
|
if (match === null) return response;
|
|
11
|
-
|
|
12
|
-
const bytes = new Uint8Array(binary.length);
|
|
13
|
-
for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
|
|
14
|
-
return bytes;
|
|
20
|
+
return (_base64ToBytes = base64ToBytes(match[1])) !== null && _base64ToBytes !== void 0 ? _base64ToBytes : response;
|
|
15
21
|
}
|
|
16
22
|
function emeCenc() {
|
|
17
23
|
return {
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
|
|
2
2
|
import _asyncToGenerator from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/asyncToGenerator.js";
|
|
3
|
+
import { bytesToBase64 } from "../../kernel/base64.js";
|
|
3
4
|
import { keySystemHandlers, normalizeSystemId } from "../drm-shared.js";
|
|
4
5
|
//#region src/stages/eme-core/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* The generic EME handshake, entanglement #3 resolved: DRM lands without
|
|
8
|
+
* touching a protocol adapter. Init data arrives by two routes — the
|
|
9
|
+
* manifest (protection descriptors already in the IR since Stage 08) and
|
|
10
|
+
* the media (the element's `encrypted` event) — and eme-core dedupes them
|
|
11
|
+
* by key id so the same key never opens two sessions.
|
|
12
|
+
*
|
|
13
|
+
* Everything here is the impure edge: MediaKeys and MediaKeySession are
|
|
14
|
+
* un-serializable and cannot enter the reducer, so this is an install-time
|
|
15
|
+
* controller. It reports through ctx.emit (drm:* events, and a fatal
|
|
16
|
+
* 'error' event that reaches engine.error) and exposes engine.drm; the
|
|
17
|
+
* trace stays complete for everything the reducer can see.
|
|
18
|
+
*
|
|
19
|
+
* ClearKey is built in — it is the only key system testable headlessly.
|
|
20
|
+
* Widevine, PlayReady, and FairPlay arrive as handlers eme-cenc and
|
|
21
|
+
* eme-fairplay register through drm-shared.
|
|
22
|
+
*/
|
|
5
23
|
const CLEARKEY = "org.w3.clearkey";
|
|
6
|
-
function bytesToBase64Url(bytes) {
|
|
7
|
-
let binary = "";
|
|
8
|
-
for (const b of bytes) binary += String.fromCharCode(b);
|
|
9
|
-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
10
|
-
}
|
|
11
24
|
/** A ClearKey handler: the license is a JSON the app answers from its keys. */
|
|
12
25
|
function clearKeyHandler(clearKeys) {
|
|
13
26
|
return {
|
|
@@ -106,13 +119,16 @@ function emeCore(options = {}) {
|
|
|
106
119
|
const handlers = allHandlers();
|
|
107
120
|
const ordered = options.preferredKeySystems ? [...handlers].sort((a, b) => options.preferredKeySystems.indexOf(a.keySystem) - options.preferredKeySystems.indexOf(b.keySystem)) : handlers;
|
|
108
121
|
const candidates = preferredSystemIds.length > 0 ? ordered.filter((h) => h.systemIds.some((id) => preferredSystemIds.includes(id))) : ordered;
|
|
122
|
+
let lastError;
|
|
109
123
|
for (const candidate of candidates.length > 0 ? candidates : ordered) try {
|
|
110
124
|
var _candidate$fairplay;
|
|
111
125
|
const keys = yield (yield navigator.requestMediaKeySystemAccess(candidate.keySystem, accessConfig(candidate))).createMediaKeys();
|
|
112
126
|
if (disposed) return false;
|
|
113
127
|
if (((_candidate$fairplay = candidate.fairplay) === null || _candidate$fairplay === void 0 ? void 0 : _candidate$fairplay.certificateUrl) !== void 0) {
|
|
114
|
-
const
|
|
115
|
-
yield
|
|
128
|
+
const url = candidate.fairplay.certificateUrl;
|
|
129
|
+
const response = yield ctx.request(url, {});
|
|
130
|
+
if (!response.ok) throw new Error(`certificate ${url}: HTTP ${response.status}`);
|
|
131
|
+
yield keys.setServerCertificate(yield response.arrayBuffer());
|
|
116
132
|
}
|
|
117
133
|
yield element.setMediaKeys(keys);
|
|
118
134
|
mediaKeys = keys;
|
|
@@ -120,8 +136,10 @@ function emeCore(options = {}) {
|
|
|
120
136
|
handler = candidate;
|
|
121
137
|
ctx.emit("drm:keysystem", { keySystem });
|
|
122
138
|
return true;
|
|
123
|
-
} catch (
|
|
124
|
-
|
|
139
|
+
} catch (err) {
|
|
140
|
+
lastError = err;
|
|
141
|
+
}
|
|
142
|
+
fail("DRM_KEY_SYSTEM_UNAVAILABLE", false, lastError);
|
|
125
143
|
return false;
|
|
126
144
|
});
|
|
127
145
|
return _ensureKeys.apply(this, arguments);
|
|
@@ -133,7 +151,7 @@ function emeCore(options = {}) {
|
|
|
133
151
|
function _openSession() {
|
|
134
152
|
_openSession = _asyncToGenerator(function* (initDataType, initData) {
|
|
135
153
|
if (mediaKeys === null || handler === null || disposed) return;
|
|
136
|
-
const fingerprint = `${initDataType}:${
|
|
154
|
+
const fingerprint = `${initDataType}:${bytesToBase64(new Uint8Array(initData), true)}`;
|
|
137
155
|
if (initDataSeen.has(fingerprint)) return;
|
|
138
156
|
initDataSeen.add(fingerprint);
|
|
139
157
|
let session;
|
|
@@ -196,7 +214,7 @@ function emeCore(options = {}) {
|
|
|
196
214
|
}
|
|
197
215
|
function onKeyStatus(session) {
|
|
198
216
|
session.keyStatuses.forEach((status, keyIdBuffer) => {
|
|
199
|
-
const keyId =
|
|
217
|
+
const keyId = bytesToBase64(new Uint8Array(keyIdBuffer), true);
|
|
200
218
|
statuses.set(keyId, status);
|
|
201
219
|
sessionsByKey.set(keyId, session);
|
|
202
220
|
ctx.emit("drm:keystatus", {
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import _objectSpread2 from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
|
|
2
|
+
import { base64ToBytes, bytesToBase64 } from "../../kernel/base64.js";
|
|
2
3
|
import { registerKeySystem } from "../drm-shared.js";
|
|
3
4
|
//#region src/stages/eme-fairplay/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* FairPlay Streaming: the non-standard SPC/CKC flow. Safari only, and it
|
|
7
|
+
* differs from CENC enough to warrant its own stage — the CDM message is
|
|
8
|
+
* an SPC to POST as form data, the response is a CKC, and the content id
|
|
9
|
+
* comes from the skd:// URI the hls parser stored in licenseUrl. Registers
|
|
10
|
+
* a handler; eme-core drives it, including the certificate fetch.
|
|
11
|
+
*/
|
|
4
12
|
const FAIRPLAY_SYSTEM_ID = "94ce86fb-07ff-4f43-adb8-93d2fa968ca2";
|
|
5
13
|
/** The content id from a skd:// init data blob: the URI's opaque tail. */
|
|
6
14
|
function contentIdFromSkd(initData) {
|
|
@@ -10,9 +18,7 @@ function contentIdFromSkd(initData) {
|
|
|
10
18
|
}
|
|
11
19
|
/** Wraps the SPC as the `spc=` form body Apple's key servers expect. */
|
|
12
20
|
function buildSpcRequest(message) {
|
|
13
|
-
|
|
14
|
-
for (const b of new Uint8Array(message)) binary += String.fromCharCode(b);
|
|
15
|
-
const spc = btoa(binary);
|
|
21
|
+
const spc = bytesToBase64(new Uint8Array(message));
|
|
16
22
|
return new TextEncoder().encode(`spc=${encodeURIComponent(spc)}`);
|
|
17
23
|
}
|
|
18
24
|
/** Decodes a CKC form/base64 response into the bytes session.update wants. */
|
|
@@ -22,10 +28,8 @@ function parseCkcResponse(response) {
|
|
|
22
28
|
const b64 = (_exec$ = (_exec = /^ckc=(.+)$/.exec(text)) === null || _exec === void 0 ? void 0 : _exec[1]) !== null && _exec$ !== void 0 ? _exec$ : /^[A-Za-z0-9+/=]+$/.test(text) ? text : null;
|
|
23
29
|
if (b64 === null) return response;
|
|
24
30
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
|
|
28
|
-
return bytes;
|
|
31
|
+
var _base64ToBytes;
|
|
32
|
+
return (_base64ToBytes = base64ToBytes(decodeURIComponent(b64))) !== null && _base64ToBytes !== void 0 ? _base64ToBytes : response;
|
|
29
33
|
} catch (_unused) {
|
|
30
34
|
return response;
|
|
31
35
|
}
|