From e0564b04c6cd08e62904903992b4de4cb50bb4b7 Mon Sep 17 00:00:00 2001 From: Elliot Chen Date: Fri, 8 Jul 2022 18:22:58 +0800 Subject: [PATCH] v4l2: fix the critical log when unreference the buffer with no data In the trick mode, driver may queue a valid buffer follow by an empty buffer which has no valid data to indicate EOS.For the empty buffer whose memory is multi-plane, need to resize it before unreference it. Part-of: --- .../gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c index a1dc9a0..b0305a7 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c @@ -121,6 +121,19 @@ done: return valid; } +static void +gst_v4l2_buffer_pool_resize_buffer (GstBufferPool * bpool, GstBuffer * buffer) +{ + GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); + GstV4l2MemoryGroup *group; + + if (gst_v4l2_is_buffer_valid (buffer, &group)) { + gst_v4l2_allocator_reset_group (pool->vallocator, group); + } else { + GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY); + } +} + static GstFlowReturn gst_v4l2_buffer_pool_copy_buffer (GstV4l2BufferPool * pool, GstBuffer * dest, GstBuffer * src) @@ -1971,8 +1984,10 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf, gsize size = gst_buffer_get_size (*buf); /* Legacy M2M devices return empty buffer when drained */ - if (size == 0 && GST_V4L2_IS_M2M (obj->device_caps)) + if (size == 0 && GST_V4L2_IS_M2M (obj->device_caps)) { + gst_v4l2_buffer_pool_resize_buffer (bpool, *buf); goto eos; + } if (GST_VIDEO_INFO_FORMAT (&pool->caps_info) != GST_VIDEO_FORMAT_ENCODED && size < pool->size) @@ -2026,8 +2041,10 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf, gst_v4l2_buffer_pool_complete_release_buffer (bpool, tmp, FALSE); /* Legacy M2M devices return empty buffer when drained */ - if (GST_V4L2_IS_M2M (obj->device_caps)) + if (GST_V4L2_IS_M2M (obj->device_caps)) { + gst_v4l2_buffer_pool_resize_buffer (bpool, *buf); goto eos; + } } ret = gst_v4l2_buffer_pool_copy_buffer (pool, *buf, tmp); -- 2.7.4