@editframe/elements 0.26.3-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/package.json +2 -2
- package/scripts/build-css.js +3 -3
- package/tsdown.config.ts +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 -934
- package/src/elements/EFTimegroup.ts +0 -882
- 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,120 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
2
|
-
import "./EFImage.js";
|
|
3
|
-
import "../gui/EFPreview.js";
|
|
4
|
-
import { v4 } from "uuid";
|
|
5
|
-
|
|
6
|
-
describe("EFImage", () => {
|
|
7
|
-
describe("when rendering", () => {
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
// @ts-expect-error
|
|
10
|
-
window.FRAMEGEN_BRIDGE = true;
|
|
11
|
-
});
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
delete window.FRAMEGEN_BRIDGE;
|
|
14
|
-
});
|
|
15
|
-
test("assetPath uses http:// protocol", () => {
|
|
16
|
-
const workbench = document.createElement("ef-workbench");
|
|
17
|
-
const element = document.createElement("ef-image");
|
|
18
|
-
workbench.appendChild(element);
|
|
19
|
-
element.assetId = "550e8400-e29b-41d4-a716-446655440000";
|
|
20
|
-
expect(element.assetPath()).toBe(
|
|
21
|
-
"https://editframe.dev/api/v1/image_files/550e8400-e29b-41d4-a716-446655440000",
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe("attribute: asset-id", () => {
|
|
27
|
-
test("determines assetPath", () => {
|
|
28
|
-
const id = v4();
|
|
29
|
-
const image = document.createElement("ef-image");
|
|
30
|
-
image.setAttribute("asset-id", id);
|
|
31
|
-
expect(image.assetPath()).toBe(
|
|
32
|
-
`https://editframe.dev/api/v1/image_files/${id}`,
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("honors apiHost", () => {
|
|
37
|
-
const id = v4();
|
|
38
|
-
const image = document.createElement("ef-image");
|
|
39
|
-
const preview = document.createElement("ef-preview");
|
|
40
|
-
image.setAttribute("asset-id", id);
|
|
41
|
-
preview.appendChild(image);
|
|
42
|
-
preview.apiHost = "test://";
|
|
43
|
-
document.body.appendChild(preview);
|
|
44
|
-
expect(image.assetPath()).toBe(`test:///api/v1/image_files/${id}`);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe("hasOwnDuration", () => {
|
|
49
|
-
test("is false by default", () => {
|
|
50
|
-
const image = document.createElement("ef-image");
|
|
51
|
-
expect(image.hasOwnDuration).toBe(false);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("is true when duration is set", () => {
|
|
55
|
-
const image = document.createElement("ef-image");
|
|
56
|
-
image.setAttribute("duration", "1s");
|
|
57
|
-
expect(image.hasOwnDuration).toBe(true);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe("durationMs", () => {
|
|
62
|
-
test("Can be set on element directly", () => {
|
|
63
|
-
const image = document.createElement("ef-image");
|
|
64
|
-
image.src =
|
|
65
|
-
"https://editframe.dev/api/v1/image_files/550e8400-e29b-41d4-a716-446655440000";
|
|
66
|
-
image.duration = "1s";
|
|
67
|
-
expect(image.durationMs).toBe(1000);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("Can be set through setAttribute", () => {
|
|
71
|
-
const image = document.createElement("ef-image");
|
|
72
|
-
image.src =
|
|
73
|
-
"https://editframe.dev/api/v1/image_files/550e8400-e29b-41d4-a716-446655440000";
|
|
74
|
-
image.setAttribute("duration", "1s");
|
|
75
|
-
expect(image.durationMs).toBe(1000);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("direct URL support", () => {
|
|
80
|
-
test("assetPath returns https URLs unchanged", () => {
|
|
81
|
-
const image = document.createElement("ef-image");
|
|
82
|
-
image.src = "https://example.com/image.jpg";
|
|
83
|
-
expect(image.assetPath()).toBe("https://example.com/image.jpg");
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("assetPath returns http URLs unchanged", () => {
|
|
87
|
-
const image = document.createElement("ef-image");
|
|
88
|
-
image.src = "http://example.com/image.jpg";
|
|
89
|
-
expect(image.assetPath()).toBe("http://example.com/image.jpg");
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("assetPath preserves local file behavior", () => {
|
|
93
|
-
const image = document.createElement("ef-image");
|
|
94
|
-
image.src = "local-image.jpg";
|
|
95
|
-
expect(image.assetPath()).toBe("/@ef-image/local-image.jpg");
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("assetPath preserves asset-id priority over direct URL", () => {
|
|
99
|
-
const image = document.createElement("ef-image");
|
|
100
|
-
const preview = document.createElement("ef-preview");
|
|
101
|
-
preview.appendChild(image);
|
|
102
|
-
preview.apiHost = "https://api.test.com";
|
|
103
|
-
image.src = "https://example.com/image.jpg";
|
|
104
|
-
image.assetId = "test-asset-id";
|
|
105
|
-
expect(image.assetPath()).toBe(
|
|
106
|
-
"https://api.test.com/api/v1/image_files/test-asset-id",
|
|
107
|
-
);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test("handles CORS fallback for direct URLs", () => {
|
|
111
|
-
const image = document.createElement("ef-image");
|
|
112
|
-
image.src =
|
|
113
|
-
"https://storage.googleapis.com/editframe-assets-7ac794b/1080-cat.jpeg";
|
|
114
|
-
expect(image.assetPath()).toBe(
|
|
115
|
-
"https://storage.googleapis.com/editframe-assets-7ac794b/1080-cat.jpeg",
|
|
116
|
-
);
|
|
117
|
-
// Note: CORS fallback behavior is tested in the fetchImage task logic
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
package/src/elements/EFImage.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Task } from "@lit/task";
|
|
2
|
-
import { css, html, LitElement } from "lit";
|
|
3
|
-
import { customElement, property } from "lit/decorators.js";
|
|
4
|
-
import { createRef, ref } from "lit/directives/ref.js";
|
|
5
|
-
import { EF_INTERACTIVE } from "../EF_INTERACTIVE.js";
|
|
6
|
-
import { EFSourceMixin } from "./EFSourceMixin.js";
|
|
7
|
-
import { EFTemporal } from "./EFTemporal.js";
|
|
8
|
-
import { FetchMixin } from "./FetchMixin.js";
|
|
9
|
-
|
|
10
|
-
@customElement("ef-image")
|
|
11
|
-
export class EFImage extends EFTemporal(
|
|
12
|
-
EFSourceMixin(FetchMixin(LitElement), {
|
|
13
|
-
assetType: "image_files",
|
|
14
|
-
}),
|
|
15
|
-
) {
|
|
16
|
-
static styles = [
|
|
17
|
-
css`
|
|
18
|
-
:host {
|
|
19
|
-
display: block;
|
|
20
|
-
display: flex;
|
|
21
|
-
align-items: center;
|
|
22
|
-
justify-content: center;
|
|
23
|
-
}
|
|
24
|
-
canvas, img {
|
|
25
|
-
position: static;
|
|
26
|
-
all: initial;
|
|
27
|
-
width: 100%;
|
|
28
|
-
height: 100%;
|
|
29
|
-
}
|
|
30
|
-
`,
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
imageRef = createRef<HTMLImageElement>();
|
|
34
|
-
canvasRef = createRef<HTMLCanvasElement>();
|
|
35
|
-
|
|
36
|
-
#assetId: string | null = null;
|
|
37
|
-
@property({ type: String, attribute: "asset-id", reflect: true })
|
|
38
|
-
set assetId(value: string | null) {
|
|
39
|
-
this.#assetId = value;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get assetId() {
|
|
43
|
-
return this.#assetId ?? this.getAttribute("asset-id");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
render() {
|
|
47
|
-
const assetPath = this.assetPath();
|
|
48
|
-
const isDirectUrl = this.isDirectUrl(assetPath);
|
|
49
|
-
return isDirectUrl
|
|
50
|
-
? html`<img ${ref(this.imageRef)} src=${assetPath} />`
|
|
51
|
-
: html`<canvas ${ref(this.canvasRef)}></canvas>`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private isDirectUrl(src: string): boolean {
|
|
55
|
-
return src.startsWith("http://") || src.startsWith("https://");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
assetPath() {
|
|
59
|
-
if (this.assetId) {
|
|
60
|
-
return `${this.apiHost}/api/v1/image_files/${this.assetId}`;
|
|
61
|
-
}
|
|
62
|
-
if (this.isDirectUrl(this.src)) {
|
|
63
|
-
return this.src;
|
|
64
|
-
}
|
|
65
|
-
return `/@ef-image/${this.src}`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
get hasOwnDuration() {
|
|
69
|
-
return this.hasExplicitDuration;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
fetchImage = new Task(this, {
|
|
73
|
-
autoRun: EF_INTERACTIVE,
|
|
74
|
-
args: () => [this.assetPath(), this.fetch] as const,
|
|
75
|
-
task: async ([assetPath, fetch], { signal }) => {
|
|
76
|
-
// For direct URLs, skip task - src is set directly in render
|
|
77
|
-
if (this.isDirectUrl(assetPath)) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// For asset-id and local files, use canvas as before
|
|
82
|
-
const response = await fetch(assetPath, { signal });
|
|
83
|
-
const image = new Image();
|
|
84
|
-
image.src = URL.createObjectURL(await response.blob());
|
|
85
|
-
|
|
86
|
-
await new Promise((resolve, reject) => {
|
|
87
|
-
image.onload = resolve;
|
|
88
|
-
image.onerror = reject;
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
if (!this.canvasRef.value) throw new Error("Canvas not ready");
|
|
92
|
-
const ctx = this.canvasRef.value.getContext("2d");
|
|
93
|
-
if (!ctx) throw new Error("Canvas 2d context not ready");
|
|
94
|
-
this.canvasRef.value.width = image.width;
|
|
95
|
-
this.canvasRef.value.height = image.height;
|
|
96
|
-
ctx.drawImage(image, 0, 0);
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
frameTask = new Task(this, {
|
|
101
|
-
autoRun: EF_INTERACTIVE,
|
|
102
|
-
args: () => [this.fetchImage.status] as const,
|
|
103
|
-
task: async () => {
|
|
104
|
-
await this.fetchImage.taskComplete;
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
declare global {
|
|
110
|
-
interface HTMLElementTagNameMap {
|
|
111
|
-
"ef-image": EFImage;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import type { TrackFragmentIndex } from "@editframe/assets";
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { UrlGenerator } from "../../transcoding/utils/UrlGenerator";
|
|
4
|
-
import type { EFMedia } from "../EFMedia";
|
|
5
|
-
import { AssetIdMediaEngine } from "./AssetIdMediaEngine";
|
|
6
|
-
|
|
7
|
-
describe("AssetIdMediaEngine", () => {
|
|
8
|
-
const mockApiHost = "https://api.example.com";
|
|
9
|
-
const mockAssetId = "test-asset-123";
|
|
10
|
-
const mockUrlGenerator = new UrlGenerator(() => "https://api.example.com");
|
|
11
|
-
|
|
12
|
-
const mockTrackFragmentData: Record<number, TrackFragmentIndex> = {
|
|
13
|
-
1: {
|
|
14
|
-
track: 1,
|
|
15
|
-
type: "audio",
|
|
16
|
-
duration: 15000,
|
|
17
|
-
timescale: 1000,
|
|
18
|
-
channel_count: 2,
|
|
19
|
-
sample_rate: 44100,
|
|
20
|
-
sample_size: 16,
|
|
21
|
-
sample_count: 1000,
|
|
22
|
-
codec: "mp4a.40.2",
|
|
23
|
-
initSegment: {
|
|
24
|
-
offset: 0,
|
|
25
|
-
size: 1024,
|
|
26
|
-
},
|
|
27
|
-
segments: [
|
|
28
|
-
{
|
|
29
|
-
cts: 0,
|
|
30
|
-
dts: 0,
|
|
31
|
-
duration: 1000,
|
|
32
|
-
offset: 1024,
|
|
33
|
-
size: 2048,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
cts: 1000,
|
|
37
|
-
dts: 1000,
|
|
38
|
-
duration: 1000,
|
|
39
|
-
offset: 3072,
|
|
40
|
-
size: 2048,
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
2: {
|
|
45
|
-
track: 2,
|
|
46
|
-
type: "video",
|
|
47
|
-
duration: 15000,
|
|
48
|
-
timescale: 1000,
|
|
49
|
-
width: 1920,
|
|
50
|
-
height: 1080,
|
|
51
|
-
sample_count: 1500,
|
|
52
|
-
codec: "avc1.640029",
|
|
53
|
-
initSegment: {
|
|
54
|
-
offset: 0,
|
|
55
|
-
size: 2048,
|
|
56
|
-
},
|
|
57
|
-
segments: [
|
|
58
|
-
{
|
|
59
|
-
cts: 0,
|
|
60
|
-
dts: 0,
|
|
61
|
-
duration: 1000,
|
|
62
|
-
offset: 7168,
|
|
63
|
-
size: 4096,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
cts: 1000,
|
|
67
|
-
dts: 1000,
|
|
68
|
-
duration: 1000,
|
|
69
|
-
offset: 11264,
|
|
70
|
-
size: 4096,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
let engine: AssetIdMediaEngine;
|
|
77
|
-
let host: EFMedia;
|
|
78
|
-
|
|
79
|
-
beforeEach(() => {
|
|
80
|
-
// Create a mock host instead of instantiating EFMedia directly
|
|
81
|
-
host = {
|
|
82
|
-
fetch: vi.fn().mockResolvedValue({
|
|
83
|
-
json: vi.fn().mockResolvedValue(mockTrackFragmentData),
|
|
84
|
-
}),
|
|
85
|
-
} as any;
|
|
86
|
-
engine = new AssetIdMediaEngine(
|
|
87
|
-
host,
|
|
88
|
-
mockAssetId,
|
|
89
|
-
mockTrackFragmentData,
|
|
90
|
-
mockApiHost,
|
|
91
|
-
);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe("constructor", () => {
|
|
95
|
-
it("should initialize with correct duration", () => {
|
|
96
|
-
expect(engine.durationMs).toBe(15000);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should set assetId correctly", () => {
|
|
100
|
-
expect(engine.assetId).toBe(mockAssetId);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("should expose assetId as src for MediaEngine interface compatibility", () => {
|
|
104
|
-
expect(engine.src).toBe(mockAssetId);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe("track access", () => {
|
|
109
|
-
it("should find audio track", () => {
|
|
110
|
-
const audioTrack = engine.audioTrackIndex;
|
|
111
|
-
expect(audioTrack).toBeDefined();
|
|
112
|
-
expect(audioTrack?.type).toBe("audio");
|
|
113
|
-
expect(audioTrack?.track).toBe(1);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("should find video track", () => {
|
|
117
|
-
const videoTrack = engine.videoTrackIndex;
|
|
118
|
-
expect(videoTrack).toBeDefined();
|
|
119
|
-
expect(videoTrack?.type).toBe("video");
|
|
120
|
-
expect(videoTrack?.track).toBe(2);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should return correct audio rendition", () => {
|
|
124
|
-
const audioRendition = engine.audioRendition;
|
|
125
|
-
expect(audioRendition).toBeDefined();
|
|
126
|
-
expect(audioRendition!.trackId).toBe(1);
|
|
127
|
-
expect(audioRendition!.src).toBe(mockAssetId);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("should return correct video rendition", () => {
|
|
131
|
-
const videoRendition = engine.videoRendition;
|
|
132
|
-
expect(videoRendition).toBeDefined();
|
|
133
|
-
expect(videoRendition!.trackId).toBe(2);
|
|
134
|
-
expect(videoRendition!.src).toBe(mockAssetId);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe("URL generation", () => {
|
|
139
|
-
it("should generate correct init segment URLs", () => {
|
|
140
|
-
const url = engine.buildInitSegmentUrl(1);
|
|
141
|
-
expect(url).toBe(`${mockApiHost}/api/v1/isobmff_tracks/${mockAssetId}/1`);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("should generate correct media segment URLs", () => {
|
|
145
|
-
const url = engine.buildMediaSegmentUrl(1, 0);
|
|
146
|
-
expect(url).toBe(`${mockApiHost}/api/v1/isobmff_tracks/${mockAssetId}/1`);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("should return correct templates", () => {
|
|
150
|
-
const templates = engine.templates;
|
|
151
|
-
expect(templates.initSegment).toBe(
|
|
152
|
-
`${mockApiHost}/api/v1/isobmff_tracks/${mockAssetId}/{trackId}`,
|
|
153
|
-
);
|
|
154
|
-
expect(templates.mediaSegment).toBe(
|
|
155
|
-
`${mockApiHost}/api/v1/isobmff_tracks/${mockAssetId}/{trackId}`,
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("should return correct init segment paths", () => {
|
|
160
|
-
const paths = engine.initSegmentPaths;
|
|
161
|
-
expect(paths.audio?.path).toBe(
|
|
162
|
-
`${mockApiHost}/api/v1/isobmff_tracks/${mockAssetId}/1`,
|
|
163
|
-
);
|
|
164
|
-
expect(paths.video?.path).toBe(
|
|
165
|
-
`${mockApiHost}/api/v1/isobmff_tracks/${mockAssetId}/2`,
|
|
166
|
-
);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
describe("segment calculations", () => {
|
|
171
|
-
it("should calculate audio segment ranges correctly", () => {
|
|
172
|
-
const ranges = engine.calculateAudioSegmentRange(
|
|
173
|
-
500,
|
|
174
|
-
1500,
|
|
175
|
-
{ trackId: 1, src: mockAssetId },
|
|
176
|
-
15000,
|
|
177
|
-
);
|
|
178
|
-
expect(ranges).toHaveLength(2);
|
|
179
|
-
expect(ranges[0]?.segmentId).toBe(0);
|
|
180
|
-
expect(ranges[1]?.segmentId).toBe(1);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("should compute segment ID correctly", () => {
|
|
184
|
-
const segmentId = engine.computeSegmentId(500, {
|
|
185
|
-
trackId: 1,
|
|
186
|
-
src: mockAssetId,
|
|
187
|
-
});
|
|
188
|
-
expect(segmentId).toBe(0);
|
|
189
|
-
|
|
190
|
-
const segmentId2 = engine.computeSegmentId(1500, {
|
|
191
|
-
trackId: 1,
|
|
192
|
-
src: mockAssetId,
|
|
193
|
-
});
|
|
194
|
-
expect(segmentId2).toBe(1);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe("static fetch method", () => {
|
|
199
|
-
it("should create engine from API response", async () => {
|
|
200
|
-
// Mock the host's fetch method
|
|
201
|
-
const mockFetch = vi.fn().mockResolvedValue({
|
|
202
|
-
json: vi.fn().mockResolvedValue(mockTrackFragmentData),
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
const mockHost = {
|
|
206
|
-
fetch: mockFetch,
|
|
207
|
-
} as any;
|
|
208
|
-
|
|
209
|
-
const fetchedEngine = await AssetIdMediaEngine.fetchByAssetId(
|
|
210
|
-
mockHost,
|
|
211
|
-
mockUrlGenerator,
|
|
212
|
-
mockAssetId,
|
|
213
|
-
mockApiHost,
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
217
|
-
`${mockApiHost}/api/v1/isobmff_files/${mockAssetId}/index`,
|
|
218
|
-
);
|
|
219
|
-
expect(fetchedEngine.assetId).toBe(mockAssetId);
|
|
220
|
-
expect(fetchedEngine.durationMs).toBe(15000);
|
|
221
|
-
expect(fetchedEngine.audioTrackIndex?.track).toBe(1);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
});
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type { TrackFragmentIndex } from "@editframe/assets";
|
|
2
|
-
import type {
|
|
3
|
-
InitSegmentPaths,
|
|
4
|
-
MediaEngine,
|
|
5
|
-
VideoRendition,
|
|
6
|
-
} from "../../transcoding/types";
|
|
7
|
-
import type { UrlGenerator } from "../../transcoding/utils/UrlGenerator";
|
|
8
|
-
import type { EFMedia } from "../EFMedia";
|
|
9
|
-
import { AssetMediaEngine } from "./AssetMediaEngine";
|
|
10
|
-
|
|
11
|
-
export class AssetIdMediaEngine
|
|
12
|
-
extends AssetMediaEngine
|
|
13
|
-
implements MediaEngine
|
|
14
|
-
{
|
|
15
|
-
static async fetchByAssetId(
|
|
16
|
-
host: EFMedia,
|
|
17
|
-
_urlGenerator: UrlGenerator,
|
|
18
|
-
assetId: string,
|
|
19
|
-
apiHost: string,
|
|
20
|
-
) {
|
|
21
|
-
const url = `${apiHost}/api/v1/isobmff_files/${assetId}/index`;
|
|
22
|
-
const response = await host.fetch(url);
|
|
23
|
-
const data = (await response.json()) as Record<number, TrackFragmentIndex>;
|
|
24
|
-
return new AssetIdMediaEngine(host, assetId, data, apiHost);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
host: EFMedia,
|
|
29
|
-
public assetId: string,
|
|
30
|
-
data: Record<number, TrackFragmentIndex>,
|
|
31
|
-
private apiHost: string,
|
|
32
|
-
) {
|
|
33
|
-
// Pass assetId as src to parent constructor for compatibility
|
|
34
|
-
super(host, assetId);
|
|
35
|
-
// Initialize data after parent constructor
|
|
36
|
-
this.data = data;
|
|
37
|
-
|
|
38
|
-
// Calculate duration from the data
|
|
39
|
-
const longestFragment = Object.values(this.data).reduce(
|
|
40
|
-
(max, fragment) => Math.max(max, fragment.duration / fragment.timescale),
|
|
41
|
-
0,
|
|
42
|
-
);
|
|
43
|
-
this.durationMs = longestFragment * 1000;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Override URL-building methods to use API endpoints instead of file paths
|
|
47
|
-
get initSegmentPaths() {
|
|
48
|
-
const paths: InitSegmentPaths = {};
|
|
49
|
-
|
|
50
|
-
if (this.audioTrackIndex !== undefined) {
|
|
51
|
-
paths.audio = {
|
|
52
|
-
path: `${this.apiHost}/api/v1/isobmff_tracks/${this.assetId}/${this.audioTrackIndex.track}`,
|
|
53
|
-
pos: this.audioTrackIndex.initSegment.offset,
|
|
54
|
-
size: this.audioTrackIndex.initSegment.size,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (this.videoTrackIndex !== undefined) {
|
|
59
|
-
paths.video = {
|
|
60
|
-
path: `${this.apiHost}/api/v1/isobmff_tracks/${this.assetId}/${this.videoTrackIndex.track}`,
|
|
61
|
-
pos: this.videoTrackIndex.initSegment.offset,
|
|
62
|
-
size: this.videoTrackIndex.initSegment.size,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return paths;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
get templates() {
|
|
70
|
-
return {
|
|
71
|
-
initSegment: `${this.apiHost}/api/v1/isobmff_tracks/${this.assetId}/{trackId}`,
|
|
72
|
-
mediaSegment: `${this.apiHost}/api/v1/isobmff_tracks/${this.assetId}/{trackId}`,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
buildInitSegmentUrl(trackId: number) {
|
|
77
|
-
return `${this.apiHost}/api/v1/isobmff_tracks/${this.assetId}/${trackId}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
buildMediaSegmentUrl(trackId: number, _segmentId: number) {
|
|
81
|
-
return `${this.apiHost}/api/v1/isobmff_tracks/${this.assetId}/${trackId}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
convertToSegmentRelativeTimestamps(
|
|
85
|
-
globalTimestamps: number[],
|
|
86
|
-
segmentId: number,
|
|
87
|
-
rendition: VideoRendition,
|
|
88
|
-
): number[] {
|
|
89
|
-
if (!rendition.trackId) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
"[convertToSegmentRelativeTimestamps] Track ID is required for asset metadata",
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
// For AssetMediaEngine, we need to calculate the actual segment start time
|
|
95
|
-
// using the precise segment boundaries from the track fragment index
|
|
96
|
-
const trackData = this.data[rendition.trackId];
|
|
97
|
-
if (!trackData) {
|
|
98
|
-
throw new Error("Track not found");
|
|
99
|
-
}
|
|
100
|
-
const segment = trackData.segments?.[segmentId];
|
|
101
|
-
if (!segment) {
|
|
102
|
-
throw new Error("Segment not found");
|
|
103
|
-
}
|
|
104
|
-
const segmentStartMs = (segment.cts / trackData.timescale) * 1000;
|
|
105
|
-
|
|
106
|
-
return globalTimestamps.map(
|
|
107
|
-
(globalMs) => (globalMs - segmentStartMs) / 1000,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { describe } from "vitest";
|
|
2
|
-
import { test as baseTest } from "../../../test/useMSW.js";
|
|
3
|
-
|
|
4
|
-
import { UrlGenerator } from "../../transcoding/utils/UrlGenerator";
|
|
5
|
-
import "../EFVideo.js";
|
|
6
|
-
import type { EFVideo } from "../EFVideo.js";
|
|
7
|
-
import { AssetMediaEngine } from "./AssetMediaEngine";
|
|
8
|
-
|
|
9
|
-
const test = baseTest.extend<{
|
|
10
|
-
urlGenerator: UrlGenerator;
|
|
11
|
-
mediaEngine: AssetMediaEngine;
|
|
12
|
-
host: EFVideo;
|
|
13
|
-
}>({
|
|
14
|
-
host: async ({}, use: any) => {
|
|
15
|
-
const configuration = document.createElement("ef-configuration");
|
|
16
|
-
const apiHost = `${window.location.protocol}//${window.location.host}`;
|
|
17
|
-
configuration.setAttribute("api-host", apiHost);
|
|
18
|
-
configuration.apiHost = apiHost;
|
|
19
|
-
|
|
20
|
-
const host = document.createElement("ef-video");
|
|
21
|
-
configuration.appendChild(host);
|
|
22
|
-
host.src = "bars-n-tone.mp4";
|
|
23
|
-
await use(host as EFVideo);
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
urlGenerator: async ({}, use: any) => {
|
|
27
|
-
const apiHost = `${window.location.protocol}//${window.location.host}`;
|
|
28
|
-
const generator = new UrlGenerator(() => apiHost);
|
|
29
|
-
await use(generator);
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
mediaEngine: async ({ urlGenerator, host }, use: any) => {
|
|
33
|
-
const engine = await AssetMediaEngine.fetch(host, urlGenerator, host.src);
|
|
34
|
-
await use(engine);
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe("AssetMediaEngine", () => {
|
|
39
|
-
test("provides duration from fragment index data", async ({
|
|
40
|
-
mediaEngine,
|
|
41
|
-
expect,
|
|
42
|
-
}) => {
|
|
43
|
-
expect(mediaEngine.durationMs).toBeCloseTo(10031, 0); // Updated: improved mediabunny processing changed duration
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test("provides source URL from constructor", async ({
|
|
47
|
-
mediaEngine,
|
|
48
|
-
host,
|
|
49
|
-
expect,
|
|
50
|
-
}) => {
|
|
51
|
-
expect(mediaEngine.src).toBe(host.src);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("returns audio rendition with correct properties", ({
|
|
55
|
-
mediaEngine,
|
|
56
|
-
host,
|
|
57
|
-
expect,
|
|
58
|
-
}) => {
|
|
59
|
-
const audioRendition = mediaEngine.audioRendition;
|
|
60
|
-
expect(audioRendition).toBeDefined();
|
|
61
|
-
expect(audioRendition!.trackId).toBe(2);
|
|
62
|
-
expect(audioRendition!.src).toBe(host.src);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("returns video rendition with correct properties", ({
|
|
66
|
-
mediaEngine,
|
|
67
|
-
host,
|
|
68
|
-
expect,
|
|
69
|
-
}) => {
|
|
70
|
-
const videoRendition = mediaEngine.videoRendition;
|
|
71
|
-
expect(videoRendition).toBeDefined();
|
|
72
|
-
expect(videoRendition!.trackId).toBe(1);
|
|
73
|
-
expect(videoRendition!.src).toBe(host.src);
|
|
74
|
-
expect(videoRendition!.startTimeOffsetMs).toBeCloseTo(66.6, 0);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("provides templates for asset endpoints", ({ mediaEngine, expect }) => {
|
|
78
|
-
expect(mediaEngine.templates).toEqual({
|
|
79
|
-
initSegment: "/@ef-track/{src}?trackId={trackId}",
|
|
80
|
-
mediaSegment: "/@ef-track/{src}?trackId={trackId}",
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test("builds init and media segment URLs", ({
|
|
85
|
-
mediaEngine,
|
|
86
|
-
host,
|
|
87
|
-
expect,
|
|
88
|
-
}) => {
|
|
89
|
-
expect(mediaEngine.buildInitSegmentUrl(2)).toBe(
|
|
90
|
-
`/@ef-track/${host.src}?trackId=2`,
|
|
91
|
-
);
|
|
92
|
-
expect(mediaEngine.buildMediaSegmentUrl(2, 5)).toBe(
|
|
93
|
-
`/@ef-track/${host.src}?trackId=2&segmentId=5`,
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("computes segment ID for audio (0-based)", ({ mediaEngine, expect }) => {
|
|
98
|
-
const audio = mediaEngine.audioRendition;
|
|
99
|
-
expect(mediaEngine.computeSegmentId(500, audio as any)).toBe(0);
|
|
100
|
-
expect(mediaEngine.computeSegmentId(1500, audio as any)).toBe(0);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe("bars n tone segment id computation", () => {
|
|
104
|
-
test("computes 0ms is 0", ({ expect, mediaEngine }) => {
|
|
105
|
-
const videoRendition = mediaEngine.getVideoRendition();
|
|
106
|
-
expect(videoRendition).toBeDefined();
|
|
107
|
-
expect(mediaEngine.computeSegmentId(0, videoRendition!)).toBe(0);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test("computes 2000 is 1", ({ expect, mediaEngine }) => {
|
|
111
|
-
const videoRendition = mediaEngine.getVideoRendition();
|
|
112
|
-
expect(videoRendition).toBeDefined();
|
|
113
|
-
expect(mediaEngine.computeSegmentId(2000, videoRendition!)).toBe(1);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test("computes 4000 is 2", ({ expect, mediaEngine }) => {
|
|
117
|
-
const videoRendition = mediaEngine.getVideoRendition();
|
|
118
|
-
expect(videoRendition).toBeDefined();
|
|
119
|
-
expect(mediaEngine.computeSegmentId(4000, videoRendition!)).toBe(2);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test("computes 6000 is 3", ({ expect, mediaEngine }) => {
|
|
123
|
-
const videoRendition = mediaEngine.getVideoRendition();
|
|
124
|
-
expect(videoRendition).toBeDefined();
|
|
125
|
-
expect(mediaEngine.computeSegmentId(6000, videoRendition!)).toBe(3);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test("computes 8000 is 4", ({ expect, mediaEngine }) => {
|
|
129
|
-
const videoRendition = mediaEngine.getVideoRendition();
|
|
130
|
-
expect(videoRendition).toBeDefined();
|
|
131
|
-
expect(mediaEngine.computeSegmentId(8000, videoRendition!)).toBe(4);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("computes 7975 is 3", ({ expect, mediaEngine }) => {
|
|
135
|
-
const videoRendition = mediaEngine.getVideoRendition();
|
|
136
|
-
expect(videoRendition).toBeDefined();
|
|
137
|
-
expect(mediaEngine.computeSegmentId(7975, videoRendition!)).toBe(3);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|