From ae25867a053a6a8f36f25dc6c251ff8129416694 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sat, 8 Oct 2005 18:01:04 +0000 Subject: [PATCH] gst/gstbin.c: Fix typos, add comments. Original commit message from CVS: * gst/gstbin.c: (is_eos), (update_degree), (gst_bin_change_state), (gst_bin_dispose), (bin_bus_handler): Fix typos, add comments. Clear EOS list when going to PAUSED from any direction and do it in a threadsafe way. Get base time in a threadsafe way too. Fix confusing debug in the change_state function. Various other mall cleanups. * gst/gstelement.c: (gst_element_post_message): Fix very verbose bus posting code. * gst/gstpipeline.c: (gst_pipeline_class_init), (gst_pipeline_set_property), (gst_pipeline_get_property), (gst_pipeline_change_state): Small ARG_ -> PROP_ cleanup --- ChangeLog | 19 +++++++++++++++++++ gst/gstbin.c | 55 ++++++++++++++++++++++++++++++------------------------- gst/gstelement.c | 20 +++++++++++--------- gst/gstpipeline.c | 18 +++++++++--------- 4 files changed, 69 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 77af308..77f2f69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,24 @@ 2005-10-08 Wim Taymans + * gst/gstbin.c: (is_eos), (update_degree), (gst_bin_change_state), + (gst_bin_dispose), (bin_bus_handler): + Fix typos, add comments. + Clear EOS list when going to PAUSED from any direction and do it + in a threadsafe way. + Get base time in a threadsafe way too. + Fix confusing debug in the change_state function. + Various other mall cleanups. + + * gst/gstelement.c: (gst_element_post_message): + Fix very verbose bus posting code. + + * gst/gstpipeline.c: (gst_pipeline_class_init), + (gst_pipeline_set_property), (gst_pipeline_get_property), + (gst_pipeline_change_state): + Small ARG_ -> PROP_ cleanup + +2005-10-08 Wim Taymans + * gst/gstbin.c: (is_eos), (bin_bus_handler): Do a less CPU demanding EOS check because we can. diff --git a/gst/gstbin.c b/gst/gstbin.c index 554c4f3..9cfe365 100644 --- a/gst/gstbin.c +++ b/gst/gstbin.c @@ -1133,7 +1133,7 @@ update_degree (GstElement * element, GstBinSortIterator * bit) gboolean linked = FALSE; GST_LOCK (element); - /* don't touch degree is element has no sourcepads */ + /* don't touch degree if element has no sourcepads */ if (element->numsinkpads != 0) { /* loop over all sinkpads, decrement degree for all connected * elements in this bin */ @@ -1147,6 +1147,7 @@ update_degree (GstElement * element, GstBinSortIterator * bit) if ((peer_element = gst_pad_get_parent_element (peer))) { GST_LOCK (peer_element); + /* check that we don't go outside of this bin */ if (GST_OBJECT_CAST (peer_element)->parent == GST_OBJECT_CAST (bit->bin)) { gint old_deg, new_deg; @@ -1175,7 +1176,8 @@ update_degree (GstElement * element, GstBinSortIterator * bit) } } if (!linked) { - GST_DEBUG ("element %s not linked to anything", GST_ELEMENT_NAME (element)); + GST_DEBUG ("element %s not linked on any sinkpads", + GST_ELEMENT_NAME (element)); } GST_UNLOCK (element); } @@ -1357,10 +1359,13 @@ gst_bin_change_state (GstElement * element, GstStateChange transition) bin = GST_BIN_CAST (element); - /* Clear eosed element list on READY-> PAUSED */ - if (transition == GST_STATE_CHANGE_READY_TO_PAUSED) { + /* Clear eosed element list on -> PAUSED */ + if (transition == GST_STATE_CHANGE_READY_TO_PAUSED || + transition == GST_STATE_CHANGE_PLAYING_TO_PAUSED) { + GST_LOCK (bin); g_list_free (bin->eosed); bin->eosed = NULL; + GST_UNLOCK (bin); } /* iterate in state change order */ @@ -1368,7 +1373,7 @@ gst_bin_change_state (GstElement * element, GstStateChange transition) restart: /* take base time */ - base_time = element->base_time; + base_time = gst_element_get_base_time (element); have_async = FALSE; have_no_preroll = FALSE; @@ -1380,40 +1385,40 @@ restart: switch (gst_iterator_next (it, &data)) { case GST_ITERATOR_OK: { - GstElement *element; + GstElement *child; - element = GST_ELEMENT_CAST (data); + child = GST_ELEMENT_CAST (data); /* set base time on element */ - gst_element_set_base_time (element, base_time); + gst_element_set_base_time (child, base_time); /* set state now */ - ret = gst_bin_element_set_state (bin, element, pending); + ret = gst_bin_element_set_state (bin, child, pending); switch (ret) { case GST_STATE_CHANGE_SUCCESS: - GST_CAT_DEBUG (GST_CAT_STATES, + GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "child '%s' changed state to %d(%s) successfully", - GST_ELEMENT_NAME (element), pending, + GST_ELEMENT_NAME (child), pending, gst_element_state_get_name (pending)); break; case GST_STATE_CHANGE_ASYNC: GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "child '%s' is changing state asynchronously", - GST_ELEMENT_NAME (element)); + GST_ELEMENT_NAME (child)); have_async = TRUE; break; case GST_STATE_CHANGE_FAILURE: GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "child '%s' failed to go to state %d(%s)", - GST_ELEMENT_NAME (element), + GST_ELEMENT_NAME (child), pending, gst_element_state_get_name (pending)); - gst_object_unref (element); + gst_object_unref (child); goto done; case GST_STATE_CHANGE_NO_PREROLL: - GST_CAT_DEBUG (GST_CAT_STATES, + GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "child '%s' changed state to %d(%s) successfully without preroll", - GST_ELEMENT_NAME (element), pending, + GST_ELEMENT_NAME (child), pending, gst_element_state_get_name (pending)); have_no_preroll = TRUE; break; @@ -1421,7 +1426,7 @@ restart: g_assert_not_reached (); break; } - gst_object_unref (element); + gst_object_unref (child); break; } case GST_ITERATOR_RESYNC: @@ -1446,14 +1451,14 @@ restart: } done: + gst_iterator_free (it); + GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "done changing bin's state from %s to %s, now in %s, ret %d", gst_element_state_get_name (old_state), gst_element_state_get_name (pending), gst_element_state_get_name (GST_STATE (element)), ret); - gst_iterator_free (it); - return ret; } @@ -1470,7 +1475,7 @@ gst_bin_dispose (GObject * object) bin->child_bus = NULL; while (bin->children) { - gst_bin_remove (bin, GST_ELEMENT (bin->children->data)); + gst_bin_remove (bin, GST_ELEMENT_CAST (bin->children->data)); } if (G_UNLIKELY (bin->children != NULL)) { g_critical ("could not remove elements from bin %s", @@ -1547,16 +1552,16 @@ bin_bus_handler (GstBus * bus, GstMessage * message, GstBin * bin) g_free (name); /* collect all eos messages from the children */ - GST_LOCK (bin->child_bus); + GST_LOCK (bin); bin->eosed = g_list_prepend (bin->eosed, src); eos = is_eos (bin); - GST_UNLOCK (bin->child_bus); + GST_UNLOCK (bin); /* if we are completely EOS, we forward an EOS message */ if (eos) { GST_DEBUG_OBJECT (bin, "all sinks posted EOS"); - gst_element_post_message (GST_ELEMENT (bin), - gst_message_new_eos (GST_OBJECT (bin))); + gst_element_post_message (GST_ELEMENT_CAST (bin), + gst_message_new_eos (GST_OBJECT_CAST (bin))); } } else { GST_DEBUG_OBJECT (bin, "got EOS message from (NULL), not processing"); @@ -1568,7 +1573,7 @@ bin_bus_handler (GstBus * bus, GstMessage * message, GstBin * bin) default: /* Send all other messages upward */ GST_DEBUG_OBJECT (bin, "posting message upward"); - gst_element_post_message (GST_ELEMENT (bin), message); + gst_element_post_message (GST_ELEMENT_CAST (bin), message); break; } diff --git a/gst/gstelement.c b/gst/gstelement.c index e439101..6a72afc 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -1347,28 +1347,30 @@ gst_element_post_message (GstElement * element, GstMessage * message) GstBus *bus; gboolean result = FALSE; - GST_DEBUG ("posting message %p ...", message); - g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE); g_return_val_if_fail (message != NULL, FALSE); GST_LOCK (element); bus = element->bus; - if (G_UNLIKELY (bus == NULL)) { - GST_DEBUG ("... but I won't because I have no bus"); - GST_UNLOCK (element); - gst_message_unref (message); - return FALSE; - } + if (G_UNLIKELY (bus == NULL)) + goto no_bus; + gst_object_ref (bus); - GST_DEBUG ("... on bus %" GST_PTR_FORMAT, bus); GST_UNLOCK (element); result = gst_bus_post (bus, message); gst_object_unref (bus); return result; + +no_bus: + { + GST_DEBUG ("not posting message %p: no bus", message); + GST_UNLOCK (element); + gst_message_unref (message); + return FALSE; + } } /** diff --git a/gst/gstpipeline.c b/gst/gstpipeline.c index db7683a..709e610 100644 --- a/gst/gstpipeline.c +++ b/gst/gstpipeline.c @@ -57,9 +57,9 @@ enum #define DEFAULT_PLAY_TIMEOUT (2*GST_SECOND) enum { - ARG_0, - ARG_DELAY, - ARG_PLAY_TIMEOUT, + PROP_0, + PROP_DELAY, + PROP_PLAY_TIMEOUT, /* FILL ME */ }; @@ -130,12 +130,12 @@ gst_pipeline_class_init (gpointer g_class, gpointer class_data) gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_pipeline_set_property); gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_pipeline_get_property); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DELAY, + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DELAY, g_param_spec_uint64 ("delay", "Delay", "Expected delay needed for elements " "to spin up to PLAYING in nanoseconds", 0, G_MAXUINT64, DEFAULT_DELAY, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PLAY_TIMEOUT, + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PLAY_TIMEOUT, g_param_spec_uint64 ("play-timeout", "Play Timeout", "Max timeout for going to PLAYING in nanoseconds", 0, G_MAXUINT64, DEFAULT_PLAY_TIMEOUT, G_PARAM_READWRITE)); @@ -183,10 +183,10 @@ gst_pipeline_set_property (GObject * object, guint prop_id, GST_LOCK (pipeline); switch (prop_id) { - case ARG_DELAY: + case PROP_DELAY: pipeline->delay = g_value_get_uint64 (value); break; - case ARG_PLAY_TIMEOUT: + case PROP_PLAY_TIMEOUT: pipeline->play_timeout = g_value_get_uint64 (value); break; default: @@ -204,10 +204,10 @@ gst_pipeline_get_property (GObject * object, guint prop_id, GST_LOCK (pipeline); switch (prop_id) { - case ARG_DELAY: + case PROP_DELAY: g_value_set_uint64 (value, pipeline->delay); break; - case ARG_PLAY_TIMEOUT: + case PROP_PLAY_TIMEOUT: g_value_set_uint64 (value, pipeline->play_timeout); break; default: -- 2.7.4