summaryrefslogtreecommitdiffstats
path: root/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2016-04-06 18:35:02 -0700
committerSteve Kondik <steve@cyngn.com>2016-04-07 15:19:57 -0700
commita4123803d0a0e9e0c69faa4207d357cc74a65d58 (patch)
tree336ade2306784822373a6a18023136090dd6d343 /services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
parente13b58b988ab642d4ae5ca6d0a89013510714956 (diff)
downloadframeworks_av-a4123803d0a0e9e0c69faa4207d357cc74a65d58.zip
frameworks_av-a4123803d0a0e9e0c69faa4207d357cc74a65d58.tar.gz
frameworks_av-a4123803d0a0e9e0c69faa4207d357cc74a65d58.tar.bz2
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
Diffstat (limited to 'services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp')
-rw-r--r--services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp68
1 files changed, 40 insertions, 28 deletions
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index 766012e..51af20b 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -18,6 +18,7 @@
//#define LOG_NDEBUG 0
#include <utils/Log.h>
+#include <media/AudioPolicyHelper.h>
#include "AudioPolicyService.h"
#include "ServiceUtilities.h"
@@ -162,18 +163,47 @@ status_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr,
return NO_INIT;
}
ALOGV("getOutput()");
- Mutex::Autolock _l(mLock);
+ status_t status;
+ sp<AudioPolicyEffects> audioPolicyEffects;
+ {
+ Mutex::Autolock _l(mLock);
- // if the caller is us, trust the specified uid
- if (IPCThreadState::self()->getCallingPid() != getpid_cached || uid == (uid_t)-1) {
- uid_t newclientUid = IPCThreadState::self()->getCallingUid();
- if (uid != (uid_t)-1 && uid != newclientUid) {
- ALOGW("%s uid %d tried to pass itself off as %d", __FUNCTION__, newclientUid, uid);
+ // if the caller is us, trust the specified uid
+ if (IPCThreadState::self()->getCallingPid() != getpid_cached || uid == (uid_t)-1) {
+ uid_t newclientUid = IPCThreadState::self()->getCallingUid();
+ if (uid != (uid_t)-1 && uid != newclientUid) {
+ ALOGW("%s uid %d tried to pass itself off as %d", __FUNCTION__, newclientUid, uid);
+ }
+ uid = newclientUid;
}
- uid = newclientUid;
+ status = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid, samplingRate,
+ format, channelMask, flags, selectedDeviceId, offloadInfo);
+ audioPolicyEffects = mAudioPolicyEffects;
+ }
+
+ if (audioPolicyEffects != 0) {
+ addOutputSessionEffects(*output, *stream, session, flags, channelMask, uid);
+ }
+
+ return status;
+}
+
+status_t AudioPolicyService::addOutputSessionEffects(audio_io_handle_t output,
+ audio_stream_type_t stream,
+ audio_session_t session,
+ audio_output_flags_t flags,
+ audio_channel_mask_t channelMask,
+ uid_t uid)
+{
+ if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
+ return BAD_VALUE;
}
- return mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid, samplingRate,
- format, channelMask, flags, selectedDeviceId, offloadInfo);
+ if (mAudioPolicyManager == NULL) {
+ return NO_INIT;
+ }
+ ALOGV("addOutputSessionEffects()");
+ return mOutputCommandThread->addOutputSessionEffectsCommand(
+ output, stream, session, flags, channelMask, uid);
}
status_t AudioPolicyService::startOutput(audio_io_handle_t output,
@@ -201,27 +231,9 @@ status_t AudioPolicyService::doStartOutput(audio_io_handle_t output,
return NO_INIT;
}
ALOGV("doStartOutput()");
- sp<AudioPolicyEffects>audioPolicyEffects;
- {
- Mutex::Autolock _l(mLock);
- audioPolicyEffects = mAudioPolicyEffects;
- }
-
- status_t status = NO_ERROR;
- if (audioPolicyEffects != 0) {
- // create audio processors according to stream
- status = audioPolicyEffects->addOutputSessionEffects(output, stream, session);
- if (status <= 0 && (status != NO_ERROR && status != ALREADY_EXISTS)) {
- ALOGW("Failed to add effects on session %d", session);
- }
- }
Mutex::Autolock _l(mLock);
- status_t status2 = mAudioPolicyManager->startOutput(output, stream, session);
- if (audioPolicyEffects != 0 && status > 0 && status2 == NO_ERROR) {
- onOutputSessionEffectsUpdate(stream, session, true);
- }
- return status2;
+ return mAudioPolicyManager->startOutput(output, stream, session);
}
status_t AudioPolicyService::stopOutput(audio_io_handle_t output,