FISWin.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using FFmpeg.AutoGen;
  2. using ManageLiteAV;
  3. using System;
  4. using System.IO;
  5. using Vinno.vCloud.FIS.CrossPlatform.Common;
  6. using Vinno.vCloud.FIS.CrossPlatform.Common.Enum;
  7. using Vinno.vCloud.FIS.CrossPlatform.Common.Helper;
  8. using Vinno.vCloud.FIS.CrossPlatform.Windows.Consultation;
  9. using Vinno.vCloud.FIS.CrossPlatform.Windows.Consultation.RTC;
  10. using Vinno.vCloud.FIS.CrossPlatform.Windows.Consultation.RTMP;
  11. using Vinno.vCloud.FIS.CrossPlatform.Windows.Hardware;
  12. using Vinno.vCloud.FIS.CrossPlatform.Windows.LiveVideo;
  13. using Vinno.vCloud.FIS.CrossPlatform.Windows.RTMPSDK;
  14. using static Vinno.vCloud.FIS.CrossPlatform.Windows.RTMPSDK.NTSmartLogDefine;
  15. namespace Vinno.vCloud.FIS.CrossPlatform.Windows
  16. {
  17. public class FISWin
  18. {
  19. public static string FISLogPath { get; private set; }
  20. /// <summary>
  21. /// Initilize for windows platform.
  22. /// </summary>
  23. public static void Initialize(string fisLogPath)
  24. {
  25. if (string.IsNullOrEmpty(fisLogPath))
  26. {
  27. FISLogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FISLogs");
  28. }
  29. else
  30. {
  31. FISLogPath = fisLogPath;
  32. }
  33. DirectoryHelper.CreateDirectory(FISLogPath);
  34. CpuInfo.Initialize();// initialize cpu info
  35. CrossPlatformHelper.Instance.Platform = EnumPlatform.Windows;
  36. CrossPlatformHelper.Instance.LiveVideoPusherCreator = new LiveVideoPusherCreator();
  37. CrossPlatformHelper.Instance.LiveVideoPusherCreatorForSonopost = new LiveVideoPusherCreatorForSonopost();
  38. CrossPlatformHelper.Instance.LiveVideoPusherCreatorV2 = new LiveVideoPusherCreatorV2();
  39. CrossPlatformHelper.Instance.RtcRoomCreator = new RtcRoomCreator();
  40. CrossPlatformHelper.Instance.RtmpPlayerCreator = new RtmpPlayerCreator();
  41. CrossPlatformHelper.Instance.RtmpPusherCreator = new RtmpPusherCreator();
  42. CrossPlatformHelper.Instance.DriverHelper = new DriverHelper();
  43. CrossPlatformHelper.Instance.HardwareDetector = new HardwareDetector();
  44. CrossPlatformHelper.Instance.ImageHelperCreator = new ImageHelperCreator();
  45. CrossPlatformHelper.Instance.CapturerCreator = new CapturerCreator();
  46. CrossPlatformHelper.Instance.StrokeHelper = new StrokeHelper();
  47. InitSetSmartSDKLogPath();
  48. InitSetTRTCSDKLogPath();
  49. RegistSmartSDK();
  50. RegisterFFmpegBinaries();
  51. }
  52. private static void InitSetTRTCSDKLogPath()
  53. {
  54. try
  55. {
  56. var logDirectory = Path.Combine(FISLogPath, "TRTCLogs");
  57. DirectoryHelper.CreateDirectory(logDirectory);
  58. var trtccloud = ITRTCCloud.getTRTCShareInstance();
  59. trtccloud.setLogCompressEnabled(false);
  60. trtccloud.setLogLevel(TRTCLogLevel.TRTCLogLevelError);
  61. trtccloud.setLogDirPath(logDirectory);
  62. CrossPlatformHelper.Instance.LogWriter?.WriteLineInfo($"Set TRTC sdk Log Path Success");
  63. var version = trtccloud.getSDKVersion();
  64. CrossPlatformHelper.Instance.LogWriter?.WriteLineInfo($"TRTC Version:{version}");
  65. }
  66. catch (Exception e)
  67. {
  68. CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Init set TRTC sdk log path error:{e}");
  69. }
  70. }
  71. private static void InitSetSmartSDKLogPath()
  72. {
  73. try
  74. {
  75. var logDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartLogs");
  76. if (!string.IsNullOrEmpty(FISLogPath))
  77. {
  78. logDirectory = Path.Combine(FISLogPath, "SmartLogs");
  79. }
  80. DirectoryHelper.CreateDirectory(logDirectory);
  81. var ret = Environment.Is64BitProcess ?
  82. NTSmartLog_x64.NT_SL_SetPath(logDirectory) : NTSmartLog_x86.NT_SL_SetPath(logDirectory);
  83. #if DEBUG
  84. ret = Environment.Is64BitProcess ?
  85. NTSmartLog_x64.NT_SL_SetLevel((uint)SL_LOG_LEVEL.SL_DEBUG_LEVEL) : NTSmartLog_x86.NT_SL_SetLevel((uint)SL_LOG_LEVEL.SL_DEBUG_LEVEL);
  86. #else
  87. ret = Environment.Is64BitProcess ?
  88. NTSmartLog_x64.NT_SL_SetLevel((uint)SL_LOG_LEVEL.SL_ERROR_LEVEL) : NTSmartLog_x86.NT_SL_SetLevel((uint)SL_LOG_LEVEL.SL_ERROR_LEVEL);
  89. #endif
  90. var path = Path.Combine(logDirectory, "smart_sdk.log");
  91. if (File.Exists(path))
  92. {
  93. FileInfo fi = new FileInfo(path);
  94. var createTime = fi.CreationTime.ToString("yyyyMMddHHmmss");
  95. var newFilePath = Path.Combine(logDirectory, $"smart_sdk_{createTime}.log");
  96. File.Copy(path, newFilePath, true);
  97. }
  98. CrossPlatformHelper.Instance.LogWriter?.WriteLineInfo($"Set smart sdk Log Path Success");
  99. }
  100. catch (Exception e)
  101. {
  102. CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Init set smart sdk log path error:{e}");
  103. }
  104. }
  105. private static void RegistSmartSDK()
  106. {
  107. var ret = Environment.Is64BitProcess
  108. ? NTSmartPublisherSDK_x64.NT_PB_SetSDKClientKey("03396870E2CA4E4F98593EC368EE77ED", "9ACF4FBED7EF4E56833941DE29267C9F79130CBB4C7345E2859ED4E1E2DC9EDD", 0, IntPtr.Zero) :
  109. NTSmartPublisherSDK_x86.NT_PB_SetSDKClientKey("03396870E2CA4E4F98593EC368EE77ED", "9ACF4FBED7EF4E56833941DE29267C9F79130CBB4C7345E2859ED4E1E2DC9EDD", 0, IntPtr.Zero);
  110. if (NTBaseCodeDefine.NT_ERC_OK != ret)
  111. {
  112. CrossPlatformHelper.Instance.LogWriter?.WriteLineError("Regist Publisher failed.");
  113. return;
  114. }
  115. ret = Environment.Is64BitProcess
  116. ? NTSmartPlayerSDK_x64.NT_SP_SetSDKClientKey("03396870E2CA4E4F98593EC368EE77ED", "9ACF4FBED7EF4E56833941DE29267C9F79130CBB4C7345E2859ED4E1E2DC9EDD", 0, IntPtr.Zero) :
  117. NTSmartPlayerSDK_x86.NT_SP_SetSDKClientKey("03396870E2CA4E4F98593EC368EE77ED", "9ACF4FBED7EF4E56833941DE29267C9F79130CBB4C7345E2859ED4E1E2DC9EDD", 0, IntPtr.Zero);
  118. if (NTBaseCodeDefine.NT_ERC_OK != ret)
  119. {
  120. CrossPlatformHelper.Instance.LogWriter?.WriteLineError("Regist Player failed.");
  121. return;
  122. }
  123. ret = Environment.Is64BitProcess
  124. ? NTSmartPublisherSDK_x64.NT_PB_Init(0, IntPtr.Zero)
  125. : NTSmartPublisherSDK_x86.NT_PB_Init(0, IntPtr.Zero);
  126. if (NTBaseCodeDefine.NT_ERC_OK != ret)
  127. {
  128. throw new InvalidOperationException("Initialize SDK failed.");
  129. }
  130. }
  131. private static void RegisterFFmpegBinaries()
  132. {
  133. var ffmpegBinaryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "x64");
  134. if (Directory.Exists(ffmpegBinaryPath))
  135. {
  136. CrossPlatformHelper.Instance.LogWriter?.WriteLineInfo($"FFmpeg binaries found in: {ffmpegBinaryPath}");
  137. ffmpeg.RootPath = ffmpegBinaryPath;
  138. }
  139. else
  140. {
  141. throw new Exception("ffmpegBinaryPath is not Exist");
  142. }
  143. }
  144. }
  145. }