From 7bc0df08005f64645b17d6ab95ef35fb3a7259f2 Mon Sep 17 00:00:00 2001 From: Konsta Date: Sat, 25 Oct 2025 20:19:52 +0300 Subject: [PATCH] audio: alsa_utils: get hdmi device from property * ALSA HDMI audio needs to be disabled when 3.5mm jack, DAC, or external USB audio cards is used. Enable HDMI audio path based on system property and the set the vc4 audio device name accordingly. --- audio/alsa_utils/alsa_device_proxy.c | 33 +++++++++++++++----- audio/alsa_utils/include/alsa_device_proxy.h | 5 +++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/audio/alsa_utils/alsa_device_proxy.c b/audio/alsa_utils/alsa_device_proxy.c index 00cc04e..e53ab10 100644 --- a/audio/alsa_utils/alsa_device_proxy.c +++ b/audio/alsa_utils/alsa_device_proxy.c @@ -50,11 +50,25 @@ static const unsigned format_byte_size_map[] = { 3, /* PCM_FORMAT_S24_3LE */ }; -static const bool hdmi = true; +static bool is_hdmi(char *hdmi_device_name) { + char hdmi_device[PROPERTY_VALUE_MAX]; + property_get("persist.vendor.audio.device", hdmi_device, "hdmi0"); + + if (!strcmp(hdmi_device, "hdmi0") || !strcmp(hdmi_device, "hdmi1")) { + // Use card configured in ALSA vc4-hdmi.conf to get IEC958 subframe conversion + sprintf(hdmi_device_name, "default:CARD=vc4%s", hdmi_device); + return true; + } + + return false; +} int proxy_prepare(alsa_device_proxy * proxy, const alsa_device_profile* profile, struct pcm_config * config, bool require_exact_match) { + // Disable HDMI for external devices + proxy->hdmi = false; + int ret = 0; ALOGD("proxy_prepare(c:%d, d:%d)", profile->card, profile->device); @@ -144,7 +158,10 @@ int proxy_prepare(alsa_device_proxy * proxy, const alsa_device_profile* profile, int proxy_prepare_from_default_config(alsa_device_proxy * proxy, const alsa_device_profile * profile) { - if (hdmi) { + // Enable HDMI based on audio device property + proxy->hdmi = is_hdmi(proxy->hdmi_device_name); + + if (proxy->hdmi) { return hdmi_proxy_prepare_from_default_config(proxy, profile); } @@ -195,7 +212,7 @@ int hdmi_proxy_prepare_from_default_config(alsa_device_proxy * proxy, int proxy_open(alsa_device_proxy * proxy) { - if (hdmi) { + if (proxy->hdmi) { return hdmi_proxy_open(proxy); } @@ -232,7 +249,7 @@ int hdmi_proxy_open(alsa_device_proxy * proxy) int err; snd_pcm_t *pcm; - if ((err = snd_pcm_open(&pcm, "default:CARD=vc4hdmi0", SND_PCM_STREAM_PLAYBACK, 0) < 0)) { + if ((err = snd_pcm_open(&pcm, proxy->hdmi_device_name, SND_PCM_STREAM_PLAYBACK, 0) < 0)) { ALOGE("Error snd_pcm_open: %s", snd_strerror(err)); return -ENODEV; } @@ -287,7 +304,7 @@ int hdmi_proxy_open(alsa_device_proxy * proxy) void proxy_close(alsa_device_proxy * proxy) { - if (hdmi) { + if (proxy->hdmi) { return hdmi_proxy_close(proxy); } @@ -359,7 +376,7 @@ unsigned proxy_get_latency(const alsa_device_proxy * proxy) int proxy_get_presentation_position(const alsa_device_proxy * proxy, uint64_t *frames, struct timespec *timestamp) { - if (hdmi) { + if (proxy->hdmi) { return hdmi_proxy_get_presentation_position(proxy, frames, timestamp); } @@ -453,7 +470,7 @@ int proxy_get_capture_position(const alsa_device_proxy * proxy, int proxy_stop(alsa_device_proxy * proxy) { - if (hdmi) { + if (proxy->hdmi) { return hdmi_proxy_stop(proxy); } @@ -481,7 +498,7 @@ int proxy_write(alsa_device_proxy * proxy, const void *data, unsigned int count) int proxy_write_with_retries( alsa_device_proxy * proxy, const void *data, unsigned int count, int tries) { - if (hdmi) { + if (proxy->hdmi) { return hdmi_proxy_write_with_retries(proxy, data, count, tries); } diff --git a/audio/alsa_utils/include/alsa_device_proxy.h b/audio/alsa_utils/include/alsa_device_proxy.h index f3f9e3f..ee6618e 100644 --- a/audio/alsa_utils/include/alsa_device_proxy.h +++ b/audio/alsa_utils/include/alsa_device_proxy.h @@ -18,6 +18,8 @@ #ifndef ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROXY_H #define ANDROID_SYSTEM_MEDIA_ALSA_UTILS_ALSA_DEVICE_PROXY_H +#include + #include #include @@ -33,6 +35,9 @@ typedef struct { size_t frame_size; /* valid after proxy_prepare(), the frame size in bytes */ uint64_t transferred; /* the total frames transferred, not cleared on standby */ + + bool hdmi; + char hdmi_device_name[PROPERTY_VALUE_MAX]; } alsa_device_proxy;