From 79af734807109d119573ce23daa1a2bff0f0eeca Mon Sep 17 00:00:00 2001 From: "xians@webrtc.org" Date: Tue, 31 Jan 2012 12:22:14 +0000 Subject: [PATCH] This patch fixes the converity warnings in voice engine. Review URL: https://webrtc-codereview.appspot.com/373017 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1579 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/voice_engine/main/source/channel.cc | 22 ++++++----- .../main/source/channel_manager_base.cc | 4 +- src/voice_engine/main/source/voe_base_impl.cc | 39 +++++++++++++++---- .../main/source/voe_external_media_impl.cc | 8 +++- .../main/source/voe_hardware_impl.cc | 16 ++++++-- .../main/source/voe_network_impl.cc | 4 +- 6 files changed, 68 insertions(+), 25 deletions(-) diff --git a/src/voice_engine/main/source/channel.cc b/src/voice_engine/main/source/channel.cc index 14816cff6..7b8b8f41b 100644 --- a/src/voice_engine/main/source/channel.cc +++ b/src/voice_engine/main/source/channel.cc @@ -5366,16 +5366,20 @@ Channel::GetRemoteRTCPData( remoteSSRC = it->remoteSSRC; } - *jitter = it->jitter; - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_instanceId, _channelId), - "GetRemoteRTCPData() => jitter = %lu", *jitter); + if (jitter) { + *jitter = it->jitter; + WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, + VoEId(_instanceId, _channelId), + "GetRemoteRTCPData() => jitter = %lu", *jitter); + } - *fractionLost = it->fractionLost; - WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, - VoEId(_instanceId, _channelId), - "GetRemoteRTCPData() => fractionLost = %lu", - *fractionLost); + if (fractionLost) { + *fractionLost = it->fractionLost; + WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, + VoEId(_instanceId, _channelId), + "GetRemoteRTCPData() => fractionLost = %lu", + *fractionLost); + } } return 0; } diff --git a/src/voice_engine/main/source/channel_manager_base.cc b/src/voice_engine/main/source/channel_manager_base.cc index 49d02354f..ea9938f07 100644 --- a/src/voice_engine/main/source/channel_manager_base.cc +++ b/src/voice_engine/main/source/channel_manager_base.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 @@ -201,7 +201,7 @@ void ChannelManagerBase::GetItemIds(WebRtc_Word32* channelsArray, MapItem* it = _items.First(); numOfChannels = (numOfChannels <= _items.Size()) ? numOfChannels : _items.Size(); - for (int i = 0; i < numOfChannels; i++) + for (int i = 0; i < numOfChannels && it != NULL; i++) { channelsArray[i] = it->GetId(); it = _items.Next(it); diff --git a/src/voice_engine/main/source/voe_base_impl.cc b/src/voice_engine/main/source/voe_base_impl.cc index 65ac21f53..6fe6ba9af 100644 --- a/src/voice_engine/main/source/voe_base_impl.cc +++ b/src/voice_engine/main/source/voe_base_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 @@ -393,7 +393,8 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm) // Register the ADM to the process thread, which will drive the error // callback mechanism - if (_moduleProcessThreadPtr->RegisterModule(_audioDevicePtr) != 0) + if (_moduleProcessThreadPtr && + _moduleProcessThreadPtr->RegisterModule(_audioDevicePtr) != 0) { _engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, @@ -407,10 +408,20 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm) // Reinitialize the ADM // Register the AudioObserver implementation - _audioDevicePtr->RegisterEventObserver(this); + if (_audioDevicePtr->RegisterEventObserver(this) != 0) { + _engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, + kTraceWarning, + "Init() failed to register event observer " + "for the ADM"); + } // Register the AudioTransport implementation - _audioDevicePtr->RegisterAudioCallback(this); + if (_audioDevicePtr->RegisterAudioCallback(this) != 0) { + _engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, + kTraceWarning, + "Init() failed to register audio callback " + "for the ADM"); + } // ADM initialization if (_audioDevicePtr->Init() != 0) @@ -472,7 +483,11 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm) } // Set number of channels - _audioDevicePtr->StereoPlayoutIsAvailable(&available); + if (_audioDevicePtr->StereoPlayoutIsAvailable(&available) != 0) { + _engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, + "Init() failed to query stereo playout " + "mode"); + } if (_audioDevicePtr->SetStereoPlayout(available) != 0) { _engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, @@ -1626,8 +1641,18 @@ WebRtc_Word32 VoEBaseImpl::TerminateInternal() "TerminateInternal() failed to stop " "recording"); } - _audioDevicePtr->RegisterEventObserver(NULL); - _audioDevicePtr->RegisterAudioCallback(NULL); + if (_audioDevicePtr->RegisterEventObserver(NULL) != 0) { + _engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, + kTraceWarning, + "TerminateInternal() failed to de-" + "register event observer for the ADM"); + } + if (_audioDevicePtr->RegisterAudioCallback(NULL) != 0) { + _engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, + kTraceWarning, + "TerminateInternal() failed to de-" + "register audio callback for the ADM"); + } if (_audioDevicePtr->Terminate() != 0) { _engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, 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 1d62a7472..02e069c19 100644 --- a/src/voice_engine/main/source/voe_external_media_impl.cc +++ b/src/voice_engine/main/source/voe_external_media_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 @@ -270,7 +270,11 @@ int VoEExternalMediaImpl::ExternalRecordingInsertData( if (!_externalPlayout) { // Use real playout delay if external playout is not enabled. - _audioDevicePtr->PlayoutDelay(&playoutDelayMS); + if (_audioDevicePtr->PlayoutDelay(&playoutDelayMS) != 0) { + _engineStatistics.SetLastError( + VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, + "PlayoutDelay() unable to get the playout delay"); + } totalDelayMS = current_delay_ms + playoutDelayMS; } else diff --git a/src/voice_engine/main/source/voe_hardware_impl.cc b/src/voice_engine/main/source/voe_hardware_impl.cc index c03f3be06..cf8cc01d7 100644 --- a/src/voice_engine/main/source/voe_hardware_impl.cc +++ b/src/voice_engine/main/source/voe_hardware_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 @@ -397,8 +397,11 @@ int VoEHardwareImpl::SetRecordingDevice(int index, return -1; } - // Cannot return error because of sanity above - _audioDevicePtr->RecordingChannel(&recCh); + if (_audioDevicePtr->SetRecordingChannel(recCh) != 0) { + _engineStatistics.SetLastError( + VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, + "SetRecordingChannel() unable to set the recording channel"); + } // Map indices to unsigned since underlying functions need that WebRtc_UWord16 indexU = static_cast (index); @@ -438,7 +441,12 @@ int VoEHardwareImpl::SetRecordingDevice(int index, // Set number of channels bool available(false); - _audioDevicePtr->StereoRecordingIsAvailable(&available); + if (_audioDevicePtr->StereoRecordingIsAvailable(&available) != 0) { + _engineStatistics.SetLastError( + VE_SOUNDCARD_ERROR, kTraceWarning, + "StereoRecordingIsAvailable() failed to query stereo recording"); + } + if (_audioDevicePtr->SetStereoRecording(available ? true : false) != 0) { _engineStatistics.SetLastError( diff --git a/src/voice_engine/main/source/voe_network_impl.cc b/src/voice_engine/main/source/voe_network_impl.cc index 9fa345ce2..213eb76f2 100644 --- a/src/voice_engine/main/source/voe_network_impl.cc +++ b/src/voice_engine/main/source/voe_network_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 @@ -290,6 +290,7 @@ int VoENetworkImpl::GetLocalIP(char ipAddr[64], bool ipv6) _engineStatistics.SetLastError( VE_INVALID_IP_ADDRESS, kTraceError, "GetLocalIP() failed to retrieve local IP - 1"); + UdpTransport::Destroy(socketPtr); return -1; } // Convert 128-bit address to character string (a:b:c:d:e:f:g:h) @@ -310,6 +311,7 @@ int VoENetworkImpl::GetLocalIP(char ipAddr[64], bool ipv6) _engineStatistics.SetLastError( VE_INVALID_IP_ADDRESS, kTraceError, "GetLocalIP() failed to retrieve local IP - 2"); + UdpTransport::Destroy(socketPtr); return -1; } // Convert 32-bit address to character string (x.y.z.w)