From bcd75c83c2abe93e4fa2d0b31f2a259db001633b Mon Sep 17 00:00:00 2001
From: lxmou666 <772765102@qq.com>
Date: Tue, 5 Jan 2021 22:42:33 +0800
Subject: [PATCH] 13
---
JianGongYun/TRTC/LiveClassroom.cs | 47 ++++++++++++-------
.../TRTC/ViewModels/SettingWindowViewModel.cs | 4 +-
JianGongYun/TRTC/Windows/LiveWindow.xaml.cs | 8 ++++
3 files changed, 41 insertions(+), 18 deletions(-)
diff --git a/JianGongYun/TRTC/LiveClassroom.cs b/JianGongYun/TRTC/LiveClassroom.cs
index 20cdc23..4887763 100644
--- a/JianGongYun/TRTC/LiveClassroom.cs
+++ b/JianGongYun/TRTC/LiveClassroom.cs
@@ -283,10 +283,10 @@ namespace JianGongYun.TRTC
if (liveWinMode.IsLive && !liveWinMode.AudioRecordRunning)
{
liveWinMode.AudioRecordRunning = true;
- var time = Util.TimeStr();
- var pars = new TRTCAudioRecordingParams { filePath = Path.Combine(RecoderDir, $"{time}audio.wav") };
+ //var time = Util.TimeStr();
+ var pars = new TRTCAudioRecordingParams { filePath = Path.Combine(RecoderDir, $"temp_audio.wav") };
var res = lTRTCCloud.startAudioRecording(ref pars);
- Console.WriteLine(res);
+ //Console.WriteLine(res);
}
}
}
@@ -328,7 +328,7 @@ namespace JianGongYun.TRTC
var delay = 1000 / (int)fps;//每帧时间
var delayEqualize = 0;//每帧时间补偿,在性能和其他因素影响下delay的时间不一定充足
var _recoderDir = RecoderDir;
- var videoFile = Path.Combine(_recoderDir, $"{Util.TimeStr()}_video.avi");
+ var videoFile = Path.Combine(_recoderDir, $"temp_video.avi");
//var videoFrameTemp = Path.Combine(_recoderDir, $"videoFrameTemp.bmp");
var backHeight = BackgroundFrame.Rows;//画面高度
var backWidth = BackgroundFrame.Cols;//画面宽度
@@ -441,26 +441,30 @@ namespace JianGongYun.TRTC
Skip2:
- //Cv2.ImShow("preview", BackgroundFrame);
- //Cv2.WaitKey(1);
- //BackgroundFrame.SaveImage(videoFrameTemp);
- //var temp = Cv2.ImRead(videoFrameTemp);
var temp = BackgroundFrame.CvtColor(ColorConversionCodes.BGRA2BGR);
vw.Write(temp);
temp.Dispose();
stopwatch.Stop();
var aa = $"video frame run {stopwatch.ElapsedMilliseconds}";
- Debug.Print(aa);
+ //Debug.Print(aa);
Console.WriteLine(aa);
var sleep = delay - (int)stopwatch.ElapsedMilliseconds;//每帧时间减去每帧处理时间为sleep时间
if (sleep < 0)//如果处理时间超过了每帧时间,记录下来
{
delayEqualize += sleep;
}
- sleep += delayEqualize;//理论休眠时间再去掉补偿时间
- if (sleep > 0)
+ if (delayEqualize < 0 && sleep > 0)
{
- Thread.Sleep(sleep);
+ delayEqualize += sleep;
+ if (delayEqualize > 0)
+ {
+ delayEqualize = 0;
+ }
+ }
+ var lastsleep = sleep + delayEqualize;//理论休眠时间再去掉补偿时间
+ if (lastsleep > 0)
+ {
+ Thread.Sleep(lastsleep);
}
}
BackgroundFrame?.Dispose();
@@ -527,21 +531,32 @@ namespace JianGongYun.TRTC
VideoViews.Remove(key);
}
}
-
///
/// 重启音频录制
///
- public static void RestartAudio() { }
+ //public static void RestartAudio() { }
///
/// 重设主视频(摄像头)
///
- public static void ResetVideoMain() { }
+ //public static void ResetVideoMain() { }
///
/// 重设副视频(录屏)
///
- public static void ResetVideoSub() { }
+ //public static void ResetVideoSub() { }
+ ///
+ /// 停止所有实时渲染
+ ///
+ ///
+ public static void PauseAllView(bool pause)
+ {
+ foreach (var item in VideoViews)
+ {
+ item.Value.SetPause(pause);
+ }
+ }
+
private static void CurrentLiveWindow_Closed(object sender, EventArgs e)
{
CurrentLiveWindow = null;
diff --git a/JianGongYun/TRTC/ViewModels/SettingWindowViewModel.cs b/JianGongYun/TRTC/ViewModels/SettingWindowViewModel.cs
index 166ea84..86c8702 100644
--- a/JianGongYun/TRTC/ViewModels/SettingWindowViewModel.cs
+++ b/JianGongYun/TRTC/ViewModels/SettingWindowViewModel.cs
@@ -528,7 +528,7 @@ namespace JianGongYun.TRTC.ViewModels
///
/// 摄像画面帧率
///
- private uint _LiveFps = 24;
+ private uint _LiveFps = 20;
public uint LiveFps
{
get
@@ -548,7 +548,7 @@ namespace JianGongYun.TRTC.ViewModels
{
_LiveFps = value;
storage.SetValue(INI_ROOT_KEY, INI_KEY_LIVE_FPS, value.ToString());//生成保存本地
- LiveClassroom.ResetVideoMain();//重设参数
+ //LiveClassroom.ResetVideoMain();//重设参数
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("LiveFps"));
diff --git a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs
index 566094b..7f65faf 100644
--- a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs
+++ b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs
@@ -52,6 +52,14 @@ namespace JianGongYun.TRTC.Windows
Rad2.Foreground = color;
Rad3.Foreground = color;
Rad4.Foreground = color;
+ //LiveClassroom.PauseAllView(false);//切前台启动实时预览渲染
+
+ }
+
+ protected override void OnDeactivated(EventArgs e)
+ {
+ base.OnDeactivated(e);
+ //LiveClassroom.PauseAllView(true);//切后台停止实时预览渲染
}
private Window settingWindow;