xref: /aosp_15_r20/external/webrtc/modules/video_capture/device_info_impl.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_MAIN_SOURCE_DEVICE_INFO_IMPL_H_
12 #define MODULES_VIDEO_CAPTURE_MAIN_SOURCE_DEVICE_INFO_IMPL_H_
13 
14 #include <stdint.h>
15 
16 #include <vector>
17 
18 #include "api/video/video_rotation.h"
19 #include "modules/video_capture/video_capture.h"
20 #include "modules/video_capture/video_capture_defines.h"
21 #include "rtc_base/synchronization/mutex.h"
22 #include "rtc_base/thread_annotations.h"
23 
24 namespace webrtc {
25 namespace videocapturemodule {
26 class DeviceInfoImpl : public VideoCaptureModule::DeviceInfo {
27  public:
28   DeviceInfoImpl();
29   ~DeviceInfoImpl(void) override;
30   int32_t NumberOfCapabilities(const char* deviceUniqueIdUTF8) override;
31   int32_t GetCapability(const char* deviceUniqueIdUTF8,
32                         uint32_t deviceCapabilityNumber,
33                         VideoCaptureCapability& capability) override;
34 
35   int32_t GetBestMatchedCapability(const char* deviceUniqueIdUTF8,
36                                    const VideoCaptureCapability& requested,
37                                    VideoCaptureCapability& resulting) override;
38   int32_t GetOrientation(const char* deviceUniqueIdUTF8,
39                          VideoRotation& orientation) override;
40 
41  protected:
42   /* Initialize this object*/
43 
44   virtual int32_t Init() = 0;
45   /*
46    * Fills the member variable _captureCapabilities with capabilities for the
47    * given device name.
48    */
49   virtual int32_t CreateCapabilityMap(const char* deviceUniqueIdUTF8)
50       RTC_EXCLUSIVE_LOCKS_REQUIRED(_apiLock) = 0;
51 
52  protected:
53   // Data members
54   typedef std::vector<VideoCaptureCapability> VideoCaptureCapabilities;
55   VideoCaptureCapabilities _captureCapabilities RTC_GUARDED_BY(_apiLock);
56   Mutex _apiLock;
57   char* _lastUsedDeviceName RTC_GUARDED_BY(_apiLock);
58   uint32_t _lastUsedDeviceNameLength RTC_GUARDED_BY(_apiLock);
59 };
60 }  // namespace videocapturemodule
61 }  // namespace webrtc
62 #endif  // MODULES_VIDEO_CAPTURE_MAIN_SOURCE_DEVICE_INFO_IMPL_H_
63