xref: /aosp_15_r20/external/webrtc/modules/video_capture/linux/video_capture_v4l2.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_V4L2_H_
12 #define MODULES_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_V4L2_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include <memory>
18 
19 #include "modules/video_capture/video_capture_defines.h"
20 #include "modules/video_capture/video_capture_impl.h"
21 #include "rtc_base/platform_thread.h"
22 #include "rtc_base/synchronization/mutex.h"
23 
24 namespace webrtc {
25 namespace videocapturemodule {
26 class VideoCaptureModuleV4L2 : public VideoCaptureImpl {
27  public:
28   VideoCaptureModuleV4L2();
29   ~VideoCaptureModuleV4L2() override;
30   int32_t Init(const char* deviceUniqueId);
31   int32_t StartCapture(const VideoCaptureCapability& capability) override;
32   int32_t StopCapture() override;
33   bool CaptureStarted() override;
34   int32_t CaptureSettings(VideoCaptureCapability& settings) override;
35 
36  private:
37   enum { kNoOfV4L2Bufffers = 4 };
38 
39   static void CaptureThread(void*);
40   bool CaptureProcess();
41   bool AllocateVideoBuffers();
42   bool DeAllocateVideoBuffers();
43 
44   rtc::PlatformThread _captureThread;
45   Mutex capture_lock_;
46   bool quit_ RTC_GUARDED_BY(capture_lock_);
47   int32_t _deviceId;
48   int32_t _deviceFd;
49 
50   int32_t _buffersAllocatedByDevice;
51   int32_t _currentWidth;
52   int32_t _currentHeight;
53   int32_t _currentFrameRate;
54   bool _captureStarted;
55   VideoType _captureVideoType;
56   struct Buffer {
57     void* start;
58     size_t length;
59   };
60   Buffer* _pool;
61 };
62 }  // namespace videocapturemodule
63 }  // namespace webrtc
64 
65 #endif  // MODULES_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_V4L2_H_
66