From 83a062cc5feca7c50218cc8fd7099dc5bdd3f4f5 Mon Sep 17 00:00:00 2001 From: "braveyao@webrtc.org" Date: Mon, 10 Jun 2013 08:09:05 +0000 Subject: [PATCH] AudioDeviceAndroidOpenSLES: NULL variables might be referenced in StopPlayout() BUG=1891 Test=ManualTest R=fischman@webrtc.org, xians@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1622004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4200 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../android/audio_device_opensles_android.cc | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/webrtc/modules/audio_device/android/audio_device_opensles_android.cc b/webrtc/modules/audio_device/android/audio_device_opensles_android.cc index 93271f0ad1..dd0805df99 100644 --- a/webrtc/modules/audio_device/android/audio_device_opensles_android.cc +++ b/webrtc/modules/audio_device/android/audio_device_opensles_android.cc @@ -1133,48 +1133,50 @@ int32_t AudioDeviceAndroidOpenSLES::StartPlayout() { } int32_t AudioDeviceAndroidOpenSLES::StopPlayout() { - { - CriticalSectionScoped lock(&crit_sect_); - if (!is_play_initialized_) { - WEBRTC_OPENSL_TRACE(kTraceInfo, kTraceAudioDevice, id_, - " Playout is not initialized"); - return 0; - } - if (!sles_player_itf_ && !sles_output_mixer_ && !sles_player_) { - // Make sure player is stopped - int32_t res = - (*sles_player_itf_)->SetPlayState(sles_player_itf_, - SL_PLAYSTATE_STOPPED); - if (res != SL_RESULT_SUCCESS) { - WEBRTC_OPENSL_TRACE(kTraceError, kTraceAudioDevice, id_, - " failed to stop playout"); - return -1; - } - res = (*sles_player_sbq_itf_)->Clear(sles_player_sbq_itf_); - if (res != SL_RESULT_SUCCESS) { - WEBRTC_OPENSL_TRACE(kTraceError, kTraceAudioDevice, id_, - " failed to clear player buffer queue"); - return -1; - } + CriticalSectionScoped lock(&crit_sect_); + if (!is_play_initialized_) { + WEBRTC_OPENSL_TRACE(kTraceInfo, kTraceAudioDevice, id_, + " Playout is not initialized"); + return 0; + } - // Destroy the player - (*sles_player_)->Destroy(sles_player_); - // Destroy Output Mix object - (*sles_output_mixer_)->Destroy(sles_output_mixer_); - sles_player_ = NULL; - sles_player_itf_ = NULL; - sles_player_sbq_itf_ = NULL; - sles_output_mixer_ = NULL; + if (sles_player_itf_) { + // Make sure player is stopped + int32_t res = (*sles_player_itf_)->SetPlayState(sles_player_itf_, + SL_PLAYSTATE_STOPPED); + if (res != SL_RESULT_SUCCESS) { + WEBRTC_OPENSL_TRACE(kTraceError, kTraceAudioDevice, id_, + " failed to stop playout"); } } - CriticalSectionScoped lock(&crit_sect_); + if (sles_player_sbq_itf_) { + int32_t res = (*sles_player_sbq_itf_)->Clear(sles_player_sbq_itf_); + if (res != SL_RESULT_SUCCESS) { + WEBRTC_OPENSL_TRACE(kTraceError, kTraceAudioDevice, id_, + " failed to clear player buffer queue"); + } + } + + if (sles_player_) { + // Destroy the player + (*sles_player_)->Destroy(sles_player_); + } + + if (sles_output_mixer_) { + // Destroy Output Mix object + (*sles_output_mixer_)->Destroy(sles_output_mixer_); + } + is_play_initialized_ = false; is_playing_ = false; play_warning_ = 0; play_error_ = 0; - + sles_player_sbq_itf_ = NULL; + sles_player_itf_ = NULL; + sles_player_ = NULL; + sles_output_mixer_ = NULL; return 0; }