v4l2: fix the critical log when unreference the buffer with no data
authorElliot Chen <elliot.chen@nxp.com>
Fri, 8 Jul 2022 10:22:58 +0000 (18:22 +0800)
committerElliot Chen <elliot.chen@nxp.com>
Mon, 25 Jul 2022 08:44:05 +0000 (16:44 +0800)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2731>

subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c

index a1dc9a0..b0305a7 100644 (file)
@@ -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);