Commit c83e91d8 authored by Arnaud Ferraris's avatar Arnaud Ferraris
Browse files

wys-audio: reconnect to pulseaudio if it restarts/crashes

Fixes #11
parent 2362f478
Pipeline #69721 passed with stages
in 6 minutes and 27 seconds
......@@ -51,6 +51,9 @@ enum {
};
static GParamSpec *props[PROP_LAST_PROP];
static void set_up_audio_context (WysAudio *self);
static void clean_up_audio_context (WysAudio *self);
static void
proplist_set (pa_proplist *props,
......@@ -113,8 +116,10 @@ context_notify_cb (pa_context *audio, WysAudio *self)
self->ready = FALSE;
break;
case PA_CONTEXT_FAILED:
wys_error ("Error in PulseAudio context: %s",
g_warning ("Error in PulseAudio context: %s",
pa_strerror (pa_context_errno (audio)));
clean_up_audio_context (self);
g_idle_add (G_SOURCE_FUNC (set_up_audio_context), self);
break;
case PA_CONTEXT_TERMINATED:
case PA_CONTEXT_READY:
......@@ -143,14 +148,20 @@ set_up_audio_context (WysAudio *self)
proplist_set (props, PA_PROP_APPLICATION_NAME, APPLICATION_NAME);
proplist_set (props, PA_PROP_APPLICATION_ID, APPLICATION_ID);
self->loop = pa_glib_mainloop_new (NULL);
if (!self->loop)
{
self->loop = pa_glib_mainloop_new (NULL);
}
if (!self->loop)
{
wys_error ("Error creating PulseAudio main loop");
}
self->ctx = pa_context_new_with_proplist (pa_glib_mainloop_get_api (self->loop),
APPLICATION_NAME, props);
if (!self->ctx)
{
self->ctx = pa_context_new_with_proplist (pa_glib_mainloop_get_api (self->loop),
APPLICATION_NAME, props);
}
if (!self->ctx)
{
wys_error ("Error creating PulseAudio context");
......@@ -171,11 +182,24 @@ set_up_audio_context (WysAudio *self)
g_main_context_iteration (NULL, TRUE);
}
pa_context_set_state_callback (self->ctx, NULL, NULL);
pa_proplist_free (props);
}
static void
clean_up_audio_context (WysAudio *self)
{
if (self->ctx)
{
pa_context_disconnect (self->ctx);
pa_context_unref (self->ctx);
self->ctx = NULL;
}
self->ready = FALSE;
}
static void
set_property (GObject *object,
guint property_id,
......@@ -214,17 +238,14 @@ dispose (GObject *object)
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
WysAudio *self = WYS_AUDIO (object);
if (self->ctx)
{
pa_context_disconnect (self->ctx);
pa_context_unref (self->ctx);
self->ctx = NULL;
clean_up_audio_context (self);
if (self->loop)
{
pa_glib_mainloop_free (self->loop);
self->loop = NULL;
}
parent_class->dispose (object);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment