getPrimary APIs now examine all non-duplicating output threads
and return the value corresponding to the thread with minimum frame count,
with a preference for a thread with fast mixer if there are multiple
output threads with the same minimum frame count.
This is in keeping with the expectation by apps that the getPrimary APIs
will return a value for the lowest available latency path.
Bug: 29164107
Change-Id: I8ae9bcad2d48185d7717ccf96085834c0ce00e37
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 0523d41..3ee9033 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1694,14 +1694,14 @@
uint32_t AudioFlinger::getPrimaryOutputSamplingRate()
{
Mutex::Autolock _l(mLock);
- PlaybackThread *thread = primaryPlaybackThread_l();
+ PlaybackThread *thread = fastPlaybackThread_l();
return thread != NULL ? thread->sampleRate() : 0;
}
size_t AudioFlinger::getPrimaryOutputFrameCount()
{
Mutex::Autolock _l(mLock);
- PlaybackThread *thread = primaryPlaybackThread_l();
+ PlaybackThread *thread = fastPlaybackThread_l();
return thread != NULL ? thread->frameCountHAL() : 0;
}
@@ -2528,6 +2528,25 @@
return thread->outDevice();
}
+AudioFlinger::PlaybackThread *AudioFlinger::fastPlaybackThread_l() const
+{
+ size_t minFrameCount = 0;
+ PlaybackThread *minThread = NULL;
+ for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
+ PlaybackThread *thread = mPlaybackThreads.valueAt(i).get();
+ if (!thread->isDuplicating()) {
+ size_t frameCount = thread->frameCountHAL();
+ if (frameCount != 0 && (minFrameCount == 0 || frameCount < minFrameCount ||
+ (frameCount == minFrameCount && thread->hasFastMixer() &&
+ /*minThread != NULL &&*/ !minThread->hasFastMixer()))) {
+ minFrameCount = frameCount;
+ minThread = thread;
+ }
+ }
+ }
+ return minThread;
+}
+
sp<AudioFlinger::SyncEvent> AudioFlinger::createSyncEvent(AudioSystem::sync_event_t type,
audio_session_t triggerSession,
audio_session_t listenerSession,
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 4a5a643..c56dcc1 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -575,6 +575,9 @@
PlaybackThread *primaryPlaybackThread_l() const;
audio_devices_t primaryOutputDevice_l() const;
+ // return the playback thread with smallest HAL buffer size, and prefer fast
+ PlaybackThread *fastPlaybackThread_l() const;
+
sp<PlaybackThread> getEffectThread_l(audio_session_t sessionId, int EffectId);