@@ -1462,7 +1462,9 @@ AudioFlinger::PlaybackThread::PlaybackThread(const sp<AudioFlinger>& audioFlinge
14621462 // Assumes constructor is called by AudioFlinger with it's mLock held,
14631463 // but it would be safer to explicitly pass initial masterVolume as parameter
14641464 mMasterVolume(audioFlinger->masterVolumeSW_l ()),
1465- mLastWriteTime(0 ), mNumWrites(0 ), mNumDelayedWrites(0 ), mInWrite(false )
1465+ mLastWriteTime(0 ), mNumWrites(0 ), mNumDelayedWrites(0 ), mInWrite(false ),
1466+ // mMixerStatus
1467+ mPrevMixerStatus(MIXER_IDLE)
14661468{
14671469 snprintf (mName , kNameLength , " AudioOut_%X" , id);
14681470
@@ -1922,7 +1924,6 @@ AudioFlinger::MixerThread::MixerThread(const sp<AudioFlinger>& audioFlinger, Aud
19221924 : PlaybackThread(audioFlinger, output, id, device, type)
19231925{
19241926 mAudioMixer = new AudioMixer (mFrameCount , mSampleRate );
1925- mPrevMixerStatus = MIXER_IDLE;
19261927 // FIXME - Current mixer implementation only supports stereo output
19271928 if (mChannelCount == 1 ) {
19281929 ALOGE (" Invalid audio hardware channel count" );
@@ -2043,7 +2044,7 @@ if (mType == MIXER) {
20432044
20442045 processConfigEvents ();
20452046
2046- mixerStatus = MIXER_IDLE;
2047+ mMixerStatus = MIXER_IDLE;
20472048 { // scope for mLock
20482049
20492050 Mutex::Autolock _l (mLock );
@@ -2098,9 +2099,7 @@ if (mType == DIRECT) {
20982099 ALOGV (" Thread %p type %d TID %d waking up" , this , mType , gettid ());
20992100 acquireWakeLock_l ();
21002101
2101- if (mType == MIXER || mType == DUPLICATING) {
21022102 mPrevMixerStatus = MIXER_IDLE;
2103- }
21042103
21052104 checkSilentMode_l ();
21062105
@@ -2122,19 +2121,19 @@ if (mType == MIXER) {
21222121 }
21232122 }
21242123
2125- mixerStatus = prepareTracks_l (&tracksToRemove);
2126- // see FIXME in AudioFlinger.h
2127- if (mixerStatus == MIXER_CONTINUE) {
2128- continue ;
2129- }
2124+ mixer_state newMixerStatus = prepareTracks_l (&tracksToRemove);
2125+ // Shift in the new status; this could be a queue if it's
2126+ // useful to filter the mixer status over several cycles.
2127+ mPrevMixerStatus = mMixerStatus ;
2128+ mMixerStatus = newMixerStatus;
21302129
21312130 // prevent any changes in effect chain list and in each effect chain
21322131 // during mixing and effect process as the audio buffers could be deleted
21332132 // or modified if an effect is created or deleted
21342133 lockEffectChains_l (effectChains);
21352134 }
21362135
2137- if (CC_LIKELY (mixerStatus == MIXER_TRACKS_READY)) {
2136+ if (CC_LIKELY (mMixerStatus == MIXER_TRACKS_READY)) {
21382137 threadLoop_mix ();
21392138 } else {
21402139 threadLoop_sleepTime ();
@@ -2271,7 +2270,7 @@ void AudioFlinger::MixerThread::threadLoop_sleepTime()
22712270 // If no tracks are ready, sleep once for the duration of an output
22722271 // buffer size, then write 0s to the output
22732272 if (sleepTime == 0 ) {
2274- if (mixerStatus == MIXER_TRACKS_ENABLED) {
2273+ if (mMixerStatus == MIXER_TRACKS_ENABLED) {
22752274 sleepTime = activeSleepTime >> sleepTimeShift;
22762275 if (sleepTime < kMinThreadSleepTimeUs ) {
22772276 sleepTime = kMinThreadSleepTimeUs ;
@@ -2287,10 +2286,10 @@ void AudioFlinger::MixerThread::threadLoop_sleepTime()
22872286 sleepTime = idleSleepTime;
22882287 }
22892288 } else if (mBytesWritten != 0 ||
2290- (mixerStatus == MIXER_TRACKS_ENABLED && longStandbyExit)) {
2289+ (mMixerStatus == MIXER_TRACKS_ENABLED && longStandbyExit)) {
22912290 memset (mMixBuffer , 0 , mixBufferSize);
22922291 sleepTime = 0 ;
2293- ALOGV_IF ((mBytesWritten == 0 && (mixerStatus == MIXER_TRACKS_ENABLED && longStandbyExit)), " anticipated start" );
2292+ ALOGV_IF ((mBytesWritten == 0 && (mMixerStatus == MIXER_TRACKS_ENABLED && longStandbyExit)), " anticipated start" );
22942293 }
22952294 // TODO add standby time extension fct of effect tail
22962295}
@@ -2546,7 +2545,6 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::MixerThread::prepareTrac
25462545 memset (mMixBuffer , 0 , mFrameCount * mChannelCount * sizeof (int16_t ));
25472546 }
25482547
2549- mPrevMixerStatus = mixerStatus;
25502548 return mixerStatus;
25512549}
25522550
@@ -2813,15 +2811,13 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::DirectOutputThread::prep
28132811{
28142812 sp<Track> trackToRemove;
28152813
2816- // FIXME Temporarily renamed to avoid confusion with the member "mixerStatus"
2817- mixer_state mixerStatus_ = MIXER_IDLE;
2814+ mixer_state mixerStatus = MIXER_IDLE;
28182815
28192816 // find out which tracks need to be processed
28202817 if (mActiveTracks .size () != 0 ) {
28212818 sp<Track> t = mActiveTracks [0 ].promote ();
2822- // see FIXME in AudioFlinger.h, return MIXER_IDLE might also work
2823- if (t == 0 ) return MIXER_CONTINUE;
2824- // if (t == 0) continue;
2819+ // The track died recently
2820+ if (t == 0 ) return MIXER_IDLE;
28252821
28262822 Track* const track = t.get ();
28272823 audio_track_cblk_t * cblk = track->cblk ();
@@ -2907,7 +2903,7 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::DirectOutputThread::prep
29072903 // reset retry count
29082904 track->mRetryCount = kMaxTrackRetriesDirect ;
29092905 mActiveTrack = t;
2910- mixerStatus_ = MIXER_TRACKS_READY;
2906+ mixerStatus = MIXER_TRACKS_READY;
29112907 } else {
29122908 // ALOGV("track %d u=%08x, s=%08x [NOT READY]", track->name(), cblk->user, cblk->server);
29132909 if (track->isStopped ()) {
@@ -2924,7 +2920,7 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::DirectOutputThread::prep
29242920 ALOGV (" BUFFER TIMEOUT: remove(%d) from active list" , track->name ());
29252921 trackToRemove = track;
29262922 } else {
2927- mixerStatus_ = MIXER_TRACKS_ENABLED;
2923+ mixerStatus = MIXER_TRACKS_ENABLED;
29282924 }
29292925 }
29302926 }
@@ -2945,7 +2941,7 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::DirectOutputThread::prep
29452941 }
29462942 }
29472943
2948- return mixerStatus_ ;
2944+ return mixerStatus ;
29492945}
29502946
29512947void AudioFlinger::DirectOutputThread::threadLoop_mix ()
@@ -2975,7 +2971,7 @@ void AudioFlinger::DirectOutputThread::threadLoop_mix()
29752971void AudioFlinger::DirectOutputThread::threadLoop_sleepTime ()
29762972{
29772973 if (sleepTime == 0 ) {
2978- if (mixerStatus == MIXER_TRACKS_ENABLED) {
2974+ if (mMixerStatus == MIXER_TRACKS_ENABLED) {
29792975 sleepTime = activeSleepTime;
29802976 } else {
29812977 sleepTime = idleSleepTime;
@@ -3111,7 +3107,7 @@ void AudioFlinger::DuplicatingThread::threadLoop_mix()
31113107void AudioFlinger::DuplicatingThread::threadLoop_sleepTime ()
31123108{
31133109 if (sleepTime == 0 ) {
3114- if (mixerStatus == MIXER_TRACKS_ENABLED) {
3110+ if (mMixerStatus == MIXER_TRACKS_ENABLED) {
31153111 sleepTime = activeSleepTime;
31163112 } else {
31173113 sleepTime = idleSleepTime;
0 commit comments