diff options
Diffstat (limited to 'audio')
-rw-r--r-- | audio/AudioPolicyManagerBase.cpp | 141 | ||||
-rw-r--r-- | audio/audio_policy_hal.cpp | 4 |
2 files changed, 74 insertions, 71 deletions
diff --git a/audio/AudioPolicyManagerBase.cpp b/audio/AudioPolicyManagerBase.cpp index 65e732f..62e7534 100644 --- a/audio/AudioPolicyManagerBase.cpp +++ b/audio/AudioPolicyManagerBase.cpp @@ -81,6 +81,7 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(audio_devices_t device // save a copy of the opened output descriptors before any output is opened or closed // by checkOutputsForDevice(). This will be needed by checkOutputForAllStrategies() mPreviousOutputs = mOutputs; + String8 paramStr; switch (state) { // handle output device connection @@ -91,7 +92,17 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(audio_devices_t device } ALOGV("setDeviceConnectionState() connecting device %x", device); - if (checkOutputsForDevice(device, state, outputs) != NO_ERROR) { + if (mHasA2dp && audio_is_a2dp_device(device)) { + // handle A2DP device connection + AudioParameter param; + param.add(String8(AUDIO_PARAMETER_A2DP_SINK_ADDRESS), String8(device_address)); + paramStr = param.toString(); + } else if (mHasUsb && audio_is_usb_device(device)) { + // handle USB device connection + paramStr = String8(device_address, MAX_DEVICE_ADDRESS_LEN); + } + + if (checkOutputsForDevice(device, state, outputs, paramStr) != NO_ERROR) { return INVALID_OPERATION; } ALOGV("setDeviceConnectionState() checkOutputsForDevice() returned %d outputs", @@ -99,31 +110,18 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(audio_devices_t device // register new device as available mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | device); - if (!outputs.isEmpty()) { - String8 paramStr; - if (mHasA2dp && audio_is_a2dp_device(device)) { - // handle A2DP device connection - AudioParameter param; - param.add(String8(AUDIO_PARAMETER_A2DP_SINK_ADDRESS), String8(device_address)); - paramStr = param.toString(); - mA2dpDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN); - mA2dpSuspended = false; - } else if (audio_is_bluetooth_sco_device(device)) { - // handle SCO device connection - mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN); - } else if (mHasUsb && audio_is_usb_device(device)) { - // handle USB device connection - mUsbCardAndDevice = String8(device_address, MAX_DEVICE_ADDRESS_LEN); - paramStr = mUsbCardAndDevice; - } - // not currently handling multiple simultaneous submixes: ignoring remote submix - // case and address - if (!paramStr.isEmpty()) { - for (size_t i = 0; i < outputs.size(); i++) { - mpClientInterface->setParameters(outputs[i], paramStr); - } - } + if (mHasA2dp && audio_is_a2dp_device(device)) { + // handle A2DP device connection + mA2dpDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN); + mA2dpSuspended = false; + } else if (audio_is_bluetooth_sco_device(device)) { + // handle SCO device connection + mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN); + } else if (mHasUsb && audio_is_usb_device(device)) { + // handle USB device connection + mUsbCardAndDevice = String8(device_address, MAX_DEVICE_ADDRESS_LEN); } + break; // handle output device disconnection case AudioSystem::DEVICE_STATE_UNAVAILABLE: { @@ -136,7 +134,7 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(audio_devices_t device // remove device from available output devices mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device); - checkOutputsForDevice(device, state, outputs); + checkOutputsForDevice(device, state, outputs, paramStr); if (mHasA2dp && audio_is_a2dp_device(device)) { // handle A2DP device disconnection mA2dpDeviceAddress = ""; @@ -495,8 +493,8 @@ void AudioPolicyManagerBase::setSystemProperty(const char* property, const char* AudioPolicyManagerBase::IOProfile *AudioPolicyManagerBase::getProfileForDirectOutput( audio_devices_t device, uint32_t samplingRate, - uint32_t format, - uint32_t channelMask, + audio_format_t format, + audio_channel_mask_t channelMask, audio_output_flags_t flags) { for (size_t i = 0; i < mHwModules.size(); i++) { @@ -529,8 +527,8 @@ AudioPolicyManagerBase::IOProfile *AudioPolicyManagerBase::getProfileForDirectOu audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type stream, uint32_t samplingRate, - uint32_t format, - uint32_t channelMask, + audio_format_t format, + audio_channel_mask_t channelMask, AudioSystem::output_flags flags, const audio_offload_info_t *offloadInfo) { @@ -622,8 +620,8 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str outputDesc = new AudioOutputDescriptor(profile); outputDesc->mDevice = device; outputDesc->mSamplingRate = samplingRate; - outputDesc->mFormat = (audio_format_t)format; - outputDesc->mChannelMask = (audio_channel_mask_t)channelMask; + outputDesc->mFormat = format; + outputDesc->mChannelMask = channelMask; outputDesc->mLatency = 0; outputDesc->mFlags =(audio_output_flags_t) (outputDesc->mFlags | flags); outputDesc->mRefCount[stream] = 0; @@ -641,7 +639,7 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str // only accept an output with the requested parameters if (output == 0 || (samplingRate != 0 && samplingRate != outputDesc->mSamplingRate) || - (format != 0 && format != outputDesc->mFormat) || + (format != AUDIO_FORMAT_DEFAULT && format != outputDesc->mFormat) || (channelMask != 0 && channelMask != outputDesc->mChannelMask)) { ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d," "format %d %d, channelMask %04x %04x", output, samplingRate, @@ -669,7 +667,7 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str // open a non direct output // for non direct outputs, only PCM is supported - if (audio_is_linear_pcm((audio_format_t)format)) { + if (audio_is_linear_pcm(format)) { // get which output is suitable for the specified stream. The actual // routing change will happen when startOutput() will be called SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs); @@ -737,7 +735,7 @@ status_t AudioPolicyManagerBase::startOutput(audio_io_handle_t output, ALOGV("startOutput() output %d, stream %d, session %d", output, stream, session); ssize_t index = mOutputs.indexOfKey(output); if (index < 0) { - ALOGW("startOutput() unknow output %d", output); + ALOGW("startOutput() unknown output %d", output); return BAD_VALUE; } @@ -805,7 +803,7 @@ status_t AudioPolicyManagerBase::stopOutput(audio_io_handle_t output, ALOGV("stopOutput() output %d, stream %d, session %d", output, stream, session); ssize_t index = mOutputs.indexOfKey(output); if (index < 0) { - ALOGW("stopOutput() unknow output %d", output); + ALOGW("stopOutput() unknown output %d", output); return BAD_VALUE; } @@ -900,8 +898,8 @@ void AudioPolicyManagerBase::releaseOutput(audio_io_handle_t output) audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource, uint32_t samplingRate, - uint32_t format, - uint32_t channelMask, + audio_format_t format, + audio_channel_mask_t channelMask, AudioSystem::audio_in_acoustics acoustics) { audio_io_handle_t input = 0; @@ -918,13 +916,13 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource, // adapt channel selection to input source switch(inputSource) { case AUDIO_SOURCE_VOICE_UPLINK: - channelMask = AudioSystem::CHANNEL_IN_VOICE_UPLINK; + channelMask = AUDIO_CHANNEL_IN_VOICE_UPLINK; break; case AUDIO_SOURCE_VOICE_DOWNLINK: - channelMask = AudioSystem::CHANNEL_IN_VOICE_DNLINK; + channelMask = AUDIO_CHANNEL_IN_VOICE_DNLINK; break; case AUDIO_SOURCE_VOICE_CALL: - channelMask = (AudioSystem::CHANNEL_IN_VOICE_UPLINK | AudioSystem::CHANNEL_IN_VOICE_DNLINK); + channelMask = AUDIO_CHANNEL_IN_VOICE_UPLINK | AUDIO_CHANNEL_IN_VOICE_DNLINK; break; default: break; @@ -935,7 +933,7 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource, format, channelMask); if (profile == NULL) { - ALOGW("getInput() could not find profile for device %04x, samplingRate %d, format %d," + ALOGW("getInput() could not find profile for device %04x, samplingRate %d, format %d, " "channelMask %04x", device, samplingRate, format, channelMask); return 0; @@ -951,8 +949,8 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource, inputDesc->mInputSource = inputSource; inputDesc->mDevice = device; inputDesc->mSamplingRate = samplingRate; - inputDesc->mFormat = (audio_format_t)format; - inputDesc->mChannelMask = (audio_channel_mask_t)channelMask; + inputDesc->mFormat = format; + inputDesc->mChannelMask = channelMask; inputDesc->mRefCount = 0; input = mpClientInterface->openInput(profile->mModule->mHandle, &inputDesc->mDevice, @@ -965,7 +963,7 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource, (samplingRate != inputDesc->mSamplingRate) || (format != inputDesc->mFormat) || (channelMask != inputDesc->mChannelMask)) { - ALOGV("getInput() failed opening input: samplingRate %d, format %d, channelMask %d", + ALOGI("getInput() failed opening input: samplingRate %d, format %d, channelMask %x", samplingRate, format, channelMask); if (input != 0) { mpClientInterface->closeInput(input); @@ -982,7 +980,7 @@ status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input) ALOGV("startInput() input %d", input); ssize_t index = mInputs.indexOfKey(input); if (index < 0) { - ALOGW("startInput() unknow input %d", input); + ALOGW("startInput() unknown input %d", input); return BAD_VALUE; } AudioInputDescriptor *inputDesc = mInputs.valueAt(index); @@ -1001,7 +999,7 @@ status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input) stopInput(activeInput); releaseInput(activeInput); } else { - ALOGW("startInput() input %d failed: other input already started..", input); + ALOGW("startInput() input %d failed: other input already started", input); return INVALID_OPERATION; } } @@ -1038,7 +1036,7 @@ status_t AudioPolicyManagerBase::stopInput(audio_io_handle_t input) ALOGV("stopInput() input %d", input); ssize_t index = mInputs.indexOfKey(input); if (index < 0) { - ALOGW("stopInput() unknow input %d", input); + ALOGW("stopInput() unknown input %d", input); return BAD_VALUE; } AudioInputDescriptor *inputDesc = mInputs.valueAt(index); @@ -1818,7 +1816,8 @@ void AudioPolicyManagerBase::addOutput(audio_io_handle_t id, AudioOutputDescript status_t AudioPolicyManagerBase::checkOutputsForDevice(audio_devices_t device, AudioSystem::device_connection_state state, - SortedVector<audio_io_handle_t>& outputs) + SortedVector<audio_io_handle_t>& outputs, + const String8 paramStr) { AudioOutputDescriptor *desc; @@ -1869,7 +1868,7 @@ status_t AudioPolicyManagerBase::checkOutputsForDevice(audio_devices_t device, continue; } - ALOGV("opening output for device %08x", device); + ALOGV("opening output for device %08x with params %s", device, paramStr.string()); desc = new AudioOutputDescriptor(profile); desc->mDevice = device; audio_offload_info_t offloadInfo = AUDIO_INFO_INITIALIZER; @@ -1886,6 +1885,10 @@ status_t AudioPolicyManagerBase::checkOutputsForDevice(audio_devices_t device, desc->mFlags, &offloadInfo); if (output != 0) { + if (!paramStr.isEmpty()) { + mpClientInterface->setParameters(output, paramStr); + } + if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) { String8 reply; char *value; @@ -1899,7 +1902,7 @@ status_t AudioPolicyManagerBase::checkOutputsForDevice(audio_devices_t device, loadSamplingRates(value + 1, profile); } } - if (profile->mFormats[0] == 0) { + if (profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) { reply = mpClientInterface->getParameters(output, String8(AUDIO_PARAMETER_STREAM_SUP_FORMATS)); ALOGV("checkOutputsForDevice() direct output sup formats %s", @@ -1921,9 +1924,9 @@ status_t AudioPolicyManagerBase::checkOutputsForDevice(audio_devices_t device, } if (((profile->mSamplingRates[0] == 0) && (profile->mSamplingRates.size() < 2)) || - ((profile->mFormats[0] == 0) && + ((profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) && (profile->mFormats.size() < 2)) || - ((profile->mFormats[0] == 0) && + ((profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) && (profile->mChannelMasks.size() < 2))) { ALOGW("checkOutputsForDevice() direct output missing param"); mpClientInterface->closeOutput(output); @@ -2004,13 +2007,13 @@ status_t AudioPolicyManagerBase::checkOutputsForDevice(audio_devices_t device, profile->mSamplingRates.clear(); profile->mSamplingRates.add(0); } - if (profile->mFormats[0] == 0) { + if (profile->mFormats[0] == AUDIO_FORMAT_DEFAULT) { profile->mFormats.clear(); - profile->mFormats.add((audio_format_t)0); + profile->mFormats.add(AUDIO_FORMAT_DEFAULT); } if (profile->mChannelMasks[0] == 0) { profile->mChannelMasks.clear(); - profile->mChannelMasks.add((audio_channel_mask_t)0); + profile->mChannelMasks.add(0); } } } @@ -2661,8 +2664,8 @@ uint32_t AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, AudioPolicyManagerBase::IOProfile *AudioPolicyManagerBase::getInputProfile(audio_devices_t device, uint32_t samplingRate, - uint32_t format, - uint32_t channelMask) + audio_format_t format, + audio_channel_mask_t channelMask) { // Choose an input profile based on the requested capture parameters: select the first available // profile supporting all requested parameters. @@ -2676,7 +2679,7 @@ AudioPolicyManagerBase::IOProfile *AudioPolicyManagerBase::getInputProfile(audio { IOProfile *profile = mHwModules[i]->mInputProfiles[j]; if (profile->isCompatibleProfile(device, samplingRate, format, - channelMask,(audio_output_flags_t)0)) { + channelMask, AUDIO_OUTPUT_FLAG_NONE)) { return profile; } } @@ -3248,8 +3251,8 @@ uint32_t AudioPolicyManagerBase::getMaxEffectsMemory() AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor( const IOProfile *profile) - : mId(0), mSamplingRate(0), mFormat((audio_format_t)0), - mChannelMask((audio_channel_mask_t)0), mLatency(0), + : mId(0), mSamplingRate(0), mFormat(AUDIO_FORMAT_DEFAULT), + mChannelMask(0), mLatency(0), mFlags((audio_output_flags_t)0), mDevice(AUDIO_DEVICE_NONE), mOutput1(0), mOutput2(0), mProfile(profile), mDirectOpenCount(0) { @@ -3400,7 +3403,7 @@ status_t AudioPolicyManagerBase::AudioOutputDescriptor::dump(int fd) // --- AudioInputDescriptor class implementation AudioPolicyManagerBase::AudioInputDescriptor::AudioInputDescriptor(const IOProfile *profile) - : mSamplingRate(0), mFormat((audio_format_t)0), mChannelMask((audio_channel_mask_t)0), + : mSamplingRate(0), mFormat(AUDIO_FORMAT_DEFAULT), mChannelMask(0), mDevice(AUDIO_DEVICE_NONE), mRefCount(0), mInputSource(0), mProfile(profile) { @@ -3549,11 +3552,11 @@ AudioPolicyManagerBase::IOProfile::~IOProfile() // get a valid a match bool AudioPolicyManagerBase::IOProfile::isCompatibleProfile(audio_devices_t device, uint32_t samplingRate, - uint32_t format, - uint32_t channelMask, + audio_format_t format, + audio_channel_mask_t channelMask, audio_output_flags_t flags) const { - if (samplingRate == 0 || format == 0 || channelMask == 0) { + if (samplingRate == 0 || !audio_is_valid_format(format) || channelMask == 0) { return false; } @@ -3787,7 +3790,7 @@ void AudioPolicyManagerBase::loadFormats(char *name, IOProfile *profile) // by convention, "0' in the first entry in mFormats indicates the supported formats // should be read from the output stream after it is opened for the first time if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) { - profile->mFormats.add((audio_format_t)0); + profile->mFormats.add(AUDIO_FORMAT_DEFAULT); return; } @@ -3795,7 +3798,7 @@ void AudioPolicyManagerBase::loadFormats(char *name, IOProfile *profile) audio_format_t format = (audio_format_t)stringToEnum(sFormatNameToEnumTable, ARRAY_SIZE(sFormatNameToEnumTable), str); - if (format != 0) { + if (format != AUDIO_FORMAT_DEFAULT) { profile->mFormats.add(format); } str = strtok(NULL, "|"); @@ -3810,7 +3813,7 @@ void AudioPolicyManagerBase::loadInChannels(char *name, IOProfile *profile) ALOGV("loadInChannels() %s", name); if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) { - profile->mChannelMasks.add((audio_channel_mask_t)0); + profile->mChannelMasks.add(0); return; } @@ -3837,7 +3840,7 @@ void AudioPolicyManagerBase::loadOutChannels(char *name, IOProfile *profile) // by convention, "0' in the first entry in mChannelMasks indicates the supported channel // masks should be read from the output stream after it is opened for the first time if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) { - profile->mChannelMasks.add((audio_channel_mask_t)0); + profile->mChannelMasks.add(0); return; } diff --git a/audio/audio_policy_hal.cpp b/audio/audio_policy_hal.cpp index e44bc48..87c4131 100644 --- a/audio/audio_policy_hal.cpp +++ b/audio/audio_policy_hal.cpp @@ -145,7 +145,7 @@ static audio_io_handle_t ap_get_output(struct audio_policy *pol, ALOGV("%s: tid %d", __func__, gettid()); return lap->apm->getOutput((AudioSystem::stream_type)stream, - sampling_rate, (int) format, channelMask, + sampling_rate, format, channelMask, (AudioSystem::output_flags)flags, offloadInfo); } @@ -180,7 +180,7 @@ static audio_io_handle_t ap_get_input(struct audio_policy *pol, audio_source_t i audio_in_acoustics_t acoustics) { struct legacy_audio_policy *lap = to_lap(pol); - return lap->apm->getInput((int) inputSource, sampling_rate, (int) format, channelMask, + return lap->apm->getInput((int) inputSource, sampling_rate, format, channelMask, (AudioSystem::audio_in_acoustics)acoustics); } |