mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-09 16:53:47 +02:00
Fix async race condition in transparency code, reduce HEVC conversion duration
This commit is contained in:
+3
-3
@@ -1036,8 +1036,6 @@ class VideoDecoderWrapper extends DecoderWrapper<VideoSample> {
|
|||||||
if (!this.alphaDecoder) {
|
if (!this.alphaDecoder) {
|
||||||
const alphaHandler = (frame: VideoFrame) => {
|
const alphaHandler = (frame: VideoFrame) => {
|
||||||
this.frameHandlerSerializer.call(async () => {
|
this.frameHandlerSerializer.call(async () => {
|
||||||
this.alphaDecoderQueueSize--;
|
|
||||||
|
|
||||||
if (this.colorQueue.length > 0) {
|
if (this.colorQueue.length > 0) {
|
||||||
const colorFrame = this.colorQueue.shift();
|
const colorFrame = this.colorQueue.shift();
|
||||||
assert(colorFrame !== undefined);
|
assert(colorFrame !== undefined);
|
||||||
@@ -1064,6 +1062,8 @@ class VideoDecoderWrapper extends DecoderWrapper<VideoSample> {
|
|||||||
this.alphaQueue.push(null);
|
this.alphaQueue.push(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.alphaDecoderQueueSize--;
|
||||||
}).catch((error: Error) => this.onError(error));
|
}).catch((error: Error) => this.onError(error));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1266,7 +1266,7 @@ let mergerGpuUnavailable = false;
|
|||||||
|
|
||||||
/** Utility class that merges together color and alpha information using simple WebGL 2 shaders. */
|
/** Utility class that merges together color and alpha information using simple WebGL 2 shaders. */
|
||||||
export class ColorAlphaMerger {
|
export class ColorAlphaMerger {
|
||||||
static forceCpu = false;
|
static forceCpu = true;
|
||||||
|
|
||||||
canvas: OffscreenCanvas | HTMLCanvasElement | null = null;
|
canvas: OffscreenCanvas | HTMLCanvasElement | null = null;
|
||||||
private gl: WebGL2RenderingContext | null = null;
|
private gl: WebGL2RenderingContext | null = null;
|
||||||
|
|||||||
+1
-1
@@ -877,7 +877,7 @@ let splitterGpuUnavailable = false;
|
|||||||
|
|
||||||
/** Utility class for splitting a composite frame into separate color and alpha components. */
|
/** Utility class for splitting a composite frame into separate color and alpha components. */
|
||||||
export class ColorAlphaSplitter {
|
export class ColorAlphaSplitter {
|
||||||
static forceCpu = false;
|
static forceCpu = true;
|
||||||
|
|
||||||
canvas: OffscreenCanvas | HTMLCanvasElement | null = null;
|
canvas: OffscreenCanvas | HTMLCanvasElement | null = null;
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,8 @@ test('Can encode transparent video, forced CPU path', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Can encode video with alternating transparency', async () => {
|
test('Can encode video with alternating transparency', async () => {
|
||||||
|
// This test is already brutal when it comes to finding async race conditions, so run it thrice to be MORE brutal
|
||||||
|
for (let j = 0; j < 3; j++) {
|
||||||
const output = new Output({
|
const output = new Output({
|
||||||
format: new WebMOutputFormat(),
|
format: new WebMOutputFormat(),
|
||||||
target: new BufferTarget(),
|
target: new BufferTarget(),
|
||||||
@@ -270,6 +272,7 @@ test('Can encode video with alternating transparency', async () => {
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Can encode transparent video with odd dimensions', async () => {
|
test('Can encode transparent video with odd dimensions', async () => {
|
||||||
|
|||||||
@@ -593,7 +593,7 @@ describe('Video', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('HEVC conversion roundtrip', { timeout: 20_000 }, async () => {
|
test('HEVC conversion roundtrip', { timeout: 20_000 }, async () => {
|
||||||
await conversionRoundtrip('hevc');
|
await conversionRoundtrip('hevc', 1); // GitHub is extremely slow on this one
|
||||||
});
|
});
|
||||||
|
|
||||||
test('VP8 conversion roundtrip', { timeout: 20_000 }, async () => {
|
test('VP8 conversion roundtrip', { timeout: 20_000 }, async () => {
|
||||||
@@ -608,7 +608,7 @@ describe('Video', async () => {
|
|||||||
await conversionRoundtrip('av1');
|
await conversionRoundtrip('av1');
|
||||||
});
|
});
|
||||||
|
|
||||||
const conversionRoundtrip = async (codec: VideoCodec) => {
|
const conversionRoundtrip = async (codec: VideoCodec, duration?: number) => {
|
||||||
using input = new Input({
|
using input = new Input({
|
||||||
source: new FilePathSource('./test/public/video.mp4'),
|
source: new FilePathSource('./test/public/video.mp4'),
|
||||||
formats: ALL_FORMATS,
|
formats: ALL_FORMATS,
|
||||||
@@ -640,6 +640,9 @@ describe('Video', async () => {
|
|||||||
}, audio: {
|
}, audio: {
|
||||||
discard: true,
|
discard: true,
|
||||||
},
|
},
|
||||||
|
trim: {
|
||||||
|
end: duration,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
await conversion.execute();
|
await conversion.execute();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user