From 52c14e2378f8dd9fd067f31900b1390220da940b Mon Sep 17 00:00:00 2001 From: Michael Tretter Date: Tue, 5 May 2020 13:07:12 +0200 Subject: [PATCH] gst: keep track of queued buffers Pipewire might update buffers that have not been recycled by GStreamer, because they are still used downstream. There is nothing we can do about it in the pipewiresrc. If a buffer is sent downstream more than once, take an additional reference to make sure that we don't queue a buffer that is still used and print a warning. --- src/gst/gstpipewirepool.h | 1 + src/gst/gstpipewiresrc.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/gst/gstpipewirepool.h b/src/gst/gstpipewirepool.h index bdb272ab0..eb3d8d16e 100644 --- a/src/gst/gstpipewirepool.h +++ b/src/gst/gstpipewirepool.h @@ -56,6 +56,7 @@ struct _GstPipeWirePoolData { goffset offset; struct pw_buffer *b; GstBuffer *buf; + gboolean queued; }; struct _GstPipeWirePool { diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index 13f14d455..74cb7b367 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -373,6 +373,7 @@ buffer_recycle (GstMiniObject *obj) GST_BUFFER_FLAGS (obj) = data->flags; src = data->owner; + data->queued = TRUE; GST_LOG_OBJECT (obj, "recycle buffer"); pw_thread_loop_lock (src->loop); @@ -392,6 +393,7 @@ on_add_buffer (void *_data, struct pw_buffer *b) gst_pipewire_pool_wrap_buffer (pwsrc->pool, b); data = b->user_data; data->owner = pwsrc; + data->queued = TRUE; GST_MINI_OBJECT_CAST (data->buf)->dispose = buffer_recycle; } @@ -426,6 +428,11 @@ static GstBuffer *dequeue_buffer(GstPipeWireSrc *pwsrc) GST_LOG_OBJECT (pwsrc, "got new buffer %p", buf); + if (!data->queued) { + GST_WARNING_OBJECT (pwsrc, "buffer %p was not recycled", buf); + gst_buffer_ref (buf); + } + data->queued = FALSE; GST_BUFFER_PTS (buf) = GST_CLOCK_TIME_NONE; GST_BUFFER_DTS (buf) = GST_CLOCK_TIME_NONE;