rx-player 4.5.0-dev.2026021900 → 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.
Files changed (100) hide show
  1. package/CHANGELOG.md +13 -3
  2. package/VERSION +1 -1
  3. package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
  4. package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
  5. package/dist/commonjs/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
  6. package/dist/commonjs/__GENERATED_CODE/embedded_worker.js +1 -1
  7. package/dist/commonjs/core/cmcd/cmcd_data_builder.js +2 -2
  8. package/dist/commonjs/core/entry/content_preparer.d.ts +1 -6
  9. package/dist/commonjs/core/entry/content_preparer.d.ts.map +1 -1
  10. package/dist/commonjs/core/entry/content_preparer.js +2 -125
  11. package/dist/commonjs/core/entry/core_entry.d.ts +1 -1
  12. package/dist/commonjs/core/entry/core_entry.d.ts.map +1 -1
  13. package/dist/commonjs/core/entry/core_entry.js +2 -7
  14. package/dist/commonjs/core/entry/core_text_displayer_interface.d.ts.map +1 -1
  15. package/dist/commonjs/core/entry/core_text_displayer_interface.js +3 -1
  16. package/dist/commonjs/core/entry/index.d.ts +1 -1
  17. package/dist/commonjs/core/entry/index.d.ts.map +1 -1
  18. package/dist/commonjs/core/entry/utils.d.ts +64 -0
  19. package/dist/commonjs/core/entry/utils.d.ts.map +1 -1
  20. package/dist/commonjs/core/entry/utils.js +165 -0
  21. package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts +5 -6
  22. package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts.map +1 -1
  23. package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
  24. package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.js +34 -30
  25. package/dist/commonjs/experimental/features/worker/index.d.ts +2 -1
  26. package/dist/commonjs/experimental/features/worker/index.d.ts.map +1 -1
  27. package/dist/commonjs/experimental/features/worker/index.js +4 -3
  28. package/dist/commonjs/main_thread/api/public_api.js +3 -3
  29. package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
  30. package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
  31. package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
  32. package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
  33. package/dist/es2017/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
  34. package/dist/es2017/__GENERATED_CODE/embedded_worker.js +1 -1
  35. package/dist/es2017/core/cmcd/cmcd_data_builder.js +2 -2
  36. package/dist/es2017/core/entry/content_preparer.d.ts +1 -6
  37. package/dist/es2017/core/entry/content_preparer.d.ts.map +1 -1
  38. package/dist/es2017/core/entry/content_preparer.js +1 -76
  39. package/dist/es2017/core/entry/core_entry.d.ts +1 -1
  40. package/dist/es2017/core/entry/core_entry.d.ts.map +1 -1
  41. package/dist/es2017/core/entry/core_entry.js +2 -7
  42. package/dist/es2017/core/entry/core_text_displayer_interface.d.ts.map +1 -1
  43. package/dist/es2017/core/entry/core_text_displayer_interface.js +3 -1
  44. package/dist/es2017/core/entry/index.d.ts +1 -1
  45. package/dist/es2017/core/entry/index.d.ts.map +1 -1
  46. package/dist/es2017/core/entry/utils.d.ts +64 -0
  47. package/dist/es2017/core/entry/utils.d.ts.map +1 -1
  48. package/dist/es2017/core/entry/utils.js +98 -0
  49. package/dist/es2017/core/fetchers/segment/segment_queue.d.ts +5 -6
  50. package/dist/es2017/core/fetchers/segment/segment_queue.d.ts.map +1 -1
  51. package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
  52. package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.js +21 -16
  53. package/dist/es2017/experimental/features/worker/index.d.ts +2 -1
  54. package/dist/es2017/experimental/features/worker/index.d.ts.map +1 -1
  55. package/dist/es2017/experimental/features/worker/index.js +2 -3
  56. package/dist/es2017/main_thread/api/public_api.js +3 -3
  57. package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
  58. package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
  59. package/dist/mpd-parser.wasm +0 -0
  60. package/dist/worker.js +8 -8
  61. package/package.json +19 -22
  62. package/src/__GENERATED_CODE/embedded_dash_wasm.ts +1 -1
  63. package/src/__GENERATED_CODE/embedded_worker.ts +1 -1
  64. package/src/core/adaptive/__tests__/adaptive_representation_selector.test.ts +734 -0
  65. package/src/core/adaptive/__tests__/guess_based_chooser.test.ts +5 -2
  66. package/src/core/adaptive/utils/__tests__/bandwidth_estimator.test.ts +117 -0
  67. package/src/core/adaptive/utils/__tests__/last_estimate_storage.test.ts +76 -0
  68. package/src/core/adaptive/utils/__tests__/pending_requests_store.test.ts +5 -2
  69. package/src/core/adaptive/utils/__tests__/representation_score_calculator.test.ts +4 -2
  70. package/src/core/cmcd/__tests__/cmcd_data_builder.test.ts +464 -0
  71. package/src/core/cmcd/cmcd_data_builder.ts +2 -2
  72. package/src/core/entry/__tests__/FreezeResolver.test.ts +1 -1
  73. package/src/core/entry/__tests__/content_time_boundaries_observer.test.ts +1 -2
  74. package/src/core/entry/__tests__/core_text_displayer_interface.test.ts +205 -0
  75. package/src/core/entry/__tests__/get_buffered_data_per_media_buffer.test.ts +95 -0
  76. package/src/core/entry/__tests__/track_choice_setter.test.ts +288 -0
  77. package/src/core/entry/__tests__/utils.test.ts +309 -0
  78. package/src/core/entry/content_preparer.ts +7 -118
  79. package/src/core/entry/core_entry.ts +7 -14
  80. package/src/core/entry/core_text_displayer_interface.ts +3 -1
  81. package/src/core/entry/index.ts +1 -1
  82. package/src/core/entry/utils.ts +151 -0
  83. package/src/core/fetchers/__tests__/cdn_prioritizer.test.ts +166 -0
  84. package/src/core/fetchers/manifest/__tests__/manifest_fetcher.test.ts +803 -0
  85. package/src/core/fetchers/segment/__tests__/segment_fetcher.test.ts +872 -0
  86. package/src/core/fetchers/segment/__tests__/segment_queue.test.ts +557 -0
  87. package/src/core/fetchers/segment/segment_queue.ts +5 -6
  88. package/src/core/fetchers/thumbnails/__tests__/thumbnail_fetcher.test.ts +435 -0
  89. package/src/core/fetchers/thumbnails/thumbnail_fetcher.ts +28 -20
  90. package/src/core/fetchers/utils/__tests__/schedule_request.test.ts +331 -0
  91. package/src/core/stream/adaptation/__tests__/get_representations_switch_strategy.test.ts +4 -3
  92. package/src/core/stream/representation/utils/__tests__/append_segment_to_buffer.test.ts +1 -1
  93. package/src/core/stream/representation/utils/__tests__/get_segment_priority.test.ts +1 -1
  94. package/src/core/stream/representation/utils/__tests__/push_init_segment.test.ts +1 -1
  95. package/src/core/stream/representation/utils/__tests__/push_media_segment.test.ts +1 -1
  96. package/src/experimental/features/worker/index.ts +2 -4
  97. package/src/main_thread/api/public_api.ts +3 -3
  98. package/src/mse/__tests__/main_media_source_interface.test.ts +846 -0
  99. package/src/parsers/texttracks/ttml/html/apply_line_height.ts +16 -1
  100. package/src/utils/__tests__/base64.test.ts +159 -191
@@ -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 { formatErrorForSender } from "./utils";
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
- }
@@ -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 synchronizeSegmentSinksOnObservation from "./synchronize_sinks_on_observation";
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.pushTextData.shift();
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;
@@ -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 "./content_preparer";
5
+ export type { ICorePlugins } from "./utils";
@@ -1,6 +1,36 @@
1
+ import { MediaSource_ } from "../../compat/browser_compatibility_types";
1
2
  import { formatError } from "../../errors";
3
+ import type { ICorePlaybackObservation } from "../../main_thread/init/utils/create_core_playback_observer";
4
+ import { createRepresentationFilterFromFnString } from "../../manifest";
5
+ import type Manifest from "../../manifest/classes";
6
+ import type {
7
+ IManifestLoader,
8
+ IRepresentationFilter,
9
+ ISegmentLoader,
10
+ } from "../../public_types";
11
+ import isNullOrUndefined from "../../utils/is_null_or_undefined";
12
+ import type SegmentSinksStore from "../segment_sinks";
2
13
  import type { ISentError } from "../types";
3
14
 
15
+ /**
16
+ * "Plugins" are a specific kind of API where an application can define complex
17
+ * functions that the RxPlayer will call in some normally-core aspects of media
18
+ * playback: e.g. loading segments.
19
+ *
20
+ * This interface lists them.
21
+ */
22
+ export interface ICorePlugins {
23
+ representationFilters: Map<string, IRepresentationFilter>;
24
+ segmentLoaders: Map<string, ISegmentLoader>;
25
+ manifestLoaders: Map<string, IManifestLoader>;
26
+ }
27
+
28
+ /**
29
+ * Format an error, which may be of any form, into an Object than can easily be
30
+ * serialized - e.g. to be communicated through a postMessage-like API.
31
+ * @param {*} error - The error to serialized
32
+ * @returns {Object} - A serialization-safe error format
33
+ */
4
34
  export function formatErrorForSender(error: unknown): ISentError {
5
35
  const formattedError = formatError(error, {
6
36
  defaultCode: "NONE",
@@ -9,3 +39,124 @@ export function formatErrorForSender(error: unknown): ISentError {
9
39
 
10
40
  return formattedError.serialize();
11
41
  }
42
+
43
+ /**
44
+ * Synchronize SegmentSinks with what has been buffered.
45
+ * @param {Object} observation - The just-received playback observation,
46
+ * including what has been buffered on lower-level buffers
47
+ * @param {Object} segmentSinksStore - Interface allowing to interact
48
+ * with `SegmentSink`s, so their inventory can be updated accordingly.
49
+ */
50
+ export function synchronizeSegmentSinksOnObservation(
51
+ observation: ICorePlaybackObservation,
52
+ segmentSinksStore: SegmentSinksStore,
53
+ ): void {
54
+ // Synchronize SegmentSinks with what has been buffered.
55
+ ["video" as const, "audio" as const, "text" as const].forEach((tType) => {
56
+ const segmentSinkStatus = segmentSinksStore.getStatus(tType);
57
+ if (segmentSinkStatus.type === "initialized") {
58
+ segmentSinkStatus.value.synchronizeInventory(observation.buffered[tType] ?? []);
59
+ }
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Set Representation.isCodecSupportedInWebWorker to true or false
65
+ * If the codec is supported in the current context.
66
+ * If MSE in worker is not available, the attribute is not set.
67
+ */
68
+ export function updateCodecSupportInWorkerMode(manifestToUpdate: Manifest) {
69
+ if (isNullOrUndefined(MediaSource_)) {
70
+ return;
71
+ }
72
+
73
+ const codecsMap = new Map<string, boolean>();
74
+ for (const period of manifestToUpdate.periods) {
75
+ const checkedAdaptations = [
76
+ ...(period.adaptations.video ?? []),
77
+ ...(period.adaptations.audio ?? []),
78
+ ];
79
+ for (const adaptation of checkedAdaptations) {
80
+ for (const representation of adaptation.representations) {
81
+ const codec = `${representation.mimeType};codecs="${representation.codecs[0]}"`;
82
+ if (codecsMap.has(codec)) {
83
+ representation.isCodecSupportedInWebWorker = codecsMap.get(codec);
84
+ } else {
85
+ const supported = MediaSource_.isTypeSupported(codec);
86
+ representation.isCodecSupportedInWebWorker = supported;
87
+ codecsMap.set(codec, supported);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Some functions may be defined by the API, we call those "plugins".
96
+ * This function parses and extract the actual function from the different
97
+ * ways an application can provide it to us.
98
+ * @param {Object} input - The API input
99
+ * @param {Object} corePlugins - Context on what identified functions are
100
+ * defined right now.
101
+ * @returns {Function}
102
+ */
103
+ export function extractExternalPlugins(
104
+ input: {
105
+ manifestLoader:
106
+ | {
107
+ fn?: IManifestLoader | undefined;
108
+ workerId?: string | undefined;
109
+ }
110
+ | undefined;
111
+ segmentLoader:
112
+ | {
113
+ fn?: ISegmentLoader | undefined;
114
+ workerId?: string | undefined;
115
+ }
116
+ | undefined;
117
+ representationFilter:
118
+ | undefined
119
+ | {
120
+ fn?: IRepresentationFilter | undefined;
121
+ eval?: string | undefined;
122
+ workerId?: string | undefined;
123
+ };
124
+ },
125
+ corePlugins: ICorePlugins,
126
+ ): {
127
+ manifestLoader: IManifestLoader | undefined;
128
+ segmentLoader: ISegmentLoader | undefined;
129
+ representationFilter: IRepresentationFilter | undefined;
130
+ } {
131
+ let manifestLoader;
132
+ let segmentLoader;
133
+ let representationFilter;
134
+ if (typeof input.representationFilter?.fn === "function") {
135
+ representationFilter = input.representationFilter.fn;
136
+ } else if (typeof input.representationFilter?.eval === "string") {
137
+ representationFilter = createRepresentationFilterFromFnString(
138
+ input.representationFilter.eval,
139
+ );
140
+ } else if (typeof input.representationFilter?.workerId === "string") {
141
+ representationFilter = corePlugins.representationFilters.get(
142
+ input.representationFilter.workerId,
143
+ );
144
+ }
145
+
146
+ if (typeof input.manifestLoader?.fn === "function") {
147
+ manifestLoader = input.manifestLoader.fn;
148
+ } else if (typeof input.manifestLoader?.workerId === "string") {
149
+ manifestLoader = corePlugins.manifestLoaders.get(input.manifestLoader.workerId);
150
+ }
151
+
152
+ if (typeof input.segmentLoader?.fn === "function") {
153
+ segmentLoader = input.segmentLoader.fn;
154
+ } else if (typeof input.segmentLoader?.workerId === "string") {
155
+ segmentLoader = corePlugins.segmentLoaders.get(input.segmentLoader.workerId);
156
+ }
157
+ return {
158
+ manifestLoader,
159
+ segmentLoader,
160
+ representationFilter,
161
+ };
162
+ }