You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.4 KiB

8 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __VIDEO_INPUT_HEADERS__
  2. #define __VIDEO_INPUT_HEADERS__
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <sys/mman.h>
  8. #include <sys/stat.h>
  9. #include <sys/time.h>
  10. #include <sys/types.h>
  11. #include <linux/types.h>
  12. #include <opencv2/opencv.hpp>
  13. #include <pthread.h>
  14. #include <vector>
  15. #include "video_proc.h"
  16. #define _NOAUDIO_
  17. #define _VIN_DefaultWidth 640
  18. #define _VIN_DefaultHeight 480
  19. #define ARM_BR_NOW 0
  20. #define _VIN_DefaultQueueSize 15
  21. #define _VIN_DefaultFPS 15
  22. typedef std::vector< cv::Mat* > _FrameQueue;
  23. typedef enum{
  24. VI_NO_SAVE_MODE = 0,
  25. VI_IMAGE_SEQUENCE = 1,
  26. VI_MJPEG_FILE = 2,
  27. VI_MPEG1_FILE = 3,
  28. VI_MPEG2_FILE = 4,
  29. VI_MP4_FILE = 5
  30. } _VI_SAVE_MODE;
  31. typedef enum{
  32. VI_CREATED = 0,
  33. VI_INIT_OK = 1,
  34. VI_DEVICE_OK = 2,
  35. VI_SETTINGS_OK = 3,
  36. VI_MEMORY_OK = 4,
  37. VI_STREAM_OK = 5,
  38. VI_WORKING_OK = 6,
  39. VI_STOPED = 7,
  40. VI_RESTARTING = 8
  41. } _VI_THREAD_STATUS;
  42. class _VideoInput{
  43. protected:
  44. _VI_THREAD_STATUS m_bStatus;
  45. int m_nWidth;
  46. int m_nHeight;
  47. bool m_bSizeIsAutomatic;
  48. int m_nFramesPerSecond;
  49. char m_sStoragePath[1024];
  50. char m_sSaveItemName[128];
  51. _VP_Pool m_vImageProcessors;
  52. _FrameQueue m_vFrameQueue;
  53. int m_nQueueDepth;
  54. bool m_bSaveStream;
  55. bool m_bPermanentSave;
  56. _VI_SAVE_MODE m_eSaveMode;
  57. int m_nSaveCounter;
  58. cv::VideoWriter *m_pVideoWriter;
  59. long long m_llFrameCounter;
  60. pthread_mutex_t m_sInputMmutex;
  61. pthread_t m_sInputThread;
  62. virtual void m_fInputProc( void ){
  63. m_bStatus = VI_WORKING_OK;
  64. while( m_bStatus == VI_WORKING_OK ){
  65. sleep(1);
  66. };
  67. pthread_exit( NULL );
  68. };
  69. static void *m_fStarterProc( void *arg );
  70. void saveQueueFrame( void );
  71. void processingImage( cv::Mat *pFrame );
  72. public:
  73. _VideoInput();
  74. ~_VideoInput();
  75. bool pushFrame( cv::Mat *pFrame );
  76. cv::Mat *getCurrent( void );
  77. bool alarm( int forwardLength = ARM_BR_NOW, int backwardReserve = ARM_BR_NOW );
  78. bool setStorage( char *Path, _VI_SAVE_MODE mode = VI_IMAGE_SEQUENCE, bool permanent = false );
  79. bool attachImageProcessing( _VideoProcessor *Proc );
  80. bool startInput( void );
  81. bool stopInput( void );
  82. };
  83. #endif