From 629f824b91fb2c6024423efdd583576e96c35bd6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 18 Jul 2017 15:28:14 +0200 Subject: [PATCH] pipewiresrc: improve remote connection errors --- src/gst/gstpipewiresrc.c | 3 +++ src/modules/module-client-node.c | 8 ------- src/modules/module-protocol-native.c | 6 ++++-- src/pipewire/remote.c | 31 +++++++++++++++------------- src/pipewire/remote.h | 3 +++ 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index aef9a8da6..6705dd4cf 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -895,6 +895,9 @@ gst_pipewire_src_create (GstPushSrc * psrc, GstBuffer ** buffer) if (pwsrc->flushing) goto streaming_stopped; + if (pwsrc->stream == NULL) + goto streaming_error; + state = pwsrc->stream->state; if (state == PW_STREAM_STATE_ERROR) goto streaming_error; diff --git a/src/modules/module-client-node.c b/src/modules/module-client-node.c index 571f771aa..dfe257fce 100644 --- a/src/modules/module-client-node.c +++ b/src/modules/module-client-node.c @@ -44,14 +44,6 @@ static struct pw_node *create_node(struct pw_node_factory *factory, { struct pw_client_node *node; - if (properties == NULL) - properties = pw_properties_new(NULL, NULL); - if (properties == NULL) - goto no_mem; - - pw_properties_setf(properties, - "pipewire.owner.client", "%d", resource->client->global->id); - node = pw_client_node_new(resource, name, properties); if (node == NULL) goto no_mem; diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 4331aca35..c3c058702 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -428,8 +428,10 @@ on_remote_data(struct spa_loop_utils *utils, if (mask & (SPA_IO_ERR | SPA_IO_HUP)) { pw_log_error("protocol-native %p: got connection error", impl); - pw_remote_destroy(this); - return; + pw_loop_destroy_source(this->core->main_loop, impl->source); + impl->source = NULL; + pw_remote_update_state(this, PW_REMOTE_STATE_ERROR, "connection error"); + return; } if (mask & SPA_IO_IN) { diff --git a/src/pipewire/remote.c b/src/pipewire/remote.c index 90f44bd95..53e545e70 100644 --- a/src/pipewire/remote.c +++ b/src/pipewire/remote.c @@ -56,8 +56,8 @@ const char *pw_remote_state_as_string(enum pw_remote_state state) return "invalid-state"; } -static void -remote_update_state(struct pw_remote *remote, enum pw_remote_state state, const char *fmt, ...) +void +pw_remote_update_state(struct pw_remote *remote, enum pw_remote_state state, const char *fmt, ...) { if (remote->state != state) { if (remote->error) @@ -101,7 +101,7 @@ static void core_event_done(void *object, uint32_t seq) pw_log_debug("core event done %d", seq); if (seq == 0) - remote_update_state(this, PW_REMOTE_STATE_CONNECTED, NULL); + pw_remote_update_state(this, PW_REMOTE_STATE_CONNECTED, NULL); pw_signal_emit(&this->sync_reply, this, seq); } @@ -110,7 +110,7 @@ static void core_event_error(void *object, uint32_t id, int res, const char *err { struct pw_proxy *proxy = object; struct pw_remote *this = proxy->object; - remote_update_state(this, PW_REMOTE_STATE_ERROR, error); + pw_remote_update_state(this, PW_REMOTE_STATE_ERROR, error); } static void core_event_remove_id(void *object, uint32_t id) @@ -211,6 +211,7 @@ struct pw_remote *pw_remote_new(struct pw_core *core, void pw_remote_destroy(struct pw_remote *remote) { struct remote *impl = SPA_CONTAINER_OF(remote, struct remote, this); + struct pw_stream *stream, *s2; pw_log_debug("remote %p: destroy", remote); pw_signal_emit(&remote->destroy_signal, remote); @@ -218,6 +219,9 @@ void pw_remote_destroy(struct pw_remote *remote) if (remote->state != PW_REMOTE_STATE_UNCONNECTED) pw_remote_disconnect(remote); + spa_list_for_each_safe(stream, s2, &remote->stream_list, link) + pw_stream_destroy(stream); + pw_protocol_connection_destroy (remote->conn); spa_list_remove(&remote->link); @@ -243,7 +247,7 @@ static int do_connect(struct pw_remote *remote) no_proxy: pw_protocol_connection_disconnect (remote->conn); - remote_update_state(remote, PW_REMOTE_STATE_ERROR, "can't connect: no memory"); + pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR, "can't connect: no memory"); return -1; } @@ -251,10 +255,10 @@ int pw_remote_connect(struct pw_remote *remote) { int res; - remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL); + pw_remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL); if ((res = pw_protocol_connection_connect (remote->conn)) < 0) { - remote_update_state(remote, PW_REMOTE_STATE_ERROR, "connect failed"); + pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR, "connect failed"); return res; } @@ -265,10 +269,10 @@ int pw_remote_connect_fd(struct pw_remote *remote, int fd) { int res; - remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL); + pw_remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL); if ((res = pw_protocol_connection_connect_fd (remote->conn, fd)) < 0) { - remote_update_state(remote, PW_REMOTE_STATE_ERROR, "connect_fd failed"); + pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR, "connect_fd failed"); return res; } @@ -281,14 +285,13 @@ void pw_remote_disconnect(struct pw_remote *remote) struct pw_stream *stream, *s2; pw_log_debug("remote %p: disconnect", remote); - pw_protocol_connection_disconnect (remote->conn); - spa_list_for_each_safe(stream, s2, &remote->stream_list, link) - pw_stream_destroy(stream); + pw_stream_disconnect(stream); + + pw_protocol_connection_disconnect (remote->conn); spa_list_for_each_safe(proxy, t2, &remote->proxy_list, link) pw_proxy_destroy(proxy); - remote->core_proxy = NULL; pw_map_clear(&remote->objects); @@ -300,5 +303,5 @@ void pw_remote_disconnect(struct pw_remote *remote) remote->info = NULL; } - remote_update_state(remote, PW_REMOTE_STATE_UNCONNECTED, NULL); + pw_remote_update_state(remote, PW_REMOTE_STATE_UNCONNECTED, NULL); } diff --git a/src/pipewire/remote.h b/src/pipewire/remote.h index dad2a062d..b3b087e2e 100644 --- a/src/pipewire/remote.h +++ b/src/pipewire/remote.h @@ -170,6 +170,9 @@ int pw_remote_connect_fd(struct pw_remote *remote, int fd); /** Disconnect from the remote PipeWire. \memberof pw_remote */ void pw_remote_disconnect(struct pw_remote *remote); +/** Update the state of the remote, mostly used by protocols */ +void pw_remote_update_state(struct pw_remote *remote, enum pw_remote_state state, const char *fmt, ...); + #ifdef __cplusplus } #endif