context: improve cleanup

This commit is contained in:
Wim Taymans 2018-12-14 16:43:34 +01:00
parent 21c11e70fb
commit 41513f11f3
2 changed files with 49 additions and 5 deletions

View file

@ -459,6 +459,8 @@ static void context_free(pa_context *c)
if (c->proplist) if (c->proplist)
pa_proplist_free(c->proplist); pa_proplist_free(c->proplist);
pw_remote_destroy(c->remote);
} }
void pa_context_unref(pa_context *c) void pa_context_unref(pa_context *c)

View file

@ -210,13 +210,20 @@ static void stream_state_changed(void *data, enum pw_stream_state old,
{ {
pa_stream *s = data; pa_stream *s = data;
pw_log_debug("stream %p: state '%s'->'%s'", s, pw_stream_state_as_string(old),
pw_stream_state_as_string(state));
switch(state) { switch(state) {
case PW_STREAM_STATE_ERROR: case PW_STREAM_STATE_ERROR:
pa_stream_set_state(s, PA_STREAM_FAILED); pa_stream_set_state(s, PA_STREAM_FAILED);
break; break;
case PW_STREAM_STATE_UNCONNECTED: case PW_STREAM_STATE_UNCONNECTED:
if (!s->disconnecting) if (!s->disconnecting) {
pa_stream_set_state(s, PA_STREAM_UNCONNECTED); pa_context_set_error(s->context, PA_ERR_KILLED);
pa_stream_set_state(s, PA_STREAM_FAILED);
} else {
pa_stream_set_state(s, PA_STREAM_TERMINATED);
}
break; break;
case PW_STREAM_STATE_CONNECTING: case PW_STREAM_STATE_CONNECTING:
pa_stream_set_state(s, PA_STREAM_CREATING); pa_stream_set_state(s, PA_STREAM_CREATING);
@ -225,9 +232,21 @@ static void stream_state_changed(void *data, enum pw_stream_state old,
case PW_STREAM_STATE_READY: case PW_STREAM_STATE_READY:
break; break;
case PW_STREAM_STATE_PAUSED: case PW_STREAM_STATE_PAUSED:
if (old < PW_STREAM_STATE_PAUSED) {
if (s->suspended && s->suspended_callback) {
s->suspended = false;
s->suspended_callback(s, s->suspended_userdata);
}
configure_device(s); configure_device(s);
configure_buffers(s); configure_buffers(s);
pa_stream_set_state(s, PA_STREAM_READY); pa_stream_set_state(s, PA_STREAM_READY);
}
else {
if (!s->suspended && s->suspended_callback) {
s->suspended = true;
s->suspended_callback(s, s->suspended_userdata);
}
}
break; break;
case PW_STREAM_STATE_STREAMING: case PW_STREAM_STATE_STREAMING:
break; break;
@ -596,13 +615,36 @@ pa_stream *pa_stream_new_extended(pa_context *c, const char *name,
static void stream_unlink(pa_stream *s) static void stream_unlink(pa_stream *s)
{ {
pa_context *c = s->context;
pa_operation *o, *t;
if (c == NULL)
return;
pw_log_debug("stream %p: unlink %d", s, s->refcount);
spa_list_for_each_safe(o, t, &c->operations, link) {
if (o->stream == s)
pa_operation_cancel(o);
}
spa_list_remove(&s->link); spa_list_remove(&s->link);
s->context = NULL;
pa_stream_unref(s);
} }
static void stream_free(pa_stream *s) static void stream_free(pa_stream *s)
{ {
int i; int i;
pw_log_debug("stream %p", s);
if (s->stream) {
spa_hook_remove(&s->stream_listener);
pw_stream_destroy(s->stream);
}
if (s->proplist) if (s->proplist)
pa_proplist_free(s->proplist); pa_proplist_free(s->proplist);