bufferlist: foreach: always remove as parent if buffer is changed

In case the buffer is not writable, the parent (the BufferList) is not
removed before calling func. So if it is changed, the parent (the BufferList)
of the previous buffer should be removed after calling func.
This commit is contained in:
Miguel Paris 2020-03-03 15:36:26 +01:00
parent 1e9dcac0fb
commit 2ef0fd1862
2 changed files with 24 additions and 1 deletions

View file

@ -307,8 +307,11 @@ gst_buffer_list_foreach (GstBufferList * list, GstBufferListFunc func,
gst_buffer_list_remove_range_internal (list, i, 1, !was_writable); gst_buffer_list_remove_range_internal (list, i, 1, !was_writable);
--len; --len;
} else { } else {
if (!was_writable) if (!was_writable) {
gst_mini_object_remove_parent (GST_MINI_OBJECT_CAST (buf),
GST_MINI_OBJECT_CAST (list));
gst_buffer_unref (buf); gst_buffer_unref (buf);
}
list->buffers[i] = buf_ret; list->buffers[i] = buf_ret;
gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (buf_ret), gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (buf_ret),

View file

@ -539,6 +539,24 @@ GST_START_TEST (test_foreach_modify_non_writeable_list)
GST_END_TEST; GST_END_TEST;
GST_START_TEST (test_foreach_modify_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));
fail_unless (gst_buffer_list_is_writable (b));
gst_buffer_list_foreach (b, foreach_replace_buffer, NULL);
gst_buffer_list_unref (b);
gst_buffer_unref (buf);
}
GST_END_TEST;
static Suite * static Suite *
gst_buffer_list_suite (void) gst_buffer_list_suite (void)
{ {
@ -546,6 +564,7 @@ gst_buffer_list_suite (void)
TCase *tc_chain = tcase_create ("general"); TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain); suite_add_tcase (s, tc_chain);
tcase_add_checked_fixture (tc_chain, setup, cleanup); tcase_add_checked_fixture (tc_chain, setup, cleanup);
tcase_add_test (tc_chain, test_add_and_iterate); tcase_add_test (tc_chain, test_add_and_iterate);
tcase_add_test (tc_chain, test_remove); tcase_add_test (tc_chain, test_remove);
@ -559,6 +578,7 @@ gst_buffer_list_suite (void)
tcase_add_test (tc_chain, test_new_sized_0); tcase_add_test (tc_chain, test_new_sized_0);
tcase_add_test (tc_chain, test_multiple_mutable_buffer_references); tcase_add_test (tc_chain, test_multiple_mutable_buffer_references);
tcase_add_test (tc_chain, test_foreach_modify_non_writeable_list); tcase_add_test (tc_chain, test_foreach_modify_non_writeable_list);
tcase_add_test (tc_chain, test_foreach_modify_writeable_list);
return s; return s;
} }