feat(decoder): add sizeChanged event

This commit is contained in:
Simon Chan 2024-01-08 19:01:40 +08:00
parent 4fbd24fc7f
commit bef336da08
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
4 changed files with 23 additions and 1 deletions

View file

@ -1,3 +1,4 @@
import { EventEmitter } from "@yume-chan/event";
import type {
ScrcpyMediaStreamDataPacket,
ScrcpyMediaStreamPacket,
@ -62,6 +63,11 @@ export class WebCodecsDecoder implements ScrcpyVideoDecoder {
return this.#frameSkipped;
}
#sizeChanged = new EventEmitter<{ width: number; height: number }>();
get sizeChanged() {
return this.#sizeChanged.event;
}
#context: CanvasRenderingContext2D;
#decoder: VideoDecoder;
#config: Uint8Array | undefined;
@ -132,6 +138,10 @@ export class WebCodecsDecoder implements ScrcpyVideoDecoder {
this.#renderer.width = croppedWidth;
this.#renderer.height = croppedHeight;
this.#sizeChanged.fire({
width: croppedWidth,
height: croppedHeight,
});
// https://www.rfc-editor.org/rfc/rfc6381#section-3.3
// ISO Base Media File Format Name Space