From 7c47e0ea0f8ccf022741d6355f817094401c2001 Mon Sep 17 00:00:00 2001
From: lxmou666 <772765102@qq.com>
Date: Tue, 29 Dec 2020 17:23:37 +0800
Subject: [PATCH] 123
---
.../TRTC/Components/TXLiteAVVideoView.cs | 6 +-
JianGongYun/TRTC/LiveClassroom.cs | 40 ++-
JianGongYun/TRTC/Utils/TRTCCloudCallback.cs | 261 ++++++++++++++++++
.../TRTC/ViewModels/LiveWindowViewModel.cs | 8 +-
JianGongYun/TRTC/Windows/LiveWindow.xaml.cs | 2 +-
5 files changed, 303 insertions(+), 14 deletions(-)
create mode 100644 JianGongYun/TRTC/Utils/TRTCCloudCallback.cs
diff --git a/JianGongYun/TRTC/Components/TXLiteAVVideoView.cs b/JianGongYun/TRTC/Components/TXLiteAVVideoView.cs
index eefed0e..2166104 100644
--- a/JianGongYun/TRTC/Components/TXLiteAVVideoView.cs
+++ b/JianGongYun/TRTC/Components/TXLiteAVVideoView.cs
@@ -230,7 +230,7 @@ namespace JianGongYun.TRTC.Components
///
/// 渲染回调int width, int height, int rotation,WriteableBitmap image
///
- public event Action OnRenderVideoFrameHandler;
+ public event Action OnRenderVideoFrameHandler;
private void RenderFillMode(DrawingContext dc, byte[] data, int width, int height, int rotation)
{
@@ -257,7 +257,7 @@ namespace JianGongYun.TRTC.Components
//result.ImWrite($"d:\\{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.png");
//var a = ConvertWriteableBitmapToBitmapImage(mWriteableBitmap);
//a.Save($"d:\\{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.png");
- OnRenderVideoFrameHandler?.Invoke(width, height, rotation, mWriteableBitmap);
+ OnRenderVideoFrameHandler?.Invoke(mWriteableBitmap);
ImageBrush brush = new ImageBrush(mWriteableBitmap);
if (rotation > 0)
@@ -295,7 +295,7 @@ namespace JianGongYun.TRTC.Components
mWriteableBitmap.AddDirtyRect(mInt32Rect);
mWriteableBitmap.Unlock();
- OnRenderVideoFrameHandler?.Invoke(width, height, rotation, mWriteableBitmap);
+ OnRenderVideoFrameHandler?.Invoke(mWriteableBitmap);
ImageBrush brush = new ImageBrush(mWriteableBitmap);
if (rotation > 0)
diff --git a/JianGongYun/TRTC/LiveClassroom.cs b/JianGongYun/TRTC/LiveClassroom.cs
index 465cad9..1151568 100644
--- a/JianGongYun/TRTC/LiveClassroom.cs
+++ b/JianGongYun/TRTC/LiveClassroom.cs
@@ -14,6 +14,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Window = System.Windows.Window;
+using System.Collections.Concurrent;
namespace JianGongYun.TRTC
{
@@ -42,6 +43,9 @@ namespace JianGongYun.TRTC
public static Window CurrentLiveWindow;
private static LiveWindowViewModel liveWinMode;
public static ClassroomEntity CurrentClassroomEntity { get; private set; }
+ public static TRTCCloudCallback TRTCCloudCallback = new TRTCCloudCallback();
+
+ public static ConcurrentBag SaveFileTask = new ConcurrentBag();
//public static int UserCount = 999;
///
/// 进入直播教室
@@ -87,7 +91,7 @@ namespace JianGongYun.TRTC
lTRTCCloud.setSystemAudioLoopbackVolume(settingWindowViewModel.SytemGatherVolume);//系统声音采集音量
if (settingWindowViewModel.AudioSource == "2")
{
- lTRTCCloud.startSystemAudioLoopback("");
+ lTRTCCloud.startSystemAudioLoopback(null);
}
else
{
@@ -102,11 +106,30 @@ namespace JianGongYun.TRTC
//设备完结
//liveWinMode.LoadAllScreen();
+ _RecoderDir = $"{classroomEntity.ClassHead}_{classroomEntity.ClassSubHead}";
+
+ lTRTCCloud.addCallback(TRTCCloudCallback);//注册回调
callerWindow.Hide();//隐藏调用窗口
CurrentLiveWindow.Show();
}
+ private static string _RecoderDir;
+ ///
+ /// 录制内容的具体路径
+ ///
+ public static string RecoderDir
+ {
+ get
+ {
+ var temp = Path.Combine(settingWindowViewModel.ScreenRecordingDir, _RecoderDir);
+ if (!Directory.Exists(temp))
+ {
+ Directory.CreateDirectory(temp);
+ }
+ return temp;
+ }
+ }
private static SettingWindowViewModel settingWindowViewModel = SettingWindowViewModel.GetInstance();
@@ -119,16 +142,18 @@ namespace JianGongYun.TRTC
/// 启动摄像头
///
/// 视频容器
- public static void StartVideoMain(Panel parent)
+ public static TXLiteAVVideoView StartVideoMain(Panel parent)
{
if (!liveWinMode.CameraRunning)
{
lTRTCCloud.startLocalPreview(IntPtr.Zero);
liveWinMode.CameraRunning = true;
- AddCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeBig, true);
+ return AddCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeBig, true);
}
+ return null;
}
+
public static void ResizeVideoMain(Panel parent)
{
if (liveWinMode.CameraRunning)
@@ -156,15 +181,16 @@ namespace JianGongYun.TRTC
/// 启动屏幕分享
///
///
- public static void StartVideoSub(Panel parent)
+ public static TXLiteAVVideoView StartVideoSub(Panel parent)
{
if (!liveWinMode.ScreenRunning)
{
liveWinMode.ScreenRunning = true;
SelectVieoSub();
lTRTCCloud.startScreenCapture(IntPtr.Zero, TRTCVideoStreamType.TRTCVideoStreamTypeSub, settingWindowViewModel.EncParams);
- AddCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeSub, true);
+ return AddCustomVideoView(parent, CurrentClassroomEntity.TeacherId, TRTCVideoStreamType.TRTCVideoStreamTypeSub, true);
}
+ return null;
}
public static void ResizeVideoSub(Panel parent)
{
@@ -241,7 +267,7 @@ namespace JianGongYun.TRTC
///
/// 添加自定义渲染 View 并绑定渲染回调
///
- private static void AddCustomVideoView(Panel parent, string userId, TRTCVideoStreamType streamType, bool local = false)
+ private static TXLiteAVVideoView AddCustomVideoView(Panel parent, string userId, TRTCVideoStreamType streamType, bool local = false)
{
TXLiteAVVideoView videoView = new TXLiteAVVideoView();
videoView.RegEngine(userId, streamType, lTRTCCloud, local);
@@ -254,6 +280,7 @@ namespace JianGongYun.TRTC
}));
string key = string.Format("{0}_{1}", userId, streamType);
VideoViews.Add(key, videoView);
+ return videoView;
}
///
@@ -301,6 +328,7 @@ namespace JianGongYun.TRTC
lTXDeviceManager.Dispose();
lTXDeviceManager = null;
lTRTCCloud.exitRoom();
+ lTRTCCloud.removeCallback(TRTCCloudCallback);//注册回调
ITRTCCloud.destroyTRTCShareInstance();//销毁TRTC实例
lTRTCCloud.Dispose();
lTRTCCloud = null;
diff --git a/JianGongYun/TRTC/Utils/TRTCCloudCallback.cs b/JianGongYun/TRTC/Utils/TRTCCloudCallback.cs
new file mode 100644
index 0000000..d38d556
--- /dev/null
+++ b/JianGongYun/TRTC/Utils/TRTCCloudCallback.cs
@@ -0,0 +1,261 @@
+using ManageLiteAV;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Text;
+
+namespace JianGongYun.TRTC.Utils
+{
+ public class TRTCCloudCallback : ITRTCCloudCallback
+ {
+ public void onAudioDeviceCaptureVolumeChanged(uint volume, bool muted)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onAudioDevicePlayoutVolumeChanged(uint volume, bool muted)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onAudioEffectFinished(int effectId, int code)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onCameraDidReady()
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onConnectionLost()
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onConnectionRecovery()
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onConnectOtherRoom(string userId, TXLiteAVError errCode, string errMsg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onDeviceChange(string deviceId, TRTCDeviceType type, TRTCDeviceState state)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onDisconnectOtherRoom(TXLiteAVError errCode, string errMsg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onEnterRoom(int result)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onError(TXLiteAVError errCode, string errMsg, IntPtr arg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onExitRoom(int reason)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onFirstAudioFrame(string userId)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onFirstVideoFrame(string userId, TRTCVideoStreamType streamType, int width, int height)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onMicDidReady()
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onMissCustomCmdMsg(string userId, int cmdId, int errCode, int missed)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onNetworkQuality(TRTCQualityInfo localQuality, TRTCQualityInfo[] remoteQuality, uint remoteQualityCount)
+ {
+ //StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onPlayBGMBegin(TXLiteAVError errCode)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onPlayBGMComplete(TXLiteAVError errCode)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onPlayBGMProgress(uint progressMS, uint durationMS)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onRecvCustomCmdMsg(string userId, int cmdID, uint seq, byte[] msg, uint msgSize)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onRecvSEIMsg(string userId, byte[] message, uint msgSize)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onRemoteUserEnterRoom(string userId)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onRemoteUserLeaveRoom(string userId, int reason)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onScreenCaptureCovered()
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onScreenCapturePaused(int reason)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onScreenCaptureResumed(int reason)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onScreenCaptureStarted()
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onScreenCaptureStoped(int reason)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onSendFirstLocalAudioFrame()
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onSendFirstLocalVideoFrame(TRTCVideoStreamType streamType)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onSetMixTranscodingConfig(int errCode, string errMsg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onSpeedTest(TRTCSpeedTestResult currentResult, uint finishedCount, uint totalCount)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onStartPublishCDNStream(int errCode, string errMsg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onStartPublishing(int errCode, string errMsg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onStatistics(TRTCStatistics statis)
+ {
+ //StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onStopPublishCDNStream(int errCode, string errMsg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onStopPublishing(int errCode, string errMsg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onSwitchRole(TXLiteAVError errCode, string errMsg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onSwitchRoom(TXLiteAVError errCode, string errMsg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onTestMicVolume(uint volume)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onTestSpeakerVolume(uint volume)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onTryToReconnect()
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onUserAudioAvailable(string userId, bool available)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onUserEnter(string userId)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onUserExit(string userId, int reason)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onUserSubStreamAvailable(string userId, bool available)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onUserVideoAvailable(string userId, bool available)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onUserVoiceVolume(TRTCVolumeInfo[] userVolumes, uint userVolumesCount, uint totalVolume)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+
+ public void onWarning(TXLiteAVWarning warningCode, string warningMsg, IntPtr arg)
+ {
+ StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name);
+ }
+ }
+}
diff --git a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs
index 1619ee0..0a7d551 100644
--- a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs
+++ b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs
@@ -220,17 +220,17 @@ namespace JianGongYun.TRTC.ViewModels
{
lock (ScreenListLock)
{
- Console.WriteLine("get LiveScreens");
+ //Console.WriteLine("get LiveScreens");
_LiveScreens.Clear();
- Console.WriteLine("get LiveScreens Clear");
+ //Console.WriteLine("get LiveScreens Clear");
var temp = LiveClassroom.lTRTCCloud.getScreenCaptureSources(ref thumbSize, ref iconSize);
var count = temp.getCount();
- Console.WriteLine($"get LiveScreens {count}");
+ //Console.WriteLine($"get LiveScreens {count}");
for (uint i = 0; i < count; i++)
{
var info = temp.getSourceInfo(i);
//var icon = Util.ToWriteableBitmap(ref info.iconBGRA);
- Console.WriteLine($"get LiveScreens {i} {info.sourceId}");
+ //Console.WriteLine($"get LiveScreens {i} {info.sourceId}");
var thumb = info.thumbBGRA.ToWriteableBitmap();
_LiveScreens.Add(new TRTCScreenEntity { SourceId = info.sourceId, SourceName = info.sourceName, Type = info.type, Thumb = thumb, Info = info });
}
diff --git a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs
index 1255d44..ae11ace 100644
--- a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs
+++ b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs
@@ -34,7 +34,7 @@ namespace JianGongYun.TRTC.Windows
InitializeComponent();
BeforeLiveSubViewWrap.SizeChanged += BeforeLiveSubViewWrap_SizeChanged;
AfterLiveSubViewWrap.SizeChanged += AfterLiveSubViewWrap_SizeChanged;
- //AttachConsole(-1);//把进程挂在控制台,通过命令行启动程序可以看到控制台输出
+ AttachConsole(-1);//把进程挂在控制台,通过命令行启动程序可以看到控制台输出
LiveWindowViewModel = new ViewModels.LiveWindowViewModel();
SettingWindowViewModel = ViewModels.SettingWindowViewModel.GetInstance();
this.DataContext = LiveWindowViewModel;