audio: support custom acdb for external device
add the specific external device setting in audio_platform_info.xml
For example:
<external_specific_dev>
<ext_device name="SND_DEVICE_OUT_USB_HEADSET" usbid="18d1:5034" acdb_id="10" />
</external_specific_dev>
Bug: 117336751
Test: manual test ok
Change-Id: Ie9abcadd9bcd6d06c5d8f0a9807c3935ee4a1d35
Signed-off-by: Carter Hsu <carterhsu@google.com>
Signed-off-by: Robert Lee <lerobert@google.com>
diff --git a/hal/audio_extn/usb.c b/hal/audio_extn/usb.c
index 71e1aed..b0b5049 100644
--- a/hal/audio_extn/usb.c
+++ b/hal/audio_extn/usb.c
@@ -43,6 +43,7 @@
#define SAMPLE_RATE_8000 8000
#define SAMPLE_RATE_11025 11025
#define DEFAULT_SERVICE_INTERVAL_US 1000
+#define USBID_SIZE 16
/* TODO: dynamically populate supported sample rates */
static uint32_t supported_sample_rates[] =
@@ -83,6 +84,7 @@
int usb_sidetone_index[USB_SIDETONE_MAX_INDEX];
int usb_sidetone_vol_min;
int usb_sidetone_vol_max;
+ char usbid[USBID_SIZE];
};
struct usb_module {
@@ -510,6 +512,48 @@
return ret;
}
+static int usb_get_usbid(struct usb_card_config *usb_card_info,
+ int card)
+{
+ int32_t fd=-1;
+ char path[128];
+ int ret = 0;
+
+ memset(usb_card_info->usbid, 0, sizeof(usb_card_info->usbid));
+
+ ret = snprintf(path, sizeof(path), "/proc/asound/card%u/usbid",
+ card);
+
+ if (ret < 0) {
+ ALOGE("%s: failed on snprintf (%d) to path %s\n",
+ __func__, ret, path);
+ goto done;
+ }
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ ALOGE("%s: error failed to open file %s error: %d\n",
+ __func__, path, errno);
+ ret = -EINVAL;
+ goto done;
+ }
+
+ if (read(fd, usb_card_info->usbid, USBID_SIZE - 1) < 0) {
+ ALOGE("file read error\n");
+ ret = -EINVAL;
+ usb_card_info->usbid[0] = '\0';
+ goto done;
+ }
+
+ strtok(usb_card_info->usbid, "\n");
+
+done:
+ if (fd >= 0)
+ close(fd);
+
+ return ret;
+}
+
static int usb_get_device_playback_config(struct usb_card_config *usb_card_info,
int card)
{
@@ -1082,6 +1126,10 @@
}
list_init(&usb_card_info->usb_device_conf_list);
if (usb_output_device(device)) {
+ if (usb_get_usbid(usb_card_info, card) < 0) {
+ ALOGE("parse card %d usbid fail", card);
+ }
+
if (!usb_get_device_playback_config(usb_card_info, card)){
usb_card_info->usb_card = card;
usb_card_info->usb_device_type = device;
@@ -1090,6 +1138,10 @@
goto exit;
}
} else if (usb_input_device(device)) {
+ if (usb_get_usbid(usb_card_info, card) < 0) {
+ ALOGE("parse card %d usbid fail", card);
+ }
+
if (!usb_get_device_capture_config(usb_card_info, card)) {
usb_card_info->usb_card = card;
usb_card_info->usb_device_type = device;
@@ -1251,6 +1303,22 @@
return 0;
}
+char *audio_extn_usb_usbid()
+{
+ struct usb_card_config *card_info;
+
+ if (usbmod == NULL)
+ return NULL;
+
+ if (list_empty(&usbmod->usb_card_conf_list))
+ return NULL;
+
+ card_info = node_to_item(list_head(&usbmod->usb_card_conf_list),\
+ struct usb_card_config, list);
+
+ return strdup(card_info->usbid);
+}
+
void audio_extn_usb_init(void *adev)
{
if (usbmod == NULL) {