@yume-chan/scrcpy-decoder-webcodecs 2.5.0 → 3.0.0-beta.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/LICENSE +1 -1
- package/README.md +1 -1
- package/esm/video/codec/av1.d.ts +4 -6
- package/esm/video/codec/av1.d.ts.map +1 -1
- package/esm/video/codec/av1.js +28 -70
- package/esm/video/codec/av1.js.map +1 -1
- package/esm/video/codec/h264.d.ts +4 -6
- package/esm/video/codec/h264.d.ts.map +1 -1
- package/esm/video/codec/h264.js +13 -25
- package/esm/video/codec/h264.js.map +1 -1
- package/esm/video/codec/h265.d.ts +4 -6
- package/esm/video/codec/h265.d.ts.map +1 -1
- package/esm/video/codec/h265.js +15 -31
- package/esm/video/codec/h265.js.map +1 -1
- package/esm/video/codec/h26x.d.ts +9 -6
- package/esm/video/codec/h26x.d.ts.map +1 -1
- package/esm/video/codec/h26x.js +25 -31
- package/esm/video/codec/h26x.js.map +1 -1
- package/esm/video/codec/index.d.ts +0 -1
- package/esm/video/codec/index.d.ts.map +1 -1
- package/esm/video/codec/index.js +0 -1
- package/esm/video/codec/index.js.map +1 -1
- package/esm/video/codec/type.d.ts +23 -8
- package/esm/video/codec/type.d.ts.map +1 -1
- package/esm/video/decoder.d.ts +62 -15
- package/esm/video/decoder.d.ts.map +1 -1
- package/esm/video/decoder.js +170 -134
- package/esm/video/decoder.js.map +1 -1
- package/esm/video/index.d.ts +1 -0
- package/esm/video/index.d.ts.map +1 -1
- package/esm/video/index.js +1 -0
- package/esm/video/index.js.map +1 -1
- package/esm/video/render/auto-canvas.d.ts +26 -0
- package/esm/video/render/auto-canvas.d.ts.map +1 -0
- package/esm/video/render/auto-canvas.js +80 -0
- package/esm/video/render/auto-canvas.js.map +1 -0
- package/esm/video/render/bitmap.d.ts +2 -2
- package/esm/video/render/bitmap.d.ts.map +1 -1
- package/esm/video/render/bitmap.js +18 -8
- package/esm/video/render/bitmap.js.map +1 -1
- package/esm/video/render/canvas.d.ts +38 -4
- package/esm/video/render/canvas.d.ts.map +1 -1
- package/esm/video/render/canvas.js +97 -10
- package/esm/video/render/canvas.js.map +1 -1
- package/esm/video/render/flow-control.d.ts +32 -0
- package/esm/video/render/flow-control.d.ts.map +1 -0
- package/esm/video/render/flow-control.js +139 -0
- package/esm/video/render/flow-control.js.map +1 -0
- package/esm/video/render/index.d.ts +2 -0
- package/esm/video/render/index.d.ts.map +1 -1
- package/esm/video/render/index.js +2 -0
- package/esm/video/render/index.js.map +1 -1
- package/esm/video/render/insertable-stream.d.ts +15 -3
- package/esm/video/render/insertable-stream.d.ts.map +1 -1
- package/esm/video/render/insertable-stream.js +29 -11
- package/esm/video/render/insertable-stream.js.map +1 -1
- package/esm/video/render/redraw.d.ts +31 -0
- package/esm/video/render/redraw.d.ts.map +1 -0
- package/esm/video/render/redraw.js +75 -0
- package/esm/video/render/redraw.js.map +1 -0
- package/esm/video/render/type.d.ts +8 -2
- package/esm/video/render/type.d.ts.map +1 -1
- package/esm/video/render/webgl.d.ts +38 -5
- package/esm/video/render/webgl.d.ts.map +1 -1
- package/esm/video/render/webgl.js +228 -59
- package/esm/video/render/webgl.js.map +1 -1
- package/esm/video/utils/index.d.ts +4 -0
- package/esm/video/utils/index.d.ts.map +1 -0
- package/esm/video/utils/index.js +4 -0
- package/esm/video/utils/index.js.map +1 -0
- package/esm/video/utils/snapshot.d.ts +2 -0
- package/esm/video/utils/snapshot.d.ts.map +1 -0
- package/esm/video/utils/snapshot.js +18 -0
- package/esm/video/utils/snapshot.js.map +1 -0
- package/esm/video/utils/timestamp.d.ts +19 -0
- package/esm/video/utils/timestamp.d.ts.map +1 -0
- package/esm/video/utils/timestamp.js +87 -0
- package/esm/video/utils/timestamp.js.map +1 -0
- package/esm/video/utils/video-decoder-stream.d.ts +30 -0
- package/esm/video/utils/video-decoder-stream.d.ts.map +1 -0
- package/esm/video/utils/video-decoder-stream.js +284 -0
- package/esm/video/utils/video-decoder-stream.js.map +1 -0
- package/package.json +12 -11
- package/src/video/codec/av1.ts +40 -102
- package/src/video/codec/h264.ts +17 -41
- package/src/video/codec/h265.ts +18 -49
- package/src/video/codec/h26x.ts +41 -36
- package/src/video/codec/index.ts +0 -1
- package/src/video/codec/type.ts +32 -12
- package/src/video/decoder.ts +203 -165
- package/src/video/index.ts +1 -0
- package/src/video/render/auto-canvas.ts +105 -0
- package/src/video/render/bitmap.ts +23 -9
- package/src/video/render/canvas.ts +157 -12
- package/src/video/render/flow-control.ts +182 -0
- package/src/video/render/index.ts +2 -0
- package/src/video/render/insertable-stream.ts +50 -10
- package/src/video/render/redraw.ts +88 -0
- package/src/video/render/type.ts +10 -2
- package/src/video/render/webgl.ts +316 -80
- package/src/video/utils/index.ts +3 -0
- package/src/video/utils/snapshot.ts +22 -0
- package/src/video/utils/timestamp.ts +108 -0
- package/src/video/utils/video-decoder-stream.ts +406 -0
- package/tsconfig.build.json +0 -14
- package/CHANGELOG.md +0 -140
- package/esm/video/codec/utils.d.ts +0 -4
- package/esm/video/codec/utils.d.ts.map +0 -1
- package/esm/video/codec/utils.js +0 -10
- package/esm/video/codec/utils.js.map +0 -1
- package/esm/video/snapshot.d.ts +0 -6
- package/esm/video/snapshot.d.ts.map +0 -1
- package/esm/video/snapshot.js +0 -41
- package/esm/video/snapshot.js.map +0 -1
- package/src/video/codec/utils.ts +0 -11
- package/src/video/snapshot.ts +0 -41
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { CanvasVideoFrameRenderer } from "./canvas.js";
|
|
2
|
-
export declare class WebGLVideoFrameRenderer extends CanvasVideoFrameRenderer {
|
|
2
|
+
export declare class WebGLVideoFrameRenderer extends CanvasVideoFrameRenderer<WebGLVideoFrameRenderer.Options> {
|
|
3
3
|
#private;
|
|
4
|
-
static
|
|
5
|
-
static
|
|
4
|
+
static VertexShader: string;
|
|
5
|
+
static FragmentShader: string;
|
|
6
|
+
/**
|
|
7
|
+
* A single oversized triangle that covers the entire canvas.
|
|
8
|
+
*/
|
|
9
|
+
static Vertices: Float32Array<ArrayBuffer>;
|
|
6
10
|
static get isSupported(): boolean;
|
|
11
|
+
get type(): "hardware";
|
|
12
|
+
/**
|
|
13
|
+
* Fired when the WebGL context is lost and cannot be restored.
|
|
14
|
+
*
|
|
15
|
+
* The current renderer will be automatically disposed.
|
|
16
|
+
*/
|
|
17
|
+
get onContextLost(): import("@yume-chan/event").Event<void>;
|
|
7
18
|
/**
|
|
8
19
|
* Create a new WebGL frame renderer.
|
|
9
20
|
* @param canvas The canvas to render frames to.
|
|
@@ -11,7 +22,29 @@ export declare class WebGLVideoFrameRenderer extends CanvasVideoFrameRenderer {
|
|
|
11
22
|
* Whether to allow capturing the canvas content using APIs like `readPixels` and `toDataURL`.
|
|
12
23
|
* Enable this option may reduce performance.
|
|
13
24
|
*/
|
|
14
|
-
constructor(
|
|
15
|
-
|
|
25
|
+
constructor(options?: WebGLVideoFrameRenderer.Options);
|
|
26
|
+
snapshot(options?: ImageEncodeOptions): Promise<Blob | undefined>;
|
|
27
|
+
dispose(): undefined;
|
|
28
|
+
}
|
|
29
|
+
export declare namespace WebGLVideoFrameRenderer {
|
|
30
|
+
interface Options extends CanvasVideoFrameRenderer.Options {
|
|
31
|
+
/**
|
|
32
|
+
* Whether to allow capturing the canvas content using APIs
|
|
33
|
+
* like `readPixels` and `toDataURL`.
|
|
34
|
+
*
|
|
35
|
+
* Enabling this option may reduce performance.
|
|
36
|
+
*/
|
|
37
|
+
enableCapture?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The timeout in milliseconds to wait for context restoration
|
|
40
|
+
* before firing `onContextLost`.
|
|
41
|
+
*
|
|
42
|
+
* When set to 0, also disables automatic context restoration,
|
|
43
|
+
* `onContextLost` will be fired immediately when the context is lost.
|
|
44
|
+
*
|
|
45
|
+
* Default is 3000.
|
|
46
|
+
*/
|
|
47
|
+
contextRestoreTimeout?: number;
|
|
48
|
+
}
|
|
16
49
|
}
|
|
17
50
|
//# sourceMappingURL=webgl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl.d.ts","sourceRoot":"","sources":["../../../src/video/render/webgl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webgl.d.ts","sourceRoot":"","sources":["../../../src/video/render/webgl.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAkDvD,qBAAa,uBAAwB,SAAQ,wBAAwB,CAAC,uBAAuB,CAAC,OAAO,CAAC;;IAClG,MAAM,CAAC,YAAY,SAarB;IAEE,MAAM,CAAC,cAAc,SAwEvB;IAEE;;OAEG;IACH,MAAM,CAAC,QAAQ,4BAAwD;IAEvE,MAAM,KAAK,WAAW,YAMrB;IAED,IAAa,IAAI,IACN,UAAU,CACpB;IAID;;;;OAIG;IACH,IAAI,aAAa,2CAEhB;IAWD;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE,uBAAuB,CAAC,OAAO;IAuItC,QAAQ,CACnB,OAAO,CAAC,EAAE,kBAAkB,GAC7B,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;IAOnB,OAAO,IAAI,SAAS;CAkBhC;AAED,yBAAiB,uBAAuB,CAAC;IACrC,UAAiB,OAAQ,SAAQ,wBAAwB,CAAC,OAAO;QAC7D;;;;;WAKG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;QAExB;;;;;;;;WAQG;QACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;KAClC;CACJ"}
|
|
@@ -1,46 +1,161 @@
|
|
|
1
|
-
|
|
1
|
+
// cspell: ignore highp
|
|
2
|
+
// cspell: ignore mediump
|
|
3
|
+
import { StickyEventEmitter } from "@yume-chan/event";
|
|
4
|
+
import { glCreateContext, glIsSupported, glLoseContext, } from "@yume-chan/scrcpy-decoder-shared";
|
|
2
5
|
import { CanvasVideoFrameRenderer } from "./canvas.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
function createShader(gl, type, source) {
|
|
7
|
+
const shader = gl.createShader(type);
|
|
8
|
+
gl.shaderSource(shader, source);
|
|
9
|
+
gl.compileShader(shader);
|
|
10
|
+
return shader;
|
|
11
|
+
}
|
|
12
|
+
function createProgram(gl, vertexShaderSource, fragmentShaderSource) {
|
|
13
|
+
const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexShaderSource);
|
|
14
|
+
const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);
|
|
15
|
+
const program = gl.createProgram();
|
|
16
|
+
gl.attachShader(program, vertexShader);
|
|
17
|
+
gl.attachShader(program, fragmentShader);
|
|
18
|
+
gl.linkProgram(program);
|
|
19
|
+
try {
|
|
20
|
+
if (gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
21
|
+
return program;
|
|
22
|
+
}
|
|
23
|
+
// Don't check shader compile status unless linking fails
|
|
24
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#dont_check_shader_compile_status_unless_linking_fails
|
|
25
|
+
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
|
26
|
+
throw new Error(gl.getShaderInfoLog(vertexShader));
|
|
27
|
+
}
|
|
28
|
+
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
|
29
|
+
throw new Error(gl.getShaderInfoLog(fragmentShader));
|
|
30
|
+
}
|
|
31
|
+
throw new Error(gl.getProgramInfoLog(program));
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
// Delete objects eagerly
|
|
35
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#delete_objects_eagerly
|
|
36
|
+
gl.deleteShader(vertexShader);
|
|
37
|
+
gl.deleteShader(fragmentShader);
|
|
38
|
+
}
|
|
16
39
|
}
|
|
17
40
|
export class WebGLVideoFrameRenderer extends CanvasVideoFrameRenderer {
|
|
18
|
-
static
|
|
41
|
+
static VertexShader = `
|
|
19
42
|
attribute vec2 xy;
|
|
20
43
|
|
|
21
44
|
varying highp vec2 uv;
|
|
22
45
|
|
|
23
46
|
void main(void) {
|
|
24
47
|
gl_Position = vec4(xy, 0.0, 1.0);
|
|
48
|
+
|
|
25
49
|
// Map vertex coordinates (-1 to +1) to UV coordinates (0 to 1).
|
|
50
|
+
uv = xy * 0.5 + 0.5;
|
|
26
51
|
// UV coordinates are Y-flipped relative to vertex coordinates.
|
|
27
|
-
uv =
|
|
52
|
+
uv.y = 1.0 - uv.y;
|
|
28
53
|
}
|
|
29
54
|
`;
|
|
30
|
-
static
|
|
31
|
-
|
|
55
|
+
static FragmentShader = `
|
|
56
|
+
precision mediump float;
|
|
32
57
|
|
|
33
|
-
uniform sampler2D
|
|
58
|
+
uniform sampler2D source;
|
|
59
|
+
uniform vec2 texelSize;
|
|
60
|
+
uniform float zoom;
|
|
34
61
|
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
varying vec2 uv;
|
|
63
|
+
|
|
64
|
+
vec4 tent4(vec2 uv) {
|
|
65
|
+
vec2 dx = vec2(texelSize.x, 0.0);
|
|
66
|
+
vec2 dy = vec2(0.0, texelSize.y);
|
|
67
|
+
|
|
68
|
+
vec4 c0 = texture2D(source, uv);
|
|
69
|
+
vec4 c1 = texture2D(source, uv + dx);
|
|
70
|
+
vec4 c2 = texture2D(source, uv + dy);
|
|
71
|
+
vec4 c3 = texture2D(source, uv + dx + dy);
|
|
72
|
+
|
|
73
|
+
return 0.25 * (c0 + c1 + c2 + c3);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
float mnWeight(float x) {
|
|
77
|
+
x = abs(x);
|
|
78
|
+
float x2 = x * x;
|
|
79
|
+
float x3 = x2 * x;
|
|
80
|
+
|
|
81
|
+
if (x < 1.0) {
|
|
82
|
+
return (1.0/6.0) * ((12.0 - 9.0 * (1.0/3.0) - 6.0 * (1.0/3.0)) * x3 +
|
|
83
|
+
(-18.0 + 12.0 * (1.0/3.0) + 6.0 * (1.0/3.0)) * x2 +
|
|
84
|
+
(6.0 - 2.0 * (1.0/3.0)));
|
|
85
|
+
} else if (x < 2.0) {
|
|
86
|
+
return (1.0/6.0) * ((- (1.0/3.0) - 6.0 * (1.0/3.0)) * x3 +
|
|
87
|
+
((6.0 * (1.0/3.0) + 30.0 * (1.0/3.0)) * x2 +
|
|
88
|
+
(-12.0 * (1.0/3.0) - 48.0 * (1.0/3.0)) * x +
|
|
89
|
+
(8.0 * (1.0/3.0) + 24.0 * (1.0/3.0))));
|
|
90
|
+
}
|
|
91
|
+
return 0.0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
vec4 bicubicMN(vec2 uv, vec2 texelSize) {
|
|
95
|
+
vec2 texCoord = uv / texelSize;
|
|
96
|
+
vec2 base = floor(texCoord - 0.5);
|
|
97
|
+
vec2 f = texCoord - base - 0.5;
|
|
98
|
+
|
|
99
|
+
vec4 sum = vec4(0.0);
|
|
100
|
+
float total = 0.0;
|
|
101
|
+
|
|
102
|
+
for (int j = -1; j <= 2; j++) {
|
|
103
|
+
float wy = mnWeight(float(j) - f.y);
|
|
104
|
+
for (int i = -1; i <= 2; i++) {
|
|
105
|
+
float wx = mnWeight(float(i) - f.x);
|
|
106
|
+
float w = wx * wy;
|
|
107
|
+
|
|
108
|
+
vec2 coord = (base + vec2(float(i), float(j)) + 0.5) * texelSize;
|
|
109
|
+
sum += texture2D(source, coord) * w;
|
|
110
|
+
total += w;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return sum / total;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void main() {
|
|
117
|
+
if (zoom > 0.95) {
|
|
118
|
+
gl_FragColor = texture2D(source, uv);
|
|
119
|
+
}
|
|
120
|
+
else if (zoom > 0.5) {
|
|
121
|
+
gl_FragColor = bicubicMN(uv, texelSize);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
gl_FragColor = tent4(uv);
|
|
125
|
+
}
|
|
37
126
|
}
|
|
38
127
|
`;
|
|
128
|
+
/**
|
|
129
|
+
* A single oversized triangle that covers the entire canvas.
|
|
130
|
+
*/
|
|
131
|
+
static Vertices = new Float32Array([-1.0, -1.0, 3.0, -1.0, -1.0, 3.0]);
|
|
39
132
|
static get isSupported() {
|
|
40
|
-
|
|
41
|
-
|
|
133
|
+
return glIsSupported({
|
|
134
|
+
// Disallow software rendering.
|
|
135
|
+
// `ImageBitmapRenderingContext` is faster than software-based WebGL.
|
|
136
|
+
failIfMajorPerformanceCaveat: true,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
get type() {
|
|
140
|
+
return "hardware";
|
|
141
|
+
}
|
|
142
|
+
#contextLostTimer;
|
|
143
|
+
#onContextLost = new StickyEventEmitter();
|
|
144
|
+
/**
|
|
145
|
+
* Fired when the WebGL context is lost and cannot be restored.
|
|
146
|
+
*
|
|
147
|
+
* The current renderer will be automatically disposed.
|
|
148
|
+
*/
|
|
149
|
+
get onContextLost() {
|
|
150
|
+
return this.#onContextLost.event;
|
|
42
151
|
}
|
|
43
152
|
#context;
|
|
153
|
+
#program;
|
|
154
|
+
#vertexBuffer;
|
|
155
|
+
#texture;
|
|
156
|
+
#texelSizeLocation;
|
|
157
|
+
#zoomLocation;
|
|
158
|
+
#abortController = new AbortController();
|
|
44
159
|
/**
|
|
45
160
|
* Create a new WebGL frame renderer.
|
|
46
161
|
* @param canvas The canvas to render frames to.
|
|
@@ -48,54 +163,108 @@ export class WebGLVideoFrameRenderer extends CanvasVideoFrameRenderer {
|
|
|
48
163
|
* Whether to allow capturing the canvas content using APIs like `readPixels` and `toDataURL`.
|
|
49
164
|
* Enable this option may reduce performance.
|
|
50
165
|
*/
|
|
51
|
-
constructor(
|
|
52
|
-
super(
|
|
53
|
-
|
|
166
|
+
constructor(options) {
|
|
167
|
+
super((frame) => {
|
|
168
|
+
const gl = this.#context;
|
|
169
|
+
if (gl.isContextLost()) {
|
|
170
|
+
// The base class will close the frame.
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, frame);
|
|
174
|
+
gl.uniform2f(this.#texelSizeLocation, 1.0 / frame.codedWidth, 1.0 / frame.codedHeight);
|
|
175
|
+
gl.uniform1f(this.#zoomLocation, this.canvas.width / frame.codedWidth);
|
|
176
|
+
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
|
177
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
178
|
+
gl.flush();
|
|
179
|
+
}, options);
|
|
180
|
+
const gl = glCreateContext(this.canvas, {
|
|
181
|
+
// Low-power GPU should be enough for video rendering.
|
|
182
|
+
// Note that `OffscreenCanvas` created in Web Workers can only use `low-power` anyway.
|
|
183
|
+
powerPreference: "low-power",
|
|
184
|
+
// Avoid alpha:false, which can be expensive
|
|
185
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#avoid_alphafalse_which_can_be_expensive
|
|
186
|
+
alpha: true,
|
|
187
|
+
// Disallow software rendering.
|
|
188
|
+
// `ImageBitmapRenderingContext` is faster than software-based WebGL.
|
|
189
|
+
failIfMajorPerformanceCaveat: true,
|
|
190
|
+
preserveDrawingBuffer: !!this.options?.enableCapture,
|
|
191
|
+
// Enable desynchronized mode when not capturing to reduce latency.
|
|
192
|
+
desynchronized: !this.options?.enableCapture,
|
|
193
|
+
antialias: false,
|
|
194
|
+
depth: false,
|
|
195
|
+
premultipliedAlpha: true,
|
|
196
|
+
stencil: false,
|
|
197
|
+
});
|
|
54
198
|
if (!gl) {
|
|
55
|
-
throw new Error("WebGL not supported");
|
|
199
|
+
throw new Error("WebGL not supported, check `isSupported` first");
|
|
56
200
|
}
|
|
57
201
|
this.#context = gl;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
202
|
+
this.#initialize();
|
|
203
|
+
this.canvas.addEventListener("webglcontextlost", (e) => {
|
|
204
|
+
if (options?.contextRestoreTimeout === 0) {
|
|
205
|
+
this.#onContextLost.fire();
|
|
206
|
+
this.dispose();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
// Notify WebGL we want to handle context restoration
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
this.#contextLostTimer = globalThis.setTimeout(() => {
|
|
212
|
+
this.#onContextLost.fire();
|
|
213
|
+
this.dispose();
|
|
214
|
+
}, options?.contextRestoreTimeout ?? 3000);
|
|
215
|
+
}, { signal: this.#abortController.signal });
|
|
216
|
+
this.canvas.addEventListener("webglcontextrestored", () => {
|
|
217
|
+
if (this.#onContextLost.hasValue) {
|
|
218
|
+
// Don't restore context if `onContextLost` has been fired,
|
|
219
|
+
// which means the caller will handle the context loss.
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
globalThis.clearTimeout(this.#contextLostTimer);
|
|
223
|
+
this.#contextLostTimer = undefined;
|
|
224
|
+
this.#initialize();
|
|
225
|
+
void this.redraw();
|
|
226
|
+
}, { signal: this.#abortController.signal });
|
|
227
|
+
}
|
|
228
|
+
#initialize() {
|
|
229
|
+
const gl = this.#context;
|
|
230
|
+
this.#program = createProgram(gl, WebGLVideoFrameRenderer.VertexShader, WebGLVideoFrameRenderer.FragmentShader);
|
|
231
|
+
gl.useProgram(this.#program);
|
|
78
232
|
// Vertex coordinates, clockwise from bottom-left.
|
|
79
|
-
|
|
80
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
|
81
|
-
gl.bufferData(gl.ARRAY_BUFFER,
|
|
82
|
-
const xyLocation = gl.getAttribLocation(
|
|
233
|
+
this.#vertexBuffer = gl.createBuffer();
|
|
234
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.#vertexBuffer);
|
|
235
|
+
gl.bufferData(gl.ARRAY_BUFFER, WebGLVideoFrameRenderer.Vertices, gl.STATIC_DRAW);
|
|
236
|
+
const xyLocation = gl.getAttribLocation(this.#program, "xy");
|
|
83
237
|
gl.vertexAttribPointer(xyLocation, 2, gl.FLOAT, false, 0, 0);
|
|
84
238
|
gl.enableVertexAttribArray(xyLocation);
|
|
239
|
+
this.#texelSizeLocation = gl.getUniformLocation(this.#program, "texelSize");
|
|
240
|
+
this.#zoomLocation = gl.getUniformLocation(this.#program, "zoom");
|
|
85
241
|
// Create one texture to upload frames to.
|
|
86
|
-
|
|
87
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
242
|
+
this.#texture = gl.createTexture();
|
|
243
|
+
gl.bindTexture(gl.TEXTURE_2D, this.#texture);
|
|
88
244
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
89
245
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
90
246
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
91
247
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
92
248
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
249
|
+
async snapshot(options) {
|
|
250
|
+
if (!this.options?.enableCapture) {
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
return super.snapshot(options);
|
|
254
|
+
}
|
|
255
|
+
dispose() {
|
|
256
|
+
globalThis.clearTimeout(this.#contextLostTimer);
|
|
257
|
+
this.#onContextLost.dispose();
|
|
258
|
+
this.#abortController.abort();
|
|
259
|
+
this.#context.deleteBuffer(this.#vertexBuffer);
|
|
260
|
+
this.#context.deleteTexture(this.#texture);
|
|
261
|
+
this.#context.deleteProgram(this.#program);
|
|
262
|
+
if (!this.#context.isContextLost()) {
|
|
263
|
+
// Lose contexts eagerly
|
|
264
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#lose_contexts_eagerly
|
|
265
|
+
glLoseContext(this.#context);
|
|
266
|
+
}
|
|
267
|
+
super.dispose();
|
|
99
268
|
}
|
|
100
269
|
}
|
|
101
270
|
//# sourceMappingURL=webgl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl.js","sourceRoot":"","sources":["../../../src/video/render/webgl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"webgl.js","sourceRoot":"","sources":["../../../src/video/render/webgl.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,yBAAyB;AAEzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACH,eAAe,EACf,aAAa,EACb,aAAa,GAChB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,SAAS,YAAY,CAAC,EAAyB,EAAE,IAAY,EAAE,MAAc;IACzE,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAE,CAAC;IACtC,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,aAAa,CAClB,EAAyB,EACzB,kBAA0B,EAC1B,oBAA4B;IAE5B,MAAM,YAAY,GAAG,YAAY,CAAC,EAAE,EAA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,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC;IACzE,CAAC;IAEQ,KAAK,CAAC,QAAQ,CACnB,OAA4B;QAE5B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC;YAC/B,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAEQ,OAAO;QACZ,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAChD,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAE9B,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAE9B,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC/C,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE3C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;YACjC,wBAAwB;YACxB,wGAAwG;YACxG,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/video/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/video/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/video/utils/snapshot.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CACxB,MAAM,EAAE,iBAAiB,GAAG,eAAe,EAC3C,OAAO,CAAC,EAAE,kBAAkB,iBAmB/B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function canvasToBlob(canvas, options) {
|
|
2
|
+
if (canvas instanceof OffscreenCanvas) {
|
|
3
|
+
return canvas.convertToBlob(options);
|
|
4
|
+
}
|
|
5
|
+
else {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
canvas.toBlob((blob) => {
|
|
8
|
+
if (!blob) {
|
|
9
|
+
reject(new Error("Failed to convert canvas to blob"));
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
resolve(blob);
|
|
13
|
+
}
|
|
14
|
+
}, options?.type, options?.quality);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../src/video/utils/snapshot.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CACxB,MAA2C,EAC3C,OAA4B;IAE5B,IAAI,MAAM,YAAY,eAAe,EAAE,CAAC;QACpC,OAAO,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;SAAM,CAAC;QACJ,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACzC,MAAM,CAAC,MAAM,CACT,CAAC,IAAI,EAAE,EAAE;gBACL,IAAI,CAAC,IAAI,EAAE,CAAC;oBACR,MAAM,CAAC,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,CAAC;gBAC1D,CAAC;qBAAM,CAAC;oBACJ,OAAO,CAAC,IAAI,CAAC,CAAC;gBAClB,CAAC;YACL,CAAC,EACD,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,OAAO,CACnB,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ScrcpyVideoDecoderPauseController } from "@yume-chan/scrcpy-decoder-shared";
|
|
2
|
+
import { TransformStream } from "@yume-chan/stream-extra";
|
|
3
|
+
import type { CodecTransformStream } from "../codec/type.js";
|
|
4
|
+
/**
|
|
5
|
+
* Gets current time.
|
|
6
|
+
*
|
|
7
|
+
* The returned value is guaranteed to be monotonically increasing.
|
|
8
|
+
*/
|
|
9
|
+
export declare function increasingNow(): number;
|
|
10
|
+
export declare class TimestampTransforms {
|
|
11
|
+
#private;
|
|
12
|
+
get addTimestamp(): TransformStream<ScrcpyVideoDecoderPauseController.Output, CodecTransformStream.Input>;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the total time spent processing and decoding frames in milliseconds.
|
|
15
|
+
*/
|
|
16
|
+
get totalDecodeTime(): number;
|
|
17
|
+
get consumeTimestamp(): TransformStream<VideoFrame, VideoFrame>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=timestamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamp.d.ts","sourceRoot":"","sources":["../../../src/video/utils/timestamp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,kCAAkC,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AA0B7D;;;;GAIG;AACH,wBAAgB,aAAa,WAO5B;AAED,qBAAa,mBAAmB;;IA8B5B,IAAI,YAAY,0FAEf;IAQD;;OAEG;IACH,IAAI,eAAe,WAElB;IAgBD,IAAI,gBAAgB,4CAEnB;CACJ"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { TransformStream } from "@yume-chan/stream-extra";
|
|
2
|
+
const view = new DataView(new ArrayBuffer(8));
|
|
3
|
+
/**
|
|
4
|
+
* Gets the next presentable double-precision floating point value greater than x
|
|
5
|
+
* @param x A number. The caller must ensure that x is not NaN or Infinity
|
|
6
|
+
* @returns The next presentable double-precision floating point value
|
|
7
|
+
*/
|
|
8
|
+
function nextUp(x) {
|
|
9
|
+
if (x === 0)
|
|
10
|
+
return Number.MIN_VALUE;
|
|
11
|
+
// Write the number as a float64
|
|
12
|
+
view.setFloat64(0, x, false);
|
|
13
|
+
let bits = view.getBigUint64(0, false);
|
|
14
|
+
// If x > 0, increment bits; if x < 0, decrement bits
|
|
15
|
+
bits += x > 0 ? 1n : -1n;
|
|
16
|
+
view.setBigUint64(0, bits, false);
|
|
17
|
+
return view.getFloat64(0, false);
|
|
18
|
+
}
|
|
19
|
+
let prevValue = 0;
|
|
20
|
+
/**
|
|
21
|
+
* Gets current time.
|
|
22
|
+
*
|
|
23
|
+
* The returned value is guaranteed to be monotonically increasing.
|
|
24
|
+
*/
|
|
25
|
+
export function increasingNow() {
|
|
26
|
+
let now = performance.now();
|
|
27
|
+
if (now <= prevValue) {
|
|
28
|
+
now = nextUp(prevValue);
|
|
29
|
+
}
|
|
30
|
+
prevValue = now;
|
|
31
|
+
return now;
|
|
32
|
+
}
|
|
33
|
+
export class TimestampTransforms {
|
|
34
|
+
/**
|
|
35
|
+
* Timestamp of the last frame to be skipped by pause controller.
|
|
36
|
+
*/
|
|
37
|
+
#skipFramesUntil = -1;
|
|
38
|
+
#addTimestamp = new TransformStream({
|
|
39
|
+
transform: (packet, controller) => {
|
|
40
|
+
if (packet.type === "configuration") {
|
|
41
|
+
controller.enqueue(packet);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Use `timestamp` to convey `skipRendering` to later step
|
|
45
|
+
// and track total decoding time
|
|
46
|
+
const timestamp = increasingNow();
|
|
47
|
+
if (packet.skipRendering) {
|
|
48
|
+
this.#skipFramesUntil = timestamp;
|
|
49
|
+
}
|
|
50
|
+
controller.enqueue({
|
|
51
|
+
...packet,
|
|
52
|
+
timestamp,
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
get addTimestamp() {
|
|
57
|
+
return this.#addTimestamp;
|
|
58
|
+
}
|
|
59
|
+
// This is not in `VideoDecoderStream` because
|
|
60
|
+
// this time includes all pre-processing time,
|
|
61
|
+
// and requires `EncodedVideoChunk.timestamp` to contain
|
|
62
|
+
// local time of when the frame is received,
|
|
63
|
+
// which is set by this class.
|
|
64
|
+
#totalDecodeTime = 0;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the total time spent processing and decoding frames in milliseconds.
|
|
67
|
+
*/
|
|
68
|
+
get totalDecodeTime() {
|
|
69
|
+
return this.#totalDecodeTime;
|
|
70
|
+
}
|
|
71
|
+
#consumeTimestamp = new TransformStream({
|
|
72
|
+
transform: (frame, controller) => {
|
|
73
|
+
// `frame.timestamp` is the same `EncodedVideoChunk.timestamp` set above
|
|
74
|
+
this.#totalDecodeTime += performance.now() - frame.timestamp;
|
|
75
|
+
// Don't count these frames as skipped rendering
|
|
76
|
+
if (frame.timestamp <= this.#skipFramesUntil) {
|
|
77
|
+
frame.close();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
controller.enqueue(frame);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
get consumeTimestamp() {
|
|
84
|
+
return this.#consumeTimestamp;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=timestamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../../../src/video/utils/timestamp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI1D,MA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,gCAAgC;YAChC,MAAM,SAAS,GAAG,aAAa,EAAE,CAAC;YAElC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACvB,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;YACtC,CAAC;YAED,UAAU,CAAC,OAAO,CAAC;gBACf,GAAG,MAAM;gBACT,SAAS;aACZ,CAAC,CAAC;QACP,CAAC;KACJ,CAAC,CAAC;IACH,IAAI,YAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,8CAA8C;IAC9C,8CAA8C;IAC9C,wDAAwD;IACxD,4CAA4C;IAC5C,8BAA8B;IAC9B,gBAAgB,GAAG,CAAC,CAAC;IACrB;;OAEG;IACH,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACjC,CAAC;IAED,iBAAiB,GAAG,IAAI,eAAe,CAAyB;QAC5D,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YAC7B,wEAAwE;YACxE,IAAI,CAAC,gBAAgB,IAAI,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;YAE7D,gDAAgD;YAChD,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAC3C,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,OAAO;YACX,CAAC;YAED,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;KACJ,CAAC,CAAC;IACH,IAAI,gBAAgB;QAChB,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAClC,CAAC;CACJ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ScrcpyVideoDecoderPerformanceCounterInterface } from "@yume-chan/scrcpy-decoder-shared";
|
|
2
|
+
import { TransformStream } from "@yume-chan/stream-extra";
|
|
3
|
+
import type { CodecTransformStream } from "../codec/type.js";
|
|
4
|
+
export declare class VideoDecoderStream extends TransformStream<CodecTransformStream.Config | CodecTransformStream.VideoChunk, VideoFrame> implements ScrcpyVideoDecoderPerformanceCounterInterface {
|
|
5
|
+
#private;
|
|
6
|
+
get hardwareAcceleration(): HardwareAcceleration;
|
|
7
|
+
get onHardwareAccelerationChange(): import("@yume-chan/event").Event<HardwareAcceleration>;
|
|
8
|
+
/**
|
|
9
|
+
* Gets the number of frames waiting to be decoded.
|
|
10
|
+
*/
|
|
11
|
+
get decodeQueueSize(): number;
|
|
12
|
+
/**
|
|
13
|
+
* Gets an event when a frame is dequeued (either decoded or discarded).
|
|
14
|
+
*/
|
|
15
|
+
get onDequeue(): import("@yume-chan/event").Event<undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the number of frames decoded by the decoder.
|
|
18
|
+
*/
|
|
19
|
+
get framesDecoded(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the number of frames skipped by the decoder.
|
|
22
|
+
*/
|
|
23
|
+
get framesSkippedDecoding(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the number of times the decoder has been reset to catch up new keyframes.
|
|
26
|
+
*/
|
|
27
|
+
get decoderResetCount(): number;
|
|
28
|
+
constructor();
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=video-decoder-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-decoder-stream.d.ts","sourceRoot":"","sources":["../../../src/video/utils/video-decoder-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6CAA6C,EAAE,MAAM,kCAAkC,CAAC;AAEtG,OAAO,EAAiB,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAyE7D,qBAAa,kBACT,SAAQ,eAAe,CACnB,oBAAoB,CAAC,MAAM,GAAG,oBAAoB,CAAC,UAAU,EAC7D,UAAU,CAEd,YAAW,6CAA6C;;IAYxD,IAAI,oBAAoB,yBAEvB;IACD,IAAI,4BAA4B,2DAE/B;IAED;;OAEG;IACH,IAAI,eAAe,WAMlB;IAGD;;OAEG;IACH,IAAI,SAAS,gDAEZ;IAGD;;OAEG;IACH,IAAI,aAAa,WAEhB;IACD;;OAEG;IACH,IAAI,qBAAqB,WAExB;IACD;;OAEG;IACH,IAAI,iBAAiB,WAEpB;;CA0QJ"}
|