This commit is contained in:
lxmou666 2021-01-04 23:49:50 +08:00
parent 11e2abe241
commit 290493f133
4 changed files with 56 additions and 32 deletions

View File

@ -18,6 +18,7 @@ using System.Collections.Concurrent;
using System.Windows.Data; using System.Windows.Data;
using System.Drawing; using System.Drawing;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices;
namespace JianGongYun.TRTC namespace JianGongYun.TRTC
{ {
@ -50,11 +51,11 @@ namespace JianGongYun.TRTC
/// <summary> /// <summary>
/// 摄像头帧 /// 摄像头帧
/// </summary> /// </summary>
public static VideoFrameEntity MainFrame = new VideoFrameEntity(); public static Mat MainFrame = new Mat();
/// <summary> /// <summary>
/// 屏幕帧 /// 屏幕帧
/// </summary> /// </summary>
public static VideoFrameEntity SubFrame = new VideoFrameEntity(); public static Mat SubFrame = new Mat();
/// <summary> /// <summary>
/// 背景帧 /// 背景帧
/// </summary> /// </summary>
@ -171,10 +172,8 @@ namespace JianGongYun.TRTC
//sw.Restart(); //sw.Restart();
lock (MainFrame) lock (MainFrame)
{ {
MainFrame.Width = w; MainFrame.Create(h, w, MatType.CV_8UC4);
MainFrame.Height = h; Marshal.Copy(data, 0, MainFrame.Data, data.Length);
MainFrame.Data = new byte[data.Length];
Buffer.BlockCopy(data, 0, MainFrame.Data, 0, data.Length);
} }
//sw.Stop(); //sw.Stop();
//Debug.Print("main" + sw.ElapsedMilliseconds.ToString()); //Debug.Print("main" + sw.ElapsedMilliseconds.ToString());
@ -215,20 +214,18 @@ namespace JianGongYun.TRTC
var view = AddCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeSub, true); var view = AddCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeSub, true);
if (liveWinMode.IsLive) if (liveWinMode.IsLive)
{ {
//Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
//VideoRecordTask(view, TRTCVideoStreamType.TRTCVideoStreamTypeSub); //VideoRecordTask(view, TRTCVideoStreamType.TRTCVideoStreamTypeSub);
view.OnRenderVideoFrameHandler += (data, w, h) => view.OnRenderVideoFrameHandler += (data, w, h) =>
{ {
//sw.Restart(); sw.Restart();
lock (SubFrame) lock (SubFrame)
{ {
SubFrame.Width = w; SubFrame.Create(h, w, MatType.CV_8UC4);
SubFrame.Height = h; Marshal.Copy(data, 0, SubFrame.Data, data.Length);
SubFrame.Data = new byte[data.Length];
Buffer.BlockCopy(data, 0, SubFrame.Data, 0, data.Length);
} }
//sw.Stop(); sw.Stop();
//Debug.Print("sub" + sw.ElapsedMilliseconds.ToString()); Debug.Print("sub" + sw.ElapsedMilliseconds.ToString());
}; };
} }
return view; return view;

View File

@ -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;
}
}

View File

@ -10,6 +10,8 @@ using System.Linq;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Threading; using System.Windows.Threading;
using System.Windows;
using System.Windows.Controls;
namespace JianGongYun.TRTC.ViewModels namespace JianGongYun.TRTC.ViewModels
{ {
@ -130,6 +132,8 @@ namespace JianGongYun.TRTC.ViewModels
if (PropertyChanged != null) if (PropertyChanged != null)
{ {
PropertyChanged(this, new PropertyChangedEventArgs("CameraRunning")); PropertyChanged(this, new PropertyChangedEventArgs("CameraRunning"));
PropertyChanged(this, new PropertyChangedEventArgs("MainSmallWrapStyle"));
PropertyChanged(this, new PropertyChangedEventArgs("MainBigWrapStyle"));
} }
} }
get get
@ -150,6 +154,8 @@ namespace JianGongYun.TRTC.ViewModels
if (PropertyChanged != null) if (PropertyChanged != null)
{ {
PropertyChanged(this, new PropertyChangedEventArgs("ScreenRunning")); PropertyChanged(this, new PropertyChangedEventArgs("ScreenRunning"));
PropertyChanged(this, new PropertyChangedEventArgs("MainSmallWrapStyle"));
PropertyChanged(this, new PropertyChangedEventArgs("MainBigWrapStyle"));
} }
} }
get 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
} }
} }

View File

@ -170,9 +170,13 @@
<!--屏幕预览容器--> <!--屏幕预览容器-->
<Grid x:Name="AfterLiveSubViewWrap" Width="{Binding ElementName=AfterLivePanel,Path=ActualWidth}" Height="{Binding ElementName=AfterLivePanel,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0"></Grid> <Grid x:Name="AfterLiveSubViewWrap" Width="{Binding ElementName=AfterLivePanel,Path=ActualWidth}" Height="{Binding ElementName=AfterLivePanel,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0"></Grid>
<!--摄像头预览容器--> <!--摄像头预览容器-->
<Border Visibility="{Binding CameraRunning, Converter={StaticResource VisibilityOfBool}}" Width="150" Height="150" BorderThickness="1" BorderBrush="#efefef" Canvas.Bottom="20" Canvas.Right="20"> <Grid Width="{Binding ElementName=AfterLivePanel,Path=ActualWidth}" Height="{Binding ElementName=AfterLivePanel,Path=ActualHeight}" Canvas.Top="0" Canvas.Left="0">
<Grid x:Name="AfterLiveViewWrap"></Grid> <Grid Style="{Binding MainBigWrapStyle}" Width="{Binding ElementName=AfterLivePanel,Path=ActualHeight}">
</Border> <Border Style="{Binding MainSmallWrapStyle}" Visibility="{Binding CameraRunning, Converter={StaticResource VisibilityOfBool}}" BorderBrush="#efefef">
<Grid x:Name="AfterLiveViewWrap"></Grid>
</Border>
</Grid>
</Grid>
</Canvas> </Canvas>
</Grid> </Grid>
</Canvas> </Canvas>