diff --git a/JianGongYun/TRTC/LiveClassroom.cs b/JianGongYun/TRTC/LiveClassroom.cs index 0fbb45c..a37b75b 100644 --- a/JianGongYun/TRTC/LiveClassroom.cs +++ b/JianGongYun/TRTC/LiveClassroom.cs @@ -18,6 +18,7 @@ using System.Collections.Concurrent; using System.Windows.Data; using System.Drawing; using System.Diagnostics; +using System.Runtime.InteropServices; namespace JianGongYun.TRTC { @@ -50,11 +51,11 @@ namespace JianGongYun.TRTC /// /// 摄像头帧 /// - public static VideoFrameEntity MainFrame = new VideoFrameEntity(); + public static Mat MainFrame = new Mat(); /// /// 屏幕帧 /// - public static VideoFrameEntity SubFrame = new VideoFrameEntity(); + public static Mat SubFrame = new Mat(); /// /// 背景帧 /// @@ -171,10 +172,8 @@ namespace JianGongYun.TRTC //sw.Restart(); lock (MainFrame) { - MainFrame.Width = w; - MainFrame.Height = h; - MainFrame.Data = new byte[data.Length]; - Buffer.BlockCopy(data, 0, MainFrame.Data, 0, data.Length); + MainFrame.Create(h, w, MatType.CV_8UC4); + Marshal.Copy(data, 0, MainFrame.Data, data.Length); } //sw.Stop(); //Debug.Print("main" + sw.ElapsedMilliseconds.ToString()); @@ -215,20 +214,18 @@ namespace JianGongYun.TRTC var view = AddCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeSub, true); if (liveWinMode.IsLive) { - //Stopwatch sw = new Stopwatch(); + Stopwatch sw = new Stopwatch(); //VideoRecordTask(view, TRTCVideoStreamType.TRTCVideoStreamTypeSub); view.OnRenderVideoFrameHandler += (data, w, h) => { - //sw.Restart(); + sw.Restart(); lock (SubFrame) { - SubFrame.Width = w; - SubFrame.Height = h; - SubFrame.Data = new byte[data.Length]; - Buffer.BlockCopy(data, 0, SubFrame.Data, 0, data.Length); + SubFrame.Create(h, w, MatType.CV_8UC4); + Marshal.Copy(data, 0, SubFrame.Data, data.Length); } - //sw.Stop(); - //Debug.Print("sub" + sw.ElapsedMilliseconds.ToString()); + sw.Stop(); + Debug.Print("sub" + sw.ElapsedMilliseconds.ToString()); }; } return view; diff --git a/JianGongYun/TRTC/Models/VideoFrameEntity.cs b/JianGongYun/TRTC/Models/VideoFrameEntity.cs deleted file mode 100644 index 8d031e2..0000000 --- a/JianGongYun/TRTC/Models/VideoFrameEntity.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace JianGongYun.TRTC.Models -{ - public class VideoFrameEntity - { - public byte[] Data { get; set; } = null; - public int Width { get; set; } = 0; - public int Height { get; set; } = 0; - - - } -} diff --git a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs index 0a4c399..d00f300 100644 --- a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs +++ b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs @@ -10,6 +10,8 @@ using System.Linq; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; +using System.Windows; +using System.Windows.Controls; namespace JianGongYun.TRTC.ViewModels { @@ -130,6 +132,8 @@ namespace JianGongYun.TRTC.ViewModels if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("CameraRunning")); + PropertyChanged(this, new PropertyChangedEventArgs("MainSmallWrapStyle")); + PropertyChanged(this, new PropertyChangedEventArgs("MainBigWrapStyle")); } } get @@ -150,6 +154,8 @@ namespace JianGongYun.TRTC.ViewModels if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ScreenRunning")); + PropertyChanged(this, new PropertyChangedEventArgs("MainSmallWrapStyle")); + PropertyChanged(this, new PropertyChangedEventArgs("MainBigWrapStyle")); } } get @@ -305,5 +311,37 @@ namespace JianGongYun.TRTC.ViewModels } } + #region 只有摄像头,则画面放大并居中 + public Style MainBigWrapStyle + { + get + { + var style = new Style(typeof(Grid)); + if (CameraRunning && ScreenRunning) + { + style.Setters.Add(new Setter { Property = FrameworkElement.HorizontalAlignmentProperty, Value = HorizontalAlignment.Right }); + } + return style; + } + } + public Style MainSmallWrapStyle + { + get + { + var style = new Style(typeof(Border)); + if (CameraRunning &&ScreenRunning) + { + style.Setters.Add(new Setter { Property = FrameworkElement.HorizontalAlignmentProperty, Value = HorizontalAlignment.Right }); + style.Setters.Add(new Setter { Property = FrameworkElement.VerticalAlignmentProperty, Value = VerticalAlignment.Bottom }); + style.Setters.Add(new Setter { Property = Border.BorderThicknessProperty, Value = new Thickness(1) }); + style.Setters.Add(new Setter { Property = Border.MarginProperty, Value = new Thickness(0, 0, 20, 20) }); + style.Setters.Add(new Setter { Property = Border.WidthProperty, Value = 150d }); + style.Setters.Add(new Setter { Property = Border.HeightProperty, Value = 150d }); + } + return style; + } + } + #endregion + } } diff --git a/JianGongYun/TRTC/Windows/LiveWindow.xaml b/JianGongYun/TRTC/Windows/LiveWindow.xaml index 77e129d..a2f59df 100644 --- a/JianGongYun/TRTC/Windows/LiveWindow.xaml +++ b/JianGongYun/TRTC/Windows/LiveWindow.xaml @@ -170,9 +170,13 @@ - - - + + + + + + +