This commit is contained in:
lxmou666 2020-12-29 17:23:37 +08:00
parent 7595ca1dd3
commit 7c47e0ea0f
5 changed files with 303 additions and 14 deletions

View File

@ -230,7 +230,7 @@ namespace JianGongYun.TRTC.Components
/// <summary> /// <summary>
/// 渲染回调int width, int height, int rotation,WriteableBitmap image /// 渲染回调int width, int height, int rotation,WriteableBitmap image
/// </summary> /// </summary>
public event Action<int, int, int, WriteableBitmap> OnRenderVideoFrameHandler; public event Action<WriteableBitmap> OnRenderVideoFrameHandler;
private void RenderFillMode(DrawingContext dc, byte[] data, int width, int height, int rotation) 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"); //result.ImWrite($"d:\\{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.png");
//var a = ConvertWriteableBitmapToBitmapImage(mWriteableBitmap); //var a = ConvertWriteableBitmapToBitmapImage(mWriteableBitmap);
//a.Save($"d:\\{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.png"); //a.Save($"d:\\{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.png");
OnRenderVideoFrameHandler?.Invoke(width, height, rotation, mWriteableBitmap); OnRenderVideoFrameHandler?.Invoke(mWriteableBitmap);
ImageBrush brush = new ImageBrush(mWriteableBitmap); ImageBrush brush = new ImageBrush(mWriteableBitmap);
if (rotation > 0) if (rotation > 0)
@ -295,7 +295,7 @@ namespace JianGongYun.TRTC.Components
mWriteableBitmap.AddDirtyRect(mInt32Rect); mWriteableBitmap.AddDirtyRect(mInt32Rect);
mWriteableBitmap.Unlock(); mWriteableBitmap.Unlock();
OnRenderVideoFrameHandler?.Invoke(width, height, rotation, mWriteableBitmap); OnRenderVideoFrameHandler?.Invoke(mWriteableBitmap);
ImageBrush brush = new ImageBrush(mWriteableBitmap); ImageBrush brush = new ImageBrush(mWriteableBitmap);
if (rotation > 0) if (rotation > 0)

View File

@ -14,6 +14,7 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Window = System.Windows.Window; using Window = System.Windows.Window;
using System.Collections.Concurrent;
namespace JianGongYun.TRTC namespace JianGongYun.TRTC
{ {
@ -42,6 +43,9 @@ namespace JianGongYun.TRTC
public static Window CurrentLiveWindow; public static Window CurrentLiveWindow;
private static LiveWindowViewModel liveWinMode; private static LiveWindowViewModel liveWinMode;
public static ClassroomEntity CurrentClassroomEntity { get; private set; } public static ClassroomEntity CurrentClassroomEntity { get; private set; }
public static TRTCCloudCallback TRTCCloudCallback = new TRTCCloudCallback();
public static ConcurrentBag<Task> SaveFileTask = new ConcurrentBag<Task>();
//public static int UserCount = 999; //public static int UserCount = 999;
/// <summary> /// <summary>
/// 进入直播教室 /// 进入直播教室
@ -87,7 +91,7 @@ namespace JianGongYun.TRTC
lTRTCCloud.setSystemAudioLoopbackVolume(settingWindowViewModel.SytemGatherVolume);//系统声音采集音量 lTRTCCloud.setSystemAudioLoopbackVolume(settingWindowViewModel.SytemGatherVolume);//系统声音采集音量
if (settingWindowViewModel.AudioSource == "2") if (settingWindowViewModel.AudioSource == "2")
{ {
lTRTCCloud.startSystemAudioLoopback(""); lTRTCCloud.startSystemAudioLoopback(null);
} }
else else
{ {
@ -102,11 +106,30 @@ namespace JianGongYun.TRTC
//设备完结 //设备完结
//liveWinMode.LoadAllScreen(); //liveWinMode.LoadAllScreen();
_RecoderDir = $"{classroomEntity.ClassHead}_{classroomEntity.ClassSubHead}";
lTRTCCloud.addCallback(TRTCCloudCallback);//注册回调
callerWindow.Hide();//隐藏调用窗口 callerWindow.Hide();//隐藏调用窗口
CurrentLiveWindow.Show(); CurrentLiveWindow.Show();
} }
private static string _RecoderDir;
/// <summary>
/// 录制内容的具体路径
/// </summary>
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(); private static SettingWindowViewModel settingWindowViewModel = SettingWindowViewModel.GetInstance();
@ -119,16 +142,18 @@ namespace JianGongYun.TRTC
/// 启动摄像头 /// 启动摄像头
/// </summary> /// </summary>
/// <param name="parent">视频容器</param> /// <param name="parent">视频容器</param>
public static void StartVideoMain(Panel parent) public static TXLiteAVVideoView StartVideoMain(Panel parent)
{ {
if (!liveWinMode.CameraRunning) if (!liveWinMode.CameraRunning)
{ {
lTRTCCloud.startLocalPreview(IntPtr.Zero); lTRTCCloud.startLocalPreview(IntPtr.Zero);
liveWinMode.CameraRunning = true; 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) public static void ResizeVideoMain(Panel parent)
{ {
if (liveWinMode.CameraRunning) if (liveWinMode.CameraRunning)
@ -156,15 +181,16 @@ namespace JianGongYun.TRTC
/// 启动屏幕分享 /// 启动屏幕分享
/// </summary> /// </summary>
/// <param name="parent"></param> /// <param name="parent"></param>
public static void StartVideoSub(Panel parent) public static TXLiteAVVideoView StartVideoSub(Panel parent)
{ {
if (!liveWinMode.ScreenRunning) if (!liveWinMode.ScreenRunning)
{ {
liveWinMode.ScreenRunning = true; liveWinMode.ScreenRunning = true;
SelectVieoSub(); SelectVieoSub();
lTRTCCloud.startScreenCapture(IntPtr.Zero, TRTCVideoStreamType.TRTCVideoStreamTypeSub, settingWindowViewModel.EncParams); 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) public static void ResizeVideoSub(Panel parent)
{ {
@ -241,7 +267,7 @@ namespace JianGongYun.TRTC
/// <summary> /// <summary>
/// 添加自定义渲染 View 并绑定渲染回调 /// 添加自定义渲染 View 并绑定渲染回调
/// </summary> /// </summary>
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(); TXLiteAVVideoView videoView = new TXLiteAVVideoView();
videoView.RegEngine(userId, streamType, lTRTCCloud, local); videoView.RegEngine(userId, streamType, lTRTCCloud, local);
@ -254,6 +280,7 @@ namespace JianGongYun.TRTC
})); }));
string key = string.Format("{0}_{1}", userId, streamType); string key = string.Format("{0}_{1}", userId, streamType);
VideoViews.Add(key, videoView); VideoViews.Add(key, videoView);
return videoView;
} }
/// <summary> /// <summary>
@ -301,6 +328,7 @@ namespace JianGongYun.TRTC
lTXDeviceManager.Dispose(); lTXDeviceManager.Dispose();
lTXDeviceManager = null; lTXDeviceManager = null;
lTRTCCloud.exitRoom(); lTRTCCloud.exitRoom();
lTRTCCloud.removeCallback(TRTCCloudCallback);//注册回调
ITRTCCloud.destroyTRTCShareInstance();//销毁TRTC实例 ITRTCCloud.destroyTRTCShareInstance();//销毁TRTC实例
lTRTCCloud.Dispose(); lTRTCCloud.Dispose();
lTRTCCloud = null; lTRTCCloud = null;

View File

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

View File

@ -220,17 +220,17 @@ namespace JianGongYun.TRTC.ViewModels
{ {
lock (ScreenListLock) lock (ScreenListLock)
{ {
Console.WriteLine("get LiveScreens"); //Console.WriteLine("get LiveScreens");
_LiveScreens.Clear(); _LiveScreens.Clear();
Console.WriteLine("get LiveScreens Clear"); //Console.WriteLine("get LiveScreens Clear");
var temp = LiveClassroom.lTRTCCloud.getScreenCaptureSources(ref thumbSize, ref iconSize); var temp = LiveClassroom.lTRTCCloud.getScreenCaptureSources(ref thumbSize, ref iconSize);
var count = temp.getCount(); var count = temp.getCount();
Console.WriteLine($"get LiveScreens {count}"); //Console.WriteLine($"get LiveScreens {count}");
for (uint i = 0; i < count; i++) for (uint i = 0; i < count; i++)
{ {
var info = temp.getSourceInfo(i); var info = temp.getSourceInfo(i);
//var icon = Util.ToWriteableBitmap(ref info.iconBGRA); //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(); var thumb = info.thumbBGRA.ToWriteableBitmap();
_LiveScreens.Add(new TRTCScreenEntity { SourceId = info.sourceId, SourceName = info.sourceName, Type = info.type, Thumb = thumb, Info = info }); _LiveScreens.Add(new TRTCScreenEntity { SourceId = info.sourceId, SourceName = info.sourceName, Type = info.type, Thumb = thumb, Info = info });
} }

View File

@ -34,7 +34,7 @@ namespace JianGongYun.TRTC.Windows
InitializeComponent(); InitializeComponent();
BeforeLiveSubViewWrap.SizeChanged += BeforeLiveSubViewWrap_SizeChanged; BeforeLiveSubViewWrap.SizeChanged += BeforeLiveSubViewWrap_SizeChanged;
AfterLiveSubViewWrap.SizeChanged += AfterLiveSubViewWrap_SizeChanged; AfterLiveSubViewWrap.SizeChanged += AfterLiveSubViewWrap_SizeChanged;
//AttachConsole(-1);//把进程挂在控制台,通过命令行启动程序可以看到控制台输出 AttachConsole(-1);//把进程挂在控制台,通过命令行启动程序可以看到控制台输出
LiveWindowViewModel = new ViewModels.LiveWindowViewModel(); LiveWindowViewModel = new ViewModels.LiveWindowViewModel();
SettingWindowViewModel = ViewModels.SettingWindowViewModel.GetInstance(); SettingWindowViewModel = ViewModels.SettingWindowViewModel.GetInstance();
this.DataContext = LiveWindowViewModel; this.DataContext = LiveWindowViewModel;