@editframe/elements 0.26.2-beta.0 → 0.26.4-beta.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/elements/EFTimegroup.js +7 -2
- package/dist/elements/EFTimegroup.js.map +1 -1
- package/package.json +2 -2
- package/scripts/build-css.js +3 -3
- package/tsdown.config.ts +1 -1
- package/types.json +1 -1
- package/src/elements/ContextProxiesController.ts +0 -124
- package/src/elements/CrossUpdateController.ts +0 -22
- package/src/elements/EFAudio.browsertest.ts +0 -706
- package/src/elements/EFAudio.ts +0 -56
- package/src/elements/EFCaptions.browsertest.ts +0 -1960
- package/src/elements/EFCaptions.ts +0 -823
- package/src/elements/EFImage.browsertest.ts +0 -120
- package/src/elements/EFImage.ts +0 -113
- package/src/elements/EFMedia/AssetIdMediaEngine.test.ts +0 -224
- package/src/elements/EFMedia/AssetIdMediaEngine.ts +0 -110
- package/src/elements/EFMedia/AssetMediaEngine.browsertest.ts +0 -140
- package/src/elements/EFMedia/AssetMediaEngine.ts +0 -385
- package/src/elements/EFMedia/BaseMediaEngine.browsertest.ts +0 -400
- package/src/elements/EFMedia/BaseMediaEngine.ts +0 -505
- package/src/elements/EFMedia/BufferedSeekingInput.browsertest.ts +0 -386
- package/src/elements/EFMedia/BufferedSeekingInput.ts +0 -430
- package/src/elements/EFMedia/JitMediaEngine.browsertest.ts +0 -226
- package/src/elements/EFMedia/JitMediaEngine.ts +0 -256
- package/src/elements/EFMedia/audioTasks/makeAudioBufferTask.browsertest.ts +0 -679
- package/src/elements/EFMedia/audioTasks/makeAudioBufferTask.ts +0 -117
- package/src/elements/EFMedia/audioTasks/makeAudioFrequencyAnalysisTask.ts +0 -246
- package/src/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.browsertest.ts +0 -59
- package/src/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.ts +0 -27
- package/src/elements/EFMedia/audioTasks/makeAudioInputTask.browsertest.ts +0 -55
- package/src/elements/EFMedia/audioTasks/makeAudioInputTask.ts +0 -53
- package/src/elements/EFMedia/audioTasks/makeAudioSeekTask.chunkboundary.regression.browsertest.ts +0 -207
- package/src/elements/EFMedia/audioTasks/makeAudioSeekTask.ts +0 -72
- package/src/elements/EFMedia/audioTasks/makeAudioSegmentFetchTask.ts +0 -32
- package/src/elements/EFMedia/audioTasks/makeAudioSegmentIdTask.ts +0 -29
- package/src/elements/EFMedia/audioTasks/makeAudioTasksVideoOnly.browsertest.ts +0 -95
- package/src/elements/EFMedia/audioTasks/makeAudioTimeDomainAnalysisTask.ts +0 -184
- package/src/elements/EFMedia/shared/AudioSpanUtils.ts +0 -129
- package/src/elements/EFMedia/shared/BufferUtils.ts +0 -342
- package/src/elements/EFMedia/shared/GlobalInputCache.ts +0 -77
- package/src/elements/EFMedia/shared/MediaTaskUtils.ts +0 -44
- package/src/elements/EFMedia/shared/PrecisionUtils.ts +0 -46
- package/src/elements/EFMedia/shared/RenditionHelpers.browsertest.ts +0 -246
- package/src/elements/EFMedia/shared/RenditionHelpers.ts +0 -56
- package/src/elements/EFMedia/shared/ThumbnailExtractor.ts +0 -227
- package/src/elements/EFMedia/tasks/makeMediaEngineTask.browsertest.ts +0 -167
- package/src/elements/EFMedia/tasks/makeMediaEngineTask.ts +0 -88
- package/src/elements/EFMedia/videoTasks/MainVideoInputCache.ts +0 -76
- package/src/elements/EFMedia/videoTasks/ScrubInputCache.ts +0 -61
- package/src/elements/EFMedia/videoTasks/makeScrubVideoBufferTask.ts +0 -114
- package/src/elements/EFMedia/videoTasks/makeScrubVideoInitSegmentFetchTask.ts +0 -35
- package/src/elements/EFMedia/videoTasks/makeScrubVideoInputTask.ts +0 -52
- package/src/elements/EFMedia/videoTasks/makeScrubVideoSeekTask.ts +0 -124
- package/src/elements/EFMedia/videoTasks/makeScrubVideoSegmentFetchTask.ts +0 -44
- package/src/elements/EFMedia/videoTasks/makeScrubVideoSegmentIdTask.ts +0 -32
- package/src/elements/EFMedia/videoTasks/makeUnifiedVideoSeekTask.ts +0 -370
- package/src/elements/EFMedia/videoTasks/makeVideoBufferTask.ts +0 -109
- package/src/elements/EFMedia.browsertest.ts +0 -872
- package/src/elements/EFMedia.ts +0 -341
- package/src/elements/EFSourceMixin.ts +0 -60
- package/src/elements/EFSurface.browsertest.ts +0 -151
- package/src/elements/EFSurface.ts +0 -142
- package/src/elements/EFTemporal.browsertest.ts +0 -215
- package/src/elements/EFTemporal.ts +0 -800
- package/src/elements/EFThumbnailStrip.browsertest.ts +0 -585
- package/src/elements/EFThumbnailStrip.media-engine.browsertest.ts +0 -714
- package/src/elements/EFThumbnailStrip.ts +0 -906
- package/src/elements/EFTimegroup.browsertest.ts +0 -870
- package/src/elements/EFTimegroup.ts +0 -878
- package/src/elements/EFVideo.browsertest.ts +0 -1482
- package/src/elements/EFVideo.ts +0 -564
- package/src/elements/EFWaveform.ts +0 -547
- package/src/elements/FetchContext.browsertest.ts +0 -401
- package/src/elements/FetchMixin.ts +0 -38
- package/src/elements/SampleBuffer.ts +0 -94
- package/src/elements/TargetController.browsertest.ts +0 -230
- package/src/elements/TargetController.ts +0 -224
- package/src/elements/TimegroupController.ts +0 -26
- package/src/elements/durationConverter.ts +0 -35
- package/src/elements/parseTimeToMs.ts +0 -9
- package/src/elements/printTaskStatus.ts +0 -16
- package/src/elements/renderTemporalAudio.ts +0 -108
- package/src/elements/updateAnimations.browsertest.ts +0 -1884
- package/src/elements/updateAnimations.ts +0 -217
- package/src/elements/util.ts +0 -24
- package/src/gui/ContextMixin.browsertest.ts +0 -860
- package/src/gui/ContextMixin.ts +0 -562
- package/src/gui/Controllable.browsertest.ts +0 -258
- package/src/gui/Controllable.ts +0 -41
- package/src/gui/EFConfiguration.ts +0 -40
- package/src/gui/EFControls.browsertest.ts +0 -389
- package/src/gui/EFControls.ts +0 -195
- package/src/gui/EFDial.browsertest.ts +0 -84
- package/src/gui/EFDial.ts +0 -172
- package/src/gui/EFFilmstrip.browsertest.ts +0 -712
- package/src/gui/EFFilmstrip.ts +0 -1349
- package/src/gui/EFFitScale.ts +0 -152
- package/src/gui/EFFocusOverlay.ts +0 -79
- package/src/gui/EFPause.browsertest.ts +0 -202
- package/src/gui/EFPause.ts +0 -73
- package/src/gui/EFPlay.browsertest.ts +0 -202
- package/src/gui/EFPlay.ts +0 -73
- package/src/gui/EFPreview.ts +0 -74
- package/src/gui/EFResizableBox.browsertest.ts +0 -79
- package/src/gui/EFResizableBox.ts +0 -898
- package/src/gui/EFScrubber.ts +0 -151
- package/src/gui/EFTimeDisplay.browsertest.ts +0 -237
- package/src/gui/EFTimeDisplay.ts +0 -55
- package/src/gui/EFToggleLoop.ts +0 -35
- package/src/gui/EFTogglePlay.ts +0 -70
- package/src/gui/EFWorkbench.ts +0 -115
- package/src/gui/PlaybackController.ts +0 -527
- package/src/gui/TWMixin.css +0 -6
- package/src/gui/TWMixin.ts +0 -61
- package/src/gui/TargetOrContextMixin.ts +0 -185
- package/src/gui/currentTimeContext.ts +0 -5
- package/src/gui/durationContext.ts +0 -3
- package/src/gui/efContext.ts +0 -6
- package/src/gui/fetchContext.ts +0 -5
- package/src/gui/focusContext.ts +0 -7
- package/src/gui/focusedElementContext.ts +0 -5
- package/src/gui/playingContext.ts +0 -5
- package/src/otel/BridgeSpanExporter.ts +0 -150
- package/src/otel/setupBrowserTracing.ts +0 -73
- package/src/otel/tracingHelpers.ts +0 -251
- package/src/transcoding/cache/RequestDeduplicator.test.ts +0 -170
- package/src/transcoding/cache/RequestDeduplicator.ts +0 -65
- package/src/transcoding/cache/URLTokenDeduplicator.test.ts +0 -182
- package/src/transcoding/cache/URLTokenDeduplicator.ts +0 -101
- package/src/transcoding/types/index.ts +0 -312
- package/src/transcoding/utils/MediaUtils.ts +0 -63
- package/src/transcoding/utils/UrlGenerator.ts +0 -68
- package/src/transcoding/utils/constants.ts +0 -36
- package/src/utils/LRUCache.test.ts +0 -274
- package/src/utils/LRUCache.ts +0 -696
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { test as baseTest, describe, vi } from "vitest";
|
|
2
|
-
import type {
|
|
3
|
-
AudioRendition,
|
|
4
|
-
MediaEngine,
|
|
5
|
-
VideoRendition,
|
|
6
|
-
} from "../../../transcoding/types";
|
|
7
|
-
import { calculateSegmentRange, computeSegmentId } from "./RenditionHelpers";
|
|
8
|
-
|
|
9
|
-
const test = baseTest.extend<{
|
|
10
|
-
mockMediaEngine: MediaEngine;
|
|
11
|
-
mockVideoRendition: VideoRendition;
|
|
12
|
-
mockAudioRendition: AudioRendition;
|
|
13
|
-
mockMediaEngineWithoutAudio: MediaEngine;
|
|
14
|
-
mockMediaEngineWithoutVideo: MediaEngine;
|
|
15
|
-
}>({
|
|
16
|
-
mockMediaEngine: async ({}, use) => {
|
|
17
|
-
const mockVideoRendition = {
|
|
18
|
-
trackId: 1,
|
|
19
|
-
src: "video-track.mp4",
|
|
20
|
-
segmentDurationMs: 1000,
|
|
21
|
-
} as VideoRendition;
|
|
22
|
-
|
|
23
|
-
const mockAudioRendition = {
|
|
24
|
-
trackId: 2,
|
|
25
|
-
src: "audio-track.mp4",
|
|
26
|
-
segmentDurationMs: 1000,
|
|
27
|
-
} as AudioRendition;
|
|
28
|
-
|
|
29
|
-
const mockMediaEngine = {
|
|
30
|
-
durationMs: 10000,
|
|
31
|
-
src: "https://example.com/media.mp4",
|
|
32
|
-
videoRendition: mockVideoRendition,
|
|
33
|
-
audioRendition: mockAudioRendition,
|
|
34
|
-
getVideoRendition: () => mockVideoRendition,
|
|
35
|
-
getAudioRendition: () => mockAudioRendition,
|
|
36
|
-
fetchMediaSegment: vi.fn(),
|
|
37
|
-
} as unknown as MediaEngine;
|
|
38
|
-
await use(mockMediaEngine);
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
mockVideoRendition: async ({}, use) => {
|
|
42
|
-
const mockVideoRendition = {
|
|
43
|
-
trackId: 1,
|
|
44
|
-
src: "video-track.mp4",
|
|
45
|
-
segmentDurationMs: 1000,
|
|
46
|
-
} as VideoRendition;
|
|
47
|
-
await use(mockVideoRendition);
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
mockAudioRendition: async ({}, use) => {
|
|
51
|
-
const mockAudioRendition = {
|
|
52
|
-
trackId: 2,
|
|
53
|
-
src: "audio-track.mp4",
|
|
54
|
-
segmentDurationMs: 1000,
|
|
55
|
-
} as AudioRendition;
|
|
56
|
-
await use(mockAudioRendition);
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
mockMediaEngineWithoutAudio: async ({}, use) => {
|
|
60
|
-
const videoRendition = {
|
|
61
|
-
trackId: 1,
|
|
62
|
-
src: "video-track.mp4",
|
|
63
|
-
segmentDurationMs: 1000,
|
|
64
|
-
} as VideoRendition;
|
|
65
|
-
|
|
66
|
-
const mockMediaEngine = {
|
|
67
|
-
durationMs: 10000,
|
|
68
|
-
src: "https://example.com/media.mp4",
|
|
69
|
-
videoRendition,
|
|
70
|
-
audioRendition: undefined,
|
|
71
|
-
getVideoRendition: () => videoRendition,
|
|
72
|
-
getAudioRendition: () => undefined,
|
|
73
|
-
fetchMediaSegment: vi.fn(),
|
|
74
|
-
} as unknown as MediaEngine;
|
|
75
|
-
await use(mockMediaEngine);
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
mockMediaEngineWithoutVideo: async ({}, use) => {
|
|
79
|
-
const audioRendition = {
|
|
80
|
-
trackId: 2,
|
|
81
|
-
src: "audio-track.mp4",
|
|
82
|
-
segmentDurationMs: 1000,
|
|
83
|
-
} as AudioRendition;
|
|
84
|
-
|
|
85
|
-
const mockMediaEngine = {
|
|
86
|
-
durationMs: 10000,
|
|
87
|
-
src: "https://example.com/media.mp4",
|
|
88
|
-
videoRendition: undefined,
|
|
89
|
-
audioRendition,
|
|
90
|
-
getVideoRendition: () => undefined,
|
|
91
|
-
getAudioRendition: () => audioRendition,
|
|
92
|
-
fetchMediaSegment: vi.fn(),
|
|
93
|
-
} as unknown as MediaEngine;
|
|
94
|
-
await use(mockMediaEngine);
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe("RenditionHelpers", () => {
|
|
99
|
-
describe("MediaEngine Rendition Access", () => {
|
|
100
|
-
test("mediaEngine.getAudioRendition() returns undefined for video-only assets", ({
|
|
101
|
-
mockMediaEngineWithoutAudio,
|
|
102
|
-
expect,
|
|
103
|
-
}) => {
|
|
104
|
-
const result = mockMediaEngineWithoutAudio.getAudioRendition();
|
|
105
|
-
expect(result).toBeUndefined();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("mediaEngine.getVideoRendition() returns undefined for audio-only assets", ({
|
|
109
|
-
mockMediaEngineWithoutVideo,
|
|
110
|
-
expect,
|
|
111
|
-
}) => {
|
|
112
|
-
const result = mockMediaEngineWithoutVideo.getVideoRendition();
|
|
113
|
-
expect(result).toBeUndefined();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test("mediaEngine.getAudioRendition() returns rendition when available", ({
|
|
117
|
-
mockMediaEngine,
|
|
118
|
-
expect,
|
|
119
|
-
}) => {
|
|
120
|
-
const result = mockMediaEngine.getAudioRendition();
|
|
121
|
-
expect(result).toBeDefined();
|
|
122
|
-
expect(result?.trackId).toBe(2);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test("mediaEngine.getVideoRendition() returns rendition when available", ({
|
|
126
|
-
mockMediaEngine,
|
|
127
|
-
expect,
|
|
128
|
-
}) => {
|
|
129
|
-
const result = mockMediaEngine.getVideoRendition();
|
|
130
|
-
expect(result).toBeDefined();
|
|
131
|
-
expect(result?.trackId).toBe(1);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("computeSegmentId", () => {
|
|
136
|
-
test("calculates segment ID correctly for audio rendition", ({
|
|
137
|
-
mockAudioRendition,
|
|
138
|
-
expect,
|
|
139
|
-
}) => {
|
|
140
|
-
// Test various time points
|
|
141
|
-
expect(computeSegmentId(0, mockAudioRendition)).toBe(1); // First segment
|
|
142
|
-
expect(computeSegmentId(500, mockAudioRendition)).toBe(1); // Still first segment
|
|
143
|
-
expect(computeSegmentId(999, mockAudioRendition)).toBe(1); // Still first segment
|
|
144
|
-
expect(computeSegmentId(1000, mockAudioRendition)).toBe(2); // Second segment
|
|
145
|
-
expect(computeSegmentId(1500, mockAudioRendition)).toBe(2); // Still second segment
|
|
146
|
-
expect(computeSegmentId(2000, mockAudioRendition)).toBe(3); // Third segment
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test("calculates segment ID correctly for video rendition", ({
|
|
150
|
-
mockVideoRendition,
|
|
151
|
-
expect,
|
|
152
|
-
}) => {
|
|
153
|
-
// Test various time points
|
|
154
|
-
expect(computeSegmentId(0, mockVideoRendition)).toBe(1); // First segment
|
|
155
|
-
expect(computeSegmentId(999, mockVideoRendition)).toBe(1); // Still first segment
|
|
156
|
-
expect(computeSegmentId(1000, mockVideoRendition)).toBe(2); // Second segment
|
|
157
|
-
expect(computeSegmentId(2500, mockVideoRendition)).toBe(3); // Third segment
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
test("returns undefined when segmentDurationMs is not available", ({
|
|
161
|
-
expect,
|
|
162
|
-
}) => {
|
|
163
|
-
const renditionWithoutDuration = {
|
|
164
|
-
trackId: 1,
|
|
165
|
-
src: "test.mp4",
|
|
166
|
-
segmentDurationMs: undefined,
|
|
167
|
-
} as AudioRendition;
|
|
168
|
-
|
|
169
|
-
expect(computeSegmentId(1000, renditionWithoutDuration)).toBeUndefined();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test("handles edge case of negative time", ({
|
|
173
|
-
mockAudioRendition,
|
|
174
|
-
expect,
|
|
175
|
-
}) => {
|
|
176
|
-
expect(computeSegmentId(-100, mockAudioRendition)).toBe(1); // Should clamp to segment 1
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
describe("calculateSegmentRange", () => {
|
|
181
|
-
test("calculates segment range for single segment", ({
|
|
182
|
-
mockAudioRendition,
|
|
183
|
-
expect,
|
|
184
|
-
}) => {
|
|
185
|
-
const result = calculateSegmentRange(100, 800, mockAudioRendition);
|
|
186
|
-
expect(result).toEqual([1]);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test("calculates segment range spanning multiple segments", ({
|
|
190
|
-
mockAudioRendition,
|
|
191
|
-
expect,
|
|
192
|
-
}) => {
|
|
193
|
-
const result = calculateSegmentRange(500, 2500, mockAudioRendition);
|
|
194
|
-
expect(result).toEqual([1, 2, 3]);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test("calculates segment range for exact segment boundaries", ({
|
|
198
|
-
mockAudioRendition,
|
|
199
|
-
expect,
|
|
200
|
-
}) => {
|
|
201
|
-
const result = calculateSegmentRange(1000, 2000, mockAudioRendition);
|
|
202
|
-
expect(result).toEqual([2, 3]);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test("handles single time point (start equals end)", ({
|
|
206
|
-
mockAudioRendition,
|
|
207
|
-
expect,
|
|
208
|
-
}) => {
|
|
209
|
-
const result = calculateSegmentRange(1500, 1500, mockAudioRendition);
|
|
210
|
-
expect(result).toEqual([2]);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
test("returns empty array when segmentDurationMs is not available", ({
|
|
214
|
-
expect,
|
|
215
|
-
}) => {
|
|
216
|
-
const renditionWithoutDuration = {
|
|
217
|
-
trackId: 1,
|
|
218
|
-
src: "test.mp4",
|
|
219
|
-
segmentDurationMs: undefined,
|
|
220
|
-
} as AudioRendition;
|
|
221
|
-
|
|
222
|
-
const result = calculateSegmentRange(
|
|
223
|
-
1000,
|
|
224
|
-
2000,
|
|
225
|
-
renditionWithoutDuration,
|
|
226
|
-
);
|
|
227
|
-
expect(result).toEqual([]);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
test("works with video renditions too", ({
|
|
231
|
-
mockVideoRendition,
|
|
232
|
-
expect,
|
|
233
|
-
}) => {
|
|
234
|
-
const result = calculateSegmentRange(1500, 3500, mockVideoRendition);
|
|
235
|
-
expect(result).toEqual([2, 3, 4]);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
test("handles edge case where start time is negative", ({
|
|
239
|
-
mockAudioRendition,
|
|
240
|
-
expect,
|
|
241
|
-
}) => {
|
|
242
|
-
const result = calculateSegmentRange(-500, 1500, mockAudioRendition);
|
|
243
|
-
expect(result).toEqual([1, 2]);
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AudioRendition,
|
|
3
|
-
VideoRendition,
|
|
4
|
-
} from "../../../transcoding/types";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Calculate which segment contains a given timestamp
|
|
8
|
-
* Returns 1-based segment ID, or undefined if segmentDurationMs is not available
|
|
9
|
-
*/
|
|
10
|
-
export const computeSegmentId = (
|
|
11
|
-
timeMs: number,
|
|
12
|
-
rendition: AudioRendition | VideoRendition,
|
|
13
|
-
): number | undefined => {
|
|
14
|
-
if (!rendition.segmentDurationMs) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Handle negative time by clamping to 0
|
|
19
|
-
const adjustedTimeMs = Math.max(0, timeMs);
|
|
20
|
-
const segmentIndex = Math.floor(adjustedTimeMs / rendition.segmentDurationMs);
|
|
21
|
-
return segmentIndex + 1; // Convert to 1-based segment ID
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Calculate range of segment IDs that overlap with a time range
|
|
26
|
-
* Returns array of 1-based segment IDs, or empty array if segmentDurationMs is not available
|
|
27
|
-
*/
|
|
28
|
-
export const calculateSegmentRange = (
|
|
29
|
-
startTimeMs: number,
|
|
30
|
-
endTimeMs: number,
|
|
31
|
-
rendition: AudioRendition | VideoRendition,
|
|
32
|
-
): number[] => {
|
|
33
|
-
if (!rendition.segmentDurationMs) {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Handle edge case where start equals end
|
|
38
|
-
if (startTimeMs === endTimeMs) {
|
|
39
|
-
const segmentId = computeSegmentId(startTimeMs, rendition);
|
|
40
|
-
return segmentId ? [segmentId] : [];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const startSegmentId = computeSegmentId(startTimeMs, rendition);
|
|
44
|
-
const endSegmentId = computeSegmentId(endTimeMs, rendition);
|
|
45
|
-
|
|
46
|
-
if (startSegmentId === undefined || endSegmentId === undefined) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const segments: number[] = [];
|
|
51
|
-
for (let segmentId = startSegmentId; segmentId <= endSegmentId; segmentId++) {
|
|
52
|
-
segments.push(segmentId);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return segments;
|
|
56
|
-
};
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { ALL_FORMATS, BlobSource, CanvasSink, Input } from "mediabunny";
|
|
2
|
-
import type {
|
|
3
|
-
ThumbnailResult,
|
|
4
|
-
VideoRendition,
|
|
5
|
-
} from "../../../transcoding/types/index.js";
|
|
6
|
-
import type { BaseMediaEngine } from "../BaseMediaEngine.js";
|
|
7
|
-
import { globalInputCache } from "./GlobalInputCache.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Shared thumbnail extraction logic for all MediaEngine implementations
|
|
11
|
-
* Eliminates code duplication and provides consistent behavior
|
|
12
|
-
*/
|
|
13
|
-
export class ThumbnailExtractor {
|
|
14
|
-
constructor(private mediaEngine: BaseMediaEngine) {}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Extract thumbnails at multiple timestamps efficiently using segment batching
|
|
18
|
-
*/
|
|
19
|
-
async extractThumbnails(
|
|
20
|
-
timestamps: number[],
|
|
21
|
-
rendition: VideoRendition,
|
|
22
|
-
durationMs: number,
|
|
23
|
-
): Promise<(ThumbnailResult | null)[]> {
|
|
24
|
-
if (timestamps.length === 0) {
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Validate and filter timestamps within bounds
|
|
29
|
-
const validTimestamps = timestamps.filter(
|
|
30
|
-
(timeMs) => timeMs >= 0 && timeMs <= durationMs,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
if (validTimestamps.length === 0) {
|
|
34
|
-
console.warn(
|
|
35
|
-
`ThumbnailExtractor: All timestamps out of bounds (0-${durationMs}ms)`,
|
|
36
|
-
);
|
|
37
|
-
return timestamps.map(() => null);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Group timestamps by segment for batch processing
|
|
41
|
-
const segmentGroups = this.groupTimestampsBySegment(
|
|
42
|
-
validTimestamps,
|
|
43
|
-
rendition,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// Extract batched by segment using CanvasSink
|
|
47
|
-
const results = new Map<number, ThumbnailResult | null>();
|
|
48
|
-
|
|
49
|
-
for (const [segmentId, segmentTimestamps] of segmentGroups) {
|
|
50
|
-
try {
|
|
51
|
-
const segmentResults = await this.extractSegmentThumbnails(
|
|
52
|
-
segmentId,
|
|
53
|
-
segmentTimestamps,
|
|
54
|
-
rendition,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
for (const [timestamp, thumbnail] of segmentResults) {
|
|
58
|
-
results.set(timestamp, thumbnail);
|
|
59
|
-
}
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.warn(
|
|
62
|
-
`ThumbnailExtractor: Failed to extract thumbnails for segment ${segmentId}:`,
|
|
63
|
-
error,
|
|
64
|
-
);
|
|
65
|
-
// Mark all timestamps in this segment as failed
|
|
66
|
-
for (const timestamp of segmentTimestamps) {
|
|
67
|
-
results.set(timestamp, null);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Return in original order, null for any that failed or were out of bounds
|
|
73
|
-
return timestamps.map((t) => {
|
|
74
|
-
// If timestamp was out of bounds, return null
|
|
75
|
-
if (t < 0 || t > durationMs) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
return results.get(t) || null;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Group timestamps by segment ID for efficient batch processing
|
|
84
|
-
*/
|
|
85
|
-
private groupTimestampsBySegment(
|
|
86
|
-
timestamps: number[],
|
|
87
|
-
rendition: VideoRendition,
|
|
88
|
-
): Map<number, number[]> {
|
|
89
|
-
const segmentGroups = new Map<number, number[]>();
|
|
90
|
-
|
|
91
|
-
for (const timeMs of timestamps) {
|
|
92
|
-
try {
|
|
93
|
-
const segmentId = this.mediaEngine.computeSegmentId(timeMs, rendition);
|
|
94
|
-
if (segmentId !== undefined) {
|
|
95
|
-
if (!segmentGroups.has(segmentId)) {
|
|
96
|
-
segmentGroups.set(segmentId, []);
|
|
97
|
-
}
|
|
98
|
-
const segmentGroup = segmentGroups.get(segmentId) ?? [];
|
|
99
|
-
if (!segmentGroup) {
|
|
100
|
-
segmentGroups.set(segmentId, []);
|
|
101
|
-
}
|
|
102
|
-
segmentGroup.push(timeMs);
|
|
103
|
-
}
|
|
104
|
-
} catch (error) {
|
|
105
|
-
console.warn(
|
|
106
|
-
`ThumbnailExtractor: Could not compute segment for timestamp ${timeMs}:`,
|
|
107
|
-
error,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return segmentGroups;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Extract thumbnails for a specific segment using CanvasSink
|
|
117
|
-
*/
|
|
118
|
-
private async extractSegmentThumbnails(
|
|
119
|
-
segmentId: number,
|
|
120
|
-
timestamps: number[],
|
|
121
|
-
rendition: VideoRendition,
|
|
122
|
-
): Promise<Map<number, ThumbnailResult | null>> {
|
|
123
|
-
const results = new Map<number, ThumbnailResult | null>();
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
// Get segment data through existing media engine methods (uses caches)
|
|
127
|
-
const abortController = new AbortController();
|
|
128
|
-
const [initSegment, mediaSegment] = await Promise.all([
|
|
129
|
-
this.mediaEngine.fetchInitSegment(rendition, abortController.signal),
|
|
130
|
-
this.mediaEngine.fetchMediaSegment(segmentId, rendition),
|
|
131
|
-
]);
|
|
132
|
-
|
|
133
|
-
// Create Input for this segment using global shared cache
|
|
134
|
-
const segmentBlob = new Blob([initSegment, mediaSegment]);
|
|
135
|
-
|
|
136
|
-
let input = globalInputCache.get(rendition.src, segmentId, rendition.id);
|
|
137
|
-
if (!input) {
|
|
138
|
-
input = new Input({
|
|
139
|
-
formats: ALL_FORMATS,
|
|
140
|
-
source: new BlobSource(segmentBlob),
|
|
141
|
-
});
|
|
142
|
-
globalInputCache.set(rendition.src, segmentId, input, rendition.id);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Set up CanvasSink for batched extraction
|
|
146
|
-
const videoTrack = await input.getPrimaryVideoTrack();
|
|
147
|
-
if (!videoTrack) {
|
|
148
|
-
// No video track - return nulls for all timestamps
|
|
149
|
-
for (const timestamp of timestamps) {
|
|
150
|
-
results.set(timestamp, null);
|
|
151
|
-
}
|
|
152
|
-
return results;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const sink = new CanvasSink(videoTrack);
|
|
156
|
-
|
|
157
|
-
// Convert global timestamps to segment-relative (in seconds for mediabunny)
|
|
158
|
-
const relativeTimestamps = this.convertToSegmentRelativeTimestamps(
|
|
159
|
-
timestamps,
|
|
160
|
-
segmentId,
|
|
161
|
-
rendition,
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
// Batch extract all thumbnails for this segment
|
|
165
|
-
const timestampResults = [];
|
|
166
|
-
for await (const result of sink.canvasesAtTimestamps(
|
|
167
|
-
relativeTimestamps,
|
|
168
|
-
)) {
|
|
169
|
-
timestampResults.push(result);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Map results back to original timestamps
|
|
173
|
-
for (let i = 0; i < timestamps.length; i++) {
|
|
174
|
-
const globalTimestamp = timestamps[i];
|
|
175
|
-
if (globalTimestamp === undefined) {
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const result = timestampResults[i];
|
|
180
|
-
|
|
181
|
-
if (result?.canvas) {
|
|
182
|
-
const canvas = result.canvas;
|
|
183
|
-
if (
|
|
184
|
-
canvas instanceof HTMLCanvasElement ||
|
|
185
|
-
canvas instanceof OffscreenCanvas
|
|
186
|
-
) {
|
|
187
|
-
results.set(globalTimestamp, {
|
|
188
|
-
timestamp: globalTimestamp,
|
|
189
|
-
thumbnail: canvas,
|
|
190
|
-
});
|
|
191
|
-
} else {
|
|
192
|
-
results.set(globalTimestamp, null);
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
results.set(globalTimestamp, null);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
} catch (error) {
|
|
199
|
-
console.error(
|
|
200
|
-
`ThumbnailExtractor: Failed to extract thumbnails for segment ${segmentId}:`,
|
|
201
|
-
error,
|
|
202
|
-
);
|
|
203
|
-
// Return nulls for all timestamps on error
|
|
204
|
-
for (const timestamp of timestamps) {
|
|
205
|
-
results.set(timestamp, null);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return results;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Convert global timestamps to segment-relative timestamps for mediabunny
|
|
214
|
-
* This is where the main difference between JIT and Asset engines lies
|
|
215
|
-
*/
|
|
216
|
-
private convertToSegmentRelativeTimestamps(
|
|
217
|
-
globalTimestamps: number[],
|
|
218
|
-
segmentId: number,
|
|
219
|
-
rendition: VideoRendition,
|
|
220
|
-
): number[] {
|
|
221
|
-
return this.mediaEngine.convertToSegmentRelativeTimestamps(
|
|
222
|
-
globalTimestamps,
|
|
223
|
-
segmentId,
|
|
224
|
-
rendition,
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { customElement } from "lit/decorators.js";
|
|
2
|
-
import { describe } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { test as baseTest } from "../../../../test/useMSW.js";
|
|
5
|
-
import { EFMedia } from "../../EFMedia.js";
|
|
6
|
-
import { createMediaEngine } from "./makeMediaEngineTask";
|
|
7
|
-
|
|
8
|
-
@customElement("test-media-engine")
|
|
9
|
-
class TestMediaEngine extends EFMedia {}
|
|
10
|
-
|
|
11
|
-
declare global {
|
|
12
|
-
interface HTMLElementTagNameMap {
|
|
13
|
-
"test-media-engine": TestMediaEngine;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const testWithElement = baseTest.extend<{
|
|
18
|
-
element: TestMediaEngine;
|
|
19
|
-
configuration: HTMLElement;
|
|
20
|
-
}>({
|
|
21
|
-
element: async ({}, use) => {
|
|
22
|
-
const element = document.createElement("test-media-engine");
|
|
23
|
-
|
|
24
|
-
// Set up element with required properties via attributes
|
|
25
|
-
const apiHost = `${window.location.protocol}//${window.location.host}`;
|
|
26
|
-
element.setAttribute("api-host", apiHost);
|
|
27
|
-
|
|
28
|
-
document.body.appendChild(element);
|
|
29
|
-
await use(element);
|
|
30
|
-
element.remove();
|
|
31
|
-
},
|
|
32
|
-
configuration: async ({}, use) => {
|
|
33
|
-
const config = document.createElement("ef-configuration") as any;
|
|
34
|
-
document.body.appendChild(config);
|
|
35
|
-
await use(config);
|
|
36
|
-
config.remove();
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("makeMediaEngineTask", () => {
|
|
41
|
-
describe("createMediaEngine - Engine Selection Logic", () => {
|
|
42
|
-
testWithElement(
|
|
43
|
-
"should throw error for empty src when no assetId",
|
|
44
|
-
async ({ element, expect }) => {
|
|
45
|
-
element.setAttribute("src", "");
|
|
46
|
-
element.removeAttribute("asset-id");
|
|
47
|
-
|
|
48
|
-
await expect(createMediaEngine(element)).rejects.toThrow(
|
|
49
|
-
"Unsupported media source",
|
|
50
|
-
);
|
|
51
|
-
},
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
testWithElement(
|
|
55
|
-
"should throw error for whitespace-only src when no assetId",
|
|
56
|
-
async ({ element, expect }) => {
|
|
57
|
-
element.setAttribute("src", " ");
|
|
58
|
-
element.removeAttribute("asset-id");
|
|
59
|
-
|
|
60
|
-
await expect(createMediaEngine(element)).rejects.toThrow(
|
|
61
|
-
"Unsupported media source",
|
|
62
|
-
);
|
|
63
|
-
},
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
testWithElement(
|
|
67
|
-
"should throw error for null src when no assetId",
|
|
68
|
-
async ({ element, expect }) => {
|
|
69
|
-
element.removeAttribute("src");
|
|
70
|
-
element.removeAttribute("asset-id");
|
|
71
|
-
|
|
72
|
-
await expect(createMediaEngine(element)).rejects.toThrow(
|
|
73
|
-
"Unsupported media source",
|
|
74
|
-
);
|
|
75
|
-
},
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
testWithElement(
|
|
79
|
-
"should throw error when assetId is provided but apiHost is missing",
|
|
80
|
-
async ({ element, expect }) => {
|
|
81
|
-
element.setAttribute("asset-id", "test-asset-123");
|
|
82
|
-
element.setAttribute("api-host", ""); // Explicitly set empty api-host
|
|
83
|
-
await element.updateComplete; // Wait for Lit to process attributes
|
|
84
|
-
|
|
85
|
-
// The test might hit "Unsupported media source" instead due to src being empty
|
|
86
|
-
// Both errors indicate improper setup, so accept either
|
|
87
|
-
await expect(createMediaEngine(element)).rejects.toThrow(
|
|
88
|
-
/(API host is required for AssetID mode|Unsupported media source)/,
|
|
89
|
-
);
|
|
90
|
-
},
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
testWithElement(
|
|
94
|
-
"should choose AssetMediaEngine for local file paths",
|
|
95
|
-
async ({ element, expect }) => {
|
|
96
|
-
element.setAttribute("src", "bars-n-tone.mp4"); // Local test asset
|
|
97
|
-
element.removeAttribute("asset-id");
|
|
98
|
-
|
|
99
|
-
const result = await createMediaEngine(element);
|
|
100
|
-
|
|
101
|
-
// Should successfully create AssetMediaEngine (doesn't throw)
|
|
102
|
-
expect(result).toBeDefined();
|
|
103
|
-
expect(result.constructor.name).toBe("AssetMediaEngine");
|
|
104
|
-
},
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
testWithElement(
|
|
108
|
-
"should choose JitMediaEngine for remote URLs with cloud configuration",
|
|
109
|
-
async ({ element, configuration, expect }) => {
|
|
110
|
-
// Set up configuration for JIT mode
|
|
111
|
-
configuration.setAttribute("media-engine", "cloud");
|
|
112
|
-
(configuration as any).mediaEngine = "cloud"; // Set property for engine selection
|
|
113
|
-
document.body.appendChild(configuration);
|
|
114
|
-
configuration.appendChild(element);
|
|
115
|
-
|
|
116
|
-
element.setAttribute("src", "http://web:3000/head-moov-480p.mp4");
|
|
117
|
-
element.removeAttribute("asset-id");
|
|
118
|
-
|
|
119
|
-
const result = await createMediaEngine(element);
|
|
120
|
-
|
|
121
|
-
// Should successfully create JitMediaEngine
|
|
122
|
-
expect(result).toBeDefined();
|
|
123
|
-
expect(result.constructor.name).toBe("JitMediaEngine");
|
|
124
|
-
},
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
testWithElement(
|
|
128
|
-
"should default to JitMediaEngine for remote URLs without configuration",
|
|
129
|
-
async ({ element, expect }) => {
|
|
130
|
-
// No configuration element = defaults to JitMediaEngine
|
|
131
|
-
element.setAttribute("src", "http://web:3000/head-moov-480p.mp4");
|
|
132
|
-
element.removeAttribute("asset-id");
|
|
133
|
-
|
|
134
|
-
const result = await createMediaEngine(element);
|
|
135
|
-
|
|
136
|
-
expect(result).toBeDefined();
|
|
137
|
-
expect(result.constructor.name).toBe("JitMediaEngine");
|
|
138
|
-
},
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
testWithElement(
|
|
142
|
-
"should ignore empty assetId and use src for engine selection",
|
|
143
|
-
async ({ element, expect }) => {
|
|
144
|
-
element.setAttribute("asset-id", ""); // Empty assetId should be ignored
|
|
145
|
-
element.setAttribute("src", "bars-n-tone.mp4");
|
|
146
|
-
|
|
147
|
-
const result = await createMediaEngine(element);
|
|
148
|
-
|
|
149
|
-
expect(result).toBeDefined();
|
|
150
|
-
expect(result.constructor.name).toBe("AssetMediaEngine");
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
testWithElement(
|
|
155
|
-
"should ignore whitespace-only assetId and use src for engine selection",
|
|
156
|
-
async ({ element, expect }) => {
|
|
157
|
-
element.setAttribute("asset-id", " "); // Whitespace-only assetId should be ignored
|
|
158
|
-
element.setAttribute("src", "bars-n-tone.mp4");
|
|
159
|
-
|
|
160
|
-
const result = await createMediaEngine(element);
|
|
161
|
-
|
|
162
|
-
expect(result).toBeDefined();
|
|
163
|
-
expect(result.constructor.name).toBe("AssetMediaEngine");
|
|
164
|
-
},
|
|
165
|
-
);
|
|
166
|
-
});
|
|
167
|
-
});
|