12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using TUCAMAPI;
- namespace TUCamera
- {
- public class TUCameraVideoSave : TUCameraIFrameProcess
- {
- public event VideoSaveHandler m_videoSaveHandler;
- private TUCamera m_camera;
- private UInt64 m_duration = 0; // 视频拍摄持续时间
- private DateTimeTools m_tools = null;
- private string m_fileName;
- private FrameProcesserState m_state = FrameProcesserState.STOP;
- private static int m_videoSave = 0;
- public TUCameraVideoSave(TUCamera camera, VideoSaveHandler videoSaveHandler, string fileName, UInt64 duration)
- {
- m_camera = camera;
- m_fileName = fileName;
- m_duration = duration;
- m_videoSaveHandler = videoSaveHandler;
- m_tools = new DateTimeTools(m_duration);
- }
- public void DoProcess(ref TUCAM_FRAME frame)
- {
- if (m_state != FrameProcesserState.PLAY)
- {
- return;
- }
- if (m_tools.Timeout())
- {
- Stop();
- }
- else
- {
- m_camera.RecAppendFrame(ref frame);
- }
- }
- public FrameProcesserState GetStatus()
- {
- return m_state;
- }
- public void Start()
- {
- if (m_videoSave != 0)
- {
- throw new TUCameraException("In the video recording, please hold on");
- }
- m_videoSave = 1;
- if (GetStatus() == FrameProcesserState.STOP)
- {
- m_camera.RecStart(m_fileName);
- m_state = FrameProcesserState.PLAY;
- }
- }
- public void Stop()
- {
- if (m_videoSave != 0)
- {
- m_videoSave = 0;
- m_camera.RecStop();
- m_state = FrameProcesserState.STOP;
- // 返回委托回调
- //m_camera.CallbackVideoSave(true, m_fileName);
- m_videoSaveHandler(true, m_fileName);
- m_camera.StopWaitForFrame();
- }
- }
- public void Pause()
- {
- m_state = FrameProcesserState.PAUSE;
- }
- public void Resume()
- {
- m_state = FrameProcesserState.PLAY;
- }
- }
- }
|