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 onUserSubStreamAvailable(string userId, bool available) { Log.I($"onUserSubStreamAvailable userId:{userId} available:{available}"); if (userId == "source") { this.Dispatcher.BeginInvoke(new Action(() => { if (available) { // 远端辅流自定义渲染 View 动态绑定和监听 SDK 渲染回调 trtcCloud.startRemoteSubStreamView(userId, IntPtr.Zero); TXLiteAVVideoView videoView = RenderMapView; videoView.RegEngine(userId, TRTCVideoStreamType.TRTCVideoStreamTypeSub, trtcCloud, false); videoView.SetRenderMode(TRTCVideoFillMode.TRTCVideoFillMode_Fit); videoView.Margin = new Thickness(0); Loading.Visibility = Visibility.Hidden; IsHaveStream = true; if (keyboardListener == null) { keyboardListener = new KeyboardListener(); } keyboardListener.KeyEvent += KeyboardListener_KeyEvent; keyboardListener.IsBlockKeyboard = true; var o = new JObject { ["cmd"] = "GetScreenCount" }; var data = Encoding.UTF8.GetBytes(o.ToString()); trtcCloud?.sendCustomCmdMsg(3, data, (uint)data.Length, true, true); } else { // 远端辅流自定义渲染 View 移除绑定 trtcCloud.stopRemoteSubStreamView(userId); Loading.Content = "远程已断开"; Loading.Visibility = Visibility.Visible; IsHaveStream = false; if (keyboardListener != null) { keyboardListener.KeyEvent -= KeyboardListener_KeyEvent; keyboardListener.IsBlockKeyboard = false; keyboardListener.Dispose(); keyboardListener = null; } } })); } }
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); } } }