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,4 +1,5 @@
import { PromiseResolver } from "@yume-chan/async";
import { EventEmitter } from "@yume-chan/event";
import type { ScrcpyMediaStreamPacket } from "@yume-chan/scrcpy";
import {
AndroidAvcLevel,
@ -51,6 +52,11 @@ export class TinyH264Decoder implements ScrcpyVideoDecoder {
return this.#renderer;
}
#sizeChanged = new EventEmitter<{ width: number; height: number }>();
get sizeChanged() {
return this.#sizeChanged.event;
}
#frameRendered = 0;
get frameRendered() {
return this.#frameRendered;
@ -112,6 +118,10 @@ export class TinyH264Decoder implements ScrcpyVideoDecoder {
cropLeft,
cropTop,
} = h264ParseConfiguration(data);
this.#sizeChanged.fire({
width: croppedWidth,
height: croppedHeight,
});
// H.264 Baseline profile only supports YUV 420 pixel format
const chromaWidth = encodedWidth / 2;

View file

@ -1,4 +1,4 @@
import type { Disposable } from "@yume-chan/event";
import type { Disposable, Event } from "@yume-chan/event";
import type {
ScrcpyMediaStreamPacket,
ScrcpyVideoCodecId,
@ -12,6 +12,7 @@ export interface ScrcpyVideoDecoderCapability {
export interface ScrcpyVideoDecoder extends Disposable {
readonly renderer: HTMLElement;
readonly sizeChanged: Event<{ width: number; height: number }>;
readonly frameRendered: number;
readonly frameSkipped: number;
readonly writable: WritableStream<ScrcpyMediaStreamPacket>;