jetson_v4l2_capturer.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef SORA_HWENC_JETSON_JETSON_V4L2_CAPTURER_H_
  2. #define SORA_HWENC_JETSON_JETSON_V4L2_CAPTURER_H_
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #include <memory>
  6. // Linux
  7. #include <linux/videodev2.h>
  8. // WebRTC
  9. #include <modules/video_capture/video_capture_defines.h>
  10. #include <modules/video_capture/video_capture_impl.h>
  11. #include <rtc_base/platform_thread.h>
  12. #include <rtc_base/synchronization/mutex.h>
  13. #include "jetson_jpeg_decoder_pool.h"
  14. #include "sora/scalable_track_source.h"
  15. #include "sora/v4l2/v4l2_video_capturer.h"
  16. namespace sora {
  17. class JetsonV4L2Capturer : public ScalableVideoTrackSource {
  18. public:
  19. static rtc::scoped_refptr<JetsonV4L2Capturer> Create(
  20. const V4L2VideoCapturerConfig& config);
  21. JetsonV4L2Capturer(const V4L2VideoCapturerConfig& config);
  22. ~JetsonV4L2Capturer();
  23. private:
  24. static void LogDeviceList(
  25. webrtc::VideoCaptureModule::DeviceInfo* device_info);
  26. int32_t Init(const char* deviceUniqueId,
  27. const std::string& specifiedVideoDevice);
  28. int32_t StartCapture(const V4L2VideoCapturerConfig& config);
  29. int32_t StopCapture();
  30. bool AllocateVideoBuffers();
  31. bool DeAllocateVideoBuffers();
  32. void OnCaptured(v4l2_buffer* buf);
  33. int32_t _deviceFd;
  34. int32_t _currentWidth;
  35. int32_t _currentHeight;
  36. int32_t _currentPixelFormat;
  37. int32_t _currentFrameRate;
  38. webrtc::VideoType _captureVideoType;
  39. struct Buffer {
  40. void* start;
  41. size_t length;
  42. int fd;
  43. };
  44. Buffer* _pool;
  45. private:
  46. static rtc::scoped_refptr<JetsonV4L2Capturer> Create(
  47. webrtc::VideoCaptureModule::DeviceInfo* device_info,
  48. const V4L2VideoCapturerConfig& config,
  49. size_t capture_device_index);
  50. bool FindDevice(const char* deviceUniqueIdUTF8, const std::string& device);
  51. enum { kNoOfV4L2Bufffers = 4 };
  52. static void CaptureThread(void*);
  53. bool CaptureProcess();
  54. rtc::PlatformThread _captureThread;
  55. webrtc::Mutex capture_lock_;
  56. bool quit_ RTC_GUARDED_BY(capture_lock_);
  57. std::string _videoDevice;
  58. int32_t _buffersAllocatedByDevice;
  59. bool _useNative;
  60. bool _captureStarted;
  61. std::shared_ptr<JetsonJpegDecoderPool> jpeg_decoder_pool_;
  62. };
  63. } // namespace sora
  64. #endif