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(); })); } }
/// <summary> /// 移除自定义渲染 View 并解绑渲染回调 /// </summary> private void RemoveCustomVideoView(Panel parent, string userId, TRTCVideoStreamType streamType, bool local = false) { TXLiteAVVideoView videoView = null; string key = String.Format("{0}_{1}", userId, streamType); if (mVideoViews.TryGetValue(key, out videoView)) { videoView.RemoveEngine(mTRTCCloud); parent.Children.Remove(videoView); mVideoViews.Remove(key); } }
/// <summary> /// 添加自定义渲染 View 并绑定渲染回调 /// </summary> private void AddCustomVideoView(Panel parent, string userId, TRTCVideoStreamType streamType, bool local = false) { TXLiteAVVideoView videoView = new TXLiteAVVideoView(); videoView.RegEngine(userId, streamType, mTRTCCloud, local); videoView.SetRenderMode(DataManager.GetInstance().videoFillMode); videoView.Width = 320; videoView.Height = 240; videoView.Margin = new Thickness(5, 5, 5, 5); parent.Children.Add(videoView); string key = String.Format("{0}_{1}", userId, streamType); mVideoViews.Add(key, videoView); }
public void RemoveView(string userId, TRTCVideoStreamType type, TXLiteAVVideoView view) { lock (mMapViews) { foreach (var item in mMapViews.ToList()) { if (item.Key.Equals(GetKey(userId, type))) { if (item.Value != null) { item.Value.Dispose(); } mMapViews.Remove(item.Key); break; } } } }
public void AddView(string userId, TRTCVideoStreamType type, TXLiteAVVideoView view) { lock (mMapViews) { bool find = false; foreach (var item in mMapViews) { if (item.Key.Equals(GetKey(userId, type))) { find = true; break; } } if (!find) { mMapViews.Add(GetKey(userId, type), view); } } }
/// <summary> /// 设置 View 绑定参数 /// </summary> /// <param name="userId">需要渲染画面的 userId,如果是本地画面,则传空字符串。</param> /// <param name="type">渲染类型</param> /// <param name="engine">TRTCCloud 实例,用户注册视频数据回调。</param> /// <param name="local">渲染本地画面,SDK 返回的 userId 为""</param> /// <returns>true:绑定成功,false:绑定失败</returns> public bool RegEngine(string userId, TRTCVideoStreamType type, ITRTCCloud engine, bool local = false) { if (mOccupy) { return(false); } mLocalView = local; mUserId = userId; mStreamType = type; int count = TXLiteAVVideoViewManager.GetInstance().Count; if (engine != null) { if (count == 0) { engine.setLocalVideoRenderCallback(TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32, TRTCVideoBufferType.TRTCVideoBufferType_Buffer, TXLiteAVVideoViewManager.GetInstance()); } if (!mLocalView) { engine.setRemoteVideoRenderCallback(userId, TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32, TRTCVideoBufferType.TRTCVideoBufferType_Buffer, TXLiteAVVideoViewManager.GetInstance()); } } if (mLocalView) { TXLiteAVVideoViewManager.GetInstance().AddView("", type, this); } else { TXLiteAVVideoViewManager.GetInstance().AddView(userId, type, this); } lock (mArgbFrame) ReleaseBuffer(mArgbFrame); mOccupy = true; this.Refresh(); return(true); }
public void onSendFirstLocalVideoFrame(TRTCVideoStreamType streamType) { }
public void onFirstVideoFrame(string userId, TRTCVideoStreamType streamType, int width, int height) { }
public void onSendFirstLocalVideoFrame(TRTCVideoStreamType streamType) { Log.I($"onSendFirstLocalVideoFrame"); }
private string GetKey(string userId, TRTCVideoStreamType type) { return(String.Format("{0}_{1}", userId, type)); }