trtc-electron-sdk 11.7.603-alpha.3 → 11.7.603

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.
Files changed (55) hide show
  1. package/liteav/LocalMediaTranscoder/index.d.ts +2 -2
  2. package/liteav/LocalMediaTranscoder/index.js +25 -9
  3. package/liteav/Render/BGRAVideoRenderer/index.js +114 -0
  4. package/liteav/Render/Canvas3DRGBARenderer/index.js +241 -0
  5. package/liteav/Render/GlRenderer/index.js +439 -0
  6. package/liteav/Render/GlRenderer/webgl-utils.js +1337 -0
  7. package/liteav/Render/I420VideoRenderer/index.js +106 -0
  8. package/liteav/Render/RGBAVideoRenderer/index.js +115 -0
  9. package/liteav/Render/RGBRenderer/index.js +112 -0
  10. package/liteav/Render/SoftwareRenderer/index.js +153 -0
  11. package/liteav/Render/index.d.ts +58 -0
  12. package/liteav/Render/index.js +63 -0
  13. package/liteav/Render/util.d.ts +46 -0
  14. package/liteav/Render/util.js +140 -0
  15. package/liteav/Renderer/Canvas2DRenderer/index.js +5 -4
  16. package/liteav/Renderer/Canvas3DRenderer/I420Canvas3DRenderer.js +13 -9
  17. package/liteav/Renderer/Canvas3DRenderer/RGBACanvas3DRenderer.js +7 -3
  18. package/liteav/Renderer/Canvas3DRenderer/index.d.ts +5 -1
  19. package/liteav/Renderer/Canvas3DRenderer/index.js +51 -28
  20. package/liteav/Renderer/Canvas3DRenderer/webgl-utils.js +2 -2
  21. package/liteav/Renderer/VideoRenderer/index.js +5 -4
  22. package/liteav/Renderer/index.d.ts +10 -1
  23. package/liteav/Renderer/index.js +28 -18
  24. package/liteav/Renderer/util.d.ts +6 -8
  25. package/liteav/Renderer/util.js +7 -9
  26. package/liteav/Renderer/yuv-buffer.d.ts +3 -3
  27. package/liteav/logger.d.ts +15 -0
  28. package/liteav/logger.js +78 -0
  29. package/liteav/trtc.d.ts +288 -96
  30. package/liteav/trtc.js +693 -386
  31. package/liteav/trtc_define.d.ts +113 -68
  32. package/liteav/trtc_define.js +142 -95
  33. package/liteav/vod_player.d.ts +8 -11
  34. package/liteav/vod_player.js +80 -40
  35. package/package.json +10 -6
  36. package/scripts/copy-sdk.js +78 -0
  37. package/scripts/copy-types.js +3 -0
  38. package/scripts/download.js +7 -11
  39. package/scripts/postinstall.js +46 -0
  40. package/scripts/prerelase.js +19 -0
  41. package/scripts/publish-doc.js +91 -0
  42. package/scripts/publish-npm.js +26 -0
  43. package/liteav/Renderer/Canvas3DRenderer/webgl-utils.d.ts +0 -0
  44. package/liteav/plugins/audio-effect-manager/index.d.ts +0 -43
  45. package/liteav/plugins/audio-effect-manager/index.js +0 -148
  46. package/liteav/plugins/audio-effect-manager/package.json +0 -14
  47. package/liteav/plugins/device-manager-plugin/index.d.ts +0 -76
  48. package/liteav/plugins/device-manager-plugin/index.js +0 -450
  49. package/liteav/plugins/device-manager-plugin/package.json +0 -16
  50. package/liteav/plugins/media-mixing-plugin/index.d.ts +0 -55
  51. package/liteav/plugins/media-mixing-plugin/index.js +0 -90
  52. package/liteav/plugins/media-mixing-plugin/package.json +0 -16
  53. package/liteav/plugins/video-effect-plugin/index.d.ts +0 -23
  54. package/liteav/plugins/video-effect-plugin/index.js +0 -53
  55. package/liteav/plugins/video-effect-plugin/package.json +0 -18
@@ -402,9 +402,9 @@ declare class TRTCLocalMediaTranscoder extends EventEmitter {
402
402
  removeImageSource(path: string): void;
403
403
  /**
404
404
  * 设置本地混流转码视频预览节点
405
- * @param el {HTMLElement | null} - 如果传入的是 HTML 元素,必须是块元素;传入 null 时,会停止视频预览
405
+ * @param view {HTMLElement | null} - 如果传入的是 HTML 元素,必须是块元素;传入 null 时,会停止视频预览
406
406
  */
407
- setMixedVideoRenderView(el: HTMLElement | null): void;
407
+ setMixedVideoRenderView(view: HTMLElement | null): void;
408
408
  private setMixedVideoFrameRenderCallback;
409
409
  private unsetMixedVideoFrameRenderCallback;
410
410
  private setEventCallback;
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.TRTCLocalMediaTranscodingSourceType = exports.TRTCLocalMediaTranscodingEvents = exports.TRTCLocalMediaTranscodingError = void 0;
4
7
  const events_1 = require("events");
5
8
  const trtc_define_1 = require("../trtc_define");
6
9
  const Renderer_1 = require("../Renderer");
10
+ const logger_1 = __importDefault(require("../logger"));
7
11
  /**
8
12
  * @description 本地媒体流混流转码错误码
9
13
  * @enum {Number}
@@ -397,7 +401,7 @@ class TRTCLocalMediaTranscoder extends events_1.EventEmitter {
397
401
  this.container = null;
398
402
  }
399
403
  catch (error) {
400
- console.warn('trtc: TRTCLocalMediaTranscoder.destroy error', error);
404
+ logger_1.default.warn('TRTCLocalMediaTranscoder.destroy error', error);
401
405
  }
402
406
  }
403
407
  // 帧率、码率在 JS 层为数值,可能被设置为负数,底层要求为无符号整数,此处做检验并将负值设置为零
@@ -516,11 +520,11 @@ class TRTCLocalMediaTranscoder extends events_1.EventEmitter {
516
520
  }
517
521
  /**
518
522
  * 设置本地混流转码视频预览节点
519
- * @param el {HTMLElement | null} - 如果传入的是 HTML 元素,必须是块元素;传入 null 时,会停止视频预览
523
+ * @param view {HTMLElement | null} - 如果传入的是 HTML 元素,必须是块元素;传入 null 时,会停止视频预览
520
524
  */
521
- setMixedVideoRenderView(el) {
522
- if (el && el instanceof HTMLElement) {
523
- if (this.container === el) {
525
+ setMixedVideoRenderView(view) {
526
+ if (view && view instanceof HTMLElement) {
527
+ if (this.container === view) {
524
528
  return; // 重复在同一个 HTML 节点内渲染,不用处理,直接退出
525
529
  }
526
530
  else if (this.renderer) {
@@ -528,13 +532,25 @@ class TRTCLocalMediaTranscoder extends events_1.EventEmitter {
528
532
  this.renderer.destroy();
529
533
  this.renderer = null;
530
534
  // 重新记录渲染的 HTML 节点并创建渲染器
531
- this.container = el;
532
- this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container);
535
+ this.container = view;
536
+ this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container, {
537
+ type: Renderer_1.RenderType.Video,
538
+ onContextLost: () => {
539
+ this.container = view;
540
+ this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container, { type: Renderer_1.RenderType.Canvas2D });
541
+ },
542
+ });
533
543
  }
534
544
  else {
535
545
  // 第一次设置渲染的 HTML 节点,并创建渲染器,设置渲染回调
536
- this.container = el;
537
- this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container);
546
+ this.container = view;
547
+ this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container, {
548
+ type: Renderer_1.RenderType.Video,
549
+ onContextLost: () => {
550
+ this.container = view;
551
+ this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container, { type: Renderer_1.RenderType.Canvas2D });
552
+ },
553
+ });
538
554
  this.setMixedVideoFrameRenderCallback();
539
555
  }
540
556
  }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const EventEmitter = require('events').EventEmitter;
13
+ const isEqual = require('lodash.isequal');
14
+ const { calcVideoStyle } = require('../util');
15
+ /* contentMode
16
+ * - 0: Cropped mode. Uniformly scale the video until it fills the visible boundaries (cropped).
17
+ * One dimension of the video may have clipped contents.
18
+ * - 1: Fit mode. Uniformly scale the video until one of its dimension fits the boundary (zoomed to fit).
19
+ * Areas that are not filled due to the disparity in the aspect ratio will be filled with black.
20
+ */
21
+ class BGRAVideoRenderer {
22
+ constructor() {
23
+ this.cachedOptions = {};
24
+ this.event = new EventEmitter();
25
+ this.element = null;
26
+ this.video = document.createElement('video');
27
+ this.video.setAttribute('style', 'width: 100%; height: 100%; display: block; margin: 0 auto;');
28
+ this.video.setAttribute('autoplay', 'autoplay');
29
+ this.video.muted = true;
30
+ this.contentMode = 1;
31
+ this.ready = false;
32
+ this.track = new MediaStreamTrackGenerator({ kind: 'video' });
33
+ this.writer = this.track.writable.getWriter();
34
+ }
35
+ getView() {
36
+ return this.element;
37
+ }
38
+ _updateStyle(options = {
39
+ contentWidth: 0,
40
+ contentHeight: 0,
41
+ rotation: 0,
42
+ mirrorView: false,
43
+ contentMode: 0,
44
+ containerWidth: 0,
45
+ containerHeight: 0,
46
+ isNeedRotate: true
47
+ }) {
48
+ if (isEqual(this.cachedOptions, options)) {
49
+ return;
50
+ }
51
+ this.cachedOptions = Object.assign({}, options);
52
+ const style = calcVideoStyle(options);
53
+ Object.keys(style).forEach(key => {
54
+ this.video.style[key] = style[key];
55
+ });
56
+ }
57
+ drawFrame(frameData) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ if (!this.ready) {
60
+ this.ready = true;
61
+ this.event.emit('ready');
62
+ }
63
+ this._updateStyle({
64
+ rotation: frameData.rotation,
65
+ isNeedRotate: frameData.isNeedRotate,
66
+ contentWidth: frameData.width,
67
+ contentHeight: frameData.height,
68
+ contentMode: this.contentMode,
69
+ mirrorView: false,
70
+ containerWidth: this.element.clientWidth,
71
+ containerHeight: this.element.clientHeight,
72
+ });
73
+ if (global.bgraFrames) {
74
+ global.bgraFrames.push(frameData);
75
+ if (global.bgraFrames.length > 100) {
76
+ global.bgraFrames.shift();
77
+ }
78
+ }
79
+ else {
80
+ global.bgraFrames = [frameData];
81
+ }
82
+ try {
83
+ const vf = new VideoFrame(frameData.data, {
84
+ format: 'BGRA',
85
+ codedWidth: frameData.width,
86
+ codedHeight: frameData.height,
87
+ timestamp: frameData.timestamp,
88
+ });
89
+ yield this.writer.write(vf);
90
+ }
91
+ catch (error) {
92
+ console.error('VideoRender.drawImage error:', error);
93
+ }
94
+ });
95
+ }
96
+ bind(element) {
97
+ this.element = element;
98
+ if (this.element.firstChild) {
99
+ this.element.removeChild(this.element.firstChild);
100
+ }
101
+ this.element.appendChild(this.video);
102
+ this.video.srcObject = new MediaStream([this.track]);
103
+ }
104
+ unbind() {
105
+ if (this.element.firstChild) {
106
+ this.element.removeChild(this.element.firstChild);
107
+ }
108
+ this.element = null;
109
+ }
110
+ setContentMode(mode) {
111
+ this.contentMode = mode;
112
+ }
113
+ }
114
+ exports.default = BGRAVideoRenderer;
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const EventEmitter = require('events').EventEmitter;
4
+ const isEqual = require('lodash.isequal');
5
+ const { calcCanvasStyle } = require('../util');
6
+ class Canvas3DRGBARenderer {
7
+ constructor() {
8
+ this.cacheCanvasOpts = {};
9
+ this.event = new EventEmitter();
10
+ this.ready = false;
11
+ this.contentMode = 1;
12
+ this.container = null;
13
+ this.canvas = null;
14
+ this.element = null;
15
+ this.gl = null;
16
+ this.glProgram = null;
17
+ this.vShader = null;
18
+ this.fShader = null;
19
+ this.samplerUniform = null;
20
+ this.texture = null;
21
+ this.vertex = [
22
+ -1, -1, 0,
23
+ 1, -1, 0.0,
24
+ 1, 1, 0.0,
25
+ -1, 1, 0.0
26
+ ];
27
+ this.vertexIndice = [
28
+ 0, 1, 2,
29
+ 0, 2, 3
30
+ ];
31
+ this.triangleTexCoords = [
32
+ 0.0, 0.0,
33
+ 1.0, 0.0,
34
+ 1.0, 1.0,
35
+ 0.0, 1.0
36
+ ];
37
+ }
38
+ _initGL() {
39
+ try {
40
+ this.gl = this.canvas.getContext('webgl', { alpha: true, premultipliedAlpha: false }); //|| canvas.getContext("experimental-webgl", { antialias: false });
41
+ }
42
+ catch (e) {
43
+ return false;
44
+ }
45
+ if (this.gl) {
46
+ return true;
47
+ }
48
+ else {
49
+ return false;
50
+ }
51
+ }
52
+ _initShaders() {
53
+ const VSHADER_SOURCE = 'attribute vec3 aPos; ' +
54
+ 'attribute vec2 aVertexTextureCoord; ' +
55
+ 'varying mediump vec2 vTextureCoord; ' +
56
+ 'void main(void){ ' +
57
+ ' gl_Position = vec4(aPos, 1); ' +
58
+ ' vTextureCoord = aVertexTextureCoord;' +
59
+ '}';
60
+ const FSHADER_SOURCE = 'varying mediump vec2 vTextureCoord; ' +
61
+ 'uniform sampler2D uSampler; ' +
62
+ 'void main(void) { ' +
63
+ ' gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); ' +
64
+ '}';
65
+ // compile shaders
66
+ const vertexShader = this._makeShader(VSHADER_SOURCE, this.gl.VERTEX_SHADER);
67
+ const fragmentShader = this._makeShader(FSHADER_SOURCE, this.gl.FRAGMENT_SHADER);
68
+ this.vShader = vertexShader;
69
+ this.fShader = fragmentShader;
70
+ if (!vertexShader || !fragmentShader) {
71
+ return false;
72
+ }
73
+ // create program
74
+ this.glProgram = this.gl.createProgram();
75
+ // attach and link shaders to the program
76
+ this.gl.attachShader(this.glProgram, vertexShader);
77
+ this.gl.attachShader(this.glProgram, fragmentShader);
78
+ this.gl.linkProgram(this.glProgram);
79
+ if (!this.gl.getProgramParameter(this.glProgram, this.gl.LINK_STATUS)) {
80
+ console.log('trtc:Unable to initialize the shader program.');
81
+ return false;
82
+ }
83
+ else {
84
+ this.gl.useProgram(this.glProgram);
85
+ return true;
86
+ }
87
+ }
88
+ _makeShader(src, type) {
89
+ //compile the vertex shader
90
+ const shader = this.gl.createShader(type);
91
+ this.gl.shaderSource(shader, src);
92
+ this.gl.compileShader(shader);
93
+ if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) {
94
+ console.log(`trtc:Error compiling shader: ${this.gl.getShaderInfoLog(shader)}`);
95
+ return null;
96
+ }
97
+ return shader;
98
+ }
99
+ _initUniforms() {
100
+ this.samplerUniform = this.gl.getUniformLocation(this.glProgram, 'uSampler');
101
+ return true;
102
+ }
103
+ _initTexture() {
104
+ this.texture = this.gl.createTexture();
105
+ this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
106
+ // c++ addon 层拷贝数据时翻转,这里不做翻转
107
+ this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, true);
108
+ this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
109
+ this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);
110
+ this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
111
+ this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
112
+ }
113
+ _initTextureAttr() {
114
+ // vertex data
115
+ const vertexBuffer = this.gl.createBuffer();
116
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, vertexBuffer);
117
+ this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(this.vertex), this.gl.STATIC_DRAW);
118
+ // indice data
119
+ const vertexIndiceBuffer = this.gl.createBuffer();
120
+ this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, vertexIndiceBuffer);
121
+ this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.vertexIndice), this.gl.STATIC_DRAW);
122
+ // set position attribute
123
+ const aVertexPosition = this.gl.getAttribLocation(this.glProgram, 'aPos');
124
+ this.gl.vertexAttribPointer(aVertexPosition, 3, this.gl.FLOAT, false, 0, 0);
125
+ this.gl.enableVertexAttribArray(aVertexPosition);
126
+ // texture coordinate data
127
+ const trianglesTexCoordBuffer = this.gl.createBuffer();
128
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, trianglesTexCoordBuffer);
129
+ this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(this.triangleTexCoords), this.gl.STATIC_DRAW);
130
+ // set texture coordinate attribute
131
+ const vertexTexCoordAttribute = this.gl.getAttribLocation(this.glProgram, 'aVertexTextureCoord');
132
+ this.gl.enableVertexAttribArray(vertexTexCoordAttribute);
133
+ this.gl.vertexAttribPointer(vertexTexCoordAttribute, 2, this.gl.FLOAT, false, 0, 0);
134
+ }
135
+ getView() {
136
+ return this.element;
137
+ }
138
+ bind(element) {
139
+ this.element = element;
140
+ const container = document.createElement('div');
141
+ Object.assign(container.style, {
142
+ width: '100%',
143
+ height: '100%',
144
+ display: 'flex',
145
+ justifyContent: 'center',
146
+ alignItems: 'center'
147
+ });
148
+ this.container = container;
149
+ element.appendChild(this.container);
150
+ this.canvas = document.createElement('canvas');
151
+ this.container.appendChild(this.canvas);
152
+ // init webgl & context
153
+ let ret = false;
154
+ do {
155
+ ret = this._initGL();
156
+ if (!ret) {
157
+ console.log('trtc:init WebGL failed');
158
+ break;
159
+ }
160
+ ret = this._initShaders();
161
+ if (!ret) {
162
+ console.log('trtc:init WebGL Shader failed');
163
+ break;
164
+ }
165
+ ret = this._initUniforms();
166
+ if (!ret) {
167
+ console.log('trtc:int WebGL Uniform failed');
168
+ break;
169
+ }
170
+ } while (false);
171
+ if (ret) {
172
+ this._initTextureAttr();
173
+ this._initTexture();
174
+ }
175
+ }
176
+ unbind() {
177
+ this.texture = null;
178
+ this.samplerUniform = null;
179
+ this.vShader = null;
180
+ this.fShader = null;
181
+ this.glProgram = null;
182
+ this.gl = null;
183
+ this.container && this.container.removeChild(this.canvas);
184
+ this.element && this.element.removeChild(this.container);
185
+ this.container = null;
186
+ this.element = null;
187
+ }
188
+ updateCanvas(options = {
189
+ contentWidth: 0,
190
+ contentHeight: 0,
191
+ rotation: 0,
192
+ mirrorView: false,
193
+ contentMode: 0,
194
+ containerWidth: 0,
195
+ containerHeight: 0,
196
+ isNeedRotate: true
197
+ }) {
198
+ if (isEqual(this.cacheCanvasOpts, options)) {
199
+ return;
200
+ }
201
+ this.cacheCanvasOpts = Object.assign({}, options);
202
+ const { width, height, transform } = calcCanvasStyle(options);
203
+ this.canvas.width = width;
204
+ this.canvas.height = height;
205
+ this.canvas.style.transform = transform;
206
+ }
207
+ drawFrame(imageData) {
208
+ if (!this.ready) {
209
+ this.ready = true;
210
+ this.event.emit('ready');
211
+ }
212
+ const mirror = false;
213
+ const contentWidth = imageData.width;
214
+ const contentHeight = imageData.height;
215
+ const rotation = imageData.rotation;
216
+ const isNeedRotate = imageData.isNeedRotate;
217
+ this.updateCanvas({
218
+ contentWidth,
219
+ contentHeight,
220
+ rotation,
221
+ mirrorView: mirror,
222
+ contentMode: this.contentMode,
223
+ containerWidth: this.container.clientWidth,
224
+ containerHeight: this.container.clientHeight,
225
+ isNeedRotate
226
+ });
227
+ try {
228
+ this.gl.viewport(0, 0, contentWidth, contentHeight);
229
+ this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, contentWidth, contentHeight, 0, this.gl.RGBA, this.gl.UNSIGNED_BYTE, imageData.data // new Uint8Array(imageData.data)
230
+ );
231
+ this.gl.drawElements(this.gl.TRIANGLES, 6, this.gl.UNSIGNED_SHORT, 0);
232
+ }
233
+ catch (error) {
234
+ console.error('trtc:', error);
235
+ }
236
+ }
237
+ setContentMode(mode = 0) {
238
+ this.contentMode = mode;
239
+ }
240
+ }
241
+ exports.default = Canvas3DRGBARenderer;