LiveVideoServiceForWindows.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. using FISLib;
  2. using FISLib.LiveVideo;
  3. using FISLib.Notification;
  4. using System;
  5. using System.Collections.Concurrent;
  6. using System.Collections.Generic;
  7. using System.Runtime.InteropServices;
  8. using System.Threading;
  9. using Vinno.FIS.TRTCClient.Common.Enum;
  10. using Vinno.IUS.Common.Log;
  11. using Vinno.vCloud.Common.FIS;
  12. using Vinno.vCloud.Common.FIS.LiveVideos;
  13. using Vinno.vCloud.FIS.CrossPlatform.Common.LiveVideo;
  14. namespace FISIMPL
  15. {
  16. internal class LiveVideoServiceForWindows : ILiveVideoService, IDisposable
  17. {
  18. private readonly ConcurrentStack<byte[]> _byteImageCache = new ConcurrentStack<byte[]>();
  19. private ILiveVideo _liveVideo;
  20. private ILiveVideoV2 _liveVideoV2;
  21. private PipeClient _pipeClient;
  22. private PipeServer _pipeServer;
  23. private FISImageFrameData _imageFrameData;
  24. private FISBase64ImageData _tempBase64ImageData;
  25. /// <summary>
  26. /// Raised when local camera live execute
  27. /// </summary>
  28. public event EventHandler<FISImageFrameData> PreviewCameraCaptured;
  29. /// <summary>
  30. /// Raised when capture image generated.(only for new server)
  31. /// </summary>
  32. public event EventHandler<string> CaptureImageGenerated;
  33. /// <summary>
  34. /// Raised when record video generated.(only for new server)
  35. /// </summary>
  36. public event EventHandler<string> RecordVideoGenerated;
  37. internal void Update(IvCloudTerminal vcloudTerminal)
  38. {
  39. try
  40. {
  41. var newLiveVideo = vcloudTerminal?.GetFeature<ILiveVideo>(TerminalFeatureType.LiveVideo);
  42. if (newLiveVideo != _liveVideo)
  43. {
  44. if (_liveVideo != null)
  45. {
  46. _liveVideo.PreviewCameraCaptured -= OnPreviewCameraCaptured;
  47. _liveVideo.CameraPreviewImageSizeChanged -= OnCameraPreviewImageSizeChanged;
  48. _liveVideo.LiveNotification -= OnLiveNotification;
  49. _liveVideo.Dispose();
  50. _liveVideo = null;
  51. if (FISIMPL.IsRunningJsonRpcMode)
  52. {
  53. _pipeClient.Dispose();
  54. _pipeClient.LogMsgThrow -= OnLogMsgThrow;
  55. _pipeClient = null;
  56. _pipeServer.DataReceived -= OnDataReceived;
  57. _pipeServer.Dispose();
  58. _pipeServer.LogMsgThrow -= OnLogMsgThrow;
  59. _pipeServer = null;
  60. }
  61. }
  62. _liveVideo = newLiveVideo;
  63. if (_liveVideo != null)
  64. {
  65. _liveVideo.PreviewCameraCaptured += OnPreviewCameraCaptured;
  66. _liveVideo.CameraPreviewImageSizeChanged += OnCameraPreviewImageSizeChanged;
  67. _liveVideo.LiveNotification += OnLiveNotification;
  68. if (FISIMPL.IsRunningJsonRpcMode)
  69. {
  70. _pipeClient = new PipeClient(FISConsts.PipeForLiveVideoCameraPreviewImage, FISIMPL.Platform == FISPlatform.Linux);
  71. _pipeClient.LogMsgThrow += OnLogMsgThrow;
  72. _pipeClient.Start();
  73. _pipeServer = new PipeServer(FISConsts.PipeForLiveVideoUltrasoundImage);
  74. _pipeServer.LogMsgThrow += OnLogMsgThrow;
  75. _pipeServer.DataReceived += OnDataReceived;
  76. _pipeServer.StartAndReceive();
  77. }
  78. }
  79. }
  80. }
  81. catch (Exception ex)
  82. {
  83. Logger.WriteLineError($"LiveVideoServiceForWindows Update Error:{ex}");
  84. }
  85. }
  86. internal void UpdateV2(IvCloudTerminalV2 vcloudTerminalV2)
  87. {
  88. try
  89. {
  90. var newLiveVideo = vcloudTerminalV2?.GetFeature<ILiveVideoV2>(TerminalFeatureType.LiveVideo);
  91. if (newLiveVideo != _liveVideoV2)
  92. {
  93. if (_liveVideoV2 != null)
  94. {
  95. _liveVideoV2.PreviewCameraCaptured -= OnPreviewCameraCaptured;
  96. _liveVideoV2.CameraPreviewImageSizeChanged -= OnCameraPreviewImageSizeChanged;
  97. _liveVideoV2.LiveNotification -= OnLiveNotification;
  98. _liveVideoV2.CaptureImageGenerated -= OnCaptureImageGenerated;
  99. _liveVideoV2.RecordVideoGenerated -= OnRecordVideoGenerated;
  100. _liveVideoV2.Dispose();
  101. _liveVideoV2 = null;
  102. if (FISIMPL.IsRunningJsonRpcMode)
  103. {
  104. _pipeClient.Dispose();
  105. _pipeClient.LogMsgThrow -= OnLogMsgThrow;
  106. _pipeClient = null;
  107. _pipeServer.DataReceived -= OnDataReceived;
  108. _pipeServer.Dispose();
  109. _pipeServer.LogMsgThrow -= OnLogMsgThrow;
  110. _pipeServer = null;
  111. }
  112. }
  113. _liveVideoV2 = newLiveVideo;
  114. if (_liveVideoV2 != null)
  115. {
  116. _liveVideoV2.PreviewCameraCaptured += OnPreviewCameraCaptured;
  117. _liveVideoV2.CameraPreviewImageSizeChanged += OnCameraPreviewImageSizeChanged;
  118. _liveVideoV2.LiveNotification += OnLiveNotification;
  119. _liveVideoV2.CaptureImageGenerated += OnCaptureImageGenerated;
  120. _liveVideoV2.RecordVideoGenerated += OnRecordVideoGenerated;
  121. if (FISIMPL.IsRunningJsonRpcMode)
  122. {
  123. _pipeClient = new PipeClient(FISConsts.PipeForLiveVideoCameraPreviewImage, FISIMPL.Platform == FISPlatform.Linux);
  124. _pipeClient.LogMsgThrow += OnLogMsgThrow;
  125. _pipeClient.Start();
  126. _pipeServer = new PipeServer(FISConsts.PipeForLiveVideoUltrasoundImage);
  127. _pipeServer.LogMsgThrow += OnLogMsgThrow;
  128. _pipeServer.DataReceived += OnDataReceived;
  129. _pipeServer.StartAndReceive();
  130. }
  131. }
  132. }
  133. }
  134. catch (Exception ex)
  135. {
  136. Logger.WriteLineError($"LiveVideoServiceForWindows UpdateV2 Error:{ex}");
  137. }
  138. }
  139. private void OnCaptureImageGenerated(object sender, string e)
  140. {
  141. CaptureImageGenerated?.Invoke(this, e);
  142. }
  143. private void OnRecordVideoGenerated(object sender, string e)
  144. {
  145. RecordVideoGenerated?.Invoke(this, e);
  146. }
  147. private void OnDataReceived(object sender, byte[] e)
  148. {
  149. _byteImageCache.Push(e);
  150. }
  151. /// <summary>
  152. /// Change camera settings.
  153. /// </summary>
  154. /// <param name="cameraSetting"></param>
  155. public void ChangeCameraSetting(CameraSetting cameraSetting)
  156. {
  157. try
  158. {
  159. if (cameraSetting == null)
  160. {
  161. Logger.WriteLineError($"ChangeCameraSetting error: cameraSetting is null");
  162. return;
  163. }
  164. if (FISIMPL.IsConnectWithOldServer)
  165. {
  166. if (_liveVideo == null)
  167. {
  168. Logger.WriteLineError($"ChangeCameraSetting error: live video feature is null");
  169. return;
  170. }
  171. _liveVideo.ChangeCameraSettings(cameraSetting.CameraLiveEnabled && cameraSetting.LiveVideoEnabled, cameraSetting.CameraSource?.Id, cameraSetting.MicSource?.Id, cameraSetting.CameraPreviewEnabled, cameraSetting.LiveVideoEnabled, cameraSetting.IsMute);
  172. }
  173. else
  174. {
  175. if (_liveVideoV2 == null)
  176. {
  177. Logger.WriteLineError($"ChangeCameraSetting error: live video v2 feature is null");
  178. return;
  179. }
  180. _liveVideoV2.ChangeCameraSettings(cameraSetting.CameraLiveEnabled && cameraSetting.LiveVideoEnabled, cameraSetting.CameraSource?.Id, cameraSetting.MicSource?.Id, cameraSetting.CameraPreviewEnabled, cameraSetting.LiveVideoEnabled, cameraSetting.IsMute);
  181. }
  182. }
  183. catch (Exception ex)
  184. {
  185. Logger.WriteLineError($"LiveVideoServiceForWindows ChangeCameraSetting Error:{ex}");
  186. }
  187. }
  188. /// <summary>
  189. /// Change camera settings for sonopost
  190. /// </summary>
  191. /// <param name="cameraSetting"></param>
  192. public void ChangeCameraSettingForSonopost(CameraSettingForSonopost cameraSetting)
  193. {
  194. try
  195. {
  196. if (cameraSetting == null)
  197. {
  198. Logger.WriteLineError($"ChangeCameraSetting error: cameraSetting is null");
  199. return;
  200. }
  201. var currentLiveChannelCategory = (EnumLiveChannelCategory)cameraSetting.CurrentLiveChannelCategory;
  202. var videoDeviceInfoList = new List<CPVideoDeviceInfo>();
  203. if (cameraSetting.VideoDeviceInfoList != null)
  204. {
  205. foreach (var fisVideoDeviceInfo in cameraSetting.VideoDeviceInfoList)
  206. {
  207. var videoDeviceInfo = FISConverter.ConvertFISVideoDeviceInfoToCPVideoDeviceInfo(fisVideoDeviceInfo);
  208. videoDeviceInfoList.Add(videoDeviceInfo);
  209. }
  210. }
  211. string micId = null;
  212. bool isMute = true;
  213. if (cameraSetting.MicDeviceInfo != null)
  214. {
  215. micId = cameraSetting.MicDeviceInfo.Id;
  216. isMute = !cameraSetting.MicDeviceInfo.IsEnable;
  217. }
  218. var rainbowImageDetectConfig = FISConverter.ConvertFISRainbowImageDetectConfigToRainbowImageDetectConfig(cameraSetting.RainbowImageDetectConfig);
  219. if (FISIMPL.IsConnectWithOldServer)
  220. {
  221. if (_liveVideo == null)
  222. {
  223. Logger.WriteLineError($"ChangeCameraSetting error: live video feature is null");
  224. return;
  225. }
  226. _liveVideo.ChangeCameraSettingsForSonopost(cameraSetting.CameraPreviewEnabled, currentLiveChannelCategory, videoDeviceInfoList, rainbowImageDetectConfig, micId, isMute);
  227. }
  228. else
  229. {
  230. if (_liveVideoV2 == null)
  231. {
  232. Logger.WriteLineError($"ChangeCameraSetting error: live videoV2 feature is null");
  233. return;
  234. }
  235. _liveVideoV2.ChangeCameraSettingsForSonopost(cameraSetting.CameraPreviewEnabled, currentLiveChannelCategory, videoDeviceInfoList, micId, isMute, rainbowImageDetectConfig);
  236. }
  237. }
  238. catch (Exception ex)
  239. {
  240. Logger.WriteLineError($"LiveVideoServiceForWindows ChangeCameraSettingForSonopost Error:{ex}");
  241. }
  242. }
  243. /// <summary>
  244. /// Speed live test network and auto select good network to server
  245. /// </summary>
  246. /// <returns></returns>
  247. public bool StartSpeedTest()
  248. {
  249. try
  250. {
  251. if (FISIMPL.IsConnectWithOldServer)
  252. {
  253. if (_liveVideo == null)
  254. {
  255. Logger.WriteLineError($"ChangeCameraSetting error: live video feature is null");
  256. return false;
  257. }
  258. return _liveVideo.StartSpeedTest();
  259. }
  260. else
  261. {
  262. if (_liveVideoV2 == null)
  263. {
  264. Logger.WriteLineError($"ChangeCameraSetting error: live video v2 feature is null");
  265. return false;
  266. }
  267. return _liveVideoV2.StartSpeedTest();
  268. }
  269. }
  270. catch (Exception ex)
  271. {
  272. Logger.WriteLineError($"LiveVideoServiceForWindows StartSpeedTest Error:{ex}");
  273. return false;
  274. }
  275. }
  276. /// <summary>
  277. /// Capture ultrasound machie image data.
  278. /// </summary>
  279. /// <param name="length">image data length</param>
  280. /// <param name="width">image width</param>
  281. /// <param name="height">image height</param>
  282. public void CapturedUSImageData(int length, int width, int height)
  283. {
  284. try
  285. {
  286. byte[] byteImage = null;
  287. int retryCount = 0;
  288. while (!_byteImageCache.TryPop(out byteImage) && retryCount < 50)
  289. {
  290. Thread.Sleep(10);
  291. retryCount++;
  292. }
  293. if (byteImage == null)
  294. {
  295. Logger.WriteLineError($"LiveVideoServiceForWindows-CapturedUSImageData Get Image Cache Fail");
  296. return;
  297. }
  298. if (byteImage == null)
  299. {
  300. return;
  301. }
  302. var imageCaptureDataInfo = new CaptureDataInfo
  303. {
  304. Width = width,
  305. Height = height,
  306. Data = byteImage,
  307. };
  308. ImageDataCapturer.RaiseImdageDataCaptured(imageCaptureDataInfo);
  309. }
  310. catch (Exception ex)
  311. {
  312. Logger.WriteLineError($"LiveVideoServiceForWindows CapturedUSImageData Error:{ex}");
  313. }
  314. }
  315. /// <summary>
  316. /// 获取品牌列表
  317. /// </summary>
  318. /// <returns></returns>
  319. public List<string> GetBrandList()
  320. {
  321. try
  322. {
  323. if (FISIMPL.IsConnectWithOldServer)
  324. {
  325. if (_liveVideo == null)
  326. {
  327. Logger.WriteLineError($"GetBrandList error: live video feature is null");
  328. return new List<string>();
  329. }
  330. return _liveVideo.GetBrandList();
  331. }
  332. else
  333. {
  334. if (_liveVideoV2 == null)
  335. {
  336. Logger.WriteLineError($"GetBrandList error: live videoV2 feature is null");
  337. return new List<string>();
  338. }
  339. return _liveVideoV2.GetBrandList();
  340. }
  341. }
  342. catch (Exception ex)
  343. {
  344. Logger.WriteLineError($"LiveVideoServiceForWindows GetBrandList Error:{ex}");
  345. return new List<string>();
  346. }
  347. }
  348. /// <summary>
  349. /// 获取型号列表
  350. /// </summary>
  351. /// <param name="brand"></param>
  352. /// <param name="model"></param>
  353. /// <returns></returns>
  354. public List<string> GetModelList(string brand)
  355. {
  356. try
  357. {
  358. if (FISIMPL.IsConnectWithOldServer)
  359. {
  360. if (_liveVideo == null)
  361. {
  362. Logger.WriteLineError($"GetModelList error: live video feature is null");
  363. return new List<string>();
  364. }
  365. return _liveVideo.GetModelList(brand);
  366. }
  367. else
  368. {
  369. if (_liveVideoV2 == null)
  370. {
  371. Logger.WriteLineError($"GetModelList error: live videoV2 feature is null");
  372. return new List<string>();
  373. }
  374. return _liveVideoV2.GetModelList(brand);
  375. }
  376. }
  377. catch (Exception ex)
  378. {
  379. Logger.WriteLineError($"LiveVideoServiceForWindows GetModelList Error:{ex}");
  380. return new List<string>();
  381. }
  382. }
  383. /// <summary>
  384. /// 获取推荐分辨率
  385. /// </summary>
  386. /// <param name="brand"></param>
  387. /// <param name="model"></param>
  388. /// <returns></returns>
  389. public FISDeviceRecommandResolution GetRecommandResolution(string brand, string model)
  390. {
  391. try
  392. {
  393. if (FISIMPL.IsConnectWithOldServer)
  394. {
  395. if (_liveVideo == null)
  396. {
  397. Logger.WriteLineError($"GetRecommandResolution error: live video feature is null");
  398. return null;
  399. }
  400. var result = _liveVideo.GetRecommandResolution(brand, model);
  401. return FISConverter.ConvertDeviceRecommandResolutionToFISDeviceRecommandResolution(result);
  402. }
  403. else
  404. {
  405. if (_liveVideoV2 == null)
  406. {
  407. Logger.WriteLineError($"GetRecommandResolution error: live videoV2 feature is null");
  408. return null;
  409. }
  410. var result = _liveVideoV2.GetRecommandResolution(brand, model);
  411. return FISConverter.ConvertDeviceRecommandResolutionToFISDeviceRecommandResolution(result);
  412. }
  413. }
  414. catch (Exception ex)
  415. {
  416. Logger.WriteLineError($"LiveVideoServiceForWindows GetRecommandResolution Error:{ex}");
  417. return null;
  418. }
  419. }
  420. /// <summary>
  421. /// Dispose
  422. /// </summary>
  423. public void Dispose()
  424. {
  425. try
  426. {
  427. Update(null);
  428. UpdateV2(null);
  429. }
  430. catch (Exception ex)
  431. {
  432. Logger.WriteLineError($"LiveVideoServiceForWindows Dispose Error:{ex}");
  433. }
  434. }
  435. private void OnPreviewCameraCaptured(object sender, byte[] e)
  436. {
  437. try
  438. {
  439. if (FISIMPL.IsRunningJsonRpcMode)
  440. {
  441. _pipeClient?.SendBytes(e);
  442. }
  443. else
  444. {
  445. if (_imageFrameData == null || _imageFrameData.Size != e.Length)
  446. {
  447. return;
  448. }
  449. Marshal.Copy(e, 0, _imageFrameData.Data, e.Length);
  450. PreviewCameraCaptured?.Invoke(this, _imageFrameData);
  451. }
  452. }
  453. catch (Exception ex)
  454. {
  455. Logger.WriteLineError($"LiveVideoServiceForWindows OnPreviewCameraCaptured Error:{ex}");
  456. }
  457. }
  458. private void OnCameraPreviewImageSizeChanged(object sender, ImageSize e)
  459. {
  460. try
  461. {
  462. if (FISIMPL.IsRunningJsonRpcMode)
  463. {
  464. var fisImageSize = new FISImageSize(e.Width, e.Height);
  465. NotificationSender.SendNotification(new FISNotificationArgs
  466. {
  467. NotificationType = FISNotificationType.FISLiveVideoCameraImageSizeChange,
  468. Params = fisImageSize
  469. });
  470. }
  471. else
  472. {
  473. if (_imageFrameData == null)
  474. {
  475. _imageFrameData = new FISImageFrameData(e.Width, e.Height);
  476. }
  477. else if (_imageFrameData.Width != e.Width || _imageFrameData.Height != e.Height)
  478. {
  479. _imageFrameData.Resize(e.Width, e.Height);
  480. }
  481. }
  482. }
  483. catch (Exception ex)
  484. {
  485. Logger.WriteLineError($"LiveVideoServiceForWindows OnCameraPreviewImageSizeChanged Error:{ex}");
  486. }
  487. }
  488. private void OnLiveNotification(object sender, LiveNotificationArgs e)
  489. {
  490. try
  491. {
  492. var fisLiveNotificationArgs = new FISLiveNotificationArgs(e.IsLive, e.LiveWidth, e.LiveHeight);
  493. if (FISIMPL.IsRunningJsonRpcMode)
  494. {
  495. NotificationSender.SendNotification(new FISNotificationArgs
  496. {
  497. Params = fisLiveNotificationArgs,
  498. NotificationType = FISNotificationType.FISLiveVideoLiveNotification
  499. });
  500. }
  501. }
  502. catch (Exception ex)
  503. {
  504. Logger.WriteLineError($"LiveVideoServiceForWindows OnLiveNotification Error:{ex}");
  505. }
  506. }
  507. private void OnLogMsgThrow(object sender, FISLogEventArgs e)
  508. {
  509. if (e == null)
  510. {
  511. return;
  512. }
  513. switch (e.LogType)
  514. {
  515. case FISDeviceLogCategory.Error:
  516. Logger.WriteLineError(e.Msg);
  517. break;
  518. case FISDeviceLogCategory.Warn:
  519. Logger.WriteLineWarn(e.Msg);
  520. break;
  521. case FISDeviceLogCategory.Verb:
  522. Logger.WriteLineVerbose(e.Msg);
  523. break;
  524. case FISDeviceLogCategory.Info:
  525. default:
  526. Logger.WriteLineInfo(e.Msg);
  527. break;
  528. }
  529. }
  530. public void ChangeRealTimeCaptureSetting(bool isStart)
  531. {
  532. try
  533. {
  534. if (FISIMPL.IsConnectWithOldServer)
  535. {
  536. Logger.WriteLineError($"ChangeRealTimeCaptureSetting error: old Server doesn't support");
  537. return;
  538. }
  539. else
  540. {
  541. if (_liveVideoV2 == null)
  542. {
  543. Logger.WriteLineError($"ChangeRealTimeCaptureSetting error: live videoV2 feature is null");
  544. return;
  545. }
  546. _liveVideoV2.ChangeRealTimeCaptureSetting(isStart);
  547. }
  548. }
  549. catch (Exception ex)
  550. {
  551. Logger.WriteLineError($"LiveVideoServiceForWindows ChangeRealTimeCaptureSetting Error:{ex}");
  552. }
  553. }
  554. /// <summary>
  555. /// Capture current Image
  556. /// </summary>
  557. public void CaptureCurrentImage()
  558. {
  559. try
  560. {
  561. if (FISIMPL.IsConnectWithOldServer)
  562. {
  563. Logger.WriteLineError($"CaptureCurrentImage error: old Server doesn't support");
  564. return;
  565. }
  566. else
  567. {
  568. if (_liveVideoV2 == null)
  569. {
  570. Logger.WriteLineError($"CaptureCurrentImage error: live videoV2 feature is null");
  571. return;
  572. }
  573. _liveVideoV2.CaptureCurrentImage();
  574. }
  575. }
  576. catch (Exception ex)
  577. {
  578. Logger.WriteLineError($"LiveVideoServiceForWindows CaptureCurrentImage Error:{ex}");
  579. }
  580. }
  581. /// <summary>
  582. /// Start Record Video
  583. /// </summary>
  584. public void StartRecordVideo()
  585. {
  586. try
  587. {
  588. if (FISIMPL.IsConnectWithOldServer)
  589. {
  590. Logger.WriteLineError($"StartRecordVideo error: old Server doesn't support");
  591. return;
  592. }
  593. else
  594. {
  595. if (_liveVideoV2 == null)
  596. {
  597. Logger.WriteLineError($"StartRecordVideo error: live videoV2 feature is null");
  598. return;
  599. }
  600. _liveVideoV2.StartRecordVideo();
  601. }
  602. }
  603. catch (Exception ex)
  604. {
  605. Logger.WriteLineError($"LiveVideoServiceForWindows StartRecordVideo Error:{ex}");
  606. }
  607. }
  608. /// <summary>
  609. /// Stop Record Video
  610. /// </summary>
  611. public void StopRecordVideo(bool isTimeOut)
  612. {
  613. try
  614. {
  615. if (FISIMPL.IsConnectWithOldServer)
  616. {
  617. Logger.WriteLineError($"StopRecordVideo error: old Server doesn't support");
  618. return;
  619. }
  620. else
  621. {
  622. if (_liveVideoV2 == null)
  623. {
  624. Logger.WriteLineError($"StopRecordVideo error: live videoV2 feature is null");
  625. return;
  626. }
  627. _liveVideoV2.StopRecordVideo(isTimeOut);
  628. }
  629. }
  630. catch (Exception ex)
  631. {
  632. Logger.WriteLineError($"LiveVideoServiceForWindows StopRecordVideo Error:{ex}");
  633. }
  634. }
  635. public void ReUploadRestVid()
  636. {
  637. try
  638. {
  639. if (FISIMPL.IsConnectWithOldServer)
  640. {
  641. Logger.WriteLineError($"ReUploadRestVid error: old Server doesn't support");
  642. return;
  643. }
  644. else
  645. {
  646. if (_liveVideoV2 == null)
  647. {
  648. Logger.WriteLineError($"ReUploadRestVid error: live videoV2 feature is null");
  649. return;
  650. }
  651. _liveVideoV2.ReUploadRestVid();
  652. }
  653. }
  654. catch (Exception ex)
  655. {
  656. Logger.WriteLineError($"LiveVideoServiceForWindows StopRecordVideo Error:{ex}");
  657. }
  658. }
  659. public FISBase64ImageData GetCurrentCaptureFrame()
  660. {
  661. try
  662. {
  663. if (FISIMPL.IsConnectWithOldServer)
  664. {
  665. Logger.WriteLineError($"GetCurrentCaptureFrame error: old Server doesn't support");
  666. return new FISBase64ImageData(0, 0, "", FailReasonForNullBase64Data.OldServerNotSupport);
  667. }
  668. else
  669. {
  670. if (_liveVideoV2 == null)
  671. {
  672. Logger.WriteLineError($"GetCurrentCaptureFrame error: live videoV2 feature is null");
  673. return new FISBase64ImageData(0, 0, "", FailReasonForNullBase64Data.vCloudIsDisconnected);
  674. }
  675. var videoFrameData = _liveVideoV2.GetCurrentCaptureFrame();
  676. if (videoFrameData == null)
  677. {
  678. return new FISBase64ImageData(0, 0, "", FailReasonForNullBase64Data.Unknown);
  679. }
  680. else if (_tempBase64ImageData == null)
  681. {
  682. _tempBase64ImageData = new FISBase64ImageData(videoFrameData.Width, videoFrameData.Height, "");
  683. }
  684. else if (_tempBase64ImageData.Width != videoFrameData.Width || _tempBase64ImageData.Height != videoFrameData.Height)
  685. {
  686. _tempBase64ImageData.Width = videoFrameData.Width;
  687. _tempBase64ImageData.Height = videoFrameData.Height;
  688. }
  689. _tempBase64ImageData.Base64Data = videoFrameData.Base64Data;
  690. _tempBase64ImageData.FailMsg = (FailReasonForNullBase64Data)videoFrameData.FailMsg;
  691. return _tempBase64ImageData;
  692. }
  693. }
  694. catch (Exception ex)
  695. {
  696. Logger.WriteLineError($"LiveVideoServiceForWindows GetCurrentCaptureFrame Error:{ex}");
  697. return null;
  698. }
  699. }
  700. }
  701. }