UNPKG

trtc-electron-sdk

Version:

trtc electron sdk

93 lines (92 loc) 3.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VideoRender = void 0; const index_1 = require("../../Renderer/index"); const util_1 = require("../../Renderer/util"); const trtc_define_1 = require("../../trtc_define"); const DEFAULT_VIDEO_WIDTH = 640; const DEFAULT_VIDEO_HEIGHT = 360; class VideoRender { constructor() { this.view = null; this.videoRender = null; this.pixelFormat = trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420; this.videoBuffer = new trtc_define_1.VideoBufferInfo(); this.pixelLength = 1.5; this.mode = trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fill; this._initVideoBuffer(); } destroy() { this.destroyRender(); } setRenderView(view) { if (this.view === view) { return; } this.view = view; this.destroyRender(); if (view !== null) { this.createRender(); } } createRender() { if (this.view !== null && this.videoRender === null) { this.videoRender = (0, index_1.createRenderer)(this.pixelFormat, this.view, { type: index_1.RenderType.Video }); this.videoRender.setContentMode(this.mode); } } destroyRender() { var _a; (_a = this.videoRender) === null || _a === void 0 ? void 0 : _a.destroy(); this.videoRender = null; } getVideoBuffer() { return this.videoBuffer; } setVideoFillMode(mode) { var _a; this.mode = mode; (_a = this.videoRender) === null || _a === void 0 ? void 0 : _a.setContentMode(this.mode); } setVideoPixelFormat(format) { if (this.pixelFormat === format) { return; } this.pixelFormat = format; this.pixelLength = this.pixelFormat === trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420 ? 1.5 : 4; } setUserId(userId) { this.videoBuffer.userId = userId; } renderVideoData(userId, streamType, width, height, timestamp, rotation, valid, bufferId) { var _a; if (userId !== this.videoBuffer.userId || bufferId !== this.videoBuffer.id) { return false; } if (valid) { const data = this.videoBuffer.buffer; const isNeedRotate = false; (_a = this.videoRender) === null || _a === void 0 ? void 0 : _a.drawFrame({ data: data, width, height, timestamp, rotation, isNeedRotate }); return true; } else { this._onBufferSizeChanged(width, height); return false; } } _initVideoBuffer() { this.videoBuffer.streamType = trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig; this.videoBuffer.width = DEFAULT_VIDEO_WIDTH; this.videoBuffer.height = DEFAULT_VIDEO_HEIGHT; this.videoBuffer.pixelFormat = this.pixelFormat; this.videoBuffer.id = (0, util_1.generateUniqueId)(); this.videoBuffer.buffer = (0, util_1.allocBuffer)(this.videoBuffer.width * this.videoBuffer.height * this.pixelLength); } _onBufferSizeChanged(width, height) { if (width !== this.videoBuffer.width || height !== this.videoBuffer.height) { this.videoBuffer.buffer = null; this.videoBuffer.width = width; this.videoBuffer.height = height; this.videoBuffer.buffer = (0, util_1.allocBuffer)(this.videoBuffer.width * this.videoBuffer.height * this.pixelLength); } } } exports.VideoRender = VideoRender;