UNPKG

@yume-chan/scrcpy-decoder-webcodecs

Version:

Raw H.264 stream decoder and renderer using WebCodecs API (requires modern browser).

35 lines 1.22 kB
export class H26xDecoder { #config; #decoder; constructor(decoder) { this.#decoder = decoder; } decode(packet) { if (packet.type === "configuration") { this.#config = packet.data; this.configure(packet.data); return; } // For H.264 and H.265, when the stream is in Annex B format // (which Scrcpy uses, as Android MediaCodec produces), // configuration data needs to be combined with the first frame data. // https://www.w3.org/TR/webcodecs-avc-codec-registration/#encodedvideochunk-type let data; if (this.#config !== undefined) { data = new Uint8Array(this.#config.length + packet.data.length); data.set(this.#config, 0); data.set(packet.data, this.#config.length); this.#config = undefined; } else { data = packet.data; } this.#decoder.decode(new EncodedVideoChunk({ // Treat `undefined` as `key`, otherwise won't decode. type: packet.keyframe === false ? "delta" : "key", timestamp: 0, data, })); } } //# sourceMappingURL=h26x.js.map