device_info_v4l2.h (2731B)
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_DEVICE_INFO_V4L2_H_ 12 #define MODULES_VIDEO_CAPTURE_LINUX_DEVICE_INFO_V4L2_H_ 13 14 #include <cstdint> 15 16 #include "modules/video_capture/device_info_impl.h" 17 #include "rtc_base/thread_annotations.h" 18 19 #include "rtc_base/platform_thread.h" 20 #ifdef WEBRTC_LINUX 21 #include <sys/inotify.h> 22 #endif 23 24 struct v4l2_capability; 25 26 namespace webrtc { 27 namespace videocapturemodule { 28 class DeviceInfoV4l2 : public DeviceInfoImpl { 29 public: 30 DeviceInfoV4l2(); 31 ~DeviceInfoV4l2() override; 32 uint32_t NumberOfDevices() override; 33 int32_t GetDeviceName(uint32_t deviceNumber, 34 char* deviceNameUTF8, 35 uint32_t deviceNameLength, 36 char* deviceUniqueIdUTF8, 37 uint32_t deviceUniqueIdUTF8Length, 38 char* productUniqueIdUTF8 = 0, 39 uint32_t productUniqueIdUTF8Length = 0, 40 pid_t* pid = 0, 41 bool* deviceIsPlaceholder = 0) override; 42 /* 43 * Fills the membervariable _captureCapabilities with capabilites for the 44 * given device name. 45 */ 46 int32_t CreateCapabilityMap(const char* deviceUniqueIdUTF8) override 47 RTC_EXCLUSIVE_LOCKS_REQUIRED(_apiLock); 48 int32_t DisplayCaptureSettingsDialogBox(const char* /*deviceUniqueIdUTF8*/, 49 const char* /*dialogTitleUTF8*/, 50 void* /*parentWindow*/, 51 uint32_t /*positionX*/, 52 uint32_t /*positionY*/) override; 53 int32_t FillCapabilities(int fd) RTC_EXCLUSIVE_LOCKS_REQUIRED(_apiLock); 54 int32_t Init() override; 55 56 private: 57 bool IsDeviceNameMatches(const char* name, const char* deviceUniqueIdUTF8); 58 bool IsVideoCaptureDevice(struct v4l2_capability* cap); 59 60 #ifdef WEBRTC_LINUX 61 void HandleEvent(inotify_event* event, int fd); 62 int EventCheck(int fd); 63 int HandleEvents(int fd); 64 int ProcessInotifyEvents(); 65 PlatformThread _inotifyEventThread; 66 void InotifyProcess(); 67 int _fd_v4l, _fd_dev, _wd_v4l, _wd_dev; /* accessed on InotifyEventThread thread */ 68 std::atomic<bool> _isShutdown; 69 #endif 70 }; 71 } // namespace videocapturemodule 72 } // namespace webrtc 73 #endif // MODULES_VIDEO_CAPTURE_LINUX_DEVICE_INFO_V4L2_H_