Add unique audio port IDs to AudioTrack and AudioRecord
This will allow to track activity at the track level instead of
at audio session level as only possible with current implementation.
AudioTracks and AudioRecords will receive a unique audio port ID the
first time they register to audio policy with
getOutputForAttr()/getInputForAttr() and keep this ID for their
lifetime.
This CL is the first partial change and just updates the
audio policy and audio flinger APIs used at track creation time.
Test: basic regression test of audio playback and capture use cases
Change-Id: I8d612e67738e120494f61e3f7c60bfd0b2c6a329
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index a714041..c2b282e 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -718,12 +718,10 @@
audio_session_t session,
audio_stream_type_t *stream,
uid_t uid,
- uint32_t samplingRate,
- audio_format_t format,
- audio_channel_mask_t channelMask,
+ const audio_config_t *config,
audio_output_flags_t flags,
audio_port_handle_t selectedDeviceId,
- const audio_offload_info_t *offloadInfo)
+ audio_port_handle_t *portId)
{
audio_attributes_t attributes;
if (attr != NULL) {
@@ -741,10 +739,16 @@
}
stream_type_to_audio_attributes(*stream, &attributes);
}
+
+ // TODO: check for existing client for this port ID
+ if (*portId == AUDIO_PORT_HANDLE_NONE) {
+ *portId = AudioPort::getNextUniqueId();
+ }
+
sp<SwAudioOutputDescriptor> desc;
if (mPolicyMixes.getOutputForAttr(attributes, uid, desc) == NO_ERROR) {
ALOG_ASSERT(desc != 0, "Invalid desc returned by getOutputForAttr");
- if (!audio_has_proportional_frames(format)) {
+ if (!audio_has_proportional_frames(config->format)) {
return BAD_VALUE;
}
*stream = streamTypefromAttributesInt(&attributes);
@@ -782,11 +786,11 @@
}
ALOGV("getOutputForAttr() device 0x%x, samplingRate %d, format %x, channelMask %x, flags %x",
- device, samplingRate, format, channelMask, flags);
+ device, config->sample_rate, config->format, config->channel_mask, flags);
*output = getOutputForDevice(device, session, *stream,
- samplingRate, format, channelMask,
- flags, offloadInfo);
+ config->sample_rate, config->format, config->channel_mask,
+ flags, &config->offload_info);
if (*output == AUDIO_IO_HANDLE_NONE) {
mOutputRoutes.removeRoute(session);
return INVALID_OPERATION;
@@ -1411,16 +1415,15 @@
audio_io_handle_t *input,
audio_session_t session,
uid_t uid,
- uint32_t samplingRate,
- audio_format_t format,
- audio_channel_mask_t channelMask,
+ const audio_config_base_t *config,
audio_input_flags_t flags,
audio_port_handle_t selectedDeviceId,
- input_type_t *inputType)
+ input_type_t *inputType,
+ audio_port_handle_t *portId)
{
ALOGV("getInputForAttr() source %d, samplingRate %d, format %d, channelMask %x,"
"session %d, flags %#x",
- attr->source, samplingRate, format, channelMask, session, flags);
+ attr->source, config->sample_rate, config->format, config->channel_mask, session, flags);
*input = AUDIO_IO_HANDLE_NONE;
*inputType = API_INPUT_INVALID;
@@ -1437,6 +1440,11 @@
}
halInputSource = inputSource;
+ // TODO: check for existing client for this port ID
+ if (*portId == AUDIO_PORT_HANDLE_NONE) {
+ *portId = AudioPort::getNextUniqueId();
+ }
+
// Explicit routing?
sp<DeviceDescriptor> deviceDesc;
for (size_t i = 0; i < mAvailableInputDevices.size(); i++) {
@@ -1486,12 +1494,13 @@
}
*input = getInputForDevice(device, address, session, uid, inputSource,
- samplingRate, format, channelMask, flags,
+ config->sample_rate, config->format, config->channel_mask, flags,
policyMix);
if (*input == AUDIO_IO_HANDLE_NONE) {
mInputRoutes.removeRoute(session);
return INVALID_OPERATION;
}
+
ALOGV("getInputForAttr() returns input type = %d", *inputType);
return NO_ERROR;
}