audio policy: refactor getOutput() method
getOtuput() was long replaced by getOutputForAttr() for the purpose of
querying an appropriate HAL output stream for a given playback use case.
It is now only used internally by AudioSystem to find an existing output
corresponding to a given stream type in limited cases.
This CL simplifies getOutput() by removing unused arguments and just
returning an output from already opened outputs.
This is in preparation of limiting access to audio policy binder calls
to what is strictly needed by apps.
Test: test main playback, capture and call use cases.
Change-Id: I137c5526aa7e82303b43948326c77ec798f432f5
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 89e5d77..9c24641 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -751,20 +751,15 @@
return profile;
}
-audio_io_handle_t AudioPolicyManager::getOutput(audio_stream_type_t stream,
- uint32_t samplingRate,
- audio_format_t format,
- audio_channel_mask_t channelMask,
- audio_output_flags_t flags,
- const audio_offload_info_t *offloadInfo)
+audio_io_handle_t AudioPolicyManager::getOutput(audio_stream_type_t stream)
{
routing_strategy strategy = getStrategy(stream);
audio_devices_t device = getDeviceForStrategy(strategy, false /*fromCache*/);
- ALOGV("getOutput() device %d, stream %d, samplingRate %d, format %x, channelMask %x, flags %x",
- device, stream, samplingRate, format, channelMask, flags);
+ SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs);
+ audio_io_handle_t output = selectOutput(outputs, AUDIO_OUTPUT_FLAG_NONE, AUDIO_FORMAT_INVALID);
- return getOutputForDevice(device, AUDIO_SESSION_ALLOCATE, stream, samplingRate, format,
- channelMask, flags, offloadInfo);
+ ALOGV("getOutput() stream %d selected device %08x, output %d", stream, device, output);
+ return output;
}
status_t AudioPolicyManager::getOutputForAttr(const audio_attributes_t *attr,
@@ -942,12 +937,12 @@
(channelMask == outputDesc->mChannelMask)) {
if (session == outputDesc->mDirectClientSession) {
outputDesc->mDirectOpenCount++;
- ALOGV("getOutput() reusing direct output %d for session %d",
+ ALOGV("getOutputForDevice() reusing direct output %d for session %d",
mOutputs.keyAt(i), session);
return mOutputs.keyAt(i);
} else {
- ALOGV("getOutput() do not reuse direct output because current client (%d) "
- "is not the same as requesting client (%d)",
+ ALOGV("getOutputForDevice() do not reuse direct output because"
+ "current client (%d) is not the same as requesting client (%d)",
outputDesc->mDirectClientSession, session);
goto non_direct_output;
}
@@ -1002,7 +997,7 @@
(samplingRate != 0 && samplingRate != config.sample_rate) ||
(format != AUDIO_FORMAT_DEFAULT && !audio_formats_match(format, config.format)) ||
(channelMask != 0 && channelMask != config.channel_mask)) {
- ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d,"
+ ALOGV("getOutputForDevice() 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);
@@ -1025,7 +1020,7 @@
addOutput(output, outputDesc);
mPreviousOutputs = mOutputs;
- ALOGV("getOutput() returns new direct output %d", output);
+ ALOGV("getOutputForDevice() returns new direct output %d", output);
mpClientInterface->onAudioPortListUpdate();
return output;
}
@@ -1052,8 +1047,9 @@
flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_DIRECT);
output = selectOutput(outputs, flags, format);
}
- ALOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d, "
- "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags);
+ ALOGW_IF((output == 0), "getOutputForDevice() could not find output for stream %d, "
+ "samplingRate %d, format %d, channels %x, flags %x",
+ stream, samplingRate, format, channelMask, flags);
return output;
}
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.h b/services/audiopolicy/managerdefault/AudioPolicyManager.h
index 1b0c315..11894dc 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.h
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.h
@@ -99,12 +99,7 @@
virtual void setSystemProperty(const char* property, const char* value);
virtual status_t initCheck();
- virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
- uint32_t samplingRate,
- audio_format_t format,
- audio_channel_mask_t channelMask,
- audio_output_flags_t flags,
- const audio_offload_info_t *offloadInfo);
+ virtual audio_io_handle_t getOutput(audio_stream_type_t stream);
virtual status_t getOutputForAttr(const audio_attributes_t *attr,
audio_io_handle_t *output,
audio_session_t session,