agora-electron-sdk 4.2.6 → 4.3.0-dev.1
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 +20 -0
- package/js/Private/AgoraBase.js +139 -174
- package/js/Private/AgoraMediaBase.js +49 -20
- package/js/Private/AgoraMediaPlayerTypes.js +32 -23
- package/js/Private/IAgoraH265Transcoder.js +39 -0
- package/js/Private/IAgoraMediaStreamingSource.js +32 -32
- package/js/Private/IAgoraMusicContentCenter.js +19 -19
- package/js/Private/IAgoraRhythmPlayer.js +9 -9
- package/js/Private/IAgoraRtcEngine.js +12 -12
- package/js/Private/IAgoraSpatialAudio.js +3 -31
- package/js/Private/extension/IAgoraH265TranscoderExtension.js +2 -0
- package/js/Private/impl/AgoraMediaBaseImpl.js +26 -2
- package/js/Private/impl/IAgoraH265TranscoderImpl.js +119 -0
- package/js/Private/impl/IAgoraMediaEngineImpl.js +13 -13
- package/js/Private/impl/IAgoraMediaPlayerImpl.js +92 -74
- package/js/Private/impl/IAgoraMediaPlayerSourceImpl.js +12 -2
- package/js/Private/impl/IAgoraMediaRecorderImpl.js +2 -2
- package/js/Private/impl/IAgoraMusicContentCenterImpl.js +20 -20
- package/js/Private/impl/IAgoraRtcEngineExImpl.js +66 -84
- package/js/Private/impl/IAgoraRtcEngineImpl.js +456 -440
- package/js/Private/impl/IAgoraSpatialAudioImpl.js +157 -181
- package/js/Private/impl/IAudioDeviceManagerImpl.js +22 -22
- package/js/Private/internal/AgoraH265TranscoderInternal.js +86 -0
- package/js/Private/internal/AgoraMediaBaseInternal.js +34 -0
- package/js/Private/internal/IrisApiEngine.js +35 -20
- package/js/Private/internal/LocalSpatialAudioEngineInternal.js +0 -39
- package/js/Private/internal/MediaPlayerInternal.js +22 -21
- package/js/Private/internal/MusicContentCenterInternal.js +1 -4
- package/js/Private/internal/RtcEngineExInternal.js +101 -134
- package/js/Private/ti/AgoraMediaBase-ti.js +1 -1
- package/js/Private/ti/IAgoraH265Transcoder-ti.js +40 -0
- package/js/Private/ti/IAgoraMediaPlayerSource-ti.js +4 -2
- package/js/Private/ti/IAgoraMusicContentCenter-ti.js +5 -5
- package/js/Private/ti/IAgoraRtcEngine-ti.js +12 -11
- package/js/Renderer/AgoraView.js +28 -14
- package/js/Renderer/IRenderer.js +65 -17
- package/js/Renderer/IRendererManager.js +230 -0
- package/js/Renderer/RendererCache.js +170 -0
- package/js/Renderer/RendererManager.js +49 -460
- package/js/Renderer/WebGLRenderer/index.js +82 -234
- package/js/Renderer/YUVCanvasRenderer/index.js +27 -147
- package/js/Types.js +6 -6
- package/js/Utils.js +37 -88
- package/package.json +4 -3
- package/scripts/clean.js +12 -0
- package/scripts/synclib.js +8 -2
- package/ts/Private/AgoraBase.ts +225 -201
- package/ts/Private/AgoraMediaBase.ts +63 -25
- package/ts/Private/AgoraMediaPlayerTypes.ts +67 -24
- package/ts/Private/IAgoraH265Transcoder.ts +73 -0
- package/ts/Private/IAgoraLog.ts +1 -0
- package/ts/Private/IAgoraMediaEngine.ts +12 -7
- package/ts/Private/IAgoraMediaPlayer.ts +47 -21
- package/ts/Private/IAgoraMediaPlayerSource.ts +27 -6
- package/ts/Private/IAgoraMediaStreamingSource.ts +38 -37
- package/ts/Private/IAgoraMusicContentCenter.ts +20 -20
- package/ts/Private/IAgoraRhythmPlayer.ts +7 -6
- package/ts/Private/IAgoraRtcEngine.ts +407 -364
- package/ts/Private/IAgoraRtcEngineEx.ts +25 -61
- package/ts/Private/IAgoraSpatialAudio.ts +80 -191
- package/ts/Private/IAudioDeviceManager.ts +27 -14
- package/ts/Private/extension/IAgoraH265TranscoderExtension.ts +39 -0
- package/ts/Private/impl/AgoraMediaBaseImpl.ts +25 -1
- package/ts/Private/impl/IAgoraH265TranscoderImpl.ts +152 -0
- package/ts/Private/impl/IAgoraMediaEngineImpl.ts +13 -13
- package/ts/Private/impl/IAgoraMediaPlayerImpl.ts +110 -81
- package/ts/Private/impl/IAgoraMediaPlayerSourceImpl.ts +17 -2
- package/ts/Private/impl/IAgoraMediaRecorderImpl.ts +2 -2
- package/ts/Private/impl/IAgoraMusicContentCenterImpl.ts +21 -21
- package/ts/Private/impl/IAgoraRtcEngineExImpl.ts +71 -106
- package/ts/Private/impl/IAgoraRtcEngineImpl.ts +589 -572
- package/ts/Private/impl/IAgoraSpatialAudioImpl.ts +211 -218
- package/ts/Private/impl/IAudioDeviceManagerImpl.ts +22 -22
- package/ts/Private/internal/AgoraH265TranscoderInternal.ts +97 -0
- package/ts/Private/internal/AgoraMediaBaseInternal.ts +15 -0
- package/ts/Private/internal/IrisApiEngine.ts +42 -27
- package/ts/Private/internal/LocalSpatialAudioEngineInternal.ts +1 -86
- package/ts/Private/internal/MediaPlayerInternal.ts +20 -29
- package/ts/Private/internal/MusicContentCenterInternal.ts +1 -5
- package/ts/Private/internal/RtcEngineExInternal.ts +91 -204
- package/ts/Private/ti/AgoraMediaBase-ti.ts +1 -1
- package/ts/Private/ti/IAgoraH265Transcoder-ti.ts +16 -0
- package/ts/Private/ti/IAgoraMediaPlayerSource-ti.ts +4 -2
- package/ts/Private/ti/IAgoraMusicContentCenter-ti.ts +5 -5
- package/ts/Private/ti/IAgoraRtcEngine-ti.ts +12 -11
- package/ts/Renderer/AgoraView.ts +29 -19
- package/ts/Renderer/IRenderer.ts +71 -22
- package/ts/Renderer/IRendererManager.ts +273 -19
- package/ts/Renderer/RendererCache.ts +167 -0
- package/ts/Renderer/RendererManager.ts +62 -607
- package/ts/Renderer/WebGLRenderer/index.ts +117 -295
- package/ts/Renderer/YUVCanvasRenderer/index.ts +45 -198
- package/ts/Types.ts +17 -194
- package/ts/Utils.ts +36 -100
- package/types/Private/AgoraBase.d.ts +219 -200
- package/types/Private/AgoraBase.d.ts.map +1 -1
- package/types/Private/AgoraMediaBase.d.ts +63 -27
- package/types/Private/AgoraMediaBase.d.ts.map +1 -1
- package/types/Private/AgoraMediaPlayerTypes.d.ts +65 -24
- package/types/Private/AgoraMediaPlayerTypes.d.ts.map +1 -1
- package/types/Private/IAgoraH265Transcoder.d.ts +28 -0
- package/types/Private/IAgoraH265Transcoder.d.ts.map +1 -0
- package/types/Private/IAgoraLog.d.ts.map +1 -1
- package/types/Private/IAgoraMediaEngine.d.ts +11 -6
- package/types/Private/IAgoraMediaEngine.d.ts.map +1 -1
- package/types/Private/IAgoraMediaPlayer.d.ts +42 -20
- package/types/Private/IAgoraMediaPlayer.d.ts.map +1 -1
- package/types/Private/IAgoraMediaPlayerSource.d.ts +23 -6
- package/types/Private/IAgoraMediaPlayerSource.d.ts.map +1 -1
- package/types/Private/IAgoraMediaStreamingSource.d.ts.map +1 -1
- package/types/Private/IAgoraMusicContentCenter.d.ts +19 -19
- package/types/Private/IAgoraMusicContentCenter.d.ts.map +1 -1
- package/types/Private/IAgoraRhythmPlayer.d.ts +6 -6
- package/types/Private/IAgoraRhythmPlayer.d.ts.map +1 -1
- package/types/Private/IAgoraRtcEngine.d.ts +329 -293
- package/types/Private/IAgoraRtcEngine.d.ts.map +1 -1
- package/types/Private/IAgoraRtcEngineEx.d.ts +21 -53
- package/types/Private/IAgoraRtcEngineEx.d.ts.map +1 -1
- package/types/Private/IAgoraSpatialAudio.d.ts +56 -167
- package/types/Private/IAgoraSpatialAudio.d.ts.map +1 -1
- package/types/Private/IAudioDeviceManager.d.ts +27 -14
- package/types/Private/IAudioDeviceManager.d.ts.map +1 -1
- package/types/Private/extension/IAgoraH265TranscoderExtension.d.ts +24 -0
- package/types/Private/extension/IAgoraH265TranscoderExtension.d.ts.map +1 -0
- package/types/Private/impl/AgoraMediaBaseImpl.d.ts +5 -1
- package/types/Private/impl/AgoraMediaBaseImpl.d.ts.map +1 -1
- package/types/Private/impl/IAgoraH265TranscoderImpl.d.ts +15 -0
- package/types/Private/impl/IAgoraH265TranscoderImpl.d.ts.map +1 -0
- package/types/Private/impl/IAgoraMediaPlayerImpl.d.ts +6 -4
- package/types/Private/impl/IAgoraMediaPlayerImpl.d.ts.map +1 -1
- package/types/Private/impl/IAgoraMediaPlayerSourceImpl.d.ts.map +1 -1
- package/types/Private/impl/IAgoraRtcEngineExImpl.d.ts +2 -4
- package/types/Private/impl/IAgoraRtcEngineExImpl.d.ts.map +1 -1
- package/types/Private/impl/IAgoraRtcEngineImpl.d.ts +30 -25
- package/types/Private/impl/IAgoraRtcEngineImpl.d.ts.map +1 -1
- package/types/Private/impl/IAgoraSpatialAudioImpl.d.ts +20 -22
- package/types/Private/impl/IAgoraSpatialAudioImpl.d.ts.map +1 -1
- package/types/Private/internal/AgoraH265TranscoderInternal.d.ts +14 -0
- package/types/Private/internal/AgoraH265TranscoderInternal.d.ts.map +1 -0
- package/types/Private/internal/AgoraMediaBaseInternal.d.ts +8 -0
- package/types/Private/internal/AgoraMediaBaseInternal.d.ts.map +1 -0
- package/types/Private/internal/IrisApiEngine.d.ts +5 -2
- package/types/Private/internal/IrisApiEngine.d.ts.map +1 -1
- package/types/Private/internal/LocalSpatialAudioEngineInternal.d.ts +0 -15
- package/types/Private/internal/LocalSpatialAudioEngineInternal.d.ts.map +1 -1
- package/types/Private/internal/MediaPlayerInternal.d.ts.map +1 -1
- package/types/Private/internal/MusicContentCenterInternal.d.ts +0 -1
- package/types/Private/internal/MusicContentCenterInternal.d.ts.map +1 -1
- package/types/Private/internal/RtcEngineExInternal.d.ts +7 -13
- package/types/Private/internal/RtcEngineExInternal.d.ts.map +1 -1
- package/types/Private/ti/IAgoraH265Transcoder-ti.d.ts +8 -0
- package/types/Private/ti/IAgoraH265Transcoder-ti.d.ts.map +1 -0
- package/types/Private/ti/IAgoraMediaPlayerSource-ti.d.ts.map +1 -1
- package/types/Private/ti/IAgoraRtcEngine-ti.d.ts.map +1 -1
- package/types/Renderer/AgoraView.d.ts +4 -4
- package/types/Renderer/AgoraView.d.ts.map +1 -1
- package/types/Renderer/IRenderer.d.ts +11 -9
- package/types/Renderer/IRenderer.d.ts.map +1 -1
- package/types/Renderer/IRendererManager.d.ts +50 -12
- package/types/Renderer/IRendererManager.d.ts.map +1 -1
- package/types/Renderer/RendererCache.d.ts +36 -0
- package/types/Renderer/RendererCache.d.ts.map +1 -0
- package/types/Renderer/RendererManager.d.ts +13 -139
- package/types/Renderer/RendererManager.d.ts.map +1 -1
- package/types/Renderer/WebGLRenderer/index.d.ts +3 -18
- package/types/Renderer/WebGLRenderer/index.d.ts.map +1 -1
- package/types/Renderer/YUVCanvasRenderer/index.d.ts +4 -10
- package/types/Renderer/YUVCanvasRenderer/index.d.ts.map +1 -1
- package/types/Types.d.ts +11 -187
- package/types/Types.d.ts.map +1 -1
- package/types/Utils.d.ts +3 -20
- package/types/Utils.d.ts.map +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { logError, logWarn } from '../../Utils';
|
|
1
|
+
import { VideoFrame } from '../../Private/AgoraMediaBase';
|
|
2
|
+
import { logWarn } from '../../Utils';
|
|
4
3
|
import { IRenderer } from '../IRenderer';
|
|
5
4
|
|
|
6
5
|
export type WebGLFallback = (renderer: WebGLRenderer, error: Error) => void;
|
|
@@ -53,19 +52,6 @@ export class WebGLRenderer extends IRenderer {
|
|
|
53
52
|
vTexture: WebGLTexture | null;
|
|
54
53
|
texCoordBuffer: WebGLBuffer | null;
|
|
55
54
|
surfaceBuffer: WebGLBuffer | null;
|
|
56
|
-
|
|
57
|
-
initWidth = 0;
|
|
58
|
-
initHeight = 0;
|
|
59
|
-
initRotation = 0;
|
|
60
|
-
clientWidth = 0;
|
|
61
|
-
clientHeight = 0;
|
|
62
|
-
lastImageWidth = 0;
|
|
63
|
-
lastImageHeight = 0;
|
|
64
|
-
lastImageRotation = 0;
|
|
65
|
-
videoBuffer = {};
|
|
66
|
-
|
|
67
|
-
observer?: ResizeObserver;
|
|
68
|
-
|
|
69
55
|
fallback?: WebGLFallback;
|
|
70
56
|
|
|
71
57
|
constructor(fallback?: WebGLFallback) {
|
|
@@ -82,13 +68,6 @@ export class WebGLRenderer extends IRenderer {
|
|
|
82
68
|
public override bind(view: HTMLElement) {
|
|
83
69
|
super.bind(view);
|
|
84
70
|
|
|
85
|
-
const ResizeObserver = window.ResizeObserver;
|
|
86
|
-
if (ResizeObserver) {
|
|
87
|
-
this.observer = new ResizeObserver(this.refreshCanvas);
|
|
88
|
-
this.observer.observe(view);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// context list after toggle resolution on electron 12.0.6
|
|
92
71
|
this.canvas?.addEventListener(
|
|
93
72
|
'webglcontextlost',
|
|
94
73
|
this.handleContextLost,
|
|
@@ -99,15 +78,63 @@ export class WebGLRenderer extends IRenderer {
|
|
|
99
78
|
this.handleContextRestored,
|
|
100
79
|
false
|
|
101
80
|
);
|
|
102
|
-
}
|
|
103
81
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
82
|
+
const getContext = (
|
|
83
|
+
contextNames = ['webgl2', 'webgl', 'experimental-webgl']
|
|
84
|
+
): WebGLRenderingContext | WebGLRenderingContext | null => {
|
|
85
|
+
for (let i = 0; i < contextNames.length; i++) {
|
|
86
|
+
const contextName = contextNames[i]!;
|
|
87
|
+
const context = this.canvas?.getContext(contextName, {
|
|
88
|
+
depth: true,
|
|
89
|
+
stencil: true,
|
|
90
|
+
alpha: false,
|
|
91
|
+
antialias: false,
|
|
92
|
+
premultipliedAlpha: true,
|
|
93
|
+
preserveDrawingBuffer: true,
|
|
94
|
+
powerPreference: 'default',
|
|
95
|
+
failIfMajorPerformanceCaveat: false,
|
|
96
|
+
});
|
|
97
|
+
if (context) {
|
|
98
|
+
return context as WebGLRenderingContext | WebGLRenderingContext;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
};
|
|
103
|
+
this.gl ??= getContext();
|
|
104
|
+
|
|
105
|
+
if (!this.gl) {
|
|
106
|
+
this.fallback?.call(
|
|
107
|
+
null,
|
|
108
|
+
this,
|
|
109
|
+
new Error('Browser not support! No WebGL detected.')
|
|
110
|
+
);
|
|
111
|
+
return;
|
|
107
112
|
}
|
|
108
|
-
this.observer?.disconnect();
|
|
109
|
-
this.observer = undefined;
|
|
110
113
|
|
|
114
|
+
// Set clear color to black, fully opaque
|
|
115
|
+
this.gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
116
|
+
// Enable depth testing
|
|
117
|
+
this.gl.enable(this.gl.DEPTH_TEST);
|
|
118
|
+
// Near things obscure far things
|
|
119
|
+
this.gl.depthFunc(this.gl.LEQUAL);
|
|
120
|
+
// Clear the color as well as the depth buffer.
|
|
121
|
+
this.gl.clear(
|
|
122
|
+
this.gl.COLOR_BUFFER_BIT |
|
|
123
|
+
this.gl.DEPTH_BUFFER_BIT |
|
|
124
|
+
this.gl.STENCIL_BUFFER_BIT
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
// Setup GLSL program
|
|
128
|
+
this.program = createProgramFromSources(this.gl, [
|
|
129
|
+
vertexShaderSource,
|
|
130
|
+
yuvShaderSource,
|
|
131
|
+
]) as WebGLProgram;
|
|
132
|
+
this.gl.useProgram(this.program);
|
|
133
|
+
|
|
134
|
+
this.initTextures();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public override unbind() {
|
|
111
138
|
this.canvas?.removeEventListener(
|
|
112
139
|
'webglcontextlost',
|
|
113
140
|
this.handleContextLost,
|
|
@@ -125,91 +152,45 @@ export class WebGLRenderer extends IRenderer {
|
|
|
125
152
|
super.unbind();
|
|
126
153
|
}
|
|
127
154
|
|
|
128
|
-
public override drawFrame(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
null,
|
|
149
|
-
this,
|
|
150
|
-
new Error('webgl lost or webgl initialize failed')
|
|
151
|
-
);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
public override refreshCanvas() {
|
|
157
|
-
if (this.lastImageWidth) {
|
|
158
|
-
this.updateViewZoomLevel(
|
|
159
|
-
this.lastImageRotation,
|
|
160
|
-
this.lastImageWidth,
|
|
161
|
-
this.lastImageHeight
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private renderImage(image: {
|
|
167
|
-
width: number;
|
|
168
|
-
height: number;
|
|
169
|
-
left: number;
|
|
170
|
-
top: number;
|
|
171
|
-
right: number;
|
|
172
|
-
bottom: number;
|
|
173
|
-
rotation: number;
|
|
174
|
-
yplane: Uint8Array;
|
|
175
|
-
uplane: Uint8Array;
|
|
176
|
-
vplane: Uint8Array;
|
|
177
|
-
}) {
|
|
178
|
-
// Rotation, width, height, left, top, right, bottom, yplane, uplane, vplane
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
image.width != this.initWidth ||
|
|
182
|
-
image.height != this.initHeight ||
|
|
183
|
-
image.rotation != this.initRotation
|
|
184
|
-
) {
|
|
185
|
-
const view = this.parentElement!;
|
|
186
|
-
this.unbind();
|
|
187
|
-
|
|
188
|
-
this.initCanvas(view, image.width, image.height, image.rotation);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (!this.gl || !this.program) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
155
|
+
public override drawFrame({
|
|
156
|
+
width,
|
|
157
|
+
height,
|
|
158
|
+
yStride,
|
|
159
|
+
uStride,
|
|
160
|
+
vStride,
|
|
161
|
+
yBuffer,
|
|
162
|
+
uBuffer,
|
|
163
|
+
vBuffer,
|
|
164
|
+
rotation,
|
|
165
|
+
}: VideoFrame) {
|
|
166
|
+
this.rotateCanvas({ width, height, rotation });
|
|
167
|
+
this.updateRenderMode();
|
|
168
|
+
|
|
169
|
+
if (!this.gl || !this.program) return;
|
|
170
|
+
|
|
171
|
+
const left = 0,
|
|
172
|
+
top = 0,
|
|
173
|
+
right = yStride! - width!,
|
|
174
|
+
bottom = 0;
|
|
194
175
|
|
|
195
176
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.texCoordBuffer);
|
|
196
|
-
const xWidth =
|
|
197
|
-
const xHeight =
|
|
177
|
+
const xWidth = width! + left + right;
|
|
178
|
+
const xHeight = height! + top + bottom;
|
|
198
179
|
this.gl.bufferData(
|
|
199
180
|
this.gl.ARRAY_BUFFER,
|
|
200
181
|
new Float32Array([
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
1 -
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
1 -
|
|
207
|
-
|
|
208
|
-
1 -
|
|
209
|
-
1 -
|
|
210
|
-
|
|
211
|
-
1 -
|
|
212
|
-
1 -
|
|
182
|
+
left / xWidth,
|
|
183
|
+
bottom / xHeight,
|
|
184
|
+
1 - right / xWidth,
|
|
185
|
+
bottom / xHeight,
|
|
186
|
+
left / xWidth,
|
|
187
|
+
1 - top / xHeight,
|
|
188
|
+
left / xWidth,
|
|
189
|
+
1 - top / xHeight,
|
|
190
|
+
1 - right / xWidth,
|
|
191
|
+
bottom / xHeight,
|
|
192
|
+
1 - right / xWidth,
|
|
193
|
+
1 - top / xHeight,
|
|
213
194
|
]),
|
|
214
195
|
this.gl.STATIC_DRAW
|
|
215
196
|
);
|
|
@@ -223,37 +204,21 @@ export class WebGLRenderer extends IRenderer {
|
|
|
223
204
|
0
|
|
224
205
|
);
|
|
225
206
|
|
|
226
|
-
this.uploadYuv(xWidth, xHeight, image.yplane, image.uplane, image.vplane);
|
|
227
|
-
|
|
228
|
-
this.updateCanvas(image.rotation, image.width, image.height);
|
|
229
|
-
this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
private uploadYuv(
|
|
233
|
-
width: number,
|
|
234
|
-
height: number,
|
|
235
|
-
yplane: Uint8Array,
|
|
236
|
-
uplane: Uint8Array,
|
|
237
|
-
vplane: Uint8Array
|
|
238
|
-
) {
|
|
239
|
-
if (!this.gl || !this.yTexture || !this.uTexture || !this.vTexture) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
207
|
this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT, 1);
|
|
208
|
+
|
|
244
209
|
this.gl.activeTexture(this.gl.TEXTURE0);
|
|
245
210
|
this.gl.bindTexture(this.gl.TEXTURE_2D, this.yTexture);
|
|
246
|
-
|
|
247
211
|
this.gl.texImage2D(
|
|
248
212
|
this.gl.TEXTURE_2D,
|
|
249
213
|
0,
|
|
250
214
|
this.gl.LUMINANCE,
|
|
251
|
-
width
|
|
252
|
-
|
|
215
|
+
// Should use xWidth instead of width here (yStide)
|
|
216
|
+
xWidth,
|
|
217
|
+
height!,
|
|
253
218
|
0,
|
|
254
219
|
this.gl.LUMINANCE,
|
|
255
220
|
this.gl.UNSIGNED_BYTE,
|
|
256
|
-
|
|
221
|
+
yBuffer!
|
|
257
222
|
);
|
|
258
223
|
|
|
259
224
|
this.gl.activeTexture(this.gl.TEXTURE1);
|
|
@@ -262,12 +227,12 @@ export class WebGLRenderer extends IRenderer {
|
|
|
262
227
|
this.gl.TEXTURE_2D,
|
|
263
228
|
0,
|
|
264
229
|
this.gl.LUMINANCE,
|
|
265
|
-
|
|
266
|
-
height / 2,
|
|
230
|
+
uStride!,
|
|
231
|
+
height! / 2,
|
|
267
232
|
0,
|
|
268
233
|
this.gl.LUMINANCE,
|
|
269
234
|
this.gl.UNSIGNED_BYTE,
|
|
270
|
-
|
|
235
|
+
uBuffer!
|
|
271
236
|
);
|
|
272
237
|
|
|
273
238
|
this.gl.activeTexture(this.gl.TEXTURE2);
|
|
@@ -276,34 +241,24 @@ export class WebGLRenderer extends IRenderer {
|
|
|
276
241
|
this.gl.TEXTURE_2D,
|
|
277
242
|
0,
|
|
278
243
|
this.gl.LUMINANCE,
|
|
279
|
-
|
|
280
|
-
height / 2,
|
|
244
|
+
vStride!,
|
|
245
|
+
height! / 2,
|
|
281
246
|
0,
|
|
282
247
|
this.gl.LUMINANCE,
|
|
283
248
|
this.gl.UNSIGNED_BYTE,
|
|
284
|
-
|
|
249
|
+
vBuffer!
|
|
285
250
|
);
|
|
251
|
+
|
|
252
|
+
this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);
|
|
286
253
|
}
|
|
287
254
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
this.lastImageRotation = rotation;
|
|
296
|
-
} else {
|
|
297
|
-
width = this.lastImageWidth;
|
|
298
|
-
height = this.lastImageHeight;
|
|
299
|
-
rotation = this.lastImageRotation;
|
|
300
|
-
}
|
|
301
|
-
if (!this.updateViewZoomLevel(rotation, width, height)) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
if (!this.gl) {
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
255
|
+
protected override rotateCanvas({ width, height, rotation }: VideoFrame) {
|
|
256
|
+
super.rotateCanvas({ width, height, rotation });
|
|
257
|
+
|
|
258
|
+
if (!this.gl) return;
|
|
259
|
+
|
|
260
|
+
this.gl.viewport(0, 0, width!, height!);
|
|
261
|
+
|
|
307
262
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.surfaceBuffer);
|
|
308
263
|
this.gl.enableVertexAttribArray(this.positionLocation!);
|
|
309
264
|
this.gl.vertexAttribPointer(
|
|
@@ -321,9 +276,9 @@ export class WebGLRenderer extends IRenderer {
|
|
|
321
276
|
// 180: 3,4,2/2,4,1
|
|
322
277
|
// 270: 4,1,3/3,1,2
|
|
323
278
|
const p1 = { x: 0, y: 0 };
|
|
324
|
-
const p2 = { x: width
|
|
325
|
-
const p3 = { x: width
|
|
326
|
-
const p4 = { x: 0, y: height };
|
|
279
|
+
const p2 = { x: width!, y: 0 };
|
|
280
|
+
const p3 = { x: width!, y: height! };
|
|
281
|
+
const p4 = { x: 0, y: height! };
|
|
327
282
|
let pp1 = p1,
|
|
328
283
|
pp2 = p2,
|
|
329
284
|
pp3 = p3,
|
|
@@ -375,140 +330,7 @@ export class WebGLRenderer extends IRenderer {
|
|
|
375
330
|
this.program!,
|
|
376
331
|
'u_resolution'
|
|
377
332
|
);
|
|
378
|
-
this.gl.uniform2f(resolutionLocation, width
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
private updateViewZoomLevel(rotation: number, width: number, height: number) {
|
|
382
|
-
if (!this.parentElement || !this.canvas) {
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
this.clientWidth = this.parentElement.clientWidth;
|
|
386
|
-
this.clientHeight = this.parentElement.clientHeight;
|
|
387
|
-
|
|
388
|
-
try {
|
|
389
|
-
if (this.contentMode === RenderModeType.RenderModeHidden) {
|
|
390
|
-
// Cover
|
|
391
|
-
if (rotation === 0 || rotation === 180) {
|
|
392
|
-
if (this.clientWidth / this.clientHeight > width / height) {
|
|
393
|
-
this.canvas.style.transform = `scale(${this.clientWidth / width})`;
|
|
394
|
-
} else {
|
|
395
|
-
this.canvas.style.transform = `scale(${
|
|
396
|
-
this.clientHeight / height
|
|
397
|
-
})`;
|
|
398
|
-
}
|
|
399
|
-
} else {
|
|
400
|
-
// 90, 270
|
|
401
|
-
if (this.clientHeight / this.clientWidth > width / height) {
|
|
402
|
-
this.canvas.style.transform = `scale(${this.clientHeight / width})`;
|
|
403
|
-
} else {
|
|
404
|
-
this.canvas.style.transform = `scale(${this.clientWidth / height})`;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
// Contain
|
|
408
|
-
} else if (rotation === 0 || rotation === 180) {
|
|
409
|
-
if (this.clientWidth / this.clientHeight > width / height) {
|
|
410
|
-
this.canvas.style.transform = `scale(${this.clientHeight / height})`;
|
|
411
|
-
} else {
|
|
412
|
-
this.canvas.style.transform = `scale(${this.clientWidth / width})`;
|
|
413
|
-
}
|
|
414
|
-
} else {
|
|
415
|
-
// 90, 270
|
|
416
|
-
if (this.clientHeight / this.clientWidth > width / height) {
|
|
417
|
-
this.canvas.style.transform = `scale(${this.clientWidth / height})`;
|
|
418
|
-
} else {
|
|
419
|
-
this.canvas.style.transform = `scale(${this.clientHeight / width})`;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
} catch (e) {
|
|
423
|
-
logError('webgl updateViewZoomLevel', e);
|
|
424
|
-
return false;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
private initCanvas(
|
|
431
|
-
view: HTMLElement,
|
|
432
|
-
width: number,
|
|
433
|
-
height: number,
|
|
434
|
-
rotation: number
|
|
435
|
-
) {
|
|
436
|
-
this.clientWidth = view.clientWidth;
|
|
437
|
-
this.clientHeight = view.clientHeight;
|
|
438
|
-
|
|
439
|
-
this.bind(view);
|
|
440
|
-
|
|
441
|
-
if (this.canvas) {
|
|
442
|
-
if (rotation == 0 || rotation == 180) {
|
|
443
|
-
this.canvas.width = width;
|
|
444
|
-
this.canvas.height = height;
|
|
445
|
-
} else {
|
|
446
|
-
this.canvas.width = height;
|
|
447
|
-
this.canvas.height = width;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
this.initWidth = width;
|
|
451
|
-
this.initHeight = height;
|
|
452
|
-
this.initRotation = rotation;
|
|
453
|
-
|
|
454
|
-
try {
|
|
455
|
-
const getContext = (
|
|
456
|
-
contextNames = ['webgl2', 'webgl', 'experimental-webgl']
|
|
457
|
-
): WebGLRenderingContext | WebGLRenderingContext | null => {
|
|
458
|
-
for (let i = 0; i < contextNames.length; i++) {
|
|
459
|
-
const contextName = contextNames[i]!;
|
|
460
|
-
const context = this.canvas?.getContext(contextName, {
|
|
461
|
-
depth: true,
|
|
462
|
-
stencil: true,
|
|
463
|
-
alpha: false,
|
|
464
|
-
antialias: false,
|
|
465
|
-
premultipliedAlpha: true,
|
|
466
|
-
preserveDrawingBuffer: false,
|
|
467
|
-
powerPreference: 'default',
|
|
468
|
-
failIfMajorPerformanceCaveat: true,
|
|
469
|
-
});
|
|
470
|
-
if (context) {
|
|
471
|
-
return context as WebGLRenderingContext | WebGLRenderingContext;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
return null;
|
|
475
|
-
};
|
|
476
|
-
// Try to grab the standard context. If it fails, fallback to experimental.
|
|
477
|
-
this.gl ??= getContext();
|
|
478
|
-
} catch (e) {
|
|
479
|
-
logWarn('webgl create happen some warming', this.gl, this.canvas);
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
if (!this.gl) {
|
|
483
|
-
this.fallback?.call(
|
|
484
|
-
null,
|
|
485
|
-
this,
|
|
486
|
-
new Error('Browser not support! No WebGL detected.')
|
|
487
|
-
);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// Set clear color to black, fully opaque
|
|
492
|
-
this.gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
493
|
-
// Enable depth testing
|
|
494
|
-
this.gl.enable(this.gl.DEPTH_TEST);
|
|
495
|
-
// Near things obscure far things
|
|
496
|
-
this.gl.depthFunc(this.gl.LEQUAL);
|
|
497
|
-
// Clear the color as well as the depth buffer.
|
|
498
|
-
this.gl.clear(
|
|
499
|
-
this.gl.COLOR_BUFFER_BIT |
|
|
500
|
-
this.gl.DEPTH_BUFFER_BIT |
|
|
501
|
-
this.gl.STENCIL_BUFFER_BIT
|
|
502
|
-
);
|
|
503
|
-
|
|
504
|
-
// Setup GLSL program
|
|
505
|
-
this.program = createProgramFromSources(this.gl, [
|
|
506
|
-
vertexShaderSource,
|
|
507
|
-
yuvShaderSource,
|
|
508
|
-
]) as WebGLProgram;
|
|
509
|
-
this.gl.useProgram(this.program);
|
|
510
|
-
|
|
511
|
-
this.initTextures();
|
|
333
|
+
this.gl.uniform2f(resolutionLocation, width!, height!);
|
|
512
334
|
}
|
|
513
335
|
|
|
514
336
|
private initTextures() {
|
|
@@ -533,7 +355,7 @@ export class WebGLRenderer extends IRenderer {
|
|
|
533
355
|
this.gl.activeTexture(textureIndex);
|
|
534
356
|
const texture = this.gl.createTexture();
|
|
535
357
|
this.gl.bindTexture(this.gl.TEXTURE_2D, texture);
|
|
536
|
-
// Set the parameters so we can render any size
|
|
358
|
+
// Set the parameters so we can render any size
|
|
537
359
|
this.gl.texParameteri(
|
|
538
360
|
this.gl.TEXTURE_2D,
|
|
539
361
|
this.gl.TEXTURE_WRAP_S,
|
|
@@ -593,7 +415,7 @@ export class WebGLRenderer extends IRenderer {
|
|
|
593
415
|
|
|
594
416
|
private handleContextLost = (event: Event) => {
|
|
595
417
|
event.preventDefault();
|
|
596
|
-
|
|
418
|
+
logWarn('webglcontextlost', event);
|
|
597
419
|
|
|
598
420
|
this.releaseTextures();
|
|
599
421
|
|
|
@@ -606,7 +428,7 @@ export class WebGLRenderer extends IRenderer {
|
|
|
606
428
|
|
|
607
429
|
private handleContextRestored = (event: Event) => {
|
|
608
430
|
event.preventDefault();
|
|
609
|
-
|
|
431
|
+
logWarn('webglcontextrestored', event);
|
|
610
432
|
|
|
611
433
|
// Setup GLSL program
|
|
612
434
|
this.program = createProgramFromSources(this.gl, [
|