docs: convert NULL, TRUE, and FALSE to %NULL, %TRUE, and %FALSE
[platform/upstream/gstreamer.git] / gst / gstpipeline.c
index b032c2f..21e0620 100644 (file)
@@ -16,8 +16,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -29,8 +29,7 @@
  * A #GstPipeline is a special #GstBin used as the toplevel container for
  * the filter graph. The #GstPipeline will manage the selection and
  * distribution of a global #GstClock as well as provide a #GstBus to the
- * application. It will also implement a default behaviour for managing
- * seek events (see gst_element_seek()).
+ * application.
  *
  * gst_pipeline_new() is used to create a pipeline. when you are done with
  * the pipeline, use gst_object_unref() to free its resources including all
  * between the clock time and the base time) will count how much time was spent
  * in the PLAYING state. This default behaviour can be changed with the
  * gst_element_set_start_time() method.
- *
- * When sending a flushing seek event to a GstPipeline (see
- * gst_element_seek()), it will make sure that the pipeline is properly
- * PAUSED and resumed as well as set the new running time to 0 when the
- * seek succeeded.
- *
- * Last reviewed on 2009-05-29 (0.10.24)
  */
 
 #include "gst_private.h"
@@ -139,25 +131,14 @@ static void gst_pipeline_handle_message (GstBin * bin, GstMessage * message);
 
 /* static guint gst_pipeline_signals[LAST_SIGNAL] = { 0 }; */
 
-#define _do_init(type) \
+#define _do_init \
 { \
   GST_DEBUG_CATEGORY_INIT (pipeline_debug, "pipeline", GST_DEBUG_BOLD, \
       "debugging info for the 'pipeline' container element"); \
 }
 
-GST_BOILERPLATE_FULL (GstPipeline, gst_pipeline, GstBin, GST_TYPE_BIN,
-    _do_init);
-
-static void
-gst_pipeline_base_init (gpointer g_class)
-{
-  GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
-
-  gst_element_class_set_details_simple (gstelement_class, "Pipeline object",
-      "Generic/Bin",
-      "Complete pipeline object",
-      "Erik Walthinsen <omega@cse.ogi.edu>, Wim Taymans <wim@fluendo.com>");
-}
+#define gst_pipeline_parent_class parent_class
+G_DEFINE_TYPE_WITH_CODE (GstPipeline, gst_pipeline, GST_TYPE_BIN, _do_init);
 
 static void
 gst_pipeline_class_init (GstPipelineClass * klass)
@@ -172,13 +153,11 @@ gst_pipeline_class_init (GstPipelineClass * klass)
   gobject_class->get_property = gst_pipeline_get_property;
 
   /**
-   * GstPipeline:delay
+   * GstPipeline:delay:
    *
    * The expected delay needed for elements to spin up to the
    * PLAYING state expressed in nanoseconds.
    * see gst_pipeline_set_delay() for more information on this option.
-   *
-   * Since: 0.10.5
    **/
   g_object_class_install_property (gobject_class, PROP_DELAY,
       g_param_spec_uint64 ("delay", "Delay",
@@ -192,8 +171,6 @@ gst_pipeline_class_init (GstPipelineClass * klass)
    * Whether or not to automatically flush all messages on the
    * pipeline's bus when going from READY to NULL state. Please see
    * gst_pipeline_set_auto_flush_bus() for more information on this option.
-   *
-   * Since: 0.10.4
    **/
   g_object_class_install_property (gobject_class, PROP_AUTO_FLUSH_BUS,
       g_param_spec_boolean ("auto-flush-bus", "Auto Flush Bus",
@@ -203,6 +180,11 @@ gst_pipeline_class_init (GstPipelineClass * klass)
 
   gobject_class->dispose = gst_pipeline_dispose;
 
+  gst_element_class_set_static_metadata (gstelement_class, "Pipeline object",
+      "Generic/Bin",
+      "Complete pipeline object",
+      "Erik Walthinsen <omega@cse.ogi.edu>, Wim Taymans <wim@fluendo.com>");
+
   gstelement_class->change_state =
       GST_DEBUG_FUNCPTR (gst_pipeline_change_state);
   gstelement_class->provide_clock =
@@ -212,7 +194,7 @@ gst_pipeline_class_init (GstPipelineClass * klass)
 }
 
 static void
-gst_pipeline_init (GstPipeline * pipeline, GstPipelineClass * klass)
+gst_pipeline_init (GstPipeline * pipeline)
 {
   GstBus *bus;
 
@@ -291,12 +273,12 @@ gst_pipeline_get_property (GObject * object, guint prop_id,
 /* set the start_time to 0, this will cause us to select a new base_time and
  * make the running_time start from 0 again. */
 static void
-reset_start_time (GstPipeline * pipeline)
+reset_start_time (GstPipeline * pipeline, GstClockTime start_time)
 {
   GST_OBJECT_LOCK (pipeline);
   if (GST_ELEMENT_START_TIME (pipeline) != GST_CLOCK_TIME_NONE) {
     GST_DEBUG_OBJECT (pipeline, "reset start_time to 0");
-    GST_ELEMENT_START_TIME (pipeline) = 0;
+    GST_ELEMENT_START_TIME (pipeline) = start_time;
     pipeline->priv->last_start_time = -1;
   } else {
     GST_DEBUG_OBJECT (pipeline, "application asked to not reset stream_time");
@@ -306,11 +288,11 @@ reset_start_time (GstPipeline * pipeline)
 
 /**
  * gst_pipeline_new:
- * @name: name of new pipeline
+ * @name: (allow-none): name of new pipeline
  *
  * Create a new pipeline with the given name.
  *
- * Returns: (transfer full): newly created GstPipeline
+ * Returns: (transfer floating): newly created GstPipeline
  *
  * MT safe.
  */
@@ -408,7 +390,9 @@ gst_pipeline_change_state (GstElement * element, GstStateChange transition)
 
       /* running time changed, either with a PAUSED or a flush, we need to check
        * if there is a new clock & update the base time */
-      if (update_clock || last_start_time != start_time) {
+      /* only do this for top-level, however */
+      if (GST_OBJECT_PARENT (element) == NULL &&
+          (update_clock || last_start_time != start_time)) {
         GST_DEBUG_OBJECT (pipeline, "Need to update start_time");
 
         /* when going to PLAYING, select a clock when needed. If we just got
@@ -419,7 +403,10 @@ gst_pipeline_change_state (GstElement * element, GstStateChange transition)
         } else {
           GST_DEBUG_OBJECT (pipeline,
               "Don't need to update clock, using old clock.");
-          clock = gst_object_ref (cur_clock);
+          /* only try to ref if cur_clock is not NULL */
+          if (cur_clock)
+            gst_object_ref (cur_clock);
+          clock = cur_clock;
         }
 
         if (clock) {
@@ -486,7 +473,8 @@ gst_pipeline_change_state (GstElement * element, GstStateChange transition)
       break;
     case GST_STATE_CHANGE_READY_TO_PAUSED:
     {
-      reset_start_time (pipeline);
+      /* READY to PAUSED starts running_time from 0 */
+      reset_start_time (pipeline, 0);
       break;
     }
     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
@@ -554,17 +542,15 @@ gst_pipeline_handle_message (GstBin * bin, GstMessage * message)
   GstPipeline *pipeline = GST_PIPELINE_CAST (bin);
 
   switch (GST_MESSAGE_TYPE (message)) {
-    case GST_MESSAGE_ASYNC_START:
+    case GST_MESSAGE_RESET_TIME:
     {
-      gboolean new_base_time;
+      GstClockTime running_time;
 
-      gst_message_parse_async_start (message, &new_base_time);
+      gst_message_parse_reset_time (message, &running_time);
 
       /* reset our running time if we need to distribute a new base_time to the
        * children. */
-      if (new_base_time)
-        reset_start_time (pipeline);
-
+      reset_start_time (pipeline, running_time);
       break;
     }
     case GST_MESSAGE_CLOCK_LOST:
@@ -604,80 +590,6 @@ gst_pipeline_get_bus (GstPipeline * pipeline)
   return gst_element_get_bus (GST_ELEMENT_CAST (pipeline));
 }
 
-/**
- * gst_pipeline_set_new_stream_time:
- * @pipeline: a #GstPipeline
- * @time: the new running time to set
- *
- * Set the new start time of @pipeline to @time. The start time is used to
- * set the base time on the elements (see gst_element_set_base_time())
- * in the PAUSED->PLAYING state transition.
- *
- * Setting @time to #GST_CLOCK_TIME_NONE will disable the pipeline's management
- * of element base time. The application will then be responsible for
- * performing base time distribution. This is sometimes useful if you want to
- * synchronize capture from multiple pipelines, and you can also ensure that the
- * pipelines have the same clock.
- *
- * MT safe.
- *
- * Deprecated: This function has the wrong name and is equivalent to
- * gst_element_set_start_time(). 
- */
-#ifndef GST_REMOVE_DEPRECATED
-#ifdef GST_DISABLE_DEPRECATED
-void
-gst_pipeline_set_new_stream_time (GstPipeline * pipeline, GstClockTime time);
-#endif
-void
-gst_pipeline_set_new_stream_time (GstPipeline * pipeline, GstClockTime time)
-{
-  g_return_if_fail (GST_IS_PIPELINE (pipeline));
-
-  gst_element_set_start_time (GST_ELEMENT_CAST (pipeline), time);
-
-  if (time == GST_CLOCK_TIME_NONE)
-    GST_DEBUG_OBJECT (pipeline, "told not to adjust base_time");
-}
-#endif /* GST_REMOVE_DEPRECATED */
-
-/**
- * gst_pipeline_get_last_stream_time:
- * @pipeline: a #GstPipeline
- *
- * Gets the last running time of @pipeline. If the pipeline is PLAYING,
- * the returned time is the running time used to configure the element's
- * base time in the PAUSED->PLAYING state. If the pipeline is PAUSED, the
- * returned time is the running time when the pipeline was paused.
- *
- * This function returns #GST_CLOCK_TIME_NONE if the pipeline was
- * configured to not handle the management of the element's base time
- * (see gst_pipeline_set_new_stream_time()).
- *
- * MT safe.
- *
- * Returns: a #GstClockTime.
- *
- * Deprecated: This function has the wrong name and is equivalent to
- * gst_element_get_start_time(). 
- */
-#ifndef GST_REMOVE_DEPRECATED
-#ifdef GST_DISABLE_DEPRECATED
-GstClockTime gst_pipeline_get_last_stream_time (GstPipeline * pipeline);
-#endif
-GstClockTime
-gst_pipeline_get_last_stream_time (GstPipeline * pipeline)
-{
-  GstClockTime result;
-
-  g_return_val_if_fail (GST_IS_PIPELINE (pipeline), GST_CLOCK_TIME_NONE);
-
-  result = gst_element_get_start_time (GST_ELEMENT_CAST (pipeline));
-
-  return result;
-}
-#endif /* GST_REMOVE_DEPRECATED */
-
 static GstClock *
 gst_pipeline_provide_clock_func (GstElement * element)
 {
@@ -734,13 +646,13 @@ gst_pipeline_get_clock (GstPipeline * pipeline)
 /**
  * gst_pipeline_use_clock:
  * @pipeline: a #GstPipeline
- * @clock: (transfer none): the clock to use
+ * @clock: (transfer none) (allow-none): the clock to use
  *
  * Force @pipeline to use the given @clock. The pipeline will
  * always use the given clock even if new clock providers are added
  * to this pipeline.
  *
- * If @clock is NULL all clocking will be disabled which will make
+ * If @clock is %NULL all clocking will be disabled which will make
  * the pipeline run as fast as possible.
  *
  * MT safe.
@@ -771,7 +683,7 @@ gst_pipeline_use_clock (GstPipeline * pipeline, GstClock * clock)
  * Set the clock for @pipeline. The clock will be distributed
  * to all the elements managed by the pipeline.
  *
- * Returns: TRUE if the clock could be set on the pipeline. FALSE if
+ * Returns: %TRUE if the clock could be set on the pipeline. %FALSE if
  *   some element did not accept the clock.
  *
  * MT safe.
@@ -833,8 +745,6 @@ gst_pipeline_auto_clock (GstPipeline * pipeline)
  * used.
  *
  * MT safe.
- *
- * Since: 0.10.5
  */
 void
 gst_pipeline_set_delay (GstPipeline * pipeline, GstClockTime delay)
@@ -856,8 +766,6 @@ gst_pipeline_set_delay (GstPipeline * pipeline, GstClockTime delay)
  * Returns: The configured delay.
  *
  * MT safe.
- *
- * Since: 0.10.5
  */
 GstClockTime
 gst_pipeline_get_delay (GstPipeline * pipeline)
@@ -893,8 +801,6 @@ gst_pipeline_get_delay (GstPipeline * pipeline)
  * automatic flushing is disabled else memory leaks will be introduced.
  *
  * MT safe.
- *
- * Since: 0.10.4
  */
 void
 gst_pipeline_set_auto_flush_bus (GstPipeline * pipeline, gboolean auto_flush)
@@ -917,8 +823,6 @@ gst_pipeline_set_auto_flush_bus (GstPipeline * pipeline, gboolean auto_flush)
  * going from READY to NULL state or not.
  *
  * MT safe.
- *
- * Since: 0.10.4
  */
 gboolean
 gst_pipeline_get_auto_flush_bus (GstPipeline * pipeline)