diff --git a/src/modules/video_capture/main/interface/video_capture.h b/src/modules/video_capture/main/interface/video_capture.h index 76a6c1626..dfe143818 100644 --- a/src/modules/video_capture/main/interface/video_capture.h +++ b/src/modules/video_capture/main/interface/video_capture.h @@ -11,257 +11,149 @@ #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_INTERFACE_VIDEO_CAPTURE_H_ #define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_INTERFACE_VIDEO_CAPTURE_H_ -/* - * video_capture.h - */ - #include "module.h" #include "video_capture_defines.h" namespace webrtc { -// Class definitions -class VideoCaptureModule: public Module -{ -public: - /* - * Create a video capture module object - * - * id - unique identifier of this video capture module object - * deviceUniqueIdUTF8 - name of the device. Available names can be found by using GetDeviceName - */ - static VideoCaptureModule* Create(const WebRtc_Word32 id, - const WebRtc_UWord8* deviceUniqueIdUTF8); - /* - * Create a video capture module object used for external capture. - * - * id - unique identifier of this video capture module object - * externalCapture - [out] interface to call when a new frame is captured. - */ - static VideoCaptureModule* Create(const WebRtc_Word32 id, - VideoCaptureExternal*& externalCapture); +class VideoCaptureModule: public RefCountedModule { + public: + // Interface for receiving information about available camera devices. + class DeviceInfo { + public: + virtual WebRtc_UWord32 NumberOfDevices() = 0; - /* - * destroy a video capture module object - * - * module - object to destroy - */ - static void Destroy(VideoCaptureModule* module); + // Returns the available capture devices. + // deviceNumber - Index of capture device. + // deviceNameUTF8 - Friendly name of the capture device. + // deviceUniqueIdUTF8 - Unique name of the capture device if it exist. + // Otherwise same as deviceNameUTF8. + // productUniqueIdUTF8 - Unique product id if it exist. + // Null terminated otherwise. + virtual WebRtc_Word32 GetDeviceName( + WebRtc_UWord32 deviceNumber, + WebRtc_UWord8* deviceNameUTF8, + WebRtc_UWord32 deviceNameLength, + WebRtc_UWord8* deviceUniqueIdUTF8, + WebRtc_UWord32 deviceUniqueIdUTF8Length, + WebRtc_UWord8* productUniqueIdUTF8 = 0, + WebRtc_UWord32 productUniqueIdUTF8Length = 0) = 0; - /* Android specific function - * Set global Android VM*/ - static WebRtc_Word32 SetAndroidObjects(void* javaVM, void* javaContext); - /* - * Returns version of the module and its components - * - * version - buffer to which the version will be written - * remainingBufferInBytes - remaining number of WebRtc_Word8 in the version buffer - * position - position of the next empty WebRtc_Word8 in the version buffer - */ - static WebRtc_Word32 GetVersion(WebRtc_Word8* version, - WebRtc_UWord32& remainingBufferInBytes, - WebRtc_UWord32& position); + // Returns the number of capabilities this device. + virtual WebRtc_Word32 NumberOfCapabilities( + const WebRtc_UWord8* deviceUniqueIdUTF8) = 0; - /* - * Change the unique identifier of this object - * - * id - new unique identifier of this video capture module object - */ - virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id) = 0; + // Gets the capabilities of the named device. + virtual WebRtc_Word32 GetCapability( + const WebRtc_UWord8* deviceUniqueIdUTF8, + const WebRtc_UWord32 deviceCapabilityNumber, + VideoCaptureCapability& capability) = 0; - /************************************************************************** - * - * Device Information - * - **************************************************************************/ + // Gets clockwise angle the captured frames should be rotated in order + // to be displayed correctly on a normally rotated display. + virtual WebRtc_Word32 GetOrientation( + const WebRtc_UWord8* deviceUniqueIdUTF8, + VideoCaptureRotation& orientation) = 0; - class DeviceInfo - { - public: + // Gets the capability that best matches the requested width, height and + // frame rate. + // Returns the deviceCapabilityNumber on success. + virtual WebRtc_Word32 GetBestMatchedCapability( + const WebRtc_UWord8*deviceUniqueIdUTF8, + const VideoCaptureCapability requested, + VideoCaptureCapability& resulting) = 0; - virtual WebRtc_UWord32 NumberOfDevices()=0; + // Display OS /capture device specific settings dialog + virtual WebRtc_Word32 DisplayCaptureSettingsDialogBox( + const WebRtc_UWord8* deviceUniqueIdUTF8, + const WebRtc_UWord8* dialogTitleUTF8, + void* parentWindow, + WebRtc_UWord32 positionX, + WebRtc_UWord32 positionY) = 0; - /* - * Returns the available capture devices. - * deviceNumber -[in] index of capture device - * deviceNameUTF8 - friendly name of the capture device - * deviceUniqueIdUTF8 - unique name of the capture device if it exist. Otherwise same as deviceNameUTF8 - * productUniqueIdUTF8 - unique product id if it exist. Null terminated otherwise. - */ - virtual WebRtc_Word32 GetDeviceName(WebRtc_UWord32 deviceNumber, - WebRtc_UWord8* deviceNameUTF8, - WebRtc_UWord32 deviceNameLength, - WebRtc_UWord8* deviceUniqueIdUTF8, - WebRtc_UWord32 deviceUniqueIdUTF8Length, - WebRtc_UWord8* productUniqueIdUTF8 = 0, - WebRtc_UWord32 productUniqueIdUTF8Length = 0) = 0; + protected: + virtual ~DeviceInfo() {} + }; - /* - * Returns the number of capabilities for this device - */ - virtual WebRtc_Word32 NumberOfCapabilities(const WebRtc_UWord8* deviceUniqueIdUTF8)=0; + class VideoCaptureEncodeInterface { + public: + virtual WebRtc_Word32 ConfigureEncoder(const VideoCodec& codec, + WebRtc_UWord32 maxPayloadSize) = 0; + // Inform the encoder about the new target bit rate. + // - newBitRate : New target bit rate in Kbit/s. + // - frameRate : The target frame rate. + virtual WebRtc_Word32 SetRates(WebRtc_Word32 newBitRate, + WebRtc_Word32 frameRate) = 0; + // Inform the encoder about the packet loss. + // - packetLoss : Fraction lost + // (loss rate in percent = 100 * packetLoss / 255). + virtual WebRtc_Word32 SetPacketLoss(WebRtc_UWord32 packetLoss) = 0; - /* - * Gets the capabilities of the named device - */ - virtual WebRtc_Word32 GetCapability(const WebRtc_UWord8* deviceUniqueIdUTF8, - const WebRtc_UWord32 deviceCapabilityNumber, - VideoCaptureCapability& capability) = 0; + // Encode the next frame as key frame. + virtual WebRtc_Word32 EncodeFrameType(const FrameType type) = 0; + protected: + virtual ~VideoCaptureEncodeInterface() { + } + }; - /* - * Gets clockwise angle the captured frames should be rotated in order to be displayed - * correctly on a normally rotated display. - */ - virtual WebRtc_Word32 GetOrientation(const WebRtc_UWord8* deviceUniqueIdUTF8, - VideoCaptureRotation& orientation)=0; + // Register capture data callback + virtual WebRtc_Word32 RegisterCaptureDataCallback( + VideoCaptureDataCallback& dataCallback) = 0; - /* - * Gets the capability that best matches the requested width, height and frame rate. - * Returns the deviceCapabilityNumber on success. - */ - virtual WebRtc_Word32 GetBestMatchedCapability( - const WebRtc_UWord8*deviceUniqueIdUTF8, - const VideoCaptureCapability requested, - VideoCaptureCapability& resulting) = 0; + // Remove capture data callback + virtual WebRtc_Word32 DeRegisterCaptureDataCallback() = 0; - /* - * Display OS /capture device specific settings dialog - */ - virtual WebRtc_Word32 DisplayCaptureSettingsDialogBox( - const WebRtc_UWord8* deviceUniqueIdUTF8, - const WebRtc_UWord8* dialogTitleUTF8, - void* parentWindow, WebRtc_UWord32 positionX, - WebRtc_UWord32 positionY) = 0; + // Register capture callback. + virtual WebRtc_Word32 RegisterCaptureCallback( + VideoCaptureFeedBack& callBack) = 0; - protected: - virtual ~DeviceInfo(){} - }; + // Remove capture callback. + virtual WebRtc_Word32 DeRegisterCaptureCallback() = 0; - static DeviceInfo* CreateDeviceInfo(const WebRtc_Word32 id); - static void DestroyDeviceInfo(DeviceInfo* deviceInfo); + // Start capture device + virtual WebRtc_Word32 StartCapture( + const VideoCaptureCapability& capability) = 0; - class VideoCaptureEncodeInterface - { - public: - virtual WebRtc_Word32 ConfigureEncoder(const VideoCodec& codec, - WebRtc_UWord32 maxPayloadSize)=0; - // Inform the encoder about the new target bit rate. - // - // - newBitRate : New target bit rate in Kbit/s - // - frameRate : The target frame rate - // - virtual WebRtc_Word32 SetRates(WebRtc_Word32 newBitRate, WebRtc_Word32 frameRate) = 0; - // Inform the encoder about the packet loss - // - // - packetLoss : Fraction lost - // (loss rate in percent = 100 * packetLoss / 255) - // - virtual WebRtc_Word32 SetPacketLoss(WebRtc_UWord32 packetLoss) = 0; - // Encode the next frame as key frame. - // - virtual WebRtc_Word32 EncodeFrameType(const FrameType type) =0; - protected: - virtual ~VideoCaptureEncodeInterface(){} - }; + virtual WebRtc_Word32 StopCapture() = 0; - /************************************************************************** - * - * Observers - * - ***************************************************************************/ + // Send an image when the capture device is not running. + virtual WebRtc_Word32 StartSendImage(const VideoFrame& videoFrame, + WebRtc_Word32 frameRate = 1) = 0; - /* - * Register capture data callback - */ - virtual WebRtc_Word32 RegisterCaptureDataCallback( - VideoCaptureDataCallback& dataCallback) = 0; + virtual WebRtc_Word32 StopSendImage() = 0; - /* - * Remove capture data callback - */ - virtual WebRtc_Word32 DeRegisterCaptureDataCallback() = 0; + // Returns the name of the device used by this module. + virtual const WebRtc_UWord8* CurrentDeviceName() const = 0; - /* - * Register capture callback - */ - virtual WebRtc_Word32 RegisterCaptureCallback(VideoCaptureFeedBack& callBack) = 0; + // Returns true if the capture device is running + virtual bool CaptureStarted() = 0; - /* - * Remove capture callback - */ - virtual WebRtc_Word32 DeRegisterCaptureCallback() = 0; + // Gets the current configuration. + virtual WebRtc_Word32 CaptureSettings(VideoCaptureCapability& settings) = 0; - /************************************************************************** - * - * Start/Stop - * - ***************************************************************************/ + virtual WebRtc_Word32 SetCaptureDelay(WebRtc_Word32 delayMS) = 0; - /* - * Start capture device - */ - virtual WebRtc_Word32 StartCapture(const VideoCaptureCapability& capability) = 0; + // Returns the current CaptureDelay. Only valid when the camera is running. + virtual WebRtc_Word32 CaptureDelay() = 0; - /* - * Stop capture device - */ - virtual WebRtc_Word32 StopCapture() = 0; + // Set the rotation of the captured frames. + // If the rotation is set to the same as returned by + // DeviceInfo::GetOrientation the captured frames are + // displayed correctly if rendered. + virtual WebRtc_Word32 SetCaptureRotation(VideoCaptureRotation rotation) = 0; - /* - * Send an image when the capture device is not running. - */ - virtual WebRtc_Word32 StartSendImage(const VideoFrame& videoFrame, - WebRtc_Word32 frameRate = 1)=0; + // Gets a pointer to an encode interface if the capture device supports the + // requested type and size. NULL otherwise. + virtual VideoCaptureEncodeInterface* GetEncodeInterface( + const VideoCodec& codec) = 0; - /* - * Stop send image. - */ - virtual WebRtc_Word32 StopSendImage()=0; - - /************************************************************************** - * - * Properties of the set device - * - ***************************************************************************/ - /* - * Returns the name of the device used by this module. - */ - virtual const WebRtc_UWord8* CurrentDeviceName() const =0; - - /* - * Returns true if the capture device is running - */ - virtual bool CaptureStarted() = 0; - - /* - * Gets the current configuration. - */ - virtual WebRtc_Word32 CaptureSettings(VideoCaptureCapability& settings) = 0; - - virtual WebRtc_Word32 SetCaptureDelay(WebRtc_Word32 delayMS)=0; - - /* Returns the current CaptureDelay. - Only valid when the camera is running*/ - virtual WebRtc_Word32 CaptureDelay()=0; - - /* Set the rotation of the captured frames. - If the rotation is set to the same as returned by - DeviceInfo::GetOrientation the captured frames are displayed correctly if rendered.*/ - virtual WebRtc_Word32 SetCaptureRotation(VideoCaptureRotation rotation)=0; - - /* Gets a pointer to an encode interface if the capture device supports the requested type and size. - NULL otherwise. - */ - virtual VideoCaptureEncodeInterface* GetEncodeInterface(const VideoCodec& codec)= 0; - - /************************************************************************** - * Information Callbacks - * - ***************************************************************************/ - virtual WebRtc_Word32 EnableFrameRateCallback(const bool enable) = 0; - virtual WebRtc_Word32 EnableNoPictureAlarm(const bool enable) = 0; + virtual WebRtc_Word32 EnableFrameRateCallback(const bool enable) = 0; + virtual WebRtc_Word32 EnableNoPictureAlarm(const bool enable) = 0; +protected: + virtual ~VideoCaptureModule() {}; }; -} //namespace webrtc + +} // namespace webrtc #endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_INTERFACE_VIDEO_CAPTURE_H_ diff --git a/src/modules/video_capture/main/source/Android/device_info_android.cc b/src/modules/video_capture/main/source/Android/device_info_android.cc index 016546539..6c33c29e4 100644 --- a/src/modules/video_capture/main/source/Android/device_info_android.cc +++ b/src/modules/video_capture/main/source/Android/device_info_android.cc @@ -8,14 +8,19 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "device_info_android.h" + +#include + +#include "ref_count.h" #include "trace.h" #include "video_capture_android.h" -#include "device_info_android.h" -#include namespace webrtc { -VideoCaptureModule::DeviceInfo* VideoCaptureModule::CreateDeviceInfo ( +namespace videocapturemodule +{ +VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo ( const WebRtc_Word32 id) { WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceVideoCapture, id, @@ -30,7 +35,7 @@ VideoCaptureModule::DeviceInfo* VideoCaptureModule::CreateDeviceInfo ( return deviceInfo; } -void VideoCaptureModule::DestroyDeviceInfo( +void VideoCaptureImpl::DestroyDeviceInfo( VideoCaptureModule::DeviceInfo* deviceInfo) { WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceVideoCapture, -1, @@ -41,8 +46,6 @@ void VideoCaptureModule::DestroyDeviceInfo( delete devInfo; } -namespace videocapturemodule -{ DeviceInfoAndroid::DeviceInfoAndroid(const WebRtc_Word32 id) : DeviceInfoImpl(id) { diff --git a/src/modules/video_capture/main/source/Android/video_capture_android.cc b/src/modules/video_capture/main/source/Android/video_capture_android.cc index a2ae08e0b..52ac55e1d 100644 --- a/src/modules/video_capture/main/source/Android/video_capture_android.cc +++ b/src/modules/video_capture/main/source/Android/video_capture_android.cc @@ -9,32 +9,33 @@ */ #include "video_capture_android.h" -#include -#include "critical_section_wrapper.h" +#include + +#include "critical_section_wrapper.h" +#include "ref_count.h" #include "trace.h" namespace webrtc { - -VideoCaptureModule* VideoCaptureModule::Create(const WebRtc_Word32 id, - const WebRtc_UWord8* deviceUniqueIdUTF8) +namespace videocapturemodule +{ +VideoCaptureModule* VideoCaptureImpl::Create( + const WebRtc_Word32 id, + const WebRtc_UWord8* deviceUniqueIdUTF8) { WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceVideoCapture, -1, "%s:", __FUNCTION__); - videocapturemodule::VideoCaptureAndroid* newCaptureModule = - new videocapturemodule::VideoCaptureAndroid(id); - if (!newCaptureModule || newCaptureModule->Init(id, deviceUniqueIdUTF8) - != 0) - { - Destroy(newCaptureModule); - newCaptureModule = NULL; - } - return newCaptureModule; -} + RefCountImpl* implementation = + new RefCountImpl(id); -namespace videocapturemodule -{ + if (!implementation || implementation->Init(id, deviceUniqueId) != 0) + { + delete implementation; + implementation = NULL; + } + return implementation; +} // Android logging, uncomment to print trace to logcat instead of trace file/callback //#include diff --git a/src/modules/video_capture/main/source/Linux/device_info_linux.cc b/src/modules/video_capture/main/source/Linux/device_info_linux.cc index 0439eed58..dbdd58261 100644 --- a/src/modules/video_capture/main/source/Linux/device_info_linux.cc +++ b/src/modules/video_capture/main/source/Linux/device_info_linux.cc @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "trace.h" #include "device_info_linux.h" #include @@ -22,10 +21,17 @@ //v4l includes #include + +#include "ref_count.h" +#include "trace.h" + + namespace webrtc { +namespace videocapturemodule +{ VideoCaptureModule::DeviceInfo* -VideoCaptureModule::CreateDeviceInfo(const WebRtc_Word32 id) +VideoCaptureImpl::CreateDeviceInfo(const WebRtc_Word32 id) { videocapturemodule::DeviceInfoLinux *deviceInfo = new videocapturemodule::DeviceInfoLinux(id); @@ -37,15 +43,13 @@ VideoCaptureModule::CreateDeviceInfo(const WebRtc_Word32 id) return deviceInfo; } -void VideoCaptureModule::DestroyDeviceInfo(DeviceInfo* deviceInfo) +void VideoCaptureImpl::DestroyDeviceInfo(DeviceInfo* deviceInfo) { videocapturemodule::DeviceInfoLinux* devInfo = static_cast (deviceInfo); delete devInfo; } -namespace videocapturemodule -{ DeviceInfoLinux::DeviceInfoLinux(const WebRtc_Word32 id) : DeviceInfoImpl(id) diff --git a/src/modules/video_capture/main/source/Linux/video_capture_linux.cc b/src/modules/video_capture/main/source/Linux/video_capture_linux.cc index 8bd40db8c..2bb0d555d 100644 --- a/src/modules/video_capture/main/source/Linux/video_capture_linux.cc +++ b/src/modules/video_capture/main/source/Linux/video_capture_linux.cc @@ -21,6 +21,7 @@ #include #include +#include "ref_count.h" #include "trace.h" #include "thread_wrapper.h" #include "critical_section_wrapper.h" @@ -28,23 +29,23 @@ namespace webrtc { -VideoCaptureModule* VideoCaptureModule::Create(const WebRtc_Word32 id, - const WebRtc_UWord8* deviceUniqueId) -{ - - videocapturemodule::VideoCaptureModuleV4L2* interface = - new videocapturemodule::VideoCaptureModuleV4L2(id); - if (!interface || interface->Init(deviceUniqueId) != 0) - { - Destroy(interface); - interface = NULL; - } - - return interface; -} - namespace videocapturemodule { +VideoCaptureModule* VideoCaptureImpl::Create(const WebRtc_Word32 id, + const WebRtc_UWord8* deviceUniqueId) +{ + RefCountImpl* implementation = + new RefCountImpl(id); + + if (!implementation || implementation->Init(deviceUniqueId) != 0) + { + delete implementation; + implementation = NULL; + } + + return implementation; +} + VideoCaptureModuleV4L2::VideoCaptureModuleV4L2(const WebRtc_Word32 id) : VideoCaptureImpl(id), _captureThread(NULL), _captureCritSect(CriticalSectionWrapper::CreateCriticalSection()), diff --git a/src/modules/video_capture/main/source/Mac/QTKit/video_capture_qtkit.cc b/src/modules/video_capture/main/source/Mac/QTKit/video_capture_qtkit.cc index a99dd332c..0132a43c7 100644 --- a/src/modules/video_capture/main/source/Mac/QTKit/video_capture_qtkit.cc +++ b/src/modules/video_capture/main/source/Mac/QTKit/video_capture_qtkit.cc @@ -18,24 +18,6 @@ namespace webrtc { -/* - * Returns version of the module and its components - * - * version - buffer to which the version will be written - * remainingBufferInBytes - remaining number of WebRtc_Word8 in the version - * buffer - * position - position of the next empty WebRtc_Word8 in the - * version buffer - */ - -WebRtc_Word32 VideoCaptureModule::GetVersion( - WebRtc_Word8* version, WebRtc_UWord32& remainingBufferInBytes, - WebRtc_UWord32& position) -{ - return webrtc::videocapturemodule::VideoCaptureMacQTKit::GetVersion( - version, remainingBufferInBytes, position); -} - namespace videocapturemodule { diff --git a/src/modules/video_capture/main/source/Mac/video_capture_mac.cc b/src/modules/video_capture/main/source/Mac/video_capture_mac.cc index 1309c0e9e..92e333f7e 100644 --- a/src/modules/video_capture/main/source/Mac/video_capture_mac.cc +++ b/src/modules/video_capture/main/source/Mac/video_capture_mac.cc @@ -13,13 +13,12 @@ * */ -// self header -#include "video_capture_mac.h" // super class stuff #include "../video_capture_impl.h" #include "../device_info_impl.h" #include "../video_capture_config.h" +#include "ref_count.h" #include "trace.h" @@ -41,7 +40,7 @@ namespace videocapturemodule { // static -bool VideoCaptureMac::CheckOSVersion() +bool CheckOSVersion() { // Check OSX version OSErr err = noErr; @@ -70,7 +69,7 @@ bool VideoCaptureMac::CheckOSVersion() } // static -bool VideoCaptureMac::CheckQTVersion() +bool CheckQTVersion() { // Check OSX version OSErr err = noErr; @@ -96,7 +95,6 @@ bool VideoCaptureMac::CheckQTVersion() "QuickTime version compatible: 0x%x", version); return true; } -} // videocapturemodule /************************************************************************** * @@ -114,13 +112,13 @@ bool VideoCaptureMac::CheckQTVersion() * version buffer */ -VideoCaptureModule* VideoCaptureModule::Create( +VideoCaptureModule* VideoCaptureImpl::Create( const WebRtc_Word32 id, const WebRtc_UWord8* deviceUniqueIdUTF8) { WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceVideoCapture, id, "Create %s", deviceUniqueIdUTF8); - if (webrtc::videocapturemodule::VideoCaptureMac::CheckOSVersion == false) + if (webrtc::videocapturemodule::CheckOSVersion() == false) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id, "OS version is too old. Could not create video capture " @@ -129,7 +127,7 @@ VideoCaptureModule* VideoCaptureModule::Create( } #if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - if (webrtc::videocapturemodule::VideoCaptureMac::CheckQTVersion == false) + if (webrtc::videocapturemodule::CheckQTVersion() == false) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id, "QuickTime version is too old. Could not create video " @@ -142,15 +140,16 @@ VideoCaptureModule* VideoCaptureModule::Create( "QuickTime framework to capture video", __FILE__, __LINE__); - webrtc::videocapturemodule::VideoCaptureMacQuickTime* newCaptureModule = - new webrtc::videocapturemodule::VideoCaptureMacQuickTime(id); + RefCountImpl* + newCaptureModule = + new RefCountImpl(id); + if (!newCaptureModule) { WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id, "could not Create for unique device %s, !newCaptureModule", deviceUniqueIdUTF8); - Destroy(newCaptureModule); - newCaptureModule = NULL; + return NULL; } if (newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0) @@ -159,8 +158,8 @@ VideoCaptureModule* VideoCaptureModule::Create( "could not Create for unique device %s, " "newCaptureModule->Init()!=0", deviceUniqueIdUTF8); - Destroy(newCaptureModule); - newCaptureModule = NULL; + delete newCaptureModule; + return NULL; } // Successfully created VideoCaptureMacQuicktime. Return it @@ -175,23 +174,23 @@ VideoCaptureModule* VideoCaptureModule::Create( WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, "Using QTKit framework to capture video", id); - webrtc::videocapturemodule::VideoCaptureMacQTKit* newCaptureModule = - new webrtc::videocapturemodule::VideoCaptureMacQTKit(id); + RefCountImpl* newCaptureModule = + new RefCountImpl(id); + if(!newCaptureModule) { WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id, "could not Create for unique device %s, !newCaptureModule", deviceUniqueIdUTF8); - Destroy(newCaptureModule); - newCaptureModule = NULL; + return NULL; } if(newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0) { WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id, "could not Create for unique device %s, " "newCaptureModule->Init()!=0", deviceUniqueIdUTF8); - Destroy(newCaptureModule); - newCaptureModule = NULL; + delete newCaptureModule; + return NULL; } // Successfully created VideoCaptureMacQuicktime. Return it @@ -202,121 +201,6 @@ VideoCaptureModule* VideoCaptureModule::Create( #endif } -void Destroy(VideoCaptureModule* module) -{ - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, 0, - "%s:%d Destroying GISPModuleVideoCapture", __FUNCTION__, - __LINE__); - -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - webrtc::videocapturemodule::VideoCaptureMacQuickTime* captureDevice = - static_cast (module); - delete captureDevice; - captureDevice = NULL; - -#else // QTKit version - webrtc::videocapturemodule::VideoCaptureMacQTKit* captureDevice = - static_cast (module); - delete captureDevice; - captureDevice = NULL; -#endif -} -/************************************************************************** - * - * End Create/Destroy VideoCaptureModule - * - ***************************************************************************/ - -// VideoCaptureMac class -namespace videocapturemodule -{ - -/************************************************************************** - * - * These will just delegate to the appropriate class - * - ***************************************************************************/ - -VideoCaptureMac::VideoCaptureMac(const WebRtc_Word32 id) : - VideoCaptureImpl(id), // super class constructor - _isFrameworkSupported(false), _captureClass(NULL) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - _isFrameworkSupported = false; - _captureClass = new VideoCaptureMacQuickTime(_id); - -#else // QTKit version - _isFrameworkSupported = true; - _captureClass = new VideoCaptureMacQTKit(_id); -#endif -} - -VideoCaptureMac::~VideoCaptureMac() -{ - delete _captureClass; -} - -WebRtc_Word32 VideoCaptureMac::Init(const WebRtc_Word32 id, - const WebRtc_UWord8* deviceUniqueIdUTF8) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast (_captureClass)->Init( - id, deviceUniqueIdUTF8); - -#else // QTKit version - return static_cast(_captureClass)->Init(id, deviceUniqueIdUTF8); -#endif -} - -WebRtc_Word32 VideoCaptureMac::StartCapture( - const VideoCaptureCapability& capability) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast (_captureClass)->StartCapture( - capability); - -#else // QTKit version - return static_cast - (_captureClass)->StartCapture(capability); -#endif -} - -WebRtc_Word32 VideoCaptureMac::StopCapture() -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureClass)->StopCapture(); - -#else // QTKit version - return static_cast(_captureClass)->StopCapture(); -#endif -} - -bool VideoCaptureMac::CaptureStarted() -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureClass)->CaptureStarted(); - -#else // QTKit version - return static_cast(_captureClass)->CaptureStarted(); -#endif -} - -WebRtc_Word32 VideoCaptureMac::CaptureSettings(VideoCaptureCapability& settings) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureClass)->CaptureSettings(settings); - -#else // QTKit version - return static_cast - (_captureClass)->CaptureSettings(settings); -#endif -} -} // namespace videocapturemodule - - /************************************************************************** * * Create/Destroy a DeviceInfo @@ -324,13 +208,13 @@ WebRtc_Word32 VideoCaptureMac::CaptureSettings(VideoCaptureCapability& settings) ***************************************************************************/ VideoCaptureModule::DeviceInfo* -VideoCaptureModule::CreateDeviceInfo(const WebRtc_Word32 id) +VideoCaptureImpl::CreateDeviceInfo(const WebRtc_Word32 id) { WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceVideoCapture, id, "Create %d", id); - if (webrtc::videocapturemodule::VideoCaptureMac::CheckOSVersion == false) + if (webrtc::videocapturemodule::CheckOSVersion() == false) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id, "OS version is too old. Could not create video capture " @@ -339,7 +223,7 @@ VideoCaptureModule::CreateDeviceInfo(const WebRtc_Word32 id) } #if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - if (webrtc::videocapturemodule::VideoCaptureMac::CheckQTVersion == false) + if (webrtc::videocapturemodule::CheckQTVersion() == false) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id, "QuickTime version is too old. Could not create video " @@ -385,7 +269,7 @@ VideoCaptureModule::CreateDeviceInfo(const WebRtc_Word32 id) } -void VideoCaptureModule::DestroyDeviceInfo(DeviceInfo* deviceInfo) +void VideoCaptureImpl::DestroyDeviceInfo(DeviceInfo* deviceInfo) { WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceVideoCapture, 0, "%s:%d", __FUNCTION__, __LINE__); @@ -410,165 +294,6 @@ void VideoCaptureModule::DestroyDeviceInfo(DeviceInfo* deviceInfo) * End Create/Destroy VideoCaptureModule * ***************************************************************************/ - -// VideoCaptureMacInfo class - -namespace videocapturemodule { - -/************************************************************************** - * - * These will just delegate to the appropriate class - * - ***************************************************************************/ - -VideoCaptureMacInfo::VideoCaptureMacInfo(const WebRtc_Word32 id) : - DeviceInfoImpl(id), _isFrameworkSupported(false)//, -//_captureInfoClass( NULL) // special init below -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - _isFrameworkSupported = false; - _captureInfoClass = new VideoCaptureMacQuickTimeInfo(_id); - -#else // QTKit version - _isFrameworkSupported = true; - _captureInfoClass = new VideoCaptureMacQTKitInfo(_id); -#endif - -} - -VideoCaptureMacInfo::~VideoCaptureMacInfo() -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - delete _captureInfoClass; -#else // QTKit version - delete _captureInfoClass; -#endif -} - -WebRtc_Word32 VideoCaptureMacInfo::Init() -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureInfoClass)->Init(); -#else // QTKit version - return static_cast(_captureInfoClass)->Init(); -#endif -} - -WebRtc_UWord32 VideoCaptureMacInfo::NumberOfDevices() -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureInfoClass)->NumberOfDevices(); - -#else // QTKit version - return static_cast - (_captureInfoClass)->NumberOfDevices(); -#endif -} - -WebRtc_Word32 VideoCaptureMacInfo::GetDeviceName( - WebRtc_UWord32 deviceNumber, WebRtc_UWord8* deviceNameUTF8, - WebRtc_UWord32 deviceNameLength, WebRtc_UWord8* deviceUniqueIdUTF8, - WebRtc_UWord32 deviceUniqueIdUTF8Length, WebRtc_UWord8* productUniqueIdUTF8, - WebRtc_UWord32 productUniqueIdUTF8Length) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureInfoClass)->GetDeviceName(deviceNumber, deviceNameUTF8, - deviceNameLength, deviceUniqueIdUTF8, - deviceUniqueIdUTF8Length, - productUniqueIdUTF8, - productUniqueIdUTF8Length); - -#else // QTKit version - return static_cast - (_captureInfoClass)->GetDeviceName(deviceNumber, deviceNameUTF8, - deviceNameLength, deviceUniqueIdUTF8, - deviceUniqueIdUTF8Length, - productUniqueIdUTF8, - productUniqueIdUTF8Length); -#endif -} - -WebRtc_Word32 VideoCaptureMacInfo::NumberOfCapabilities( - const WebRtc_UWord8* deviceUniqueIdUTF8) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureInfoClass)->NumberOfCapabilities(deviceUniqueIdUTF8); - -#else // QTKit version - return static_cast - (_captureInfoClass)->NumberOfCapabilities(deviceUniqueIdUTF8); -#endif -} - -WebRtc_Word32 VideoCaptureMacInfo::GetCapability( - const WebRtc_UWord8* deviceUniqueIdUTF8, - const WebRtc_UWord32 deviceCapabilityNumber, - VideoCaptureCapability& capability) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureInfoClass)->GetCapability(deviceUniqueIdUTF8, - deviceCapabilityNumber, capability); - -#else // QTKit version - return static_cast - (_captureInfoClass)->GetCapability(deviceUniqueIdUTF8, - deviceCapabilityNumber, capability); -#endif -} - -WebRtc_Word32 VideoCaptureMacInfo::GetBestMatchedCapability( - const WebRtc_UWord8*deviceUniqueIdUTF8, - const VideoCaptureCapability requested, VideoCaptureCapability& resulting) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureInfoClass)->GetBestMatchedCapability(deviceUniqueIdUTF8, - requested, resulting); - -#else // QTKit version - return static_cast - (_captureInfoClass)->GetBestMatchedCapability(deviceUniqueIdUTF8, - requested, resulting); -#endif -} - -WebRtc_Word32 VideoCaptureMacInfo::DisplayCaptureSettingsDialogBox( - const WebRtc_UWord8* deviceUniqueIdUTF8, - const WebRtc_UWord8* dialogTitleUTF8, void* parentWindow, - WebRtc_UWord32 positionX, WebRtc_UWord32 positionY) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version - return static_cast - (_captureInfoClass)->DisplayCaptureSettingsDialogBox(deviceUniqueIdUTF8, - dialogTitleUTF8, - parentWindow, - positionX, - positionY); -#else // QTKit version - return static_cast - (_captureInfoClass)->DisplayCaptureSettingsDialogBox(deviceUniqueIdUTF8, - dialogTitleUTF8, - parentWindow, - positionX, - positionY); -#endif -} - -WebRtc_Word32 VideoCaptureMacInfo::CreateCapabilityMap( - const WebRtc_UWord8* deviceUniqueIdUTF8) -{ -#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version -#else // QTKit version -#endif - // not supported. The call stack should never make it this deep. - // This call should be returned higher in the order - return -1; - -} -} // namespace webrtc } // namespace videocapturemodule +} // namespace webrtc + diff --git a/src/modules/video_capture/main/source/Mac/video_capture_mac.h b/src/modules/video_capture/main/source/Mac/video_capture_mac.h index 9fc5617ec..e69de29bb 100644 --- a/src/modules/video_capture/main/source/Mac/video_capture_mac.h +++ b/src/modules/video_capture/main/source/Mac/video_capture_mac.h @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * video_capture_mac.h - * - */ - -/************************************************************************** - * - * This class exists so that the correct capturing framework can be called - * at runtime for compatiblity reasons. - * - * * QTKit is the modern objective-c interface. Our capturing code was - * rewritten to use QTKit because QuickTime does not support 64-bit. - * Although QTKit exists in 10.4, it does not support all of the - * capture APIs needed - * * QuickTime is the older C++ interface. It supports - * - ***************************************************************************/ - -#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_VIDEO_CAPTURE_MAC_H_ -#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_VIDEO_CAPTURE_MAC_H_ - -#include "../video_capture_impl.h" -#include "../device_info_impl.h" -#include "../video_capture_config.h" - -namespace webrtc -{ -namespace videocapturemodule -{ - -class VideoCaptureMac: public VideoCaptureImpl -{ -public: - VideoCaptureMac(const WebRtc_Word32 id); - virtual ~VideoCaptureMac(); - - static VideoCaptureModule* Create(const WebRtc_Word32 id, - const WebRtc_UWord8* deviceUniqueIdUTF8); - static void Destroy(VideoCaptureModule* module); - - WebRtc_Word32 Init(const WebRtc_Word32 id, - const WebRtc_UWord8* deviceUniqueIdUTF8); - virtual WebRtc_Word32 StartCapture( - const VideoCaptureCapability& capability); - virtual WebRtc_Word32 StopCapture(); - virtual bool CaptureStarted(); - virtual WebRtc_Word32 CaptureSettings(VideoCaptureCapability& settings); - static bool CheckQTVersion(); - static bool CheckOSVersion(); - -private: - - bool _isFrameworkSupported; - VideoCaptureImpl* _captureClass; - WebRtc_Word32 _id; -}; - -class VideoCaptureMacInfo: public DeviceInfoImpl -{ -public: - // public methods - - static DeviceInfo* Create(const WebRtc_Word32 id); - static void Destroy(DeviceInfo* deviceInfo); - - VideoCaptureMacInfo(const WebRtc_Word32 id); - virtual ~VideoCaptureMacInfo(); - - WebRtc_Word32 Init(); - - virtual WebRtc_UWord32 NumberOfDevices(); - virtual WebRtc_Word32 GetDeviceName( - WebRtc_UWord32 deviceNumber, - WebRtc_UWord8* deviceNameUTF8, - WebRtc_UWord32 deviceNameLength, - WebRtc_UWord8* deviceUniqueIdUTF8, - WebRtc_UWord32 deviceUniqueIdUTF8Length, - WebRtc_UWord8* productUniqueIdUTF8 = 0, - WebRtc_UWord32 productUniqueIdUTF8Length = 0); - - virtual WebRtc_Word32 NumberOfCapabilities( - const WebRtc_UWord8* deviceUniqueIdUTF8); - - virtual WebRtc_Word32 GetCapability( - const WebRtc_UWord8* deviceUniqueIdUTF8, - const WebRtc_UWord32 deviceCapabilityNumber, - VideoCaptureCapability& capability); - - virtual WebRtc_Word32 GetBestMatchedCapability( - const WebRtc_UWord8*deviceUniqueIdUTF8, - const VideoCaptureCapability requested, - VideoCaptureCapability& resulting); - - virtual WebRtc_Word32 DisplayCaptureSettingsDialogBox( - const WebRtc_UWord8* deviceUniqueIdUTF8, - const WebRtc_UWord8* dialogTitleUTF8, - void* parentWindow, WebRtc_UWord32 positionX, - WebRtc_UWord32 positionY); - - virtual WebRtc_Word32 CreateCapabilityMap( - const WebRtc_UWord8* deviceUniqueIdUTF8); - -private: - bool _isFrameworkSupported; - DeviceInfoImpl* _captureInfoClass; - WebRtc_Word32 _id; -}; -} // namespace videocapturemodule -} // namespace webrtc - -#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_VIDEO_CAPTURE_MAC_H_ diff --git a/src/modules/video_capture/main/source/Windows/device_info_windows.cc b/src/modules/video_capture/main/source/Windows/device_info_windows.cc index ea4d70276..3fb10d4ec 100644 --- a/src/modules/video_capture/main/source/Windows/device_info_windows.cc +++ b/src/modules/video_capture/main/source/Windows/device_info_windows.cc @@ -10,17 +10,20 @@ #include "device_info_windows.h" -#include "trace.h" -#include "help_functions_windows.h" #include "../video_capture_config.h" +#include "help_functions_windows.h" #include "capture_delay_values_windows.h" +#include "ref_count.h" +#include "trace.h" #include #include namespace webrtc { -VideoCaptureModule::DeviceInfo* VideoCaptureModule::CreateDeviceInfo( +namespace videocapturemodule +{ +VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo( const WebRtc_Word32 id) { videocapturemodule::DeviceInfoWindows* dsInfo = @@ -34,16 +37,13 @@ VideoCaptureModule::DeviceInfo* VideoCaptureModule::CreateDeviceInfo( return dsInfo; } -void VideoCaptureModule::DestroyDeviceInfo(DeviceInfo* deviceInfo) +void VideoCaptureImpl::DestroyDeviceInfo(DeviceInfo* deviceInfo) { videocapturemodule::DeviceInfoWindows* impl = static_cast (deviceInfo); delete impl; } -namespace videocapturemodule -{ - DeviceInfoWindows::DeviceInfoWindows(const WebRtc_Word32 id) : DeviceInfoImpl(id), _dsDevEnum(NULL), _dsMonikerDevEnum(NULL), _CoUninitializeIsRequired(true) diff --git a/src/modules/video_capture/main/source/Windows/video_capture_factory_windows.cc b/src/modules/video_capture/main/source/Windows/video_capture_factory_windows.cc index 7e786f660..9f056f325 100644 --- a/src/modules/video_capture/main/source/Windows/video_capture_factory_windows.cc +++ b/src/modules/video_capture/main/source/Windows/video_capture_factory_windows.cc @@ -8,14 +8,17 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "ref_count.h" #include "video_capture_windows.h" #include "trace.h" namespace webrtc { -VideoCaptureModule* VideoCaptureModule::Create( - const WebRtc_Word32 id, - const WebRtc_UWord8* deviceUniqueIdUTF8) +namespace videocapturemodule +{ +VideoCaptureModule* VideoCaptureImpl::Create( + const WebRtc_Word32 id, + const WebRtc_UWord8* deviceUniqueIdUTF8) { WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceVideoCapture, id, "Create %s", deviceUniqueIdUTF8); @@ -31,16 +34,16 @@ VideoCaptureModule* VideoCaptureModule::Create( videocapturemodule::DeviceInfoWindows::GetProductId(deviceUniqueIdUTF8, productId, sizeof(productId)); + + RefCountImpl* newCaptureModule = + new RefCountImpl(id); - videocapturemodule::VideoCaptureDS* newCaptureModule = NULL; - newCaptureModule = new videocapturemodule::VideoCaptureDS(id); - - if (!newCaptureModule - || newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0) + if (newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0) { - Destroy(newCaptureModule); + delete newCaptureModule; newCaptureModule = NULL; } return newCaptureModule; } +} //namespace videocapturemodule } //namespace webrtc diff --git a/src/modules/video_capture/main/source/Windows/video_capture_windows.cc b/src/modules/video_capture/main/source/Windows/video_capture_windows.cc index 728770839..8f94d6a2b 100644 --- a/src/modules/video_capture/main/source/Windows/video_capture_windows.cc +++ b/src/modules/video_capture/main/source/Windows/video_capture_windows.cc @@ -9,11 +9,13 @@ */ #include "video_capture_windows.h" -#include "trace.h" -#include "sink_filter_windows.h" -#include "help_functions_windows.h" + #include "../video_capture_config.h" #include "critical_section_wrapper.h" +#include "help_functions_windows.h" +#include "sink_filter_windows.h" +#include "trace.h" + #include // VIDEOINFOHEADER2 namespace webrtc diff --git a/src/modules/video_capture/main/source/video_capture.gyp b/src/modules/video_capture/main/source/video_capture.gyp index 30ba5e79b..1c8ff85df 100644 --- a/src/modules/video_capture/main/source/video_capture.gyp +++ b/src/modules/video_capture/main/source/video_capture.gyp @@ -57,8 +57,7 @@ ], }], ['OS=="mac" and build_with_chromium==0', { - 'sources': [ - 'Mac/video_capture_mac.h', + 'sources': [ 'Mac/QTKit/video_capture_recursive_lock.h', 'Mac/QTKit/video_capture_qtkit.h', 'Mac/QTKit/video_capture_qtkit_info.h', diff --git a/src/modules/video_capture/main/source/video_capture_config.h b/src/modules/video_capture/main/source/video_capture_config.h index c0d1c5b28..ab4010c36 100644 --- a/src/modules/video_capture/main/source/video_capture_config.h +++ b/src/modules/video_capture/main/source/video_capture_config.h @@ -28,7 +28,7 @@ enum {kProcessInterval = 300}; enum {kFrameRateCallbackInterval = 1000}; enum {kFrameRateCountHistorySize = 90}; enum {kFrameRateHistoryWindowMs = 2000}; -} //namespace videocapturemodule -} //namespace webrtc +} // namespace videocapturemodule +} // namespace webrtc #endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_CONFIG_H_ diff --git a/src/modules/video_capture/main/source/video_capture_impl.cc b/src/modules/video_capture/main/source/video_capture_impl.cc index 80cc673bb..c7690bbfb 100644 --- a/src/modules/video_capture/main/source/video_capture_impl.cc +++ b/src/modules/video_capture/main/source/video_capture_impl.cc @@ -15,6 +15,7 @@ #include "vplib_conversions.h" #include "video_capture_config.h" #include "module_common_types.h" +#include "ref_count.h" #ifdef WEBRTC_ANDROID #include "video_capture_android.h" // Need inclusion here to set Java environment. @@ -22,33 +23,26 @@ namespace webrtc { - -VideoCaptureModule* VideoCaptureModule::Create(const WebRtc_Word32 id, - VideoCaptureExternal*& externalCapture) +namespace videocapturemodule { - videocapturemodule::VideoCaptureImpl* implementation = - new videocapturemodule::VideoCaptureImpl(id); +VideoCaptureModule* VideoCaptureImpl::Create( + const WebRtc_Word32 id, + VideoCaptureExternal*& externalCapture) +{ + RefCountImpl* implementation = + new RefCountImpl(id); externalCapture = implementation; return implementation; } - -void VideoCaptureModule::Destroy(VideoCaptureModule* module) -{ - delete module; -} - #ifdef WEBRTC_ANDROID -WebRtc_Word32 VideoCaptureModule::SetAndroidObjects(void* javaVM,void* javaContext) +WebRtc_Word32 VideoCaptureImpl::SetAndroidObjects(void* javaVM,void* javaContext) { WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceVideoCapture, 0, "SetAndroidObjects"); return videocapturemodule::VideoCaptureAndroid::SetAndroidObjects(javaVM,javaContext); } #endif -namespace videocapturemodule -{ - WebRtc_Word32 VideoCaptureImpl::Version(WebRtc_Word8* version, WebRtc_UWord32& remainingBufferInBytes, WebRtc_UWord32& position) const @@ -281,7 +275,8 @@ WebRtc_Word32 VideoCaptureImpl::IncomingFrame(WebRtc_UWord8* videoFrame, if (frameInfo.codecType == kVideoCodecUnknown) // None encoded. Convert to I420. { - const VideoType vpLibType =RawVideoTypeToVplibVideoType(frameInfo.rawType); + const VideoType vpLibType = videocapturemodule:: + RawVideoTypeToVplibVideoType(frameInfo.rawType); int size = CalcBufferSize(vpLibType, width, height); if (size != videoFrameLength) { @@ -477,5 +472,5 @@ WebRtc_UWord32 VideoCaptureImpl::CalculateFrameRate(const TickTime& now) return nrOfFrames; } -} //namespace videocapturemodule +} // namespace videocapturemodule } // namespace webrtc diff --git a/src/modules/video_capture/main/source/video_capture_impl.h b/src/modules/video_capture/main/source/video_capture_impl.h index 6f91e7d25..b11e1de39 100644 --- a/src/modules/video_capture/main/source/video_capture_impl.h +++ b/src/modules/video_capture/main/source/video_capture_impl.h @@ -24,24 +24,43 @@ namespace webrtc { class CriticalSectionWrapper; -namespace videocapturemodule -{ +namespace videocapturemodule { // Class definitions class VideoCaptureImpl: public VideoCaptureModule, public VideoCaptureExternal { public: - VideoCaptureImpl(const WebRtc_Word32 id); - virtual ~VideoCaptureImpl(); + /* + * Create a video capture module object + * + * id - unique identifier of this video capture module object + * deviceUniqueIdUTF8 - name of the device. Available names can be found by using GetDeviceName + */ + static VideoCaptureModule* Create(const WebRtc_Word32 id, + const WebRtc_UWord8* deviceUniqueIdUTF8); + /* + * Create a video capture module object used for external capture. + * + * id - unique identifier of this video capture module object + * externalCapture - [out] interface to call when a new frame is captured. + */ static VideoCaptureModule* Create(const WebRtc_Word32 id, VideoCaptureExternal*& externalCapture); - static void Destroy(VideoCaptureModule* module); + static DeviceInfo* CreateDeviceInfo(const WebRtc_Word32 id); + static void DestroyDeviceInfo(DeviceInfo* deviceInfo); + +#ifdef WEBRTC_ANDROID + static WebRtc_Word32 SetAndroidObjects(void* javaVM, void* javaContext); +#endif + static WebRtc_Word32 GetVersion(WebRtc_Word8* version, WebRtc_UWord32& remainingBufferInBytes, WebRtc_UWord32& position); + + // Implements Module declared functions. virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id); @@ -91,6 +110,9 @@ public: { return NULL; } protected: + VideoCaptureImpl(const WebRtc_Word32 id); + virtual ~VideoCaptureImpl(); + WebRtc_Word32 _id; // Module ID WebRtc_UWord8* _deviceUniqueId; // current Device unique name; CriticalSectionWrapper& _apiCs; @@ -121,6 +143,6 @@ private: VideoFrame _captureFrame; }; -} //namespace videocapturemodule +} // namespace videocapturemodule } //namespace webrtc #endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_ diff --git a/src/modules/video_capture/main/test/android/jni/video_capture_module_android_test_jni.cc b/src/modules/video_capture/main/test/android/jni/video_capture_module_android_test_jni.cc index 7786e0941..9d93fa34e 100644 --- a/src/modules/video_capture/main/test/android/jni/video_capture_module_android_test_jni.cc +++ b/src/modules/video_capture/main/test/android/jni/video_capture_module_android_test_jni.cc @@ -13,6 +13,7 @@ #include "org_webrtc_capturemoduleandroidtest_VideoCaptureModuleTest.h" #include "../../../interface/video_capture.h" +#include "../../../source/video_capture_impl.h" #include "../../../../../video_render/main/interface/video_render.h" #include "../../testAPI/testPlatformDependent.h" #include "../../testAPI/testPlatformDependent.h" @@ -116,11 +117,11 @@ Java_org_webrtc_capturemoduleandroidtest_VideoCaptureModuleTest_StartCapture( { if (!jniData._captureInfo) { VideoCaptureModule::SetAndroidObjects(jniData.jvm, context); - jniData._captureInfo = VideoCaptureModule::CreateDeviceInfo(5); + jniData._captureInfo = VideoCaptureImpl::CreateDeviceInfo(5); WebRtc_UWord8 id[256]; WebRtc_UWord8 name[256]; jniData._captureInfo->GetDeviceName(0, name, 256, id, 256); - jniData._videoCapture = VideoCaptureModule::Create(0, id); + jniData._videoCapture = VideoCaptureImpl::Create(0, id); VideoCaptureCapability capability; jniData._captureInfo->GetCapability(id, 0, capability); diff --git a/src/video_engine/main/source/video_engine_core.gyp b/src/video_engine/main/source/video_engine_core.gyp index 0f73a2eee..6f444d65b 100644 --- a/src/video_engine/main/source/video_engine_core.gyp +++ b/src/video_engine/main/source/video_engine_core.gyp @@ -36,6 +36,7 @@ 'include_dirs': [ '../interface', '../../../modules/video_capture/main/interface', + '../../../modules/video_capture/main/source', '../../../modules/video_render/main/interface', ], 'direct_dependent_settings': { diff --git a/src/video_engine/main/source/vie_capturer.cc b/src/video_engine/main/source/vie_capturer.cc index d712582b1..bd8ef815c 100644 --- a/src/video_engine/main/source/vie_capturer.cc +++ b/src/video_engine/main/source/vie_capturer.cc @@ -19,7 +19,7 @@ #include "event_wrapper.h" #include "module_common_types.h" #include "video_capture.h" -#include "video_capture.h" +#include "video_capture_impl.h" #include "video_processing.h" #include "video_render_defines.h" #include "thread_wrapper.h" @@ -41,7 +41,6 @@ ViECapturer::ViECapturer(int captureId, _captureCritsect(*CriticalSectionWrapper::CreateCriticalSection()), _deliverCritsect(*CriticalSectionWrapper::CreateCriticalSection()), _captureModule(NULL), - _useExternalModule(false), _externalCaptureModule(NULL), _moduleProcessThread(moduleProcessThread), _captureId(captureId), @@ -118,6 +117,8 @@ ViECapturer::~ViECapturer() { _moduleProcessThread.DeRegisterModule(_captureModule); _captureModule->DeRegisterCaptureDataCallback(); + _captureModule->Release(); + _captureModule = NULL; } if (_vieCaptureThread.Stop()) { @@ -134,11 +135,6 @@ ViECapturer::~ViECapturer() // Not possible to stop the thread, leak it... } - if (!_useExternalModule) - { - VideoCaptureModule::Destroy(_captureModule); - } - _captureModule = NULL; if (_imageProcModule) { VideoProcessingModule::Destroy(_imageProcModule); @@ -179,9 +175,10 @@ ViECapturer* ViECapturer::CreateViECapture(int captureId, WebRtc_Word32 ViECapturer::Init(VideoCaptureModule& captureModule) { + assert(_captureModule == NULL); _captureModule = &captureModule; - _useExternalModule = true; _captureModule->RegisterCaptureDataCallback(*this); + _captureModule->AddRef(); if (_moduleProcessThread.RegisterModule(_captureModule) != 0) { return -1; @@ -205,23 +202,23 @@ ViECapturer* ViECapturer::CreateViECapture(int captureId, return capture; } WebRtc_Word32 ViECapturer::Init(const WebRtc_UWord8* deviceUniqueIdUTF8, - const WebRtc_UWord32 deviceUniqueIdUTF8Length) + const WebRtc_UWord32 deviceUniqueIdUTF8Length) { + assert(_captureModule == NULL); #ifndef WEBRTC_VIDEO_EXTERNAL_CAPTURE_AND_RENDER if (deviceUniqueIdUTF8 == NULL) { - _captureModule = VideoCaptureModule::Create( - ViEModuleId(_engineId, _captureId), - _externalCaptureModule); + _captureModule = videocapturemodule::VideoCaptureImpl::Create( + ViEModuleId(_engineId, _captureId), _externalCaptureModule); } else { - _captureModule = VideoCaptureModule::Create( - ViEModuleId(_engineId, _captureId), - deviceUniqueIdUTF8); + _captureModule = videocapturemodule::VideoCaptureImpl::Create( + ViEModuleId(_engineId, _captureId), deviceUniqueIdUTF8); } #endif if (!_captureModule) return -1; + _captureModule->AddRef(); _captureModule->RegisterCaptureDataCallback(*this); if (_moduleProcessThread.RegisterModule(_captureModule) != 0) { diff --git a/src/video_engine/main/source/vie_capturer.h b/src/video_engine/main/source/vie_capturer.h index 0e893ba38..6a9531798 100644 --- a/src/video_engine/main/source/vie_capturer.h +++ b/src/video_engine/main/source/vie_capturer.h @@ -157,7 +157,6 @@ private: CriticalSectionWrapper& _captureCritsect; // Never take this one before deliverCritsect! CriticalSectionWrapper& _deliverCritsect; VideoCaptureModule* _captureModule; - bool _useExternalModule; VideoCaptureExternal* _externalCaptureModule; ProcessThread& _moduleProcessThread; const int _captureId; diff --git a/src/video_engine/main/source/vie_impl.cc b/src/video_engine/main/source/vie_impl.cc index 4f9741b9a..5caf373e8 100644 --- a/src/video_engine/main/source/vie_impl.cc +++ b/src/video_engine/main/source/vie_impl.cc @@ -22,6 +22,7 @@ #ifdef WEBRTC_ANDROID #include "video_capture.h" +#include "video_capture_impl.h" #include "video_render.h" #endif @@ -281,7 +282,7 @@ int VideoEngine::SetAndroidObjects(void* javaVM, void* javaContext) "SetAndroidObjects()"); #ifdef WEBRTC_ANDROID - if (VideoCaptureModule::SetAndroidObjects(javaVM,javaContext) != 0) + if (VideoCaptureImpl::SetAndroidObjects(javaVM,javaContext) != 0) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, gViEActiveInstanceCounter, "Could not set capture module Android objects"); diff --git a/src/video_engine/main/source/vie_input_manager.cc b/src/video_engine/main/source/vie_input_manager.cc index 4505dc751..6c66f2f9e 100644 --- a/src/video_engine/main/source/vie_input_manager.cc +++ b/src/video_engine/main/source/vie_input_manager.cc @@ -18,7 +18,7 @@ #include "common_types.h" #include "critical_section_wrapper.h" #include "video_capture.h" -#include "video_capture.h" +#include "video_capture_impl.h" #include "video_coding.h" #include "video_coding_defines.h" #include "rw_lock_wrapper.h" @@ -58,8 +58,9 @@ ViEInputManager::ViEInputManager(const int engineId) #ifdef WEBRTC_VIDEO_EXTERNAL_CAPTURE_AND_RENDER _ptrCaptureDeviceInfo=NULL; #else - _ptrCaptureDeviceInfo = VideoCaptureModule::CreateDeviceInfo( - ViEModuleId(_engineId)); + _ptrCaptureDeviceInfo = + videocapturemodule::VideoCaptureImpl::CreateDeviceInfo( + ViEModuleId(_engineId)); #endif for (int idx = 0; idx < kViEMaxFilePlayers; idx++) { @@ -87,11 +88,14 @@ ViEInputManager::~ViEInputManager() } delete &_mapCritsect; +#ifndef WEBRTC_VIDEO_EXTERNAL_CAPTURE_AND_RENDER if (_ptrCaptureDeviceInfo) { - VideoCaptureModule::DestroyDeviceInfo( _ptrCaptureDeviceInfo); + videocapturemodule::VideoCaptureImpl::DestroyDeviceInfo( + _ptrCaptureDeviceInfo); _ptrCaptureDeviceInfo = NULL; } +#endif } // ---------------------------------------------------------------------------- diff --git a/src/video_engine/main/test/AutoTest/source/tb_capture_device.cc b/src/video_engine/main/test/AutoTest/source/tb_capture_device.cc index 7d23efba7..52e55bcdf 100644 --- a/src/video_engine/main/test/AutoTest/source/tb_capture_device.cc +++ b/src/video_engine/main/test/AutoTest/source/tb_capture_device.cc @@ -9,6 +9,7 @@ */ #include "tb_capture_device.h" +#include "video_capture_impl.h" tbCaptureDevice::tbCaptureDevice(tbInterfaces& Engine, int& nrOfErrors) : captureId(-1), @@ -27,7 +28,7 @@ tbCaptureDevice::tbCaptureDevice(tbInterfaces& Engine, int& nrOfErrors) : bool captureDeviceSet = false; webrtc::VideoCaptureModule::DeviceInfo* devInfo = - webrtc::VideoCaptureModule::CreateDeviceInfo(0); + webrtc::videocapturemodule::VideoCaptureImpl::CreateDeviceInfo(0); for (size_t captureIdx = 0; captureIdx < devInfo->NumberOfDevices(); captureIdx++) @@ -39,11 +40,13 @@ tbCaptureDevice::tbCaptureDevice(tbInterfaces& Engine, int& nrOfErrors) : "ERROR: %s at line %d", __FUNCTION__, __LINE__); - vcpm_ = webrtc::VideoCaptureModule::Create(captureIdx, uniqueId); + vcpm_ = webrtc::videocapturemodule::VideoCaptureImpl::Create( + captureIdx, uniqueId); if (vcpm_ == NULL) // Failed to open this device. Try next. { continue; } + vcpm_->AddRef(); error = ViE.ptrViECapture->AllocateCaptureDevice(*vcpm_, captureId); if (error == 0) @@ -54,7 +57,7 @@ tbCaptureDevice::tbCaptureDevice(tbInterfaces& Engine, int& nrOfErrors) : break; } } - webrtc::VideoCaptureModule::DestroyDeviceInfo(devInfo); + webrtc::videocapturemodule::VideoCaptureImpl::DestroyDeviceInfo(devInfo); numberOfErrors += ViETest::TestError( captureDeviceSet, "ERROR: %s at line %d - Could not set capture device", __FUNCTION__, __LINE__); @@ -78,9 +81,7 @@ tbCaptureDevice::~tbCaptureDevice(void) error = ViE.ptrViECapture->ReleaseCaptureDevice(captureId); numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); - - webrtc::VideoCaptureModule::Destroy(vcpm_); - + vcpm_->Release(); } void tbCaptureDevice::ConnectTo(int videoChannel) diff --git a/src/video_engine/main/test/AutoTest/source/vie_autotest_base.cc b/src/video_engine/main/test/AutoTest/source/vie_autotest_base.cc index 4e54d0f19..014ff8b08 100644 --- a/src/video_engine/main/test/AutoTest/source/vie_autotest_base.cc +++ b/src/video_engine/main/test/AutoTest/source/vie_autotest_base.cc @@ -15,7 +15,7 @@ #include "vie_autotest_defines.h" #include "vie_autotest.h" #include "engine_configurations.h" -#include "video_capture.h" +#include "video_capture_impl.h" int ViEAutoTest::ViEBaseStandardTest() { @@ -82,7 +82,7 @@ int ViEAutoTest::ViEBaseStandardTest() bool captureDeviceSet = false; int captureId = 0; webrtc::VideoCaptureModule::DeviceInfo* devInfo = - webrtc::VideoCaptureModule::CreateDeviceInfo(0); + webrtc::videocapturemodule::VideoCaptureImpl::CreateDeviceInfo(0); for (unsigned int captureIdx = 0; captureIdx < devInfo->NumberOfDevices(); @@ -95,7 +95,9 @@ int ViEAutoTest::ViEBaseStandardTest() "ERROR: %s at line %d", __FUNCTION__, __LINE__); - vcpm = webrtc::VideoCaptureModule::Create(4571, uniqueId); + vcpm = webrtc::videocapturemodule::VideoCaptureImpl::Create( + 4571, uniqueId); + vcpm->AddRef(); numberOfErrors += ViETest::TestError(vcpm != NULL, "ERROR: %s at line %d", __FUNCTION__, __LINE__); @@ -110,11 +112,11 @@ int ViEAutoTest::ViEBaseStandardTest() } else { - webrtc::VideoCaptureModule::Destroy(vcpm); + vcpm->Release(); vcpm = NULL; } } - webrtc::VideoCaptureModule::DestroyDeviceInfo(devInfo); + webrtc::videocapturemodule::VideoCaptureImpl::DestroyDeviceInfo(devInfo); numberOfErrors+= ViETest::TestError( captureDeviceSet, @@ -314,7 +316,7 @@ int ViEAutoTest::ViEBaseStandardTest() numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); - webrtc::VideoCaptureModule::Destroy(vcpm); + vcpm->Release(); vcpm = NULL; remainingInterfaces = ptrViECapture->Release(); diff --git a/src/video_engine/main/test/AutoTest/source/vie_autotest_capture.cc b/src/video_engine/main/test/AutoTest/source/vie_autotest_capture.cc index 668b48750..76d815f92 100644 --- a/src/video_engine/main/test/AutoTest/source/vie_autotest_capture.cc +++ b/src/video_engine/main/test/AutoTest/source/vie_autotest_capture.cc @@ -28,7 +28,7 @@ #include "tb_interfaces.h" #include "tb_video_channel.h" -#include "video_capture.h" +#include "video_capture_impl.h" class CaptureObserver: public webrtc::ViECaptureObserver { @@ -138,7 +138,7 @@ int ViEAutoTest::ViECaptureStandardTest() tbInterfaces ViE("WebRTCViECapture_Standard", numberOfErrors); webrtc::VideoCaptureModule::DeviceInfo* devInfo = - webrtc::VideoCaptureModule::CreateDeviceInfo(0); + webrtc::videocapturemodule::VideoCaptureImpl::CreateDeviceInfo(0); int numberOfCaptureDevices = devInfo->NumberOfDevices(); ViETest::Log("Number of capture devices %d", numberOfCaptureDevices); @@ -229,7 +229,9 @@ int ViEAutoTest::ViECaptureStandardTest() __FUNCTION__, __LINE__); webrtc::VideoCaptureModule* vcpm = - webrtc::VideoCaptureModule::Create(deviceIndex, deviceUniqueName); + webrtc::videocapturemodule::VideoCaptureImpl::Create( + deviceIndex, deviceUniqueName); + vcpm->AddRef(); numberOfErrors += ViETest::TestError(vcpm != NULL, "ERROR: %s at line %d", __FUNCTION__, __LINE__); @@ -323,7 +325,7 @@ int ViEAutoTest::ViECaptureStandardTest() numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); #endif - webrtc::VideoCaptureModule::Destroy(vcpms[deviceIndex]); + vcpms[deviceIndex]->Release(); } #endif if (numberOfErrors > 0) @@ -336,7 +338,7 @@ int ViEAutoTest::ViECaptureStandardTest() ViETest::Log(" "); return numberOfErrors; } - webrtc::VideoCaptureModule::DestroyDeviceInfo(devInfo); + webrtc::videocapturemodule::VideoCaptureImpl::DestroyDeviceInfo(devInfo); ViETest::Log(" "); ViETest::Log(" ViECapture Standard Test PASSED!"); @@ -384,7 +386,7 @@ int ViEAutoTest::ViECaptureAPITest() int captureId = 0; webrtc::VideoCaptureModule::DeviceInfo* devInfo = - webrtc::VideoCaptureModule::CreateDeviceInfo(0); + webrtc::videocapturemodule::VideoCaptureImpl::CreateDeviceInfo(0); numberOfErrors += ViETest::TestError(devInfo != NULL, "ERROR: %s at line %d", __FUNCTION__, __LINE__); @@ -396,7 +398,9 @@ int ViEAutoTest::ViECaptureAPITest() __FUNCTION__, __LINE__); webrtc::VideoCaptureModule* vcpm = - webrtc::VideoCaptureModule::Create(0, deviceUniqueName); + webrtc::videocapturemodule::VideoCaptureImpl::Create( + 0, deviceUniqueName); + vcpm->AddRef(); numberOfErrors += ViETest::TestError(vcpm != NULL, "ERROR: %s at line %d", __FUNCTION__, __LINE__); @@ -554,8 +558,8 @@ int ViEAutoTest::ViECaptureAPITest() numberOfErrors += ViETest::TestError(error == 0, "ERROR: %s at line %d", __FUNCTION__, __LINE__); - webrtc::VideoCaptureModule::DestroyDeviceInfo(devInfo); - webrtc::VideoCaptureModule::Destroy(vcpm); + webrtc::videocapturemodule::VideoCaptureImpl::DestroyDeviceInfo(devInfo); + vcpm->Release(); //*************************************************************** // Testing finished. Tear down Video Engine @@ -604,7 +608,9 @@ int ViEAutoTest::ViECaptureExternalCaptureTest() // Allocate the external capture device webrtc::VideoCaptureModule* vcpm = - webrtc::VideoCaptureModule::Create(0, externalCapture); + webrtc::videocapturemodule::VideoCaptureImpl::Create( + 0, externalCapture); + vcpm->AddRef(); numberOfErrors += ViETest::TestError(vcpm != NULL, "ERROR: %s at line %d", __FUNCTION__, __LINE__); @@ -787,6 +793,7 @@ int ViEAutoTest::ViECaptureExternalCaptureTest() numberOfErrors += ViETest::TestError( ViE.LastError() == kViECaptureDeviceDoesnNotExist, "ERROR: %s at line %d", __FUNCTION__, __LINE__); + vcpm->Release(); //*************************************************************** // Testing finished. Tear down Video Engine diff --git a/src/video_engine/main/test/AutoTest/vie_auto_test.gypi b/src/video_engine/main/test/AutoTest/vie_auto_test.gypi index f1f7ef5cd..d3a7ea3de 100644 --- a/src/video_engine/main/test/AutoTest/vie_auto_test.gypi +++ b/src/video_engine/main/test/AutoTest/vie_auto_test.gypi @@ -21,6 +21,7 @@ 'interface/', '../../interface', '../../source', + '../../../../modules/video_capture/main/source/', '../../../../modules/video_coding/codecs/interface/', '../../../../common_video/interface/', ], diff --git a/third_party_mods/libjingle/source/talk/session/phone/webrtcvideoengine.cc b/third_party_mods/libjingle/source/talk/session/phone/webrtcvideoengine.cc index f35153b83..c6e753210 100644 --- a/third_party_mods/libjingle/source/talk/session/phone/webrtcvideoengine.cc +++ b/third_party_mods/libjingle/source/talk/session/phone/webrtcvideoengine.cc @@ -116,6 +116,8 @@ WebRtcVideoEngine::WebRtcVideoEngine(WebRtcVoiceEngine* voice_engine, voice_engine_(voice_engine), log_level_(kDefaultLogSeverity), capture_started_(false) { + if(capture_) + capture_->AddRef(); } WebRtcVideoEngine::WebRtcVideoEngine(WebRtcVoiceEngine* voice_engine, @@ -137,7 +139,7 @@ WebRtcVideoEngine::~WebRtcVideoEngine() { Terminate(); vie_wrapper_.reset(); if (capture_) { - webrtc::VideoCaptureModule::Destroy(capture_); + capture_->Release(); } if (renderer_) { webrtc::VideoRender::DestroyVideoRender(renderer_); @@ -382,9 +384,10 @@ bool WebRtcVideoEngine::SetCaptureDevice(const Device* cam) { bool WebRtcVideoEngine::SetCaptureModule(webrtc::VideoCaptureModule* vcm) { ReleaseCaptureDevice(); if (capture_) { - webrtc::VideoCaptureModule::Destroy(capture_); + capture_->Release(); } capture_ = vcm; + capture_->AddRef(); external_capture_ = true; return true; }