trtc-electron-sdk 10.1.8-beta.2 → 10.1.113-beta.2
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/GlRenderer/index.js +14 -14
- package/liteav/Render/GlRenderer/webgl-utils.js +2 -2
- package/liteav/Render/RGBRenderer/index.js +71 -44
- package/liteav/Render/SoftwareRenderer/index.js +52 -52
- package/liteav/Render/index.d.ts +0 -4
- package/liteav/Render/index.js +1 -9
- package/liteav/Render/util.d.ts +0 -28
- package/liteav/Render/util.js +1 -107
- package/liteav/trtc.d.ts +75 -114
- package/liteav/trtc.js +180 -655
- package/liteav/trtc_define.d.ts +22 -88
- package/liteav/trtc_define.js +36 -120
- package/package.json +8 -8
- package/scripts/download.js +0 -27
- package/liteav/Render/BGRAVideoRenderer/index.js +0 -114
- package/liteav/Render/Canvas3DRGBARenderer/index.js +0 -241
- package/liteav/Render/I420VideoRenderer/index.js +0 -115
- package/liteav/Render/RGBAVideoRenderer/index.js +0 -115
- package/liteav/trtc.10.0.100-beta.12.d.ts +0 -2036
- package/liteav/trtc.10.0.100-beta.12.js +0 -3789
|
@@ -48,7 +48,7 @@ const TrtcRender = function () {
|
|
|
48
48
|
gl.getExtension('WEBGL_lose_context').loseContext();
|
|
49
49
|
}
|
|
50
50
|
catch (err) {
|
|
51
|
-
console.warn(
|
|
51
|
+
console.warn(err);
|
|
52
52
|
}
|
|
53
53
|
program = undefined;
|
|
54
54
|
positionLocation = undefined;
|
|
@@ -69,7 +69,7 @@ const TrtcRender = function () {
|
|
|
69
69
|
that.view && that.view.removeChild(that.container);
|
|
70
70
|
}
|
|
71
71
|
catch (e) {
|
|
72
|
-
console.warn(
|
|
72
|
+
console.warn(e);
|
|
73
73
|
}
|
|
74
74
|
that.canvas = undefined;
|
|
75
75
|
that.container = undefined;
|
|
@@ -83,7 +83,7 @@ const TrtcRender = function () {
|
|
|
83
83
|
};
|
|
84
84
|
that.renderImage = function (image) {
|
|
85
85
|
if (!gl) {
|
|
86
|
-
console.log('
|
|
86
|
+
console.log('!gl');
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
if (image.width != that.initWidth
|
|
@@ -93,7 +93,7 @@ const TrtcRender = function () {
|
|
|
93
93
|
const view = that.view;
|
|
94
94
|
that.unbind();
|
|
95
95
|
initCanvas(view, image.mirror, image.width, image.height, image.rotation, image.isNeedRotate, e => {
|
|
96
|
-
console.error(`
|
|
96
|
+
console.error(`init canvas ${image.width}*${image.height} rotation ${image.rotation} failed. ${e}`);
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
|
|
@@ -158,9 +158,9 @@ const TrtcRender = function () {
|
|
|
158
158
|
right,
|
|
159
159
|
bottom,
|
|
160
160
|
rotation: rotation,
|
|
161
|
-
yplane: imageData.yUint8Array,
|
|
162
|
-
uplane: imageData.uUint8Array,
|
|
163
|
-
vplane: imageData.vUint8Array,
|
|
161
|
+
yplane: new Uint8Array(imageData.yUint8Array),
|
|
162
|
+
uplane: new Uint8Array(imageData.uUint8Array),
|
|
163
|
+
vplane: new Uint8Array(imageData.vUint8Array),
|
|
164
164
|
isNeedRotate
|
|
165
165
|
});
|
|
166
166
|
const now32 = (Date.now() & 0xffffffff) >>> 0;
|
|
@@ -175,7 +175,7 @@ const TrtcRender = function () {
|
|
|
175
175
|
if (config.getDebugMode()) {
|
|
176
176
|
e = gl.getError();
|
|
177
177
|
if (e != gl.NO_ERROR) {
|
|
178
|
-
console.log('
|
|
178
|
+
console.log('upload y plane ', width, height, yplane.byteLength, ' error', e);
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
gl.activeTexture(gl.TEXTURE1);
|
|
@@ -184,7 +184,7 @@ const TrtcRender = function () {
|
|
|
184
184
|
if (config.getDebugMode()) {
|
|
185
185
|
e = gl.getError();
|
|
186
186
|
if (e != gl.NO_ERROR) {
|
|
187
|
-
console.log('
|
|
187
|
+
console.log('upload u plane ', width, height, uplane.byteLength, ' error', e);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
gl.activeTexture(gl.TEXTURE2);
|
|
@@ -194,7 +194,7 @@ const TrtcRender = function () {
|
|
|
194
194
|
if (config.getDebugMode()) {
|
|
195
195
|
e = gl.getError();
|
|
196
196
|
if (e != gl.NO_ERROR) {
|
|
197
|
-
console.log('
|
|
197
|
+
console.log('upload v plane ', width, height, vplane.byteLength, ' error', e);
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
}
|
|
@@ -273,7 +273,7 @@ const TrtcRender = function () {
|
|
|
273
273
|
}) || that.canvas.getContext('experimental-webgl');
|
|
274
274
|
}
|
|
275
275
|
catch (e) {
|
|
276
|
-
console.log(
|
|
276
|
+
console.log(e);
|
|
277
277
|
}
|
|
278
278
|
if (!gl) {
|
|
279
279
|
gl = undefined;
|
|
@@ -361,9 +361,9 @@ const TrtcRender = function () {
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
catch (e) {
|
|
364
|
-
console.log(`
|
|
365
|
-
console.log(
|
|
366
|
-
console.error(
|
|
364
|
+
console.log(`updateCanvas error ${that.canvas}`);
|
|
365
|
+
console.log(that);
|
|
366
|
+
console.error(e);
|
|
367
367
|
return false;
|
|
368
368
|
}
|
|
369
369
|
return true;
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
function error(msg) {
|
|
52
52
|
if (topWindow.console) {
|
|
53
53
|
if (topWindow.console.error) {
|
|
54
|
-
topWindow.console.error(
|
|
54
|
+
topWindow.console.error(msg);
|
|
55
55
|
}
|
|
56
56
|
else if (topWindow.console.log) {
|
|
57
|
-
topWindow.console.log(
|
|
57
|
+
topWindow.console.log(msg);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const EventEmitter = require('events').EventEmitter;
|
|
4
4
|
const isEqual = require('lodash.isequal');
|
|
5
|
-
const {
|
|
5
|
+
const { isNeedKeepWidthAndHeight } = require('../util');
|
|
6
6
|
/* contentMode
|
|
7
7
|
* - 0: Cropped mode. Uniformly scale the video until it fills the visible boundaries (cropped). One dimension of the video may have clipped contents.
|
|
8
8
|
* - 1: Fit mode. Uniformly scale the video until one of its dimension fits the boundary (zoomed to fit). Areas that are not filled due to the disparity
|
|
@@ -21,6 +21,33 @@ class RGBRenderer {
|
|
|
21
21
|
getView() {
|
|
22
22
|
return this.element;
|
|
23
23
|
}
|
|
24
|
+
_calcZoom(vertical = false, contentMode = 0, width, height, clientWidth, clientHeight) {
|
|
25
|
+
let localRatio = clientWidth / clientHeight;
|
|
26
|
+
let tempRatio = width / height;
|
|
27
|
+
if (isNaN(localRatio) || isNaN(tempRatio)) {
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
if (!contentMode) {
|
|
31
|
+
if (vertical) {
|
|
32
|
+
return localRatio > tempRatio ?
|
|
33
|
+
clientHeight / height : clientWidth / width;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return localRatio < tempRatio ?
|
|
37
|
+
clientHeight / height : clientWidth / width;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (vertical) {
|
|
42
|
+
return localRatio < tempRatio ?
|
|
43
|
+
clientHeight / height : clientWidth / width;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return localRatio > tempRatio ?
|
|
47
|
+
clientHeight / height : clientWidth / width;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
24
51
|
bind(element) {
|
|
25
52
|
this.element = element;
|
|
26
53
|
let container = document.createElement('div');
|
|
@@ -46,64 +73,64 @@ class RGBRenderer {
|
|
|
46
73
|
refreshCanvas() {
|
|
47
74
|
}
|
|
48
75
|
updateCanvas(options = {
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
width: 0,
|
|
77
|
+
height: 0,
|
|
51
78
|
rotation: 0,
|
|
52
79
|
mirrorView: false,
|
|
53
80
|
contentMode: 0,
|
|
54
|
-
|
|
55
|
-
|
|
81
|
+
clientWidth: 0,
|
|
82
|
+
clientHeight: 0,
|
|
56
83
|
isNeedRotate: true
|
|
57
84
|
}) {
|
|
58
85
|
if (isEqual(this.cacheCanvasOpts, options)) {
|
|
59
86
|
return;
|
|
60
87
|
}
|
|
61
88
|
this.cacheCanvasOpts = Object.assign({}, options);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
89
|
+
if ([0, 90, 180, 270].indexOf(options.rotation) === -1) {
|
|
90
|
+
throw new Error('Invalid value for rotation. Only support 0, 90, 180, 270');
|
|
91
|
+
}
|
|
92
|
+
const isKeepWidthHeight = isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate);
|
|
93
|
+
if (isKeepWidthHeight) {
|
|
94
|
+
this.canvas.width = options.width;
|
|
95
|
+
this.canvas.height = options.height;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.canvas.height = options.width;
|
|
99
|
+
this.canvas.width = options.height;
|
|
100
|
+
}
|
|
101
|
+
this.canvas.style.zoom = this._calcZoom(!isKeepWidthHeight, options.contentMode, options.width, options.height, options.clientWidth, options.clientHeight);
|
|
102
|
+
if (options.mirrorView) {
|
|
103
|
+
this.canvas.style.transform = 'rotateY(180deg)';
|
|
104
|
+
}
|
|
66
105
|
}
|
|
67
106
|
drawFrame(imageData) {
|
|
68
107
|
if (!this.ready) {
|
|
69
108
|
this.ready = true;
|
|
70
109
|
this.event.emit('ready');
|
|
71
110
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
let newImage = new ImageData(new Uint8ClampedArray(imageData.data.buffer || imageData.data), width, height);
|
|
96
|
-
const tempCanvas = document.createElement('canvas');
|
|
97
|
-
tempCanvas.width = imageData.width;
|
|
98
|
-
tempCanvas.height = imageData.height;
|
|
99
|
-
const tempCtx = tempCanvas.getContext('2d');
|
|
100
|
-
tempCtx.putImageData(newImage, 0, 0);
|
|
101
|
-
let ctx = this.canvas.getContext("2d");
|
|
102
|
-
ctx.drawImage(tempCanvas, 0, 0);
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
console.error('trtc:RGBRenderer.drawFrame error:', error);
|
|
106
|
-
}
|
|
111
|
+
let mirror = 0;
|
|
112
|
+
let contentWidth = imageData.width;
|
|
113
|
+
let contentHeight = imageData.height;
|
|
114
|
+
const isNeedRotate = imageData.isNeedRotate;
|
|
115
|
+
let left = 0;
|
|
116
|
+
let top = 0;
|
|
117
|
+
let right = 0;
|
|
118
|
+
let bottom = 0;
|
|
119
|
+
let rotation = imageData.rotation;
|
|
120
|
+
let ts = imageData.timestamp;
|
|
121
|
+
let width = contentWidth + left + right;
|
|
122
|
+
let height = contentHeight + top + bottom;
|
|
123
|
+
this.updateCanvas({
|
|
124
|
+
width, height, rotation,
|
|
125
|
+
mirrorView: mirror,
|
|
126
|
+
contentMode: this.contentMode,
|
|
127
|
+
clientWidth: this.container.clientWidth,
|
|
128
|
+
clientHeight: this.container.clientHeight,
|
|
129
|
+
isNeedRotate
|
|
130
|
+
});
|
|
131
|
+
let ctx = this.canvas.getContext("2d");
|
|
132
|
+
let tmpimage = new ImageData(imageData.data, width, height);
|
|
133
|
+
ctx.putImageData(tmpimage, 0, 0);
|
|
107
134
|
}
|
|
108
135
|
setContentMode(mode = 0) {
|
|
109
136
|
this.contentMode = mode;
|
|
@@ -4,7 +4,7 @@ const EventEmitter = require('events').EventEmitter;
|
|
|
4
4
|
const isEqual = require('lodash.isequal');
|
|
5
5
|
const YUVBuffer = require('yuv-buffer');
|
|
6
6
|
const YUVCanvas = require('yuv-canvas');
|
|
7
|
-
const {
|
|
7
|
+
const { isNeedKeepWidthAndHeight } = require('../util');
|
|
8
8
|
/* contentMode
|
|
9
9
|
* - 0: Cropped mode. Uniformly scale the video until it fills the visible boundaries (cropped).
|
|
10
10
|
* One dimension of the video may have clipped contents.
|
|
@@ -25,6 +25,33 @@ class Renderer {
|
|
|
25
25
|
getView() {
|
|
26
26
|
return this.element;
|
|
27
27
|
}
|
|
28
|
+
_calcZoom(vertical = false, contentMode = 0, width, height, clientWidth, clientHeight) {
|
|
29
|
+
const localRatio = clientWidth / clientHeight;
|
|
30
|
+
const tempRatio = width / height;
|
|
31
|
+
if (isNaN(localRatio) || isNaN(tempRatio)) {
|
|
32
|
+
return 1;
|
|
33
|
+
}
|
|
34
|
+
if (!contentMode) {
|
|
35
|
+
if (vertical) {
|
|
36
|
+
return localRatio > tempRatio
|
|
37
|
+
? clientHeight / height : clientWidth / width;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return localRatio < tempRatio
|
|
41
|
+
? clientHeight / height : clientWidth / width;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (vertical) {
|
|
46
|
+
return localRatio < tempRatio
|
|
47
|
+
? clientHeight / height : clientWidth / width;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return localRatio > tempRatio
|
|
51
|
+
? clientHeight / height : clientWidth / width;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
28
55
|
bind(element) {
|
|
29
56
|
this.element = element;
|
|
30
57
|
const container = document.createElement('div');
|
|
@@ -47,72 +74,47 @@ class Renderer {
|
|
|
47
74
|
this.yuv = null;
|
|
48
75
|
this.element = null;
|
|
49
76
|
this.canvas = null;
|
|
77
|
+
this.view = null;
|
|
50
78
|
}
|
|
51
79
|
refreshCanvas() {
|
|
52
80
|
}
|
|
53
81
|
updateCanvas(options = {
|
|
54
|
-
|
|
55
|
-
|
|
82
|
+
width: 0,
|
|
83
|
+
height: 0,
|
|
56
84
|
rotation: 0,
|
|
57
85
|
mirrorView: false,
|
|
58
86
|
contentMode: 0,
|
|
59
|
-
|
|
60
|
-
|
|
87
|
+
clientWidth: 0,
|
|
88
|
+
clientHeight: 0,
|
|
61
89
|
isNeedRotate: true
|
|
62
90
|
}) {
|
|
63
91
|
if (isEqual(this.cacheCanvasOpts, options)) {
|
|
64
92
|
return;
|
|
65
93
|
}
|
|
66
94
|
this.cacheCanvasOpts = Object.assign({}, options);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
for (let h = 0; h < height; h += 1) {
|
|
83
|
-
for (let w = 0; w < newWidth; w += 1) {
|
|
84
|
-
oldIndex = width * h + w;
|
|
85
|
-
newIndex = newWidth * h + w;
|
|
86
|
-
newYUint8Array[newIndex] = yUint8Array[oldIndex];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const oldChromaWidth = width / 2;
|
|
90
|
-
const newChromaWidth = newWidth / 2;
|
|
91
|
-
const chromaHeight = height / 2;
|
|
92
|
-
const newChromaSize = newChromaWidth * chromaHeight;
|
|
93
|
-
const newUArrayBuffer = new ArrayBuffer(newChromaSize);
|
|
94
|
-
const newUInt8Array = new Uint8Array(newUArrayBuffer);
|
|
95
|
-
const newVArrayBuffer = new ArrayBuffer(newChromaSize);
|
|
96
|
-
const newVInt8Array = new Uint8Array(newVArrayBuffer);
|
|
97
|
-
for (let h = 0; h < chromaHeight; h += 1) {
|
|
98
|
-
for (let w = 0; w < newChromaWidth; w += 1) {
|
|
99
|
-
oldIndex = oldChromaWidth * h + w;
|
|
100
|
-
newIndex = newChromaWidth * h + w;
|
|
101
|
-
newUInt8Array[newIndex] = uUint8Array[oldIndex];
|
|
102
|
-
newVInt8Array[newIndex] = vUint8Array[oldIndex];
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return Object.assign(Object.assign({}, imageData), { width: newWidth, height, yUint8Array: newYUint8Array, uUint8Array: newUInt8Array, vUint8Array: newVInt8Array });
|
|
95
|
+
if ([0, 90, 180, 270].indexOf(options.rotation) === -1) {
|
|
96
|
+
throw new Error('Invalid value for rotation. Only support 0, 90, 180, 270');
|
|
97
|
+
}
|
|
98
|
+
const isKeepWidthHeight = isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate);
|
|
99
|
+
if (isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate)) {
|
|
100
|
+
this.canvas.width = options.width;
|
|
101
|
+
this.canvas.height = options.height;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.canvas.height = options.width;
|
|
105
|
+
this.canvas.width = options.height;
|
|
106
|
+
}
|
|
107
|
+
this.canvas.style.zoom = this._calcZoom(!isKeepWidthHeight, options.contentMode, options.width, options.height, options.clientWidth, options.clientHeight);
|
|
108
|
+
if (options.mirrorView) {
|
|
109
|
+
this.canvas.style.transform = 'rotateY(180deg)';
|
|
106
110
|
}
|
|
107
|
-
return imageData;
|
|
108
111
|
}
|
|
109
112
|
drawFrame(imageData) {
|
|
110
113
|
if (!this.ready) {
|
|
111
114
|
this.ready = true;
|
|
112
115
|
this.event.emit('ready');
|
|
113
116
|
}
|
|
114
|
-
|
|
115
|
-
const mirror = false;
|
|
117
|
+
const mirror = 0;
|
|
116
118
|
const contentWidth = imageData.width;
|
|
117
119
|
const contentHeight = imageData.height;
|
|
118
120
|
const left = 0;
|
|
@@ -125,13 +127,11 @@ class Renderer {
|
|
|
125
127
|
const width = contentWidth + left + right;
|
|
126
128
|
const height = contentHeight + top + bottom;
|
|
127
129
|
this.updateCanvas({
|
|
128
|
-
|
|
129
|
-
contentHeight: height,
|
|
130
|
-
rotation,
|
|
130
|
+
width, height, rotation,
|
|
131
131
|
mirrorView: mirror,
|
|
132
132
|
contentMode: this.contentMode,
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
clientWidth: this.container.clientWidth,
|
|
134
|
+
clientHeight: this.container.clientHeight,
|
|
135
135
|
isNeedRotate
|
|
136
136
|
});
|
|
137
137
|
const format = YUVBuffer.format({
|
package/liteav/Render/index.d.ts
CHANGED
package/liteav/Render/index.js
CHANGED
|
@@ -9,10 +9,6 @@ const GlRenderer_1 = __importDefault(require("./GlRenderer"));
|
|
|
9
9
|
const SoftwareRenderer_1 = __importDefault(require("./SoftwareRenderer"));
|
|
10
10
|
// @ts-ignore
|
|
11
11
|
const RGBRenderer_1 = __importDefault(require("./RGBRenderer"));
|
|
12
|
-
const I420VideoRenderer_1 = __importDefault(require("./I420VideoRenderer"));
|
|
13
|
-
const BGRAVideoRenderer_1 = __importDefault(require("./BGRAVideoRenderer"));
|
|
14
|
-
const RGBAVideoRenderer_1 = __importDefault(require("./RGBAVideoRenderer"));
|
|
15
|
-
const Canvas3DRGBARenderer_1 = __importDefault(require("./Canvas3DRGBARenderer"));
|
|
16
12
|
class GlRenderer {
|
|
17
13
|
constructor() {
|
|
18
14
|
// @ts-ignore
|
|
@@ -55,9 +51,5 @@ exports.default = {
|
|
|
55
51
|
CustomRenderer,
|
|
56
52
|
GlRenderer,
|
|
57
53
|
SoftwareRenderer: SoftwareRenderer_1.default,
|
|
58
|
-
RGBRenderer: RGBRenderer_1.default
|
|
59
|
-
I420VideoRenderer: I420VideoRenderer_1.default,
|
|
60
|
-
BGRAVideoRenderer: BGRAVideoRenderer_1.default,
|
|
61
|
-
RGBAVideoRenderer: RGBAVideoRenderer_1.default,
|
|
62
|
-
Canvas3DRGBARenderer: Canvas3DRGBARenderer_1.default,
|
|
54
|
+
RGBRenderer: RGBRenderer_1.default
|
|
63
55
|
};
|
package/liteav/Render/util.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { TRTCVideoStreamType } from "../trtc_define";
|
|
3
1
|
/**
|
|
4
2
|
* 配置对象, 可用来打开 debug 模式
|
|
5
3
|
*
|
|
@@ -17,30 +15,4 @@ export declare class Config {
|
|
|
17
15
|
getDebugMode(): boolean;
|
|
18
16
|
}
|
|
19
17
|
export declare function isNeedKeepWidthAndHeight(rotation: number, isNeedRotate: boolean): boolean;
|
|
20
|
-
export declare function calcScaleRate(vertical: boolean, contentMode: number, contentWidth: number, contentHeight: number, containerWidth: number, containerHeight: number): number;
|
|
21
|
-
export declare function calcCanvasStyle(options?: {
|
|
22
|
-
contentWidth: number;
|
|
23
|
-
contentHeight: number;
|
|
24
|
-
rotation: number;
|
|
25
|
-
mirrorView: boolean;
|
|
26
|
-
contentMode: number;
|
|
27
|
-
containerWidth: number;
|
|
28
|
-
containerHeight: number;
|
|
29
|
-
isNeedRotate: boolean;
|
|
30
|
-
}): {
|
|
31
|
-
[x: string]: any;
|
|
32
|
-
};
|
|
33
|
-
export declare function calcVideoStyle(options?: {
|
|
34
|
-
contentWidth: number;
|
|
35
|
-
contentHeight: number;
|
|
36
|
-
rotation: number;
|
|
37
|
-
mirrorView: boolean;
|
|
38
|
-
contentMode: number;
|
|
39
|
-
containerWidth: number;
|
|
40
|
-
containerHeight: number;
|
|
41
|
-
isNeedRotate: boolean;
|
|
42
|
-
}): {
|
|
43
|
-
[x: string]: any;
|
|
44
|
-
};
|
|
45
18
|
export declare const config: Config;
|
|
46
|
-
export declare function allocBuffer(length: number, userId?: string, streamType?: TRTCVideoStreamType): Buffer;
|
package/liteav/Render/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.config = exports.isNeedKeepWidthAndHeight = exports.Config = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 配置对象, 可用来打开 debug 模式
|
|
6
6
|
*
|
|
@@ -28,110 +28,4 @@ function isNeedKeepWidthAndHeight(rotation, isNeedRotate) {
|
|
|
28
28
|
return rotation === 0 || rotation === 180 || !isNeedRotate;
|
|
29
29
|
}
|
|
30
30
|
exports.isNeedKeepWidthAndHeight = isNeedKeepWidthAndHeight;
|
|
31
|
-
function calcScaleRate(vertical = false, contentMode = 0, contentWidth, contentHeight, containerWidth, containerHeight) {
|
|
32
|
-
const containerRatio = containerWidth / containerHeight;
|
|
33
|
-
const contentRatio = contentWidth / contentHeight;
|
|
34
|
-
if (isNaN(containerRatio) || isNaN(contentRatio)) {
|
|
35
|
-
return 1;
|
|
36
|
-
}
|
|
37
|
-
if (!contentMode) {
|
|
38
|
-
if (vertical) {
|
|
39
|
-
return containerRatio > contentRatio
|
|
40
|
-
? containerHeight / contentHeight : containerWidth / contentWidth;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
return containerRatio < contentRatio
|
|
44
|
-
? containerHeight / contentHeight : containerWidth / contentWidth;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
if (vertical) {
|
|
49
|
-
return containerRatio < contentRatio
|
|
50
|
-
? containerHeight / contentHeight : containerWidth / contentWidth;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return containerRatio > contentRatio
|
|
54
|
-
? containerHeight / contentHeight : containerWidth / contentWidth;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.calcScaleRate = calcScaleRate;
|
|
59
|
-
function calcCanvasStyle(options = {
|
|
60
|
-
contentWidth: 0,
|
|
61
|
-
contentHeight: 0,
|
|
62
|
-
rotation: 0,
|
|
63
|
-
mirrorView: false,
|
|
64
|
-
contentMode: 0,
|
|
65
|
-
containerWidth: 0,
|
|
66
|
-
containerHeight: 0,
|
|
67
|
-
isNeedRotate: true
|
|
68
|
-
}) {
|
|
69
|
-
if ([0, 90, 180, 270].indexOf(options.rotation) === -1) {
|
|
70
|
-
throw new Error('Invalid value for rotation. Only support 0, 90, 180, 270');
|
|
71
|
-
}
|
|
72
|
-
const style = {
|
|
73
|
-
width: 0,
|
|
74
|
-
height: 0,
|
|
75
|
-
transform: ''
|
|
76
|
-
};
|
|
77
|
-
const isKeepWidthHeight = isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate);
|
|
78
|
-
if (isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate)) {
|
|
79
|
-
style.width = options.contentWidth;
|
|
80
|
-
style.height = options.contentHeight;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
style.height = options.contentWidth;
|
|
84
|
-
style.width = options.contentHeight;
|
|
85
|
-
}
|
|
86
|
-
const scale = calcScaleRate(!isKeepWidthHeight, options.contentMode, style.width, style.height, options.containerWidth, options.containerHeight);
|
|
87
|
-
style.transform = `scale(${scale})`;
|
|
88
|
-
if (options.mirrorView) {
|
|
89
|
-
style.transform = `${style.transform} rotateY(180deg)`;
|
|
90
|
-
}
|
|
91
|
-
return style;
|
|
92
|
-
}
|
|
93
|
-
exports.calcCanvasStyle = calcCanvasStyle;
|
|
94
|
-
function calcVideoStyle(options = {
|
|
95
|
-
contentWidth: 0,
|
|
96
|
-
contentHeight: 0,
|
|
97
|
-
rotation: 0,
|
|
98
|
-
mirrorView: false,
|
|
99
|
-
contentMode: 0,
|
|
100
|
-
containerWidth: 0,
|
|
101
|
-
containerHeight: 0,
|
|
102
|
-
isNeedRotate: true
|
|
103
|
-
}) {
|
|
104
|
-
if ([0, 90, 180, 270].indexOf(options.rotation) === -1) {
|
|
105
|
-
throw new Error('Invalid value for rotation. Only support 0, 90, 180, 270');
|
|
106
|
-
}
|
|
107
|
-
let width = 0;
|
|
108
|
-
let height = 0;
|
|
109
|
-
const isKeepWidthHeight = isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate);
|
|
110
|
-
if (isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate)) {
|
|
111
|
-
width = options.contentWidth;
|
|
112
|
-
height = options.contentHeight;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
height = options.contentWidth;
|
|
116
|
-
width = options.contentHeight;
|
|
117
|
-
}
|
|
118
|
-
const scale = calcScaleRate(!isKeepWidthHeight, options.contentMode, width, height, options.containerWidth, options.containerHeight);
|
|
119
|
-
const style = {
|
|
120
|
-
width: `${width * scale}px`,
|
|
121
|
-
height: `${height * scale}px`,
|
|
122
|
-
};
|
|
123
|
-
if (options.mirrorView) {
|
|
124
|
-
style.transform = 'rotateY(180deg)';
|
|
125
|
-
}
|
|
126
|
-
return style;
|
|
127
|
-
}
|
|
128
|
-
exports.calcVideoStyle = calcVideoStyle;
|
|
129
31
|
exports.config = new Config();
|
|
130
|
-
function allocBuffer(length, userId, streamType) {
|
|
131
|
-
console.debug('trtc:alloc buffer:', length, userId, streamType);
|
|
132
|
-
if (length >= 1) {
|
|
133
|
-
return Buffer.alloc(length);
|
|
134
|
-
}
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
exports.allocBuffer = allocBuffer;
|