From f202b5d2e9157aaed1457d7932020ec4710a4189 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Tue, 20 Sep 2016 22:17:29 +0200 Subject: [PATCH] [pulseaudio] Try to spawn Pulseaudio if it doesn't by itself Requiring the user to set up Pulseaudio in system mode is not optimal. This would, however, be required especially on headless systems. This is the sledgehammer alternative to starting Pulseaudio. --- src/outputs/pulse.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/outputs/pulse.c b/src/outputs/pulse.c index 9e3d0182..acee452a 100644 --- a/src/outputs/pulse.c +++ b/src/outputs/pulse.c @@ -806,7 +806,26 @@ pulse_init(void) if (pa_context_connect(p->context, NULL, 0, NULL) < 0) { ret = pa_context_errno(p->context); - goto fail; + if (ret == PA_ERR_CONNECTIONREFUSED) + { + DPRINTF(E_LOG, L_LAUDIO, "Connection to Pulseaudio refused, trying to start daemon for our user\n"); + + ret = system("pulseaudio --start"); + if (ret < 0) + { + DPRINTF(E_LOG, L_LAUDIO, "Could not start Pulseaudio\n"); + return -1; + } + } + + // Try connecting again + if (pa_context_connect(p->context, NULL, 0, NULL) < 0) + { + ret = pa_context_errno(p->context); + goto fail; + } + + DPRINTF(E_LOG, L_LAUDIO, "Connection to Pulseaudio established\n"); } pa_threaded_mainloop_lock(p->mainloop);