From 8ea948df924b5ca69c0146a047bd8cf103b3bbbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Thu, 15 Dec 2005 12:22:38 +0000 Subject: [PATCH] gst/gstminiobject.c: Fix lcopy for mini objects, the mini object needs to be ref'ed. Original commit message from CVS: * gst/gstminiobject.c: (gst_value_mini_object_lcopy): Fix lcopy for mini objects, the mini object needs to be ref'ed. * tests/check/gst/gstminiobject.c: (my_foo_init), (my_foo_get_property), (my_foo_set_property), (my_foo_class_init), (test_value_collection), (gst_mini_object_suite): Add test to ensure refcounts end up as expected when passing GstMiniObjects through g_object_get() and g_object_set(). --- ChangeLog | 11 +++++ gst/gstminiobject.c | 7 ++- tests/check/gst/gstminiobject.c | 97 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fbab0bc..5a741c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-12-15 Tim-Philipp Müller + + * gst/gstminiobject.c: (gst_value_mini_object_lcopy): + Fix lcopy for mini objects, the mini object needs to be ref'ed. + + * tests/check/gst/gstminiobject.c: (my_foo_init), + (my_foo_get_property), (my_foo_set_property), (my_foo_class_init), + (test_value_collection), (gst_mini_object_suite): + Add test to ensure refcounts end up as expected when passing + GstMiniObjects through g_object_get() and g_object_set(). + 2005-12-14 Julien MOUTTE * libs/gst/base/gstcollectpads.c: (gst_collect_pads_base_init), diff --git a/gst/gstminiobject.c b/gst/gstminiobject.c index 3d6c72c..efd69d8 100644 --- a/gst/gstminiobject.c +++ b/gst/gstminiobject.c @@ -375,7 +375,12 @@ gst_value_mini_object_lcopy (const GValue * value, guint n_collect_values, G_VALUE_TYPE_NAME (value)); } - *mini_object_p = value->data[0].v_pointer; + if (!value->data[0].v_pointer) + *mini_object_p = NULL; + else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) + *mini_object_p = value->data[0].v_pointer; + else + *mini_object_p = gst_mini_object_ref (value->data[0].v_pointer); return NULL; } diff --git a/tests/check/gst/gstminiobject.c b/tests/check/gst/gstminiobject.c index 5043370..d57ada3 100644 --- a/tests/check/gst/gstminiobject.c +++ b/tests/check/gst/gstminiobject.c @@ -3,6 +3,7 @@ * unit test for GstMiniObject * * Copyright (C) <2005> Thomas Vander Stichele + * Copyright (C) <2005> Tim-Philipp Müller * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -174,6 +175,101 @@ GST_START_TEST (test_unref_threaded) GST_END_TEST; +/* ======== value collection test ======== */ +typedef struct _MyFoo +{ + GObject object; +} MyFoo; + +typedef struct _MyFooClass +{ + GObjectClass gobject_class; +} MyFooClass; + +enum +{ + PROP_BUFFER = 1 +}; + +G_DEFINE_TYPE (MyFoo, my_foo, G_TYPE_OBJECT) + + static void my_foo_init (MyFoo * foo) +{ +} + +static void +my_foo_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) +{ + GstBuffer *new_buf; + + g_assert (prop_id == PROP_BUFFER); + + new_buf = gst_buffer_new_and_alloc (1024); + gst_value_set_mini_object (value, GST_MINI_OBJECT (new_buf)); + gst_buffer_unref (new_buf); +} + +static void +my_foo_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) +{ + GstMiniObject *mini_obj; + + g_assert (prop_id == PROP_BUFFER); + + mini_obj = gst_value_get_mini_object (value); + g_assert (GST_IS_MINI_OBJECT (mini_obj)); + g_assert (GST_IS_BUFFER (mini_obj)); + +#if 0 + /* gst_value_dup_mini_object() does not exist yet */ + mini_obj = gst_value_dup_mini_object (value); + g_assert (GST_IS_MINI_OBJECT (mini_obj)); + g_assert (GST_IS_BUFFER (mini_obj)); + gst_mini_object_unref (mini_obj); +#endif +} + + +static void +my_foo_class_init (MyFooClass * klass) +{ + GObjectClass *gobject_klass = G_OBJECT_CLASS (klass); + + gobject_klass->get_property = my_foo_get_property; + gobject_klass->set_property = my_foo_set_property; + + g_object_class_install_property (gobject_klass, PROP_BUFFER, + gst_param_spec_mini_object ("buffer", "Buffer", + "a newly created GstBuffer", GST_TYPE_BUFFER, G_PARAM_READWRITE)); +} + +GST_START_TEST (test_value_collection) +{ + GstBuffer *buf = NULL; + MyFoo *foo; + + foo = (MyFoo *) g_object_new (my_foo_get_type (), NULL); + + /* test g_object_get() refcounting */ + g_object_get (foo, "buffer", &buf, NULL); + g_assert (GST_IS_BUFFER (buf)); + g_assert (GST_MINI_OBJECT_REFCOUNT_VALUE (GST_MINI_OBJECT_CAST (buf)) == 1); + gst_buffer_unref (buf); + + /* test g_object_set() refcounting */ + buf = gst_buffer_new_and_alloc (1024); + g_object_set (foo, "buffer", buf, NULL); + g_assert (GST_MINI_OBJECT_REFCOUNT_VALUE (GST_MINI_OBJECT_CAST (buf)) == 1); + gst_buffer_unref (buf); + + g_object_unref (foo); +} + +GST_END_TEST; + + Suite * gst_mini_object_suite (void) { @@ -189,6 +285,7 @@ gst_mini_object_suite (void) tcase_add_test (tc_chain, test_make_writable); tcase_add_test (tc_chain, test_ref_threaded); tcase_add_test (tc_chain, test_unref_threaded); + tcase_add_test (tc_chain, test_value_collection); return s; } -- 2.7.4