diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index a03f2eaf6626a..e2e5214688789 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1849,7 +1849,7 @@ uint32_t AudioFlinger::PlaybackThread::activeSleepTimeUs() AudioFlinger::MixerThread::MixerThread(const sp& audioFlinger, AudioStreamOut* output, int id, uint32_t device) : PlaybackThread(audioFlinger, output, id, device), - mAudioMixer(NULL) + mAudioMixer(NULL), mPrevMixerStatus(MIXER_IDLE) { mType = ThreadBase::MIXER; mAudioMixer = new AudioMixer(mFrameCount, mSampleRate); @@ -1962,6 +1962,7 @@ bool AudioFlinger::MixerThread::threadLoop() ALOGV("MixerThread %p TID %d waking up\n", this, gettid()); acquireWakeLock_l(); + mPrevMixerStatus = MIXER_IDLE; if (!mMasterMute) { char value[PROPERTY_VALUE_MAX]; property_get("ro.audio.silent", value, "0"); @@ -2121,11 +2122,11 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wpmRetryCount >= kMaxTrackRetries) meaning the track was mixed + // hence the test on (mPrevMixerStatus == MIXER_TRACKS_READY) meaning the track was mixed // during last round uint32_t minFrames = 1; if (!track->isStopped() && !track->isPausing() && - (track->mRetryCount >= kMaxTrackRetries)) { + (mPrevMixerStatus == MIXER_TRACKS_READY)) { if (t->sampleRate() == (int)mSampleRate) { minFrames = mFrameCount; } else { @@ -2274,7 +2275,13 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wpmRetryCount = kMaxTrackRetries; - mixerStatus = MIXER_TRACKS_READY; + // If one track is ready, set the mixer ready if: + // - the mixer was not ready during previous round OR + // - no other track is not ready + if (mPrevMixerStatus != MIXER_TRACKS_READY || + mixerStatus != MIXER_TRACKS_ENABLED) { + mixerStatus = MIXER_TRACKS_READY; + } } else { //ALOGV("track %d u=%08x, s=%08x [NOT READY] on thread %p", name, cblk->user, cblk->server, this); if (track->isStopped()) { @@ -2292,7 +2299,11 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wpadd(track); // indicate to client process that the track was disabled because of underrun android_atomic_or(CBLK_DISABLED_ON, &cblk->flags); - } else if (mixerStatus != MIXER_TRACKS_READY) { + // If one track is not ready, mark the mixer also not ready if: + // - the mixer was ready during previous round OR + // - no other track is ready + } else if (mPrevMixerStatus == MIXER_TRACKS_READY || + mixerStatus != MIXER_TRACKS_READY) { mixerStatus = MIXER_TRACKS_ENABLED; } } @@ -2326,6 +2337,7 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp