Skip to content

Commit eaf9236

Browse files
committed
Give access to mixers in a HDMI device by attaching the mixer to the device's name but replacing the header hdmi: with hw:
1 parent 19556bf commit eaf9236

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

audio_alsa.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* libalsa output driver. This file is part of Shairport.
33
* Copyright (c) Muffinman, Skaman 2013
4-
* Copyright (c) Mike Brady 2014 -- 2022
4+
* Copyright (c) Mike Brady 2014 -- 2024
55
* All rights reserved.
66
*
77
* Permission is hereby granted, free of charge, to any person
@@ -146,6 +146,7 @@ long alsa_mix_minv, alsa_mix_maxv;
146146
long alsa_mix_mindb, alsa_mix_maxdb;
147147

148148
char *alsa_out_dev = "default";
149+
char *hw_alsa_out_dev = NULL;
149150
char *alsa_mix_dev = NULL;
150151
char *alsa_mix_ctrl = NULL;
151152
int alsa_mix_index = 0;
@@ -291,7 +292,12 @@ static void help(void) {
291292
debug(2, "error %d executing a script to list alsa hardware device names", r);
292293
}
293294

294-
void set_alsa_out_dev(char *dev) { alsa_out_dev = dev; } // ugh -- not static!
295+
void set_alsa_out_dev(char *dev) {
296+
alsa_out_dev = dev;
297+
if (hw_alsa_out_dev != NULL)
298+
free(hw_alsa_out_dev);
299+
hw_alsa_out_dev = str_replace(alsa_out_dev, "hdmi:", "hw:");
300+
} // ugh -- not static!
295301

296302
// assuming pthread cancellation is disabled
297303
// returns zero of all is okay, a Unx error code if there's a problem
@@ -902,7 +908,7 @@ static int prepare_mixer() {
902908
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); // make this un-cancellable
903909

904910
if (alsa_mix_dev == NULL)
905-
alsa_mix_dev = alsa_out_dev;
911+
alsa_mix_dev = hw_alsa_out_dev;
906912

907913
// Now, start trying to initialise the alsa device with the settings
908914
// obtained
@@ -1355,11 +1361,19 @@ static int init(int argc, char **argv) {
13551361
}
13561362

13571363
debug(1, "alsa: output device name is \"%s\".", alsa_out_dev);
1358-
1364+
1365+
1366+
// now, we need a version of the alsa_out_dev that substitutes "hw:" for "hdmi" if it's
1367+
// there. It seems hw:1 would be a valid devcie name where hdmi:1 would not
1368+
1369+
if (alsa_out_dev != NULL)
1370+
hw_alsa_out_dev = str_replace(alsa_out_dev, "hdmi:", "hw:");
1371+
13591372
// so, now, if the option to keep the DAC running has been selected, start a
13601373
// thread to monitor the
13611374
// length of the queue
13621375
// if the queue gets too short, stuff it with silence
1376+
13631377

13641378
pthread_create(&alsa_buffer_monitor_thread, NULL, &alsa_buffer_monitor_thread_code, NULL);
13651379

@@ -1376,6 +1390,8 @@ static void deinit(void) {
13761390
debug(3, "Join buffer monitor thread.");
13771391
pthread_join(alsa_buffer_monitor_thread, NULL);
13781392
pthread_setcancelstate(oldState, NULL);
1393+
if (hw_alsa_out_dev != NULL)
1394+
free(hw_alsa_out_dev);
13791395
}
13801396

13811397
static int set_mute_state() {

0 commit comments

Comments
 (0)