@meframe/core 0.6.13 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -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/resource/ResourceCache.d.ts +0 -12
- package/dist/cache/resource/ResourceCache.d.ts.map +1 -1
- package/dist/cache/resource/ResourceCache.js +0 -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 +5 -4
- package/dist/orchestrator/AudioWindowPreparer.d.ts.map +1 -1
- package/dist/orchestrator/AudioWindowPreparer.js +76 -28
- 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 +1 -1
- package/dist/orchestrator/aac-window-timeline.d.ts.map +1 -1
- package/dist/orchestrator/aac-window-timeline.js +10 -2
- 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/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 +69 -8
- package/dist/stages/load/ResourceLoader.d.ts.map +1 -1
- package/dist/stages/load/ResourceLoader.js +248 -67
- 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 +1 -1
- 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
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface OwnedFrameTransformOptions<In, Out> {
|
|
2
|
+
/** Processes one input. `admit` hands an output item to the stream; `releaseInput` ends the stream's ownership of the input. */
|
|
3
|
+
transform: (input: In, admit: (item: Out) => void, releaseInput: () => void) => Promise<void>;
|
|
4
|
+
flush?: (admit: (item: Out) => void) => Promise<void>;
|
|
5
|
+
disposeInput?: (input: In) => void;
|
|
6
|
+
disposeOutput?: (item: Out) => void;
|
|
7
|
+
onRelease?: () => void;
|
|
8
|
+
inputHighWaterMark?: number;
|
|
9
|
+
outputHighWaterMark?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A transform stream that owns the native frames it holds outside its own queues. The transform hands each output item to
|
|
13
|
+
* `admit`. The item stays owned here until a reader takes it through the readable side, so a cancel, an error or an abort closes
|
|
14
|
+
* exactly the items no reader has taken. An item admitted after the stream has ended is disposed on admission. The writable side
|
|
15
|
+
* keeps at most `inputHighWaterMark` inputs queued here, so a cancel can dispose them; the transform processes the next input only
|
|
16
|
+
* when fewer than `outputHighWaterMark` items are waiting for a reader. The current input remains owned here while its transform
|
|
17
|
+
* callback runs. A callback that disposes or transfers that input can call `releaseInput`. As with a TransformStream, closing the
|
|
18
|
+
* writable side settles once every queued input is transformed and the flush has run, and `error` fails both sides; here it also
|
|
19
|
+
* disposes everything the stream holds.
|
|
20
|
+
*/
|
|
21
|
+
export declare class OwnedFrameTransform<In, Out> {
|
|
22
|
+
readonly readable: ReadableStream<Out>;
|
|
23
|
+
readonly writable: WritableStream<In>;
|
|
24
|
+
private readonly transform;
|
|
25
|
+
private readonly flush?;
|
|
26
|
+
private readonly disposeInput;
|
|
27
|
+
private readonly disposeOutput;
|
|
28
|
+
private readonly onRelease;
|
|
29
|
+
private readonly inputLimit;
|
|
30
|
+
private readonly outputLimit;
|
|
31
|
+
private readonly queued;
|
|
32
|
+
private inFlight;
|
|
33
|
+
private readonly owned;
|
|
34
|
+
private readonly waiters;
|
|
35
|
+
private inputOpen;
|
|
36
|
+
private closing;
|
|
37
|
+
private finished;
|
|
38
|
+
private failure;
|
|
39
|
+
private writableController?;
|
|
40
|
+
constructor({ transform, flush, disposeInput, disposeOutput, onRelease, inputHighWaterMark, outputHighWaterMark, }: OwnedFrameTransformOptions<In, Out>);
|
|
41
|
+
error(reason: unknown): void;
|
|
42
|
+
private writeInput;
|
|
43
|
+
private closeInput;
|
|
44
|
+
private run;
|
|
45
|
+
/** Hands an output item to the stream. The stream owns it until a reader takes it. */
|
|
46
|
+
admit(item: Out): void;
|
|
47
|
+
private pullOutput;
|
|
48
|
+
private stop;
|
|
49
|
+
private wait;
|
|
50
|
+
private wake;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=OwnedFrameTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OwnedFrameTransform.d.ts","sourceRoot":"","sources":["../../../src/stages/compose/OwnedFrameTransform.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B,CAAC,EAAE,EAAE,GAAG;IACjD,gIAAgI;IAChI,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,EAAE,KAA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C,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,kBAAkB,CAAC,CAAkC;gBAEjD,EACV,SAAS,EACT,KAAK,EAEL,YAAyE,EACzE,aAAwE,EACxE,SAAoB,EACpB,kBAAsB,EACtB,mBAAuB,GACxB,EAAE,0BAA0B,CAAC,EAAE,EAAE,GAAG,CAAC;IAmCtC,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;YAKd,UAAU;YAWV,UAAU;YAOV,GAAG;IA8BjB,sFAAsF;IACtF,KAAK,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;YASR,UAAU;IAcxB,OAAO,CAAC,IAAI;IAaZ,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,IAAI;CAGb"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
class OwnedFrameTransform {
|
|
2
|
+
readable;
|
|
3
|
+
writable;
|
|
4
|
+
transform;
|
|
5
|
+
flush;
|
|
6
|
+
disposeInput;
|
|
7
|
+
disposeOutput;
|
|
8
|
+
onRelease;
|
|
9
|
+
inputLimit;
|
|
10
|
+
outputLimit;
|
|
11
|
+
queued = [];
|
|
12
|
+
inFlight = null;
|
|
13
|
+
owned = [];
|
|
14
|
+
waiters = [];
|
|
15
|
+
inputOpen = true;
|
|
16
|
+
closing = false;
|
|
17
|
+
finished = false;
|
|
18
|
+
failure = null;
|
|
19
|
+
writableController;
|
|
20
|
+
constructor({
|
|
21
|
+
transform,
|
|
22
|
+
flush,
|
|
23
|
+
// Inputs are native frames unless the caller says how to dispose them.
|
|
24
|
+
disposeInput = (input) => input.close(),
|
|
25
|
+
disposeOutput = (item) => item.close(),
|
|
26
|
+
onRelease = () => {
|
|
27
|
+
},
|
|
28
|
+
inputHighWaterMark = 1,
|
|
29
|
+
outputHighWaterMark = 1
|
|
30
|
+
}) {
|
|
31
|
+
this.transform = transform;
|
|
32
|
+
this.flush = flush;
|
|
33
|
+
this.disposeInput = disposeInput;
|
|
34
|
+
this.disposeOutput = disposeOutput;
|
|
35
|
+
this.onRelease = onRelease;
|
|
36
|
+
this.inputLimit = inputHighWaterMark;
|
|
37
|
+
this.outputLimit = outputHighWaterMark;
|
|
38
|
+
this.readable = new ReadableStream(
|
|
39
|
+
{
|
|
40
|
+
pull: (controller) => this.pullOutput(controller),
|
|
41
|
+
cancel: (reason) => {
|
|
42
|
+
this.stop(null);
|
|
43
|
+
this.writableController?.error(reason);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{ highWaterMark: 0 }
|
|
47
|
+
);
|
|
48
|
+
this.writable = new WritableStream(
|
|
49
|
+
{
|
|
50
|
+
start: (controller) => {
|
|
51
|
+
this.writableController = controller;
|
|
52
|
+
},
|
|
53
|
+
write: (input) => this.writeInput(input),
|
|
54
|
+
close: () => this.closeInput(),
|
|
55
|
+
abort: (reason) => this.stop(reason ?? new Error("OwnedFrameTransform aborted"))
|
|
56
|
+
},
|
|
57
|
+
{ highWaterMark: 1 }
|
|
58
|
+
);
|
|
59
|
+
void this.run();
|
|
60
|
+
}
|
|
61
|
+
error(reason) {
|
|
62
|
+
this.stop(reason);
|
|
63
|
+
this.writableController?.error(reason);
|
|
64
|
+
}
|
|
65
|
+
async writeInput(input) {
|
|
66
|
+
if (this.finished) {
|
|
67
|
+
this.disposeInput(input);
|
|
68
|
+
throw this.failure ?? new Error("OwnedFrameTransform cancelled");
|
|
69
|
+
}
|
|
70
|
+
this.queued.push(input);
|
|
71
|
+
this.wake();
|
|
72
|
+
while (this.queued.length > this.inputLimit && !this.finished) await this.wait();
|
|
73
|
+
if (this.finished) throw this.failure ?? new Error("OwnedFrameTransform cancelled");
|
|
74
|
+
}
|
|
75
|
+
async closeInput() {
|
|
76
|
+
this.inputOpen = false;
|
|
77
|
+
this.wake();
|
|
78
|
+
while (!this.closing && !this.finished) await this.wait();
|
|
79
|
+
if (this.finished) throw this.failure ?? new Error("OwnedFrameTransform cancelled");
|
|
80
|
+
}
|
|
81
|
+
async run() {
|
|
82
|
+
try {
|
|
83
|
+
for (; ; ) {
|
|
84
|
+
while (!this.finished && this.owned.length >= this.outputLimit) await this.wait();
|
|
85
|
+
while (!this.finished && this.queued.length === 0 && this.inputOpen) await this.wait();
|
|
86
|
+
if (this.finished) return;
|
|
87
|
+
if (this.queued.length === 0) {
|
|
88
|
+
if (this.flush) await this.flush((item) => this.admit(item));
|
|
89
|
+
if (this.finished) return;
|
|
90
|
+
this.closing = true;
|
|
91
|
+
this.wake();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const input = this.queued.shift();
|
|
95
|
+
this.wake();
|
|
96
|
+
this.inFlight = input;
|
|
97
|
+
await this.transform(
|
|
98
|
+
input,
|
|
99
|
+
(item) => this.admit(item),
|
|
100
|
+
() => {
|
|
101
|
+
if (this.inFlight === input) this.inFlight = null;
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
if (this.inFlight === input) this.inFlight = null;
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
this.stop(error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Hands an output item to the stream. The stream owns it until a reader takes it. */
|
|
111
|
+
admit(item) {
|
|
112
|
+
if (this.finished) {
|
|
113
|
+
this.disposeOutput(item);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.owned.push(item);
|
|
117
|
+
this.wake();
|
|
118
|
+
}
|
|
119
|
+
async pullOutput(controller) {
|
|
120
|
+
while (this.owned.length === 0 && !this.finished && !this.closing) await this.wait();
|
|
121
|
+
if (this.finished) {
|
|
122
|
+
if (this.failure) controller.error(this.failure);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (this.owned.length > 0) {
|
|
126
|
+
controller.enqueue(this.owned.shift());
|
|
127
|
+
this.wake();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
controller.close();
|
|
131
|
+
}
|
|
132
|
+
stop(error) {
|
|
133
|
+
if (this.finished) return;
|
|
134
|
+
this.finished = true;
|
|
135
|
+
this.failure = error ?? null;
|
|
136
|
+
const inFlight = this.inFlight;
|
|
137
|
+
this.inFlight = null;
|
|
138
|
+
if (inFlight) this.disposeInput(inFlight);
|
|
139
|
+
for (const input of this.queued.splice(0)) this.disposeInput(input);
|
|
140
|
+
for (const item of this.owned.splice(0)) this.disposeOutput(item);
|
|
141
|
+
this.onRelease();
|
|
142
|
+
this.wake();
|
|
143
|
+
}
|
|
144
|
+
wait() {
|
|
145
|
+
return new Promise((resolve) => this.waiters.push(resolve));
|
|
146
|
+
}
|
|
147
|
+
wake() {
|
|
148
|
+
for (const resume of this.waiters.splice(0)) resume();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export {
|
|
152
|
+
OwnedFrameTransform
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=OwnedFrameTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OwnedFrameTransform.js","sources":["../../../src/stages/compose/OwnedFrameTransform.ts"],"sourcesContent":["export interface OwnedFrameTransformOptions<In, Out> {\n /** Processes one input. `admit` hands an output item to the stream; `releaseInput` ends the stream's ownership of the input. */\n transform: (input: In, admit: (item: Out) => void, releaseInput: () => void) => Promise<void>;\n flush?: (admit: (item: Out) => void) => Promise<void>;\n disposeInput?: (input: In) => void;\n disposeOutput?: (item: Out) => void;\n onRelease?: () => void;\n inputHighWaterMark?: number;\n outputHighWaterMark?: number;\n}\n\n/**\n * A transform stream that owns the native frames it holds outside its own queues. The transform hands each output item to\n * `admit`. The item stays owned here until a reader takes it through the readable side, so a cancel, an error or an abort closes\n * exactly the items no reader has taken. An item admitted after the stream has ended is disposed on admission. The writable side\n * keeps at most `inputHighWaterMark` inputs queued here, so a cancel can dispose them; the transform processes the next input only\n * when fewer than `outputHighWaterMark` items are waiting for a reader. The current input remains owned here while its transform\n * callback runs. A callback that disposes or transfers that input can call `releaseInput`. As with a TransformStream, closing the\n * writable side settles once every queued input is transformed and the flush has run, and `error` fails both sides; here it also\n * disposes everything the stream holds.\n */\nexport class OwnedFrameTransform<In, Out> {\n readonly readable: ReadableStream<Out>;\n readonly writable: WritableStream<In>;\n\n private readonly transform: OwnedFrameTransformOptions<In, Out>['transform'];\n private readonly flush?: OwnedFrameTransformOptions<In, Out>['flush'];\n private readonly disposeInput: (input: In) => void;\n private readonly disposeOutput: (item: Out) => void;\n private readonly onRelease: () => void;\n private readonly inputLimit: number;\n private readonly outputLimit: number;\n private readonly queued: In[] = [];\n private inFlight: In | null = null;\n private readonly owned: Out[] = [];\n private readonly waiters: Array<() => void> = [];\n private inputOpen = true;\n private closing = false;\n private finished = false;\n private failure: unknown = null;\n private writableController?: WritableStreamDefaultController;\n\n constructor({\n transform,\n flush,\n // Inputs are native frames unless the caller says how to dispose them.\n disposeInput = (input) => (input as unknown as { close(): void }).close(),\n disposeOutput = (item) => (item as unknown as { close(): void }).close(),\n onRelease = () => {},\n inputHighWaterMark = 1,\n outputHighWaterMark = 1,\n }: OwnedFrameTransformOptions<In, Out>) {\n this.transform = transform;\n this.flush = flush;\n this.disposeInput = disposeInput;\n this.disposeOutput = disposeOutput;\n this.onRelease = onRelease;\n this.inputLimit = inputHighWaterMark;\n this.outputLimit = outputHighWaterMark;\n\n this.readable = new ReadableStream<Out>(\n {\n pull: (controller) => this.pullOutput(controller),\n cancel: (reason) => {\n this.stop(null);\n this.writableController?.error(reason);\n },\n },\n { highWaterMark: 0 }\n );\n // The writable side must have a positive highWaterMark: with 0, pipeTo never writes. With 1 and a blocking write, pipeTo keeps\n // at most one chunk inside the stream's own queue, and that chunk is already in `queued`, so stop disposes it.\n this.writable = new WritableStream<In>(\n {\n start: (controller) => {\n this.writableController = controller;\n },\n write: (input) => this.writeInput(input),\n close: () => this.closeInput(),\n abort: (reason) => this.stop(reason ?? new Error('OwnedFrameTransform aborted')),\n },\n { highWaterMark: 1 }\n );\n void this.run();\n }\n\n error(reason: unknown): void {\n this.stop(reason);\n this.writableController?.error(reason);\n }\n\n private async writeInput(input: In): Promise<void> {\n if (this.finished) {\n this.disposeInput(input);\n throw this.failure ?? new Error('OwnedFrameTransform cancelled');\n }\n this.queued.push(input);\n this.wake();\n while (this.queued.length > this.inputLimit && !this.finished) await this.wait();\n if (this.finished) throw this.failure ?? new Error('OwnedFrameTransform cancelled');\n }\n\n private async closeInput(): Promise<void> {\n this.inputOpen = false;\n this.wake();\n while (!this.closing && !this.finished) await this.wait();\n if (this.finished) throw this.failure ?? new Error('OwnedFrameTransform cancelled');\n }\n\n private async run(): Promise<void> {\n try {\n for (;;) {\n while (!this.finished && this.owned.length >= this.outputLimit) await this.wait();\n while (!this.finished && this.queued.length === 0 && this.inputOpen) await this.wait();\n if (this.finished) return;\n if (this.queued.length === 0) {\n if (this.flush) await this.flush((item) => this.admit(item));\n if (this.finished) return;\n this.closing = true;\n this.wake();\n return;\n }\n const input = this.queued.shift()!;\n this.wake();\n this.inFlight = input;\n await this.transform(\n input,\n (item) => this.admit(item),\n () => {\n if (this.inFlight === input) this.inFlight = null;\n }\n );\n if (this.inFlight === input) this.inFlight = null;\n }\n } catch (error) {\n this.stop(error);\n }\n }\n\n /** Hands an output item to the stream. The stream owns it until a reader takes it. */\n admit(item: Out): void {\n if (this.finished) {\n this.disposeOutput(item);\n return;\n }\n this.owned.push(item);\n this.wake();\n }\n\n private async pullOutput(controller: ReadableStreamDefaultController<Out>): Promise<void> {\n while (this.owned.length === 0 && !this.finished && !this.closing) await this.wait();\n if (this.finished) {\n if (this.failure) controller.error(this.failure);\n return;\n }\n if (this.owned.length > 0) {\n controller.enqueue(this.owned.shift()!);\n this.wake();\n return;\n }\n controller.close();\n }\n\n private stop(error: unknown): void {\n if (this.finished) return;\n this.finished = true;\n this.failure = error ?? null;\n const inFlight = this.inFlight;\n this.inFlight = null;\n if (inFlight) this.disposeInput(inFlight);\n for (const input of this.queued.splice(0)) this.disposeInput(input);\n for (const item of this.owned.splice(0)) this.disposeOutput(item);\n this.onRelease();\n this.wake();\n }\n\n private wait(): Promise<void> {\n return new Promise((resolve) => this.waiters.push(resolve));\n }\n\n private wake(): void {\n for (const resume of this.waiters.splice(0)) resume();\n }\n}\n"],"names":[],"mappings":"AAqBO,MAAM,oBAA6B;AAAA,EAC/B;AAAA,EACA;AAAA,EAEQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAe,CAAA;AAAA,EACxB,WAAsB;AAAA,EACb,QAAe,CAAA;AAAA,EACf,UAA6B,CAAA;AAAA,EACtC,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,UAAmB;AAAA,EACnB;AAAA,EAER,YAAY;AAAA,IACV;AAAA,IACA;AAAA;AAAA,IAEA,eAAe,CAAC,UAAW,MAAuC,MAAA;AAAA,IAClE,gBAAgB,CAAC,SAAU,KAAsC,MAAA;AAAA,IACjE,YAAY,MAAM;AAAA,IAAC;AAAA,IACnB,qBAAqB;AAAA,IACrB,sBAAsB;AAAA,EAAA,GACgB;AACtC,SAAK,YAAY;AACjB,SAAK,QAAQ;AACb,SAAK,eAAe;AACpB,SAAK,gBAAgB;AACrB,SAAK,YAAY;AACjB,SAAK,aAAa;AAClB,SAAK,cAAc;AAEnB,SAAK,WAAW,IAAI;AAAA,MAClB;AAAA,QACE,MAAM,CAAC,eAAe,KAAK,WAAW,UAAU;AAAA,QAChD,QAAQ,CAAC,WAAW;AAClB,eAAK,KAAK,IAAI;AACd,eAAK,oBAAoB,MAAM,MAAM;AAAA,QACvC;AAAA,MAAA;AAAA,MAEF,EAAE,eAAe,EAAA;AAAA,IAAE;AAIrB,SAAK,WAAW,IAAI;AAAA,MAClB;AAAA,QACE,OAAO,CAAC,eAAe;AACrB,eAAK,qBAAqB;AAAA,QAC5B;AAAA,QACA,OAAO,CAAC,UAAU,KAAK,WAAW,KAAK;AAAA,QACvC,OAAO,MAAM,KAAK,WAAA;AAAA,QAClB,OAAO,CAAC,WAAW,KAAK,KAA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AAQ,KAAK,OAAO,CAAC;AAAA,EAC5D;AAAA,EAEQ,OAAa;AACnB,eAAW,UAAU,KAAK,QAAQ,OAAO,CAAC,EAAG,QAAA;AAAA,EAC/C;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransitionProcessor.js","sources":["../../../src/stages/compose/TransitionProcessor.ts"],"sourcesContent":["import type { TransitionEffect } from './types';\n\n/**\n * TransitionProcessor - Handles transition effects between frames/scenes\n * Single responsibility: Apply transition transformations to canvas context\n */\nexport class TransitionProcessor {\n private width: number;\n private height: number;\n\n constructor(width: number, height: number) {\n this.width = width;\n this.height = height;\n }\n\n /**\n * Apply transition effect to the canvas context\n * Returns true if transition was applied, false if not needed\n */\n applyTransition(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n transition: TransitionEffect\n ): boolean {\n if (!transition || transition.progress <= 0) return false;\n\n const progress = this.calculateEasedProgress(transition.progress, transition.easing);\n\n switch (transition.type) {\n case 'fade':\n return this.applyFade(ctx, progress);\n case 'slide':\n return this.applySlide(ctx, progress, transition.direction);\n case 'wipe':\n return this.applyWipe(ctx, progress, transition.direction);\n case 'zoom':\n return this.applyZoom(ctx, progress, transition.direction);\n case 'rotate':\n return this.applyRotate(ctx, progress);\n case 'dissolve':\n return this.applyDissolve(ctx, progress);\n default:\n return false;\n }\n }\n\n private calculateEasedProgress(\n progress: number,\n easing?: 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out'\n ): number {\n switch (easing) {\n case 'ease-in':\n return progress * progress;\n case 'ease-out':\n return 1 - (1 - progress) * (1 - progress);\n case 'ease-in-out':\n return progress < 0.5 ? 2 * progress * progress : 1 - Math.pow(-2 * progress + 2, 2) / 2;\n default:\n return progress;\n }\n }\n\n private applyFade(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number\n ): boolean {\n ctx.globalAlpha = progress;\n return true;\n }\n\n private applySlide(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number,\n direction?: 'left' | 'right' | 'up' | 'down' | 'in' | 'out'\n ): boolean {\n const distance = 1 - progress;\n\n switch (direction) {\n case 'left':\n ctx.translate(-this.width * distance, 0);\n break;\n case 'right':\n ctx.translate(this.width * distance, 0);\n break;\n case 'up':\n ctx.translate(0, -this.height * distance);\n break;\n case 'down':\n ctx.translate(0, this.height * distance);\n break;\n default:\n ctx.translate(-this.width * distance, 0);\n }\n\n return true;\n }\n\n private applyWipe(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number,\n direction?: 'left' | 'right' | 'up' | 'down' | 'in' | 'out'\n ): boolean {\n ctx.save();\n ctx.beginPath();\n\n switch (direction) {\n case 'left':\n ctx.rect(0, 0, this.width * progress, this.height);\n break;\n case 'right':\n ctx.rect(this.width * (1 - progress), 0, this.width * progress, this.height);\n break;\n case 'up':\n ctx.rect(0, 0, this.width, this.height * progress);\n break;\n case 'down':\n ctx.rect(0, this.height * (1 - progress), this.width, this.height * progress);\n break;\n default:\n ctx.rect(0, 0, this.width * progress, this.height);\n }\n\n ctx.clip();\n return true;\n }\n\n private applyZoom(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number,\n direction?: 'left' | 'right' | 'up' | 'down' | 'in' | 'out'\n ): boolean {\n const scale = direction === 'out' ? 1 + (1 - progress) : progress;\n const centerX = this.width / 2;\n const centerY = this.height / 2;\n\n ctx.translate(centerX, centerY);\n ctx.scale(scale, scale);\n ctx.translate(-centerX, -centerY);\n\n if (direction === 'out') {\n ctx.globalAlpha = progress;\n }\n\n return true;\n }\n\n private applyRotate(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number\n ): boolean {\n const rotation = (1 - progress) * Math.PI * 2;\n const centerX = this.width / 2;\n const centerY = this.height / 2;\n\n ctx.translate(centerX, centerY);\n ctx.rotate(rotation);\n ctx.translate(-centerX, -centerY);\n\n return true;\n }\n\n private applyDissolve(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number\n ): boolean {\n // Simple dissolve using alpha\n ctx.globalAlpha = progress;\n ctx.globalCompositeOperation = 'multiply';\n return true;\n }\n\n /**\n * Create a transition mask for advanced effects\n */\n createTransitionMask(transition: TransitionEffect, canvas: OffscreenCanvas): ImageData | null {\n const ctx = canvas.getContext('2d');\n if (!ctx) return null;\n\n const imageData = ctx.createImageData(this.width, this.height);\n const data = imageData.data;\n const progress = this.calculateEasedProgress(transition.progress, transition.easing);\n\n // Generate gradient mask based on transition type\n for (let y = 0; y < this.height; y++) {\n for (let x = 0; x < this.width; x++) {\n const index = (y * this.width + x) * 4;\n let alpha = 255;\n\n switch (transition.type) {\n case 'wipe':\n alpha = this.calculateWipeAlpha(x, y, progress, transition.direction);\n break;\n case 'dissolve':\n // Random noise dissolve\n alpha = Math.random() < progress ? 255 : 0;\n break;\n default:\n alpha = Math.floor(255 * progress);\n }\n\n data[index] = 255; // R\n data[index + 1] = 255; // G\n data[index + 2] = 255; // B\n data[index + 3] = alpha; // A\n }\n }\n\n return imageData;\n }\n\n private calculateWipeAlpha(\n x: number,\n y: number,\n progress: number,\n direction?: 'left' | 'right' | 'up' | 'down' | 'in' | 'out'\n ): number {\n let position = 0;\n\n switch (direction) {\n case 'left':\n position = x / this.width;\n break;\n case 'right':\n position = 1 - x / this.width;\n break;\n case 'up':\n position = y / this.height;\n break;\n case 'down':\n position = 1 - y / this.height;\n break;\n case 'in': {\n // Radial wipe from center\n const cx = x - this.width / 2;\n const cy = y - this.height / 2;\n const maxDist = Math.sqrt(this.width * this.width + this.height * this.height) / 2;\n position = Math.sqrt(cx * cx + cy * cy) / maxDist;\n break;\n }\n case 'out': {\n // Radial wipe to center\n const cx2 = x - this.width / 2;\n const cy2 = y - this.height / 2;\n const maxDist2 = Math.sqrt(this.width * this.width + this.height * this.height) / 2;\n position = 1 - Math.sqrt(cx2 * cx2 + cy2 * cy2) / maxDist2;\n break;\n }\n default:\n position = x / this.width;\n }\n\n return position < progress ? 255 : 0;\n }\n\n updateDimensions(width: number, height: number): void {\n this.width = width;\n this.height = height;\n }\n}\n"],"names":[],"mappings":"AAMO,MAAM,oBAAoB;AAAA,EACvB;AAAA,EACA;AAAA,EAER,YAAY,OAAe,QAAgB;AACzC,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBACE,KACA,YACS;AACT,QAAI,CAAC,cAAc,WAAW,YAAY,EAAG,QAAO;AAEpD,UAAM,WAAW,KAAK,uBAAuB,WAAW,UAAU,WAAW,MAAM;AAEnF,YAAQ,WAAW,MAAA;AAAA,MACjB,KAAK;AACH,eAAO,KAAK,UAAU,KAAK,QAAQ;AAAA,MACrC,KAAK;AACH,eAAO,KAAK,WAAW,KAAK,UAAU,WAAW,SAAS;AAAA,MAC5D,KAAK;AACH,eAAO,KAAK,UAAU,KAAK,UAAU,WAAW,SAAS;AAAA,MAC3D,KAAK;AACH,eAAO,KAAK,UAAU,KAAK,UAAU,WAAW,SAAS;AAAA,MAC3D,KAAK;AACH,eAAO,KAAK,YAAY,KAAK,QAAQ;AAAA,MACvC,KAAK;AACH,eAAO,KAAK,cAAc,KAAK,QAAQ;AAAA,MACzC;AACE,eAAO;AAAA,IAAA;AAAA,EAEb;AAAA,EAEQ,uBACN,UACA,QACQ;AACR,YAAQ,QAAA;AAAA,MACN,KAAK;AACH,eAAO,WAAW;AAAA,MACpB,KAAK;AACH,eAAO,KAAK,IAAI,aAAa,IAAI;AAAA,MACnC,KAAK;AACH,eAAO,WAAW,MAAM,IAAI,WAAW,WAAW,IAAI,KAAK,IAAI,KAAK,WAAW,GAAG,CAAC,IAAI;AAAA,MACzF;AACE,eAAO;AAAA,IAAA;AAAA,EAEb;AAAA,EAEQ,UACN,KACA,UACS;AACT,QAAI,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EAEQ,WACN,KACA,UACA,WACS;AACT,UAAM,WAAW,IAAI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T;AAAA,EAEQ,mBACN,GACA,GACA,UACA,WACQ;AACR,QAAI,WAAW;AAEf,YAAQ,WAAA;AAAA,MACN,KAAK;AACH,mBAAW,IAAI,KAAK;AACpB;AAAA,MACF,KAAK;AACH,mBAAW,IAAI,IAAI,KAAK;AACxB;AAAA,MACF,KAAK;AACH,mBAAW,IAAI,KAAK;AACpB;AAAA,MACF,KAAK;AACH,mBAAW,IAAI,IAAI,KAAK;AACxB;AAAA,MACF,KAAK,MAAM;AAET,cAAM,KAAK,IAAI,KAAK,QAAQ;AAC5B,cAAM,KAAK,IAAI,KAAK,SAAS;AAC7B,cAAM,UAAU,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,IAAI;AACjF,mBAAW,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE,IAAI;AAC1C;AAAA,MACF;AAAA,MACA,KAAK,OAAO;AAEV,cAAM,MAAM,IAAI,KAAK,QAAQ;AAC7B,cAAM,MAAM,IAAI,KAAK,SAAS;AAC9B,cAAM,WAAW,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,IAAI;AAClF,mBAAW,IAAI,KAAK,KAAK,MAAM,MAAM,MAAM,GAAG,IAAI;AAClD;AAAA,MACF;AAAA,MACA;AACE,mBAAW,IAAI,KAAK;AAAA,IAAA;AAGxB,WAAO,WAAW,WAAW,MAAM;AAAA,EACrC;AAAA,EAEA,iBAAiB,OAAe,QAAsB;AACpD,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EAChB;AACF;"}
|
|
1
|
+
{"version":3,"file":"TransitionProcessor.js","sources":["../../../src/stages/compose/TransitionProcessor.ts"],"sourcesContent":["import type { TransitionEffect } from './types';\n\n/**\n * TransitionProcessor - Handles transition effects between frames/scenes\n * Single responsibility: Apply transition transformations to canvas context\n */\nexport class TransitionProcessor {\n private width: number;\n private height: number;\n\n constructor(width: number, height: number) {\n this.width = width;\n this.height = height;\n }\n\n /**\n * Apply transition effect to the canvas context\n * Returns true if transition was applied, false if not needed\n */\n applyTransition(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n transition: TransitionEffect\n ): boolean {\n if (!transition || transition.progress <= 0) return false;\n\n const progress = this.calculateEasedProgress(transition.progress, transition.easing);\n\n switch (transition.type) {\n case 'fade':\n return this.applyFade(ctx, progress);\n case 'slide':\n return this.applySlide(ctx, progress, transition.direction);\n case 'wipe':\n return this.applyWipe(ctx, progress, transition.direction);\n case 'zoom':\n return this.applyZoom(ctx, progress, transition.direction);\n case 'rotate':\n return this.applyRotate(ctx, progress);\n case 'dissolve':\n return this.applyDissolve(ctx, progress);\n default:\n return false;\n }\n }\n\n private calculateEasedProgress(\n progress: number,\n easing?: 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out'\n ): number {\n switch (easing) {\n case 'ease-in':\n return progress * progress;\n case 'ease-out':\n return 1 - (1 - progress) * (1 - progress);\n case 'ease-in-out':\n return progress < 0.5 ? 2 * progress * progress : 1 - Math.pow(-2 * progress + 2, 2) / 2;\n default:\n return progress;\n }\n }\n\n private applyFade(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number\n ): boolean {\n ctx.globalAlpha = progress;\n return true;\n }\n\n private applySlide(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number,\n direction?: 'left' | 'right' | 'up' | 'down' | 'in' | 'out'\n ): boolean {\n const distance = 1 - progress;\n\n switch (direction) {\n case 'left':\n ctx.translate(-this.width * distance, 0);\n break;\n case 'right':\n ctx.translate(this.width * distance, 0);\n break;\n case 'up':\n ctx.translate(0, -this.height * distance);\n break;\n case 'down':\n ctx.translate(0, this.height * distance);\n break;\n default:\n ctx.translate(-this.width * distance, 0);\n }\n\n return true;\n }\n\n private applyWipe(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number,\n direction?: 'left' | 'right' | 'up' | 'down' | 'in' | 'out'\n ): boolean {\n // No save() here: composeFrame saves before applyTransition and restores after the layers, which also drops the clip.\n ctx.beginPath();\n\n switch (direction) {\n case 'left':\n ctx.rect(0, 0, this.width * progress, this.height);\n break;\n case 'right':\n ctx.rect(this.width * (1 - progress), 0, this.width * progress, this.height);\n break;\n case 'up':\n ctx.rect(0, 0, this.width, this.height * progress);\n break;\n case 'down':\n ctx.rect(0, this.height * (1 - progress), this.width, this.height * progress);\n break;\n default:\n ctx.rect(0, 0, this.width * progress, this.height);\n }\n\n ctx.clip();\n return true;\n }\n\n private applyZoom(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number,\n direction?: 'left' | 'right' | 'up' | 'down' | 'in' | 'out'\n ): boolean {\n const scale = direction === 'out' ? 1 + (1 - progress) : progress;\n const centerX = this.width / 2;\n const centerY = this.height / 2;\n\n ctx.translate(centerX, centerY);\n ctx.scale(scale, scale);\n ctx.translate(-centerX, -centerY);\n\n if (direction === 'out') {\n ctx.globalAlpha = progress;\n }\n\n return true;\n }\n\n private applyRotate(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number\n ): boolean {\n const rotation = (1 - progress) * Math.PI * 2;\n const centerX = this.width / 2;\n const centerY = this.height / 2;\n\n ctx.translate(centerX, centerY);\n ctx.rotate(rotation);\n ctx.translate(-centerX, -centerY);\n\n return true;\n }\n\n private applyDissolve(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n progress: number\n ): boolean {\n // Simple dissolve using alpha\n ctx.globalAlpha = progress;\n ctx.globalCompositeOperation = 'multiply';\n return true;\n }\n\n /**\n * Create a transition mask for advanced effects\n */\n createTransitionMask(transition: TransitionEffect, canvas: OffscreenCanvas): ImageData | null {\n const ctx = canvas.getContext('2d');\n if (!ctx) return null;\n\n const imageData = ctx.createImageData(this.width, this.height);\n const data = imageData.data;\n const progress = this.calculateEasedProgress(transition.progress, transition.easing);\n\n // Generate gradient mask based on transition type\n for (let y = 0; y < this.height; y++) {\n for (let x = 0; x < this.width; x++) {\n const index = (y * this.width + x) * 4;\n let alpha = 255;\n\n switch (transition.type) {\n case 'wipe':\n alpha = this.calculateWipeAlpha(x, y, progress, transition.direction);\n break;\n case 'dissolve':\n // Random noise dissolve\n alpha = Math.random() < progress ? 255 : 0;\n break;\n default:\n alpha = Math.floor(255 * progress);\n }\n\n data[index] = 255; // R\n data[index + 1] = 255; // G\n data[index + 2] = 255; // B\n data[index + 3] = alpha; // A\n }\n }\n\n return imageData;\n }\n\n private calculateWipeAlpha(\n x: number,\n y: number,\n progress: number,\n direction?: 'left' | 'right' | 'up' | 'down' | 'in' | 'out'\n ): number {\n let position = 0;\n\n switch (direction) {\n case 'left':\n position = x / this.width;\n break;\n case 'right':\n position = 1 - x / this.width;\n break;\n case 'up':\n position = y / this.height;\n break;\n case 'down':\n position = 1 - y / this.height;\n break;\n case 'in': {\n // Radial wipe from center\n const cx = x - this.width / 2;\n const cy = y - this.height / 2;\n const maxDist = Math.sqrt(this.width * this.width + this.height * this.height) / 2;\n position = Math.sqrt(cx * cx + cy * cy) / maxDist;\n break;\n }\n case 'out': {\n // Radial wipe to center\n const cx2 = x - this.width / 2;\n const cy2 = y - this.height / 2;\n const maxDist2 = Math.sqrt(this.width * this.width + this.height * this.height) / 2;\n position = 1 - Math.sqrt(cx2 * cx2 + cy2 * cy2) / maxDist2;\n break;\n }\n default:\n position = x / this.width;\n }\n\n return position < progress ? 255 : 0;\n }\n\n updateDimensions(width: number, height: number): void {\n this.width = width;\n this.height = height;\n }\n}\n"],"names":[],"mappings":"AAMO,MAAM,oBAAoB;AAAA,EACvB;AAAA,EACA;AAAA,EAER,YAAY,OAAe,QAAgB;AACzC,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBACE,KACA,YACS;AACT,QAAI,CAAC,cAAc,WAAW,YAAY,EAAG,QAAO;AAEpD,UAAM,WAAW,KAAK,uBAAuB,WAAW,UAA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U,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,IAAI;AACjF,mBAAW,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE,IAAI;AAC1C;AAAA,MACF;AAAA,MACA,KAAK,OAAO;AAEV,cAAM,MAAM,IAAI,KAAK,QAAQ;AAC7B,cAAM,MAAM,IAAI,KAAK,SAAS;AAC9B,cAAM,WAAW,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,IAAI;AAClF,mBAAW,IAAI,KAAK,KAAK,MAAM,MAAM,MAAM,GAAG,IAAI;AAClD;AAAA,MACF;AAAA,MACA;AACE,mBAAW,IAAI,KAAK;AAAA,IAAA;AAGxB,WAAO,WAAW,WAAW,MAAM;AAAA,EACrC;AAAA,EAEA,iBAAiB,OAAe,QAAsB;AACpD,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EAChB;AACF;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { VideoComposeConfig, ComposeRequest, ComposeResult, TransitionEffect } from './types';
|
|
1
|
+
import { VideoComposeConfig, ComposeRequest, ComposeResult, TransitionEffect, Layer } from './types';
|
|
2
2
|
import { ClipInstructionSet } from './instructions';
|
|
3
|
+
import { OwnedFrameTransform } from './OwnedFrameTransform';
|
|
3
4
|
|
|
5
|
+
export declare const closeLayerFrame: (layer: Layer) => void;
|
|
4
6
|
/**
|
|
5
7
|
* VideoComposer - Main visual composition orchestrator
|
|
6
8
|
*/
|
|
@@ -9,6 +11,7 @@ export declare class VideoComposer {
|
|
|
9
11
|
externalCanvas?: HTMLCanvasElement | OffscreenCanvas;
|
|
10
12
|
};
|
|
11
13
|
readonly canvas: OffscreenCanvas | HTMLCanvasElement;
|
|
14
|
+
private readonly fontAbort;
|
|
12
15
|
private ctx;
|
|
13
16
|
private layerRenderer;
|
|
14
17
|
private transitionProcessor;
|
|
@@ -21,7 +24,7 @@ export declare class VideoComposer {
|
|
|
21
24
|
private traceComposeFrames;
|
|
22
25
|
constructor(config: VideoComposeConfig);
|
|
23
26
|
private applyDefaults;
|
|
24
|
-
createStreams(_instruction?: ClipInstructionSet):
|
|
27
|
+
createStreams(_instruction?: ClipInstructionSet): OwnedFrameTransform<ComposeRequest, VideoFrame>;
|
|
25
28
|
/** 重置合成耗时埋点(每次导出开始时由 export.worker 调用)。 */
|
|
26
29
|
resetTraceStats(): void;
|
|
27
30
|
/** 读取累计合成耗时埋点(导出结束时由 export.worker 汇总)。 */
|
|
@@ -30,6 +33,13 @@ export declare class VideoComposer {
|
|
|
30
33
|
composeFrames: number;
|
|
31
34
|
};
|
|
32
35
|
composeFrame(request: ComposeRequest): Promise<ComposeResult>;
|
|
36
|
+
private composeLayers;
|
|
37
|
+
/**
|
|
38
|
+
* Draws one layer inside its own save()/restore(), so whatever state it sets (alpha, composite operation, filter,
|
|
39
|
+
* transform, font, clip) is undone when it finishes or throws. This relies on every renderer below pairing its own
|
|
40
|
+
* save() with a restore() in a finally; then a throw unwinds the stack to exactly where this layer started.
|
|
41
|
+
*/
|
|
42
|
+
private renderIsolatedLayer;
|
|
33
43
|
composeTransition(fromRequest: ComposeRequest, toRequest: ComposeRequest, transition: TransitionEffect): Promise<ComposeResult>;
|
|
34
44
|
private clearCanvas;
|
|
35
45
|
private createOutputFrame;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VideoComposer.d.ts","sourceRoot":"","sources":["../../../src/stages/compose/VideoComposer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,
|
|
1
|
+
{"version":3,"file":"VideoComposer.d.ts","sourceRoot":"","sources":["../../../src/stages/compose/VideoComposer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,EAGhB,KAAK,EACN,MAAM,SAAS,CAAC;AAIjB,OAAO,EAAE,kBAAkB,EA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B,SAAS,EAAE,cAAc,EACzB,UAAU,EAAE,gBAAgB,GAC3B,OAAO,CAAC,aAAa,CAAC;IAWzB,OAAO,CAAC,WAAW;YAaL,iBAAiB;YAUjB,SAAS;YA6BT,WAAW;IAwBzB,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,IAAI;IAuBvD,OAAO,IAAI,IAAI;CAIhB"}
|
|
@@ -3,13 +3,23 @@ import { TransitionProcessor } from "./TransitionProcessor.js";
|
|
|
3
3
|
import { FilterProcessor } from "./FilterProcessor.js";
|
|
4
4
|
import { clearCaptionStaggerCache } from "./text-renderers/caption-stagger-entrance-renderer.js";
|
|
5
5
|
import { clearTextLayoutCache } from "./text-utils/text-layout-cache.js";
|
|
6
|
+
import { OwnedFrameTransform } from "./OwnedFrameTransform.js";
|
|
7
|
+
import { renderLayers } from "./LayerRenderPolicy.js";
|
|
6
8
|
const closeLayerFrame = (layer) => {
|
|
9
|
+
if (layer.type === "image") {
|
|
10
|
+
const imageLayer = layer;
|
|
11
|
+
if (imageLayer.ownedSource && imageLayer.source) {
|
|
12
|
+
imageLayer.source.close();
|
|
13
|
+
imageLayer.source = null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
7
16
|
if (layer.type === "video") {
|
|
8
17
|
const videoLayer = layer;
|
|
9
18
|
if (!videoLayer.rcFrame) {
|
|
10
19
|
const vf = videoLayer.videoFrame;
|
|
11
20
|
if (vf?.close) {
|
|
12
21
|
vf.close();
|
|
22
|
+
videoLayer.videoFrame = void 0;
|
|
13
23
|
}
|
|
14
24
|
}
|
|
15
25
|
}
|
|
@@ -17,6 +27,7 @@ const closeLayerFrame = (layer) => {
|
|
|
17
27
|
class VideoComposer {
|
|
18
28
|
config;
|
|
19
29
|
canvas;
|
|
30
|
+
fontAbort = new AbortController();
|
|
20
31
|
ctx;
|
|
21
32
|
layerRenderer;
|
|
22
33
|
transitionProcessor;
|
|
@@ -93,31 +104,28 @@ class VideoComposer {
|
|
|
93
104
|
};
|
|
94
105
|
}
|
|
95
106
|
createStreams(_instruction) {
|
|
96
|
-
|
|
97
|
-
{
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
controller.enqueue(result.frame);
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
flush: async () => {
|
|
108
|
-
this.filterProcessor.clearCache();
|
|
109
|
-
clearTextLayoutCache();
|
|
110
|
-
clearCaptionStaggerCache();
|
|
107
|
+
return new OwnedFrameTransform({
|
|
108
|
+
transform: async (request, admit) => {
|
|
109
|
+
const t0 = performance.now();
|
|
110
|
+
const result = await this.composeFrame(request);
|
|
111
|
+
this.traceComposeMs += performance.now() - t0;
|
|
112
|
+
this.traceComposeFrames++;
|
|
113
|
+
if (result.frame) {
|
|
114
|
+
admit(result.frame);
|
|
111
115
|
}
|
|
112
116
|
},
|
|
113
|
-
{
|
|
114
|
-
|
|
117
|
+
flush: async () => {
|
|
118
|
+
this.filterProcessor.clearCache();
|
|
119
|
+
clearTextLayoutCache();
|
|
120
|
+
clearCaptionStaggerCache();
|
|
115
121
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
122
|
+
// The request's layers hold native frames; a stream that ends early closes them.
|
|
123
|
+
disposeInput: (request) => {
|
|
124
|
+
for (const layer of request.layers) closeLayerFrame(layer);
|
|
125
|
+
},
|
|
126
|
+
inputHighWaterMark: this.config.inputHighWaterMark,
|
|
127
|
+
outputHighWaterMark: this.config.outputHighWaterMark
|
|
128
|
+
});
|
|
121
129
|
}
|
|
122
130
|
/** 重置合成耗时埋点(每次导出开始时由 export.worker 调用)。 */
|
|
123
131
|
resetTraceStats() {
|
|
@@ -129,13 +137,28 @@ class VideoComposer {
|
|
|
129
137
|
return { composeMs: this.traceComposeMs, composeFrames: this.traceComposeFrames };
|
|
130
138
|
}
|
|
131
139
|
async composeFrame(request) {
|
|
140
|
+
const signal = request.signal;
|
|
141
|
+
try {
|
|
142
|
+
signal?.throwIfAborted();
|
|
143
|
+
return await this.composeLayers(request, signal);
|
|
144
|
+
} finally {
|
|
145
|
+
for (const layer of request.layers) closeLayerFrame(layer);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async composeLayers(request, signal) {
|
|
132
149
|
if (this.fontsLoadingPromise) {
|
|
133
150
|
try {
|
|
134
|
-
await this.withTimeout(
|
|
135
|
-
|
|
151
|
+
await this.withTimeout(
|
|
152
|
+
this.fontsLoadingPromise,
|
|
153
|
+
VideoComposer.FONT_LOAD_TIMEOUT_MS,
|
|
154
|
+
signal
|
|
155
|
+
);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (signal?.aborted) throw error;
|
|
136
158
|
}
|
|
137
159
|
this.fontsLoadingPromise = null;
|
|
138
160
|
}
|
|
161
|
+
signal?.throwIfAborted();
|
|
139
162
|
if (request.layers.length > this.config.maxLayers) {
|
|
140
163
|
throw new Error(`Too many layers: ${request.layers.length} > ${this.config.maxLayers}`);
|
|
141
164
|
}
|
|
@@ -143,47 +166,28 @@ class VideoComposer {
|
|
|
143
166
|
const frameDurationUs = 1e6 / this.config.fps;
|
|
144
167
|
const relativeFrame = Math.floor(request.timeUs / frameDurationUs);
|
|
145
168
|
this.layerRenderer.setCurrentFrame(relativeFrame);
|
|
146
|
-
if (request.transition)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
for (const layer of request.layers) {
|
|
151
|
-
if (!layer.visible || layer.opacity <= 0) {
|
|
152
|
-
closeLayerFrame(layer);
|
|
153
|
-
continue;
|
|
169
|
+
if (request.transition) this.ctx.save();
|
|
170
|
+
try {
|
|
171
|
+
if (request.transition) {
|
|
172
|
+
this.transitionProcessor.applyTransition(this.ctx, request.transition);
|
|
154
173
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
videoLayer
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this.
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this.ctx.restore();
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
} else {
|
|
170
|
-
if (layer.filters && layer.filters.length > 0) {
|
|
171
|
-
this.ctx.save();
|
|
172
|
-
this.filterProcessor.applyFilters(this.ctx, layer.filters);
|
|
173
|
-
}
|
|
174
|
-
this.layerRenderer.renderLayer(layer);
|
|
175
|
-
if (layer.filters && layer.filters.length > 0) {
|
|
176
|
-
this.ctx.restore();
|
|
174
|
+
renderLayers(
|
|
175
|
+
request.layers,
|
|
176
|
+
(layer) => {
|
|
177
|
+
const videoLayer = layer;
|
|
178
|
+
if (videoLayer.rcFrame) {
|
|
179
|
+
videoLayer.rcFrame.use((frame2) => {
|
|
180
|
+
videoLayer.videoFrame = frame2;
|
|
181
|
+
this.renderIsolatedLayer(layer);
|
|
182
|
+
});
|
|
183
|
+
} else {
|
|
184
|
+
this.renderIsolatedLayer(layer);
|
|
177
185
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (request.transition) {
|
|
186
|
-
this.ctx.restore();
|
|
186
|
+
},
|
|
187
|
+
request.onLayerError
|
|
188
|
+
);
|
|
189
|
+
} finally {
|
|
190
|
+
if (request.transition) this.ctx.restore();
|
|
187
191
|
}
|
|
188
192
|
let frame = null;
|
|
189
193
|
if (!this.config.externalCanvas) {
|
|
@@ -194,6 +198,22 @@ class VideoComposer {
|
|
|
194
198
|
timeUs: request.timeUs
|
|
195
199
|
};
|
|
196
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Draws one layer inside its own save()/restore(), so whatever state it sets (alpha, composite operation, filter,
|
|
203
|
+
* transform, font, clip) is undone when it finishes or throws. This relies on every renderer below pairing its own
|
|
204
|
+
* save() with a restore() in a finally; then a throw unwinds the stack to exactly where this layer started.
|
|
205
|
+
*/
|
|
206
|
+
renderIsolatedLayer(layer) {
|
|
207
|
+
this.ctx.save();
|
|
208
|
+
try {
|
|
209
|
+
if (layer.filters && layer.filters.length > 0) {
|
|
210
|
+
this.filterProcessor.applyFilters(this.ctx, layer.filters);
|
|
211
|
+
}
|
|
212
|
+
this.layerRenderer.renderLayer(layer);
|
|
213
|
+
} finally {
|
|
214
|
+
this.ctx.restore();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
197
217
|
async composeTransition(fromRequest, toRequest, transition) {
|
|
198
218
|
await this.composeFrame(fromRequest);
|
|
199
219
|
const toFrameRequest = {
|
|
@@ -237,44 +257,30 @@ class VideoComposer {
|
|
|
237
257
|
fontFace.load(),
|
|
238
258
|
VideoComposer.FONT_LOAD_TIMEOUT_MS
|
|
239
259
|
);
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
260
|
+
const fontSet = typeof document !== "undefined" ? document.fonts : self.fonts;
|
|
261
|
+
fontSet.add(loadedFont);
|
|
243
262
|
this.loadedFonts.add(font.family);
|
|
244
263
|
} catch {
|
|
245
264
|
}
|
|
246
265
|
}
|
|
247
266
|
}
|
|
248
|
-
async withTimeout(promise, timeoutMs) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
let timeoutId = null;
|
|
267
|
+
async withTimeout(promise, timeoutMs, signal = this.fontAbort.signal) {
|
|
268
|
+
signal?.throwIfAborted();
|
|
269
|
+
let timer;
|
|
270
|
+
let abort;
|
|
253
271
|
try {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
(error) => ({ ok: false, error })
|
|
257
|
-
);
|
|
258
|
-
const result = await Promise.race([
|
|
259
|
-
safe,
|
|
272
|
+
return await Promise.race([
|
|
273
|
+
promise,
|
|
260
274
|
new Promise((_, reject) => {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
275
|
+
abort = () => reject(signal?.reason);
|
|
276
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
277
|
+
if (timeoutMs > 0)
|
|
278
|
+
timer = setTimeout(() => reject(new Error("Font load timeout")), timeoutMs);
|
|
265
279
|
})
|
|
266
280
|
]);
|
|
267
|
-
if (result?.ok === true) {
|
|
268
|
-
return result.value;
|
|
269
|
-
}
|
|
270
|
-
if (result?.ok === false) {
|
|
271
|
-
throw result.error;
|
|
272
|
-
}
|
|
273
|
-
return result;
|
|
274
281
|
} finally {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
282
|
+
clearTimeout(timer);
|
|
283
|
+
if (abort) signal?.removeEventListener("abort", abort);
|
|
278
284
|
}
|
|
279
285
|
}
|
|
280
286
|
updateConfig(config) {
|
|
@@ -296,10 +302,12 @@ class VideoComposer {
|
|
|
296
302
|
}
|
|
297
303
|
}
|
|
298
304
|
dispose() {
|
|
305
|
+
this.fontAbort.abort(new DOMException("Composer disposed", "AbortError"));
|
|
299
306
|
this.filterProcessor.clearCache();
|
|
300
307
|
}
|
|
301
308
|
}
|
|
302
309
|
export {
|
|
303
|
-
VideoComposer
|
|
310
|
+
VideoComposer,
|
|
311
|
+
closeLayerFrame
|
|
304
312
|
};
|
|
305
313
|
//# sourceMappingURL=VideoComposer.js.map
|