diff options
-rw-r--r-- | audio/A2dpAudioInterface.cpp | 4 | ||||
-rw-r--r-- | audio/AudioPolicyManagerBase.cpp | 109 | ||||
-rw-r--r-- | audio/audio_hw_hal.cpp | 147 | ||||
-rw-r--r-- | include/hardware_legacy/AudioPolicyManagerBase.h | 2 | ||||
-rw-r--r-- | include/hardware_legacy/AudioSystemLegacy.h | 10 |
5 files changed, 180 insertions, 92 deletions
diff --git a/audio/A2dpAudioInterface.cpp b/audio/A2dpAudioInterface.cpp index cc435bd..9359ec3 100644 --- a/audio/A2dpAudioInterface.cpp +++ b/audio/A2dpAudioInterface.cpp @@ -63,7 +63,7 @@ status_t A2dpAudioInterface::initCheck() AudioStreamOut* A2dpAudioInterface::openOutputStream( uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status) { - if (!AudioSystem::isA2dpDevice((AudioSystem::audio_devices)devices)) { + if (!audio_is_a2dp_device(devices)) { ALOGV("A2dpAudioInterface::openOutputStream() open HW device: %x", devices); return mHardwareInterface->openOutputStream(devices, format, channels, sampleRate, status); } @@ -398,7 +398,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setParameters(const String8& ke } key = AudioParameter::keyRouting; if (param.getInt(key, device) == NO_ERROR) { - if (AudioSystem::isA2dpDevice((AudioSystem::audio_devices)device)) { + if (audio_is_a2dp_device(device)) { mDevice = device; status = NO_ERROR; } else { diff --git a/audio/AudioPolicyManagerBase.cpp b/audio/AudioPolicyManagerBase.cpp index 9d4d6b9..32de6c1 100644 --- a/audio/AudioPolicyManagerBase.cpp +++ b/audio/AudioPolicyManagerBase.cpp @@ -31,10 +31,6 @@ #include <math.h> #include <hardware_legacy/audio_policy_conf.h> -// For code clarity in AudioPolicyManager: a value to indicate no audio device (both for input -// and output) when comparing audio_devices_t mask values -#define APM_AUDIO_DEVICE_NONE 0 - namespace android_audio_legacy { // ---------------------------------------------------------------------------- @@ -51,7 +47,7 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(audio_devices_t device ALOGV("setDeviceConnectionState() device: %x, state %d, address %s", device, state, device_address); // connect/disconnect only 1 device at a time - if (AudioSystem::popCount(device) != 1) return BAD_VALUE; + if (!audio_is_output_device(device) && !audio_is_input_device(device)) return BAD_VALUE; if (strlen(device_address) >= MAX_DEVICE_ADDRESS_LEN) { ALOGE("setDeviceConnectionState() invalid address: %s", device_address); @@ -193,7 +189,7 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(audio_devices_t device ALOGW("setDeviceConnectionState() device already connected: %d", device); return INVALID_OPERATION; } - mAvailableInputDevices = (audio_devices_t)(mAvailableInputDevices | device); + mAvailableInputDevices = mAvailableInputDevices | (device & ~AUDIO_DEVICE_BIT_IN); } break; @@ -215,7 +211,7 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(audio_devices_t device if (activeInput != 0) { AudioInputDescriptor *inputDesc = mInputs.valueFor(activeInput); audio_devices_t newDevice = getDeviceForInputSource(inputDesc->mInputSource); - if ((newDevice != APM_AUDIO_DEVICE_NONE) && (newDevice != inputDesc->mDevice)) { + if ((newDevice != AUDIO_DEVICE_NONE) && (newDevice != inputDesc->mDevice)) { ALOGV("setDeviceConnectionState() changing device from %x to %x for input %d", inputDesc->mDevice, newDevice, activeInput); inputDesc->mDevice = newDevice; @@ -269,7 +265,7 @@ AudioSystem::device_connection_state AudioPolicyManagerBase::getDeviceConnection void AudioPolicyManagerBase::setPhoneState(int state) { ALOGV("setPhoneState() state %d", state); - audio_devices_t newDevice = APM_AUDIO_DEVICE_NONE; + audio_devices_t newDevice = AUDIO_DEVICE_NONE; if (state < 0 || state >= AudioSystem::NUM_MODES) { ALOGW("setPhoneState() invalid state %d", state); return; @@ -322,7 +318,7 @@ void AudioPolicyManagerBase::setPhoneState(int state) // force routing command to audio hardware when ending call // even if no device change is needed - if (isStateInCall(oldState) && newDevice == APM_AUDIO_DEVICE_NONE) { + if (isStateInCall(oldState) && newDevice == AUDIO_DEVICE_NONE) { newDevice = hwOutputDesc->device(); } @@ -422,8 +418,8 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst for (size_t i = 0; i < mOutputs.size(); i++) { audio_io_handle_t output = mOutputs.keyAt(i); audio_devices_t newDevice = getNewDevice(output, true /*fromCache*/); - setOutputDevice(output, newDevice, (newDevice != APM_AUDIO_DEVICE_NONE)); - if (forceVolumeReeval && (newDevice != APM_AUDIO_DEVICE_NONE)) { + setOutputDevice(output, newDevice, (newDevice != AUDIO_DEVICE_NONE)); + if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) { applyStreamVolumes(output, newDevice, 0, true); } } @@ -432,7 +428,7 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst if (activeInput != 0) { AudioInputDescriptor *inputDesc = mInputs.valueFor(activeInput); audio_devices_t newDevice = getDeviceForInputSource(inputDesc->mInputSource); - if ((newDevice != APM_AUDIO_DEVICE_NONE) && (newDevice != inputDesc->mDevice)) { + if ((newDevice != AUDIO_DEVICE_NONE) && (newDevice != inputDesc->mDevice)) { ALOGV("setForceUse() changing device from %x to %x for input %d", inputDesc->mDevice, newDevice, activeInput); inputDesc->mDevice = newDevice; @@ -811,7 +807,7 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource, ALOGV("getInput() inputSource %d, samplingRate %d, format %d, channelMask %x, acoustics %x", inputSource, samplingRate, format, channelMask, acoustics); - if (device == APM_AUDIO_DEVICE_NONE) { + if (device == AUDIO_DEVICE_NONE) { ALOGW("getInput() could not find device for inputSource %d", inputSource); return 0; } @@ -1252,7 +1248,7 @@ AudioPolicyManagerBase::AudioPolicyManagerBase(AudioPolicyClientInterface *clien Thread(false), #endif //AUDIO_POLICY_TEST mPrimaryOutput((audio_io_handle_t)0), - mAvailableOutputDevices(APM_AUDIO_DEVICE_NONE), + mAvailableOutputDevices(AUDIO_DEVICE_NONE), mPhoneState(AudioSystem::MODE_NORMAL), mLimitRingtoneVolume(false), mLastVoiceVolume(-1.0f), mTotalEffectsCpuLoad(0), mTotalEffectsMemory(0), @@ -1938,7 +1934,7 @@ void AudioPolicyManagerBase::checkA2dpSuspend() audio_devices_t AudioPolicyManagerBase::getNewDevice(audio_io_handle_t output, bool fromCache) { - audio_devices_t device = APM_AUDIO_DEVICE_NONE; + audio_devices_t device = AUDIO_DEVICE_NONE; AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output); // check the following by order of priority to request a routing change if necessary: @@ -1983,7 +1979,7 @@ audio_devices_t AudioPolicyManagerBase::getDevicesForStream(AudioSystem::stream_ // getStrategy's behavior for invalid streams. getStrategy would do a ALOGE // and then return STRATEGY_MEDIA, but we want to return the empty set. if (stream < (AudioSystem::stream_type) 0 || stream >= AudioSystem::NUM_STREAM_TYPES) { - devices = APM_AUDIO_DEVICE_NONE; + devices = AUDIO_DEVICE_NONE; } else { AudioPolicyManagerBase::routing_strategy strategy = getStrategy(stream); devices = getDeviceForStrategy(strategy, true /*fromCache*/); @@ -2032,7 +2028,7 @@ void AudioPolicyManagerBase::handleNotificationRoutingForStream(AudioSystem::str audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy, bool fromCache) { - uint32_t device = APM_AUDIO_DEVICE_NONE; + uint32_t device = AUDIO_DEVICE_NONE; if (fromCache) { ALOGVV("getDeviceForStrategy() from cache strategy %d, device %x", @@ -2084,7 +2080,7 @@ audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy st // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to A2DP if (mHasA2dp && !isInCall() && (mForceUse[AudioSystem::FOR_MEDIA] != AudioSystem::FORCE_NO_BT_A2DP) && - (getA2dpOutput() != APM_AUDIO_DEVICE_NONE) && !mA2dpSuspended) { + (getA2dpOutput() != 0) && !mA2dpSuspended) { device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP; if (device) break; device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES; @@ -2107,7 +2103,7 @@ audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy st device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_EARPIECE; if (device) break; device = mDefaultOutputDevice; - if (device == APM_AUDIO_DEVICE_NONE) { + if (device == AUDIO_DEVICE_NONE) { ALOGE("getDeviceForStrategy() no device found for STRATEGY_PHONE"); } break; @@ -2117,7 +2113,7 @@ audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy st // A2DP speaker when forcing to speaker output if (mHasA2dp && !isInCall() && (mForceUse[AudioSystem::FOR_MEDIA] != AudioSystem::FORCE_NO_BT_A2DP) && - (getA2dpOutput() != APM_AUDIO_DEVICE_NONE) && !mA2dpSuspended) { + (getA2dpOutput() != 0) && !mA2dpSuspended) { device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER; if (device) break; } @@ -2134,7 +2130,7 @@ audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy st device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_SPEAKER; if (device) break; device = mDefaultOutputDevice; - if (device == APM_AUDIO_DEVICE_NONE) { + if (device == AUDIO_DEVICE_NONE) { ALOGE("getDeviceForStrategy() no device found for STRATEGY_PHONE, FORCE_SPEAKER"); } break; @@ -2160,7 +2156,7 @@ audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy st if (strategy == STRATEGY_SONIFICATION || !mStreams[AUDIO_STREAM_ENFORCED_AUDIBLE].mCanBeMuted) { device = mAvailableOutputDevices & AUDIO_DEVICE_OUT_SPEAKER; - if (device == APM_AUDIO_DEVICE_NONE) { + if (device == AUDIO_DEVICE_NONE) { ALOGE("getDeviceForStrategy() speaker device not found for STRATEGY_SONIFICATION"); } } @@ -2168,53 +2164,53 @@ audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy st // FALL THROUGH case STRATEGY_MEDIA: { - uint32_t device2 = APM_AUDIO_DEVICE_NONE; + uint32_t device2 = AUDIO_DEVICE_NONE; if (mHasRemoteSubmix && mForceUse[AudioSystem::FOR_MEDIA] == AudioSystem::FORCE_REMOTE_SUBMIX) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_REMOTE_SUBMIX; } - if ((device2 == APM_AUDIO_DEVICE_NONE) && + if ((device2 == AUDIO_DEVICE_NONE) && mHasA2dp && (mForceUse[AudioSystem::FOR_MEDIA] != AudioSystem::FORCE_NO_BT_A2DP) && - (getA2dpOutput() != APM_AUDIO_DEVICE_NONE) && !mA2dpSuspended) { + (getA2dpOutput() != 0) && !mA2dpSuspended) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP; - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES; } - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER; } } - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; } - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_WIRED_HEADSET; } - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_USB_ACCESSORY; } - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_USB_DEVICE; } - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET; } - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_AUX_DIGITAL; } - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET; } - if (device2 == APM_AUDIO_DEVICE_NONE) { + if (device2 == AUDIO_DEVICE_NONE) { device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_SPEAKER; } // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION or - // STRATEGY_ENFORCED_AUDIBLE, APM_AUDIO_DEVICE_NONE otherwise + // STRATEGY_ENFORCED_AUDIBLE, AUDIO_DEVICE_NONE otherwise device |= device2; if (device) break; device = mDefaultOutputDevice; - if (device == APM_AUDIO_DEVICE_NONE) { + if (device == AUDIO_DEVICE_NONE) { ALOGE("getDeviceForStrategy() no device found for STRATEGY_MEDIA"); } } break; @@ -2271,7 +2267,7 @@ uint32_t AudioPolicyManagerBase::checkDeviceMuteStrategies(AudioOutputDescriptor for (size_t j = 0; j < mOutputs.size(); j++) { AudioOutputDescriptor *desc = mOutputs.valueAt(j); if ((desc->supportedDevices() & outputDesc->supportedDevices()) - == APM_AUDIO_DEVICE_NONE) { + == AUDIO_DEVICE_NONE) { continue; } audio_io_handle_t curOutput = mOutputs.keyAt(j); @@ -2330,16 +2326,16 @@ uint32_t AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, ALOGV("setOutputDevice() prevDevice %04x", prevDevice); - if (device != APM_AUDIO_DEVICE_NONE) { + if (device != AUDIO_DEVICE_NONE) { outputDesc->mDevice = device; } muteWaitMs = checkDeviceMuteStrategies(outputDesc, prevDevice, delayMs); // Do not change the routing if: - // - the requested device is APM_AUDIO_DEVICE_NONE + // - the requested device is AUDIO_DEVICE_NONE // - the requested device is the same as current device and force is not specified. // Doing this check here allows the caller to call setOutputDevice() without conditions - if ((device == APM_AUDIO_DEVICE_NONE || device == prevDevice) && !force) { + if ((device == AUDIO_DEVICE_NONE || device == prevDevice) && !force) { ALOGV("setOutputDevice() setting same device %04x or null device for output %d", device, output); return muteWaitMs; } @@ -2382,7 +2378,7 @@ AudioPolicyManagerBase::IOProfile *AudioPolicyManagerBase::getInputProfile(audio audio_devices_t AudioPolicyManagerBase::getDeviceForInputSource(int inputSource) { - uint32_t device = APM_AUDIO_DEVICE_NONE; + uint32_t device = AUDIO_DEVICE_NONE; switch(inputSource) { case AUDIO_SOURCE_DEFAULT: @@ -2438,7 +2434,7 @@ audio_io_handle_t AudioPolicyManagerBase::getActiveInput() audio_devices_t AudioPolicyManagerBase::getDeviceForVolume(audio_devices_t device) { - if (device == APM_AUDIO_DEVICE_NONE) { + if (device == AUDIO_DEVICE_NONE) { // this happens when forcing a route update and no track is active on an output. // In this case the returned category is not important. device = AUDIO_DEVICE_OUT_SPEAKER; @@ -2640,7 +2636,7 @@ float AudioPolicyManagerBase::computeVolume(int stream, AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output); StreamDescriptor &streamDesc = mStreams[stream]; - if (device == APM_AUDIO_DEVICE_NONE) { + if (device == AUDIO_DEVICE_NONE) { device = outputDesc->device(); } @@ -2798,7 +2794,7 @@ void AudioPolicyManagerBase::setStreamMute(int stream, { StreamDescriptor &streamDesc = mStreams[stream]; AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output); - if (device == APM_AUDIO_DEVICE_NONE) { + if (device == AUDIO_DEVICE_NONE) { device = outputDesc->device(); } @@ -2908,7 +2904,7 @@ AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor( const IOProfile *profile) : mId(0), mSamplingRate(0), mFormat((audio_format_t)0), mChannelMask((audio_channel_mask_t)0), mLatency(0), - mFlags((audio_output_flags_t)0), mDevice(APM_AUDIO_DEVICE_NONE), + mFlags((audio_output_flags_t)0), mDevice(AUDIO_DEVICE_NONE), mOutput1(0), mOutput2(0), mProfile(profile) { // clear usage count for all stream types @@ -3034,7 +3030,7 @@ status_t AudioPolicyManagerBase::AudioOutputDescriptor::dump(int fd) AudioPolicyManagerBase::AudioInputDescriptor::AudioInputDescriptor(const IOProfile *profile) : mSamplingRate(0), mFormat((audio_format_t)0), mChannelMask((audio_channel_mask_t)0), - mDevice(APM_AUDIO_DEVICE_NONE), mRefCount(0), + mDevice(AUDIO_DEVICE_NONE), mRefCount(0), mInputSource(0), mProfile(profile) { } @@ -3299,6 +3295,9 @@ const struct StringToEnum sDeviceNameToEnumTable[] = { STRING_TO_ENUM(AUDIO_DEVICE_IN_VOICE_CALL), STRING_TO_ENUM(AUDIO_DEVICE_IN_BACK_MIC), STRING_TO_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX), + STRING_TO_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET), + STRING_TO_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET), + STRING_TO_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY), }; const struct StringToEnum sFlagNameToEnumTable[] = { @@ -3490,7 +3489,7 @@ status_t AudioPolicyManagerBase::loadInput(cnode *root, HwModule *module) } node = node->next; } - ALOGW_IF(profile->mSupportedDevices == APM_AUDIO_DEVICE_NONE, + ALOGW_IF(profile->mSupportedDevices == AUDIO_DEVICE_NONE, "loadInput() invalid supported devices"); ALOGW_IF(profile->mChannelMasks.size() == 0, "loadInput() invalid supported channel masks"); @@ -3498,7 +3497,7 @@ status_t AudioPolicyManagerBase::loadInput(cnode *root, HwModule *module) "loadInput() invalid supported sampling rates"); ALOGW_IF(profile->mFormats.size() == 0, "loadInput() invalid supported formats"); - if ((profile->mSupportedDevices != APM_AUDIO_DEVICE_NONE) && + if ((profile->mSupportedDevices != AUDIO_DEVICE_NONE) && (profile->mChannelMasks.size() != 0) && (profile->mSamplingRates.size() != 0) && (profile->mFormats.size() != 0)) { @@ -3533,7 +3532,7 @@ status_t AudioPolicyManagerBase::loadOutput(cnode *root, HwModule *module) } node = node->next; } - ALOGW_IF(profile->mSupportedDevices == APM_AUDIO_DEVICE_NONE, + ALOGW_IF(profile->mSupportedDevices == AUDIO_DEVICE_NONE, "loadOutput() invalid supported devices"); ALOGW_IF(profile->mChannelMasks.size() == 0, "loadOutput() invalid supported channel masks"); @@ -3541,7 +3540,7 @@ status_t AudioPolicyManagerBase::loadOutput(cnode *root, HwModule *module) "loadOutput() invalid supported sampling rates"); ALOGW_IF(profile->mFormats.size() == 0, "loadOutput() invalid supported formats"); - if ((profile->mSupportedDevices != APM_AUDIO_DEVICE_NONE) && + if ((profile->mSupportedDevices != AUDIO_DEVICE_NONE) && (profile->mChannelMasks.size() != 0) && (profile->mSamplingRates.size() != 0) && (profile->mFormats.size() != 0)) { @@ -3627,18 +3626,18 @@ void AudioPolicyManagerBase::loadGlobalConfig(cnode *root) while (node) { if (strcmp(ATTACHED_OUTPUT_DEVICES_TAG, node->name) == 0) { mAttachedOutputDevices = parseDeviceNames((char *)node->value); - ALOGW_IF(mAttachedOutputDevices == APM_AUDIO_DEVICE_NONE, + ALOGW_IF(mAttachedOutputDevices == AUDIO_DEVICE_NONE, "loadGlobalConfig() no attached output devices"); ALOGV("loadGlobalConfig() mAttachedOutputDevices %04x", mAttachedOutputDevices); } else if (strcmp(DEFAULT_OUTPUT_DEVICE_TAG, node->name) == 0) { mDefaultOutputDevice = (audio_devices_t)stringToEnum(sDeviceNameToEnumTable, ARRAY_SIZE(sDeviceNameToEnumTable), (char *)node->value); - ALOGW_IF(mDefaultOutputDevice == APM_AUDIO_DEVICE_NONE, + ALOGW_IF(mDefaultOutputDevice == AUDIO_DEVICE_NONE, "loadGlobalConfig() default device not specified"); ALOGV("loadGlobalConfig() mDefaultOutputDevice %04x", mDefaultOutputDevice); } else if (strcmp(ATTACHED_INPUT_DEVICES_TAG, node->name) == 0) { - mAvailableInputDevices = parseDeviceNames((char *)node->value); + mAvailableInputDevices = parseDeviceNames((char *)node->value) & ~AUDIO_DEVICE_BIT_IN; ALOGV("loadGlobalConfig() mAvailableInputDevices %04x", mAvailableInputDevices); } node = node->next; @@ -3676,7 +3675,7 @@ void AudioPolicyManagerBase::defaultAudioPolicyConfig(void) mDefaultOutputDevice = AUDIO_DEVICE_OUT_SPEAKER; mAttachedOutputDevices = AUDIO_DEVICE_OUT_SPEAKER; - mAvailableInputDevices = AUDIO_DEVICE_IN_BUILTIN_MIC; + mAvailableInputDevices = AUDIO_DEVICE_IN_BUILTIN_MIC & ~AUDIO_DEVICE_BIT_IN; module = new HwModule("primary"); diff --git a/audio/audio_hw_hal.cpp b/audio/audio_hw_hal.cpp index 68fa076..07d735d 100644 --- a/audio/audio_hw_hal.cpp +++ b/audio/audio_hw_hal.cpp @@ -52,6 +52,69 @@ struct legacy_stream_in { AudioStreamIn *legacy_in; }; + +enum { + HAL_API_REV_1_0, + HAL_API_REV_2_0, + HAL_API_REV_NUM +} hal_api_rev; + +static uint32_t audio_device_conv_table[][HAL_API_REV_NUM] = +{ + /* output devices */ + { AudioSystem::DEVICE_OUT_EARPIECE, AUDIO_DEVICE_OUT_EARPIECE }, + { AudioSystem::DEVICE_OUT_SPEAKER, AUDIO_DEVICE_OUT_SPEAKER }, + { AudioSystem::DEVICE_OUT_WIRED_HEADSET, AUDIO_DEVICE_OUT_WIRED_HEADSET }, + { AudioSystem::DEVICE_OUT_WIRED_HEADPHONE, AUDIO_DEVICE_OUT_WIRED_HEADPHONE }, + { AudioSystem::DEVICE_OUT_BLUETOOTH_SCO, AUDIO_DEVICE_OUT_BLUETOOTH_SCO }, + { AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET }, + { AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT }, + { AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP }, + { AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES }, + { AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER }, + { AudioSystem::DEVICE_OUT_AUX_DIGITAL, AUDIO_DEVICE_OUT_AUX_DIGITAL }, + { AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET, AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET }, + { AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET, AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET }, + { AudioSystem::DEVICE_OUT_DEFAULT, AUDIO_DEVICE_OUT_DEFAULT }, + /* input devices */ + { AudioSystem::DEVICE_IN_COMMUNICATION, AUDIO_DEVICE_IN_COMMUNICATION }, + { AudioSystem::DEVICE_IN_AMBIENT, AUDIO_DEVICE_IN_AMBIENT }, + { AudioSystem::DEVICE_IN_BUILTIN_MIC, AUDIO_DEVICE_IN_BUILTIN_MIC }, + { AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET }, + { AudioSystem::DEVICE_IN_WIRED_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET }, + { AudioSystem::DEVICE_IN_AUX_DIGITAL, AUDIO_DEVICE_IN_AUX_DIGITAL }, + { AudioSystem::DEVICE_IN_VOICE_CALL, AUDIO_DEVICE_IN_VOICE_CALL }, + { AudioSystem::DEVICE_IN_BACK_MIC, AUDIO_DEVICE_IN_BACK_MIC }, + { AudioSystem::DEVICE_IN_DEFAULT, AUDIO_DEVICE_IN_DEFAULT }, +}; + +static uint32_t convert_audio_device(uint32_t from_device, int from_rev, int to_rev) +{ + const uint32_t k_num_devices = sizeof(audio_device_conv_table)/sizeof(uint32_t)/HAL_API_REV_NUM; + uint32_t to_device = AUDIO_DEVICE_NONE; + uint32_t in_bit = 0; + + if (from_rev != HAL_API_REV_1_0) { + in_bit = from_device & AUDIO_DEVICE_BIT_IN; + from_device &= ~AUDIO_DEVICE_BIT_IN; + } + + while (from_device) { + uint32_t i = 31 - __builtin_clz(from_device); + uint32_t cur_device = (1 << i) | in_bit; + + for (i = 0; i < k_num_devices; i++) { + if (audio_device_conv_table[i][from_rev] == cur_device) { + to_device |= audio_device_conv_table[i][to_rev]; + break; + } + } + from_device &= ~cur_device; + } + return to_device; +} + + /** audio_stream_out implementation **/ static uint32_t out_get_sample_rate(const struct audio_stream *stream) { @@ -120,7 +183,18 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) { struct legacy_stream_out *out = reinterpret_cast<struct legacy_stream_out *>(stream); - return out->legacy_out->setParameters(String8(kvpairs)); + int val; + String8 s8 = String8(kvpairs); + AudioParameter parms = AudioParameter(String8(kvpairs)); + + if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) { + val = convert_audio_device(val, HAL_API_REV_2_0, HAL_API_REV_1_0); + parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING)); + parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val); + s8 = parms.toString(); + } + + return out->legacy_out->setParameters(s8); } static char * out_get_parameters(const struct audio_stream *stream, const char *keys) @@ -128,7 +202,18 @@ static char * out_get_parameters(const struct audio_stream *stream, const char * const struct legacy_stream_out *out = reinterpret_cast<const struct legacy_stream_out *>(stream); String8 s8; + int val; + s8 = out->legacy_out->getParameters(String8(keys)); + + AudioParameter parms = AudioParameter(s8); + if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) { + val = convert_audio_device(val, HAL_API_REV_1_0, HAL_API_REV_2_0); + parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING)); + parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val); + s8 = parms.toString(); + } + return strdup(s8.string()); } @@ -248,7 +333,18 @@ static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) { struct legacy_stream_in *in = reinterpret_cast<struct legacy_stream_in *>(stream); - return in->legacy_in->setParameters(String8(kvpairs)); + int val; + AudioParameter parms = AudioParameter(String8(kvpairs)); + String8 s8 = String8(kvpairs); + + if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) { + val = convert_audio_device(val, HAL_API_REV_2_0, HAL_API_REV_1_0); + parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING)); + parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val); + s8 = parms.toString(); + } + + return in->legacy_in->setParameters(s8); } static char * in_get_parameters(const struct audio_stream *stream, @@ -257,7 +353,18 @@ static char * in_get_parameters(const struct audio_stream *stream, const struct legacy_stream_in *in = reinterpret_cast<const struct legacy_stream_in *>(stream); String8 s8; + int val; + s8 = in->legacy_in->getParameters(String8(keys)); + + AudioParameter parms = AudioParameter(s8); + if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) { + val = convert_audio_device(val, HAL_API_REV_1_0, HAL_API_REV_2_0); + parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING)); + parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val); + s8 = parms.toString(); + } + return strdup(s8.string()); } @@ -308,35 +415,6 @@ static inline const struct legacy_audio_device * to_cladev(const struct audio_hw return reinterpret_cast<const struct legacy_audio_device *>(dev); } -static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev) -{ - /* XXX: The old AudioHardwareInterface interface is not smart enough to - * tell us this, so we'll lie and basically tell AF that we support the - * below input/output devices and cross our fingers. To do things properly, - * audio hardware interfaces that need advanced features (like this) should - * convert to the new HAL interface and not use this wrapper. */ - - return (/* OUT */ - AUDIO_DEVICE_OUT_EARPIECE | - AUDIO_DEVICE_OUT_SPEAKER | - AUDIO_DEVICE_OUT_WIRED_HEADSET | - AUDIO_DEVICE_OUT_WIRED_HEADPHONE | - AUDIO_DEVICE_OUT_AUX_DIGITAL | - AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | - AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | - AUDIO_DEVICE_OUT_ALL_SCO | - AUDIO_DEVICE_OUT_DEFAULT | - /* IN */ - AUDIO_DEVICE_IN_COMMUNICATION | - AUDIO_DEVICE_IN_AMBIENT | - AUDIO_DEVICE_IN_BUILTIN_MIC | - AUDIO_DEVICE_IN_WIRED_HEADSET | - AUDIO_DEVICE_IN_AUX_DIGITAL | - AUDIO_DEVICE_IN_BACK_MIC | - AUDIO_DEVICE_IN_ALL_SCO | - AUDIO_DEVICE_IN_DEFAULT); -} - static int adev_init_check(const struct audio_hw_device *dev) { const struct legacy_audio_device *ladev = to_cladev(dev); @@ -421,6 +499,8 @@ static int adev_open_output_stream(struct audio_hw_device *dev, if (!out) return -ENOMEM; + devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0); + out->legacy_out = ladev->hwif->openOutputStream(devices, (int *) &config->format, &config->channel_mask, &config->sample_rate, &status); @@ -482,6 +562,8 @@ static int adev_open_input_stream(struct audio_hw_device *dev, if (!in) return -ENOMEM; + devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0); + in->legacy_in = ladev->hwif->openInputStream(devices, (int *) &config->format, &config->channel_mask, &config->sample_rate, &status, (AudioSystem::audio_in_acoustics)0); @@ -564,11 +646,10 @@ static int legacy_adev_open(const hw_module_t* module, const char* name, return -ENOMEM; ladev->device.common.tag = HARDWARE_DEVICE_TAG; - ladev->device.common.version = AUDIO_DEVICE_API_VERSION_1_0; + ladev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; ladev->device.common.module = const_cast<hw_module_t*>(module); ladev->device.common.close = legacy_adev_close; - ladev->device.get_supported_devices = adev_get_supported_devices; ladev->device.init_check = adev_init_check; ladev->device.set_voice_volume = adev_set_voice_volume; ladev->device.set_master_volume = adev_set_master_volume; diff --git a/include/hardware_legacy/AudioPolicyManagerBase.h b/include/hardware_legacy/AudioPolicyManagerBase.h index a6ae397..07e52f7 100644 --- a/include/hardware_legacy/AudioPolicyManagerBase.h +++ b/include/hardware_legacy/AudioPolicyManagerBase.h @@ -507,6 +507,8 @@ protected: DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs; // list of input descriptors audio_devices_t mAvailableOutputDevices; // bit field of all available output devices audio_devices_t mAvailableInputDevices; // bit field of all available input devices + // without AUDIO_DEVICE_BIT_IN to allow direct bit + // field comparisons int mPhoneState; // current phone state AudioSystem::forced_config mForceUse[AudioSystem::NUM_FORCE_USE]; // current forced use configuration diff --git a/include/hardware_legacy/AudioSystemLegacy.h b/include/hardware_legacy/AudioSystemLegacy.h index 8eec57b..7cf7672 100644 --- a/include/hardware_legacy/AudioSystemLegacy.h +++ b/include/hardware_legacy/AudioSystemLegacy.h @@ -321,10 +321,16 @@ public: #if 1 static bool isOutputDevice(audio_devices device) { - return audio_is_output_device((audio_devices_t)device); + if ((popcount(device) == 1) && ((device & ~DEVICE_OUT_ALL) == 0)) + return true; + else + return false; } static bool isInputDevice(audio_devices device) { - return audio_is_input_device((audio_devices_t)device); + if ((popcount(device) == 1) && ((device & ~DEVICE_IN_ALL) == 0)) + return true; + else + return false; } static bool isA2dpDevice(audio_devices device) { return audio_is_a2dp_device((audio_devices_t)device); |