ezuikit-js 7.6.5 → 7.6.7
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/demos/base-demo/ezuikit_static/v65/v1/css/theme.css +6 -0
- package/demos/base-demo/ezuikit_static/v65/v1/js/SuperRender_10.js +394 -394
- package/demos/base-demo/ezuikit_static/v65/v1/js/jsPluginV1-1.0.0.min.js +4 -18
- package/demos/base-demo/ezuikit_static/v65/v1/js/playctrl/AudioRenderer.js +225 -201
- package/demos/base-demo/ezuikit_static/v65/v1/js/playctrl/DecodeWorker.js +615 -617
- package/demos/base-demo/ezuikit_static/v65/v1/js/playctrl/DecodeWorkerString.js +623 -0
- package/demos/base-demo/ezuikit_static/v65/v1/js/playctrl/Decoder.js +1 -1
- package/demos/base-demo/ezuikit_static/v65/v1/js/playctrl/JSPlaySDKInterface.js +2353 -2052
- package/demos/base-demo/ezuikit_static/v65/v1/js/playctrl/SuperRender_10.js +486 -396
- package/demos/base-demo/ezuikit_static/v65/v1/js/transform/SystemTransform.js +22 -22
- package/demos/base-demo/ezuikit_static/v65/v1/js/tts-v4.js +346 -346
- package/demos/base-demo/ezuikit_static/v65/v1/rec/jquery.min.js +1 -1
- package/demos/base-demo/ezuikit_static/v65/v1/speed/speed.css +6 -4
- package/demos/base-demo/ezuikit_static/v65/v1/talk/tts-v4.js +346 -346
- package/demos/base-demo/ezuikit_static/v65/v2/js/jsPluginV2-2.0.1.min.js +11335 -132
- package/demos/react-demo/package.json +1 -1
- package/demos/vue-demo/package.json +1 -1
- package/ezuikit.js +2633 -1128
- package/ezuikit_static/v65/v1/js/jsPluginV1-1.0.0.min.js +4 -18
- package/ezuikit_static/v65/v1/js/playctrl/AudioRenderer.js +225 -201
- package/ezuikit_static/v65/v1/js/playctrl/DecodeWorker.js +132 -134
- package/ezuikit_static/v65/v1/js/playctrl/DecodeWorkerString.js +623 -0
- package/ezuikit_static/v65/v1/js/playctrl/Decoder.js +1 -1
- package/ezuikit_static/v65/v1/js/playctrl/JSPlaySDKInterface.js +2154 -1853
- package/ezuikit_static/v65/v1/js/playctrl/SuperRender_10.js +475 -385
- package/ezuikit_static/v65/v1/speed/speed.css +6 -4
- package/ezuikit_static/v65/v2/css/theme.css +0 -6
- package/ezuikit_static/v65/v2/js/jsPluginV2-2.0.1.min.js +797 -973
- package/package.json +1 -1
|
@@ -1,396 +1,486 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
//attribute修饰符用于声明由浏览器(javascript)传输给顶点着色器的变量值;
|
|
4
|
-
// vertexPos即我们定义的顶点坐标;
|
|
5
|
-
// gl_Position是一个内建的传出变量。
|
|
6
|
-
var vertexYUVShader = [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var fragmentYUVShader = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(function (root, factory) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
var
|
|
344
|
-
|
|
345
|
-
var
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
gl.
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
//顶点着色器
|
|
3
|
+
//attribute修饰符用于声明由浏览器(javascript)传输给顶点着色器的变量值;
|
|
4
|
+
// vertexPos即我们定义的顶点坐标;
|
|
5
|
+
// gl_Position是一个内建的传出变量。
|
|
6
|
+
var vertexYUVShader = [
|
|
7
|
+
"attribute vec4 vertexPos;",
|
|
8
|
+
"attribute vec2 texturePos;",
|
|
9
|
+
"varying vec2 textureCoord;",
|
|
10
|
+
|
|
11
|
+
"void main()",
|
|
12
|
+
"{",
|
|
13
|
+
"gl_Position = vertexPos;",
|
|
14
|
+
"textureCoord = texturePos;",
|
|
15
|
+
"}",
|
|
16
|
+
].join("\n");
|
|
17
|
+
//像素着色器(yuv->rgb)
|
|
18
|
+
var fragmentYUVShader = [
|
|
19
|
+
"precision highp float;",
|
|
20
|
+
"varying highp vec2 textureCoord;",
|
|
21
|
+
"uniform sampler2D ySampler;",
|
|
22
|
+
"uniform sampler2D uSampler;",
|
|
23
|
+
"uniform sampler2D vSampler;",
|
|
24
|
+
"const mat4 YUV2RGB = mat4",
|
|
25
|
+
"(",
|
|
26
|
+
"1.1643828125, 0, 1.59602734375, -.87078515625,",
|
|
27
|
+
"1.1643828125, -.39176171875, -.81296875, .52959375,",
|
|
28
|
+
"1.1643828125, 2.017234375, 0, -1.081390625,",
|
|
29
|
+
"0, 0, 0, 1",
|
|
30
|
+
");",
|
|
31
|
+
|
|
32
|
+
"void main(void) {",
|
|
33
|
+
"highp float y = texture2D(ySampler, textureCoord).r;",
|
|
34
|
+
"highp float u = texture2D(uSampler, textureCoord).r;",
|
|
35
|
+
"highp float v = texture2D(vSampler, textureCoord).r;",
|
|
36
|
+
"gl_FragColor = vec4(y, u, v, 1) * YUV2RGB;",
|
|
37
|
+
"}",
|
|
38
|
+
].join("\n");
|
|
39
|
+
|
|
40
|
+
(function (root, factory) {
|
|
41
|
+
// root.SuperRender = factory();
|
|
42
|
+
window.SuperRender = factory();
|
|
43
|
+
})(this, function () {
|
|
44
|
+
function RenderManager(canvas) {
|
|
45
|
+
this.canvasElement = document.getElementById(canvas);
|
|
46
|
+
|
|
47
|
+
this.initContextGL();
|
|
48
|
+
|
|
49
|
+
if (this.contextGL) {
|
|
50
|
+
this.YUVProgram = this.initProgram(vertexYUVShader, fragmentYUVShader);
|
|
51
|
+
this.initBuffers();
|
|
52
|
+
this.initTextures();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 初始化WebGL上下文
|
|
58
|
+
*/
|
|
59
|
+
RenderManager.prototype.initContextGL = function () {
|
|
60
|
+
var canvas = this.canvasElement;
|
|
61
|
+
|
|
62
|
+
var gl = null;
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
gl =
|
|
66
|
+
canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
|
67
|
+
} catch (e) {
|
|
68
|
+
gl = null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!gl || typeof gl.getParameter !== "function") {
|
|
72
|
+
gl = null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.contextGL = gl;
|
|
76
|
+
|
|
77
|
+
console.log("WebGL1.0");
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 初始化着色器程序
|
|
82
|
+
* @param vertexShaderScript 顶点着色器脚本
|
|
83
|
+
* @param fragmentShaderScript 片段着色器脚本
|
|
84
|
+
*/
|
|
85
|
+
RenderManager.prototype.initProgram = function (
|
|
86
|
+
vertexShaderScript,
|
|
87
|
+
fragmentShaderScript
|
|
88
|
+
) {
|
|
89
|
+
var gl = this.contextGL;
|
|
90
|
+
|
|
91
|
+
var vertexShader = gl.createShader(gl.VERTEX_SHADER); //创建定点着色器
|
|
92
|
+
gl.shaderSource(vertexShader, vertexShaderScript);
|
|
93
|
+
gl.compileShader(vertexShader);
|
|
94
|
+
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
|
95
|
+
console.log(
|
|
96
|
+
"Vertex shader failed to compile: " + gl.getShaderInfoLog(vertexShader)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
|
|
101
|
+
gl.shaderSource(fragmentShader, fragmentShaderScript);
|
|
102
|
+
gl.compileShader(fragmentShader);
|
|
103
|
+
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
|
104
|
+
console.log(
|
|
105
|
+
"Fragment shader failed to compile: " +
|
|
106
|
+
gl.getShaderInfoLog(fragmentShader)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
var program = gl.createProgram();
|
|
111
|
+
gl.attachShader(program, vertexShader);
|
|
112
|
+
gl.attachShader(program, fragmentShader);
|
|
113
|
+
gl.linkProgram(program);
|
|
114
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
115
|
+
console.log(
|
|
116
|
+
"Program failed to compile: " + gl.getProgramInfoLog(program)
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
gl.deleteShader(vertexShader);
|
|
121
|
+
gl.deleteShader(fragmentShader);
|
|
122
|
+
|
|
123
|
+
return program;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 初始化数据缓存
|
|
128
|
+
*/
|
|
129
|
+
RenderManager.prototype.initBuffers = function () {
|
|
130
|
+
var gl = this.contextGL;
|
|
131
|
+
|
|
132
|
+
var vertexPosBuffer = gl.createBuffer();
|
|
133
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vertexPosBuffer);
|
|
134
|
+
gl.bufferData(
|
|
135
|
+
gl.ARRAY_BUFFER,
|
|
136
|
+
new Float32Array([1, 1, -1, 1, 1, -1, -1, -1]),
|
|
137
|
+
gl.STATIC_DRAW
|
|
138
|
+
);
|
|
139
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
140
|
+
|
|
141
|
+
var texturePosBuffer = gl.createBuffer();
|
|
142
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texturePosBuffer);
|
|
143
|
+
gl.bufferData(
|
|
144
|
+
gl.ARRAY_BUFFER,
|
|
145
|
+
new Float32Array([1, 0, 0, 0, 1, 1, 0, 1]),
|
|
146
|
+
gl.DYNAMIC_DRAW
|
|
147
|
+
);
|
|
148
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
149
|
+
|
|
150
|
+
this.vertexPosBuffer = vertexPosBuffer;
|
|
151
|
+
this.texturePosBuffer = texturePosBuffer;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 创建纹理
|
|
156
|
+
*/
|
|
157
|
+
RenderManager.prototype.initTexture = function () {
|
|
158
|
+
var gl = this.contextGL;
|
|
159
|
+
|
|
160
|
+
var textureRef = gl.createTexture();
|
|
161
|
+
gl.bindTexture(gl.TEXTURE_2D, textureRef);
|
|
162
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
163
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
164
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
165
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
166
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
167
|
+
|
|
168
|
+
return textureRef;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 初始化YUV纹理
|
|
173
|
+
*/
|
|
174
|
+
RenderManager.prototype.initTextures = function () {
|
|
175
|
+
var gl = this.contextGL;
|
|
176
|
+
|
|
177
|
+
var program = this.YUVProgram;
|
|
178
|
+
gl.useProgram(program);
|
|
179
|
+
|
|
180
|
+
var yTextureRef = this.initTexture();
|
|
181
|
+
var ySamplerRef = gl.getUniformLocation(program, "ySampler");
|
|
182
|
+
gl.uniform1i(ySamplerRef, 0);
|
|
183
|
+
this.yTextureRef = yTextureRef;
|
|
184
|
+
|
|
185
|
+
var uTextureRef = this.initTexture();
|
|
186
|
+
var uSamplerRef = gl.getUniformLocation(program, "uSampler");
|
|
187
|
+
gl.uniform1i(uSamplerRef, 1);
|
|
188
|
+
this.uTextureRef = uTextureRef;
|
|
189
|
+
|
|
190
|
+
var vTextureRef = this.initTexture();
|
|
191
|
+
var vSamplerRef = gl.getUniformLocation(program, "vSampler");
|
|
192
|
+
gl.uniform1i(vSamplerRef, 2);
|
|
193
|
+
this.vTextureRef = vTextureRef;
|
|
194
|
+
|
|
195
|
+
gl.useProgram(null);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 显示帧数据
|
|
200
|
+
* @param nWidth 宽度
|
|
201
|
+
* @param nHeight 高度
|
|
202
|
+
* @param nHeight 帧数据
|
|
203
|
+
*/
|
|
204
|
+
RenderManager.prototype.SR_DisplayFrameData = function (
|
|
205
|
+
nWidth,
|
|
206
|
+
nHeight,
|
|
207
|
+
pData,
|
|
208
|
+
dWidth,
|
|
209
|
+
dHeight
|
|
210
|
+
) {
|
|
211
|
+
if (nWidth <= 0 || nHeight <= 0) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
var gl = this.contextGL;
|
|
216
|
+
|
|
217
|
+
if (null == pData) {
|
|
218
|
+
gl.clearColor(0.0, 0.0, 0.0, 0.0);
|
|
219
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
var canvas = this.canvasElement;
|
|
224
|
+
|
|
225
|
+
this.nWindowWidth = canvas.width;
|
|
226
|
+
this.nWindowHeight = canvas.height;
|
|
227
|
+
|
|
228
|
+
var nWindowWidth = this.nWindowWidth;
|
|
229
|
+
var nWindowHeight = this.nWindowHeight;
|
|
230
|
+
|
|
231
|
+
gl.clearColor(0.8, 0.8, 1.0, 1.0);
|
|
232
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
233
|
+
|
|
234
|
+
gl.viewport(0, 0, nWindowWidth, nWindowHeight);
|
|
235
|
+
|
|
236
|
+
this.updateFrameData(nWidth, nHeight, pData, dWidth, dHeight);
|
|
237
|
+
|
|
238
|
+
var program = this.YUVProgram;
|
|
239
|
+
gl.useProgram(program);
|
|
240
|
+
|
|
241
|
+
var vertexPosBuffer = this.vertexPosBuffer;
|
|
242
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vertexPosBuffer);
|
|
243
|
+
var vertexPosRef = gl.getAttribLocation(program, "vertexPos");
|
|
244
|
+
gl.enableVertexAttribArray(vertexPosRef);
|
|
245
|
+
gl.vertexAttribPointer(vertexPosRef, 2, gl.FLOAT, false, 0, 0);
|
|
246
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
247
|
+
|
|
248
|
+
var texturePosBuffer = this.texturePosBuffer;
|
|
249
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texturePosBuffer);
|
|
250
|
+
var texturePosRef = gl.getAttribLocation(program, "texturePos");
|
|
251
|
+
gl.enableVertexAttribArray(texturePosRef);
|
|
252
|
+
gl.vertexAttribPointer(texturePosRef, 2, gl.FLOAT, false, 0, 0);
|
|
253
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
254
|
+
|
|
255
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
256
|
+
|
|
257
|
+
gl.disableVertexAttribArray(vertexPosRef);
|
|
258
|
+
gl.disableVertexAttribArray(texturePosRef);
|
|
259
|
+
|
|
260
|
+
gl.useProgram(null);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 上传YUV数据到纹理
|
|
265
|
+
* @param nWidth 宽度
|
|
266
|
+
* @param nHeight 高度
|
|
267
|
+
* @param nHeight 帧数据
|
|
268
|
+
*/
|
|
269
|
+
RenderManager.prototype.updateFrameData = function (
|
|
270
|
+
width,
|
|
271
|
+
height,
|
|
272
|
+
data,
|
|
273
|
+
dWidth,
|
|
274
|
+
dHeight
|
|
275
|
+
) {
|
|
276
|
+
var gl = this.contextGL;
|
|
277
|
+
|
|
278
|
+
var yTextureRef = this.yTextureRef;
|
|
279
|
+
var uTextureRef = this.uTextureRef;
|
|
280
|
+
var vTextureRef = this.vTextureRef;
|
|
281
|
+
|
|
282
|
+
var i420Data = data;
|
|
283
|
+
// debugger;
|
|
284
|
+
if (width == dWidth && height == dHeight) {
|
|
285
|
+
var yDataLength = width * height;
|
|
286
|
+
var yData = i420Data.subarray(0, yDataLength);
|
|
287
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
288
|
+
gl.bindTexture(gl.TEXTURE_2D, yTextureRef);
|
|
289
|
+
gl.texImage2D(
|
|
290
|
+
gl.TEXTURE_2D,
|
|
291
|
+
0,
|
|
292
|
+
gl.LUMINANCE,
|
|
293
|
+
width,
|
|
294
|
+
height,
|
|
295
|
+
0,
|
|
296
|
+
gl.LUMINANCE,
|
|
297
|
+
gl.UNSIGNED_BYTE,
|
|
298
|
+
yData
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
var cbDataLength = ((width / 2) * height) / 2;
|
|
302
|
+
var cbData = i420Data.subarray(
|
|
303
|
+
width * height,
|
|
304
|
+
width * height + cbDataLength
|
|
305
|
+
);
|
|
306
|
+
gl.activeTexture(gl.TEXTURE2);
|
|
307
|
+
gl.bindTexture(gl.TEXTURE_2D, vTextureRef);
|
|
308
|
+
gl.texImage2D(
|
|
309
|
+
gl.TEXTURE_2D,
|
|
310
|
+
0,
|
|
311
|
+
gl.LUMINANCE,
|
|
312
|
+
width / 2,
|
|
313
|
+
height / 2,
|
|
314
|
+
0,
|
|
315
|
+
gl.LUMINANCE,
|
|
316
|
+
gl.UNSIGNED_BYTE,
|
|
317
|
+
cbData
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
var crDataLength = cbDataLength;
|
|
321
|
+
var crData = i420Data.subarray(
|
|
322
|
+
width * height + (width * height) / 4,
|
|
323
|
+
width * height + (width * height) / 4 + crDataLength
|
|
324
|
+
);
|
|
325
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
326
|
+
gl.bindTexture(gl.TEXTURE_2D, uTextureRef);
|
|
327
|
+
gl.texImage2D(
|
|
328
|
+
gl.TEXTURE_2D,
|
|
329
|
+
0,
|
|
330
|
+
gl.LUMINANCE,
|
|
331
|
+
width / 2,
|
|
332
|
+
height / 2,
|
|
333
|
+
0,
|
|
334
|
+
gl.LUMINANCE,
|
|
335
|
+
gl.UNSIGNED_BYTE,
|
|
336
|
+
crData
|
|
337
|
+
);
|
|
338
|
+
} else {
|
|
339
|
+
// //裁剪宽
|
|
340
|
+
var yDataLength = dWidth * dHeight;
|
|
341
|
+
var yData = new Uint8Array(yDataLength);
|
|
342
|
+
for (var i = 0; i < dHeight; i++) {
|
|
343
|
+
//var ySonData=new Uint8Array(dWidth) ;
|
|
344
|
+
var ySonData = i420Data.subarray(i * width, i * width + dWidth);
|
|
345
|
+
for (var j = 0; j < dWidth; j++) {
|
|
346
|
+
yData[i * dWidth + j] = ySonData[j];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
350
|
+
gl.bindTexture(gl.TEXTURE_2D, yTextureRef);
|
|
351
|
+
gl.texImage2D(
|
|
352
|
+
gl.TEXTURE_2D,
|
|
353
|
+
0,
|
|
354
|
+
gl.LUMINANCE,
|
|
355
|
+
dWidth,
|
|
356
|
+
dHeight,
|
|
357
|
+
0,
|
|
358
|
+
gl.LUMINANCE,
|
|
359
|
+
gl.UNSIGNED_BYTE,
|
|
360
|
+
yData
|
|
361
|
+
);
|
|
362
|
+
yData = null;
|
|
363
|
+
ySonData = null;
|
|
364
|
+
|
|
365
|
+
var cbDataLength = ((dWidth / 2) * dHeight) / 2;
|
|
366
|
+
var cbData = new Uint8Array(cbDataLength);
|
|
367
|
+
//var cbSonData=new Uint8Array(dWidth/2) ;
|
|
368
|
+
for (var i = 0; i < dHeight / 2; i++) {
|
|
369
|
+
var cbSonData = i420Data.subarray(
|
|
370
|
+
width * height + (i * width) / 2,
|
|
371
|
+
width * height + (i * width) / 2 + dWidth / 2
|
|
372
|
+
);
|
|
373
|
+
for (var j = 0; j < dWidth / 2; j++) {
|
|
374
|
+
cbData[(i * dWidth) / 2 + j] = cbSonData[j];
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
gl.activeTexture(gl.TEXTURE2);
|
|
378
|
+
gl.bindTexture(gl.TEXTURE_2D, vTextureRef);
|
|
379
|
+
gl.texImage2D(
|
|
380
|
+
gl.TEXTURE_2D,
|
|
381
|
+
0,
|
|
382
|
+
gl.LUMINANCE,
|
|
383
|
+
dWidth / 2,
|
|
384
|
+
dHeight / 2,
|
|
385
|
+
0,
|
|
386
|
+
gl.LUMINANCE,
|
|
387
|
+
gl.UNSIGNED_BYTE,
|
|
388
|
+
cbData
|
|
389
|
+
);
|
|
390
|
+
cbData = null;
|
|
391
|
+
cbSonData = null;
|
|
392
|
+
|
|
393
|
+
var crDataLength = cbDataLength;
|
|
394
|
+
var crData = new Uint8Array(crDataLength);
|
|
395
|
+
for (var i = 0; i < dHeight / 2; i++) {
|
|
396
|
+
var crSonData = i420Data.subarray(
|
|
397
|
+
(width * height * 5) / 4 + (i * width) / 2,
|
|
398
|
+
(width * height * 5) / 4 + (i * width) / 2 + dWidth / 2
|
|
399
|
+
);
|
|
400
|
+
for (var j = 0; j < dWidth / 2; j++) {
|
|
401
|
+
crData[(i * dWidth) / 2 + j] = crSonData[j];
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
405
|
+
gl.bindTexture(gl.TEXTURE_2D, uTextureRef);
|
|
406
|
+
gl.texImage2D(
|
|
407
|
+
gl.TEXTURE_2D,
|
|
408
|
+
0,
|
|
409
|
+
gl.LUMINANCE,
|
|
410
|
+
dWidth / 2,
|
|
411
|
+
dHeight / 2,
|
|
412
|
+
0,
|
|
413
|
+
gl.LUMINANCE,
|
|
414
|
+
gl.UNSIGNED_BYTE,
|
|
415
|
+
crData
|
|
416
|
+
);
|
|
417
|
+
crData = null;
|
|
418
|
+
crSonData = null;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* 设置显示区域
|
|
424
|
+
* @param stDisplayRect 显示区域
|
|
425
|
+
*/
|
|
426
|
+
RenderManager.prototype.SR_SetDisplayRect = function (stDisplayRect) {
|
|
427
|
+
var gl = this.contextGL;
|
|
428
|
+
|
|
429
|
+
var nWindowWidth = this.nWindowWidth;
|
|
430
|
+
var nWindowHeight = this.nWindowHeight;
|
|
431
|
+
|
|
432
|
+
var texturePosValues = null;
|
|
433
|
+
|
|
434
|
+
if (stDisplayRect && nWindowWidth > 0 && nWindowHeight > 0) {
|
|
435
|
+
var fLeft = stDisplayRect.left / nWindowWidth;
|
|
436
|
+
var fTop = stDisplayRect.top / nWindowHeight;
|
|
437
|
+
var fRight = stDisplayRect.right / nWindowWidth;
|
|
438
|
+
var fBottom = stDisplayRect.bottom / nWindowHeight;
|
|
439
|
+
|
|
440
|
+
texturePosValues = new Float32Array([
|
|
441
|
+
fRight,
|
|
442
|
+
fTop,
|
|
443
|
+
fLeft,
|
|
444
|
+
fTop,
|
|
445
|
+
fRight,
|
|
446
|
+
fBottom,
|
|
447
|
+
fLeft,
|
|
448
|
+
fBottom,
|
|
449
|
+
]);
|
|
450
|
+
} else {
|
|
451
|
+
texturePosValues = new Float32Array([1, 0, 0, 0, 1, 1, 0, 1]);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
var texturePosBuffer = this.texturePosBuffer;
|
|
455
|
+
|
|
456
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texturePosBuffer);
|
|
457
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, texturePosValues);
|
|
458
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* 释放显示资源
|
|
463
|
+
*/
|
|
464
|
+
RenderManager.prototype.SR_Destroy = function () {
|
|
465
|
+
var gl = this.contextGL;
|
|
466
|
+
|
|
467
|
+
var YUVProgram = this.YUVProgram;
|
|
468
|
+
gl.deleteProgram(YUVProgram);
|
|
469
|
+
|
|
470
|
+
var vertexPosBuffer = this.vertexPosBuffer;
|
|
471
|
+
var texturePosBuffer = this.texturePosBuffer;
|
|
472
|
+
|
|
473
|
+
gl.deleteBuffer(vertexPosBuffer);
|
|
474
|
+
gl.deleteBuffer(texturePosBuffer);
|
|
475
|
+
|
|
476
|
+
var yTextureRef = this.yTextureRef;
|
|
477
|
+
var uTextureRef = this.uTextureRef;
|
|
478
|
+
var vTextureRef = this.vTextureRef;
|
|
479
|
+
gl.deleteTexture(yTextureRef);
|
|
480
|
+
gl.deleteTexture(uTextureRef);
|
|
481
|
+
gl.deleteTexture(vTextureRef);
|
|
482
|
+
//gl.getExtension('WEBGL_lose_context').loseContext();
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
return RenderManager;
|
|
486
|
+
});
|