This commit is contained in:
lxmou666 2021-01-05 22:42:33 +08:00
parent 000907087c
commit bcd75c83c2
3 changed files with 41 additions and 18 deletions

View File

@ -283,10 +283,10 @@ namespace JianGongYun.TRTC
if (liveWinMode.IsLive && !liveWinMode.AudioRecordRunning) if (liveWinMode.IsLive && !liveWinMode.AudioRecordRunning)
{ {
liveWinMode.AudioRecordRunning = true; liveWinMode.AudioRecordRunning = true;
var time = Util.TimeStr(); //var time = Util.TimeStr();
var pars = new TRTCAudioRecordingParams { filePath = Path.Combine(RecoderDir, $"{time}audio.wav") }; var pars = new TRTCAudioRecordingParams { filePath = Path.Combine(RecoderDir, $"temp_audio.wav") };
var res = lTRTCCloud.startAudioRecording(ref pars); 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 delay = 1000 / (int)fps;//每帧时间
var delayEqualize = 0;//每帧时间补偿在性能和其他因素影响下delay的时间不一定充足 var delayEqualize = 0;//每帧时间补偿在性能和其他因素影响下delay的时间不一定充足
var _recoderDir = RecoderDir; 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 videoFrameTemp = Path.Combine(_recoderDir, $"videoFrameTemp.bmp");
var backHeight = BackgroundFrame.Rows;//画面高度 var backHeight = BackgroundFrame.Rows;//画面高度
var backWidth = BackgroundFrame.Cols;//画面宽度 var backWidth = BackgroundFrame.Cols;//画面宽度
@ -441,26 +441,30 @@ namespace JianGongYun.TRTC
Skip2: Skip2:
//Cv2.ImShow("preview", BackgroundFrame);
//Cv2.WaitKey(1);
//BackgroundFrame.SaveImage(videoFrameTemp);
//var temp = Cv2.ImRead(videoFrameTemp);
var temp = BackgroundFrame.CvtColor(ColorConversionCodes.BGRA2BGR); var temp = BackgroundFrame.CvtColor(ColorConversionCodes.BGRA2BGR);
vw.Write(temp); vw.Write(temp);
temp.Dispose(); temp.Dispose();
stopwatch.Stop(); stopwatch.Stop();
var aa = $"video frame run {stopwatch.ElapsedMilliseconds}"; var aa = $"video frame run {stopwatch.ElapsedMilliseconds}";
Debug.Print(aa); //Debug.Print(aa);
Console.WriteLine(aa); Console.WriteLine(aa);
var sleep = delay - (int)stopwatch.ElapsedMilliseconds;//每帧时间减去每帧处理时间为sleep时间 var sleep = delay - (int)stopwatch.ElapsedMilliseconds;//每帧时间减去每帧处理时间为sleep时间
if (sleep < 0)//如果处理时间超过了每帧时间,记录下来 if (sleep < 0)//如果处理时间超过了每帧时间,记录下来
{ {
delayEqualize += sleep; delayEqualize += sleep;
} }
sleep += delayEqualize;//理论休眠时间再去掉补偿时间 if (delayEqualize < 0 && sleep > 0)
if (sleep > 0)
{ {
Thread.Sleep(sleep); delayEqualize += sleep;
if (delayEqualize > 0)
{
delayEqualize = 0;
}
}
var lastsleep = sleep + delayEqualize;//理论休眠时间再去掉补偿时间
if (lastsleep > 0)
{
Thread.Sleep(lastsleep);
} }
} }
BackgroundFrame?.Dispose(); BackgroundFrame?.Dispose();
@ -527,21 +531,32 @@ namespace JianGongYun.TRTC
VideoViews.Remove(key); VideoViews.Remove(key);
} }
} }
/// <summary> /// <summary>
/// 重启音频录制 /// 重启音频录制
/// </summary> /// </summary>
public static void RestartAudio() { } //public static void RestartAudio() { }
/// <summary> /// <summary>
/// 重设主视频(摄像头) /// 重设主视频(摄像头)
/// </summary> /// </summary>
public static void ResetVideoMain() { } //public static void ResetVideoMain() { }
/// <summary> /// <summary>
/// 重设副视频(录屏) /// 重设副视频(录屏)
/// </summary> /// </summary>
public static void ResetVideoSub() { } //public static void ResetVideoSub() { }
/// <summary>
/// 停止所有实时渲染
/// </summary>
/// <param name="pause"></param>
public static void PauseAllView(bool pause)
{
foreach (var item in VideoViews)
{
item.Value.SetPause(pause);
}
}
private static void CurrentLiveWindow_Closed(object sender, EventArgs e) private static void CurrentLiveWindow_Closed(object sender, EventArgs e)
{ {
CurrentLiveWindow = null; CurrentLiveWindow = null;

View File

@ -528,7 +528,7 @@ namespace JianGongYun.TRTC.ViewModels
/// <summary> /// <summary>
/// 摄像画面帧率 /// 摄像画面帧率
/// </summary> /// </summary>
private uint _LiveFps = 24; private uint _LiveFps = 20;
public uint LiveFps public uint LiveFps
{ {
get get
@ -548,7 +548,7 @@ namespace JianGongYun.TRTC.ViewModels
{ {
_LiveFps = value; _LiveFps = value;
storage.SetValue(INI_ROOT_KEY, INI_KEY_LIVE_FPS, value.ToString());//生成保存本地 storage.SetValue(INI_ROOT_KEY, INI_KEY_LIVE_FPS, value.ToString());//生成保存本地
LiveClassroom.ResetVideoMain();//重设参数 //LiveClassroom.ResetVideoMain();//重设参数
if (PropertyChanged != null) if (PropertyChanged != null)
{ {
PropertyChanged(this, new PropertyChangedEventArgs("LiveFps")); PropertyChanged(this, new PropertyChangedEventArgs("LiveFps"));

View File

@ -52,6 +52,14 @@ namespace JianGongYun.TRTC.Windows
Rad2.Foreground = color; Rad2.Foreground = color;
Rad3.Foreground = color; Rad3.Foreground = color;
Rad4.Foreground = color; Rad4.Foreground = color;
//LiveClassroom.PauseAllView(false);//切前台启动实时预览渲染
}
protected override void OnDeactivated(EventArgs e)
{
base.OnDeactivated(e);
//LiveClassroom.PauseAllView(true);//切后台停止实时预览渲染
} }
private Window settingWindow; private Window settingWindow;