2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000,2005 Wim Taymans <wim@fluendo.com>
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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 * @short_description: Base class for getrange based source elements
26 * @see_also: #GstPushSrc, #GstBaseTransform, #GstBaseSink
28 * This is a generice base class for source elements. The following
29 * types of sources are supported:
31 * <listitem><para>random access sources like files</para></listitem>
32 * <listitem><para>seekable sources</para></listitem>
33 * <listitem><para>live sources</para></listitem>
36 * The source can be configured to operate in any #GstFormat with the
37 * gst_base_src_set_format() method. The currently set format determines
38 * the format of the internal #GstSegment and any #GST_EVENT_NEWSEGMENT
39 * events. The default format for #GstBaseSrc is #GST_FORMAT_BYTES.
41 * #GstBaseSrc always supports push mode scheduling. If the following
42 * conditions are met, it also supports pull mode scheduling:
44 * <listitem><para>The format is set to #GST_FORMAT_BYTES (default).</para>
46 * <listitem><para>#GstBaseSrcClass.is_seekable() returns %TRUE.</para>
50 * Since 0.10.9, any #GstBaseSrc can enable pull based scheduling at any time
51 * by overriding #GstBaseSrcClass.check_get_range() so that it returns %TRUE.
53 * If all the conditions are met for operating in pull mode, #GstBaseSrc is
54 * automatically seekable in push mode as well. The following conditions must
55 * be met to make the element seekable in push mode when the format is not
59 * #GstBaseSrcClass.is_seekable() returns %TRUE.
62 * #GstBaseSrcClass.query() can convert all supported seek formats to the
63 * internal format as set with gst_base_src_set_format().
66 * #GstBaseSrcClass.do_seek() is implemented, performs the seek and returns
71 * When the element does not meet the requirements to operate in pull mode, the
72 * offset and length in the #GstBaseSrcClass.create() method should be ignored.
73 * It is recommended to subclass #GstPushSrc instead, in this situation. If the
74 * element can operate in pull mode but only with specific offsets and
75 * lengths, it is allowed to generate an error when the wrong values are passed
76 * to the #GstBaseSrcClass.create() function.
78 * #GstBaseSrc has support for live sources. Live sources are sources that when
79 * paused discard data, such as audio or video capture devices. A typical live
80 * source also produces data at a fixed rate and thus provides a clock to publish
82 * Use gst_base_src_set_live() to activate the live source mode.
84 * A live source does not produce data in the PAUSED state. This means that the
85 * #GstBaseSrcClass.create() method will not be called in PAUSED but only in
86 * PLAYING. To signal the pipeline that the element will not produce data, the
87 * return value from the READY to PAUSED state will be
88 * #GST_STATE_CHANGE_NO_PREROLL.
90 * A typical live source will timestamp the buffers it creates with the
91 * current running time of the pipeline. This is one reason why a live source
92 * can only produce data in the PLAYING state, when the clock is actually
93 * distributed and running.
95 * Live sources that synchronize and block on the clock (an audio source, for
96 * example) can since 0.10.12 use gst_base_src_wait_playing() when the
97 * #GstBaseSrcClass.create() function was interrupted by a state change to
100 * The #GstBaseSrcClass.get_times() method can be used to implement pseudo-live
101 * sources. It only makes sense to implement the #GstBaseSrcClass.get_times()
102 * function if the source is a live source. The #GstBaseSrcClass.get_times()
103 * function should return timestamps starting from 0, as if it were a non-live
104 * source. The base class will make sure that the timestamps are transformed
105 * into the current running_time. The base source will then wait for the
106 * calculated running_time before pushing out the buffer.
108 * For live sources, the base class will by default report a latency of 0.
109 * For pseudo live sources, the base class will by default measure the difference
110 * between the first buffer timestamp and the start time of get_times and will
111 * report this value as the latency.
112 * Subclasses should override the query function when this behaviour is not
115 * There is only support in #GstBaseSrc for exactly one source pad, which
116 * should be named "src". A source implementation (subclass of #GstBaseSrc)
117 * should install a pad template in its class_init function, like so:
120 * my_element_class_init (GstMyElementClass *klass)
122 * GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
123 * // srctemplate should be a #GstStaticPadTemplate with direction
124 * // #GST_PAD_SRC and name "src"
125 * gst_element_class_add_pad_template (gstelement_class,
126 * gst_static_pad_template_get (&srctemplate));
127 * // see #GstElementDetails
128 * gst_element_class_set_details (gstelement_class, &details);
133 * <title>Controlled shutdown of live sources in applications</title>
135 * Applications that record from a live source may want to stop recording
136 * in a controlled way, so that the recording is stopped, but the data
137 * already in the pipeline is processed to the end (remember that many live
138 * sources would go on recording forever otherwise). For that to happen the
139 * application needs to make the source stop recording and send an EOS
140 * event down the pipeline. The application would then wait for an
141 * EOS message posted on the pipeline's bus to know when all data has
142 * been processed and the pipeline can safely be stopped.
144 * Since GStreamer 0.10.16 an application may send an EOS event to a source
145 * element to make it perform the EOS logic (send EOS event downstream or post a
146 * #GST_MESSAGE_SEGMENT_DONE on the bus). This can typically be done
147 * with the gst_element_send_event() function on the element or its parent bin.
149 * After the EOS has been sent to the element, the application should wait for
150 * an EOS message to be posted on the pipeline's bus. Once this EOS message is
151 * received, it may safely shut down the entire pipeline.
153 * The old behaviour for controlled shutdown introduced since GStreamer 0.10.3
154 * is still available but deprecated as it is dangerous and less flexible.
156 * Last reviewed on 2007-12-19 (0.10.16)
168 #include <gst/gst_private.h>
170 #include "gstbasesrc.h"
171 #include "gsttypefindhelper.h"
172 #include <gst/gstmarshal.h>
173 #include <gst/gst-i18n-lib.h>
175 GST_DEBUG_CATEGORY_STATIC (gst_base_src_debug);
176 #define GST_CAT_DEFAULT gst_base_src_debug
178 #define GST_LIVE_GET_LOCK(elem) (GST_BASE_SRC_CAST(elem)->live_lock)
179 #define GST_LIVE_LOCK(elem) g_mutex_lock(GST_LIVE_GET_LOCK(elem))
180 #define GST_LIVE_TRYLOCK(elem) g_mutex_trylock(GST_LIVE_GET_LOCK(elem))
181 #define GST_LIVE_UNLOCK(elem) g_mutex_unlock(GST_LIVE_GET_LOCK(elem))
182 #define GST_LIVE_GET_COND(elem) (GST_BASE_SRC_CAST(elem)->live_cond)
183 #define GST_LIVE_WAIT(elem) g_cond_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem))
184 #define GST_LIVE_TIMED_WAIT(elem, timeval) g_cond_timed_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem),\
186 #define GST_LIVE_SIGNAL(elem) g_cond_signal (GST_LIVE_GET_COND (elem));
187 #define GST_LIVE_BROADCAST(elem) g_cond_broadcast (GST_LIVE_GET_COND (elem));
189 /* BaseSrc signals and args */
196 #define DEFAULT_BLOCKSIZE 4096
197 #define DEFAULT_NUM_BUFFERS -1
198 #define DEFAULT_TYPEFIND FALSE
199 #define DEFAULT_DO_TIMESTAMP FALSE
210 #define GST_BASE_SRC_GET_PRIVATE(obj) \
211 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_SRC, GstBaseSrcPrivate))
213 struct _GstBaseSrcPrivate
215 gboolean last_sent_eos; /* last thing we did was send an EOS (we set this
216 * to avoid the sending of two EOS in some cases) */
220 /* two segments to be sent in the streaming thread with STREAM_LOCK */
221 GstEvent *close_segment;
222 GstEvent *start_segment;
223 gboolean newsegment_pending;
225 /* if EOS is pending (atomic) */
228 /* startup latency is the time it takes between going to PLAYING and producing
229 * the first BUFFER with running_time 0. This value is included in the latency
231 GstClockTime latency;
232 /* timestamp offset, this is the offset add to the values of gst_times for
233 * pseudo live sources */
234 GstClockTimeDiff ts_offset;
236 gboolean do_timestamp;
238 /* stream sequence number */
241 /* pending events (TAG, CUSTOM_BOTH, CUSTOM_DOWNSTREAM) to be
242 * pushed in the data stream */
243 GList *pending_events;
244 volatile gint have_events;
246 /* QoS *//* with LOCK */
247 gboolean qos_enabled;
249 GstClockTime earliest_time;
252 static GstElementClass *parent_class = NULL;
254 static void gst_base_src_base_init (gpointer g_class);
255 static void gst_base_src_class_init (GstBaseSrcClass * klass);
256 static void gst_base_src_init (GstBaseSrc * src, gpointer g_class);
257 static void gst_base_src_finalize (GObject * object);
261 gst_base_src_get_type (void)
263 static volatile gsize base_src_type = 0;
265 if (g_once_init_enter (&base_src_type)) {
267 static const GTypeInfo base_src_info = {
268 sizeof (GstBaseSrcClass),
269 (GBaseInitFunc) gst_base_src_base_init,
271 (GClassInitFunc) gst_base_src_class_init,
276 (GInstanceInitFunc) gst_base_src_init,
279 _type = g_type_register_static (GST_TYPE_ELEMENT,
280 "GstBaseSrc", &base_src_info, G_TYPE_FLAG_ABSTRACT);
281 g_once_init_leave (&base_src_type, _type);
283 return base_src_type;
286 static GstCaps *gst_base_src_getcaps (GstPad * pad);
287 static gboolean gst_base_src_setcaps (GstPad * pad, GstCaps * caps);
288 static void gst_base_src_fixate (GstPad * pad, GstCaps * caps);
290 static gboolean gst_base_src_activate_push (GstPad * pad, gboolean active);
291 static gboolean gst_base_src_activate_pull (GstPad * pad, gboolean active);
292 static void gst_base_src_set_property (GObject * object, guint prop_id,
293 const GValue * value, GParamSpec * pspec);
294 static void gst_base_src_get_property (GObject * object, guint prop_id,
295 GValue * value, GParamSpec * pspec);
296 static gboolean gst_base_src_event_handler (GstPad * pad, GstEvent * event);
297 static gboolean gst_base_src_send_event (GstElement * elem, GstEvent * event);
298 static gboolean gst_base_src_default_event (GstBaseSrc * src, GstEvent * event);
299 static const GstQueryType *gst_base_src_get_query_types (GstElement * element);
301 static gboolean gst_base_src_query (GstPad * pad, GstQuery * query);
303 static gboolean gst_base_src_default_negotiate (GstBaseSrc * basesrc);
304 static gboolean gst_base_src_default_do_seek (GstBaseSrc * src,
305 GstSegment * segment);
306 static gboolean gst_base_src_default_query (GstBaseSrc * src, GstQuery * query);
307 static gboolean gst_base_src_default_prepare_seek_segment (GstBaseSrc * src,
308 GstEvent * event, GstSegment * segment);
310 static gboolean gst_base_src_set_flushing (GstBaseSrc * basesrc,
311 gboolean flushing, gboolean live_play, gboolean unlock, gboolean * playing);
312 static gboolean gst_base_src_start (GstBaseSrc * basesrc);
313 static gboolean gst_base_src_stop (GstBaseSrc * basesrc);
315 static GstStateChangeReturn gst_base_src_change_state (GstElement * element,
316 GstStateChange transition);
318 static void gst_base_src_loop (GstPad * pad);
319 static gboolean gst_base_src_pad_check_get_range (GstPad * pad);
320 static gboolean gst_base_src_default_check_get_range (GstBaseSrc * bsrc);
321 static GstFlowReturn gst_base_src_pad_get_range (GstPad * pad, guint64 offset,
322 guint length, GstBuffer ** buf);
323 static GstFlowReturn gst_base_src_get_range (GstBaseSrc * src, guint64 offset,
324 guint length, GstBuffer ** buf);
325 static gboolean gst_base_src_seekable (GstBaseSrc * src);
328 gst_base_src_base_init (gpointer g_class)
330 GST_DEBUG_CATEGORY_INIT (gst_base_src_debug, "basesrc", 0, "basesrc element");
334 gst_base_src_class_init (GstBaseSrcClass * klass)
336 GObjectClass *gobject_class;
337 GstElementClass *gstelement_class;
339 gobject_class = G_OBJECT_CLASS (klass);
340 gstelement_class = GST_ELEMENT_CLASS (klass);
342 g_type_class_add_private (klass, sizeof (GstBaseSrcPrivate));
344 parent_class = g_type_class_peek_parent (klass);
346 gobject_class->finalize = gst_base_src_finalize;
347 gobject_class->set_property = gst_base_src_set_property;
348 gobject_class->get_property = gst_base_src_get_property;
350 /* FIXME 0.11: blocksize property should be int, not ulong (min is >max here) */
351 g_object_class_install_property (gobject_class, PROP_BLOCKSIZE,
352 g_param_spec_ulong ("blocksize", "Block size",
353 "Size in bytes to read per buffer (-1 = default)", 0, G_MAXULONG,
354 DEFAULT_BLOCKSIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
355 g_object_class_install_property (gobject_class, PROP_NUM_BUFFERS,
356 g_param_spec_int ("num-buffers", "num-buffers",
357 "Number of buffers to output before sending EOS (-1 = unlimited)",
358 -1, G_MAXINT, DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE |
359 G_PARAM_STATIC_STRINGS));
360 g_object_class_install_property (gobject_class, PROP_TYPEFIND,
361 g_param_spec_boolean ("typefind", "Typefind",
362 "Run typefind before negotiating", DEFAULT_TYPEFIND,
363 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
364 g_object_class_install_property (gobject_class, PROP_DO_TIMESTAMP,
365 g_param_spec_boolean ("do-timestamp", "Do timestamp",
366 "Apply current stream time to buffers", DEFAULT_DO_TIMESTAMP,
367 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
369 gstelement_class->change_state =
370 GST_DEBUG_FUNCPTR (gst_base_src_change_state);
371 gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_base_src_send_event);
372 gstelement_class->get_query_types =
373 GST_DEBUG_FUNCPTR (gst_base_src_get_query_types);
375 klass->negotiate = GST_DEBUG_FUNCPTR (gst_base_src_default_negotiate);
376 klass->event = GST_DEBUG_FUNCPTR (gst_base_src_default_event);
377 klass->do_seek = GST_DEBUG_FUNCPTR (gst_base_src_default_do_seek);
378 klass->query = GST_DEBUG_FUNCPTR (gst_base_src_default_query);
379 klass->check_get_range =
380 GST_DEBUG_FUNCPTR (gst_base_src_default_check_get_range);
381 klass->prepare_seek_segment =
382 GST_DEBUG_FUNCPTR (gst_base_src_default_prepare_seek_segment);
384 /* Registering debug symbols for function pointers */
385 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_activate_push);
386 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_activate_pull);
387 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_event_handler);
388 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_query);
389 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_pad_get_range);
390 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_pad_check_get_range);
391 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_getcaps);
392 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_setcaps);
393 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_fixate);
397 gst_base_src_init (GstBaseSrc * basesrc, gpointer g_class)
400 GstPadTemplate *pad_template;
402 basesrc->priv = GST_BASE_SRC_GET_PRIVATE (basesrc);
404 basesrc->is_live = FALSE;
405 basesrc->live_lock = g_mutex_new ();
406 basesrc->live_cond = g_cond_new ();
407 basesrc->num_buffers = DEFAULT_NUM_BUFFERS;
408 basesrc->num_buffers_left = -1;
410 basesrc->can_activate_push = TRUE;
411 basesrc->pad_mode = GST_ACTIVATE_NONE;
414 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src");
415 g_return_if_fail (pad_template != NULL);
417 GST_DEBUG_OBJECT (basesrc, "creating src pad");
418 pad = gst_pad_new_from_template (pad_template, "src");
420 GST_DEBUG_OBJECT (basesrc, "setting functions on src pad");
421 gst_pad_set_activatepush_function (pad, gst_base_src_activate_push);
422 gst_pad_set_activatepull_function (pad, gst_base_src_activate_pull);
423 gst_pad_set_event_function (pad, gst_base_src_event_handler);
424 gst_pad_set_query_function (pad, gst_base_src_query);
425 gst_pad_set_checkgetrange_function (pad, gst_base_src_pad_check_get_range);
426 gst_pad_set_getrange_function (pad, gst_base_src_pad_get_range);
427 gst_pad_set_getcaps_function (pad, gst_base_src_getcaps);
428 gst_pad_set_setcaps_function (pad, gst_base_src_setcaps);
429 gst_pad_set_fixatecaps_function (pad, gst_base_src_fixate);
431 /* hold pointer to pad */
432 basesrc->srcpad = pad;
433 GST_DEBUG_OBJECT (basesrc, "adding src pad");
434 gst_element_add_pad (GST_ELEMENT (basesrc), pad);
436 basesrc->blocksize = DEFAULT_BLOCKSIZE;
437 basesrc->clock_id = NULL;
438 /* we operate in BYTES by default */
439 gst_base_src_set_format (basesrc, GST_FORMAT_BYTES);
440 basesrc->data.ABI.typefind = DEFAULT_TYPEFIND;
441 basesrc->priv->do_timestamp = DEFAULT_DO_TIMESTAMP;
442 g_atomic_int_set (&basesrc->priv->have_events, FALSE);
444 GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
445 GST_OBJECT_FLAG_SET (basesrc, GST_ELEMENT_IS_SOURCE);
447 GST_DEBUG_OBJECT (basesrc, "init done");
451 gst_base_src_finalize (GObject * object)
456 basesrc = GST_BASE_SRC (object);
458 g_mutex_free (basesrc->live_lock);
459 g_cond_free (basesrc->live_cond);
461 event_p = &basesrc->data.ABI.pending_seek;
462 gst_event_replace (event_p, NULL);
464 if (basesrc->priv->pending_events) {
465 g_list_foreach (basesrc->priv->pending_events, (GFunc) gst_event_unref,
467 g_list_free (basesrc->priv->pending_events);
470 G_OBJECT_CLASS (parent_class)->finalize (object);
474 * gst_base_src_wait_playing:
477 * If the #GstBaseSrcClass.create() method performs its own synchronisation
478 * against the clock it must unblock when going from PLAYING to the PAUSED state
479 * and call this method before continuing to produce the remaining data.
481 * This function will block until a state change to PLAYING happens (in which
482 * case this function returns #GST_FLOW_OK) or the processing must be stopped due
483 * to a state change to READY or a FLUSH event (in which case this function
484 * returns #GST_FLOW_WRONG_STATE).
488 * Returns: #GST_FLOW_OK if @src is PLAYING and processing can
489 * continue. Any other return value should be returned from the create vmethod.
492 gst_base_src_wait_playing (GstBaseSrc * src)
494 g_return_val_if_fail (GST_IS_BASE_SRC (src), GST_FLOW_ERROR);
497 /* block until the state changes, or we get a flush, or something */
498 GST_DEBUG_OBJECT (src, "live source waiting for running state");
500 GST_DEBUG_OBJECT (src, "live source unlocked");
501 if (src->priv->flushing)
503 } while (G_UNLIKELY (!src->live_running));
510 GST_DEBUG_OBJECT (src, "we are flushing");
511 return GST_FLOW_WRONG_STATE;
516 * gst_base_src_set_live:
517 * @src: base source instance
518 * @live: new live-mode
520 * If the element listens to a live source, @live should
523 * A live source will not produce data in the PAUSED state and
524 * will therefore not be able to participate in the PREROLL phase
525 * of a pipeline. To signal this fact to the application and the
526 * pipeline, the state change return value of the live source will
527 * be GST_STATE_CHANGE_NO_PREROLL.
530 gst_base_src_set_live (GstBaseSrc * src, gboolean live)
532 g_return_if_fail (GST_IS_BASE_SRC (src));
534 GST_OBJECT_LOCK (src);
536 GST_OBJECT_UNLOCK (src);
540 * gst_base_src_is_live:
541 * @src: base source instance
543 * Check if an element is in live mode.
545 * Returns: %TRUE if element is in live mode.
548 gst_base_src_is_live (GstBaseSrc * src)
552 g_return_val_if_fail (GST_IS_BASE_SRC (src), FALSE);
554 GST_OBJECT_LOCK (src);
555 result = src->is_live;
556 GST_OBJECT_UNLOCK (src);
562 * gst_base_src_set_format:
563 * @src: base source instance
564 * @format: the format to use
566 * Sets the default format of the source. This will be the format used
567 * for sending NEW_SEGMENT events and for performing seeks.
569 * If a format of GST_FORMAT_BYTES is set, the element will be able to
570 * operate in pull mode if the #GstBaseSrcClass.is_seekable() returns TRUE.
572 * This function must only be called in states < %GST_STATE_PAUSED.
577 gst_base_src_set_format (GstBaseSrc * src, GstFormat format)
579 g_return_if_fail (GST_IS_BASE_SRC (src));
580 g_return_if_fail (GST_STATE (src) <= GST_STATE_READY);
582 GST_OBJECT_LOCK (src);
583 gst_segment_init (&src->segment, format);
584 GST_OBJECT_UNLOCK (src);
588 * gst_base_src_query_latency:
590 * @live: (out) (allow-none): if the source is live
591 * @min_latency: (out) (allow-none): the min latency of the source
592 * @max_latency: (out) (allow-none): the max latency of the source
594 * Query the source for the latency parameters. @live will be TRUE when @src is
595 * configured as a live source. @min_latency will be set to the difference
596 * between the running time and the timestamp of the first buffer.
597 * @max_latency is always the undefined value of -1.
599 * This function is mostly used by subclasses.
601 * Returns: TRUE if the query succeeded.
606 gst_base_src_query_latency (GstBaseSrc * src, gboolean * live,
607 GstClockTime * min_latency, GstClockTime * max_latency)
611 g_return_val_if_fail (GST_IS_BASE_SRC (src), FALSE);
613 GST_OBJECT_LOCK (src);
615 *live = src->is_live;
617 /* if we have a startup latency, report this one, else report 0. Subclasses
618 * are supposed to override the query function if they want something
620 if (src->priv->latency != -1)
621 min = src->priv->latency;
630 GST_LOG_OBJECT (src, "latency: live %d, min %" GST_TIME_FORMAT
631 ", max %" GST_TIME_FORMAT, src->is_live, GST_TIME_ARGS (min),
633 GST_OBJECT_UNLOCK (src);
639 * gst_base_src_set_blocksize:
641 * @blocksize: the new blocksize in bytes
643 * Set the number of bytes that @src will push out with each buffer. When
644 * @blocksize is set to -1, a default length will be used.
648 /* FIXME 0.11: blocksize property should be int, not ulong */
650 gst_base_src_set_blocksize (GstBaseSrc * src, gulong blocksize)
652 g_return_if_fail (GST_IS_BASE_SRC (src));
654 GST_OBJECT_LOCK (src);
655 src->blocksize = blocksize;
656 GST_OBJECT_UNLOCK (src);
660 * gst_base_src_get_blocksize:
663 * Get the number of bytes that @src will push out with each buffer.
665 * Returns: the number of bytes pushed with each buffer.
669 /* FIXME 0.11: blocksize property should be int, not ulong */
671 gst_base_src_get_blocksize (GstBaseSrc * src)
675 g_return_val_if_fail (GST_IS_BASE_SRC (src), 0);
677 GST_OBJECT_LOCK (src);
678 res = src->blocksize;
679 GST_OBJECT_UNLOCK (src);
686 * gst_base_src_set_do_timestamp:
688 * @timestamp: enable or disable timestamping
690 * Configure @src to automatically timestamp outgoing buffers based on the
691 * current running_time of the pipeline. This property is mostly useful for live
697 gst_base_src_set_do_timestamp (GstBaseSrc * src, gboolean timestamp)
699 g_return_if_fail (GST_IS_BASE_SRC (src));
701 GST_OBJECT_LOCK (src);
702 src->priv->do_timestamp = timestamp;
703 GST_OBJECT_UNLOCK (src);
707 * gst_base_src_get_do_timestamp:
710 * Query if @src timestamps outgoing buffers based on the current running_time.
712 * Returns: %TRUE if the base class will automatically timestamp outgoing buffers.
717 gst_base_src_get_do_timestamp (GstBaseSrc * src)
721 g_return_val_if_fail (GST_IS_BASE_SRC (src), FALSE);
723 GST_OBJECT_LOCK (src);
724 res = src->priv->do_timestamp;
725 GST_OBJECT_UNLOCK (src);
731 * gst_base_src_new_seamless_segment:
733 * @start: The new start value for the segment
734 * @stop: Stop value for the new segment
735 * @position: The position value for the new segent
737 * Prepare a new seamless segment for emission downstream. This function must
738 * only be called by derived sub-classes, and only from the create() function,
739 * as the stream-lock needs to be held.
741 * The format for the new segment will be the current format of the source, as
742 * configured with gst_base_src_set_format()
744 * Returns: %TRUE if preparation of the seamless segment succeeded.
749 gst_base_src_new_seamless_segment (GstBaseSrc * src, gint64 start, gint64 stop,
754 GST_DEBUG_OBJECT (src,
755 "Starting new seamless segment. Start %" GST_TIME_FORMAT " stop %"
756 GST_TIME_FORMAT " position %" GST_TIME_FORMAT, GST_TIME_ARGS (start),
757 GST_TIME_ARGS (stop), GST_TIME_ARGS (position));
759 GST_OBJECT_LOCK (src);
760 if (src->data.ABI.running && !src->priv->newsegment_pending) {
761 if (src->priv->close_segment)
762 gst_event_unref (src->priv->close_segment);
763 src->priv->close_segment =
764 gst_event_new_new_segment_full (TRUE,
765 src->segment.rate, src->segment.applied_rate, src->segment.format,
766 src->segment.start, src->segment.last_stop, src->segment.time);
769 gst_segment_set_newsegment_full (&src->segment, FALSE, src->segment.rate,
770 src->segment.applied_rate, src->segment.format, start, stop, position);
772 if (src->priv->start_segment)
773 gst_event_unref (src->priv->start_segment);
774 if (src->segment.rate >= 0.0) {
775 /* forward, we send data from last_stop to stop */
776 src->priv->start_segment =
777 gst_event_new_new_segment_full (FALSE,
778 src->segment.rate, src->segment.applied_rate, src->segment.format,
779 src->segment.last_stop, stop, src->segment.time);
781 /* reverse, we send data from last_stop to start */
782 src->priv->start_segment =
783 gst_event_new_new_segment_full (FALSE,
784 src->segment.rate, src->segment.applied_rate, src->segment.format,
785 src->segment.start, src->segment.last_stop, src->segment.time);
787 GST_OBJECT_UNLOCK (src);
789 src->priv->discont = TRUE;
790 src->data.ABI.running = TRUE;
796 gst_base_src_setcaps (GstPad * pad, GstCaps * caps)
798 GstBaseSrcClass *bclass;
802 bsrc = GST_BASE_SRC (GST_PAD_PARENT (pad));
803 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
805 if (bclass->set_caps)
806 res = bclass->set_caps (bsrc, caps);
812 gst_base_src_getcaps (GstPad * pad)
814 GstBaseSrcClass *bclass;
816 GstCaps *caps = NULL;
818 bsrc = GST_BASE_SRC (GST_PAD_PARENT (pad));
819 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
820 if (bclass->get_caps)
821 caps = bclass->get_caps (bsrc);
824 GstPadTemplate *pad_template;
827 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
828 if (pad_template != NULL) {
829 caps = gst_caps_ref (gst_pad_template_get_caps (pad_template));
836 gst_base_src_fixate (GstPad * pad, GstCaps * caps)
838 GstBaseSrcClass *bclass;
841 bsrc = GST_BASE_SRC (gst_pad_get_parent (pad));
842 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
845 bclass->fixate (bsrc, caps);
847 gst_object_unref (bsrc);
851 gst_base_src_default_query (GstBaseSrc * src, GstQuery * query)
855 switch (GST_QUERY_TYPE (query)) {
856 case GST_QUERY_POSITION:
860 gst_query_parse_position (query, &format, NULL);
862 GST_DEBUG_OBJECT (src, "position query in format %s",
863 gst_format_get_name (format));
866 case GST_FORMAT_PERCENT:
872 GST_OBJECT_LOCK (src);
873 position = src->segment.last_stop;
874 duration = src->segment.duration;
875 GST_OBJECT_UNLOCK (src);
877 if (position != -1 && duration != -1) {
878 if (position < duration)
879 percent = gst_util_uint64_scale (GST_FORMAT_PERCENT_MAX, position,
882 percent = GST_FORMAT_PERCENT_MAX;
886 gst_query_set_position (query, GST_FORMAT_PERCENT, percent);
893 GstFormat seg_format;
895 GST_OBJECT_LOCK (src);
897 gst_segment_to_stream_time (&src->segment, src->segment.format,
898 src->segment.last_stop);
899 seg_format = src->segment.format;
900 GST_OBJECT_UNLOCK (src);
902 if (position != -1) {
903 /* convert to requested format */
905 gst_pad_query_convert (src->srcpad, seg_format,
906 position, &format, &position);
910 gst_query_set_position (query, format, position);
916 case GST_QUERY_DURATION:
920 gst_query_parse_duration (query, &format, NULL);
922 GST_DEBUG_OBJECT (src, "duration query in format %s",
923 gst_format_get_name (format));
926 case GST_FORMAT_PERCENT:
927 gst_query_set_duration (query, GST_FORMAT_PERCENT,
928 GST_FORMAT_PERCENT_MAX);
934 GstFormat seg_format;
936 GST_OBJECT_LOCK (src);
937 /* this is the duration as configured by the subclass. */
938 duration = src->segment.duration;
939 seg_format = src->segment.format;
940 GST_OBJECT_UNLOCK (src);
942 GST_LOG_OBJECT (src, "duration %" G_GINT64_FORMAT ", format %s",
943 duration, gst_format_get_name (seg_format));
945 if (duration != -1) {
946 /* convert to requested format, if this fails, we have a duration
947 * but we cannot answer the query, we must return FALSE. */
949 gst_pad_query_convert (src->srcpad, seg_format,
950 duration, &format, &duration);
952 /* The subclass did not configure a duration, we assume that the
953 * media has an unknown duration then and we return TRUE to report
954 * this. Note that this is not the same as returning FALSE, which
955 * means that we cannot report the duration at all. */
958 gst_query_set_duration (query, format, duration);
965 case GST_QUERY_SEEKING:
967 GstFormat format, seg_format;
970 GST_OBJECT_LOCK (src);
971 duration = src->segment.duration;
972 seg_format = src->segment.format;
973 GST_OBJECT_UNLOCK (src);
975 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
976 if (format == seg_format) {
977 gst_query_set_seeking (query, seg_format,
978 gst_base_src_seekable (src), 0, duration);
981 /* FIXME 0.11: return TRUE + seekable=FALSE for SEEKING query here */
982 /* Don't reply to the query to make up for demuxers which don't
983 * handle the SEEKING query yet. Players like Totem will fall back
984 * to the duration when the SEEKING query isn't answered. */
989 case GST_QUERY_SEGMENT:
993 GST_OBJECT_LOCK (src);
994 /* no end segment configured, current duration then */
995 if ((stop = src->segment.stop) == -1)
996 stop = src->segment.duration;
997 start = src->segment.start;
999 /* adjust to stream time */
1000 if (src->segment.time != -1) {
1001 start -= src->segment.time;
1003 stop -= src->segment.time;
1006 gst_query_set_segment (query, src->segment.rate, src->segment.format,
1008 GST_OBJECT_UNLOCK (src);
1013 case GST_QUERY_FORMATS:
1015 gst_query_set_formats (query, 3, GST_FORMAT_DEFAULT,
1016 GST_FORMAT_BYTES, GST_FORMAT_PERCENT);
1020 case GST_QUERY_CONVERT:
1022 GstFormat src_fmt, dest_fmt;
1023 gint64 src_val, dest_val;
1025 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
1027 /* we can only convert between equal formats... */
1028 if (src_fmt == dest_fmt) {
1034 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
1037 case GST_QUERY_LATENCY:
1039 GstClockTime min, max;
1042 /* Subclasses should override and implement something usefull */
1043 res = gst_base_src_query_latency (src, &live, &min, &max);
1045 GST_LOG_OBJECT (src, "report latency: live %d, min %" GST_TIME_FORMAT
1046 ", max %" GST_TIME_FORMAT, live, GST_TIME_ARGS (min),
1047 GST_TIME_ARGS (max));
1049 gst_query_set_latency (query, live, min, max);
1052 case GST_QUERY_JITTER:
1053 case GST_QUERY_RATE:
1056 case GST_QUERY_BUFFERING:
1058 GstFormat format, seg_format;
1059 gint64 start, stop, estimated;
1061 gst_query_parse_buffering_range (query, &format, NULL, NULL, NULL);
1063 GST_DEBUG_OBJECT (src, "buffering query in format %s",
1064 gst_format_get_name (format));
1066 GST_OBJECT_LOCK (src);
1067 if (src->random_access) {
1070 if (format == GST_FORMAT_PERCENT)
1071 stop = GST_FORMAT_PERCENT_MAX;
1073 stop = src->segment.duration;
1079 seg_format = src->segment.format;
1080 GST_OBJECT_UNLOCK (src);
1082 /* convert to required format. When the conversion fails, we can't answer
1083 * the query. When the value is unknown, we can don't perform conversion
1084 * but report TRUE. */
1085 if (format != GST_FORMAT_PERCENT && stop != -1) {
1086 res = gst_pad_query_convert (src->srcpad, seg_format,
1087 stop, &format, &stop);
1091 if (res && format != GST_FORMAT_PERCENT && start != -1)
1092 res = gst_pad_query_convert (src->srcpad, seg_format,
1093 start, &format, &start);
1095 gst_query_set_buffering_range (query, format, start, stop, estimated);
1102 GST_DEBUG_OBJECT (src, "query %s returns %d", GST_QUERY_TYPE_NAME (query),
1108 gst_base_src_query (GstPad * pad, GstQuery * query)
1111 GstBaseSrcClass *bclass;
1112 gboolean result = FALSE;
1114 src = GST_BASE_SRC (gst_pad_get_parent (pad));
1116 bclass = GST_BASE_SRC_GET_CLASS (src);
1119 result = bclass->query (src, query);
1121 result = gst_pad_query_default (pad, query);
1123 gst_object_unref (src);
1129 gst_base_src_default_do_seek (GstBaseSrc * src, GstSegment * segment)
1131 gboolean res = TRUE;
1133 /* update our offset if the start/stop position was updated */
1134 if (segment->format == GST_FORMAT_BYTES) {
1135 segment->time = segment->start;
1136 } else if (segment->start == 0) {
1137 /* seek to start, we can implement a default for this. */
1141 GST_INFO_OBJECT (src, "Can't do a default seek");
1148 gst_base_src_do_seek (GstBaseSrc * src, GstSegment * segment)
1150 GstBaseSrcClass *bclass;
1151 gboolean result = FALSE;
1153 bclass = GST_BASE_SRC_GET_CLASS (src);
1155 if (bclass->do_seek)
1156 result = bclass->do_seek (src, segment);
1161 #define SEEK_TYPE_IS_RELATIVE(t) (((t) != GST_SEEK_TYPE_NONE) && ((t) != GST_SEEK_TYPE_SET))
1164 gst_base_src_default_prepare_seek_segment (GstBaseSrc * src, GstEvent * event,
1165 GstSegment * segment)
1167 /* By default, we try one of 2 things:
1168 * - For absolute seek positions, convert the requested position to our
1169 * configured processing format and place it in the output segment \
1170 * - For relative seek positions, convert our current (input) values to the
1171 * seek format, adjust by the relative seek offset and then convert back to
1172 * the processing format
1174 GstSeekType cur_type, stop_type;
1177 GstFormat seek_format, dest_format;
1180 gboolean res = TRUE;
1182 gst_event_parse_seek (event, &rate, &seek_format, &flags,
1183 &cur_type, &cur, &stop_type, &stop);
1184 dest_format = segment->format;
1186 if (seek_format == dest_format) {
1187 gst_segment_set_seek (segment, rate, seek_format, flags,
1188 cur_type, cur, stop_type, stop, &update);
1192 if (cur_type != GST_SEEK_TYPE_NONE) {
1193 /* FIXME: Handle seek_cur & seek_end by converting the input segment vals */
1195 gst_pad_query_convert (src->srcpad, seek_format, cur, &dest_format,
1197 cur_type = GST_SEEK_TYPE_SET;
1200 if (res && stop_type != GST_SEEK_TYPE_NONE) {
1201 /* FIXME: Handle seek_cur & seek_end by converting the input segment vals */
1203 gst_pad_query_convert (src->srcpad, seek_format, stop, &dest_format,
1205 stop_type = GST_SEEK_TYPE_SET;
1208 /* And finally, configure our output segment in the desired format */
1209 gst_segment_set_seek (segment, rate, dest_format, flags, cur_type, cur,
1210 stop_type, stop, &update);
1219 GST_DEBUG_OBJECT (src, "undefined format given, seek aborted.");
1225 gst_base_src_prepare_seek_segment (GstBaseSrc * src, GstEvent * event,
1226 GstSegment * seeksegment)
1228 GstBaseSrcClass *bclass;
1229 gboolean result = FALSE;
1231 bclass = GST_BASE_SRC_GET_CLASS (src);
1233 if (bclass->prepare_seek_segment)
1234 result = bclass->prepare_seek_segment (src, event, seeksegment);
1239 /* this code implements the seeking. It is a good example
1240 * handling all cases.
1242 * A seek updates the currently configured segment.start
1243 * and segment.stop values based on the SEEK_TYPE. If the
1244 * segment.start value is updated, a seek to this new position
1245 * should be performed.
1247 * The seek can only be executed when we are not currently
1248 * streaming any data, to make sure that this is the case, we
1249 * acquire the STREAM_LOCK which is taken when we are in the
1250 * _loop() function or when a getrange() is called. Normally
1251 * we will not receive a seek if we are operating in pull mode
1252 * though. When we operate as a live source we might block on the live
1253 * cond, which does not release the STREAM_LOCK. Therefore we will try
1254 * to grab the LIVE_LOCK instead of the STREAM_LOCK to make sure it is
1255 * safe to perform the seek.
1257 * When we are in the loop() function, we might be in the middle
1258 * of pushing a buffer, which might block in a sink. To make sure
1259 * that the push gets unblocked we push out a FLUSH_START event.
1260 * Our loop function will get a WRONG_STATE return value from
1261 * the push and will pause, effectively releasing the STREAM_LOCK.
1263 * For a non-flushing seek, we pause the task, which might eventually
1264 * release the STREAM_LOCK. We say eventually because when the sink
1265 * blocks on the sample we might wait a very long time until the sink
1266 * unblocks the sample. In any case we acquire the STREAM_LOCK and
1267 * can continue the seek. A non-flushing seek is normally done in a
1268 * running pipeline to perform seamless playback, this means that the sink is
1269 * PLAYING and will return from its chain function.
1270 * In the case of a non-flushing seek we need to make sure that the
1271 * data we output after the seek is continuous with the previous data,
1272 * this is because a non-flushing seek does not reset the running-time
1273 * to 0. We do this by closing the currently running segment, ie. sending
1274 * a new_segment event with the stop position set to the last processed
1277 * After updating the segment.start/stop values, we prepare for
1278 * streaming again. We push out a FLUSH_STOP to make the peer pad
1279 * accept data again and we start our task again.
1281 * A segment seek posts a message on the bus saying that the playback
1282 * of the segment started. We store the segment flag internally because
1283 * when we reach the segment.stop we have to post a segment.done
1284 * instead of EOS when doing a segment seek.
1286 /* FIXME (0.11), we have the unlock gboolean here because most current
1287 * implementations (fdsrc, -base/gst/tcp/, ...) unconditionally unlock, even when
1288 * the streaming thread isn't running, resulting in bogus unlocks later when it
1289 * starts. This is fixed by adding unlock_stop, but we should still avoid unlocking
1290 * unnecessarily for backwards compatibility. Ergo, the unlock variable stays
1294 gst_base_src_perform_seek (GstBaseSrc * src, GstEvent * event, gboolean unlock)
1296 gboolean res = TRUE, tres;
1298 GstFormat seek_format, dest_format;
1300 GstSeekType cur_type, stop_type;
1302 gboolean flush, playing;
1304 gboolean relative_seek = FALSE;
1305 gboolean seekseg_configured = FALSE;
1306 GstSegment seeksegment;
1310 GST_DEBUG_OBJECT (src, "doing seek: %" GST_PTR_FORMAT, event);
1312 GST_OBJECT_LOCK (src);
1313 dest_format = src->segment.format;
1314 GST_OBJECT_UNLOCK (src);
1317 gst_event_parse_seek (event, &rate, &seek_format, &flags,
1318 &cur_type, &cur, &stop_type, &stop);
1320 relative_seek = SEEK_TYPE_IS_RELATIVE (cur_type) ||
1321 SEEK_TYPE_IS_RELATIVE (stop_type);
1323 if (dest_format != seek_format && !relative_seek) {
1324 /* If we have an ABSOLUTE position (SEEK_SET only), we can convert it
1325 * here before taking the stream lock, otherwise we must convert it later,
1326 * once we have the stream lock and can read the last configures segment
1327 * start and stop positions */
1328 gst_segment_init (&seeksegment, dest_format);
1330 if (!gst_base_src_prepare_seek_segment (src, event, &seeksegment))
1331 goto prepare_failed;
1333 seekseg_configured = TRUE;
1336 flush = flags & GST_SEEK_FLAG_FLUSH;
1337 seqnum = gst_event_get_seqnum (event);
1340 /* get next seqnum */
1341 seqnum = gst_util_seqnum_next ();
1344 /* send flush start */
1346 tevent = gst_event_new_flush_start ();
1347 gst_event_set_seqnum (tevent, seqnum);
1348 gst_pad_push_event (src->srcpad, tevent);
1350 gst_pad_pause_task (src->srcpad);
1352 /* unblock streaming thread. */
1353 gst_base_src_set_flushing (src, TRUE, FALSE, unlock, &playing);
1355 /* grab streaming lock, this should eventually be possible, either
1356 * because the task is paused, our streaming thread stopped
1357 * or because our peer is flushing. */
1358 GST_PAD_STREAM_LOCK (src->srcpad);
1359 if (G_UNLIKELY (src->priv->seqnum == seqnum)) {
1360 /* we have seen this event before, issue a warning for now */
1361 GST_WARNING_OBJECT (src, "duplicate event found %" G_GUINT32_FORMAT,
1364 src->priv->seqnum = seqnum;
1365 GST_DEBUG_OBJECT (src, "seek with seqnum %" G_GUINT32_FORMAT, seqnum);
1368 gst_base_src_set_flushing (src, FALSE, playing, unlock, NULL);
1370 /* If we configured the seeksegment above, don't overwrite it now. Otherwise
1371 * copy the current segment info into the temp segment that we can actually
1372 * attempt the seek with. We only update the real segment if the seek suceeds. */
1373 if (!seekseg_configured) {
1374 memcpy (&seeksegment, &src->segment, sizeof (GstSegment));
1376 /* now configure the final seek segment */
1378 if (seeksegment.format != seek_format) {
1379 /* OK, here's where we give the subclass a chance to convert the relative
1380 * seek into an absolute one in the processing format. We set up any
1381 * absolute seek above, before taking the stream lock. */
1382 if (!gst_base_src_prepare_seek_segment (src, event, &seeksegment)) {
1383 GST_DEBUG_OBJECT (src, "Preparing the seek failed after flushing. "
1388 /* The seek format matches our processing format, no need to ask the
1389 * the subclass to configure the segment. */
1390 gst_segment_set_seek (&seeksegment, rate, seek_format, flags,
1391 cur_type, cur, stop_type, stop, &update);
1394 /* Else, no seek event passed, so we're just (re)starting the
1399 GST_DEBUG_OBJECT (src, "segment configured from %" G_GINT64_FORMAT
1400 " to %" G_GINT64_FORMAT ", position %" G_GINT64_FORMAT,
1401 seeksegment.start, seeksegment.stop, seeksegment.last_stop);
1403 /* do the seek, segment.last_stop contains the new position. */
1404 res = gst_base_src_do_seek (src, &seeksegment);
1407 /* and prepare to continue streaming */
1409 tevent = gst_event_new_flush_stop ();
1410 gst_event_set_seqnum (tevent, seqnum);
1411 /* send flush stop, peer will accept data and events again. We
1412 * are not yet providing data as we still have the STREAM_LOCK. */
1413 gst_pad_push_event (src->srcpad, tevent);
1414 } else if (res && src->data.ABI.running) {
1415 /* we are running the current segment and doing a non-flushing seek,
1416 * close the segment first based on the last_stop. */
1417 GST_DEBUG_OBJECT (src, "closing running segment %" G_GINT64_FORMAT
1418 " to %" G_GINT64_FORMAT, src->segment.start, src->segment.last_stop);
1420 /* queue the segment for sending in the stream thread */
1421 if (src->priv->close_segment)
1422 gst_event_unref (src->priv->close_segment);
1423 src->priv->close_segment =
1424 gst_event_new_new_segment_full (TRUE,
1425 src->segment.rate, src->segment.applied_rate, src->segment.format,
1426 src->segment.start, src->segment.last_stop, src->segment.time);
1427 gst_event_set_seqnum (src->priv->close_segment, seqnum);
1430 /* The subclass must have converted the segment to the processing format
1432 if (res && seeksegment.format != dest_format) {
1433 GST_DEBUG_OBJECT (src, "Subclass failed to prepare a seek segment "
1434 "in the correct format. Aborting seek.");
1438 /* if the seek was successful, we update our real segment and push
1439 * out the new segment. */
1441 GST_OBJECT_LOCK (src);
1442 memcpy (&src->segment, &seeksegment, sizeof (GstSegment));
1443 GST_OBJECT_UNLOCK (src);
1445 if (seeksegment.flags & GST_SEEK_FLAG_SEGMENT) {
1446 GstMessage *message;
1448 message = gst_message_new_segment_start (GST_OBJECT (src),
1449 seeksegment.format, seeksegment.last_stop);
1450 gst_message_set_seqnum (message, seqnum);
1452 gst_element_post_message (GST_ELEMENT (src), message);
1455 /* for deriving a stop position for the playback segment from the seek
1456 * segment, we must take the duration when the stop is not set */
1457 if ((stop = seeksegment.stop) == -1)
1458 stop = seeksegment.duration;
1460 GST_DEBUG_OBJECT (src, "Sending newsegment from %" G_GINT64_FORMAT
1461 " to %" G_GINT64_FORMAT, seeksegment.start, stop);
1463 /* now replace the old segment so that we send it in the stream thread the
1464 * next time it is scheduled. */
1465 if (src->priv->start_segment)
1466 gst_event_unref (src->priv->start_segment);
1467 if (seeksegment.rate >= 0.0) {
1468 /* forward, we send data from last_stop to stop */
1469 src->priv->start_segment =
1470 gst_event_new_new_segment_full (FALSE,
1471 seeksegment.rate, seeksegment.applied_rate, seeksegment.format,
1472 seeksegment.last_stop, stop, seeksegment.time);
1474 /* reverse, we send data from last_stop to start */
1475 src->priv->start_segment =
1476 gst_event_new_new_segment_full (FALSE,
1477 seeksegment.rate, seeksegment.applied_rate, seeksegment.format,
1478 seeksegment.start, seeksegment.last_stop, seeksegment.time);
1480 gst_event_set_seqnum (src->priv->start_segment, seqnum);
1481 src->priv->newsegment_pending = TRUE;
1484 src->priv->discont = TRUE;
1485 src->data.ABI.running = TRUE;
1486 /* and restart the task in case it got paused explicitly or by
1487 * the FLUSH_START event we pushed out. */
1488 tres = gst_pad_start_task (src->srcpad, (GstTaskFunction) gst_base_src_loop,
1493 /* and release the lock again so we can continue streaming */
1494 GST_PAD_STREAM_UNLOCK (src->srcpad);
1500 GST_DEBUG_OBJECT (src, "Preparing the seek failed before flushing. "
1505 static const GstQueryType *
1506 gst_base_src_get_query_types (GstElement * element)
1508 static const GstQueryType query_types[] = {
1524 /* all events send to this element directly. This is mainly done from the
1528 gst_base_src_send_event (GstElement * element, GstEvent * event)
1531 gboolean result = FALSE;
1533 src = GST_BASE_SRC (element);
1535 GST_DEBUG_OBJECT (src, "handling event %p %" GST_PTR_FORMAT, event, event);
1537 switch (GST_EVENT_TYPE (event)) {
1538 /* bidirectional events */
1539 case GST_EVENT_FLUSH_START:
1540 case GST_EVENT_FLUSH_STOP:
1541 /* sending random flushes downstream can break stuff,
1542 * especially sync since all segment info will get flushed */
1545 /* downstream serialized events */
1548 GstBaseSrcClass *bclass;
1550 bclass = GST_BASE_SRC_GET_CLASS (src);
1552 /* queue EOS and make sure the task or pull function performs the EOS
1555 * We have two possibilities:
1557 * - Before we are to enter the _create function, we check the pending_eos
1558 * first and do EOS instead of entering it.
1559 * - If we are in the _create function or we did not manage to set the
1560 * flag fast enough and we are about to enter the _create function,
1561 * we unlock it so that we exit with WRONG_STATE immediatly. We then
1562 * check the EOS flag and do the EOS logic.
1564 g_atomic_int_set (&src->priv->pending_eos, TRUE);
1565 GST_DEBUG_OBJECT (src, "EOS marked, calling unlock");
1567 /* unlock the _create function so that we can check the pending_eos flag
1568 * and we can do EOS. This will eventually release the LIVE_LOCK again so
1569 * that we can grab it and stop the unlock again. We don't take the stream
1570 * lock so that this operation is guaranteed to never block. */
1572 bclass->unlock (src);
1574 GST_DEBUG_OBJECT (src, "unlock called, waiting for LIVE_LOCK");
1576 GST_LIVE_LOCK (src);
1577 GST_DEBUG_OBJECT (src, "LIVE_LOCK acquired, calling unlock_stop");
1578 /* now stop the unlock of the streaming thread again. Grabbing the live
1579 * lock is enough because that protects the create function. */
1580 if (bclass->unlock_stop)
1581 bclass->unlock_stop (src);
1582 GST_LIVE_UNLOCK (src);
1587 case GST_EVENT_NEWSEGMENT:
1588 /* sending random NEWSEGMENT downstream can break sync. */
1591 case GST_EVENT_CUSTOM_DOWNSTREAM:
1592 case GST_EVENT_CUSTOM_BOTH:
1593 /* Insert TAG, CUSTOM_DOWNSTREAM, CUSTOM_BOTH in the dataflow */
1594 GST_OBJECT_LOCK (src);
1595 src->priv->pending_events =
1596 g_list_append (src->priv->pending_events, event);
1597 g_atomic_int_set (&src->priv->have_events, TRUE);
1598 GST_OBJECT_UNLOCK (src);
1602 case GST_EVENT_BUFFERSIZE:
1603 /* does not seem to make much sense currently */
1606 /* upstream events */
1608 /* elements should override send_event and do something */
1610 case GST_EVENT_SEEK:
1614 GST_OBJECT_LOCK (src->srcpad);
1615 if (GST_PAD_ACTIVATE_MODE (src->srcpad) == GST_ACTIVATE_PULL)
1617 started = GST_PAD_ACTIVATE_MODE (src->srcpad) == GST_ACTIVATE_PUSH;
1618 GST_OBJECT_UNLOCK (src->srcpad);
1621 GST_DEBUG_OBJECT (src, "performing seek");
1622 /* when we are running in push mode, we can execute the
1623 * seek right now, we need to unlock. */
1624 result = gst_base_src_perform_seek (src, event, TRUE);
1628 /* else we store the event and execute the seek when we
1630 GST_OBJECT_LOCK (src);
1631 GST_DEBUG_OBJECT (src, "queueing seek");
1632 event_p = &src->data.ABI.pending_seek;
1633 gst_event_replace ((GstEvent **) event_p, event);
1634 GST_OBJECT_UNLOCK (src);
1635 /* assume the seek will work */
1640 case GST_EVENT_NAVIGATION:
1641 /* could make sense for elements that do something with navigation events
1642 * but then they would need to override the send_event function */
1644 case GST_EVENT_LATENCY:
1645 /* does not seem to make sense currently */
1649 case GST_EVENT_CUSTOM_UPSTREAM:
1650 /* override send_event if you want this */
1652 case GST_EVENT_CUSTOM_DOWNSTREAM_OOB:
1653 case GST_EVENT_CUSTOM_BOTH_OOB:
1654 /* insert a random custom event into the pipeline */
1655 GST_DEBUG_OBJECT (src, "pushing custom OOB event downstream");
1656 result = gst_pad_push_event (src->srcpad, event);
1657 /* we gave away the ref to the event in the push */
1664 /* if we still have a ref to the event, unref it now */
1666 gst_event_unref (event);
1673 GST_DEBUG_OBJECT (src, "cannot perform seek when operating in pull mode");
1674 GST_OBJECT_UNLOCK (src->srcpad);
1681 gst_base_src_seekable (GstBaseSrc * src)
1683 GstBaseSrcClass *bclass;
1684 bclass = GST_BASE_SRC_GET_CLASS (src);
1685 if (bclass->is_seekable)
1686 return bclass->is_seekable (src);
1692 gst_base_src_update_qos (GstBaseSrc * src,
1693 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
1695 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, src,
1696 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
1697 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
1699 GST_OBJECT_LOCK (src);
1700 src->priv->proportion = proportion;
1701 src->priv->earliest_time = timestamp + diff;
1702 GST_OBJECT_UNLOCK (src);
1707 gst_base_src_default_event (GstBaseSrc * src, GstEvent * event)
1711 GST_DEBUG_OBJECT (src, "handle event %" GST_PTR_FORMAT, event);
1713 switch (GST_EVENT_TYPE (event)) {
1714 case GST_EVENT_SEEK:
1715 /* is normally called when in push mode */
1716 if (!gst_base_src_seekable (src))
1719 result = gst_base_src_perform_seek (src, event, TRUE);
1721 case GST_EVENT_FLUSH_START:
1722 /* cancel any blocking getrange, is normally called
1723 * when in pull mode. */
1724 result = gst_base_src_set_flushing (src, TRUE, FALSE, TRUE, NULL);
1726 case GST_EVENT_FLUSH_STOP:
1727 result = gst_base_src_set_flushing (src, FALSE, TRUE, TRUE, NULL);
1732 GstClockTimeDiff diff;
1733 GstClockTime timestamp;
1735 gst_event_parse_qos (event, &proportion, &diff, ×tamp);
1736 gst_base_src_update_qos (src, proportion, diff, timestamp);
1749 GST_DEBUG_OBJECT (src, "is not seekable");
1755 gst_base_src_event_handler (GstPad * pad, GstEvent * event)
1758 GstBaseSrcClass *bclass;
1759 gboolean result = FALSE;
1761 src = GST_BASE_SRC (gst_pad_get_parent (pad));
1762 if (G_UNLIKELY (src == NULL))
1764 bclass = GST_BASE_SRC_GET_CLASS (src);
1766 if (bclass->event) {
1767 if (!(result = bclass->event (src, event)))
1768 goto subclass_failed;
1772 gst_event_unref (event);
1773 gst_object_unref (src);
1780 GST_DEBUG_OBJECT (src, "subclass refused event");
1786 gst_base_src_set_property (GObject * object, guint prop_id,
1787 const GValue * value, GParamSpec * pspec)
1791 src = GST_BASE_SRC (object);
1794 case PROP_BLOCKSIZE:
1795 gst_base_src_set_blocksize (src, g_value_get_ulong (value));
1797 case PROP_NUM_BUFFERS:
1798 src->num_buffers = g_value_get_int (value);
1801 src->data.ABI.typefind = g_value_get_boolean (value);
1803 case PROP_DO_TIMESTAMP:
1804 gst_base_src_set_do_timestamp (src, g_value_get_boolean (value));
1807 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1813 gst_base_src_get_property (GObject * object, guint prop_id, GValue * value,
1818 src = GST_BASE_SRC (object);
1821 case PROP_BLOCKSIZE:
1822 g_value_set_ulong (value, gst_base_src_get_blocksize (src));
1824 case PROP_NUM_BUFFERS:
1825 g_value_set_int (value, src->num_buffers);
1828 g_value_set_boolean (value, src->data.ABI.typefind);
1830 case PROP_DO_TIMESTAMP:
1831 g_value_set_boolean (value, gst_base_src_get_do_timestamp (src));
1834 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1839 /* with STREAM_LOCK and LOCK */
1840 static GstClockReturn
1841 gst_base_src_wait (GstBaseSrc * basesrc, GstClock * clock, GstClockTime time)
1846 id = gst_clock_new_single_shot_id (clock, time);
1848 basesrc->clock_id = id;
1849 /* release the live lock while waiting */
1850 GST_LIVE_UNLOCK (basesrc);
1852 ret = gst_clock_id_wait (id, NULL);
1854 GST_LIVE_LOCK (basesrc);
1855 gst_clock_id_unref (id);
1856 basesrc->clock_id = NULL;
1861 /* perform synchronisation on a buffer.
1864 static GstClockReturn
1865 gst_base_src_do_sync (GstBaseSrc * basesrc, GstBuffer * buffer)
1867 GstClockReturn result;
1868 GstClockTime start, end;
1869 GstBaseSrcClass *bclass;
1870 GstClockTime base_time;
1872 GstClockTime now = GST_CLOCK_TIME_NONE, timestamp;
1873 gboolean do_timestamp, first, pseudo_live;
1875 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
1878 if (bclass->get_times)
1879 bclass->get_times (basesrc, buffer, &start, &end);
1881 /* get buffer timestamp */
1882 timestamp = GST_BUFFER_TIMESTAMP (buffer);
1884 /* grab the lock to prepare for clocking and calculate the startup
1886 GST_OBJECT_LOCK (basesrc);
1888 /* if we are asked to sync against the clock we are a pseudo live element */
1889 pseudo_live = (start != -1 && basesrc->is_live);
1890 /* check for the first buffer */
1891 first = (basesrc->priv->latency == -1);
1893 if (timestamp != -1 && pseudo_live) {
1894 GstClockTime latency;
1896 /* we have a timestamp and a sync time, latency is the diff */
1897 if (timestamp <= start)
1898 latency = start - timestamp;
1903 GST_DEBUG_OBJECT (basesrc, "pseudo_live with latency %" GST_TIME_FORMAT,
1904 GST_TIME_ARGS (latency));
1905 /* first time we calculate latency, just configure */
1906 basesrc->priv->latency = latency;
1908 if (basesrc->priv->latency != latency) {
1909 /* we have a new latency, FIXME post latency message */
1910 basesrc->priv->latency = latency;
1911 GST_DEBUG_OBJECT (basesrc, "latency changed to %" GST_TIME_FORMAT,
1912 GST_TIME_ARGS (latency));
1916 GST_DEBUG_OBJECT (basesrc, "no latency needed, live %d, sync %d",
1917 basesrc->is_live, start != -1);
1918 basesrc->priv->latency = 0;
1921 /* get clock, if no clock, we can't sync or do timestamps */
1922 if ((clock = GST_ELEMENT_CLOCK (basesrc)) == NULL)
1925 base_time = GST_ELEMENT_CAST (basesrc)->base_time;
1927 do_timestamp = basesrc->priv->do_timestamp;
1929 /* first buffer, calculate the timestamp offset */
1931 GstClockTime running_time;
1933 now = gst_clock_get_time (clock);
1934 running_time = now - base_time;
1936 GST_LOG_OBJECT (basesrc,
1937 "startup timestamp: %" GST_TIME_FORMAT ", running_time %"
1938 GST_TIME_FORMAT, GST_TIME_ARGS (timestamp),
1939 GST_TIME_ARGS (running_time));
1941 if (pseudo_live && timestamp != -1) {
1942 /* live source and we need to sync, add startup latency to all timestamps
1943 * to get the real running_time. Live sources should always timestamp
1944 * according to the current running time. */
1945 basesrc->priv->ts_offset = GST_CLOCK_DIFF (timestamp, running_time);
1947 GST_LOG_OBJECT (basesrc, "live with sync, ts_offset %" GST_TIME_FORMAT,
1948 GST_TIME_ARGS (basesrc->priv->ts_offset));
1950 basesrc->priv->ts_offset = 0;
1951 GST_LOG_OBJECT (basesrc, "no timestamp offset needed");
1954 if (!GST_CLOCK_TIME_IS_VALID (timestamp)) {
1956 timestamp = running_time;
1960 GST_BUFFER_TIMESTAMP (buffer) = timestamp;
1962 GST_LOG_OBJECT (basesrc, "created timestamp: %" GST_TIME_FORMAT,
1963 GST_TIME_ARGS (timestamp));
1966 /* add the timestamp offset we need for sync */
1967 timestamp += basesrc->priv->ts_offset;
1969 /* not the first buffer, the timestamp is the diff between the clock and
1971 if (do_timestamp && !GST_CLOCK_TIME_IS_VALID (timestamp)) {
1972 now = gst_clock_get_time (clock);
1974 GST_BUFFER_TIMESTAMP (buffer) = now - base_time;
1976 GST_LOG_OBJECT (basesrc, "created timestamp: %" GST_TIME_FORMAT,
1977 GST_TIME_ARGS (now - base_time));
1981 /* if we don't have a buffer timestamp, we don't sync */
1982 if (!GST_CLOCK_TIME_IS_VALID (start))
1985 if (basesrc->is_live && GST_CLOCK_TIME_IS_VALID (timestamp)) {
1986 /* for pseudo live sources, add our ts_offset to the timestamp */
1987 GST_BUFFER_TIMESTAMP (buffer) += basesrc->priv->ts_offset;
1988 start += basesrc->priv->ts_offset;
1991 GST_LOG_OBJECT (basesrc,
1992 "waiting for clock, base time %" GST_TIME_FORMAT
1993 ", stream_start %" GST_TIME_FORMAT,
1994 GST_TIME_ARGS (base_time), GST_TIME_ARGS (start));
1995 GST_OBJECT_UNLOCK (basesrc);
1997 result = gst_base_src_wait (basesrc, clock, start + base_time);
1999 GST_LOG_OBJECT (basesrc, "clock entry done: %d", result);
2006 GST_DEBUG_OBJECT (basesrc, "we have no clock");
2007 GST_OBJECT_UNLOCK (basesrc);
2008 return GST_CLOCK_OK;
2012 GST_DEBUG_OBJECT (basesrc, "no sync needed");
2013 GST_OBJECT_UNLOCK (basesrc);
2014 return GST_CLOCK_OK;
2018 /* Called with STREAM_LOCK and LIVE_LOCK */
2020 gst_base_src_update_length (GstBaseSrc * src, guint64 offset, guint * length)
2022 guint64 size, maxsize;
2023 GstBaseSrcClass *bclass;
2027 bclass = GST_BASE_SRC_GET_CLASS (src);
2029 format = src->segment.format;
2030 stop = src->segment.stop;
2031 /* get total file size */
2032 size = (guint64) src->segment.duration;
2034 /* only operate if we are working with bytes */
2035 if (format != GST_FORMAT_BYTES)
2038 /* the max amount of bytes to read is the total size or
2039 * up to the segment.stop if present. */
2041 maxsize = MIN (size, stop);
2045 GST_DEBUG_OBJECT (src,
2046 "reading offset %" G_GUINT64_FORMAT ", length %u, size %" G_GINT64_FORMAT
2047 ", segment.stop %" G_GINT64_FORMAT ", maxsize %" G_GINT64_FORMAT, offset,
2048 *length, size, stop, maxsize);
2050 /* check size if we have one */
2051 if (maxsize != -1) {
2052 /* if we run past the end, check if the file became bigger and
2054 if (G_UNLIKELY (offset + *length >= maxsize)) {
2055 /* see if length of the file changed */
2056 if (bclass->get_size)
2057 if (!bclass->get_size (src, &size))
2060 /* make sure we don't exceed the configured segment stop
2063 maxsize = MIN (size, stop);
2067 /* if we are at or past the end, EOS */
2068 if (G_UNLIKELY (offset >= maxsize))
2069 goto unexpected_length;
2071 /* else we can clip to the end */
2072 if (G_UNLIKELY (offset + *length >= maxsize))
2073 *length = maxsize - offset;
2078 /* keep track of current position and update duration.
2079 * segment is in bytes, we checked that above. */
2080 GST_OBJECT_LOCK (src);
2081 gst_segment_set_duration (&src->segment, GST_FORMAT_BYTES, size);
2082 gst_segment_set_last_stop (&src->segment, GST_FORMAT_BYTES, offset);
2083 GST_OBJECT_UNLOCK (src);
2094 /* must be called with LIVE_LOCK */
2095 static GstFlowReturn
2096 gst_base_src_get_range (GstBaseSrc * src, guint64 offset, guint length,
2100 GstBaseSrcClass *bclass;
2101 GstClockReturn status;
2103 bclass = GST_BASE_SRC_GET_CLASS (src);
2107 if (G_UNLIKELY (!src->live_running)) {
2108 ret = gst_base_src_wait_playing (src);
2109 if (ret != GST_FLOW_OK)
2114 if (G_UNLIKELY (!GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_STARTED)))
2117 if (G_UNLIKELY (!bclass->create))
2120 if (G_UNLIKELY (!gst_base_src_update_length (src, offset, &length)))
2121 goto unexpected_length;
2123 /* normally we don't count buffers */
2124 if (G_UNLIKELY (src->num_buffers_left >= 0)) {
2125 if (src->num_buffers_left == 0)
2126 goto reached_num_buffers;
2128 src->num_buffers_left--;
2131 /* don't enter the create function if a pending EOS event was set. For the
2132 * logic of the pending_eos, check the event function of this class. */
2133 if (G_UNLIKELY (g_atomic_int_get (&src->priv->pending_eos)))
2136 GST_DEBUG_OBJECT (src,
2137 "calling create offset %" G_GUINT64_FORMAT " length %u, time %"
2138 G_GINT64_FORMAT, offset, length, src->segment.time);
2140 ret = bclass->create (src, offset, length, buf);
2142 /* The create function could be unlocked because we have a pending EOS. It's
2143 * possible that we have a valid buffer from create that we need to
2144 * discard when the create function returned _OK. */
2145 if (G_UNLIKELY (g_atomic_int_get (&src->priv->pending_eos))) {
2146 if (ret == GST_FLOW_OK) {
2147 gst_buffer_unref (*buf);
2153 if (G_UNLIKELY (ret != GST_FLOW_OK))
2156 /* no timestamp set and we are at offset 0, we can timestamp with 0 */
2157 if (offset == 0 && src->segment.time == 0
2158 && GST_BUFFER_TIMESTAMP (*buf) == -1) {
2159 *buf = gst_buffer_make_metadata_writable (*buf);
2160 GST_BUFFER_TIMESTAMP (*buf) = 0;
2163 /* set pad caps on the buffer if the buffer had no caps */
2164 if (GST_BUFFER_CAPS (*buf) == NULL) {
2165 *buf = gst_buffer_make_metadata_writable (*buf);
2166 gst_buffer_set_caps (*buf, GST_PAD_CAPS (src->srcpad));
2169 /* now sync before pushing the buffer */
2170 status = gst_base_src_do_sync (src, *buf);
2172 /* waiting for the clock could have made us flushing */
2173 if (G_UNLIKELY (src->priv->flushing))
2177 case GST_CLOCK_EARLY:
2178 /* the buffer is too late. We currently don't drop the buffer. */
2179 GST_DEBUG_OBJECT (src, "buffer too late!, returning anyway");
2182 /* buffer synchronised properly */
2183 GST_DEBUG_OBJECT (src, "buffer ok");
2185 case GST_CLOCK_UNSCHEDULED:
2186 /* this case is triggered when we were waiting for the clock and
2187 * it got unlocked because we did a state change. In any case, get rid of
2189 gst_buffer_unref (*buf);
2191 if (!src->live_running) {
2192 /* We return WRONG_STATE when we are not running to stop the dataflow also
2193 * get rid of the produced buffer. */
2194 GST_DEBUG_OBJECT (src,
2195 "clock was unscheduled (%d), returning WRONG_STATE", status);
2196 ret = GST_FLOW_WRONG_STATE;
2198 /* If we are running when this happens, we quickly switched between
2199 * pause and playing. We try to produce a new buffer */
2200 GST_DEBUG_OBJECT (src,
2201 "clock was unscheduled (%d), but we are running", status);
2206 /* all other result values are unexpected and errors */
2207 GST_ELEMENT_ERROR (src, CORE, CLOCK,
2208 (_("Internal clock error.")),
2209 ("clock returned unexpected return value %d", status));
2210 gst_buffer_unref (*buf);
2212 ret = GST_FLOW_ERROR;
2220 GST_DEBUG_OBJECT (src, "wait_playing returned %d (%s)", ret,
2221 gst_flow_get_name (ret));
2226 GST_DEBUG_OBJECT (src, "create returned %d (%s)", ret,
2227 gst_flow_get_name (ret));
2232 GST_DEBUG_OBJECT (src, "getrange but not started");
2233 return GST_FLOW_WRONG_STATE;
2237 GST_DEBUG_OBJECT (src, "no create function");
2238 return GST_FLOW_ERROR;
2242 GST_DEBUG_OBJECT (src, "unexpected length %u (offset=%" G_GUINT64_FORMAT
2243 ", size=%" G_GINT64_FORMAT ")", length, offset, src->segment.duration);
2244 return GST_FLOW_UNEXPECTED;
2246 reached_num_buffers:
2248 GST_DEBUG_OBJECT (src, "sent all buffers");
2249 return GST_FLOW_UNEXPECTED;
2253 GST_DEBUG_OBJECT (src, "we are flushing");
2254 gst_buffer_unref (*buf);
2256 return GST_FLOW_WRONG_STATE;
2260 GST_DEBUG_OBJECT (src, "we are EOS");
2261 return GST_FLOW_UNEXPECTED;
2265 static GstFlowReturn
2266 gst_base_src_pad_get_range (GstPad * pad, guint64 offset, guint length,
2272 src = GST_BASE_SRC_CAST (gst_object_ref (GST_OBJECT_PARENT (pad)));
2274 GST_LIVE_LOCK (src);
2275 if (G_UNLIKELY (src->priv->flushing))
2278 res = gst_base_src_get_range (src, offset, length, buf);
2281 GST_LIVE_UNLOCK (src);
2283 gst_object_unref (src);
2290 GST_DEBUG_OBJECT (src, "we are flushing");
2291 res = GST_FLOW_WRONG_STATE;
2297 gst_base_src_default_check_get_range (GstBaseSrc * src)
2301 if (!GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_STARTED)) {
2302 GST_LOG_OBJECT (src, "doing start/stop to check get_range support");
2303 if (G_LIKELY (gst_base_src_start (src)))
2304 gst_base_src_stop (src);
2307 /* we can operate in getrange mode if the native format is bytes
2308 * and we are seekable, this condition is set in the random_access
2309 * flag and is set in the _start() method. */
2310 res = src->random_access;
2316 gst_base_src_check_get_range (GstBaseSrc * src)
2318 GstBaseSrcClass *bclass;
2321 bclass = GST_BASE_SRC_GET_CLASS (src);
2323 if (bclass->check_get_range == NULL)
2326 res = bclass->check_get_range (src);
2327 GST_LOG_OBJECT (src, "%s() returned %d",
2328 GST_DEBUG_FUNCPTR_NAME (bclass->check_get_range), (gint) res);
2335 GST_WARNING_OBJECT (src, "no check_get_range function set");
2341 gst_base_src_pad_check_get_range (GstPad * pad)
2346 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
2348 res = gst_base_src_check_get_range (src);
2354 gst_base_src_loop (GstPad * pad)
2357 GstBuffer *buf = NULL;
2362 GList *pending_events = NULL, *tmp;
2366 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
2368 GST_LIVE_LOCK (src);
2370 if (G_UNLIKELY (src->priv->flushing))
2373 src->priv->last_sent_eos = FALSE;
2375 blocksize = src->blocksize;
2377 /* if we operate in bytes, we can calculate an offset */
2378 if (src->segment.format == GST_FORMAT_BYTES) {
2379 position = src->segment.last_stop;
2380 /* for negative rates, start with subtracting the blocksize */
2381 if (src->segment.rate < 0.0) {
2382 /* we cannot go below segment.start */
2383 if (position > src->segment.start + blocksize)
2384 position -= blocksize;
2386 /* last block, remainder up to segment.start */
2387 blocksize = position - src->segment.start;
2388 position = src->segment.start;
2394 GST_LOG_OBJECT (src, "next_ts %" GST_TIME_FORMAT " size %lu",
2395 GST_TIME_ARGS (position), blocksize);
2397 ret = gst_base_src_get_range (src, position, blocksize, &buf);
2398 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
2399 GST_INFO_OBJECT (src, "pausing after gst_base_src_get_range() = %s",
2400 gst_flow_get_name (ret));
2401 GST_LIVE_UNLOCK (src);
2404 /* this should not happen */
2405 if (G_UNLIKELY (buf == NULL))
2408 /* push events to close/start our segment before we push the buffer. */
2409 if (G_UNLIKELY (src->priv->close_segment)) {
2410 gst_pad_push_event (pad, src->priv->close_segment);
2411 src->priv->close_segment = NULL;
2413 if (G_UNLIKELY (src->priv->start_segment)) {
2414 gst_pad_push_event (pad, src->priv->start_segment);
2415 src->priv->start_segment = NULL;
2417 src->priv->newsegment_pending = FALSE;
2419 if (g_atomic_int_get (&src->priv->have_events)) {
2420 GST_OBJECT_LOCK (src);
2421 /* take the events */
2422 pending_events = src->priv->pending_events;
2423 src->priv->pending_events = NULL;
2424 g_atomic_int_set (&src->priv->have_events, FALSE);
2425 GST_OBJECT_UNLOCK (src);
2428 /* Push out pending events if any */
2429 if (G_UNLIKELY (pending_events != NULL)) {
2430 for (tmp = pending_events; tmp; tmp = g_list_next (tmp)) {
2431 GstEvent *ev = (GstEvent *) tmp->data;
2432 gst_pad_push_event (pad, ev);
2434 g_list_free (pending_events);
2437 /* figure out the new position */
2438 switch (src->segment.format) {
2439 case GST_FORMAT_BYTES:
2441 guint bufsize = GST_BUFFER_SIZE (buf);
2443 /* we subtracted above for negative rates */
2444 if (src->segment.rate >= 0.0)
2445 position += bufsize;
2448 case GST_FORMAT_TIME:
2450 GstClockTime start, duration;
2452 start = GST_BUFFER_TIMESTAMP (buf);
2453 duration = GST_BUFFER_DURATION (buf);
2455 if (GST_CLOCK_TIME_IS_VALID (start))
2458 position = src->segment.last_stop;
2460 if (GST_CLOCK_TIME_IS_VALID (duration)) {
2461 if (src->segment.rate >= 0.0)
2462 position += duration;
2463 else if (position > duration)
2464 position -= duration;
2470 case GST_FORMAT_DEFAULT:
2471 if (src->segment.rate >= 0.0)
2472 position = GST_BUFFER_OFFSET_END (buf);
2474 position = GST_BUFFER_OFFSET (buf);
2480 if (position != -1) {
2481 if (src->segment.rate >= 0.0) {
2482 /* positive rate, check if we reached the stop */
2483 if (src->segment.stop != -1) {
2484 if (position >= src->segment.stop) {
2486 position = src->segment.stop;
2490 /* negative rate, check if we reached the start. start is always set to
2491 * something different from -1 */
2492 if (position <= src->segment.start) {
2494 position = src->segment.start;
2496 /* when going reverse, all buffers are DISCONT */
2497 src->priv->discont = TRUE;
2499 GST_OBJECT_LOCK (src);
2500 gst_segment_set_last_stop (&src->segment, src->segment.format, position);
2501 GST_OBJECT_UNLOCK (src);
2504 if (G_UNLIKELY (src->priv->discont)) {
2505 buf = gst_buffer_make_metadata_writable (buf);
2506 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
2507 src->priv->discont = FALSE;
2509 GST_LIVE_UNLOCK (src);
2511 ret = gst_pad_push (pad, buf);
2512 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
2513 GST_INFO_OBJECT (src, "pausing after gst_pad_push() = %s",
2514 gst_flow_get_name (ret));
2518 if (G_UNLIKELY (eos)) {
2519 GST_INFO_OBJECT (src, "pausing after end of segment");
2520 ret = GST_FLOW_UNEXPECTED;
2530 GST_DEBUG_OBJECT (src, "we are flushing");
2531 GST_LIVE_UNLOCK (src);
2532 ret = GST_FLOW_WRONG_STATE;
2537 const gchar *reason = gst_flow_get_name (ret);
2540 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
2541 src->data.ABI.running = FALSE;
2542 gst_pad_pause_task (pad);
2543 if (ret == GST_FLOW_UNEXPECTED) {
2544 gboolean flag_segment;
2548 /* perform EOS logic */
2549 flag_segment = (src->segment.flags & GST_SEEK_FLAG_SEGMENT) != 0;
2550 format = src->segment.format;
2551 last_stop = src->segment.last_stop;
2554 GstMessage *message;
2556 message = gst_message_new_segment_done (GST_OBJECT_CAST (src),
2558 gst_message_set_seqnum (message, src->priv->seqnum);
2559 gst_element_post_message (GST_ELEMENT_CAST (src), message);
2561 event = gst_event_new_eos ();
2562 gst_event_set_seqnum (event, src->priv->seqnum);
2563 gst_pad_push_event (pad, event);
2564 src->priv->last_sent_eos = TRUE;
2566 } else if (ret == GST_FLOW_NOT_LINKED || ret <= GST_FLOW_UNEXPECTED) {
2567 event = gst_event_new_eos ();
2568 gst_event_set_seqnum (event, src->priv->seqnum);
2569 /* for fatal errors we post an error message, post the error
2570 * first so the app knows about the error first.
2571 * Also don't do this for WRONG_STATE because it happens
2572 * due to flushing and posting an error message because of
2573 * that is the wrong thing to do, e.g. when we're doing
2574 * a flushing seek. */
2575 GST_ELEMENT_ERROR (src, STREAM, FAILED,
2576 (_("Internal data flow error.")),
2577 ("streaming task paused, reason %s (%d)", reason, ret));
2578 gst_pad_push_event (pad, event);
2579 src->priv->last_sent_eos = TRUE;
2585 GST_ELEMENT_ERROR (src, STREAM, FAILED,
2586 (_("Internal data flow error.")), ("element returned NULL buffer"));
2587 GST_LIVE_UNLOCK (src);
2592 /* default negotiation code.
2594 * Take intersection between src and sink pads, take first
2598 gst_base_src_default_negotiate (GstBaseSrc * basesrc)
2601 GstCaps *caps = NULL;
2602 GstCaps *peercaps = NULL;
2603 gboolean result = FALSE;
2605 /* first see what is possible on our source pad */
2606 thiscaps = gst_pad_get_caps_reffed (GST_BASE_SRC_PAD (basesrc));
2607 GST_DEBUG_OBJECT (basesrc, "caps of src: %" GST_PTR_FORMAT, thiscaps);
2608 /* nothing or anything is allowed, we're done */
2609 if (thiscaps == NULL || gst_caps_is_any (thiscaps))
2610 goto no_nego_needed;
2612 if (G_UNLIKELY (gst_caps_is_empty (thiscaps)))
2615 /* get the peer caps */
2616 peercaps = gst_pad_peer_get_caps_reffed (GST_BASE_SRC_PAD (basesrc));
2617 GST_DEBUG_OBJECT (basesrc, "caps of peer: %" GST_PTR_FORMAT, peercaps);
2619 /* get intersection */
2621 gst_caps_intersect_full (peercaps, thiscaps, GST_CAPS_INTERSECT_FIRST);
2622 GST_DEBUG_OBJECT (basesrc, "intersect: %" GST_PTR_FORMAT, caps);
2623 gst_caps_unref (peercaps);
2625 /* no peer, work with our own caps then */
2626 caps = gst_caps_copy (thiscaps);
2628 gst_caps_unref (thiscaps);
2630 /* take first (and best, since they are sorted) possibility */
2631 gst_caps_truncate (caps);
2634 if (!gst_caps_is_empty (caps)) {
2635 gst_pad_fixate_caps (GST_BASE_SRC_PAD (basesrc), caps);
2636 GST_DEBUG_OBJECT (basesrc, "fixated to: %" GST_PTR_FORMAT, caps);
2638 if (gst_caps_is_any (caps)) {
2639 /* hmm, still anything, so element can do anything and
2640 * nego is not needed */
2642 } else if (gst_caps_is_fixed (caps)) {
2643 /* yay, fixed caps, use those then, it's possible that the subclass does
2644 * not accept this caps after all and we have to fail. */
2645 result = gst_pad_set_caps (GST_BASE_SRC_PAD (basesrc), caps);
2648 gst_caps_unref (caps);
2650 GST_DEBUG_OBJECT (basesrc, "no common caps");
2656 GST_DEBUG_OBJECT (basesrc, "no negotiation needed");
2658 gst_caps_unref (thiscaps);
2663 GST_ELEMENT_ERROR (basesrc, STREAM, FORMAT,
2664 ("No supported formats found"),
2665 ("This element did not produce valid caps"));
2667 gst_caps_unref (thiscaps);
2673 gst_base_src_negotiate (GstBaseSrc * basesrc)
2675 GstBaseSrcClass *bclass;
2676 gboolean result = TRUE;
2678 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
2680 if (bclass->negotiate)
2681 result = bclass->negotiate (basesrc);
2687 gst_base_src_start (GstBaseSrc * basesrc)
2689 GstBaseSrcClass *bclass;
2695 if (GST_OBJECT_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED))
2698 GST_DEBUG_OBJECT (basesrc, "starting source");
2700 basesrc->num_buffers_left = basesrc->num_buffers;
2702 GST_OBJECT_LOCK (basesrc);
2703 gst_segment_init (&basesrc->segment, basesrc->segment.format);
2704 GST_OBJECT_UNLOCK (basesrc);
2706 basesrc->data.ABI.running = FALSE;
2707 basesrc->priv->newsegment_pending = FALSE;
2709 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
2711 result = bclass->start (basesrc);
2716 goto could_not_start;
2718 GST_OBJECT_FLAG_SET (basesrc, GST_BASE_SRC_STARTED);
2720 format = basesrc->segment.format;
2722 /* figure out the size */
2723 if (format == GST_FORMAT_BYTES) {
2724 if (bclass->get_size) {
2725 if (!(result = bclass->get_size (basesrc, &size)))
2731 GST_DEBUG_OBJECT (basesrc, "setting size %" G_GUINT64_FORMAT, size);
2732 /* only update the size when operating in bytes, subclass is supposed
2733 * to set duration in the start method for other formats */
2734 GST_OBJECT_LOCK (basesrc);
2735 gst_segment_set_duration (&basesrc->segment, GST_FORMAT_BYTES, size);
2736 GST_OBJECT_UNLOCK (basesrc);
2741 GST_DEBUG_OBJECT (basesrc,
2742 "format: %s, have size: %d, size: %" G_GUINT64_FORMAT ", duration: %"
2743 G_GINT64_FORMAT, gst_format_get_name (format), result, size,
2744 basesrc->segment.duration);
2746 seekable = gst_base_src_seekable (basesrc);
2747 GST_DEBUG_OBJECT (basesrc, "is seekable: %d", seekable);
2749 /* update for random access flag */
2750 basesrc->random_access = seekable && format == GST_FORMAT_BYTES;
2752 GST_DEBUG_OBJECT (basesrc, "is random_access: %d", basesrc->random_access);
2754 /* run typefind if we are random_access and the typefinding is enabled. */
2755 if (basesrc->random_access && basesrc->data.ABI.typefind && size != -1) {
2758 if (!(caps = gst_type_find_helper (basesrc->srcpad, size)))
2759 goto typefind_failed;
2761 result = gst_pad_set_caps (basesrc->srcpad, caps);
2762 gst_caps_unref (caps);
2764 /* use class or default negotiate function */
2765 if (!(result = gst_base_src_negotiate (basesrc)))
2766 goto could_not_negotiate;
2774 GST_DEBUG_OBJECT (basesrc, "could not start");
2775 /* subclass is supposed to post a message. We don't have to call _stop. */
2778 could_not_negotiate:
2780 GST_DEBUG_OBJECT (basesrc, "could not negotiate, stopping");
2781 GST_ELEMENT_ERROR (basesrc, STREAM, FORMAT,
2782 ("Could not negotiate format"), ("Check your filtered caps, if any"));
2783 /* we must call stop */
2784 gst_base_src_stop (basesrc);
2789 GST_DEBUG_OBJECT (basesrc, "could not typefind, stopping");
2790 GST_ELEMENT_ERROR (basesrc, STREAM, TYPE_NOT_FOUND, (NULL), (NULL));
2791 /* we must call stop */
2792 gst_base_src_stop (basesrc);
2798 gst_base_src_stop (GstBaseSrc * basesrc)
2800 GstBaseSrcClass *bclass;
2801 gboolean result = TRUE;
2803 if (!GST_OBJECT_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED))
2806 GST_DEBUG_OBJECT (basesrc, "stopping source");
2808 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
2810 result = bclass->stop (basesrc);
2813 GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
2818 /* start or stop flushing dataprocessing
2821 gst_base_src_set_flushing (GstBaseSrc * basesrc,
2822 gboolean flushing, gboolean live_play, gboolean unlock, gboolean * playing)
2824 GstBaseSrcClass *bclass;
2826 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
2828 if (flushing && unlock) {
2829 /* unlock any subclasses, we need to do this before grabbing the
2830 * LIVE_LOCK since we hold this lock before going into ::create. We pass an
2831 * unlock to the params because of backwards compat (see seek handler)*/
2833 bclass->unlock (basesrc);
2836 /* the live lock is released when we are blocked, waiting for playing or
2837 * when we sync to the clock. */
2838 GST_LIVE_LOCK (basesrc);
2840 *playing = basesrc->live_running;
2841 basesrc->priv->flushing = flushing;
2843 /* if we are locked in the live lock, signal it to make it flush */
2844 basesrc->live_running = TRUE;
2846 /* clear pending EOS if any */
2847 g_atomic_int_set (&basesrc->priv->pending_eos, FALSE);
2849 /* step 1, now that we have the LIVE lock, clear our unlock request */
2850 if (bclass->unlock_stop)
2851 bclass->unlock_stop (basesrc);
2853 /* step 2, unblock clock sync (if any) or any other blocking thing */
2854 if (basesrc->clock_id)
2855 gst_clock_id_unschedule (basesrc->clock_id);
2857 /* signal the live source that it can start playing */
2858 basesrc->live_running = live_play;
2860 /* When unlocking drop all delayed events */
2862 GST_OBJECT_LOCK (basesrc);
2863 if (basesrc->priv->pending_events) {
2864 g_list_foreach (basesrc->priv->pending_events, (GFunc) gst_event_unref,
2866 g_list_free (basesrc->priv->pending_events);
2867 basesrc->priv->pending_events = NULL;
2868 g_atomic_int_set (&basesrc->priv->have_events, FALSE);
2870 GST_OBJECT_UNLOCK (basesrc);
2873 GST_LIVE_SIGNAL (basesrc);
2874 GST_LIVE_UNLOCK (basesrc);
2879 /* the purpose of this function is to make sure that a live source blocks in the
2880 * LIVE lock or leaves the LIVE lock and continues playing. */
2882 gst_base_src_set_playing (GstBaseSrc * basesrc, gboolean live_play)
2884 GstBaseSrcClass *bclass;
2886 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
2888 /* unlock subclasses locked in ::create, we only do this when we stop playing. */
2890 GST_DEBUG_OBJECT (basesrc, "unlock");
2892 bclass->unlock (basesrc);
2895 /* we are now able to grab the LIVE lock, when we get it, we can be
2896 * waiting for PLAYING while blocked in the LIVE cond or we can be waiting
2898 GST_LIVE_LOCK (basesrc);
2899 GST_DEBUG_OBJECT (basesrc, "unschedule clock");
2901 /* unblock clock sync (if any) */
2902 if (basesrc->clock_id)
2903 gst_clock_id_unschedule (basesrc->clock_id);
2905 /* configure what to do when we get to the LIVE lock. */
2906 GST_DEBUG_OBJECT (basesrc, "live running %d", live_play);
2907 basesrc->live_running = live_play;
2912 /* clear our unlock request when going to PLAYING */
2913 GST_DEBUG_OBJECT (basesrc, "unlock stop");
2914 if (bclass->unlock_stop)
2915 bclass->unlock_stop (basesrc);
2917 /* for live sources we restart the timestamp correction */
2918 basesrc->priv->latency = -1;
2919 /* have to restart the task in case it stopped because of the unlock when
2920 * we went to PAUSED. Only do this if we operating in push mode. */
2921 GST_OBJECT_LOCK (basesrc->srcpad);
2922 start = (GST_PAD_ACTIVATE_MODE (basesrc->srcpad) == GST_ACTIVATE_PUSH);
2923 GST_OBJECT_UNLOCK (basesrc->srcpad);
2925 gst_pad_start_task (basesrc->srcpad, (GstTaskFunction) gst_base_src_loop,
2927 GST_DEBUG_OBJECT (basesrc, "signal");
2928 GST_LIVE_SIGNAL (basesrc);
2930 GST_LIVE_UNLOCK (basesrc);
2936 gst_base_src_activate_push (GstPad * pad, gboolean active)
2938 GstBaseSrc *basesrc;
2941 basesrc = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
2943 /* prepare subclass first */
2945 GST_DEBUG_OBJECT (basesrc, "Activating in push mode");
2947 if (G_UNLIKELY (!basesrc->can_activate_push))
2948 goto no_push_activation;
2950 if (G_UNLIKELY (!gst_base_src_start (basesrc)))
2953 basesrc->priv->last_sent_eos = FALSE;
2954 basesrc->priv->discont = TRUE;
2955 gst_base_src_set_flushing (basesrc, FALSE, FALSE, FALSE, NULL);
2957 /* do initial seek, which will start the task */
2958 GST_OBJECT_LOCK (basesrc);
2959 event = basesrc->data.ABI.pending_seek;
2960 basesrc->data.ABI.pending_seek = NULL;
2961 GST_OBJECT_UNLOCK (basesrc);
2963 /* no need to unlock anything, the task is certainly
2964 * not running here. The perform seek code will start the task when
2966 if (G_UNLIKELY (!gst_base_src_perform_seek (basesrc, event, FALSE)))
2970 gst_event_unref (event);
2972 GST_DEBUG_OBJECT (basesrc, "Deactivating in push mode");
2974 gst_base_src_set_flushing (basesrc, TRUE, FALSE, TRUE, NULL);
2976 gst_pad_stop_task (pad);
2977 /* now we can stop the source */
2978 if (G_UNLIKELY (!gst_base_src_stop (basesrc)))
2986 GST_WARNING_OBJECT (basesrc, "Subclass disabled push-mode activation");
2991 GST_WARNING_OBJECT (basesrc, "Failed to start in push mode");
2996 GST_ERROR_OBJECT (basesrc, "Failed to perform initial seek");
2998 gst_base_src_set_flushing (basesrc, TRUE, FALSE, TRUE, NULL);
3000 gst_pad_stop_task (pad);
3001 /* Stop the basesrc */
3002 gst_base_src_stop (basesrc);
3004 gst_event_unref (event);
3009 GST_DEBUG_OBJECT (basesrc, "Failed to stop in push mode");
3015 gst_base_src_activate_pull (GstPad * pad, gboolean active)
3017 GstBaseSrc *basesrc;
3019 basesrc = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
3021 /* prepare subclass first */
3023 GST_DEBUG_OBJECT (basesrc, "Activating in pull mode");
3024 if (G_UNLIKELY (!gst_base_src_start (basesrc)))
3027 /* if not random_access, we cannot operate in pull mode for now */
3028 if (G_UNLIKELY (!gst_base_src_check_get_range (basesrc)))
3031 /* stop flushing now but for live sources, still block in the LIVE lock when
3032 * we are not yet PLAYING */
3033 gst_base_src_set_flushing (basesrc, FALSE, FALSE, FALSE, NULL);
3035 GST_DEBUG_OBJECT (basesrc, "Deactivating in pull mode");
3036 /* flush all, there is no task to stop */
3037 gst_base_src_set_flushing (basesrc, TRUE, FALSE, TRUE, NULL);
3039 /* don't send EOS when going from PAUSED => READY when in pull mode */
3040 basesrc->priv->last_sent_eos = TRUE;
3042 if (G_UNLIKELY (!gst_base_src_stop (basesrc)))
3050 GST_ERROR_OBJECT (basesrc, "Failed to start in pull mode");
3055 GST_ERROR_OBJECT (basesrc, "Cannot operate in pull mode, stopping");
3056 gst_base_src_stop (basesrc);
3061 GST_ERROR_OBJECT (basesrc, "Failed to stop in pull mode");
3066 static GstStateChangeReturn
3067 gst_base_src_change_state (GstElement * element, GstStateChange transition)
3069 GstBaseSrc *basesrc;
3070 GstStateChangeReturn result;
3071 gboolean no_preroll = FALSE;
3073 basesrc = GST_BASE_SRC (element);
3075 switch (transition) {
3076 case GST_STATE_CHANGE_NULL_TO_READY:
3078 case GST_STATE_CHANGE_READY_TO_PAUSED:
3079 no_preroll = gst_base_src_is_live (basesrc);
3081 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
3082 GST_DEBUG_OBJECT (basesrc, "PAUSED->PLAYING");
3083 if (gst_base_src_is_live (basesrc)) {
3084 /* now we can start playback */
3085 gst_base_src_set_playing (basesrc, TRUE);
3093 GST_ELEMENT_CLASS (parent_class)->change_state (element,
3094 transition)) == GST_STATE_CHANGE_FAILURE)
3097 switch (transition) {
3098 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3099 GST_DEBUG_OBJECT (basesrc, "PLAYING->PAUSED");
3100 if (gst_base_src_is_live (basesrc)) {
3101 /* make sure we block in the live lock in PAUSED */
3102 gst_base_src_set_playing (basesrc, FALSE);
3106 case GST_STATE_CHANGE_PAUSED_TO_READY:
3108 GstEvent **event_p, *event;
3110 /* we don't need to unblock anything here, the pad deactivation code
3111 * already did this */
3113 /* FIXME, deprecate this behaviour, it is very dangerous.
3114 * the prefered way of sending EOS downstream is by sending
3115 * the EOS event to the element */
3116 if (!basesrc->priv->last_sent_eos) {
3117 GST_DEBUG_OBJECT (basesrc, "Sending EOS event");
3118 event = gst_event_new_eos ();
3119 gst_event_set_seqnum (event, basesrc->priv->seqnum);
3120 gst_pad_push_event (basesrc->srcpad, event);
3121 basesrc->priv->last_sent_eos = TRUE;
3123 g_atomic_int_set (&basesrc->priv->pending_eos, FALSE);
3124 event_p = &basesrc->data.ABI.pending_seek;
3125 gst_event_replace (event_p, NULL);
3126 event_p = &basesrc->priv->close_segment;
3127 gst_event_replace (event_p, NULL);
3128 event_p = &basesrc->priv->start_segment;
3129 gst_event_replace (event_p, NULL);
3132 case GST_STATE_CHANGE_READY_TO_NULL:
3138 if (no_preroll && result == GST_STATE_CHANGE_SUCCESS)
3139 result = GST_STATE_CHANGE_NO_PREROLL;
3146 GST_DEBUG_OBJECT (basesrc, "parent failed state change");