diff --git a/src/modules/rtp_rtcp/source/rtcp_sender.cc b/src/modules/rtp_rtcp/source/rtcp_sender.cc index 78af10929..5d2e7dd72 100644 --- a/src/modules/rtp_rtcp/source/rtcp_sender.cc +++ b/src/modules/rtp_rtcp/source/rtcp_sender.cc @@ -360,7 +360,9 @@ WebRtc_Word32 RTCPSender::CNAME(char cName[RTCP_CNAME_SIZE]) { } WebRtc_Word32 RTCPSender::SetCNAME(const char cName[RTCP_CNAME_SIZE]) { - assert(cName); + if (!cName) + return -1; + CriticalSectionScoped lock(_criticalSectionRTCPSender); _CNAME[RTCP_CNAME_SIZE - 1] = 0; strncpy(_CNAME, cName, RTCP_CNAME_SIZE - 1); diff --git a/src/voice_engine/main/interface/voe_base.h b/src/voice_engine/main/interface/voe_base.h index be6849cc3..28f465e6d 100644 --- a/src/voice_engine/main/interface/voe_base.h +++ b/src/voice_engine/main/interface/voe_base.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * 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 @@ -65,12 +65,10 @@ public: static VoiceEngine* Create(); // Deletes a created VoiceEngine object and releases the utilized resources. - // If |ignoreRefCounters| is set to false, all reference counters must be - // zero to enable a valid release of the allocated resources. When set to - // true, a release of all resources allocated by the VoE is performed - // without checking the reference counter state. - static bool Delete(VoiceEngine*& voiceEngine, - bool ignoreRefCounters = false); + // Note that if there are outstanding references held via other interfaces, + // the voice engine instance will not actually be deleted until those + // references have been released. + static bool Delete(VoiceEngine*& voiceEngine); // Specifies the amount and type of trace information which will be // created by the VoiceEngine. diff --git a/src/voice_engine/main/source/ref_count.cc b/src/voice_engine/main/source/ref_count.cc deleted file mode 100644 index 9723bc3ca..000000000 --- a/src/voice_engine/main/source/ref_count.cc +++ /dev/null @@ -1,60 +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. - */ - -#include "critical_section_wrapper.h" -#include "ref_count.h" - -namespace webrtc { - -namespace voe { - -RefCount::RefCount() : - _count(0), - _crit(*CriticalSectionWrapper::CreateCriticalSection()) -{ -} - -RefCount::~RefCount() -{ - delete &_crit; -} - -RefCount& -RefCount::operator++(int) -{ - CriticalSectionScoped lock(&_crit); - _count++; - return *this; -} - -RefCount& -RefCount::operator--(int) -{ - CriticalSectionScoped lock(&_crit); - _count--; - return *this; -} - -void -RefCount::Reset() -{ - CriticalSectionScoped lock(&_crit); - _count = 0; -} - -int -RefCount::GetCount() const -{ - return _count; -} - -} // namespace voe - -} // namespace webrtc diff --git a/src/voice_engine/main/source/ref_count.h b/src/voice_engine/main/source/ref_count.h deleted file mode 100644 index e8c0a8183..000000000 --- a/src/voice_engine/main/source/ref_count.h +++ /dev/null @@ -1,36 +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. - */ - -#ifndef WEBRTC_VOICE_ENGINE_REF_COUNT_H -#define WEBRTC_VOICE_ENGINE_REF_COUNT_H - -namespace webrtc { -class CriticalSectionWrapper; - -namespace voe { - -class RefCount -{ -public: - RefCount(); - ~RefCount(); - RefCount& operator++(int); - RefCount& operator--(int); - void Reset(); - int GetCount() const; -private: - volatile int _count; - CriticalSectionWrapper& _crit; -}; - -} // namespace voe - -} // namespace webrtc -#endif // #ifndef WEBRTC_VOICE_ENGINE_REF_COUNT_H diff --git a/src/voice_engine/main/source/voe_audio_processing_impl.cc b/src/voice_engine/main/source/voe_audio_processing_impl.cc index 8f518d019..64540a5cd 100644 --- a/src/voice_engine/main/source/voe_audio_processing_impl.cc +++ b/src/voice_engine/main/source/voe_audio_processing_impl.cc @@ -41,9 +41,8 @@ VoEAudioProcessing* VoEAudioProcessing::GetInterface(VoiceEngine* voiceEngine) { return NULL; } VoiceEngineImpl* s = reinterpret_cast(voiceEngine); - VoEAudioProcessingImpl* d = s; - (*d)++; - return (d); + s->AddRef(); + return s; #endif } @@ -59,21 +58,6 @@ VoEAudioProcessingImpl::~VoEAudioProcessingImpl() { "VoEAudioProcessingImpl::~VoEAudioProcessingImpl() - dtor"); } -int VoEAudioProcessingImpl::Release() { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoEAudioProcessing::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) { - Reset(); // reset reference counter to zero => OK to delete VE - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoEAudioProcessing reference counter = %d", refCount); - return (refCount); -} - int VoEAudioProcessingImpl::SetNsStatus(bool enable, NsModes mode) { WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), "SetNsStatus(enable=%d, mode=%d)", enable, mode); diff --git a/src/voice_engine/main/source/voe_audio_processing_impl.h b/src/voice_engine/main/source/voe_audio_processing_impl.h index 11c4ef5d7..a798c37e6 100644 --- a/src/voice_engine/main/source/voe_audio_processing_impl.h +++ b/src/voice_engine/main/source/voe_audio_processing_impl.h @@ -13,17 +13,12 @@ #include "voe_audio_processing.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoEAudioProcessingImpl - : public VoEAudioProcessing, - public voe::RefCount { +class VoEAudioProcessingImpl : public VoEAudioProcessing { public: - virtual int Release(); - virtual int SetNsStatus(bool enable, NsModes mode = kNsUnchanged); virtual int GetNsStatus(bool& enabled, NsModes& mode); diff --git a/src/voice_engine/main/source/voe_base_impl.cc b/src/voice_engine/main/source/voe_base_impl.cc index cf73e6500..590e661c8 100644 --- a/src/voice_engine/main/source/voe_base_impl.cc +++ b/src/voice_engine/main/source/voe_base_impl.cc @@ -40,10 +40,9 @@ VoEBase* VoEBase::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = reinterpret_cast (voiceEngine); - VoEBaseImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; } VoEBaseImpl::VoEBaseImpl(voe::SharedData* shared) : @@ -66,24 +65,6 @@ VoEBaseImpl::~VoEBaseImpl() delete &_callbackCritSect; } -int VoEBaseImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoEBaseImpl::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoEBaseImpl reference counter = %d", refCount); - return (refCount); -} - void VoEBaseImpl::OnErrorIsReported(const ErrorCode error) { CriticalSectionScoped cs(&_callbackCritSect); diff --git a/src/voice_engine/main/source/voe_base_impl.h b/src/voice_engine/main/source/voe_base_impl.h index 264c4adb5..0eb44fa3c 100644 --- a/src/voice_engine/main/source/voe_base_impl.h +++ b/src/voice_engine/main/source/voe_base_impl.h @@ -14,7 +14,6 @@ #include "voe_base.h" #include "module_common_types.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc @@ -23,13 +22,10 @@ namespace webrtc class ProcessThread; class VoEBaseImpl: public VoEBase, - public voe::RefCount, public AudioTransport, public AudioDeviceObserver { public: - virtual int Release(); - virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer); virtual int DeRegisterVoiceEngineObserver(); diff --git a/src/voice_engine/main/source/voe_call_report_impl.cc b/src/voice_engine/main/source/voe_call_report_impl.cc index 7875ec6b8..ef4c39c29 100644 --- a/src/voice_engine/main/source/voe_call_report_impl.cc +++ b/src/voice_engine/main/source/voe_call_report_impl.cc @@ -30,11 +30,9 @@ VoECallReport* VoECallReport::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoECallReportImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -54,24 +52,6 @@ VoECallReportImpl::~VoECallReportImpl() delete &_file; } -int VoECallReportImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoECallReportImpl::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoECallReportImpl reference counter = %d", refCount); - return (refCount); -} - int VoECallReportImpl::ResetCallReportStatistics(int channel) { WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), diff --git a/src/voice_engine/main/source/voe_call_report_impl.h b/src/voice_engine/main/source/voe_call_report_impl.h index 2a39bd6d9..fcc708a83 100644 --- a/src/voice_engine/main/source/voe_call_report_impl.h +++ b/src/voice_engine/main/source/voe_call_report_impl.h @@ -13,7 +13,6 @@ #include "voe_call_report.h" -#include "ref_count.h" #include "shared_data.h" @@ -21,12 +20,9 @@ namespace webrtc { class FileWrapper; -class VoECallReportImpl: public VoECallReport, - public voe::RefCount +class VoECallReportImpl: public VoECallReport { public: - virtual int Release(); - virtual int ResetCallReportStatistics(int channel); virtual int GetEchoMetricSummary(EchoStatistics& stats); diff --git a/src/voice_engine/main/source/voe_codec_impl.cc b/src/voice_engine/main/source/voe_codec_impl.cc index b7623336e..93f4f18b0 100644 --- a/src/voice_engine/main/source/voe_codec_impl.cc +++ b/src/voice_engine/main/source/voe_codec_impl.cc @@ -29,11 +29,9 @@ VoECodec* VoECodec::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoECodecImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -51,24 +49,6 @@ VoECodecImpl::~VoECodecImpl() "~VoECodecImpl() - dtor"); } -int VoECodecImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoECodecImpl::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoECodecImpl reference counter = %d", refCount); - return (refCount); -} - int VoECodecImpl::NumOfCodecs() { WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), diff --git a/src/voice_engine/main/source/voe_codec_impl.h b/src/voice_engine/main/source/voe_codec_impl.h index 8fef9fed2..eb955ece9 100644 --- a/src/voice_engine/main/source/voe_codec_impl.h +++ b/src/voice_engine/main/source/voe_codec_impl.h @@ -13,18 +13,14 @@ #include "voe_codec.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoECodecImpl: public VoECodec, - public voe::RefCount +class VoECodecImpl: public VoECodec { public: - virtual int Release(); - virtual int NumOfCodecs(); virtual int GetCodec(int index, CodecInst& codec); diff --git a/src/voice_engine/main/source/voe_dtmf_impl.cc b/src/voice_engine/main/source/voe_dtmf_impl.cc index b9ce67e93..e7c22bf5b 100644 --- a/src/voice_engine/main/source/voe_dtmf_impl.cc +++ b/src/voice_engine/main/source/voe_dtmf_impl.cc @@ -29,11 +29,9 @@ VoEDtmf* VoEDtmf::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoEDtmfImpl* d = s; - ( *d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -54,24 +52,6 @@ VoEDtmfImpl::~VoEDtmfImpl() "VoEDtmfImpl::~VoEDtmfImpl() - dtor"); } -int VoEDtmfImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoEDtmf::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); // reset reference counter to zero => OK to delete VE - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoEDtmf reference counter = %d", refCount); - return (refCount); -} - int VoEDtmfImpl::SendTelephoneEvent(int channel, int eventCode, bool outOfBand, diff --git a/src/voice_engine/main/source/voe_dtmf_impl.h b/src/voice_engine/main/source/voe_dtmf_impl.h index 27fa68bbc..ad3874bf1 100644 --- a/src/voice_engine/main/source/voe_dtmf_impl.h +++ b/src/voice_engine/main/source/voe_dtmf_impl.h @@ -13,18 +13,14 @@ #include "voe_dtmf.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoEDtmfImpl : public VoEDtmf, - public voe::RefCount +class VoEDtmfImpl : public VoEDtmf { public: - virtual int Release(); - virtual int SendTelephoneEvent( int channel, int eventCode, diff --git a/src/voice_engine/main/source/voe_encryption_impl.cc b/src/voice_engine/main/source/voe_encryption_impl.cc index b84fa1b37..4ac8ada53 100644 --- a/src/voice_engine/main/source/voe_encryption_impl.cc +++ b/src/voice_engine/main/source/voe_encryption_impl.cc @@ -28,11 +28,9 @@ VoEEncryption* VoEEncryption::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoEEncryptionImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -50,25 +48,6 @@ VoEEncryptionImpl::~VoEEncryptionImpl() "VoEEncryptionImpl::~VoEEncryptionImpl() - dtor"); } -int VoEEncryptionImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoEEncryption::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - // reset reference counter to zero => OK to delete VE - Reset(); - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoEEncryption reference counter = %d", refCount); - return (refCount); -} - int VoEEncryptionImpl::EnableSRTPSend( int channel, CipherTypes cipherType, diff --git a/src/voice_engine/main/source/voe_encryption_impl.h b/src/voice_engine/main/source/voe_encryption_impl.h index e2aa296c0..76124d415 100644 --- a/src/voice_engine/main/source/voe_encryption_impl.h +++ b/src/voice_engine/main/source/voe_encryption_impl.h @@ -13,18 +13,13 @@ #include "voe_encryption.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoEEncryptionImpl : public VoEEncryption, - public voe::RefCount +class VoEEncryptionImpl : public VoEEncryption { public: - - virtual int Release(); - // SRTP virtual int EnableSRTPSend( int channel, diff --git a/src/voice_engine/main/source/voe_external_media_impl.cc b/src/voice_engine/main/source/voe_external_media_impl.cc index 998198eb4..31d03abde 100644 --- a/src/voice_engine/main/source/voe_external_media_impl.cc +++ b/src/voice_engine/main/source/voe_external_media_impl.cc @@ -29,10 +29,9 @@ VoEExternalMedia* VoEExternalMedia::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = reinterpret_cast (voiceEngine); - VoEExternalMediaImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -51,24 +50,6 @@ VoEExternalMediaImpl::~VoEExternalMediaImpl() "~VoEExternalMediaImpl() - dtor"); } -int VoEExternalMediaImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(shared_->instance_id(), -1), - "VoEExternalMedia::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); - shared_->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(shared_->instance_id(), -1), - "VoEExternalMedia reference counter = %d", refCount); - return (refCount); -} - int VoEExternalMediaImpl::RegisterExternalMediaProcessing( int channel, ProcessingTypes type, diff --git a/src/voice_engine/main/source/voe_external_media_impl.h b/src/voice_engine/main/source/voe_external_media_impl.h index 36696e0f8..c92239230 100644 --- a/src/voice_engine/main/source/voe_external_media_impl.h +++ b/src/voice_engine/main/source/voe_external_media_impl.h @@ -13,17 +13,13 @@ #include "voe_external_media.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoEExternalMediaImpl : public VoEExternalMedia, - public voe::RefCount +class VoEExternalMediaImpl : public VoEExternalMedia { public: - virtual int Release(); - virtual int RegisterExternalMediaProcessing( int channel, ProcessingTypes type, diff --git a/src/voice_engine/main/source/voe_file_impl.cc b/src/voice_engine/main/source/voe_file_impl.cc index 06b45d13d..a69079615 100644 --- a/src/voice_engine/main/source/voe_file_impl.cc +++ b/src/voice_engine/main/source/voe_file_impl.cc @@ -31,11 +31,9 @@ VoEFile* VoEFile::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoEFileImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -53,24 +51,6 @@ VoEFileImpl::~VoEFileImpl() "VoEFileImpl::~VoEFileImpl() - dtor"); } -int VoEFileImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoEFile::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoEFile reference counter = %d", refCount); - return (refCount); -} - int VoEFileImpl::StartPlayingFileLocally( int channel, const char fileNameUTF8[1024], diff --git a/src/voice_engine/main/source/voe_file_impl.h b/src/voice_engine/main/source/voe_file_impl.h index 20ac8e5a1..dcb564269 100644 --- a/src/voice_engine/main/source/voe_file_impl.h +++ b/src/voice_engine/main/source/voe_file_impl.h @@ -13,16 +13,12 @@ #include "voe_file.h" #include "shared_data.h" -#include "ref_count.h" namespace webrtc { -class VoEFileImpl : public VoEFile, - public voe::RefCount +class VoEFileImpl : public VoEFile { public: - virtual int Release(); - // Playout file locally virtual int StartPlayingFileLocally( diff --git a/src/voice_engine/main/source/voe_hardware_impl.cc b/src/voice_engine/main/source/voe_hardware_impl.cc index c6ed4aef8..851967e40 100644 --- a/src/voice_engine/main/source/voe_hardware_impl.cc +++ b/src/voice_engine/main/source/voe_hardware_impl.cc @@ -30,11 +30,9 @@ VoEHardware* VoEHardware::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoEHardwareImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -65,24 +63,6 @@ VoEHardwareImpl::~VoEHardwareImpl() } } -int VoEHardwareImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoEHardwareImpl::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoEHardwareImpl reference counter = %d", refCount); - return (refCount); -} - int VoEHardwareImpl::SetAudioDeviceLayer(AudioLayers audioLayer) { WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), diff --git a/src/voice_engine/main/source/voe_hardware_impl.h b/src/voice_engine/main/source/voe_hardware_impl.h index 4a5a3c35f..c80122808 100644 --- a/src/voice_engine/main/source/voe_hardware_impl.h +++ b/src/voice_engine/main/source/voe_hardware_impl.h @@ -13,19 +13,15 @@ #include "voe_hardware.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { class CpuWrapper; -class VoEHardwareImpl: public VoEHardware, - public voe::RefCount +class VoEHardwareImpl: public VoEHardware { public: - virtual int Release(); - virtual int GetNumOfRecordingDevices(int& devices); virtual int GetNumOfPlayoutDevices(int& devices); diff --git a/src/voice_engine/main/source/voe_neteq_stats_impl.cc b/src/voice_engine/main/source/voe_neteq_stats_impl.cc index b4a8ecafd..c82f4143f 100644 --- a/src/voice_engine/main/source/voe_neteq_stats_impl.cc +++ b/src/voice_engine/main/source/voe_neteq_stats_impl.cc @@ -29,11 +29,9 @@ VoENetEqStats* VoENetEqStats::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoENetEqStatsImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -51,24 +49,6 @@ VoENetEqStatsImpl::~VoENetEqStatsImpl() "VoENetEqStatsImpl::~VoENetEqStatsImpl() - dtor"); } -int VoENetEqStatsImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoENetEqStats::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); // reset reference counter to zero => OK to delete VE - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoENetEqStats reference counter = %d", refCount); - return (refCount); -} - int VoENetEqStatsImpl::GetNetworkStatistics(int channel, NetworkStatistics& stats) { diff --git a/src/voice_engine/main/source/voe_neteq_stats_impl.h b/src/voice_engine/main/source/voe_neteq_stats_impl.h index e261ef410..1b077b383 100644 --- a/src/voice_engine/main/source/voe_neteq_stats_impl.h +++ b/src/voice_engine/main/source/voe_neteq_stats_impl.h @@ -13,17 +13,13 @@ #include "voe_neteq_stats.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoENetEqStatsImpl : public VoENetEqStats, - public voe::RefCount +class VoENetEqStatsImpl : public VoENetEqStats { public: - virtual int Release(); - virtual int GetNetworkStatistics(int channel, NetworkStatistics& stats); diff --git a/src/voice_engine/main/source/voe_network_impl.cc b/src/voice_engine/main/source/voe_network_impl.cc index 317a09a1a..174abcab2 100644 --- a/src/voice_engine/main/source/voe_network_impl.cc +++ b/src/voice_engine/main/source/voe_network_impl.cc @@ -28,11 +28,9 @@ VoENetwork* VoENetwork::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoENetworkImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -50,24 +48,6 @@ VoENetworkImpl::~VoENetworkImpl() "~VoENetworkImpl() - dtor"); } -int VoENetworkImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoENetworkImpl::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoENetworkImpl reference counter = %d", refCount); - return (refCount); -} - int VoENetworkImpl::RegisterExternalTransport(int channel, Transport& transport) { @@ -264,7 +244,8 @@ int VoENetworkImpl::GetLocalIP(char ipAddr[64], bool ipv6) return -1; } - char localIPAddr[64]; + // Use a buffer big enough for IPv6 addresses and initialize it with zeros. + char localIPAddr[256] = {0}; if (ipv6) { diff --git a/src/voice_engine/main/source/voe_network_impl.h b/src/voice_engine/main/source/voe_network_impl.h index fa5d8c535..b159c81b5 100644 --- a/src/voice_engine/main/source/voe_network_impl.h +++ b/src/voice_engine/main/source/voe_network_impl.h @@ -13,19 +13,15 @@ #include "voe_network.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoENetworkImpl: public VoENetwork, - public voe::RefCount +class VoENetworkImpl: public VoENetwork { public: - virtual int Release(); - virtual int RegisterExternalTransport(int channel, Transport& transport); virtual int DeRegisterExternalTransport(int channel); diff --git a/src/voice_engine/main/source/voe_rtp_rtcp_impl.cc b/src/voice_engine/main/source/voe_rtp_rtcp_impl.cc index 62609b878..737d6ba5f 100644 --- a/src/voice_engine/main/source/voe_rtp_rtcp_impl.cc +++ b/src/voice_engine/main/source/voe_rtp_rtcp_impl.cc @@ -29,10 +29,9 @@ VoERTP_RTCP* VoERTP_RTCP::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = reinterpret_cast (voiceEngine); - VoERTP_RTCPImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -50,24 +49,6 @@ VoERTP_RTCPImpl::~VoERTP_RTCPImpl() "VoERTP_RTCPImpl::~VoERTP_RTCPImpl() - dtor"); } -int VoERTP_RTCPImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoERTP_RTCP::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); // reset reference counter to zero => OK to delete VE - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoERTP_RTCP reference counter = %d", refCount); - return (refCount); -} - int VoERTP_RTCPImpl::RegisterRTPObserver(int channel, VoERTPObserver& observer) { WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), diff --git a/src/voice_engine/main/source/voe_rtp_rtcp_impl.h b/src/voice_engine/main/source/voe_rtp_rtcp_impl.h index 845b93fc2..aa060b44f 100644 --- a/src/voice_engine/main/source/voe_rtp_rtcp_impl.h +++ b/src/voice_engine/main/source/voe_rtp_rtcp_impl.h @@ -13,17 +13,13 @@ #include "voe_rtp_rtcp.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoERTP_RTCPImpl : public VoERTP_RTCP, - public voe::RefCount +class VoERTP_RTCPImpl : public VoERTP_RTCP { public: - - virtual int Release(); // Registration of observers for RTP and RTCP callbacks virtual int RegisterRTPObserver(int channel, VoERTPObserver& observer); diff --git a/src/voice_engine/main/source/voe_video_sync_impl.cc b/src/voice_engine/main/source/voe_video_sync_impl.cc index 5b6773b87..a509f7025 100644 --- a/src/voice_engine/main/source/voe_video_sync_impl.cc +++ b/src/voice_engine/main/source/voe_video_sync_impl.cc @@ -27,11 +27,9 @@ VoEVideoSync* VoEVideoSync::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoEVideoSyncImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -49,24 +47,6 @@ VoEVideoSyncImpl::~VoEVideoSyncImpl() "VoEVideoSyncImpl::~VoEVideoSyncImpl() - dtor"); } -int VoEVideoSyncImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoEVideoSync::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); // reset reference counter to zero => OK to delete VE - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoEVideoSync reference counter = %d", refCount); - return (refCount); -} - int VoEVideoSyncImpl::GetPlayoutTimestamp(int channel, unsigned int& timestamp) { WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), diff --git a/src/voice_engine/main/source/voe_video_sync_impl.h b/src/voice_engine/main/source/voe_video_sync_impl.h index c4c946f77..1b75f05f7 100644 --- a/src/voice_engine/main/source/voe_video_sync_impl.h +++ b/src/voice_engine/main/source/voe_video_sync_impl.h @@ -13,17 +13,13 @@ #include "voe_video_sync.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoEVideoSyncImpl : public VoEVideoSync, - public voe::RefCount +class VoEVideoSyncImpl : public VoEVideoSync { public: - virtual int Release(); - virtual int GetPlayoutBufferSize(int& bufferMs); virtual int SetMinimumPlayoutDelay(int channel, int delayMs); diff --git a/src/voice_engine/main/source/voe_volume_control_impl.cc b/src/voice_engine/main/source/voe_volume_control_impl.cc index 92d787059..f821ab30f 100644 --- a/src/voice_engine/main/source/voe_volume_control_impl.cc +++ b/src/voice_engine/main/source/voe_volume_control_impl.cc @@ -29,11 +29,9 @@ VoEVolumeControl* VoEVolumeControl::GetInterface(VoiceEngine* voiceEngine) { return NULL; } - VoiceEngineImpl* s = - reinterpret_cast (voiceEngine); - VoEVolumeControlImpl* d = s; - (*d)++; - return (d); + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + s->AddRef(); + return s; #endif } @@ -52,24 +50,6 @@ VoEVolumeControlImpl::~VoEVolumeControlImpl() "VoEVolumeControlImpl::~VoEVolumeControlImpl() - dtor"); } -int VoEVolumeControlImpl::Release() -{ - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoEVolumeControl::Release()"); - (*this)--; - int refCount = GetCount(); - if (refCount < 0) - { - Reset(); // reset reference counter to zero => OK to delete VE - _shared->SetLastError(VE_INTERFACE_NOT_FOUND, kTraceWarning); - return (-1); - } - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_shared->instance_id(), -1), - "VoEVolumeControl reference counter = %d", refCount); - return (refCount); -} - int VoEVolumeControlImpl::SetSpeakerVolume(unsigned int volume) { WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), diff --git a/src/voice_engine/main/source/voe_volume_control_impl.h b/src/voice_engine/main/source/voe_volume_control_impl.h index 4faebba8b..9e1cc5abc 100644 --- a/src/voice_engine/main/source/voe_volume_control_impl.h +++ b/src/voice_engine/main/source/voe_volume_control_impl.h @@ -13,17 +13,13 @@ #include "voe_volume_control.h" -#include "ref_count.h" #include "shared_data.h" namespace webrtc { -class VoEVolumeControlImpl : public VoEVolumeControl, - public voe::RefCount +class VoEVolumeControlImpl : public VoEVolumeControl { public: - virtual int Release(); - virtual int SetSpeakerVolume(unsigned int volume); virtual int GetSpeakerVolume(unsigned int& volume); diff --git a/src/voice_engine/main/source/voice_engine_core.gypi b/src/voice_engine/main/source/voice_engine_core.gypi index 135d78b75..0d8c81485 100644 --- a/src/voice_engine/main/source/voice_engine_core.gypi +++ b/src/voice_engine/main/source/voice_engine_core.gypi @@ -72,8 +72,6 @@ 'monitor_module.h', 'output_mixer.cc', 'output_mixer.h', - 'ref_count.cc', - 'ref_count.h', 'shared_data.cc', 'shared_data.h', 'statistics.cc', diff --git a/src/voice_engine/main/source/voice_engine_impl.cc b/src/voice_engine/main/source/voice_engine_impl.cc index 07af08e33..d0f06dbb6 100644 --- a/src/voice_engine/main/source/voice_engine_impl.cc +++ b/src/voice_engine/main/source/voice_engine_impl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * 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 @@ -35,15 +35,35 @@ WEBRTC_DLLEXPORT VoiceEngine* GetVoiceEngine(); VoiceEngine* GetVoiceEngine() { VoiceEngineImpl* self = new VoiceEngineImpl(); - VoiceEngine* ve = reinterpret_cast (self); + VoiceEngine* ve = reinterpret_cast(self); if (ve != NULL) { + self->AddRef(); // First reference. Released in VoiceEngine::Delete. gVoiceEngineInstanceCounter++; } return ve; } } // extern "C" +int VoiceEngineImpl::AddRef() { + return ++_ref_count; +} + +// This implements the Release() method for all the inherited interfaces. +int VoiceEngineImpl::Release() { + int new_ref = --_ref_count; + assert(new_ref >= 0); + if (new_ref == 0) { + WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1, + "VoiceEngineImpl self deleting (voiceEngine=0x%p)", + this); + + delete this; + } + + return new_ref; +} + VoiceEngine* VoiceEngine::Create() { #if (defined _WIN32) @@ -107,199 +127,22 @@ int VoiceEngine::SetTraceCallback(TraceCallback* callback) return (Trace::SetTraceCallback(callback)); } -bool VoiceEngine::Delete(VoiceEngine*& voiceEngine, bool ignoreRefCounters) +bool VoiceEngine::Delete(VoiceEngine*& voiceEngine) { if (voiceEngine == NULL) - { return false; - } - VoiceEngineImpl* s = reinterpret_cast (voiceEngine); - VoEBaseImpl* base = s; - - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1, - "VoiceEngine::Delete(voiceEngine=0x%p, ignoreRefCounters=%d)", - voiceEngine, ignoreRefCounters); - - if (!ignoreRefCounters) - { - if (base->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoEBase reference counter is %d => memory will not " - "be released properly!", base->GetCount()); - return false; - } -#ifdef WEBRTC_VOICE_ENGINE_CODEC_API - VoECodecImpl* codec = s; - if (codec->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoECodec reference counter is %d => memory will not " - "be released properly!", codec->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_DTMF_API - VoEDtmfImpl* dtmf = s; - if (dtmf->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoEDtmf reference counter is %d =>" - "memory will not be released properly!", - dtmf->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_ENCRYPTION_API - VoEEncryptionImpl* encrypt = s; - if (encrypt->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoEEncryption reference counter is %d => " - "memory will not be released properly!", - encrypt->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_EXTERNAL_MEDIA_API - VoEExternalMediaImpl* extmedia = s; - if (extmedia->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoEExternalMedia reference counter is %d => " - "memory will not be released properly!", - extmedia->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_CALL_REPORT_API - VoECallReportImpl* report = s; - if (report->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoECallReport reference counter is %d => memory " - "will not be released properly!", - report->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_FILE_API - VoEFileImpl* file = s; - if (file->GetCount() != 0) - { - WEBRTC_TRACE( - kTraceCritical, - kTraceVoice, - -1, - "VoEFile reference counter is %d => memory will not " - "be released properly!", - file->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_HARDWARE_API - VoEHardwareImpl* hware = s; - if (hware->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoEHardware reference counter is %d => memory will " - "not be released properly!", hware->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API - VoENetEqStatsImpl* neteqst = s; - if (neteqst->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoENetEqStats reference counter is %d => " - "memory will not be released properly!", - neteqst->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_NETWORK_API - VoENetworkImpl* netw = s; - if (netw->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoENetworkImpl reference counter is %d => memory " - "will not be released properly!", netw->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_RTP_RTCP_API - VoERTP_RTCPImpl* rtcp = s; - if (rtcp->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoERTP_RTCP reference counter is %d =>" - "memory will not be released properly!", - rtcp->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_VIDEO_SYNC_API - VoEVideoSyncImpl* vsync = s; - if (vsync->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoEVideoSync reference counter is %d => " - "memory will not be released properly!", - vsync->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_VOLUME_CONTROL_API - VoEVolumeControlImpl* volume = s; - if (volume->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoEVolumeControl reference counter is %d =>" - "memory will not be released properly!", - volume->GetCount()); - return false; - } -#endif - -#ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API - VoEAudioProcessingImpl* apm = s; - if (apm->GetCount() != 0) - { - WEBRTC_TRACE(kTraceCritical, kTraceVoice, -1, - "VoEAudioProcessing reference counter is %d => " - "memory will not be released properly!", - apm->GetCount()); - return false; - } -#endif - WEBRTC_TRACE(kTraceInfo, kTraceVoice, -1, - "all reference counters are zero => deleting the " - "VoiceEngine instance..."); - - } // if (!ignoreRefCounters) - else - { - WEBRTC_TRACE(kTraceInfo, kTraceVoice, -1, - "reference counters are ignored => deleting the " - "VoiceEngine instance..."); - } - - delete s; + VoiceEngineImpl* s = reinterpret_cast(voiceEngine); + // Release the reference that was added in GetVoiceEngine. + int ref = s->Release(); voiceEngine = NULL; + if (ref != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVoice, -1, + "VoiceEngine::Delete did not release the very last reference. " + "%d references remain.", ref); + } + return true; } diff --git a/src/voice_engine/main/source/voice_engine_impl.h b/src/voice_engine/main/source/voice_engine_impl.h index 68df2b657..7db77be6e 100644 --- a/src/voice_engine/main/source/voice_engine_impl.h +++ b/src/voice_engine/main/source/voice_engine_impl.h @@ -11,6 +11,7 @@ #ifndef WEBRTC_VOICE_ENGINE_VOICE_ENGINE_IMPL_H #define WEBRTC_VOICE_ENGINE_VOICE_ENGINE_IMPL_H +#include "atomic32.h" #include "engine_configurations.h" #include "voe_base_impl.h" @@ -140,12 +141,22 @@ public: #ifdef WEBRTC_VOICE_ENGINE_VOLUME_CONTROL_API VoEVolumeControlImpl(this), #endif - VoEBaseImpl(this) + VoEBaseImpl(this), + _ref_count(0) { } virtual ~VoiceEngineImpl() { + assert(_ref_count.Value() == 0); } + + int AddRef(); + + // This implements the Release() method for all the inherited interfaces. + virtual int Release(); + +private: + Atomic32 _ref_count; }; } // namespace webrtc diff --git a/src/voice_engine/main/test/auto_test/fixtures/before_initialization_fixture.cc b/src/voice_engine/main/test/auto_test/fixtures/before_initialization_fixture.cc index 408141bef..407e5b39c 100644 --- a/src/voice_engine/main/test/auto_test/fixtures/before_initialization_fixture.cc +++ b/src/voice_engine/main/test/auto_test/fixtures/before_initialization_fixture.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * 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 @@ -33,20 +33,20 @@ BeforeInitializationFixture::BeforeInitializationFixture() } BeforeInitializationFixture::~BeforeInitializationFixture() { - EXPECT_EQ(0, voe_base_->Release()); - EXPECT_EQ(0, voe_codec_->Release()); - EXPECT_EQ(0, voe_volume_control_->Release()); - EXPECT_EQ(0, voe_dtmf_->Release()); - EXPECT_EQ(0, voe_rtp_rtcp_->Release()); - EXPECT_EQ(0, voe_apm_->Release()); - EXPECT_EQ(0, voe_network_->Release()); - EXPECT_EQ(0, voe_file_->Release()); - EXPECT_EQ(0, voe_vsync_->Release()); - EXPECT_EQ(0, voe_encrypt_->Release()); - EXPECT_EQ(0, voe_hardware_->Release()); - EXPECT_EQ(0, voe_xmedia_->Release()); - EXPECT_EQ(0, voe_call_report_->Release()); - EXPECT_EQ(0, voe_neteq_stats_->Release()); + voe_base_->Release(); + voe_codec_->Release(); + voe_volume_control_->Release(); + voe_dtmf_->Release(); + voe_rtp_rtcp_->Release(); + voe_apm_->Release(); + voe_network_->Release(); + voe_file_->Release(); + voe_vsync_->Release(); + voe_encrypt_->Release(); + voe_hardware_->Release(); + voe_xmedia_->Release(); + voe_call_report_->Release(); + voe_neteq_stats_->Release(); EXPECT_TRUE(webrtc::VoiceEngine::Delete(voice_engine_)); } diff --git a/src/voice_engine/main/test/auto_test/voe_extended_test.cc b/src/voice_engine/main/test/auto_test/voe_extended_test.cc index 6c5a63f5c..55db29bd8 100644 --- a/src/voice_engine/main/test/auto_test/voe_extended_test.cc +++ b/src/voice_engine/main/test/auto_test/voe_extended_test.cc @@ -1531,7 +1531,7 @@ int VoEExtendedTest::TestBase() { for (int instNum = 0; instNum < 7; instNum++) { TEST_MUSTPASS(baseVE[instNum]->DeleteChannel(0)); TEST_MUSTPASS(baseVE[instNum]->Terminate()); - TEST_MUSTPASS(baseVE[instNum]->Release()); + baseVE[instNum]->Release(); VoiceEngine::Delete(instVE[instNum]); } @@ -5307,7 +5307,8 @@ int VoEExtendedTest::TestNetwork() { const char* localIP = "192.168.1.4"; #else - char localIP[64]; + // Must be big enough so that we can print an IPv6 address. + char localIP[256] = {0}; // invalid parameter TEST_MUSTPASS(!netw->GetLocalIP(NULL)); diff --git a/src/voice_engine/main/test/auto_test/voe_standard_test.cc b/src/voice_engine/main/test/auto_test/voe_standard_test.cc index 0324870a4..f5015269e 100644 --- a/src/voice_engine/main/test/auto_test/voe_standard_test.cc +++ b/src/voice_engine/main/test/auto_test/voe_standard_test.cc @@ -618,186 +618,70 @@ void VoETestManager::GetInterfaces() { } int VoETestManager::ReleaseInterfaces() { - int err(0), remInt(1), j(0); bool releaseOK(true); if (voe_base_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_base_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d base interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - // try to release one addition time (should fail) - TEST_MUSTPASS(-1 != voe_base_->Release()); - err = voe_base_->LastError(); - // it is considered safe to delete even if Release has been called - // too many times - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_base_->Release(); + voe_base_ = NULL; } if (voe_codec_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_codec_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d codec interfaces" - " (should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_codec_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_codec_->Release(); + voe_codec_ = NULL; } if (voe_volume_control_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_volume_control_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d volume interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_volume_control_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_volume_control_->Release(); + voe_volume_control_ = NULL; } if (voe_dtmf_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_dtmf_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d dtmf interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_dtmf_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_dtmf_->Release(); + voe_dtmf_ = NULL; } if (voe_rtp_rtcp_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_rtp_rtcp_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d rtp/rtcp interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_rtp_rtcp_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_rtp_rtcp_->Release(); + voe_rtp_rtcp_ = NULL; } if (voe_apm_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_apm_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d apm interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_apm_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_apm_->Release(); + voe_apm_ = NULL; } if (voe_network_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_network_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d network interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_network_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_network_->Release(); + voe_network_ = NULL; } if (voe_file_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_file_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d file interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_file_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_file_->Release(); + voe_file_ = NULL; } #ifdef _TEST_VIDEO_SYNC_ if (voe_vsync_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_vsync_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d video sync interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_vsync_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_vsync_->Release(); + voe_vsync_ = NULL; } #endif if (voe_encrypt_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_encrypt_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d encryption interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_encrypt_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_encrypt_->Release(); + voe_encrypt_ = NULL; } if (voe_hardware_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_hardware_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d hardware interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_hardware_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_hardware_->Release(); + voe_hardware_ = NULL; } #ifdef _TEST_XMEDIA_ if (voe_xmedia_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_xmedia_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d external media interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_xmedia_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_xmedia_->Release(); + voe_xmedia_ = NULL; } #endif #ifdef _TEST_CALL_REPORT_ if (voe_call_report_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_call_report_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d call report interfaces" - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_call_report_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_call_report_->Release(); + voe_call_report_ = NULL; } #endif #ifdef _TEST_NETEQ_STATS_ if (voe_neteq_stats_) { - for (remInt = 1, j = 0; remInt > 0; j++) - TEST_MUSTPASS(-1 == (remInt = voe_neteq_stats_->Release())); - if (j > 1) { - TEST_LOG("\n\n*** Error: released %d neteq stat interfaces " - "(should only be 1) \n", j); - releaseOK = false; - } - TEST_MUSTPASS(-1 != voe_neteq_stats_->Release()); - err = voe_base_->LastError(); - TEST_MUSTPASS(err != VE_INTERFACE_NOT_FOUND); + voe_neteq_stats_->Release(); + voe_neteq_stats_ = NULL; } #endif if (false == VoiceEngine::Delete(voice_engine_)) {