mattebox 0.6.0 → 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 +75 -7
- package/dist/containers/mp4-box/index.d.ts.map +1 -1
- package/dist/containers/mp4-box/index.js +225 -49
- 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 +9 -27
- 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 +11 -2
- 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/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/asyncToGenerator.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/defineProperty.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectSpread2.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectWithoutProperties.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectWithoutPropertiesLoose.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPrimitive.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPropertyKey.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/typeof.js +1 -1
- 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 +3 -3
- package/dist/es2015/containers/mp4-box/index.js +224 -39
- package/dist/es2015/containers/packed-audio/index.js +6 -33
- 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 +2 -18
- package/dist/es2015/containers/ts-transmux/index.js +9 -9
- 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 +40 -42
- package/dist/es2015/kernel/append-queue.js +1 -1
- package/dist/es2015/kernel/base64.js +25 -0
- package/dist/es2015/kernel/context.js +7 -0
- package/dist/es2015/kernel/effects.js +21 -1
- package/dist/es2015/kernel/loader.js +5 -4
- package/dist/es2015/kernel/mime.js +5 -1
- package/dist/es2015/kernel/mse.js +27 -71
- package/dist/es2015/kernel/prepare.js +77 -0
- package/dist/es2015/kernel/presentation.js +24 -0
- package/dist/es2015/kernel/reducer.js +279 -124
- package/dist/es2015/kernel/refresh.js +35 -0
- package/dist/es2015/kernel/rendition-select.js +109 -4
- package/dist/es2015/kernel/scheduler.js +23 -5
- package/dist/es2015/kernel/sinks/text-track-sink.js +27 -26
- package/dist/es2015/kernel/timeline.js +22 -1
- package/dist/es2015/kernel/trace.js +1 -1
- package/dist/es2015/kernel/track-registry.js +10 -2
- package/dist/es2015/kernel/transport.js +4 -4
- package/dist/es2015/kernel/url.js +12 -0
- package/dist/es2015/presets/define.js +2 -2
- package/dist/es2015/presets/full/index.js +9 -3
- package/dist/es2015/presets/tiers.js +7 -6
- package/dist/es2015/protocols/adapter-shared.js +28 -0
- package/dist/es2015/protocols/dash-cmaf/index.js +132 -88
- package/dist/es2015/protocols/dash-cmaf/parse.js +62 -64
- package/dist/es2015/protocols/dash-live/index.js +62 -37
- package/dist/es2015/protocols/dimensions.js +15 -0
- package/dist/es2015/protocols/hls-cmaf/index.js +108 -95
- package/dist/es2015/protocols/hls-cmaf/lexer.js +3 -0
- package/dist/es2015/protocols/hls-cmaf/parse.js +167 -56
- package/dist/es2015/protocols/hls-cmaf/unavailable.js +43 -0
- package/dist/es2015/protocols/hls-live/index.js +187 -109
- package/dist/es2015/stages/abr/index.js +8 -11
- package/dist/es2015/stages/abr-persist/index.js +18 -11
- package/dist/es2015/stages/aes-128/index.js +15 -8
- package/dist/es2015/stages/alt-audio/index.js +25 -13
- package/dist/es2015/stages/chapters/index.js +151 -0
- package/dist/es2015/stages/chapters/parse.js +149 -0
- package/dist/es2015/stages/cmaf-timing/index.js +24 -39
- package/dist/es2015/stages/cmcd/index.js +29 -6
- package/dist/es2015/stages/codec-switch/index.js +2 -5
- package/dist/es2015/stages/content-steering/index.js +13 -16
- package/dist/es2015/stages/eme-cenc/index.js +10 -4
- package/dist/es2015/stages/eme-core/index.js +31 -13
- package/dist/es2015/stages/eme-fairplay/index.js +12 -8
- package/dist/es2015/stages/nal-scan/index.js +30 -140
- package/dist/es2015/stages/recovery/index.js +47 -54
- package/dist/es2015/stages/text-cea608/decode.js +1 -1
- 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 +213 -43
- 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 +36 -53
- 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/context.d.ts +5 -1
- package/dist/kernel/context.d.ts.map +1 -1
- package/dist/kernel/context.js +10 -0
- package/dist/kernel/context.js.map +1 -1
- 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/loader.d.ts.map +1 -1
- package/dist/kernel/loader.js +5 -7
- package/dist/kernel/loader.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/mse.d.ts +6 -10
- package/dist/kernel/mse.d.ts.map +1 -1
- package/dist/kernel/mse.js +20 -73
- package/dist/kernel/mse.js.map +1 -1
- package/dist/kernel/prepare.d.ts +28 -0
- package/dist/kernel/prepare.d.ts.map +1 -0
- package/dist/kernel/prepare.js +89 -0
- package/dist/kernel/prepare.js.map +1 -0
- 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 +24 -0
- package/dist/kernel/reducer.d.ts.map +1 -1
- package/dist/kernel/reducer.js +375 -152
- package/dist/kernel/reducer.js.map +1 -1
- package/dist/kernel/refresh.d.ts +14 -0
- package/dist/kernel/refresh.d.ts.map +1 -0
- package/dist/kernel/refresh.js +51 -0
- package/dist/kernel/refresh.js.map +1 -0
- package/dist/kernel/rendition-select.d.ts +38 -5
- package/dist/kernel/rendition-select.d.ts.map +1 -1
- package/dist/kernel/rendition-select.js +134 -2
- package/dist/kernel/rendition-select.js.map +1 -1
- package/dist/kernel/scheduler.d.ts +18 -3
- package/dist/kernel/scheduler.d.ts.map +1 -1
- package/dist/kernel/scheduler.js +32 -7
- package/dist/kernel/scheduler.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 +26 -7
- package/dist/kernel/timeline.d.ts.map +1 -1
- package/dist/kernel/timeline.js +21 -7
- 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/transport.d.ts.map +1 -1
- package/dist/kernel/transport.js +1 -0
- package/dist/kernel/transport.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/presets/tiers.d.ts +7 -6
- package/dist/presets/tiers.d.ts.map +1 -1
- package/dist/presets/tiers.js +7 -6
- package/dist/presets/tiers.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 +2 -2
- package/dist/protocols/dash-cmaf/index.d.ts.map +1 -1
- package/dist/protocols/dash-cmaf/index.js +150 -97
- 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 +67 -25
- 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 +3 -2
- package/dist/protocols/hls-cmaf/index.d.ts.map +1 -1
- package/dist/protocols/hls-cmaf/index.js +127 -114
- 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 +22 -14
- package/dist/protocols/hls-cmaf/parse.d.ts.map +1 -1
- package/dist/protocols/hls-cmaf/parse.js +196 -69
- package/dist/protocols/hls-cmaf/parse.js.map +1 -1
- package/dist/protocols/hls-cmaf/unavailable.d.ts +17 -0
- package/dist/protocols/hls-cmaf/unavailable.d.ts.map +1 -0
- package/dist/protocols/hls-cmaf/unavailable.js +38 -0
- package/dist/protocols/hls-cmaf/unavailable.js.map +1 -0
- package/dist/protocols/hls-live/index.d.ts +17 -0
- package/dist/protocols/hls-live/index.d.ts.map +1 -1
- package/dist/protocols/hls-live/index.js +202 -106
- 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 +15 -13
- 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 +28 -15
- 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/cmaf-timing/index.d.ts.map +1 -1
- package/dist/stages/cmaf-timing/index.js +33 -42
- package/dist/stages/cmaf-timing/index.js.map +1 -1
- 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 +30 -12
- 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 +41 -13
- package/dist/types/kernel.d.ts.map +1 -1
- package/dist/types/kernel.js +2 -1
- package/dist/types/kernel.js.map +1 -1
- package/dist/types/messages.d.ts +61 -10
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/stage.d.ts +18 -0
- package/dist/types/stage.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
package/dist/kernel/reducer.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The pure kernel reducer. reduce(state, msg) returns [nextState, effects]
|
|
3
|
+
* and nothing else: no clocks, no randomness, no I/O. Time enters as fields
|
|
4
|
+
* on facts; effect tokens come from a counter in state.
|
|
5
|
+
*
|
|
6
|
+
* A command may be rejected: unchanged state plus an emit effect describing
|
|
7
|
+
* the rejection. A fact is never rejected: facts that make no sense in the
|
|
8
|
+
* current state are absorbed and ignored, because the world already moved.
|
|
9
|
+
*/
|
|
10
|
+
import { APPENDED_MEMORY } from '../types/kernel.js';
|
|
11
|
+
import { tickAfter } from './effects.js';
|
|
12
|
+
import { normalizeMimeType, typeString } from './mime.js';
|
|
13
|
+
import { findRendition, findTrackSite, isTrick } from './presentation.js';
|
|
14
|
+
import { applyRefresh } from './refresh.js';
|
|
15
|
+
import { availableGroups, canSwitchTo, codecFamily, createArbiter, planPinApply, withDeadGroups, } from './rendition-select.js';
|
|
3
16
|
import { bufferedEndFrom, schedule } from './scheduler.js';
|
|
4
17
|
import { sbIdFor } from './sinks/mse-sink.js';
|
|
5
|
-
import { segmentAtTime } from './timeline.js';
|
|
18
|
+
import { reconciledOffset, segmentAtTime } from './timeline.js';
|
|
6
19
|
import { DEFAULT_TRACE_CAPACITY } from './trace.js';
|
|
7
20
|
/**
|
|
8
21
|
* The default tuning. Every value is overridable through the `config`
|
|
@@ -29,7 +42,6 @@ export const DEFAULT_KERNEL_CONFIG = {
|
|
|
29
42
|
// Long enough that a recovery stage's zero-delay commands apply first,
|
|
30
43
|
// short enough that a retry without recovery still feels prompt.
|
|
31
44
|
baseRetryDelayMs: 400,
|
|
32
|
-
mediaTimeNormalized: false,
|
|
33
45
|
};
|
|
34
46
|
export function resolveConfig(config) {
|
|
35
47
|
return { ...DEFAULT_KERNEL_CONFIG, ...config };
|
|
@@ -39,7 +51,7 @@ export function initialState(config) {
|
|
|
39
51
|
return {
|
|
40
52
|
lifecycle: { phase: 'idle' },
|
|
41
53
|
presentation: null,
|
|
42
|
-
timeline: { periodOffsets: new Map(), discontinuitySeq: 0 },
|
|
54
|
+
timeline: { periodOffsets: new Map(), discontinuitySeq: 0, reconciled: new Map() },
|
|
43
55
|
buffers: new Map(),
|
|
44
56
|
bufferErrors: new Map(),
|
|
45
57
|
cues: new Map(),
|
|
@@ -130,20 +142,6 @@ function clearRepeat(scheduling) {
|
|
|
130
142
|
function ewma(previous, sample, alpha) {
|
|
131
143
|
return previous === 0 ? sample : alpha * sample + (1 - alpha) * previous;
|
|
132
144
|
}
|
|
133
|
-
/** Companion groups present, as `contentType:groupId`, for the coupling filter. */
|
|
134
|
-
function availableGroups(state) {
|
|
135
|
-
const groups = new Set();
|
|
136
|
-
for (const period of state.presentation?.periods ?? []) {
|
|
137
|
-
for (const track of period.tracks) {
|
|
138
|
-
if (track.contentType !== 'audio' && track.contentType !== 'text')
|
|
139
|
-
continue;
|
|
140
|
-
const colon = track.id.indexOf(':');
|
|
141
|
-
const group = colon === -1 ? track.id : track.id.slice(0, colon);
|
|
142
|
-
groups.add(`${track.contentType}:${group}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return groups;
|
|
146
|
-
}
|
|
147
145
|
/** Merges one span into a sorted coverage list, coalescing overlaps. */
|
|
148
146
|
function mergeCoverage(coverage, added) {
|
|
149
147
|
const merged = [];
|
|
@@ -162,25 +160,65 @@ function mergeCoverage(coverage, added) {
|
|
|
162
160
|
merged.push(pending);
|
|
163
161
|
return merged.sort((a, b) => a.start - b.start);
|
|
164
162
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
163
|
+
/**
|
|
164
|
+
* The spans `before` holds and `after` does not. Browsers round the ranges
|
|
165
|
+
* they report, so a loss narrower than the gap tolerance is that rounding.
|
|
166
|
+
*/
|
|
167
|
+
function lostSpans(before, after) {
|
|
168
|
+
const held = [...after].sort((a, b) => a.start - b.start);
|
|
169
|
+
const lost = [];
|
|
170
|
+
for (const range of before) {
|
|
171
|
+
let cursor = range.start;
|
|
172
|
+
for (const kept of held) {
|
|
173
|
+
if (kept.end <= cursor)
|
|
174
|
+
continue;
|
|
175
|
+
if (kept.start >= range.end)
|
|
176
|
+
break;
|
|
177
|
+
if (kept.start - cursor >= GAP_TOLERANCE)
|
|
178
|
+
lost.push({ start: cursor, end: kept.start });
|
|
179
|
+
cursor = kept.end;
|
|
172
180
|
}
|
|
181
|
+
if (range.end - cursor >= GAP_TOLERANCE)
|
|
182
|
+
lost.push({ start: cursor, end: range.end });
|
|
173
183
|
}
|
|
174
|
-
return
|
|
184
|
+
return lost;
|
|
175
185
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
186
|
+
/** The buffers without what they remember receiving: one buffer, or all of them. */
|
|
187
|
+
function forgetAppended(buffers, only) {
|
|
188
|
+
const next = new Map(buffers);
|
|
189
|
+
for (const [sbId, buffer] of buffers) {
|
|
190
|
+
if (buffer.appended === undefined || (only !== undefined && sbId !== only))
|
|
191
|
+
continue;
|
|
192
|
+
const { appended: _appended, ...rest } = buffer;
|
|
193
|
+
next.set(sbId, rest);
|
|
182
194
|
}
|
|
183
|
-
return
|
|
195
|
+
return next;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The buffers after the flushes among `effects`. A flush is an unbounded
|
|
199
|
+
* remove, and it forgets every segment that ends past its start: the next
|
|
200
|
+
* append there starts a new run, so a segment that left nothing the first
|
|
201
|
+
* time can land whole the second time. Lost content cannot say this, a
|
|
202
|
+
* segment that left nothing has none to lose. A bounded remove is eviction
|
|
203
|
+
* and reports through its updateend.
|
|
204
|
+
*/
|
|
205
|
+
function forgetFlushed(buffers, effects) {
|
|
206
|
+
let next = buffers;
|
|
207
|
+
for (const effect of effects) {
|
|
208
|
+
if (effect.kind !== 'remove' || effect.end !== Number.POSITIVE_INFINITY)
|
|
209
|
+
continue;
|
|
210
|
+
const buffer = next.get(effect.sbId);
|
|
211
|
+
if (buffer?.appended === undefined)
|
|
212
|
+
continue;
|
|
213
|
+
const appended = buffer.appended.filter((seg) => seg.end <= effect.start);
|
|
214
|
+
if (appended.length === buffer.appended.length)
|
|
215
|
+
continue;
|
|
216
|
+
next = new Map(next).set(effect.sbId, { ...buffer, appended });
|
|
217
|
+
}
|
|
218
|
+
return next;
|
|
219
|
+
}
|
|
220
|
+
function findTrack(presentation, trackId) {
|
|
221
|
+
return findTrackSite(presentation, trackId)?.track ?? null;
|
|
184
222
|
}
|
|
185
223
|
/**
|
|
186
224
|
* The first candidate whose segment list places a boundary around `time`.
|
|
@@ -193,19 +231,6 @@ function findTrackSite(presentation, trackId) {
|
|
|
193
231
|
function segmentedAt(candidates, time, periodStart) {
|
|
194
232
|
return candidates.find((rendition) => rendition !== undefined && segmentAtTime(rendition.segments, time, periodStart) !== null);
|
|
195
233
|
}
|
|
196
|
-
function findRendition(presentation, renditionId) {
|
|
197
|
-
if (presentation === null)
|
|
198
|
-
return null;
|
|
199
|
-
for (const period of presentation.periods) {
|
|
200
|
-
for (const track of period.tracks) {
|
|
201
|
-
for (const rendition of track.renditions) {
|
|
202
|
-
if (rendition.id === renditionId)
|
|
203
|
-
return { rendition, track, period };
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
234
|
/**
|
|
210
235
|
* Whether a completed request feeds the throughput estimate: only media of
|
|
211
236
|
* the lead track (video where there is one, else audio). An audio segment
|
|
@@ -331,8 +356,15 @@ function reduceCommand(state, msg, cfg, hooks) {
|
|
|
331
356
|
const to = state.live === null
|
|
332
357
|
? msg.to
|
|
333
358
|
: Math.min(Math.max(msg.to, state.live.span.start), state.live.edge);
|
|
359
|
+
// The target is the position from now on: a command that follows in
|
|
360
|
+
// the same turn (a track switch) plans around it, not around the time
|
|
361
|
+
// the element last reported.
|
|
334
362
|
return [
|
|
335
|
-
{
|
|
363
|
+
{
|
|
364
|
+
...next,
|
|
365
|
+
playback: { ...next.playback, currentTime: to, seeking: true },
|
|
366
|
+
scheduling: clearRepeat(next.scheduling),
|
|
367
|
+
},
|
|
336
368
|
[...aborts, { kind: 'seekElement', to }],
|
|
337
369
|
];
|
|
338
370
|
}
|
|
@@ -354,6 +386,12 @@ function reduceCommand(state, msg, cfg, hooks) {
|
|
|
354
386
|
if (track === null) {
|
|
355
387
|
return reject(state, msg.type, `unknown track: ${msg.trackId}`);
|
|
356
388
|
}
|
|
389
|
+
// A track the browser cannot decode would fail its buffer.
|
|
390
|
+
const undecodableIds = state.quality.constraints.get(CODECS)?.excludeIds ?? [];
|
|
391
|
+
if (track.renditions.length > 0 &&
|
|
392
|
+
track.renditions.every((r) => undecodableIds.includes(r.id))) {
|
|
393
|
+
return reject(state, msg.type, `undecodable track: ${msg.trackId}`);
|
|
394
|
+
}
|
|
357
395
|
const previous = state.tracks.active.get(track.contentType);
|
|
358
396
|
const active = new Map(state.tracks.active);
|
|
359
397
|
active.set(track.contentType, track.id);
|
|
@@ -368,7 +406,7 @@ function reduceCommand(state, msg, cfg, hooks) {
|
|
|
368
406
|
// playback until the new track's first segment lands. The element is
|
|
369
407
|
// not nudged for audio: a video decoder holds stale frames, an audio
|
|
370
408
|
// one does not.
|
|
371
|
-
const site =
|
|
409
|
+
const site = findTrackSite(state.presentation, track.id);
|
|
372
410
|
const previousTrack = previous === undefined ? null : findTrack(state.presentation, previous);
|
|
373
411
|
const flushRendition = site === null
|
|
374
412
|
? undefined
|
|
@@ -380,21 +418,31 @@ function reduceCommand(state, msg, cfg, hooks) {
|
|
|
380
418
|
flushRendition !== undefined) {
|
|
381
419
|
const sbId = sbIdFor(track.contentType);
|
|
382
420
|
const buffer = state.buffers.get(sbId);
|
|
421
|
+
// Trick frames and normal frames never share the buffer: a switch
|
|
422
|
+
// to or from an I-frame track clears all of it, behind the playhead
|
|
423
|
+
// too, and restarts the decoder where the playhead is.
|
|
424
|
+
const trickSwitch = track.contentType === 'video' &&
|
|
425
|
+
(isTrick(track) || (previousTrack !== null && isTrick(previousTrack)));
|
|
383
426
|
if (buffer !== undefined) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
427
|
+
if (trickSwitch) {
|
|
428
|
+
effects.push({ kind: 'remove', sbId, start: 0, end: Number.POSITIVE_INFINITY }, { kind: 'seekElement', to: state.playback.currentTime });
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
const plan = planPinApply({
|
|
432
|
+
strategy: msg.apply ?? 'now',
|
|
433
|
+
currentTime: state.playback.currentTime,
|
|
434
|
+
ranges: buffer.ranges,
|
|
435
|
+
sbId,
|
|
436
|
+
trackId: track.id,
|
|
437
|
+
inflightTokens: [],
|
|
438
|
+
period: site.period,
|
|
439
|
+
rendition: flushRendition,
|
|
440
|
+
tokenSeq: state.scheduling.tokenSeq,
|
|
441
|
+
});
|
|
442
|
+
for (const effect of plan.effects) {
|
|
443
|
+
if (effect.kind !== 'seekElement' || track.contentType === 'video') {
|
|
444
|
+
effects.push(effect);
|
|
445
|
+
}
|
|
398
446
|
}
|
|
399
447
|
}
|
|
400
448
|
// Force an init re-fetch for the new track: its initFor no
|
|
@@ -547,11 +595,108 @@ function reduceCommand(state, msg, cfg, hooks) {
|
|
|
547
595
|
}
|
|
548
596
|
return [{ ...state, scheduling: { ...state.scheduling, bufferGoal: msg.seconds } }, []];
|
|
549
597
|
}
|
|
598
|
+
case 'RESOLVE_RENDITION': {
|
|
599
|
+
if (findRendition(state.presentation, msg.renditionId) === null) {
|
|
600
|
+
return reject(state, msg.type, `unknown rendition: ${msg.renditionId}`);
|
|
601
|
+
}
|
|
602
|
+
if (state.tracks.resolve?.has(msg.renditionId))
|
|
603
|
+
return [state, []];
|
|
604
|
+
const resolve = new Set(state.tracks.resolve ?? []).add(msg.renditionId);
|
|
605
|
+
// The quality version moves so the adapters look at the selection again.
|
|
606
|
+
return [
|
|
607
|
+
{ ...state, tracks: { ...state.tracks, resolve }, quality: bumped(state.quality) },
|
|
608
|
+
[],
|
|
609
|
+
];
|
|
610
|
+
}
|
|
550
611
|
case 'ABORT_INFLIGHT': {
|
|
551
612
|
return abortInflight(state, msg.trackId);
|
|
552
613
|
}
|
|
553
614
|
}
|
|
554
615
|
}
|
|
616
|
+
/** The constraint source for renditions this browser cannot decode. */
|
|
617
|
+
const CODECS = 'codecs';
|
|
618
|
+
/**
|
|
619
|
+
* The renditions this browser cannot play: a declared codec it does not
|
|
620
|
+
* decode, and a video variant whose audio group it cannot decode at all.
|
|
621
|
+
* VHS drops these when the manifest loads; left in, ABR climbs onto one and
|
|
622
|
+
* its buffer fails to open or to append. A rendition that declares no
|
|
623
|
+
* codec counts as decodable.
|
|
624
|
+
*/
|
|
625
|
+
function undecodable(presentation, decodable) {
|
|
626
|
+
const out = new Set();
|
|
627
|
+
for (const period of presentation.periods) {
|
|
628
|
+
for (const track of period.tracks) {
|
|
629
|
+
if (track.contentType !== 'video' && track.contentType !== 'audio')
|
|
630
|
+
continue;
|
|
631
|
+
for (const r of track.renditions) {
|
|
632
|
+
if (r.codecs !== null && !decodable(typeString(r.mimeType, r.codecs)))
|
|
633
|
+
out.add(r.id);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
return withDeadGroups(presentation, out);
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* A presentation replaces the one held: a manifest landed, or a playlist
|
|
641
|
+
* merged into it. Activates default tracks and reports what changed.
|
|
642
|
+
*/
|
|
643
|
+
function loadPresentation(state, presentation, undecodableIds = new Set()) {
|
|
644
|
+
const available = [];
|
|
645
|
+
for (const period of presentation.periods) {
|
|
646
|
+
for (const track of period.tracks)
|
|
647
|
+
available.push(track.id);
|
|
648
|
+
}
|
|
649
|
+
const inflight = new Map(state.scheduling.inflight);
|
|
650
|
+
for (const [token, request] of inflight) {
|
|
651
|
+
if (request.trackId === 'manifest')
|
|
652
|
+
inflight.delete(token);
|
|
653
|
+
}
|
|
654
|
+
const phase = state.lifecycle.phase === 'loading' ? 'ready' : state.lifecycle.phase;
|
|
655
|
+
// Default activation: the first video and audio track the browser can
|
|
656
|
+
// decode, so a manifest alone yields a playable composition without a
|
|
657
|
+
// SELECT_TRACK.
|
|
658
|
+
const active = new Map(state.tracks.active);
|
|
659
|
+
for (const period of presentation.periods) {
|
|
660
|
+
for (const track of period.tracks) {
|
|
661
|
+
if ((track.contentType === 'video' || track.contentType === 'audio') &&
|
|
662
|
+
!isTrick(track) &&
|
|
663
|
+
!active.has(track.contentType) &&
|
|
664
|
+
track.renditions.some((r) => !undecodableIds.has(r.id))) {
|
|
665
|
+
active.set(track.contentType, track.id);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
const loaded = {
|
|
670
|
+
...state,
|
|
671
|
+
lifecycle: { phase },
|
|
672
|
+
presentation,
|
|
673
|
+
scheduling: { ...state.scheduling, inflight },
|
|
674
|
+
tracks: { ...state.tracks, active, available },
|
|
675
|
+
quality: bumped(state.quality),
|
|
676
|
+
};
|
|
677
|
+
// Every playlist merge lands here too; the track list only changed if
|
|
678
|
+
// the ids did.
|
|
679
|
+
const sameTracks = available.length === state.tracks.available.length &&
|
|
680
|
+
available.every((id, index) => id === state.tracks.available[index]);
|
|
681
|
+
const manifestEffects = sameTracks
|
|
682
|
+
? []
|
|
683
|
+
: [{ kind: 'emit', event: 'tracks:changed', payload: { available } }];
|
|
684
|
+
// The manifest DRM route: emit every track's protection schemes so
|
|
685
|
+
// eme-core (if loaded) can open sessions. Serializable init data
|
|
686
|
+
// rides the event; nothing DRM-specific enters the reducer.
|
|
687
|
+
const schemes = presentation.periods.flatMap((period) => period.tracks.flatMap((track) => track.protection?.schemes ?? []));
|
|
688
|
+
if (schemes.length > 0) {
|
|
689
|
+
manifestEffects.push({
|
|
690
|
+
kind: 'emit',
|
|
691
|
+
event: 'presentation:protection',
|
|
692
|
+
payload: schemes,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
if (!presentation.isLive && presentation.duration !== undefined) {
|
|
696
|
+
manifestEffects.push({ kind: 'setDuration', seconds: presentation.duration });
|
|
697
|
+
}
|
|
698
|
+
return [loaded, manifestEffects];
|
|
699
|
+
}
|
|
555
700
|
function reduceFact(state, msg, cfg, hooks) {
|
|
556
701
|
switch (msg.type) {
|
|
557
702
|
case 'ELEMENT_ATTACHED':
|
|
@@ -560,65 +705,48 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
560
705
|
// Lifecycle detail owned by the mse module. Absorbed for the trace.
|
|
561
706
|
return [state, []];
|
|
562
707
|
case 'MANIFEST_LOADED': {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
708
|
+
if (hooks.decodable === undefined)
|
|
709
|
+
return loadPresentation(state, msg.presentation);
|
|
710
|
+
const excluded = undecodable(msg.presentation, hooks.decodable);
|
|
711
|
+
// A trick track cannot stand in for the stream: it is never selected.
|
|
712
|
+
const tracks = msg.presentation.periods
|
|
713
|
+
.flatMap((period) => period.tracks)
|
|
714
|
+
.filter((track) => !isTrick(track));
|
|
715
|
+
const lead = ['video', 'audio'].find((c) => tracks.some((t) => t.contentType === c));
|
|
716
|
+
// Nothing to play: say so now, not after a buffer fails to open.
|
|
717
|
+
if (lead !== undefined &&
|
|
718
|
+
!tracks.some((t) => t.contentType === lead && t.renditions.some((r) => !excluded.has(r.id)))) {
|
|
719
|
+
const codecs = new Set(tracks.flatMap((t) => t.renditions.map((r) => r.codecs ?? '')));
|
|
720
|
+
codecs.delete('');
|
|
721
|
+
return failManifest(state, { category: 'media', code: 'MEDIA_CODEC_UNSUPPORTED', fatal: true, recoverable: false }, { codecs: [...codecs] });
|
|
572
722
|
}
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if ((track.contentType === 'video' || track.contentType === 'audio') &&
|
|
580
|
-
!active.has(track.contentType)) {
|
|
581
|
-
active.set(track.contentType, track.id);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
const loaded = {
|
|
586
|
-
...state,
|
|
587
|
-
lifecycle: { phase },
|
|
588
|
-
presentation: msg.presentation,
|
|
589
|
-
scheduling: { ...state.scheduling, inflight },
|
|
590
|
-
tracks: { active, available },
|
|
591
|
-
quality: bumped(state.quality),
|
|
592
|
-
};
|
|
593
|
-
// A live reload feeds a MANIFEST_LOADED per playlist; the track list
|
|
594
|
-
// only changed if the ids did.
|
|
595
|
-
const sameTracks = available.length === state.tracks.available.length &&
|
|
596
|
-
available.every((id, index) => id === state.tracks.available[index]);
|
|
597
|
-
const manifestEffects = sameTracks
|
|
598
|
-
? []
|
|
599
|
-
: [{ kind: 'emit', event: 'tracks:changed', payload: { available } }];
|
|
600
|
-
// The manifest DRM route: emit every track's protection schemes so
|
|
601
|
-
// eme-core (if loaded) can open sessions. Serializable init data
|
|
602
|
-
// rides the event; nothing DRM-specific enters the reducer.
|
|
603
|
-
const schemes = msg.presentation.periods.flatMap((period) => period.tracks.flatMap((track) => track.protection?.schemes ?? []));
|
|
604
|
-
if (schemes.length > 0) {
|
|
605
|
-
manifestEffects.push({
|
|
606
|
-
kind: 'emit',
|
|
607
|
-
event: 'presentation:protection',
|
|
608
|
-
payload: schemes,
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
if (!msg.presentation.isLive && msg.presentation.duration !== undefined) {
|
|
612
|
-
manifestEffects.push({ kind: 'setDuration', seconds: msg.presentation.duration });
|
|
613
|
-
}
|
|
614
|
-
return [loaded, manifestEffects];
|
|
723
|
+
const constraints = new Map(state.quality.constraints);
|
|
724
|
+
if (excluded.size > 0)
|
|
725
|
+
constraints.set(CODECS, { excludeIds: [...excluded] });
|
|
726
|
+
else
|
|
727
|
+
constraints.delete(CODECS);
|
|
728
|
+
return loadPresentation({ ...state, quality: { ...state.quality, constraints } }, msg.presentation, excluded);
|
|
615
729
|
}
|
|
616
730
|
case 'MANIFEST_FAILED':
|
|
617
731
|
return failManifest(state, msg.error);
|
|
618
|
-
case 'PLAYLIST_REFRESHED':
|
|
619
|
-
//
|
|
620
|
-
//
|
|
621
|
-
|
|
732
|
+
case 'PLAYLIST_REFRESHED': {
|
|
733
|
+
// Merged into the presentation held now, not a snapshot an adapter
|
|
734
|
+
// took earlier: another rendition may have merged in between.
|
|
735
|
+
const merged = state.presentation === null ? null : applyRefresh(state.presentation, msg);
|
|
736
|
+
if (merged === null)
|
|
737
|
+
return [state, []];
|
|
738
|
+
return loadPresentation(state, merged);
|
|
739
|
+
}
|
|
740
|
+
case 'MEDIA_ERROR': {
|
|
741
|
+
// The element gave up. An engine that already failed keeps its error.
|
|
742
|
+
if (state.lifecycle.phase === 'error')
|
|
743
|
+
return [state, []];
|
|
744
|
+
const [stopped, aborts] = abortInflight(state);
|
|
745
|
+
const [failed, report] = failManifest(stopped, { ...msg.error, fatal: true },
|
|
746
|
+
// The facade builds this context from the element's strings.
|
|
747
|
+
{ context: msg.error.context });
|
|
748
|
+
return [failed, [...aborts, ...report]];
|
|
749
|
+
}
|
|
622
750
|
case 'SEGMENT_LOADED': {
|
|
623
751
|
let matched = null;
|
|
624
752
|
if (msg.token !== undefined) {
|
|
@@ -710,7 +838,7 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
710
838
|
const declared = targetSite?.rendition.codecs ?? null;
|
|
711
839
|
const targetCodecs = targetSite === null || declared === null
|
|
712
840
|
? buffer.codecs
|
|
713
|
-
:
|
|
841
|
+
: typeString(targetSite.rendition.mimeType, declared);
|
|
714
842
|
const familyChanged = declared !== null &&
|
|
715
843
|
codecFamily(declared) !== codecFamily(bufferCodecString(buffer.codecs));
|
|
716
844
|
const nextBuffers = new Map(state.buffers);
|
|
@@ -765,32 +893,67 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
765
893
|
],
|
|
766
894
|
];
|
|
767
895
|
}
|
|
768
|
-
// The
|
|
769
|
-
//
|
|
896
|
+
// The offset this append takes. The first media segment to land in
|
|
897
|
+
// an epoch settles it for every buffer: its presentation start minus
|
|
898
|
+
// the decode time the probe read from its bytes, or the manifest's
|
|
899
|
+
// prediction when nothing read one. Later segments of the epoch,
|
|
900
|
+
// on any buffer, apply the settled value, so audio and video keep
|
|
901
|
+
// the alignment their shared media clock gives them: one offset per
|
|
902
|
+
// timeline, as videojs-http-streaming takes it from its main loader.
|
|
770
903
|
// Playlist discontinuities and period boundaries both land here.
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
904
|
+
let reconciled = state.timeline.reconciled;
|
|
905
|
+
let offset = matched.epoch === undefined ? undefined : reconciled.get(matched.epoch);
|
|
906
|
+
if (offset === undefined &&
|
|
907
|
+
matched.epoch !== undefined &&
|
|
908
|
+
matched.seq >= 0 &&
|
|
909
|
+
matched.segmentStart !== undefined) {
|
|
910
|
+
const settled = msg.mediaStart !== undefined
|
|
911
|
+
? reconciledOffset(matched.segmentStart, msg.mediaStart)
|
|
912
|
+
: matched.timestampOffset;
|
|
913
|
+
if (settled !== undefined) {
|
|
914
|
+
offset = settled;
|
|
915
|
+
reconciled = new Map(reconciled).set(matched.epoch, settled);
|
|
916
|
+
}
|
|
781
917
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
918
|
+
if (offset === undefined)
|
|
919
|
+
offset = matched.timestampOffset;
|
|
920
|
+
let periodOffsets = state.timeline.periodOffsets;
|
|
921
|
+
if (offset !== undefined && periodOffsets.get(matched.sbId) !== offset) {
|
|
922
|
+
effects.push({ kind: 'setTimestampOffset', sbId: matched.sbId, offset });
|
|
923
|
+
periodOffsets = new Map(periodOffsets).set(matched.sbId, offset);
|
|
924
|
+
}
|
|
925
|
+
if (periodOffsets !== state.timeline.periodOffsets ||
|
|
926
|
+
reconciled !== state.timeline.reconciled) {
|
|
927
|
+
timeline = { ...state.timeline, periodOffsets, reconciled };
|
|
928
|
+
}
|
|
929
|
+
effects.push({ kind: 'append', sbId: matched.sbId, data: msg.bytes });
|
|
790
930
|
const buffer = buffers.get(matched.sbId);
|
|
791
931
|
if (buffer !== undefined) {
|
|
792
932
|
const nextBuffers = new Map(buffers);
|
|
793
|
-
|
|
933
|
+
// What the buffer receives, so the scheduler never asks for it
|
|
934
|
+
// twice. Media only, and with the span it lands at, so a removal
|
|
935
|
+
// there can forget it.
|
|
936
|
+
let appended = buffer.appended;
|
|
937
|
+
const { renditionId, seq, segmentStart } = matched;
|
|
938
|
+
if (seq >= 0 && renditionId !== undefined && segmentStart !== undefined) {
|
|
939
|
+
const entry = {
|
|
940
|
+
renditionId,
|
|
941
|
+
seq,
|
|
942
|
+
start: segmentStart,
|
|
943
|
+
end: segmentStart + (matched.segmentDuration ?? 0),
|
|
944
|
+
};
|
|
945
|
+
appended = [
|
|
946
|
+
...(appended ?? [])
|
|
947
|
+
.filter((seg) => seg.seq !== seq || seg.renditionId !== renditionId)
|
|
948
|
+
.slice(1 - APPENDED_MEMORY),
|
|
949
|
+
entry,
|
|
950
|
+
];
|
|
951
|
+
}
|
|
952
|
+
nextBuffers.set(matched.sbId, {
|
|
953
|
+
...buffer,
|
|
954
|
+
pendingAppends: buffer.pendingAppends + 1,
|
|
955
|
+
...(appended !== undefined ? { appended } : {}),
|
|
956
|
+
});
|
|
794
957
|
buffers = nextBuffers;
|
|
795
958
|
}
|
|
796
959
|
if (matched.sbId === sbIdFor('video') &&
|
|
@@ -886,13 +1049,7 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
886
1049
|
// giving exclusion and skip time to change the decision. Without
|
|
887
1050
|
// recovery, the same segment retries until the breaker ends it.
|
|
888
1051
|
if (!isCueTrack) {
|
|
889
|
-
failEffects.push(
|
|
890
|
-
kind: 'schedule',
|
|
891
|
-
token: 'kernel:retry',
|
|
892
|
-
delayMs: cfg.baseRetryDelayMs,
|
|
893
|
-
// biome-ignore lint/suspicious/noThenProperty: `then` is the schedule effect's field name from the message taxonomy
|
|
894
|
-
then: { type: 'TICK', token: 'kernel:retry' },
|
|
895
|
-
});
|
|
1052
|
+
failEffects.push(tickAfter('kernel:retry', cfg.baseRetryDelayMs));
|
|
896
1053
|
}
|
|
897
1054
|
return [{ ...state, cues, scheduling: { ...state.scheduling, inflight } }, failEffects];
|
|
898
1055
|
}
|
|
@@ -917,10 +1074,23 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
917
1074
|
// The buffer was removed by a concurrent detach. Absorb and ignore.
|
|
918
1075
|
return [state, []];
|
|
919
1076
|
}
|
|
1077
|
+
// Content the buffer lost takes the memory of its segments with it.
|
|
1078
|
+
// Every removal reports here: a switch's flush, the evictor dropping
|
|
1079
|
+
// forward buffer under quota, the browser's own eviction during an
|
|
1080
|
+
// append. Those segments are gone and a fetch restores them, where a
|
|
1081
|
+
// segment that never left a usable range stays remembered.
|
|
1082
|
+
let appended = buffer.appended;
|
|
1083
|
+
if (appended !== undefined && msg.ranges !== undefined) {
|
|
1084
|
+
const lost = lostSpans(buffer.ranges, msg.ranges);
|
|
1085
|
+
if (lost.length > 0) {
|
|
1086
|
+
appended = appended.filter((seg) => !lost.some((span) => span.start <= seg.end && span.end >= seg.start));
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
920
1089
|
const buffers = new Map(state.buffers);
|
|
921
1090
|
buffers.set(msg.sbId, {
|
|
922
1091
|
...buffer,
|
|
923
1092
|
...(msg.ranges !== undefined ? { ranges: msg.ranges } : {}),
|
|
1093
|
+
...(appended !== undefined ? { appended } : {}),
|
|
924
1094
|
pendingAppends: Math.max(0, buffer.pendingAppends - 1),
|
|
925
1095
|
});
|
|
926
1096
|
// A successful append proves the buffer works: the breaker resets.
|
|
@@ -944,8 +1114,27 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
944
1114
|
// The buffer never opened, so nothing holds its init any more: the
|
|
945
1115
|
// next decision fetches it again.
|
|
946
1116
|
const scheduling = withPendingInit(state.scheduling, withoutPendingInit(state.scheduling.pendingInit, msg.sbId));
|
|
1117
|
+
// The buffer did not keep what it was handed, or never got it: a
|
|
1118
|
+
// failed append, or a transform that threw before the append. The
|
|
1119
|
+
// parser also starts over (MSE append error algorithm, reset parser
|
|
1120
|
+
// state), so what the buffer received before says nothing about the
|
|
1121
|
+
// next append. The failed segment is fetched again, and the breaker
|
|
1122
|
+
// above counts it.
|
|
1123
|
+
let buffers = forgetAppended(state.buffers, msg.sbId);
|
|
947
1124
|
const fatal = msg.error.fatal || count >= cfg.bufferErrorLimit;
|
|
948
1125
|
const phase = fatal ? 'error' : state.lifecycle.phase;
|
|
1126
|
+
// A transform that threw never reached the buffer, so no updateend
|
|
1127
|
+
// reports for that append: this fact does. Without it the track waits
|
|
1128
|
+
// on the append and never schedules again. A parser error is followed
|
|
1129
|
+
// by its updateend (MSE append error algorithm), which reports.
|
|
1130
|
+
const neverAppended = msg.error.code === 'MEDIA_CONTAINER_INVALID';
|
|
1131
|
+
const waiting = buffers.get(msg.sbId);
|
|
1132
|
+
if (neverAppended && waiting !== undefined && waiting.pendingAppends > 0) {
|
|
1133
|
+
buffers = new Map(buffers).set(msg.sbId, {
|
|
1134
|
+
...waiting,
|
|
1135
|
+
pendingAppends: waiting.pendingAppends - 1,
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
949
1138
|
const effects = [
|
|
950
1139
|
{
|
|
951
1140
|
kind: 'emit',
|
|
@@ -960,6 +1149,11 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
960
1149
|
},
|
|
961
1150
|
},
|
|
962
1151
|
];
|
|
1152
|
+
if (neverAppended && !fatal) {
|
|
1153
|
+
// Nothing else re-drives: the refetch waits the same backoff a
|
|
1154
|
+
// failed fetch does, so recovery can change the decision first.
|
|
1155
|
+
effects.push(tickAfter('kernel:retry', cfg.baseRetryDelayMs));
|
|
1156
|
+
}
|
|
963
1157
|
let inflight = state.scheduling.inflight;
|
|
964
1158
|
if (fatal) {
|
|
965
1159
|
// Stop the world for this buffer: whatever is in flight will only
|
|
@@ -976,6 +1170,7 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
976
1170
|
return [
|
|
977
1171
|
{
|
|
978
1172
|
...state,
|
|
1173
|
+
buffers,
|
|
979
1174
|
bufferErrors,
|
|
980
1175
|
lifecycle: { phase },
|
|
981
1176
|
scheduling: { ...scheduling, inflight },
|
|
@@ -1001,10 +1196,13 @@ function reduceFact(state, msg, cfg, hooks) {
|
|
|
1001
1196
|
case 'SEEKING': {
|
|
1002
1197
|
// Seeking out of the ended phase resumes an ordinary ready state.
|
|
1003
1198
|
const phase = state.lifecycle.phase === 'ended' ? 'ready' : state.lifecycle.phase;
|
|
1199
|
+
// A seek starts the decisions over: what the buffers last received
|
|
1200
|
+
// no longer says anything about what the playhead needs.
|
|
1004
1201
|
return [
|
|
1005
1202
|
{
|
|
1006
1203
|
...state,
|
|
1007
1204
|
lifecycle: { phase },
|
|
1205
|
+
buffers: forgetAppended(state.buffers),
|
|
1008
1206
|
playback: { ...state.playback, currentTime: msg.to, seeking: true },
|
|
1009
1207
|
},
|
|
1010
1208
|
[],
|
|
@@ -1173,9 +1371,7 @@ function driveScheduling(state, hooks, cfg) {
|
|
|
1173
1371
|
// fetch is in flight the SOURCEBUFFER_CREATED fact is on its way, so
|
|
1174
1372
|
// re-requesting every tick would spam the trace.
|
|
1175
1373
|
if (!state.buffers.has(sbId) && inflight.length === 0) {
|
|
1176
|
-
const codecs = rendition.codecs
|
|
1177
|
-
? rendition.mimeType
|
|
1178
|
-
: `${rendition.mimeType}; codecs="${rendition.codecs}"`;
|
|
1374
|
+
const codecs = typeString(rendition.mimeType, rendition.codecs);
|
|
1179
1375
|
effects.push({ kind: 'createSourceBuffer', sbId, codecs });
|
|
1180
1376
|
}
|
|
1181
1377
|
// Init before media, always: while the buffer's init is not this
|
|
@@ -1192,6 +1388,7 @@ function driveScheduling(state, hooks, cfg) {
|
|
|
1192
1388
|
}
|
|
1193
1389
|
continue;
|
|
1194
1390
|
}
|
|
1391
|
+
const appended = state.buffers.get(sbId)?.appended;
|
|
1195
1392
|
tracks.push({
|
|
1196
1393
|
trackId,
|
|
1197
1394
|
period: found.period,
|
|
@@ -1199,6 +1396,7 @@ function driveScheduling(state, hooks, cfg) {
|
|
|
1199
1396
|
ranges: state.buffers.get(sbId)?.ranges ?? [],
|
|
1200
1397
|
sbId,
|
|
1201
1398
|
inflight,
|
|
1399
|
+
...(appended !== undefined ? { appended } : {}),
|
|
1202
1400
|
});
|
|
1203
1401
|
}
|
|
1204
1402
|
// Cue pipelines schedule like media, minus everything SourceBuffer:
|
|
@@ -1225,13 +1423,23 @@ function driveScheduling(state, hooks, cfg) {
|
|
|
1225
1423
|
inflight,
|
|
1226
1424
|
});
|
|
1227
1425
|
}
|
|
1426
|
+
// The lead buffer settles each epoch's offset: video when the
|
|
1427
|
+
// presentation has it, else audio. Its init and media requests count as
|
|
1428
|
+
// pending, so a companion track cannot settle the epoch from its own
|
|
1429
|
+
// bytes while the lead is still on its way there.
|
|
1430
|
+
const leadSbId = sbIdFor(state.tracks.active.has('video') ? 'video' : 'audio');
|
|
1431
|
+
const leadPending = initFetches.some((pending) => pending.sbId === leadSbId) ||
|
|
1432
|
+
[...state.scheduling.inflight.values()].some((request) => request.sbId === leadSbId);
|
|
1228
1433
|
const result = schedule({
|
|
1229
1434
|
currentTime: state.playback.currentTime,
|
|
1230
1435
|
bufferGoal: state.scheduling.bufferGoal,
|
|
1231
1436
|
tokenSeq: state.scheduling.tokenSeq + initFetches.length,
|
|
1232
1437
|
tracks,
|
|
1233
1438
|
liveWindow: state.presentation.isLive ? (state.live?.span ?? null) : null,
|
|
1234
|
-
|
|
1439
|
+
reconciles: hooks.timeProbe != null,
|
|
1440
|
+
leadSbId,
|
|
1441
|
+
reconciled: state.timeline.reconciled,
|
|
1442
|
+
leadPending,
|
|
1235
1443
|
});
|
|
1236
1444
|
// The scheduling breaker: an identical decision repeated past the limit
|
|
1237
1445
|
// means appends report success but nothing ever progresses, and the
|
|
@@ -1351,6 +1559,7 @@ const COMMAND_TYPES = {
|
|
|
1351
1559
|
CONSTRAIN: true,
|
|
1352
1560
|
RELEASE_CONSTRAINT: true,
|
|
1353
1561
|
SET_BUFFER_GOAL: true,
|
|
1562
|
+
RESOLVE_RENDITION: true,
|
|
1354
1563
|
ABORT_INFLIGHT: true,
|
|
1355
1564
|
};
|
|
1356
1565
|
export function isCommand(msg) {
|
|
@@ -1368,6 +1577,7 @@ export function createReducer(slices, config, hooks = {}) {
|
|
|
1368
1577
|
const cfg = resolveConfig(config);
|
|
1369
1578
|
const DRIVING_FACTS = new Set([
|
|
1370
1579
|
'MANIFEST_LOADED',
|
|
1580
|
+
'PLAYLIST_REFRESHED',
|
|
1371
1581
|
'SEGMENT_LOADED',
|
|
1372
1582
|
// A buffer that opens holding an init unblocks media scheduling, and
|
|
1373
1583
|
// nothing else would drive it on a paused element.
|
|
@@ -1400,7 +1610,9 @@ export function createReducer(slices, config, hooks = {}) {
|
|
|
1400
1610
|
// fetch next. TIME_UPDATE drives inside its own reduction; the others
|
|
1401
1611
|
// drive here, which is what makes startup work on a paused element
|
|
1402
1612
|
// that fires no timeupdate.
|
|
1403
|
-
|
|
1613
|
+
// A refresh that merged nothing changes nothing to drive.
|
|
1614
|
+
const merged = msg.type !== 'PLAYLIST_REFRESHED' || next.presentation !== state.presentation;
|
|
1615
|
+
if (!isCommand(msg) && DRIVING_FACTS.has(msg.type) && merged) {
|
|
1404
1616
|
const [driven, driveEffects] = driveScheduling(next, hooks, cfg);
|
|
1405
1617
|
next = driven;
|
|
1406
1618
|
if (driveEffects.length > 0)
|
|
@@ -1437,6 +1649,17 @@ export function createReducer(slices, config, hooks = {}) {
|
|
|
1437
1649
|
next = failed;
|
|
1438
1650
|
effects = [...effects, ...failEffects];
|
|
1439
1651
|
}
|
|
1652
|
+
// After the slices: a stage flushes too, recovery for one.
|
|
1653
|
+
const buffers = forgetFlushed(next.buffers, effects);
|
|
1654
|
+
if (buffers !== next.buffers)
|
|
1655
|
+
next = { ...next, buffers };
|
|
1656
|
+
// A failed engine starts nothing: no fetch, no timer, no append, from
|
|
1657
|
+
// the kernel or from any stage. Reports and aborts still go out. A
|
|
1658
|
+
// response or a timer already on its way lands here and ends here, so
|
|
1659
|
+
// every loop (playlist reloads, steering, retries) stops on its own.
|
|
1660
|
+
if (next.lifecycle.phase === 'error') {
|
|
1661
|
+
effects = effects.filter((effect) => effect.kind === 'emit' || effect.kind === 'abort');
|
|
1662
|
+
}
|
|
1440
1663
|
return [next, effects];
|
|
1441
1664
|
};
|
|
1442
1665
|
}
|