trtc-electron-sdk 10.3.402 → 10.3.403
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/liteav/Render/I420VideoRenderer/index.js +0 -9
- package/liteav/Render/util.js +0 -1
- package/liteav/Renderer/Canvas2DRenderer/index.d.ts +24 -0
- package/liteav/Renderer/Canvas2DRenderer/index.js +213 -0
- package/liteav/Renderer/Canvas3DRenderer/I420Canvas3DRenderer.d.ts +23 -0
- package/liteav/Renderer/Canvas3DRenderer/I420Canvas3DRenderer.js +276 -0
- package/liteav/Renderer/Canvas3DRenderer/ICanvas3DRenderer.d.ts +4 -0
- package/liteav/Renderer/Canvas3DRenderer/ICanvas3DRenderer.js +2 -0
- package/liteav/Renderer/Canvas3DRenderer/RGBACanvas3DRenderer.d.ts +8 -0
- package/liteav/Renderer/Canvas3DRenderer/RGBACanvas3DRenderer.js +163 -0
- package/liteav/Renderer/Canvas3DRenderer/index.d.ts +27 -0
- package/liteav/Renderer/Canvas3DRenderer/index.js +201 -0
- package/liteav/Renderer/Canvas3DRenderer/webgl-utils.js +1337 -0
- package/liteav/Renderer/IRenderer.d.ts +6 -0
- package/liteav/Renderer/IRenderer.js +2 -0
- package/liteav/Renderer/VideoRenderer/index.d.ts +25 -0
- package/liteav/Renderer/VideoRenderer/index.js +148 -0
- package/liteav/Renderer/index.d.ts +3 -0
- package/liteav/Renderer/index.js +38 -0
- package/liteav/Renderer/types.d.ts +19 -0
- package/liteav/Renderer/types.js +2 -0
- package/liteav/Renderer/util.d.ts +52 -0
- package/liteav/Renderer/util.js +181 -0
- package/liteav/Renderer/yuv-buffer.d.ts +189 -0
- package/liteav/Renderer/yuv-buffer.js +264 -0
- package/liteav/trtc.d.ts +6 -9
- package/liteav/trtc.js +100 -265
- package/package.json +7 -8
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vertex = [
|
|
4
|
+
-1, -1, 0,
|
|
5
|
+
1, -1, 0.0,
|
|
6
|
+
1, 1, 0.0,
|
|
7
|
+
-1, 1, 0.0
|
|
8
|
+
];
|
|
9
|
+
const vertexIndice = [
|
|
10
|
+
0, 1, 2,
|
|
11
|
+
0, 2, 3
|
|
12
|
+
];
|
|
13
|
+
const triangleTexCoords = [
|
|
14
|
+
0.0, 0.0,
|
|
15
|
+
1.0, 0.0,
|
|
16
|
+
1.0, 1.0,
|
|
17
|
+
0.0, 1.0
|
|
18
|
+
];
|
|
19
|
+
const createGL = function (canvas) {
|
|
20
|
+
const errMsg = 'Create WebGL context failed';
|
|
21
|
+
let isSuccess = true;
|
|
22
|
+
let gl = null;
|
|
23
|
+
try {
|
|
24
|
+
gl = canvas.getContext('webgl', { alpha: true, premultipliedAlpha: false })
|
|
25
|
+
|| canvas.getContext("experimental-webgl", { alpha: true, premultipliedAlpha: false });
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.warn('trtc:createGL error:', err);
|
|
29
|
+
isSuccess = false;
|
|
30
|
+
}
|
|
31
|
+
if (!isSuccess || !gl) {
|
|
32
|
+
throw new Error(errMsg);
|
|
33
|
+
}
|
|
34
|
+
return gl;
|
|
35
|
+
};
|
|
36
|
+
const createShader = function (gl, shaderSource, shaderType) {
|
|
37
|
+
//compile the vertex shader
|
|
38
|
+
const shader = gl.createShader(shaderType);
|
|
39
|
+
if (shader) {
|
|
40
|
+
gl.shaderSource(shader, shaderSource);
|
|
41
|
+
gl.compileShader(shader);
|
|
42
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
43
|
+
throw new Error(`Compile shader failed: ${gl.getShaderInfoLog(shader)}`);
|
|
44
|
+
}
|
|
45
|
+
return shader;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error('create Shader failed');
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const initShaders = function (gl) {
|
|
52
|
+
const VSHADER_SOURCE = 'attribute vec3 aPos; ' +
|
|
53
|
+
'attribute vec2 aVertexTextureCoord; ' +
|
|
54
|
+
'varying mediump vec2 vTextureCoord; ' +
|
|
55
|
+
'void main(void){ ' +
|
|
56
|
+
' gl_Position = vec4(aPos, 1); ' +
|
|
57
|
+
' vTextureCoord = aVertexTextureCoord;' +
|
|
58
|
+
'}';
|
|
59
|
+
const FSHADER_SOURCE = 'varying mediump vec2 vTextureCoord; ' +
|
|
60
|
+
'uniform sampler2D uSampler; ' +
|
|
61
|
+
'void main(void) { ' +
|
|
62
|
+
' gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); ' +
|
|
63
|
+
'}';
|
|
64
|
+
// compile shaders
|
|
65
|
+
const vertexShader = createShader(gl, VSHADER_SOURCE, gl.VERTEX_SHADER);
|
|
66
|
+
const fragmentShader = createShader(gl, FSHADER_SOURCE, gl.FRAGMENT_SHADER);
|
|
67
|
+
const vShader = vertexShader;
|
|
68
|
+
const fShader = fragmentShader;
|
|
69
|
+
if (!vertexShader || !fragmentShader) {
|
|
70
|
+
throw new Error('initialize shader failed');
|
|
71
|
+
}
|
|
72
|
+
// create program
|
|
73
|
+
const glProgram = gl.createProgram();
|
|
74
|
+
if (glProgram) {
|
|
75
|
+
// attach and link shaders to the program
|
|
76
|
+
gl.attachShader(glProgram, vertexShader);
|
|
77
|
+
gl.attachShader(glProgram, fragmentShader);
|
|
78
|
+
gl.linkProgram(glProgram);
|
|
79
|
+
if (!gl.getProgramParameter(glProgram, gl.LINK_STATUS)) {
|
|
80
|
+
throw new Error('initialize shader program failed');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
gl.useProgram(glProgram);
|
|
84
|
+
return {
|
|
85
|
+
vShader,
|
|
86
|
+
fShader,
|
|
87
|
+
glProgram,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
throw new Error('create shader program failed');
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const initUniforms = function (gl, glProgram) {
|
|
96
|
+
return gl.getUniformLocation(glProgram, 'uSampler');
|
|
97
|
+
};
|
|
98
|
+
const initTexture = function (gl) {
|
|
99
|
+
const texture = gl.createTexture();
|
|
100
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
101
|
+
// c++ addon 层拷贝数据时翻转,这里不做翻转
|
|
102
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
103
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
104
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
105
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
106
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
107
|
+
};
|
|
108
|
+
const initTextureAttr = function (gl, glProgram) {
|
|
109
|
+
// vertex data
|
|
110
|
+
const vertexBuffer = gl.createBuffer();
|
|
111
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
|
112
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertex), gl.STATIC_DRAW);
|
|
113
|
+
// indice data
|
|
114
|
+
const vertexIndiceBuffer = gl.createBuffer();
|
|
115
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vertexIndiceBuffer);
|
|
116
|
+
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(vertexIndice), gl.STATIC_DRAW);
|
|
117
|
+
// set position attribute
|
|
118
|
+
const aVertexPosition = gl.getAttribLocation(glProgram, 'aPos');
|
|
119
|
+
gl.vertexAttribPointer(aVertexPosition, 3, gl.FLOAT, false, 0, 0);
|
|
120
|
+
gl.enableVertexAttribArray(aVertexPosition);
|
|
121
|
+
// texture coordinate data
|
|
122
|
+
const trianglesTexCoordBuffer = gl.createBuffer();
|
|
123
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, trianglesTexCoordBuffer);
|
|
124
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(triangleTexCoords), gl.STATIC_DRAW);
|
|
125
|
+
// set texture coordinate attribute
|
|
126
|
+
const vertexTexCoordAttribute = gl.getAttribLocation(glProgram, 'aVertexTextureCoord');
|
|
127
|
+
gl.enableVertexAttribArray(vertexTexCoordAttribute);
|
|
128
|
+
gl.vertexAttribPointer(vertexTexCoordAttribute, 2, gl.FLOAT, false, 0, 0);
|
|
129
|
+
};
|
|
130
|
+
class RGBACanvas3DRenderer {
|
|
131
|
+
constructor(canvas) {
|
|
132
|
+
try {
|
|
133
|
+
this.gl = createGL(canvas);
|
|
134
|
+
const { vShader, fShader, glProgram } = initShaders(this.gl);
|
|
135
|
+
const samplerUniform = initUniforms(this.gl, glProgram);
|
|
136
|
+
initTextureAttr(this.gl, glProgram);
|
|
137
|
+
initTexture(this.gl);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
console.warn('trtc:RGBARenderContextCreator.create() failed.', err);
|
|
141
|
+
throw new Error('create WebGL context failed');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
draw(data, width, height) {
|
|
145
|
+
try {
|
|
146
|
+
if (this.gl) {
|
|
147
|
+
this.gl.viewport(0, 0, width, height);
|
|
148
|
+
this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, width, height, 0, this.gl.RGBA, this.gl.UNSIGNED_BYTE, data);
|
|
149
|
+
this.gl.drawElements(this.gl.TRIANGLES, 6, this.gl.UNSIGNED_SHORT, 0);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
throw new Error('WebGL context is null');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
console.warn('trtc:RGBACanvas3DRenderer.draw error:', err);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
destroy() {
|
|
160
|
+
this.gl = null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.default = RGBACanvas3DRenderer;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TRTCVideoFillMode, TRTCVideoPixelFormat } from "../../trtc_define";
|
|
2
|
+
import IRenderer from "../IRenderer";
|
|
3
|
+
import { TFrameData } from "../types";
|
|
4
|
+
declare class Canvas3dRenderer implements IRenderer {
|
|
5
|
+
private pixelFormat;
|
|
6
|
+
private viewContainer;
|
|
7
|
+
private contentMode;
|
|
8
|
+
private canvas;
|
|
9
|
+
private viewWrapper;
|
|
10
|
+
private cacheCanvasOptions;
|
|
11
|
+
private canvas3DRenderer;
|
|
12
|
+
private i420Width;
|
|
13
|
+
private i420Height;
|
|
14
|
+
private i420Rotation;
|
|
15
|
+
constructor(pixelFormat: TRTCVideoPixelFormat, view: HTMLElement);
|
|
16
|
+
private _createCanvas3DRenderer;
|
|
17
|
+
setContentMode(mode: TRTCVideoFillMode): void;
|
|
18
|
+
private bind;
|
|
19
|
+
private unbind;
|
|
20
|
+
drawFrame(frameData: TFrameData): void;
|
|
21
|
+
private _drawFrameI420;
|
|
22
|
+
private _drawFrameRGBA;
|
|
23
|
+
private _drawFrameBGRA;
|
|
24
|
+
private _updateCanvasStyle;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
27
|
+
export default Canvas3dRenderer;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
7
|
+
const trtc_define_1 = require("../../trtc_define");
|
|
8
|
+
const util_1 = require("../util");
|
|
9
|
+
const RGBACanvas3DRenderer_1 = __importDefault(require("./RGBACanvas3DRenderer"));
|
|
10
|
+
const I420Canvas3DRenderer_1 = __importDefault(require("./I420Canvas3DRenderer"));
|
|
11
|
+
const UP_LIMIT_COUNT = 16;
|
|
12
|
+
let currentCreatedCount = 0;
|
|
13
|
+
class Canvas3dRenderer {
|
|
14
|
+
constructor(pixelFormat, view) {
|
|
15
|
+
this.i420Width = 0;
|
|
16
|
+
this.i420Height = 0;
|
|
17
|
+
this.i420Rotation = 0;
|
|
18
|
+
if (currentCreatedCount < UP_LIMIT_COUNT) {
|
|
19
|
+
currentCreatedCount = currentCreatedCount + 1;
|
|
20
|
+
console.log('trtc: currentCreatedCount=', currentCreatedCount);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error('trtc: WebGL context reach up limit');
|
|
24
|
+
}
|
|
25
|
+
this.pixelFormat = pixelFormat;
|
|
26
|
+
this.viewContainer = view;
|
|
27
|
+
this.contentMode = trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fit;
|
|
28
|
+
const viewWrapper = document.createElement('div');
|
|
29
|
+
viewWrapper.className = 'trtc-webgl';
|
|
30
|
+
Object.assign(viewWrapper.style, {
|
|
31
|
+
width: '100%',
|
|
32
|
+
height: '100%',
|
|
33
|
+
display: 'flex',
|
|
34
|
+
justifyContent: 'center',
|
|
35
|
+
alignItems: 'center'
|
|
36
|
+
});
|
|
37
|
+
this.viewWrapper = viewWrapper;
|
|
38
|
+
this.canvas = null;
|
|
39
|
+
this.cacheCanvasOptions = {};
|
|
40
|
+
this.canvas3DRenderer = null;
|
|
41
|
+
this.bind(view);
|
|
42
|
+
}
|
|
43
|
+
_createCanvas3DRenderer() {
|
|
44
|
+
if (this.canvas) {
|
|
45
|
+
try {
|
|
46
|
+
if (this.pixelFormat === trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_RGBA32 || this.pixelFormat === trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32) {
|
|
47
|
+
return new RGBACanvas3DRenderer_1.default(this.canvas);
|
|
48
|
+
}
|
|
49
|
+
else if (this.pixelFormat === trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420) {
|
|
50
|
+
return new I420Canvas3DRenderer_1.default(this.canvas);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error(`pixel format '${this.pixelFormat}' not supported`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
console.warn('trtc:create WebGL context failed.', err);
|
|
58
|
+
throw new Error('create and initialize WebGL context failed');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
setContentMode(mode) {
|
|
64
|
+
this.contentMode = mode;
|
|
65
|
+
}
|
|
66
|
+
bind(viewContainer) {
|
|
67
|
+
this.viewContainer = viewContainer;
|
|
68
|
+
if (this.viewWrapper && this.viewContainer) {
|
|
69
|
+
this.canvas = document.createElement('canvas');
|
|
70
|
+
this.viewWrapper.appendChild(this.canvas);
|
|
71
|
+
this.viewContainer.appendChild(this.viewWrapper);
|
|
72
|
+
// I420 WebGL 渲染有些特殊,视频宽高发生变化时,需要重新创建 canvas
|
|
73
|
+
if (this.pixelFormat === trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420) {
|
|
74
|
+
// 初始化时,i420Width 和 i420Height 为 0,所以不会创建渲染器
|
|
75
|
+
if (this.i420Width || this.i420Height) {
|
|
76
|
+
this.canvas.width = this.i420Width;
|
|
77
|
+
this.canvas.height = this.i420Height;
|
|
78
|
+
this.canvas3DRenderer = this._createCanvas3DRenderer();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.canvas3DRenderer = this._createCanvas3DRenderer();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
unbind() {
|
|
87
|
+
var _a;
|
|
88
|
+
(_a = this.canvas3DRenderer) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
89
|
+
this.canvas3DRenderer = null;
|
|
90
|
+
this.canvas && this.viewWrapper && this.viewWrapper.removeChild(this.canvas);
|
|
91
|
+
this.canvas = null;
|
|
92
|
+
this.viewWrapper && this.viewContainer && this.viewContainer.removeChild(this.viewWrapper);
|
|
93
|
+
this.viewContainer = null;
|
|
94
|
+
}
|
|
95
|
+
drawFrame(frameData) {
|
|
96
|
+
switch (this.pixelFormat) {
|
|
97
|
+
case trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420:
|
|
98
|
+
this._drawFrameI420(frameData);
|
|
99
|
+
break;
|
|
100
|
+
case trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_RGBA32:
|
|
101
|
+
this._drawFrameRGBA(frameData);
|
|
102
|
+
break;
|
|
103
|
+
case trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32:
|
|
104
|
+
this._drawFrameBGRA(frameData);
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
console.warn('trtc:Canvas2dRenderer.drawFrame error. Not support video format:', this.pixelFormat);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
_drawFrameI420(frameData) {
|
|
111
|
+
var _a, _b, _c;
|
|
112
|
+
try {
|
|
113
|
+
const { data, width, height, timestamp, rotation, isNeedRotate } = frameData;
|
|
114
|
+
if (width <= 0 || height <= 0) {
|
|
115
|
+
throw new Error(`wrong video parameter width:${width} or height:${height}`);
|
|
116
|
+
}
|
|
117
|
+
// I420 WebGL 渲染有些特殊,视频宽高发生变化时,需要重新创建 canvas
|
|
118
|
+
if (width !== this.i420Width || height !== this.i420Height || rotation !== this.i420Rotation) {
|
|
119
|
+
const tempViewContainer = this.viewContainer;
|
|
120
|
+
this.unbind();
|
|
121
|
+
this.i420Width = width;
|
|
122
|
+
this.i420Height = height;
|
|
123
|
+
this.i420Rotation = rotation;
|
|
124
|
+
this.bind(tempViewContainer);
|
|
125
|
+
}
|
|
126
|
+
if (this.viewWrapper && this.canvas3DRenderer) {
|
|
127
|
+
this._updateCanvasStyle({
|
|
128
|
+
contentWidth: width,
|
|
129
|
+
contentHeight: height,
|
|
130
|
+
containerWidth: (_a = this.viewWrapper) === null || _a === void 0 ? void 0 : _a.clientWidth,
|
|
131
|
+
containerHeight: (_b = this.viewWrapper) === null || _b === void 0 ? void 0 : _b.clientHeight,
|
|
132
|
+
contentMode: this.contentMode,
|
|
133
|
+
rotation,
|
|
134
|
+
isNeedMirror: false,
|
|
135
|
+
isNeedRotate,
|
|
136
|
+
});
|
|
137
|
+
(_c = this.canvas3DRenderer) === null || _c === void 0 ? void 0 : _c.draw(data, width, height);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
throw new Error('renderer container element is null');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
console.error('trtc:Canvas3dRenderer._drawFrameI420 error:', err);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
_drawFrameRGBA(frameData) {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
try {
|
|
150
|
+
const { data, width, height, timestamp, rotation, isNeedRotate } = frameData;
|
|
151
|
+
if (width <= 0 || height <= 0) {
|
|
152
|
+
throw new Error(`wrong video parameter width:${width} or height:${height}`);
|
|
153
|
+
}
|
|
154
|
+
if (this.viewWrapper && this.canvas3DRenderer) {
|
|
155
|
+
this._updateCanvasStyle({
|
|
156
|
+
contentWidth: width,
|
|
157
|
+
contentHeight: height,
|
|
158
|
+
containerWidth: (_a = this.viewWrapper) === null || _a === void 0 ? void 0 : _a.clientWidth,
|
|
159
|
+
containerHeight: (_b = this.viewWrapper) === null || _b === void 0 ? void 0 : _b.clientHeight,
|
|
160
|
+
contentMode: this.contentMode,
|
|
161
|
+
rotation,
|
|
162
|
+
isNeedMirror: false,
|
|
163
|
+
isNeedRotate,
|
|
164
|
+
});
|
|
165
|
+
this.canvas3DRenderer.draw(data, width, height);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
throw new Error('renderer container element is null');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
console.error('trtc:Canvas3dRenderer._drawFrameRGBA error:', err);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
_drawFrameBGRA(frameData) {
|
|
176
|
+
this._drawFrameRGBA(Object.assign(Object.assign({}, frameData), { data: (0, util_1.transferBGRA2RGBA)(frameData.data, frameData.width, frameData.height) }));
|
|
177
|
+
}
|
|
178
|
+
_updateCanvasStyle(options) {
|
|
179
|
+
if (this.canvas) {
|
|
180
|
+
if ((0, lodash_isequal_1.default)(this.cacheCanvasOptions, options)) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.cacheCanvasOptions = Object.assign({}, options);
|
|
184
|
+
const { width, height, transform } = (0, util_1.calcCanvasStyle)(options);
|
|
185
|
+
this.canvas.width = width;
|
|
186
|
+
this.canvas.height = height;
|
|
187
|
+
this.canvas.style.transform = transform;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
throw new Error('canvas element not exist');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
destroy() {
|
|
194
|
+
if (this.viewWrapper) {
|
|
195
|
+
this.unbind();
|
|
196
|
+
this.viewWrapper = null;
|
|
197
|
+
currentCreatedCount--;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.default = Canvas3dRenderer;
|