From b8a2adb4ec6d1b7b525599dd5d0767c4e74aa408 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 26 Aug 2015 17:09:55 -0700 Subject: [PATCH] PulseAudio: detect server going offline --- README.md | 2 +- src/pulseaudio.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 97ce8de..f1dec63 100644 --- a/README.md +++ b/README.md @@ -272,10 +272,10 @@ Then look at `html/index.html` in a browser. ## Roadmap - 0. Detect PulseAudio server going offline and emit `on_backend_disconnect`. 0. Ability to "activate" a buffer-flexible outstream by jumping the gun and causing `write_callback` to be called early. - Use the same mechanism when destroying the outstream + 0. Create a test for recovering from backend disconnecting that reconnects 0. Create a test for input stream overflow handling. 0. Create a test for the latency / synchronization API. - Input is an audio file and some events indexed at particular frame - when diff --git a/src/pulseaudio.cpp b/src/pulseaudio.cpp index db23d64..1d7add9 100644 --- a/src/pulseaudio.cpp +++ b/src/pulseaudio.cpp @@ -36,6 +36,7 @@ static int subscribe_to_events(SoundIoPrivate *si) { static void context_state_callback(pa_context *context, void *userdata) { SoundIoPrivate *si = (SoundIoPrivate *)userdata; SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; + SoundIo *soundio = &si->pub; switch (pa_context_get_state(context)) { case PA_CONTEXT_UNCONNECTED: // The context hasn't been connected yet. @@ -55,7 +56,9 @@ static void context_state_callback(pa_context *context, void *userdata) { return; case PA_CONTEXT_FAILED: // The connection failed or was disconnected. sipa->connection_err = SoundIoErrorInitAudioBackend; - sipa->ready_flag = true; + if (sipa->ready_flag.exchange(true)) { + soundio->on_backend_disconnect(soundio, SoundIoErrorBackendDisconnected); + } pa_threaded_mainloop_signal(sipa->main_loop, 0); return; }