gst: sink: post an element error when all buffers are removed abruptly

When the link on the pipewire side is destroyed, on video streams, buffers
are removed abruptly and there is no way this pipeline can be revived,
so let's post an element error to stop it.

On a normal shutdown, the pool is first set to flushing in change_state(),
so checking for the flushing state is a good indicator to know if this
is a normal shutdown or not.

See #1980
This commit is contained in:
George Kiagiadakis 2024-05-28 17:34:45 +03:00
parent ef5f5d4c3c
commit 68711290bd
3 changed files with 18 additions and 0 deletions

View file

@ -117,6 +117,8 @@ void gst_pipewire_pool_wrap_buffer (GstPipeWirePool *pool, struct pw_buffer *b)
data,
pool_data_destroy);
b->user_data = data;
pool->n_buffers++;
}
void gst_pipewire_pool_remove_buffer (GstPipeWirePool *pool, struct pw_buffer *b)
@ -132,6 +134,8 @@ void gst_pipewire_pool_remove_buffer (GstPipeWirePool *pool, struct pw_buffer *b
/* this will also destroy the pool data, if this is the last reference */
gst_clear_buffer (&data->buf);
pool->n_buffers--;
}
GstPipeWirePoolData *gst_pipewire_pool_get_data (GstBuffer *buffer)

View file

@ -46,6 +46,7 @@ struct _GstPipeWirePool {
GstBufferPool parent;
struct pw_stream *stream;
guint n_buffers;
gboolean add_metavideo;
GstVideoInfo video_info;
@ -67,6 +68,12 @@ GstPipeWirePool * gst_pipewire_pool_new (void);
void gst_pipewire_pool_wrap_buffer (GstPipeWirePool *pool, struct pw_buffer *buffer);
void gst_pipewire_pool_remove_buffer (GstPipeWirePool *pool, struct pw_buffer *buffer);
static inline gboolean
gst_pipewire_pool_has_buffers (GstPipeWirePool *pool)
{
return pool->n_buffers > 0;
}
GstPipeWirePoolData *gst_pipewire_pool_get_data (GstBuffer *buffer);
G_END_DECLS

View file

@ -475,6 +475,13 @@ on_remove_buffer (void *_data, struct pw_buffer *b)
GstPipeWireSink *pwsink = _data;
GST_DEBUG_OBJECT (pwsink, "remove pw_buffer %p", b);
gst_pipewire_pool_remove_buffer (pwsink->pool, b);
if (!gst_pipewire_pool_has_buffers (pwsink->pool) &&
!GST_BUFFER_POOL_IS_FLUSHING (GST_BUFFER_POOL_CAST (pwsink->pool))) {
GST_ELEMENT_ERROR (pwsink, RESOURCE, NOT_FOUND,
("all buffers have been removed"),
("PipeWire link to remote node was destroyed"));
}
}
static void