audio HAL: add support for audio patch API.
Add support for audio patch routing APIs and update
audio HAL version to 3.0.
Audio patch APIs are needed for LE audio because LE Audio
device types have more than one bit set.
Bug: 150670922
Test: regression tests with BT A2DP SW encoder path
Change-Id: I2c7c3db05063c6cc248681b9964af6c4633ffe99
(cherry picked from commit 2f7ce9f5a539aa99b4e91743007941f21cfee22f)
diff --git a/system/audio_bluetooth_hw/audio_bluetooth_hw.cc b/system/audio_bluetooth_hw/audio_bluetooth_hw.cc
index 887c4e3..35de87d 100644
--- a/system/audio_bluetooth_hw/audio_bluetooth_hw.cc
+++ b/system/audio_bluetooth_hw/audio_bluetooth_hw.cc
@@ -99,6 +99,59 @@
return -ENOSYS;
}
+static int adev_create_audio_patch(struct audio_hw_device* device,
+ unsigned int num_sources,
+ const struct audio_port_config* sources,
+ unsigned int num_sinks,
+ const struct audio_port_config* sinks,
+ audio_patch_handle_t* handle) {
+ if (device == nullptr || sources == nullptr || sinks == nullptr ||
+ handle == nullptr || num_sources != 1 || num_sinks == 0 ||
+ num_sinks > AUDIO_PATCH_PORTS_MAX) {
+ return -EINVAL;
+ }
+ if (sources[0].type == AUDIO_PORT_TYPE_DEVICE) {
+ if (num_sinks != 1 || sinks[0].type != AUDIO_PORT_TYPE_MIX) {
+ return -EINVAL;
+ }
+ } else if (sources[0].type == AUDIO_PORT_TYPE_MIX) {
+ for (unsigned int i = 0; i < num_sinks; i++) {
+ if (sinks[i].type != AUDIO_PORT_TYPE_DEVICE) {
+ return -EINVAL;
+ }
+ }
+ } else {
+ return -EINVAL;
+ }
+
+ auto* bluetooth_device = reinterpret_cast<BluetoothAudioDevice*>(device);
+ std::lock_guard<std::mutex> guard(bluetooth_device->mutex_);
+ if (*handle == AUDIO_PATCH_HANDLE_NONE) {
+ *handle = ++bluetooth_device->next_unique_id;
+ }
+
+ LOG(INFO) << __func__ << ": device=" << std::hex << sinks[0].ext.device.type
+ << " handle: " << *handle;
+ return 0;
+}
+
+static int adev_release_audio_patch(struct audio_hw_device* device,
+ audio_patch_handle_t patch_handle) {
+ if (device == nullptr) {
+ return -EINVAL;
+ }
+ LOG(INFO) << __func__ << ": patch_handle=" << patch_handle;
+ return 0;
+}
+
+static int adev_get_audio_port(struct audio_hw_device* device,
+ struct audio_port* port) {
+ if (device == nullptr || port == nullptr) {
+ return -EINVAL;
+ }
+ return -ENOSYS;
+}
+
static int adev_dump(const audio_hw_device_t* device, int fd) { return 0; }
static int adev_close(hw_device_t* device) {
@@ -117,7 +170,7 @@
if (!adev) return -ENOMEM;
adev->common.tag = HARDWARE_DEVICE_TAG;
- adev->common.version = AUDIO_DEVICE_API_VERSION_2_0;
+ adev->common.version = AUDIO_DEVICE_API_VERSION_3_0;
adev->common.module = (struct hw_module_t*)module;
adev->common.close = adev_close;
@@ -138,6 +191,9 @@
adev->dump = adev_dump;
adev->set_master_mute = adev_set_master_mute;
adev->get_master_mute = adev_get_master_mute;
+ adev->create_audio_patch = adev_create_audio_patch;
+ adev->release_audio_patch = adev_release_audio_patch;
+ adev->get_audio_port = adev_get_audio_port;
*device = &adev->common;
return 0;
diff --git a/system/audio_bluetooth_hw/stream_apis.h b/system/audio_bluetooth_hw/stream_apis.h
index 36dd589..d101027 100644
--- a/system/audio_bluetooth_hw/stream_apis.h
+++ b/system/audio_bluetooth_hw/stream_apis.h
@@ -81,6 +81,7 @@
std::mutex mutex_;
std::list<BluetoothStreamOut*> opened_stream_outs_ =
std::list<BluetoothStreamOut*>(0);
+ uint32_t next_unique_id = 1;
};
struct BluetoothStreamIn {