Replace RefCountImpl with rtc::RefCountedObject.

Removes code duplication and use of the dangerous public destructor in
RefCountImpl.

Also making wider use of scoped_refptr and fixing various leaks in the
process.

BUG=webrtc:5229
R=tommi@webrtc.org

Review URL: https://codereview.webrtc.org/1477013005 .

Cr-Commit-Position: refs/heads/master@{#12075}
This commit is contained in:
Peter Boström 2016-03-21 16:44:31 +01:00
parent af510afc91
commit 1d1944187f
27 changed files with 124 additions and 260 deletions

View File

@ -8,10 +8,10 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/base/refcount.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
#include "webrtc/modules/audio_device/audio_device_config.h"
#include "webrtc/modules/audio_device/audio_device_impl.h"
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/system_wrappers/include/tick_util.h"
#include <assert.h>
@ -65,13 +65,7 @@
}; \
}
namespace webrtc
{
AudioDeviceModule* CreateAudioDeviceModule(
int32_t id, AudioDeviceModule::AudioLayer audioLayer) {
return AudioDeviceModuleImpl::Create(id, audioLayer);
}
namespace webrtc {
// ============================================================================
// Static methods
@ -81,33 +75,30 @@ AudioDeviceModule* CreateAudioDeviceModule(
// AudioDeviceModule::Create()
// ----------------------------------------------------------------------------
AudioDeviceModule* AudioDeviceModuleImpl::Create(const int32_t id,
const AudioLayer audioLayer)
{
rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModuleImpl::Create(
const int32_t id,
const AudioLayer audioLayer) {
// Create the generic ref counted (platform independent) implementation.
RefCountImpl<AudioDeviceModuleImpl>* audioDevice =
new RefCountImpl<AudioDeviceModuleImpl>(id, audioLayer);
rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audioLayer));
// Ensure that the current platform is supported.
if (audioDevice->CheckPlatform() == -1)
{
delete audioDevice;
return NULL;
return nullptr;
}
// Create the platform-dependent implementation.
if (audioDevice->CreatePlatformSpecificObjects() == -1)
{
delete audioDevice;
return NULL;
return nullptr;
}
// Ensure that the generic audio buffer can communicate with the
// platform-specific parts.
if (audioDevice->AttachAudioBuffer() == -1)
{
delete audioDevice;
return NULL;
return nullptr;
}
WebRtcSpl_Init();

View File

@ -16,6 +16,7 @@
#include <memory>
#include "webrtc/base/checks.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/audio_device/audio_device_buffer.h"
#include "webrtc/modules/audio_device/include/audio_device.h"
@ -48,7 +49,7 @@ class AudioDeviceModuleImpl : public AudioDeviceModule {
void Process() override;
// Factory methods (resource allocation/deallocation)
static AudioDeviceModule* Create(
static rtc::scoped_refptr<AudioDeviceModule> Create(
const int32_t id,
const AudioLayer audioLayer = kPlatformDefaultAudio);

View File

@ -211,9 +211,6 @@ class AudioDeviceModule : public RefCountedModule {
virtual ~AudioDeviceModule() {}
};
AudioDeviceModule* CreateAudioDeviceModule(
int32_t id, AudioDeviceModule::AudioLayer audioLayer);
} // namespace webrtc
#endif // MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_

View File

@ -48,11 +48,11 @@ using namespace webrtc;
class AudioEventObserverAPI: public AudioDeviceObserver {
public:
AudioEventObserverAPI(AudioDeviceModule* audioDevice)
AudioEventObserverAPI(
const rtc::scoped_refptr<AudioDeviceModule>& audioDevice)
: error_(kRecordingError),
warning_(kRecordingWarning),
audio_device_(audioDevice) {
}
audio_device_(audioDevice) {}
~AudioEventObserverAPI() {}
@ -72,12 +72,12 @@ class AudioEventObserverAPI: public AudioDeviceObserver {
ErrorCode error_;
WarningCode warning_;
private:
AudioDeviceModule* audio_device_;
rtc::scoped_refptr<AudioDeviceModule> audio_device_;
};
class AudioTransportAPI: public AudioTransport {
public:
AudioTransportAPI(AudioDeviceModule* audioDevice)
AudioTransportAPI(const rtc::scoped_refptr<AudioDeviceModule>& audioDevice)
: rec_count_(0),
play_count_(0) {
}
@ -161,13 +161,11 @@ class AudioDeviceAPITest: public testing::Test {
// create default implementation (=Core Audio) instance
EXPECT_TRUE((audio_device_ = AudioDeviceModuleImpl::Create(
kId, AudioDeviceModule::kPlatformDefaultAudio)) != NULL);
audio_device_->AddRef();
EXPECT_EQ(0, audio_device_->Release());
EXPECT_EQ(0, audio_device_.release()->Release());
// create non-default (=Wave Audio) instance
EXPECT_TRUE((audio_device_ = AudioDeviceModuleImpl::Create(
kId, AudioDeviceModule::kWindowsWaveAudio)) != NULL);
audio_device_->AddRef();
EXPECT_EQ(0, audio_device_->Release());
EXPECT_EQ(0, audio_device_.release()->Release());
// explicitly specify usage of Core Audio (same as default)
EXPECT_TRUE((audio_device_ = AudioDeviceModuleImpl::Create(
kId, AudioDeviceModule::kWindowsCoreAudio)) != NULL);
@ -178,8 +176,7 @@ class AudioDeviceAPITest: public testing::Test {
// create default implementation (=Wave Audio) instance
EXPECT_TRUE((audio_device_ = AudioDeviceModuleImpl::Create(
kId, AudioDeviceModule::kPlatformDefaultAudio)) != NULL);
audio_device_->AddRef();
EXPECT_EQ(0, audio_device_->Release());
EXPECT_EQ(0, audio_device_.release()->Release());
// explicitly specify usage of Wave Audio (same as default)
EXPECT_TRUE((audio_device_ = AudioDeviceModuleImpl::Create(
kId, AudioDeviceModule::kWindowsWaveAudio)) != NULL);
@ -207,9 +204,8 @@ class AudioDeviceAPITest: public testing::Test {
// create default implementation instance
EXPECT_TRUE((audio_device_ = AudioDeviceModuleImpl::Create(
kId, AudioDeviceModule::kPlatformDefaultAudio)) != NULL);
audio_device_->AddRef();
EXPECT_EQ(0, audio_device_->Terminate());
EXPECT_EQ(0, audio_device_->Release());
EXPECT_EQ(0, audio_device_.release()->Release());
// explicitly specify usage of Pulse Audio (same as default)
EXPECT_TRUE((audio_device_ = AudioDeviceModuleImpl::Create(
kId, AudioDeviceModule::kLinuxPulseAudio)) != NULL);
@ -234,9 +230,6 @@ class AudioDeviceAPITest: public testing::Test {
FAIL() << "Failed creating audio device object!";
}
// The ADM is reference counted.
audio_device_->AddRef();
process_thread_->RegisterModule(audio_device_);
AudioDeviceModule::AudioLayer audio_layer =
@ -261,9 +254,8 @@ class AudioDeviceAPITest: public testing::Test {
delete audio_transport_;
audio_transport_ = NULL;
}
if (audio_device_) {
EXPECT_EQ(0, audio_device_->Release());
}
if (audio_device_)
EXPECT_EQ(0, audio_device_.release()->Release());
PRINT_TEST_RESULTS;
}
@ -304,7 +296,7 @@ class AudioDeviceAPITest: public testing::Test {
// TODO(henrika): Get rid of globals.
static bool linux_alsa_;
static std::unique_ptr<ProcessThread> process_thread_;
static AudioDeviceModule* audio_device_;
static rtc::scoped_refptr<AudioDeviceModule> audio_device_;
static AudioTransportAPI* audio_transport_;
static AudioEventObserverAPI* event_observer_;
};
@ -312,7 +304,7 @@ class AudioDeviceAPITest: public testing::Test {
// Must be initialized like this to handle static SetUpTestCase() above.
bool AudioDeviceAPITest::linux_alsa_ = false;
std::unique_ptr<ProcessThread> AudioDeviceAPITest::process_thread_;
AudioDeviceModule* AudioDeviceAPITest::audio_device_ = NULL;
rtc::scoped_refptr<AudioDeviceModule> AudioDeviceAPITest::audio_device_;
AudioTransportAPI* AudioDeviceAPITest::audio_transport_ = NULL;
AudioEventObserverAPI* AudioDeviceAPITest::event_observer_ = NULL;

View File

@ -10,7 +10,6 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "webrtc/modules/desktop_capture/differ_block.h"
#include "webrtc/system_wrappers/include/ref_count.h"
namespace webrtc {

View File

@ -14,9 +14,9 @@
#include <list>
#include <vector>
#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/typedefs.h"
namespace webrtc {

View File

@ -8,19 +8,17 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/base/refcount.h"
#include "webrtc/modules/video_capture/video_capture_impl.h"
#include "webrtc/system_wrappers/include/ref_count.h"
namespace webrtc {
namespace videocapturemodule {
VideoCaptureModule* VideoCaptureImpl::Create(
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create(
const int32_t id,
const char* deviceUniqueIdUTF8) {
RefCountImpl<VideoCaptureImpl>* implementation =
new RefCountImpl<VideoCaptureImpl>(id);
return implementation;
return new rtc::RefCountedObject<VideoCaptureImpl>(id);
}
} // namespace videocapturemodule

View File

@ -11,6 +11,7 @@
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_H_
#define WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_H_
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/video_capture/video_capture_impl.h"
@class RTCVideoCaptureIosObjC;
@ -22,8 +23,9 @@ class VideoCaptureIos : public VideoCaptureImpl {
explicit VideoCaptureIos(const int32_t capture_id);
virtual ~VideoCaptureIos();
static VideoCaptureModule* Create(const int32_t capture_id,
const char* device_unique_id_utf8);
static rtc::scoped_refptr<VideoCaptureModule> Create(
const int32_t capture_id,
const char* device_unique_id_utf8);
// Implementation of VideoCaptureImpl.
int32_t StartCapture(const VideoCaptureCapability& capability) override;

View File

@ -12,16 +12,18 @@
#error "This file requires ARC support."
#endif
#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
#include "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h"
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/system_wrappers/include/trace.h"
using namespace webrtc;
using namespace videocapturemodule;
VideoCaptureModule* VideoCaptureImpl::Create(const int32_t capture_id,
const char* deviceUniqueIdUTF8) {
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create(
const int32_t capture_id,
const char* deviceUniqueIdUTF8) {
return VideoCaptureIos::Create(capture_id, deviceUniqueIdUTF8);
}
@ -40,18 +42,19 @@ VideoCaptureIos::~VideoCaptureIos() {
}
}
VideoCaptureModule* VideoCaptureIos::Create(const int32_t capture_id,
const char* deviceUniqueIdUTF8) {
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureIos::Create(
const int32_t capture_id,
const char* deviceUniqueIdUTF8) {
if (!deviceUniqueIdUTF8[0]) {
return NULL;
}
RefCountImpl<VideoCaptureIos>* capture_module =
new RefCountImpl<VideoCaptureIos>(capture_id);
rtc::scoped_refptr<VideoCaptureIos> capture_module(
new rtc::RefCountedObject<VideoCaptureIos>(capture_id));
const int32_t name_length = strlen(deviceUniqueIdUTF8);
if (name_length > kVideoCaptureUniqueNameLength)
return NULL;
return nullptr;
capture_module->_deviceUniqueId = new char[name_length + 1];
strncpy(capture_module->_deviceUniqueId, deviceUniqueIdUTF8, name_length + 1);
@ -61,13 +64,13 @@ VideoCaptureModule* VideoCaptureIos::Create(const int32_t capture_id,
[[RTCVideoCaptureIosObjC alloc] initWithOwner:capture_module
captureId:capture_module->id_];
if (!capture_module->capture_device_) {
return NULL;
return nullptr;
}
if (![capture_module->capture_device_ setCaptureDeviceByUniqueId:[
[NSString alloc] initWithCString:deviceUniqueIdUTF8
encoding:NSUTF8StringEncoding]]) {
return NULL;
return nullptr;
}
return capture_module;
}

View File

@ -20,7 +20,6 @@
//v4l includes
#include <linux/videodev2.h>
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/system_wrappers/include/trace.h"
@ -31,14 +30,7 @@ namespace videocapturemodule
VideoCaptureModule::DeviceInfo*
VideoCaptureImpl::CreateDeviceInfo(const int32_t id)
{
videocapturemodule::DeviceInfoLinux *deviceInfo =
new videocapturemodule::DeviceInfoLinux(id);
if (!deviceInfo)
{
deviceInfo = NULL;
}
return deviceInfo;
return new videocapturemodule::DeviceInfoLinux(id);
}
DeviceInfoLinux::DeviceInfoLinux(const int32_t id)

View File

@ -21,26 +21,22 @@
#include <iostream>
#include <new>
#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/video_capture/linux/video_capture_linux.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/system_wrappers/include/trace.h"
namespace webrtc
{
namespace videocapturemodule
{
VideoCaptureModule* VideoCaptureImpl::Create(const int32_t id,
const char* deviceUniqueId)
{
RefCountImpl<videocapturemodule::VideoCaptureModuleV4L2>* implementation =
new RefCountImpl<videocapturemodule::VideoCaptureModuleV4L2>(id);
namespace webrtc {
namespace videocapturemodule {
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create(
const int32_t id,
const char* deviceUniqueId) {
rtc::scoped_refptr<VideoCaptureModuleV4L2> implementation(
new rtc::RefCountedObject<VideoCaptureModuleV4L2>(id));
if (!implementation || implementation->Init(deviceUniqueId) != 0)
{
delete implementation;
implementation = NULL;
}
if (implementation->Init(deviceUniqueId) != 0)
return nullptr;
return implementation;
}

View File

@ -15,10 +15,11 @@
#include <QuickTime/QuickTime.h>
#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/video_capture/device_info_impl.h"
#include "webrtc/modules/video_capture/video_capture_config.h"
#include "webrtc/modules/video_capture/video_capture_impl.h"
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/system_wrappers/include/trace.h"
// 10.4 support must be decided runtime. We will just decide which framework to
@ -109,25 +110,23 @@ bool CheckQTVersion()
* version buffer
*/
VideoCaptureModule* VideoCaptureImpl::Create(
const int32_t id, const char* deviceUniqueIdUTF8)
{
if (webrtc::videocapturemodule::CheckOSVersion() == false)
{
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create(
const int32_t id,
const char* deviceUniqueIdUTF8) {
if (!CheckOSVersion()) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
"OS version is too old. Could not create video capture "
"module. Returning NULL");
return NULL;
return nullptr;
}
#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version
if (webrtc::videocapturemodule::CheckQTVersion() == false)
if (!CheckQTVersion())
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
"QuickTime version is too old. Could not create video "
"capture module. Returning NULL");
return NULL;
return nullptr;
}
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
@ -135,17 +134,8 @@ VideoCaptureModule* VideoCaptureImpl::Create(
"QuickTime framework to capture video",
__FILE__, __LINE__);
RefCountImpl<videocapturemodule::VideoCaptureMacQuickTime>*
newCaptureModule =
new RefCountImpl<videocapturemodule::VideoCaptureMacQuickTime>(id);
if (!newCaptureModule)
{
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id,
"could not Create for unique device %s, !newCaptureModule",
deviceUniqueIdUTF8);
return NULL;
}
rtc::scoped_refptr<VideoCaptureMacQuickTime> newCaptureModule(
new rtc::RefCountedObject<VideoCaptureMacQuickTime>(id));
if (newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0)
{
@ -153,8 +143,7 @@ VideoCaptureModule* VideoCaptureImpl::Create(
"could not Create for unique device %s, "
"newCaptureModule->Init()!=0",
deviceUniqueIdUTF8);
delete newCaptureModule;
return NULL;
return nullptr;
}
// Successfully created VideoCaptureMacQuicktime. Return it
@ -169,23 +158,15 @@ VideoCaptureModule* VideoCaptureImpl::Create(
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
"Using QTKit framework to capture video", id);
RefCountImpl<videocapturemodule::VideoCaptureMacQTKit>* newCaptureModule =
new RefCountImpl<videocapturemodule::VideoCaptureMacQTKit>(id);
rtc::scoped_refptr<VideoCaptureMacQTKit> newCaptureModule(
new rtc::RefCountedObject<VideoCaptureMacQTKit>(id));
if(!newCaptureModule)
{
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id,
"could not Create for unique device %s, !newCaptureModule",
deviceUniqueIdUTF8);
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);
delete newCaptureModule;
return NULL;
return nullptr;
}
// Successfully created VideoCaptureMacQuicktime. Return it

View File

@ -12,10 +12,10 @@
#include "webrtc/modules/video_capture/video_capture_impl.h"
namespace webrtc
{
namespace webrtc {
VideoCaptureModule* VideoCaptureFactory::Create(const int32_t id,
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureFactory::Create(
const int32_t id,
const char* deviceUniqueIdUTF8) {
#if defined(ANDROID)
return nullptr;
@ -24,7 +24,8 @@ VideoCaptureModule* VideoCaptureFactory::Create(const int32_t id,
#endif
}
VideoCaptureModule* VideoCaptureFactory::Create(const int32_t id,
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureFactory::Create(
const int32_t id,
VideoCaptureExternal*& externalCapture) {
return videocapturemodule::VideoCaptureImpl::Create(id, externalCapture);
}

View File

@ -24,14 +24,16 @@ class VideoCaptureFactory {
// 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 int32_t id,
const char* deviceUniqueIdUTF8);
static rtc::scoped_refptr<VideoCaptureModule> Create(
const int32_t id,
const char* 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 int32_t id,
VideoCaptureExternal*& externalCapture);
static rtc::scoped_refptr<VideoCaptureModule> Create(
const int32_t id,
VideoCaptureExternal*& externalCapture);
static VideoCaptureModule::DeviceInfo* CreateDeviceInfo(
const int32_t id);

View File

@ -12,6 +12,7 @@
#include <stdlib.h>
#include "webrtc/base/refcount.h"
#include "webrtc/base/trace_event.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/include/module_common_types.h"
@ -19,22 +20,17 @@
#include "webrtc/system_wrappers/include/clock.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
#include "webrtc/system_wrappers/include/logging.h"
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/system_wrappers/include/tick_util.h"
namespace webrtc
{
namespace videocapturemodule
{
VideoCaptureModule* VideoCaptureImpl::Create(
namespace webrtc {
namespace videocapturemodule {
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create(
const int32_t id,
VideoCaptureExternal*& externalCapture)
{
RefCountImpl<VideoCaptureImpl>* implementation =
new RefCountImpl<VideoCaptureImpl>(id);
externalCapture = implementation;
return implementation;
VideoCaptureExternal*& externalCapture) {
rtc::scoped_refptr<VideoCaptureImpl> implementation(
new rtc::RefCountedObject<VideoCaptureImpl>(id));
externalCapture = implementation.get();
return implementation;
}
const char* VideoCaptureImpl::CurrentDeviceName() const

View File

@ -15,6 +15,7 @@
* video_capture_impl.h
*/
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/common_video/rotation.h"
#include "webrtc/modules/video_capture/video_capture.h"
@ -38,8 +39,9 @@ public:
* 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 int32_t id,
const char* deviceUniqueIdUTF8);
static rtc::scoped_refptr<VideoCaptureModule> Create(
const int32_t id,
const char* deviceUniqueIdUTF8);
/*
* Create a video capture module object used for external capture.
@ -47,8 +49,9 @@ public:
* id - unique identifier of this video capture module object
* externalCapture - [out] interface to call when a new frame is captured.
*/
static VideoCaptureModule* Create(const int32_t id,
VideoCaptureExternal*& externalCapture);
static rtc::scoped_refptr<VideoCaptureModule> Create(
const int32_t id,
VideoCaptureExternal*& externalCapture);
static DeviceInfo* CreateDeviceInfo(const int32_t id);

View File

@ -13,7 +13,6 @@
#include "webrtc/modules/video_capture/video_capture_config.h"
#include "webrtc/modules/video_capture/video_capture_delay.h"
#include "webrtc/modules/video_capture/windows/help_functions_ds.h"
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/system_wrappers/include/trace.h"
#include <Dvdmedia.h>

View File

@ -8,9 +8,10 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/video_capture/windows/video_capture_ds.h"
#include "webrtc/modules/video_capture/windows/video_capture_mf.h"
#include "webrtc/system_wrappers/include/ref_count.h"
namespace webrtc {
namespace videocapturemodule {
@ -22,16 +23,17 @@ VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo(
return DeviceInfoDS::Create(id);
}
VideoCaptureModule* VideoCaptureImpl::Create(const int32_t id,
const char* device_id) {
if (device_id == NULL)
return NULL;
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create(
const int32_t id,
const char* device_id) {
if (device_id == nullptr)
return nullptr;
// TODO(tommi): Use Media Foundation implementation for Vista and up.
RefCountImpl<VideoCaptureDS>* capture = new RefCountImpl<VideoCaptureDS>(id);
rtc::scoped_refptr<VideoCaptureDS> capture(
new rtc::RefCountedObject<VideoCaptureDS>(id));
if (capture->Init(id, device_id) != 0) {
delete capture;
capture = NULL;
return nullptr;
}
return capture;

View File

@ -27,7 +27,6 @@ static_library("system_wrappers") {
"include/fix_interlocked_exchange_pointer_win.h",
"include/logging.h",
"include/metrics.h",
"include/ref_count.h",
"include/rtp_to_ntp.h",
"include/rw_lock_wrapper.h",
"include/scoped_vector.h",

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2012 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.
*/
#ifndef SYSTEM_WRAPPERS_INCLUDE_REF_COUNT_H_
#define SYSTEM_WRAPPERS_INCLUDE_REF_COUNT_H_
#include "webrtc/system_wrappers/include/atomic32.h"
namespace webrtc {
// This class can be used for instantiating
// reference counted objects.
// int32_t AddRef() and int32_t Release().
// Usage:
// RefCountImpl<T>* implementation = new RefCountImpl<T>(p);
//
// Example:
// class MyInterface {
// public:
// virtual void DoSomething() = 0;
// virtual int32_t AddRef() = 0;
// virtual int32_t Release() = 0:
// private:
// virtual ~MyInterface(){};
// }
// class MyImplementation : public MyInterface {
// public:
// virtual DoSomething() { printf("hello"); };
// };
// MyImplementation* CreateMyImplementation() {
// RefCountImpl<MyImplementation>* implementation =
// new RefCountImpl<MyImplementation>();
// return implementation;
// }
template <class T>
class RefCountImpl : public T {
public:
RefCountImpl() : ref_count_(0) {}
template<typename P>
explicit RefCountImpl(P p) : T(p), ref_count_(0) {}
template<typename P1, typename P2>
RefCountImpl(P1 p1, P2 p2) : T(p1, p2), ref_count_(0) {}
template<typename P1, typename P2, typename P3>
RefCountImpl(P1 p1, P2 p2, P3 p3) : T(p1, p2, p3), ref_count_(0) {}
template<typename P1, typename P2, typename P3, typename P4>
RefCountImpl(P1 p1, P2 p2, P3 p3, P4 p4) : T(p1, p2, p3, p4), ref_count_(0) {}
template<typename P1, typename P2, typename P3, typename P4, typename P5>
RefCountImpl(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
: T(p1, p2, p3, p4, p5), ref_count_(0) {}
int32_t AddRef() const override {
return ++ref_count_;
}
int32_t Release() const override {
int32_t ref_count;
ref_count = --ref_count_;
if (ref_count == 0)
delete this;
return ref_count;
}
protected:
mutable Atomic32 ref_count_;
};
} // namespace webrtc
#endif // SYSTEM_WRAPPERS_INCLUDE_REF_COUNT_H_

View File

@ -35,7 +35,6 @@
'include/logging.h',
'include/metrics.h',
'include/ntp_time.h',
'include/ref_count.h',
'include/rtp_to_ntp.h',
'include/rw_lock_wrapper.h',
'include/scoped_vector.h',

View File

@ -79,17 +79,13 @@ void VcmCapturer::Stop() {
}
void VcmCapturer::Destroy() {
if (vcm_ == NULL) {
if (!vcm_)
return;
}
vcm_->StopCapture();
vcm_->DeRegisterCaptureDataCallback();
vcm_->Release();
// TODO(pbos): How do I destroy the VideoCaptureModule? This still leaves
// non-freed memory.
vcm_ = NULL;
// Release reference to VCM.
vcm_ = nullptr;
}
VcmCapturer::~VcmCapturer() { Destroy(); }

View File

@ -11,6 +11,7 @@
#define WEBRTC_TEST_VCM_CAPTURER_H_
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/common_types.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/video_capture/video_capture.h"
@ -41,7 +42,7 @@ class VcmCapturer : public VideoCapturer, public VideoCaptureDataCallback {
rtc::CriticalSection crit_;
bool started_ GUARDED_BY(crit_);
VideoCaptureModule* vcm_;
rtc::scoped_refptr<VideoCaptureModule> vcm_;
VideoCaptureCapability capability_;
};
} // test

View File

@ -14,7 +14,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/event.h"
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/base/refcount.h"
#include "webrtc/system_wrappers/include/scoped_vector.h"
#include "webrtc/test/fake_texture_frame.h"
#include "webrtc/video/send_statistics_proxy.h"

View File

@ -28,7 +28,6 @@
#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_format_vp9.h"
#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
#include "webrtc/system_wrappers/include/ref_count.h"
#include "webrtc/system_wrappers/include/sleep.h"
#include "webrtc/test/call_test.h"
#include "webrtc/test/configurable_frame_size_encoder.h"

View File

@ -54,14 +54,9 @@ SharedData::~SharedData()
Trace::ReturnTrace();
}
void SharedData::set_audio_device(AudioDeviceModule* audio_device)
{
// AddRef first in case the pointers are equal.
if (audio_device)
audio_device->AddRef();
if (_audioDevicePtr)
_audioDevicePtr->Release();
_audioDevicePtr = audio_device;
void SharedData::set_audio_device(
const rtc::scoped_refptr<AudioDeviceModule>& audio_device) {
_audioDevicePtr = audio_device;
}
void SharedData::set_audio_processing(AudioProcessing* audioproc) {

View File

@ -14,6 +14,7 @@
#include <memory>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/modules/audio_device/include/audio_device.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/modules/utility/include/process_thread.h"
@ -38,8 +39,9 @@ public:
uint32_t instance_id() const { return _instanceId; }
Statistics& statistics() { return _engineStatistics; }
ChannelManager& channel_manager() { return _channelManager; }
AudioDeviceModule* audio_device() { return _audioDevicePtr; }
void set_audio_device(AudioDeviceModule* audio_device);
AudioDeviceModule* audio_device() { return _audioDevicePtr.get(); }
void set_audio_device(
const rtc::scoped_refptr<AudioDeviceModule>& audio_device);
AudioProcessing* audio_processing() { return audioproc_.get(); }
void set_audio_processing(AudioProcessing* audio_processing);
TransmitMixer* transmit_mixer() { return _transmitMixerPtr; }
@ -67,7 +69,7 @@ protected:
rtc::CriticalSection _apiCritPtr;
ChannelManager _channelManager;
Statistics _engineStatistics;
AudioDeviceModule* _audioDevicePtr;
rtc::scoped_refptr<AudioDeviceModule> _audioDevicePtr;
OutputMixer* _outputMixerPtr;
TransmitMixer* _transmitMixerPtr;
std::unique_ptr<AudioProcessing> audioproc_;