video_capture.h (6281B)
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_VIDEO_CAPTURE_H_ 12 #define MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_H_ 13 14 #include <cstdint> 15 16 #include "api/ref_count.h" 17 #include "api/video/video_frame.h" 18 #include "api/video/video_rotation.h" 19 #include "api/video/video_sink_interface.h" 20 #include "modules/video_capture/raw_video_sink_interface.h" 21 #include "modules/video_capture/video_capture_defines.h" 22 #include "rtc_base/synchronization/mutex.h" 23 #include "rtc_base/thread_annotations.h" 24 #include <set> 25 26 #if defined(ANDROID) 27 #include <jni.h> 28 #endif 29 30 namespace webrtc { 31 32 class VideoInputFeedBack 33 { 34 public: 35 virtual void OnDeviceChange() = 0; 36 protected: 37 virtual ~VideoInputFeedBack(){} 38 }; 39 40 class VideoCaptureModule : public RefCountInterface { 41 public: 42 // Interface for receiving information about available camera devices. 43 class DeviceInfo { 44 public: 45 virtual uint32_t NumberOfDevices() = 0; 46 virtual int32_t Refresh() = 0; 47 virtual void DeviceChange() { 48 MutexLock lock(&_inputCallbacksMutex); 49 for (auto inputCallBack : _inputCallBacks) { 50 inputCallBack->OnDeviceChange(); 51 } 52 } 53 virtual void RegisterVideoInputFeedBack(VideoInputFeedBack* callBack) { 54 MutexLock lock(&_inputCallbacksMutex); 55 _inputCallBacks.insert(callBack); 56 } 57 58 virtual void DeRegisterVideoInputFeedBack(VideoInputFeedBack* callBack) { 59 MutexLock lock(&_inputCallbacksMutex); 60 auto it = _inputCallBacks.find(callBack); 61 if (it != _inputCallBacks.end()) { 62 _inputCallBacks.erase(it); 63 } 64 } 65 66 // Returns the available capture devices. 67 // deviceNumber - Index of capture device. 68 // deviceNameUTF8 - Friendly name of the capture device. 69 // deviceUniqueIdUTF8 - Unique name of the capture device if it exist. 70 // Otherwise same as deviceNameUTF8. 71 // productUniqueIdUTF8 - Unique product id if it exist. 72 // Null terminated otherwise. 73 virtual int32_t GetDeviceName(uint32_t deviceNumber, 74 char* deviceNameUTF8, 75 uint32_t deviceNameLength, 76 char* deviceUniqueIdUTF8, 77 uint32_t deviceUniqueIdUTF8Length, 78 char* productUniqueIdUTF8 = 0, 79 uint32_t productUniqueIdUTF8Length = 0, 80 pid_t* pid = 0, 81 bool* deviceIsPlaceholder = 0) = 0; 82 83 // Returns the number of capabilities this device. 84 virtual int32_t NumberOfCapabilities(const char* deviceUniqueIdUTF8) = 0; 85 86 // Gets the capabilities of the named device. 87 virtual int32_t GetCapability(const char* deviceUniqueIdUTF8, 88 uint32_t deviceCapabilityNumber, 89 VideoCaptureCapability& capability) = 0; 90 91 // Gets clockwise angle the captured frames should be rotated in order 92 // to be displayed correctly on a normally rotated display. 93 virtual int32_t GetOrientation(const char* deviceUniqueIdUTF8, 94 VideoRotation& orientation) = 0; 95 96 // Gets the capability that best matches the requested width, height and 97 // frame rate. 98 // Returns the deviceCapabilityNumber on success. 99 virtual int32_t GetBestMatchedCapability( 100 const char* deviceUniqueIdUTF8, 101 const VideoCaptureCapability& requested, 102 VideoCaptureCapability& resulting) = 0; 103 104 // Display OS /capture device specific settings dialog 105 virtual int32_t DisplayCaptureSettingsDialogBox( 106 const char* deviceUniqueIdUTF8, 107 const char* dialogTitleUTF8, 108 void* parentWindow, 109 uint32_t positionX, 110 uint32_t positionY) = 0; 111 112 virtual ~DeviceInfo() {} 113 private: 114 Mutex _inputCallbacksMutex; 115 std::set<VideoInputFeedBack*> _inputCallBacks RTC_GUARDED_BY(_inputCallbacksMutex); 116 }; 117 118 // Register capture data callback 119 virtual void RegisterCaptureDataCallback( 120 VideoSinkInterface<VideoFrame>* dataCallback) = 0; 121 virtual void RegisterCaptureDataCallback( 122 RawVideoSinkInterface* dataCallback) = 0; 123 124 // Remove capture data callback 125 virtual void DeRegisterCaptureDataCallback( 126 webrtc::VideoSinkInterface<VideoFrame> *dataCallback) = 0; 127 128 // Start capture device 129 virtual int32_t StartCapture(const VideoCaptureCapability& capability) = 0; 130 131 virtual int32_t StopCaptureIfAllClientsClose() = 0; 132 133 virtual bool FocusOnSelectedSource() { return false; } 134 135 virtual int32_t StopCapture() = 0; 136 137 // Returns the name of the device used by this module. 138 virtual const char* CurrentDeviceName() const = 0; 139 140 // Returns true if the capture device is running 141 virtual bool CaptureStarted() = 0; 142 143 // Gets the current configuration. 144 virtual int32_t CaptureSettings(VideoCaptureCapability& settings) = 0; 145 146 // Set the rotation of the captured frames. 147 // If the rotation is set to the same as returned by 148 // DeviceInfo::GetOrientation the captured frames are 149 // displayed correctly if rendered. 150 virtual int32_t SetCaptureRotation(VideoRotation rotation) = 0; 151 152 // Tells the capture module whether to apply the pending rotation. By default, 153 // the rotation is applied and the generated frame is up right. When set to 154 // false, generated frames will carry the rotation information from 155 // SetCaptureRotation. Return value indicates whether this operation succeeds. 156 virtual bool SetApplyRotation(bool enable) = 0; 157 158 // Return whether the rotation is applied or left pending. 159 virtual bool GetApplyRotation() = 0; 160 161 // Mozilla: TrackingId setter for use in profiler markers. 162 virtual void SetTrackingId(uint32_t aTrackingIdProcId) {} 163 164 protected: 165 ~VideoCaptureModule() override {} 166 }; 167 168 } // namespace webrtc 169 #endif // MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_H_