blob: ac9409e23a5d23cf446bf5d1f06df670a6f05756 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mallinath@webrtc.org0d757b82012-02-21 16:47:55 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CAPTURE_MAIN_SOURCE_LINUX_VIDEO_CAPTURE_LINUX_H_
12#define MODULES_VIDEO_CAPTURE_MAIN_SOURCE_LINUX_VIDEO_CAPTURE_LINUX_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
kwiberge065fcf2016-03-02 01:01:11 -080017#include <memory>
18
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "modules/video_capture/video_capture_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/video_capture/video_capture_impl.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/platform_thread.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
Yves Gerey665174f2018-06-19 15:03:05 +020024namespace webrtc {
25namespace videocapturemodule {
26class VideoCaptureModuleV4L2 : public VideoCaptureImpl {
27 public:
28 VideoCaptureModuleV4L2();
Mirko Bonadei5aec1f62018-08-29 13:27:15 +020029 ~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;
niklase@google.com470e71d2011-07-07 08:21:25 +000035
Yves Gerey665174f2018-06-19 15:03:05 +020036 private:
37 enum { kNoOfV4L2Bufffers = 4 };
niklase@google.com470e71d2011-07-07 08:21:25 +000038
Niels Möller4731f002019-05-03 09:34:24 +020039 static void CaptureThread(void*);
Yves Gerey665174f2018-06-19 15:03:05 +020040 bool CaptureProcess();
41 bool AllocateVideoBuffers();
42 bool DeAllocateVideoBuffers();
niklase@google.com470e71d2011-07-07 08:21:25 +000043
Yves Gerey665174f2018-06-19 15:03:05 +020044 // TODO(pbos): Stop using unique_ptr and resetting the thread.
45 std::unique_ptr<rtc::PlatformThread> _captureThread;
46 rtc::CriticalSection _captureCritSect;
Niels Möller4731f002019-05-03 09:34:24 +020047 bool quit_ RTC_GUARDED_BY(_captureCritSect);
Yves Gerey665174f2018-06-19 15:03:05 +020048 int32_t _deviceId;
49 int32_t _deviceFd;
niklase@google.com470e71d2011-07-07 08:21:25 +000050
Yves Gerey665174f2018-06-19 15:03:05 +020051 int32_t _buffersAllocatedByDevice;
52 int32_t _currentWidth;
53 int32_t _currentHeight;
54 int32_t _currentFrameRate;
55 bool _captureStarted;
56 VideoType _captureVideoType;
57 struct Buffer {
58 void* start;
59 size_t length;
60 };
61 Buffer* _pool;
niklase@google.com470e71d2011-07-07 08:21:25 +000062};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000063} // namespace videocapturemodule
64} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000065
Yves Gerey665174f2018-06-19 15:03:05 +020066#endif // MODULES_VIDEO_CAPTURE_MAIN_SOURCE_LINUX_VIDEO_CAPTURE_LINUX_H_