2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2004,2005 Wim Taymans <wim@fluendo.com>
5 * gstpipeline.c: Overall pipeline management element
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 * @short_description: Top-level bin with clocking and bus management
28 * @see_also: #GstElement, #GstBin, #GstClock, #GstBus
30 * A #GstPipeline is a special #GstBin used as the toplevel container for
31 * the filter graph. The #GstPipeline will manage the selection and
32 * distribution of a global #GstClock as well as provide a #GstBus to the
35 * gst_pipeline_new() is used to create a pipeline. when you are done with
36 * the pipeline, use gst_object_unref() to free its resources including all
37 * added #GstElement objects (if not otherwise referenced).
39 * Elements are added and removed from the pipeline using the #GstBin
40 * methods like gst_bin_add() and gst_bin_remove() (see #GstBin).
42 * Before changing the state of the #GstPipeline (see #GstElement) a #GstBus
43 * can be retrieved with gst_pipeline_get_bus(). This bus can then be
44 * used to receive #GstMessage from the elements in the pipeline.
46 * By default, a #GstPipeline will automatically flush the pending #GstBus
47 * messages when going to the NULL state to ensure that no circular
48 * references exist when no messages are read from the #GstBus. This
49 * behaviour can be changed with gst_pipeline_set_auto_flush_bus().
51 * When the #GstPipeline performs the PAUSED to PLAYING state change it will
52 * select a clock for the elements. The clock selection algorithm will by
53 * default select a clock provided by an element that is most upstream
54 * (closest to the source). For live pipelines (ones that return
55 * #GST_STATE_CHANGE_NO_PREROLL from the gst_element_set_state() call) this
56 * will select the clock provided by the live source. For normal pipelines
57 * this will select a clock provided by the sinks (most likely the audio
58 * sink). If no element provides a clock, a default #GstSystemClock is used.
60 * The clock selection can be controlled with the gst_pipeline_use_clock()
61 * method, which will enforce a given clock on the pipeline. With
62 * gst_pipeline_auto_clock() the default clock selection algorithm can be
65 * A #GstPipeline maintains a running time for the elements. The running
66 * time is defined as the difference between the current clock time and
67 * the base time. When the pipeline goes to READY or a flushing seek is
68 * performed on it, the running time is reset to 0. When the pipeline is
69 * set from PLAYING to PAUSED, the current clock time is sampled and used to
70 * configure the base time for the elements when the pipeline is set
71 * to PLAYING again. The effect is that the running time (as the difference
72 * between the clock time and the base time) will count how much time was spent
73 * in the PLAYING state. This default behaviour can be changed with the
74 * gst_element_set_start_time() method.
77 #include "gst_private.h"
79 #include "gst-i18n-lib.h"
81 #include "gstpipeline.h"
83 #include "gstsystemclock.h"
86 GST_DEBUG_CATEGORY_STATIC (pipeline_debug);
87 #define GST_CAT_DEFAULT pipeline_debug
89 /* Pipeline signals and args */
96 #define DEFAULT_DELAY 0
97 #define DEFAULT_AUTO_FLUSH_BUS TRUE
98 #define DEFAULT_LATENCY GST_CLOCK_TIME_NONE
108 struct _GstPipelinePrivate
111 gboolean auto_flush_bus;
113 /* when we need to update stream_time or clock when going back to
115 GstClockTime last_start_time;
116 gboolean update_clock;
118 GstClockTime latency;
122 static void gst_pipeline_dispose (GObject * object);
123 static void gst_pipeline_set_property (GObject * object, guint prop_id,
124 const GValue * value, GParamSpec * pspec);
125 static void gst_pipeline_get_property (GObject * object, guint prop_id,
126 GValue * value, GParamSpec * pspec);
128 static GstClock *gst_pipeline_provide_clock_func (GstElement * element);
129 static GstStateChangeReturn gst_pipeline_change_state (GstElement * element,
130 GstStateChange transition);
132 static void gst_pipeline_handle_message (GstBin * bin, GstMessage * message);
133 static gboolean gst_pipeline_do_latency (GstBin * bin);
135 /* static guint gst_pipeline_signals[LAST_SIGNAL] = { 0 }; */
139 GST_DEBUG_CATEGORY_INIT (pipeline_debug, "pipeline", GST_DEBUG_BOLD, \
140 "debugging info for the 'pipeline' container element"); \
143 #define gst_pipeline_parent_class parent_class
144 G_DEFINE_TYPE_WITH_CODE (GstPipeline, gst_pipeline, GST_TYPE_BIN,
145 G_ADD_PRIVATE (GstPipeline) _do_init);
148 gst_pipeline_class_init (GstPipelineClass * klass)
150 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
151 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
152 GstBinClass *gstbin_class = GST_BIN_CLASS (klass);
154 gobject_class->set_property = gst_pipeline_set_property;
155 gobject_class->get_property = gst_pipeline_get_property;
160 * The expected delay needed for elements to spin up to the
161 * PLAYING state expressed in nanoseconds.
162 * see gst_pipeline_set_delay() for more information on this option.
164 g_object_class_install_property (gobject_class, PROP_DELAY,
165 g_param_spec_uint64 ("delay", "Delay",
166 "Expected delay needed for elements "
167 "to spin up to PLAYING in nanoseconds", 0, G_MAXUINT64, DEFAULT_DELAY,
168 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
171 * GstPipeline:auto-flush-bus:
173 * Whether or not to automatically flush all messages on the
174 * pipeline's bus when going from READY to NULL state. Please see
175 * gst_pipeline_set_auto_flush_bus() for more information on this option.
177 g_object_class_install_property (gobject_class, PROP_AUTO_FLUSH_BUS,
178 g_param_spec_boolean ("auto-flush-bus", "Auto Flush Bus",
179 "Whether to automatically flush the pipeline's bus when going "
180 "from READY into NULL state", DEFAULT_AUTO_FLUSH_BUS,
181 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
184 * GstPipeline:latency:
186 * Latency to configure on the pipeline. See gst_pipeline_set_latency().
190 g_object_class_install_property (gobject_class, PROP_LATENCY,
191 g_param_spec_uint64 ("latency", "Latency",
192 "Latency to configure on the pipeline", 0, G_MAXUINT64,
193 DEFAULT_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
195 gobject_class->dispose = gst_pipeline_dispose;
197 gst_element_class_set_static_metadata (gstelement_class, "Pipeline object",
199 "Complete pipeline object",
200 "Erik Walthinsen <omega@cse.ogi.edu>, Wim Taymans <wim@fluendo.com>");
202 gstelement_class->change_state =
203 GST_DEBUG_FUNCPTR (gst_pipeline_change_state);
204 gstelement_class->provide_clock =
205 GST_DEBUG_FUNCPTR (gst_pipeline_provide_clock_func);
206 gstbin_class->handle_message =
207 GST_DEBUG_FUNCPTR (gst_pipeline_handle_message);
208 gstbin_class->do_latency = GST_DEBUG_FUNCPTR (gst_pipeline_do_latency);
212 gst_pipeline_init (GstPipeline * pipeline)
216 pipeline->priv = gst_pipeline_get_instance_private (pipeline);
218 /* set default property values */
219 pipeline->priv->auto_flush_bus = DEFAULT_AUTO_FLUSH_BUS;
220 pipeline->delay = DEFAULT_DELAY;
221 pipeline->priv->latency = DEFAULT_LATENCY;
223 /* create and set a default bus */
224 bus = gst_bus_new ();
226 /* FIXME, disabled for 0.10.5 release as it caused to many regressions */
227 /* Start our bus in flushing if appropriate */
228 if (pipeline->priv->auto_flush_bus)
229 gst_bus_set_flushing (bus, TRUE);
232 gst_element_set_bus (GST_ELEMENT_CAST (pipeline), bus);
233 GST_DEBUG_OBJECT (pipeline, "set bus %" GST_PTR_FORMAT " on pipeline", bus);
234 gst_object_unref (bus);
238 gst_pipeline_dispose (GObject * object)
240 GstPipeline *pipeline = GST_PIPELINE (object);
241 GstClock **clock_p = &pipeline->fixed_clock;
243 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pipeline, "%p dispose", pipeline);
245 /* clear and unref any fixed clock */
246 gst_object_replace ((GstObject **) clock_p, NULL);
248 G_OBJECT_CLASS (parent_class)->dispose (object);
252 gst_pipeline_set_property (GObject * object, guint prop_id,
253 const GValue * value, GParamSpec * pspec)
255 GstPipeline *pipeline = GST_PIPELINE (object);
259 gst_pipeline_set_delay (pipeline, g_value_get_uint64 (value));
261 case PROP_AUTO_FLUSH_BUS:
262 gst_pipeline_set_auto_flush_bus (pipeline, g_value_get_boolean (value));
265 gst_pipeline_set_latency (pipeline, g_value_get_uint64 (value));
268 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
274 gst_pipeline_get_property (GObject * object, guint prop_id,
275 GValue * value, GParamSpec * pspec)
277 GstPipeline *pipeline = GST_PIPELINE (object);
281 g_value_set_uint64 (value, gst_pipeline_get_delay (pipeline));
283 case PROP_AUTO_FLUSH_BUS:
284 g_value_set_boolean (value, gst_pipeline_get_auto_flush_bus (pipeline));
287 g_value_set_uint64 (value, gst_pipeline_get_latency (pipeline));
290 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
295 /* set the start_time to 0, this will cause us to select a new base_time and
296 * make the running_time start from 0 again. */
298 reset_start_time (GstPipeline * pipeline, GstClockTime start_time)
300 GST_OBJECT_LOCK (pipeline);
301 if (GST_ELEMENT_START_TIME (pipeline) != GST_CLOCK_TIME_NONE) {
302 GST_DEBUG_OBJECT (pipeline, "reset start_time to 0");
303 GST_ELEMENT_START_TIME (pipeline) = start_time;
304 pipeline->priv->last_start_time = -1;
306 GST_DEBUG_OBJECT (pipeline, "application asked to not reset stream_time");
308 GST_OBJECT_UNLOCK (pipeline);
313 * @name: (allow-none): name of new pipeline
315 * Create a new pipeline with the given name.
317 * Returns: (transfer floating): newly created GstPipeline
322 gst_pipeline_new (const gchar * name)
324 return gst_element_factory_make ("pipeline", name);
327 /* takes a snapshot of the running_time of the pipeline and store this as the
328 * element start_time. This is the time we will set as the running_time of the
329 * pipeline when we go to PLAYING next. */
331 pipeline_update_start_time (GstElement * element)
333 GstPipeline *pipeline = GST_PIPELINE_CAST (element);
336 GST_OBJECT_LOCK (element);
337 if ((clock = element->clock)) {
340 gst_object_ref (clock);
341 GST_OBJECT_UNLOCK (element);
343 /* calculate the time when we stopped */
344 now = gst_clock_get_time (clock);
345 gst_object_unref (clock);
347 GST_OBJECT_LOCK (element);
348 /* store the current running time */
349 if (GST_ELEMENT_START_TIME (pipeline) != GST_CLOCK_TIME_NONE) {
350 if (now != GST_CLOCK_TIME_NONE)
351 GST_ELEMENT_START_TIME (pipeline) = now - element->base_time;
353 GST_WARNING_OBJECT (element,
354 "Clock %s returned invalid time, can't calculate "
355 "running_time when going to the PAUSED state",
356 GST_OBJECT_NAME (clock));
358 /* we went to PAUSED, when going to PLAYING select clock and new
360 pipeline->priv->update_clock = TRUE;
362 GST_DEBUG_OBJECT (element,
363 "start_time=%" GST_TIME_FORMAT ", now=%" GST_TIME_FORMAT
364 ", base_time %" GST_TIME_FORMAT,
365 GST_TIME_ARGS (GST_ELEMENT_START_TIME (pipeline)),
366 GST_TIME_ARGS (now), GST_TIME_ARGS (element->base_time));
368 GST_OBJECT_UNLOCK (element);
372 static GstStateChangeReturn
373 gst_pipeline_change_state (GstElement * element, GstStateChange transition)
375 GstStateChangeReturn result = GST_STATE_CHANGE_SUCCESS;
376 GstPipeline *pipeline = GST_PIPELINE_CAST (element);
379 switch (transition) {
380 case GST_STATE_CHANGE_NULL_TO_NULL:
382 case GST_STATE_CHANGE_READY_TO_READY:
384 case GST_STATE_CHANGE_PAUSED_TO_PAUSED:
386 case GST_STATE_CHANGE_PLAYING_TO_PLAYING:
388 case GST_STATE_CHANGE_NULL_TO_READY:
389 GST_OBJECT_LOCK (element);
391 gst_bus_set_flushing (element->bus, FALSE);
392 GST_OBJECT_UNLOCK (element);
394 case GST_STATE_CHANGE_READY_TO_PAUSED:
395 GST_OBJECT_LOCK (element);
396 pipeline->priv->update_clock = TRUE;
397 GST_OBJECT_UNLOCK (element);
399 /* READY to PAUSED starts running_time from 0 */
400 reset_start_time (pipeline, 0);
402 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
404 GstClockTime now, start_time, last_start_time, delay;
405 gboolean update_clock;
408 GST_DEBUG_OBJECT (element, "selecting clock and base_time");
410 GST_OBJECT_LOCK (element);
411 cur_clock = element->clock;
413 gst_object_ref (cur_clock);
414 /* get the desired running_time of the first buffer aka the start_time */
415 start_time = GST_ELEMENT_START_TIME (pipeline);
416 last_start_time = pipeline->priv->last_start_time;
417 pipeline->priv->last_start_time = start_time;
418 /* see if we need to update the clock */
419 update_clock = pipeline->priv->update_clock;
420 pipeline->priv->update_clock = FALSE;
421 delay = pipeline->delay;
422 GST_OBJECT_UNLOCK (element);
424 /* running time changed, either with a PAUSED or a flush, we need to check
425 * if there is a new clock & update the base time */
426 /* only do this for top-level, however */
427 if (GST_OBJECT_PARENT (element) == NULL &&
428 (update_clock || last_start_time != start_time)) {
429 GST_DEBUG_OBJECT (pipeline, "Need to update start_time");
431 /* when going to PLAYING, select a clock when needed. If we just got
432 * flushed, we don't reselect the clock. */
434 GST_DEBUG_OBJECT (pipeline, "Need to update clock.");
435 clock = gst_element_provide_clock (element);
437 GST_DEBUG_OBJECT (pipeline,
438 "Don't need to update clock, using old clock.");
439 /* only try to ref if cur_clock is not NULL */
441 gst_object_ref (cur_clock);
446 now = gst_clock_get_time (clock);
448 GST_DEBUG_OBJECT (pipeline, "no clock, using base time of NONE");
449 now = GST_CLOCK_TIME_NONE;
452 if (clock != cur_clock) {
453 /* now distribute the clock (which could be NULL). If some
454 * element refuses the clock, this will return FALSE and
455 * we effectively fail the state change. */
456 if (!gst_element_set_clock (element, clock))
459 /* if we selected and distributed a new clock, let the app
461 gst_element_post_message (element,
462 gst_message_new_new_clock (GST_OBJECT_CAST (element), clock));
466 gst_object_unref (clock);
468 if (start_time != GST_CLOCK_TIME_NONE && now != GST_CLOCK_TIME_NONE) {
469 GstClockTime new_base_time = now - start_time + delay;
470 GST_DEBUG_OBJECT (element,
471 "start_time=%" GST_TIME_FORMAT ", now=%" GST_TIME_FORMAT
472 ", base_time %" GST_TIME_FORMAT,
473 GST_TIME_ARGS (start_time), GST_TIME_ARGS (now),
474 GST_TIME_ARGS (new_base_time));
476 gst_element_set_base_time (element, new_base_time);
478 GST_DEBUG_OBJECT (pipeline,
479 "NOT adjusting base_time because start_time is NONE");
482 GST_DEBUG_OBJECT (pipeline,
483 "NOT adjusting base_time because we selected one before");
487 gst_object_unref (cur_clock);
490 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
492 /* we take a start_time snapshot before calling the children state changes
493 * so that they know about when the pipeline PAUSED. */
494 pipeline_update_start_time (element);
497 case GST_STATE_CHANGE_PAUSED_TO_READY:
498 reset_start_time (pipeline, 0);
500 case GST_STATE_CHANGE_READY_TO_NULL:
504 result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
506 switch (transition) {
507 case GST_STATE_CHANGE_NULL_TO_NULL:
509 case GST_STATE_CHANGE_READY_TO_READY:
511 case GST_STATE_CHANGE_PAUSED_TO_PAUSED:
513 case GST_STATE_CHANGE_PLAYING_TO_PLAYING:
515 case GST_STATE_CHANGE_NULL_TO_READY:
517 case GST_STATE_CHANGE_READY_TO_PAUSED:
519 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
521 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
523 /* Take a new snapshot of the start_time after calling the state change on
524 * all children. This will be the running_time of the pipeline when we go
526 pipeline_update_start_time (element);
529 case GST_STATE_CHANGE_PAUSED_TO_READY:
531 case GST_STATE_CHANGE_READY_TO_NULL:
536 /* grab some stuff before we release the lock to flush out the bus */
537 GST_OBJECT_LOCK (element);
538 if ((bus = element->bus))
539 gst_object_ref (bus);
540 auto_flush = pipeline->priv->auto_flush_bus;
541 GST_OBJECT_UNLOCK (element);
545 gst_bus_set_flushing (bus, TRUE);
547 GST_INFO_OBJECT (element, "not flushing bus, auto-flushing disabled");
549 gst_object_unref (bus);
559 /* we generate this error when the selected clock was not
560 * accepted by some element */
561 GST_ELEMENT_ERROR (pipeline, CORE, CLOCK,
562 (_("Selected clock cannot be used in pipeline.")),
563 ("Pipeline cannot operate with selected clock"));
564 GST_DEBUG_OBJECT (pipeline,
565 "Pipeline cannot operate with selected clock %p", clock);
567 gst_object_unref (clock);
568 return GST_STATE_CHANGE_FAILURE;
572 /* intercept the bus messages from our children. We watch for the ASYNC_START
573 * message with is posted by the elements (sinks) that require a reset of the
574 * running_time after a flush. ASYNC_START also brings the pipeline back into
575 * the PAUSED, pending PAUSED state. When the ASYNC_DONE message is received the
576 * pipeline will redistribute the new base_time and will bring the elements back
577 * to the desired state of the pipeline. */
579 gst_pipeline_handle_message (GstBin * bin, GstMessage * message)
581 GstPipeline *pipeline = GST_PIPELINE_CAST (bin);
583 switch (GST_MESSAGE_TYPE (message)) {
584 case GST_MESSAGE_RESET_TIME:
586 GstClockTime running_time;
588 gst_message_parse_reset_time (message, &running_time);
590 /* reset our running time if we need to distribute a new base_time to the
592 reset_start_time (pipeline, running_time);
595 case GST_MESSAGE_CLOCK_LOST:
599 gst_message_parse_clock_lost (message, &clock);
601 GST_OBJECT_LOCK (bin);
602 if (clock == GST_ELEMENT_CAST (bin)->clock) {
603 GST_DEBUG_OBJECT (bin, "Used clock '%s' got lost",
604 GST_OBJECT_NAME (clock));
605 pipeline->priv->update_clock = TRUE;
607 GST_OBJECT_UNLOCK (bin);
612 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
616 gst_pipeline_do_latency (GstBin * bin)
618 GstPipeline *pipeline = GST_PIPELINE (bin);
620 GstClockTime latency;
621 GstClockTime min_latency, max_latency;
624 GST_OBJECT_LOCK (pipeline);
625 latency = pipeline->priv->latency;
626 GST_OBJECT_UNLOCK (pipeline);
628 if (latency == GST_CLOCK_TIME_NONE)
629 return GST_BIN_CLASS (parent_class)->do_latency (bin);
631 GST_DEBUG_OBJECT (pipeline, "querying latency");
633 query = gst_query_new_latency ();
634 if ((res = gst_element_query (GST_ELEMENT_CAST (pipeline), query))) {
637 gst_query_parse_latency (query, &live, &min_latency, &max_latency);
639 GST_DEBUG_OBJECT (pipeline,
640 "got min latency %" GST_TIME_FORMAT ", max latency %"
641 GST_TIME_FORMAT ", live %d", GST_TIME_ARGS (min_latency),
642 GST_TIME_ARGS (max_latency), live);
644 if (max_latency < min_latency) {
645 /* this is an impossible situation, some parts of the pipeline might not
646 * work correctly. We post a warning for now. */
647 GST_ELEMENT_WARNING (pipeline, CORE, CLOCK, (NULL),
648 ("Impossible to configure latency: max %" GST_TIME_FORMAT " < min %"
649 GST_TIME_FORMAT ". Add queues or other buffering elements.",
650 GST_TIME_ARGS (max_latency), GST_TIME_ARGS (min_latency)));
653 if (latency < min_latency) {
654 /* This is a problematic situation as we will most likely drop lots of
655 * data if we configure a too low latency */
656 GST_ELEMENT_WARNING (pipeline, CORE, CLOCK, (NULL),
657 ("Configured latency is lower than detected minimum latency: configured %"
658 GST_TIME_FORMAT " < min %" GST_TIME_FORMAT,
659 GST_TIME_ARGS (latency), GST_TIME_ARGS (min_latency)));
662 /* this is not a real problem, we just don't configure any latency. */
663 GST_WARNING_OBJECT (pipeline, "failed to query latency");
665 gst_query_unref (query);
668 /* configure latency on elements */
670 gst_element_send_event (GST_ELEMENT_CAST (pipeline),
671 gst_event_new_latency (latency));
673 GST_INFO_OBJECT (pipeline, "configured latency of %" GST_TIME_FORMAT,
674 GST_TIME_ARGS (latency));
676 GST_WARNING_OBJECT (pipeline,
677 "did not really configure latency of %" GST_TIME_FORMAT,
678 GST_TIME_ARGS (latency));
685 * gst_pipeline_get_bus:
686 * @pipeline: a #GstPipeline
688 * Gets the #GstBus of @pipeline. The bus allows applications to receive
689 * #GstMessage packets.
691 * Returns: (transfer full): a #GstBus, unref after usage.
696 gst_pipeline_get_bus (GstPipeline * pipeline)
698 return gst_element_get_bus (GST_ELEMENT_CAST (pipeline));
702 gst_pipeline_provide_clock_func (GstElement * element)
704 GstClock *clock = NULL;
705 GstPipeline *pipeline = GST_PIPELINE (element);
707 /* if we have a fixed clock, use that one */
708 GST_OBJECT_LOCK (pipeline);
709 if (GST_OBJECT_FLAG_IS_SET (pipeline, GST_PIPELINE_FLAG_FIXED_CLOCK)) {
710 clock = pipeline->fixed_clock;
712 gst_object_ref (clock);
713 GST_OBJECT_UNLOCK (pipeline);
715 GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline using fixed clock %p (%s)",
716 clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
718 GST_OBJECT_UNLOCK (pipeline);
719 /* let the parent bin select a clock */
721 GST_ELEMENT_CLASS (parent_class)->provide_clock (GST_ELEMENT
723 /* no clock, use a system clock */
725 clock = gst_system_clock_obtain ();
727 GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline obtained system clock: %p (%s)",
728 clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
730 GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline obtained clock: %p (%s)",
731 clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-");
738 * gst_pipeline_get_clock: (skip)
739 * @pipeline: a #GstPipeline
741 * Gets the current clock used by @pipeline. Users of object
742 * oriented languages should use gst_pipeline_get_pipeline_clock()
743 * to avoid confusion with gst_element_get_clock() which has a different behavior.
745 * Unlike gst_element_get_clock(), this function will always return a
746 * clock, even if the pipeline is not in the PLAYING state.
748 * Returns: (transfer full): a #GstClock, unref after usage.
751 gst_pipeline_get_clock (GstPipeline * pipeline)
753 return gst_pipeline_get_pipeline_clock (pipeline);
757 * gst_pipeline_get_pipeline_clock:
758 * @pipeline: a #GstPipeline
760 * Gets the current clock used by @pipeline.
762 * Unlike gst_element_get_clock(), this function will always return a
763 * clock, even if the pipeline is not in the PLAYING state.
765 * Returns: (transfer full): a #GstClock, unref after usage.
770 gst_pipeline_get_pipeline_clock (GstPipeline * pipeline)
772 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL);
774 return gst_pipeline_provide_clock_func (GST_ELEMENT_CAST (pipeline));
779 * gst_pipeline_use_clock:
780 * @pipeline: a #GstPipeline
781 * @clock: (transfer none) (allow-none): the clock to use
783 * Force @pipeline to use the given @clock. The pipeline will
784 * always use the given clock even if new clock providers are added
787 * If @clock is %NULL all clocking will be disabled which will make
788 * the pipeline run as fast as possible.
793 gst_pipeline_use_clock (GstPipeline * pipeline, GstClock * clock)
797 g_return_if_fail (GST_IS_PIPELINE (pipeline));
799 GST_OBJECT_LOCK (pipeline);
800 GST_OBJECT_FLAG_SET (pipeline, GST_PIPELINE_FLAG_FIXED_CLOCK);
802 clock_p = &pipeline->fixed_clock;
803 gst_object_replace ((GstObject **) clock_p, (GstObject *) clock);
804 GST_OBJECT_UNLOCK (pipeline);
806 GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline using fixed clock %p (%s)", clock,
807 (clock ? GST_OBJECT_NAME (clock) : "nil"));
811 * gst_pipeline_set_clock: (skip)
812 * @pipeline: a #GstPipeline
813 * @clock: (transfer none): the clock to set
815 * Set the clock for @pipeline. The clock will be distributed
816 * to all the elements managed by the pipeline.
818 * Returns: %TRUE if the clock could be set on the pipeline. %FALSE if
819 * some element did not accept the clock.
824 gst_pipeline_set_clock (GstPipeline * pipeline, GstClock * clock)
826 g_return_val_if_fail (pipeline != NULL, FALSE);
827 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), FALSE);
830 GST_ELEMENT_CLASS (parent_class)->set_clock (GST_ELEMENT_CAST (pipeline),
835 * gst_pipeline_auto_clock:
836 * @pipeline: a #GstPipeline
838 * Let @pipeline select a clock automatically. This is the default
841 * Use this function if you previous forced a fixed clock with
842 * gst_pipeline_use_clock() and want to restore the default
843 * pipeline clock selection algorithm.
848 gst_pipeline_auto_clock (GstPipeline * pipeline)
852 g_return_if_fail (pipeline != NULL);
853 g_return_if_fail (GST_IS_PIPELINE (pipeline));
855 GST_OBJECT_LOCK (pipeline);
856 GST_OBJECT_FLAG_UNSET (pipeline, GST_PIPELINE_FLAG_FIXED_CLOCK);
858 clock_p = &pipeline->fixed_clock;
859 gst_object_replace ((GstObject **) clock_p, NULL);
860 GST_OBJECT_UNLOCK (pipeline);
862 GST_CAT_DEBUG (GST_CAT_CLOCK, "pipeline using automatic clock");
866 * gst_pipeline_set_delay:
867 * @pipeline: a #GstPipeline
870 * Set the expected delay needed for all elements to perform the
871 * PAUSED to PLAYING state change. @delay will be added to the
872 * base time of the elements so that they wait an additional @delay
873 * amount of time before starting to process buffers and cannot be
874 * #GST_CLOCK_TIME_NONE.
876 * This option is used for tuning purposes and should normally not be
882 gst_pipeline_set_delay (GstPipeline * pipeline, GstClockTime delay)
884 g_return_if_fail (GST_IS_PIPELINE (pipeline));
885 g_return_if_fail (delay != GST_CLOCK_TIME_NONE);
887 GST_OBJECT_LOCK (pipeline);
888 pipeline->delay = delay;
889 GST_OBJECT_UNLOCK (pipeline);
893 * gst_pipeline_get_delay:
894 * @pipeline: a #GstPipeline
896 * Get the configured delay (see gst_pipeline_set_delay()).
898 * Returns: The configured delay.
903 gst_pipeline_get_delay (GstPipeline * pipeline)
907 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), GST_CLOCK_TIME_NONE);
909 GST_OBJECT_LOCK (pipeline);
910 res = pipeline->delay;
911 GST_OBJECT_UNLOCK (pipeline);
917 * gst_pipeline_set_auto_flush_bus:
918 * @pipeline: a #GstPipeline
919 * @auto_flush: whether or not to automatically flush the bus when
920 * the pipeline goes from READY to NULL state
922 * Usually, when a pipeline goes from READY to NULL state, it automatically
923 * flushes all pending messages on the bus, which is done for refcounting
924 * purposes, to break circular references.
926 * This means that applications that update state using (async) bus messages
927 * (e.g. do certain things when a pipeline goes from PAUSED to READY) might
928 * not get to see messages when the pipeline is shut down, because they might
929 * be flushed before they can be dispatched in the main thread. This behaviour
930 * can be disabled using this function.
932 * It is important that all messages on the bus are handled when the
933 * automatic flushing is disabled else memory leaks will be introduced.
938 gst_pipeline_set_auto_flush_bus (GstPipeline * pipeline, gboolean auto_flush)
940 g_return_if_fail (GST_IS_PIPELINE (pipeline));
942 GST_OBJECT_LOCK (pipeline);
943 pipeline->priv->auto_flush_bus = auto_flush;
944 GST_OBJECT_UNLOCK (pipeline);
948 * gst_pipeline_get_auto_flush_bus:
949 * @pipeline: a #GstPipeline
951 * Check if @pipeline will automatically flush messages when going to
954 * Returns: whether the pipeline will automatically flush its bus when
955 * going from READY to NULL state or not.
960 gst_pipeline_get_auto_flush_bus (GstPipeline * pipeline)
964 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), FALSE);
966 GST_OBJECT_LOCK (pipeline);
967 res = pipeline->priv->auto_flush_bus;
968 GST_OBJECT_UNLOCK (pipeline);
974 * gst_pipeline_set_latency:
975 * @pipeline: a #GstPipeline
976 * @latency: latency to configure
978 * Sets the latency that should be configured on the pipeline. Setting
979 * GST_CLOCK_TIME_NONE will restore the default behaviour of using the minimum
980 * latency from the LATENCY query. Setting this is usually not required and
981 * the pipeline will figure out an appropriate latency automatically.
983 * Setting a too low latency, especially lower than the minimum latency from
984 * the LATENCY query, will most likely cause the pipeline to fail.
989 gst_pipeline_set_latency (GstPipeline * pipeline, GstClockTime latency)
993 g_return_if_fail (GST_IS_PIPELINE (pipeline));
995 GST_OBJECT_LOCK (pipeline);
996 changed = (pipeline->priv->latency != latency);
997 pipeline->priv->latency = latency;
998 GST_OBJECT_UNLOCK (pipeline);
1001 gst_bin_recalculate_latency (GST_BIN_CAST (pipeline));
1005 * gst_pipeline_get_latency:
1006 * @pipeline: a #GstPipeline
1008 * Gets the latency that should be configured on the pipeline. See
1009 * gst_pipeline_set_latency().
1011 * Returns: Latency to configure on the pipeline or GST_CLOCK_TIME_NONE
1017 gst_pipeline_get_latency (GstPipeline * pipeline)
1019 GstClockTime latency;
1021 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), GST_CLOCK_TIME_NONE);
1023 GST_OBJECT_LOCK (pipeline);
1024 latency = pipeline->priv->latency;
1025 GST_OBJECT_UNLOCK (pipeline);