2009-05-12 10:08:56 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* unit test for GstBufferList
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Axis Communications <dev-gstreamer at axis dot com>
|
|
|
|
* @author Jonas Holmberg <jonas dot holmberg at axis dot com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-05-12 10:08:56 +00:00
|
|
|
*/
|
2017-11-24 12:41:20 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2009-05-12 10:08:56 +00:00
|
|
|
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
#include <gst/gstbufferlist.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static GstBufferList *list;
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup (void)
|
|
|
|
{
|
|
|
|
list = gst_buffer_list_new ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup (void)
|
|
|
|
{
|
|
|
|
gst_buffer_list_unref (list);
|
2014-06-17 13:39:00 +00:00
|
|
|
list = NULL;
|
2009-05-12 10:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_add_and_iterate)
|
|
|
|
{
|
|
|
|
GstBuffer *buf1;
|
|
|
|
GstBuffer *buf2;
|
|
|
|
|
|
|
|
/* buffer list is initially empty */
|
2011-10-29 06:24:12 +00:00
|
|
|
fail_unless (gst_buffer_list_length (list) == 0);
|
2009-05-12 10:08:56 +00:00
|
|
|
|
2011-03-31 15:51:02 +00:00
|
|
|
ASSERT_CRITICAL (gst_buffer_list_insert (list, 0, NULL));
|
|
|
|
ASSERT_CRITICAL (gst_buffer_list_insert (NULL, 0, NULL));
|
2009-05-12 10:08:56 +00:00
|
|
|
|
|
|
|
buf1 = gst_buffer_new ();
|
|
|
|
|
|
|
|
/* add a group of 2 buffers */
|
2011-10-29 06:24:12 +00:00
|
|
|
fail_unless (gst_buffer_list_length (list) == 0);
|
2011-03-31 15:51:02 +00:00
|
|
|
ASSERT_CRITICAL (gst_buffer_list_insert (list, -1, NULL));
|
2009-05-12 10:08:56 +00:00
|
|
|
ASSERT_BUFFER_REFCOUNT (buf1, "buf1", 1);
|
2011-03-31 15:51:02 +00:00
|
|
|
gst_buffer_list_add (list, buf1);
|
2009-05-12 10:08:56 +00:00
|
|
|
ASSERT_BUFFER_REFCOUNT (buf1, "buf1", 1); /* list takes ownership */
|
2011-10-29 06:24:12 +00:00
|
|
|
fail_unless (gst_buffer_list_length (list) == 1);
|
2009-05-12 10:08:56 +00:00
|
|
|
buf2 = gst_buffer_new ();
|
2011-03-31 15:51:02 +00:00
|
|
|
gst_buffer_list_add (list, buf2);
|
2009-05-12 10:08:56 +00:00
|
|
|
ASSERT_BUFFER_REFCOUNT (buf2, "buf2", 1);
|
2011-10-29 06:24:12 +00:00
|
|
|
fail_unless (gst_buffer_list_length (list) == 2);
|
2009-05-12 10:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2014-06-16 19:30:13 +00:00
|
|
|
GST_START_TEST (test_remove)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
/* buffer list is initially empty */
|
|
|
|
fail_unless (gst_buffer_list_length (list) == 0);
|
|
|
|
|
|
|
|
buf = gst_buffer_new ();
|
|
|
|
|
|
|
|
/* add our own ref so it stays alive after removal from the list */
|
|
|
|
buf = gst_buffer_ref (buf);
|
|
|
|
|
|
|
|
/* add a buffer */
|
|
|
|
fail_unless (gst_buffer_list_length (list) == 0);
|
|
|
|
ASSERT_CRITICAL (gst_buffer_list_insert (list, -1, NULL));
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf, "buf", 2);
|
|
|
|
gst_buffer_list_add (list, buf);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf, "buf", 2); /* list takes ownership */
|
|
|
|
fail_unless (gst_buffer_list_length (list) == 1);
|
|
|
|
gst_buffer_list_remove (list, 0, 1);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
fail_unless (gst_buffer_list_length (list) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2009-05-12 10:08:56 +00:00
|
|
|
GST_START_TEST (test_make_writable)
|
|
|
|
{
|
|
|
|
GstBufferList *wlist;
|
|
|
|
GstBuffer *buf1;
|
|
|
|
GstBuffer *buf2;
|
|
|
|
GstBuffer *buf3;
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
/* add buffers to list */
|
2014-06-26 12:24:08 +00:00
|
|
|
buf1 = gst_buffer_new_allocate (NULL, 1, NULL);
|
|
|
|
gst_buffer_list_add (list, buf1);
|
|
|
|
|
|
|
|
buf2 = gst_buffer_new_allocate (NULL, 2, NULL);
|
|
|
|
buf3 = gst_buffer_new_allocate (NULL, 3, NULL);
|
|
|
|
gst_buffer_list_add (list, gst_buffer_append (buf2, buf3));
|
2009-05-12 10:08:56 +00:00
|
|
|
|
|
|
|
/* making it writable with refcount 1 returns the same list */
|
|
|
|
wlist = gst_buffer_list_make_writable (list);
|
|
|
|
fail_unless (wlist == list);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (gst_buffer_list_length (list), 2);
|
|
|
|
buf = gst_buffer_list_get (list, 0);
|
2009-05-12 10:08:56 +00:00
|
|
|
fail_unless (buf == buf1);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf1, "buf1", 1);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (gst_buffer_get_size (buf), 1);
|
|
|
|
buf = gst_buffer_list_get (list, 1);
|
2009-05-12 10:08:56 +00:00
|
|
|
fail_unless (buf == buf2);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf2, "buf2", 1);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (gst_buffer_n_memory (buf), 2);
|
2009-05-12 10:08:56 +00:00
|
|
|
|
|
|
|
/* making it writable with refcount 2 returns a copy of the list with
|
|
|
|
* increased refcount on the buffers in the list */
|
|
|
|
gst_buffer_list_ref (list);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (list), 2);
|
2009-05-12 10:08:56 +00:00
|
|
|
wlist = gst_buffer_list_make_writable (list);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (list), 1);
|
|
|
|
fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (wlist), 1);
|
2009-05-12 10:08:56 +00:00
|
|
|
fail_unless (wlist != list);
|
2014-06-26 12:24:08 +00:00
|
|
|
/* check list */
|
|
|
|
fail_unless_equals_int (gst_buffer_list_length (list), 2);
|
|
|
|
buf = gst_buffer_list_get (list, 0);
|
|
|
|
fail_unless (buf == buf1);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf1, "buf1", 2);
|
|
|
|
fail_unless_equals_int (gst_buffer_get_size (buf), 1);
|
|
|
|
buf = gst_buffer_list_get (list, 1);
|
|
|
|
fail_unless (buf == buf2);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf2, "buf2", 2);
|
|
|
|
fail_unless_equals_int (gst_buffer_n_memory (buf), 2);
|
|
|
|
/* check wlist */
|
|
|
|
fail_unless_equals_int (gst_buffer_list_length (wlist), 2);
|
|
|
|
buf = gst_buffer_list_get (wlist, 0);
|
2009-05-12 10:08:56 +00:00
|
|
|
fail_unless (buf == buf1);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf1, "buf1", 2);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (gst_buffer_get_size (buf), 1);
|
|
|
|
buf = gst_buffer_list_get (wlist, 1);
|
2009-05-12 10:08:56 +00:00
|
|
|
fail_unless (buf == buf2);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf2, "buf2", 2);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (gst_buffer_n_memory (buf), 2);
|
2009-05-12 10:08:56 +00:00
|
|
|
gst_buffer_list_unref (wlist);
|
2014-06-26 12:24:08 +00:00
|
|
|
/* list will be unrefed in cleanup hook */
|
2009-05-12 10:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_copy)
|
|
|
|
{
|
|
|
|
GstBufferList *list_copy;
|
|
|
|
GstBuffer *buf1;
|
|
|
|
GstBuffer *buf2;
|
|
|
|
GstBuffer *buf3;
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
/* add buffers to the list */
|
2014-06-26 12:24:08 +00:00
|
|
|
buf1 = gst_buffer_new_allocate (NULL, 1, NULL);
|
|
|
|
gst_buffer_list_add (list, buf1);
|
|
|
|
|
|
|
|
buf2 = gst_buffer_new_allocate (NULL, 2, NULL);
|
|
|
|
buf3 = gst_buffer_new_allocate (NULL, 3, NULL);
|
|
|
|
gst_buffer_list_add (list, gst_buffer_append (buf2, buf3));
|
2009-05-12 10:08:56 +00:00
|
|
|
|
|
|
|
/* make a copy */
|
|
|
|
list_copy = gst_buffer_list_copy (list);
|
|
|
|
fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (list) == 1);
|
|
|
|
fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (list_copy) == 1);
|
|
|
|
fail_unless (list_copy != list);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (gst_buffer_list_length (list_copy), 2);
|
|
|
|
buf = gst_buffer_list_get (list_copy, 0);
|
2009-05-12 10:08:56 +00:00
|
|
|
fail_unless (buf == buf1);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf1, "buf1", 2);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (gst_buffer_get_size (buf1), 1);
|
|
|
|
buf = gst_buffer_list_get (list_copy, 1);
|
2009-05-12 10:08:56 +00:00
|
|
|
fail_unless (buf == buf2);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf2, "buf2", 2);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless_equals_int (gst_buffer_get_size (buf2), 5);
|
|
|
|
fail_unless_equals_int (gst_buffer_n_memory (buf2), 2);
|
2009-05-12 10:08:56 +00:00
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
gst_buffer_list_unref (list_copy);
|
2009-05-12 10:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2015-06-24 05:18:47 +00:00
|
|
|
GST_START_TEST (test_copy_deep)
|
|
|
|
{
|
|
|
|
GstBufferList *list_copy;
|
|
|
|
GstMapInfo info, sinfo;
|
|
|
|
GstBuffer *buf1;
|
|
|
|
GstBuffer *buf2;
|
|
|
|
GstBuffer *buf_copy;
|
|
|
|
|
|
|
|
/* add buffers to the list */
|
|
|
|
buf1 = gst_buffer_new_allocate (NULL, 1, NULL);
|
|
|
|
gst_buffer_list_add (list, buf1);
|
|
|
|
|
|
|
|
buf2 = gst_buffer_new_allocate (NULL, 2, NULL);
|
|
|
|
gst_buffer_list_add (list, buf2);
|
|
|
|
|
|
|
|
/* make a copy */
|
|
|
|
list_copy = gst_buffer_list_copy_deep (list);
|
|
|
|
fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (list) == 1);
|
|
|
|
fail_unless (GST_MINI_OBJECT_REFCOUNT_VALUE (list_copy) == 1);
|
|
|
|
fail_unless (list_copy != list);
|
|
|
|
fail_unless_equals_int (gst_buffer_list_length (list_copy), 2);
|
|
|
|
|
|
|
|
buf_copy = gst_buffer_list_get (list_copy, 0);
|
|
|
|
/* each buffer in the list is copied and must point to different memory */
|
|
|
|
fail_unless (buf_copy != buf1);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf1, "buf1", 1);
|
|
|
|
fail_unless_equals_int (gst_buffer_get_size (buf1), 1);
|
|
|
|
|
|
|
|
buf_copy = gst_buffer_list_get (list_copy, 1);
|
|
|
|
fail_unless (buf_copy != buf2);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf2, "buf2", 1);
|
|
|
|
fail_unless_equals_int (gst_buffer_get_size (buf2), 2);
|
|
|
|
|
|
|
|
fail_unless (gst_buffer_map (buf2, &info, GST_MAP_READ));
|
|
|
|
fail_unless (gst_buffer_map (buf_copy, &sinfo, GST_MAP_READ));
|
|
|
|
|
|
|
|
/* NOTE that data is refcounted */
|
|
|
|
fail_unless (info.size == sinfo.size);
|
|
|
|
/* copy_deep() forces new GstMemory to be used */
|
|
|
|
fail_unless (info.data != sinfo.data);
|
|
|
|
|
|
|
|
gst_buffer_unmap (buf_copy, &sinfo);
|
|
|
|
gst_buffer_unmap (buf2, &info);
|
|
|
|
|
|
|
|
gst_buffer_list_unref (list_copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2009-06-19 13:29:14 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-06-26 12:24:08 +00:00
|
|
|
GstBuffer *buf[2];
|
2009-06-19 13:29:14 +00:00
|
|
|
guint iter;
|
|
|
|
} ForeachData;
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
static gboolean
|
|
|
|
foreach_func1 (GstBuffer ** buffer, guint idx, ForeachData * data)
|
2009-06-19 13:29:14 +00:00
|
|
|
{
|
|
|
|
fail_unless (buffer != NULL);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless (GST_IS_BUFFER (*buffer));
|
|
|
|
fail_unless (*buffer == data->buf[idx]);
|
2009-06-19 13:29:14 +00:00
|
|
|
|
|
|
|
data->iter++;
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
return TRUE;
|
2009-06-19 13:29:14 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
static gboolean
|
|
|
|
foreach_func3 (GstBuffer ** buffer, guint idx, ForeachData * data)
|
2009-06-19 13:29:14 +00:00
|
|
|
{
|
|
|
|
fail_unless (idx == 0);
|
|
|
|
fail_unless (buffer != NULL);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless (GST_IS_BUFFER (*buffer));
|
|
|
|
fail_unless (*buffer == data->buf[idx]);
|
2009-06-19 13:29:14 +00:00
|
|
|
|
|
|
|
data->iter++;
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
return FALSE;
|
2009-06-19 13:29:14 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
static gboolean
|
|
|
|
foreach_func4 (GstBuffer ** buffer, guint idx, ForeachData * data)
|
2009-06-19 13:29:14 +00:00
|
|
|
{
|
|
|
|
fail_unless (idx == 0);
|
|
|
|
fail_unless (buffer != NULL);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless (GST_IS_BUFFER (*buffer));
|
|
|
|
fail_unless (*buffer == data->buf[data->iter]);
|
2009-06-19 13:29:14 +00:00
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
/* remove first */
|
|
|
|
if (*buffer == data->buf[0]) {
|
|
|
|
gst_buffer_unref (*buffer);
|
|
|
|
*buffer = NULL;
|
|
|
|
}
|
2009-06-19 13:29:14 +00:00
|
|
|
|
|
|
|
data->iter++;
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
return TRUE;
|
2009-06-19 13:29:14 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
static gboolean
|
|
|
|
foreach_func5 (GstBuffer ** buffer, guint idx, ForeachData * data)
|
2009-06-19 13:29:14 +00:00
|
|
|
{
|
|
|
|
fail_unless (buffer != NULL);
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless (GST_IS_BUFFER (*buffer));
|
2009-06-19 13:29:14 +00:00
|
|
|
|
|
|
|
data->iter++;
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
return TRUE;
|
2009-06-19 13:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_foreach)
|
|
|
|
{
|
2014-06-26 12:24:08 +00:00
|
|
|
GstBuffer *buf2, *buf3;
|
2009-06-19 13:29:14 +00:00
|
|
|
ForeachData data;
|
|
|
|
|
|
|
|
/* add buffers to the list */
|
2014-06-26 12:24:08 +00:00
|
|
|
data.buf[0] = gst_buffer_new_allocate (NULL, 1, NULL);
|
|
|
|
gst_buffer_list_add (list, data.buf[0]);
|
|
|
|
|
|
|
|
buf2 = gst_buffer_new_allocate (NULL, 2, NULL);
|
|
|
|
buf3 = gst_buffer_new_allocate (NULL, 3, NULL);
|
|
|
|
data.buf[1] = gst_buffer_append (buf2, buf3);
|
|
|
|
gst_buffer_list_add (list, data.buf[1]);
|
|
|
|
|
|
|
|
fail_unless (gst_buffer_list_get (list, 0) == data.buf[0]);
|
|
|
|
fail_unless (gst_buffer_list_get (list, 1) == data.buf[1]);
|
2009-06-19 13:29:14 +00:00
|
|
|
|
|
|
|
/* iterate everything */
|
|
|
|
data.iter = 0;
|
|
|
|
gst_buffer_list_foreach (list, (GstBufferListFunc) foreach_func1, &data);
|
|
|
|
fail_unless (data.iter == 2);
|
|
|
|
|
|
|
|
/* iterate only the first buffer */
|
|
|
|
data.iter = 0;
|
|
|
|
gst_buffer_list_foreach (list, (GstBufferListFunc) foreach_func3, &data);
|
|
|
|
fail_unless (data.iter == 1);
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
/* remove the first buffer */
|
2009-06-19 13:29:14 +00:00
|
|
|
data.iter = 0;
|
|
|
|
gst_buffer_list_foreach (list, (GstBufferListFunc) foreach_func4, &data);
|
|
|
|
fail_unless (data.iter == 2);
|
|
|
|
|
2014-06-26 12:24:08 +00:00
|
|
|
fail_unless (gst_buffer_list_get (list, 0) == data.buf[1]);
|
|
|
|
fail_unless_equals_int (gst_buffer_list_length (list), 1);
|
2009-06-19 13:29:14 +00:00
|
|
|
|
|
|
|
/* iterate everything, just one more buffer now */
|
|
|
|
data.iter = 0;
|
|
|
|
gst_buffer_list_foreach (list, (GstBufferListFunc) foreach_func5, &data);
|
|
|
|
fail_unless (data.iter == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2014-06-26 13:08:03 +00:00
|
|
|
/* make sure everything is fine if we exceed the pre-allocated size */
|
|
|
|
GST_START_TEST (test_expand_and_remove)
|
|
|
|
{
|
2014-07-02 07:41:18 +00:00
|
|
|
GArray *arr;
|
2014-06-26 13:08:03 +00:00
|
|
|
GstBuffer *buf;
|
|
|
|
guint i, idx, num, counter = 0;
|
|
|
|
|
|
|
|
gst_buffer_list_unref (list);
|
|
|
|
|
2014-07-02 07:41:18 +00:00
|
|
|
arr = g_array_new (FALSE, FALSE, sizeof (guint));
|
2014-06-26 13:08:03 +00:00
|
|
|
|
|
|
|
list = gst_buffer_list_new_sized (1);
|
|
|
|
|
|
|
|
for (i = 0; i < 250; ++i) {
|
|
|
|
num = ++counter;
|
|
|
|
buf = gst_buffer_new_allocate (NULL, num, NULL);
|
|
|
|
gst_buffer_list_add (list, buf);
|
2014-07-02 07:41:18 +00:00
|
|
|
g_array_append_val (arr, num);
|
2014-06-26 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 250; ++i) {
|
|
|
|
num = ++counter;
|
|
|
|
buf = gst_buffer_new_allocate (NULL, num, NULL);
|
|
|
|
idx = g_random_int_range (0, gst_buffer_list_length (list));
|
|
|
|
gst_buffer_list_insert (list, idx, buf);
|
2014-07-02 07:41:18 +00:00
|
|
|
g_array_insert_val (arr, idx, num);
|
2014-06-26 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure the list looks like it should */
|
|
|
|
fail_unless_equals_int (arr->len, gst_buffer_list_length (list));
|
|
|
|
for (i = 0; i < arr->len; ++i) {
|
|
|
|
buf = gst_buffer_list_get (list, i);
|
|
|
|
num = gst_buffer_get_size (buf);
|
2014-07-02 07:41:18 +00:00
|
|
|
fail_unless_equals_int (num, g_array_index (arr, guint, i));
|
2014-06-26 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 44; ++i) {
|
|
|
|
num = g_random_int_range (1, 5);
|
|
|
|
idx = g_random_int_range (0, gst_buffer_list_length (list) - num);
|
|
|
|
gst_buffer_list_remove (list, idx, num);
|
2014-07-02 07:41:18 +00:00
|
|
|
g_array_remove_range (arr, idx, num);
|
2014-06-26 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure the list still looks like it should */
|
|
|
|
fail_unless_equals_int (arr->len, gst_buffer_list_length (list));
|
|
|
|
for (i = 0; i < arr->len; ++i) {
|
|
|
|
buf = gst_buffer_list_get (list, i);
|
|
|
|
num = gst_buffer_get_size (buf);
|
2014-07-02 07:41:18 +00:00
|
|
|
fail_unless_equals_int (num, g_array_index (arr, guint, i));
|
2014-06-26 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 500; ++i) {
|
|
|
|
num = ++counter;
|
|
|
|
buf = gst_buffer_new_allocate (NULL, num, NULL);
|
|
|
|
gst_buffer_list_add (list, buf);
|
2014-07-02 07:41:18 +00:00
|
|
|
g_array_append_val (arr, num);
|
2014-06-26 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 500; ++i) {
|
|
|
|
num = ++counter;
|
|
|
|
buf = gst_buffer_new_allocate (NULL, num, NULL);
|
|
|
|
idx = g_random_int_range (0, gst_buffer_list_length (list));
|
|
|
|
gst_buffer_list_insert (list, idx, buf);
|
2014-07-02 07:41:18 +00:00
|
|
|
g_array_insert_val (arr, idx, num);
|
2014-06-26 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure the list still looks like it should */
|
|
|
|
fail_unless_equals_int (arr->len, gst_buffer_list_length (list));
|
|
|
|
for (i = 0; i < arr->len; ++i) {
|
|
|
|
buf = gst_buffer_list_get (list, i);
|
|
|
|
num = gst_buffer_get_size (buf);
|
2014-07-02 07:41:18 +00:00
|
|
|
fail_unless_equals_int (num, g_array_index (arr, guint, i));
|
2014-06-26 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 07:41:18 +00:00
|
|
|
g_array_unref (arr);
|
2014-06-26 13:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2017-08-30 12:50:33 +00:00
|
|
|
GST_START_TEST (test_get_writable)
|
|
|
|
{
|
|
|
|
GstBuffer *buf, *writable_buf;
|
|
|
|
|
|
|
|
/* buffer list is initially empty */
|
|
|
|
fail_unless (gst_buffer_list_length (list) == 0);
|
|
|
|
|
|
|
|
/* Add 2 buffers */
|
|
|
|
buf = gst_buffer_new ();
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
|
|
|
|
gst_buffer_list_add (list, buf);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf, "buf", 1); /* list takes ownership */
|
|
|
|
fail_unless (gst_buffer_list_length (list) == 1);
|
|
|
|
fail_unless (buf == gst_buffer_list_get_writable (list, 0));
|
|
|
|
fail_unless (buf == gst_buffer_list_get (list, 0));
|
|
|
|
|
|
|
|
/* extra ref to make buffer no longer writable */
|
|
|
|
gst_buffer_ref (buf);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf, "buf", 2);
|
|
|
|
fail_unless (buf == gst_buffer_list_get (list, 0));
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf, "buf", 2);
|
|
|
|
|
|
|
|
/* should make a copy to make it writable */
|
|
|
|
writable_buf = gst_buffer_list_get_writable (list, 0);
|
|
|
|
fail_if (buf == writable_buf);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (writable_buf, "writable_buf", 1);
|
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2017-08-31 11:54:55 +00:00
|
|
|
GST_START_TEST (test_calc_size)
|
|
|
|
{
|
|
|
|
gst_buffer_list_add (list, gst_buffer_new_wrapped (g_strdup ("Hello"), 5));
|
|
|
|
gst_buffer_list_add (list, gst_buffer_new_wrapped (g_strdup (", "), 2));
|
|
|
|
gst_buffer_list_add (list, gst_buffer_new_wrapped (g_strdup ("world!"), 6));
|
|
|
|
|
|
|
|
fail_unless_equals_int (5 + 2 + 6, gst_buffer_list_calculate_size (list));
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2018-05-05 14:16:45 +00:00
|
|
|
GST_START_TEST (test_new_sized_0)
|
|
|
|
{
|
|
|
|
GstBufferList *b = gst_buffer_list_new_sized (0);
|
|
|
|
|
|
|
|
gst_buffer_list_unref (b);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2018-06-28 12:13:39 +00:00
|
|
|
GST_START_TEST (test_multiple_mutable_buffer_references)
|
|
|
|
{
|
|
|
|
GstBufferList *b = gst_buffer_list_new_sized (1);
|
|
|
|
GstBuffer *buf1, *buf2;
|
|
|
|
|
|
|
|
gst_buffer_list_add (b, gst_buffer_new ());
|
|
|
|
gst_buffer_list_ref (b);
|
|
|
|
|
|
|
|
buf1 = gst_buffer_list_get (b, 0);
|
|
|
|
buf2 = gst_buffer_list_get (b, 0);
|
|
|
|
|
|
|
|
fail_if (gst_buffer_list_is_writable (b));
|
|
|
|
fail_if (gst_buffer_is_writable (buf1));
|
|
|
|
fail_if (gst_buffer_is_writable (buf2));
|
|
|
|
|
|
|
|
/* Immutable operations that have optimizations for writable buffers
|
|
|
|
* will cause problems now, e.g. read-mapping the buffer and merging
|
|
|
|
* together all the memories and replacing them in the buffer */
|
|
|
|
|
|
|
|
gst_buffer_list_unref (b);
|
|
|
|
gst_buffer_list_unref (b);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2018-06-29 05:16:28 +00:00
|
|
|
static gboolean
|
|
|
|
foreach_replace_buffer (GstBuffer ** buffer, guint idx, gpointer user_data)
|
|
|
|
{
|
|
|
|
gst_buffer_unref (*buffer);
|
|
|
|
*buffer = gst_buffer_new ();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_foreach_modify_non_writeable_list)
|
|
|
|
{
|
|
|
|
GstBufferList *b = gst_buffer_list_new_sized (1);
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
buf = gst_buffer_new ();
|
|
|
|
gst_buffer_list_add (b, gst_buffer_ref (buf));
|
|
|
|
gst_buffer_list_ref (b);
|
|
|
|
|
|
|
|
fail_if (gst_buffer_list_is_writable (b));
|
|
|
|
|
|
|
|
ASSERT_CRITICAL (gst_buffer_list_foreach (b, foreach_replace_buffer, NULL));
|
|
|
|
|
|
|
|
fail_unless (gst_buffer_list_get (b, 0) == buf);
|
|
|
|
|
|
|
|
gst_buffer_list_unref (b);
|
|
|
|
gst_buffer_list_unref (b);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2009-05-12 10:08:56 +00:00
|
|
|
static Suite *
|
|
|
|
gst_buffer_list_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("GstBufferList");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
tcase_add_checked_fixture (tc_chain, setup, cleanup);
|
|
|
|
tcase_add_test (tc_chain, test_add_and_iterate);
|
2014-06-16 19:30:13 +00:00
|
|
|
tcase_add_test (tc_chain, test_remove);
|
2009-05-12 10:08:56 +00:00
|
|
|
tcase_add_test (tc_chain, test_make_writable);
|
|
|
|
tcase_add_test (tc_chain, test_copy);
|
2015-06-24 05:18:47 +00:00
|
|
|
tcase_add_test (tc_chain, test_copy_deep);
|
2009-06-19 13:29:14 +00:00
|
|
|
tcase_add_test (tc_chain, test_foreach);
|
2014-06-26 13:08:03 +00:00
|
|
|
tcase_add_test (tc_chain, test_expand_and_remove);
|
2017-08-30 12:50:33 +00:00
|
|
|
tcase_add_test (tc_chain, test_get_writable);
|
2017-08-31 11:54:55 +00:00
|
|
|
tcase_add_test (tc_chain, test_calc_size);
|
2018-05-05 14:16:45 +00:00
|
|
|
tcase_add_test (tc_chain, test_new_sized_0);
|
2018-06-28 12:13:39 +00:00
|
|
|
tcase_add_test (tc_chain, test_multiple_mutable_buffer_references);
|
2018-06-29 05:16:28 +00:00
|
|
|
tcase_add_test (tc_chain, test_foreach_modify_non_writeable_list);
|
2009-05-12 10:08:56 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_CHECK_MAIN (gst_buffer_list);
|