From 76fbc7949498392b002bd38bb43b0f155819bcde Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 25 Jul 2023 12:19:22 -0400 Subject: [PATCH] v4l2: bufferpool: Keep processing bitstream buffer Bitstream buffers may no fit a single v4l2 buffer, following spec recommendation, keep processing the buffer until all the data has been queued. Part-of: --- .../sys/v4l2/gstv4l2bufferpool.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c index 58d06cb163..fd3499e267 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c @@ -2048,6 +2048,8 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf, GstV4l2MemoryGroup *group; gint index; gboolean outstanding; + gsize queued_size = 0; + gsize remaining_size = 0; if ((*buf)->pool != bpool) goto copying; @@ -2121,6 +2123,13 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf, goto start_failed; } + /* Save the amount of data that has been submitted for encoded data */ + if (GST_VIDEO_INFO_FORMAT (&pool->caps_info) == + GST_VIDEO_FORMAT_ENCODED) { + queued_size = gst_buffer_get_size (to_queue); + remaining_size = gst_buffer_get_size (*buf) - queued_size; + } + /* Remove our ref, we will still hold this buffer in acquire as needed, * otherwise the pool will think it is outstanding and will refuse to stop. */ gst_buffer_unref (to_queue); @@ -2144,6 +2153,14 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf, gst_v4l2_buffer_pool_complete_release_buffer (bpool, buffer, FALSE); } + + /* For encoded data, just queue de remaining in the next available + * buffer. */ + if (remaining_size) { + *buf = gst_buffer_make_writable (*buf); + gst_buffer_resize (*buf, queued_size, -1); + return gst_v4l2_buffer_pool_process (pool, buf, frame_number); + } break; } default: