UNPKG

trtc-electron-sdk

Version:

trtc electron sdk

580 lines (579 loc) 27.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TRTCLocalMediaTranscodingSourceType = exports.TRTCLocalMediaTranscodingError = void 0; const events_1 = require("events"); const trtc_define_1 = require("../trtc_define"); const Renderer_1 = require("../Renderer"); const util_1 = require("../Renderer/util"); const types_1 = require("./types"); const logger_1 = __importDefault(require("../logger")); var types_2 = require("./types"); Object.defineProperty(exports, "TRTCLocalMediaTranscodingError", { enumerable: true, get: function () { return types_2.TRTCLocalMediaTranscodingError; } }); Object.defineProperty(exports, "TRTCLocalMediaTranscodingSourceType", { enumerable: true, get: function () { return types_2.TRTCLocalMediaTranscodingSourceType; } }); /** * @description 本地媒体流混流转码错误码 * @enum {Number} */ const TRTCLocalMediaTranscodingError_HACK_JSDOC = { /** 调用成功。 */ Success: 0, /** 通用错误码。 */ Error: -1, /** 参数非法。 */ InvalidParams: -2, /** 数据源混流异常,数据源超过 30 秒没数据。 */ NotFoundSource: -3, /** 图片源加载失败。*/ ImageSourceLoadFailed: -4, }; /** * 媒体源类型 * @enum {Number} */ const TRTCLocalMediaTranscodingSourceType_HACK_JSDOC = { /** 摄像头媒体类型 */ MediaSourceCamera: 0, /** 屏幕媒体类型 */ MediaSourceScreen: 1, /** 图片媒体类型,目前只支持 BMP、JPG、PNG、GIF 四种格式 */ MediaSourceImage: 2, /** 预留字段,当前版本不支持远端用户视频源混流转码 */ MediaSourceRemoteVideo: 3 }; /** * 媒体源 * @namespace TRTCLocalMediaTranscoding * @typedef {Object} TRTCLocalMediaTranscodingSource - 媒体源 * @property {TRTCLocalMediaTranscodingSourceType} mode - 【字段含义】媒体类型。 * @property {String} cameraDeviceId * 【字段含义】摄像头 ID<br/> * 当 sourceType 为 TRTCMediaSourceCamera 时此字段有效,您可以使用该字段指定摄像头的设备 * ID,摄像头的设备 ID 可以通过 TRTCCloud 的 getCameraDevicesList() 接口获取 * @property {String} screenSourceId * 【字段含义】屏幕或窗口 ID<br/> * 当 sourceType 为 TRTCMediaSourceCamera 时此字段有效,您可以使用该字段指定整个屏幕或者某个窗口的窗口 ID。 * 您可以通过 TRTCCloud 中的 getScreenCaptureSources 接口获取可以被分享的窗口 ID。 * @property {String} imagePath * 【字段含义】图像的地址<br/> * 当 sourceType 为 TRTCMediaSourceCamera 时此字段有效,您可以使用该字段指定图片的文件路径,目前版本只支持 BMP、JPG、PNG、GIF 四种图像格式。 * @property {String} userId * 【字段含义】远端视频流的用户 ID<br/> * 当 sourceType 为 TRTCMediaSourceCamera 时此字段有效,不过当前版本的 SDK 还不支持这个能力。 * @property {Rect} rect - 【字段含义】指定该路画面的坐标区域(单位:像素)。 * @property {Number} zOrder - 【字段含义】指定该路画面的层级(取值范围:0 - 15,不可重复)。 * @property {TRTCRenderParams} renderParams - 【字段含义】指定该路数据源是否旋转、镜像和填充模式。 */ const TRTCLocalMediaTranscodingSource_HACK_JSDOC = null; /** * 本地媒体流混流转码配置参数 * @typedef {Object} TRTCLocalMediaTranscodingParams - 本地媒体流混流转码配置参数 * @property {Array<TRTCLocalMediaTranscodingSource>} inputSourceList * 【字段含义】指定转码流中的每一路输入媒体源配置的信息。<br/> * 【推荐取值】该字段是一个 TRTCLocalMediaTranscodingSource 类型的数组,数组中的每一个元素都用来代表每一路输入媒体源的信息。<br/> * 【特别说明】媒体源信息不支持留空,否则 TRTCLocalMediaTranscoder 的 onTranscodingStarted 会报错。 * * @property {TRTCVideoEncParam} videoEncoderParams * 【字段含义】转码流的视频编码参数。 * * @property {Number} canvasColor * 【字段含义】指定混合画面的底色。<br/> * 【推荐取值】默认值:0x000000 代表黑色。格式为十六进制数字,比如:“0x61B9F1” 代表 RGB 分别为(97、158、241)。 */ const TRTCLocalMediaTranscodingParams_HACK_JSDOC = null; /** * @description 本地媒体流混流转码(目前只支持 Windows) * * @extends EventEmitter * * @example * // 运行示例 * import TRTCCloud, { * TRTCCameraCaptureMode, * TRTCVideoRotation, * TRTCVideoFillMode, * TRTCVideoMirrorType, * TRTCVideoStreamType, * TRTCLocalMediaTranscodingSourceType, * TRTCVideoResolution, * TRTCVideoResolutionMode, * TRTCVideoPixelFormat * } from 'trtc-electron-sdk'; * * const trtcCloud = TRTCCloud.getTRTCShareInstance(); * const cameraList =trtcCloud.getCameraDevicesList(); * * // 获取本地合图转码推流对象 * const localMediaTranscoder =trtcCloud.createLocalMediaTranscoder({ * pixelFormat: TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420, * }); * * // 注册事件监听 * // 监听合图开始、结束事件 * localMediaTranscoder.on('onTranscodingStarted', (errCode: number, errMsg: string) => { * console.log(`onTranscodingStarted { errCode:${errCode} errMsg:${errMsg}`); * }); * localMediaTranscoder.on('onTranscodingStopped', (reason: number, reasonMsg: string) => { * console.log(`onTranscodingStopped { reason:${reason} reasonMsg:${reasonMsg} }`); * }); * // 监听摄像头事件 * localMediaTranscoder.on('onCameraSourceStarted', (deviceId: string, errCode: number, errMsg: string) => { * console.log(`onCameraSourceStarted { deviceId:${deviceId} errCode:${errCode} errMsg:${errMsg} }`); * }); * localMediaTranscoder.on('onCameraSourceStopped', (deviceId: string, reasonMsg: string) => { * console.log(`onCameraSourceStopped { deviceId:${deviceId} reasonMsg:${reasonMsg}}`); * }); * // 监听屏幕、窗口分享事件 * localMediaTranscoder.on('onScreenSourceStarted', (sourceId: string, errCode: number, errMsg: string) => { * console.log(`onScreenSourceStarted { sourceId:${sourceId} errCode:${errCode} errMsg:${errMsg} }`); * }); * localMediaTranscoder.on('onScreenSourceStopped', (sourceId: string, reason: number) => { * console.log(`onScreenSourceStopped { sourceId:${sourceId}, reason:${reason} }`); * }); * // 监听图片事件 * localMediaTranscoder.on('onImageSourceStarted', (imagePath: string, errCode: number, errMsg: string) => { * console.log(`onImageSourceStarted { imagePath:${imagePath} errCode:${errCode} errMsg:${errMsg} }`); * }); * localMediaTranscoder.on('onImageSourceStopped', (imagePath: string) => { * console.log(`onImageSourceStopped { imagePath:${imagePath} }`); * }); * * // 开启摄像头一 * localMediaTranscoder.startCameraSource(cameraList[0].deviceId); * localMediaTranscoder.setCameraCaptureParams( * cameraList[0].deviceId, * { * mode: TRTCCameraCaptureMode.TRTCCameraResolutionStrategyAuto, * width: 480, * height: 480, * } * ); * * // 开启摄像头二 * localMediaTranscoder.startCameraSource(cameraList[1].deviceId); * localMediaTranscoder.setCameraCaptureParams( * cameraList[1].deviceId, * { * mode: TRTCCameraCaptureMode.TRTCCameraResolutionStrategyAuto, * width: 960, * height: 540 * } * ); * * * // 开启屏幕一 * localMediaTranscoder.startScreenSource(screenSourceList[0], {top:10, left:10, right:1200, bottom:800}); * * // 开启屏幕二 * localMediaTranscoder.startScreenSource(screenSourceList[1], {top:0, left:0, right:0, bottom:0}); * * // 加载图片一 * localMediaTranscoder.addImageSource('<please set valid image path>', 15); * * // 加载图片二 * localMediaTranscoder.addImageSource('<please set valid image path>', 15); * * // 启动合图转码并推流 * localMediaTranscoder.startTranscoding( * TRTCVideoStreamType.TRTCVideoStreamTypeBig, * { * inputSourceList: [ * { // camera 1 * sourceType: TRTCLocalMediaTranscodingSourceType.MediaSourceCamera, * cameraDeviceId: cameraList[0].deviceId, * rect: { left: 0, top: 0, right: 320, bottom: 180 }, * zOrder: 1, * renderParams: { * rotation: TRTCVideoRotation.TRTCVideoRotation0, * fillMode: TRTCVideoFillMode.TRTCVideoFillMode_Fit, * mirrorType: TRTCVideoMirrorType.TRTCVideoMirrorType_Disable * }, * }, * { // camera 2 * sourceType: TRTCLocalMediaTranscodingSourceType.MediaSourceCamera, * cameraDeviceId: cameraList[1].deviceId, * rect: {left: 320 + 20, top: 180 + 20, right: 640 + 20, bottom: 360 + 20}, * zOrder: 2, * renderParams: { * rotation: TRTCVideoRotation.TRTCVideoRotation90, * fillMode: TRTCVideoFillMode.TRTCVideoFillMode_Fill, * mirrorType: TRTCVideoMirrorType.TRTCVideoMirrorType_Enable * }, * }, * { * // screen 1 * sourceType: TRTCLocalMediaTranscodingSourceType.MediaSourceScreen, * screenSourceId: screenSourceList[0].sourceId, * rect: {left: 320 + 20, top: 0, right: 640 + 20, bottom: 180}, * zOrder: 3, * renderParams: { * rotation: TRTCVideoRotation.TRTCVideoRotation180, * fillMode: TRTCVideoFillMode.TRTCVideoFillMode_Fit, * mirrorType: TRTCVideoMirrorType.TRTCVideoMirrorType_Enable * }, * }, * { * // screen 2 * sourceType: TRTCLocalMediaTranscodingSourceType.MediaSourceScreen, * screenSourceId: screenSourceList[1].sourceId, * rect: {left: 0, top: 180 + 20, right: 320, bottom: 360 + 20}, * zOrder: 4, * renderParams: { * rotation: TRTCVideoRotation.TRTCVideoRotation270, * fillMode: TRTCVideoFillMode.TRTCVideoFillMode_Fill, * mirrorType: TRTCVideoMirrorType.TRTCVideoMirrorType_Auto * }, * }, * { // image 1 * sourceType: TRTCLocalMediaTranscodingSourceType.MediaSourceImage, * imagePath: '<please set valid image path>', * rect: {left: 0, top: 360 + 40, right: 320, bottom: 540 + 40}, * zOrder: 5, * renderParams: { * rotation: TRTCVideoRotation.TRTCVideoRotation90, // 不会生效,参数设置将被忽略 * fillMode: TRTCVideoFillMode.TRTCVideoFillMode_Fit, * mirrorType: TRTCVideoMirrorType.TRTCVideoMirrorType_Enable // 不会生效,参数设置将被忽略 * }, * }, * { // image 2 * sourceType: TRTCLocalMediaTranscodingSourceType.MediaSourceImage, * imagePath: '<please set valid image path>', * rect: {left: 320 + 20, top: 360 + 40, right: 640, bottom: 540 + 40}, * zOrder: 5, * renderParams: { * rotation: TRTCVideoRotation.TRTCVideoRotation0, // 不会生效,参数设置将被忽略 * fillMode: TRTCVideoFillMode.TRTCVideoFillMode_Fill, * mirrorType: TRTCVideoMirrorType.TRTCVideoMirrorType_Disable // 不会生效,参数设置将被忽略 * }, * } * ], * videoEncoderParams: { * videoResolution: TRTCVideoResolution.TRTCVideoResolution_960_720, * resMode: TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape, * videoFps: 30, * videoBitrate: 800, * minVideoBitrate: 0, * enableAdjustRes: false, * }, * canvasColor: 0xff0000, // 0x61b9f1, * } * ); * * // 设置本地预览 * const view = document.getElementById("preview-view"); * localMediaTranscoder.setMixedVideoRenderView(view as HTMLElement); */ class TRTCLocalMediaTranscoder extends events_1.EventEmitter { constructor(nativeLocalMediaTranscoder, pixelFormat) { super(); this.logPrefix = '[TRTCLocalMediaTranscoder]'; this.nativeLocalMediaTranscoder = nativeLocalMediaTranscoder; this.renderer = null; this.container = null; this.pixelFormat = pixelFormat || trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420; this.pixelLength = this.pixelFormat === trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420 ? 1.5 : 4; this.streamType = trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig; this.videoRenderBuffer = new trtc_define_1.VideoBufferInfo({ userId: '', id: (0, util_1.generateUniqueId)(), streamType: this.streamType, width: 1920, height: 1080, pixelFormat: this.pixelFormat, }); this.setEventCallback(); this.nativeLocalMediaTranscoder.setVideoFrameProcessCallback(this.pixelFormat); } destroy() { var _a; try { if (this.nativeLocalMediaTranscoder) { // 避免重复销毁报错 this.nativeLocalMediaTranscoder.setVideoFrameRenderCallback(this.pixelFormat, null); this.nativeLocalMediaTranscoder.setVideoFrameProcessCallback(trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_Unknown); this.nativeLocalMediaTranscoder = null; } this.videoRenderBuffer.buffer = null; this.videoRenderBuffer.id = 0; (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.destroy(); this.renderer = null; this.container = null; } catch (error) { logger_1.default.warn(`${this.logPrefix}destroy error`, error); } } // 帧率、码率在 JS 层为数值,可能被设置为负数,底层要求为无符号整数,此处做检验并将负值设置为零 validateTranscodingConfig(params) { if (params.videoEncoderParams.videoFps < 0) { params.videoEncoderParams.videoFps = 0; } if (params.videoEncoderParams.videoBitrate < 0) { params.videoEncoderParams.videoBitrate = 0; } if (params.videoEncoderParams.minVideoBitrate < 0) { params.videoEncoderParams.minVideoBitrate = 0; } } /** * 启动本地混流转码 * * @param streamType {TRTCVideoStreamType} - 指定使用 TRTC 的 TRTCVideoStreamTypeBig 来推流,还是 TRTCVideoStreamTypeSub 来推流。 * @param params {TRTCLocalMediaTranscodingParams} - 指定本地混流转码的参数 * @param params.inputSourceList {TRTCLocalMediaTranscodingSource} - 【字段含义】指定转码流中的每一路输入媒体源配置的信息。 * -【推荐取值】该字段是一个 TRTCLocalMediaTranscodingSource 类型的数组,数组中的每一个元素都用来代表每一路输入媒体源的信息。 * -【特别说明】媒体源信息不支持留空,否则 TRTCLocalMediaTranscoder 的 onTranscodingStarted 会报错。 * @param params.videoEncoderParams {TRTCVideoEncParam} -【字段含义】转码流的视频编码参数 * @param params.canvasColor {Number} - 【字段含义】指定混合画面的底色。 * -【推荐取值】默认值:0x000000 代表黑色。格式为十六进制数字,比如:“0x61B9F1” 代表 RGB 分别为(97、158、241)。 * * @fires [onTranscodingStarted]{@link TRTCLocalMediaTranscodingEvent#onTranscodingStarted} */ startTranscoding(streamType, params) { this.validateTranscodingConfig(params); if (streamType !== this.streamType) { this.streamType = streamType; this.videoRenderBuffer.streamType = this.streamType; } this.nativeLocalMediaTranscoder.startTranscoding(streamType, params); } /** * 更新本地混流转码参数 * * @param params {TRTCLocalMediaTranscodingParams} - 指定本地混流转码的参数 */ updateTranscodingParams(params) { this.validateTranscodingConfig(params); this.nativeLocalMediaTranscoder.updateTranscodingParams(params); } /** * 停止本地混流转码 * * @fires [onTranscodingStopped]{@link TRTCLocalMediaTranscodingEvent#onTranscodingStopped} */ stopTranscoding() { this.nativeLocalMediaTranscoder.stopTranscoding(); } /** * 启动摄像头采集 * * @param deviceId {String} - 摄像头设备 Id * * @fires [onCameraSourceStarted]{@link TRTCLocalMediaTranscodingEvent#onCameraSourceStarted} */ startCameraSource(deviceId) { this.nativeLocalMediaTranscoder.startCameraSource(deviceId); } /** * 设置摄像头采集参数 * * @param deviceId {String} - 摄像头设备 Id * @param cameraCaptureParams {TRTCCameraCaptureParams} - 指定摄像头采集分辨率和帧率 */ setCameraCaptureParams(deviceId, cameraCaptureParams) { this.nativeLocalMediaTranscoder.setCameraCaptureParam(deviceId, cameraCaptureParams); } /** * 停止摄像头采集 * @param deviceId {String} - 摄像头设备 Id * * @fires [onCameraSourceStopped]{@link TRTCLocalMediaTranscodingEvent#onCameraSourceStopped} */ stopCameraSource(deviceId) { this.nativeLocalMediaTranscoder.stopCameraSource(deviceId); } /** * 启用摄像头采集画面绿幕抠图 * * @param cameraDeviceId {String} - 摄像头设备 ID。 * @param enable {Boolean} - 是否启用摄像头采集画面绿幕抠图。 * @param color {Number} - 指定画面中需要抠除的颜色值。默认值:0x00FF00 代表绿色。格式为十六进制数字,比如:“0x61B9F1” 代表 RGB 分别为(97、185、241)。 */ enableCameraGreenScreen(deviceId, enable) { this.nativeLocalMediaTranscoder.enableCameraGreenScreen(deviceId, enable); } /** * 启动屏幕/窗口采集 * * @param source {TRTCScreenCaptureSourceInfo} - 屏幕/窗口采集的详细参数 * @param rect {Rect} - 指定捕获的区域 * * @fires [onScreenSourceStarted]{@link TRTCLocalMediaTranscodingEvent#onScreenSourceStarted} */ startScreenSource(source, rect) { this.nativeLocalMediaTranscoder.startScreenSource(source, rect); } /** * 更新窗口/屏幕采集属性 * * @param {String} sourceId 屏幕/窗口的 Id * @param {TRTCScreenCaptureProperty} property 屏幕/窗口采集参数 */ updateScreenCaptureProperty(sourceId, property) { this.nativeLocalMediaTranscoder.updateScreenCaptureProperty(sourceId, property); } /** * 停止屏幕/窗口采集 * @param sourceId {String} - 屏幕/窗口的 Id * * @fires [onScreenSourceStopped]{@link TRTCLocalMediaTranscodingEvent#onScreenSourceStopped} */ stopScreenSource(sourceId) { this.nativeLocalMediaTranscoder.stopScreenSource(sourceId); } /** * 启动图片采集 * @param path {String} - 图片路径 ,目前只支持 BMP、JPG、PNG、GIF 四种格式 * @param fps {Number} - 采集输出帧率,可以不设置由 SDK 做最佳决策 * * @fires [onImageSourceStarted]{@link TRTCLocalMediaTranscodingEvent#onImageSourceStarted} */ addImageSource(path, fps) { this.nativeLocalMediaTranscoder.addImageSource(path, fps); } /** * 停止图片采集 * @param path {String} - 图片路径 * * @fires [onImageSourceStopped]{@link TRTCLocalMediaTranscodingEvent#onImageSourceStopped} */ removeImageSource(path) { this.nativeLocalMediaTranscoder.removeImageSource(path); } /** * 设置本地混流转码视频预览节点 * @param view {HTMLElement | null} - 如果传入的是 HTML 元素,必须是块元素;传入 null 时,会停止视频预览 */ setMixedVideoRenderView(view) { if (view && view instanceof HTMLElement) { if (this.container === view) { return; // 重复在同一个 HTML 节点内渲染,不用处理,直接退出 } else if (this.renderer) { // 渲染的 HTML 节点发生改变,之前已经存在渲染器,先销毁之前渲染器 this.renderer.destroy(); this.renderer = null; // 重新记录渲染的 HTML 节点并创建渲染器 this.container = view; this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container, { type: Renderer_1.RenderType.Video, onContextLost: () => { this.container = view; this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container, { type: Renderer_1.RenderType.Canvas2D }); }, }); } else { // 第一次设置渲染的 HTML 节点,并创建渲染器,设置渲染回调 this.container = view; this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container, { type: Renderer_1.RenderType.Video, onContextLost: () => { this.container = view; this.renderer = (0, Renderer_1.createRenderer)(this.pixelFormat, this.container, { type: Renderer_1.RenderType.Canvas2D }); }, }); this.setMixedVideoFrameRenderCallback(); } } else { if (this.renderer) { this.renderer.destroy(); this.renderer = null; } this.container = null; this.unsetMixedVideoFrameRenderCallback(); } } setMixedVideoFrameRenderCallback() { const renderCallback = (args) => { const [id, type, width, height, timestamp, rotation, valid, bufferId] = args; if (valid === true) { this.renderMixedVideoFrame({ data: this.videoRenderBuffer.buffer, width: width, height: height, timestamp: timestamp, rotation: rotation, }); } else { logger_1.default.info(`${this.logPrefix} video size changed:`, width, height); this.videoRenderBuffer.width = width; this.videoRenderBuffer.height = height; this.videoRenderBuffer.buffer = (0, util_1.allocBuffer)(width * height * this.pixelLength); this.nativeLocalMediaTranscoder.setVideoFrameRenderBuffer(this.videoRenderBuffer.userId, this.videoRenderBuffer.buffer, this.videoRenderBuffer.streamType, this.videoRenderBuffer.width, this.videoRenderBuffer.height, this.videoRenderBuffer.pixelFormat, this.videoRenderBuffer.id); } }; this.nativeLocalMediaTranscoder.setVideoFrameRenderBuffer(this.videoRenderBuffer.userId, this.videoRenderBuffer.buffer, this.videoRenderBuffer.streamType, this.videoRenderBuffer.width, this.videoRenderBuffer.height, this.videoRenderBuffer.pixelFormat, this.videoRenderBuffer.id); this.nativeLocalMediaTranscoder.setVideoFrameRenderCallback(this.pixelFormat, renderCallback); } unsetMixedVideoFrameRenderCallback() { this.nativeLocalMediaTranscoder.setVideoFrameRenderCallback(this.pixelFormat, null); this.videoRenderBuffer.width = 0; this.videoRenderBuffer.height = 0; this.nativeLocalMediaTranscoder.setVideoFrameRenderBuffer(this.videoRenderBuffer.userId, this.videoRenderBuffer.buffer, this.videoRenderBuffer.streamType, this.videoRenderBuffer.width, this.videoRenderBuffer.height, this.videoRenderBuffer.pixelFormat, this.videoRenderBuffer.id); } setEventCallback() { const eventCallback = (args) => { const key = args[0]; const data = args[1]; logger_1.default.debug(`${this.logPrefix}event:`, key, data); switch (key) { case types_1.TRTCLocalMediaTranscodingEvents.onTranscodingStarted: this.emit(key, data.errCode, data.errMsg); break; case types_1.TRTCLocalMediaTranscodingEvents.onTranscodingStopped: this.emit(key, data.reason, data.reasonMsg); break; case types_1.TRTCLocalMediaTranscodingEvents.onCameraSourceStarted: this.emit(key, data.deviceId, data.errCode, data.errMsg); break; case types_1.TRTCLocalMediaTranscodingEvents.onCameraSourceStopped: this.emit(key, data.deviceId, data.errCode, data.reasonMsg); break; case types_1.TRTCLocalMediaTranscodingEvents.onImageSourceStarted: this.emit(key, data.imagePath, data.errCode, data.errMsg); break; case types_1.TRTCLocalMediaTranscodingEvents.onImageSourceStopped: this.emit(key, data.imagePath); break; case types_1.TRTCLocalMediaTranscodingEvents.onScreenSourceStarted: this.emit(key, data.sourceId, data.errCode, data.errMsg); break; case types_1.TRTCLocalMediaTranscodingEvents.onScreenSourcePaused: case types_1.TRTCLocalMediaTranscodingEvents.onScreenSourceResumed: case types_1.TRTCLocalMediaTranscodingEvents.onScreenSourceStopped: this.emit(key, data.sourceId, data.reason); break; case types_1.TRTCLocalMediaTranscodingEvents.onMediaSourceSizeChanged: this.emit(key, data.mediaSource, data.newSize); break; default: logger_1.default.warn(`${this.logPrefix}unkown event type:${key}`); } }; this.nativeLocalMediaTranscoder.setTranscodingCallback(eventCallback); } renderMixedVideoFrame(frame) { if (!this.renderer || !this.container) { return; } const { width, height, data, timestamp, rotation } = frame; if (data) { const realRotation = rotation * 90; // const newData = data.slice(0); // Electron 12及以下版本需要复制一次,否则会引起奔溃。 this.renderer.drawFrame({ data, width, height, timestamp, rotation: realRotation, isNeedRotate: false, }); } } } exports.default = TRTCLocalMediaTranscoder;