TUCameraVideoSave.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using TUCAMAPI;
  3. namespace TUCamera
  4. {
  5. public class TUCameraVideoSave : TUCameraIFrameProcess
  6. {
  7. public event VideoSaveHandler m_videoSaveHandler;
  8. private TUCamera m_camera;
  9. private UInt64 m_duration = 0; // 视频拍摄持续时间
  10. private DateTimeTools m_tools = null;
  11. private string m_fileName;
  12. private FrameProcesserState m_state = FrameProcesserState.STOP;
  13. private static int m_videoSave = 0;
  14. public TUCameraVideoSave(TUCamera camera, VideoSaveHandler videoSaveHandler, string fileName, UInt64 duration)
  15. {
  16. m_camera = camera;
  17. m_fileName = fileName;
  18. m_duration = duration;
  19. m_videoSaveHandler = videoSaveHandler;
  20. m_tools = new DateTimeTools(m_duration);
  21. }
  22. public void DoProcess(ref TUCAM_FRAME frame)
  23. {
  24. if (m_state != FrameProcesserState.PLAY)
  25. {
  26. return;
  27. }
  28. if (m_tools.Timeout())
  29. {
  30. Stop();
  31. }
  32. else
  33. {
  34. m_camera.RecAppendFrame(ref frame);
  35. }
  36. }
  37. public FrameProcesserState GetStatus()
  38. {
  39. return m_state;
  40. }
  41. public void Start()
  42. {
  43. if (m_videoSave != 0)
  44. {
  45. throw new TUCameraException("In the video recording, please hold on");
  46. }
  47. m_videoSave = 1;
  48. if (GetStatus() == FrameProcesserState.STOP)
  49. {
  50. m_camera.RecStart(m_fileName);
  51. m_state = FrameProcesserState.PLAY;
  52. }
  53. }
  54. public void Stop()
  55. {
  56. if (m_videoSave != 0)
  57. {
  58. m_videoSave = 0;
  59. m_camera.RecStop();
  60. m_state = FrameProcesserState.STOP;
  61. // 返回委托回调
  62. //m_camera.CallbackVideoSave(true, m_fileName);
  63. m_videoSaveHandler(true, m_fileName);
  64. m_camera.StopWaitForFrame();
  65. }
  66. }
  67. public void Pause()
  68. {
  69. m_state = FrameProcesserState.PAUSE;
  70. }
  71. public void Resume()
  72. {
  73. m_state = FrameProcesserState.PLAY;
  74. }
  75. }
  76. }