gstbuffer: reset buffer to its original size if intact
authorPetr Kulhavy <brain@jikos.cz>
Mon, 14 Nov 2016 14:35:50 +0000 (15:35 +0100)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 21 Mar 2018 21:50:30 +0000 (17:50 -0400)
Enhance default_reset_buffer() to resize the buffer to its full size if the
memory hasn't changed. This allows to reuse the buffer even if the offset has
changed or the size has shrunk, rather than freeing the buffer.

Change related to: https://bugzilla.gnome.org/show_bug.cgi?id=772841

gst/gstbufferpool.c

index 3d91236..6db0f5d 100644 (file)
@@ -1226,6 +1226,10 @@ default_reset_buffer (GstBufferPool * pool, GstBuffer * buffer)
   GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
   GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
 
+  /* if the memory is intact reset the size to the full size */
+  if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY))
+    gst_buffer_resize (buffer, 0, pool->priv->size);
+
   /* remove all metadata without the POOLED flag */
   gst_buffer_foreach_meta (buffer, remove_meta_unpooled, pool);
 }