@meframe/core 0.0.11 → 0.0.13
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 +3 -4
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +5 -30
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/l1/VideoL1Cache.d.ts +1 -1
- package/dist/cache/l1/VideoL1Cache.d.ts.map +1 -1
- package/dist/cache/l1/VideoL1Cache.js +1 -1
- package/dist/cache/l1/VideoL1Cache.js.map +1 -1
- package/dist/controllers/PlaybackController.d.ts.map +1 -1
- package/dist/controllers/PlaybackController.js +1 -2
- package/dist/controllers/PlaybackController.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/CompositionModel.d.ts +2 -1
- package/dist/model/CompositionModel.d.ts.map +1 -1
- package/dist/model/CompositionModel.js +80 -11
- package/dist/model/CompositionModel.js.map +1 -1
- package/dist/model/types.d.ts +30 -1
- package/dist/model/types.d.ts.map +1 -1
- package/dist/orchestrator/ClipSessionManager.d.ts +1 -5
- package/dist/orchestrator/ClipSessionManager.d.ts.map +1 -1
- package/dist/orchestrator/ClipSessionManager.js +1 -6
- package/dist/orchestrator/ClipSessionManager.js.map +1 -1
- package/dist/orchestrator/CompositionPlanner.d.ts.map +1 -1
- package/dist/orchestrator/CompositionPlanner.js +18 -2
- package/dist/orchestrator/CompositionPlanner.js.map +1 -1
- package/dist/orchestrator/Orchestrator.d.ts +1 -0
- package/dist/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/Orchestrator.js +70 -7
- package/dist/orchestrator/Orchestrator.js.map +1 -1
- package/dist/orchestrator/VideoClipSession.d.ts +2 -1
- package/dist/orchestrator/VideoClipSession.d.ts.map +1 -1
- package/dist/orchestrator/VideoClipSession.js +16 -1
- package/dist/orchestrator/VideoClipSession.js.map +1 -1
- package/dist/stages/compose/LayerRenderer.d.ts +2 -0
- package/dist/stages/compose/LayerRenderer.d.ts.map +1 -1
- package/dist/stages/compose/instructions.d.ts +24 -1
- package/dist/stages/compose/instructions.d.ts.map +1 -1
- package/dist/stages/compose/types.d.ts +2 -0
- package/dist/stages/compose/types.d.ts.map +1 -1
- package/dist/stages/decode/BaseDecoder.js +130 -0
- package/dist/stages/decode/BaseDecoder.js.map +1 -0
- package/dist/stages/decode/VideoChunkDecoder.js +199 -0
- package/dist/stages/decode/VideoChunkDecoder.js.map +1 -0
- package/dist/stages/load/ResourceLoader.d.ts +8 -0
- package/dist/stages/load/ResourceLoader.d.ts.map +1 -1
- package/dist/stages/load/ResourceLoader.js +74 -12
- package/dist/stages/load/ResourceLoader.js.map +1 -1
- package/dist/stages/load/types.d.ts +1 -0
- package/dist/stages/load/types.d.ts.map +1 -1
- package/dist/utils/animation-utils.d.ts +16 -0
- package/dist/utils/animation-utils.d.ts.map +1 -0
- package/dist/utils/image-utils.d.ts +5 -0
- package/dist/utils/image-utils.d.ts.map +1 -0
- package/dist/utils/image-utils.js +32 -0
- package/dist/utils/image-utils.js.map +1 -0
- package/dist/workers/stages/compose/video-compose.worker.js +256 -29
- package/dist/workers/stages/compose/video-compose.worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
class BaseDecoder {
|
|
2
|
+
decoder;
|
|
3
|
+
config;
|
|
4
|
+
controller = null;
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
}
|
|
8
|
+
async initialize() {
|
|
9
|
+
if (this.decoder?.state === "configured") {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const isSupported = await this.isConfigSupported(this.config);
|
|
13
|
+
if (!isSupported.supported) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`Codec not supported: ${this.config.codecString || this.config.codec}`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
this.decoder = this.createDecoder({
|
|
19
|
+
output: this.handleOutput.bind(this),
|
|
20
|
+
error: this.handleError.bind(this)
|
|
21
|
+
});
|
|
22
|
+
await this.configureDecoder(this.config);
|
|
23
|
+
}
|
|
24
|
+
async reconfigure(config) {
|
|
25
|
+
this.config = { ...this.config, ...config };
|
|
26
|
+
if (!this.decoder) {
|
|
27
|
+
await this.initialize();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (this.decoder.state === "configured") {
|
|
31
|
+
await this.decoder.flush();
|
|
32
|
+
}
|
|
33
|
+
const isSupported = await this.isConfigSupported(this.config);
|
|
34
|
+
if (!isSupported.supported) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`New configuration not supported: ${this.config.codecString || this.config.codec}`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
await this.configureDecoder(this.config);
|
|
40
|
+
}
|
|
41
|
+
async flush() {
|
|
42
|
+
if (!this.decoder) return;
|
|
43
|
+
await this.decoder.flush();
|
|
44
|
+
}
|
|
45
|
+
async reset() {
|
|
46
|
+
if (!this.decoder) return;
|
|
47
|
+
this.decoder.reset();
|
|
48
|
+
this.onReset();
|
|
49
|
+
}
|
|
50
|
+
async close() {
|
|
51
|
+
if (!this.decoder) return;
|
|
52
|
+
if (this.decoder.state === "configured") {
|
|
53
|
+
await this.decoder.flush();
|
|
54
|
+
}
|
|
55
|
+
this.decoder.close();
|
|
56
|
+
this.decoder = void 0;
|
|
57
|
+
}
|
|
58
|
+
get isReady() {
|
|
59
|
+
return this.decoder?.state === "configured";
|
|
60
|
+
}
|
|
61
|
+
get queueSize() {
|
|
62
|
+
return this.decoder?.decodeQueueSize ?? 0;
|
|
63
|
+
}
|
|
64
|
+
handleOutput(data) {
|
|
65
|
+
if (!this.controller) {
|
|
66
|
+
this.closeIfPossible(data);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
this.controller.enqueue(data);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (error instanceof TypeError && /Cannot enqueue a chunk into a readable stream that is closed/.test(error.message)) {
|
|
73
|
+
this.closeIfPossible(data);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
handleError(error) {
|
|
80
|
+
console.error(`${this.getDecoderType()} decoder error:`, error);
|
|
81
|
+
this.controller?.error(error);
|
|
82
|
+
}
|
|
83
|
+
closeIfPossible(data) {
|
|
84
|
+
data?.close?.();
|
|
85
|
+
data?.frame?.close?.();
|
|
86
|
+
}
|
|
87
|
+
onReset() {
|
|
88
|
+
}
|
|
89
|
+
createStream() {
|
|
90
|
+
return new TransformStream(
|
|
91
|
+
{
|
|
92
|
+
start: async (controller) => {
|
|
93
|
+
this.controller = controller;
|
|
94
|
+
if (!this.isReady) {
|
|
95
|
+
await this.initialize();
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
transform: async (input) => {
|
|
99
|
+
if (!this.decoder || this.decoder.state !== "configured") {
|
|
100
|
+
throw new Error("Decoder not configured");
|
|
101
|
+
}
|
|
102
|
+
if (this.decoder.decodeQueueSize >= this.decodeQueueThreshold) {
|
|
103
|
+
await new Promise((resolve) => {
|
|
104
|
+
const check = () => {
|
|
105
|
+
if (!this.decoder || this.decoder.decodeQueueSize < this.decodeQueueThreshold - 1) {
|
|
106
|
+
resolve();
|
|
107
|
+
} else {
|
|
108
|
+
setTimeout(check, 10);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
check();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
this.decode(input);
|
|
115
|
+
},
|
|
116
|
+
flush: async () => {
|
|
117
|
+
await this.flush();
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
highWaterMark: this.highWaterMark,
|
|
122
|
+
size: () => 1
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
BaseDecoder
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=BaseDecoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseDecoder.js","sources":["../../../src/stages/decode/BaseDecoder.ts"],"sourcesContent":["/**\n * Base decoder class abstracting common WebCodecs decoder workflow.\n * Mirrors BaseEncoder but for decoding path.\n */\nimport { AudioDecoderConfig, DecodedVideoFrame, VideoDecoderConfig } from './types';\n\nexport abstract class BaseDecoder<\n TDecoder extends VideoDecoder | AudioDecoder,\n TConfig extends VideoDecoderConfig | AudioDecoderConfig,\n TInput extends EncodedVideoChunk | EncodedAudioChunk,\n TOutput extends VideoFrame | AudioData | DecodedVideoFrame,\n> {\n protected decoder?: TDecoder;\n protected config: TConfig;\n protected controller: TransformStreamDefaultController<TOutput> | null = null;\n\n constructor(config: TConfig) {\n this.config = config;\n }\n\n async initialize(): Promise<void> {\n if (this.decoder?.state === 'configured') {\n return;\n }\n const isSupported = await this.isConfigSupported(this.config);\n if (!isSupported.supported) {\n throw new Error(\n `Codec not supported: ${(this.config as any).codecString || (this.config as any).codec}`\n );\n }\n\n this.decoder = this.createDecoder({\n output: this.handleOutput.bind(this),\n error: this.handleError.bind(this),\n });\n\n await this.configureDecoder(this.config);\n }\n\n async reconfigure(config: Partial<TConfig>): Promise<void> {\n this.config = { ...this.config, ...config } as TConfig;\n\n if (!this.decoder) {\n await this.initialize();\n return;\n }\n\n // Flush before reconfiguring\n if (this.decoder.state === 'configured') {\n await this.decoder.flush();\n }\n\n const isSupported = await this.isConfigSupported(this.config);\n if (!isSupported.supported) {\n throw new Error(\n `New configuration not supported: ${(this.config as any).codecString || (this.config as any).codec}`\n );\n }\n\n await this.configureDecoder(this.config);\n }\n\n async flush(): Promise<void> {\n if (!this.decoder) return;\n await this.decoder.flush();\n }\n\n async reset(): Promise<void> {\n if (!this.decoder) return;\n this.decoder.reset();\n this.onReset();\n }\n\n async close(): Promise<void> {\n if (!this.decoder) return;\n\n if (this.decoder.state === 'configured') {\n await this.decoder.flush();\n }\n\n this.decoder.close();\n this.decoder = undefined;\n }\n\n get isReady(): boolean {\n return this.decoder?.state === 'configured';\n }\n\n get queueSize(): number {\n return (this.decoder as any)?.decodeQueueSize ?? 0;\n }\n\n protected handleOutput(data: TOutput): void {\n if (!this.controller) {\n this.closeIfPossible(data);\n return;\n }\n\n try {\n this.controller.enqueue(data);\n } catch (error) {\n if (\n error instanceof TypeError &&\n /Cannot enqueue a chunk into a readable stream that is closed/.test(error.message)\n ) {\n this.closeIfPossible(data);\n return;\n }\n\n throw error;\n }\n }\n\n protected handleError(error: DOMException): void {\n console.error(`${this.getDecoderType()} decoder error:`, error);\n this.controller?.error(error);\n }\n\n private closeIfPossible(data: TOutput): void {\n (data as any)?.close?.();\n (data as DecodedVideoFrame)?.frame?.close?.();\n }\n\n // Abstracts\n protected abstract isConfigSupported(config: TConfig): Promise<{ supported: boolean }>;\n protected abstract createDecoder(init: DecoderInit): TDecoder;\n protected abstract configureDecoder(config: TConfig): Promise<void>;\n protected abstract getDecoderType(): string;\n protected abstract decode(input: TInput): void;\n protected onReset(): void {}\n\n // Backpressure\n protected abstract readonly highWaterMark: number;\n protected abstract readonly decodeQueueThreshold: number;\n\n createStream(): TransformStream<TInput, TOutput> {\n return new TransformStream<TInput, TOutput>(\n {\n start: async (controller) => {\n this.controller = controller;\n if (!this.isReady) {\n await this.initialize();\n }\n },\n transform: async (input) => {\n if (!this.decoder || this.decoder.state !== 'configured') {\n throw new Error('Decoder not configured');\n }\n // backpressure\n if ((this.decoder as any).decodeQueueSize >= this.decodeQueueThreshold) {\n await new Promise<void>((resolve) => {\n const check = () => {\n if (\n !this.decoder ||\n (this.decoder as any).decodeQueueSize < this.decodeQueueThreshold - 1\n ) {\n resolve();\n } else {\n setTimeout(check, 10);\n }\n };\n check();\n });\n }\n this.decode(input);\n },\n flush: async () => {\n await this.flush();\n },\n },\n {\n highWaterMark: this.highWaterMark,\n size: () => 1,\n }\n );\n }\n}\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AAM,wBAAwB;AAAA,UAC1C;AAEA,cAAK,KAAK,QAAgB,mBAAmB,KAAK,sBAAsB;AACtE,kBAAM,IAAI,QAAc,CAAC,YAAY;AACnC,oBAAM,QAAQ,MAAM;AAClB,oBACE,CAAC,KAAK,WACL,KAAK,QAAgB,kBAAkB,KAAK,uBAAuB,GACpE;AACA,0BAAA;AAAA,gBACF,OAAO;AACL,6BAAW,OAAO,EAAE;AAAA,gBACtB;AAAA,cACF;AACA,oBAAA;AAAA,YACF,CAAC;AAAA,UACH;AACA,eAAK,OAAO,KAAK;AAAA,QACnB;AAAA,QACA,OAAO,YAAY;AACjB,gBAAM,KAAK,MAAA;AAAA,QACb;AAAA,MAAA;AAAA,MAEF;AAAA,QACE,eAAe,KAAK;AAAA,QACpB,MAAM,MAAM;AAAA,MAAA;AAAA,IACd;AAAA,EAEJ;AACF;"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { BaseDecoder } from "./BaseDecoder.js";
|
|
2
|
+
class VideoChunkDecoder extends BaseDecoder {
|
|
3
|
+
static DEFAULT_HIGH_WATER_MARK = 4;
|
|
4
|
+
static DEFAULT_DECODE_QUEUE_THRESHOLD = 16;
|
|
5
|
+
trackId;
|
|
6
|
+
highWaterMark;
|
|
7
|
+
decodeQueueThreshold;
|
|
8
|
+
// GOP tracking (serial is derived from keyframe timestamp for idempotency)
|
|
9
|
+
currentGopSerial = -1;
|
|
10
|
+
isCurrentFrameKeyframe = false;
|
|
11
|
+
// Buffering support for delayed configuration
|
|
12
|
+
bufferedChunks = [];
|
|
13
|
+
isProcessingBuffer = false;
|
|
14
|
+
constructor(trackId, config) {
|
|
15
|
+
super(config || {});
|
|
16
|
+
this.trackId = trackId;
|
|
17
|
+
this.highWaterMark = config?.backpressure?.highWaterMark ?? VideoChunkDecoder.DEFAULT_HIGH_WATER_MARK;
|
|
18
|
+
this.decodeQueueThreshold = config?.backpressure?.decodeQueueThreshold ?? VideoChunkDecoder.DEFAULT_DECODE_QUEUE_THRESHOLD;
|
|
19
|
+
}
|
|
20
|
+
// Computed properties
|
|
21
|
+
get isConfigured() {
|
|
22
|
+
return this.isReady;
|
|
23
|
+
}
|
|
24
|
+
get state() {
|
|
25
|
+
return this.decoder?.state || "unconfigured";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Update configuration - can be called before or after initialization
|
|
29
|
+
*/
|
|
30
|
+
async updateConfig(config) {
|
|
31
|
+
if (!this.isReady && config.codec) {
|
|
32
|
+
await this.configure(config);
|
|
33
|
+
await this.processBufferedChunks();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Override createStream to handle GOP tracking and buffering
|
|
37
|
+
// Always create new stream for each clip (ReadableStreams can only be consumed once)
|
|
38
|
+
createStream() {
|
|
39
|
+
return new TransformStream(
|
|
40
|
+
{
|
|
41
|
+
start: async (controller) => {
|
|
42
|
+
this.controller = controller;
|
|
43
|
+
if (this.config?.codec && this.config?.description && !this.isReady) {
|
|
44
|
+
await this.initialize();
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
transform: async (chunk) => {
|
|
48
|
+
if (!this.isReady) {
|
|
49
|
+
this.bufferedChunks.push(chunk);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (this.isProcessingBuffer) {
|
|
53
|
+
this.bufferedChunks.push(chunk);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
await this.processChunk(chunk);
|
|
57
|
+
},
|
|
58
|
+
flush: async () => {
|
|
59
|
+
if (this.isReady) {
|
|
60
|
+
await this.flush();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
highWaterMark: this.highWaterMark,
|
|
66
|
+
size: () => 1
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Process a single chunk (extracted from transform for reuse)
|
|
72
|
+
*/
|
|
73
|
+
async processChunk(chunk) {
|
|
74
|
+
if (!this.decoder) {
|
|
75
|
+
throw new Error("Decoder not initialized");
|
|
76
|
+
}
|
|
77
|
+
if (this.decoder.state !== "configured") {
|
|
78
|
+
console.error("[VideoChunkDecoder] Decoder in unexpected state:", this.decoder.state);
|
|
79
|
+
throw new Error(`Decoder not configured, state: ${this.decoder.state}`);
|
|
80
|
+
}
|
|
81
|
+
if (chunk.type === "key") {
|
|
82
|
+
this.handleKeyFrame(chunk.timestamp);
|
|
83
|
+
}
|
|
84
|
+
if (this.decoder.decodeQueueSize >= this.decodeQueueThreshold) {
|
|
85
|
+
await new Promise((resolve) => {
|
|
86
|
+
const check = () => {
|
|
87
|
+
if (!this.decoder || this.decoder.decodeQueueSize < this.decodeQueueThreshold - 1) {
|
|
88
|
+
resolve();
|
|
89
|
+
} else {
|
|
90
|
+
setTimeout(check, 20);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
check();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
this.decode(chunk);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error(`[VideoChunkDecoder] decode error:`, error);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Override handleOutput to attach GOP metadata
|
|
104
|
+
handleOutput(frame) {
|
|
105
|
+
const wrappedFrame = {
|
|
106
|
+
frame,
|
|
107
|
+
gopSerial: this.currentGopSerial,
|
|
108
|
+
isKeyframe: this.isCurrentFrameKeyframe,
|
|
109
|
+
timestamp: frame.timestamp
|
|
110
|
+
};
|
|
111
|
+
this.isCurrentFrameKeyframe = false;
|
|
112
|
+
super.handleOutput(wrappedFrame);
|
|
113
|
+
}
|
|
114
|
+
// Implement abstract methods
|
|
115
|
+
async isConfigSupported(config) {
|
|
116
|
+
const result = await VideoDecoder.isConfigSupported({
|
|
117
|
+
codec: config.codec,
|
|
118
|
+
codedWidth: config.width,
|
|
119
|
+
codedHeight: config.height
|
|
120
|
+
});
|
|
121
|
+
return { supported: result.supported ?? false };
|
|
122
|
+
}
|
|
123
|
+
createDecoder(init) {
|
|
124
|
+
return new VideoDecoder(init);
|
|
125
|
+
}
|
|
126
|
+
getDecoderType() {
|
|
127
|
+
return "Video";
|
|
128
|
+
}
|
|
129
|
+
async configureDecoder(config) {
|
|
130
|
+
if (!this.decoder) return;
|
|
131
|
+
const decoderConfig = {
|
|
132
|
+
codec: config.codec,
|
|
133
|
+
codedWidth: config.width,
|
|
134
|
+
codedHeight: config.height,
|
|
135
|
+
hardwareAcceleration: config.hardwareAcceleration || "no-preference",
|
|
136
|
+
optimizeForLatency: false,
|
|
137
|
+
...config.description && { description: config.description },
|
|
138
|
+
...config.displayAspectWidth && { displayAspectWidth: config.displayAspectWidth },
|
|
139
|
+
...config.displayAspectHeight && { displayAspectHeight: config.displayAspectHeight }
|
|
140
|
+
};
|
|
141
|
+
this.decoder.configure(decoderConfig);
|
|
142
|
+
}
|
|
143
|
+
decode(chunk) {
|
|
144
|
+
this.decoder?.decode(chunk);
|
|
145
|
+
}
|
|
146
|
+
// Override reset to clear GOP data
|
|
147
|
+
onReset() {
|
|
148
|
+
this.currentGopSerial = -1;
|
|
149
|
+
this.isCurrentFrameKeyframe = false;
|
|
150
|
+
}
|
|
151
|
+
// GOP management methods
|
|
152
|
+
handleKeyFrame(timestamp) {
|
|
153
|
+
this.currentGopSerial = timestamp;
|
|
154
|
+
this.isCurrentFrameKeyframe = true;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Configure the decoder with codec info (can be called after creation)
|
|
158
|
+
*/
|
|
159
|
+
async configure(config) {
|
|
160
|
+
if (this.isReady) {
|
|
161
|
+
await this.reconfigure(config);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.config = config;
|
|
165
|
+
await this.initialize();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Process any buffered chunks after configuration
|
|
169
|
+
*/
|
|
170
|
+
async processBufferedChunks() {
|
|
171
|
+
if (!this.isReady || this.bufferedChunks.length === 0) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.isProcessingBuffer = true;
|
|
175
|
+
const chunks = [...this.bufferedChunks];
|
|
176
|
+
this.bufferedChunks = [];
|
|
177
|
+
for (const chunk of chunks) {
|
|
178
|
+
try {
|
|
179
|
+
await this.processChunk(chunk);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error("[VideoChunkDecoder] Error processing buffered chunk:", error);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
this.isProcessingBuffer = false;
|
|
185
|
+
if (this.bufferedChunks.length > 0) {
|
|
186
|
+
await this.processBufferedChunks();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Override close to clean up GOP data
|
|
190
|
+
async close() {
|
|
191
|
+
this.bufferedChunks = [];
|
|
192
|
+
this.onReset();
|
|
193
|
+
await super.close();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export {
|
|
197
|
+
VideoChunkDecoder
|
|
198
|
+
};
|
|
199
|
+
//# sourceMappingURL=VideoChunkDecoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VideoChunkDecoder.js","sources":["../../../src/stages/decode/VideoChunkDecoder.ts"],"sourcesContent":["import { VideoDecoderConfig } from './types';\nimport { BaseDecoder } from './BaseDecoder';\n\n/**\n * Video decoder with GOP tracking\n * Tracks keyframe boundaries and attaches GOP metadata to decoded frames\n */\nexport class VideoChunkDecoder extends BaseDecoder<\n VideoDecoder,\n VideoDecoderConfig,\n EncodedVideoChunk,\n VideoFrame\n> {\n private static readonly DEFAULT_HIGH_WATER_MARK = 4;\n private static readonly DEFAULT_DECODE_QUEUE_THRESHOLD = 16;\n\n readonly trackId: string;\n\n protected readonly highWaterMark: number;\n protected readonly decodeQueueThreshold: number;\n\n // GOP tracking (serial is derived from keyframe timestamp for idempotency)\n private currentGopSerial = -1;\n private isCurrentFrameKeyframe = false;\n\n // Buffering support for delayed configuration\n private bufferedChunks: EncodedVideoChunk[] = [];\n private isProcessingBuffer: boolean = false;\n\n constructor(trackId: string, config?: Partial<VideoDecoderConfig>) {\n super((config || {}) as VideoDecoderConfig);\n\n this.trackId = trackId;\n this.highWaterMark =\n config?.backpressure?.highWaterMark ?? VideoChunkDecoder.DEFAULT_HIGH_WATER_MARK;\n this.decodeQueueThreshold =\n config?.backpressure?.decodeQueueThreshold ??\n VideoChunkDecoder.DEFAULT_DECODE_QUEUE_THRESHOLD;\n }\n\n // Computed properties\n get isConfigured(): boolean {\n return this.isReady;\n }\n\n get state(): string {\n return this.decoder?.state || 'unconfigured';\n }\n\n /**\n * Update configuration - can be called before or after initialization\n */\n async updateConfig(config: Partial<VideoDecoderConfig>): Promise<void> {\n if (!this.isReady && config.codec) {\n await this.configure(config as VideoDecoderConfig);\n await this.processBufferedChunks();\n }\n }\n\n // Override createStream to handle GOP tracking and buffering\n // Always create new stream for each clip (ReadableStreams can only be consumed once)\n override createStream(): TransformStream<EncodedVideoChunk, VideoFrame> {\n return new TransformStream<EncodedVideoChunk, VideoFrame>(\n {\n start: async (controller) => {\n this.controller = controller;\n // Don't initialize if no codec config yet\n if (this.config?.codec && this.config?.description && !this.isReady) {\n await this.initialize();\n }\n },\n\n transform: async (chunk) => {\n // If not configured yet, buffer the chunk\n if (!this.isReady) {\n this.bufferedChunks.push(chunk);\n return; // Don't process yet\n }\n\n // If we're processing buffered chunks, add to buffer to maintain order\n if (this.isProcessingBuffer) {\n this.bufferedChunks.push(chunk);\n return;\n }\n\n // Normal processing\n await this.processChunk(chunk);\n },\n\n flush: async () => {\n if (this.isReady) {\n await this.flush();\n }\n },\n },\n {\n highWaterMark: this.highWaterMark,\n size: () => 1,\n }\n );\n }\n\n /**\n * Process a single chunk (extracted from transform for reuse)\n */\n private async processChunk(chunk: EncodedVideoChunk): Promise<void> {\n if (!this.decoder) {\n throw new Error('Decoder not initialized');\n }\n\n if (this.decoder.state !== 'configured') {\n console.error('[VideoChunkDecoder] Decoder in unexpected state:', this.decoder.state);\n throw new Error(`Decoder not configured, state: ${this.decoder.state}`);\n }\n\n // Track GOP boundaries\n if (chunk.type === 'key') {\n this.handleKeyFrame(chunk.timestamp);\n }\n\n // Check decoder queue pressure\n if (this.decoder.decodeQueueSize >= this.decodeQueueThreshold) {\n await new Promise<void>((resolve) => {\n const check = () => {\n if (!this.decoder || this.decoder.decodeQueueSize < this.decodeQueueThreshold - 1) {\n resolve();\n } else {\n setTimeout(check, 20);\n }\n };\n check();\n });\n }\n\n // Decode the chunk\n try {\n this.decode(chunk);\n } catch (error) {\n console.error(`[VideoChunkDecoder] decode error:`, error);\n throw error; // Re-throw to propagate\n }\n }\n\n // Override handleOutput to attach GOP metadata\n protected override handleOutput(frame: VideoFrame): void {\n // Wrap frame with GOP metadata as a plain object\n // The frame itself will be transferred, but metadata travels separately\n const wrappedFrame = {\n frame,\n gopSerial: this.currentGopSerial,\n isKeyframe: this.isCurrentFrameKeyframe,\n timestamp: frame.timestamp,\n };\n\n // Reset keyframe flag for subsequent frames\n this.isCurrentFrameKeyframe = false;\n\n // Call parent to enqueue wrapped frame\n super.handleOutput(wrappedFrame as any);\n }\n\n // Implement abstract methods\n protected async isConfigSupported(config: VideoDecoderConfig): Promise<{ supported: boolean }> {\n const result = await VideoDecoder.isConfigSupported({\n codec: config.codec,\n codedWidth: config.width,\n codedHeight: config.height,\n });\n return { supported: result.supported ?? false };\n }\n\n protected createDecoder(init: {\n output: (frame: VideoFrame) => void;\n error: (error: DOMException) => void;\n }): VideoDecoder {\n return new VideoDecoder(init);\n }\n\n protected getDecoderType(): string {\n return 'Video';\n }\n\n protected async configureDecoder(config: VideoDecoderConfig): Promise<void> {\n if (!this.decoder) return;\n\n const decoderConfig = {\n codec: config.codec,\n codedWidth: config.width,\n codedHeight: config.height,\n hardwareAcceleration: config.hardwareAcceleration || 'no-preference',\n optimizeForLatency: false,\n ...(config.description && { description: config.description }),\n ...(config.displayAspectWidth && { displayAspectWidth: config.displayAspectWidth }),\n ...(config.displayAspectHeight && { displayAspectHeight: config.displayAspectHeight }),\n };\n\n this.decoder.configure(decoderConfig as any);\n // console.log('[VideoChunkDecoder] Decoder configured, state:', this.decoder.state);\n }\n\n protected decode(chunk: EncodedVideoChunk): void {\n this.decoder?.decode(chunk);\n }\n\n // Override reset to clear GOP data\n protected override onReset(): void {\n this.currentGopSerial = -1;\n this.isCurrentFrameKeyframe = false;\n }\n\n // GOP management methods\n private handleKeyFrame(timestamp: number): void {\n // Use timestamp as gopSerial for idempotency (same keyframe = same serial)\n this.currentGopSerial = timestamp;\n this.isCurrentFrameKeyframe = true;\n }\n\n /**\n * Configure the decoder with codec info (can be called after creation)\n */\n async configure(config: VideoDecoderConfig): Promise<void> {\n // console.log('[VideoChunkDecoder] Configuring with:', config);\n\n if (this.isReady) {\n // If already configured, reconfigure\n await this.reconfigure(config);\n return;\n }\n\n this.config = config as any;\n\n // Initialize decoder with new config\n await this.initialize();\n }\n\n /**\n * Process any buffered chunks after configuration\n */\n async processBufferedChunks(): Promise<void> {\n if (!this.isReady || this.bufferedChunks.length === 0) {\n return;\n }\n\n // console.log('[VideoChunkDecoder] Processing', this.bufferedChunks.length, 'buffered chunks');\n this.isProcessingBuffer = true;\n\n // Process buffered chunks in order\n const chunks = [...this.bufferedChunks];\n this.bufferedChunks = [];\n\n for (const chunk of chunks) {\n try {\n await this.processChunk(chunk);\n } catch (error) {\n console.error('[VideoChunkDecoder] Error processing buffered chunk:', error);\n }\n }\n\n this.isProcessingBuffer = false;\n\n // Process any new chunks that arrived while processing buffer\n if (this.bufferedChunks.length > 0) {\n await this.processBufferedChunks();\n }\n }\n\n // Override close to clean up GOP data\n override async close(): Promise<void> {\n // Clear buffered chunks\n this.bufferedChunks = [];\n\n // Clean up GOP data first\n this.onReset();\n\n // Call parent close\n await super.close();\n }\n}\n"],"names":[],"mappings":";AAOO,MAAM,0BAA0B,YAKrC;AAAA,EACA,OAAwB,0BAA0B;AAAA,EAClD,OAAwB,iCAAiC;AAAA,EAEh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cAAM,KAAK,aAAa,KAAK;AAAA,MAC/B,SAAS,OAAO;AACd,gBAAQ,MAAM,wDAAwD,KAAK;AAAA,MAC7E;AAAA,IACF;AAEA,SAAK,qBAAqB;AAG1B,QAAI,KAAK,eAAe,SAAS,GAAG;AAClC,YAAM,KAAK,sBAAA;AAAA,IACb;AAAA,EACF;AAAA;AAAA,EAGA,MAAe,QAAuB;AAEpC,SAAK,iBAAiB,CAAA;AAGtB,SAAK,QAAA;AAGL,UAAM,MAAM,MAAA;AAAA,EACd;AACF;"}
|
|
@@ -12,6 +12,8 @@ export declare class ResourceLoader {
|
|
|
12
12
|
private eventBus?;
|
|
13
13
|
private onStateChange?;
|
|
14
14
|
private byteRangeResolver;
|
|
15
|
+
private blobCache;
|
|
16
|
+
private pendingTransfers;
|
|
15
17
|
constructor(options?: ResourceLoaderOptions);
|
|
16
18
|
/**
|
|
17
19
|
* Bind to Orchestrator event system
|
|
@@ -23,6 +25,7 @@ export declare class ResourceLoader {
|
|
|
23
25
|
unbind(): void;
|
|
24
26
|
private handleModelSet;
|
|
25
27
|
private enqueueLoad;
|
|
28
|
+
private registerPendingTransfer;
|
|
26
29
|
private processQueue;
|
|
27
30
|
/**
|
|
28
31
|
* Start loading a resource
|
|
@@ -47,6 +50,11 @@ export declare class ResourceLoader {
|
|
|
47
50
|
* Transfer ImageBitmap to VideoComposeWorker
|
|
48
51
|
*/
|
|
49
52
|
private transferImageToWorker;
|
|
53
|
+
/**
|
|
54
|
+
* Transfer cached image to a session
|
|
55
|
+
* Creates new ImageBitmap from cached Blob and transfers to worker
|
|
56
|
+
*/
|
|
57
|
+
private transferCachedImage;
|
|
50
58
|
private transferToDemuxWorker;
|
|
51
59
|
private updateResourceState;
|
|
52
60
|
fetch(resourceId?: string, options?: ResourceLoadOptions): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceLoader.d.ts","sourceRoot":"","sources":["../../../src/stages/load/ResourceLoader.ts"],"names":[],"mappings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AC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB9E,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKhC;;OAEG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAI9C,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAOzB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB9E,IAAI,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAEvC;IAED,IAAI,SAAS,IAAI,QAAQ,EAAE,CAE1B;IAED,OAAO,IAAI,IAAI;CAOhB"}
|
|
@@ -3,6 +3,7 @@ import { StreamFactory } from "./StreamFactory.js";
|
|
|
3
3
|
import { EventHandlers } from "./EventHandlers.js";
|
|
4
4
|
import { MeframeEvent } from "../../event/events.js";
|
|
5
5
|
import { WindowByteRangeResolver } from "./WindowByteRangeResolver.js";
|
|
6
|
+
import { createImageBitmapFromBlob } from "../../utils/image-utils.js";
|
|
6
7
|
class ResourceConflictError extends Error {
|
|
7
8
|
constructor(message) {
|
|
8
9
|
super(message);
|
|
@@ -18,6 +19,8 @@ class ResourceLoader {
|
|
|
18
19
|
eventBus;
|
|
19
20
|
onStateChange;
|
|
20
21
|
byteRangeResolver;
|
|
22
|
+
blobCache = /* @__PURE__ */ new Map();
|
|
23
|
+
pendingTransfers = /* @__PURE__ */ new Map();
|
|
21
24
|
constructor(options) {
|
|
22
25
|
const maxConcurrent = options?.config?.maxConcurrent ?? 4;
|
|
23
26
|
this.taskManager = new TaskManager(maxConcurrent);
|
|
@@ -52,15 +55,37 @@ class ResourceLoader {
|
|
|
52
55
|
handleModelSet(model) {
|
|
53
56
|
this.model = model;
|
|
54
57
|
}
|
|
55
|
-
enqueueLoad(resource, priority = "normal", sessionId, trackId) {
|
|
56
|
-
if (this.taskManager.hasActiveTask(resource.id)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
enqueueLoad(resource, priority = "normal", sessionId, trackId, isMainTrack = false) {
|
|
59
|
+
if (this.taskManager.hasActiveTask(resource.id)) {
|
|
60
|
+
if (priority === "high") ;
|
|
61
|
+
else if (isMainTrack) {
|
|
62
|
+
throw new ResourceConflictError(
|
|
63
|
+
`Resource ${resource.id} is being loaded by another session. Preview channel has priority.`
|
|
64
|
+
);
|
|
65
|
+
} else {
|
|
66
|
+
if (this.blobCache.has(resource.id)) {
|
|
67
|
+
void this.transferCachedImage(resource.id, sessionId);
|
|
68
|
+
return;
|
|
69
|
+
} else {
|
|
70
|
+
this.registerPendingTransfer(resource.id, sessionId);
|
|
71
|
+
console.debug(
|
|
72
|
+
`[ResourceLoader] Attachment resource ${resource.id} loading, registered for pending transfer`
|
|
73
|
+
);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
60
77
|
}
|
|
61
78
|
this.taskManager.enqueue(resource, priority, sessionId, trackId);
|
|
62
79
|
this.processQueue();
|
|
63
80
|
}
|
|
81
|
+
registerPendingTransfer(resourceId, sessionId) {
|
|
82
|
+
if (!sessionId) return;
|
|
83
|
+
const pending = this.pendingTransfers.get(resourceId) || [];
|
|
84
|
+
if (!pending.includes(sessionId)) {
|
|
85
|
+
pending.push(sessionId);
|
|
86
|
+
this.pendingTransfers.set(resourceId, pending);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
64
89
|
processQueue() {
|
|
65
90
|
while (this.taskManager.canProcess) {
|
|
66
91
|
const task = this.taskManager.getNextTask();
|
|
@@ -110,13 +135,20 @@ class ResourceLoader {
|
|
|
110
135
|
* Note: Images don't need streaming (typically < 5MB)
|
|
111
136
|
*/
|
|
112
137
|
async loadImageBitmap(task) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
let blob = this.blobCache.get(task.resourceId);
|
|
139
|
+
if (!blob) {
|
|
140
|
+
blob = await this.fetchBlob(task.resource.uri, task.controller.signal);
|
|
141
|
+
this.blobCache.set(task.resourceId, blob);
|
|
142
|
+
}
|
|
143
|
+
const imageBitmap = await createImageBitmapFromBlob(blob);
|
|
119
144
|
await this.transferImageToWorker(task, imageBitmap);
|
|
145
|
+
const pending = this.pendingTransfers.get(task.resourceId);
|
|
146
|
+
if (pending && pending.length > 0) {
|
|
147
|
+
for (const sessionId of pending) {
|
|
148
|
+
await this.transferCachedImage(task.resourceId, sessionId);
|
|
149
|
+
}
|
|
150
|
+
this.pendingTransfers.delete(task.resourceId);
|
|
151
|
+
}
|
|
120
152
|
}
|
|
121
153
|
/**
|
|
122
154
|
* Fetch resource as blob (for images, json, etc.)
|
|
@@ -151,6 +183,28 @@ class ResourceLoader {
|
|
|
151
183
|
{ transfer: [imageBitmap] }
|
|
152
184
|
);
|
|
153
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Transfer cached image to a session
|
|
188
|
+
* Creates new ImageBitmap from cached Blob and transfers to worker
|
|
189
|
+
*/
|
|
190
|
+
async transferCachedImage(resourceId, sessionId) {
|
|
191
|
+
const blob = this.blobCache.get(resourceId);
|
|
192
|
+
if (!blob || !sessionId) return;
|
|
193
|
+
const imageBitmap = await createImageBitmapFromBlob(blob);
|
|
194
|
+
if (!this.orchestrator) return;
|
|
195
|
+
const composeWorker = await this.orchestrator.workers.get("videoCompose", sessionId, {
|
|
196
|
+
lazy: true
|
|
197
|
+
});
|
|
198
|
+
await composeWorker.send(
|
|
199
|
+
"receive_image",
|
|
200
|
+
{
|
|
201
|
+
resourceId,
|
|
202
|
+
sessionId,
|
|
203
|
+
imageBitmap
|
|
204
|
+
},
|
|
205
|
+
{ transfer: [imageBitmap] }
|
|
206
|
+
);
|
|
207
|
+
}
|
|
154
208
|
async transferToDemuxWorker(task) {
|
|
155
209
|
if (!task.stream || !this.orchestrator) return;
|
|
156
210
|
if (!task.sessionId) {
|
|
@@ -194,7 +248,13 @@ class ResourceLoader {
|
|
|
194
248
|
console.warn(`Resource ${resourceId} not found in model`);
|
|
195
249
|
return;
|
|
196
250
|
}
|
|
197
|
-
this.enqueueLoad(
|
|
251
|
+
this.enqueueLoad(
|
|
252
|
+
resource,
|
|
253
|
+
options?.priority || "normal",
|
|
254
|
+
options?.sessionId,
|
|
255
|
+
options?.trackId,
|
|
256
|
+
options?.isMainTrack ?? false
|
|
257
|
+
);
|
|
198
258
|
}
|
|
199
259
|
cancel(resourceId) {
|
|
200
260
|
this.taskManager.cancelTask(resourceId);
|
|
@@ -238,6 +298,8 @@ class ResourceLoader {
|
|
|
238
298
|
dispose() {
|
|
239
299
|
this.taskManager.clear();
|
|
240
300
|
this.byteRangeResolver.dispose();
|
|
301
|
+
this.blobCache.clear();
|
|
302
|
+
this.pendingTransfers.clear();
|
|
241
303
|
this.unbind();
|
|
242
304
|
}
|
|
243
305
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceLoader.js","sources":["../../../src/stages/load/ResourceLoader.ts"],"sourcesContent":["import type { Resource, CompositionModel } from '../../model';\nimport type { Orchestrator, ResourceLoadOptions, LoadTask, ResourceLoaderOptions } from './types';\nimport { TaskManager } from './TaskManager';\nimport { StreamFactory } from './StreamFactory';\nimport { EventHandlers } from './EventHandlers';\nimport { EventPayloadMap, MeframeEvent } from '../../event/events';\nimport { EventBus } from '../../event/EventBus';\nimport { WindowByteRangeResolver } from './WindowByteRangeResolver';\n\nexport class ResourceConflictError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ResourceConflictError';\n }\n}\n\nexport class ResourceLoader {\n private orchestrator?: Orchestrator;\n private model?: CompositionModel;\n private taskManager: TaskManager;\n private streamFactory: StreamFactory;\n private eventHandlers?: EventHandlers;\n private eventBus?: EventBus<EventPayloadMap>;\n private onStateChange?: (resourceId: string, state: Resource['state']) => void;\n private byteRangeResolver: WindowByteRangeResolver;\n\n constructor(options?: ResourceLoaderOptions) {\n const maxConcurrent = options?.config?.maxConcurrent ?? 4;\n this.taskManager = new TaskManager(maxConcurrent);\n this.streamFactory = new StreamFactory(options?.onProgress, options?.config);\n this.eventBus = options?.eventBus;\n this.onStateChange = options?.onStateChange;\n this.byteRangeResolver = new WindowByteRangeResolver();\n\n if (options?.orchestrator) {\n this.bind(options.orchestrator);\n }\n }\n\n /**\n * Bind to Orchestrator event system\n */\n bind(orchestrator: Orchestrator): void {\n this.unbind();\n this.orchestrator = orchestrator;\n\n this.eventHandlers = new EventHandlers(\n orchestrator,\n (resourceId) => this.cancel(resourceId),\n (model) => this.handleModelSet(model)\n );\n }\n\n /**\n * Unbind from Orchestrator\n */\n unbind(): void {\n this.eventHandlers?.dispose();\n this.eventHandlers = undefined;\n this.orchestrator = undefined;\n }\n\n private handleModelSet(model: CompositionModel): void {\n this.model = model;\n }\n\n private enqueueLoad(\n resource: Resource,\n priority: 'high' | 'normal' | 'low' = 'normal',\n sessionId?: string,\n trackId?: string\n ): void {\n if (this.taskManager.hasActiveTask(resource.id) && priority !== 'high') {\n throw new ResourceConflictError(\n `Resource ${resource.id} is being loaded by another session. Preview channel has priority.`\n );\n }\n\n this.taskManager.enqueue(resource, priority, sessionId, trackId);\n this.processQueue();\n }\n\n private processQueue(): void {\n while (this.taskManager.canProcess) {\n const task = this.taskManager.getNextTask();\n if (!task) break;\n this.startLoad(task);\n }\n }\n\n /**\n * Start loading a resource\n * Handles state management (loading → ready/error) for all resource types\n */\n private async startLoad(task: LoadTask): Promise<void> {\n this.taskManager.activateTask(task);\n\n try {\n this.updateResourceState(task.resourceId, 'loading');\n task.controller = new AbortController();\n\n // Route to different handlers based on resource type\n // Note: Each handler only deals with data, state is managed here\n if (task.resource.type === 'image') {\n await this.loadImageBitmap(task);\n } else if (task.resource.type === 'video' || task.resource.type === 'audio') {\n const stream = await this.streamFactory.createRegularStream(task);\n if (!stream) {\n throw new Error(`Failed to create stream for ${task.resourceId}`);\n }\n task.stream = stream;\n await this.transferToDemuxWorker(task);\n } else if (task.resource.type === 'json' || task.resource.type === 'text') {\n await this.loadTextResource(task);\n }\n\n // Unified state update for all resource types\n this.updateResourceState(task.resourceId, 'ready');\n } catch (error) {\n task.error = error as Error;\n this.updateResourceState(task.resourceId, 'error');\n } finally {\n this.taskManager.completeTask(task.resourceId);\n this.processQueue();\n }\n }\n\n /**\n * Load text-based resources (json, text)\n * Just download the content - state management is handled by startLoad()\n */\n private async loadTextResource(task: LoadTask): Promise<void> {\n await this.fetchBlob(task.resource.uri, task.controller!.signal);\n // For json/text, just verify we can download it\n // Future: could parse and validate json here if needed\n }\n\n /**\n * Load image resource: fetch blob → create ImageBitmap → transfer to worker\n * Note: Images don't need streaming (typically < 5MB)\n */\n private async loadImageBitmap(task: LoadTask): Promise<void> {\n const blob = await this.fetchBlob(task.resource.uri, task.controller!.signal);\n\n // Create ImageBitmap in main thread, then transfer to worker\n // Note: In Worker context, ImageBitmap is the only way to create VideoFrame from image data\n const imageBitmap = await createImageBitmap(blob, {\n premultiplyAlpha: 'premultiply',\n colorSpaceConversion: 'default',\n imageOrientation: 'from-image',\n });\n\n await this.transferImageToWorker(task, imageBitmap);\n }\n\n /**\n * Fetch resource as blob (for images, json, etc.)\n */\n private async fetchBlob(uri: string, signal: AbortSignal): Promise<Blob> {\n const response = await fetch(uri, { signal });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n return response.blob();\n }\n\n /**\n * Transfer ImageBitmap to VideoComposeWorker\n */\n private async transferImageToWorker(task: LoadTask, imageBitmap: ImageBitmap): Promise<void> {\n if (!this.orchestrator) return;\n\n if (!task.sessionId) {\n throw new Error(\n `[ResourceLoader] sessionId required for resource ${task.resourceId}. ` +\n `In Clip-based architecture, use fetch(resourceId, { sessionId })`\n );\n }\n\n const composeWorker = await this.orchestrator.workers.get('videoCompose', task.sessionId, {\n lazy: true,\n });\n\n await composeWorker.send(\n 'receive_image',\n {\n resourceId: task.resourceId,\n sessionId: task.sessionId,\n imageBitmap,\n },\n { transfer: [imageBitmap] }\n );\n }\n\n private async transferToDemuxWorker(task: LoadTask): Promise<void> {\n if (!task.stream || !this.orchestrator) return;\n\n if (!task.sessionId) {\n throw new Error(\n `[ResourceLoader] sessionId required for resource ${task.resourceId}. ` +\n `In Clip-based architecture, use fetch(resourceId, { sessionId })`\n );\n }\n\n const workerType = task.resource.type === 'video' ? 'videoDemux' : 'audioDemux';\n const demuxWorker = await this.orchestrator.workers.get(workerType, task.sessionId, {\n lazy: true,\n });\n\n await demuxWorker.sendStream(task.stream, {\n sessionId: task.sessionId,\n ...task.metadata,\n ...(task.range && { range: task.range }),\n ...(task.trackId && { trackId: task.trackId }),\n });\n }\n\n private updateResourceState(resourceId: string, state: Resource['state']): void {\n const resource = this.model?.resources.get(resourceId);\n if (resource) {\n const oldState = resource.state;\n resource.state = state;\n if (this.orchestrator) {\n this.eventBus?.emit(MeframeEvent.ResourceStageChange, {\n type: MeframeEvent.ResourceStageChange,\n resourceId,\n oldState,\n newState: state,\n });\n }\n }\n\n this.onStateChange?.(resourceId, state);\n }\n\n async fetch(resourceId?: string, options?: ResourceLoadOptions): Promise<void> {\n if (!resourceId) {\n return;\n }\n\n const resource = this.model?.resources.get(resourceId);\n if (!resource) {\n console.warn(`Resource ${resourceId} not found in model`);\n return;\n }\n\n this.enqueueLoad(resource, options?.priority || 'normal', options?.sessionId, options?.trackId);\n }\n\n cancel(resourceId: string): void {\n this.taskManager.cancelTask(resourceId);\n this.processQueue();\n }\n\n /**\n * Check if a resource is currently being loaded\n */\n isResourceLoading(resourceId: string): boolean {\n return this.taskManager.hasActiveTask(resourceId);\n }\n\n pause(resourceId: string): void {\n const task = this.taskManager.getActiveTask(resourceId);\n if (task) {\n task.controller?.abort();\n }\n }\n\n async resume(resourceId: string, options?: ResourceLoadOptions): Promise<void> {\n const resource = this.model?.getResource(resourceId);\n if (!resource) {\n throw new Error(`Resource ${resourceId} not found`);\n }\n\n const pausedTask = this.taskManager.getActiveTask(resourceId);\n\n if (pausedTask?.pausedAt !== undefined) {\n this.enqueueLoad(\n resource,\n options?.priority || 'normal',\n options?.sessionId,\n options?.trackId\n );\n } else {\n await this.fetch(resourceId, options);\n }\n }\n\n get activeTasks(): Map<string, LoadTask> {\n return this.taskManager.activeTasks;\n }\n\n get taskQueue(): LoadTask[] {\n return this.taskManager.taskQueue;\n }\n\n dispose(): void {\n this.taskManager.clear();\n this.byteRangeResolver.dispose();\n this.unbind();\n }\n}\n"],"names":[],"mappings":";;;;;AASO,MAAM,8BAA8B,MAAM;AAAA,EAC/C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,eAAe;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,SAAiC;AAC3C,UAAM,gBAAgB,SAAS,QAAQ,iBAAiB;AACxD,SAAK,cAAc,IAAI,YAAY,aAAa;AAChD,SAAK,gBAAgB,IAAI,cAAc,SAAS,YAAY,SAAS,MAAM;AAC3E,SAAK,WAAW,SAAS;AACzB,SAAK,gBAAgB,SAAS;AAC9B,SAAK,oBAAoB,IAAI,wBAAA;AAE7B,QAAI,SAAS,cAAc;AACzB,WAAK,KAAK,QAAQ,YAAY;AAAA,IAChC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,KAAK,cAAkC;AACrC,SAAK,OAAA;AACL,SAAK,eAAe;AAEpB,SAAK,gBAAgB,IAAI;AAAA,MACvB;AAAA,MACA,CAAC,eAAe,KAAK,OAAO,UAAU;AAAA,MACtC,CAAC,UAAU,KAAK,eAAe,KAAK;AAAA,IAAA;AAAA,EAExC;AAAA;AAAA;AAAA;AAAA,EAKA,SAAe;AACb,SAAK,eAAe,QAAA;AACpB,SAAK,gBAAgB;AACrB,SAAK,eAAe;AAAA,EACtB;AAAA,EAEQ,eAAe,OAA+B;AACpD,SAAK,QAAQ;AAAA,EACf;AAAA,EAEQ,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kBAAkB,YAA6B;AAC7C,WAAO,KAAK,YAAY,cAAc,UAAU;AAAA,EAClD;AAAA,EAEA,MAAM,YAA0B;AAC9B,UAAM,OAAO,KAAK,YAAY,cAAc,UAAU;AACtD,QAAI,MAAM;AACR,WAAK,YAAY,MAAA;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,YAAoB,SAA8C;AAC7E,UAAM,WAAW,KAAK,OAAO,YAAY,UAAU;AACnD,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,YAAY,UAAU,YAAY;AAAA,IACpD;AAEA,UAAM,aAAa,KAAK,YAAY,cAAc,UAAU;AAE5D,QAAI,YAAY,aAAa,QAAW;AACtC,WAAK;AAAA,QACH;AAAA,QACA,SAAS,YAAY;AAAA,QACrB,SAAS;AAAA,QACT,SAAS;AAAA,MAAA;AAAA,IAEb,OAAO;AACL,YAAM,KAAK,MAAM,YAAY,OAAO;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,IAAI,cAAqC;AACvC,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEA,IAAI,YAAwB;AAC1B,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEA,UAAgB;AACd,SAAK,YAAY,MAAA;AACjB,SAAK,kBAAkB,QAAA;AACvB,SAAK,OAAA;AAAA,EACP;AACF;"}
|
|
1
|
+
{"version":3,"file":"ResourceLoader.js","sources":["../../../src/stages/load/ResourceLoader.ts"],"sourcesContent":["import type { Resource, CompositionModel } from '../../model';\nimport type { Orchestrator, ResourceLoadOptions, LoadTask, ResourceLoaderOptions } from './types';\nimport { TaskManager } from './TaskManager';\nimport { StreamFactory } from './StreamFactory';\nimport { EventHandlers } from './EventHandlers';\nimport { EventPayloadMap, MeframeEvent } from '../../event/events';\nimport { EventBus } from '../../event/EventBus';\nimport { WindowByteRangeResolver } from './WindowByteRangeResolver';\nimport { createImageBitmapFromBlob } from '../../utils/image-utils';\n\nexport class ResourceConflictError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ResourceConflictError';\n }\n}\n\nexport class ResourceLoader {\n private orchestrator?: Orchestrator;\n private model?: CompositionModel;\n private taskManager: TaskManager;\n private streamFactory: StreamFactory;\n private eventHandlers?: EventHandlers;\n private eventBus?: EventBus<EventPayloadMap>;\n private onStateChange?: (resourceId: string, state: Resource['state']) => void;\n private byteRangeResolver: WindowByteRangeResolver;\n private blobCache = new Map<string, Blob>();\n private pendingTransfers = new Map<string, string[]>();\n\n constructor(options?: ResourceLoaderOptions) {\n const maxConcurrent = options?.config?.maxConcurrent ?? 4;\n this.taskManager = new TaskManager(maxConcurrent);\n this.streamFactory = new StreamFactory(options?.onProgress, options?.config);\n this.eventBus = options?.eventBus;\n this.onStateChange = options?.onStateChange;\n this.byteRangeResolver = new WindowByteRangeResolver();\n\n if (options?.orchestrator) {\n this.bind(options.orchestrator);\n }\n }\n\n /**\n * Bind to Orchestrator event system\n */\n bind(orchestrator: Orchestrator): void {\n this.unbind();\n this.orchestrator = orchestrator;\n\n this.eventHandlers = new EventHandlers(\n orchestrator,\n (resourceId) => this.cancel(resourceId),\n (model) => this.handleModelSet(model)\n );\n }\n\n /**\n * Unbind from Orchestrator\n */\n unbind(): void {\n this.eventHandlers?.dispose();\n this.eventHandlers = undefined;\n this.orchestrator = undefined;\n }\n\n private handleModelSet(model: CompositionModel): void {\n this.model = model;\n }\n\n private enqueueLoad(\n resource: Resource,\n priority: 'high' | 'normal' | 'low' = 'normal',\n sessionId?: string,\n trackId?: string,\n isMainTrack = false\n ): void {\n if (this.taskManager.hasActiveTask(resource.id)) {\n if (priority === 'high') {\n // Preview channel: high priority can preempt (existing logic preserved)\n } else if (isMainTrack) {\n // Main track resource conflict: throw error for PreRenderService to detect\n throw new ResourceConflictError(\n `Resource ${resource.id} is being loaded by another session. Preview channel has priority.`\n );\n } else {\n // Attachment resource conflict: check cache\n if (this.blobCache.has(resource.id)) {\n // Already cached: immediately create ImageBitmap and transfer\n void this.transferCachedImage(resource.id, sessionId);\n return;\n } else {\n // Loading in progress: register to pending queue, will transfer after load complete\n this.registerPendingTransfer(resource.id, sessionId);\n console.debug(\n `[ResourceLoader] Attachment resource ${resource.id} loading, registered for pending transfer`\n );\n return;\n }\n }\n }\n\n this.taskManager.enqueue(resource, priority, sessionId, trackId);\n this.processQueue();\n }\n\n private registerPendingTransfer(resourceId: string, sessionId?: string): void {\n if (!sessionId) return;\n\n const pending = this.pendingTransfers.get(resourceId) || [];\n if (!pending.includes(sessionId)) {\n pending.push(sessionId);\n this.pendingTransfers.set(resourceId, pending);\n }\n }\n\n private processQueue(): void {\n while (this.taskManager.canProcess) {\n const task = this.taskManager.getNextTask();\n if (!task) break;\n this.startLoad(task);\n }\n }\n\n /**\n * Start loading a resource\n * Handles state management (loading → ready/error) for all resource types\n */\n private async startLoad(task: LoadTask): Promise<void> {\n this.taskManager.activateTask(task);\n\n try {\n this.updateResourceState(task.resourceId, 'loading');\n task.controller = new AbortController();\n\n // Route to different handlers based on resource type\n // Note: Each handler only deals with data, state is managed here\n if (task.resource.type === 'image') {\n await this.loadImageBitmap(task);\n } else if (task.resource.type === 'video' || task.resource.type === 'audio') {\n const stream = await this.streamFactory.createRegularStream(task);\n if (!stream) {\n throw new Error(`Failed to create stream for ${task.resourceId}`);\n }\n task.stream = stream;\n await this.transferToDemuxWorker(task);\n } else if (task.resource.type === 'json' || task.resource.type === 'text') {\n await this.loadTextResource(task);\n }\n\n // Unified state update for all resource types\n this.updateResourceState(task.resourceId, 'ready');\n } catch (error) {\n task.error = error as Error;\n this.updateResourceState(task.resourceId, 'error');\n } finally {\n this.taskManager.completeTask(task.resourceId);\n this.processQueue();\n }\n }\n\n /**\n * Load text-based resources (json, text)\n * Just download the content - state management is handled by startLoad()\n */\n private async loadTextResource(task: LoadTask): Promise<void> {\n await this.fetchBlob(task.resource.uri, task.controller!.signal);\n // For json/text, just verify we can download it\n // Future: could parse and validate json here if needed\n }\n\n /**\n * Load image resource: fetch blob → create ImageBitmap → transfer to worker\n * Note: Images don't need streaming (typically < 5MB)\n */\n private async loadImageBitmap(task: LoadTask): Promise<void> {\n // Check cache\n let blob = this.blobCache.get(task.resourceId);\n\n if (!blob) {\n // Not cached: download and cache\n blob = await this.fetchBlob(task.resource.uri, task.controller!.signal);\n this.blobCache.set(task.resourceId, blob);\n }\n\n // Create ImageBitmap from Blob (with special handling for SVG)\n const imageBitmap = await createImageBitmapFromBlob(blob);\n\n await this.transferImageToWorker(task, imageBitmap);\n\n // Process pending transfer queue\n const pending = this.pendingTransfers.get(task.resourceId);\n if (pending && pending.length > 0) {\n for (const sessionId of pending) {\n await this.transferCachedImage(task.resourceId, sessionId);\n }\n this.pendingTransfers.delete(task.resourceId);\n }\n }\n\n /**\n * Fetch resource as blob (for images, json, etc.)\n */\n private async fetchBlob(uri: string, signal: AbortSignal): Promise<Blob> {\n const response = await fetch(uri, { signal });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n return response.blob();\n }\n\n /**\n * Transfer ImageBitmap to VideoComposeWorker\n */\n private async transferImageToWorker(task: LoadTask, imageBitmap: ImageBitmap): Promise<void> {\n if (!this.orchestrator) return;\n\n if (!task.sessionId) {\n throw new Error(\n `[ResourceLoader] sessionId required for resource ${task.resourceId}. ` +\n `In Clip-based architecture, use fetch(resourceId, { sessionId })`\n );\n }\n\n const composeWorker = await this.orchestrator.workers.get('videoCompose', task.sessionId, {\n lazy: true,\n });\n\n await composeWorker.send(\n 'receive_image',\n {\n resourceId: task.resourceId,\n sessionId: task.sessionId,\n imageBitmap,\n },\n { transfer: [imageBitmap] }\n );\n }\n\n /**\n * Transfer cached image to a session\n * Creates new ImageBitmap from cached Blob and transfers to worker\n */\n private async transferCachedImage(resourceId: string, sessionId?: string): Promise<void> {\n const blob = this.blobCache.get(resourceId);\n if (!blob || !sessionId) return;\n\n // Create new ImageBitmap from cached Blob (with SVG support)\n const imageBitmap = await createImageBitmapFromBlob(blob);\n\n // Transfer to Worker\n if (!this.orchestrator) return;\n\n const composeWorker = await this.orchestrator.workers.get('videoCompose', sessionId, {\n lazy: true,\n });\n\n await composeWorker.send(\n 'receive_image',\n {\n resourceId,\n sessionId,\n imageBitmap,\n },\n { transfer: [imageBitmap] }\n );\n }\n\n private async transferToDemuxWorker(task: LoadTask): Promise<void> {\n if (!task.stream || !this.orchestrator) return;\n\n if (!task.sessionId) {\n throw new Error(\n `[ResourceLoader] sessionId required for resource ${task.resourceId}. ` +\n `In Clip-based architecture, use fetch(resourceId, { sessionId })`\n );\n }\n\n const workerType = task.resource.type === 'video' ? 'videoDemux' : 'audioDemux';\n const demuxWorker = await this.orchestrator.workers.get(workerType, task.sessionId, {\n lazy: true,\n });\n\n await demuxWorker.sendStream(task.stream, {\n sessionId: task.sessionId,\n ...task.metadata,\n ...(task.range && { range: task.range }),\n ...(task.trackId && { trackId: task.trackId }),\n });\n }\n\n private updateResourceState(resourceId: string, state: Resource['state']): void {\n const resource = this.model?.resources.get(resourceId);\n if (resource) {\n const oldState = resource.state;\n resource.state = state;\n if (this.orchestrator) {\n this.eventBus?.emit(MeframeEvent.ResourceStageChange, {\n type: MeframeEvent.ResourceStageChange,\n resourceId,\n oldState,\n newState: state,\n });\n }\n }\n\n this.onStateChange?.(resourceId, state);\n }\n\n async fetch(resourceId?: string, options?: ResourceLoadOptions): Promise<void> {\n if (!resourceId) {\n return;\n }\n\n const resource = this.model?.resources.get(resourceId);\n if (!resource) {\n console.warn(`Resource ${resourceId} not found in model`);\n return;\n }\n\n this.enqueueLoad(\n resource,\n options?.priority || 'normal',\n options?.sessionId,\n options?.trackId,\n options?.isMainTrack ?? false\n );\n }\n\n cancel(resourceId: string): void {\n this.taskManager.cancelTask(resourceId);\n this.processQueue();\n }\n\n /**\n * Check if a resource is currently being loaded\n */\n isResourceLoading(resourceId: string): boolean {\n return this.taskManager.hasActiveTask(resourceId);\n }\n\n pause(resourceId: string): void {\n const task = this.taskManager.getActiveTask(resourceId);\n if (task) {\n task.controller?.abort();\n }\n }\n\n async resume(resourceId: string, options?: ResourceLoadOptions): Promise<void> {\n const resource = this.model?.getResource(resourceId);\n if (!resource) {\n throw new Error(`Resource ${resourceId} not found`);\n }\n\n const pausedTask = this.taskManager.getActiveTask(resourceId);\n\n if (pausedTask?.pausedAt !== undefined) {\n this.enqueueLoad(\n resource,\n options?.priority || 'normal',\n options?.sessionId,\n options?.trackId\n );\n } else {\n await this.fetch(resourceId, options);\n }\n }\n\n get activeTasks(): Map<string, LoadTask> {\n return this.taskManager.activeTasks;\n }\n\n get taskQueue(): LoadTask[] {\n return this.taskManager.taskQueue;\n }\n\n dispose(): void {\n this.taskManager.clear();\n this.byteRangeResolver.dispose();\n this.blobCache.clear();\n this.pendingTransfers.clear();\n this.unbind();\n }\n}\n"],"names":[],"mappings":";;;;;;AAUO,MAAM,8BAA8B,MAAM;AAAA,EAC/C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,eAAe;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gCAAgB,IAAA;AAAA,EAChB,uCAAuB,IAAA;AAAA,EAE/B,YAAY,SAAiC;AAC3C,UAAM,gBAAgB,SAAS,QAAQ,iBAAiB;AACxD,SAAK,cAAc,IAAI,YAAY,aAAa;AAChD,SAAK,gBAAgB,IAAI,cAAc,SAAS,YAAY,SAAS,MAAM;AAC3E,SAAK,WAAW,SAAS;AACzB,SAAK,gBAAgB,SAAS;AAC9B,SAAK,oBAAoB,IAAI,wBAAA;AAE7B,QAAI,SAAS,cAAc;AACzB,WAAK,KAAK,QAAQ,YAAY;AAAA,IAChC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,KAAK,cAAkC;AACrC,SAAK,OAAA;AACL,SAAK,eAAe;AAEpB,SAAK,gBAAgB,IAAI;AAAA,MACvB;AAAA,MACA,CAAC,eAAe,KAAK,OAAO,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