bufferlist: add gst_buffer_list_calculate_size()

Returns size in bytes.
This commit is contained in:
Tim-Philipp Müller 2017-08-31 12:54:55 +01:00
parent 177c4ffe6a
commit 8f26af8b02
5 changed files with 47 additions and 0 deletions

View file

@ -395,6 +395,8 @@ gst_buffer_list_foreach
gst_buffer_list_get
gst_buffer_list_get_writable
gst_buffer_list_calculate_size
<SUBSECTION Standard>
GST_BUFFER_LIST
GST_IS_BUFFER_LIST

View file

@ -436,3 +436,32 @@ gst_buffer_list_copy_deep (const GstBufferList * list)
return result;
}
/**
* gst_buffer_list_calculate_size:
* @list: a #GstBufferList
*
* Calculates the size of the data contained in buffer list by adding the
* size of all buffers.
*
* Returns: the size of the data contained in buffer list in bytes.
*
* Since: 1.14
*/
gsize
gst_buffer_list_calculate_size (GstBufferList * list)
{
GstBuffer **buffers;
gsize size = 0;
guint i, n;
g_return_val_if_fail (GST_IS_BUFFER_LIST (list), 0);
n = list->n_buffers;
buffers = list->buffers;
for (i = 0; i < n; ++i)
size += gst_buffer_get_size (buffers[i]);
return size;
}

View file

@ -164,6 +164,9 @@ gboolean gst_buffer_list_foreach (GstBufferList *l
GST_EXPORT
GstBufferList * gst_buffer_list_copy_deep (const GstBufferList * list);
GST_EXPORT
gsize gst_buffer_list_calculate_size (GstBufferList * list);
#define gst_buffer_list_add(l,b) gst_buffer_list_insert((l),-1,(b));
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC

View file

@ -460,6 +460,17 @@ GST_START_TEST (test_get_writable)
GST_END_TEST;
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;
static Suite *
gst_buffer_list_suite (void)
{
@ -476,6 +487,7 @@ gst_buffer_list_suite (void)
tcase_add_test (tc_chain, test_foreach);
tcase_add_test (tc_chain, test_expand_and_remove);
tcase_add_test (tc_chain, test_get_writable);
tcase_add_test (tc_chain, test_calc_size);
return s;
}

View file

@ -146,6 +146,7 @@ EXPORTS
gst_buffer_is_memory_range_writable
gst_buffer_iterate_meta
gst_buffer_iterate_meta_filtered
gst_buffer_list_calculate_size
gst_buffer_list_copy_deep
gst_buffer_list_foreach
gst_buffer_list_get