rx-player 4.5.0-dev.2026012302 → 4.5.0-dev.2026031700
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/CHANGELOG.md +21 -3
- package/VERSION +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_worker.js +1 -1
- package/dist/commonjs/compat/should_seek_at_zero.d.ts +12 -0
- package/dist/commonjs/compat/should_seek_at_zero.d.ts.map +1 -0
- package/dist/commonjs/compat/should_seek_at_zero.js +23 -0
- package/dist/commonjs/core/cmcd/cmcd_data_builder.js +2 -2
- package/dist/commonjs/core/entry/FreezeResolver.js +2 -2
- package/dist/commonjs/core/entry/content_preparer.d.ts +1 -6
- package/dist/commonjs/core/entry/content_preparer.d.ts.map +1 -1
- package/dist/commonjs/core/entry/content_preparer.js +2 -125
- package/dist/commonjs/core/entry/content_time_boundaries_observer.d.ts.map +1 -1
- package/dist/commonjs/core/entry/content_time_boundaries_observer.js +8 -0
- package/dist/commonjs/core/entry/core_entry.d.ts +1 -1
- package/dist/commonjs/core/entry/core_entry.d.ts.map +1 -1
- package/dist/commonjs/core/entry/core_entry.js +2 -7
- package/dist/commonjs/core/entry/core_text_displayer_interface.d.ts.map +1 -1
- package/dist/commonjs/core/entry/core_text_displayer_interface.js +3 -1
- package/dist/commonjs/core/entry/index.d.ts +1 -1
- package/dist/commonjs/core/entry/index.d.ts.map +1 -1
- package/dist/commonjs/core/entry/utils.d.ts +64 -0
- package/dist/commonjs/core/entry/utils.d.ts.map +1 -1
- package/dist/commonjs/core/entry/utils.js +165 -0
- package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts +5 -6
- package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts.map +1 -1
- package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
- package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.js +34 -30
- package/dist/commonjs/core/stream/representation/encryption_data_notifier.d.ts +70 -0
- package/dist/commonjs/core/stream/representation/encryption_data_notifier.d.ts.map +1 -0
- package/dist/commonjs/core/stream/representation/encryption_data_notifier.js +107 -0
- package/dist/commonjs/core/stream/representation/representation_stream.d.ts.map +1 -1
- package/dist/commonjs/core/stream/representation/representation_stream.js +12 -60
- package/dist/commonjs/core/stream/representation/utils/get_needed_segments.js +1 -1
- package/dist/commonjs/default_config.d.ts +5 -0
- package/dist/commonjs/default_config.d.ts.map +1 -1
- package/dist/commonjs/default_config.js +5 -0
- package/dist/commonjs/experimental/features/worker/index.d.ts +2 -1
- package/dist/commonjs/experimental/features/worker/index.d.ts.map +1 -1
- package/dist/commonjs/experimental/features/worker/index.js +4 -3
- package/dist/commonjs/main_thread/api/public_api.d.ts.map +1 -1
- package/dist/commonjs/main_thread/api/public_api.js +28 -4
- package/dist/commonjs/main_thread/init/directfile_content_initializer.d.ts.map +1 -1
- package/dist/commonjs/main_thread/init/directfile_content_initializer.js +23 -1
- package/dist/commonjs/main_thread/init/utils/initial_seek_and_play.d.ts.map +1 -1
- package/dist/commonjs/main_thread/init/utils/initial_seek_and_play.js +3 -1
- package/dist/commonjs/manifest/classes/index.d.ts +2 -1
- package/dist/commonjs/manifest/classes/index.d.ts.map +1 -1
- package/dist/commonjs/manifest/classes/representation.d.ts +1 -1
- package/dist/commonjs/manifest/classes/representation.d.ts.map +1 -1
- package/dist/commonjs/manifest/classes/representation.js +2 -2
- package/dist/commonjs/manifest/classes/representation_index/types.d.ts +2 -2
- package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
- package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
- package/dist/commonjs/utils/base64.d.ts +15 -1
- package/dist/commonjs/utils/base64.d.ts.map +1 -1
- package/dist/commonjs/utils/base64.js +6 -0
- package/dist/commonjs/utils/ranges.d.ts +1 -1
- package/dist/commonjs/utils/ranges.js +1 -1
- package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
- package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
- package/dist/es2017/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
- package/dist/es2017/__GENERATED_CODE/embedded_worker.js +1 -1
- package/dist/es2017/compat/should_seek_at_zero.d.ts +12 -0
- package/dist/es2017/compat/should_seek_at_zero.d.ts.map +1 -0
- package/dist/es2017/compat/should_seek_at_zero.js +20 -0
- package/dist/es2017/core/cmcd/cmcd_data_builder.js +2 -2
- package/dist/es2017/core/entry/FreezeResolver.js +1 -1
- package/dist/es2017/core/entry/content_preparer.d.ts +1 -6
- package/dist/es2017/core/entry/content_preparer.d.ts.map +1 -1
- package/dist/es2017/core/entry/content_preparer.js +1 -76
- package/dist/es2017/core/entry/content_time_boundaries_observer.d.ts.map +1 -1
- package/dist/es2017/core/entry/content_time_boundaries_observer.js +8 -0
- package/dist/es2017/core/entry/core_entry.d.ts +1 -1
- package/dist/es2017/core/entry/core_entry.d.ts.map +1 -1
- package/dist/es2017/core/entry/core_entry.js +2 -7
- package/dist/es2017/core/entry/core_text_displayer_interface.d.ts.map +1 -1
- package/dist/es2017/core/entry/core_text_displayer_interface.js +3 -1
- package/dist/es2017/core/entry/index.d.ts +1 -1
- package/dist/es2017/core/entry/index.d.ts.map +1 -1
- package/dist/es2017/core/entry/utils.d.ts +64 -0
- package/dist/es2017/core/entry/utils.d.ts.map +1 -1
- package/dist/es2017/core/entry/utils.js +98 -0
- package/dist/es2017/core/fetchers/segment/segment_queue.d.ts +5 -6
- package/dist/es2017/core/fetchers/segment/segment_queue.d.ts.map +1 -1
- package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
- package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.js +21 -16
- package/dist/es2017/core/stream/representation/encryption_data_notifier.d.ts +70 -0
- package/dist/es2017/core/stream/representation/encryption_data_notifier.d.ts.map +1 -0
- package/dist/es2017/core/stream/representation/encryption_data_notifier.js +80 -0
- package/dist/es2017/core/stream/representation/representation_stream.d.ts.map +1 -1
- package/dist/es2017/core/stream/representation/representation_stream.js +10 -38
- package/dist/es2017/core/stream/representation/utils/get_needed_segments.js +1 -1
- package/dist/es2017/default_config.d.ts +5 -0
- package/dist/es2017/default_config.d.ts.map +1 -1
- package/dist/es2017/default_config.js +5 -0
- package/dist/es2017/experimental/features/worker/index.d.ts +2 -1
- package/dist/es2017/experimental/features/worker/index.d.ts.map +1 -1
- package/dist/es2017/experimental/features/worker/index.js +2 -3
- package/dist/es2017/main_thread/api/public_api.d.ts.map +1 -1
- package/dist/es2017/main_thread/api/public_api.js +28 -4
- package/dist/es2017/main_thread/init/directfile_content_initializer.d.ts.map +1 -1
- package/dist/es2017/main_thread/init/directfile_content_initializer.js +23 -1
- package/dist/es2017/main_thread/init/utils/initial_seek_and_play.d.ts.map +1 -1
- package/dist/es2017/main_thread/init/utils/initial_seek_and_play.js +3 -1
- package/dist/es2017/manifest/classes/index.d.ts +2 -1
- package/dist/es2017/manifest/classes/index.d.ts.map +1 -1
- package/dist/es2017/manifest/classes/representation.d.ts +1 -1
- package/dist/es2017/manifest/classes/representation.d.ts.map +1 -1
- package/dist/es2017/manifest/classes/representation.js +1 -1
- package/dist/es2017/manifest/classes/representation_index/types.d.ts +2 -2
- package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
- package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
- package/dist/es2017/utils/base64.d.ts +15 -1
- package/dist/es2017/utils/base64.d.ts.map +1 -1
- package/dist/es2017/utils/base64.js +6 -0
- package/dist/es2017/utils/ranges.d.ts +1 -1
- package/dist/es2017/utils/ranges.js +1 -1
- package/dist/mpd-parser.wasm +0 -0
- package/dist/worker.js +8 -8
- package/package.json +26 -23
- package/src/__GENERATED_CODE/embedded_dash_wasm.ts +1 -1
- package/src/__GENERATED_CODE/embedded_worker.ts +1 -1
- package/src/compat/should_seek_at_zero.ts +23 -0
- package/src/core/adaptive/__tests__/adaptive_representation_selector.test.ts +734 -0
- package/src/core/adaptive/__tests__/guess_based_chooser.test.ts +793 -0
- package/src/core/adaptive/__tests__/network_analyzer.test.ts +514 -0
- package/src/core/adaptive/utils/__tests__/bandwidth_estimator.test.ts +117 -0
- package/src/core/adaptive/utils/__tests__/last_estimate_storage.test.ts +76 -0
- package/src/core/adaptive/utils/__tests__/pending_requests_store.test.ts +288 -0
- package/src/core/adaptive/utils/__tests__/representation_score_calculator.test.ts +249 -0
- package/src/core/cmcd/__tests__/cmcd_data_builder.test.ts +464 -0
- package/src/core/cmcd/cmcd_data_builder.ts +2 -2
- package/src/core/entry/FreezeResolver.ts +1 -1
- package/src/core/entry/__tests__/FreezeResolver.test.ts +542 -0
- package/src/core/entry/__tests__/content_time_boundaries_observer.test.ts +867 -0
- package/src/core/entry/__tests__/core_text_displayer_interface.test.ts +205 -0
- package/src/core/entry/__tests__/get_buffered_data_per_media_buffer.test.ts +95 -0
- package/src/core/entry/__tests__/track_choice_setter.test.ts +288 -0
- package/src/core/entry/__tests__/utils.test.ts +309 -0
- package/src/core/entry/content_preparer.ts +7 -118
- package/src/core/entry/content_time_boundaries_observer.ts +10 -0
- package/src/core/entry/core_entry.ts +7 -14
- package/src/core/entry/core_text_displayer_interface.ts +3 -1
- package/src/core/entry/index.ts +1 -1
- package/src/core/entry/utils.ts +151 -0
- package/src/core/fetchers/__tests__/cdn_prioritizer.test.ts +166 -0
- package/src/core/fetchers/manifest/__tests__/manifest_fetcher.test.ts +803 -0
- package/src/core/fetchers/segment/__tests__/segment_fetcher.test.ts +872 -0
- package/src/core/fetchers/segment/__tests__/segment_queue.test.ts +557 -0
- package/src/core/fetchers/segment/segment_queue.ts +5 -6
- package/src/core/fetchers/thumbnails/__tests__/thumbnail_fetcher.test.ts +435 -0
- package/src/core/fetchers/thumbnails/thumbnail_fetcher.ts +28 -20
- package/src/core/fetchers/utils/__tests__/schedule_request.test.ts +331 -0
- package/src/core/stream/adaptation/__tests__/get_representations_switch_strategy.test.ts +593 -0
- package/src/core/stream/period/utils/__tests__/get_adaptation_switch_strategy.test.ts +646 -0
- package/src/core/stream/representation/__tests__/encryption_data_notifier.test.ts +531 -0
- package/src/core/stream/representation/encryption_data_notifier.ts +122 -0
- package/src/core/stream/representation/representation_stream.ts +11 -49
- package/src/core/stream/representation/utils/__tests__/append_segment_to_buffer.test.ts +321 -0
- package/src/core/stream/representation/utils/__tests__/check_for_discontinuity.test.ts +513 -0
- package/src/core/stream/representation/utils/__tests__/get_segment_priority.test.ts +132 -0
- package/src/core/stream/representation/utils/__tests__/push_init_segment.test.ts +209 -0
- package/src/core/stream/representation/utils/__tests__/push_media_segment.test.ts +343 -0
- package/src/core/stream/representation/utils/get_needed_segments.ts +1 -1
- package/src/default_config.ts +6 -0
- package/src/experimental/features/worker/index.ts +2 -4
- package/src/main_thread/api/public_api.ts +33 -4
- package/src/main_thread/init/directfile_content_initializer.ts +26 -1
- package/src/main_thread/init/utils/initial_seek_and_play.ts +5 -1
- package/src/manifest/classes/index.ts +2 -0
- package/src/manifest/classes/representation.ts +2 -1
- package/src/manifest/classes/representation_index/types.ts +2 -2
- package/src/mse/__tests__/main_media_source_interface.test.ts +846 -0
- package/src/parsers/texttracks/ttml/html/apply_line_height.ts +16 -1
- package/src/utils/__tests__/base64.test.ts +159 -191
- package/src/utils/base64.ts +30 -1
- package/src/utils/ranges.ts +1 -1
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
formatErrorForSender,
|
|
4
|
+
synchronizeSegmentSinksOnObservation,
|
|
5
|
+
updateCodecSupportInWorkerMode,
|
|
6
|
+
extractExternalPlugins,
|
|
7
|
+
} from "../utils";
|
|
8
|
+
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
12
|
+
|
|
13
|
+
const { mockFormatError, mockMediaSource_, mockCreateRepresentationFilter } = vi.hoisted(
|
|
14
|
+
() => {
|
|
15
|
+
return {
|
|
16
|
+
mockFormatError: vi.fn(),
|
|
17
|
+
mockMediaSource_: { isTypeSupported: vi.fn() },
|
|
18
|
+
mockCreateRepresentationFilter: vi.fn(),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
vi.mock("../../../errors", () => ({
|
|
23
|
+
formatError: mockFormatError,
|
|
24
|
+
}));
|
|
25
|
+
vi.mock("../../../compat/browser_compatibility_types", () => ({
|
|
26
|
+
MediaSource_: mockMediaSource_,
|
|
27
|
+
}));
|
|
28
|
+
vi.mock("../../../manifest", () => ({
|
|
29
|
+
createRepresentationFilterFromFnString: mockCreateRepresentationFilter,
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
vi.resetAllMocks();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("formatErrorForSender", () => {
|
|
37
|
+
it("should call formatError with the error and default options, then serialize", () => {
|
|
38
|
+
const mockSerialize = vi
|
|
39
|
+
.fn()
|
|
40
|
+
.mockReturnValue({ code: "NONE", message: "An unknown error" });
|
|
41
|
+
mockFormatError.mockReturnValue({ serialize: mockSerialize });
|
|
42
|
+
|
|
43
|
+
const result = formatErrorForSender(new Error("test"));
|
|
44
|
+
|
|
45
|
+
expect(mockFormatError).toHaveBeenCalledWith(new Error("test"), {
|
|
46
|
+
defaultCode: "NONE",
|
|
47
|
+
defaultReason: "An unknown error stopped content playback.",
|
|
48
|
+
});
|
|
49
|
+
expect(mockSerialize).toHaveBeenCalled();
|
|
50
|
+
expect(result).toEqual({ code: "NONE", message: "An unknown error" });
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("synchronizeSegmentSinksOnObservation", () => {
|
|
55
|
+
it("should call synchronizeInventory for initialized segment sinks", () => {
|
|
56
|
+
const syncInventory = vi.fn();
|
|
57
|
+
const segmentSinksStore = {
|
|
58
|
+
getStatus: vi.fn((type: string) => {
|
|
59
|
+
if (type === "video") {
|
|
60
|
+
return { type: "initialized", value: { synchronizeInventory: syncInventory } };
|
|
61
|
+
}
|
|
62
|
+
return { type: "not-initialized" };
|
|
63
|
+
}),
|
|
64
|
+
} as any;
|
|
65
|
+
|
|
66
|
+
const observation = {
|
|
67
|
+
buffered: {
|
|
68
|
+
video: [{ start: 0, end: 10 }],
|
|
69
|
+
audio: [],
|
|
70
|
+
text: [],
|
|
71
|
+
},
|
|
72
|
+
} as any;
|
|
73
|
+
|
|
74
|
+
synchronizeSegmentSinksOnObservation(observation, segmentSinksStore);
|
|
75
|
+
|
|
76
|
+
expect(syncInventory).toHaveBeenCalledTimes(1);
|
|
77
|
+
expect(syncInventory).toHaveBeenCalledWith([{ start: 0, end: 10 }]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should call synchronizeInventory for all initialized sinks with their buffered ranges", () => {
|
|
81
|
+
const videoSync = vi.fn();
|
|
82
|
+
const audioSync = vi.fn();
|
|
83
|
+
const textSync = vi.fn();
|
|
84
|
+
|
|
85
|
+
const segmentSinksStore = {
|
|
86
|
+
getStatus: vi.fn((type: string) => {
|
|
87
|
+
if (type === "video") {
|
|
88
|
+
return { type: "initialized", value: { synchronizeInventory: videoSync } };
|
|
89
|
+
}
|
|
90
|
+
if (type === "audio") {
|
|
91
|
+
return { type: "initialized", value: { synchronizeInventory: audioSync } };
|
|
92
|
+
}
|
|
93
|
+
if (type === "text") {
|
|
94
|
+
return { type: "initialized", value: { synchronizeInventory: textSync } };
|
|
95
|
+
}
|
|
96
|
+
return { type: "not-initialized" };
|
|
97
|
+
}),
|
|
98
|
+
} as any;
|
|
99
|
+
|
|
100
|
+
const observation = {
|
|
101
|
+
buffered: {
|
|
102
|
+
video: [{ start: 0, end: 5 }],
|
|
103
|
+
audio: [{ start: 1, end: 6 }],
|
|
104
|
+
text: undefined,
|
|
105
|
+
},
|
|
106
|
+
} as any;
|
|
107
|
+
|
|
108
|
+
synchronizeSegmentSinksOnObservation(observation, segmentSinksStore);
|
|
109
|
+
|
|
110
|
+
expect(videoSync).toHaveBeenCalledWith([{ start: 0, end: 5 }]);
|
|
111
|
+
expect(audioSync).toHaveBeenCalledWith([{ start: 1, end: 6 }]);
|
|
112
|
+
expect(textSync).toHaveBeenCalledWith([]); // undefined falls back to []
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("updateCodecSupportInWorkerMode", () => {
|
|
117
|
+
it("should do nothing if MediaSource_ is null", async () => {
|
|
118
|
+
// Re-import with MediaSource_ as null - we test indirectly
|
|
119
|
+
// by checking that isTypeSupported is never called when MediaSource_ is null
|
|
120
|
+
// This test verifies the null-guard works via a manifest with no periods
|
|
121
|
+
const manifest = { periods: [] } as any;
|
|
122
|
+
// Since we can't easily change the module-level import, we verify normal flow
|
|
123
|
+
updateCodecSupportInWorkerMode(manifest);
|
|
124
|
+
expect(mockMediaSource_.isTypeSupported).not.toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should set isCodecSupportedInWebWorker based on isTypeSupported", () => {
|
|
128
|
+
mockMediaSource_.isTypeSupported.mockImplementation((codec: string) => {
|
|
129
|
+
// eslint-disable-next-line no-restricted-properties
|
|
130
|
+
return codec.includes("avc1");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const videoRep = {
|
|
134
|
+
mimeType: "video/mp4",
|
|
135
|
+
codecs: ["avc1.42E01E"],
|
|
136
|
+
isCodecSupportedInWebWorker: undefined,
|
|
137
|
+
};
|
|
138
|
+
const audioRep = {
|
|
139
|
+
mimeType: "audio/mp4",
|
|
140
|
+
codecs: ["mp4a.40.2"],
|
|
141
|
+
isCodecSupportedInWebWorker: undefined,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const manifest = {
|
|
145
|
+
periods: [
|
|
146
|
+
{
|
|
147
|
+
adaptations: {
|
|
148
|
+
video: [{ representations: [videoRep] }],
|
|
149
|
+
audio: [{ representations: [audioRep] }],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
} as any;
|
|
154
|
+
|
|
155
|
+
updateCodecSupportInWorkerMode(manifest);
|
|
156
|
+
|
|
157
|
+
expect(videoRep.isCodecSupportedInWebWorker).toBe(true);
|
|
158
|
+
expect(audioRep.isCodecSupportedInWebWorker).toBe(false);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("should cache codec support results", () => {
|
|
162
|
+
mockMediaSource_.isTypeSupported.mockReturnValue(true);
|
|
163
|
+
|
|
164
|
+
const rep1 = {
|
|
165
|
+
mimeType: "video/mp4",
|
|
166
|
+
codecs: ["avc1.42E01E"],
|
|
167
|
+
isCodecSupportedInWebWorker: undefined,
|
|
168
|
+
};
|
|
169
|
+
const rep2 = {
|
|
170
|
+
mimeType: "video/mp4",
|
|
171
|
+
codecs: ["avc1.42E01E"],
|
|
172
|
+
isCodecSupportedInWebWorker: undefined,
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const manifest = {
|
|
176
|
+
periods: [
|
|
177
|
+
{
|
|
178
|
+
adaptations: {
|
|
179
|
+
video: [{ representations: [rep1, rep2] }],
|
|
180
|
+
audio: [],
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
} as any;
|
|
185
|
+
|
|
186
|
+
updateCodecSupportInWorkerMode(manifest);
|
|
187
|
+
|
|
188
|
+
expect(mockMediaSource_.isTypeSupported).toHaveBeenCalledTimes(1);
|
|
189
|
+
expect(rep1.isCodecSupportedInWebWorker).toBe(true);
|
|
190
|
+
expect(rep2.isCodecSupportedInWebWorker).toBe(true);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("extractExternalPlugins", () => {
|
|
195
|
+
const emptyCorePlugins = {
|
|
196
|
+
representationFilters: new Map(),
|
|
197
|
+
segmentLoaders: new Map(),
|
|
198
|
+
manifestLoaders: new Map(),
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
it("should return undefined for all when input has no loaders", () => {
|
|
202
|
+
const result = extractExternalPlugins(
|
|
203
|
+
{
|
|
204
|
+
manifestLoader: undefined,
|
|
205
|
+
segmentLoader: undefined,
|
|
206
|
+
representationFilter: undefined,
|
|
207
|
+
},
|
|
208
|
+
emptyCorePlugins,
|
|
209
|
+
);
|
|
210
|
+
expect(result).toEqual({
|
|
211
|
+
manifestLoader: undefined,
|
|
212
|
+
segmentLoader: undefined,
|
|
213
|
+
representationFilter: undefined,
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("should use fn directly when provided", () => {
|
|
218
|
+
const repFilter = vi.fn();
|
|
219
|
+
const manifestLoader = vi.fn();
|
|
220
|
+
const segmentLoader = vi.fn();
|
|
221
|
+
|
|
222
|
+
const result = extractExternalPlugins(
|
|
223
|
+
{
|
|
224
|
+
representationFilter: { fn: repFilter },
|
|
225
|
+
manifestLoader: { fn: manifestLoader },
|
|
226
|
+
segmentLoader: { fn: segmentLoader },
|
|
227
|
+
},
|
|
228
|
+
emptyCorePlugins,
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
expect(result.representationFilter).toBe(repFilter);
|
|
232
|
+
expect(result.manifestLoader).toBe(manifestLoader);
|
|
233
|
+
expect(result.segmentLoader).toBe(segmentLoader);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("should use eval string for representationFilter", () => {
|
|
237
|
+
const createdFilter = vi.fn();
|
|
238
|
+
mockCreateRepresentationFilter.mockReturnValue(createdFilter);
|
|
239
|
+
|
|
240
|
+
const result = extractExternalPlugins(
|
|
241
|
+
{
|
|
242
|
+
representationFilter: { eval: "some code" },
|
|
243
|
+
manifestLoader: undefined,
|
|
244
|
+
segmentLoader: undefined,
|
|
245
|
+
},
|
|
246
|
+
emptyCorePlugins,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
expect(mockCreateRepresentationFilter).toHaveBeenCalledWith("some code");
|
|
250
|
+
expect(result.representationFilter).toBe(createdFilter);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("should look up workerId in corePlugins maps", () => {
|
|
254
|
+
const workerRepFilter = vi.fn();
|
|
255
|
+
const workerManifestLoader = vi.fn();
|
|
256
|
+
const workerSegmentLoader = vi.fn();
|
|
257
|
+
|
|
258
|
+
const corePlugins = {
|
|
259
|
+
representationFilters: new Map([["rf-id", workerRepFilter]]),
|
|
260
|
+
segmentLoaders: new Map([["sl-id", workerSegmentLoader]]),
|
|
261
|
+
manifestLoaders: new Map([["ml-id", workerManifestLoader]]),
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const result = extractExternalPlugins(
|
|
265
|
+
{
|
|
266
|
+
representationFilter: { workerId: "rf-id" },
|
|
267
|
+
manifestLoader: { workerId: "ml-id" },
|
|
268
|
+
segmentLoader: { workerId: "sl-id" },
|
|
269
|
+
},
|
|
270
|
+
corePlugins,
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
expect(result.representationFilter).toBe(workerRepFilter);
|
|
274
|
+
expect(result.manifestLoader).toBe(workerManifestLoader);
|
|
275
|
+
expect(result.segmentLoader).toBe(workerSegmentLoader);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("should return undefined when workerId is not found in maps", () => {
|
|
279
|
+
const result = extractExternalPlugins(
|
|
280
|
+
{
|
|
281
|
+
representationFilter: { workerId: "unknown" },
|
|
282
|
+
manifestLoader: { workerId: "unknown" },
|
|
283
|
+
segmentLoader: { workerId: "unknown" },
|
|
284
|
+
},
|
|
285
|
+
emptyCorePlugins,
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
expect(result.representationFilter).toBeUndefined();
|
|
289
|
+
expect(result.manifestLoader).toBeUndefined();
|
|
290
|
+
expect(result.segmentLoader).toBeUndefined();
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("should prefer fn over eval and workerId for representationFilter", () => {
|
|
294
|
+
const fnFilter = vi.fn();
|
|
295
|
+
mockCreateRepresentationFilter.mockReturnValue(vi.fn());
|
|
296
|
+
|
|
297
|
+
const result = extractExternalPlugins(
|
|
298
|
+
{
|
|
299
|
+
representationFilter: { fn: fnFilter, eval: "some code", workerId: "rf-id" },
|
|
300
|
+
manifestLoader: undefined,
|
|
301
|
+
segmentLoader: undefined,
|
|
302
|
+
},
|
|
303
|
+
emptyCorePlugins,
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
expect(result.representationFilter).toBe(fnFilter);
|
|
307
|
+
expect(mockCreateRepresentationFilter).not.toHaveBeenCalled();
|
|
308
|
+
});
|
|
309
|
+
});
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import { MediaSource_ } from "../../compat/browser_compatibility_types";
|
|
2
1
|
import features from "../../features";
|
|
3
2
|
import log from "../../log";
|
|
4
3
|
import type { IContentInitializationData } from "../../main_thread/types";
|
|
5
4
|
import type { IManifest } from "../../manifest";
|
|
6
|
-
import { createRepresentationFilterFromFnString } from "../../manifest";
|
|
7
|
-
import type Manifest from "../../manifest/classes";
|
|
8
5
|
import type { IMediaSourceInterface } from "../../mse";
|
|
9
6
|
import MainMediaSourceInterface from "../../mse/main_media_source_interface";
|
|
10
7
|
import WorkerMediaSourceInterface from "../../mse/worker_media_source_interface";
|
|
11
|
-
import type {
|
|
12
|
-
IPlayerError,
|
|
13
|
-
IRepresentationFilter,
|
|
14
|
-
ISegmentLoader,
|
|
15
|
-
IManifestLoader,
|
|
16
|
-
} from "../../public_types";
|
|
8
|
+
import type { IPlayerError } from "../../public_types";
|
|
17
9
|
import idGenerator from "../../utils/id_generator";
|
|
18
|
-
import isNullOrUndefined from "../../utils/is_null_or_undefined";
|
|
19
10
|
import type { CancellationError, CancellationSignal } from "../../utils/task_canceller";
|
|
20
11
|
import TaskCanceller from "../../utils/task_canceller";
|
|
21
12
|
import type { IRepresentationEstimator } from "../adaptive";
|
|
@@ -33,7 +24,12 @@ import { CoreMessageType } from "../types";
|
|
|
33
24
|
import CoreTextDisplayerInterface from "./core_text_displayer_interface";
|
|
34
25
|
import FreezeResolver from "./FreezeResolver";
|
|
35
26
|
import TrackChoiceSetter from "./track_choice_setter";
|
|
36
|
-
import {
|
|
27
|
+
import type { ICorePlugins } from "./utils";
|
|
28
|
+
import {
|
|
29
|
+
extractExternalPlugins,
|
|
30
|
+
formatErrorForSender,
|
|
31
|
+
updateCodecSupportInWorkerMode,
|
|
32
|
+
} from "./utils";
|
|
37
33
|
|
|
38
34
|
/** Function allowing to associate a unique identifier to all created `MediaSource` */
|
|
39
35
|
const generateMediaSourceId = idGenerator();
|
|
@@ -463,12 +459,6 @@ export interface IPreparedContentData {
|
|
|
463
459
|
useMseInWorker: boolean;
|
|
464
460
|
}
|
|
465
461
|
|
|
466
|
-
export interface ICorePlugins {
|
|
467
|
-
representationFilters: Map<string, IRepresentationFilter>;
|
|
468
|
-
segmentLoaders: Map<string, ISegmentLoader>;
|
|
469
|
-
manifestLoaders: Map<string, IManifestLoader>;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
462
|
/**
|
|
473
463
|
* @param {Function} sendMessage
|
|
474
464
|
* @param {string} contentId
|
|
@@ -540,104 +530,3 @@ function createMediaSourceInterfaceAndSegmentSinksStore(
|
|
|
540
530
|
|
|
541
531
|
return [mediaSourceInterface, segmentSinksStore, textSender];
|
|
542
532
|
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Set Representation.isCodecSupportedInWebWorker to true or false
|
|
546
|
-
* If the codec is supported in the current context.
|
|
547
|
-
* If MSE in worker is not available, the attribute is not set.
|
|
548
|
-
*/
|
|
549
|
-
function updateCodecSupportInWorkerMode(manifestToUpdate: Manifest) {
|
|
550
|
-
if (isNullOrUndefined(MediaSource_)) {
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
const codecsMap = new Map<string, boolean>();
|
|
555
|
-
for (const period of manifestToUpdate.periods) {
|
|
556
|
-
const checkedAdaptations = [
|
|
557
|
-
...(period.adaptations.video ?? []),
|
|
558
|
-
...(period.adaptations.audio ?? []),
|
|
559
|
-
];
|
|
560
|
-
for (const adaptation of checkedAdaptations) {
|
|
561
|
-
for (const representation of adaptation.representations) {
|
|
562
|
-
const codec = `${representation.mimeType};codecs="${representation.codecs[0]}"`;
|
|
563
|
-
if (codecsMap.has(codec)) {
|
|
564
|
-
representation.isCodecSupportedInWebWorker = codecsMap.get(codec);
|
|
565
|
-
} else {
|
|
566
|
-
const supported = MediaSource_.isTypeSupported(codec);
|
|
567
|
-
representation.isCodecSupportedInWebWorker = supported;
|
|
568
|
-
codecsMap.set(codec, supported);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
/**
|
|
576
|
-
* Some functions may be defined by the API, we call those "plugins".
|
|
577
|
-
* This function parses and extract the actual function from the different
|
|
578
|
-
* ways an application can provide it to us.
|
|
579
|
-
* @param {Object} input - The API input
|
|
580
|
-
* @param {Object} corePlugins - Context on what identified functions are
|
|
581
|
-
* defined right now.
|
|
582
|
-
* @returns {Function}
|
|
583
|
-
*/
|
|
584
|
-
function extractExternalPlugins(
|
|
585
|
-
input: {
|
|
586
|
-
manifestLoader:
|
|
587
|
-
| {
|
|
588
|
-
fn?: IManifestLoader | undefined;
|
|
589
|
-
workerId?: string | undefined;
|
|
590
|
-
}
|
|
591
|
-
| undefined;
|
|
592
|
-
segmentLoader:
|
|
593
|
-
| {
|
|
594
|
-
fn?: ISegmentLoader | undefined;
|
|
595
|
-
workerId?: string | undefined;
|
|
596
|
-
}
|
|
597
|
-
| undefined;
|
|
598
|
-
representationFilter:
|
|
599
|
-
| undefined
|
|
600
|
-
| {
|
|
601
|
-
fn?: IRepresentationFilter | undefined;
|
|
602
|
-
eval?: string | undefined;
|
|
603
|
-
workerId?: string | undefined;
|
|
604
|
-
};
|
|
605
|
-
},
|
|
606
|
-
corePlugins: ICorePlugins,
|
|
607
|
-
): {
|
|
608
|
-
manifestLoader: IManifestLoader | undefined;
|
|
609
|
-
segmentLoader: ISegmentLoader | undefined;
|
|
610
|
-
representationFilter: IRepresentationFilter | undefined;
|
|
611
|
-
} {
|
|
612
|
-
let manifestLoader;
|
|
613
|
-
let segmentLoader;
|
|
614
|
-
let representationFilter;
|
|
615
|
-
if (typeof input.representationFilter?.fn === "function") {
|
|
616
|
-
representationFilter = input.representationFilter.fn;
|
|
617
|
-
} else if (typeof input.representationFilter?.eval === "string") {
|
|
618
|
-
representationFilter = createRepresentationFilterFromFnString(
|
|
619
|
-
input.representationFilter.eval,
|
|
620
|
-
);
|
|
621
|
-
} else if (typeof input.representationFilter?.workerId === "string") {
|
|
622
|
-
representationFilter = corePlugins.representationFilters.get(
|
|
623
|
-
input.representationFilter.workerId,
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
if (typeof input.manifestLoader?.fn === "function") {
|
|
628
|
-
manifestLoader = input.manifestLoader.fn;
|
|
629
|
-
} else if (typeof input.manifestLoader?.workerId === "string") {
|
|
630
|
-
manifestLoader = corePlugins.manifestLoaders.get(input.manifestLoader.workerId);
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
if (typeof input.segmentLoader?.fn === "function") {
|
|
634
|
-
segmentLoader = input.segmentLoader.fn;
|
|
635
|
-
} else if (typeof input.segmentLoader?.workerId === "string") {
|
|
636
|
-
segmentLoader = corePlugins.segmentLoaders.get(input.segmentLoader.workerId);
|
|
637
|
-
}
|
|
638
|
-
return {
|
|
639
|
-
manifestLoader,
|
|
640
|
-
segmentLoader,
|
|
641
|
-
representationFilter,
|
|
642
|
-
};
|
|
643
|
-
}
|
|
@@ -27,6 +27,7 @@ import type {
|
|
|
27
27
|
} from "../../manifest";
|
|
28
28
|
import type { IReadOnlyPlaybackObserver } from "../../playback_observer";
|
|
29
29
|
import type { IPlayerError } from "../../public_types";
|
|
30
|
+
import arrayIncludes from "../../utils/array_includes";
|
|
30
31
|
import EventEmitter from "../../utils/event_emitter";
|
|
31
32
|
import isNullOrUndefined from "../../utils/is_null_or_undefined";
|
|
32
33
|
import queueMicrotask from "../../utils/queue_microtask";
|
|
@@ -92,6 +93,15 @@ export default class ContentTimeBoundariesObserver extends EventEmitter<IContent
|
|
|
92
93
|
* whole content.
|
|
93
94
|
*/
|
|
94
95
|
const maximumPositionCalculator = new MaximumPositionCalculator(manifest);
|
|
96
|
+
|
|
97
|
+
// Indicate directly that no Adaptation of a particular type will be set
|
|
98
|
+
if (!arrayIncludes(this._allBufferTypes, "video")) {
|
|
99
|
+
maximumPositionCalculator.updateLastVideoAdaptation(null);
|
|
100
|
+
}
|
|
101
|
+
if (!arrayIncludes(this._allBufferTypes, "audio")) {
|
|
102
|
+
maximumPositionCalculator.updateLastAudioAdaptation(null);
|
|
103
|
+
}
|
|
104
|
+
|
|
95
105
|
this._maximumPositionCalculator = maximumPositionCalculator;
|
|
96
106
|
|
|
97
107
|
const cancelSignal = this._canceller.signal;
|
|
@@ -36,13 +36,12 @@ import type {
|
|
|
36
36
|
} from "../types";
|
|
37
37
|
import { CoreMessageType } from "../types";
|
|
38
38
|
import ContentPreparer from "./content_preparer";
|
|
39
|
-
import type { ICorePlugins } from "./content_preparer";
|
|
40
39
|
import createContentTimeBoundariesObserver from "./create_content_time_boundaries_observer";
|
|
41
40
|
import type { IFreezeResolution } from "./FreezeResolver";
|
|
42
41
|
import getBufferedDataPerMediaBuffer from "./get_buffered_data_per_media_buffer";
|
|
43
42
|
import getThumbnailData from "./get_thumbnail_data";
|
|
44
|
-
import
|
|
45
|
-
import { formatErrorForSender } from "./utils";
|
|
43
|
+
import type { ICorePlugins } from "./utils";
|
|
44
|
+
import { formatErrorForSender, synchronizeSegmentSinksOnObservation } from "./utils";
|
|
46
45
|
|
|
47
46
|
export type IMessageReceiverCallback = (evt: { data: IMainThreadMessage }) => void;
|
|
48
47
|
|
|
@@ -795,17 +794,6 @@ function loadPreparedContent(
|
|
|
795
794
|
},
|
|
796
795
|
|
|
797
796
|
adaptationChange(value) {
|
|
798
|
-
contentTimeBoundariesObserver.onAdaptationChange(
|
|
799
|
-
value.type,
|
|
800
|
-
value.period,
|
|
801
|
-
value.adaptation,
|
|
802
|
-
);
|
|
803
|
-
if (
|
|
804
|
-
currentLoadCanceller === null ||
|
|
805
|
-
currentLoadCanceller.signal.isCancelled()
|
|
806
|
-
) {
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
797
|
sendMessage({
|
|
810
798
|
type: CoreMessageType.AdaptationChanged,
|
|
811
799
|
contentId,
|
|
@@ -815,6 +803,11 @@ function loadPreparedContent(
|
|
|
815
803
|
type: value.type,
|
|
816
804
|
},
|
|
817
805
|
});
|
|
806
|
+
contentTimeBoundariesObserver.onAdaptationChange(
|
|
807
|
+
value.type,
|
|
808
|
+
value.period,
|
|
809
|
+
value.adaptation,
|
|
810
|
+
);
|
|
818
811
|
},
|
|
819
812
|
|
|
820
813
|
representationChange(value) {
|
|
@@ -104,9 +104,11 @@ export default class CoreTextDisplayerInterface implements ITextDisplayerInterfa
|
|
|
104
104
|
this._queues.pushTextData.forEach((elt) => {
|
|
105
105
|
elt.reject(error);
|
|
106
106
|
});
|
|
107
|
+
this._queues.pushTextData.length = 0;
|
|
107
108
|
this._queues.remove.forEach((elt) => {
|
|
108
109
|
elt.reject(error);
|
|
109
110
|
});
|
|
111
|
+
this._queues.remove.length = 0;
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
/**
|
|
@@ -149,7 +151,7 @@ export default class CoreTextDisplayerInterface implements ITextDisplayerInterfa
|
|
|
149
151
|
* @param {unknown} err
|
|
150
152
|
*/
|
|
151
153
|
public onRemoveError(err: Error): void {
|
|
152
|
-
const element = this._queues.
|
|
154
|
+
const element = this._queues.remove.shift();
|
|
153
155
|
if (element === undefined) {
|
|
154
156
|
log.error("text", "pushTextData error for inexistant operation");
|
|
155
157
|
return;
|
package/src/core/entry/index.ts
CHANGED
|
@@ -2,4 +2,4 @@ import type { IMessageReceiverCallback } from "./core_entry";
|
|
|
2
2
|
import initializeCoreEntry from "./core_entry";
|
|
3
3
|
export default initializeCoreEntry;
|
|
4
4
|
export type { IMessageReceiverCallback };
|
|
5
|
-
export type { ICorePlugins } from "./
|
|
5
|
+
export type { ICorePlugins } from "./utils";
|