From a4123803d0a0e9e0c69faa4207d357cc74a65d58 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Wed, 6 Apr 2016 18:35:02 -0700 Subject: audiopolicy: Be a little smarter with auto-attach * The edge cases, ZOMG! * Instead of relying on effects to be automatically attached, let's just always notify userspace and send a bit more information. This lets the application decide if effects should be attached rather than relying on a hard-coded configuration file. * Perform the setup in getOutputForAttr, but do it on the command thread so we don't block the client. OPO-593 Change-Id: I3900b349f2e895d51fa3a3dcc2de0c4bdf6dbc08 --- .../audiopolicy/service/AudioPolicyEffects.cpp | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'services/audiopolicy/service/AudioPolicyEffects.cpp') diff --git a/services/audiopolicy/service/AudioPolicyEffects.cpp b/services/audiopolicy/service/AudioPolicyEffects.cpp index 725bc64..bd1cc33 100644 --- a/services/audiopolicy/service/AudioPolicyEffects.cpp +++ b/services/audiopolicy/service/AudioPolicyEffects.cpp @@ -246,6 +246,7 @@ status_t AudioPolicyEffects::addOutputSessionEffects(audio_io_handle_t output, if (idx < 0) { procDesc = new EffectVector(audioSession); mOutputSessions.add(audioSession, procDesc); + } else { // EffectVector is existing and we just need to increase ref count procDesc = mOutputSessions.valueAt(idx); @@ -273,11 +274,35 @@ status_t AudioPolicyEffects::addOutputSessionEffects(audio_io_handle_t output, } procDesc->setProcessorEnabled(true); - return 1; } return status; } +status_t AudioPolicyEffects::doAddOutputSessionEffects(audio_io_handle_t output, + audio_stream_type_t stream, + int session, + audio_output_flags_t flags, + audio_channel_mask_t channelMask, uid_t uid) +{ + if (uint32_t(stream) >= AUDIO_STREAM_CNT) { + return BAD_VALUE; + } + ALOGV("doAddOutputSessionEffects()"); + + // create audio processors according to stream + status_t status = addOutputSessionEffects(output, stream, session); + if (status <= 0 && (status != NO_ERROR && status != ALREADY_EXISTS)) { + ALOGW("Failed to add effects on session %d", session); + } + + // notify listeners + mAudioPolicyService->onOutputSessionEffectsUpdate(stream, (audio_session_t)session, + flags, channelMask, uid, true); + + // Never return an error if effects setup fails. + return NO_ERROR; +} + status_t AudioPolicyEffects::releaseOutputSessionEffects(audio_io_handle_t output, audio_stream_type_t stream, int audioSession) @@ -335,10 +360,13 @@ status_t AudioPolicyEffects::doReleaseOutputSessionEffects(audio_io_handle_t out procDesc->mEffects.clear(); delete procDesc; mOutputSessions.removeItemsAt(index); - mAudioPolicyService->onOutputSessionEffectsUpdate(stream, audioSession, false); ALOGV("doReleaseOutputSessionEffects(): output processing released from session: %d", audioSession); } + + mAudioPolicyService->onOutputSessionEffectsUpdate(stream, (audio_session_t)audioSession, + AUDIO_OUTPUT_FLAG_NONE, 0, -1, false); + return status; } -- cgit v1.1