Commit 7ecef53d authored by Hyunjun Ko's avatar Hyunjun Ko Committed by Sebastian Dröge

bufferlist: add new api gst_buffer_list_copy_deep

https://bugzilla.gnome.org/show_bug.cgi?id=751420
parent fabe966b
......@@ -372,6 +372,7 @@ gst_buffer_list_remove
gst_buffer_list_ref
gst_buffer_list_unref
gst_buffer_list_copy
gst_buffer_list_copy_deep
gst_buffer_list_is_writable
gst_buffer_list_make_writable
......
......@@ -364,3 +364,33 @@ gst_buffer_list_remove (GstBufferList * list, guint idx, guint length)
gst_buffer_list_remove_range_internal (list, idx, length, TRUE);
}
/**
* gst_buffer_list_copy_deep:
* @list: a #GstBufferList
*
* Create a copy of the given buffer list. This will make a newly allocated
* copy of the buffer that the source buffer list contains.
*
* Returns: (transfer full): a new copy of @list.
*
* Since: 1.6
*/
GstBufferList *
gst_buffer_list_copy_deep (const GstBufferList * list)
{
guint i, len;
GstBufferList *result = NULL;
g_return_val_if_fail (GST_IS_BUFFER_LIST (list), NULL);
result = gst_buffer_list_new ();
len = list->n_buffers;
for (i = 0; i < len; i++) {
GstBuffer *old = list->buffers[i];
gst_buffer_list_insert (result, i, gst_buffer_copy_deep (old));
}
return result;
}
......@@ -158,6 +158,7 @@ void gst_buffer_list_remove (GstBufferList *l
gboolean gst_buffer_list_foreach (GstBufferList *list,
GstBufferListFunc func,
gpointer user_data);
GstBufferList * gst_buffer_list_copy_deep (const GstBufferList * list);
#define gst_buffer_list_add(l,b) gst_buffer_list_insert((l),-1,(b));
......
......@@ -195,6 +195,55 @@ GST_START_TEST (test_copy)
GST_END_TEST;
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;
typedef struct
{
GstBuffer *buf[2];
......@@ -390,6 +439,7 @@ gst_buffer_list_suite (void)
tcase_add_test (tc_chain, test_remove);
tcase_add_test (tc_chain, test_make_writable);
tcase_add_test (tc_chain, test_copy);
tcase_add_test (tc_chain, test_copy_deep);
tcase_add_test (tc_chain, test_foreach);
tcase_add_test (tc_chain, test_expand_and_remove);
......
......@@ -149,6 +149,7 @@ EXPORTS
gst_buffer_list_new
gst_buffer_list_new_sized
gst_buffer_list_remove
gst_buffer_list_copy_deep
gst_buffer_map
gst_buffer_map_range
gst_buffer_memcmp
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment