policy_hal: handle compress offload concurrency
If multiple offload capability is disabled, subsequent session will
either try to reuse or close the previous offload session. Hence,
offload session from varoius clients will interfere with each other.
Fallback to non-direct output when compress offload is already active
and clients are not same. Force deep-buffer when falling back from
compress offload to non-direct outputs.
Change-Id: I6699af71b83c54651976029a9e71be0c99551db6
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index cc5747c..9ccd2c1 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1654,9 +1654,10 @@
*flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_NONE);
}
- // check if direct output for pcm/track offload already exits
+ // check if direct output for pcm/track offload or compress offload already exist
bool direct_pcm_already_in_use = false;
- if (*flags == AUDIO_OUTPUT_FLAG_DIRECT) {
+ bool compress_offload_already_in_use = false;
+ if (*flags & AUDIO_OUTPUT_FLAG_DIRECT) {
for (size_t i = 0; i < mOutputs.size(); i++) {
sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
if (desc->mFlags == AUDIO_OUTPUT_FLAG_DIRECT) {
@@ -1664,6 +1665,11 @@
ALOGD("Direct PCM already in use");
break;
}
+ if (desc->mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
+ compress_offload_already_in_use = true;
+ ALOGD("Compress Offload already in use");
+ break;
+ }
}
// prevent direct pcm for non-music stream blindly if direct pcm already in use
// for other music stream concurrency is handled after checking direct ouput usage
@@ -1677,9 +1683,10 @@
bool forced_deep = false;
// only allow deep buffering for music stream type
if (stream != AUDIO_STREAM_MUSIC) {
- *flags = (audio_output_flags_t)(*flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
+ *flags = (audio_output_flags_t)(*flags & ~AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
} else if (/* stream == AUDIO_STREAM_MUSIC && */
- (*flags == AUDIO_OUTPUT_FLAG_NONE || *flags == AUDIO_OUTPUT_FLAG_DIRECT) &&
+ (*flags == AUDIO_OUTPUT_FLAG_NONE || *flags == AUDIO_OUTPUT_FLAG_DIRECT ||
+ (*flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) &&
mApmConfigs->isAudioDeepbufferMediaEnabled() && !isInCall()) {
forced_deep = true;
}
@@ -1764,8 +1771,9 @@
}
}
if (outputDesc != NULL) {
- if (*flags == AUDIO_OUTPUT_FLAG_DIRECT &&
- direct_pcm_already_in_use == true &&
+ if ((((*flags == AUDIO_OUTPUT_FLAG_DIRECT) && direct_pcm_already_in_use) ||
+ ((*flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
+ compress_offload_already_in_use)) &&
session != outputDesc->mDirectClientSession) {
ALOGV("getOutput() do not reuse direct pcm output because current client (%d) "
"is not the same as requesting client (%d) for different output conf",