gst: do a sync before disconnect

This makes sure we first nicely remove the stream from the server
and then close the socket.

If we don't do this, the disconnect might not have flushed out our
disconnect and the server is left with a non-responsive node,
especially if the disconnect on the core was done with a socket from
the portal that is still open.
This commit is contained in:
Wim Taymans 2020-05-21 12:22:48 +02:00
parent 48dea3d5ea
commit 6eba010d38
4 changed files with 81 additions and 12 deletions

View file

@ -689,6 +689,30 @@ gst_pipewire_sink_stop (GstBaseSink * basesink)
return TRUE;
}
static void on_core_done (void *object, uint32_t id, int seq)
{
GstPipeWireSink * pwsink = object;
if (id == PW_ID_CORE) {
pwsink->last_seq = seq;
pw_thread_loop_signal (pwsink->loop, FALSE);
}
}
static const struct pw_core_events core_events = {
PW_VERSION_CORE_EVENTS,
.done = on_core_done,
};
static void do_sync(GstPipeWireSink * pwsink)
{
pwsink->pending_seq = pw_core_sync(pwsink->core, 0, pwsink->pending_seq);
while (true) {
if (pwsink->last_seq == pwsink->pending_seq || pwsink->last_error < 0)
break;
pw_thread_loop_wait (pwsink->loop);
}
}
static gboolean
gst_pipewire_sink_open (GstPipeWireSink * pwsink)
{
@ -705,6 +729,11 @@ gst_pipewire_sink_open (GstPipeWireSink * pwsink)
if (pwsink->core == NULL)
goto connect_error;
pw_core_add_listener(pwsink->core,
&pwsink->core_listener,
&core_events,
pwsink);
pw_thread_loop_unlock (pwsink->loop);
return TRUE;
@ -730,9 +759,11 @@ gst_pipewire_sink_close (GstPipeWireSink * pwsink)
{
pw_thread_loop_lock (pwsink->loop);
if (pwsink->stream) {
pw_stream_disconnect (pwsink->stream);
pw_stream_destroy (pwsink->stream);
pwsink->stream = NULL;
}
if (pwsink->core) {
do_sync(pwsink);
pw_core_disconnect (pwsink->core);
pwsink->core = NULL;
}
@ -740,10 +771,6 @@ gst_pipewire_sink_close (GstPipeWireSink * pwsink)
pw_thread_loop_stop (pwsink->loop);
if (pwsink->stream) {
pw_stream_destroy (pwsink->stream);
pwsink->stream = NULL;
}
return TRUE;
}