From 238e4bbfa382e968bae10b0632e9613f157b604b Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Sat, 1 Jun 2024 22:08:41 +0100 Subject: [PATCH 1/2] Modify the alsa help to use the hdmi: prefix for the HDMI devices it finds. --- audio_alsa.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/audio_alsa.c b/audio_alsa.c index bcd2d6a4..177ce8dc 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -279,16 +279,70 @@ uint64_t frames_sent_for_playing; // frames_sent_for_playing (which Shairport Sync might hold) would be invalid. int frames_sent_break_occurred; +// if a device name ends in ",DEV=0", drop it. Then if it also begins with "CARD=", drop that too. +static void simplify_and_printf_mutable_device_name(char *device_name) { + if (strstr(device_name, ",DEV=0") == device_name + strlen(device_name) - strlen(",DEV=0")) { + char *shortened_device_name = str_replace(device_name, ",DEV=0", ""); + char *simplified_device_name = str_replace(shortened_device_name, "CARD=", ""); + printf(" \"%s\"\n", simplified_device_name); + free(simplified_device_name); + free(shortened_device_name); + } else { + printf(" \"%s\"\n", device_name); + } +} + static void help(void) { + printf(" -d output-device set the output device, default is \"default\".\n" " -c mixer-control set the mixer control name, default is to use no mixer.\n" " -m mixer-device set the mixer device, default is the output device.\n" " -i mixer-index set the mixer index, default is 0.\n"); - int r = system("if [ -d /proc/asound ] ; then echo \" hardware output devices:\" ; ls -al " - "/proc/asound/ 2>/dev/null | grep '\\->' | tr -s ' ' | cut -d ' ' -f 9 | while " - "read line; do echo \" \\\"hw:$line\\\"\" ; done ; fi"); - if (r != 0) - debug(2, "error %d executing a script to list alsa hardware device names", r); + // look for devices with a name prefix of hw: or hdmi: + int card_number = -1; + snd_card_next(&card_number); + + if (card_number < 0) { + printf(" no hardware output devices found.\n"); + } + + int at_least_one_device_found = 0; + while (card_number >= 0) { + void **hints; + char *hdmi_str = NULL; + char *hw_str = NULL; + if (snd_device_name_hint(card_number, "pcm", &hints) == 0) { + void **device_on_card_hints = hints; + while (*device_on_card_hints != NULL) { + char *device_on_card_name = snd_device_name_get_hint(*device_on_card_hints, "NAME"); + if ((strstr(device_on_card_name, "hw:") == device_on_card_name) && (hw_str == NULL)) + hw_str = strdup(device_on_card_name); + if ((strstr(device_on_card_name, "hdmi:") == device_on_card_name) && (hdmi_str == NULL)) + hdmi_str = strdup(device_on_card_name); + free(device_on_card_name); + device_on_card_hints++; + } + snd_device_name_free_hint(hints); + if ((hdmi_str != NULL) || (hw_str != NULL)) { + if (at_least_one_device_found == 0) { + printf(" hardware output devices:\n"); + at_least_one_device_found = 1; + } + } + if (hdmi_str != NULL) { + simplify_and_printf_mutable_device_name(hdmi_str); + } else if (hw_str != NULL) { + simplify_and_printf_mutable_device_name(hw_str); + } + if (hdmi_str != NULL) + free(hdmi_str); + if (hw_str != NULL) + free(hw_str); + } + snd_card_next(&card_number); + } + if (at_least_one_device_found == 0) + printf(" no hardware output devices found.\n"); } void set_alsa_out_dev(char *dev) { alsa_out_dev = dev; } // ugh -- not static! From 7e16d6f91ee1acc8d78869ccb256b0d8f9bf029d Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Sat, 1 Jun 2024 22:30:50 +0100 Subject: [PATCH 2/2] Update RELEASENOTES-DEVELOPMENT.md --- RELEASENOTES-DEVELOPMENT.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/RELEASENOTES-DEVELOPMENT.md b/RELEASENOTES-DEVELOPMENT.md index 1b55442e..b3bd6fc8 100644 --- a/RELEASENOTES-DEVELOPMENT.md +++ b/RELEASENOTES-DEVELOPMENT.md @@ -1,3 +1,36 @@ +Version 4.3.4-dev-3-g238e4bbf +== +**Enhancement -- HDMI Ports** +* If your device has HDMI ports, the Shairport Sync help command has previously listed them with a `hw:` prefix, e.g. `hw:vc4hdmi0`. Unfortunately, if you use a name like that as an `output_device` name for a HDMI device in Shairport Sync, the device may not be usable. + + But if you use the `hdmi:` prefix, e.g. `hdmi:vc4hdmi0`, it _may_ work: something capable of receiving audio must be connected to the HDMI port and it must be powered on _when your device boots up_. + + The enhancement is to update the help text for the ALSA backend to denote HDMI devices using the `hdmi:` prefix rather than `hw:`. Now, for example, on a Raspberry Pi 4, the output is: + ``` + Settings and options for the audio backend "alsa": + -d output-device set the output device, default is "default". + -c mixer-control set the mixer control name, default is to use no mixer. + -m mixer-device set the mixer device, default is the output device. + -i mixer-index set the mixer index, default is 0. + hardware output devices: + "hdmi:vc4hdmi0" + "hdmi:vc4hdmi1" + ``` + Previously it was: + ``` + Settings and options for the audio backend "alsa": + -d output-device set the output device, default is "default". + -c mixer-control set the mixer control name, default is to use no mixer. + -m mixer-device set the mixer device, default is the output device. + -i mixer-index set the mixer index, default is 0. + hardware output devices: + "hw:vc4hdmi0" + "hw:vc4hdmi1" + ``` + ...which is technically correct but unfortunately not very useful. + + Get more information about the hardware output devices using [sps-alsa-explore](https://github.com/mikebrady/sps-alsa-explore) (also available as a Docker image). + Version 4.3.4-dev-1-gc945f3a9 == This is effectively release version 4.3.3 -- the starting point for 4.3.4.