From 782049413376ee1833a08ba02cc5ba6b5905792f Mon Sep 17 00:00:00 2001 From: Paul McLean Date: Mon, 16 Apr 2018 12:47:19 -0700 Subject: [PATCH] Add retry mechanism to AudioRecord::restoreRecord_l(). This is analogous to similar code in AudioTrack::restoreTrack_l(). Bug: 77682459 Test: Connect USB headset. Start Skype call. Note input audio on DUT is heard on remote phone. Manually kill audio server, verify that input from USB headset is restored on DUT and heard on remote phone. Change-Id: Icbf624aba8a3fe6917b132d8c38c2812f9519ec6 --- media/libaudioclient/AudioRecord.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/media/libaudioclient/AudioRecord.cpp b/media/libaudioclient/AudioRecord.cpp index 21d3fa666c..a8369c22b1 100644 --- a/media/libaudioclient/AudioRecord.cpp +++ b/media/libaudioclient/AudioRecord.cpp @@ -1231,6 +1231,14 @@ status_t AudioRecord::restoreRecord_l(const char *from) ALOGW("dead IAudioRecord, creating a new one from %s()", from); ++mSequence; + const int INITIAL_RETRIES = 3; + int retries = INITIAL_RETRIES; +retry: + if (retries < INITIAL_RETRIES) { + // refresh the audio configuration cache in this process to make sure we get new + // input parameters and new IAudioRecord in createRecord_l() + AudioSystem::clearAudioConfigCache(); + } mFlags = mOrigFlags; // if the new IAudioRecord is created, createRecord_l() will modify the @@ -1239,7 +1247,11 @@ status_t AudioRecord::restoreRecord_l(const char *from) Modulo position(mProxy->getPosition()); mNewPosition = position + mUpdatePeriod; status_t result = createRecord_l(position, mOpPackageName); - if (result == NO_ERROR) { + + if (result != NO_ERROR) { + ALOGW("%s(): createRecord_l failed, do not retry", __func__); + retries = 0; + } else { if (mActive) { // callback thread or sync event hasn't changed // FIXME this fails if we have a new AudioFlinger instance @@ -1248,6 +1260,14 @@ status_t AudioRecord::restoreRecord_l(const char *from) } mFramesReadServerOffset = mFramesRead; // server resets to zero so we need an offset. } + + if (result != NO_ERROR) { + ALOGW("%s() failed status %d, retries %d", __func__, result, retries); + if (--retries > 0) { + goto retry; + } + } + if (result != NO_ERROR) { ALOGW("restoreRecord_l() failed status %d", result); mActive = false;