@meframe/core 0.0.38-beta.2 → 0.0.38
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/orchestrator/OnDemandVideoSession.d.ts +17 -1
- package/dist/orchestrator/OnDemandVideoSession.d.ts.map +1 -1
- package/dist/orchestrator/OnDemandVideoSession.js +93 -140
- package/dist/orchestrator/OnDemandVideoSession.js.map +1 -1
- package/dist/stages/decode/VideoChunkDecoder.d.ts.map +1 -1
- package/dist/utils/platform-utils.d.ts +46 -0
- package/dist/utils/platform-utils.d.ts.map +1 -0
- package/dist/utils/platform-utils.js +31 -0
- package/dist/utils/platform-utils.js.map +1 -0
- package/dist/utils/video-decoder-helpers.d.ts +31 -0
- package/dist/utils/video-decoder-helpers.d.ts.map +1 -0
- package/dist/utils/video-decoder-helpers.js +71 -0
- package/dist/utils/video-decoder-helpers.js.map +1 -0
- package/dist/workers/stages/decode/{video-decode.worker.BBhZwyRw.js → video-decode.worker.CwOjEmre.js} +32 -3
- package/dist/workers/stages/decode/video-decode.worker.CwOjEmre.js.map +1 -0
- package/dist/workers/worker-manifest.json +1 -1
- package/package.json +1 -1
- package/dist/stages/decode/VideoChunkDecoder.js +0 -160
- package/dist/stages/decode/VideoChunkDecoder.js.map +0 -1
- package/dist/workers/stages/decode/video-decode.worker.BBhZwyRw.js.map +0 -1
|
@@ -36,7 +36,7 @@ export declare class OnDemandVideoSession {
|
|
|
36
36
|
* Static method to decode and cache first frame from extracted GOP chunks
|
|
37
37
|
* Used by ResourceLoader during streaming download for fast cover rendering
|
|
38
38
|
*/
|
|
39
|
-
static decodeAndCacheFirstFrame(
|
|
39
|
+
static decodeAndCacheFirstFrame(_resourceId: string, chunks: EncodedVideoChunk[], index: MP4Index, clip: Clip, cacheManager: CacheManager, fps: number): Promise<void>;
|
|
40
40
|
private readonly clipId;
|
|
41
41
|
private readonly resourceId;
|
|
42
42
|
private readonly mp4IndexCache;
|
|
@@ -57,6 +57,18 @@ export declare class OnDemandVideoSession {
|
|
|
57
57
|
* Decode a window range, write raw frames to L1 cache
|
|
58
58
|
*/
|
|
59
59
|
decodeWindow(startUs: TimeUs, endUs: TimeUs): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Handle image resource by creating a VideoFrame from ImageBitmap
|
|
62
|
+
*/
|
|
63
|
+
private handleImageResource;
|
|
64
|
+
/**
|
|
65
|
+
* Handle video resource by decoding from OPFS
|
|
66
|
+
*/
|
|
67
|
+
private handleVideoResource;
|
|
68
|
+
/**
|
|
69
|
+
* Release all decoded frames without caching
|
|
70
|
+
*/
|
|
71
|
+
private releaseDecodedFrames;
|
|
60
72
|
private calculateGOPRangesForWindow;
|
|
61
73
|
/**
|
|
62
74
|
* Extract video chunks from GOP data
|
|
@@ -67,6 +79,10 @@ export declare class OnDemandVideoSession {
|
|
|
67
79
|
*/
|
|
68
80
|
private demuxGOPData;
|
|
69
81
|
private decodeChunks;
|
|
82
|
+
/**
|
|
83
|
+
* Cache a single frame to L1 with proper timestamp calculations
|
|
84
|
+
*/
|
|
85
|
+
private cacheFrame;
|
|
70
86
|
private cacheDecodedFrames;
|
|
71
87
|
/**
|
|
72
88
|
* Fast decode single keyframe for immediate seek preview
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnDemandVideoSession.d.ts","sourceRoot":"","sources":["../../src/orchestrator/OnDemandVideoSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAO,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"OnDemandVideoSession.d.ts","sourceRoot":"","sources":["../../src/orchestrator/OnDemandVideoSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM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S;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IAEtC,OAAO,CAAC,OAAO,CAA6B;IAC5C,UAAU,UAAS;IACnB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,aAAa,CAAoB;IAEzC,OAAO;WAYM,MAAM,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAMxE,IAAI;IAIlB;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBjE;;OAEG;YACW,mBAAmB;IAsBjC;;OAEG;YACW,mBAAmB;IAuCjC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,2BAA2B;IAgDnC;;;;;;OAMG;YACW,YAAY;YA0DZ,YAAY;IAgC1B;;OAEG;IACH,OAAO,CAAC,UAAU;YAcJ,kBAAkB;IA+BhC;;;OAGG;IACG,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAyC5D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAoB/B"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { VideoChunkDecoder } from "../stages/decode/VideoChunkDecoder.js";
|
|
2
1
|
import { binarySearchOverlapping } from "../utils/binary-search.js";
|
|
2
|
+
import { decodeChunksWithoutFlush } from "../utils/video-decoder-helpers.js";
|
|
3
3
|
class OnDemandVideoSession {
|
|
4
4
|
/**
|
|
5
5
|
* Static method to decode and cache first frame from extracted GOP chunks
|
|
6
6
|
* Used by ResourceLoader during streaming download for fast cover rendering
|
|
7
7
|
*/
|
|
8
|
-
static async decodeAndCacheFirstFrame(
|
|
8
|
+
static async decodeAndCacheFirstFrame(_resourceId, chunks, index, clip, cacheManager, fps) {
|
|
9
9
|
if (chunks.length === 0) return;
|
|
10
10
|
const videoTrack = index.tracks.video;
|
|
11
11
|
if (!videoTrack) return;
|
|
@@ -15,46 +15,22 @@ class OnDemandVideoSession {
|
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
try {
|
|
18
|
-
const
|
|
18
|
+
const result = await decodeChunksWithoutFlush(chunks, {
|
|
19
19
|
codec: videoTrack.codec,
|
|
20
20
|
width: videoTrack.width,
|
|
21
21
|
height: videoTrack.height,
|
|
22
|
-
description: videoTrack.description
|
|
23
|
-
hardwareAcceleration: "no-preference",
|
|
24
|
-
thread: "main"
|
|
22
|
+
description: videoTrack.description
|
|
25
23
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const reader = frameStream.getReader();
|
|
37
|
-
try {
|
|
38
|
-
const frameDuration = Math.round(1e6 / fps);
|
|
39
|
-
while (true) {
|
|
40
|
-
const { done, value } = await reader.read();
|
|
41
|
-
if (done) break;
|
|
42
|
-
if (value) {
|
|
43
|
-
const frameGlobalTime = clip.startUs + value.timestamp;
|
|
44
|
-
cacheManager.addFrame(
|
|
45
|
-
value,
|
|
46
|
-
clip.id,
|
|
47
|
-
frameDuration,
|
|
48
|
-
clip.trackId ?? "main",
|
|
49
|
-
frameGlobalTime
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
} finally {
|
|
54
|
-
reader.releaseLock();
|
|
55
|
-
}
|
|
56
|
-
} finally {
|
|
57
|
-
await decoder.close();
|
|
24
|
+
const frameDuration = Math.round(1e6 / fps);
|
|
25
|
+
for (const frame of result.frames) {
|
|
26
|
+
const frameGlobalTime = clip.startUs + frame.timestamp;
|
|
27
|
+
cacheManager.addFrame(
|
|
28
|
+
frame,
|
|
29
|
+
clip.id,
|
|
30
|
+
frameDuration,
|
|
31
|
+
clip.trackId ?? "main",
|
|
32
|
+
frameGlobalTime
|
|
33
|
+
);
|
|
58
34
|
}
|
|
59
35
|
} catch (error) {
|
|
60
36
|
console.warn("[OnDemandVideoSession] Failed to decode first GOP:", error);
|
|
@@ -99,23 +75,37 @@ class OnDemandVideoSession {
|
|
|
99
75
|
throw new Error("Session already disposed");
|
|
100
76
|
}
|
|
101
77
|
const resource = this.compositionModel.getResource(this.resourceId);
|
|
102
|
-
if (resource
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
duration: endUs - startUs
|
|
108
|
-
});
|
|
109
|
-
this.cacheManager.addFrame(
|
|
110
|
-
frame,
|
|
111
|
-
this.clipId,
|
|
112
|
-
endUs - startUs,
|
|
113
|
-
this.compositionModel.mainTrackId,
|
|
114
|
-
this.globalTimeUs
|
|
115
|
-
);
|
|
116
|
-
}
|
|
78
|
+
if (!resource) {
|
|
79
|
+
throw new Error(`Resource not found: ${this.resourceId}`);
|
|
80
|
+
}
|
|
81
|
+
if (resource.type === "image") {
|
|
82
|
+
await this.handleImageResource(resource, startUs, endUs);
|
|
117
83
|
return;
|
|
118
84
|
}
|
|
85
|
+
await this.handleVideoResource(startUs, endUs);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Handle image resource by creating a VideoFrame from ImageBitmap
|
|
89
|
+
*/
|
|
90
|
+
async handleImageResource(resource, startUs, endUs) {
|
|
91
|
+
const image = await this.resourceLoader.loadImage(resource);
|
|
92
|
+
if (!image) return;
|
|
93
|
+
const frame = new VideoFrame(image, {
|
|
94
|
+
timestamp: startUs,
|
|
95
|
+
duration: endUs - startUs
|
|
96
|
+
});
|
|
97
|
+
this.cacheManager.addFrame(
|
|
98
|
+
frame,
|
|
99
|
+
this.clipId,
|
|
100
|
+
endUs - startUs,
|
|
101
|
+
this.compositionModel.mainTrackId,
|
|
102
|
+
this.globalTimeUs
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Handle video resource by decoding from OPFS
|
|
107
|
+
*/
|
|
108
|
+
async handleVideoResource(startUs, endUs) {
|
|
119
109
|
const index = this.mp4IndexCache.get(this.resourceId);
|
|
120
110
|
if (!index) {
|
|
121
111
|
throw new Error(`No index found for resource ${this.resourceId}`);
|
|
@@ -135,14 +125,20 @@ class OnDemandVideoSession {
|
|
|
135
125
|
if (this.aborted) return;
|
|
136
126
|
await this.decodeChunks(chunks, index);
|
|
137
127
|
if (this.aborted) {
|
|
138
|
-
|
|
139
|
-
frame.close();
|
|
140
|
-
}
|
|
141
|
-
this.decodedFrames = [];
|
|
128
|
+
this.releaseDecodedFrames();
|
|
142
129
|
return;
|
|
143
130
|
}
|
|
144
131
|
await this.cacheDecodedFrames(startUs, endUs);
|
|
145
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Release all decoded frames without caching
|
|
135
|
+
*/
|
|
136
|
+
releaseDecodedFrames() {
|
|
137
|
+
for (const frame of this.decodedFrames) {
|
|
138
|
+
frame.close();
|
|
139
|
+
}
|
|
140
|
+
this.decodedFrames = [];
|
|
141
|
+
}
|
|
146
142
|
calculateGOPRangesForWindow(index, startUs, endUs) {
|
|
147
143
|
if (!index.tracks.video) {
|
|
148
144
|
console.warn("[OnDemandVideoSession] No video track in index");
|
|
@@ -232,81 +228,54 @@ class OnDemandVideoSession {
|
|
|
232
228
|
codec: videoTrack.codec,
|
|
233
229
|
dimensions: `${videoTrack.width}x${videoTrack.height}`
|
|
234
230
|
});
|
|
235
|
-
|
|
231
|
+
const result = await decodeChunksWithoutFlush(chunks, {
|
|
236
232
|
codec: videoTrack.codec,
|
|
237
233
|
width: videoTrack.width,
|
|
238
234
|
height: videoTrack.height,
|
|
239
|
-
description: videoTrack.description
|
|
240
|
-
hardwareAcceleration: "no-preference",
|
|
241
|
-
thread: "main"
|
|
235
|
+
description: videoTrack.description
|
|
242
236
|
});
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
controller.enqueue(chunk);
|
|
251
|
-
}
|
|
252
|
-
controller.close();
|
|
253
|
-
}
|
|
237
|
+
this.decodedFrames = result.frames;
|
|
238
|
+
console.log("[OnDemandVideoSession] decodeChunks complete:", {
|
|
239
|
+
clipId: this.clipId,
|
|
240
|
+
inputChunks: result.stats.inputChunks,
|
|
241
|
+
outputFrames: result.stats.outputFrames,
|
|
242
|
+
durationMs: result.stats.durationMs
|
|
254
243
|
});
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
outputFrames: this.decodedFrames.length,
|
|
270
|
-
aborted: this.aborted
|
|
271
|
-
});
|
|
272
|
-
} catch (error) {
|
|
273
|
-
console.error("[OnDemandVideoSession] decodeChunks error:", {
|
|
274
|
-
clipId: this.clipId,
|
|
275
|
-
error: error instanceof Error ? error.message : String(error),
|
|
276
|
-
aborted: this.aborted,
|
|
277
|
-
decodedSoFar: this.decodedFrames.length
|
|
278
|
-
});
|
|
279
|
-
if (this.aborted) return;
|
|
280
|
-
throw error;
|
|
281
|
-
} finally {
|
|
282
|
-
reader.releaseLock();
|
|
283
|
-
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Cache a single frame to L1 with proper timestamp calculations
|
|
247
|
+
*/
|
|
248
|
+
cacheFrame(frame, globalTimeOffset = 0) {
|
|
249
|
+
const frameDuration = frame.duration ?? Math.round(1e6 / this.fps);
|
|
250
|
+
const frameGlobalTime = this.globalTimeUs + (frame.timestamp - this.targetTimeUs) + globalTimeOffset;
|
|
251
|
+
this.cacheManager.addFrame(
|
|
252
|
+
frame,
|
|
253
|
+
this.clipId,
|
|
254
|
+
frameDuration,
|
|
255
|
+
this.compositionModel.mainTrackId,
|
|
256
|
+
frameGlobalTime
|
|
257
|
+
);
|
|
284
258
|
}
|
|
285
259
|
async cacheDecodedFrames(startUs, endUs) {
|
|
286
|
-
const framesToCache =
|
|
287
|
-
|
|
288
|
-
|
|
260
|
+
const framesToCache = [];
|
|
261
|
+
const framesToDiscard = [];
|
|
262
|
+
for (const frame of this.decodedFrames) {
|
|
263
|
+
if (frame.timestamp >= startUs && frame.timestamp < endUs) {
|
|
264
|
+
framesToCache.push(frame);
|
|
265
|
+
} else {
|
|
266
|
+
framesToDiscard.push(frame);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
289
269
|
for (const frame of framesToCache) {
|
|
290
270
|
try {
|
|
291
|
-
|
|
292
|
-
const originalDuration = frame.duration ?? Math.round(1e6 / this.fps);
|
|
293
|
-
const frameGlobalTime = this.globalTimeUs + (originalTimestamp - this.targetTimeUs);
|
|
294
|
-
this.cacheManager.addFrame(
|
|
295
|
-
frame,
|
|
296
|
-
this.clipId,
|
|
297
|
-
originalDuration,
|
|
298
|
-
this.compositionModel.mainTrackId,
|
|
299
|
-
frameGlobalTime
|
|
300
|
-
);
|
|
271
|
+
this.cacheFrame(frame);
|
|
301
272
|
} catch (error) {
|
|
302
273
|
console.error("[OnDemandVideoSession] Cache error:", error);
|
|
303
274
|
frame.close();
|
|
304
275
|
}
|
|
305
276
|
}
|
|
306
|
-
for (const frame of
|
|
307
|
-
|
|
308
|
-
frame.close();
|
|
309
|
-
}
|
|
277
|
+
for (const frame of framesToDiscard) {
|
|
278
|
+
frame.close();
|
|
310
279
|
}
|
|
311
280
|
this.decodedFrames = [];
|
|
312
281
|
}
|
|
@@ -332,20 +301,11 @@ class OnDemandVideoSession {
|
|
|
332
301
|
duration: keyframeSample.duration,
|
|
333
302
|
data: keyframeData
|
|
334
303
|
});
|
|
335
|
-
if (this.aborted) return null;
|
|
336
304
|
await this.decodeChunks([chunk], index);
|
|
337
305
|
if (this.aborted || this.decodedFrames.length === 0) return null;
|
|
338
306
|
const frame = this.decodedFrames[0];
|
|
339
307
|
if (!frame) return null;
|
|
340
|
-
|
|
341
|
-
const frameGlobalTime = this.globalTimeUs + (frame.timestamp - this.targetTimeUs);
|
|
342
|
-
this.cacheManager.addFrame(
|
|
343
|
-
frame,
|
|
344
|
-
this.clipId,
|
|
345
|
-
frameDuration,
|
|
346
|
-
this.compositionModel.mainTrackId,
|
|
347
|
-
frameGlobalTime
|
|
348
|
-
);
|
|
308
|
+
this.cacheFrame(frame);
|
|
349
309
|
this.decodedFrames = [];
|
|
350
310
|
return keyframeSample.timestamp;
|
|
351
311
|
}
|
|
@@ -353,21 +313,14 @@ class OnDemandVideoSession {
|
|
|
353
313
|
if (this.isDisposed) return;
|
|
354
314
|
this.aborted = true;
|
|
355
315
|
if (this.decoder) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (this.decoder.state !== "closed") {
|
|
363
|
-
await this.decoder.close();
|
|
316
|
+
try {
|
|
317
|
+
this.decoder.close();
|
|
318
|
+
} catch (error) {
|
|
319
|
+
console.warn("[OnDemandVideoSession] Decoder close error:", error);
|
|
364
320
|
}
|
|
365
321
|
this.decoder = null;
|
|
366
322
|
}
|
|
367
|
-
|
|
368
|
-
frame.close();
|
|
369
|
-
}
|
|
370
|
-
this.decodedFrames = [];
|
|
323
|
+
this.releaseDecodedFrames();
|
|
371
324
|
this.isDisposed = true;
|
|
372
325
|
}
|
|
373
326
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnDemandVideoSession.js","sources":["../../src/orchestrator/OnDemandVideoSession.ts"],"sourcesContent":["import type { CacheManager } from '../cache/CacheManager';\nimport type { MP4IndexCache } from '../cache/resource/MP4IndexCache';\nimport type { MP4Index, GOP } from '../stages/demux/types';\nimport type { TimeUs } from '../model/types';\nimport type { CompositionModel, Clip } from '../model';\nimport { VideoChunkDecoder } from '../stages/decode/VideoChunkDecoder';\nimport { binarySearchOverlapping } from '../utils/binary-search';\nimport type { ResourceLoader } from '../stages/load/ResourceLoader';\n\ninterface GOPWindowResult {\n gops: GOP[];\n byteStart: number;\n byteEnd: number;\n}\n\ninterface OnDemandVideoSessionConfig {\n clipId: string;\n resourceId: string;\n targetTimeUs: TimeUs;\n globalTimeUs: TimeUs;\n mp4IndexCache: MP4IndexCache;\n cacheManager: CacheManager;\n compositionModel: CompositionModel;\n resourceLoader: ResourceLoader;\n fps: number;\n}\n\n/**\n * OnDemandVideoSession - Main-thread on-demand decoder\n *\n * Strategy:\n * 1. Read GOP range from OPFS\n * 2. Demux using MP4Box (main thread)\n * 3. Decode using VideoDecoder (main thread)\n * 4. Write RAW VideoFrames (YUV) to L1 cache\n * 5. Dispose immediately after window completes\n *\n * Why main thread?\n * - Window is small (±2s, ~60-120 frames)\n * - Worker overhead (10-50ms) is significant for small workloads\n * - Decode is fast enough\n */\nexport class OnDemandVideoSession {\n /**\n * Static method to decode and cache first frame from extracted GOP chunks\n * Used by ResourceLoader during streaming download for fast cover rendering\n */\n static async decodeAndCacheFirstFrame(\n resourceId: string,\n chunks: EncodedVideoChunk[],\n index: MP4Index,\n clip: Clip,\n cacheManager: CacheManager,\n fps: number\n ): Promise<void> {\n if (chunks.length === 0) return;\n\n const videoTrack = index.tracks.video;\n if (!videoTrack) return;\n\n // Verify first chunk is keyframe\n const firstChunk = chunks[0];\n if (!firstChunk || firstChunk.type !== 'key') {\n console.warn('[OnDemandVideoSession] First chunk is not a keyframe, skipping');\n return;\n }\n\n try {\n // Create temporary decoder\n const decoder = new VideoChunkDecoder(`first-frame-${resourceId}`, {\n codec: videoTrack.codec,\n width: videoTrack.width,\n height: videoTrack.height,\n description: videoTrack.description,\n hardwareAcceleration: 'no-preference' as HardwareAcceleration,\n thread: 'main',\n });\n\n try {\n // Create chunk stream with ALL chunks from first GOP\n const chunkStream = new ReadableStream<EncodedVideoChunk>({\n start(controller) {\n for (const chunk of chunks) {\n controller.enqueue(chunk);\n }\n controller.close();\n },\n });\n\n // Decode all frames\n const frameStream = chunkStream.pipeThrough(decoder.createStream());\n const reader = frameStream.getReader();\n\n try {\n const frameDuration = Math.round(1_000_000 / fps);\n\n // Read and cache all decoded frames\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n if (value) {\n // Calculate global time for this frame\n const frameGlobalTime = clip.startUs + value.timestamp;\n\n cacheManager.addFrame(\n value,\n clip.id,\n frameDuration,\n clip.trackId ?? 'main',\n frameGlobalTime\n );\n }\n }\n } finally {\n reader.releaseLock();\n }\n } finally {\n await decoder.close();\n }\n } catch (error) {\n console.warn('[OnDemandVideoSession] Failed to decode first GOP:', error);\n // Don't throw - this is a best-effort optimization\n }\n }\n private readonly clipId: string;\n private readonly resourceId: string;\n private readonly mp4IndexCache: MP4IndexCache;\n private readonly cacheManager: CacheManager;\n private readonly compositionModel: CompositionModel;\n private readonly resourceLoader: ResourceLoader;\n private readonly fps: number;\n private readonly globalTimeUs: TimeUs;\n private readonly targetTimeUs: TimeUs;\n\n private decoder: VideoChunkDecoder | null = null;\n isDisposed = false;\n private aborted = false;\n private decodedFrames: VideoFrame[] = [];\n\n private constructor(config: OnDemandVideoSessionConfig) {\n this.clipId = config.clipId;\n this.resourceId = config.resourceId;\n this.mp4IndexCache = config.mp4IndexCache;\n this.cacheManager = config.cacheManager;\n this.resourceLoader = config.resourceLoader;\n this.compositionModel = config.compositionModel;\n this.fps = config.fps;\n this.globalTimeUs = config.globalTimeUs;\n this.targetTimeUs = config.targetTimeUs;\n }\n\n static async create(config: OnDemandVideoSessionConfig): Promise<OnDemandVideoSession> {\n const session = new OnDemandVideoSession(config);\n await session.init();\n return session;\n }\n\n private async init(): Promise<void> {\n // No special initialization needed for now\n }\n\n /**\n * Decode a window range, write raw frames to L1 cache\n */\n async decodeWindow(startUs: TimeUs, endUs: TimeUs): Promise<void> {\n if (this.isDisposed) {\n throw new Error('Session already disposed');\n }\n\n // Check if resource is an image (no MP4 index)\n const resource = this.compositionModel.getResource(this.resourceId);\n if (resource?.type === 'image') {\n // Image clip: handled by direct ImageBitmap access in PlaybackController\n // No need to decode anything here\n const image = await this.resourceLoader.loadImage(resource);\n if (image) {\n const frame = new VideoFrame(image, {\n timestamp: startUs,\n duration: endUs - startUs,\n });\n this.cacheManager.addFrame(\n frame,\n this.clipId,\n endUs - startUs,\n this.compositionModel.mainTrackId,\n this.globalTimeUs\n );\n }\n return;\n }\n\n // Video clip: decode from OPFS\n // Get MP4 index\n const index = this.mp4IndexCache.get(this.resourceId);\n if (!index) {\n throw new Error(`No index found for resource ${this.resourceId}`);\n }\n\n // Calculate GOP ranges needed (with binary search optimization)\n const gopWindow = this.calculateGOPRangesForWindow(index, startUs, endUs);\n if (gopWindow.gops.length === 0) {\n console.warn('[OnDemandVideoSession] No GOP ranges for window', startUs, endUs);\n return;\n }\n\n // Read GOP data from OPFS (merged byte range)\n const gopData = await this.cacheManager.readResourceRange(\n this.resourceId,\n gopWindow.byteStart,\n gopWindow.byteEnd\n );\n\n if (this.aborted) return;\n\n // Extract chunks from GOP data (direct sample index slicing)\n const chunks = await this.demuxGOPData(gopData, index, gopWindow);\n\n if (this.aborted) return;\n\n // Decode chunks to frames\n await this.decodeChunks(chunks, index);\n\n if (this.aborted) {\n for (const frame of this.decodedFrames) {\n frame.close();\n }\n this.decodedFrames = [];\n return;\n }\n\n // Write frames to L1\n await this.cacheDecodedFrames(startUs, endUs);\n }\n\n private calculateGOPRangesForWindow(\n index: MP4Index,\n startUs: TimeUs,\n endUs: TimeUs\n ): GOPWindowResult {\n if (!index.tracks.video) {\n console.warn('[OnDemandVideoSession] No video track in index');\n return { gops: [], byteStart: 0, byteEnd: 0 };\n }\n\n const { gopIndex, samples } = index.tracks.video;\n\n // Find GOP containing startUs (or the nearest keyframe before it)\n const nearestKeyframe = this.mp4IndexCache.getNearestKeyframe(this.resourceId, startUs);\n const decodeStartUs = nearestKeyframe?.timestamp ?? startUs;\n\n // Use binary search to find all overlapping GOPs\n const overlappingGOPs = binarySearchOverlapping(gopIndex, decodeStartUs, endUs, (gop, idx) => {\n const nextGOP = gopIndex[idx + 1];\n return {\n start: gop.startTimeUs,\n end: nextGOP ? nextGOP.startTimeUs : Infinity,\n };\n });\n\n if (overlappingGOPs.length === 0) {\n console.warn('[OnDemandVideoSession] No GOP ranges for window', startUs, endUs);\n return { gops: [], byteStart: 0, byteEnd: 0 };\n }\n\n // Calculate merged byte range for OPFS read\n let byteStart = Infinity;\n let byteEnd = 0;\n\n for (const gop of overlappingGOPs) {\n const startSample = samples[gop.keyframeSampleIndex];\n const endSampleIndex = gop.keyframeSampleIndex + gop.sampleCount - 1;\n const endSample = samples[endSampleIndex];\n\n if (startSample && endSample) {\n byteStart = Math.min(byteStart, startSample.byteOffset);\n byteEnd = Math.max(byteEnd, endSample.byteOffset + endSample.byteLength);\n }\n }\n\n return { gops: overlappingGOPs, byteStart, byteEnd };\n }\n\n /**\n * Extract video chunks from GOP data\n *\n * Directly use GOP sample indices to slice the samples array.\n * This is O(k) where k is the number of samples in the window,\n * vs O(n×m) for the old approach (n=all samples, m=GOP count).\n */\n private async demuxGOPData(\n data: ArrayBuffer,\n index: MP4Index,\n gopWindow: GOPWindowResult\n ): Promise<EncodedVideoChunk[]> {\n const videoTrack = index.tracks.video;\n if (!videoTrack) {\n throw new Error('No video track in index');\n }\n\n const { samples } = videoTrack;\n const chunks: EncodedVideoChunk[] = [];\n const dataView = new Uint8Array(data);\n const baseByteOffset = gopWindow.byteStart;\n\n // Direct sample index slicing - iterate only samples in the window\n for (const gop of gopWindow.gops) {\n const startIdx = gop.keyframeSampleIndex;\n const endIdx = startIdx + gop.sampleCount;\n\n // Extract samples for this GOP (direct array slice)\n for (let i = startIdx; i < endIdx; i++) {\n const sample = samples[i];\n if (!sample) continue;\n\n // Calculate relative offset within the data buffer\n const relativeOffset = sample.byteOffset - baseByteOffset;\n\n // Validate offset is within buffer\n if (relativeOffset < 0 || relativeOffset + sample.byteLength > data.byteLength) {\n console.warn('[OnDemandVideoSession] Sample outside buffer:', {\n sampleOffset: sample.byteOffset,\n sampleLength: sample.byteLength,\n baseOffset: baseByteOffset,\n relativeOffset,\n bufferLength: data.byteLength,\n });\n continue;\n }\n\n // Extract sample data\n const sampleData = dataView.slice(relativeOffset, relativeOffset + sample.byteLength);\n\n // Create EncodedVideoChunk\n const chunk = new EncodedVideoChunk({\n type: sample.isKeyframe ? 'key' : 'delta',\n timestamp: sample.timestamp,\n duration: sample.duration,\n data: sampleData,\n });\n\n chunks.push(chunk);\n }\n }\n\n return chunks;\n }\n\n private async decodeChunks(chunks: EncodedVideoChunk[], index: MP4Index): Promise<void> {\n const videoTrack = index.tracks.video;\n if (!videoTrack) {\n throw new Error('No video track in index');\n }\n\n console.log('[OnDemandVideoSession] decodeChunks start:', {\n clipId: this.clipId,\n chunkCount: chunks.length,\n firstChunkType: chunks[0]?.type,\n codec: videoTrack.codec,\n dimensions: `${videoTrack.width}x${videoTrack.height}`,\n });\n\n // Create decoder (reuse VideoChunkDecoder like decodeFromL2)\n this.decoder = new VideoChunkDecoder(`ondemand-${this.clipId}`, {\n codec: videoTrack.codec,\n width: videoTrack.width,\n height: videoTrack.height,\n description: videoTrack.description,\n hardwareAcceleration: 'no-preference' as HardwareAcceleration,\n thread: 'main',\n });\n\n // Create stream from chunks\n const chunkStream = new ReadableStream<EncodedVideoChunk>({\n start: (controller) => {\n for (const chunk of chunks) {\n if (this.aborted) {\n controller.close();\n return;\n }\n controller.enqueue(chunk);\n }\n controller.close();\n },\n });\n\n // Pipe through decoder\n const frameStream = chunkStream.pipeThrough(this.decoder.createStream());\n\n // Collect decoded frames\n const reader = frameStream.getReader();\n try {\n while (true) {\n if (this.aborted) break;\n\n const { done, value } = await reader.read();\n if (done) break;\n if (value) {\n this.decodedFrames.push(value);\n }\n }\n\n console.log('[OnDemandVideoSession] decodeChunks complete:', {\n clipId: this.clipId,\n inputChunks: chunks.length,\n outputFrames: this.decodedFrames.length,\n aborted: this.aborted,\n });\n } catch (error) {\n console.error('[OnDemandVideoSession] decodeChunks error:', {\n clipId: this.clipId,\n error: error instanceof Error ? error.message : String(error),\n aborted: this.aborted,\n decodedSoFar: this.decodedFrames.length,\n });\n if (this.aborted) return;\n throw error;\n } finally {\n reader.releaseLock();\n }\n }\n\n private async cacheDecodedFrames(startUs: TimeUs, endUs: TimeUs): Promise<void> {\n // Filter frames within window (include boundary frames)\n // Use original timestamp (no quantization)\n const framesToCache = this.decodedFrames.filter((f) => {\n // Exclude frames at window end boundary\n return f.timestamp >= startUs && f.timestamp < endUs;\n });\n\n for (const frame of framesToCache) {\n try {\n // Use original timestamp and duration (preserve source frame rate)\n const originalTimestamp = frame.timestamp;\n const originalDuration = frame.duration ?? Math.round(1_000_000 / this.fps);\n\n // Calculate global timestamp using original value\n const frameGlobalTime = this.globalTimeUs + (originalTimestamp - this.targetTimeUs);\n\n // Write RAW video frame to L1 with original timestamp, duration and global time\n // NOTE: addComposedFrame name is legacy, but now we store raw frames\n this.cacheManager.addFrame(\n frame,\n this.clipId,\n originalDuration,\n this.compositionModel.mainTrackId,\n frameGlobalTime\n );\n\n // Don't close frame here - it's now owned by L1 cache\n // (CacheManager.addComposedFrame clones it or takes ownership)\n } catch (error) {\n console.error('[OnDemandVideoSession] Cache error:', error);\n frame.close();\n }\n }\n\n // Clean up decoded frames that weren't cached\n for (const frame of this.decodedFrames) {\n if (!framesToCache.includes(frame)) {\n frame.close();\n }\n }\n this.decodedFrames = [];\n }\n\n /**\n * Fast decode single keyframe for immediate seek preview\n * Returns the decoded keyframe timestamp\n */\n async decodeKeyframe(targetTimeUs: TimeUs): Promise<TimeUs | null> {\n if (this.isDisposed || this.aborted) return null;\n\n const index = this.mp4IndexCache.get(this.resourceId);\n if (!index || !index.tracks.video) return null;\n\n // Find nearest keyframe\n const keyframeSample = this.mp4IndexCache.getNearestKeyframe(this.resourceId, targetTimeUs);\n if (!keyframeSample) return null;\n\n // Read only the keyframe bytes from OPFS\n const keyframeData = await this.cacheManager.readResourceRange(\n this.resourceId,\n keyframeSample.byteOffset,\n keyframeSample.byteOffset + keyframeSample.byteLength\n );\n\n if (this.aborted) return null;\n\n // Extract keyframe chunk\n const chunk = new EncodedVideoChunk({\n type: 'key',\n timestamp: keyframeSample.timestamp,\n duration: keyframeSample.duration,\n data: keyframeData,\n });\n\n if (this.aborted) return null;\n\n // Decode single keyframe\n await this.decodeChunks([chunk], index);\n\n if (this.aborted || this.decodedFrames.length === 0) return null;\n\n // Cache the keyframe\n const frame = this.decodedFrames[0];\n if (!frame) return null;\n\n const frameDuration = frame.duration ?? Math.round(1_000_000 / this.fps);\n const frameGlobalTime = this.globalTimeUs + (frame.timestamp - this.targetTimeUs);\n\n this.cacheManager.addFrame(\n frame,\n this.clipId,\n frameDuration,\n this.compositionModel.mainTrackId,\n frameGlobalTime\n );\n\n this.decodedFrames = [];\n\n return keyframeSample.timestamp;\n }\n\n async dispose(): Promise<void> {\n if (this.isDisposed) return;\n\n this.aborted = true;\n\n if (this.decoder) {\n // Properly cleanup decoder: flush pending frames before close\n // Windows Media Foundation requires this to avoid decoder errors\n if (this.decoder.state === 'configured') {\n try {\n await this.decoder.flush();\n } catch {\n // Ignore flush errors during dispose\n }\n }\n\n if (this.decoder.state !== 'closed') {\n await this.decoder.close();\n }\n this.decoder = null;\n }\n\n for (const frame of this.decodedFrames) {\n frame.close();\n }\n this.decodedFrames = [];\n\n this.isDisposed = true;\n }\n}\n"],"names":[],"mappings":";;AA0CO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKhC,aAAa,yBACX,YACA,QACA,OACA,MACA,cACA,KACe;AACf,QAAI,OAAO,WAAW,EAAG;AAEzB,UAAM,aAAa,MAAM,OAAO;AAChC,QAAI,CAAC,WAAY;AAGjB,UAAM,aAAa,OAAO,CAAC;AAC3B,QAAI,CAAC,cAAc,WAAW,SAAS,OAAO;AAC5C,cAAQ,KAAK,gEAAgE;AAC7E;AAAA,IACF;AAEA,QAAI;AAEF,YAAM,UAAU,IAAI,kBAAkB,eAAe,UAAU,IAAI;AAAA,QACjE,OAAO,WAAW;AAAA,QAClB,OAAO,WAAW;AAAA,QAClB,QAAQ,WAAW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zB,UAAM,QAAQ,IAAI,kBAAkB;AAAA,MAClC,MAAM;AAAA,MACN,WAAW,eAAe;AAAA,MAC1B,UAAU,eAAe;AAAA,MACzB,MAAM;AAAA,IAAA,CACP;AAED,QAAI,KAAK,QAAS,QAAO;AAGzB,UAAM,KAAK,aAAa,CAAC,KAAK,GAAG,KAAK;AAEtC,QAAI,KAAK,WAAW,KAAK,cAAc,WAAW,EAAG,QAAO;AAG5D,UAAM,QAAQ,KAAK,cAAc,CAAC;AAClC,QAAI,CAAC,MAAO,QAAO;AAEnB,UAAM,gBAAgB,MAAM,YAAY,KAAK,MAAM,MAAY,KAAK,GAAG;AACvE,UAAM,kBAAkB,KAAK,gBAAgB,MAAM,YAAY,KAAK;AAEpE,SAAK,aAAa;AAAA,MAChB;AAAA,MACA,KAAK;AAAA,MACL;AAAA,MACA,KAAK,iBAAiB;AAAA,MACtB;AAAA,IAAA;AAGF,SAAK,gBAAgB,CAAA;AAErB,WAAO,eAAe;AAAA,EACxB;AAAA,EAEA,MAAM,UAAyB;AAC7B,QAAI,KAAK,WAAY;AAErB,SAAK,UAAU;AAEf,QAAI,KAAK,SAAS;AAGhB,UAAI,KAAK,QAAQ,UAAU,cAAc;AACvC,YAAI;AACF,gBAAM,KAAK,QAAQ,MAAA;AAAA,QACrB,QAAQ;AAAA,QAER;AAAA,MACF;AAEA,UAAI,KAAK,QAAQ,UAAU,UAAU;AACnC,cAAM,KAAK,QAAQ,MAAA;AAAA,MACrB;AACA,WAAK,UAAU;AAAA,IACjB;AAEA,eAAW,SAAS,KAAK,eAAe;AACtC,YAAM,MAAA;AAAA,IACR;AACA,SAAK,gBAAgB,CAAA;AAErB,SAAK,aAAa;AAAA,EACpB;AACF;"}
|
|
1
|
+
{"version":3,"file":"OnDemandVideoSession.js","sources":["../../src/orchestrator/OnDemandVideoSession.ts"],"sourcesContent":["import type { CacheManager } from '../cache/CacheManager';\nimport type { MP4IndexCache } from '../cache/resource/MP4IndexCache';\nimport type { MP4Index, GOP } from '../stages/demux/types';\nimport type { TimeUs, Resource } from '../model/types';\nimport type { CompositionModel, Clip } from '../model';\nimport { binarySearchOverlapping } from '../utils/binary-search';\nimport type { ResourceLoader } from '../stages/load/ResourceLoader';\nimport { decodeChunksWithoutFlush } from '../utils/video-decoder-helpers';\n\ninterface GOPWindowResult {\n gops: GOP[];\n byteStart: number;\n byteEnd: number;\n}\n\ninterface OnDemandVideoSessionConfig {\n clipId: string;\n resourceId: string;\n targetTimeUs: TimeUs;\n globalTimeUs: TimeUs;\n mp4IndexCache: MP4IndexCache;\n cacheManager: CacheManager;\n compositionModel: CompositionModel;\n resourceLoader: ResourceLoader;\n fps: number;\n}\n\n/**\n * OnDemandVideoSession - Main-thread on-demand decoder\n *\n * Strategy:\n * 1. Read GOP range from OPFS\n * 2. Demux using MP4Box (main thread)\n * 3. Decode using VideoDecoder (main thread)\n * 4. Write RAW VideoFrames (YUV) to L1 cache\n * 5. Dispose immediately after window completes\n *\n * Why main thread?\n * - Window is small (±2s, ~60-120 frames)\n * - Worker overhead (10-50ms) is significant for small workloads\n * - Decode is fast enough\n */\nexport class OnDemandVideoSession {\n /**\n * Static method to decode and cache first frame from extracted GOP chunks\n * Used by ResourceLoader during streaming download for fast cover rendering\n */\n static async decodeAndCacheFirstFrame(\n _resourceId: string,\n chunks: EncodedVideoChunk[],\n index: MP4Index,\n clip: Clip,\n cacheManager: CacheManager,\n fps: number\n ): Promise<void> {\n if (chunks.length === 0) return;\n\n const videoTrack = index.tracks.video;\n if (!videoTrack) return;\n\n // Verify first chunk is keyframe\n const firstChunk = chunks[0];\n if (!firstChunk || firstChunk.type !== 'key') {\n console.warn('[OnDemandVideoSession] First chunk is not a keyframe, skipping');\n return;\n }\n\n try {\n const result = await decodeChunksWithoutFlush(chunks, {\n codec: videoTrack.codec,\n width: videoTrack.width,\n height: videoTrack.height,\n description: videoTrack.description,\n });\n\n // Cache all decoded frames\n const frameDuration = Math.round(1_000_000 / fps);\n for (const frame of result.frames) {\n const frameGlobalTime = clip.startUs + frame.timestamp;\n cacheManager.addFrame(\n frame,\n clip.id,\n frameDuration,\n clip.trackId ?? 'main',\n frameGlobalTime\n );\n }\n } catch (error) {\n console.warn('[OnDemandVideoSession] Failed to decode first GOP:', error);\n // Don't throw - this is a best-effort optimization\n }\n }\n private readonly clipId: string;\n private readonly resourceId: string;\n private readonly mp4IndexCache: MP4IndexCache;\n private readonly cacheManager: CacheManager;\n private readonly compositionModel: CompositionModel;\n private readonly resourceLoader: ResourceLoader;\n private readonly fps: number;\n private readonly globalTimeUs: TimeUs;\n private readonly targetTimeUs: TimeUs;\n\n private decoder: VideoDecoder | null = null;\n isDisposed = false;\n private aborted = false;\n private decodedFrames: VideoFrame[] = [];\n\n private constructor(config: OnDemandVideoSessionConfig) {\n this.clipId = config.clipId;\n this.resourceId = config.resourceId;\n this.mp4IndexCache = config.mp4IndexCache;\n this.cacheManager = config.cacheManager;\n this.resourceLoader = config.resourceLoader;\n this.compositionModel = config.compositionModel;\n this.fps = config.fps;\n this.globalTimeUs = config.globalTimeUs;\n this.targetTimeUs = config.targetTimeUs;\n }\n\n static async create(config: OnDemandVideoSessionConfig): Promise<OnDemandVideoSession> {\n const session = new OnDemandVideoSession(config);\n await session.init();\n return session;\n }\n\n private async init(): Promise<void> {\n // No special initialization needed for now\n }\n\n /**\n * Decode a window range, write raw frames to L1 cache\n */\n async decodeWindow(startUs: TimeUs, endUs: TimeUs): Promise<void> {\n if (this.isDisposed) {\n throw new Error('Session already disposed');\n }\n\n const resource = this.compositionModel.getResource(this.resourceId);\n if (!resource) {\n throw new Error(`Resource not found: ${this.resourceId}`);\n }\n\n if (resource.type === 'image') {\n await this.handleImageResource(resource, startUs, endUs);\n return;\n }\n\n await this.handleVideoResource(startUs, endUs);\n }\n\n /**\n * Handle image resource by creating a VideoFrame from ImageBitmap\n */\n private async handleImageResource(\n resource: Resource,\n startUs: TimeUs,\n endUs: TimeUs\n ): Promise<void> {\n const image = await this.resourceLoader.loadImage(resource);\n if (!image) return;\n\n const frame = new VideoFrame(image, {\n timestamp: startUs,\n duration: endUs - startUs,\n });\n\n this.cacheManager.addFrame(\n frame,\n this.clipId,\n endUs - startUs,\n this.compositionModel.mainTrackId,\n this.globalTimeUs\n );\n }\n\n /**\n * Handle video resource by decoding from OPFS\n */\n private async handleVideoResource(startUs: TimeUs, endUs: TimeUs): Promise<void> {\n const index = this.mp4IndexCache.get(this.resourceId);\n if (!index) {\n throw new Error(`No index found for resource ${this.resourceId}`);\n }\n\n // Calculate GOP ranges needed\n const gopWindow = this.calculateGOPRangesForWindow(index, startUs, endUs);\n if (gopWindow.gops.length === 0) {\n console.warn('[OnDemandVideoSession] No GOP ranges for window', startUs, endUs);\n return;\n }\n\n // Read GOP data from OPFS\n const gopData = await this.cacheManager.readResourceRange(\n this.resourceId,\n gopWindow.byteStart,\n gopWindow.byteEnd\n );\n\n if (this.aborted) return;\n\n // Extract chunks from GOP data\n const chunks = await this.demuxGOPData(gopData, index, gopWindow);\n if (this.aborted) return;\n\n // Decode chunks to frames\n await this.decodeChunks(chunks, index);\n\n // Check abort and cleanup if needed\n if (this.aborted) {\n this.releaseDecodedFrames();\n return;\n }\n\n // Write frames to L1 cache\n await this.cacheDecodedFrames(startUs, endUs);\n }\n\n /**\n * Release all decoded frames without caching\n */\n private releaseDecodedFrames(): void {\n for (const frame of this.decodedFrames) {\n frame.close();\n }\n this.decodedFrames = [];\n }\n\n private calculateGOPRangesForWindow(\n index: MP4Index,\n startUs: TimeUs,\n endUs: TimeUs\n ): GOPWindowResult {\n if (!index.tracks.video) {\n console.warn('[OnDemandVideoSession] No video track in index');\n return { gops: [], byteStart: 0, byteEnd: 0 };\n }\n\n const { gopIndex, samples } = index.tracks.video;\n\n // Find GOP containing startUs (or the nearest keyframe before it)\n const nearestKeyframe = this.mp4IndexCache.getNearestKeyframe(this.resourceId, startUs);\n const decodeStartUs = nearestKeyframe?.timestamp ?? startUs;\n\n // Use binary search to find all overlapping GOPs\n const overlappingGOPs = binarySearchOverlapping(gopIndex, decodeStartUs, endUs, (gop, idx) => {\n const nextGOP = gopIndex[idx + 1];\n return {\n start: gop.startTimeUs,\n end: nextGOP ? nextGOP.startTimeUs : Infinity,\n };\n });\n\n if (overlappingGOPs.length === 0) {\n console.warn('[OnDemandVideoSession] No GOP ranges for window', startUs, endUs);\n return { gops: [], byteStart: 0, byteEnd: 0 };\n }\n\n // Calculate merged byte range for OPFS read\n let byteStart = Infinity;\n let byteEnd = 0;\n\n for (const gop of overlappingGOPs) {\n const startSample = samples[gop.keyframeSampleIndex];\n const endSampleIndex = gop.keyframeSampleIndex + gop.sampleCount - 1;\n const endSample = samples[endSampleIndex];\n\n if (startSample && endSample) {\n byteStart = Math.min(byteStart, startSample.byteOffset);\n byteEnd = Math.max(byteEnd, endSample.byteOffset + endSample.byteLength);\n }\n }\n\n return { gops: overlappingGOPs, byteStart, byteEnd };\n }\n\n /**\n * Extract video chunks from GOP data\n *\n * Directly use GOP sample indices to slice the samples array.\n * This is O(k) where k is the number of samples in the window,\n * vs O(n×m) for the old approach (n=all samples, m=GOP count).\n */\n private async demuxGOPData(\n data: ArrayBuffer,\n index: MP4Index,\n gopWindow: GOPWindowResult\n ): Promise<EncodedVideoChunk[]> {\n const videoTrack = index.tracks.video;\n if (!videoTrack) {\n throw new Error('No video track in index');\n }\n\n const { samples } = videoTrack;\n const chunks: EncodedVideoChunk[] = [];\n const dataView = new Uint8Array(data);\n const baseByteOffset = gopWindow.byteStart;\n\n // Direct sample index slicing - iterate only samples in the window\n for (const gop of gopWindow.gops) {\n const startIdx = gop.keyframeSampleIndex;\n const endIdx = startIdx + gop.sampleCount;\n\n // Extract samples for this GOP (direct array slice)\n for (let i = startIdx; i < endIdx; i++) {\n const sample = samples[i];\n if (!sample) continue;\n\n // Calculate relative offset within the data buffer\n const relativeOffset = sample.byteOffset - baseByteOffset;\n\n // Validate offset is within buffer\n if (relativeOffset < 0 || relativeOffset + sample.byteLength > data.byteLength) {\n console.warn('[OnDemandVideoSession] Sample outside buffer:', {\n sampleOffset: sample.byteOffset,\n sampleLength: sample.byteLength,\n baseOffset: baseByteOffset,\n relativeOffset,\n bufferLength: data.byteLength,\n });\n continue;\n }\n\n // Extract sample data\n const sampleData = dataView.slice(relativeOffset, relativeOffset + sample.byteLength);\n\n // Create EncodedVideoChunk\n const chunk = new EncodedVideoChunk({\n type: sample.isKeyframe ? 'key' : 'delta',\n timestamp: sample.timestamp,\n duration: sample.duration,\n data: sampleData,\n });\n\n chunks.push(chunk);\n }\n }\n\n return chunks;\n }\n\n private async decodeChunks(chunks: EncodedVideoChunk[], index: MP4Index): Promise<void> {\n const videoTrack = index.tracks.video;\n if (!videoTrack) {\n throw new Error('No video track in index');\n }\n\n console.log('[OnDemandVideoSession] decodeChunks start:', {\n clipId: this.clipId,\n chunkCount: chunks.length,\n firstChunkType: chunks[0]?.type,\n codec: videoTrack.codec,\n dimensions: `${videoTrack.width}x${videoTrack.height}`,\n });\n\n const result = await decodeChunksWithoutFlush(chunks, {\n codec: videoTrack.codec,\n width: videoTrack.width,\n height: videoTrack.height,\n description: videoTrack.description,\n });\n\n // Store frames for caching\n this.decodedFrames = result.frames;\n\n console.log('[OnDemandVideoSession] decodeChunks complete:', {\n clipId: this.clipId,\n inputChunks: result.stats.inputChunks,\n outputFrames: result.stats.outputFrames,\n durationMs: result.stats.durationMs,\n });\n }\n\n /**\n * Cache a single frame to L1 with proper timestamp calculations\n */\n private cacheFrame(frame: VideoFrame, globalTimeOffset: TimeUs = 0): void {\n const frameDuration = frame.duration ?? Math.round(1_000_000 / this.fps);\n const frameGlobalTime =\n this.globalTimeUs + (frame.timestamp - this.targetTimeUs) + globalTimeOffset;\n\n this.cacheManager.addFrame(\n frame,\n this.clipId,\n frameDuration,\n this.compositionModel.mainTrackId,\n frameGlobalTime\n );\n }\n\n private async cacheDecodedFrames(startUs: TimeUs, endUs: TimeUs): Promise<void> {\n const framesToCache: VideoFrame[] = [];\n const framesToDiscard: VideoFrame[] = [];\n\n // Partition frames into cacheable and discardable\n for (const frame of this.decodedFrames) {\n if (frame.timestamp >= startUs && frame.timestamp < endUs) {\n framesToCache.push(frame);\n } else {\n framesToDiscard.push(frame);\n }\n }\n\n // Cache frames within window\n for (const frame of framesToCache) {\n try {\n this.cacheFrame(frame);\n } catch (error) {\n console.error('[OnDemandVideoSession] Cache error:', error);\n frame.close();\n }\n }\n\n // Release frames outside window\n for (const frame of framesToDiscard) {\n frame.close();\n }\n\n this.decodedFrames = [];\n }\n\n /**\n * Fast decode single keyframe for immediate seek preview\n * Returns the decoded keyframe timestamp\n */\n async decodeKeyframe(targetTimeUs: TimeUs): Promise<TimeUs | null> {\n if (this.isDisposed || this.aborted) return null;\n\n const index = this.mp4IndexCache.get(this.resourceId);\n if (!index || !index.tracks.video) return null;\n\n // Find nearest keyframe\n const keyframeSample = this.mp4IndexCache.getNearestKeyframe(this.resourceId, targetTimeUs);\n if (!keyframeSample) return null;\n\n // Read only the keyframe bytes from OPFS\n const keyframeData = await this.cacheManager.readResourceRange(\n this.resourceId,\n keyframeSample.byteOffset,\n keyframeSample.byteOffset + keyframeSample.byteLength\n );\n\n if (this.aborted) return null;\n\n // Create and decode keyframe chunk\n const chunk = new EncodedVideoChunk({\n type: 'key',\n timestamp: keyframeSample.timestamp,\n duration: keyframeSample.duration,\n data: keyframeData,\n });\n\n await this.decodeChunks([chunk], index);\n\n if (this.aborted || this.decodedFrames.length === 0) return null;\n\n // Cache the first (and only) decoded frame\n const frame = this.decodedFrames[0];\n if (!frame) return null;\n\n this.cacheFrame(frame);\n this.decodedFrames = [];\n\n return keyframeSample.timestamp;\n }\n\n async dispose(): Promise<void> {\n if (this.isDisposed) return;\n\n this.aborted = true;\n\n // Clean up decoder if exists\n if (this.decoder) {\n try {\n this.decoder.close();\n } catch (error) {\n console.warn('[OnDemandVideoSession] Decoder close error:', error);\n }\n this.decoder = null;\n }\n\n // Release all decoded frames\n this.releaseDecodedFrames();\n\n this.isDisposed = true;\n }\n}\n"],"names":[],"m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AAErB,WAAO,eAAe;AAAA,EACxB;AAAA,EAEA,MAAM,UAAyB;AAC7B,QAAI,KAAK,WAAY;AAErB,SAAK,UAAU;AAGf,QAAI,KAAK,SAAS;AAChB,UAAI;AACF,aAAK,QAAQ,MAAA;AAAA,MACf,SAAS,OAAO;AACd,gBAAQ,KAAK,+CAA+C,KAAK;AAAA,MACnE;AACA,WAAK,UAAU;AAAA,IACjB;AAGA,SAAK,qBAAA;AAEL,SAAK,aAAa;AAAA,EACpB;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VideoChunkDecoder.d.ts","sourceRoot":"","sources":["../../../src/stages/decode/VideoChunkDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"VideoChunkDecoder.d.ts","sourceRoot":"","sources":["../../../src/stages/decode/VideoChunkDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,WAAW,CAChD,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,CACX;IACC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAAK;IACpD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,8BAA8B,CAAM;IAE5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IAGhD,OAAO,CAAC,cAAc,CAA2B;IACjD,OAAO,CAAC,kBAAkB,CAAkB;gBAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC;IAYjE,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7D,YAAY,IAAI,eAAe,CAAC,iBAAiB,EAAE,UAAU,CAAC;IA2CvE;;OAEG;YACW,YAAY;cAcP,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;cAKxC,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IAS9F,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE;QAC5B,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;QACpC,KAAK,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;KACtC,GAAG,YAAY;IAIhB,SAAS,CAAC,cAAc,IAAI,MAAM;cAIlB,gBAAgB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB3E,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IAIhD;;OAEG;IACG,SAAS,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1D;;OAEG;IACG,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IA6B7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAOtC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform detection utilities with caching for performance
|
|
3
|
+
*/
|
|
4
|
+
export interface PlatformInfo {
|
|
5
|
+
isWindows: boolean;
|
|
6
|
+
isMacOS: boolean;
|
|
7
|
+
isLinux: boolean;
|
|
8
|
+
platform: string;
|
|
9
|
+
userAgent: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Detect current platform (cached after first call)
|
|
13
|
+
*/
|
|
14
|
+
export declare function detectPlatform(): PlatformInfo;
|
|
15
|
+
/**
|
|
16
|
+
* Check if current platform is Windows (cached)
|
|
17
|
+
*/
|
|
18
|
+
export declare function isWindows(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Check if current platform is macOS (cached)
|
|
21
|
+
*/
|
|
22
|
+
export declare function isMacOS(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Check if current platform is Linux (cached)
|
|
25
|
+
*/
|
|
26
|
+
export declare function isLinux(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Get platform-recommended hardware acceleration setting for video decoding
|
|
29
|
+
*
|
|
30
|
+
* Background:
|
|
31
|
+
* Windows hardware video decoders (especially with DXVA2/D3D11) may hang indefinitely
|
|
32
|
+
* when calling VideoDecoder.flush() in certain scenarios (frequent seeks, large GOPs).
|
|
33
|
+
* This appears to be a driver/platform-specific issue affecting Chromium's WebCodecs.
|
|
34
|
+
*
|
|
35
|
+
* Related discussions:
|
|
36
|
+
* - https://github.com/w3c/webcodecs/issues
|
|
37
|
+
* - Observed in production on Windows 10/11 with various GPU vendors
|
|
38
|
+
*
|
|
39
|
+
* Workaround:
|
|
40
|
+
* Use software decoding on Windows to avoid flush() hangs, with ~4x slower decode
|
|
41
|
+
* but reliable operation. Other platforms use hardware acceleration by default.
|
|
42
|
+
*
|
|
43
|
+
* @returns Platform-recommended hardware acceleration setting
|
|
44
|
+
*/
|
|
45
|
+
export declare function getRecommendedHardwareAcceleration(): HardwareAcceleration;
|
|
46
|
+
//# sourceMappingURL=platform-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-utils.d.ts","sourceRoot":"","sources":["../../src/utils/platform-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAKD;;GAEG;AACH,wBAAgB,cAAc,IAAI,YAAY,CAiB7C;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;GAEG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAEjC;AAED;;GAEG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAEjC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kCAAkC,IAAI,oBAAoB,CAQzE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
let cachedPlatformInfo = null;
|
|
2
|
+
function detectPlatform() {
|
|
3
|
+
if (cachedPlatformInfo) {
|
|
4
|
+
return cachedPlatformInfo;
|
|
5
|
+
}
|
|
6
|
+
const platform = typeof navigator !== "undefined" ? navigator.platform : "";
|
|
7
|
+
const userAgent = typeof navigator !== "undefined" ? navigator.userAgent : "";
|
|
8
|
+
cachedPlatformInfo = {
|
|
9
|
+
isWindows: /Win/i.test(platform) || /Win/i.test(userAgent),
|
|
10
|
+
isMacOS: /Mac/i.test(platform),
|
|
11
|
+
isLinux: /Linux/i.test(platform),
|
|
12
|
+
platform,
|
|
13
|
+
userAgent
|
|
14
|
+
};
|
|
15
|
+
return cachedPlatformInfo;
|
|
16
|
+
}
|
|
17
|
+
function isWindows() {
|
|
18
|
+
return detectPlatform().isWindows;
|
|
19
|
+
}
|
|
20
|
+
function getRecommendedHardwareAcceleration() {
|
|
21
|
+
if (isWindows()) {
|
|
22
|
+
return "prefer-software";
|
|
23
|
+
}
|
|
24
|
+
return "no-preference";
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
detectPlatform,
|
|
28
|
+
getRecommendedHardwareAcceleration,
|
|
29
|
+
isWindows
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=platform-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-utils.js","sources":["../../src/utils/platform-utils.ts"],"sourcesContent":["/**\n * Platform detection utilities with caching for performance\n */\n\nexport interface PlatformInfo {\n isWindows: boolean;\n isMacOS: boolean;\n isLinux: boolean;\n platform: string;\n userAgent: string;\n}\n\n// Cache platform detection result (only detect once)\nlet cachedPlatformInfo: PlatformInfo | null = null;\n\n/**\n * Detect current platform (cached after first call)\n */\nexport function detectPlatform(): PlatformInfo {\n if (cachedPlatformInfo) {\n return cachedPlatformInfo;\n }\n\n const platform = typeof navigator !== 'undefined' ? navigator.platform : '';\n const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : '';\n\n cachedPlatformInfo = {\n isWindows: /Win/i.test(platform) || /Win/i.test(userAgent),\n isMacOS: /Mac/i.test(platform),\n isLinux: /Linux/i.test(platform),\n platform,\n userAgent,\n };\n\n return cachedPlatformInfo;\n}\n\n/**\n * Check if current platform is Windows (cached)\n */\nexport function isWindows(): boolean {\n return detectPlatform().isWindows;\n}\n\n/**\n * Check if current platform is macOS (cached)\n */\nexport function isMacOS(): boolean {\n return detectPlatform().isMacOS;\n}\n\n/**\n * Check if current platform is Linux (cached)\n */\nexport function isLinux(): boolean {\n return detectPlatform().isLinux;\n}\n\n/**\n * Get platform-recommended hardware acceleration setting for video decoding\n *\n * Background:\n * Windows hardware video decoders (especially with DXVA2/D3D11) may hang indefinitely\n * when calling VideoDecoder.flush() in certain scenarios (frequent seeks, large GOPs).\n * This appears to be a driver/platform-specific issue affecting Chromium's WebCodecs.\n *\n * Related discussions:\n * - https://github.com/w3c/webcodecs/issues\n * - Observed in production on Windows 10/11 with various GPU vendors\n *\n * Workaround:\n * Use software decoding on Windows to avoid flush() hangs, with ~4x slower decode\n * but reliable operation. Other platforms use hardware acceleration by default.\n *\n * @returns Platform-recommended hardware acceleration setting\n */\nexport function getRecommendedHardwareAcceleration(): HardwareAcceleration {\n // Windows: prefer software to avoid flush hang in hardware decoders\n if (isWindows()) {\n return 'prefer-software';\n }\n\n // Other platforms: no preference (let browser choose)\n return 'no-preference';\n}\n"],"names":[],"mappings":"AAaA,IAAI,qBAA0C;AAKvC,SAAS,iBAA+B;AAC7C,MAAI,oBAAoB;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,OAAO,cAAc,cAAc,UAAU,WAAW;AACzE,QAAM,YAAY,OAAO,cAAc,cAAc,UAAU,YAAY;AAE3E,uBAAqB;AAAA,IACnB,WAAW,OAAO,KAAK,QAAQ,KAAK,OAAO,KAAK,SAAS;AAAA,IACzD,SAAS,OAAO,KAAK,QAAQ;AAAA,IAC7B,SAAS,SAAS,KAAK,QAAQ;AAAA,IAC/B;AAAA,IACA;AAAA,EAAA;AAGF,SAAO;AACT;AAKO,SAAS,YAAqB;AACnC,SAAO,iBAAiB;AAC1B;AAkCO,SAAS,qCAA2D;AAEzE,MAAI,aAAa;AACf,WAAO;AAAA,EACT;AAGA,SAAO;AACT;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface DecodeResult {
|
|
2
|
+
frames: VideoFrame[];
|
|
3
|
+
stats: {
|
|
4
|
+
inputChunks: number;
|
|
5
|
+
outputFrames: number;
|
|
6
|
+
durationMs: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface VideoDecoderConfig {
|
|
10
|
+
codec: string;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
description?: ArrayBuffer;
|
|
14
|
+
hardwareAcceleration?: HardwareAcceleration;
|
|
15
|
+
}
|
|
16
|
+
export interface DecodeOptions {
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
pollIntervalMs?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Decode chunks using native VideoDecoder without awaiting flush
|
|
22
|
+
* This avoids Windows hardware acceleration flush hang bug
|
|
23
|
+
*
|
|
24
|
+
* Strategy:
|
|
25
|
+
* - Feed all chunks to decoder
|
|
26
|
+
* - Call flush() but don't await (may hang on Windows HW)
|
|
27
|
+
* - Poll decodeQueueSize to detect completion
|
|
28
|
+
* - Timeout fallback ensures no infinite hang
|
|
29
|
+
*/
|
|
30
|
+
export declare function decodeChunksWithoutFlush(chunks: EncodedVideoChunk[], config: VideoDecoderConfig, options?: DecodeOptions): Promise<DecodeResult>;
|
|
31
|
+
//# sourceMappingURL=video-decoder-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-decoder-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/video-decoder-helpers.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,KAAK,EAAE;QACL,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,iBAAiB,EAAE,EAC3B,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAiFvB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { getRecommendedHardwareAcceleration } from "./platform-utils.js";
|
|
2
|
+
async function decodeChunksWithoutFlush(chunks, config, options = {}) {
|
|
3
|
+
const { timeoutMs = 2e3, pollIntervalMs = 10 } = options;
|
|
4
|
+
const startTime = performance.now();
|
|
5
|
+
const frames = [];
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
let isSettled = false;
|
|
8
|
+
let pollTimer = null;
|
|
9
|
+
let timeoutTimer = null;
|
|
10
|
+
const cleanup = () => {
|
|
11
|
+
if (pollTimer !== null) {
|
|
12
|
+
clearInterval(pollTimer);
|
|
13
|
+
pollTimer = null;
|
|
14
|
+
}
|
|
15
|
+
if (timeoutTimer !== null) {
|
|
16
|
+
clearTimeout(timeoutTimer);
|
|
17
|
+
timeoutTimer = null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const settle = (success, errorMsg) => {
|
|
21
|
+
if (isSettled) return;
|
|
22
|
+
isSettled = true;
|
|
23
|
+
cleanup();
|
|
24
|
+
const stats = {
|
|
25
|
+
inputChunks: chunks.length,
|
|
26
|
+
outputFrames: frames.length,
|
|
27
|
+
durationMs: performance.now() - startTime
|
|
28
|
+
};
|
|
29
|
+
if (success && frames.length > 0) {
|
|
30
|
+
resolve({ frames, stats });
|
|
31
|
+
} else {
|
|
32
|
+
reject(new Error(errorMsg || "Decode failed"));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const decoder = new VideoDecoder({
|
|
36
|
+
output: (frame) => {
|
|
37
|
+
frames.push(frame);
|
|
38
|
+
},
|
|
39
|
+
error: (error) => {
|
|
40
|
+
settle(false, error.message);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
decoder.configure({
|
|
44
|
+
codec: config.codec,
|
|
45
|
+
codedWidth: config.width,
|
|
46
|
+
codedHeight: config.height,
|
|
47
|
+
hardwareAcceleration: config.hardwareAcceleration ?? getRecommendedHardwareAcceleration(),
|
|
48
|
+
optimizeForLatency: true,
|
|
49
|
+
...config.description && { description: config.description }
|
|
50
|
+
});
|
|
51
|
+
for (const chunk of chunks) {
|
|
52
|
+
decoder.decode(chunk);
|
|
53
|
+
}
|
|
54
|
+
decoder.flush().catch(() => {
|
|
55
|
+
});
|
|
56
|
+
pollTimer = setInterval(() => {
|
|
57
|
+
if (decoder.decodeQueueSize === 0 && frames.length > 0) {
|
|
58
|
+
decoder.close();
|
|
59
|
+
settle(true);
|
|
60
|
+
}
|
|
61
|
+
}, pollIntervalMs);
|
|
62
|
+
timeoutTimer = setTimeout(() => {
|
|
63
|
+
decoder.close();
|
|
64
|
+
settle(frames.length > 0, `Decode timeout after ${timeoutMs}ms`);
|
|
65
|
+
}, timeoutMs);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
decodeChunksWithoutFlush
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=video-decoder-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-decoder-helpers.js","sources":["../../src/utils/video-decoder-helpers.ts"],"sourcesContent":["import { getRecommendedHardwareAcceleration } from './platform-utils';\n\nexport interface DecodeResult {\n frames: VideoFrame[];\n stats: {\n inputChunks: number;\n outputFrames: number;\n durationMs: number;\n };\n}\n\nexport interface VideoDecoderConfig {\n codec: string;\n width: number;\n height: number;\n description?: ArrayBuffer;\n hardwareAcceleration?: HardwareAcceleration;\n}\n\nexport interface DecodeOptions {\n timeoutMs?: number;\n pollIntervalMs?: number;\n}\n\n/**\n * Decode chunks using native VideoDecoder without awaiting flush\n * This avoids Windows hardware acceleration flush hang bug\n *\n * Strategy:\n * - Feed all chunks to decoder\n * - Call flush() but don't await (may hang on Windows HW)\n * - Poll decodeQueueSize to detect completion\n * - Timeout fallback ensures no infinite hang\n */\nexport async function decodeChunksWithoutFlush(\n chunks: EncodedVideoChunk[],\n config: VideoDecoderConfig,\n options: DecodeOptions = {}\n): Promise<DecodeResult> {\n const { timeoutMs = 2000, pollIntervalMs = 10 } = options;\n const startTime = performance.now();\n const frames: VideoFrame[] = [];\n\n return new Promise((resolve, reject) => {\n let isSettled = false;\n let pollTimer: ReturnType<typeof setInterval> | null = null;\n let timeoutTimer: ReturnType<typeof setTimeout> | null = null;\n\n const cleanup = () => {\n if (pollTimer !== null) {\n clearInterval(pollTimer);\n pollTimer = null;\n }\n if (timeoutTimer !== null) {\n clearTimeout(timeoutTimer);\n timeoutTimer = null;\n }\n };\n\n const settle = (success: boolean, errorMsg?: string) => {\n if (isSettled) return;\n isSettled = true;\n cleanup();\n\n const stats = {\n inputChunks: chunks.length,\n outputFrames: frames.length,\n durationMs: performance.now() - startTime,\n };\n\n if (success && frames.length > 0) {\n resolve({ frames, stats });\n } else {\n reject(new Error(errorMsg || 'Decode failed'));\n }\n };\n\n const decoder = new VideoDecoder({\n output: (frame) => {\n frames.push(frame);\n },\n error: (error) => {\n settle(false, error.message);\n },\n });\n\n decoder.configure({\n codec: config.codec,\n codedWidth: config.width,\n codedHeight: config.height,\n hardwareAcceleration: config.hardwareAcceleration ?? getRecommendedHardwareAcceleration(),\n optimizeForLatency: true,\n ...(config.description && { description: config.description }),\n });\n\n // Feed all chunks\n for (const chunk of chunks) {\n decoder.decode(chunk);\n }\n\n // Call flush but don't await (may hang on Windows HW acceleration)\n decoder.flush().catch(() => {\n // Flush errors are non-critical\n });\n\n // Poll decode queue to detect completion\n pollTimer = setInterval(() => {\n if (decoder.decodeQueueSize === 0 && frames.length > 0) {\n decoder.close();\n settle(true);\n }\n }, pollIntervalMs);\n\n // Timeout fallback\n timeoutTimer = setTimeout(() => {\n decoder.close();\n settle(frames.length > 0, `Decode timeout after ${timeoutMs}ms`);\n }, timeoutMs);\n });\n}\n"],"names":[],"mappings":";AAkCA,eAAsB,yBACpB,QACA,QACA,UAAyB,CAAA,GACF;AACvB,QAAM,EAAE,YAAY,KAAM,iBAAiB,OAAO;AAClD,QAAM,YAAY,YAAY,IAAA;AAC9B,QAAM,SAAuB,CAAA;AAE7B,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,YAAY;AAChB,QAAI,YAAmD;AACvD,QAAI,eAAqD;AAEzD,UAAM,UAAU,MAAM;AACpB,UAAI,cAAc,MAAM;AACtB,sBAAc,SAAS;AACvB,oBAAY;AAAA,M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A,EACd,CAAC;AACH;"}
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import { W as WorkerChannel, a as WorkerMessageType, b as WorkerState } from "../../WorkerChannel.CE5euh3R.js";
|
|
2
2
|
import { B as BaseDecoder } from "../../BaseDecoder.DWHTBMDB.js";
|
|
3
|
+
let cachedPlatformInfo = null;
|
|
4
|
+
function detectPlatform() {
|
|
5
|
+
if (cachedPlatformInfo) {
|
|
6
|
+
return cachedPlatformInfo;
|
|
7
|
+
}
|
|
8
|
+
const platform = typeof navigator !== "undefined" ? navigator.platform : "";
|
|
9
|
+
const userAgent = typeof navigator !== "undefined" ? navigator.userAgent : "";
|
|
10
|
+
cachedPlatformInfo = {
|
|
11
|
+
isWindows: /Win/i.test(platform) || /Win/i.test(userAgent),
|
|
12
|
+
isMacOS: /Mac/i.test(platform),
|
|
13
|
+
isLinux: /Linux/i.test(platform),
|
|
14
|
+
platform,
|
|
15
|
+
userAgent
|
|
16
|
+
};
|
|
17
|
+
return cachedPlatformInfo;
|
|
18
|
+
}
|
|
19
|
+
function isWindows() {
|
|
20
|
+
return detectPlatform().isWindows;
|
|
21
|
+
}
|
|
22
|
+
function getRecommendedHardwareAcceleration() {
|
|
23
|
+
if (isWindows()) {
|
|
24
|
+
return "prefer-software";
|
|
25
|
+
}
|
|
26
|
+
return "no-preference";
|
|
27
|
+
}
|
|
3
28
|
class VideoChunkDecoder extends BaseDecoder {
|
|
4
29
|
static DEFAULT_HIGH_WATER_MARK = 4;
|
|
5
30
|
static DEFAULT_DECODE_QUEUE_THRESHOLD = 16;
|
|
@@ -101,17 +126,21 @@ class VideoChunkDecoder extends BaseDecoder {
|
|
|
101
126
|
}
|
|
102
127
|
async configureDecoder(config) {
|
|
103
128
|
if (!this.decoder) return;
|
|
129
|
+
const hardwareAcceleration = config.hardwareAcceleration ?? getRecommendedHardwareAcceleration();
|
|
104
130
|
const decoderConfig = {
|
|
105
131
|
codec: config.codec,
|
|
106
132
|
codedWidth: config.width,
|
|
107
133
|
codedHeight: config.height,
|
|
108
|
-
hardwareAcceleration
|
|
109
|
-
optimizeForLatency:
|
|
134
|
+
hardwareAcceleration,
|
|
135
|
+
optimizeForLatency: true,
|
|
110
136
|
...config.description && { description: config.description },
|
|
111
137
|
...config.displayAspectWidth && { displayAspectWidth: config.displayAspectWidth },
|
|
112
138
|
...config.displayAspectHeight && { displayAspectHeight: config.displayAspectHeight }
|
|
113
139
|
};
|
|
114
140
|
this.decoder.configure(decoderConfig);
|
|
141
|
+
if (hardwareAcceleration === "prefer-software") {
|
|
142
|
+
console.info("[VideoChunkDecoder] Using software decoding for platform compatibility");
|
|
143
|
+
}
|
|
115
144
|
}
|
|
116
145
|
decode(chunk) {
|
|
117
146
|
this.decoder?.decode(chunk);
|
|
@@ -304,4 +333,4 @@ export {
|
|
|
304
333
|
VideoDecodeWorker,
|
|
305
334
|
videoDecode_worker as default
|
|
306
335
|
};
|
|
307
|
-
//# sourceMappingURL=video-decode.worker.
|
|
336
|
+
//# sourceMappingURL=video-decode.worker.CwOjEmre.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-decode.worker.CwOjEmre.js","sources":["../../../../src/utils/platform-utils.ts","../../../../src/stages/decode/VideoChunkDecoder.ts","../../../../src/stages/decode/video-decode.worker.ts"],"sourcesContent":["/**\n * Platform detection utilities with caching for performance\n */\n\nexport interface PlatformInfo {\n isWindows: boolean;\n isMacOS: boolean;\n isLinux: boolean;\n platform: string;\n userAgent: string;\n}\n\n// Cache platform detection result (only detect once)\nlet cachedPlatformInfo: PlatformInfo | null = null;\n\n/**\n * Detect current platform (cached after first call)\n */\nexport function detectPlatform(): PlatformInfo {\n if (cachedPlatformInfo) {\n return cachedPlatformInfo;\n }\n\n const platform = typeof navigator !== 'undefined' ? navigator.platform : '';\n const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : '';\n\n cachedPlatformInfo = {\n isWindows: /Win/i.test(platform) || /Win/i.test(userAgent),\n isMacOS: /Mac/i.test(platform),\n isLinux: /Linux/i.test(platform),\n platform,\n userAgent,\n };\n\n return cachedPlatformInfo;\n}\n\n/**\n * Check if current platform is Windows (cached)\n */\nexport function isWindows(): boolean {\n return detectPlatform().isWindows;\n}\n\n/**\n * Check if current platform is macOS (cached)\n */\nexport function isMacOS(): boolean {\n return detectPlatform().isMacOS;\n}\n\n/**\n * Check if current platform is Linux (cached)\n */\nexport function isLinux(): boolean {\n return detectPlatform().isLinux;\n}\n\n/**\n * Get platform-recommended hardware acceleration setting for video decoding\n *\n * Background:\n * Windows hardware video decoders (especially with DXVA2/D3D11) may hang indefinitely\n * when calling VideoDecoder.flush() in certain scenarios (frequent seeks, large GOPs).\n * This appears to be a driver/platform-specific issue affecting Chromium's WebCodecs.\n *\n * Related discussions:\n * - https://github.com/w3c/webcodecs/issues\n * - Observed in production on Windows 10/11 with various GPU vendors\n *\n * Workaround:\n * Use software decoding on Windows to avoid flush() hangs, with ~4x slower decode\n * but reliable operation. Other platforms use hardware acceleration by default.\n *\n * @returns Platform-recommended hardware acceleration setting\n */\nexport function getRecommendedHardwareAcceleration(): HardwareAcceleration {\n // Windows: prefer software to avoid flush hang in hardware decoders\n if (isWindows()) {\n return 'prefer-software';\n }\n\n // Other platforms: no preference (let browser choose)\n return 'no-preference';\n}\n","import { VideoDecoderConfig } from './types';\nimport { BaseDecoder } from './BaseDecoder';\nimport { getRecommendedHardwareAcceleration } from '../../utils/platform-utils';\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 // 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 console.log('>>>>>>>>>>[VideoChunkDecoder] start flushing decoder');\n await this.flush();\n console.log('>>>>>>>>>>[VideoChunkDecoder] flushed decoder');\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 this.decode(chunk);\n }\n\n // Override handleOutput to enqueue decoded frames\n protected override handleOutput(frame: VideoFrame): void {\n super.handleOutput(frame);\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 hardwareAcceleration =\n config.hardwareAcceleration ?? getRecommendedHardwareAcceleration();\n\n const decoderConfig = {\n codec: config.codec,\n codedWidth: config.width,\n codedHeight: config.height,\n hardwareAcceleration,\n optimizeForLatency: true,\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\n // Log when using software decoding for debugging\n if (hardwareAcceleration === 'prefer-software') {\n console.info('[VideoChunkDecoder] Using software decoding for platform compatibility');\n }\n }\n\n protected decode(chunk: EncodedVideoChunk): void {\n this.decoder?.decode(chunk);\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 buffered chunks\n override async close(): Promise<void> {\n // Clear buffered chunks\n this.bufferedChunks = [];\n\n // Call parent close\n await super.close();\n }\n}\n","import { WorkerChannel } from '../../worker/WorkerChannel';\nimport { WorkerMessageType, WorkerState } from '../../worker/types';\nimport { VideoChunkDecoder } from './VideoChunkDecoder';\nimport { VideoDecoderConfig } from './types';\n\nconst normalizeDescription = (desc?: ArrayBuffer | ArrayBufferView): ArrayBuffer | undefined => {\n if (!desc) return undefined;\n\n if (desc instanceof ArrayBuffer) return desc;\n\n const view = desc as ArrayBufferView;\n return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength) as ArrayBuffer;\n};\n\n/**\n * VideoDecodeWorker (Clip Local) - Decodes video for a single clip\n * Receives encoded video chunks from VideoDemuxWorker and outputs decoded frames\n *\n * Pipeline: VideoDemuxWorker → VideoDecodeWorker → VideoComposeWorker\n *\n * Features:\n * - Single clip, single VideoDecoder instance (no routing)\n * - GOP-based decoding with metadata\n * - Stream-based processing with backpressure\n * - Lifecycle tied to clip pipeline\n */\nexport class VideoDecodeWorker {\n private channel: WorkerChannel;\n private decoder: VideoChunkDecoder | null = null;\n private clipId: string = '';\n\n private defaultConfig: Partial<VideoDecoderConfig> = {};\n\n private upstreamPort: MessagePort | null = null;\n private downstreamPort: MessagePort | null = null;\n\n constructor() {\n this.channel = new WorkerChannel(self as any, {\n name: 'VideoDecodeWorker',\n timeout: 30000,\n });\n\n this.setupHandlers();\n }\n\n private setupHandlers(): void {\n this.channel.registerHandler('configure', this.handleConfigure.bind(this));\n this.channel.registerHandler('connect', this.handleConnect.bind(this));\n this.channel.registerHandler('flush', this.handleFlush.bind(this));\n this.channel.registerHandler('reset', this.handleReset.bind(this));\n this.channel.registerHandler('get_stats', this.handleGetStats.bind(this));\n this.channel.registerHandler(WorkerMessageType.Dispose, this.handleDispose.bind(this));\n }\n\n private async handleConnect(payload: {\n direction: 'upstream' | 'downstream';\n port: MessagePort;\n streamType?: 'video';\n sessionId?: string;\n clipStartUs?: number;\n clipDurationUs?: number;\n }): Promise<{ success: boolean }> {\n const { port, direction, sessionId } = payload;\n\n if (direction === 'upstream') {\n this.upstreamPort = port;\n this.clipId = sessionId || 'default';\n\n const channel = new WorkerChannel(port, {\n name: 'Demux-VideoDecode',\n timeout: 30000,\n });\n\n channel.receiveStream((stream, metadata) => {\n this.handleReceiveStream(stream, {\n ...metadata,\n clipStartUs: payload.clipStartUs,\n clipDurationUs: payload.clipDurationUs,\n });\n });\n\n channel.registerHandler('configure', this.handleConfigure.bind(this));\n }\n\n if (direction === 'downstream') {\n this.downstreamPort = port;\n }\n\n return { success: true };\n }\n\n private async handleConfigure(payload: {\n config?: { video?: Partial<VideoDecoderConfig> };\n sessionId?: string;\n streamType?: 'video';\n codec?: string;\n width?: number;\n height?: number;\n description?: ArrayBuffer | Uint8Array;\n }): Promise<{ success: boolean }> {\n const { sessionId, streamType, codec, width, height, description, config } = payload;\n\n if (sessionId && streamType === 'video') {\n if (this.decoder) {\n await this.decoder.updateConfig({\n codec,\n width,\n height,\n description: normalizeDescription(description),\n });\n }\n return { success: true };\n }\n\n if (config?.video) {\n Object.assign(this.defaultConfig, config.video);\n\n if (this.decoder) {\n await this.decoder.updateConfig(config.video);\n }\n }\n\n this.channel.state = WorkerState.Ready;\n\n return { success: true };\n }\n\n private async handleReceiveStream(\n stream: ReadableStream,\n metadata?: Record<string, any>\n ): Promise<void> {\n const sessionId = metadata?.sessionId || this.clipId;\n\n if (!this.decoder) {\n this.decoder = new VideoChunkDecoder(sessionId, {\n ...this.defaultConfig,\n codec: metadata?.codec,\n width: metadata?.width,\n height: metadata?.height,\n description: normalizeDescription(metadata?.description),\n });\n }\n\n const transform = this.decoder.createStream();\n\n if (this.downstreamPort) {\n const channel = new WorkerChannel(this.downstreamPort, {\n name: 'VideoDecode-Compose',\n timeout: 30000,\n });\n\n channel.sendStream(transform.readable as ReadableStream, {\n streamType: 'video',\n sessionId,\n });\n\n stream\n .pipeTo(transform.writable)\n .catch((error) =>\n console.error('[VideoDecodeWorker] Video stream pipe error:', sessionId, error)\n );\n }\n }\n\n private async handleFlush(): Promise<{ success: boolean }> {\n if (this.decoder) {\n await this.decoder.flush();\n }\n return { success: true };\n }\n\n private async handleReset(): Promise<{ success: boolean }> {\n if (this.decoder) {\n await this.decoder.reset();\n }\n\n this.channel.notify('reset_complete', {\n type: 'video',\n });\n\n return { success: true };\n }\n\n private async handleGetStats(): Promise<{ video?: any }> {\n if (!this.decoder) {\n return {};\n }\n\n return {\n video: {\n clipId: this.clipId,\n configured: this.decoder.isConfigured,\n queueSize: this.decoder.queueSize,\n state: this.decoder.state,\n },\n };\n }\n\n private async handleDispose(): Promise<{ success: boolean }> {\n if (this.decoder) {\n await this.decoder.close();\n this.decoder = null;\n }\n\n this.upstreamPort?.close();\n this.upstreamPort = null;\n\n this.downstreamPort?.close();\n this.downstreamPort = null;\n\n this.channel.state = WorkerState.Disposed;\n\n return { success: true };\n }\n}\n\nconst worker = new VideoDecodeWorker();\n\nself.addEventListener('beforeunload', () => {\n worker['handleDispose']();\n});\n\nexport default null;\n"],"names":[],"mappings":";;AAaA,IAAI,qBAA0C;AAKvC,SAAS,iBAA+B;AAC7C,MAAI,oBAAoB;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,OAAO,cAAc,cAAc,UAAU,WAAW;AACzE,QAAM,YAAY,OAAO,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I,kBAAA;AAEnB,KAAK,iBAAiB,gBAAgB,MAAM;AAC1C,SAAO,eAAe,EAAA;AACxB,CAAC;AAED,MAAA,qBAAe;"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"audio-compose.worker": "stages/compose/audio-compose.worker.rW63uN6z.js",
|
|
3
3
|
"video-compose.worker": "stages/compose/video-compose.worker.BhpN-lxf.js",
|
|
4
4
|
"audio-decode.worker": "stages/decode/audio-decode.worker.BsuBzFx5.js",
|
|
5
|
-
"video-decode.worker": "stages/decode/video-decode.worker.
|
|
5
|
+
"video-decode.worker": "stages/decode/video-decode.worker.CwOjEmre.js",
|
|
6
6
|
"audio-demux.worker": "stages/demux/audio-demux.worker.DgvvQVXU.js",
|
|
7
7
|
"video-demux.worker": "stages/demux/video-demux.worker.DhG3CRix.js",
|
|
8
8
|
"video-encode.worker": "stages/encode/video-encode.worker.CXgr5E16.js"
|
package/package.json
CHANGED
|
@@ -1,160 +0,0 @@
|
|
|
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
|
-
// Buffering support for delayed configuration
|
|
9
|
-
bufferedChunks = [];
|
|
10
|
-
isProcessingBuffer = false;
|
|
11
|
-
constructor(trackId, config) {
|
|
12
|
-
super(config || {});
|
|
13
|
-
this.trackId = trackId;
|
|
14
|
-
this.highWaterMark = config?.backpressure?.highWaterMark ?? VideoChunkDecoder.DEFAULT_HIGH_WATER_MARK;
|
|
15
|
-
this.decodeQueueThreshold = config?.backpressure?.decodeQueueThreshold ?? VideoChunkDecoder.DEFAULT_DECODE_QUEUE_THRESHOLD;
|
|
16
|
-
}
|
|
17
|
-
// Computed properties
|
|
18
|
-
get isConfigured() {
|
|
19
|
-
return this.isReady;
|
|
20
|
-
}
|
|
21
|
-
get state() {
|
|
22
|
-
return this.decoder?.state || "unconfigured";
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Update configuration - can be called before or after initialization
|
|
26
|
-
*/
|
|
27
|
-
async updateConfig(config) {
|
|
28
|
-
if (!this.isReady && config.codec) {
|
|
29
|
-
await this.configure(config);
|
|
30
|
-
await this.processBufferedChunks();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// Override createStream to handle GOP tracking and buffering
|
|
34
|
-
// Always create new stream for each clip (ReadableStreams can only be consumed once)
|
|
35
|
-
createStream() {
|
|
36
|
-
return new TransformStream(
|
|
37
|
-
{
|
|
38
|
-
start: async (controller) => {
|
|
39
|
-
this.controller = controller;
|
|
40
|
-
if (this.config?.codec && this.config?.description && !this.isReady) {
|
|
41
|
-
await this.initialize();
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
transform: async (chunk) => {
|
|
45
|
-
if (!this.isReady) {
|
|
46
|
-
this.bufferedChunks.push(chunk);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (this.isProcessingBuffer) {
|
|
50
|
-
this.bufferedChunks.push(chunk);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
await this.processChunk(chunk);
|
|
54
|
-
},
|
|
55
|
-
flush: async () => {
|
|
56
|
-
if (this.isReady) {
|
|
57
|
-
console.log(">>>>>>>>>>[VideoChunkDecoder] start flushing decoder");
|
|
58
|
-
await this.flush();
|
|
59
|
-
console.log(">>>>>>>>>>[VideoChunkDecoder] flushed decoder");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
highWaterMark: this.highWaterMark,
|
|
65
|
-
size: () => 1
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Process a single chunk (extracted from transform for reuse)
|
|
71
|
-
*/
|
|
72
|
-
async processChunk(chunk) {
|
|
73
|
-
if (!this.decoder) {
|
|
74
|
-
throw new Error("Decoder not initialized");
|
|
75
|
-
}
|
|
76
|
-
if (this.decoder.state !== "configured") {
|
|
77
|
-
console.error("[VideoChunkDecoder] Decoder in unexpected state:", this.decoder.state);
|
|
78
|
-
throw new Error(`Decoder not configured, state: ${this.decoder.state}`);
|
|
79
|
-
}
|
|
80
|
-
this.decode(chunk);
|
|
81
|
-
}
|
|
82
|
-
// Override handleOutput to enqueue decoded frames
|
|
83
|
-
handleOutput(frame) {
|
|
84
|
-
super.handleOutput(frame);
|
|
85
|
-
}
|
|
86
|
-
// Implement abstract methods
|
|
87
|
-
async isConfigSupported(config) {
|
|
88
|
-
const result = await VideoDecoder.isConfigSupported({
|
|
89
|
-
codec: config.codec,
|
|
90
|
-
codedWidth: config.width,
|
|
91
|
-
codedHeight: config.height
|
|
92
|
-
});
|
|
93
|
-
return { supported: result.supported ?? false };
|
|
94
|
-
}
|
|
95
|
-
createDecoder(init) {
|
|
96
|
-
return new VideoDecoder(init);
|
|
97
|
-
}
|
|
98
|
-
getDecoderType() {
|
|
99
|
-
return "Video";
|
|
100
|
-
}
|
|
101
|
-
async configureDecoder(config) {
|
|
102
|
-
if (!this.decoder) return;
|
|
103
|
-
const decoderConfig = {
|
|
104
|
-
codec: config.codec,
|
|
105
|
-
codedWidth: config.width,
|
|
106
|
-
codedHeight: config.height,
|
|
107
|
-
hardwareAcceleration: config.hardwareAcceleration || "no-preference",
|
|
108
|
-
optimizeForLatency: false,
|
|
109
|
-
...config.description && { description: config.description },
|
|
110
|
-
...config.displayAspectWidth && { displayAspectWidth: config.displayAspectWidth },
|
|
111
|
-
...config.displayAspectHeight && { displayAspectHeight: config.displayAspectHeight }
|
|
112
|
-
};
|
|
113
|
-
this.decoder.configure(decoderConfig);
|
|
114
|
-
}
|
|
115
|
-
decode(chunk) {
|
|
116
|
-
this.decoder?.decode(chunk);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Configure the decoder with codec info (can be called after creation)
|
|
120
|
-
*/
|
|
121
|
-
async configure(config) {
|
|
122
|
-
if (this.isReady) {
|
|
123
|
-
await this.reconfigure(config);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
this.config = config;
|
|
127
|
-
await this.initialize();
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Process any buffered chunks after configuration
|
|
131
|
-
*/
|
|
132
|
-
async processBufferedChunks() {
|
|
133
|
-
if (!this.isReady || this.bufferedChunks.length === 0) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
this.isProcessingBuffer = true;
|
|
137
|
-
const chunks = [...this.bufferedChunks];
|
|
138
|
-
this.bufferedChunks = [];
|
|
139
|
-
for (const chunk of chunks) {
|
|
140
|
-
try {
|
|
141
|
-
await this.processChunk(chunk);
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.error("[VideoChunkDecoder] Error processing buffered chunk:", error);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
this.isProcessingBuffer = false;
|
|
147
|
-
if (this.bufferedChunks.length > 0) {
|
|
148
|
-
await this.processBufferedChunks();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// Override close to clean up buffered chunks
|
|
152
|
-
async close() {
|
|
153
|
-
this.bufferedChunks = [];
|
|
154
|
-
await super.close();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
export {
|
|
158
|
-
VideoChunkDecoder
|
|
159
|
-
};
|
|
160
|
-
//# sourceMappingURL=VideoChunkDecoder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 // 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 console.log('>>>>>>>>>>[VideoChunkDecoder] start flushing decoder');\n await this.flush();\n console.log('>>>>>>>>>>[VideoChunkDecoder] flushed decoder');\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 this.decode(chunk);\n }\n\n // Override handleOutput to enqueue decoded frames\n protected override handleOutput(frame: VideoFrame): void {\n super.handleOutput(frame);\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 /**\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 buffered chunks\n override async close(): Promise<void> {\n // Clear buffered chunks\n this.bufferedChunks = [];\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,EAEhD;AAAA,EAEU;AAAA,EACA;AAAA;AAAA,EAGX,iBAAsC,CAAA;AAAA,EACtC,qBAA8B;AAAA,EAEtC,YAAY,SAAiB,QAAsC;AACjE,UAAO,UAAU,EAAyB;AAE1C,SAAK,UAAU;AACf,SAAK,gBACH,QAAQ,cAAc,iBAAiB,kBAAkB;AAC3D,SAAK,uBACH,QAAQ,cAAc,wBACtB,kBAAkB;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,eAAwB;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,SAAS,SAAS;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAAa,QAAoD;AACrE,QAAI,CAAC,KAAK,WAAW,O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AI;AACF,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,UAAM,MAAM,MAAA;AAAA,EACd;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"video-decode.worker.BBhZwyRw.js","sources":["../../../../src/stages/decode/VideoChunkDecoder.ts","../../../../src/stages/decode/video-decode.worker.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 // 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 console.log('>>>>>>>>>>[VideoChunkDecoder] start flushing decoder');\n await this.flush();\n console.log('>>>>>>>>>>[VideoChunkDecoder] flushed decoder');\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 this.decode(chunk);\n }\n\n // Override handleOutput to enqueue decoded frames\n protected override handleOutput(frame: VideoFrame): void {\n super.handleOutput(frame);\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 /**\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 buffered chunks\n override async close(): Promise<void> {\n // Clear buffered chunks\n this.bufferedChunks = [];\n\n // Call parent close\n await super.close();\n }\n}\n","import { WorkerChannel } from '../../worker/WorkerChannel';\nimport { WorkerMessageType, WorkerState } from '../../worker/types';\nimport { VideoChunkDecoder } from './VideoChunkDecoder';\nimport { VideoDecoderConfig } from './types';\n\nconst normalizeDescription = (desc?: ArrayBuffer | ArrayBufferView): ArrayBuffer | undefined => {\n if (!desc) return undefined;\n\n if (desc instanceof ArrayBuffer) return desc;\n\n const view = desc as ArrayBufferView;\n return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength) as ArrayBuffer;\n};\n\n/**\n * VideoDecodeWorker (Clip Local) - Decodes video for a single clip\n * Receives encoded video chunks from VideoDemuxWorker and outputs decoded frames\n *\n * Pipeline: VideoDemuxWorker → VideoDecodeWorker → VideoComposeWorker\n *\n * Features:\n * - Single clip, single VideoDecoder instance (no routing)\n * - GOP-based decoding with metadata\n * - Stream-based processing with backpressure\n * - Lifecycle tied to clip pipeline\n */\nexport class VideoDecodeWorker {\n private channel: WorkerChannel;\n private decoder: VideoChunkDecoder | null = null;\n private clipId: string = '';\n\n private defaultConfig: Partial<VideoDecoderConfig> = {};\n\n private upstreamPort: MessagePort | null = null;\n private downstreamPort: MessagePort | null = null;\n\n constructor() {\n this.channel = new WorkerChannel(self as any, {\n name: 'VideoDecodeWorker',\n timeout: 30000,\n });\n\n this.setupHandlers();\n }\n\n private setupHandlers(): void {\n this.channel.registerHandler('configure', this.handleConfigure.bind(this));\n this.channel.registerHandler('connect', this.handleConnect.bind(this));\n this.channel.registerHandler('flush', this.handleFlush.bind(this));\n this.channel.registerHandler('reset', this.handleReset.bind(this));\n this.channel.registerHandler('get_stats', this.handleGetStats.bind(this));\n this.channel.registerHandler(WorkerMessageType.Dispose, this.handleDispose.bind(this));\n }\n\n private async handleConnect(payload: {\n direction: 'upstream' | 'downstream';\n port: MessagePort;\n streamType?: 'video';\n sessionId?: string;\n clipStartUs?: number;\n clipDurationUs?: number;\n }): Promise<{ success: boolean }> {\n const { port, direction, sessionId } = payload;\n\n if (direction === 'upstream') {\n this.upstreamPort = port;\n this.clipId = sessionId || 'default';\n\n const channel = new WorkerChannel(port, {\n name: 'Demux-VideoDecode',\n timeout: 30000,\n });\n\n channel.receiveStream((stream, metadata) => {\n this.handleReceiveStream(stream, {\n ...metadata,\n clipStartUs: payload.clipStartUs,\n clipDurationUs: payload.clipDurationUs,\n });\n });\n\n channel.registerHandler('configure', this.handleConfigure.bind(this));\n }\n\n if (direction === 'downstream') {\n this.downstreamPort = port;\n }\n\n return { success: true };\n }\n\n private async handleConfigure(payload: {\n config?: { video?: Partial<VideoDecoderConfig> };\n sessionId?: string;\n streamType?: 'video';\n codec?: string;\n width?: number;\n height?: number;\n description?: ArrayBuffer | Uint8Array;\n }): Promise<{ success: boolean }> {\n const { sessionId, streamType, codec, width, height, description, config } = payload;\n\n if (sessionId && streamType === 'video') {\n if (this.decoder) {\n await this.decoder.updateConfig({\n codec,\n width,\n height,\n description: normalizeDescription(description),\n });\n }\n return { success: true };\n }\n\n if (config?.video) {\n Object.assign(this.defaultConfig, config.video);\n\n if (this.decoder) {\n await this.decoder.updateConfig(config.video);\n }\n }\n\n this.channel.state = WorkerState.Ready;\n\n return { success: true };\n }\n\n private async handleReceiveStream(\n stream: ReadableStream,\n metadata?: Record<string, any>\n ): Promise<void> {\n const sessionId = metadata?.sessionId || this.clipId;\n\n if (!this.decoder) {\n this.decoder = new VideoChunkDecoder(sessionId, {\n ...this.defaultConfig,\n codec: metadata?.codec,\n width: metadata?.width,\n height: metadata?.height,\n description: normalizeDescription(metadata?.description),\n });\n }\n\n const transform = this.decoder.createStream();\n\n if (this.downstreamPort) {\n const channel = new WorkerChannel(this.downstreamPort, {\n name: 'VideoDecode-Compose',\n timeout: 30000,\n });\n\n channel.sendStream(transform.readable as ReadableStream, {\n streamType: 'video',\n sessionId,\n });\n\n stream\n .pipeTo(transform.writable)\n .catch((error) =>\n console.error('[VideoDecodeWorker] Video stream pipe error:', sessionId, error)\n );\n }\n }\n\n private async handleFlush(): Promise<{ success: boolean }> {\n if (this.decoder) {\n await this.decoder.flush();\n }\n return { success: true };\n }\n\n private async handleReset(): Promise<{ success: boolean }> {\n if (this.decoder) {\n await this.decoder.reset();\n }\n\n this.channel.notify('reset_complete', {\n type: 'video',\n });\n\n return { success: true };\n }\n\n private async handleGetStats(): Promise<{ video?: any }> {\n if (!this.decoder) {\n return {};\n }\n\n return {\n video: {\n clipId: this.clipId,\n configured: this.decoder.isConfigured,\n queueSize: this.decoder.queueSize,\n state: this.decoder.state,\n },\n };\n }\n\n private async handleDispose(): Promise<{ success: boolean }> {\n if (this.decoder) {\n await this.decoder.close();\n this.decoder = null;\n }\n\n this.upstreamPort?.close();\n this.upstreamPort = null;\n\n this.downstreamPort?.close();\n this.downstreamPort = null;\n\n this.channel.state = WorkerState.Disposed;\n\n return { success: true };\n }\n}\n\nconst worker = new VideoDecodeWorker();\n\nself.addEventListener('beforeunload', () => {\n worker['handleDispose']();\n});\n\nexport default null;\n"],"names":[],"mappings":";;AAOO,MAAM,0BAA0B,YAKrC;AAAA,EACA,OAAwB,0BAA0B;AAAA,EAClD,OAAwB,iCAAiC;AAAA,EAEhD;AAAA,EAEU;AAAA,EACA;AAAA;AAAA,EAGX,iBAAsC,CAAA;AAAA,EACtC,qBAA8B;AAAA,EAEtC,YAAY,SAAiB,QAAsC;AACjE,UAAO,UAAU,EAAyB;AAE1C,SAAK,UAAU;AACf,SAAK,gBACH,QAAQ,cAAc,iBAAiB,kBAAkB;AAC3D,SAAK,uBACH,QAAQ,cAAc,wBACtB,kBAAkB;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,eAAwB;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,SAAS,SAAS;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAAa,QAAoD;AACrE,QAAI,CAAC,KAAK,WAAW,OAAO,OAAO;AACjC,YAAM,KAAK,UAAU,MAA4B;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