diff options
Diffstat (limited to 'services/audiopolicy')
-rw-r--r-- | services/audiopolicy/AudioPolicyClientImpl.cpp | 37 | ||||
-rw-r--r-- | services/audiopolicy/AudioPolicyClientImplLegacy.cpp | 106 | ||||
-rw-r--r-- | services/audiopolicy/AudioPolicyInterface.h | 28 | ||||
-rw-r--r-- | services/audiopolicy/AudioPolicyManager.cpp | 343 | ||||
-rw-r--r-- | services/audiopolicy/AudioPolicyManager.h | 2 | ||||
-rw-r--r-- | services/audiopolicy/AudioPolicyService.h | 24 |
6 files changed, 320 insertions, 220 deletions
diff --git a/services/audiopolicy/AudioPolicyClientImpl.cpp b/services/audiopolicy/AudioPolicyClientImpl.cpp index b5af089..aa309d1 100644 --- a/services/audiopolicy/AudioPolicyClientImpl.cpp +++ b/services/audiopolicy/AudioPolicyClientImpl.cpp @@ -35,22 +35,20 @@ audio_module_handle_t AudioPolicyService::AudioPolicyClient::loadHwModule(const return af->loadHwModule(name); } -audio_io_handle_t AudioPolicyService::AudioPolicyClient::openOutput(audio_module_handle_t module, - audio_devices_t *pDevices, - uint32_t *pSamplingRate, - audio_format_t *pFormat, - audio_channel_mask_t *pChannelMask, - uint32_t *pLatencyMs, - audio_output_flags_t flags, - const audio_offload_info_t *offloadInfo) +status_t AudioPolicyService::AudioPolicyClient::openOutput(audio_module_handle_t module, + audio_io_handle_t *output, + audio_config_t *config, + audio_devices_t *devices, + const String8& address, + uint32_t *latencyMs, + audio_output_flags_t flags) { sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); if (af == 0) { ALOGW("%s: could not get AudioFlinger", __func__); - return 0; + return PERMISSION_DENIED; } - return af->openOutput(module, pDevices, pSamplingRate, pFormat, pChannelMask, - pLatencyMs, flags, offloadInfo); + return af->openOutput(module, output, config, devices, address, latencyMs, flags); } audio_io_handle_t AudioPolicyService::AudioPolicyClient::openDuplicateOutput( @@ -97,20 +95,21 @@ status_t AudioPolicyService::AudioPolicyClient::restoreOutput(audio_io_handle_t return af->restoreOutput(output); } -audio_io_handle_t AudioPolicyService::AudioPolicyClient::openInput(audio_module_handle_t module, - audio_devices_t *pDevices, - uint32_t *pSamplingRate, - audio_format_t *pFormat, - audio_channel_mask_t *pChannelMask, - audio_input_flags_t flags) +status_t AudioPolicyService::AudioPolicyClient::openInput(audio_module_handle_t module, + audio_io_handle_t *input, + audio_config_t *config, + audio_devices_t *device, + const String8& address, + audio_source_t source, + audio_input_flags_t flags) { sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); if (af == 0) { ALOGW("%s: could not get AudioFlinger", __func__); - return 0; + return PERMISSION_DENIED; } - return af->openInput(module, pDevices, pSamplingRate, pFormat, pChannelMask, flags); + return af->openInput(module, input, config, device, address, source, flags); } status_t AudioPolicyService::AudioPolicyClient::closeInput(audio_io_handle_t input) diff --git a/services/audiopolicy/AudioPolicyClientImplLegacy.cpp b/services/audiopolicy/AudioPolicyClientImplLegacy.cpp index 97e12cc..9639096 100644 --- a/services/audiopolicy/AudioPolicyClientImplLegacy.cpp +++ b/services/audiopolicy/AudioPolicyClientImplLegacy.cpp @@ -62,6 +62,46 @@ audio_module_handle_t aps_load_hw_module(void *service __unused, return af->loadHwModule(name); } +static audio_io_handle_t open_output(audio_module_handle_t module, + audio_devices_t *pDevices, + uint32_t *pSamplingRate, + audio_format_t *pFormat, + audio_channel_mask_t *pChannelMask, + uint32_t *pLatencyMs, + audio_output_flags_t flags, + const audio_offload_info_t *offloadInfo) +{ + sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); + if (af == 0) { + ALOGW("%s: could not get AudioFlinger", __func__); + return AUDIO_IO_HANDLE_NONE; + } + + if (pSamplingRate == NULL || pFormat == NULL || pChannelMask == NULL || + pDevices == NULL || pLatencyMs == NULL) { + return AUDIO_IO_HANDLE_NONE; + } + audio_config_t config = AUDIO_CONFIG_INITIALIZER; + config.sample_rate = *pSamplingRate; + config.format = *pFormat; + config.channel_mask = *pChannelMask; + if (offloadInfo != NULL) { + config.offload_info = *offloadInfo; + } + audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; + status_t status = af->openOutput(module, &output, &config, pDevices, + String8(""), pLatencyMs, flags); + if (status == NO_ERROR) { + *pSamplingRate = config.sample_rate; + *pFormat = config.format; + *pChannelMask = config.channel_mask; + if (offloadInfo != NULL) { + *offloadInfo = config.offload_info; + } + } + return output; +} + // deprecated: replaced by aps_open_output_on_module() audio_io_handle_t aps_open_output(void *service __unused, audio_devices_t *pDevices, @@ -71,14 +111,8 @@ audio_io_handle_t aps_open_output(void *service __unused, uint32_t *pLatencyMs, audio_output_flags_t flags) { - sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); - if (af == 0) { - ALOGW("%s: could not get AudioFlinger", __func__); - return 0; - } - - return af->openOutput((audio_module_handle_t)0, pDevices, pSamplingRate, pFormat, pChannelMask, - pLatencyMs, flags); + return open_output((audio_module_handle_t)0, pDevices, pSamplingRate, pFormat, pChannelMask, + pLatencyMs, flags, NULL); } audio_io_handle_t aps_open_output_on_module(void *service __unused, @@ -91,12 +125,7 @@ audio_io_handle_t aps_open_output_on_module(void *service __unused, audio_output_flags_t flags, const audio_offload_info_t *offloadInfo) { - sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); - if (af == 0) { - ALOGW("%s: could not get AudioFlinger", __func__); - return 0; - } - return af->openOutput(module, pDevices, pSamplingRate, pFormat, pChannelMask, + return open_output(module, pDevices, pSamplingRate, pFormat, pChannelMask, pLatencyMs, flags, offloadInfo); } @@ -144,6 +173,37 @@ int aps_restore_output(void *service __unused, audio_io_handle_t output) return af->restoreOutput(output); } +static audio_io_handle_t open_input(audio_module_handle_t module, + audio_devices_t *pDevices, + uint32_t *pSamplingRate, + audio_format_t *pFormat, + audio_channel_mask_t *pChannelMask) +{ + sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); + if (af == 0) { + ALOGW("%s: could not get AudioFlinger", __func__); + return AUDIO_IO_HANDLE_NONE; + } + + if (pSamplingRate == NULL || pFormat == NULL || pChannelMask == NULL || pDevices == NULL) { + return AUDIO_IO_HANDLE_NONE; + } + audio_config_t config = AUDIO_CONFIG_INITIALIZER;; + config.sample_rate = *pSamplingRate; + config.format = *pFormat; + config.channel_mask = *pChannelMask; + audio_io_handle_t input = AUDIO_IO_HANDLE_NONE; + status_t status = af->openInput(module, &input, &config, pDevices, + String8(""), AUDIO_SOURCE_MIC, AUDIO_INPUT_FLAG_FAST /*FIXME*/); + if (status == NO_ERROR) { + *pSamplingRate = config.sample_rate; + *pFormat = config.format; + *pChannelMask = config.channel_mask; + } + return input; +} + + // deprecated: replaced by aps_open_input_on_module(), and acoustics parameter is ignored audio_io_handle_t aps_open_input(void *service __unused, audio_devices_t *pDevices, @@ -152,14 +212,7 @@ audio_io_handle_t aps_open_input(void *service __unused, audio_channel_mask_t *pChannelMask, audio_in_acoustics_t acoustics __unused) { - sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); - if (af == 0) { - ALOGW("%s: could not get AudioFlinger", __func__); - return 0; - } - - return af->openInput((audio_module_handle_t)0, pDevices, pSamplingRate, pFormat, pChannelMask, - AUDIO_INPUT_FLAG_FAST /*FIXME*/); + return open_input((audio_module_handle_t)0, pDevices, pSamplingRate, pFormat, pChannelMask); } audio_io_handle_t aps_open_input_on_module(void *service __unused, @@ -169,14 +222,7 @@ audio_io_handle_t aps_open_input_on_module(void *service __unused, audio_format_t *pFormat, audio_channel_mask_t *pChannelMask) { - sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); - if (af == 0) { - ALOGW("%s: could not get AudioFlinger", __func__); - return 0; - } - - return af->openInput(module, pDevices, pSamplingRate, pFormat, pChannelMask, - AUDIO_INPUT_FLAG_FAST /*FIXME*/); + return open_input(module, pDevices, pSamplingRate, pFormat, pChannelMask); } int aps_close_input(void *service __unused, audio_io_handle_t input) diff --git a/services/audiopolicy/AudioPolicyInterface.h b/services/audiopolicy/AudioPolicyInterface.h index d45776b..0e53afc 100644 --- a/services/audiopolicy/AudioPolicyInterface.h +++ b/services/audiopolicy/AudioPolicyInterface.h @@ -211,14 +211,13 @@ public: // in case the audio policy manager has no specific requirements for the output being opened. // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream. // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly. - virtual audio_io_handle_t openOutput(audio_module_handle_t module, - audio_devices_t *pDevices, - uint32_t *pSamplingRate, - audio_format_t *pFormat, - audio_channel_mask_t *pChannelMask, - uint32_t *pLatencyMs, - audio_output_flags_t flags, - const audio_offload_info_t *offloadInfo = NULL) = 0; + virtual status_t openOutput(audio_module_handle_t module, + audio_io_handle_t *output, + audio_config_t *config, + audio_devices_t *devices, + const String8& address, + uint32_t *latencyMs, + audio_output_flags_t flags) = 0; // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by // a special mixer thread in the AudioFlinger. virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2) = 0; @@ -235,12 +234,13 @@ public: // // opens an audio input - virtual audio_io_handle_t openInput(audio_module_handle_t module, - audio_devices_t *pDevices, - uint32_t *pSamplingRate, - audio_format_t *pFormat, - audio_channel_mask_t *pChannelMask, - audio_input_flags_t flags) = 0; + virtual status_t openInput(audio_module_handle_t module, + audio_io_handle_t *input, + audio_config_t *config, + audio_devices_t *device, + const String8& address, + audio_source_t source, + audio_input_flags_t flags) = 0; // closes an audio input virtual status_t closeInput(audio_io_handle_t input) = 0; // diff --git a/services/audiopolicy/AudioPolicyManager.cpp b/services/audiopolicy/AudioPolicyManager.cpp index c5248fe..7fd9b3a 100644 --- a/services/audiopolicy/AudioPolicyManager.cpp +++ b/services/audiopolicy/AudioPolicyManager.cpp @@ -686,8 +686,9 @@ audio_io_handle_t AudioPolicyManager::getOutputForDevice( audio_output_flags_t flags, const audio_offload_info_t *offloadInfo) { - audio_io_handle_t output = 0; + audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; uint32_t latency = 0; + status_t status; #ifdef AUDIO_POLICY_TEST if (mCurOutput != 0) { @@ -698,21 +699,26 @@ audio_io_handle_t AudioPolicyManager::getOutputForDevice( ALOGV("getOutput() opening test output"); sp<AudioOutputDescriptor> outputDesc = new AudioOutputDescriptor(NULL); outputDesc->mDevice = mTestDevice; - outputDesc->mSamplingRate = mTestSamplingRate; - outputDesc->mFormat = mTestFormat; - outputDesc->mChannelMask = mTestChannels; outputDesc->mLatency = mTestLatencyMs; outputDesc->mFlags = (audio_output_flags_t)(mDirectOutput ? AUDIO_OUTPUT_FLAG_DIRECT : 0); outputDesc->mRefCount[stream] = 0; - mTestOutputs[mCurOutput] = mpClientInterface->openOutput(0, &outputDesc->mDevice, - &outputDesc->mSamplingRate, - &outputDesc->mFormat, - &outputDesc->mChannelMask, - &outputDesc->mLatency, - outputDesc->mFlags, - offloadInfo); - if (mTestOutputs[mCurOutput]) { + audio_config_t config = AUDIO_CONFIG_INITIALIZER; + config.sample_rate = mTestSamplingRate; + config.channel_mask = mTestChannels; + config.format = mTestFormat; + config.offload_info = *offloadInfo; + status = mpClientInterface->openOutput(0, + &mTestOutputs[mCurOutput], + &config, + &outputDesc->mDevice, + String8(""), + &outputDesc->mLatency, + outputDesc->mFlags); + if (status == NO_ERROR) { + outputDesc->mSamplingRate = config.sample_rate; + outputDesc->mFormat = config.format; + outputDesc->mChannelMask = config.channel_mask; AudioParameter outputCmd = AudioParameter(); outputCmd.addInt(String8("set_id"),mCurOutput); mpClientInterface->setParameters(mTestOutputs[mCurOutput],outputCmd.toString()); @@ -770,37 +776,42 @@ audio_io_handle_t AudioPolicyManager::getOutputForDevice( } outputDesc = new AudioOutputDescriptor(profile); outputDesc->mDevice = device; - outputDesc->mSamplingRate = samplingRate; - outputDesc->mFormat = format; - outputDesc->mChannelMask = channelMask; outputDesc->mLatency = 0; outputDesc->mFlags =(audio_output_flags_t) (outputDesc->mFlags | flags); - outputDesc->mRefCount[stream] = 0; - outputDesc->mStopTime[stream] = 0; - outputDesc->mDirectOpenCount = 1; - output = mpClientInterface->openOutput(profile->mModule->mHandle, - &outputDesc->mDevice, - &outputDesc->mSamplingRate, - &outputDesc->mFormat, - &outputDesc->mChannelMask, - &outputDesc->mLatency, - outputDesc->mFlags, - offloadInfo); + audio_config_t config = AUDIO_CONFIG_INITIALIZER; + config.sample_rate = samplingRate; + config.channel_mask = channelMask; + config.format = format; + config.offload_info = *offloadInfo; + status = mpClientInterface->openOutput(profile->mModule->mHandle, + &output, + &config, + &outputDesc->mDevice, + String8(""), + &outputDesc->mLatency, + outputDesc->mFlags); // only accept an output with the requested parameters - if (output == 0 || - (samplingRate != 0 && samplingRate != outputDesc->mSamplingRate) || - (format != AUDIO_FORMAT_DEFAULT && format != outputDesc->mFormat) || - (channelMask != 0 && channelMask != outputDesc->mChannelMask)) { + if (status != NO_ERROR || + (samplingRate != 0 && samplingRate != config.sample_rate) || + (format != AUDIO_FORMAT_DEFAULT && format != config.format) || + (channelMask != 0 && channelMask != config.channel_mask)) { ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d," "format %d %d, channelMask %04x %04x", output, samplingRate, outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask, outputDesc->mChannelMask); - if (output != 0) { + if (output != AUDIO_IO_HANDLE_NONE) { mpClientInterface->closeOutput(output); } - return 0; + return AUDIO_IO_HANDLE_NONE; } + outputDesc->mSamplingRate = config.sample_rate; + outputDesc->mChannelMask = config.channel_mask; + outputDesc->mFormat = config.format; + outputDesc->mRefCount[stream] = 0; + outputDesc->mStopTime[stream] = 0; + outputDesc->mDirectOpenCount = 1; + audio_io_handle_t srcOutput = getOutputForEffect(); addOutput(output, outputDesc); audio_io_handle_t dstOutput = getOutputForEffect(); @@ -1062,7 +1073,7 @@ audio_io_handle_t AudioPolicyManager::getInput(audio_source_t inputSource, if (device == AUDIO_DEVICE_NONE) { ALOGW("getInput() could not find device for inputSource %d", inputSource); - return 0; + return AUDIO_IO_HANDLE_NONE; } // adapt channel selection to input source @@ -1089,43 +1100,49 @@ audio_io_handle_t AudioPolicyManager::getInput(audio_source_t inputSource, ALOGW("getInput() could not find profile for device 0x%X, samplingRate %u, format %#x, " "channelMask 0x%X, flags %#x", device, samplingRate, format, channelMask, flags); - return 0; + return AUDIO_IO_HANDLE_NONE; } if (profile->mModule->mHandle == 0) { ALOGE("getInput(): HW module %s not opened", profile->mModule->mName); - return 0; + return AUDIO_IO_HANDLE_NONE; + } + + audio_config_t config = AUDIO_CONFIG_INITIALIZER; + config.sample_rate = samplingRate; + config.channel_mask = channelMask; + config.format = format; + audio_io_handle_t input = AUDIO_IO_HANDLE_NONE; + status_t status = mpClientInterface->openInput(profile->mModule->mHandle, + &input, + &config, + &device, + String8(""), + inputSource, + flags); + + // only accept input with the exact requested set of parameters + if (status != NO_ERROR || + (samplingRate != config.sample_rate) || + (format != config.format) || + (channelMask != config.channel_mask)) { + ALOGW("getInput() failed opening input: samplingRate %d, format %d, channelMask %x", + samplingRate, format, channelMask); + if (input != AUDIO_IO_HANDLE_NONE) { + mpClientInterface->closeInput(input); + } + return AUDIO_IO_HANDLE_NONE; } sp<AudioInputDescriptor> inputDesc = new AudioInputDescriptor(profile); - inputDesc->mInputSource = inputSource; - inputDesc->mDevice = device; + inputDesc->mRefCount = 0; + inputDesc->mOpenRefCount = 1; inputDesc->mSamplingRate = samplingRate; inputDesc->mFormat = format; inputDesc->mChannelMask = channelMask; - inputDesc->mRefCount = 0; - inputDesc->mOpenRefCount = 1; - - audio_io_handle_t input = mpClientInterface->openInput(profile->mModule->mHandle, - &inputDesc->mDevice, - &inputDesc->mSamplingRate, - &inputDesc->mFormat, - &inputDesc->mChannelMask, - flags); + inputDesc->mDevice = device; - // only accept input with the exact requested set of parameters - if (input == 0 || - (samplingRate != inputDesc->mSamplingRate) || - (format != inputDesc->mFormat) || - (channelMask != inputDesc->mChannelMask)) { - ALOGW("getInput() failed opening input: samplingRate %d, format %d, channelMask %x", - samplingRate, format, channelMask); - if (input != 0) { - mpClientInterface->closeInput(input); - } - return 0; - } addInput(input, inputDesc); mpClientInterface->onAudioPortListUpdate(); return input; @@ -2317,19 +2334,28 @@ AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterfa sp<AudioOutputDescriptor> outputDesc = new AudioOutputDescriptor(outProfile); outputDesc->mDevice = profileType; - audio_io_handle_t output = mpClientInterface->openOutput( - outProfile->mModule->mHandle, - &outputDesc->mDevice, - &outputDesc->mSamplingRate, - &outputDesc->mFormat, - &outputDesc->mChannelMask, - &outputDesc->mLatency, - outputDesc->mFlags); - if (output == 0) { + audio_config_t config = AUDIO_CONFIG_INITIALIZER; + config.sample_rate = outputDesc->mSamplingRate; + config.channel_mask = outputDesc->mChannelMask; + config.format = outputDesc->mFormat; + audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; + status_t status = mpClientInterface->openOutput(outProfile->mModule->mHandle, + &output, + &config, + &outputDesc->mDevice, + String8(""), + &outputDesc->mLatency, + outputDesc->mFlags); + + if (status != NO_ERROR) { ALOGW("Cannot open output stream for device %08x on hw module %s", outputDesc->mDevice, mHwModules[i]->mName); } else { + outputDesc->mSamplingRate = config.sample_rate; + outputDesc->mChannelMask = config.channel_mask; + outputDesc->mFormat = config.format; + for (size_t k = 0; k < outProfile->mSupportedDevices.size(); k++) { audio_devices_t type = outProfile->mSupportedDevices[k]->mDeviceType; ssize_t index = @@ -2368,15 +2394,21 @@ AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterfa inputDesc->mInputSource = AUDIO_SOURCE_MIC; inputDesc->mDevice = profileType; - audio_io_handle_t input = mpClientInterface->openInput( - inProfile->mModule->mHandle, - &inputDesc->mDevice, - &inputDesc->mSamplingRate, - &inputDesc->mFormat, - &inputDesc->mChannelMask, - AUDIO_INPUT_FLAG_NONE /*FIXME*/); - if (input != 0) { + audio_config_t config = AUDIO_CONFIG_INITIALIZER; + config.sample_rate = inputDesc->mSamplingRate; + config.channel_mask = inputDesc->mChannelMask; + config.format = inputDesc->mFormat; + audio_io_handle_t input = AUDIO_IO_HANDLE_NONE; + status_t status = mpClientInterface->openInput(inProfile->mModule->mHandle, + &input, + &config, + &inputDesc->mDevice, + String8(""), + AUDIO_SOURCE_MIC, + AUDIO_INPUT_FLAG_NONE); + + if (status == NO_ERROR) { for (size_t k = 0; k < inProfile->mSupportedDevices.size(); k++) { audio_devices_t type = inProfile->mSupportedDevices[k]->mDeviceType; ssize_t index = @@ -2575,17 +2607,25 @@ bool AudioPolicyManager::threadLoop() sp<AudioOutputDescriptor> outputDesc = new AudioOutputDescriptor(NULL); outputDesc->mDevice = AUDIO_DEVICE_OUT_SPEAKER; - mPrimaryOutput = mpClientInterface->openOutput(moduleHandle, - &outputDesc->mDevice, - &outputDesc->mSamplingRate, - &outputDesc->mFormat, - &outputDesc->mChannelMask, - &outputDesc->mLatency, - outputDesc->mFlags); - if (mPrimaryOutput == 0) { - ALOGE("Failed to reopen hardware output stream, samplingRate: %d, format %d, channels %d", - outputDesc->mSamplingRate, outputDesc->mFormat, outputDesc->mChannelMask); + audio_config_t config = AUDIO_CONFIG_INITIALIZER; + config.sample_rate = outputDesc->mSamplingRate; + config.channel_mask = outputDesc->mChannelMask; + config.format = outputDesc->mFormat; + status_t status = mpClientInterface->openOutput(moduleHandle, + &mPrimaryOutput, + &config, + &outputDesc->mDevice, + String8(""), + &outputDesc->mLatency, + outputDesc->mFlags); + if (status != NO_ERROR) { + ALOGE("Failed to reopen hardware output stream, " + "samplingRate: %d, format %d, channels %d", + outputDesc->mSamplingRate, outputDesc->mFormat, outputDesc->mChannelMask); } else { + outputDesc->mSamplingRate = config.sample_rate; + outputDesc->mChannelMask = config.channel_mask; + outputDesc->mFormat = config.format; AudioParameter outputCmd = AudioParameter(); outputCmd.addInt(String8("set_id"), 0); mpClientInterface->setParameters(mPrimaryOutput, outputCmd.toString()); @@ -2637,16 +2677,6 @@ void AudioPolicyManager::addInput(audio_io_handle_t input, sp<AudioInputDescript nextAudioPortGeneration(); } -String8 AudioPolicyManager::addressToParameter(audio_devices_t device, const String8 address) -{ - if (device & AUDIO_DEVICE_OUT_ALL_A2DP) { - return String8("a2dp_sink_address=")+address; - } else if (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) { - return String8("mix=")+address; - } - return address; -} - void AudioPolicyManager::findIoHandlesByAddress(sp<AudioOutputDescriptor> desc /*in*/, const String8 address /*in*/, SortedVector<audio_io_handle_t>& outputs /*out*/) { @@ -2739,23 +2769,31 @@ status_t AudioPolicyManager::checkOutputsForDevice(audio_devices_t device, device, address.string(), profile.get()); desc = new AudioOutputDescriptor(profile); desc->mDevice = device; - audio_offload_info_t offloadInfo = AUDIO_INFO_INITIALIZER; - offloadInfo.sample_rate = desc->mSamplingRate; - offloadInfo.format = desc->mFormat; - offloadInfo.channel_mask = desc->mChannelMask; - - audio_io_handle_t output = mpClientInterface->openOutput(profile->mModule->mHandle, - &desc->mDevice, - &desc->mSamplingRate, - &desc->mFormat, - &desc->mChannelMask, - &desc->mLatency, - desc->mFlags, - &offloadInfo); - if (output != 0) { + audio_config_t config = AUDIO_CONFIG_INITIALIZER; + config.sample_rate = desc->mSamplingRate; + config.channel_mask = desc->mChannelMask; + config.format = desc->mFormat; + config.offload_info.sample_rate = desc->mSamplingRate; + config.offload_info.channel_mask = desc->mChannelMask; + config.offload_info.format = desc->mFormat; + audio_io_handle_t output = AUDIO_IO_HANDLE_NONE; + status_t status = mpClientInterface->openOutput(profile->mModule->mHandle, + &output, + &config, + &desc->mDevice, + address, + &desc->mLatency, + desc->mFlags); + if (status == NO_ERROR) { + desc->mSamplingRate = config.sample_rate; + desc->mChannelMask = config.channel_mask; + desc->mFormat = config.format; + // Here is where the out_set_parameters() for card & device gets called if (!address.isEmpty()) { - mpClientInterface->setParameters(output, addressToParameter(device, address)); + char *param = audio_device_address_to_parameter(device, address); + mpClientInterface->setParameters(output, String8(param)); + free(param); } // Here is where we step through and resolve any "dynamic" fields @@ -2799,31 +2837,36 @@ status_t AudioPolicyManager::checkOutputsForDevice(audio_devices_t device, (profile->mChannelMasks.size() < 2))) { ALOGW("checkOutputsForDevice() missing param"); mpClientInterface->closeOutput(output); - output = 0; + output = AUDIO_IO_HANDLE_NONE; } else if (profile->mSamplingRates[0] == 0 || profile->mFormats[0] == 0 || profile->mChannelMasks[0] == 0) { mpClientInterface->closeOutput(output); - desc->mSamplingRate = profile->pickSamplingRate(); - desc->mFormat = profile->pickFormat(); - desc->mChannelMask = profile->pickChannelMask(); - offloadInfo.sample_rate = desc->mSamplingRate; - offloadInfo.format = desc->mFormat; - offloadInfo.channel_mask = desc->mChannelMask; - output = mpClientInterface->openOutput( - profile->mModule->mHandle, - &desc->mDevice, - &desc->mSamplingRate, - &desc->mFormat, - &desc->mChannelMask, - &desc->mLatency, - desc->mFlags, - &offloadInfo); + config.sample_rate = profile->pickSamplingRate(); + config.channel_mask = profile->pickChannelMask(); + config.format = profile->pickFormat(); + config.offload_info.sample_rate = config.sample_rate; + config.offload_info.channel_mask = config.channel_mask; + config.offload_info.format = config.format; + status = mpClientInterface->openOutput(profile->mModule->mHandle, + &output, + &config, + &desc->mDevice, + address, + &desc->mLatency, + desc->mFlags); + if (status == NO_ERROR) { + desc->mSamplingRate = config.sample_rate; + desc->mChannelMask = config.channel_mask; + desc->mFormat = config.format; + } else { + output = AUDIO_IO_HANDLE_NONE; + } } - if (output != 0) { + if (output != AUDIO_IO_HANDLE_NONE) { addOutput(output, desc); if ((desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) == 0) { - audio_io_handle_t duplicatedOutput = 0; + audio_io_handle_t duplicatedOutput = AUDIO_IO_HANDLE_NONE; // set initial stream volume for device applyStreamVolumes(output, device, 0, true); @@ -2833,9 +2876,10 @@ status_t AudioPolicyManager::checkOutputsForDevice(audio_devices_t device, // open a duplicating output thread for the new output and the primary output duplicatedOutput = mpClientInterface->openDuplicateOutput(output, mPrimaryOutput); - if (duplicatedOutput != 0) { + if (duplicatedOutput != AUDIO_IO_HANDLE_NONE) { // add duplicated output descriptor - sp<AudioOutputDescriptor> dupOutputDesc = new AudioOutputDescriptor(NULL); + sp<AudioOutputDescriptor> dupOutputDesc = + new AudioOutputDescriptor(NULL); dupOutputDesc->mOutput1 = mOutputs.valueFor(mPrimaryOutput); dupOutputDesc->mOutput2 = mOutputs.valueFor(output); dupOutputDesc->mSamplingRate = desc->mSamplingRate; @@ -2850,12 +2894,14 @@ status_t AudioPolicyManager::checkOutputsForDevice(audio_devices_t device, mpClientInterface->closeOutput(output); mOutputs.removeItem(output); nextAudioPortGeneration(); - output = 0; + output = AUDIO_IO_HANDLE_NONE; } } } + } else { + output = AUDIO_IO_HANDLE_NONE; } - if (output == 0) { + if (output == AUDIO_IO_HANDLE_NONE) { ALOGW("checkOutputsForDevice() could not open output for device %x", device); profiles.removeAt(profile_index); profile_index--; @@ -2984,17 +3030,28 @@ status_t AudioPolicyManager::checkInputsForDevice(audio_devices_t device, ALOGV("opening input for device 0x%X with params %s", device, address.string()); desc = new AudioInputDescriptor(profile); desc->mDevice = device; + audio_config_t config = AUDIO_CONFIG_INITIALIZER; + config.sample_rate = desc->mSamplingRate; + config.channel_mask = desc->mChannelMask; + config.format = desc->mFormat; + audio_io_handle_t input = AUDIO_IO_HANDLE_NONE; + status_t status = mpClientInterface->openInput(profile->mModule->mHandle, + &input, + &config, + &desc->mDevice, + address, + AUDIO_SOURCE_MIC, + AUDIO_INPUT_FLAG_NONE /*FIXME*/); - audio_io_handle_t input = mpClientInterface->openInput(profile->mModule->mHandle, - &desc->mDevice, - &desc->mSamplingRate, - &desc->mFormat, - &desc->mChannelMask, - AUDIO_INPUT_FLAG_NONE /*FIXME*/); + if (status == NO_ERROR) { + desc->mSamplingRate = config.sample_rate; + desc->mChannelMask = config.channel_mask; + desc->mFormat = config.format; - if (input != 0) { if (!address.isEmpty()) { - mpClientInterface->setParameters(input, addressToParameter(device, address)); + char *param = audio_device_address_to_parameter(device, address); + mpClientInterface->setParameters(input, String8(param)); + free(param); } // Here is where we step through and resolve any "dynamic" fields @@ -3034,7 +3091,7 @@ status_t AudioPolicyManager::checkInputsForDevice(audio_devices_t device, ((profile->mChannelMasks[0] == 0) && (profile->mChannelMasks.size() < 2))) { ALOGW("checkInputsForDevice() direct input missing param"); mpClientInterface->closeInput(input); - input = 0; + input = AUDIO_IO_HANDLE_NONE; } if (input != 0) { @@ -3042,7 +3099,7 @@ status_t AudioPolicyManager::checkInputsForDevice(audio_devices_t device, } } // endif input != 0 - if (input == 0) { + if (input == AUDIO_IO_HANDLE_NONE) { ALOGW("checkInputsForDevice() could not open input for device 0x%X", device); profiles.removeAt(profile_index); profile_index--; @@ -5621,7 +5678,7 @@ void AudioPolicyManager::AudioPort::dump(int fd, int spaces) const if (i == 0 && strcmp(formatStr, "") == 0) { snprintf(buffer, SIZE, "Dynamic"); } else { - snprintf(buffer, SIZE, "%-48s", formatStr); + snprintf(buffer, SIZE, "%s", formatStr); } result.append(buffer); result.append(i == (mFormats.size() - 1) ? "" : ", "); diff --git a/services/audiopolicy/AudioPolicyManager.h b/services/audiopolicy/AudioPolicyManager.h index 62b3ce5..cb4b056 100644 --- a/services/audiopolicy/AudioPolicyManager.h +++ b/services/audiopolicy/AudioPolicyManager.h @@ -802,8 +802,6 @@ private: uint32_t nextUniqueId(); uint32_t nextAudioPortGeneration(); uint32_t curAudioPortGeneration() const { return mAudioPortGeneration; } - // converts device address to string sent to audio HAL via setParameters - static String8 addressToParameter(audio_devices_t device, const String8 address); // internal method to return the output handle for the given device and format audio_io_handle_t getOutputForDevice( audio_devices_t device, diff --git a/services/audiopolicy/AudioPolicyService.h b/services/audiopolicy/AudioPolicyService.h index 08942ee..63fc0c3 100644 --- a/services/audiopolicy/AudioPolicyService.h +++ b/services/audiopolicy/AudioPolicyService.h @@ -361,14 +361,13 @@ private: // in case the audio policy manager has no specific requirements for the output being opened. // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream. // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly. - virtual audio_io_handle_t openOutput(audio_module_handle_t module, - audio_devices_t *pDevices, - uint32_t *pSamplingRate, - audio_format_t *pFormat, - audio_channel_mask_t *pChannelMask, - uint32_t *pLatencyMs, - audio_output_flags_t flags, - const audio_offload_info_t *offloadInfo = NULL); + virtual status_t openOutput(audio_module_handle_t module, + audio_io_handle_t *output, + audio_config_t *config, + audio_devices_t *devices, + const String8& address, + uint32_t *latencyMs, + audio_output_flags_t flags); // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by // a special mixer thread in the AudioFlinger. virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2); @@ -386,10 +385,11 @@ private: // opens an audio input virtual audio_io_handle_t openInput(audio_module_handle_t module, - audio_devices_t *pDevices, - uint32_t *pSamplingRate, - audio_format_t *pFormat, - audio_channel_mask_t *pChannelMask, + audio_io_handle_t *input, + audio_config_t *config, + audio_devices_t *devices, + const String8& address, + audio_source_t source, audio_input_flags_t flags); // closes an audio input virtual status_t closeInput(audio_io_handle_t input); |