@yume-chan/scrcpy-decoder-webcodecs 0.0.23 → 1.0.0
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/CHANGELOG.md +40 -2
- package/LICENSE +1 -1
- package/README.md +49 -29
- package/esm/index.d.ts +1 -20
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -181
- package/esm/index.js.map +1 -1
- package/esm/video/codec/av1.d.ts +8 -0
- package/esm/video/codec/av1.d.ts.map +1 -0
- package/esm/video/codec/av1.js +71 -0
- package/esm/video/codec/av1.js.map +1 -0
- package/esm/video/codec/h264.d.ts +7 -0
- package/esm/video/codec/h264.d.ts.map +1 -0
- package/esm/video/codec/h264.js +27 -0
- package/esm/video/codec/h264.js.map +1 -0
- package/esm/video/codec/h265.d.ts +7 -0
- package/esm/video/codec/h265.d.ts.map +1 -0
- package/esm/video/codec/h265.js +33 -0
- package/esm/video/codec/h265.js.map +1 -0
- package/esm/video/codec/h26x.d.ts +9 -0
- package/esm/video/codec/h26x.d.ts.map +1 -0
- package/esm/video/codec/h26x.js +35 -0
- package/esm/video/codec/h26x.js.map +1 -0
- package/esm/video/codec/index.d.ts +7 -0
- package/esm/video/codec/index.d.ts.map +1 -0
- package/esm/video/codec/index.js +7 -0
- package/esm/video/codec/index.js.map +1 -0
- package/esm/video/codec/type.d.ts +8 -0
- package/esm/video/codec/type.d.ts.map +1 -0
- package/esm/video/codec/type.js +2 -0
- package/esm/video/codec/type.js.map +1 -0
- package/esm/video/codec/utils.d.ts +4 -0
- package/esm/video/codec/utils.d.ts.map +1 -0
- package/esm/video/codec/utils.js +10 -0
- package/esm/video/codec/utils.js.map +1 -0
- package/esm/video/decoder.d.ts +35 -0
- package/esm/video/decoder.d.ts.map +1 -0
- package/esm/video/decoder.js +240 -0
- package/esm/video/decoder.js.map +1 -0
- package/esm/video/index.d.ts +4 -0
- package/esm/video/index.d.ts.map +1 -0
- package/esm/video/index.js +4 -0
- package/esm/video/index.js.map +1 -0
- package/esm/video/render/bitmap.d.ts +7 -0
- package/esm/video/render/bitmap.d.ts.map +1 -0
- package/esm/video/render/bitmap.js +15 -0
- package/esm/video/render/bitmap.js.map +1 -0
- package/esm/video/render/canvas.d.ts +9 -0
- package/esm/video/render/canvas.d.ts.map +1 -0
- package/esm/video/render/canvas.js +22 -0
- package/esm/video/render/canvas.js.map +1 -0
- package/esm/video/render/index.d.ts +6 -0
- package/esm/video/render/index.d.ts.map +1 -0
- package/esm/video/render/index.js +7 -0
- package/esm/video/render/index.js.map +1 -0
- package/esm/video/render/insertable-stream.d.ts +10 -0
- package/esm/video/render/insertable-stream.d.ts.map +1 -0
- package/esm/video/render/insertable-stream.js +45 -0
- package/esm/video/render/insertable-stream.js.map +1 -0
- package/esm/video/render/type.d.ts +6 -0
- package/esm/video/render/type.d.ts.map +1 -0
- package/esm/video/render/type.js +2 -0
- package/esm/video/render/type.js.map +1 -0
- package/esm/video/render/webgl.d.ts +17 -0
- package/esm/video/render/webgl.d.ts.map +1 -0
- package/esm/{webgl.js → video/render/webgl.js} +47 -26
- package/esm/video/render/webgl.js.map +1 -0
- package/package.json +12 -17
- package/src/index.ts +1 -247
- package/src/video/codec/av1.ts +101 -0
- package/src/video/codec/h264.ts +42 -0
- package/src/video/codec/h265.ts +50 -0
- package/src/video/codec/h26x.ts +45 -0
- package/src/video/codec/index.ts +6 -0
- package/src/video/codec/type.ts +12 -0
- package/src/video/codec/utils.ts +11 -0
- package/src/video/decoder.ts +307 -0
- package/src/video/index.ts +3 -0
- package/src/video/render/bitmap.ts +18 -0
- package/src/video/render/canvas.ts +29 -0
- package/src/video/render/index.ts +7 -0
- package/src/video/render/insertable-stream.ts +62 -0
- package/src/video/render/type.ts +7 -0
- package/src/{webgl.ts → video/render/webgl.ts} +67 -30
- package/tsconfig.build.json +4 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/CHANGELOG.json +0 -74
- package/esm/bitmap.d.ts +0 -7
- package/esm/bitmap.d.ts.map +0 -1
- package/esm/bitmap.js +0 -17
- package/esm/bitmap.js.map +0 -1
- package/esm/renderer.d.ts +0 -4
- package/esm/renderer.d.ts.map +0 -1
- package/esm/renderer.js +0 -2
- package/esm/renderer.js.map +0 -1
- package/esm/webgl.d.ts +0 -9
- package/esm/webgl.d.ts.map +0 -1
- package/esm/webgl.js.map +0 -1
- package/src/bitmap.ts +0 -24
- package/src/renderer.ts +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/video/codec/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/video/codec/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ScrcpyMediaStreamPacket } from "@yume-chan/scrcpy";
|
|
2
|
+
export interface CodecDecoder {
|
|
3
|
+
decode(packet: ScrcpyMediaStreamPacket): void;
|
|
4
|
+
}
|
|
5
|
+
export interface CodecDecoderConstructor {
|
|
6
|
+
new (decoder: VideoDecoder, updateSize: (width: number, height: number) => void): CodecDecoder;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/video/codec/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAEjE,MAAM,WAAW,YAAY;IACzB,MAAM,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAAC;CACjD;AAED,MAAM,WAAW,uBAAuB;IACpC,KACI,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GACpD,YAAY,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/video/codec/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/video/codec/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,UAEtC;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,UAEzC;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,UAE7C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function hexDigits(value) {
|
|
2
|
+
return value.toString(16).toUpperCase();
|
|
3
|
+
}
|
|
4
|
+
export function hexTwoDigits(value) {
|
|
5
|
+
return value.toString(16).toUpperCase().padStart(2, "0");
|
|
6
|
+
}
|
|
7
|
+
export function decimalTwoDigits(value) {
|
|
8
|
+
return value.toString(10).padStart(2, "0");
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/video/codec/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC1C,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ScrcpyMediaStreamPacket } from "@yume-chan/scrcpy";
|
|
2
|
+
import { ScrcpyVideoCodecId } from "@yume-chan/scrcpy";
|
|
3
|
+
import type { ScrcpyVideoDecoder, ScrcpyVideoDecoderCapability } from "@yume-chan/scrcpy-decoder-tinyh264";
|
|
4
|
+
import { WritableStream } from "@yume-chan/stream-extra";
|
|
5
|
+
import type { WebCodecsVideoDecoderRenderer } from "./render/index.js";
|
|
6
|
+
export declare class WebCodecsVideoDecoder implements ScrcpyVideoDecoder {
|
|
7
|
+
#private;
|
|
8
|
+
static get isSupported(): boolean;
|
|
9
|
+
static readonly capabilities: Record<string, ScrcpyVideoDecoderCapability>;
|
|
10
|
+
get codec(): ScrcpyVideoCodecId;
|
|
11
|
+
get writable(): WritableStream<ScrcpyMediaStreamPacket>;
|
|
12
|
+
get renderer(): WebCodecsVideoDecoderRenderer;
|
|
13
|
+
get framesRendered(): number;
|
|
14
|
+
get framesSkipped(): number;
|
|
15
|
+
get sizeChanged(): import("@yume-chan/event").AddEventListener<{
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new WebCodecs video decoder.
|
|
21
|
+
*/
|
|
22
|
+
constructor({ codec, renderer }: WebCodecsVideoDecoder.Options);
|
|
23
|
+
snapshot(): Promise<Blob | undefined>;
|
|
24
|
+
dispose(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare namespace WebCodecsVideoDecoder {
|
|
27
|
+
interface Options {
|
|
28
|
+
/**
|
|
29
|
+
* The video codec to decode
|
|
30
|
+
*/
|
|
31
|
+
codec: ScrcpyVideoCodecId;
|
|
32
|
+
renderer: WebCodecsVideoDecoderRenderer;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoder.d.ts","sourceRoot":"","sources":["../../src/video/decoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EACR,kBAAkB,EAClB,4BAA4B,EAC/B,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAIzD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAsFvE,qBAAa,qBAAsB,YAAW,kBAAkB;;IAC5D,MAAM,KAAK,WAAW,YAErB;IAED,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,4BAA4B,CAAC,CAKpE;IAGN,IAAI,KAAK,uBAER;IAKD,IAAI,QAAQ,4CAEX;IAMD,IAAI,QAAQ,kCAEX;IAID,IAAI,cAAc,WAEjB;IAGD,IAAI,aAAa,WAEhB;IAGD,IAAI,WAAW;eAD0B,MAAM;gBAAU,MAAM;gBAG9D;IAUD;;OAEG;gBACS,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,qBAAqB,CAAC,OAAO;IAsHxD,QAAQ;IAYd,OAAO;CAQV;AAED,yBAAiB,qBAAqB,CAAC;IACnC,UAAiB,OAAO;QACpB;;WAEG;QACH,KAAK,EAAE,kBAAkB,CAAC;QAE1B,QAAQ,EAAE,6BAA6B,CAAC;KAC3C;CACJ"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { EventEmitter } from "@yume-chan/event";
|
|
2
|
+
import { ScrcpyVideoCodecId } from "@yume-chan/scrcpy";
|
|
3
|
+
import { WritableStream } from "@yume-chan/stream-extra";
|
|
4
|
+
import { Av1Codec, H264Decoder, H265Decoder } from "./codec/index.js";
|
|
5
|
+
class Pool {
|
|
6
|
+
#controller;
|
|
7
|
+
#readable = new ReadableStream({
|
|
8
|
+
start: (controller) => {
|
|
9
|
+
this.#controller = controller;
|
|
10
|
+
},
|
|
11
|
+
pull: (controller) => {
|
|
12
|
+
controller.enqueue(this.#initializer());
|
|
13
|
+
},
|
|
14
|
+
}, { highWaterMark: 0 });
|
|
15
|
+
#reader = this.#readable.getReader();
|
|
16
|
+
#initializer;
|
|
17
|
+
#size = 0;
|
|
18
|
+
#capacity;
|
|
19
|
+
constructor(initializer, capacity) {
|
|
20
|
+
this.#initializer = initializer;
|
|
21
|
+
this.#capacity = capacity;
|
|
22
|
+
}
|
|
23
|
+
async borrow() {
|
|
24
|
+
const result = await this.#reader.read();
|
|
25
|
+
return result.value;
|
|
26
|
+
}
|
|
27
|
+
return(value) {
|
|
28
|
+
if (this.#size < this.#capacity) {
|
|
29
|
+
this.#controller.enqueue(value);
|
|
30
|
+
this.#size += 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class VideoFrameCapturer {
|
|
35
|
+
#canvas;
|
|
36
|
+
#context;
|
|
37
|
+
constructor() {
|
|
38
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
39
|
+
this.#canvas = new OffscreenCanvas(1, 1);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.#canvas = document.createElement("canvas");
|
|
43
|
+
this.#canvas.width = 1;
|
|
44
|
+
this.#canvas.height = 1;
|
|
45
|
+
}
|
|
46
|
+
this.#context = this.#canvas.getContext("bitmaprenderer", {
|
|
47
|
+
alpha: false,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async capture(frame) {
|
|
51
|
+
this.#canvas.width = frame.displayWidth;
|
|
52
|
+
this.#canvas.height = frame.displayHeight;
|
|
53
|
+
const bitmap = await createImageBitmap(frame);
|
|
54
|
+
this.#context.transferFromImageBitmap(bitmap);
|
|
55
|
+
if (this.#canvas instanceof OffscreenCanvas) {
|
|
56
|
+
return await this.#canvas.convertToBlob({
|
|
57
|
+
type: "image/png",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
this.#canvas.toBlob((blob) => {
|
|
63
|
+
if (!blob) {
|
|
64
|
+
reject(new Error("Failed to convert canvas to blob"));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
resolve(blob);
|
|
68
|
+
}
|
|
69
|
+
}, "image/png");
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const VideoFrameCapturerPool =
|
|
75
|
+
/* #__PURE__ */
|
|
76
|
+
new Pool(() => new VideoFrameCapturer(), 4);
|
|
77
|
+
export class WebCodecsVideoDecoder {
|
|
78
|
+
static get isSupported() {
|
|
79
|
+
return typeof globalThis.VideoDecoder !== "undefined";
|
|
80
|
+
}
|
|
81
|
+
static capabilities = {
|
|
82
|
+
h264: {},
|
|
83
|
+
h265: {},
|
|
84
|
+
av1: {},
|
|
85
|
+
};
|
|
86
|
+
#codec;
|
|
87
|
+
get codec() {
|
|
88
|
+
return this.#codec;
|
|
89
|
+
}
|
|
90
|
+
#codecDecoder;
|
|
91
|
+
#writable;
|
|
92
|
+
get writable() {
|
|
93
|
+
return this.#writable;
|
|
94
|
+
}
|
|
95
|
+
#error;
|
|
96
|
+
#controller;
|
|
97
|
+
#renderer;
|
|
98
|
+
get renderer() {
|
|
99
|
+
return this.#renderer;
|
|
100
|
+
}
|
|
101
|
+
#framesDraw = 0;
|
|
102
|
+
#framesPresented = 0;
|
|
103
|
+
get framesRendered() {
|
|
104
|
+
return this.#framesPresented;
|
|
105
|
+
}
|
|
106
|
+
#framesSkipped = 0;
|
|
107
|
+
get framesSkipped() {
|
|
108
|
+
return this.#framesSkipped;
|
|
109
|
+
}
|
|
110
|
+
#sizeChanged = new EventEmitter();
|
|
111
|
+
get sizeChanged() {
|
|
112
|
+
return this.#sizeChanged.event;
|
|
113
|
+
}
|
|
114
|
+
#decoder;
|
|
115
|
+
#drawing = false;
|
|
116
|
+
#nextFrame;
|
|
117
|
+
#captureFrame;
|
|
118
|
+
#animationFrameId = 0;
|
|
119
|
+
/**
|
|
120
|
+
* Create a new WebCodecs video decoder.
|
|
121
|
+
*/
|
|
122
|
+
constructor({ codec, renderer }) {
|
|
123
|
+
this.#codec = codec;
|
|
124
|
+
this.#renderer = renderer;
|
|
125
|
+
this.#decoder = new VideoDecoder({
|
|
126
|
+
output: (frame) => {
|
|
127
|
+
this.#captureFrame?.close();
|
|
128
|
+
// PERF: `VideoFrame#clone` is cheap
|
|
129
|
+
this.#captureFrame = frame.clone();
|
|
130
|
+
if (this.#drawing) {
|
|
131
|
+
if (this.#nextFrame) {
|
|
132
|
+
this.#nextFrame.close();
|
|
133
|
+
this.#framesSkipped += 1;
|
|
134
|
+
}
|
|
135
|
+
this.#nextFrame = frame;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
void this.#draw(frame);
|
|
139
|
+
},
|
|
140
|
+
error: (error) => {
|
|
141
|
+
this.#setError(error);
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
switch (this.#codec) {
|
|
145
|
+
case ScrcpyVideoCodecId.H264:
|
|
146
|
+
this.#codecDecoder = new H264Decoder(this.#decoder, this.#updateSize);
|
|
147
|
+
break;
|
|
148
|
+
case ScrcpyVideoCodecId.H265:
|
|
149
|
+
this.#codecDecoder = new H265Decoder(this.#decoder, this.#updateSize);
|
|
150
|
+
break;
|
|
151
|
+
case ScrcpyVideoCodecId.AV1:
|
|
152
|
+
this.#codecDecoder = new Av1Codec(this.#decoder, this.#updateSize);
|
|
153
|
+
break;
|
|
154
|
+
default:
|
|
155
|
+
throw new Error(`Unsupported codec: ${this.#codec}`);
|
|
156
|
+
}
|
|
157
|
+
this.#writable = new WritableStream({
|
|
158
|
+
start: (controller) => {
|
|
159
|
+
if (this.#error) {
|
|
160
|
+
controller.error(this.#error);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
this.#controller = controller;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
write: (packet) => {
|
|
167
|
+
this.#codecDecoder.decode(packet);
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
this.#onVerticalSync();
|
|
171
|
+
}
|
|
172
|
+
#setError(error) {
|
|
173
|
+
if (this.#controller) {
|
|
174
|
+
try {
|
|
175
|
+
this.#controller.error(error);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// ignore
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
this.#error = error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async #draw(frame) {
|
|
186
|
+
try {
|
|
187
|
+
this.#drawing = true;
|
|
188
|
+
// PERF: Draw every frame to minimize latency at cost of performance.
|
|
189
|
+
// When multiple frames are drawn in one vertical sync interval,
|
|
190
|
+
// only the last one is visible to users.
|
|
191
|
+
// But this ensures users can always see the most up-to-date screen.
|
|
192
|
+
// This is also the behavior of official Scrcpy client.
|
|
193
|
+
// https://github.com/Genymobile/scrcpy/issues/3679
|
|
194
|
+
this.#updateSize(frame.displayWidth, frame.displayHeight);
|
|
195
|
+
await this.#renderer.draw(frame);
|
|
196
|
+
this.#framesDraw += 1;
|
|
197
|
+
frame.close();
|
|
198
|
+
if (this.#nextFrame) {
|
|
199
|
+
const frame = this.#nextFrame;
|
|
200
|
+
this.#nextFrame = undefined;
|
|
201
|
+
await this.#draw(frame);
|
|
202
|
+
}
|
|
203
|
+
this.#drawing = false;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
this.#setError(error);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
#updateSize = (width, height) => {
|
|
210
|
+
this.#renderer.setSize(width, height);
|
|
211
|
+
this.#sizeChanged.fire({ width, height });
|
|
212
|
+
};
|
|
213
|
+
#onVerticalSync = () => {
|
|
214
|
+
if (this.#framesDraw > 0) {
|
|
215
|
+
this.#framesPresented += 1;
|
|
216
|
+
this.#framesSkipped += this.#framesDraw - 1;
|
|
217
|
+
this.#framesDraw = 0;
|
|
218
|
+
}
|
|
219
|
+
this.#animationFrameId = requestAnimationFrame(this.#onVerticalSync);
|
|
220
|
+
};
|
|
221
|
+
async snapshot() {
|
|
222
|
+
const frame = this.#captureFrame;
|
|
223
|
+
if (!frame) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
const capturer = await VideoFrameCapturerPool.borrow();
|
|
227
|
+
const result = await capturer.capture(frame);
|
|
228
|
+
VideoFrameCapturerPool.return(capturer);
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
dispose() {
|
|
232
|
+
cancelAnimationFrame(this.#animationFrameId);
|
|
233
|
+
if (this.#decoder.state !== "closed") {
|
|
234
|
+
this.#decoder.close();
|
|
235
|
+
}
|
|
236
|
+
this.#nextFrame?.close();
|
|
237
|
+
this.#captureFrame?.close();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoder.js","sourceRoot":"","sources":["../../src/video/decoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAMvD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAItE,MAAM,IAAI;IACN,WAAW,CAAsC;IACjD,SAAS,GAAG,IAAI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I,IAAI,CAAC,QAAQ,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACnC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/video/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/video/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CanvasWebCodecsDecoderRenderer } from "./canvas.js";
|
|
2
|
+
export declare class BitmapWebCodecsDecoderRenderer extends CanvasWebCodecsDecoderRenderer {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(canvas?: HTMLCanvasElement | OffscreenCanvas);
|
|
5
|
+
draw(frame: VideoFrame): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=bitmap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmap.d.ts","sourceRoot":"","sources":["../../../src/video/render/bitmap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAE7D,qBAAa,8BAA+B,SAAQ,8BAA8B;;gBAGlE,MAAM,CAAC,EAAE,iBAAiB,GAAG,eAAe;IAQlD,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAI/C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CanvasWebCodecsDecoderRenderer } from "./canvas.js";
|
|
2
|
+
export class BitmapWebCodecsDecoderRenderer extends CanvasWebCodecsDecoderRenderer {
|
|
3
|
+
#context;
|
|
4
|
+
constructor(canvas) {
|
|
5
|
+
super(canvas);
|
|
6
|
+
this.#context = this.canvas.getContext("bitmaprenderer", {
|
|
7
|
+
alpha: false,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
async draw(frame) {
|
|
11
|
+
const bitmap = await createImageBitmap(frame);
|
|
12
|
+
this.#context.transferFromImageBitmap(bitmap);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=bitmap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmap.js","sourceRoot":"","sources":["../../../src/video/render/bitmap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAE7D,MAAM,OAAO,8BAA+B,SAAQ,8BAA8B;IAC9E,QAAQ,CAA8B;IAEtC,YAAY,MAA4C;QACpD,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,gBAAgB,EAAE;YACrD,KAAK,EAAE,KAAK;SACf,CAAE,CAAC;IACR,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAiB;QACxB,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;CACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WebCodecsVideoDecoderRenderer } from "./type.js";
|
|
2
|
+
export declare abstract class CanvasWebCodecsDecoderRenderer implements WebCodecsVideoDecoderRenderer {
|
|
3
|
+
#private;
|
|
4
|
+
get canvas(): HTMLCanvasElement | OffscreenCanvas;
|
|
5
|
+
constructor(canvas?: HTMLCanvasElement | OffscreenCanvas);
|
|
6
|
+
setSize(width: number, height: number): void;
|
|
7
|
+
abstract draw(frame: VideoFrame): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=canvas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../../src/video/render/canvas.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAE/D,8BAAsB,8BAClB,YAAW,6BAA6B;;IAGxC,IAAI,MAAM,wCAET;gBAEW,MAAM,CAAC,EAAE,iBAAiB,GAAG,eAAe;IAQxD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAO5C,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAClD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createCanvas } from "@yume-chan/scrcpy-decoder-tinyh264";
|
|
2
|
+
export class CanvasWebCodecsDecoderRenderer {
|
|
3
|
+
#canvas;
|
|
4
|
+
get canvas() {
|
|
5
|
+
return this.#canvas;
|
|
6
|
+
}
|
|
7
|
+
constructor(canvas) {
|
|
8
|
+
if (canvas) {
|
|
9
|
+
this.#canvas = canvas;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
this.#canvas = createCanvas();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
setSize(width, height) {
|
|
16
|
+
if (this.#canvas.width !== width || this.#canvas.height !== height) {
|
|
17
|
+
this.#canvas.width = width;
|
|
18
|
+
this.#canvas.height = height;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=canvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../../src/video/render/canvas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAIlE,MAAM,OAAgB,8BAA8B;IAGhD,OAAO,CAAsC;IAC7C,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,YAAY,MAA4C;QACpD,IAAI,MAAM,EAAE,CAAC;YACT,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAC1B,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,OAAO,GAAG,YAAY,EAAE,CAAC;QAClC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,KAAa,EAAE,MAAc;QACjC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YACjE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;YAC3B,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QACjC,CAAC;IACL,CAAC;CAGJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/video/render/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/video/render/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAE5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WebCodecsVideoDecoderRenderer } from "./type.js";
|
|
2
|
+
export declare class InsertableStreamWebCodecsDecoderRenderer implements WebCodecsVideoDecoderRenderer {
|
|
3
|
+
#private;
|
|
4
|
+
static get isSupported(): boolean;
|
|
5
|
+
get element(): HTMLVideoElement;
|
|
6
|
+
constructor(element?: HTMLVideoElement);
|
|
7
|
+
setSize(width: number, height: number): void;
|
|
8
|
+
draw(frame: VideoFrame): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=insertable-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insertable-stream.d.ts","sourceRoot":"","sources":["../../../src/video/render/insertable-stream.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAQ/D,qBAAa,wCACT,YAAW,6BAA6B;;IAExC,MAAM,KAAK,WAAW,YAErB;IAGD,IAAI,OAAO,qBAEV;gBAMW,OAAO,CAAC,EAAE,gBAAgB;IAyBtC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAOtC,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAG/C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// cspell: ignore insertable
|
|
2
|
+
export class InsertableStreamWebCodecsDecoderRenderer {
|
|
3
|
+
static get isSupported() {
|
|
4
|
+
return typeof MediaStreamTrackGenerator !== "undefined";
|
|
5
|
+
}
|
|
6
|
+
#element;
|
|
7
|
+
get element() {
|
|
8
|
+
return this.#element;
|
|
9
|
+
}
|
|
10
|
+
#generator;
|
|
11
|
+
#writer;
|
|
12
|
+
#stream;
|
|
13
|
+
constructor(element) {
|
|
14
|
+
if (element) {
|
|
15
|
+
this.#element = element;
|
|
16
|
+
}
|
|
17
|
+
else if (typeof document !== "undefined") {
|
|
18
|
+
this.#element = document.createElement("video");
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
throw new Error("no video element input found nor any video element can be created");
|
|
22
|
+
}
|
|
23
|
+
this.#element.muted = true;
|
|
24
|
+
this.#element.autoplay = true;
|
|
25
|
+
this.#element.disablePictureInPicture = true;
|
|
26
|
+
this.#element.disableRemotePlayback = true;
|
|
27
|
+
// The spec replaced `MediaStreamTrackGenerator` with `VideoTrackGenerator`.
|
|
28
|
+
// But Chrome has not implemented it yet.
|
|
29
|
+
// https://issues.chromium.org/issues/40058895
|
|
30
|
+
this.#generator = new MediaStreamTrackGenerator({ kind: "video" });
|
|
31
|
+
this.#writer = this.#generator.writable.getWriter();
|
|
32
|
+
this.#stream = new MediaStream([this.#generator]);
|
|
33
|
+
this.#element.srcObject = this.#stream;
|
|
34
|
+
}
|
|
35
|
+
setSize(width, height) {
|
|
36
|
+
if (this.#element.width !== width || this.#element.height !== height) {
|
|
37
|
+
this.#element.width = width;
|
|
38
|
+
this.#element.height = height;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async draw(frame) {
|
|
42
|
+
await this.#writer.write(frame);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=insertable-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insertable-stream.js","sourceRoot":"","sources":["../../../src/video/render/insertable-stream.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAU5B,MAAM,OAAO,wCAAwC;IAGjD,MAAM,KAAK,WAAW;QAClB,OAAO,OAAO,yBAAyB,KAAK,WAAW,CAAC;IAC5D,CAAC;IAED,QAAQ,CAAmB;IAC3B,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,UAAU,CAA4B;IACtC,OAAO,CAA0C;IACjD,OAAO,CAAc;IAErB,YAAY,OAA0B;QAClC,IAAI,OAAO,EAAE,CAAC;YACV,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAC5B,CAAC;aAAM,IAAI,OAAO,QAAQ,KAAK,WAAW,EAA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1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/video/render/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,WAAW,6BAA6B;IAC1C,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7C,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/video/render/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CanvasWebCodecsDecoderRenderer } from "./canvas.js";
|
|
2
|
+
export declare class WebGLWebCodecsDecoderRenderer extends CanvasWebCodecsDecoderRenderer {
|
|
3
|
+
#private;
|
|
4
|
+
static vertexShaderSource: string;
|
|
5
|
+
static fragmentShaderSource: string;
|
|
6
|
+
static get isSupported(): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new WebGL frame renderer.
|
|
9
|
+
* @param canvas The canvas to render frames to.
|
|
10
|
+
* @param enableCapture
|
|
11
|
+
* Whether to allow capturing the canvas content using APIs like `readPixels` and `toDataURL`.
|
|
12
|
+
* Enable this option may reduce performance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(canvas?: HTMLCanvasElement | OffscreenCanvas, enableCapture?: boolean);
|
|
15
|
+
draw(frame: VideoFrame): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=webgl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webgl.d.ts","sourceRoot":"","sources":["../../../src/video/render/webgl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAwB7D,qBAAa,6BAA8B,SAAQ,8BAA8B;;IAC7E,MAAM,CAAC,kBAAkB,SAW3B;IAEE,MAAM,CAAC,oBAAoB,SAQ7B;IAEE,MAAM,KAAK,WAAW,YAGrB;IAID;;;;;;OAMG;gBAEC,MAAM,CAAC,EAAE,iBAAiB,GAAG,eAAe,EAC5C,aAAa,CAAC,EAAE,OAAO;IA6D3B,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAgBzC"}
|