check/gst/gstbin.c: Add bus to bin.

Original commit message from CVS:
* check/gst/gstbin.c: (GST_START_TEST):
Add bus to bin.

* gst/gstbin.c: (gst_bin_class_init), (gst_bin_init),
(add_to_queue), (clear_queue), (reset_degree), (update_degree),
(find_element), (gst_bin_sort_iterator_next),
(gst_bin_sort_iterator_resync), (gst_bin_sort_iterator_free),
(gst_bin_iterate_sorted), (gst_bin_element_set_state),
(gst_bin_change_state), (gst_bin_dispose):
A bin does not have a bus, it gets the bus from the parent.

* gst/gstelement.c: (gst_element_requires_clock),
(gst_element_provides_clock), (gst_element_is_indexable),
(gst_element_is_locked_state), (gst_element_change_state),
(gst_element_set_bus_func):
Small cleanups.

* gst/gstpipeline.c: (gst_pipeline_class_init),
(gst_pipeline_init), (gst_pipeline_provide_clock_func):
The pipeline provides a bus.
This commit is contained in:
Wim Taymans 2005-09-29 09:39:36 +00:00
parent d52d4b4a4d
commit 92836e5172
6 changed files with 115 additions and 68 deletions

View file

@ -1,3 +1,26 @@
2005-09-29 Wim Taymans <wim@fluendo.com>
* check/gst/gstbin.c: (GST_START_TEST):
Add bus to bin.
* gst/gstbin.c: (gst_bin_class_init), (gst_bin_init),
(add_to_queue), (clear_queue), (reset_degree), (update_degree),
(find_element), (gst_bin_sort_iterator_next),
(gst_bin_sort_iterator_resync), (gst_bin_sort_iterator_free),
(gst_bin_iterate_sorted), (gst_bin_element_set_state),
(gst_bin_change_state), (gst_bin_dispose):
A bin does not have a bus, it gets the bus from the parent.
* gst/gstelement.c: (gst_element_requires_clock),
(gst_element_provides_clock), (gst_element_is_indexable),
(gst_element_is_locked_state), (gst_element_change_state),
(gst_element_set_bus_func):
Small cleanups.
* gst/gstpipeline.c: (gst_pipeline_class_init),
(gst_pipeline_init), (gst_pipeline_provide_clock_func):
The pipeline provides a bus.
2005-09-28 Johan Dahlin <johan@gnome.org> 2005-09-28 Johan Dahlin <johan@gnome.org>
* gst/gstmessage.c (gst_message_parse_state_changed): Use * gst/gstmessage.c (gst_message_parse_state_changed): Use

View file

@ -114,7 +114,8 @@ GST_START_TEST (test_message_state_changed)
fail_unless (bin != NULL, "Could not create bin"); fail_unless (bin != NULL, "Could not create bin");
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
bus = GST_ELEMENT_BUS (bin); bus = g_object_new (gst_bus_get_type (), NULL);
gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
/* change state, spawning a message, causing an incref on the bin */ /* change state, spawning a message, causing an incref on the bin */
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY); gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
@ -132,6 +133,7 @@ GST_START_TEST (test_message_state_changed)
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
/* clean up */ /* clean up */
gst_object_unref (bus);
gst_object_unref (bin); gst_object_unref (bin);
} }
@ -148,14 +150,15 @@ GST_START_TEST (test_message_state_changed_child)
fail_unless (bin != NULL, "Could not create bin"); fail_unless (bin != NULL, "Could not create bin");
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
bus = g_object_new (gst_bus_get_type (), NULL);
gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
fail_if (src == NULL, "Could not create fakesrc"); fail_if (src == NULL, "Could not create fakesrc");
gst_bin_add (bin, src); gst_bin_add (bin, src);
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
bus = GST_ELEMENT_BUS (bin);
/* change state, spawning two messages: /* change state, spawning two messages:
* - first for fakesrc, forwarded to bin's bus, causing incref on fakesrc * - first for fakesrc, forwarded to bin's bus, causing incref on fakesrc
* - second for bin, causing an incref on the bin */ * - second for bin, causing an incref on the bin */
@ -189,6 +192,7 @@ GST_START_TEST (test_message_state_changed_child)
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
/* clean up */ /* clean up */
gst_object_unref (bus);
gst_object_unref (bin); gst_object_unref (bin);
} }
@ -224,7 +228,7 @@ GST_START_TEST (test_message_state_changed_children)
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1); ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
bus = GST_ELEMENT_BUS (pipeline); bus = gst_pipeline_get_bus (pipeline);
/* change state to READY, spawning three messages */ /* change state to READY, spawning three messages */
GST_DEBUG ("setting pipeline to READY"); GST_DEBUG ("setting pipeline to READY");
@ -232,7 +236,7 @@ GST_START_TEST (test_message_state_changed_children)
== GST_STATE_CHANGE_SUCCESS); == GST_STATE_CHANGE_SUCCESS);
/* each object is referenced by a message */ /* each object is referenced by a message */
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1); ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
ASSERT_OBJECT_REFCOUNT (src, "src", 2); ASSERT_OBJECT_REFCOUNT (src, "src", 2);
ASSERT_OBJECT_REFCOUNT (sink, "sink", 2); ASSERT_OBJECT_REFCOUNT (sink, "sink", 2);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 2); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 2);
@ -240,7 +244,7 @@ GST_START_TEST (test_message_state_changed_children)
pop_messages (bus, 3); pop_messages (bus, 3);
fail_if ((gst_bus_pop (bus)) != NULL); fail_if ((gst_bus_pop (bus)) != NULL);
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1); ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1); ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
@ -260,7 +264,7 @@ GST_START_TEST (test_message_state_changed_children)
pop_messages (bus, 3); pop_messages (bus, 3);
fail_if ((gst_bus_pop (bus)) != NULL); fail_if ((gst_bus_pop (bus)) != NULL);
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1); ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
ASSERT_OBJECT_REFCOUNT (sink, "sink", 2); ASSERT_OBJECT_REFCOUNT (sink, "sink", 2);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
@ -279,7 +283,7 @@ GST_START_TEST (test_message_state_changed_children)
pop_messages (bus, 3); pop_messages (bus, 3);
fail_if ((gst_bus_pop (bus)) != NULL); fail_if ((gst_bus_pop (bus)) != NULL);
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1); ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
/* sink might have an extra reference if it's still blocked on preroll */ /* sink might have an extra reference if it's still blocked on preroll */
ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 1, 2); ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 1, 2);
@ -311,6 +315,7 @@ GST_START_TEST (test_message_state_changed_children)
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
/* clean up */ /* clean up */
gst_object_unref (bus);
gst_object_unref (pipeline); gst_object_unref (pipeline);
} }
@ -324,6 +329,9 @@ GST_START_TEST (test_watch_for_state_change)
bin = gst_element_factory_make ("bin", NULL); bin = gst_element_factory_make ("bin", NULL);
fail_unless (bin != NULL, "Could not create bin"); fail_unless (bin != NULL, "Could not create bin");
bus = g_object_new (gst_bus_get_type (), NULL);
gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
fail_if (src == NULL, "Could not create fakesrc"); fail_if (src == NULL, "Could not create fakesrc");
sink = gst_element_factory_make ("fakesink", NULL); sink = gst_element_factory_make ("fakesink", NULL);
@ -334,15 +342,13 @@ GST_START_TEST (test_watch_for_state_change)
fail_unless (gst_element_link (src, sink), "could not link src and sink"); fail_unless (gst_element_link (src, sink), "could not link src and sink");
bus = GST_ELEMENT_BUS (bin);
/* change state, spawning two times three messages, minus one async */ /* change state, spawning two times three messages, minus one async */
fail_unless (gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED) fail_unless (gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED)
== GST_STATE_CHANGE_ASYNC); == GST_STATE_CHANGE_ASYNC);
pop_messages (bus, 5); pop_messages (bus, 5);
fail_unless (gst_bus_have_pending (bus, GST_MESSAGE_ANY) == FALSE, fail_unless (gst_bus_have_pending (bus) == FALSE,
"Unexpected messages on bus"); "Unexpected messages on bus");
gst_bin_watch_for_state_change (GST_BIN (bin)); gst_bin_watch_for_state_change (GST_BIN (bin));
@ -350,7 +356,7 @@ GST_START_TEST (test_watch_for_state_change)
/* should get the bin's state change message now */ /* should get the bin's state change message now */
pop_messages (bus, 1); pop_messages (bus, 1);
fail_unless (gst_bus_have_pending (bus, GST_MESSAGE_ANY) == FALSE, fail_unless (gst_bus_have_pending (bus) == FALSE,
"Unexpected messages on bus"); "Unexpected messages on bus");
fail_unless (gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING) fail_unless (gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING)
@ -365,7 +371,7 @@ GST_START_TEST (test_watch_for_state_change)
pop_messages (bus, 3); pop_messages (bus, 3);
fail_unless (gst_bus_have_pending (bus, GST_MESSAGE_ANY) == FALSE, fail_unless (gst_bus_have_pending (bus) == FALSE,
"Unexpected messages on bus"); "Unexpected messages on bus");
/* setting bin to NULL flushes the bus automatically */ /* setting bin to NULL flushes the bus automatically */
@ -373,6 +379,7 @@ GST_START_TEST (test_watch_for_state_change)
== GST_STATE_CHANGE_SUCCESS); == GST_STATE_CHANGE_SUCCESS);
/* clean up */ /* clean up */
gst_object_unref (bus);
gst_object_unref (bin); gst_object_unref (bin);
} }
@ -458,7 +465,7 @@ GST_START_TEST (test_children_state_change_order_flagged_sink)
pipeline = gst_pipeline_new (NULL); pipeline = gst_pipeline_new (NULL);
fail_unless (pipeline != NULL, "Could not create pipeline"); fail_unless (pipeline != NULL, "Could not create pipeline");
bus = GST_ELEMENT_BUS (pipeline); bus = gst_element_get_bus (pipeline);
fail_unless (bus != NULL, "Pipeline has no bus?!"); fail_unless (bus != NULL, "Pipeline has no bus?!");
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
@ -531,6 +538,7 @@ GST_START_TEST (test_children_state_change_order_flagged_sink)
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1); ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
gst_object_unref (bus);
gst_object_unref (pipeline); gst_object_unref (pipeline);
} }
@ -548,7 +556,7 @@ GST_START_TEST (test_children_state_change_order_semi_sink)
pipeline = gst_pipeline_new (NULL); pipeline = gst_pipeline_new (NULL);
fail_unless (pipeline != NULL, "Could not create pipeline"); fail_unless (pipeline != NULL, "Could not create pipeline");
bus = GST_ELEMENT_BUS (pipeline); bus = gst_element_get_bus (pipeline);
fail_unless (bus != NULL, "Pipeline has no bus?!"); fail_unless (bus != NULL, "Pipeline has no bus?!");
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
@ -623,6 +631,7 @@ GST_START_TEST (test_children_state_change_order_semi_sink)
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1); ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
gst_object_unref (bus);
gst_object_unref (pipeline); gst_object_unref (pipeline);
} }
@ -637,7 +646,7 @@ GST_START_TEST (test_children_state_change_order_two_sink)
pipeline = gst_pipeline_new (NULL); pipeline = gst_pipeline_new (NULL);
fail_unless (pipeline != NULL, "Could not create pipeline"); fail_unless (pipeline != NULL, "Could not create pipeline");
bus = GST_ELEMENT_BUS (pipeline); bus = gst_element_get_bus (pipeline);
fail_unless (bus != NULL, "Pipeline has no bus?!"); fail_unless (bus != NULL, "Pipeline has no bus?!");
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
@ -718,6 +727,7 @@ GST_START_TEST (test_children_state_change_order_two_sink)
ASSERT_OBJECT_REFCOUNT (sink2, "sink2", 1); ASSERT_OBJECT_REFCOUNT (sink2, "sink2", 1);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
gst_object_unref (bus);
gst_object_unref (pipeline); gst_object_unref (pipeline);
} }

View file

@ -273,16 +273,10 @@ gst_bin_init (GstBin * bin)
bin->children_cookie = 0; bin->children_cookie = 0;
bin->eosed = NULL; bin->eosed = NULL;
/* Set up a bus for listening to child elements, /* Set up a bus for listening to child elements */
* and one for sending messages up the hierarchy */
bus = g_object_new (gst_bus_get_type (), NULL); bus = g_object_new (gst_bus_get_type (), NULL);
bin->child_bus = bus; bin->child_bus = bus;
gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bin_bus_handler, bin); gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bin_bus_handler, bin);
bus = g_object_new (gst_bus_get_type (), NULL);
gst_element_set_bus (GST_ELEMENT (bin), bus);
/* set_bus refs the bus via gst_object_replace, we drop our ref */
gst_object_unref (bus);
} }
/** /**
@ -1466,7 +1460,6 @@ gst_bin_dispose (GObject * object)
bin->eosed = NULL; bin->eosed = NULL;
gst_object_unref (bin->child_bus); gst_object_unref (bin->child_bus);
bin->child_bus = NULL; bin->child_bus = NULL;
gst_element_set_bus (GST_ELEMENT (bin), NULL);
while (bin->children) { while (bin->children) {
gst_bin_remove (bin, GST_ELEMENT (bin->children->data)); gst_bin_remove (bin, GST_ELEMENT (bin->children->data));

View file

@ -30,8 +30,8 @@
* *
* The name of a GstElement can be get with gst_element_get_name() and set with * The name of a GstElement can be get with gst_element_get_name() and set with
* gst_element_set_name(). For speed, GST_ELEMENT_NAME() can be used in the * gst_element_set_name(). For speed, GST_ELEMENT_NAME() can be used in the
* core. Do not use this in plug-ins or applications in order to retain ABI * core when using the appropriate locking. Do not use this in plug-ins or
* compatibility. * applications in order to retain ABI compatibility.
* *
* All elements have pads (of the type #GstPad). These pads link to pads on * All elements have pads (of the type #GstPad). These pads link to pads on
* other elements. Buffers flow between these linked pads. * other elements. Buffers flow between these linked pads.
@ -308,9 +308,9 @@ gst_element_release_request_pad (GstElement * element, GstPad * pad)
gboolean gboolean
gst_element_requires_clock (GstElement * element) gst_element_requires_clock (GstElement * element)
{ {
gboolean result = FALSE; gboolean result;
g_return_val_if_fail (GST_IS_ELEMENT (element), result); g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
result = (GST_ELEMENT_GET_CLASS (element)->set_clock != NULL); result = (GST_ELEMENT_GET_CLASS (element)->set_clock != NULL);
@ -330,7 +330,7 @@ gst_element_requires_clock (GstElement * element)
gboolean gboolean
gst_element_provides_clock (GstElement * element) gst_element_provides_clock (GstElement * element)
{ {
gboolean result = FALSE; gboolean result;
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE); g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
@ -346,7 +346,7 @@ gst_element_provides_clock (GstElement * element)
* Get the clock provided by the given element. * Get the clock provided by the given element.
* *
* Returns: the GstClock provided by the element or NULL * Returns: the GstClock provided by the element or NULL
* if no clock could be provided. * if no clock could be provided. Unref after usage.
* *
* MT safe. * MT safe.
*/ */
@ -479,9 +479,9 @@ gst_element_get_base_time (GstElement * element)
gboolean gboolean
gst_element_is_indexable (GstElement * element) gst_element_is_indexable (GstElement * element)
{ {
gboolean result = FALSE; gboolean result;
g_return_val_if_fail (GST_IS_ELEMENT (element), result); g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
result = (GST_ELEMENT_GET_CLASS (element)->set_index != NULL); result = (GST_ELEMENT_GET_CLASS (element)->set_index != NULL);
@ -493,7 +493,8 @@ gst_element_is_indexable (GstElement * element)
* @element: a #GstElement. * @element: a #GstElement.
* @index: a #GstIndex. * @index: a #GstIndex.
* *
* Set the specified GstIndex on the element. * Set the specified GstIndex on the element. The refcount of the index
* will be increased, any previously set index is unreffed.
* *
* MT safe. * MT safe.
*/ */
@ -547,7 +548,8 @@ gst_element_get_index (GstElement * element)
* see gst_object_set_parent() for refcounting information. * see gst_object_set_parent() for refcounting information.
* *
* Pads are not automatically activated so elements should perform the needed * Pads are not automatically activated so elements should perform the needed
* steps to activate the pad. * steps to activate the pad in case this pad is added in the PAUSED or PLAYING
* state.
* *
* The pad and the element should be unlocked when calling this function. * The pad and the element should be unlocked when calling this function.
* *
@ -912,7 +914,7 @@ gst_element_get_pad (GstElement * element, const gchar * name)
return pad; return pad;
} }
GstIteratorItem static GstIteratorItem
iterate_pad (GstIterator * it, GstPad * pad) iterate_pad (GstIterator * it, GstPad * pad)
{ {
gst_object_ref (pad); gst_object_ref (pad);
@ -923,7 +925,8 @@ iterate_pad (GstIterator * it, GstPad * pad)
* gst_element_iterate_pads: * gst_element_iterate_pads:
* @element: a #GstElement to iterate pads of. * @element: a #GstElement to iterate pads of.
* *
* Retrieves an iterattor of @element's pads. * Retrieves an iterattor of @element's pads. The iterator should
* be freed after usage.
* *
* Returns: the #GstIterator of #GstPad. Unref each pad after use. * Returns: the #GstIterator of #GstPad. Unref each pad after use.
* *
@ -1488,7 +1491,7 @@ void gst_element_message_full
gboolean gboolean
gst_element_is_locked_state (GstElement * element) gst_element_is_locked_state (GstElement * element)
{ {
gboolean result = FALSE; gboolean result;
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE); g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
@ -2038,15 +2041,8 @@ gst_element_change_state (GstElement * element, GstStateChange transition)
pending = GST_STATE_PENDING (element); pending = GST_STATE_PENDING (element);
/* if the element already is in the given state, we just return success */ /* if the element already is in the given state, we just return success */
if (pending == GST_STATE_VOID_PENDING || state == GST_STATE_PENDING (element)) { if (pending == GST_STATE_VOID_PENDING || state == GST_STATE_PENDING (element))
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, goto was_ok;
"element is already in the %s state",
gst_element_state_get_name (state));
if (GST_STATE_NO_PREROLL (element))
return GST_STATE_CHANGE_NO_PREROLL;
else
return GST_STATE_CHANGE_SUCCESS;
}
GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, GST_CAT_LOG_OBJECT (GST_CAT_STATES, element,
"default handler tries setting state from %s to %s (%04x)", "default handler tries setting state from %s to %s (%04x)",
@ -2072,9 +2068,7 @@ gst_element_change_state (GstElement * element, GstStateChange transition)
if (!gst_element_pads_activate (element, FALSE)) { if (!gst_element_pads_activate (element, FALSE)) {
result = GST_STATE_CHANGE_FAILURE; result = GST_STATE_CHANGE_FAILURE;
} else { } else {
GST_LOCK (element); gst_element_set_base_time (element, 0);
element->base_time = 0;
GST_UNLOCK (element);
} }
break; break;
default: default:
@ -2088,8 +2082,19 @@ gst_element_change_state (GstElement * element, GstStateChange transition)
gst_element_state_get_name (pending)); gst_element_state_get_name (pending));
break; break;
} }
return result; return result;
was_ok:
{
GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
"element is already in the %s state",
gst_element_state_get_name (state));
if (GST_STATE_NO_PREROLL (element))
return GST_STATE_CHANGE_NO_PREROLL;
else
return GST_STATE_CHANGE_SUCCESS;
}
} }
/** /**
@ -2098,7 +2103,8 @@ gst_element_change_state (GstElement * element, GstStateChange transition)
* *
* Retrieves the factory that was used to create this element. * Retrieves the factory that was used to create this element.
* *
* Returns: the #GstElementFactory used for creating this element. * Returns: the #GstElementFactory used for creating this element.
* no refcounting is needed.
*/ */
GstElementFactory * GstElementFactory *
gst_element_get_factory (GstElement * element) gst_element_get_factory (GstElement * element)
@ -2298,7 +2304,7 @@ gst_element_set_bus_func (GstElement * element, GstBus * bus)
GST_LOCK (element); GST_LOCK (element);
gst_object_replace ((GstObject **) & GST_ELEMENT_BUS (element), gst_object_replace ((GstObject **) & GST_ELEMENT_BUS (element),
GST_OBJECT (bus)); GST_OBJECT_CAST (bus));
GST_UNLOCK (element); GST_UNLOCK (element);
} }

View file

@ -153,9 +153,14 @@ static void
gst_pipeline_init (GTypeInstance * instance, gpointer g_class) gst_pipeline_init (GTypeInstance * instance, gpointer g_class)
{ {
GstPipeline *pipeline = GST_PIPELINE (instance); GstPipeline *pipeline = GST_PIPELINE (instance);
GstBus *bus;
pipeline->delay = DEFAULT_DELAY; pipeline->delay = DEFAULT_DELAY;
pipeline->play_timeout = DEFAULT_PLAY_TIMEOUT; pipeline->play_timeout = DEFAULT_PLAY_TIMEOUT;
bus = g_object_new (gst_bus_get_type (), NULL);
gst_element_set_bus (GST_ELEMENT_CAST (pipeline), bus);
gst_object_unref (bus);
} }
static void static void

View file

@ -114,7 +114,8 @@ GST_START_TEST (test_message_state_changed)
fail_unless (bin != NULL, "Could not create bin"); fail_unless (bin != NULL, "Could not create bin");
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
bus = GST_ELEMENT_BUS (bin); bus = g_object_new (gst_bus_get_type (), NULL);
gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
/* change state, spawning a message, causing an incref on the bin */ /* change state, spawning a message, causing an incref on the bin */
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY); gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
@ -132,6 +133,7 @@ GST_START_TEST (test_message_state_changed)
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
/* clean up */ /* clean up */
gst_object_unref (bus);
gst_object_unref (bin); gst_object_unref (bin);
} }
@ -148,14 +150,15 @@ GST_START_TEST (test_message_state_changed_child)
fail_unless (bin != NULL, "Could not create bin"); fail_unless (bin != NULL, "Could not create bin");
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
bus = g_object_new (gst_bus_get_type (), NULL);
gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
fail_if (src == NULL, "Could not create fakesrc"); fail_if (src == NULL, "Could not create fakesrc");
gst_bin_add (bin, src); gst_bin_add (bin, src);
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
bus = GST_ELEMENT_BUS (bin);
/* change state, spawning two messages: /* change state, spawning two messages:
* - first for fakesrc, forwarded to bin's bus, causing incref on fakesrc * - first for fakesrc, forwarded to bin's bus, causing incref on fakesrc
* - second for bin, causing an incref on the bin */ * - second for bin, causing an incref on the bin */
@ -189,6 +192,7 @@ GST_START_TEST (test_message_state_changed_child)
ASSERT_OBJECT_REFCOUNT (bin, "bin", 1); ASSERT_OBJECT_REFCOUNT (bin, "bin", 1);
/* clean up */ /* clean up */
gst_object_unref (bus);
gst_object_unref (bin); gst_object_unref (bin);
} }
@ -224,7 +228,7 @@ GST_START_TEST (test_message_state_changed_children)
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1); ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
bus = GST_ELEMENT_BUS (pipeline); bus = gst_pipeline_get_bus (pipeline);
/* change state to READY, spawning three messages */ /* change state to READY, spawning three messages */
GST_DEBUG ("setting pipeline to READY"); GST_DEBUG ("setting pipeline to READY");
@ -232,7 +236,7 @@ GST_START_TEST (test_message_state_changed_children)
== GST_STATE_CHANGE_SUCCESS); == GST_STATE_CHANGE_SUCCESS);
/* each object is referenced by a message */ /* each object is referenced by a message */
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1); ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
ASSERT_OBJECT_REFCOUNT (src, "src", 2); ASSERT_OBJECT_REFCOUNT (src, "src", 2);
ASSERT_OBJECT_REFCOUNT (sink, "sink", 2); ASSERT_OBJECT_REFCOUNT (sink, "sink", 2);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 2); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 2);
@ -240,7 +244,7 @@ GST_START_TEST (test_message_state_changed_children)
pop_messages (bus, 3); pop_messages (bus, 3);
fail_if ((gst_bus_pop (bus)) != NULL); fail_if ((gst_bus_pop (bus)) != NULL);
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1); ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1); ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
@ -260,7 +264,7 @@ GST_START_TEST (test_message_state_changed_children)
pop_messages (bus, 3); pop_messages (bus, 3);
fail_if ((gst_bus_pop (bus)) != NULL); fail_if ((gst_bus_pop (bus)) != NULL);
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1); ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
ASSERT_OBJECT_REFCOUNT (sink, "sink", 2); ASSERT_OBJECT_REFCOUNT (sink, "sink", 2);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
@ -279,7 +283,7 @@ GST_START_TEST (test_message_state_changed_children)
pop_messages (bus, 3); pop_messages (bus, 3);
fail_if ((gst_bus_pop (bus)) != NULL); fail_if ((gst_bus_pop (bus)) != NULL);
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1); ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
ASSERT_OBJECT_REFCOUNT (src, "src", 1); ASSERT_OBJECT_REFCOUNT (src, "src", 1);
/* sink might have an extra reference if it's still blocked on preroll */ /* sink might have an extra reference if it's still blocked on preroll */
ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 1, 2); ASSERT_OBJECT_REFCOUNT_BETWEEN (sink, "sink", 1, 2);
@ -311,6 +315,7 @@ GST_START_TEST (test_message_state_changed_children)
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
/* clean up */ /* clean up */
gst_object_unref (bus);
gst_object_unref (pipeline); gst_object_unref (pipeline);
} }
@ -324,6 +329,9 @@ GST_START_TEST (test_watch_for_state_change)
bin = gst_element_factory_make ("bin", NULL); bin = gst_element_factory_make ("bin", NULL);
fail_unless (bin != NULL, "Could not create bin"); fail_unless (bin != NULL, "Could not create bin");
bus = g_object_new (gst_bus_get_type (), NULL);
gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
fail_if (src == NULL, "Could not create fakesrc"); fail_if (src == NULL, "Could not create fakesrc");
sink = gst_element_factory_make ("fakesink", NULL); sink = gst_element_factory_make ("fakesink", NULL);
@ -334,15 +342,13 @@ GST_START_TEST (test_watch_for_state_change)
fail_unless (gst_element_link (src, sink), "could not link src and sink"); fail_unless (gst_element_link (src, sink), "could not link src and sink");
bus = GST_ELEMENT_BUS (bin);
/* change state, spawning two times three messages, minus one async */ /* change state, spawning two times three messages, minus one async */
fail_unless (gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED) fail_unless (gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED)
== GST_STATE_CHANGE_ASYNC); == GST_STATE_CHANGE_ASYNC);
pop_messages (bus, 5); pop_messages (bus, 5);
fail_unless (gst_bus_have_pending (bus, GST_MESSAGE_ANY) == FALSE, fail_unless (gst_bus_have_pending (bus) == FALSE,
"Unexpected messages on bus"); "Unexpected messages on bus");
gst_bin_watch_for_state_change (GST_BIN (bin)); gst_bin_watch_for_state_change (GST_BIN (bin));
@ -350,7 +356,7 @@ GST_START_TEST (test_watch_for_state_change)
/* should get the bin's state change message now */ /* should get the bin's state change message now */
pop_messages (bus, 1); pop_messages (bus, 1);
fail_unless (gst_bus_have_pending (bus, GST_MESSAGE_ANY) == FALSE, fail_unless (gst_bus_have_pending (bus) == FALSE,
"Unexpected messages on bus"); "Unexpected messages on bus");
fail_unless (gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING) fail_unless (gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING)
@ -365,7 +371,7 @@ GST_START_TEST (test_watch_for_state_change)
pop_messages (bus, 3); pop_messages (bus, 3);
fail_unless (gst_bus_have_pending (bus, GST_MESSAGE_ANY) == FALSE, fail_unless (gst_bus_have_pending (bus) == FALSE,
"Unexpected messages on bus"); "Unexpected messages on bus");
/* setting bin to NULL flushes the bus automatically */ /* setting bin to NULL flushes the bus automatically */
@ -373,6 +379,7 @@ GST_START_TEST (test_watch_for_state_change)
== GST_STATE_CHANGE_SUCCESS); == GST_STATE_CHANGE_SUCCESS);
/* clean up */ /* clean up */
gst_object_unref (bus);
gst_object_unref (bin); gst_object_unref (bin);
} }
@ -458,7 +465,7 @@ GST_START_TEST (test_children_state_change_order_flagged_sink)
pipeline = gst_pipeline_new (NULL); pipeline = gst_pipeline_new (NULL);
fail_unless (pipeline != NULL, "Could not create pipeline"); fail_unless (pipeline != NULL, "Could not create pipeline");
bus = GST_ELEMENT_BUS (pipeline); bus = gst_element_get_bus (pipeline);
fail_unless (bus != NULL, "Pipeline has no bus?!"); fail_unless (bus != NULL, "Pipeline has no bus?!");
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
@ -531,6 +538,7 @@ GST_START_TEST (test_children_state_change_order_flagged_sink)
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1); ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
gst_object_unref (bus);
gst_object_unref (pipeline); gst_object_unref (pipeline);
} }
@ -548,7 +556,7 @@ GST_START_TEST (test_children_state_change_order_semi_sink)
pipeline = gst_pipeline_new (NULL); pipeline = gst_pipeline_new (NULL);
fail_unless (pipeline != NULL, "Could not create pipeline"); fail_unless (pipeline != NULL, "Could not create pipeline");
bus = GST_ELEMENT_BUS (pipeline); bus = gst_element_get_bus (pipeline);
fail_unless (bus != NULL, "Pipeline has no bus?!"); fail_unless (bus != NULL, "Pipeline has no bus?!");
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
@ -623,6 +631,7 @@ GST_START_TEST (test_children_state_change_order_semi_sink)
ASSERT_OBJECT_REFCOUNT (sink, "sink", 1); ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
gst_object_unref (bus);
gst_object_unref (pipeline); gst_object_unref (pipeline);
} }
@ -637,7 +646,7 @@ GST_START_TEST (test_children_state_change_order_two_sink)
pipeline = gst_pipeline_new (NULL); pipeline = gst_pipeline_new (NULL);
fail_unless (pipeline != NULL, "Could not create pipeline"); fail_unless (pipeline != NULL, "Could not create pipeline");
bus = GST_ELEMENT_BUS (pipeline); bus = gst_element_get_bus (pipeline);
fail_unless (bus != NULL, "Pipeline has no bus?!"); fail_unless (bus != NULL, "Pipeline has no bus?!");
src = gst_element_factory_make ("fakesrc", NULL); src = gst_element_factory_make ("fakesrc", NULL);
@ -718,6 +727,7 @@ GST_START_TEST (test_children_state_change_order_two_sink)
ASSERT_OBJECT_REFCOUNT (sink2, "sink2", 1); ASSERT_OBJECT_REFCOUNT (sink2, "sink2", 1);
ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1); ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
gst_object_unref (bus);
gst_object_unref (pipeline); gst_object_unref (pipeline);
} }