videocapture_linux.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #include "ivideocaptureinterface.h"
  3. #include "videoutil.h"
  4. #include "common_video/videocommon.h"
  5. #include "videocapturedefines.h"
  6. #include <pthread.h>
  7. #include "libyuv.h"
  8. #include "libyuv/convert_argb.h"
  9. #include "libyuv/rotate.h"
  10. static const int mode_width[VIDEOCAP_MAX_MODE] = {
  11. VIDEOCAP_SQCIF_WIDTH,VIDEOCAP_QQVGA_WIDTH,
  12. VIDEOCAP_QCIF_WIDTH,VIDEOCAP_QVGA_WIDTH,
  13. VIDEOCAP_CIF_WIDTH,VIDEOCAP_VGA_WIDTH,
  14. VIDEOCAP_4CIF_WIDTH,VIDEOCAP_SVGA_WIDTH,
  15. VIDEOCAP_NHD_WIDTH,VIDEOCAP_SXGA_WIDTH,
  16. VIDEOCAP_720P_WIDTH,VIDEOCAP_1080P_WIDTH,
  17. };
  18. static const int mode_height[VIDEOCAP_MAX_MODE] = {
  19. VIDEOCAP_SQCIF_HEIGHT,VIDEOCAP_QQVGA_HEIGHT,
  20. VIDEOCAP_QCIF_HEIGHT,VIDEOCAP_QVGA_HEIGHT,
  21. VIDEOCAP_CIF_HEIGHT,VIDEOCAP_VGA_HEIGHT,
  22. VIDEOCAP_4CIF_HEIGHT,VIDEOCAP_SVGA_HEIGHT,
  23. VIDEOCAP_NHD_HEIGHT,VIDEOCAP_SXGA_HEIGHT,
  24. VIDEOCAP_720P_HEIGHT,VIDEOCAP_1080P_HEIGHT,
  25. };
  26. typedef struct videocap_s
  27. {
  28. videocap_param_t param;
  29. int running;
  30. int cap_index;
  31. video_frame cap_frame;
  32. video_frame res_frame;
  33. struct SwsContext* sws_context; /* for image scaling and format converting */
  34. } videocap_t;
  35. struct Buffer
  36. {
  37. void* start;
  38. size_t length;
  39. };
  40. class VideoCaptureImpl : public IVideoCapture
  41. {
  42. public:
  43. VideoCaptureImpl(videocap_callback_t* pCallback);
  44. ~VideoCaptureImpl();
  45. virtual int VideoCaptureSetParam(videocap_param_t* param);
  46. virtual int StartVideoCapture();
  47. virtual int StopVideoCapture();
  48. virtual void VideoCaptureDestroy();
  49. int GetCamBrightness(int* ibright, bool bRawRange);
  50. int SetCamBrightness(int ibright, bool bRawRange);
  51. int SetCamAutoBrightness();
  52. bool GetCamRawBrightnessRange(int* imin, int* imax);
  53. bool GetCamBrightnessInfo();
  54. bool VideoCaptureStarted();
  55. int GetCaptureVideoFd();
  56. bool AllocateVideoBuffers();
  57. bool DeAllocateVideoBuffers();
  58. bool AlignedMallocVideoBuffer();
  59. bool FreeAlignedMallocVideoBuffer();
  60. bool AllocateVideoCapturebuffer();
  61. VideoType GetCaptureVideoType();
  62. int GetCapture_Width();
  63. int GetCapture_Height();
  64. bool GetStopCaptureFlag();
  65. int32_t IncomingFrame(uint8_t* videoFrame, size_t videoFrameLength, const VideoCaptureCapability& frameInfo, int64_t captureTime = 0);
  66. Buffer* GetCaptureBuffer();
  67. void CapLog(const char* fmt, ...);
  68. void CapLogEvent(int itype, const char* strmessage);
  69. private:
  70. int TransToRealBrightnessValue(int ibright);
  71. int TransFromRealBrightnessValue(int ibright);
  72. libyuv::RotationMode RotateTrans(int irotate);
  73. private:
  74. enum { kNoOfV4L2Bufffers = 4 };
  75. videocap_callback_t m_callback;
  76. videocap_t* m_capture;
  77. bool m_bCaptureStarted;
  78. bool m_bStopCapture;
  79. pthread_t m_CaptureThreadId;
  80. int m_deviceId;
  81. int m_deviceFd;
  82. int m_frame_fmt;
  83. int m_in_cap_width;
  84. int m_in_cap_height;
  85. int m_real_cap_width;
  86. int m_real_cap_height;
  87. int m_out_cap_width;
  88. int m_out_cap_height;
  89. libyuv::RotationMode m_rotate;
  90. VideoType m_captureVideoType;
  91. int m_currentFrameRate;
  92. uint8_t* m_i420;
  93. uint8_t* m_opti420;
  94. uint8_t* m_rgb24;
  95. int m_iminbrightness;
  96. int m_imaxbrightness;
  97. int m_idefaultbrightness;
  98. int m_ilogcount;
  99. int32_t m_buffersAllocatedByDevice;
  100. Buffer* m_pool;
  101. };