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.

103 lines
2.2 KiB

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