Use android.media.audio.common.AudioDeviceAddress
Make sure that pairs of 'AudioDeviceDescription' (aka type) and
the device address are always represented in AIDL as AudioDevice.
Move all the AIDL<->legacy conversions into AidlConversion
so it is possible to switch to structured device address
representations in a subsequent CL.
Bug: 198812639
Test: m
Change-Id: If4300e411d76c90d42939f07298535ebdb4185f4
diff --git a/media/libaudioclient/AidlConversion.cpp b/media/libaudioclient/AidlConversion.cpp
index b0426fa..9928b7d 100644
--- a/media/libaudioclient/AidlConversion.cpp
+++ b/media/libaudioclient/AidlConversion.cpp
@@ -38,6 +38,8 @@
using media::audio::common::AudioConfig;
using media::audio::common::AudioConfigBase;
using media::audio::common::AudioContentType;
+using media::audio::common::AudioDevice;
+using media::audio::common::AudioDeviceAddress;
using media::audio::common::AudioDeviceDescription;
using media::audio::common::AudioDeviceType;
using media::audio::common::AudioEncapsulationMetadataType;
@@ -1161,6 +1163,58 @@
}
}
+status_t aidl2legacy_AudioDevice_audio_device(
+ const AudioDevice& aidl,
+ audio_devices_t* legacyType, char* legacyAddress) {
+ *legacyType = VALUE_OR_RETURN_STATUS(
+ aidl2legacy_AudioDeviceDescription_audio_devices_t(aidl.type));
+ return aidl2legacy_string(
+ aidl.address.get<AudioDeviceAddress::id>(),
+ legacyAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN);
+}
+
+status_t aidl2legacy_AudioDevice_audio_device(
+ const AudioDevice& aidl,
+ audio_devices_t* legacyType, String8* legacyAddress) {
+ *legacyType = VALUE_OR_RETURN_STATUS(
+ aidl2legacy_AudioDeviceDescription_audio_devices_t(aidl.type));
+ *legacyAddress = VALUE_OR_RETURN_STATUS(aidl2legacy_string_view_String8(
+ aidl.address.get<AudioDeviceAddress::id>()));
+ return OK;
+}
+
+status_t aidl2legacy_AudioDevice_audio_device(
+ const AudioDevice& aidl,
+ audio_devices_t* legacyType, std::string* legacyAddress) {
+ *legacyType = VALUE_OR_RETURN_STATUS(
+ aidl2legacy_AudioDeviceDescription_audio_devices_t(aidl.type));
+ *legacyAddress = aidl.address.get<AudioDeviceAddress::id>();
+ return OK;
+}
+
+ConversionResult<AudioDevice> legacy2aidl_audio_device_AudioDevice(
+ audio_devices_t legacyType, const char* legacyAddress) {
+ AudioDevice aidl;
+ aidl.type = VALUE_OR_RETURN(
+ legacy2aidl_audio_devices_t_AudioDeviceDescription(legacyType));
+ const std::string aidl_id = VALUE_OR_RETURN(
+ legacy2aidl_string(legacyAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN));
+ aidl.address = AudioDeviceAddress::make<AudioDeviceAddress::id>(aidl_id);
+ return aidl;
+}
+
+ConversionResult<AudioDevice>
+legacy2aidl_audio_device_AudioDevice(
+ audio_devices_t legacyType, const String8& legacyAddress) {
+ AudioDevice aidl;
+ aidl.type = VALUE_OR_RETURN(
+ legacy2aidl_audio_devices_t_AudioDeviceDescription(legacyType));
+ const std::string aidl_id = VALUE_OR_RETURN(
+ legacy2aidl_String8_string(legacyAddress));
+ aidl.address = AudioDeviceAddress::make<AudioDeviceAddress::id>(aidl_id);
+ return aidl;
+}
+
ConversionResult<audio_format_t> aidl2legacy_AudioFormatDescription_audio_format_t(
const AudioFormatDescription& aidl) {
static const std::unordered_map<AudioFormatDescription, audio_format_t> m =
@@ -1491,8 +1545,8 @@
const media::AudioPortConfigDeviceExt& aidl) {
audio_port_config_device_ext legacy;
legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule));
- legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioDeviceDescription_audio_devices_t(aidl.type));
- RETURN_IF_ERROR(aidl2legacy_string(aidl.address, legacy.address, AUDIO_DEVICE_MAX_ADDRESS_LEN));
+ RETURN_IF_ERROR(aidl2legacy_AudioDevice_audio_device(
+ aidl.device, &legacy.type, legacy.address));
return legacy;
}
@@ -1501,9 +1555,8 @@
const audio_port_config_device_ext& legacy) {
media::AudioPortConfigDeviceExt aidl;
aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module));
- aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_devices_t_AudioDeviceDescription(legacy.type));
- aidl.address = VALUE_OR_RETURN(
- legacy2aidl_string(legacy.address, AUDIO_DEVICE_MAX_ADDRESS_LEN));
+ aidl.device = VALUE_OR_RETURN(legacy2aidl_audio_device_AudioDevice(
+ legacy.type, legacy.address));
return aidl;
}
@@ -2578,10 +2631,8 @@
aidl2legacy_AudioPortDeviceExt_audio_port_device_ext(const media::AudioPortDeviceExt& aidl) {
audio_port_device_ext legacy;
legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule));
- legacy.type = VALUE_OR_RETURN(
- aidl2legacy_AudioDeviceDescription_audio_devices_t(aidl.device.type));
- RETURN_IF_ERROR(
- aidl2legacy_string(aidl.device.address, legacy.address, sizeof(legacy.address)));
+ RETURN_IF_ERROR(aidl2legacy_AudioDevice_audio_device(
+ aidl.device, &legacy.type, legacy.address));
legacy.encapsulation_modes = VALUE_OR_RETURN(
aidl2legacy_AudioEncapsulationMode_mask(aidl.encapsulationModes));
legacy.encapsulation_metadata_types = VALUE_OR_RETURN(
@@ -2593,10 +2644,8 @@
legacy2aidl_audio_port_device_ext_AudioPortDeviceExt(const audio_port_device_ext& legacy) {
media::AudioPortDeviceExt aidl;
aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module));
- aidl.device.type = VALUE_OR_RETURN(
- legacy2aidl_audio_devices_t_AudioDeviceDescription(legacy.type));
- aidl.device.address = VALUE_OR_RETURN(
- legacy2aidl_string(legacy.address, sizeof(legacy.address)));
+ aidl.device = VALUE_OR_RETURN(legacy2aidl_audio_device_AudioDevice(
+ legacy.type, legacy.address));
aidl.encapsulationModes = VALUE_OR_RETURN(
legacy2aidl_AudioEncapsulationMode_mask(legacy.encapsulation_modes));
aidl.encapsulationMetadataTypes = VALUE_OR_RETURN(
diff --git a/media/libaudioclient/AudioSystem.cpp b/media/libaudioclient/AudioSystem.cpp
index afc65d7..2557482 100644
--- a/media/libaudioclient/AudioSystem.cpp
+++ b/media/libaudioclient/AudioSystem.cpp
@@ -56,6 +56,7 @@
using media::audio::common::AudioConfig;
using media::audio::common::AudioConfigBase;
using media::audio::common::AudioDevice;
+using media::audio::common::AudioDeviceAddress;
using media::audio::common::AudioDeviceDescription;
using media::audio::common::AudioFormatDescription;
using media::audio::common::AudioOffloadInfo;
@@ -855,10 +856,8 @@
name = device_name;
}
- AudioDevice deviceAidl;
- deviceAidl.type = VALUE_OR_RETURN_STATUS(
- legacy2aidl_audio_devices_t_AudioDeviceDescription(device));
- deviceAidl.address = address;
+ AudioDevice deviceAidl = VALUE_OR_RETURN_STATUS(
+ legacy2aidl_audio_device_AudioDevice(device, address));
return statusTFromBinderStatus(
aps->setDeviceConnectionState(
@@ -876,10 +875,8 @@
if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
auto result = [&]() -> ConversionResult<audio_policy_dev_state_t> {
- AudioDevice deviceAidl;
- deviceAidl.type = VALUE_OR_RETURN(
- legacy2aidl_audio_devices_t_AudioDeviceDescription(device));
- deviceAidl.address = device_address;
+ AudioDevice deviceAidl = VALUE_OR_RETURN(
+ legacy2aidl_audio_device_AudioDevice(device, device_address));
media::AudioPolicyDeviceState result;
RETURN_IF_ERROR(statusTFromBinderStatus(
@@ -907,10 +904,8 @@
name = device_name;
}
- AudioDevice deviceAidl;
- deviceAidl.type = VALUE_OR_RETURN_STATUS(
- legacy2aidl_audio_devices_t_AudioDeviceDescription(device));
- deviceAidl.address = address;
+ AudioDevice deviceAidl = VALUE_OR_RETURN_STATUS(
+ legacy2aidl_audio_device_AudioDevice(device, address));
return statusTFromBinderStatus(
aps->handleDeviceConfigChange(deviceAidl, name, VALUE_OR_RETURN_STATUS(
diff --git a/media/libaudioclient/PolicyAidlConversion.cpp b/media/libaudioclient/PolicyAidlConversion.cpp
index c3b7ce7..fd94568 100644
--- a/media/libaudioclient/PolicyAidlConversion.cpp
+++ b/media/libaudioclient/PolicyAidlConversion.cpp
@@ -25,6 +25,7 @@
namespace android {
using base::unexpected;
+using media::audio::common::AudioDeviceAddress;
ConversionResult<volume_group_t>
aidl2legacy_int32_t_volume_group_t(int32_t aidl) {
@@ -238,9 +239,8 @@
aidl.format, false /*isInput*/));
legacy.mRouteFlags = VALUE_OR_RETURN(
aidl2legacy_AudioMixRouteFlag_uint32_t_mask(aidl.routeFlags));
- legacy.mDeviceType = VALUE_OR_RETURN(
- aidl2legacy_AudioDeviceDescription_audio_devices_t(aidl.device.type));
- legacy.mDeviceAddress = VALUE_OR_RETURN(aidl2legacy_string_view_String8(aidl.device.address));
+ RETURN_IF_ERROR(aidl2legacy_AudioDevice_audio_device(
+ aidl.device, &legacy.mDeviceType, &legacy.mDeviceAddress));
legacy.mCbFlags = VALUE_OR_RETURN(aidl2legacy_AudioMixCallbackFlag_uint32_t_mask(aidl.cbFlags));
legacy.mAllowPrivilegedMediaPlaybackCapture = aidl.allowPrivilegedMediaPlaybackCapture;
legacy.mVoiceCommunicationCaptureAllowed = aidl.voiceCommunicationCaptureAllowed;
@@ -261,9 +261,9 @@
legacy.mFormat, false /*isInput*/));
aidl.routeFlags = VALUE_OR_RETURN(
legacy2aidl_uint32_t_AudioMixRouteFlag_mask(legacy.mRouteFlags));
- aidl.device.type = VALUE_OR_RETURN(
- legacy2aidl_audio_devices_t_AudioDeviceDescription(legacy.mDeviceType));
- aidl.device.address = VALUE_OR_RETURN(legacy2aidl_String8_string(legacy.mDeviceAddress));
+ aidl.device = VALUE_OR_RETURN(
+ legacy2aidl_audio_device_AudioDevice(
+ legacy.mDeviceType, legacy.mDeviceAddress));
aidl.cbFlags = VALUE_OR_RETURN(legacy2aidl_uint32_t_AudioMixCallbackFlag_mask(legacy.mCbFlags));
aidl.allowPrivilegedMediaPlaybackCapture = legacy.mAllowPrivilegedMediaPlaybackCapture;
aidl.voiceCommunicationCaptureAllowed = legacy.mVoiceCommunicationCaptureAllowed;
diff --git a/media/libaudioclient/aidl/android/media/AudioPortConfigDeviceExt.aidl b/media/libaudioclient/aidl/android/media/AudioPortConfigDeviceExt.aidl
index 82e1bae..640a63b 100644
--- a/media/libaudioclient/aidl/android/media/AudioPortConfigDeviceExt.aidl
+++ b/media/libaudioclient/aidl/android/media/AudioPortConfigDeviceExt.aidl
@@ -16,7 +16,7 @@
package android.media;
-import android.media.audio.common.AudioDeviceDescription;
+import android.media.audio.common.AudioDevice;
/**
* {@hide}
@@ -28,9 +28,7 @@
*/
int hwModule;
/**
- * Device type.
+ * Audio device instance.
*/
- AudioDeviceDescription type;
- /** Device address. "" if N/A. */
- @utf8InCpp String address;
+ AudioDevice device;
}
diff --git a/media/libaudioclient/include/media/AidlConversion.h b/media/libaudioclient/include/media/AidlConversion.h
index d4069d4..3bdd11c 100644
--- a/media/libaudioclient/include/media/AidlConversion.h
+++ b/media/libaudioclient/include/media/AidlConversion.h
@@ -146,6 +146,22 @@
ConversionResult<media::audio::common::AudioDeviceDescription>
legacy2aidl_audio_devices_t_AudioDeviceDescription(audio_devices_t legacy);
+status_t aidl2legacy_AudioDevice_audio_device(
+ const media::audio::common::AudioDevice& aidl,
+ audio_devices_t* legacyType, char* legacyAddress);
+status_t aidl2legacy_AudioDevice_audio_device(
+ const media::audio::common::AudioDevice& aidl,
+ audio_devices_t* legacyType, String8* legacyAddress);
+status_t aidl2legacy_AudioDevice_audio_device(
+ const media::audio::common::AudioDevice& aidl,
+ audio_devices_t* legacyType, std::string* legacyAddress);
+ConversionResult<media::audio::common::AudioDevice>
+legacy2aidl_audio_device_AudioDevice(
+ audio_devices_t legacyType, const char* legacyAddress);
+ConversionResult<media::audio::common::AudioDevice>
+legacy2aidl_audio_device_AudioDevice(
+ audio_devices_t legacyType, const String8& legacyAddress);
+
ConversionResult<audio_format_t> aidl2legacy_AudioFormatDescription_audio_format_t(
const media::audio::common::AudioFormatDescription& aidl);
ConversionResult<media::audio::common::AudioFormatDescription>