audio policy: set track spatialization state from audio policy manager.
When an audio track is created, AudioPolicyManager.getOutputForAttr()
will return if it is actually being spatialized. This will allow removing
the duplicated logic in audio flinger to tell if a track is spatialized and
also to only enable the spatializer effect if spatialized tracks are active
and connected to the spatializer mixer.
Bug: 227740874
Test: music and spatial audio playback regression
Change-Id: If75c8ad06afdf3b47e3cc5d30c777af22d6fc35e
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index ae5772d..0f27f90 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -2228,7 +2228,8 @@
pid_t tid,
status_t *status,
audio_port_handle_t portId,
- const sp<media::IAudioTrackCallback>& callback)
+ const sp<media::IAudioTrackCallback>& callback,
+ bool isSpatialized)
{
size_t frameCount = *pFrameCount;
size_t notificationFrameCount = *pNotificationFrameCount;
@@ -2520,7 +2521,8 @@
channelMask, frameCount,
nullptr /* buffer */, (size_t)0 /* bufferSize */, sharedBuffer,
sessionId, creatorPid, attributionSource, trackFlags,
- TrackBase::TYPE_DEFAULT, portId, SIZE_MAX /*frameCountToBeReady*/, speed);
+ TrackBase::TYPE_DEFAULT, portId, SIZE_MAX /*frameCountToBeReady*/,
+ speed, isSpatialized);
lStatus = track != 0 ? track->initCheck() : (status_t) NO_MEMORY;
if (lStatus != NO_ERROR) {
@@ -3882,14 +3884,14 @@
&& effectChain->containsHapticGeneratingEffect_l()) {
activeHapticSessionId = track->sessionId();
isHapticSessionSpatialized =
- mType == SPATIALIZER && track->canBeSpatialized();
+ mType == SPATIALIZER && track->isSpatialized();
break;
}
if (activeHapticSessionId == AUDIO_SESSION_NONE
&& track->getHapticPlaybackEnabled()) {
activeHapticSessionId = track->sessionId();
isHapticSessionSpatialized =
- mType == SPATIALIZER && track->canBeSpatialized();
+ mType == SPATIALIZER && track->isSpatialized();
}
}
}
@@ -5569,7 +5571,7 @@
AudioMixer::TRACK,
AudioMixer::CHANNEL_MASK, (void *)(uintptr_t)track->channelMask());
- if (mType == SPATIALIZER && !track->canBeSpatialized()) {
+ if (mType == SPATIALIZER && !track->isSpatialized()) {
mAudioMixer->setParameter(
trackId,
AudioMixer::TRACK,
@@ -5619,7 +5621,7 @@
if (mMixerBufferEnabled
&& (track->mainBuffer() == mSinkBuffer
|| track->mainBuffer() == mMixerBuffer)) {
- if (mType == SPATIALIZER && !track->canBeSpatialized()) {
+ if (mType == SPATIALIZER && !track->isSpatialized()) {
mAudioMixer->setParameter(
trackId,
AudioMixer::TRACK,
@@ -9494,6 +9496,7 @@
(audio_output_flags_t)(AUDIO_OUTPUT_FLAG_MMAP_NOIRQ | AUDIO_OUTPUT_FLAG_DIRECT);
audio_port_handle_t deviceId = mDeviceId;
std::vector<audio_io_handle_t> secondaryOutputs;
+ bool isSpatialized;
ret = AudioSystem::getOutputForAttr(&mAttr, &io,
mSessionId,
&stream,
@@ -9502,7 +9505,8 @@
flags,
&deviceId,
&portId,
- &secondaryOutputs);
+ &secondaryOutputs,
+ &isSpatialized);
ALOGD_IF(!secondaryOutputs.empty(),
"MmapThread::start does not support secondary outputs, ignoring them");
} else {