From 9210450a8b62805c8e961aa66e025c1a84a4b382 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Wed, 10 Dec 2014 11:21:49 -0800 Subject: audio policy: suppport for dynamic source Completed support for dynamic sources: - remote submix input device is dynamically connected/disconnected when corresponding AudioTrack starts/stops. Also do not create a duplicated output for mixes used by dynamic policies. Bug: 16006090. Change-Id: Ib5b5a2159fcac9d9f410a5a2f1c64d7ebad79f72 --- services/audiopolicy/AudioPolicyManager.cpp | 140 +++++++++++++++++++--------- services/audiopolicy/AudioPolicyManager.h | 9 +- 2 files changed, 101 insertions(+), 48 deletions(-) (limited to 'services/audiopolicy') diff --git a/services/audiopolicy/AudioPolicyManager.cpp b/services/audiopolicy/AudioPolicyManager.cpp index 9918b6f..3cd5fb2 100644 --- a/services/audiopolicy/AudioPolicyManager.cpp +++ b/services/audiopolicy/AudioPolicyManager.cpp @@ -899,14 +899,13 @@ status_t AudioPolicyManager::getOutputForAttr(const audio_attributes_t *attr, mPolicyMixes[i]->mMix.mRegistrationId.string(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - strlen("addr=") - 1) == 0) { desc = mPolicyMixes[i]->mOutput; - break; } } if (desc != 0) { if (!audio_is_linear_pcm(format)) { return BAD_VALUE; } - desc->mPolicyMixAddress = mPolicyMixes[i]->mMix.mRegistrationId; + desc->mPolicyMix = &mPolicyMixes[i]->mMix; *stream = streamTypefromAttributesInt(&attributes); *output = desc->mIoHandle; ALOGV("getOutputForAttr() returns output %d", *output); @@ -1227,8 +1226,7 @@ status_t AudioPolicyManager::startOutput(audio_io_handle_t output, if (outputDesc->mRefCount[stream] == 1) { // starting an output being rerouted? audio_devices_t newDevice; - if (outputDesc->mPolicyMixAddress != String8("") - && outputDesc->mPolicyMixAddress != String8("0")) { + if (outputDesc->mPolicyMix != NULL) { newDevice = AUDIO_DEVICE_OUT_REMOTE_SUBMIX; } else { newDevice = getNewOutputDevice(output, false /*fromCache*/); @@ -1275,6 +1273,16 @@ status_t AudioPolicyManager::startOutput(audio_io_handle_t output, // update the outputs if starting an output with a stream that can affect notification // routing handleNotificationRoutingForStream(stream); + + // Automatically enable the remote submix input when output is started on a re routing mix + // of type MIX_TYPE_RECORDERS + if (audio_is_remote_submix_device(newDevice) && outputDesc->mPolicyMix != NULL && + outputDesc->mPolicyMix->mMixType == MIX_TYPE_RECORDERS) { + setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, + AUDIO_POLICY_DEVICE_STATE_AVAILABLE, + outputDesc->mPolicyMix->mRegistrationId); + } + if (waitMs > muteWaitMs) { usleep((waitMs - muteWaitMs) * 2 * 1000); } @@ -1309,6 +1317,16 @@ status_t AudioPolicyManager::stopOutput(audio_io_handle_t output, outputDesc->changeRefCount(stream, -1); // store time at which the stream was stopped - see isStreamActive() if (outputDesc->mRefCount[stream] == 0) { + // Automatically disable the remote submix input when output is stopped on a + // re routing mix of type MIX_TYPE_RECORDERS + if (audio_is_remote_submix_device(outputDesc->mDevice) && + outputDesc->mPolicyMix != NULL && + outputDesc->mPolicyMix->mMixType == MIX_TYPE_RECORDERS) { + setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, + AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, + outputDesc->mPolicyMix->mRegistrationId); + } + outputDesc->mStopTime[stream] = systemTime(); audio_devices_t newDevice = getNewOutputDevice(output, false /*fromCache*/); // delay the device switch by twice the latency because stopOutput() is executed when @@ -1406,6 +1424,7 @@ status_t AudioPolicyManager::getInputForAttr(const audio_attributes_t *attr, String8 address = String8(""); bool isSoundTrigger = false; audio_source_t halInputSource = attr->source; + AudioMix *policyMix = NULL; if (attr->source == AUDIO_SOURCE_REMOTE_SUBMIX && strncmp(attr->tags, "addr=", strlen("addr=")) == 0) { @@ -1416,13 +1435,22 @@ status_t AudioPolicyManager::getInputForAttr(const audio_attributes_t *attr, ALOGW("getInputForAttr() no policy for address %s", address.string()); return BAD_VALUE; } + if (mPolicyMixes[index]->mMix.mMixType != MIX_TYPE_PLAYERS) { + ALOGW("getInputForAttr() bad policy mix type for address %s", address.string()); + return BAD_VALUE; + } + policyMix = &mPolicyMixes[index]->mMix; } else { - device = getDeviceForInputSource(attr->source, &address); - + device = getDeviceForInputSource(attr->source, &policyMix); if (device == AUDIO_DEVICE_NONE) { ALOGW("getInputForAttr() could not find device for source %d", attr->source); return BAD_VALUE; } + if (policyMix != NULL) { + address = policyMix->mRegistrationId; + } else if (audio_is_remote_submix_device(device)) { + address = String8("0"); + } // adapt channel selection to input source switch (attr->source) { case AUDIO_SOURCE_VOICE_UPLINK: @@ -1507,8 +1535,9 @@ status_t AudioPolicyManager::getInputForAttr(const audio_attributes_t *attr, inputDesc->mFormat = format; inputDesc->mChannelMask = channelMask; inputDesc->mDevice = device; - inputDesc->mSessions.add(session, address); + inputDesc->mSessions.add(session); inputDesc->mIsSoundTrigger = isSoundTrigger; + inputDesc->mPolicyMix = policyMix; addInput(*input, inputDesc); mpClientInterface->onAudioPortListUpdate(); @@ -1526,7 +1555,7 @@ status_t AudioPolicyManager::startInput(audio_io_handle_t input, } sp inputDesc = mInputs.valueAt(index); - index = inputDesc->mSessions.indexOfKey(session); + index = inputDesc->mSessions.indexOf(session); if (index < 0) { ALOGW("startInput() unknown session %d on input %d", session, input); return BAD_VALUE; @@ -1544,8 +1573,8 @@ status_t AudioPolicyManager::startInput(audio_io_handle_t input, sp activeDesc = mInputs.valueFor(activeInput); if (activeDesc->mInputSource == AUDIO_SOURCE_HOTWORD) { ALOGW("startInput(%d) preempting low-priority input %d", input, activeInput); - stopInput(activeInput, activeDesc->mSessions.keyAt(0)); - releaseInput(activeInput, activeDesc->mSessions.keyAt(0)); + stopInput(activeInput, activeDesc->mSessions.itemAt(0)); + releaseInput(activeInput, activeDesc->mSessions.itemAt(0)); } else { ALOGE("startInput(%d) failed: other input %d already started", input, activeInput); return INVALID_OPERATION; @@ -1559,12 +1588,21 @@ status_t AudioPolicyManager::startInput(audio_io_handle_t input, } setInputDevice(input, getNewInputDevice(input), true /* force */); - // Automatically enable the remote submix output when input is started. + // automatically enable the remote submix output when input is started if not + // used by a policy mix of type MIX_TYPE_RECORDERS // For remote submix (a virtual device), we open only one input per capture request. if (audio_is_remote_submix_device(inputDesc->mDevice)) { - setDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, - AUDIO_POLICY_DEVICE_STATE_AVAILABLE, - inputDesc->mSessions.valueAt(index)); + String8 address = String8(""); + if (inputDesc->mPolicyMix == NULL) { + address = String8("0"); + } else if (inputDesc->mPolicyMix->mMixType == MIX_TYPE_PLAYERS) { + address = inputDesc->mPolicyMix->mRegistrationId; + } + if (address != "") { + setDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, + AUDIO_POLICY_DEVICE_STATE_AVAILABLE, + address); + } } } @@ -1585,7 +1623,7 @@ status_t AudioPolicyManager::stopInput(audio_io_handle_t input, } sp inputDesc = mInputs.valueAt(index); - index = inputDesc->mSessions.indexOfKey(session); + index = inputDesc->mSessions.indexOf(session); if (index < 0) { ALOGW("stopInput() unknown session %d on input %d", session, input); return BAD_VALUE; @@ -1599,11 +1637,20 @@ status_t AudioPolicyManager::stopInput(audio_io_handle_t input, inputDesc->mRefCount--; if (inputDesc->mRefCount == 0) { - // automatically disable the remote submix output when input is stopped + // automatically disable the remote submix output when input is stopped if not + // used by a policy mix of type MIX_TYPE_RECORDERS if (audio_is_remote_submix_device(inputDesc->mDevice)) { - setDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, - AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, - inputDesc->mSessions.valueAt(index)); + String8 address = String8(""); + if (inputDesc->mPolicyMix == NULL) { + address = String8("0"); + } else if (inputDesc->mPolicyMix->mMixType == MIX_TYPE_PLAYERS) { + address = inputDesc->mPolicyMix->mRegistrationId; + } + if (address != "") { + setDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, + AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, + address); + } } resetInputDevice(input); @@ -1627,12 +1674,12 @@ void AudioPolicyManager::releaseInput(audio_io_handle_t input, sp inputDesc = mInputs.valueAt(index); ALOG_ASSERT(inputDesc != 0); - index = inputDesc->mSessions.indexOfKey(session); + index = inputDesc->mSessions.indexOf(session); if (index < 0) { ALOGW("releaseInput() unknown session %d on input %d", session, input); return; } - inputDesc->mSessions.removeItem(session); + inputDesc->mSessions.remove(session); if (inputDesc->mOpenRefCount == 0) { ALOGW("releaseInput() invalid open ref count %d", inputDesc->mOpenRefCount); return; @@ -1961,10 +2008,9 @@ bool AudioPolicyManager::isStreamActiveRemotely(audio_stream_type_t stream, const sp outputDesc = mOutputs.valueAt(i); if (((outputDesc->device() & APM_AUDIO_OUT_DEVICE_REMOTE_ALL) != 0) && outputDesc->isStreamActive(stream, inPastMs, sysTime)) { - // only consider empty or "0" address to only qualify the screen mirroring case - // as "remote playback" (vs rerouting when the output is going to a dynamic policy) - if (outputDesc->mPolicyMixAddress == String8("") - || outputDesc->mPolicyMixAddress == String8("0")) { + // do not consider re routing (when the output is going to a dynamic policy) + // as "remote playback" + if (outputDesc->mPolicyMix == NULL) { return true; } } @@ -2046,9 +2092,15 @@ status_t AudioPolicyManager::registerPolicyMixes(Vector mixes) sp policyMix = new AudioPolicyMix(); policyMix->mMix = mixes[i]; mPolicyMixes.add(address, policyMix); - setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, - AUDIO_POLICY_DEVICE_STATE_AVAILABLE, - address.string()); + if (mixes[i].mMixType == MIX_TYPE_PLAYERS) { + setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, + AUDIO_POLICY_DEVICE_STATE_AVAILABLE, + address.string()); + } else { + setDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, + AUDIO_POLICY_DEVICE_STATE_AVAILABLE, + address.string()); + } } return NO_ERROR; } @@ -2080,9 +2132,13 @@ status_t AudioPolicyManager::unregisterPolicyMixes(Vector mixes) mPolicyMixes.removeItemsAt(index); - setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, - AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, - address.string()); + if (getDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, address.string()) == + AUDIO_POLICY_DEVICE_STATE_AVAILABLE) + { + setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, + AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, + address.string()); + } if (getDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, address.string()) == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) @@ -3543,12 +3599,14 @@ status_t AudioPolicyManager::checkOutputsForDevice(const sp de ssize_t index = mPolicyMixes.indexOfKey(address); if (index >= 0) { mPolicyMixes[index]->mOutput = desc; + desc->mPolicyMix = &mPolicyMixes[index]->mMix; } else { ALOGE("checkOutputsForDevice() cannot find policy for address %s", address.string()); } - } - if ((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) == 0) { + } else if ((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) == 0) { + // no duplicated output for direct outputs and + // outputs used by dynamic policy mixes audio_io_handle_t duplicatedOutput = AUDIO_IO_HANDLE_NONE; // set initial stream volume for device @@ -5014,7 +5072,7 @@ sp AudioPolicyManager::getInputProfile(audio_devi } audio_devices_t AudioPolicyManager::getDeviceForInputSource(audio_source_t inputSource, - String8 *address) + AudioMix **policyMix) { uint32_t device = AUDIO_DEVICE_NONE; audio_devices_t availableDeviceTypes = mAvailableInputDevices.types() & @@ -5030,8 +5088,8 @@ audio_devices_t AudioPolicyManager::getDeviceForInputSource(audio_source_t input (RULE_EXCLUDE_ATTRIBUTE_CAPTURE_PRESET == mPolicyMixes[i]->mMix.mCriteria[j].mRule && mPolicyMixes[i]->mMix.mCriteria[j].mAttr.mSource != inputSource)) { if (availableDeviceTypes & AUDIO_DEVICE_IN_REMOTE_SUBMIX) { - if (address != NULL) { - *address = mPolicyMixes[i]->mMix.mRegistrationId; + if (policyMix != NULL) { + *policyMix = &mPolicyMixes[i]->mMix; } return AUDIO_DEVICE_IN_REMOTE_SUBMIX; } @@ -5127,9 +5185,6 @@ audio_devices_t AudioPolicyManager::getDeviceForInputSource(audio_source_t input case AUDIO_SOURCE_REMOTE_SUBMIX: if (availableDeviceTypes & AUDIO_DEVICE_IN_REMOTE_SUBMIX) { device = AUDIO_DEVICE_IN_REMOTE_SUBMIX; - if (address != NULL) { - *address = "0"; - } } break; case AUDIO_SOURCE_FM_TUNER: @@ -5571,8 +5626,7 @@ status_t AudioPolicyManager::checkAndSetVolume(audio_stream_type_t stream, ssize_t index = mOutputs.indexOfKey(output); if (index >= 0) { sp outputDesc = mOutputs.valueAt(index); - if (outputDesc->mPolicyMixAddress != String8("") - && outputDesc->mPolicyMixAddress != String8("0")) { + if (outputDesc->mPolicyMix != NULL) { ALOGV("max gain when rerouting for output=%d", output); volume = 1.0f; } @@ -5761,7 +5815,7 @@ uint32_t AudioPolicyManager::getMaxEffectsMemory() AudioPolicyManager::AudioOutputDescriptor::AudioOutputDescriptor( const sp& profile) : mId(0), mIoHandle(0), mLatency(0), - mFlags((audio_output_flags_t)0), mDevice(AUDIO_DEVICE_NONE), mPolicyMixAddress(String8("")), + mFlags((audio_output_flags_t)0), mDevice(AUDIO_DEVICE_NONE), mPolicyMix(NULL), mPatchHandle(0), mOutput1(0), mOutput2(0), mProfile(profile), mDirectOpenCount(0) { @@ -5957,7 +6011,7 @@ status_t AudioPolicyManager::AudioOutputDescriptor::dump(int fd) AudioPolicyManager::AudioInputDescriptor::AudioInputDescriptor(const sp& profile) : mId(0), mIoHandle(0), - mDevice(AUDIO_DEVICE_NONE), mPatchHandle(0), mRefCount(0), + mDevice(AUDIO_DEVICE_NONE), mPolicyMix(NULL), mPatchHandle(0), mRefCount(0), mInputSource(AUDIO_SOURCE_DEFAULT), mProfile(profile), mIsSoundTrigger(false) { if (profile != NULL) { diff --git a/services/audiopolicy/AudioPolicyManager.h b/services/audiopolicy/AudioPolicyManager.h index 3eef8fe..9ec3557 100644 --- a/services/audiopolicy/AudioPolicyManager.h +++ b/services/audiopolicy/AudioPolicyManager.h @@ -497,7 +497,7 @@ protected: uint32_t mLatency; // audio_output_flags_t mFlags; // audio_devices_t mDevice; // current device this output is routed to - String8 mPolicyMixAddress; // non empty or "0" when used by a dynamic policy + AudioMix *mPolicyMix; // non NULL when used by a dynamic policy audio_patch_handle_t mPatchHandle; uint32_t mRefCount[AUDIO_STREAM_CNT]; // number of streams of each type using this output nsecs_t mStopTime[AUDIO_STREAM_CNT]; @@ -523,6 +523,7 @@ protected: audio_port_handle_t mId; audio_io_handle_t mIoHandle; // input handle audio_devices_t mDevice; // current device this input is routed to + AudioMix *mPolicyMix; // non NULL when used by a dynamic policy audio_patch_handle_t mPatchHandle; uint32_t mRefCount; // number of AudioRecord clients using // this input @@ -530,9 +531,7 @@ protected: audio_source_t mInputSource; // input source selected by application //(mediarecorder.h) const sp mProfile; // I/O profile this output derives from - // audio sessions attached to this input and the - // corresponding device address - DefaultKeyedVector mSessions; + SortedVector mSessions; // audio sessions attached to this input bool mIsSoundTrigger; // used by a soundtrigger capture virtual void toAudioPortConfig(struct audio_port_config *dstConfig, @@ -612,7 +611,7 @@ protected: // select input device corresponding to requested audio source virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource, - String8 *address = NULL); + AudioMix **policyMix = NULL); // return io handle of active input or 0 if no input is active // Only considers inputs from physical devices (e.g. main mic, headset mic) when -- cgit v1.1 From fa736496b3a7c1de2a4dbe2ced5bb62df4db6a6e Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Fri, 12 Dec 2014 14:34:22 -0800 Subject: audio policy: fix remote mic capture commit 275e8e9de introduced a regression for platforms overriding AudioPolicyManager::getDeviceForInputSource() method. Fixed by defining specific non virtual methods when overiding would break remote submix implementation. Bug: 18736417. Change-Id: Id4d0a6c48da987e6fb24422f2d61c7ab0fbfc921 --- services/audiopolicy/AudioPolicyManager.cpp | 47 ++++++++++++++++++++--------- services/audiopolicy/AudioPolicyManager.h | 13 ++++++-- 2 files changed, 43 insertions(+), 17 deletions(-) (limited to 'services/audiopolicy') diff --git a/services/audiopolicy/AudioPolicyManager.cpp b/services/audiopolicy/AudioPolicyManager.cpp index 3cd5fb2..744556d 100644 --- a/services/audiopolicy/AudioPolicyManager.cpp +++ b/services/audiopolicy/AudioPolicyManager.cpp @@ -215,6 +215,13 @@ status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device, audio_policy_dev_state_t state, const char *device_address) { + return setDeviceConnectionStateInt(device, state, device_address); +} + +status_t AudioPolicyManager::setDeviceConnectionStateInt(audio_devices_t device, + audio_policy_dev_state_t state, + const char *device_address) +{ String8 address = (device_address == NULL) ? String8("") : String8(device_address); // handle legacy remote submix case where the address was not always specified if (deviceDistinguishesOnAddress(device) && (address.length() == 0)) { @@ -457,7 +464,7 @@ void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs audio_patch_handle_t afPatchHandle; DeviceVector deviceList; - audio_devices_t txDevice = getDeviceForInputSource(AUDIO_SOURCE_VOICE_COMMUNICATION); + audio_devices_t txDevice = getDeviceAndMixForInputSource(AUDIO_SOURCE_VOICE_COMMUNICATION); ALOGV("updateCallRouting device rxDevice %08x txDevice %08x", rxDevice, txDevice); // release existing RX patch if any @@ -1278,7 +1285,7 @@ status_t AudioPolicyManager::startOutput(audio_io_handle_t output, // of type MIX_TYPE_RECORDERS if (audio_is_remote_submix_device(newDevice) && outputDesc->mPolicyMix != NULL && outputDesc->mPolicyMix->mMixType == MIX_TYPE_RECORDERS) { - setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, + setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, outputDesc->mPolicyMix->mRegistrationId); } @@ -1322,7 +1329,7 @@ status_t AudioPolicyManager::stopOutput(audio_io_handle_t output, if (audio_is_remote_submix_device(outputDesc->mDevice) && outputDesc->mPolicyMix != NULL && outputDesc->mPolicyMix->mMixType == MIX_TYPE_RECORDERS) { - setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, + setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, outputDesc->mPolicyMix->mRegistrationId); } @@ -1441,7 +1448,7 @@ status_t AudioPolicyManager::getInputForAttr(const audio_attributes_t *attr, } policyMix = &mPolicyMixes[index]->mMix; } else { - device = getDeviceForInputSource(attr->source, &policyMix); + device = getDeviceAndMixForInputSource(attr->source, &policyMix); if (device == AUDIO_DEVICE_NONE) { ALOGW("getInputForAttr() could not find device for source %d", attr->source); return BAD_VALUE; @@ -1599,7 +1606,7 @@ status_t AudioPolicyManager::startInput(audio_io_handle_t input, address = inputDesc->mPolicyMix->mRegistrationId; } if (address != "") { - setDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, + setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, address); } @@ -1647,7 +1654,7 @@ status_t AudioPolicyManager::stopInput(audio_io_handle_t input, address = inputDesc->mPolicyMix->mRegistrationId; } if (address != "") { - setDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, + setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, address); } @@ -2093,11 +2100,11 @@ status_t AudioPolicyManager::registerPolicyMixes(Vector mixes) policyMix->mMix = mixes[i]; mPolicyMixes.add(address, policyMix); if (mixes[i].mMixType == MIX_TYPE_PLAYERS) { - setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, + setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, address.string()); } else { - setDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, + setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, AUDIO_POLICY_DEVICE_STATE_AVAILABLE, address.string()); } @@ -2135,7 +2142,7 @@ status_t AudioPolicyManager::unregisterPolicyMixes(Vector mixes) if (getDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, address.string()) == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) { - setDeviceConnectionState(AUDIO_DEVICE_IN_REMOTE_SUBMIX, + setDeviceConnectionStateInt(AUDIO_DEVICE_IN_REMOTE_SUBMIX, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, address.string()); } @@ -2143,7 +2150,7 @@ status_t AudioPolicyManager::unregisterPolicyMixes(Vector mixes) if (getDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, address.string()) == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) { - setDeviceConnectionState(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, + setDeviceConnectionStateInt(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, address.string()); } @@ -2896,7 +2903,7 @@ status_t AudioPolicyManager::acquireSoundTriggerSession(audio_session_t *session { *session = (audio_session_t)mpClientInterface->newAudioUniqueId(); *ioHandle = (audio_io_handle_t)mpClientInterface->newAudioUniqueId(); - *device = getDeviceForInputSource(AUDIO_SOURCE_HOTWORD); + *device = getDeviceAndMixForInputSource(AUDIO_SOURCE_HOTWORD); mSoundTriggerSessions.add(*session, *ioHandle); @@ -4224,7 +4231,7 @@ audio_devices_t AudioPolicyManager::getNewInputDevice(audio_io_handle_t input) } } - audio_devices_t device = getDeviceForInputSource(inputDesc->mInputSource); + audio_devices_t device = getDeviceAndMixForInputSource(inputDesc->mInputSource); ALOGV("getNewInputDevice() selected device %x", device); return device; @@ -4490,7 +4497,8 @@ audio_devices_t AudioPolicyManager::getDeviceForStrategy(routing_strategy strate // - cannot route from voice call RX OR // - audio HAL version is < 3.0 and TX device is on the primary HW module if (mPhoneState == AUDIO_MODE_IN_CALL) { - audio_devices_t txDevice = getDeviceForInputSource(AUDIO_SOURCE_VOICE_COMMUNICATION); + audio_devices_t txDevice = + getDeviceAndMixForInputSource(AUDIO_SOURCE_VOICE_COMMUNICATION); sp hwOutputDesc = mOutputs.valueFor(mPrimaryOutput); if (((mAvailableInputDevices.types() & AUDIO_DEVICE_IN_TELEPHONY_RX & ~AUDIO_DEVICE_BIT_IN) == 0) || @@ -5071,10 +5079,10 @@ sp AudioPolicyManager::getInputProfile(audio_devi return NULL; } -audio_devices_t AudioPolicyManager::getDeviceForInputSource(audio_source_t inputSource, + +audio_devices_t AudioPolicyManager::getDeviceAndMixForInputSource(audio_source_t inputSource, AudioMix **policyMix) { - uint32_t device = AUDIO_DEVICE_NONE; audio_devices_t availableDeviceTypes = mAvailableInputDevices.types() & ~AUDIO_DEVICE_BIT_IN; @@ -5098,6 +5106,15 @@ audio_devices_t AudioPolicyManager::getDeviceForInputSource(audio_source_t input } } + return getDeviceForInputSource(inputSource); +} + +audio_devices_t AudioPolicyManager::getDeviceForInputSource(audio_source_t inputSource) +{ + uint32_t device = AUDIO_DEVICE_NONE; + audio_devices_t availableDeviceTypes = mAvailableInputDevices.types() & + ~AUDIO_DEVICE_BIT_IN; + switch (inputSource) { case AUDIO_SOURCE_VOICE_UPLINK: if (availableDeviceTypes & AUDIO_DEVICE_IN_VOICE_CALL) { diff --git a/services/audiopolicy/AudioPolicyManager.h b/services/audiopolicy/AudioPolicyManager.h index 9ec3557..ff3afab 100644 --- a/services/audiopolicy/AudioPolicyManager.h +++ b/services/audiopolicy/AudioPolicyManager.h @@ -610,8 +610,7 @@ protected: audio_patch_handle_t *patchHandle = NULL); // select input device corresponding to requested audio source - virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource, - AudioMix **policyMix = NULL); + virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource); // return io handle of active input or 0 if no input is active // Only considers inputs from physical devices (e.g. main mic, headset mic) when @@ -914,6 +913,16 @@ private: uint32_t handleEventForBeacon(int event); uint32_t setBeaconMute(bool mute); bool isValidAttributes(const audio_attributes_t *paa); + + // select input device corresponding to requested audio source and return associated policy + // mix if any. Calls getDeviceForInputSource(). + audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource, + AudioMix **policyMix = NULL); + + // Called by setDeviceConnectionState(). + status_t setDeviceConnectionStateInt(audio_devices_t device, + audio_policy_dev_state_t state, + const char *device_address); }; }; -- cgit v1.1 From 5db7897ddd32e3ec3ab45ecdb6f21b6265e7e14a Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Wed, 7 Jan 2015 10:42:33 -0800 Subject: make libserviceutility a shared lib so that we have only one getpid_cached in mediaserver process bug: 18919657 Change-Id: Iff3cd932c9110e874b3885f79705f49bf3e3f1fc --- services/audiopolicy/Android.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'services/audiopolicy') diff --git a/services/audiopolicy/Android.mk b/services/audiopolicy/Android.mk index 6512c38..188fc89 100644 --- a/services/audiopolicy/Android.mk +++ b/services/audiopolicy/Android.mk @@ -30,7 +30,8 @@ LOCAL_SHARED_LIBRARIES := \ libbinder \ libmedia \ libhardware \ - libhardware_legacy + libhardware_legacy \ + libserviceutility ifneq ($(USE_LEGACY_AUDIO_POLICY), 1) LOCAL_SHARED_LIBRARIES += \ @@ -38,8 +39,7 @@ LOCAL_SHARED_LIBRARIES += \ endif LOCAL_STATIC_LIBRARIES := \ - libmedia_helper \ - libserviceutility + libmedia_helper LOCAL_MODULE:= libaudiopolicyservice -- cgit v1.1