Attempt to honor PULSE_SERVER.
This commit is contained in:
1 parent
a5d7df5094
commit
e5b3e15e61
3 files changed
+50
-9
No files matched your search
@@ -230,6 +230,12 @@ Barnard uses OpenAL Soft for audio. The default backend order is determined by t
|
|||||||
- Config file: add `audiodriver = "pipewire"` to your `~/.barnard.toml`
|
- Config file: add `audiodriver = "pipewire"` to your `~/.barnard.toml`
|
||||||
- Environment: `ALSOFT_DRIVERS=pipewire ./barnard` (takes precedence over config)
|
- Environment: `ALSOFT_DRIVERS=pipewire ./barnard` (takes precedence over config)
|
||||||
|
|
||||||
|
If `PULSE_SERVER` is set, Barnard selects OpenAL Soft's `pulse` backend so both
|
||||||
|
playback and capture use that server. `--audio-driver` and `ALSOFT_DRIVERS` take
|
||||||
|
precedence over `PULSE_SERVER`; otherwise `PULSE_SERVER` takes precedence over
|
||||||
|
the configured `audiodriver`. For example, in Termux, set `PULSE_SERVER` to the
|
||||||
|
address of the PulseAudio server before starting Barnard.
|
||||||
|
|
||||||
If PipeWire or PulseAudio support is missing, install OpenAL Soft with the corresponding backend enabled (e.g., `libopenal1` or `openal-soft` packages built with PipeWire). After changing drivers, rerun with `--list_devices` to confirm the desired devices appear.
|
If PipeWire or PulseAudio support is missing, install OpenAL Soft with the corresponding backend enabled (e.g., `libopenal1` or `openal-soft` packages built with PipeWire). After changing drivers, rerun with `--list_devices` to confirm the desired devices appear.
|
||||||
|
|
||||||
Leaving `audiodriver` empty uses the OpenAL Soft default ordering from the installed library.
|
Leaving `audiodriver` empty uses the OpenAL Soft default ordering from the installed library.
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestSelectAudioDriver(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
flagDriver string
|
||||||
|
envDriver string
|
||||||
|
pulseServer string
|
||||||
|
configDriver string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{name: "defaults", want: ""},
|
||||||
|
{name: "configured driver", configDriver: " alsa ", want: "alsa"},
|
||||||
|
{name: "Pulse server", pulseServer: "tcp:127.0.0.1:4713", want: "pulse"},
|
||||||
|
{name: "Pulse server over configured driver", pulseServer: "unix:/tmp/pulse.sock", configDriver: "pipewire", want: "pulse"},
|
||||||
|
{name: "explicit environment over Pulse server", envDriver: "alsa", pulseServer: "tcp:127.0.0.1:4713", want: "alsa"},
|
||||||
|
{name: "flag over environment", flagDriver: " pipewire ", envDriver: "alsa", pulseServer: "tcp:127.0.0.1:4713", want: "pipewire"},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
got := select_audio_driver(test.flagDriver, test.envDriver, test.pulseServer, test.configDriver)
|
||||||
|
if got != test.want {
|
||||||
|
t.Errorf("select_audio_driver() = %q, want %q", got, test.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,6 +70,19 @@ func expandNotification(template string, event []string) string {
|
|||||||
).Replace(template)
|
).Replace(template)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func select_audio_driver(flagDriver, envDriver, pulseServer, configDriver string) string {
|
||||||
|
if driver := strings.TrimSpace(flagDriver); driver != "" {
|
||||||
|
return driver
|
||||||
|
}
|
||||||
|
if envDriver != "" {
|
||||||
|
return envDriver
|
||||||
|
}
|
||||||
|
if pulseServer != "" {
|
||||||
|
return "pulse"
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(configDriver)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Command line flags
|
// Command line flags
|
||||||
server := flag.String("server", "localhost:64738", "the server to connect to")
|
server := flag.String("server", "localhost:64738", "the server to connect to")
|
||||||
@@ -173,15 +186,8 @@ func main() {
|
|||||||
certificate = userConfig.GetCertificate()
|
certificate = userConfig.GetCertificate()
|
||||||
}
|
}
|
||||||
|
|
||||||
driver := strings.TrimSpace(*audioDriver)
|
driver := select_audio_driver(*audioDriver, os.Getenv("ALSOFT_DRIVERS"),
|
||||||
if driver == "" {
|
os.Getenv("PULSE_SERVER"), userConfig.GetAudioDriver())
|
||||||
// Environment variable takes precedence over config
|
|
||||||
if envDriver := os.Getenv("ALSOFT_DRIVERS"); envDriver != "" {
|
|
||||||
driver = envDriver
|
|
||||||
} else {
|
|
||||||
driver = strings.TrimSpace(userConfig.GetAudioDriver())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if driver != "" {
|
if driver != "" {
|
||||||
os.Setenv("ALSOFT_DRIVERS", driver)
|
os.Setenv("ALSOFT_DRIVERS", driver)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user