Skip to content

Commit 3562931

Browse files
author
Eric Laurent
committed
resolved conflicts for merge of 05683c8 to master
Change-Id: I7846b7da8c5813b7a9b1f3f71aede0229689ff0d
2 parents 92ecdd6 + 05683c8 commit 3562931

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

services/audioflinger/AudioFlinger.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ uint32_t AudioFlinger::PlaybackThread::activeSleepTimeUs()
18491849

18501850
AudioFlinger::MixerThread::MixerThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device)
18511851
: PlaybackThread(audioFlinger, output, id, device),
1852-
mAudioMixer(NULL)
1852+
mAudioMixer(NULL), mPrevMixerStatus(MIXER_IDLE)
18531853
{
18541854
mType = ThreadBase::MIXER;
18551855
mAudioMixer = new AudioMixer(mFrameCount, mSampleRate);
@@ -1962,6 +1962,7 @@ bool AudioFlinger::MixerThread::threadLoop()
19621962
ALOGV("MixerThread %p TID %d waking up\n", this, gettid());
19631963
acquireWakeLock_l();
19641964

1965+
mPrevMixerStatus = MIXER_IDLE;
19651966
if (!mMasterMute) {
19661967
char value[PROPERTY_VALUE_MAX];
19671968
property_get("ro.audio.silent", value, "0");
@@ -2121,11 +2122,11 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
21212122
// make sure that we have enough frames to mix one full buffer.
21222123
// enforce this condition only once to enable draining the buffer in case the client
21232124
// app does not call stop() and relies on underrun to stop:
2124-
// hence the test on (track->mRetryCount >= kMaxTrackRetries) meaning the track was mixed
2125+
// hence the test on (mPrevMixerStatus == MIXER_TRACKS_READY) meaning the track was mixed
21252126
// during last round
21262127
uint32_t minFrames = 1;
21272128
if (!track->isStopped() && !track->isPausing() &&
2128-
(track->mRetryCount >= kMaxTrackRetries)) {
2129+
(mPrevMixerStatus == MIXER_TRACKS_READY)) {
21292130
if (t->sampleRate() == (int)mSampleRate) {
21302131
minFrames = mFrameCount;
21312132
} else {
@@ -2274,7 +2275,13 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
22742275

22752276
// reset retry count
22762277
track->mRetryCount = kMaxTrackRetries;
2277-
mixerStatus = MIXER_TRACKS_READY;
2278+
// If one track is ready, set the mixer ready if:
2279+
// - the mixer was not ready during previous round OR
2280+
// - no other track is not ready
2281+
if (mPrevMixerStatus != MIXER_TRACKS_READY ||
2282+
mixerStatus != MIXER_TRACKS_ENABLED) {
2283+
mixerStatus = MIXER_TRACKS_READY;
2284+
}
22782285
} else {
22792286
//ALOGV("track %d u=%08x, s=%08x [NOT READY] on thread %p", name, cblk->user, cblk->server, this);
22802287
if (track->isStopped()) {
@@ -2292,7 +2299,11 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
22922299
tracksToRemove->add(track);
22932300
// indicate to client process that the track was disabled because of underrun
22942301
android_atomic_or(CBLK_DISABLED_ON, &cblk->flags);
2295-
} else if (mixerStatus != MIXER_TRACKS_READY) {
2302+
// If one track is not ready, mark the mixer also not ready if:
2303+
// - the mixer was ready during previous round OR
2304+
// - no other track is ready
2305+
} else if (mPrevMixerStatus == MIXER_TRACKS_READY ||
2306+
mixerStatus != MIXER_TRACKS_READY) {
22962307
mixerStatus = MIXER_TRACKS_ENABLED;
22972308
}
22982309
}
@@ -2326,6 +2337,7 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
23262337
memset(mMixBuffer, 0, mFrameCount * mChannelCount * sizeof(int16_t));
23272338
}
23282339

2340+
mPrevMixerStatus = mixerStatus;
23292341
return mixerStatus;
23302342
}
23312343

@@ -3054,6 +3066,7 @@ bool AudioFlinger::DuplicatingThread::threadLoop()
30543066
ALOGV("DuplicatingThread %p TID %d waking up\n", this, gettid());
30553067
acquireWakeLock_l();
30563068

3069+
mPrevMixerStatus = MIXER_IDLE;
30573070
if (!mMasterMute) {
30583071
char value[PROPERTY_VALUE_MAX];
30593072
property_get("ro.audio.silent", value, "0");

services/audioflinger/AudioFlinger.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,9 @@ class AudioFlinger :
830830
virtual uint32_t idleSleepTimeUs();
831831
virtual uint32_t suspendSleepTimeUs();
832832

833-
AudioMixer* mAudioMixer;
833+
AudioMixer* mAudioMixer;
834+
uint32_t mPrevMixerStatus; // previous status (mixer_state) returned by
835+
// prepareTracks_l()
834836
};
835837

836838
class DirectOutputThread : public PlaybackThread {

0 commit comments

Comments
 (0)