From 5ba2563820c0104d9591821c56335e12042ce221 Mon Sep 17 00:00:00 2001 From: Hou Qi Date: Tue, 9 Apr 2024 11:29:46 +0900 Subject: [PATCH] v4l2bufferpool: queue back the buffer flagged LAST but empty Some decoder drivers need to wait enough capture buffers before starting to decode. But the dequeued buffer flag LAST but empty has no chance to queue back to driver, which makes decode hang after seek. So need to queue back such kind of buffer to driver. Part-of: --- .../sys/v4l2/gstv4l2bufferpool.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c index 49e6a5de3e..67036dcdd4 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c @@ -1238,6 +1238,7 @@ static GstFlowReturn gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer, gboolean * outstanding, gboolean wait) { + GstBufferPool *bpool = GST_BUFFER_POOL_CAST (pool); GstFlowReturn res; GstBuffer *outbuf = NULL; GstV4l2Object *obj = pool->obj; @@ -1281,12 +1282,6 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer, group->buffer.index); } - if (group->buffer.flags & V4L2_BUF_FLAG_LAST && - group->planes[0].bytesused == 0) { - GST_DEBUG_OBJECT (pool, "Empty last buffer, signalling eos."); - goto eos; - } - outbuf = pool->buffers[group->buffer.index]; if (outbuf == NULL) goto no_buffer; @@ -1298,6 +1293,16 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer, GST_OBJECT_UNLOCK (pool); } + if (group->buffer.flags & V4L2_BUF_FLAG_LAST && + group->planes[0].bytesused == 0) { + GST_DEBUG_OBJECT (pool, "Empty last buffer, signalling eos."); + *buffer = outbuf; + outbuf = NULL; + gst_buffer_ref (*buffer); + gst_v4l2_buffer_pool_complete_release_buffer (bpool, *buffer, FALSE); + goto eos; + } + timestamp = GST_TIMEVAL_TO_TIME (group->buffer.timestamp); for (i = 0; i < group->n_mem; i++) {