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/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 2813f72..894b31c 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -585,14 +585,14 @@
fullConfig.channel_mask = config->channel_mask;
fullConfig.format = config->format;
std::vector<audio_io_handle_t> secondaryOutputs;
-
+ bool isSpatialized;
ret = AudioSystem::getOutputForAttr(&localAttr, &io,
actualSessionId,
&streamType, client.attributionSource,
&fullConfig,
(audio_output_flags_t)(AUDIO_OUTPUT_FLAG_MMAP_NOIRQ |
AUDIO_OUTPUT_FLAG_DIRECT),
- deviceId, &portId, &secondaryOutputs);
+ deviceId, &portId, &secondaryOutputs, &isSpatialized);
ALOGW_IF(!secondaryOutputs.empty(),
"%s does not support secondary outputs, ignoring them", __func__);
} else {
@@ -1034,6 +1034,7 @@
audio_stream_type_t streamType;
audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
std::vector<audio_io_handle_t> secondaryOutputs;
+ bool isSpatialized = false;;
// TODO b/182392553: refactor or make clearer
pid_t clientPid =
@@ -1077,7 +1078,8 @@
output.selectedDeviceId = input.selectedDeviceId;
lStatus = AudioSystem::getOutputForAttr(&localAttr, &output.outputId, sessionId, &streamType,
adjAttributionSource, &input.config, input.flags,
- &output.selectedDeviceId, &portId, &secondaryOutputs);
+ &output.selectedDeviceId, &portId, &secondaryOutputs,
+ &isSpatialized);
if (lStatus != NO_ERROR || output.outputId == AUDIO_IO_HANDLE_NONE) {
ALOGE("createTrack() getOutputForAttr() return error %d or invalid output handle", lStatus);
@@ -1143,7 +1145,7 @@
input.notificationsPerBuffer, input.speed,
input.sharedBuffer, sessionId, &output.flags,
callingPid, adjAttributionSource, input.clientInfo.clientTid,
- &lStatus, portId, input.audioTrackCallback);
+ &lStatus, portId, input.audioTrackCallback, isSpatialized);
LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (track == 0));
// we don't abort yet if lStatus != NO_ERROR; there is still work to be done regardless
diff --git a/services/audioflinger/PlaybackTracks.h b/services/audioflinger/PlaybackTracks.h
index aecd4d3..6a138bb 100644
--- a/services/audioflinger/PlaybackTracks.h
+++ b/services/audioflinger/PlaybackTracks.h
@@ -82,7 +82,8 @@
/** default behaviour is to start when there are as many frames
* ready as possible (aka. Buffer is full). */
size_t frameCountToBeReady = SIZE_MAX,
- float speed = 1.0f);
+ float speed = 1.0f,
+ bool isSpatialized = false);
virtual ~Track();
virtual status_t initCheck() const;
@@ -201,6 +202,7 @@
audio_output_flags_t getOutputFlags() const { return mFlags; }
float getSpeed() const { return mSpeed; }
+ bool isSpatialized() const override { return mIsSpatialized; }
protected:
// for numerous
@@ -351,6 +353,7 @@
audio_output_flags_t mFlags;
TeePatches mTeePatches;
const float mSpeed;
+ const bool mIsSpatialized;
}; // end of Track
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 {
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index 982893d..1fccdc5 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -483,7 +483,7 @@
if (track->isFastTrack()) {
result |= FAST_SESSION; // caution, only represents first track.
}
- if (track->canBeSpatialized()) {
+ if (track->isSpatialized()) {
result |= SPATIALIZED_SESSION; // caution, only first track.
}
break;
@@ -960,7 +960,8 @@
pid_t tid,
status_t *status /*non-NULL*/,
audio_port_handle_t portId,
- const sp<media::IAudioTrackCallback>& callback);
+ const sp<media::IAudioTrackCallback>& callback,
+ bool isSpatialized);
AudioStreamOut* getOutput() const;
AudioStreamOut* clearOutput();
diff --git a/services/audioflinger/TrackBase.h b/services/audioflinger/TrackBase.h
index 98a1bd9..2677ab3 100644
--- a/services/audioflinger/TrackBase.h
+++ b/services/audioflinger/TrackBase.h
@@ -107,9 +107,7 @@
audio_attributes_t attributes() const { return mAttr; }
- bool canBeSpatialized() const { return mIsOut && (mAttr.flags
- & (AUDIO_FLAG_CONTENT_SPATIALIZED | AUDIO_FLAG_NEVER_SPATIALIZE)) == 0
- && mChannelCount > 2; }
+ virtual bool isSpatialized() const { return false; }
#ifdef TEE_SINK
void dumpTee(int fd, const std::string &reason) const {
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index 279ff3d..6135020 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -633,7 +633,8 @@
track_type type,
audio_port_handle_t portId,
size_t frameCountToBeReady,
- float speed)
+ float speed,
+ bool isSpatialized)
: TrackBase(thread, client, attr, sampleRate, format, channelMask, frameCount,
// TODO: Using unsecurePointer() has some associated security pitfalls
// (see declaration for details).
@@ -667,7 +668,8 @@
mResumeToStopping(false),
mFlushHwPending(false),
mFlags(flags),
- mSpeed(speed)
+ mSpeed(speed),
+ mIsSpatialized(isSpatialized)
{
// client == 0 implies sharedBuffer == 0
ALOG_ASSERT(!(client == 0 && sharedBuffer != 0));