FISAndroid.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using Android.App;
  2. using Com.Tencent.Trtc;
  3. using System;
  4. using System.IO;
  5. using Vinno.FIS.TRTCClient.Common;
  6. using Vinno.FIS.TRTCClient.Common.FileTransfer;
  7. using Vinno.FIS.TRTCClient.Common.Log;
  8. using Vinno.vCloud.FIS.CrossPlatform.Android.Consultation;
  9. using Vinno.vCloud.FIS.CrossPlatform.Android.Consultation.RTC;
  10. using Vinno.vCloud.FIS.CrossPlatform.Android.Consultation.RTMP;
  11. using Vinno.vCloud.FIS.CrossPlatform.Android.Hardware;
  12. using Vinno.vCloud.FIS.CrossPlatform.Android.LiveVideo;
  13. using Vinno.vCloud.FIS.CrossPlatform.Common;
  14. using Vinno.vCloud.FIS.CrossPlatform.Common.Enum;
  15. using Vinno.vCloud.FIS.CrossPlatform.Common.Helper;
  16. namespace Vinno.vCloud.FIS.CrossPlatform.Android
  17. {
  18. public class FISAndroid
  19. {
  20. internal static string FISLogPath;
  21. internal static string FISFolderPath;
  22. internal static FileTransferReader FileReaderFromTRTCLiveVideoToCommon;
  23. internal static FileTransferWriter FileWrtierFromCommonToTRTCLiveVideo;
  24. internal static FileTransferReader FileReaderFromTRTCConsultationToCommon;
  25. internal static FileTransferWriter FileWrtierFromCommonToTRTCConsultation;
  26. public static void Initialize(string fisLogFolderPath, string fisFolderPath)
  27. {
  28. if (string.IsNullOrEmpty(fisFolderPath))
  29. {
  30. FISFolderPath = Path.Combine(Application.Context.GetExternalFilesDir(null).Path, "FIS");
  31. }
  32. else
  33. {
  34. FISFolderPath = fisFolderPath;
  35. }
  36. if (string.IsNullOrEmpty(fisLogFolderPath))
  37. {
  38. FISLogPath = Path.Combine(FISFolderPath, "FISLogs");
  39. }
  40. else
  41. {
  42. FISLogPath = fisLogFolderPath;
  43. }
  44. DirectoryHelper.CreateDirectory(FISFolderPath);
  45. DirectoryHelper.CreateDirectory(FISLogPath);
  46. MobileInfo.Initialize();
  47. CrossPlatformHelper.Instance.Platform = EnumPlatform.Android;
  48. CrossPlatformHelper.Instance.LiveVideoPusherCreator = new LiveVideoPusherCreator();
  49. CrossPlatformHelper.Instance.HardwareDetector = new HardwareDetector();
  50. CrossPlatformHelper.Instance.ImageHelperCreator = new ImageHelperCreator();
  51. CrossPlatformHelper.Instance.RtmpPusherCreator = new RtmpPusherCreator();
  52. CrossPlatformHelper.Instance.RtmpPlayerCreator = new RtmpPlayerCreator();
  53. CrossPlatformHelper.Instance.CapturerCreator = new CapturerCreator();
  54. CrossPlatformHelper.Instance.RtcRoomCreator = new RtcRoomCreator();
  55. CrossPlatformHelper.Instance.LiveVideoPusherCreatorV2 = new LiveVideoPusherCreatorV2();
  56. FileWrtierFromCommonToTRTCLiveVideo = new FileTransferWriter(FISTRTCConsts.CommonToTRTCLiveVideoMessageTransferFolder, FISTRTCConsts.DataTransferFolderForTRTCLiveVideo, FISFolderPath, FISTRTCConsts.CommonToTRTCLiveVideoReserveMessageTransferFolder);
  57. FileWrtierFromCommonToTRTCLiveVideo.LogMsgThrow += OnLogMsgThrow;
  58. FileReaderFromTRTCLiveVideoToCommon = new FileTransferReader(FISTRTCConsts.TRTCLiveVideoToCommonMessageTransferFolder, FISTRTCConsts.DataTransferFolderForTRTCLiveVideo, FISFolderPath, null);
  59. FileReaderFromTRTCLiveVideoToCommon.LogMsgThrow += OnLogMsgThrow;
  60. FileReaderFromTRTCLiveVideoToCommon.StartContinuousRead();
  61. FileWrtierFromCommonToTRTCConsultation = new FileTransferWriter(FISTRTCConsts.CommonToTRTCConsultationMessageTransferFolder, FISTRTCConsts.DataTransferFolderForTRTCConsultation, FISFolderPath, FISTRTCConsts.CommonToTRTCConsultationReserveMessageTransferFolder);
  62. FileWrtierFromCommonToTRTCConsultation.LogMsgThrow += OnLogMsgThrow;
  63. FileReaderFromTRTCConsultationToCommon = new FileTransferReader(FISTRTCConsts.TRTCConsultationToCommonMessageTransferFolder, FISTRTCConsts.DataTransferFolderForTRTCConsultation, FISFolderPath, null);
  64. FileReaderFromTRTCConsultationToCommon.LogMsgThrow += OnLogMsgThrow;
  65. FileReaderFromTRTCConsultationToCommon.StartContinuousRead();
  66. InitSetTRTCSDKLogPath();
  67. }
  68. private static void OnLogMsgThrow(object sender, LogEventArgs e)
  69. {
  70. switch (e.LogType)
  71. {
  72. case DeviceLogCategory.Error:
  73. CrossPlatformHelper.Instance.LogWriter?.WriteLineError(e.Msg);
  74. break;
  75. case DeviceLogCategory.Info:
  76. CrossPlatformHelper.Instance.LogWriter?.WriteLineInfo(e.Msg);
  77. break;
  78. case DeviceLogCategory.Warn:
  79. CrossPlatformHelper.Instance.LogWriter?.WriteLineWarn(e.Msg);
  80. break;
  81. case DeviceLogCategory.Verb:
  82. CrossPlatformHelper.Instance.LogWriter?.WriteLineDebug(e.Msg);
  83. break;
  84. }
  85. }
  86. private static void InitSetTRTCSDKLogPath()
  87. {
  88. try
  89. {
  90. var logDirectory = Path.Combine(FISLogPath, "TRTCLogs");
  91. if (!Directory.Exists(logDirectory))
  92. {
  93. Directory.CreateDirectory(logDirectory);
  94. }
  95. TRTCCloud.SetLogCompressEnabled(false);
  96. TRTCCloud.SetLogDirPath(logDirectory);
  97. TRTCCloud.SetLogLevel(TRTCCloudDef.TrtcLogLevelError);
  98. var version = TRTCCloud.SDKVersion;
  99. CrossPlatformHelper.Instance.LogWriter?.WriteLineInfo($"TRTC Version:{version}");
  100. }
  101. catch (Exception e)
  102. {
  103. CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Init set TRTC sdk log path error:{e}");
  104. }
  105. }
  106. }
  107. }