]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Merge branch 'development' of github.com:mikebrady/shairport-sync into development
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 3 Jun 2024 08:37:11 +0000 (09:37 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 3 Jun 2024 08:37:11 +0000 (09:37 +0100)
forgot online update

1  2 
audio_alsa.c

diff --cc audio_alsa.c
index 1833150cc898a74228bc65c45de4ba92efd2f6c7,177ce8dc3e4eb292cd146273dba399b21faead1e..092781a6246420c8fe131d220fb3c818fc029016
@@@ -285,19 -298,54 +299,59 @@@ static void help(void) 
           "    -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!
 +void set_alsa_out_dev(char *dev) {
 +  alsa_out_dev = dev;
 +  if (hw_alsa_out_dev != NULL)
 +    free(hw_alsa_out_dev);
 +  hw_alsa_out_dev = str_replace(alsa_out_dev, "hdmi:", "hw:");
 +} // ugh -- not static!
  
  // assuming pthread cancellation is disabled
  // returns zero of all is okay, a Unx error code if there's a problem