PushConfiguration.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System.Diagnostics;
  2. using Vinno.vCloud.FIS.CrossPlatform.Common.LiveVideo;
  3. namespace Vinno.vCloud.Common.FIS.LiveVideos
  4. {
  5. /// <summary>
  6. /// Configuration for pushing live video.
  7. /// </summary>
  8. public abstract class PushConfiguration
  9. {
  10. /// <summary>
  11. /// Push url
  12. /// </summary>
  13. public string PushUrl { get; set; }
  14. /// <summary>
  15. /// Gets the mode of this configuration.
  16. /// </summary>
  17. public PushMode Mode { get; }
  18. /// <summary>
  19. /// Get mic hardware path
  20. /// </summary>
  21. public string MicHardwarePath { get; set; }
  22. public ResolutionMode Resolution { get; set; }
  23. public string PushAppLogPath { get; }
  24. /// <summary>
  25. /// Enable preivew image
  26. /// </summary>
  27. public bool EnablePreviewImage { get; }
  28. /// <summary>
  29. /// Show Preview Image
  30. /// </summary>
  31. public bool ShowPreviewImage { get; set; }
  32. /// <summary>
  33. /// Should push data
  34. /// </summary>
  35. public bool ShouldPushData { get; set; }
  36. public string CameraHardwarePath { get; set; }
  37. protected PushConfiguration(PushMode mode, bool enablePreviewImage, bool showPreviewImage)
  38. {
  39. Mode = mode;
  40. EnablePreviewImage = enablePreviewImage;
  41. ShowPreviewImage = showPreviewImage;
  42. }
  43. protected PushConfiguration(PushMode mode, string micHardwarePath, bool enablePreviewImage, bool showPreviewImage)
  44. {
  45. Mode = mode;
  46. MicHardwarePath = micHardwarePath;
  47. EnablePreviewImage = enablePreviewImage;
  48. ShowPreviewImage = showPreviewImage;
  49. }
  50. protected PushConfiguration(PushMode mode, string micHardwarePath, ResolutionMode rMode, bool enablePreviewImage, bool showPreviewImage)
  51. {
  52. Mode = mode;
  53. MicHardwarePath = micHardwarePath;
  54. Resolution = rMode;
  55. EnablePreviewImage = enablePreviewImage;
  56. ShowPreviewImage = showPreviewImage;
  57. }
  58. protected PushConfiguration(PushMode mode, string micHardwarePath, ResolutionMode rMode, string pushAppLogPath = "", bool enablePreviewImage = false, bool showPreviewImage = false)
  59. {
  60. Mode = mode;
  61. MicHardwarePath = micHardwarePath;
  62. Resolution = rMode;
  63. EnablePreviewImage = enablePreviewImage;
  64. ShowPreviewImage = showPreviewImage;
  65. PushAppLogPath = pushAppLogPath;
  66. }
  67. protected string GetModeString()
  68. {
  69. return Mode == PushMode.Screen ? "Screen" : "Camera";
  70. }
  71. /// <summary>
  72. /// Convert configuration to a command line arguments.
  73. /// </summary>
  74. /// <returns>The command line arguments</returns>
  75. public abstract string ToArguments();
  76. }
  77. /// <inheritdoc />
  78. /// <summary>
  79. /// Configuration for pushing live video from desktop.
  80. /// </summary>
  81. public class ScreenPushConfiguration : PushConfiguration
  82. {
  83. public ScreenPushConfiguration(ResolutionMode rMode, string cameraHardwarePath, string micHardwarePath = "", string pushLogPath = "", bool enablePreviewImage = false, bool showPreviewImage = false)
  84. : base(PushMode.Screen, micHardwarePath, rMode, pushLogPath, enablePreviewImage, showPreviewImage)
  85. {
  86. CameraHardwarePath = cameraHardwarePath;
  87. }
  88. /// <inheritdoc />
  89. /// <summary>
  90. /// Convert configuration to a command line arguments.
  91. /// </summary>
  92. /// <returns>The command line arguments</returns>
  93. public override string ToArguments()
  94. {
  95. return $"\"{PushUrl}\" /p:plp=\"{PushAppLogPath}\" /p:m={GetModeString()} /p:vdp=\"{CameraHardwarePath}\" /p:adp=\"{MicHardwarePath}\" /p:irm=\"{Resolution}\" /p:pid={Process.GetCurrentProcess().Id} /p:epi={EnablePreviewImage} /p:spi={ShowPreviewImage} /p:spd={ShouldPushData}";
  96. }
  97. }
  98. /// <inheritdoc />
  99. /// <summary>
  100. /// Configuration for pushing live video from camera.
  101. /// </summary>
  102. public class CameraPushConfiguration : PushConfiguration
  103. {
  104. /// <summary>
  105. /// Gets the hardware source of the camera.
  106. /// </summary>
  107. public string CameraHardwarePath { get; set; }
  108. public CameraPushConfiguration(string cameraHardwarePath, ResolutionMode rMode, string micHardwarePath = "", string pushLogPath = "", bool enablePreviewImage = false, bool showPreviewImage = false)
  109. : base(PushMode.Camera, micHardwarePath, rMode, pushLogPath, enablePreviewImage, showPreviewImage)
  110. {
  111. CameraHardwarePath = cameraHardwarePath;
  112. }
  113. /// <inheritdoc />
  114. /// <summary>
  115. /// Convert configuration to a command line arguments.
  116. /// </summary>
  117. /// <returns>The command line arguments</returns>
  118. public override string ToArguments()
  119. {
  120. return $"\"{PushUrl}\" /p:plp=\"{PushAppLogPath}\" /p:m={GetModeString()} /p:vdp=\"{CameraHardwarePath}\" /p:irm=\"{Resolution}\" /p:adp=\"{MicHardwarePath}\" /p:pid={Process.GetCurrentProcess().Id} /p:epi={EnablePreviewImage} /p:spi={ShowPreviewImage} /p:spd={ShouldPushData}";
  121. }
  122. }
  123. public class HardwareResolution
  124. {
  125. /// <summary>
  126. /// Get average frame rate.
  127. /// </summary>
  128. public int AverageFrameRate { get; }
  129. /// <summary>
  130. /// Get frame height.
  131. /// </summary>
  132. public int FrameHeight { get; }
  133. /// <summary>
  134. /// Get frame width.
  135. /// </summary>
  136. public int FrameWidth { get; }
  137. public HardwareResolution(int averageFrameRate, int frameHeight, int frameWidth)
  138. {
  139. AverageFrameRate = averageFrameRate;
  140. FrameHeight = frameHeight;
  141. FrameWidth = frameWidth;
  142. }
  143. public override string ToString()
  144. {
  145. return $"{AverageFrameRate};{FrameHeight};{FrameWidth}";
  146. }
  147. }
  148. }