@meframe/core 0.0.43 → 0.0.44
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/cache/CacheManager.d.ts +0 -1
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +1 -2
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/storage/opfs/OPFSManager.d.ts +7 -3
- package/dist/cache/storage/opfs/OPFSManager.d.ts.map +1 -1
- package/dist/cache/storage/opfs/OPFSManager.js +32 -11
- package/dist/cache/storage/opfs/OPFSManager.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +1 -6
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/types.d.ts +2 -8
- package/dist/config/types.d.ts.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 +11 -9
- package/dist/orchestrator/ExportScheduler.js.map +1 -1
- package/dist/orchestrator/OnDemandVideoSession.d.ts +5 -0
- package/dist/orchestrator/OnDemandVideoSession.d.ts.map +1 -1
- package/dist/orchestrator/OnDemandVideoSession.js +78 -0
- package/dist/orchestrator/OnDemandVideoSession.js.map +1 -1
- package/dist/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/Orchestrator.js +5 -6
- package/dist/orchestrator/Orchestrator.js.map +1 -1
- package/dist/orchestrator/VideoClipSession.d.ts +8 -9
- package/dist/orchestrator/VideoClipSession.d.ts.map +1 -1
- package/dist/orchestrator/VideoClipSession.js +87 -177
- package/dist/orchestrator/VideoClipSession.js.map +1 -1
- package/dist/stages/compose/LayerRenderer.d.ts +9 -0
- package/dist/stages/compose/LayerRenderer.d.ts.map +1 -1
- package/dist/stages/compose/LayerRenderer.js +41 -35
- package/dist/stages/compose/LayerRenderer.js.map +1 -1
- package/dist/stages/compose/font-system/font-templates.js +1 -1
- package/dist/stages/compose/font-system/font-templates.js.map +1 -1
- package/dist/stages/load/ResourceLoader.d.ts +5 -4
- package/dist/stages/load/ResourceLoader.d.ts.map +1 -1
- package/dist/stages/load/ResourceLoader.js +14 -59
- package/dist/stages/load/ResourceLoader.js.map +1 -1
- package/dist/worker/WorkerChannel.d.ts.map +1 -1
- package/dist/worker/WorkerChannel.js +11 -2
- package/dist/worker/WorkerChannel.js.map +1 -1
- package/dist/worker/WorkerPool.d.ts.map +1 -1
- package/dist/worker/WorkerPool.js +5 -2
- package/dist/worker/WorkerPool.js.map +1 -1
- package/dist/worker/transferable-helper.js +22 -0
- package/dist/worker/transferable-helper.js.map +1 -1
- package/dist/worker/types.d.ts +1 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/types.js.map +1 -1
- package/dist/workers/{WorkerChannel.CE5euh3R.js → WorkerChannel.DjBEVvEA.js} +31 -2
- package/dist/workers/WorkerChannel.DjBEVvEA.js.map +1 -0
- package/dist/workers/stages/compose/{audio-compose.worker.rW63uN6z.js → audio-compose.worker.CiM_KP27.js} +2 -2
- package/dist/workers/stages/compose/{audio-compose.worker.rW63uN6z.js.map → audio-compose.worker.CiM_KP27.js.map} +1 -1
- package/dist/workers/stages/compose/{video-compose.worker.D_542rY_.js → video-compose.worker.CvELsCtH.js} +49 -38
- package/dist/workers/stages/compose/video-compose.worker.CvELsCtH.js.map +1 -0
- package/dist/workers/stages/decode/{audio-decode.worker.B__6tqsy.js → audio-decode.worker.CpjkrZtT.js} +2 -2
- package/dist/workers/stages/decode/{audio-decode.worker.B__6tqsy.js.map → audio-decode.worker.CpjkrZtT.js.map} +1 -1
- package/dist/workers/stages/decode/{video-decode.worker.tOv-QR2f.js → video-decode.worker.BQtw6eWn.js} +2 -2
- package/dist/workers/stages/decode/video-decode.worker.BQtw6eWn.js.map +1 -0
- package/dist/workers/stages/demux/{audio-demux.worker.DgvvQVXU.js → audio-demux.worker.C4V11GQi.js} +2 -2
- package/dist/workers/stages/demux/{audio-demux.worker.DgvvQVXU.js.map → audio-demux.worker.C4V11GQi.js.map} +1 -1
- package/dist/workers/stages/demux/{video-demux.worker.DhG3CRix.js → video-demux.worker.5pJr0Ij-.js} +2 -2
- package/dist/workers/stages/demux/video-demux.worker.5pJr0Ij-.js.map +1 -0
- package/dist/workers/stages/encode/{video-encode.worker.D8pfFber.js → video-encode.worker.CX2_3YhQ.js} +2 -2
- package/dist/workers/stages/encode/{video-encode.worker.D8pfFber.js.map → video-encode.worker.CX2_3YhQ.js.map} +1 -1
- package/dist/workers/worker-manifest.json +7 -7
- package/package.json +1 -1
- package/dist/workers/WorkerChannel.CE5euh3R.js.map +0 -1
- package/dist/workers/stages/compose/video-compose.worker.D_542rY_.js.map +0 -1
- package/dist/workers/stages/decode/video-decode.worker.tOv-QR2f.js.map +0 -1
- package/dist/workers/stages/demux/video-demux.worker.DhG3CRix.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { hasResourceId } from "../model/types.js";
|
|
2
|
+
import { OnDemandVideoSession } from "./OnDemandVideoSession.js";
|
|
2
3
|
class VideoClipSession {
|
|
3
4
|
clipId;
|
|
4
5
|
sessionId;
|
|
5
|
-
forL2Only;
|
|
6
6
|
planner;
|
|
7
7
|
workerPool;
|
|
8
8
|
cacheManager;
|
|
@@ -12,13 +12,10 @@ class VideoClipSession {
|
|
|
12
12
|
resourceLoader;
|
|
13
13
|
instructionContext = null;
|
|
14
14
|
composeWorker = null;
|
|
15
|
-
decodeWorker = null;
|
|
16
15
|
videoEncodeWorker = null;
|
|
17
|
-
|
|
16
|
+
onDemandSession = null;
|
|
18
17
|
visualStream = null;
|
|
19
18
|
composeToEncodeChannel = null;
|
|
20
|
-
decodeToVisualChannel = null;
|
|
21
|
-
demuxToDecodeChannel = null;
|
|
22
19
|
isActive = false;
|
|
23
20
|
isDisposed = false;
|
|
24
21
|
static async create(config) {
|
|
@@ -27,7 +24,6 @@ class VideoClipSession {
|
|
|
27
24
|
constructor(config) {
|
|
28
25
|
this.clipId = config.clipId;
|
|
29
26
|
this.sessionId = config.sessionId ?? config.clipId;
|
|
30
|
-
this.forL2Only = config.forL2Only ?? false;
|
|
31
27
|
this.planner = config.planner;
|
|
32
28
|
this.workerPool = config.workerPool;
|
|
33
29
|
this.cacheManager = config.cacheManager;
|
|
@@ -44,6 +40,7 @@ class VideoClipSession {
|
|
|
44
40
|
console.warn("[VideoClipSession] activate: clip or resource not found", this.sessionId);
|
|
45
41
|
return;
|
|
46
42
|
}
|
|
43
|
+
await this.ensureInstructions(clip);
|
|
47
44
|
if (resource.type === "video") {
|
|
48
45
|
await this.setupVideoPipeline(clip, resource);
|
|
49
46
|
} else if (resource.type === "image") {
|
|
@@ -56,7 +53,6 @@ class VideoClipSession {
|
|
|
56
53
|
this.sessionId
|
|
57
54
|
);
|
|
58
55
|
}
|
|
59
|
-
await this.ensureInstructions(clip);
|
|
60
56
|
this.isActive = true;
|
|
61
57
|
const attachmentResources = this.extractAttachmentImageResources();
|
|
62
58
|
if (this.callbacks.onPipelineReady) {
|
|
@@ -131,78 +127,58 @@ class VideoClipSession {
|
|
|
131
127
|
await this.installInstructions(instructions);
|
|
132
128
|
}
|
|
133
129
|
async setupImagePipeline(clip) {
|
|
134
|
-
await this.acquireWorkers(clip
|
|
130
|
+
await this.acquireWorkers(clip);
|
|
135
131
|
await this.connectImagePipeline();
|
|
136
132
|
}
|
|
137
133
|
async connectImagePipeline() {
|
|
138
|
-
if (!this.composeWorker) {
|
|
134
|
+
if (!this.composeWorker || !this.videoEncodeWorker) {
|
|
139
135
|
throw new Error("Pipeline workers not ready");
|
|
140
136
|
}
|
|
141
137
|
const sessionId = this.sessionId;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
138
|
+
this.composeToEncodeChannel = new MessageChannel();
|
|
139
|
+
await this.composeWorker.send(
|
|
140
|
+
"connect",
|
|
141
|
+
{
|
|
142
|
+
direction: "downstream",
|
|
143
|
+
port: this.composeToEncodeChannel.port1,
|
|
144
|
+
streamType: "video",
|
|
145
|
+
sessionId
|
|
146
|
+
},
|
|
147
|
+
{ transfer: [this.composeToEncodeChannel.port1] }
|
|
148
|
+
);
|
|
149
|
+
await this.videoEncodeWorker.send(
|
|
150
|
+
"connect",
|
|
151
|
+
{
|
|
152
|
+
direction: "upstream",
|
|
153
|
+
port: this.composeToEncodeChannel.port2,
|
|
154
|
+
streamType: "video",
|
|
155
|
+
sessionId
|
|
156
|
+
},
|
|
157
|
+
{ transfer: [this.composeToEncodeChannel.port2] }
|
|
158
|
+
);
|
|
159
|
+
this.videoEncodeWorker.receiveStream((stream, metadata) => {
|
|
160
|
+
this.callbacks.onEncodedStreamReady(
|
|
161
|
+
stream,
|
|
162
|
+
metadata?.streamType ?? "video"
|
|
163
163
|
);
|
|
164
|
-
}
|
|
165
|
-
this.composeWorker.receiveStream(async (stream) => {
|
|
166
|
-
const visualConfig = this.workerConfigs.videoCompose ?? {};
|
|
167
|
-
const fps = this.compositionModel.fps ?? visualConfig.fps ?? 30;
|
|
168
|
-
await this.callbacks.onComposedStreamReady(stream, fps);
|
|
169
164
|
});
|
|
170
|
-
if (this.videoEncodeWorker) {
|
|
171
|
-
this.videoEncodeWorker.receiveStream((stream, metadata) => {
|
|
172
|
-
this.callbacks.onEncodedStreamReady(
|
|
173
|
-
stream,
|
|
174
|
-
metadata?.streamType ?? "video"
|
|
175
|
-
);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
165
|
}
|
|
179
|
-
async setupVideoPipeline(clip,
|
|
180
|
-
await this.acquireWorkers(clip
|
|
166
|
+
async setupVideoPipeline(clip, resource) {
|
|
167
|
+
await this.acquireWorkers(clip);
|
|
168
|
+
this.onDemandSession = await OnDemandVideoSession.create({
|
|
169
|
+
clipId: this.clipId,
|
|
170
|
+
resourceId: resource.id,
|
|
171
|
+
targetTimeUs: clip.trimStartUs ?? 0,
|
|
172
|
+
globalTimeUs: clip.startUs,
|
|
173
|
+
mp4IndexCache: this.cacheManager.mp4IndexCache,
|
|
174
|
+
cacheManager: this.cacheManager,
|
|
175
|
+
compositionModel: this.compositionModel,
|
|
176
|
+
resourceLoader: this.resourceLoader,
|
|
177
|
+
fps: this.compositionModel.fps ?? 30
|
|
178
|
+
});
|
|
181
179
|
await this.connectVideoPipeline();
|
|
182
180
|
}
|
|
183
|
-
async acquireWorkers(clip
|
|
184
|
-
if (isVideo) {
|
|
185
|
-
this.videoDemuxWorker = await this.workerPool.getOrCreate("videoDemux", this.sessionId, {
|
|
186
|
-
lazy: true
|
|
187
|
-
});
|
|
188
|
-
const demuxConfig = this.workerConfigs.videoDemux ?? {};
|
|
189
|
-
await this.videoDemuxWorker.send("configure", {
|
|
190
|
-
initial: true,
|
|
191
|
-
config: {
|
|
192
|
-
...demuxConfig,
|
|
193
|
-
// Audio is handled by GlobalAudioSession via AudioSampleCache
|
|
194
|
-
emitAudioToMain: false
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
this.decodeWorker = await this.workerPool.getOrCreate("videoDecode", this.sessionId, {
|
|
198
|
-
lazy: true
|
|
199
|
-
});
|
|
200
|
-
const decodeConfig = this.workerConfigs.videoDecode ?? {};
|
|
201
|
-
await this.decodeWorker.send("configure", {
|
|
202
|
-
initial: true,
|
|
203
|
-
config: decodeConfig
|
|
204
|
-
});
|
|
205
|
-
}
|
|
181
|
+
async acquireWorkers(clip) {
|
|
206
182
|
this.composeWorker = await this.workerPool.getOrCreate("videoCompose", this.sessionId, {
|
|
207
183
|
lazy: true
|
|
208
184
|
});
|
|
@@ -220,107 +196,69 @@ class VideoClipSession {
|
|
|
220
196
|
clipId: clip.id,
|
|
221
197
|
config: { ...visualConfig, ...renderOverrides, timeline }
|
|
222
198
|
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
encoderConfig.width = this.compositionModel.renderConfig.width;
|
|
231
|
-
}
|
|
232
|
-
if (this.compositionModel.renderConfig?.height) {
|
|
233
|
-
encoderConfig.height = this.compositionModel.renderConfig.height;
|
|
234
|
-
}
|
|
235
|
-
await this.videoEncodeWorker.send("configure", {
|
|
236
|
-
initial: true,
|
|
237
|
-
config: encoderConfig
|
|
238
|
-
});
|
|
199
|
+
this.videoEncodeWorker = await this.workerPool.getOrCreate("videoEncode", this.sessionId, {
|
|
200
|
+
lazy: true
|
|
201
|
+
});
|
|
202
|
+
const encodeConfig = this.workerConfigs.videoEncode ?? {};
|
|
203
|
+
const encoderConfig = { ...encodeConfig };
|
|
204
|
+
if (this.compositionModel.renderConfig?.width) {
|
|
205
|
+
encoderConfig.width = this.compositionModel.renderConfig.width;
|
|
239
206
|
}
|
|
207
|
+
if (this.compositionModel.renderConfig?.height) {
|
|
208
|
+
encoderConfig.height = this.compositionModel.renderConfig.height;
|
|
209
|
+
}
|
|
210
|
+
await this.videoEncodeWorker.send("configure", {
|
|
211
|
+
initial: true,
|
|
212
|
+
config: encoderConfig
|
|
213
|
+
});
|
|
240
214
|
}
|
|
241
215
|
async connectVideoPipeline() {
|
|
242
|
-
if (!this.composeWorker || !this.
|
|
216
|
+
if (!this.composeWorker || !this.videoEncodeWorker || !this.onDemandSession) {
|
|
243
217
|
throw new Error("Pipeline workers not ready");
|
|
244
218
|
}
|
|
245
219
|
const sessionId = this.sessionId;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
"connect",
|
|
250
|
-
{
|
|
251
|
-
direction: "downstream",
|
|
252
|
-
port: this.composeToEncodeChannel.port1,
|
|
253
|
-
streamType: "video",
|
|
254
|
-
sessionId
|
|
255
|
-
},
|
|
256
|
-
{ transfer: [this.composeToEncodeChannel.port1] }
|
|
257
|
-
);
|
|
258
|
-
await this.videoEncodeWorker.send(
|
|
259
|
-
"connect",
|
|
260
|
-
{
|
|
261
|
-
direction: "upstream",
|
|
262
|
-
port: this.composeToEncodeChannel.port2,
|
|
263
|
-
streamType: "video",
|
|
264
|
-
sessionId
|
|
265
|
-
},
|
|
266
|
-
{ transfer: [this.composeToEncodeChannel.port2] }
|
|
267
|
-
);
|
|
220
|
+
const clip = this.getClip();
|
|
221
|
+
if (!clip) {
|
|
222
|
+
throw new Error("[VideoClipSession] Clip not found for pipeline connection");
|
|
268
223
|
}
|
|
269
|
-
this.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
direction: "downstream",
|
|
274
|
-
port: this.decodeToVisualChannel.port1,
|
|
275
|
-
streamType: "video",
|
|
276
|
-
sessionId
|
|
277
|
-
},
|
|
278
|
-
{ transfer: [this.decodeToVisualChannel.port1] }
|
|
279
|
-
);
|
|
224
|
+
if (!this.instructionContext) {
|
|
225
|
+
throw new Error("[VideoClipSession] Instructions not installed before connecting pipeline");
|
|
226
|
+
}
|
|
227
|
+
this.composeToEncodeChannel = new MessageChannel();
|
|
280
228
|
await this.composeWorker.send(
|
|
281
|
-
"connect",
|
|
282
|
-
{
|
|
283
|
-
direction: "upstream",
|
|
284
|
-
port: this.decodeToVisualChannel.port2,
|
|
285
|
-
streamType: "video",
|
|
286
|
-
sessionId
|
|
287
|
-
},
|
|
288
|
-
{ transfer: [this.decodeToVisualChannel.port2] }
|
|
289
|
-
);
|
|
290
|
-
this.demuxToDecodeChannel = new MessageChannel();
|
|
291
|
-
await this.videoDemuxWorker.send(
|
|
292
229
|
"connect",
|
|
293
230
|
{
|
|
294
231
|
direction: "downstream",
|
|
295
|
-
port: this.
|
|
232
|
+
port: this.composeToEncodeChannel.port1,
|
|
296
233
|
streamType: "video",
|
|
297
234
|
sessionId
|
|
298
235
|
},
|
|
299
|
-
{ transfer: [this.
|
|
236
|
+
{ transfer: [this.composeToEncodeChannel.port1] }
|
|
300
237
|
);
|
|
301
|
-
await this.
|
|
238
|
+
await this.videoEncodeWorker.send(
|
|
302
239
|
"connect",
|
|
303
240
|
{
|
|
304
241
|
direction: "upstream",
|
|
305
|
-
port: this.
|
|
242
|
+
port: this.composeToEncodeChannel.port2,
|
|
306
243
|
streamType: "video",
|
|
307
244
|
sessionId
|
|
308
245
|
},
|
|
309
|
-
{ transfer: [this.
|
|
246
|
+
{ transfer: [this.composeToEncodeChannel.port2] }
|
|
310
247
|
);
|
|
311
|
-
this.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
248
|
+
this.videoEncodeWorker.receiveStream((stream, metadata) => {
|
|
249
|
+
this.callbacks.onEncodedStreamReady(
|
|
250
|
+
stream,
|
|
251
|
+
metadata?.streamType ?? "video"
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
const trimStartUs = clip.trimStartUs ?? 0;
|
|
255
|
+
const trimEndUs = clip.trimEndUs ?? trimStartUs + clip.durationUs;
|
|
256
|
+
const frameStream = await this.onDemandSession.decodeRangeToStream(trimStartUs, trimEndUs);
|
|
257
|
+
await this.composeWorker.sendStream(frameStream, {
|
|
258
|
+
sessionId,
|
|
259
|
+
streamType: "video",
|
|
260
|
+
instructions: this.instructionContext.instructions
|
|
315
261
|
});
|
|
316
|
-
if (this.videoEncodeWorker) {
|
|
317
|
-
this.videoEncodeWorker.receiveStream((stream, metadata) => {
|
|
318
|
-
this.callbacks.onEncodedStreamReady(
|
|
319
|
-
stream,
|
|
320
|
-
metadata?.streamType ?? "video"
|
|
321
|
-
);
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
262
|
}
|
|
325
263
|
async installInstructions(instructions) {
|
|
326
264
|
this.instructionContext = {
|
|
@@ -328,26 +266,8 @@ class VideoClipSession {
|
|
|
328
266
|
instructions,
|
|
329
267
|
status: instructions.status
|
|
330
268
|
};
|
|
331
|
-
if (this.composeWorker) {
|
|
332
|
-
await this.composeWorker.send("install_instructions", instructions);
|
|
333
|
-
}
|
|
334
269
|
}
|
|
335
270
|
async releasePipeline() {
|
|
336
|
-
if (!this.forL2Only) {
|
|
337
|
-
const clip = this.getClip();
|
|
338
|
-
if (clip && this.resourceLoader) {
|
|
339
|
-
if (clip.oldResourceId) {
|
|
340
|
-
this.resourceLoader.cancel(clip.oldResourceId);
|
|
341
|
-
}
|
|
342
|
-
if (hasResourceId(clip)) {
|
|
343
|
-
this.resourceLoader.cancel(clip.resourceId);
|
|
344
|
-
}
|
|
345
|
-
const attachmentResources = this.extractAttachmentImageResources();
|
|
346
|
-
for (const resourceId of attachmentResources) {
|
|
347
|
-
this.resourceLoader.cancel(resourceId);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
271
|
if (this.composeWorker && this.instructionContext) {
|
|
352
272
|
await this.composeWorker.notify("dispose_clip", {
|
|
353
273
|
sessionId: this.sessionId,
|
|
@@ -358,13 +278,9 @@ class VideoClipSession {
|
|
|
358
278
|
this.callbacks.onStreamDisposed();
|
|
359
279
|
}
|
|
360
280
|
this.visualStream = null;
|
|
361
|
-
if (this.
|
|
362
|
-
this.
|
|
363
|
-
this.
|
|
364
|
-
}
|
|
365
|
-
if (this.decodeWorker) {
|
|
366
|
-
this.workerPool.terminate("videoDecode", this.sessionId);
|
|
367
|
-
this.decodeWorker = null;
|
|
281
|
+
if (this.onDemandSession) {
|
|
282
|
+
await this.onDemandSession.dispose();
|
|
283
|
+
this.onDemandSession = null;
|
|
368
284
|
}
|
|
369
285
|
if (this.composeWorker) {
|
|
370
286
|
this.workerPool.terminate("videoCompose", this.sessionId);
|
|
@@ -376,13 +292,7 @@ class VideoClipSession {
|
|
|
376
292
|
}
|
|
377
293
|
this.composeToEncodeChannel?.port1.close();
|
|
378
294
|
this.composeToEncodeChannel?.port2.close();
|
|
379
|
-
this.decodeToVisualChannel?.port1.close();
|
|
380
|
-
this.decodeToVisualChannel?.port2.close();
|
|
381
|
-
this.demuxToDecodeChannel?.port1.close();
|
|
382
|
-
this.demuxToDecodeChannel?.port2.close();
|
|
383
295
|
this.composeToEncodeChannel = null;
|
|
384
|
-
this.decodeToVisualChannel = null;
|
|
385
|
-
this.demuxToDecodeChannel = null;
|
|
386
296
|
}
|
|
387
297
|
async invalidateClipCache() {
|
|
388
298
|
await this.cacheManager.invalidateClip(this.clipId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VideoClipSession.js","sources":["../../src/orchestrator/VideoClipSession.ts"],"sourcesContent":["import type { WorkerPool } from '../worker/WorkerPool';\nimport type { CacheManager } from '../cache/CacheManager';\nimport type { CompositionModel, Clip } from '../model';\nimport type { CompositionPlanner, ClipUpdateResult } from './CompositionPlanner';\nimport type { ClipInstructionSet } from '../stages/compose/instructions';\nimport type { BaseWorker } from '../worker/BaseWorker';\nimport type { WorkerType } from '../worker/types';\nimport type { ResourceLoader } from '../stages/load/ResourceLoader';\nimport { hasResourceId } from '../model/types';\n\ninterface VideoClipSessionCallbacks {\n onComposedStreamReady(stream: ReadableStream<VideoFrame>, fps: number): Promise<void>;\n onEncodedStreamReady(\n stream: ReadableStream<{ chunk: EncodedVideoChunk; metadata: EncodedVideoChunkMetadata }>,\n track: 'video' | 'audio'\n ): Promise<void>;\n onAudioStreamReady?(\n stream: ReadableStream<AudioData>,\n metadata: {\n sessionId: string;\n clipStartUs: number;\n clipDurationUs: number;\n }\n ): void;\n onStreamDisposed?(): void;\n onPipelineReady?(attachmentResourceIds?: string[]): Promise<void>;\n}\n\ninterface VideoClipSessionConfig {\n clipId: string;\n sessionId?: string;\n forL2Only?: boolean;\n planner: CompositionPlanner;\n workerPool: WorkerPool;\n cacheManager: CacheManager;\n compositionModel: CompositionModel;\n workerConfigs: Record<WorkerType, any>;\n callbacks: VideoClipSessionCallbacks;\n resourceLoader?: ResourceLoader;\n}\n\ninterface InstructionContext {\n revision: number;\n instructions: ClipInstructionSet;\n status: ClipInstructionSet['status'];\n}\n\nexport class VideoClipSession {\n private readonly clipId: string;\n private readonly sessionId: string;\n private readonly forL2Only: boolean;\n private readonly planner: CompositionPlanner;\n private readonly workerPool: WorkerPool;\n private readonly cacheManager: CacheManager;\n private readonly compositionModel: CompositionModel;\n private readonly workerConfigs: Record<WorkerType, any>;\n private readonly callbacks: VideoClipSessionCallbacks;\n private readonly resourceLoader?: ResourceLoader;\n\n private instructionContext: InstructionContext | null = null;\n composeWorker: BaseWorker | null = null;\n private decodeWorker: BaseWorker | null = null;\n private videoEncodeWorker: BaseWorker | null = null;\n private videoDemuxWorker: BaseWorker | null = null;\n private visualStream: ReadableStream<VideoFrame> | null = null;\n private composeToEncodeChannel: MessageChannel | null = null;\n private decodeToVisualChannel: MessageChannel | null = null;\n private demuxToDecodeChannel: MessageChannel | null = null;\n private isActive = false;\n private isDisposed = false;\n\n static async create(config: VideoClipSessionConfig): Promise<VideoClipSession> {\n return new VideoClipSession(config);\n }\n\n private constructor(config: VideoClipSessionConfig) {\n this.clipId = config.clipId;\n this.sessionId = config.sessionId ?? config.clipId;\n this.forL2Only = config.forL2Only ?? false;\n this.planner = config.planner;\n this.workerPool = config.workerPool;\n this.cacheManager = config.cacheManager;\n this.compositionModel = config.compositionModel;\n this.workerConfigs = config.workerConfigs;\n this.callbacks = config.callbacks;\n this.resourceLoader = config.resourceLoader;\n }\n\n async activate(): Promise<void> {\n if (this.isActive || this.isDisposed) return;\n\n const clip = this.getClip();\n const resource = this.getResource();\n if (!clip || !resource) {\n console.warn('[VideoClipSession] activate: clip or resource not found', this.sessionId);\n return;\n }\n if (resource.type === 'video') {\n await this.setupVideoPipeline(clip, resource);\n } else if (resource.type === 'image') {\n await this.setupImagePipeline(clip);\n } else {\n console.warn(\n '[VideoClipSession] Unknown resource type:',\n resource.type,\n 'for',\n this.sessionId\n );\n }\n\n await this.ensureInstructions(clip);\n\n this.isActive = true;\n\n // Notify that pipeline is ready - triggers resource loading\n const attachmentResources = this.extractAttachmentImageResources();\n if (this.callbacks.onPipelineReady) {\n await this.callbacks.onPipelineReady(attachmentResources);\n }\n }\n\n async deactivate(): Promise<void> {\n if (!this.isActive || this.isDisposed) return;\n this.isActive = false;\n\n await this.releasePipeline();\n }\n\n async dispose(): Promise<void> {\n if (this.isDisposed) return;\n await this.deactivate();\n this.planner.releaseClip(this.clipId);\n this.isDisposed = true;\n }\n\n async handlePlannerUpdate(update: ClipUpdateResult): Promise<void> {\n if (this.isDisposed) {\n return;\n }\n\n if (update.type === 'remove') {\n await this.dispose();\n return;\n }\n\n const instructions = update.instructions;\n if (!instructions) {\n return;\n }\n\n const clip = this.getClip();\n const resource = this.getResource();\n if (!clip || !resource || (resource.type !== 'video' && resource.type !== 'image')) {\n return;\n }\n\n // Any update requires pipeline restart (stream is closed after cache eviction)\n if (this.isActive) {\n await this.releasePipeline();\n this.isActive = false;\n }\n await this.activate();\n }\n\n private getClip(): Clip | null {\n return this.compositionModel?.findClip?.(this.clipId) ?? null;\n }\n\n private getResource() {\n const clip = this.getClip();\n if (!clip || !hasResourceId(clip)) return null;\n return this.compositionModel.getResource(clip.resourceId) ?? null;\n }\n\n private extractAttachmentImageResources(): string[] {\n if (!this.instructionContext?.instructions) return [];\n\n const resourceIdSet = new Set<string>();\n for (const layer of this.instructionContext.instructions.layers) {\n // Only process attachment layers (with attachmentId)\n if (!layer.payload.attachmentId) continue;\n\n if (layer.type === 'image') {\n const imagePayload = layer.payload;\n if (imagePayload.oldResourceId) {\n resourceIdSet.add(imagePayload.oldResourceId);\n }\n const resourceId = imagePayload.resourceId;\n if (resourceId) {\n resourceIdSet.add(resourceId);\n }\n }\n }\n return Array.from(resourceIdSet);\n }\n\n private async ensureInstructions(_clip: Clip): Promise<void> {\n const instructions = this.planner.getInstructions(this.clipId);\n if (!instructions) {\n throw new Error(`No instructions for clip ${this.clipId}`);\n }\n await this.installInstructions(instructions);\n }\n\n private async setupImagePipeline(clip: Clip): Promise<void> {\n await this.acquireWorkers(clip, false);\n await this.connectImagePipeline();\n }\n\n private async connectImagePipeline(): Promise<void> {\n if (!this.composeWorker) {\n throw new Error('Pipeline workers not ready');\n }\n\n // Use sessionId for worker communication\n const sessionId = this.sessionId;\n\n // Connect visualWorker to encodeWorker (only if L2 mode)\n if (this.videoEncodeWorker) {\n this.composeToEncodeChannel = new MessageChannel();\n await this.composeWorker.send(\n 'connect',\n {\n direction: 'downstream',\n port: this.composeToEncodeChannel.port1,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.composeToEncodeChannel.port1] }\n );\n await this.videoEncodeWorker.send(\n 'connect',\n {\n direction: 'upstream',\n port: this.composeToEncodeChannel.port2,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.composeToEncodeChannel.port2] }\n );\n }\n\n this.composeWorker.receiveStream(async (stream) => {\n const visualConfig = this.workerConfigs.videoCompose ?? {};\n const fps = this.compositionModel.fps ?? visualConfig.fps ?? 30;\n await this.callbacks.onComposedStreamReady(stream, fps);\n });\n\n // Receive encoded chunks from EncodeWorker (only in L2 mode)\n if (this.videoEncodeWorker) {\n this.videoEncodeWorker.receiveStream((stream, metadata) => {\n this.callbacks.onEncodedStreamReady(\n stream as ReadableStream<{\n chunk: EncodedVideoChunk;\n metadata: EncodedVideoChunkMetadata;\n }>,\n metadata?.streamType ?? 'video'\n );\n });\n }\n }\n\n private async setupVideoPipeline(clip: Clip, _resource: { id: string }): Promise<void> {\n await this.acquireWorkers(clip, true);\n await this.connectVideoPipeline();\n }\n\n private async acquireWorkers(clip: Clip, isVideo: boolean): Promise<void> {\n // Acquire video pipeline workers\n if (isVideo) {\n // VideoDemuxWorker\n this.videoDemuxWorker = await this.workerPool.getOrCreate('videoDemux', this.sessionId, {\n lazy: true,\n });\n const demuxConfig = this.workerConfigs.videoDemux ?? {};\n await this.videoDemuxWorker.send('configure', {\n initial: true,\n config: {\n ...demuxConfig,\n // Audio is handled by GlobalAudioSession via AudioSampleCache\n emitAudioToMain: false,\n },\n });\n\n // VideoDecodeWorker\n this.decodeWorker = await this.workerPool.getOrCreate('videoDecode', this.sessionId, {\n lazy: true,\n });\n const decodeConfig = this.workerConfigs.videoDecode ?? {};\n await this.decodeWorker.send('configure', {\n initial: true,\n config: decodeConfig,\n });\n\n // Note: Audio is handled by GlobalAudioSession via AudioSampleCache (main thread)\n }\n\n // VideoComposeWorker (always needed)\n this.composeWorker = await this.workerPool.getOrCreate('videoCompose', this.sessionId, {\n lazy: true,\n });\n const visualConfig = this.workerConfigs.videoCompose ?? {};\n const renderOverrides = this.compositionModel.renderConfig ?? {};\n const timeline = {\n clipId: clip.id,\n clipStartUs: clip.startUs,\n clipEndUs: clip.startUs + clip.durationUs,\n clipDurationUs: clip.durationUs,\n compositionFps: this.compositionModel.fps ?? visualConfig.fps ?? 30,\n };\n await this.composeWorker.send('configure', {\n initial: true,\n clipId: clip.id,\n config: { ...visualConfig, ...renderOverrides, timeline },\n });\n\n // VideoEncodeWorker (only for L2)\n if (this.forL2Only) {\n this.videoEncodeWorker = await this.workerPool.getOrCreate('videoEncode', this.sessionId, {\n lazy: true,\n });\n const encodeConfig = this.workerConfigs.videoEncode ?? {};\n const encoderConfig = { ...encodeConfig };\n if (this.compositionModel.renderConfig?.width) {\n encoderConfig.width = this.compositionModel.renderConfig.width;\n }\n if (this.compositionModel.renderConfig?.height) {\n encoderConfig.height = this.compositionModel.renderConfig.height;\n }\n await this.videoEncodeWorker.send('configure', {\n initial: true,\n config: encoderConfig,\n });\n }\n }\n\n private async connectVideoPipeline(): Promise<void> {\n if (!this.composeWorker || !this.decodeWorker || !this.videoDemuxWorker) {\n throw new Error('Pipeline workers not ready');\n }\n\n // Use sessionId for worker communication\n const sessionId = this.sessionId;\n\n // Connect visualWorker to encodeWorker (only if L2 mode)\n if (this.videoEncodeWorker) {\n this.composeToEncodeChannel = new MessageChannel();\n await this.composeWorker.send(\n 'connect',\n {\n direction: 'downstream',\n port: this.composeToEncodeChannel.port1,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.composeToEncodeChannel.port1] }\n );\n await this.videoEncodeWorker.send(\n 'connect',\n {\n direction: 'upstream',\n port: this.composeToEncodeChannel.port2,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.composeToEncodeChannel.port2] }\n );\n }\n\n this.decodeToVisualChannel = new MessageChannel();\n await this.decodeWorker.send(\n 'connect',\n {\n direction: 'downstream',\n port: this.decodeToVisualChannel.port1,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.decodeToVisualChannel.port1] }\n );\n await this.composeWorker.send(\n 'connect',\n {\n direction: 'upstream',\n port: this.decodeToVisualChannel.port2,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.decodeToVisualChannel.port2] }\n );\n\n this.demuxToDecodeChannel = new MessageChannel();\n await this.videoDemuxWorker.send(\n 'connect',\n {\n direction: 'downstream',\n port: this.demuxToDecodeChannel.port1,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.demuxToDecodeChannel.port1] }\n );\n await this.decodeWorker.send(\n 'connect',\n {\n direction: 'upstream',\n port: this.demuxToDecodeChannel.port2,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.demuxToDecodeChannel.port2] }\n );\n\n // Setup stream receivers\n this.composeWorker.receiveStream(async (stream) => {\n const visualConfig = this.workerConfigs.videoCompose ?? {};\n const fps = this.compositionModel.fps ?? visualConfig.fps ?? 30;\n await this.callbacks.onComposedStreamReady(stream, fps);\n });\n\n // Receive encoded chunks from EncodeWorker (only in L2 mode)\n if (this.videoEncodeWorker) {\n this.videoEncodeWorker.receiveStream((stream, metadata) => {\n this.callbacks.onEncodedStreamReady(\n stream as ReadableStream<{\n chunk: EncodedVideoChunk;\n metadata: EncodedVideoChunkMetadata;\n }>,\n metadata?.streamType ?? 'video'\n );\n });\n }\n }\n\n private async installInstructions(instructions: ClipInstructionSet): Promise<void> {\n this.instructionContext = {\n revision: instructions.revision,\n instructions,\n status: instructions.status,\n };\n\n if (this.composeWorker) {\n await this.composeWorker.send('install_instructions', instructions);\n }\n }\n\n private async releasePipeline(): Promise<void> {\n if (!this.forL2Only) {\n const clip = this.getClip();\n if (clip && this.resourceLoader) {\n if (clip.oldResourceId) {\n this.resourceLoader.cancel(clip.oldResourceId);\n }\n if (hasResourceId(clip)) {\n this.resourceLoader.cancel(clip.resourceId);\n }\n\n const attachmentResources = this.extractAttachmentImageResources();\n for (const resourceId of attachmentResources) {\n this.resourceLoader.cancel(resourceId);\n }\n }\n }\n\n if (this.composeWorker && this.instructionContext) {\n await this.composeWorker.notify('dispose_clip', {\n sessionId: this.sessionId,\n revision: this.instructionContext.revision,\n });\n }\n\n if (this.visualStream && this.callbacks.onStreamDisposed) {\n this.callbacks.onStreamDisposed();\n }\n this.visualStream = null;\n\n // Terminate clip-local workers\n if (this.videoDemuxWorker) {\n this.workerPool.terminate('videoDemux', this.sessionId);\n this.videoDemuxWorker = null;\n }\n\n if (this.decodeWorker) {\n this.workerPool.terminate('videoDecode', this.sessionId);\n this.decodeWorker = null;\n }\n\n if (this.composeWorker) {\n this.workerPool.terminate('videoCompose', this.sessionId);\n this.composeWorker = null;\n }\n\n if (this.videoEncodeWorker) {\n this.workerPool.terminate('videoEncode', this.sessionId);\n this.videoEncodeWorker = null;\n }\n\n this.composeToEncodeChannel?.port1.close();\n this.composeToEncodeChannel?.port2.close();\n this.decodeToVisualChannel?.port1.close();\n this.decodeToVisualChannel?.port2.close();\n this.demuxToDecodeChannel?.port1.close();\n this.demuxToDecodeChannel?.port2.close();\n\n this.composeToEncodeChannel = null;\n this.decodeToVisualChannel = null;\n this.demuxToDecodeChannel = null;\n }\n\n async invalidateClipCache(): Promise<void> {\n await this.cacheManager.invalidateClip(this.clipId);\n }\n}\n"],"names":[],"mappings":";AA+CO,MAAM,iBAAiB;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,qBAAgD;AAAA,EACxD,gBAAmC;AAAA,EAC3B,eAAkC;AAAA,EAClC,oBAAuC;AAAA,EACvC,mBAAsC;AAAA,EACt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S;AACvD,WAAK,eAAe;AAAA,IACtB;AAEA,QAAI,KAAK,eAAe;AACtB,WAAK,WAAW,UAAU,gBAAgB,KAAK,SAAS;AACxD,WAAK,gBAAgB;AAAA,IACvB;AAEA,QAAI,KAAK,mBAAmB;AAC1B,WAAK,WAAW,UAAU,eAAe,KAAK,SAAS;AACvD,WAAK,oBAAoB;AAAA,IAC3B;AAEA,SAAK,wBAAwB,MAAM,MAAA;AACnC,SAAK,wBAAwB,MAAM,MAAA;AACnC,SAAK,uBAAuB,MAAM,MAAA;AAClC,SAAK,uBAAuB,MAAM,MAAA;AAClC,SAAK,sBAAsB,MAAM,MAAA;AACjC,SAAK,sBAAsB,MAAM,MAAA;AAEjC,SAAK,yBAAyB;AAC9B,SAAK,wBAAwB;AAC7B,SAAK,uBAAuB;AAAA,EAC9B;AAAA,EAEA,MAAM,sBAAqC;AACzC,UAAM,KAAK,aAAa,eAAe,KAAK,MAAM;AAAA,EACpD;AACF;"}
|
|
1
|
+
{"version":3,"file":"VideoClipSession.js","sources":["../../src/orchestrator/VideoClipSession.ts"],"sourcesContent":["import type { WorkerPool } from '../worker/WorkerPool';\nimport type { CacheManager } from '../cache/CacheManager';\nimport type { CompositionModel, Clip } from '../model';\nimport type { CompositionPlanner, ClipUpdateResult } from './CompositionPlanner';\nimport type { ClipInstructionSet } from '../stages/compose/instructions';\nimport type { BaseWorker } from '../worker/BaseWorker';\nimport type { WorkerType } from '../worker/types';\nimport type { ResourceLoader } from '../stages/load/ResourceLoader';\nimport { hasResourceId } from '../model/types';\nimport { OnDemandVideoSession } from './OnDemandVideoSession';\n\ninterface VideoClipSessionCallbacks {\n onEncodedStreamReady(\n stream: ReadableStream<{ chunk: EncodedVideoChunk; metadata: EncodedVideoChunkMetadata }>,\n track: 'video' | 'audio'\n ): Promise<void>;\n onAudioStreamReady?(\n stream: ReadableStream<AudioData>,\n metadata: {\n sessionId: string;\n clipStartUs: number;\n clipDurationUs: number;\n }\n ): void;\n onStreamDisposed?(): void;\n onPipelineReady?(attachmentResourceIds?: string[]): Promise<void>;\n}\n\ninterface VideoClipSessionConfig {\n clipId: string;\n sessionId?: string;\n planner: CompositionPlanner;\n workerPool: WorkerPool;\n cacheManager: CacheManager;\n compositionModel: CompositionModel;\n workerConfigs: Record<WorkerType, any>;\n callbacks: VideoClipSessionCallbacks;\n resourceLoader?: ResourceLoader;\n}\n\ninterface InstructionContext {\n revision: number;\n instructions: ClipInstructionSet;\n status: ClipInstructionSet['status'];\n}\n\n/**\n * VideoClipSession - Export-only session for rendering video clips\n *\n * Pipeline: OnDemandVideoSession (decode) -> ComposeWorker -> EncodeWorker\n * All sessions now use this architecture for export processing\n */\nexport class VideoClipSession {\n private readonly clipId: string;\n private readonly sessionId: string;\n private readonly planner: CompositionPlanner;\n private readonly workerPool: WorkerPool;\n private readonly cacheManager: CacheManager;\n private readonly compositionModel: CompositionModel;\n private readonly workerConfigs: Record<WorkerType, any>;\n private readonly callbacks: VideoClipSessionCallbacks;\n private readonly resourceLoader?: ResourceLoader;\n\n private instructionContext: InstructionContext | null = null;\n private composeWorker: BaseWorker | null = null;\n private videoEncodeWorker: BaseWorker | null = null;\n private onDemandSession: OnDemandVideoSession | null = null;\n private visualStream: ReadableStream<VideoFrame> | null = null;\n private composeToEncodeChannel: MessageChannel | null = null;\n private isActive = false;\n private isDisposed = false;\n\n static async create(config: VideoClipSessionConfig): Promise<VideoClipSession> {\n return new VideoClipSession(config);\n }\n\n private constructor(config: VideoClipSessionConfig) {\n this.clipId = config.clipId;\n this.sessionId = config.sessionId ?? config.clipId;\n this.planner = config.planner;\n this.workerPool = config.workerPool;\n this.cacheManager = config.cacheManager;\n this.compositionModel = config.compositionModel;\n this.workerConfigs = config.workerConfigs;\n this.callbacks = config.callbacks;\n this.resourceLoader = config.resourceLoader;\n }\n\n async activate(): Promise<void> {\n if (this.isActive || this.isDisposed) return;\n\n const clip = this.getClip();\n const resource = this.getResource();\n if (!clip || !resource) {\n console.warn('[VideoClipSession] activate: clip or resource not found', this.sessionId);\n return;\n }\n\n // Prepare instructions (but don't send yet - will send with stream)\n await this.ensureInstructions(clip);\n\n if (resource.type === 'video') {\n await this.setupVideoPipeline(clip, resource);\n } else if (resource.type === 'image') {\n await this.setupImagePipeline(clip);\n } else {\n console.warn(\n '[VideoClipSession] Unknown resource type:',\n resource.type,\n 'for',\n this.sessionId\n );\n }\n\n this.isActive = true;\n\n // Notify that pipeline is ready - triggers resource loading\n const attachmentResources = this.extractAttachmentImageResources();\n if (this.callbacks.onPipelineReady) {\n await this.callbacks.onPipelineReady(attachmentResources);\n }\n }\n\n async deactivate(): Promise<void> {\n if (!this.isActive || this.isDisposed) return;\n this.isActive = false;\n\n await this.releasePipeline();\n }\n\n async dispose(): Promise<void> {\n if (this.isDisposed) return;\n await this.deactivate();\n this.planner.releaseClip(this.clipId);\n this.isDisposed = true;\n }\n\n async handlePlannerUpdate(update: ClipUpdateResult): Promise<void> {\n if (this.isDisposed) {\n return;\n }\n\n if (update.type === 'remove') {\n await this.dispose();\n return;\n }\n\n const instructions = update.instructions;\n if (!instructions) {\n return;\n }\n\n const clip = this.getClip();\n const resource = this.getResource();\n if (!clip || !resource || (resource.type !== 'video' && resource.type !== 'image')) {\n return;\n }\n\n // Any update requires pipeline restart (stream is closed after cache eviction)\n if (this.isActive) {\n await this.releasePipeline();\n this.isActive = false;\n }\n await this.activate();\n }\n\n private getClip(): Clip | null {\n return this.compositionModel?.findClip?.(this.clipId) ?? null;\n }\n\n private getResource() {\n const clip = this.getClip();\n if (!clip || !hasResourceId(clip)) return null;\n return this.compositionModel.getResource(clip.resourceId) ?? null;\n }\n\n private extractAttachmentImageResources(): string[] {\n if (!this.instructionContext?.instructions) return [];\n\n const resourceIdSet = new Set<string>();\n for (const layer of this.instructionContext.instructions.layers) {\n // Only process attachment layers (with attachmentId)\n if (!layer.payload.attachmentId) continue;\n\n if (layer.type === 'image') {\n const imagePayload = layer.payload;\n if (imagePayload.oldResourceId) {\n resourceIdSet.add(imagePayload.oldResourceId);\n }\n const resourceId = imagePayload.resourceId;\n if (resourceId) {\n resourceIdSet.add(resourceId);\n }\n }\n }\n return Array.from(resourceIdSet);\n }\n\n private async ensureInstructions(_clip: Clip): Promise<void> {\n const instructions = this.planner.getInstructions(this.clipId);\n if (!instructions) {\n throw new Error(`No instructions for clip ${this.clipId}`);\n }\n await this.installInstructions(instructions);\n }\n\n private async setupImagePipeline(clip: Clip): Promise<void> {\n await this.acquireWorkers(clip);\n await this.connectImagePipeline();\n }\n\n private async connectImagePipeline(): Promise<void> {\n if (!this.composeWorker || !this.videoEncodeWorker) {\n throw new Error('Pipeline workers not ready');\n }\n\n const sessionId = this.sessionId;\n\n // STEP 1: Connect ComposeWorker -> EncodeWorker\n this.composeToEncodeChannel = new MessageChannel();\n await this.composeWorker.send(\n 'connect',\n {\n direction: 'downstream',\n port: this.composeToEncodeChannel.port1,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.composeToEncodeChannel.port1] }\n );\n await this.videoEncodeWorker.send(\n 'connect',\n {\n direction: 'upstream',\n port: this.composeToEncodeChannel.port2,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.composeToEncodeChannel.port2] }\n );\n\n // STEP 2: Setup EncodeWorker stream receiver\n this.videoEncodeWorker.receiveStream((stream, metadata) => {\n this.callbacks.onEncodedStreamReady(\n stream as ReadableStream<{\n chunk: EncodedVideoChunk;\n metadata: EncodedVideoChunkMetadata;\n }>,\n metadata?.streamType ?? 'video'\n );\n });\n }\n\n private async setupVideoPipeline(clip: Clip, resource: { id: string }): Promise<void> {\n await this.acquireWorkers(clip);\n\n // Create OnDemandVideoSession for main-thread decoding\n this.onDemandSession = await OnDemandVideoSession.create({\n clipId: this.clipId,\n resourceId: resource.id,\n targetTimeUs: clip.trimStartUs ?? 0,\n globalTimeUs: clip.startUs,\n mp4IndexCache: this.cacheManager.mp4IndexCache,\n cacheManager: this.cacheManager,\n compositionModel: this.compositionModel,\n resourceLoader: this.resourceLoader!,\n fps: this.compositionModel.fps ?? 30,\n });\n\n await this.connectVideoPipeline();\n }\n\n private async acquireWorkers(clip: Clip): Promise<void> {\n // VideoComposeWorker\n this.composeWorker = await this.workerPool.getOrCreate('videoCompose', this.sessionId, {\n lazy: true,\n });\n const visualConfig = this.workerConfigs.videoCompose ?? {};\n const renderOverrides = this.compositionModel.renderConfig ?? {};\n const timeline = {\n clipId: clip.id,\n clipStartUs: clip.startUs,\n clipEndUs: clip.startUs + clip.durationUs,\n clipDurationUs: clip.durationUs,\n compositionFps: this.compositionModel.fps ?? visualConfig.fps ?? 30,\n };\n await this.composeWorker.send('configure', {\n initial: true,\n clipId: clip.id,\n config: { ...visualConfig, ...renderOverrides, timeline },\n });\n\n // VideoEncodeWorker (always needed for export)\n this.videoEncodeWorker = await this.workerPool.getOrCreate('videoEncode', this.sessionId, {\n lazy: true,\n });\n const encodeConfig = this.workerConfigs.videoEncode ?? {};\n const encoderConfig = { ...encodeConfig };\n if (this.compositionModel.renderConfig?.width) {\n encoderConfig.width = this.compositionModel.renderConfig.width;\n }\n if (this.compositionModel.renderConfig?.height) {\n encoderConfig.height = this.compositionModel.renderConfig.height;\n }\n await this.videoEncodeWorker.send('configure', {\n initial: true,\n config: encoderConfig,\n });\n }\n\n private async connectVideoPipeline(): Promise<void> {\n if (!this.composeWorker || !this.videoEncodeWorker || !this.onDemandSession) {\n throw new Error('Pipeline workers not ready');\n }\n\n const sessionId = this.sessionId;\n const clip = this.getClip();\n if (!clip) {\n throw new Error('[VideoClipSession] Clip not found for pipeline connection');\n }\n\n if (!this.instructionContext) {\n throw new Error('[VideoClipSession] Instructions not installed before connecting pipeline');\n }\n\n // STEP 1: Connect ComposeWorker -> EncodeWorker\n this.composeToEncodeChannel = new MessageChannel();\n await this.composeWorker.send(\n 'connect',\n {\n direction: 'downstream',\n port: this.composeToEncodeChannel.port1,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.composeToEncodeChannel.port1] }\n );\n await this.videoEncodeWorker.send(\n 'connect',\n {\n direction: 'upstream',\n port: this.composeToEncodeChannel.port2,\n streamType: 'video',\n sessionId,\n },\n { transfer: [this.composeToEncodeChannel.port2] }\n );\n\n // STEP 2: Setup EncodeWorker stream receiver\n this.videoEncodeWorker.receiveStream((stream, metadata) => {\n this.callbacks.onEncodedStreamReady(\n stream as ReadableStream<{\n chunk: EncodedVideoChunk;\n metadata: EncodedVideoChunkMetadata;\n }>,\n metadata?.streamType ?? 'video'\n );\n });\n\n // STEP 3: Start decoding and send frames to ComposeWorker\n const trimStartUs = clip.trimStartUs ?? 0;\n const trimEndUs = clip.trimEndUs ?? trimStartUs + clip.durationUs;\n const frameStream = await this.onDemandSession.decodeRangeToStream(trimStartUs, trimEndUs);\n\n // Send VideoFrame stream to ComposeWorker (main thread → worker)\n // Include instructions in metadata to avoid race conditions\n await this.composeWorker.sendStream(frameStream, {\n sessionId,\n streamType: 'video',\n instructions: this.instructionContext.instructions,\n });\n }\n\n private async installInstructions(instructions: ClipInstructionSet): Promise<void> {\n this.instructionContext = {\n revision: instructions.revision,\n instructions,\n status: instructions.status,\n };\n }\n\n private async releasePipeline(): Promise<void> {\n if (this.composeWorker && this.instructionContext) {\n await this.composeWorker.notify('dispose_clip', {\n sessionId: this.sessionId,\n revision: this.instructionContext.revision,\n });\n }\n\n if (this.visualStream && this.callbacks.onStreamDisposed) {\n this.callbacks.onStreamDisposed();\n }\n this.visualStream = null;\n\n // Cleanup OnDemandVideoSession\n if (this.onDemandSession) {\n await this.onDemandSession.dispose();\n this.onDemandSession = null;\n }\n\n // Terminate workers\n if (this.composeWorker) {\n this.workerPool.terminate('videoCompose', this.sessionId);\n this.composeWorker = null;\n }\n\n if (this.videoEncodeWorker) {\n this.workerPool.terminate('videoEncode', this.sessionId);\n this.videoEncodeWorker = null;\n }\n\n this.composeToEncodeChannel?.port1.close();\n this.composeToEncodeChannel?.port2.close();\n this.composeToEncodeChannel = null;\n }\n\n async invalidateClipCache(): Promise<void> {\n await this.cacheManager.invalidateClip(this.clipId);\n }\n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export declare class LayerRenderer {
|
|
|
10
10
|
private height;
|
|
11
11
|
private currentFrame;
|
|
12
12
|
private fps;
|
|
13
|
+
private readonly FILL_THRESHOLD;
|
|
13
14
|
constructor(ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D, width: number, height: number, fps?: number);
|
|
14
15
|
setCurrentFrame(frame: number): void;
|
|
15
16
|
private ensureHighQualityRendering;
|
|
@@ -19,6 +20,14 @@ export declare class LayerRenderer {
|
|
|
19
20
|
renderLayer(layer: Layer): Promise<void>;
|
|
20
21
|
private parseDimension;
|
|
21
22
|
private getLayerDimensions;
|
|
23
|
+
/**
|
|
24
|
+
* Calculate render dimensions with smart fill logic
|
|
25
|
+
* @param sourceWidth Source width
|
|
26
|
+
* @param sourceHeight Source height
|
|
27
|
+
* @param naturalScale Natural scale factor (scaleY for video, scaleX for image)
|
|
28
|
+
* @returns Render dimensions and position
|
|
29
|
+
*/
|
|
30
|
+
private calculateRenderDimensions;
|
|
22
31
|
private applyTransform;
|
|
23
32
|
private renderVideoLayer;
|
|
24
33
|
private renderImageLayer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayerRenderer.d.ts","sourceRoot":"","sources":["../../../src/stages/compose/LayerRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAA8D,MAAM,SAAS,CAAC;AAMjG;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,GAAG,CAA+D;IAC1E,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,GAAG,CAAc;
|
|
1
|
+
{"version":3,"file":"LayerRenderer.d.ts","sourceRoot":"","sources":["../../../src/stages/compose/LayerRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAA8D,MAAM,SAAS,CAAC;AAMjG;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,GAAG,CAA+D;IAC1E,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAO;gBAGpC,GAAG,EAAE,iCAAiC,GAAG,wBAAwB,EACjE,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,GAAG,GAAE,MAAW;IASlB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIpC,OAAO,CAAC,0BAA0B;IAKlC;;OAEG;IACG,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IA0C9C,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,kBAAkB;IA+C1B;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAkCjC,OAAO,CAAC,cAAc;YA2BR,gBAAgB;YAmChB,gBAAgB;YAqFhB,eAAe;IAuC7B,OAAO,CAAC,SAAS;IAkBjB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAKtD"}
|
|
@@ -8,6 +8,7 @@ class LayerRenderer {
|
|
|
8
8
|
height;
|
|
9
9
|
currentFrame = 0;
|
|
10
10
|
fps = 30;
|
|
11
|
+
FILL_THRESHOLD = 0.9;
|
|
11
12
|
constructor(ctx, width, height, fps = 30) {
|
|
12
13
|
this.ctx = ctx;
|
|
13
14
|
this.width = width;
|
|
@@ -105,6 +106,31 @@ class LayerRenderer {
|
|
|
105
106
|
}
|
|
106
107
|
return { width: this.width, height: this.height };
|
|
107
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Calculate render dimensions with smart fill logic
|
|
111
|
+
* @param sourceWidth Source width
|
|
112
|
+
* @param sourceHeight Source height
|
|
113
|
+
* @param naturalScale Natural scale factor (scaleY for video, scaleX for image)
|
|
114
|
+
* @returns Render dimensions and position
|
|
115
|
+
*/
|
|
116
|
+
calculateRenderDimensions(sourceWidth, sourceHeight, naturalScale) {
|
|
117
|
+
const scaledWidth = sourceWidth * naturalScale;
|
|
118
|
+
const scaledHeight = sourceHeight * naturalScale;
|
|
119
|
+
const shouldFill = scaledWidth / this.width > this.FILL_THRESHOLD && scaledHeight / this.height > this.FILL_THRESHOLD;
|
|
120
|
+
let renderWidth;
|
|
121
|
+
let renderHeight;
|
|
122
|
+
if (shouldFill) {
|
|
123
|
+
const coverScale = Math.max(this.width / sourceWidth, this.height / sourceHeight);
|
|
124
|
+
renderWidth = Math.round(sourceWidth * coverScale);
|
|
125
|
+
renderHeight = Math.round(sourceHeight * coverScale);
|
|
126
|
+
} else {
|
|
127
|
+
renderWidth = Math.round(scaledWidth);
|
|
128
|
+
renderHeight = Math.round(scaledHeight);
|
|
129
|
+
}
|
|
130
|
+
const renderX = Math.round((this.width - renderWidth) / 2);
|
|
131
|
+
const renderY = Math.round((this.height - renderHeight) / 2);
|
|
132
|
+
return { width: renderWidth, height: renderHeight, x: renderX, y: renderY };
|
|
133
|
+
}
|
|
108
134
|
applyTransform(transform, layerDimensions) {
|
|
109
135
|
const anchorX = transform.anchorX ?? 0.5;
|
|
110
136
|
const anchorY = transform.anchorY ?? 0.5;
|
|
@@ -125,25 +151,7 @@ class LayerRenderer {
|
|
|
125
151
|
const videoWidth = videoFrame.displayWidth || videoFrame.codedWidth;
|
|
126
152
|
const videoHeight = videoFrame.displayHeight || videoFrame.codedHeight;
|
|
127
153
|
const naturalScale = this.height / videoHeight;
|
|
128
|
-
const
|
|
129
|
-
const scaledHeight = videoHeight * naturalScale;
|
|
130
|
-
const FILL_THRESHOLD = 0.9;
|
|
131
|
-
const shouldFill = scaledWidth / this.width > FILL_THRESHOLD && scaledHeight / this.height > FILL_THRESHOLD;
|
|
132
|
-
let renderWidth;
|
|
133
|
-
let renderHeight;
|
|
134
|
-
let renderX;
|
|
135
|
-
let renderY;
|
|
136
|
-
if (shouldFill) {
|
|
137
|
-
renderWidth = this.width;
|
|
138
|
-
renderHeight = this.height;
|
|
139
|
-
renderX = 0;
|
|
140
|
-
renderY = 0;
|
|
141
|
-
} else {
|
|
142
|
-
renderWidth = Math.round(scaledWidth);
|
|
143
|
-
renderHeight = Math.round(scaledHeight);
|
|
144
|
-
renderX = Math.round((this.width - renderWidth) / 2);
|
|
145
|
-
renderY = Math.round((this.height - renderHeight) / 2);
|
|
146
|
-
}
|
|
154
|
+
const dimensions = this.calculateRenderDimensions(videoWidth, videoHeight, naturalScale);
|
|
147
155
|
if (crop) {
|
|
148
156
|
this.ctx.drawImage(
|
|
149
157
|
videoFrame,
|
|
@@ -151,13 +159,19 @@ class LayerRenderer {
|
|
|
151
159
|
crop.y,
|
|
152
160
|
crop.width,
|
|
153
161
|
crop.height,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
162
|
+
dimensions.x,
|
|
163
|
+
dimensions.y,
|
|
164
|
+
dimensions.width,
|
|
165
|
+
dimensions.height
|
|
158
166
|
);
|
|
159
167
|
} else {
|
|
160
|
-
this.ctx.drawImage(
|
|
168
|
+
this.ctx.drawImage(
|
|
169
|
+
videoFrame,
|
|
170
|
+
dimensions.x,
|
|
171
|
+
dimensions.y,
|
|
172
|
+
dimensions.width,
|
|
173
|
+
dimensions.height
|
|
174
|
+
);
|
|
161
175
|
}
|
|
162
176
|
videoFrame.close();
|
|
163
177
|
}
|
|
@@ -201,17 +215,9 @@ class LayerRenderer {
|
|
|
201
215
|
}
|
|
202
216
|
} else {
|
|
203
217
|
const naturalScale = this.width / imgWidth;
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const shouldFill = scaledWidth / this.width > FILL_THRESHOLD && scaledHeight / this.height > FILL_THRESHOLD;
|
|
208
|
-
if (shouldFill) {
|
|
209
|
-
renderWidth = this.width;
|
|
210
|
-
renderHeight = this.height;
|
|
211
|
-
} else {
|
|
212
|
-
renderWidth = Math.round(scaledWidth);
|
|
213
|
-
renderHeight = Math.round(scaledHeight);
|
|
214
|
-
}
|
|
218
|
+
const dimensions = this.calculateRenderDimensions(imgWidth, imgHeight, naturalScale);
|
|
219
|
+
renderWidth = dimensions.width;
|
|
220
|
+
renderHeight = dimensions.height;
|
|
215
221
|
}
|
|
216
222
|
const renderX = isAttachment ? 0 : Math.round((this.width - renderWidth) / 2);
|
|
217
223
|
const renderY = isAttachment ? 0 : Math.round((this.height - renderHeight) / 2);
|