bufferpool: Fix the buffer size reset code
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Sat, 29 Jun 2019 13:22:05 +0000 (09:22 -0400)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 8 Aug 2019 17:49:40 +0000 (18:49 +0100)
The offset in gst_buffer_resize() is additive. So to move back the
offset to zero, we need to pass the opposite of the current offset. This
was raised through the related unit test failingon 32bit as on 64bit
the alignment padding was enough to hide the issue. The test was
modified to also fail on 64bit. This patch will remove spurious
assertions like:

  assertion 'bufmax >= bufoffs + offset + size' failed

Fixes #316

gst/gstbufferpool.c
tests/check/gst/gstbufferpool.c

index e5c7a5872ab7d0c81a7772b1c95d306714f792c0..619860e63ffa976251329ce89a86bcade364c5d3 100644 (file)
@@ -1222,8 +1222,11 @@ default_reset_buffer (GstBufferPool * pool, GstBuffer * buffer)
   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);
+  if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY)) {
+    gsize offset;
+    gst_buffer_get_sizes (buffer, &offset, NULL);
+    gst_buffer_resize (buffer, -offset, pool->priv->size);
+  }
 
   /* remove all metadata without the POOLED flag */
   gst_buffer_foreach_meta (buffer, remove_meta_unpooled, pool);
index f0c3c8d8e725ba48ef79eb7437fc6ed1fdfb57d1..dd9b2dc033099426ed5ee9626827fb9577acbce2 100644 (file)
@@ -190,7 +190,7 @@ GST_START_TEST (test_buffer_modify_discard)
   gst_buffer_pool_acquire_buffer (pool, &buf, NULL);
   buffer_track_destroy (buf, &dcount);
   /* do resize, as we didn't modify the memory, pool should reuse this buffer */
-  gst_buffer_resize (buf, 5, 2);
+  gst_buffer_resize (buf, 8, 2);
   gst_buffer_unref (buf);
 
   /* buffer should've gone back into pool */