From fc5dc6de66bfc1e316f3f135c8e1139a23d8944b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 11 Oct 2005 12:58:44 +0000 Subject: [PATCH] gst/gstbin.*: Work on proper clock selection. Original commit message from CVS: * gst/gstbin.c: (gst_bin_init), (gst_bin_provide_clock_func), (gst_bin_add_func), (gst_bin_remove_func), (gst_bin_recalc_state), (gst_bin_change_state_func), (bin_bus_handler): * gst/gstbin.h: Work on proper clock selection. --- ChangeLog | 8 ++++++++ common | 2 +- gst/gstbin.c | 39 +++++++++++++++++++++++++++++++++++---- gst/gstbin.h | 3 +++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08b1b11cf4..003adcd693 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-10-11 Wim Taymans + + * gst/gstbin.c: (gst_bin_init), (gst_bin_provide_clock_func), + (gst_bin_add_func), (gst_bin_remove_func), (gst_bin_recalc_state), + (gst_bin_change_state_func), (bin_bus_handler): + * gst/gstbin.h: + Work on proper clock selection. + 2005-10-11 Edward Hervey * libs/gst/controller/gstcontroller.c: (gst_controller_remove_properties_list): diff --git a/common b/common index 54920e38c6..615cf4d450 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 54920e38c65eaf03ea52c21b14a6d104a56581a9 +Subproject commit 615cf4d4506ef1ffb1f600c434fced1fa26b0f44 diff --git a/gst/gstbin.c b/gst/gstbin.c index 1f9bfa6925..bc14c6c0cc 100644 --- a/gst/gstbin.c +++ b/gst/gstbin.c @@ -289,6 +289,8 @@ gst_bin_init (GstBin * bin) bin->eosed = NULL; bin->polling = FALSE; bin->state_dirty = FALSE; + bin->provided_clock = NULL; + bin->clock_dirty = FALSE; /* Set up a bus for listening to child elements */ bus = g_object_new (gst_bus_get_type (), NULL); @@ -361,8 +363,11 @@ gst_bin_set_clock_func (GstElement * element, GstClock * clock) * The ref of the returned clock in increased so unref after usage. * * MT safe - * - * FIXME, clock selection is not correct here. + */ +/* + * FIXME, clock selection is not correct here. We should loop the + * elements in state order and pick the last clock we can get. This + * makes sure we get a clock from the source. */ static GstClock * gst_bin_provide_clock_func (GstElement * element) @@ -374,16 +379,32 @@ gst_bin_provide_clock_func (GstElement * element) bin = GST_BIN (element); GST_LOCK (bin); + if (!bin->clock_dirty) + goto not_dirty; + for (children = bin->children; children; children = g_list_next (children)) { GstElement *child = GST_ELEMENT (children->data); - result = gst_element_provide_clock (child); - if (result) + if ((result = gst_element_provide_clock (child))) break; } + gst_object_replace ((GstObject **) & bin->provided_clock, + (GstObject *) result); + bin->clock_dirty = FALSE; + GST_DEBUG_OBJECT (bin, "provided new clock %p", result); GST_UNLOCK (bin); return result; + +not_dirty: + { + if ((result = bin->provided_clock)) + gst_object_ref (result); + GST_DEBUG_OBJECT (bin, "returning old clock %p", result); + GST_UNLOCK (bin); + + return result; + } } /* Check if the bin is EOS. We do this by scanning all sinks and @@ -468,6 +489,11 @@ gst_bin_add_func (GstBin * bin, GstElement * element) elem_name); GST_FLAG_SET (bin, GST_ELEMENT_IS_SINK); } + if (gst_element_provides_clock (element)) { + GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, + "element \"%s\" can provide a clock", elem_name); + bin->clock_dirty = TRUE; + } bin->children = g_list_prepend (bin->children, element); bin->numchildren++; @@ -618,6 +644,11 @@ gst_bin_remove_func (GstBin * bin, GstElement * element) GST_FLAG_UNSET (bin, GST_ELEMENT_IS_SINK); } } + if (gst_element_provides_clock (element)) { + GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, + "element \"%s\" could provide a clock", elem_name); + bin->clock_dirty = TRUE; + } bin->state_dirty = TRUE; GST_UNLOCK (bin); diff --git a/gst/gstbin.h b/gst/gstbin.h index e90066fd2b..7d8a8425c2 100644 --- a/gst/gstbin.h +++ b/gst/gstbin.h @@ -95,6 +95,9 @@ struct _GstBin { gboolean polling; gboolean state_dirty; + gboolean clock_dirty; + GstClock *provided_clock; + /*< private >*/ gpointer _gst_reserved[GST_PADDING]; };