123
This commit is contained in:
parent
11e2abe241
commit
290493f133
|
@ -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
|
|||
/// <summary>
|
||||
/// 摄像头帧
|
||||
/// </summary>
|
||||
public static VideoFrameEntity MainFrame = new VideoFrameEntity();
|
||||
public static Mat MainFrame = new Mat();
|
||||
/// <summary>
|
||||
/// 屏幕帧
|
||||
/// </summary>
|
||||
public static VideoFrameEntity SubFrame = new VideoFrameEntity();
|
||||
public static Mat SubFrame = new Mat();
|
||||
/// <summary>
|
||||
/// 背景帧
|
||||
/// </summary>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
<!--摄像头预览容器-->
|
||||
<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 Style="{Binding MainBigWrapStyle}" Width="{Binding ElementName=AfterLivePanel,Path=ActualHeight}">
|
||||
<Border Style="{Binding MainSmallWrapStyle}" Visibility="{Binding CameraRunning, Converter={StaticResource VisibilityOfBool}}" BorderBrush="#efefef">
|
||||
<Grid x:Name="AfterLiveViewWrap"></Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Canvas>
|
||||
</Grid>
|
||||
</Canvas>
|
||||
|
|
Loading…
Reference in New Issue