@meframe/core 0.6.13 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -0
- package/README.md +17 -5
- package/dist/Meframe.d.ts +14 -3
- package/dist/Meframe.d.ts.map +1 -1
- package/dist/Meframe.js +22 -12
- package/dist/Meframe.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +2 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +5 -0
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/l1/VideoL1Cache.d.ts +2 -0
- package/dist/cache/l1/VideoL1Cache.d.ts.map +1 -1
- package/dist/cache/l1/VideoL1Cache.js +13 -7
- package/dist/cache/l1/VideoL1Cache.js.map +1 -1
- package/dist/cache/l2/IndexedDBStore.d.ts +1 -2
- package/dist/cache/l2/IndexedDBStore.d.ts.map +1 -1
- package/dist/cache/l2/L2Cache.d.ts +3 -2
- package/dist/cache/l2/L2Cache.d.ts.map +1 -1
- package/dist/cache/l2/L2OPFSStore.d.ts +3 -3
- package/dist/cache/l2/L2OPFSStore.d.ts.map +1 -1
- package/dist/cache/l2/OPFSStore.d.ts +1 -2
- package/dist/cache/l2/OPFSStore.d.ts.map +1 -1
- package/dist/cache/resource/AudioSampleCache.d.ts +12 -0
- package/dist/cache/resource/AudioSampleCache.d.ts.map +1 -1
- package/dist/cache/resource/AudioSampleCache.js +39 -5
- package/dist/cache/resource/AudioSampleCache.js.map +1 -1
- package/dist/cache/resource/ResourceCache.d.ts +4 -12
- package/dist/cache/resource/ResourceCache.d.ts.map +1 -1
- package/dist/cache/resource/ResourceCache.js +7 -24
- package/dist/cache/resource/ResourceCache.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +4 -1
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/types.d.ts +29 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/validation.d.ts.map +1 -1
- package/dist/config/validation.js +3 -0
- package/dist/config/validation.js.map +1 -1
- package/dist/controllers/PlaybackController.d.ts +38 -9
- package/dist/controllers/PlaybackController.d.ts.map +1 -1
- package/dist/controllers/PlaybackController.js +269 -154
- package/dist/controllers/PlaybackController.js.map +1 -1
- package/dist/controllers/PlaybackStateMachine.d.ts.map +1 -1
- package/dist/controllers/PlaybackStateMachine.js +2 -1
- package/dist/controllers/PlaybackStateMachine.js.map +1 -1
- package/dist/controllers/types.d.ts +10 -2
- package/dist/controllers/types.d.ts.map +1 -1
- package/dist/controllers/types.js.map +1 -1
- package/dist/event/events.d.ts +2 -0
- package/dist/event/events.d.ts.map +1 -1
- package/dist/event/events.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/CompositionModel.d.ts +0 -1
- package/dist/model/CompositionModel.d.ts.map +1 -1
- package/dist/model/CompositionModel.js +0 -6
- package/dist/model/CompositionModel.js.map +1 -1
- package/dist/model/patch.js +12 -12
- package/dist/model/patch.js.map +1 -1
- package/dist/node_modules/.pnpm/{mp4-muxer@5.2.2 → mp4-muxer@5.2.2_patch_hash_452653ac44da4ef32d244694e500e34d084eaa3c4232515ddec962eacc5f30ea}/node_modules/mp4-muxer/build/mp4-muxer.js +17 -3
- package/dist/node_modules/.pnpm/mp4-muxer@5.2.2_patch_hash_452653ac44da4ef32d244694e500e34d084eaa3c4232515ddec962eacc5f30ea/node_modules/mp4-muxer/build/mp4-muxer.js.map +1 -0
- package/dist/orchestrator/AudioExportSession.d.ts +28 -3
- package/dist/orchestrator/AudioExportSession.d.ts.map +1 -1
- package/dist/orchestrator/AudioExportSession.js +131 -15
- package/dist/orchestrator/AudioExportSession.js.map +1 -1
- package/dist/orchestrator/AudioPreviewSession.d.ts +6 -1
- package/dist/orchestrator/AudioPreviewSession.d.ts.map +1 -1
- package/dist/orchestrator/AudioPreviewSession.js +57 -18
- package/dist/orchestrator/AudioPreviewSession.js.map +1 -1
- package/dist/orchestrator/AudioWindowPreparer.d.ts +6 -4
- package/dist/orchestrator/AudioWindowPreparer.d.ts.map +1 -1
- package/dist/orchestrator/AudioWindowPreparer.js +247 -54
- package/dist/orchestrator/AudioWindowPreparer.js.map +1 -1
- package/dist/orchestrator/CompositionPlanner.d.ts +5 -2
- package/dist/orchestrator/CompositionPlanner.d.ts.map +1 -1
- package/dist/orchestrator/CompositionPlanner.js +8 -3
- package/dist/orchestrator/CompositionPlanner.js.map +1 -1
- package/dist/orchestrator/ExportScheduler.d.ts +1 -0
- package/dist/orchestrator/ExportScheduler.d.ts.map +1 -1
- package/dist/orchestrator/ExportScheduler.js +177 -106
- package/dist/orchestrator/ExportScheduler.js.map +1 -1
- package/dist/orchestrator/Orchestrator.d.ts +30 -4
- package/dist/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/Orchestrator.js +264 -111
- package/dist/orchestrator/Orchestrator.js.map +1 -1
- package/dist/orchestrator/PreviewFrameScheduler.d.ts +21 -1
- package/dist/orchestrator/PreviewFrameScheduler.d.ts.map +1 -1
- package/dist/orchestrator/PreviewFrameScheduler.js +129 -30
- package/dist/orchestrator/PreviewFrameScheduler.js.map +1 -1
- package/dist/orchestrator/VideoWindowDecodeSession.d.ts +22 -1
- package/dist/orchestrator/VideoWindowDecodeSession.d.ts.map +1 -1
- package/dist/orchestrator/VideoWindowDecodeSession.js +426 -198
- package/dist/orchestrator/VideoWindowDecodeSession.js.map +1 -1
- package/dist/orchestrator/aac-window-timeline.d.ts +6 -2
- package/dist/orchestrator/aac-window-timeline.d.ts.map +1 -1
- package/dist/orchestrator/aac-window-timeline.js +156 -19
- package/dist/orchestrator/aac-window-timeline.js.map +1 -1
- package/dist/orchestrator/types.d.ts +5 -1
- package/dist/orchestrator/types.d.ts.map +1 -1
- package/dist/stages/compose/FrameRateConverter.d.ts +2 -1
- package/dist/stages/compose/FrameRateConverter.d.ts.map +1 -1
- package/dist/stages/compose/LayerRenderPolicy.d.ts +14 -0
- package/dist/stages/compose/LayerRenderPolicy.d.ts.map +1 -0
- package/dist/stages/compose/LayerRenderPolicy.js +18 -0
- package/dist/stages/compose/LayerRenderPolicy.js.map +1 -0
- package/dist/stages/compose/OfflineAudioMixer.d.ts +2 -0
- package/dist/stages/compose/OfflineAudioMixer.d.ts.map +1 -1
- package/dist/stages/compose/OfflineAudioMixer.js +14 -2
- package/dist/stages/compose/OfflineAudioMixer.js.map +1 -1
- package/dist/stages/compose/OwnedFrameTransform.d.ts +52 -0
- package/dist/stages/compose/OwnedFrameTransform.d.ts.map +1 -0
- package/dist/stages/compose/OwnedFrameTransform.js +154 -0
- package/dist/stages/compose/OwnedFrameTransform.js.map +1 -0
- package/dist/stages/compose/TransitionProcessor.js +0 -1
- package/dist/stages/compose/TransitionProcessor.js.map +1 -1
- package/dist/stages/compose/VideoComposer.d.ts +12 -2
- package/dist/stages/compose/VideoComposer.d.ts.map +1 -1
- package/dist/stages/compose/VideoComposer.js +100 -92
- package/dist/stages/compose/VideoComposer.js.map +1 -1
- package/dist/stages/compose/text-renderers/basic-text-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/basic-text-renderer.js +24 -21
- package/dist/stages/compose/text-renderers/basic-text-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/caption-stagger-entrance-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/caption-stagger-entrance-renderer.js +110 -99
- package/dist/stages/compose/text-renderers/caption-stagger-entrance-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/character-ktv-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/character-ktv-renderer.js +41 -38
- package/dist/stages/compose/text-renderers/character-ktv-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/word-by-word-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/word-by-word-renderer.js +47 -39
- package/dist/stages/compose/text-renderers/word-by-word-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/word-fancy-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/word-fancy-renderer.js +54 -48
- package/dist/stages/compose/text-renderers/word-fancy-renderer.js.map +1 -1
- package/dist/stages/compose/text-utils/text-metrics.d.ts.map +1 -1
- package/dist/stages/compose/text-utils/text-metrics.js +6 -4
- package/dist/stages/compose/text-utils/text-metrics.js.map +1 -1
- package/dist/stages/compose/types.d.ts +12 -0
- package/dist/stages/compose/types.d.ts.map +1 -1
- package/dist/stages/decode/BaseDecoder.d.ts +5 -0
- package/dist/stages/decode/BaseDecoder.d.ts.map +1 -1
- package/dist/stages/decode/BaseDecoder.js +52 -10
- package/dist/stages/decode/BaseDecoder.js.map +1 -1
- package/dist/stages/decode/preview-video-decoder.d.ts +48 -2
- package/dist/stages/decode/preview-video-decoder.d.ts.map +1 -1
- package/dist/stages/decode/preview-video-decoder.js +241 -71
- package/dist/stages/decode/preview-video-decoder.js.map +1 -1
- package/dist/stages/decode/video-decoder.d.ts +2 -11
- package/dist/stages/decode/video-decoder.d.ts.map +1 -1
- package/dist/stages/decode/video-decoder.js +60 -61
- package/dist/stages/decode/video-decoder.js.map +1 -1
- package/dist/stages/demux/MP3FrameParser.d.ts +18 -0
- package/dist/stages/demux/MP3FrameParser.d.ts.map +1 -1
- package/dist/stages/demux/MP3FrameParser.js +143 -11
- package/dist/stages/demux/MP3FrameParser.js.map +1 -1
- package/dist/stages/demux/MP4IndexParser.d.ts +32 -21
- package/dist/stages/demux/MP4IndexParser.d.ts.map +1 -1
- package/dist/stages/demux/MP4IndexParser.js +202 -309
- package/dist/stages/demux/MP4IndexParser.js.map +1 -1
- package/dist/stages/demux/sample-collector.d.ts +35 -0
- package/dist/stages/demux/sample-collector.d.ts.map +1 -0
- package/dist/stages/demux/sample-collector.js +105 -0
- package/dist/stages/demux/sample-collector.js.map +1 -0
- package/dist/stages/encode/BaseEncoder.d.ts +9 -2
- package/dist/stages/encode/BaseEncoder.d.ts.map +1 -1
- package/dist/stages/encode/BaseEncoder.js +90 -59
- package/dist/stages/encode/BaseEncoder.js.map +1 -1
- package/dist/stages/load/ResourceLoader.d.ts +71 -18
- package/dist/stages/load/ResourceLoader.d.ts.map +1 -1
- package/dist/stages/load/ResourceLoader.js +369 -143
- package/dist/stages/load/ResourceLoader.js.map +1 -1
- package/dist/stages/load/TaskManager.d.ts.map +1 -1
- package/dist/stages/load/TaskManager.js +9 -3
- package/dist/stages/load/TaskManager.js.map +1 -1
- package/dist/stages/load/types.d.ts +2 -2
- package/dist/stages/load/types.d.ts.map +1 -1
- package/dist/stages/mux/MP4Muxer.d.ts +7 -1
- package/dist/stages/mux/MP4Muxer.d.ts.map +1 -1
- package/dist/stages/mux/MP4Muxer.js +8 -10
- package/dist/stages/mux/MP4Muxer.js.map +1 -1
- package/dist/stages/mux/MuxManager.d.ts +7 -0
- package/dist/stages/mux/MuxManager.d.ts.map +1 -1
- package/dist/stages/mux/MuxManager.js +9 -0
- package/dist/stages/mux/MuxManager.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +2 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +10 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/until-aborted.d.ts +8 -0
- package/dist/utils/until-aborted.d.ts.map +1 -0
- package/dist/utils/until-aborted.js +33 -0
- package/dist/utils/until-aborted.js.map +1 -0
- package/dist/worker/WorkerChannel.d.ts.map +1 -1
- package/dist/worker/WorkerChannel.js +45 -10
- package/dist/worker/WorkerChannel.js.map +1 -1
- package/dist/worker/worker-manifest.js +1 -1
- package/dist/worker/worker-manifest.js.map +1 -1
- package/dist/workers/stages/export/{export.worker.C8jKSbVj.js → export.worker.BG8HA7dY.js} +745 -450
- package/dist/workers/stages/export/export.worker.BG8HA7dY.js.map +1 -0
- package/dist/workers/worker-manifest.json +1 -1
- package/package.json +23 -22
- package/dist/node_modules/.pnpm/mp4-muxer@5.2.2/node_modules/mp4-muxer/build/mp4-muxer.js.map +0 -1
- package/dist/workers/stages/export/export.worker.C8jKSbVj.js.map +0 -1
|
@@ -15,7 +15,7 @@ import { MuxManager } from "../stages/mux/MuxManager.js";
|
|
|
15
15
|
import { VideoWindowDecodeSession } from "./VideoWindowDecodeSession.js";
|
|
16
16
|
import { ExportScheduler } from "./ExportScheduler.js";
|
|
17
17
|
import { filterRenderConfig } from "../utils/object-utils.js";
|
|
18
|
-
import { isTerminalMediaResourceError } from "../utils/errors.js";
|
|
18
|
+
import { isReportedToHost, isTerminalMediaResourceError } from "../utils/errors.js";
|
|
19
19
|
import { attachmentEntranceRelativeTimeUs, attachmentActiveDurationUs } from "../stages/compose/text-layer-animation-time.js";
|
|
20
20
|
import { playbackDiagnostic } from "../utils/playback-diagnostics.js";
|
|
21
21
|
import { binarySearchFirst } from "../utils/binary-search.js";
|
|
@@ -33,18 +33,38 @@ class Orchestrator {
|
|
|
33
33
|
config = ConfigLoader.getInstance().getConfig();
|
|
34
34
|
ensureCacheDebounceTimer = null;
|
|
35
35
|
activeDecodeSession = null;
|
|
36
|
+
disposed = false;
|
|
37
|
+
disposePromise = null;
|
|
38
|
+
// Work that drain() and dispose() wait for; settled work leaves the set.
|
|
39
|
+
work = /* @__PURE__ */ new Set();
|
|
40
|
+
decodeSessions = /* @__PURE__ */ new Set();
|
|
41
|
+
// Aborted when the model is replaced (drain) or the engine is disposed.
|
|
42
|
+
lifetime = new AbortController();
|
|
43
|
+
disposal = new AbortController();
|
|
44
|
+
exports = /* @__PURE__ */ new Set();
|
|
36
45
|
previewFrames = new PreviewFrameScheduler(
|
|
37
46
|
(clipId, timeUs) => this.getCachedPreviewFrame(clipId, timeUs),
|
|
38
|
-
(error) =>
|
|
47
|
+
(error) => {
|
|
48
|
+
if (!isReportedToHost(error)) this.eventBus.emit(MeframeEvent.PlaybackError, error);
|
|
49
|
+
}
|
|
39
50
|
);
|
|
40
51
|
getCachedPreviewFrame(clipId, timeUs) {
|
|
41
52
|
return this.cacheManager.videoL1Cache.getCovering(clipId, timeUs);
|
|
42
53
|
}
|
|
54
|
+
getPreviewLookaheadUs() {
|
|
55
|
+
const meta = this.cacheManager?.videoL1Cache?.getMetadata();
|
|
56
|
+
if (!meta) return 1e6;
|
|
57
|
+
return meta.maxFrames >= 60 && meta.maxSize >= 256 * 1024 * 1024 ? 2e6 : 1e6;
|
|
58
|
+
}
|
|
43
59
|
configurePreviewBudget(timeUs) {
|
|
44
60
|
const model = this.compositionModel;
|
|
45
61
|
if (!model || this.cacheManager.isExporting) return;
|
|
46
62
|
const demands = [];
|
|
47
|
-
for (const clip of model.getClipsInRange(
|
|
63
|
+
for (const clip of model.getClipsInRange(
|
|
64
|
+
timeUs,
|
|
65
|
+
timeUs + this.getPreviewLookaheadUs(),
|
|
66
|
+
model.mainTrackId
|
|
67
|
+
)) {
|
|
48
68
|
if (!hasResourceId(clip)) continue;
|
|
49
69
|
const resource = model.getResource(clip.resourceId);
|
|
50
70
|
if (resource?.state === "error" && resource.error?.terminal) continue;
|
|
@@ -119,6 +139,7 @@ class Orchestrator {
|
|
|
119
139
|
)
|
|
120
140
|
);
|
|
121
141
|
endUs = this.limitPreviewEnd(video, startUs, endUs, maxFrames);
|
|
142
|
+
endUs = Math.min(endUs, this.previewVideoTail(video)?.end ?? endUs);
|
|
122
143
|
}
|
|
123
144
|
return {
|
|
124
145
|
clipId: clip.id,
|
|
@@ -148,11 +169,9 @@ class Orchestrator {
|
|
|
148
169
|
modelToken = 0;
|
|
149
170
|
previewGeneration = 0;
|
|
150
171
|
previewVideoTails = /* @__PURE__ */ new WeakMap();
|
|
151
|
-
/**
|
|
152
|
-
|
|
153
|
-
if (
|
|
154
|
-
const video = this.cacheManager.mp4IndexCache.get(resourceId)?.tracks.video;
|
|
155
|
-
if (!video?.samples.length) return timeUs;
|
|
172
|
+
/** The last presentation frame of an indexed video track; null when the index does not tell where it ends. */
|
|
173
|
+
previewVideoTail(video) {
|
|
174
|
+
if (!video.samples.length) return null;
|
|
156
175
|
let tail = this.previewVideoTails.get(video);
|
|
157
176
|
if (!tail || tail.count !== video.samples.length) {
|
|
158
177
|
let last = video.samples[0];
|
|
@@ -166,10 +185,23 @@ class Orchestrator {
|
|
|
166
185
|
};
|
|
167
186
|
this.previewVideoTails.set(video, tail);
|
|
168
187
|
}
|
|
169
|
-
|
|
170
|
-
|
|
188
|
+
return Number.isFinite(tail.end) && tail.end > tail.pts ? tail : null;
|
|
189
|
+
}
|
|
190
|
+
/** Hold the final presentation frame only beyond the indexed video track's end. */
|
|
191
|
+
previewTimeWithinVideo(resourceId, timeUs) {
|
|
192
|
+
if (this.cacheManager.isExporting) return timeUs;
|
|
193
|
+
const video = this.cacheManager.mp4IndexCache.get(resourceId)?.tracks.video;
|
|
194
|
+
const tail = video ? this.previewVideoTail(video) : null;
|
|
195
|
+
return tail && timeUs >= tail.end - 1 ? tail.pts : timeUs;
|
|
171
196
|
}
|
|
172
197
|
events;
|
|
198
|
+
/** Work that drain() and dispose() wait for; settled work leaves the set. */
|
|
199
|
+
trackWork(promise) {
|
|
200
|
+
this.work.add(promise);
|
|
201
|
+
const forget = () => this.work.delete(promise);
|
|
202
|
+
promise.then(forget, forget);
|
|
203
|
+
return promise;
|
|
204
|
+
}
|
|
173
205
|
constructor(config) {
|
|
174
206
|
this.eventBus = config.eventBus || new EventBus();
|
|
175
207
|
this.events = this.eventBus.asReadonly();
|
|
@@ -214,21 +246,24 @@ class Orchestrator {
|
|
|
214
246
|
maxConcurrent: Math.max(this.config.load.maxConcurrent ?? 3, 4),
|
|
215
247
|
preloadConcurrency: 1
|
|
216
248
|
},
|
|
217
|
-
onStateChange: (resourceId, state) => this.handleResourceStateChange(resourceId, state),
|
|
218
249
|
onResourceInvalidated: (resourceId) => this.invalidateResourceData(resourceId),
|
|
219
|
-
ensureCached: config.resourceLoader.ensureCached
|
|
250
|
+
ensureCached: config.resourceLoader.ensureCached,
|
|
251
|
+
getCompositionModel: () => this.compositionModel
|
|
220
252
|
});
|
|
221
|
-
this.planner = new CompositionPlanner();
|
|
253
|
+
this.planner = new CompositionPlanner(() => this.compositionModel);
|
|
222
254
|
const audioPreparer = new AudioWindowPreparer({
|
|
223
255
|
cacheManager: this.cacheManager,
|
|
224
256
|
resourceLoader: this.resourceLoader,
|
|
225
|
-
eventBus: this.eventBus
|
|
257
|
+
eventBus: this.eventBus,
|
|
258
|
+
getCompositionModel: () => this.compositionModel
|
|
226
259
|
});
|
|
227
260
|
const audioPreview = new AudioPreviewSession({
|
|
261
|
+
onError: (error) => this.eventBus.emit(MeframeEvent.PlaybackError, error),
|
|
228
262
|
cacheManager: this.cacheManager,
|
|
229
263
|
preparer: audioPreparer
|
|
230
264
|
});
|
|
231
265
|
const audioExport = new AudioExportSession({
|
|
266
|
+
encoderFactory: this.config.encode?.audio?.encoderFactory,
|
|
232
267
|
cacheManager: this.cacheManager,
|
|
233
268
|
preparer: audioPreparer
|
|
234
269
|
});
|
|
@@ -249,21 +284,23 @@ class Orchestrator {
|
|
|
249
284
|
setupResourceFirstFrameHandler() {
|
|
250
285
|
this.eventBus.on(MeframeEvent.ResourceFirstFrameReady, async (payload) => {
|
|
251
286
|
const { resourceId, clipId, index, chunks } = payload;
|
|
252
|
-
if (!this.compositionModel) return;
|
|
287
|
+
if (!this.compositionModel || this.disposed) return;
|
|
253
288
|
const clip = this.compositionModel.findClip(clipId);
|
|
254
289
|
if (!clip || !clip.trackId) return;
|
|
255
290
|
if (clip.startUs === 0) {
|
|
256
291
|
const fps = this.compositionModel.fps ?? 30;
|
|
257
292
|
const model = this.compositionModel;
|
|
258
293
|
const generation = this.previewGeneration;
|
|
259
|
-
await
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
294
|
+
await this.trackWork(
|
|
295
|
+
VideoWindowDecodeSession.decodeAndCacheFirstFrame(
|
|
296
|
+
resourceId,
|
|
297
|
+
chunks,
|
|
298
|
+
index,
|
|
299
|
+
clip,
|
|
300
|
+
this.cacheManager,
|
|
301
|
+
fps,
|
|
302
|
+
() => this.compositionModel === model && this.previewGeneration === generation
|
|
303
|
+
)
|
|
267
304
|
);
|
|
268
305
|
}
|
|
269
306
|
});
|
|
@@ -305,7 +342,8 @@ class Orchestrator {
|
|
|
305
342
|
}
|
|
306
343
|
}
|
|
307
344
|
}
|
|
308
|
-
async setCompositionModel(model) {
|
|
345
|
+
async setCompositionModel(model, options) {
|
|
346
|
+
await this.drain();
|
|
309
347
|
this.cacheManager.clear();
|
|
310
348
|
this.cancelActiveDecoding();
|
|
311
349
|
this.audio.preview.stopPlayback();
|
|
@@ -314,7 +352,7 @@ class Orchestrator {
|
|
|
314
352
|
this.compositionModel = model;
|
|
315
353
|
this.planner.setModel(model);
|
|
316
354
|
this.audio.prepare.setModel(model);
|
|
317
|
-
const resourceLoaderSetModelPromise = this.resourceLoader.setModel(model);
|
|
355
|
+
const resourceLoaderSetModelPromise = this.resourceLoader.setModel(model, options);
|
|
318
356
|
await resourceLoaderSetModelPromise;
|
|
319
357
|
this.eventBus.emit(MeframeEvent.ModelSet, model);
|
|
320
358
|
this.eventBus.emit(MeframeEvent.CompositionUpdated, {
|
|
@@ -332,6 +370,7 @@ class Orchestrator {
|
|
|
332
370
|
this.audio.preview.invalidatePreviewMixCache();
|
|
333
371
|
this.audio.preview.resetPlaybackStates();
|
|
334
372
|
const affectedClipIds = applyPatch(this.compositionModel, patch);
|
|
373
|
+
const reidentified = this.resourceLoader.refreshResourceIdentities(this.compositionModel);
|
|
335
374
|
this.planner.applyPatch(patch, affectedClipIds);
|
|
336
375
|
this.eventBus.emit(MeframeEvent.PatchApplied, {
|
|
337
376
|
operations: patch.operations.length,
|
|
@@ -347,20 +386,24 @@ class Orchestrator {
|
|
|
347
386
|
await this.audio.prepare.deactivateClip(clipId);
|
|
348
387
|
}
|
|
349
388
|
}
|
|
350
|
-
|
|
389
|
+
if (reidentified.length > 0) this.resourceLoader.startPreloading(new Set(reidentified));
|
|
351
390
|
await this.audio.prepare.activateAllAudioClips();
|
|
352
391
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
392
|
+
/** Loads a resource again after the host repaired its bytes; see ResourceLoader.reloadResource. */
|
|
393
|
+
reloadResource(resourceId) {
|
|
394
|
+
if (!this.compositionModel) return Promise.reject(new Error("No composition model set"));
|
|
395
|
+
return this.trackWork(
|
|
396
|
+
this.resourceLoader.reloadResource(resourceId, { signal: this.lifetime.signal })
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
getFrame(timeUs, options) {
|
|
400
|
+
return this.trackWork(this.getFrameInternal(timeUs, options));
|
|
361
401
|
}
|
|
362
|
-
async
|
|
402
|
+
async getFrameInternal(timeUs, options) {
|
|
403
|
+
this.lifetime.signal.throwIfAborted();
|
|
404
|
+
options?.signal?.throwIfAborted();
|
|
363
405
|
const signal = options?.signal;
|
|
406
|
+
const owned = options?.owned === true;
|
|
364
407
|
const preheat = options?.preheat ?? false;
|
|
365
408
|
const scrub = options?.scrub ?? false;
|
|
366
409
|
const mode = options?.mode ?? "blocking";
|
|
@@ -400,7 +443,7 @@ class Orchestrator {
|
|
|
400
443
|
resourceTimeUs,
|
|
401
444
|
scrub: true
|
|
402
445
|
});
|
|
403
|
-
return cachedFrame;
|
|
446
|
+
return this.cacheManager.cloneForCaller(cachedFrame, owned);
|
|
404
447
|
}
|
|
405
448
|
} else {
|
|
406
449
|
const covering = this.getCachedPreviewFrame(clip.id, resourceTimeUs);
|
|
@@ -411,7 +454,7 @@ class Orchestrator {
|
|
|
411
454
|
resourceTimeUs,
|
|
412
455
|
scrub: false
|
|
413
456
|
});
|
|
414
|
-
return covering;
|
|
457
|
+
return this.cacheManager.cloneForCaller(covering, owned);
|
|
415
458
|
}
|
|
416
459
|
playbackDiagnostic("frame.cache-gap", {
|
|
417
460
|
clipId: clip.id,
|
|
@@ -460,7 +503,8 @@ class Orchestrator {
|
|
|
460
503
|
const fetchOptions = {
|
|
461
504
|
isPreload: false,
|
|
462
505
|
clipId: clip.id,
|
|
463
|
-
trackId: clip.trackId
|
|
506
|
+
trackId: clip.trackId,
|
|
507
|
+
signal: options?.signal
|
|
464
508
|
};
|
|
465
509
|
const mode = options?.mode ?? "blocking";
|
|
466
510
|
if (isTerminalError) {
|
|
@@ -502,6 +546,7 @@ class Orchestrator {
|
|
|
502
546
|
});
|
|
503
547
|
return null;
|
|
504
548
|
}
|
|
549
|
+
if (options?.signal?.aborted || this.modelToken !== startModelToken) return null;
|
|
505
550
|
throw error;
|
|
506
551
|
}
|
|
507
552
|
if (this.modelToken !== startModelToken || this.compositionModel !== startModel) {
|
|
@@ -531,7 +576,7 @@ class Orchestrator {
|
|
|
531
576
|
const rate = videoClipPlaybackRate(clip);
|
|
532
577
|
const endUs = Math.min(
|
|
533
578
|
trimStartUs + clip.durationUs * rate,
|
|
534
|
-
resourceTimeUs +
|
|
579
|
+
resourceTimeUs + this.getPreviewLookaheadUs() * rate
|
|
535
580
|
);
|
|
536
581
|
playbackDiagnostic("decode.preview-start", {
|
|
537
582
|
clipId: clip.id,
|
|
@@ -542,8 +587,14 @@ class Orchestrator {
|
|
|
542
587
|
});
|
|
543
588
|
const frame = await this.previewFrames.request(
|
|
544
589
|
this.previewRequest(clip, resourceTimeUs, endUs, globalTimeUs),
|
|
545
|
-
resourceTimeUs
|
|
590
|
+
resourceTimeUs,
|
|
591
|
+
(cached) => this.cacheManager.cloneForCaller(cached, options?.owned === true),
|
|
592
|
+
options?.signal
|
|
546
593
|
);
|
|
594
|
+
if (this.modelToken !== startModelToken || options?.signal?.aborted) {
|
|
595
|
+
if (options?.owned === true) frame?.close();
|
|
596
|
+
return null;
|
|
597
|
+
}
|
|
547
598
|
playbackDiagnostic(frame ? "decode.preview-frame" : "decode.preview-empty", {
|
|
548
599
|
clipId: clip.id,
|
|
549
600
|
resourceTimeUs
|
|
@@ -564,10 +615,21 @@ class Orchestrator {
|
|
|
564
615
|
fps: this.compositionModel?.fps ?? 30
|
|
565
616
|
});
|
|
566
617
|
this.activeDecodeSession = session;
|
|
618
|
+
const owned = options?.owned === true;
|
|
619
|
+
this.decodeSessions.add(session);
|
|
620
|
+
if (this.disposed || options?.signal?.aborted) await session.dispose();
|
|
621
|
+
const abort = () => {
|
|
622
|
+
void session.dispose();
|
|
623
|
+
};
|
|
624
|
+
options?.signal?.addEventListener("abort", abort, { once: true });
|
|
567
625
|
try {
|
|
568
626
|
if (options?.scrub) {
|
|
569
627
|
await session.decodeScrub(resourceTimeUs);
|
|
570
|
-
|
|
628
|
+
if (this.modelToken !== startModelToken || options?.signal?.aborted) return null;
|
|
629
|
+
return this.cacheManager.cloneForCaller(
|
|
630
|
+
this.cacheManager.getFrame(resourceTimeUs, clip.id),
|
|
631
|
+
owned
|
|
632
|
+
);
|
|
571
633
|
}
|
|
572
634
|
const DECODE_WINDOW_SIZE = 6e6;
|
|
573
635
|
const playbackRate = videoClipPlaybackRate(clip);
|
|
@@ -575,18 +637,23 @@ class Orchestrator {
|
|
|
575
637
|
const windowStart = resourceTimeUs;
|
|
576
638
|
const windowEnd = Math.min(trimStartUs + resourceSpanUs, resourceTimeUs + DECODE_WINDOW_SIZE);
|
|
577
639
|
await session.decodeWindow(windowStart, windowEnd);
|
|
578
|
-
|
|
640
|
+
if (this.modelToken !== startModelToken || options?.signal?.aborted) return null;
|
|
641
|
+
return this.cacheManager.cloneForCaller(
|
|
642
|
+
this.cacheManager.getFrame(resourceTimeUs, clip.id),
|
|
643
|
+
owned
|
|
644
|
+
);
|
|
579
645
|
} catch (error) {
|
|
580
646
|
if (session.isDisposed) {
|
|
581
647
|
return null;
|
|
582
648
|
}
|
|
583
|
-
|
|
584
|
-
return null;
|
|
649
|
+
throw error;
|
|
585
650
|
} finally {
|
|
586
651
|
if (this.activeDecodeSession === session) {
|
|
587
652
|
this.activeDecodeSession = null;
|
|
588
653
|
}
|
|
654
|
+
options?.signal?.removeEventListener("abort", abort);
|
|
589
655
|
await session.dispose();
|
|
656
|
+
this.decodeSessions.delete(session);
|
|
590
657
|
}
|
|
591
658
|
}
|
|
592
659
|
/**
|
|
@@ -610,24 +677,58 @@ class Orchestrator {
|
|
|
610
677
|
timeoutMs: options?.timeoutMs ?? 5e3
|
|
611
678
|
});
|
|
612
679
|
}
|
|
613
|
-
|
|
680
|
+
/** Bumps the model token and aborts the lifetime signal, then resolves once work started before the call has settled. */
|
|
681
|
+
async drain() {
|
|
682
|
+
this.modelToken++;
|
|
683
|
+
this.lifetime.abort(new DOMException("Model replaced", "AbortError"));
|
|
684
|
+
const sessions = [...this.decodeSessions].map((session) => session.dispose());
|
|
685
|
+
await Promise.allSettled([
|
|
686
|
+
this.resourceLoader.drain(),
|
|
687
|
+
this.previewFrames.drain(),
|
|
688
|
+
...sessions,
|
|
689
|
+
...this.work
|
|
690
|
+
]);
|
|
691
|
+
this.activeDecodeSession = null;
|
|
692
|
+
this.decodeSessions.clear();
|
|
693
|
+
if (!this.disposed) this.lifetime = new AbortController();
|
|
694
|
+
}
|
|
695
|
+
/** Idempotent: the first call disposes every owned resource, later calls return the same promise. */
|
|
696
|
+
dispose() {
|
|
697
|
+
if (this.disposePromise) return this.disposePromise;
|
|
698
|
+
this.disposed = true;
|
|
699
|
+
this.modelToken++;
|
|
700
|
+
this.lifetime.abort(new DOMException("Engine disposed", "AbortError"));
|
|
701
|
+
this.disposal.abort(new DOMException("Engine disposed", "AbortError"));
|
|
614
702
|
if (this.ensureCacheDebounceTimer !== null) {
|
|
615
703
|
clearTimeout(this.ensureCacheDebounceTimer);
|
|
616
704
|
this.ensureCacheDebounceTimer = null;
|
|
617
705
|
}
|
|
618
706
|
this.audio.preview.reset();
|
|
619
707
|
this.audio.prepare.setModel(null);
|
|
620
|
-
this.resourceLoader.dispose();
|
|
708
|
+
const loads = this.resourceLoader.dispose();
|
|
621
709
|
this.cancelActiveDecoding();
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
710
|
+
const sessions = [...this.decodeSessions].map((session) => session.dispose());
|
|
711
|
+
this.disposePromise = (async () => {
|
|
712
|
+
await Promise.allSettled([
|
|
713
|
+
loads,
|
|
714
|
+
this.previewFrames.drain(),
|
|
715
|
+
...sessions,
|
|
716
|
+
...this.work,
|
|
717
|
+
...this.exports
|
|
718
|
+
]);
|
|
719
|
+
await this.audio.preview.drain();
|
|
720
|
+
await this.audio.prepare.drain();
|
|
721
|
+
await this.audio.export.abortExportAudio();
|
|
722
|
+
this.activeDecodeSession = null;
|
|
723
|
+
this.decodeSessions.clear();
|
|
724
|
+
this.cacheManager.clear();
|
|
725
|
+
this.cacheManager.audioSampleCache.clear();
|
|
726
|
+
this.cacheManager.mp4IndexCache.clear();
|
|
727
|
+
this.workers.terminateAll();
|
|
728
|
+
this.compositionModel = null;
|
|
729
|
+
this.eventBus.dispose();
|
|
730
|
+
})();
|
|
731
|
+
return this.disposePromise;
|
|
631
732
|
}
|
|
632
733
|
getAudioLifecycleSnapshot() {
|
|
633
734
|
const pcm = this.cacheManager.getAudioCacheStats();
|
|
@@ -716,8 +817,26 @@ class Orchestrator {
|
|
|
716
817
|
return 25e6;
|
|
717
818
|
}
|
|
718
819
|
}
|
|
820
|
+
/** Runs one export that ends with the caller's signal or with this orchestrator's disposal, whichever aborts first. */
|
|
719
821
|
async export(model, options) {
|
|
720
|
-
|
|
822
|
+
this.previewFrames.cancel();
|
|
823
|
+
const owner = new AbortController();
|
|
824
|
+
const sources = [options.signal, this.disposal.signal].filter(
|
|
825
|
+
(source) => !!source
|
|
826
|
+
);
|
|
827
|
+
const abort = (event) => owner.abort(event.target.reason);
|
|
828
|
+
for (const source of sources) {
|
|
829
|
+
if (source.aborted) owner.abort(source.reason);
|
|
830
|
+
else source.addEventListener("abort", abort, { once: true });
|
|
831
|
+
}
|
|
832
|
+
const task = this.exportScheduler.execute(model, { ...options, signal: owner.signal });
|
|
833
|
+
this.exports.add(task);
|
|
834
|
+
try {
|
|
835
|
+
return await task;
|
|
836
|
+
} finally {
|
|
837
|
+
this.exports.delete(task);
|
|
838
|
+
for (const source of sources) source.removeEventListener("abort", abort);
|
|
839
|
+
}
|
|
721
840
|
}
|
|
722
841
|
/**
|
|
723
842
|
* Preheat a specific clip's window range
|
|
@@ -730,12 +849,12 @@ class Orchestrator {
|
|
|
730
849
|
*/
|
|
731
850
|
async preheatClipWindow(clipId, clipRelativeStart, clipRelativeEnd, globalTimeUs) {
|
|
732
851
|
const model = this.compositionModel;
|
|
733
|
-
if (!model) return;
|
|
852
|
+
if (!model || this.disposed) return;
|
|
734
853
|
const clip = model.findClip(clipId);
|
|
735
854
|
if (!clip || !hasResourceId(clip)) return;
|
|
736
855
|
const activeWindow = model.getClipsInRange(
|
|
737
856
|
this.previewBudgetTimeUs,
|
|
738
|
-
this.previewBudgetTimeUs +
|
|
857
|
+
this.previewBudgetTimeUs + this.getPreviewLookaheadUs(),
|
|
739
858
|
model.mainTrackId
|
|
740
859
|
);
|
|
741
860
|
if (!activeWindow.some((candidate) => candidate.id === clipId)) return;
|
|
@@ -755,7 +874,7 @@ class Orchestrator {
|
|
|
755
874
|
const resourceEnd = trimStartUs + clipRelativeEnd * playbackRate;
|
|
756
875
|
if (resourceEnd <= resourceStart) return;
|
|
757
876
|
const request = this.previewRequest(clip, resourceStart, resourceEnd, globalTimeUs);
|
|
758
|
-
if (this.cacheManager.videoL1Cache.covers(clipId, request.startUs, request.endUs)) {
|
|
877
|
+
if (request.endUs <= request.startUs || this.cacheManager.videoL1Cache.covers(clipId, request.startUs, request.endUs)) {
|
|
759
878
|
playbackDiagnostic("preheat.covered", { clipId, resourceStart, resourceEnd });
|
|
760
879
|
return;
|
|
761
880
|
}
|
|
@@ -772,67 +891,90 @@ class Orchestrator {
|
|
|
772
891
|
if (!startModel) {
|
|
773
892
|
return null;
|
|
774
893
|
}
|
|
775
|
-
const frame = await this.getFrame(timeUs, options);
|
|
776
|
-
if (this.modelToken !== startModelToken || this.compositionModel !== startModel) {
|
|
894
|
+
const frame = await this.getFrame(timeUs, { ...options, owned: true });
|
|
895
|
+
if (this.modelToken !== startModelToken || this.compositionModel !== startModel || options?.signal?.aborted) {
|
|
896
|
+
frame?.close();
|
|
777
897
|
return null;
|
|
778
898
|
}
|
|
779
899
|
if (!frame) {
|
|
780
900
|
playbackDiagnostic("render.no-frame", { timeUs, mode: options?.mode ?? "blocking" });
|
|
781
901
|
return null;
|
|
782
902
|
}
|
|
783
|
-
const clip = startModel.getClipsAtTime(timeUs, startModel.mainTrackId)[0];
|
|
784
|
-
if (!clip) {
|
|
785
|
-
playbackDiagnostic("render.no-clip-after-frame", { timeUs });
|
|
786
|
-
return null;
|
|
787
|
-
}
|
|
788
|
-
const clipRelativeTimeUs = timeUs - clip.startUs;
|
|
789
|
-
const trimStartUs = clip.trimStartUs ?? 0;
|
|
790
|
-
const playbackRate = videoClipPlaybackRate(clip);
|
|
791
|
-
let resourceTimeUs = trimStartUs + clipRelativeTimeUs * playbackRate;
|
|
792
|
-
if (clip.durationUs > 0) {
|
|
793
|
-
const resourceSpanUs = clip.durationUs * playbackRate;
|
|
794
|
-
resourceTimeUs = Math.min(resourceTimeUs, trimStartUs + resourceSpanUs - 1);
|
|
795
|
-
}
|
|
796
|
-
const instructions = this.planner.getInstructions(clip.id);
|
|
797
|
-
if (!instructions) {
|
|
798
|
-
playbackDiagnostic("render.no-instructions", { timeUs, clipId: clip.id });
|
|
799
|
-
return null;
|
|
800
|
-
}
|
|
801
903
|
const layers = [];
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
904
|
+
let mainFrameUsed = false;
|
|
905
|
+
let complete = false;
|
|
906
|
+
try {
|
|
907
|
+
const clip = startModel.getClipsAtTime(timeUs, startModel.mainTrackId)[0];
|
|
908
|
+
if (!clip) {
|
|
909
|
+
playbackDiagnostic("render.no-clip-after-frame", { timeUs });
|
|
910
|
+
return null;
|
|
805
911
|
}
|
|
806
|
-
|
|
807
|
-
|
|
912
|
+
const clipRelativeTimeUs = timeUs - clip.startUs;
|
|
913
|
+
const trimStartUs = clip.trimStartUs ?? 0;
|
|
914
|
+
const playbackRate = videoClipPlaybackRate(clip);
|
|
915
|
+
let resourceTimeUs = trimStartUs + clipRelativeTimeUs * playbackRate;
|
|
916
|
+
if (clip.durationUs > 0) {
|
|
917
|
+
const resourceSpanUs = clip.durationUs * playbackRate;
|
|
918
|
+
resourceTimeUs = Math.min(resourceTimeUs, trimStartUs + resourceSpanUs - 1);
|
|
808
919
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
920
|
+
const instructions = this.planner.getInstructions(clip.id);
|
|
921
|
+
if (!instructions) {
|
|
922
|
+
playbackDiagnostic("render.no-instructions", { timeUs, clipId: clip.id });
|
|
923
|
+
return null;
|
|
924
|
+
}
|
|
925
|
+
const activeLayers = instructions.layers.filter((layer) => {
|
|
926
|
+
if (!layer.payload.attachmentId) {
|
|
927
|
+
return true;
|
|
928
|
+
}
|
|
929
|
+
if (layer.status !== "ready") {
|
|
930
|
+
return false;
|
|
931
|
+
}
|
|
932
|
+
return layer.activeRanges.some(
|
|
933
|
+
(range) => clipRelativeTimeUs >= range.startUs && clipRelativeTimeUs < range.endUs
|
|
934
|
+
);
|
|
935
|
+
});
|
|
936
|
+
for (const layerPlan of activeLayers) {
|
|
937
|
+
if (layerPlan.type === "video" && !layerPlan.payload.attachmentId) {
|
|
938
|
+
const mainVideoLayer = {
|
|
939
|
+
id: layerPlan.layerId,
|
|
940
|
+
type: "video",
|
|
941
|
+
zIndex: layerPlan.zIndex ?? 0,
|
|
942
|
+
visible: true,
|
|
943
|
+
opacity: layerPlan.opacity ?? 1,
|
|
944
|
+
origin: layerOrigin(layerPlan, clip),
|
|
945
|
+
// Each layer owns the frame it composes; a second main layer gets its own clone.
|
|
946
|
+
videoFrame: mainFrameUsed ? frame.clone() : frame
|
|
947
|
+
};
|
|
948
|
+
const mainRenderConfig = filterRenderConfig(
|
|
949
|
+
layerPlan.payload.renderConfig,
|
|
950
|
+
"video layer"
|
|
951
|
+
);
|
|
952
|
+
if (mainRenderConfig) {
|
|
953
|
+
mainVideoLayer.renderConfig = mainRenderConfig;
|
|
954
|
+
}
|
|
955
|
+
layers.push(mainVideoLayer);
|
|
956
|
+
mainFrameUsed = true;
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
const layer = await this.materializeLayer(layerPlan, clip, resourceTimeUs, timeUs);
|
|
960
|
+
if (layer) {
|
|
961
|
+
layers.push(layer);
|
|
962
|
+
}
|
|
963
|
+
if (this.modelToken !== startModelToken || this.compositionModel !== startModel || options?.signal?.aborted) {
|
|
964
|
+
return null;
|
|
826
965
|
}
|
|
827
|
-
layers.push(mainVideoLayer);
|
|
828
|
-
continue;
|
|
829
966
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
967
|
+
complete = true;
|
|
968
|
+
return { layers };
|
|
969
|
+
} finally {
|
|
970
|
+
if (!mainFrameUsed) frame.close();
|
|
971
|
+
if (!complete) {
|
|
972
|
+
for (const layer of layers) {
|
|
973
|
+
layer.videoFrame?.close();
|
|
974
|
+
if (layer.ownedSource) layer.source?.close();
|
|
975
|
+
}
|
|
833
976
|
}
|
|
834
977
|
}
|
|
835
|
-
return { layers };
|
|
836
978
|
}
|
|
837
979
|
/**
|
|
838
980
|
* Materialize a serialized layer plan into concrete Layer
|
|
@@ -843,18 +985,22 @@ class Orchestrator {
|
|
|
843
985
|
type: layerPlan.type,
|
|
844
986
|
zIndex: layerPlan.zIndex ?? 0,
|
|
845
987
|
visible: true,
|
|
846
|
-
opacity: layerPlan.opacity ?? 1
|
|
988
|
+
opacity: layerPlan.opacity ?? 1,
|
|
989
|
+
origin: layerOrigin(layerPlan, clip)
|
|
847
990
|
};
|
|
848
991
|
if (layerPlan.type === "video" && !layerPlan.payload.attachmentId) {
|
|
849
|
-
const
|
|
850
|
-
|
|
992
|
+
const videoFrame = this.cacheManager.cloneForCaller(
|
|
993
|
+
this.cacheManager.getFrame(resourceTimeUs, clip.id),
|
|
994
|
+
true
|
|
995
|
+
);
|
|
996
|
+
if (!videoFrame) {
|
|
851
997
|
console.warn("[Orchestrator] Video frame not found in L1:", clip.id, resourceTimeUs);
|
|
852
998
|
return null;
|
|
853
999
|
}
|
|
854
1000
|
const mainVideoLayer = {
|
|
855
1001
|
...baseLayer,
|
|
856
1002
|
type: "video",
|
|
857
|
-
|
|
1003
|
+
videoFrame
|
|
858
1004
|
};
|
|
859
1005
|
const mainRenderConfig = filterRenderConfig(layerPlan.payload.renderConfig, "video layer");
|
|
860
1006
|
if (mainRenderConfig) {
|
|
@@ -897,6 +1043,7 @@ class Orchestrator {
|
|
|
897
1043
|
...baseLayer,
|
|
898
1044
|
type: "image",
|
|
899
1045
|
source,
|
|
1046
|
+
ownedSource: true,
|
|
900
1047
|
attachmentId: payload.attachmentId
|
|
901
1048
|
};
|
|
902
1049
|
const filteredRenderConfig = filterRenderConfig(
|
|
@@ -910,6 +1057,7 @@ class Orchestrator {
|
|
|
910
1057
|
const { position, keyframes, overlayClipStartUs } = payload.animation;
|
|
911
1058
|
const relativeTimeUs = globalTimeUs - overlayClipStartUs;
|
|
912
1059
|
if (relativeTimeUs < 0 || relativeTimeUs > keyframes[keyframes.length - 1].time) {
|
|
1060
|
+
source?.close();
|
|
913
1061
|
return null;
|
|
914
1062
|
}
|
|
915
1063
|
const rotationRad = 0;
|
|
@@ -928,6 +1076,11 @@ class Orchestrator {
|
|
|
928
1076
|
return baseLayer;
|
|
929
1077
|
}
|
|
930
1078
|
}
|
|
1079
|
+
function layerOrigin(layerPlan, clip) {
|
|
1080
|
+
const payload = layerPlan.payload ?? {};
|
|
1081
|
+
const resourceId = typeof payload.resourceId === "string" ? payload.resourceId : !payload.attachmentId && hasResourceId(clip) ? clip.resourceId : void 0;
|
|
1082
|
+
return { clipId: payload.attachmentId ?? clip.id, resourceId };
|
|
1083
|
+
}
|
|
931
1084
|
export {
|
|
932
1085
|
Orchestrator
|
|
933
1086
|
};
|