mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 06:58:56 +00:00
No point in checking if the size of the subbuffer > 0, the code handles it correclty as demonstrated by unit test.
Original commit message from CVS: * gst/gstbuffer.c: (_gst_buffer_copy), (gst_buffer_create_sub): * tests/check/gst/gstbuffer.c: (GST_START_TEST), (gst_buffer_suite): No point in checking if the size of the subbuffer > 0, the code handles it correclty as demonstrated by unit test. Also add a unit test for the zero sized _new_and_alloc and _copy. Fixes #346663.
This commit is contained in:
parent
d7c7dcc686
commit
fa9bb7929e
3 changed files with 61 additions and 4 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2006-07-05 Wim Taymans <wim@fluendo.com>
|
||||
|
||||
* gst/gstbuffer.c: (_gst_buffer_copy), (gst_buffer_create_sub):
|
||||
* tests/check/gst/gstbuffer.c: (GST_START_TEST),
|
||||
(gst_buffer_suite):
|
||||
No point in checking if the size of the subbuffer > 0, the
|
||||
code handles it correclty as demonstrated by unit test.
|
||||
Also add a unit test for the zero sized _new_and_alloc and
|
||||
_copy. Fixes #346663.
|
||||
|
||||
2006-07-05 Wim Taymans <wim@fluendo.com>
|
||||
|
||||
* libs/gst/base/gstbasetransform.c:
|
||||
|
|
|
@ -210,7 +210,7 @@ _gst_buffer_copy (GstBuffer * buffer)
|
|||
/* we simply copy everything from our parent */
|
||||
copy->data = g_memdup (buffer->data, buffer->size);
|
||||
/* make sure it gets freed (even if the parent is subclassed, we return a
|
||||
normal buffer */
|
||||
normal buffer) */
|
||||
copy->malloc_data = copy->data;
|
||||
|
||||
copy->size = buffer->size;
|
||||
|
@ -270,6 +270,8 @@ gst_buffer_new (void)
|
|||
* Creates a newly allocated buffer with data of the given size.
|
||||
* The buffer memory is not cleared.
|
||||
*
|
||||
* Note that when @size == 0, the buffer data pointer will be NULL.
|
||||
*
|
||||
* MT safe.
|
||||
* Returns: the new #GstBuffer.
|
||||
*/
|
||||
|
@ -466,7 +468,7 @@ gst_subbuffer_init (GTypeInstance * instance, gpointer g_class)
|
|||
* @parent: a #GstBuffer.
|
||||
* @offset: the offset into parent #GstBuffer at which the new sub-buffer
|
||||
* begins.
|
||||
* @size: the size of the new #GstBuffer sub-buffer, in bytes (with size > 0).
|
||||
* @size: the size of the new #GstBuffer sub-buffer, in bytes.
|
||||
*
|
||||
* Creates a sub-buffer from @parent at @offset and @size.
|
||||
* This sub-buffer uses the actual memory space of the parent buffer.
|
||||
|
@ -486,7 +488,6 @@ gst_buffer_create_sub (GstBuffer * buffer, guint offset, guint size)
|
|||
|
||||
g_return_val_if_fail (buffer != NULL, NULL);
|
||||
g_return_val_if_fail (buffer->mini_object.refcount > 0, NULL);
|
||||
g_return_val_if_fail (size > 0, NULL);
|
||||
g_return_val_if_fail (buffer->size >= offset + size, NULL);
|
||||
|
||||
/* find real parent */
|
||||
|
|
|
@ -81,6 +81,17 @@ GST_START_TEST (test_subbuffer)
|
|||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 2);
|
||||
ASSERT_BUFFER_REFCOUNT (sub, "subbuffer", 1);
|
||||
|
||||
gst_buffer_unref (sub);
|
||||
|
||||
/* create a subbuffer of size 0 */
|
||||
sub = gst_buffer_create_sub (buffer, 1, 0);
|
||||
fail_if (sub == NULL, "create_sub of buffer returned NULL");
|
||||
fail_unless (GST_BUFFER_SIZE (sub) == 0, "subbuffer has wrong size");
|
||||
fail_unless (memcmp (GST_BUFFER_DATA (buffer) + 1, GST_BUFFER_DATA (sub),
|
||||
0) == 0, "subbuffer contains the wrong data");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 2);
|
||||
ASSERT_BUFFER_REFCOUNT (sub, "subbuffer", 1);
|
||||
|
||||
/* clean up */
|
||||
gst_buffer_unref (sub);
|
||||
gst_buffer_unref (buffer);
|
||||
|
@ -186,7 +197,7 @@ GST_START_TEST (test_span)
|
|||
gst_buffer_unref (span);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
|
||||
|
||||
/* clean up */
|
||||
/* clean up */
|
||||
gst_buffer_unref (sub1);
|
||||
gst_buffer_unref (sub2);
|
||||
gst_buffer_unref (buffer);
|
||||
|
@ -321,6 +332,39 @@ GST_START_TEST (test_metadata_writable)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_copy)
|
||||
{
|
||||
GstBuffer *buffer, *copy;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
|
||||
|
||||
copy = gst_buffer_copy (buffer);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (copy, "copy", 1);
|
||||
/* data must be copied and thus point to different memory */
|
||||
fail_if (GST_BUFFER_DATA (buffer) == GST_BUFFER_DATA (copy));
|
||||
|
||||
gst_buffer_unref (copy);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
/* a 0-sized buffer has NULL data as per docs */
|
||||
buffer = gst_buffer_new_and_alloc (0);
|
||||
fail_unless (GST_BUFFER_DATA (buffer) == NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (buffer) == 0);
|
||||
|
||||
/* copying a 0-sized buffer should not crash and also set
|
||||
* the data member NULL. */
|
||||
copy = gst_buffer_copy (buffer);
|
||||
fail_unless (GST_BUFFER_DATA (copy) == NULL);
|
||||
fail_unless (GST_BUFFER_SIZE (copy) == 0);
|
||||
|
||||
gst_buffer_unref (copy);
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
gst_buffer_suite (void)
|
||||
{
|
||||
|
@ -335,6 +379,8 @@ gst_buffer_suite (void)
|
|||
tcase_add_test (tc_chain, test_is_span_fast);
|
||||
tcase_add_test (tc_chain, test_span);
|
||||
tcase_add_test (tc_chain, test_metadata_writable);
|
||||
tcase_add_test (tc_chain, test_copy);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue