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 "modules/audio_processing/include/config.h" 15 #include "api/video/video_rotation.h" 16 #include "media/base/videosinkinterface.h" 17 #include "modules/include/module.h" 18 #include "modules/video_capture/video_capture_defines.h" 19 #include <set> 20 21 #if defined(ANDROID) 22 #include <jni.h> 23 #endif 24 25 namespace webrtc { 26 27 // Mozilla addition 28 enum class CaptureDeviceType { 29 Camera, 30 Screen, 31 Window, 32 Browser 33 }; 34 // Mozilla addition 35 36 struct CaptureDeviceInfo { 37 CaptureDeviceType type; 38 CaptureDeviceInfoCaptureDeviceInfo39 CaptureDeviceInfo() : type(CaptureDeviceType::Camera) {} CaptureDeviceInfoCaptureDeviceInfo40 CaptureDeviceInfo(CaptureDeviceType t) : type(t) {} 41 42 static const ConfigOptionID identifier = ConfigOptionID::kCaptureDeviceInfo; TypeNameCaptureDeviceInfo43 const char * TypeName() const 44 { 45 switch(type) { 46 case CaptureDeviceType::Camera: { 47 return "Camera"; 48 } 49 case CaptureDeviceType::Screen: { 50 return "Screen"; 51 } 52 case CaptureDeviceType::Window: { 53 return "Window"; 54 } 55 case CaptureDeviceType::Browser: { 56 return "Browser"; 57 } 58 } 59 assert(false); 60 return "UNKOWN-CaptureDeviceType!"; 61 } 62 }; 63 64 class VideoInputFeedBack 65 { 66 public: 67 virtual void OnDeviceChange() = 0; 68 protected: ~VideoInputFeedBack()69 virtual ~VideoInputFeedBack(){} 70 }; 71 72 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 73 int32_t SetCaptureAndroidVM(JavaVM* javaVM); 74 #endif 75 76 class VideoCaptureModule: public rtc::RefCountInterface { 77 public: 78 // Interface for receiving information about available camera devices. 79 class DeviceInfo { 80 public: 81 virtual uint32_t NumberOfDevices() = 0; 82 virtual int32_t Refresh() = 0; DeviceChange()83 virtual void DeviceChange() { 84 for (auto inputCallBack : _inputCallBacks) { 85 inputCallBack->OnDeviceChange(); 86 } 87 } RegisterVideoInputFeedBack(VideoInputFeedBack * callBack)88 virtual void RegisterVideoInputFeedBack(VideoInputFeedBack* callBack) { 89 _inputCallBacks.insert(callBack); 90 } 91 DeRegisterVideoInputFeedBack(VideoInputFeedBack * callBack)92 virtual void DeRegisterVideoInputFeedBack(VideoInputFeedBack* callBack) { 93 auto it = _inputCallBacks.find(callBack); 94 if (it != _inputCallBacks.end()) { 95 _inputCallBacks.erase(it); 96 } 97 } 98 99 // Returns the available capture devices. 100 // deviceNumber - Index of capture device. 101 // deviceNameUTF8 - Friendly name of the capture device. 102 // deviceUniqueIdUTF8 - Unique name of the capture device if it exist. 103 // Otherwise same as deviceNameUTF8. 104 // productUniqueIdUTF8 - Unique product id if it exist. 105 // Null terminated otherwise. 106 virtual int32_t GetDeviceName( 107 uint32_t deviceNumber, 108 char* deviceNameUTF8, 109 uint32_t deviceNameSize, 110 char* deviceUniqueIdUTF8, 111 uint32_t deviceUniqueIdUTF8Size, 112 char* productUniqueIdUTF8 = 0, 113 uint32_t productUniqueIdUTF8Size = 0, 114 pid_t* pid = 0) = 0; 115 116 117 // Returns the number of capabilities this device. 118 virtual int32_t NumberOfCapabilities( 119 const char* deviceUniqueIdUTF8) = 0; 120 121 // Gets the capabilities of the named device. 122 virtual int32_t GetCapability( 123 const char* deviceUniqueIdUTF8, 124 const uint32_t deviceCapabilityNumber, 125 VideoCaptureCapability& capability) = 0; 126 127 // Gets clockwise angle the captured frames should be rotated in order 128 // to be displayed correctly on a normally rotated display. 129 virtual int32_t GetOrientation(const char* deviceUniqueIdUTF8, 130 VideoRotation& orientation) = 0; 131 132 // Gets the capability that best matches the requested width, height and 133 // frame rate. 134 // Returns the deviceCapabilityNumber on success. 135 virtual int32_t GetBestMatchedCapability( 136 const char* deviceUniqueIdUTF8, 137 const VideoCaptureCapability& requested, 138 VideoCaptureCapability& resulting) = 0; 139 140 // Display OS /capture device specific settings dialog 141 virtual int32_t DisplayCaptureSettingsDialogBox( 142 const char* deviceUniqueIdUTF8, 143 const char* dialogTitleUTF8, 144 void* parentWindow, 145 uint32_t positionX, 146 uint32_t positionY) = 0; 147 ~DeviceInfo()148 virtual ~DeviceInfo() {} 149 private: 150 std::set<VideoInputFeedBack*> _inputCallBacks; 151 }; 152 153 // Register capture data callback 154 virtual void RegisterCaptureDataCallback( 155 rtc::VideoSinkInterface<VideoFrame> *dataCallback) = 0; 156 157 // Remove capture data callback 158 virtual void DeRegisterCaptureDataCallback( 159 rtc::VideoSinkInterface<VideoFrame> *dataCallback) = 0; 160 161 // Start capture device 162 virtual int32_t StartCapture( 163 const VideoCaptureCapability& capability) = 0; 164 165 virtual int32_t StopCaptureIfAllClientsClose() = 0; 166 FocusOnSelectedSource()167 virtual bool FocusOnSelectedSource() { return false; }; 168 169 virtual int32_t StopCapture() = 0; 170 171 // Returns the name of the device used by this module. 172 virtual const char* CurrentDeviceName() const = 0; 173 174 // Returns true if the capture device is running 175 virtual bool CaptureStarted() = 0; 176 177 // Gets the current configuration. 178 virtual int32_t CaptureSettings(VideoCaptureCapability& settings) = 0; 179 180 // Set the rotation of the captured frames. 181 // If the rotation is set to the same as returned by 182 // DeviceInfo::GetOrientation the captured frames are 183 // displayed correctly if rendered. 184 virtual int32_t SetCaptureRotation(VideoRotation rotation) = 0; 185 186 // Tells the capture module whether to apply the pending rotation. By default, 187 // the rotation is applied and the generated frame is up right. When set to 188 // false, generated frames will carry the rotation information from 189 // SetCaptureRotation. Return value indicates whether this operation succeeds. 190 virtual bool SetApplyRotation(bool enable) = 0; 191 192 // Return whether the rotation is applied or left pending. 193 virtual bool GetApplyRotation() = 0; 194 195 protected: ~VideoCaptureModule()196 virtual ~VideoCaptureModule() {}; 197 }; 198 199 } // namespace webrtc 200 #endif // MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_H_ 201