public void SendCustomVideoFrame() { if (!mStartCustomCaptureVideo) { return; } try { using (FileStream fs = File.OpenRead(mVideoFilePath)) { uint bufSize = mVideoWidth * mVideoHeight * 3 / 2; if (mVideoBuffer == null) { mVideoBuffer = new byte[bufSize]; } if (mOffsetVideoRead + bufSize > mVideoFileLength) { mOffsetVideoRead = 0; } fs.Seek(mOffsetVideoRead, SeekOrigin.Begin); fs.Read(mVideoBuffer, 0, (int)bufSize); mOffsetVideoRead += bufSize; TRTCVideoFrame frame = new TRTCVideoFrame(); frame.videoFormat = TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420; frame.data = mVideoBuffer; frame.width = mVideoWidth; frame.height = mVideoHeight; frame.length = bufSize; mTRTCCloud.sendCustomVideoData(frame); } } catch (Exception e) { Log.E(e.Message); } }
public void onRenderVideoFrame(string userId, TRTCVideoStreamType streamType, TRTCVideoFrame frame) { // 大小视频是占一个视频位,底层支持动态切换。 if (streamType == TRTCVideoStreamType.TRTCVideoStreamTypeSmall) { streamType = TRTCVideoStreamType.TRTCVideoStreamTypeBig; } TXLiteAVVideoView view = null; lock (mMapViews) { foreach (var item in mMapViews) { if (item.Key.Equals(GetKey(userId, streamType)) && item.Value != null) { view = item.Value; break; } } } if (view != null) { view.AppendVideoFrame(frame.data, (int)frame.width, (int)frame.height, frame.videoFormat, frame.rotation); } }
public void onRenderVideoFrame(string userId, TRTCVideoStreamType streamType, TRTCVideoFrame frame) { // 回调不是在主线程,处理数据时需要注意多线程下的同步问题 if (mIsStartCustomRender && string.IsNullOrEmpty(userId) && streamType == TRTCVideoStreamType.TRTCVideoStreamTypeBig) { AppendVideoFrame(frame.data, frame.length, frame.width, frame.height, frame.videoFormat, frame.rotation); // 实时刷新画面渲染数据 this.Invoke(new Action(() => { this.Refresh(); })); } }