audiopolicy: check active direct output before adding DIRECT_PCM flag
When getting new output with DIRECT_PCM flag set, the existing direct
pcm output can be closed and interrupted mutually with the requested one.
Don't add DIRECT_PCM flag if there's an active direct output for track
offload.
Change-Id: I250c9555dff2c17f94b57a14a1722bae00fe9f9b
CRs-Fixed: 986087
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index 839f1eb..9008936 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1598,10 +1598,21 @@
flags = AUDIO_OUTPUT_FLAG_TTS;
}
+ // check if direct output for track offload already exits
+ bool is_track_offload_active = false;
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
+ if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
+ is_track_offload_active = true;
+ ALOGD("Track offload already active");
+ break;
+ }
+ }
+
// Do offload magic here
if ((flags == AUDIO_OUTPUT_FLAG_NONE) &&
(stream == AUDIO_STREAM_MUSIC) &&
- (offloadInfo != NULL) &&
+ (offloadInfo != NULL) && !is_track_offload_active &&
((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) {
flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT_PCM);
ALOGD("AudioCustomHAL --> Force Direct Flag .. flag (0x%x)", flags);