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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
25 * @short_description: Base class for getrange based source elements
26 * @see_also: #GstPushSrc, #GstBaseTransform, #GstBaseSink
28 * This is a generic 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_SEGMENT
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 * If all the conditions are met for operating in pull mode, #GstBaseSrc is
51 * automatically seekable in push mode as well. The following conditions must
52 * be met to make the element seekable in push mode when the format is not
56 * #GstBaseSrcClass.is_seekable() returns %TRUE.
59 * #GstBaseSrcClass.query() can convert all supported seek formats to the
60 * internal format as set with gst_base_src_set_format().
63 * #GstBaseSrcClass.do_seek() is implemented, performs the seek and returns
68 * When the element does not meet the requirements to operate in pull mode, the
69 * offset and length in the #GstBaseSrcClass.create() method should be ignored.
70 * It is recommended to subclass #GstPushSrc instead, in this situation. If the
71 * element can operate in pull mode but only with specific offsets and
72 * lengths, it is allowed to generate an error when the wrong values are passed
73 * to the #GstBaseSrcClass.create() function.
75 * #GstBaseSrc has support for live sources. Live sources are sources that when
76 * paused discard data, such as audio or video capture devices. A typical live
77 * source also produces data at a fixed rate and thus provides a clock to publish
79 * Use gst_base_src_set_live() to activate the live source mode.
81 * A live source does not produce data in the PAUSED state. This means that the
82 * #GstBaseSrcClass.create() method will not be called in PAUSED but only in
83 * PLAYING. To signal the pipeline that the element will not produce data, the
84 * return value from the READY to PAUSED state will be
85 * %GST_STATE_CHANGE_NO_PREROLL.
87 * A typical live source will timestamp the buffers it creates with the
88 * current running time of the pipeline. This is one reason why a live source
89 * can only produce data in the PLAYING state, when the clock is actually
90 * distributed and running.
92 * Live sources that synchronize and block on the clock (an audio source, for
93 * example) can use gst_base_src_wait_playing() when the
94 * #GstBaseSrcClass.create() function was interrupted by a state change to
97 * The #GstBaseSrcClass.get_times() method can be used to implement pseudo-live
98 * sources. It only makes sense to implement the #GstBaseSrcClass.get_times()
99 * function if the source is a live source. The #GstBaseSrcClass.get_times()
100 * function should return timestamps starting from 0, as if it were a non-live
101 * source. The base class will make sure that the timestamps are transformed
102 * into the current running_time. The base source will then wait for the
103 * calculated running_time before pushing out the buffer.
105 * For live sources, the base class will by default report a latency of 0.
106 * For pseudo live sources, the base class will by default measure the difference
107 * between the first buffer timestamp and the start time of get_times and will
108 * report this value as the latency.
109 * Subclasses should override the query function when this behaviour is not
112 * There is only support in #GstBaseSrc for exactly one source pad, which
113 * should be named "src". A source implementation (subclass of #GstBaseSrc)
114 * should install a pad template in its class_init function, like so:
117 * my_element_class_init (GstMyElementClass *klass)
119 * GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
120 * // srctemplate should be a #GstStaticPadTemplate with direction
121 * // %GST_PAD_SRC and name "src"
122 * gst_element_class_add_pad_template (gstelement_class,
123 * gst_static_pad_template_get (&srctemplate));
125 * gst_element_class_set_static_metadata (gstelement_class,
128 * "My Source element",
129 * "The author <my.sink@my.email>");
134 * <title>Controlled shutdown of live sources in applications</title>
136 * Applications that record from a live source may want to stop recording
137 * in a controlled way, so that the recording is stopped, but the data
138 * already in the pipeline is processed to the end (remember that many live
139 * sources would go on recording forever otherwise). For that to happen the
140 * application needs to make the source stop recording and send an EOS
141 * event down the pipeline. The application would then wait for an
142 * EOS message posted on the pipeline's bus to know when all data has
143 * been processed and the pipeline can safely be stopped.
145 * An application may send an EOS event to a source element to make it
146 * perform the EOS logic (send EOS event downstream or post a
147 * %GST_MESSAGE_SEGMENT_DONE on the bus). This can typically be done
148 * with the gst_element_send_event() function on the element or its parent bin.
150 * After the EOS has been sent to the element, the application should wait for
151 * an EOS message to be posted on the pipeline's bus. Once this EOS message is
152 * received, it may safely shut down the entire pipeline.
164 #include <gst/gst_private.h>
165 #include <gst/glib-compat-private.h>
167 #include "gstbasesrc.h"
168 #include "gsttypefindhelper.h"
169 #include <gst/gst-i18n-lib.h>
171 GST_DEBUG_CATEGORY_STATIC (gst_base_src_debug);
172 #define GST_CAT_DEFAULT gst_base_src_debug
174 #define GST_LIVE_GET_LOCK(elem) (&GST_BASE_SRC_CAST(elem)->live_lock)
175 #define GST_LIVE_LOCK(elem) g_mutex_lock(GST_LIVE_GET_LOCK(elem))
176 #define GST_LIVE_TRYLOCK(elem) g_mutex_trylock(GST_LIVE_GET_LOCK(elem))
177 #define GST_LIVE_UNLOCK(elem) g_mutex_unlock(GST_LIVE_GET_LOCK(elem))
178 #define GST_LIVE_GET_COND(elem) (&GST_BASE_SRC_CAST(elem)->live_cond)
179 #define GST_LIVE_WAIT(elem) g_cond_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem))
180 #define GST_LIVE_WAIT_UNTIL(elem, end_time) g_cond_timed_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem), end_time)
181 #define GST_LIVE_SIGNAL(elem) g_cond_signal (GST_LIVE_GET_COND (elem));
182 #define GST_LIVE_BROADCAST(elem) g_cond_broadcast (GST_LIVE_GET_COND (elem));
185 #define GST_ASYNC_GET_COND(elem) (&GST_BASE_SRC_CAST(elem)->priv->async_cond)
186 #define GST_ASYNC_WAIT(elem) g_cond_wait (GST_ASYNC_GET_COND (elem), GST_OBJECT_GET_LOCK (elem))
187 #define GST_ASYNC_SIGNAL(elem) g_cond_signal (GST_ASYNC_GET_COND (elem));
189 #define CLEAR_PENDING_EOS(bsrc) \
191 g_atomic_int_set (&bsrc->priv->has_pending_eos, FALSE); \
192 gst_event_replace (&bsrc->priv->pending_eos, NULL); \
196 /* BaseSrc signals and args */
203 #define DEFAULT_BLOCKSIZE 4096
204 #define DEFAULT_NUM_BUFFERS -1
205 #define DEFAULT_TYPEFIND FALSE
206 #define DEFAULT_DO_TIMESTAMP FALSE
207 #ifdef TIZEN_PROFILE_TV
208 #define DEFAULT_SEGMENT_TIME -1
218 #ifdef TIZEN_PROFILE_TV
223 #define GST_BASE_SRC_GET_PRIVATE(obj) \
224 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_SRC, GstBaseSrcPrivate))
226 struct _GstBaseSrcPrivate
231 GstFlowReturn start_result;
234 /* if a stream-start event should be sent */
235 gboolean stream_start_pending;
237 /* if segment should be sent and a
238 * seqnum if it was originated by a seek */
239 gboolean segment_pending;
240 guint32 segment_seqnum;
242 /* if EOS is pending (atomic) */
243 GstEvent *pending_eos;
244 gint has_pending_eos;
246 /* if the eos was caused by a forced eos from the application */
249 /* startup latency is the time it takes between going to PLAYING and producing
250 * the first BUFFER with running_time 0. This value is included in the latency
252 GstClockTime latency;
253 /* timestamp offset, this is the offset add to the values of gst_times for
254 * pseudo live sources */
255 GstClockTimeDiff ts_offset;
257 gboolean do_timestamp;
258 volatile gint dynamic_size;
259 volatile gint automatic_eos;
261 /* stream sequence number */
264 /* pending events (TAG, CUSTOM_BOTH, CUSTOM_DOWNSTREAM) to be
265 * pushed in the data stream */
266 GList *pending_events;
267 volatile gint have_events;
269 /* QoS *//* with LOCK */
270 gboolean qos_enabled;
272 GstClockTime earliest_time;
275 GstAllocator *allocator;
276 GstAllocationParams params;
281 static GstElementClass *parent_class = NULL;
283 static void gst_base_src_class_init (GstBaseSrcClass * klass);
284 static void gst_base_src_init (GstBaseSrc * src, gpointer g_class);
285 static void gst_base_src_finalize (GObject * object);
289 gst_base_src_get_type (void)
291 static volatile gsize base_src_type = 0;
293 if (g_once_init_enter (&base_src_type)) {
295 static const GTypeInfo base_src_info = {
296 sizeof (GstBaseSrcClass),
299 (GClassInitFunc) gst_base_src_class_init,
304 (GInstanceInitFunc) gst_base_src_init,
307 _type = g_type_register_static (GST_TYPE_ELEMENT,
308 "GstBaseSrc", &base_src_info, G_TYPE_FLAG_ABSTRACT);
309 g_once_init_leave (&base_src_type, _type);
311 return base_src_type;
314 static GstCaps *gst_base_src_default_get_caps (GstBaseSrc * bsrc,
316 static GstCaps *gst_base_src_default_fixate (GstBaseSrc * src, GstCaps * caps);
317 static GstCaps *gst_base_src_fixate (GstBaseSrc * src, GstCaps * caps);
319 static gboolean gst_base_src_is_random_access (GstBaseSrc * src);
320 static gboolean gst_base_src_activate_mode (GstPad * pad, GstObject * parent,
321 GstPadMode mode, gboolean active);
322 static void gst_base_src_set_property (GObject * object, guint prop_id,
323 const GValue * value, GParamSpec * pspec);
324 static void gst_base_src_get_property (GObject * object, guint prop_id,
325 GValue * value, GParamSpec * pspec);
326 static gboolean gst_base_src_event (GstPad * pad, GstObject * parent,
328 static gboolean gst_base_src_send_event (GstElement * elem, GstEvent * event);
329 static gboolean gst_base_src_default_event (GstBaseSrc * src, GstEvent * event);
331 static gboolean gst_base_src_query (GstPad * pad, GstObject * parent,
334 static gboolean gst_base_src_activate_pool (GstBaseSrc * basesrc,
336 static gboolean gst_base_src_default_negotiate (GstBaseSrc * basesrc);
337 static gboolean gst_base_src_default_do_seek (GstBaseSrc * src,
338 GstSegment * segment);
339 static gboolean gst_base_src_default_query (GstBaseSrc * src, GstQuery * query);
340 static gboolean gst_base_src_default_prepare_seek_segment (GstBaseSrc * src,
341 GstEvent * event, GstSegment * segment);
342 static GstFlowReturn gst_base_src_default_create (GstBaseSrc * basesrc,
343 guint64 offset, guint size, GstBuffer ** buf);
344 static GstFlowReturn gst_base_src_default_alloc (GstBaseSrc * basesrc,
345 guint64 offset, guint size, GstBuffer ** buf);
346 static gboolean gst_base_src_decide_allocation_default (GstBaseSrc * basesrc,
349 static gboolean gst_base_src_set_flushing (GstBaseSrc * basesrc,
350 gboolean flushing, gboolean live_play, gboolean * playing);
352 static gboolean gst_base_src_start (GstBaseSrc * basesrc);
353 static gboolean gst_base_src_stop (GstBaseSrc * basesrc);
355 static GstStateChangeReturn gst_base_src_change_state (GstElement * element,
356 GstStateChange transition);
358 static void gst_base_src_loop (GstPad * pad);
359 static GstFlowReturn gst_base_src_getrange (GstPad * pad, GstObject * parent,
360 guint64 offset, guint length, GstBuffer ** buf);
361 static GstFlowReturn gst_base_src_get_range (GstBaseSrc * src, guint64 offset,
362 guint length, GstBuffer ** buf);
363 static gboolean gst_base_src_seekable (GstBaseSrc * src);
364 static gboolean gst_base_src_negotiate (GstBaseSrc * basesrc);
365 static gboolean gst_base_src_update_length (GstBaseSrc * src, guint64 offset,
366 guint * length, gboolean force);
369 gst_base_src_class_init (GstBaseSrcClass * klass)
371 GObjectClass *gobject_class;
372 GstElementClass *gstelement_class;
374 gobject_class = G_OBJECT_CLASS (klass);
375 gstelement_class = GST_ELEMENT_CLASS (klass);
377 GST_DEBUG_CATEGORY_INIT (gst_base_src_debug, "basesrc", 0, "basesrc element");
379 g_type_class_add_private (klass, sizeof (GstBaseSrcPrivate));
381 parent_class = g_type_class_peek_parent (klass);
383 gobject_class->finalize = gst_base_src_finalize;
384 gobject_class->set_property = gst_base_src_set_property;
385 gobject_class->get_property = gst_base_src_get_property;
387 g_object_class_install_property (gobject_class, PROP_BLOCKSIZE,
388 g_param_spec_uint ("blocksize", "Block size",
389 "Size in bytes to read per buffer (-1 = default)", 0, G_MAXUINT,
390 DEFAULT_BLOCKSIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
391 g_object_class_install_property (gobject_class, PROP_NUM_BUFFERS,
392 g_param_spec_int ("num-buffers", "num-buffers",
393 "Number of buffers to output before sending EOS (-1 = unlimited)",
394 -1, G_MAXINT, DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE |
395 G_PARAM_STATIC_STRINGS));
396 g_object_class_install_property (gobject_class, PROP_TYPEFIND,
397 g_param_spec_boolean ("typefind", "Typefind",
398 "Run typefind before negotiating", DEFAULT_TYPEFIND,
399 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
400 g_object_class_install_property (gobject_class, PROP_DO_TIMESTAMP,
401 g_param_spec_boolean ("do-timestamp", "Do timestamp",
402 "Apply current stream time to buffers", DEFAULT_DO_TIMESTAMP,
403 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
404 #ifdef TIZEN_PROFILE_TV
405 g_object_class_install_property (gobject_class, PROP_UPDATE_SEGMENT,
406 g_param_spec_int64 ("update-segment", "Update Segment",
407 "Timestamp that application want to set (-1 unlimited)",
408 -1, G_MAXINT64, DEFAULT_SEGMENT_TIME,
409 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
412 gstelement_class->change_state =
413 GST_DEBUG_FUNCPTR (gst_base_src_change_state);
414 gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_base_src_send_event);
416 klass->get_caps = GST_DEBUG_FUNCPTR (gst_base_src_default_get_caps);
417 klass->negotiate = GST_DEBUG_FUNCPTR (gst_base_src_default_negotiate);
418 klass->fixate = GST_DEBUG_FUNCPTR (gst_base_src_default_fixate);
419 klass->prepare_seek_segment =
420 GST_DEBUG_FUNCPTR (gst_base_src_default_prepare_seek_segment);
421 klass->do_seek = GST_DEBUG_FUNCPTR (gst_base_src_default_do_seek);
422 klass->query = GST_DEBUG_FUNCPTR (gst_base_src_default_query);
423 klass->event = GST_DEBUG_FUNCPTR (gst_base_src_default_event);
424 klass->create = GST_DEBUG_FUNCPTR (gst_base_src_default_create);
425 klass->alloc = GST_DEBUG_FUNCPTR (gst_base_src_default_alloc);
426 klass->decide_allocation =
427 GST_DEBUG_FUNCPTR (gst_base_src_decide_allocation_default);
429 /* Registering debug symbols for function pointers */
430 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_activate_mode);
431 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_event);
432 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_query);
433 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_getrange);
434 GST_DEBUG_REGISTER_FUNCPTR (gst_base_src_fixate);
438 gst_base_src_init (GstBaseSrc * basesrc, gpointer g_class)
441 GstPadTemplate *pad_template;
443 basesrc->priv = GST_BASE_SRC_GET_PRIVATE (basesrc);
445 basesrc->is_live = FALSE;
446 g_mutex_init (&basesrc->live_lock);
447 g_cond_init (&basesrc->live_cond);
448 basesrc->num_buffers = DEFAULT_NUM_BUFFERS;
449 basesrc->num_buffers_left = -1;
450 basesrc->priv->automatic_eos = TRUE;
452 basesrc->can_activate_push = TRUE;
455 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src");
456 g_return_if_fail (pad_template != NULL);
458 GST_DEBUG_OBJECT (basesrc, "creating src pad");
459 pad = gst_pad_new_from_template (pad_template, "src");
461 GST_DEBUG_OBJECT (basesrc, "setting functions on src pad");
462 gst_pad_set_activatemode_function (pad, gst_base_src_activate_mode);
463 gst_pad_set_event_function (pad, gst_base_src_event);
464 gst_pad_set_query_function (pad, gst_base_src_query);
465 gst_pad_set_getrange_function (pad, gst_base_src_getrange);
467 /* hold pointer to pad */
468 basesrc->srcpad = pad;
469 GST_DEBUG_OBJECT (basesrc, "adding src pad");
470 gst_element_add_pad (GST_ELEMENT (basesrc), pad);
472 basesrc->blocksize = DEFAULT_BLOCKSIZE;
473 basesrc->clock_id = NULL;
474 /* we operate in BYTES by default */
475 gst_base_src_set_format (basesrc, GST_FORMAT_BYTES);
476 basesrc->typefind = DEFAULT_TYPEFIND;
477 basesrc->priv->do_timestamp = DEFAULT_DO_TIMESTAMP;
478 g_atomic_int_set (&basesrc->priv->have_events, FALSE);
480 g_cond_init (&basesrc->priv->async_cond);
481 basesrc->priv->start_result = GST_FLOW_FLUSHING;
482 GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTED);
483 GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTING);
484 GST_OBJECT_FLAG_SET (basesrc, GST_ELEMENT_FLAG_SOURCE);
486 GST_DEBUG_OBJECT (basesrc, "init done");
490 gst_base_src_finalize (GObject * object)
495 basesrc = GST_BASE_SRC (object);
497 g_mutex_clear (&basesrc->live_lock);
498 g_cond_clear (&basesrc->live_cond);
499 g_cond_clear (&basesrc->priv->async_cond);
501 event_p = &basesrc->pending_seek;
502 gst_event_replace (event_p, NULL);
504 if (basesrc->priv->pending_events) {
505 g_list_foreach (basesrc->priv->pending_events, (GFunc) gst_event_unref,
507 g_list_free (basesrc->priv->pending_events);
510 G_OBJECT_CLASS (parent_class)->finalize (object);
514 * gst_base_src_wait_playing:
517 * If the #GstBaseSrcClass.create() method performs its own synchronisation
518 * against the clock it must unblock when going from PLAYING to the PAUSED state
519 * and call this method before continuing to produce the remaining data.
521 * This function will block until a state change to PLAYING happens (in which
522 * case this function returns %GST_FLOW_OK) or the processing must be stopped due
523 * to a state change to READY or a FLUSH event (in which case this function
524 * returns %GST_FLOW_FLUSHING).
526 * Returns: %GST_FLOW_OK if @src is PLAYING and processing can
527 * continue. Any other return value should be returned from the create vmethod.
530 gst_base_src_wait_playing (GstBaseSrc * src)
532 g_return_val_if_fail (GST_IS_BASE_SRC (src), GST_FLOW_ERROR);
535 /* block until the state changes, or we get a flush, or something */
536 GST_DEBUG_OBJECT (src, "live source waiting for running state");
538 GST_DEBUG_OBJECT (src, "live source unlocked");
539 if (src->priv->flushing)
541 } while (G_UNLIKELY (!src->live_running));
548 GST_DEBUG_OBJECT (src, "we are flushing");
549 return GST_FLOW_FLUSHING;
554 * gst_base_src_set_live:
555 * @src: base source instance
556 * @live: new live-mode
558 * If the element listens to a live source, @live should
561 * A live source will not produce data in the PAUSED state and
562 * will therefore not be able to participate in the PREROLL phase
563 * of a pipeline. To signal this fact to the application and the
564 * pipeline, the state change return value of the live source will
565 * be GST_STATE_CHANGE_NO_PREROLL.
568 gst_base_src_set_live (GstBaseSrc * src, gboolean live)
570 g_return_if_fail (GST_IS_BASE_SRC (src));
572 GST_OBJECT_LOCK (src);
574 GST_OBJECT_UNLOCK (src);
578 * gst_base_src_is_live:
579 * @src: base source instance
581 * Check if an element is in live mode.
583 * Returns: %TRUE if element is in live mode.
586 gst_base_src_is_live (GstBaseSrc * src)
590 g_return_val_if_fail (GST_IS_BASE_SRC (src), FALSE);
592 GST_OBJECT_LOCK (src);
593 result = src->is_live;
594 GST_OBJECT_UNLOCK (src);
600 * gst_base_src_set_format:
601 * @src: base source instance
602 * @format: the format to use
604 * Sets the default format of the source. This will be the format used
605 * for sending SEGMENT events and for performing seeks.
607 * If a format of GST_FORMAT_BYTES is set, the element will be able to
608 * operate in pull mode if the #GstBaseSrcClass.is_seekable() returns %TRUE.
610 * This function must only be called in states < %GST_STATE_PAUSED.
613 gst_base_src_set_format (GstBaseSrc * src, GstFormat format)
615 g_return_if_fail (GST_IS_BASE_SRC (src));
616 g_return_if_fail (GST_STATE (src) <= GST_STATE_READY);
618 GST_OBJECT_LOCK (src);
619 gst_segment_init (&src->segment, format);
620 GST_OBJECT_UNLOCK (src);
624 * gst_base_src_set_dynamic_size:
625 * @src: base source instance
626 * @dynamic: new dynamic size mode
628 * If not @dynamic, size is only updated when needed, such as when trying to
629 * read past current tracked size. Otherwise, size is checked for upon each
633 gst_base_src_set_dynamic_size (GstBaseSrc * src, gboolean dynamic)
635 g_return_if_fail (GST_IS_BASE_SRC (src));
637 g_atomic_int_set (&src->priv->dynamic_size, dynamic);
641 * gst_base_src_set_automatic_eos:
642 * @src: base source instance
643 * @automatic_eos: automatic eos
645 * If @automatic_eos is %TRUE, @src will automatically go EOS if a buffer
646 * after the total size is returned. By default this is %TRUE but sources
647 * that can't return an authoritative size and only know that they're EOS
648 * when trying to read more should set this to %FALSE.
653 gst_base_src_set_automatic_eos (GstBaseSrc * src, gboolean automatic_eos)
655 g_return_if_fail (GST_IS_BASE_SRC (src));
657 g_atomic_int_set (&src->priv->automatic_eos, automatic_eos);
661 * gst_base_src_set_async:
662 * @src: base source instance
663 * @async: new async mode
665 * Configure async behaviour in @src, no state change will block. The open,
666 * close, start, stop, play and pause virtual methods will be executed in a
667 * different thread and are thus allowed to perform blocking operations. Any
668 * blocking operation should be unblocked with the unlock vmethod.
671 gst_base_src_set_async (GstBaseSrc * src, gboolean async)
673 g_return_if_fail (GST_IS_BASE_SRC (src));
675 GST_OBJECT_LOCK (src);
676 src->priv->async = async;
677 GST_OBJECT_UNLOCK (src);
681 * gst_base_src_is_async:
682 * @src: base source instance
684 * Get the current async behaviour of @src. See also gst_base_src_set_async().
686 * Returns: %TRUE if @src is operating in async mode.
689 gst_base_src_is_async (GstBaseSrc * src)
693 g_return_val_if_fail (GST_IS_BASE_SRC (src), FALSE);
695 GST_OBJECT_LOCK (src);
696 res = src->priv->async;
697 GST_OBJECT_UNLOCK (src);
704 * gst_base_src_query_latency:
706 * @live: (out) (allow-none): if the source is live
707 * @min_latency: (out) (allow-none): the min latency of the source
708 * @max_latency: (out) (allow-none): the max latency of the source
710 * Query the source for the latency parameters. @live will be %TRUE when @src is
711 * configured as a live source. @min_latency and @max_latency will be set
712 * to the difference between the running time and the timestamp of the first
715 * This function is mostly used by subclasses.
717 * Returns: %TRUE if the query succeeded.
720 gst_base_src_query_latency (GstBaseSrc * src, gboolean * live,
721 GstClockTime * min_latency, GstClockTime * max_latency)
725 g_return_val_if_fail (GST_IS_BASE_SRC (src), FALSE);
727 GST_OBJECT_LOCK (src);
729 *live = src->is_live;
731 /* if we have a startup latency, report this one, else report 0. Subclasses
732 * are supposed to override the query function if they want something
734 if (src->priv->latency != -1)
735 min = src->priv->latency;
744 GST_LOG_OBJECT (src, "latency: live %d, min %" GST_TIME_FORMAT
745 ", max %" GST_TIME_FORMAT, src->is_live, GST_TIME_ARGS (min),
746 GST_TIME_ARGS (min));
747 GST_OBJECT_UNLOCK (src);
753 * gst_base_src_set_blocksize:
755 * @blocksize: the new blocksize in bytes
757 * Set the number of bytes that @src will push out with each buffer. When
758 * @blocksize is set to -1, a default length will be used.
761 gst_base_src_set_blocksize (GstBaseSrc * src, guint blocksize)
763 g_return_if_fail (GST_IS_BASE_SRC (src));
765 GST_OBJECT_LOCK (src);
766 src->blocksize = blocksize;
767 GST_OBJECT_UNLOCK (src);
771 * gst_base_src_get_blocksize:
774 * Get the number of bytes that @src will push out with each buffer.
776 * Returns: the number of bytes pushed with each buffer.
779 gst_base_src_get_blocksize (GstBaseSrc * src)
783 g_return_val_if_fail (GST_IS_BASE_SRC (src), 0);
785 GST_OBJECT_LOCK (src);
786 res = src->blocksize;
787 GST_OBJECT_UNLOCK (src);
794 * gst_base_src_set_do_timestamp:
796 * @timestamp: enable or disable timestamping
798 * Configure @src to automatically timestamp outgoing buffers based on the
799 * current running_time of the pipeline. This property is mostly useful for live
803 gst_base_src_set_do_timestamp (GstBaseSrc * src, gboolean timestamp)
805 g_return_if_fail (GST_IS_BASE_SRC (src));
807 GST_OBJECT_LOCK (src);
808 src->priv->do_timestamp = timestamp;
809 if (timestamp && src->segment.format != GST_FORMAT_TIME)
810 gst_segment_init (&src->segment, GST_FORMAT_TIME);
811 GST_OBJECT_UNLOCK (src);
814 #ifdef TIZEN_PROFILE_TV
816 *gst_base_src_update_segment:
818 *@timestamp: timestamp to set
821 gst_base_src_update_segment (GstBaseSrc * src, gint64 timestamp)
823 g_return_if_fail (GST_IS_BASE_SRC (src));
825 GST_OBJECT_LOCK (src);
826 if (timestamp != -1) {
827 GST_DEBUG_OBJECT (src,
828 "udpate the segment parameter for es player resume playback,%lld",
830 src->segment.start = timestamp;
831 src->segment.time = timestamp;
832 src->segment.position = timestamp;
834 GST_OBJECT_UNLOCK (src);
835 GST_DEBUG_OBJECT (src, "udpate the segment end");
840 * gst_base_src_get_do_timestamp:
843 * Query if @src timestamps outgoing buffers based on the current running_time.
845 * Returns: %TRUE if the base class will automatically timestamp outgoing buffers.
848 gst_base_src_get_do_timestamp (GstBaseSrc * src)
852 g_return_val_if_fail (GST_IS_BASE_SRC (src), FALSE);
854 GST_OBJECT_LOCK (src);
855 res = src->priv->do_timestamp;
856 GST_OBJECT_UNLOCK (src);
862 * gst_base_src_new_seamless_segment:
864 * @start: The new start value for the segment
865 * @stop: Stop value for the new segment
866 * @time: The new time value for the start of the new segment
868 * Prepare a new seamless segment for emission downstream. This function must
869 * only be called by derived sub-classes, and only from the create() function,
870 * as the stream-lock needs to be held.
872 * The format for the new segment will be the current format of the source, as
873 * configured with gst_base_src_set_format()
875 * Returns: %TRUE if preparation of the seamless segment succeeded.
878 gst_base_src_new_seamless_segment (GstBaseSrc * src, gint64 start, gint64 stop,
883 GST_OBJECT_LOCK (src);
885 src->segment.base = gst_segment_to_running_time (&src->segment,
886 src->segment.format, src->segment.position);
887 src->segment.position = src->segment.start = start;
888 src->segment.stop = stop;
889 src->segment.time = time;
891 /* Mark pending segment. Will be sent before next data */
892 src->priv->segment_pending = TRUE;
893 src->priv->segment_seqnum = gst_util_seqnum_next ();
895 GST_DEBUG_OBJECT (src,
896 "Starting new seamless segment. Start %" GST_TIME_FORMAT " stop %"
897 GST_TIME_FORMAT " time %" GST_TIME_FORMAT " base %" GST_TIME_FORMAT,
898 GST_TIME_ARGS (start), GST_TIME_ARGS (stop), GST_TIME_ARGS (time),
899 GST_TIME_ARGS (src->segment.base));
901 GST_OBJECT_UNLOCK (src);
903 src->priv->discont = TRUE;
910 gst_base_src_send_stream_start (GstBaseSrc * src)
914 if (src->priv->stream_start_pending) {
919 gst_pad_create_stream_id (src->srcpad, GST_ELEMENT_CAST (src), NULL);
921 GST_DEBUG_OBJECT (src, "Pushing STREAM_START");
922 event = gst_event_new_stream_start (stream_id);
923 gst_event_set_group_id (event, gst_util_group_id_next ());
925 ret = gst_pad_push_event (src->srcpad, event);
926 src->priv->stream_start_pending = FALSE;
934 * gst_base_src_set_caps:
935 * @src: a #GstBaseSrc
936 * @caps: (transfer none): a #GstCaps
938 * Set new caps on the basesrc source pad.
940 * Returns: %TRUE if the caps could be set
943 gst_base_src_set_caps (GstBaseSrc * src, GstCaps * caps)
945 GstBaseSrcClass *bclass;
947 GstCaps *current_caps;
949 bclass = GST_BASE_SRC_GET_CLASS (src);
951 gst_base_src_send_stream_start (src);
953 current_caps = gst_pad_get_current_caps (GST_BASE_SRC_PAD (src));
954 if (current_caps && gst_caps_is_equal (current_caps, caps)) {
955 GST_DEBUG_OBJECT (src, "New caps equal to old ones: %" GST_PTR_FORMAT,
959 if (bclass->set_caps)
960 res = bclass->set_caps (src, caps);
963 res = gst_pad_push_event (src->srcpad, gst_event_new_caps (caps));
967 gst_caps_unref (current_caps);
973 gst_base_src_default_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
975 GstCaps *caps = NULL;
976 GstPadTemplate *pad_template;
977 GstBaseSrcClass *bclass;
979 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
982 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
984 if (pad_template != NULL) {
985 caps = gst_pad_template_get_caps (pad_template);
988 GstCaps *intersection;
991 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
992 gst_caps_unref (caps);
1000 gst_base_src_default_fixate (GstBaseSrc * bsrc, GstCaps * caps)
1002 GST_DEBUG_OBJECT (bsrc, "using default caps fixate function");
1003 return gst_caps_fixate (caps);
1007 gst_base_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
1009 GstBaseSrcClass *bclass;
1011 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
1014 caps = bclass->fixate (bsrc, caps);
1020 gst_base_src_default_query (GstBaseSrc * src, GstQuery * query)
1024 switch (GST_QUERY_TYPE (query)) {
1025 case GST_QUERY_POSITION:
1029 gst_query_parse_position (query, &format, NULL);
1031 GST_DEBUG_OBJECT (src, "position query in format %s",
1032 gst_format_get_name (format));
1035 case GST_FORMAT_PERCENT:
1041 GST_OBJECT_LOCK (src);
1042 position = src->segment.position;
1043 duration = src->segment.duration;
1044 GST_OBJECT_UNLOCK (src);
1046 if (position != -1 && duration != -1) {
1047 if (position < duration)
1048 percent = gst_util_uint64_scale (GST_FORMAT_PERCENT_MAX, position,
1051 percent = GST_FORMAT_PERCENT_MAX;
1055 gst_query_set_position (query, GST_FORMAT_PERCENT, percent);
1062 GstFormat seg_format;
1064 GST_OBJECT_LOCK (src);
1066 gst_segment_to_stream_time (&src->segment, src->segment.format,
1067 src->segment.position);
1068 seg_format = src->segment.format;
1069 GST_OBJECT_UNLOCK (src);
1071 if (position != -1) {
1072 /* convert to requested format */
1074 gst_pad_query_convert (src->srcpad, seg_format,
1075 position, format, &position);
1079 gst_query_set_position (query, format, position);
1085 case GST_QUERY_DURATION:
1089 gst_query_parse_duration (query, &format, NULL);
1091 GST_DEBUG_OBJECT (src, "duration query in format %s",
1092 gst_format_get_name (format));
1095 case GST_FORMAT_PERCENT:
1096 gst_query_set_duration (query, GST_FORMAT_PERCENT,
1097 GST_FORMAT_PERCENT_MAX);
1103 GstFormat seg_format;
1106 /* may have to refresh duration */
1107 gst_base_src_update_length (src, 0, &length,
1108 g_atomic_int_get (&src->priv->dynamic_size));
1110 /* this is the duration as configured by the subclass. */
1111 GST_OBJECT_LOCK (src);
1112 duration = src->segment.duration;
1113 seg_format = src->segment.format;
1114 GST_OBJECT_UNLOCK (src);
1116 GST_LOG_OBJECT (src, "duration %" G_GINT64_FORMAT ", format %s",
1117 duration, gst_format_get_name (seg_format));
1119 if (duration != -1) {
1120 /* convert to requested format, if this fails, we have a duration
1121 * but we cannot answer the query, we must return FALSE. */
1123 gst_pad_query_convert (src->srcpad, seg_format,
1124 duration, format, &duration);
1126 /* The subclass did not configure a duration, we assume that the
1127 * media has an unknown duration then and we return TRUE to report
1128 * this. Note that this is not the same as returning FALSE, which
1129 * means that we cannot report the duration at all. */
1132 gst_query_set_duration (query, format, duration);
1139 case GST_QUERY_SEEKING:
1141 GstFormat format, seg_format;
1144 GST_OBJECT_LOCK (src);
1145 duration = src->segment.duration;
1146 seg_format = src->segment.format;
1147 GST_OBJECT_UNLOCK (src);
1149 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
1150 if (format == seg_format) {
1151 gst_query_set_seeking (query, seg_format,
1152 gst_base_src_seekable (src), 0, duration);
1155 /* FIXME 2.0: return TRUE + seekable=FALSE for SEEKING query here */
1156 /* Don't reply to the query to make up for demuxers which don't
1157 * handle the SEEKING query yet. Players like Totem will fall back
1158 * to the duration when the SEEKING query isn't answered. */
1163 case GST_QUERY_SEGMENT:
1168 GST_OBJECT_LOCK (src);
1170 format = src->segment.format;
1173 gst_segment_to_stream_time (&src->segment, format,
1174 src->segment.start);
1175 if ((stop = src->segment.stop) == -1)
1176 stop = src->segment.duration;
1178 stop = gst_segment_to_stream_time (&src->segment, format, stop);
1180 gst_query_set_segment (query, src->segment.rate, format, start, stop);
1182 GST_OBJECT_UNLOCK (src);
1187 case GST_QUERY_FORMATS:
1189 gst_query_set_formats (query, 3, GST_FORMAT_DEFAULT,
1190 GST_FORMAT_BYTES, GST_FORMAT_PERCENT);
1194 case GST_QUERY_CONVERT:
1196 GstFormat src_fmt, dest_fmt;
1197 gint64 src_val, dest_val;
1199 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
1201 /* we can only convert between equal formats... */
1202 if (src_fmt == dest_fmt) {
1208 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
1211 case GST_QUERY_LATENCY:
1213 GstClockTime min, max;
1216 /* Subclasses should override and implement something useful */
1217 res = gst_base_src_query_latency (src, &live, &min, &max);
1219 GST_LOG_OBJECT (src, "report latency: live %d, min %" GST_TIME_FORMAT
1220 ", max %" GST_TIME_FORMAT, live, GST_TIME_ARGS (min),
1221 GST_TIME_ARGS (max));
1223 gst_query_set_latency (query, live, min, max);
1226 case GST_QUERY_JITTER:
1227 case GST_QUERY_RATE:
1230 case GST_QUERY_BUFFERING:
1232 GstFormat format, seg_format;
1233 gint64 start, stop, estimated;
1235 gst_query_parse_buffering_range (query, &format, NULL, NULL, NULL);
1237 GST_DEBUG_OBJECT (src, "buffering query in format %s",
1238 gst_format_get_name (format));
1240 GST_OBJECT_LOCK (src);
1241 if (src->random_access) {
1244 if (format == GST_FORMAT_PERCENT)
1245 stop = GST_FORMAT_PERCENT_MAX;
1247 stop = src->segment.duration;
1253 seg_format = src->segment.format;
1254 GST_OBJECT_UNLOCK (src);
1256 /* convert to required format. When the conversion fails, we can't answer
1257 * the query. When the value is unknown, we can don't perform conversion
1258 * but report TRUE. */
1259 if (format != GST_FORMAT_PERCENT && stop != -1) {
1260 res = gst_pad_query_convert (src->srcpad, seg_format,
1261 stop, format, &stop);
1265 if (res && format != GST_FORMAT_PERCENT && start != -1)
1266 res = gst_pad_query_convert (src->srcpad, seg_format,
1267 start, format, &start);
1269 gst_query_set_buffering_range (query, format, start, stop, estimated);
1272 case GST_QUERY_SCHEDULING:
1274 gboolean random_access;
1276 random_access = gst_base_src_is_random_access (src);
1278 /* we can operate in getrange mode if the native format is bytes
1279 * and we are seekable, this condition is set in the random_access
1280 * flag and is set in the _start() method. */
1281 gst_query_set_scheduling (query, GST_SCHEDULING_FLAG_SEEKABLE, 1, -1, 0);
1283 gst_query_add_scheduling_mode (query, GST_PAD_MODE_PULL);
1284 gst_query_add_scheduling_mode (query, GST_PAD_MODE_PUSH);
1289 case GST_QUERY_CAPS:
1291 GstBaseSrcClass *bclass;
1292 GstCaps *caps, *filter;
1294 bclass = GST_BASE_SRC_GET_CLASS (src);
1295 if (bclass->get_caps) {
1296 gst_query_parse_caps (query, &filter);
1297 if ((caps = bclass->get_caps (src, filter))) {
1298 gst_query_set_caps_result (query, caps);
1299 gst_caps_unref (caps);
1308 case GST_QUERY_URI:{
1309 if (GST_IS_URI_HANDLER (src)) {
1310 gchar *uri = gst_uri_handler_get_uri (GST_URI_HANDLER (src));
1313 gst_query_set_uri (query, uri);
1328 GST_DEBUG_OBJECT (src, "query %s returns %d", GST_QUERY_TYPE_NAME (query),
1335 gst_base_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
1338 GstBaseSrcClass *bclass;
1339 gboolean result = FALSE;
1341 src = GST_BASE_SRC (parent);
1342 bclass = GST_BASE_SRC_GET_CLASS (src);
1345 result = bclass->query (src, query);
1351 gst_base_src_default_do_seek (GstBaseSrc * src, GstSegment * segment)
1353 gboolean res = TRUE;
1355 /* update our offset if the start/stop position was updated */
1356 if (segment->format == GST_FORMAT_BYTES) {
1357 segment->time = segment->start;
1358 } else if (segment->start == 0) {
1359 /* seek to start, we can implement a default for this. */
1363 GST_INFO_OBJECT (src, "Can't do a default seek");
1370 gst_base_src_do_seek (GstBaseSrc * src, GstSegment * segment)
1372 GstBaseSrcClass *bclass;
1373 gboolean result = FALSE;
1375 bclass = GST_BASE_SRC_GET_CLASS (src);
1377 GST_INFO_OBJECT (src, "seeking: %" GST_SEGMENT_FORMAT, segment);
1379 if (bclass->do_seek)
1380 result = bclass->do_seek (src, segment);
1385 #define SEEK_TYPE_IS_RELATIVE(t) (((t) != GST_SEEK_TYPE_NONE) && ((t) != GST_SEEK_TYPE_SET))
1388 gst_base_src_default_prepare_seek_segment (GstBaseSrc * src, GstEvent * event,
1389 GstSegment * segment)
1391 /* By default, we try one of 2 things:
1392 * - For absolute seek positions, convert the requested position to our
1393 * configured processing format and place it in the output segment \
1394 * - For relative seek positions, convert our current (input) values to the
1395 * seek format, adjust by the relative seek offset and then convert back to
1396 * the processing format
1398 GstSeekType start_type, stop_type;
1401 GstFormat seek_format, dest_format;
1404 gboolean res = TRUE;
1406 gst_event_parse_seek (event, &rate, &seek_format, &flags,
1407 &start_type, &start, &stop_type, &stop);
1408 dest_format = segment->format;
1410 if (seek_format == dest_format) {
1411 gst_segment_do_seek (segment, rate, seek_format, flags,
1412 start_type, start, stop_type, stop, &update);
1416 if (start_type != GST_SEEK_TYPE_NONE) {
1417 /* FIXME: Handle seek_end by converting the input segment vals */
1419 gst_pad_query_convert (src->srcpad, seek_format, start, dest_format,
1421 start_type = GST_SEEK_TYPE_SET;
1424 if (res && stop_type != GST_SEEK_TYPE_NONE) {
1425 /* FIXME: Handle seek_end by converting the input segment vals */
1427 gst_pad_query_convert (src->srcpad, seek_format, stop, dest_format,
1429 stop_type = GST_SEEK_TYPE_SET;
1432 /* And finally, configure our output segment in the desired format */
1433 gst_segment_do_seek (segment, rate, dest_format, flags, start_type, start,
1434 stop_type, stop, &update);
1443 GST_DEBUG_OBJECT (src, "undefined format given, seek aborted.");
1449 gst_base_src_prepare_seek_segment (GstBaseSrc * src, GstEvent * event,
1450 GstSegment * seeksegment)
1452 GstBaseSrcClass *bclass;
1453 gboolean result = FALSE;
1455 bclass = GST_BASE_SRC_GET_CLASS (src);
1457 if (bclass->prepare_seek_segment)
1458 result = bclass->prepare_seek_segment (src, event, seeksegment);
1463 static GstFlowReturn
1464 gst_base_src_default_alloc (GstBaseSrc * src, guint64 offset,
1465 guint size, GstBuffer ** buffer)
1468 GstBaseSrcPrivate *priv = src->priv;
1471 ret = gst_buffer_pool_acquire_buffer (priv->pool, buffer, NULL);
1472 } else if (size != -1) {
1473 *buffer = gst_buffer_new_allocate (priv->allocator, size, &priv->params);
1474 if (G_UNLIKELY (*buffer == NULL))
1479 GST_WARNING_OBJECT (src, "Not trying to alloc %u bytes. Blocksize not set?",
1488 GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", size);
1489 return GST_FLOW_ERROR;
1493 static GstFlowReturn
1494 gst_base_src_default_create (GstBaseSrc * src, guint64 offset,
1495 guint size, GstBuffer ** buffer)
1497 GstBaseSrcClass *bclass;
1501 bclass = GST_BASE_SRC_GET_CLASS (src);
1503 if (G_UNLIKELY (!bclass->alloc))
1505 if (G_UNLIKELY (!bclass->fill))
1508 if (*buffer == NULL) {
1509 /* downstream did not provide us with a buffer to fill, allocate one
1511 ret = bclass->alloc (src, offset, size, &res_buf);
1512 if (G_UNLIKELY (ret != GST_FLOW_OK))
1518 if (G_LIKELY (size > 0)) {
1519 /* only call fill when there is a size */
1520 ret = bclass->fill (src, offset, size, res_buf);
1521 if (G_UNLIKELY (ret != GST_FLOW_OK))
1532 GST_DEBUG_OBJECT (src, "no fill or alloc function");
1533 return GST_FLOW_NOT_SUPPORTED;
1537 GST_DEBUG_OBJECT (src, "Failed to allocate buffer of %u bytes", size);
1542 GST_DEBUG_OBJECT (src, "fill returned %d (%s)", ret,
1543 gst_flow_get_name (ret));
1544 if (*buffer == NULL)
1545 gst_buffer_unref (res_buf);
1550 /* this code implements the seeking. It is a good example
1551 * handling all cases.
1553 * A seek updates the currently configured segment.start
1554 * and segment.stop values based on the SEEK_TYPE. If the
1555 * segment.start value is updated, a seek to this new position
1556 * should be performed.
1558 * The seek can only be executed when we are not currently
1559 * streaming any data, to make sure that this is the case, we
1560 * acquire the STREAM_LOCK which is taken when we are in the
1561 * _loop() function or when a getrange() is called. Normally
1562 * we will not receive a seek if we are operating in pull mode
1563 * though. When we operate as a live source we might block on the live
1564 * cond, which does not release the STREAM_LOCK. Therefore we will try
1565 * to grab the LIVE_LOCK instead of the STREAM_LOCK to make sure it is
1566 * safe to perform the seek.
1568 * When we are in the loop() function, we might be in the middle
1569 * of pushing a buffer, which might block in a sink. To make sure
1570 * that the push gets unblocked we push out a FLUSH_START event.
1571 * Our loop function will get a FLUSHING return value from
1572 * the push and will pause, effectively releasing the STREAM_LOCK.
1574 * For a non-flushing seek, we pause the task, which might eventually
1575 * release the STREAM_LOCK. We say eventually because when the sink
1576 * blocks on the sample we might wait a very long time until the sink
1577 * unblocks the sample. In any case we acquire the STREAM_LOCK and
1578 * can continue the seek. A non-flushing seek is normally done in a
1579 * running pipeline to perform seamless playback, this means that the sink is
1580 * PLAYING and will return from its chain function.
1581 * In the case of a non-flushing seek we need to make sure that the
1582 * data we output after the seek is continuous with the previous data,
1583 * this is because a non-flushing seek does not reset the running-time
1584 * to 0. We do this by closing the currently running segment, ie. sending
1585 * a new_segment event with the stop position set to the last processed
1588 * After updating the segment.start/stop values, we prepare for
1589 * streaming again. We push out a FLUSH_STOP to make the peer pad
1590 * accept data again and we start our task again.
1592 * A segment seek posts a message on the bus saying that the playback
1593 * of the segment started. We store the segment flag internally because
1594 * when we reach the segment.stop we have to post a segment.done
1595 * instead of EOS when doing a segment seek.
1598 gst_base_src_perform_seek (GstBaseSrc * src, GstEvent * event, gboolean unlock)
1600 gboolean res = TRUE, tres;
1602 GstFormat seek_format, dest_format;
1604 GstSeekType start_type, stop_type;
1606 gboolean flush, playing;
1608 gboolean relative_seek = FALSE;
1609 gboolean seekseg_configured = FALSE;
1610 GstSegment seeksegment;
1614 GST_DEBUG_OBJECT (src, "doing seek: %" GST_PTR_FORMAT, event);
1616 GST_OBJECT_LOCK (src);
1617 dest_format = src->segment.format;
1618 GST_OBJECT_UNLOCK (src);
1621 gst_event_parse_seek (event, &rate, &seek_format, &flags,
1622 &start_type, &start, &stop_type, &stop);
1624 relative_seek = SEEK_TYPE_IS_RELATIVE (start_type) ||
1625 SEEK_TYPE_IS_RELATIVE (stop_type);
1627 if (dest_format != seek_format && !relative_seek) {
1628 /* If we have an ABSOLUTE position (SEEK_SET only), we can convert it
1629 * here before taking the stream lock, otherwise we must convert it later,
1630 * once we have the stream lock and can read the last configures segment
1631 * start and stop positions */
1632 gst_segment_init (&seeksegment, dest_format);
1634 if (!gst_base_src_prepare_seek_segment (src, event, &seeksegment))
1635 goto prepare_failed;
1637 seekseg_configured = TRUE;
1640 flush = flags & GST_SEEK_FLAG_FLUSH;
1641 seqnum = gst_event_get_seqnum (event);
1644 /* get next seqnum */
1645 seqnum = gst_util_seqnum_next ();
1648 /* send flush start */
1650 tevent = gst_event_new_flush_start ();
1651 gst_event_set_seqnum (tevent, seqnum);
1652 gst_pad_push_event (src->srcpad, tevent);
1654 gst_pad_pause_task (src->srcpad);
1656 /* unblock streaming thread. */
1658 gst_base_src_set_flushing (src, TRUE, FALSE, &playing);
1660 /* grab streaming lock, this should eventually be possible, either
1661 * because the task is paused, our streaming thread stopped
1662 * or because our peer is flushing. */
1663 GST_PAD_STREAM_LOCK (src->srcpad);
1664 if (G_UNLIKELY (src->priv->seqnum == seqnum)) {
1665 /* we have seen this event before, issue a warning for now */
1666 GST_WARNING_OBJECT (src, "duplicate event found %" G_GUINT32_FORMAT,
1669 src->priv->seqnum = seqnum;
1670 GST_DEBUG_OBJECT (src, "seek with seqnum %" G_GUINT32_FORMAT, seqnum);
1674 gst_base_src_set_flushing (src, FALSE, playing, NULL);
1676 /* If we configured the seeksegment above, don't overwrite it now. Otherwise
1677 * copy the current segment info into the temp segment that we can actually
1678 * attempt the seek with. We only update the real segment if the seek succeeds. */
1679 if (!seekseg_configured) {
1680 memcpy (&seeksegment, &src->segment, sizeof (GstSegment));
1682 /* now configure the final seek segment */
1684 if (seeksegment.format != seek_format) {
1685 /* OK, here's where we give the subclass a chance to convert the relative
1686 * seek into an absolute one in the processing format. We set up any
1687 * absolute seek above, before taking the stream lock. */
1688 if (!gst_base_src_prepare_seek_segment (src, event, &seeksegment)) {
1689 GST_DEBUG_OBJECT (src, "Preparing the seek failed after flushing. "
1694 /* The seek format matches our processing format, no need to ask the
1695 * the subclass to configure the segment. */
1696 gst_segment_do_seek (&seeksegment, rate, seek_format, flags,
1697 start_type, start, stop_type, stop, &update);
1700 /* Else, no seek event passed, so we're just (re)starting the
1705 GST_DEBUG_OBJECT (src, "segment configured from %" G_GINT64_FORMAT
1706 " to %" G_GINT64_FORMAT ", position %" G_GINT64_FORMAT,
1707 seeksegment.start, seeksegment.stop, seeksegment.position);
1709 /* do the seek, segment.position contains the new position. */
1710 res = gst_base_src_do_seek (src, &seeksegment);
1713 /* and prepare to continue streaming */
1715 tevent = gst_event_new_flush_stop (TRUE);
1716 gst_event_set_seqnum (tevent, seqnum);
1717 /* send flush stop, peer will accept data and events again. We
1718 * are not yet providing data as we still have the STREAM_LOCK. */
1719 gst_pad_push_event (src->srcpad, tevent);
1722 /* The subclass must have converted the segment to the processing format
1724 if (res && seeksegment.format != dest_format) {
1725 GST_DEBUG_OBJECT (src, "Subclass failed to prepare a seek segment "
1726 "in the correct format. Aborting seek.");
1730 /* if the seek was successful, we update our real segment and push
1731 * out the new segment. */
1733 GST_OBJECT_LOCK (src);
1734 memcpy (&src->segment, &seeksegment, sizeof (GstSegment));
1735 GST_OBJECT_UNLOCK (src);
1737 if (seeksegment.flags & GST_SEGMENT_FLAG_SEGMENT) {
1738 GstMessage *message;
1740 message = gst_message_new_segment_start (GST_OBJECT (src),
1741 seeksegment.format, seeksegment.position);
1742 gst_message_set_seqnum (message, seqnum);
1744 gst_element_post_message (GST_ELEMENT (src), message);
1747 src->priv->segment_pending = TRUE;
1748 src->priv->segment_seqnum = seqnum;
1751 src->priv->discont = TRUE;
1752 src->running = TRUE;
1753 /* and restart the task in case it got paused explicitly or by
1754 * the FLUSH_START event we pushed out. */
1755 tres = gst_pad_start_task (src->srcpad, (GstTaskFunction) gst_base_src_loop,
1760 /* and release the lock again so we can continue streaming */
1761 GST_PAD_STREAM_UNLOCK (src->srcpad);
1767 GST_DEBUG_OBJECT (src, "Preparing the seek failed before flushing. "
1772 /* all events send to this element directly. This is mainly done from the
1776 gst_base_src_send_event (GstElement * element, GstEvent * event)
1779 gboolean result = FALSE;
1780 GstBaseSrcClass *bclass;
1782 src = GST_BASE_SRC (element);
1783 bclass = GST_BASE_SRC_GET_CLASS (src);
1785 GST_DEBUG_OBJECT (src, "handling event %p %" GST_PTR_FORMAT, event, event);
1787 switch (GST_EVENT_TYPE (event)) {
1788 /* bidirectional events */
1789 case GST_EVENT_FLUSH_START:
1790 GST_DEBUG_OBJECT (src, "pushing flush-start event downstream");
1791 result = gst_pad_push_event (src->srcpad, event);
1792 /* also unblock the create function */
1793 gst_base_src_activate_pool (src, FALSE);
1794 /* unlock any subclasses, we need to do this before grabbing the
1795 * LIVE_LOCK since we hold this lock before going into ::create. We pass an
1796 * unlock to the params because of backwards compat (see seek handler)*/
1798 bclass->unlock (src);
1800 /* the live lock is released when we are blocked, waiting for playing or
1801 * when we sync to the clock. */
1802 GST_LIVE_LOCK (src);
1803 src->priv->flushing = TRUE;
1804 /* clear pending EOS if any */
1805 if (g_atomic_int_get (&src->priv->has_pending_eos)) {
1806 GST_OBJECT_LOCK (src);
1807 CLEAR_PENDING_EOS (src);
1808 src->priv->forced_eos = FALSE;
1809 GST_OBJECT_UNLOCK (src);
1811 if (bclass->unlock_stop)
1812 bclass->unlock_stop (src);
1814 gst_clock_id_unschedule (src->clock_id);
1815 GST_DEBUG_OBJECT (src, "signal");
1816 GST_LIVE_SIGNAL (src);
1817 GST_LIVE_UNLOCK (src);
1820 case GST_EVENT_FLUSH_STOP:
1824 GST_LIVE_LOCK (src);
1825 src->priv->segment_pending = TRUE;
1826 src->priv->flushing = FALSE;
1827 GST_DEBUG_OBJECT (src, "pushing flush-stop event downstream");
1828 result = gst_pad_push_event (src->srcpad, event);
1830 gst_base_src_activate_pool (src, TRUE);
1832 GST_OBJECT_LOCK (src->srcpad);
1833 start = (GST_PAD_MODE (src->srcpad) == GST_PAD_MODE_PUSH);
1834 GST_OBJECT_UNLOCK (src->srcpad);
1837 if (!src->live_running)
1842 gst_pad_start_task (src->srcpad, (GstTaskFunction) gst_base_src_loop,
1844 GST_LIVE_UNLOCK (src);
1849 /* downstream serialized events */
1852 /* queue EOS and make sure the task or pull function performs the EOS
1855 * We have two possibilities:
1857 * - Before we are to enter the _create function, we check the has_pending_eos
1858 * first and do EOS instead of entering it.
1859 * - If we are in the _create function or we did not manage to set the
1860 * flag fast enough and we are about to enter the _create function,
1861 * we unlock it so that we exit with FLUSHING immediately. We then
1862 * check the EOS flag and do the EOS logic.
1864 GST_OBJECT_LOCK (src);
1865 g_atomic_int_set (&src->priv->has_pending_eos, TRUE);
1866 if (src->priv->pending_eos)
1867 gst_event_unref (src->priv->pending_eos);
1868 src->priv->pending_eos = event;
1870 GST_OBJECT_UNLOCK (src);
1872 GST_DEBUG_OBJECT (src, "EOS marked, calling unlock");
1874 /* unlock the _create function so that we can check the has_pending_eos flag
1875 * and we can do EOS. This will eventually release the LIVE_LOCK again so
1876 * that we can grab it and stop the unlock again. We don't take the stream
1877 * lock so that this operation is guaranteed to never block. */
1878 gst_base_src_activate_pool (src, FALSE);
1880 bclass->unlock (src);
1882 GST_DEBUG_OBJECT (src, "unlock called, waiting for LIVE_LOCK");
1884 GST_LIVE_LOCK (src);
1885 GST_DEBUG_OBJECT (src, "LIVE_LOCK acquired, calling unlock_stop");
1886 /* now stop the unlock of the streaming thread again. Grabbing the live
1887 * lock is enough because that protects the create function. */
1888 if (bclass->unlock_stop)
1889 bclass->unlock_stop (src);
1890 gst_base_src_activate_pool (src, TRUE);
1891 GST_LIVE_UNLOCK (src);
1896 case GST_EVENT_SEGMENT:
1897 /* sending random SEGMENT downstream can break sync. */
1900 case GST_EVENT_CUSTOM_DOWNSTREAM:
1901 case GST_EVENT_CUSTOM_BOTH:
1902 /* Insert TAG, CUSTOM_DOWNSTREAM, CUSTOM_BOTH in the dataflow */
1903 GST_OBJECT_LOCK (src);
1904 src->priv->pending_events =
1905 g_list_append (src->priv->pending_events, event);
1906 g_atomic_int_set (&src->priv->have_events, TRUE);
1907 GST_OBJECT_UNLOCK (src);
1911 case GST_EVENT_BUFFERSIZE:
1912 /* does not seem to make much sense currently */
1915 /* upstream events */
1917 /* elements should override send_event and do something */
1919 case GST_EVENT_SEEK:
1923 GST_OBJECT_LOCK (src->srcpad);
1924 if (GST_PAD_MODE (src->srcpad) == GST_PAD_MODE_PULL)
1926 started = GST_PAD_MODE (src->srcpad) == GST_PAD_MODE_PUSH;
1927 GST_OBJECT_UNLOCK (src->srcpad);
1930 GST_DEBUG_OBJECT (src, "performing seek");
1931 /* when we are running in push mode, we can execute the
1932 * seek right now. */
1933 result = gst_base_src_perform_seek (src, event, TRUE);
1937 /* else we store the event and execute the seek when we
1939 GST_OBJECT_LOCK (src);
1940 GST_DEBUG_OBJECT (src, "queueing seek");
1941 event_p = &src->pending_seek;
1942 gst_event_replace ((GstEvent **) event_p, event);
1943 GST_OBJECT_UNLOCK (src);
1944 /* assume the seek will work */
1949 case GST_EVENT_NAVIGATION:
1950 /* could make sense for elements that do something with navigation events
1951 * but then they would need to override the send_event function */
1953 case GST_EVENT_LATENCY:
1954 /* does not seem to make sense currently */
1958 case GST_EVENT_CUSTOM_UPSTREAM:
1959 /* override send_event if you want this */
1961 case GST_EVENT_CUSTOM_DOWNSTREAM_OOB:
1962 case GST_EVENT_CUSTOM_BOTH_OOB:
1963 /* insert a random custom event into the pipeline */
1964 GST_DEBUG_OBJECT (src, "pushing custom OOB event downstream");
1965 result = gst_pad_push_event (src->srcpad, event);
1966 /* we gave away the ref to the event in the push */
1973 /* if we still have a ref to the event, unref it now */
1975 gst_event_unref (event);
1982 GST_DEBUG_OBJECT (src, "cannot perform seek when operating in pull mode");
1983 GST_OBJECT_UNLOCK (src->srcpad);
1990 gst_base_src_seekable (GstBaseSrc * src)
1992 GstBaseSrcClass *bclass;
1993 bclass = GST_BASE_SRC_GET_CLASS (src);
1994 if (bclass->is_seekable)
1995 return bclass->is_seekable (src);
2001 gst_base_src_update_qos (GstBaseSrc * src,
2002 gdouble proportion, GstClockTimeDiff diff, GstClockTime timestamp)
2004 GST_CAT_DEBUG_OBJECT (GST_CAT_QOS, src,
2005 "qos: proportion: %lf, diff %" G_GINT64_FORMAT ", timestamp %"
2006 GST_TIME_FORMAT, proportion, diff, GST_TIME_ARGS (timestamp));
2008 GST_OBJECT_LOCK (src);
2009 src->priv->proportion = proportion;
2010 src->priv->earliest_time = timestamp + diff;
2011 GST_OBJECT_UNLOCK (src);
2016 gst_base_src_default_event (GstBaseSrc * src, GstEvent * event)
2020 GST_DEBUG_OBJECT (src, "handle event %" GST_PTR_FORMAT, event);
2022 switch (GST_EVENT_TYPE (event)) {
2023 case GST_EVENT_SEEK:
2024 /* is normally called when in push mode */
2025 if (!gst_base_src_seekable (src))
2028 result = gst_base_src_perform_seek (src, event, TRUE);
2030 case GST_EVENT_FLUSH_START:
2031 /* cancel any blocking getrange, is normally called
2032 * when in pull mode. */
2033 result = gst_base_src_set_flushing (src, TRUE, FALSE, NULL);
2035 case GST_EVENT_FLUSH_STOP:
2036 result = gst_base_src_set_flushing (src, FALSE, TRUE, NULL);
2041 GstClockTimeDiff diff;
2042 GstClockTime timestamp;
2044 gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
2045 gst_base_src_update_qos (src, proportion, diff, timestamp);
2049 case GST_EVENT_RECONFIGURE:
2052 case GST_EVENT_LATENCY:
2064 GST_DEBUG_OBJECT (src, "is not seekable");
2070 gst_base_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
2073 GstBaseSrcClass *bclass;
2074 gboolean result = FALSE;
2076 src = GST_BASE_SRC (parent);
2077 bclass = GST_BASE_SRC_GET_CLASS (src);
2079 if (bclass->event) {
2080 if (!(result = bclass->event (src, event)))
2081 goto subclass_failed;
2085 gst_event_unref (event);
2092 GST_DEBUG_OBJECT (src, "subclass refused event");
2098 gst_base_src_set_property (GObject * object, guint prop_id,
2099 const GValue * value, GParamSpec * pspec)
2103 src = GST_BASE_SRC (object);
2106 case PROP_BLOCKSIZE:
2107 gst_base_src_set_blocksize (src, g_value_get_uint (value));
2109 case PROP_NUM_BUFFERS:
2110 src->num_buffers = g_value_get_int (value);
2113 src->typefind = g_value_get_boolean (value);
2115 case PROP_DO_TIMESTAMP:
2116 gst_base_src_set_do_timestamp (src, g_value_get_boolean (value));
2118 #ifdef TIZEN_PROFILE_TV
2119 case PROP_UPDATE_SEGMENT:
2120 gst_base_src_update_segment (src, g_value_get_int64 (value));
2124 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2130 gst_base_src_get_property (GObject * object, guint prop_id, GValue * value,
2135 src = GST_BASE_SRC (object);
2138 case PROP_BLOCKSIZE:
2139 g_value_set_uint (value, gst_base_src_get_blocksize (src));
2141 case PROP_NUM_BUFFERS:
2142 g_value_set_int (value, src->num_buffers);
2145 g_value_set_boolean (value, src->typefind);
2147 case PROP_DO_TIMESTAMP:
2148 g_value_set_boolean (value, gst_base_src_get_do_timestamp (src));
2151 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2156 /* with STREAM_LOCK and LOCK */
2157 static GstClockReturn
2158 gst_base_src_wait (GstBaseSrc * basesrc, GstClock * clock, GstClockTime time)
2163 id = gst_clock_new_single_shot_id (clock, time);
2165 basesrc->clock_id = id;
2166 /* release the live lock while waiting */
2167 GST_LIVE_UNLOCK (basesrc);
2169 ret = gst_clock_id_wait (id, NULL);
2171 GST_LIVE_LOCK (basesrc);
2172 gst_clock_id_unref (id);
2173 basesrc->clock_id = NULL;
2178 /* perform synchronisation on a buffer.
2181 static GstClockReturn
2182 gst_base_src_do_sync (GstBaseSrc * basesrc, GstBuffer * buffer)
2184 GstClockReturn result;
2185 GstClockTime start, end;
2186 GstBaseSrcClass *bclass;
2187 GstClockTime base_time;
2189 GstClockTime now = GST_CLOCK_TIME_NONE, pts, dts, timestamp;
2190 gboolean do_timestamp, first, pseudo_live, is_live;
2192 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
2195 if (bclass->get_times)
2196 bclass->get_times (basesrc, buffer, &start, &end);
2198 /* get buffer timestamp */
2199 dts = GST_BUFFER_DTS (buffer);
2200 pts = GST_BUFFER_PTS (buffer);
2202 if (GST_CLOCK_TIME_IS_VALID (dts))
2207 /* grab the lock to prepare for clocking and calculate the startup
2209 GST_OBJECT_LOCK (basesrc);
2211 is_live = basesrc->is_live;
2212 /* if we are asked to sync against the clock we are a pseudo live element */
2213 pseudo_live = (start != -1 && is_live);
2214 /* check for the first buffer */
2215 first = (basesrc->priv->latency == -1);
2217 if (timestamp != -1 && pseudo_live) {
2218 GstClockTime latency;
2220 /* we have a timestamp and a sync time, latency is the diff */
2221 if (timestamp <= start)
2222 latency = start - timestamp;
2227 GST_DEBUG_OBJECT (basesrc, "pseudo_live with latency %" GST_TIME_FORMAT,
2228 GST_TIME_ARGS (latency));
2229 /* first time we calculate latency, just configure */
2230 basesrc->priv->latency = latency;
2232 if (basesrc->priv->latency != latency) {
2233 /* we have a new latency, FIXME post latency message */
2234 basesrc->priv->latency = latency;
2235 GST_DEBUG_OBJECT (basesrc, "latency changed to %" GST_TIME_FORMAT,
2236 GST_TIME_ARGS (latency));
2240 GST_DEBUG_OBJECT (basesrc, "no latency needed, live %d, sync %d",
2241 is_live, start != -1);
2242 basesrc->priv->latency = 0;
2245 /* get clock, if no clock, we can't sync or do timestamps */
2246 if ((clock = GST_ELEMENT_CLOCK (basesrc)) == NULL)
2249 gst_object_ref (clock);
2251 base_time = GST_ELEMENT_CAST (basesrc)->base_time;
2253 do_timestamp = basesrc->priv->do_timestamp;
2254 GST_OBJECT_UNLOCK (basesrc);
2256 /* first buffer, calculate the timestamp offset */
2258 GstClockTime running_time;
2260 now = gst_clock_get_time (clock);
2261 running_time = now - base_time;
2263 GST_LOG_OBJECT (basesrc,
2264 "startup PTS: %" GST_TIME_FORMAT ", DTS %" GST_TIME_FORMAT
2265 ", running_time %" GST_TIME_FORMAT, GST_TIME_ARGS (pts),
2266 GST_TIME_ARGS (dts), GST_TIME_ARGS (running_time));
2268 if (pseudo_live && timestamp != -1) {
2269 /* live source and we need to sync, add startup latency to all timestamps
2270 * to get the real running_time. Live sources should always timestamp
2271 * according to the current running time. */
2272 basesrc->priv->ts_offset = GST_CLOCK_DIFF (timestamp, running_time);
2274 GST_LOG_OBJECT (basesrc, "live with sync, ts_offset %" GST_TIME_FORMAT,
2275 GST_TIME_ARGS (basesrc->priv->ts_offset));
2277 basesrc->priv->ts_offset = 0;
2278 GST_LOG_OBJECT (basesrc, "no timestamp offset needed");
2281 if (!GST_CLOCK_TIME_IS_VALID (dts)) {
2284 } else if (!GST_CLOCK_TIME_IS_VALID (pts)) {
2285 if (GST_CLOCK_TIME_IS_VALID (basesrc->segment.start)) {
2286 dts = basesrc->segment.start;
2291 GST_BUFFER_DTS (buffer) = dts;
2293 GST_LOG_OBJECT (basesrc, "created DTS %" GST_TIME_FORMAT,
2294 GST_TIME_ARGS (dts));
2297 /* not the first buffer, the timestamp is the diff between the clock and
2299 if (do_timestamp && !GST_CLOCK_TIME_IS_VALID (dts)) {
2300 now = gst_clock_get_time (clock);
2302 dts = now - base_time;
2303 GST_BUFFER_DTS (buffer) = dts;
2305 GST_LOG_OBJECT (basesrc, "created DTS %" GST_TIME_FORMAT,
2306 GST_TIME_ARGS (dts));
2309 if (!GST_CLOCK_TIME_IS_VALID (pts)) {
2310 if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT))
2313 GST_BUFFER_PTS (buffer) = dts;
2315 GST_LOG_OBJECT (basesrc, "created PTS %" GST_TIME_FORMAT,
2316 GST_TIME_ARGS (pts));
2319 /* if we don't have a buffer timestamp, we don't sync */
2320 if (!GST_CLOCK_TIME_IS_VALID (start))
2324 /* for pseudo live sources, add our ts_offset to the timestamp */
2325 if (GST_CLOCK_TIME_IS_VALID (pts))
2326 GST_BUFFER_PTS (buffer) += basesrc->priv->ts_offset;
2327 if (GST_CLOCK_TIME_IS_VALID (dts))
2328 GST_BUFFER_DTS (buffer) += basesrc->priv->ts_offset;
2329 start += basesrc->priv->ts_offset;
2332 GST_LOG_OBJECT (basesrc,
2333 "waiting for clock, base time %" GST_TIME_FORMAT
2334 ", stream_start %" GST_TIME_FORMAT,
2335 GST_TIME_ARGS (base_time), GST_TIME_ARGS (start));
2337 result = gst_base_src_wait (basesrc, clock, start + base_time);
2339 gst_object_unref (clock);
2341 GST_LOG_OBJECT (basesrc, "clock entry done: %d", result);
2348 GST_DEBUG_OBJECT (basesrc, "we have no clock");
2349 GST_OBJECT_UNLOCK (basesrc);
2350 return GST_CLOCK_OK;
2354 GST_DEBUG_OBJECT (basesrc, "no sync needed");
2355 gst_object_unref (clock);
2356 return GST_CLOCK_OK;
2360 /* Called with STREAM_LOCK and LIVE_LOCK */
2362 gst_base_src_update_length (GstBaseSrc * src, guint64 offset, guint * length,
2365 guint64 size, maxsize;
2366 GstBaseSrcClass *bclass;
2369 /* only operate if we are working with bytes */
2370 if (src->segment.format != GST_FORMAT_BYTES)
2373 bclass = GST_BASE_SRC_GET_CLASS (src);
2375 stop = src->segment.stop;
2376 /* get total file size */
2377 size = src->segment.duration;
2379 /* when not doing automatic EOS, just use the stop position. We don't use
2380 * the size to check for EOS */
2381 if (!g_atomic_int_get (&src->priv->automatic_eos))
2383 /* Otherwise, the max amount of bytes to read is the total
2384 * size or up to the segment.stop if present. */
2385 else if (stop != -1)
2386 maxsize = size != -1 ? MIN (size, stop) : stop;
2390 GST_DEBUG_OBJECT (src,
2391 "reading offset %" G_GUINT64_FORMAT ", length %u, size %" G_GINT64_FORMAT
2392 ", segment.stop %" G_GINT64_FORMAT ", maxsize %" G_GINT64_FORMAT, offset,
2393 *length, size, stop, maxsize);
2395 /* check size if we have one */
2396 if (maxsize != -1) {
2397 /* if we run past the end, check if the file became bigger and
2398 * retry. Mind wrap when checking. */
2399 if (G_UNLIKELY (offset >= maxsize || offset + *length >= maxsize || force)) {
2400 /* see if length of the file changed */
2401 if (bclass->get_size)
2402 if (!bclass->get_size (src, &size))
2405 /* make sure we don't exceed the configured segment stop
2408 maxsize = MIN (size, stop);
2412 /* if we are at or past the end, EOS */
2413 if (G_UNLIKELY (offset >= maxsize))
2414 goto unexpected_length;
2416 /* else we can clip to the end */
2417 if (G_UNLIKELY (offset + *length >= maxsize))
2418 *length = maxsize - offset;
2423 /* keep track of current duration. segment is in bytes, we checked
2425 GST_OBJECT_LOCK (src);
2426 src->segment.duration = size;
2427 GST_OBJECT_UNLOCK (src);
2434 GST_WARNING_OBJECT (src, "processing at or past EOS");
2439 /* must be called with LIVE_LOCK */
2440 static GstFlowReturn
2441 gst_base_src_get_range (GstBaseSrc * src, guint64 offset, guint length,
2445 GstBaseSrcClass *bclass;
2446 GstClockReturn status;
2450 bclass = GST_BASE_SRC_GET_CLASS (src);
2454 if (G_UNLIKELY (!src->live_running)) {
2455 ret = gst_base_src_wait_playing (src);
2456 if (ret != GST_FLOW_OK)
2461 if (G_UNLIKELY (!GST_BASE_SRC_IS_STARTED (src)
2462 && !GST_BASE_SRC_IS_STARTING (src)))
2465 if (G_UNLIKELY (!bclass->create))
2468 if (G_UNLIKELY (!gst_base_src_update_length (src, offset, &length, FALSE)))
2469 goto unexpected_length;
2471 /* track position */
2472 GST_OBJECT_LOCK (src);
2473 if (src->segment.format == GST_FORMAT_BYTES)
2474 src->segment.position = offset;
2475 GST_OBJECT_UNLOCK (src);
2477 /* normally we don't count buffers */
2478 if (G_UNLIKELY (src->num_buffers_left >= 0)) {
2479 if (src->num_buffers_left == 0)
2480 goto reached_num_buffers;
2482 src->num_buffers_left--;
2485 /* don't enter the create function if a pending EOS event was set. For the
2486 * logic of the has_pending_eos, check the event function of this class. */
2487 if (G_UNLIKELY (g_atomic_int_get (&src->priv->has_pending_eos))) {
2488 src->priv->forced_eos = TRUE;
2492 GST_DEBUG_OBJECT (src,
2493 "calling create offset %" G_GUINT64_FORMAT " length %u, time %"
2494 G_GINT64_FORMAT, offset, length, src->segment.time);
2496 res_buf = in_buf = *buf;
2498 ret = bclass->create (src, offset, length, &res_buf);
2500 /* The create function could be unlocked because we have a pending EOS. It's
2501 * possible that we have a valid buffer from create that we need to
2502 * discard when the create function returned _OK. */
2503 if (G_UNLIKELY (g_atomic_int_get (&src->priv->has_pending_eos))) {
2504 if (ret == GST_FLOW_OK) {
2507 #ifdef TIZEN_FEATURE_TRUSTZONE
2508 /*tzappsrc patch : release handle when unref res_buf*/
2509 if(bclass->tz_src_release_handle)
2511 GST_INFO_OBJECT (src, "tzappsrc release the handle");
2512 bclass->tz_src_release_handle(src,res_buf);
2515 gst_buffer_unref (res_buf);
2518 src->priv->forced_eos = TRUE;
2522 if (G_UNLIKELY (ret != GST_FLOW_OK))
2525 /* fallback in case the create function didn't fill a provided buffer */
2526 if (in_buf != NULL && res_buf != in_buf) {
2530 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, src, "create function didn't "
2531 "fill the provided buffer, copying");
2533 if (!gst_buffer_map (in_buf, &info, GST_MAP_WRITE))
2536 copied_size = gst_buffer_extract (res_buf, 0, info.data, info.size);
2537 gst_buffer_unmap (in_buf, &info);
2538 gst_buffer_set_size (in_buf, copied_size);
2540 gst_buffer_copy_into (in_buf, res_buf, GST_BUFFER_COPY_METADATA, 0, -1);
2542 gst_buffer_unref (res_buf);
2546 /* no timestamp set and we are at offset 0, we can timestamp with 0 */
2547 if (offset == 0 && src->segment.time == 0
2548 && GST_BUFFER_DTS (res_buf) == -1 && !src->is_live) {
2549 GST_DEBUG_OBJECT (src, "setting first timestamp to 0");
2550 res_buf = gst_buffer_make_writable (res_buf);
2551 GST_BUFFER_DTS (res_buf) = 0;
2554 /* now sync before pushing the buffer */
2555 status = gst_base_src_do_sync (src, res_buf);
2557 /* waiting for the clock could have made us flushing */
2558 if (G_UNLIKELY (src->priv->flushing))
2562 case GST_CLOCK_EARLY:
2563 /* the buffer is too late. We currently don't drop the buffer. */
2564 GST_DEBUG_OBJECT (src, "buffer too late!, returning anyway");
2567 /* buffer synchronised properly */
2568 GST_DEBUG_OBJECT (src, "buffer ok");
2570 case GST_CLOCK_UNSCHEDULED:
2571 /* this case is triggered when we were waiting for the clock and
2572 * it got unlocked because we did a state change. In any case, get rid of
2576 #ifdef TIZEN_FEATURE_TRUSTZONE
2577 /*tzappsrc patch : release handle when unref res_buf*/
2578 GstBaseSrcClass *klass = GST_BASE_SRC_GET_CLASS(src);
2579 if(klass->tz_src_release_handle)
2581 GST_INFO_OBJECT (src, "tzappsrc release the handle");
2582 klass->tz_src_release_handle(src,res_buf);
2585 gst_buffer_unref (res_buf);
2588 if (!src->live_running) {
2589 /* We return FLUSHING when we are not running to stop the dataflow also
2590 * get rid of the produced buffer. */
2591 GST_DEBUG_OBJECT (src,
2592 "clock was unscheduled (%d), returning FLUSHING", status);
2593 ret = GST_FLOW_FLUSHING;
2595 /* If we are running when this happens, we quickly switched between
2596 * pause and playing. We try to produce a new buffer */
2597 GST_DEBUG_OBJECT (src,
2598 "clock was unscheduled (%d), but we are running", status);
2603 /* all other result values are unexpected and errors */
2604 GST_ELEMENT_ERROR (src, CORE, CLOCK,
2605 (_("Internal clock error.")),
2606 ("clock returned unexpected return value %d", status));
2609 #ifdef TIZEN_FEATURE_TRUSTZONE
2610 /*tzappsrc patch : release handle when unref res_buf*/
2611 GstBaseSrcClass *klass = GST_BASE_SRC_GET_CLASS(src);
2612 if(klass->tz_src_release_handle)
2614 GST_INFO_OBJECT (src, "tzappsrc release the handle");
2615 klass->tz_src_release_handle(src,res_buf);
2618 gst_buffer_unref (res_buf);
2620 ret = GST_FLOW_ERROR;
2623 if (G_LIKELY (ret == GST_FLOW_OK))
2631 GST_DEBUG_OBJECT (src, "wait_playing returned %d (%s)", ret,
2632 gst_flow_get_name (ret));
2637 GST_DEBUG_OBJECT (src, "create returned %d (%s)", ret,
2638 gst_flow_get_name (ret));
2643 GST_ELEMENT_ERROR (src, RESOURCE, BUSY,
2644 (_("Failed to map buffer.")),
2645 ("failed to map result buffer in WRITE mode"));
2648 #ifdef TIZEN_FEATURE_TRUSTZONE
2649 /*tzappsrc patch : release handle when unref res_buf*/
2650 GstBaseSrcClass *klass = GST_BASE_SRC_GET_CLASS(src);
2651 if(klass->tz_src_release_handle)
2653 GST_INFO_OBJECT (src, "tzappsrc release the handle");
2654 klass->tz_src_release_handle(src,res_buf);
2657 gst_buffer_unref (res_buf);
2659 return GST_FLOW_ERROR;
2663 GST_DEBUG_OBJECT (src, "getrange but not started");
2664 return GST_FLOW_FLUSHING;
2668 GST_DEBUG_OBJECT (src, "no create function");
2669 return GST_FLOW_NOT_SUPPORTED;
2673 GST_DEBUG_OBJECT (src, "unexpected length %u (offset=%" G_GUINT64_FORMAT
2674 ", size=%" G_GINT64_FORMAT ")", length, offset, src->segment.duration);
2675 return GST_FLOW_EOS;
2677 reached_num_buffers:
2679 GST_DEBUG_OBJECT (src, "sent all buffers");
2680 return GST_FLOW_EOS;
2684 GST_DEBUG_OBJECT (src, "we are flushing");
2687 #ifdef TIZEN_FEATURE_TRUSTZONE
2688 /*tzappsrc patch : release handle when unref res_buf*/
2689 GstBaseSrcClass *klass = GST_BASE_SRC_GET_CLASS(src);
2690 if(klass->tz_src_release_handle)
2692 GST_INFO_OBJECT (src, "tzappsrc release the handle");
2693 klass->tz_src_release_handle(src,res_buf);
2696 gst_buffer_unref (res_buf);
2698 return GST_FLOW_FLUSHING;
2702 GST_DEBUG_OBJECT (src, "we are EOS");
2703 return GST_FLOW_EOS;
2707 static GstFlowReturn
2708 gst_base_src_getrange (GstPad * pad, GstObject * parent, guint64 offset,
2709 guint length, GstBuffer ** buf)
2714 src = GST_BASE_SRC_CAST (parent);
2716 GST_LIVE_LOCK (src);
2717 if (G_UNLIKELY (src->priv->flushing))
2720 res = gst_base_src_get_range (src, offset, length, buf);
2723 GST_LIVE_UNLOCK (src);
2730 GST_DEBUG_OBJECT (src, "we are flushing");
2731 res = GST_FLOW_FLUSHING;
2737 gst_base_src_is_random_access (GstBaseSrc * src)
2739 /* we need to start the basesrc to check random access */
2740 if (!GST_BASE_SRC_IS_STARTED (src)) {
2741 GST_LOG_OBJECT (src, "doing start/stop to check get_range support");
2742 if (G_LIKELY (gst_base_src_start (src))) {
2743 if (gst_base_src_start_wait (src) != GST_FLOW_OK)
2745 gst_base_src_stop (src);
2749 return src->random_access;
2754 GST_DEBUG_OBJECT (src, "failed to start");
2760 gst_base_src_loop (GstPad * pad)
2763 GstBuffer *buf = NULL;
2768 GList *pending_events = NULL, *tmp;
2772 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
2774 /* Just leave immediately if we're flushing */
2775 GST_LIVE_LOCK (src);
2776 if (G_UNLIKELY (src->priv->flushing || GST_PAD_IS_FLUSHING (pad)))
2778 GST_LIVE_UNLOCK (src);
2780 gst_base_src_send_stream_start (src);
2782 /* The stream-start event could've caused something to flush us */
2783 GST_LIVE_LOCK (src);
2784 if (G_UNLIKELY (src->priv->flushing || GST_PAD_IS_FLUSHING (pad)))
2786 GST_LIVE_UNLOCK (src);
2788 /* check if we need to renegotiate */
2789 if (gst_pad_check_reconfigure (pad)) {
2790 if (!gst_base_src_negotiate (src)) {
2791 gst_pad_mark_reconfigure (pad);
2792 if (GST_PAD_IS_FLUSHING (pad)) {
2793 GST_LIVE_LOCK (src);
2796 goto negotiate_failed;
2801 GST_LIVE_LOCK (src);
2803 if (G_UNLIKELY (src->priv->flushing || GST_PAD_IS_FLUSHING (pad)))
2806 blocksize = src->blocksize;
2808 /* if we operate in bytes, we can calculate an offset */
2809 if (src->segment.format == GST_FORMAT_BYTES) {
2810 position = src->segment.position;
2811 /* for negative rates, start with subtracting the blocksize */
2812 if (src->segment.rate < 0.0) {
2813 /* we cannot go below segment.start */
2814 if (position > src->segment.start + blocksize)
2815 position -= blocksize;
2817 /* last block, remainder up to segment.start */
2818 blocksize = position - src->segment.start;
2819 position = src->segment.start;
2825 GST_LOG_OBJECT (src, "next_ts %" GST_TIME_FORMAT " size %u",
2826 GST_TIME_ARGS (position), blocksize);
2828 ret = gst_base_src_get_range (src, position, blocksize, &buf);
2829 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
2830 GST_INFO_OBJECT (src, "pausing after gst_base_src_get_range() = %s",
2831 gst_flow_get_name (ret));
2832 GST_LIVE_UNLOCK (src);
2835 /* this should not happen */
2836 if (G_UNLIKELY (buf == NULL))
2839 /* push events to close/start our segment before we push the buffer. */
2840 if (G_UNLIKELY (src->priv->segment_pending)) {
2841 GstEvent *seg_event = gst_event_new_segment (&src->segment);
2843 gst_event_set_seqnum (seg_event, src->priv->segment_seqnum);
2844 src->priv->segment_seqnum = gst_util_seqnum_next ();
2845 gst_pad_push_event (pad, seg_event);
2846 src->priv->segment_pending = FALSE;
2849 if (g_atomic_int_get (&src->priv->have_events)) {
2850 GST_OBJECT_LOCK (src);
2851 /* take the events */
2852 pending_events = src->priv->pending_events;
2853 src->priv->pending_events = NULL;
2854 g_atomic_int_set (&src->priv->have_events, FALSE);
2855 GST_OBJECT_UNLOCK (src);
2858 /* Push out pending events if any */
2859 if (G_UNLIKELY (pending_events != NULL)) {
2860 for (tmp = pending_events; tmp; tmp = g_list_next (tmp)) {
2861 GstEvent *ev = (GstEvent *) tmp->data;
2862 gst_pad_push_event (pad, ev);
2864 g_list_free (pending_events);
2867 /* figure out the new position */
2868 switch (src->segment.format) {
2869 case GST_FORMAT_BYTES:
2871 guint bufsize = gst_buffer_get_size (buf);
2873 /* we subtracted above for negative rates */
2874 if (src->segment.rate >= 0.0)
2875 position += bufsize;
2878 case GST_FORMAT_TIME:
2880 GstClockTime start, duration;
2882 start = GST_BUFFER_TIMESTAMP (buf);
2883 duration = GST_BUFFER_DURATION (buf);
2885 if (GST_CLOCK_TIME_IS_VALID (start))
2888 position = src->segment.position;
2890 if (GST_CLOCK_TIME_IS_VALID (duration)) {
2891 if (src->segment.rate >= 0.0)
2892 position += duration;
2893 else if (position > duration)
2894 position -= duration;
2900 case GST_FORMAT_DEFAULT:
2901 if (src->segment.rate >= 0.0)
2902 position = GST_BUFFER_OFFSET_END (buf);
2904 position = GST_BUFFER_OFFSET (buf);
2910 if (position != -1) {
2911 if (src->segment.rate >= 0.0) {
2912 /* positive rate, check if we reached the stop */
2913 if (src->segment.stop != -1) {
2914 if (position >= src->segment.stop) {
2916 position = src->segment.stop;
2920 /* negative rate, check if we reached the start. start is always set to
2921 * something different from -1 */
2922 if (position <= src->segment.start) {
2924 position = src->segment.start;
2926 /* when going reverse, all buffers are DISCONT */
2927 src->priv->discont = TRUE;
2929 GST_OBJECT_LOCK (src);
2930 src->segment.position = position;
2931 GST_OBJECT_UNLOCK (src);
2934 if (G_UNLIKELY (src->priv->discont)) {
2935 GST_INFO_OBJECT (src, "marking pending DISCONT");
2936 buf = gst_buffer_make_writable (buf);
2937 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
2938 src->priv->discont = FALSE;
2940 GST_LIVE_UNLOCK (src);
2942 ret = gst_pad_push (pad, buf);
2943 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
2944 #ifdef TIZEN_FEATURE_TRUSTZONE
2945 /*tzappsrc patch : release handle when unref res_buf*/
2946 GstBaseSrcClass *klass = GST_BASE_SRC_GET_CLASS(src);
2947 if(klass->tz_src_release_handle)
2949 GST_INFO_OBJECT (src, "tzappsrc release the handle");
2950 klass->tz_src_release_handle(src,buf);
2953 if (ret == GST_FLOW_NOT_NEGOTIATED) {
2954 goto not_negotiated;
2956 GST_INFO_OBJECT (src, "pausing after gst_pad_push() = %s",
2957 gst_flow_get_name (ret));
2961 /* Segment pending means that a new segment was configured
2962 * during this loop run */
2963 if (G_UNLIKELY (eos && !src->priv->segment_pending)) {
2964 GST_INFO_OBJECT (src, "pausing after end of segment");
2975 if (gst_pad_needs_reconfigure (pad)) {
2976 GST_DEBUG_OBJECT (src, "Retrying to renegotiate");
2979 /* fallthrough when push returns NOT_NEGOTIATED and we don't have
2980 * a pending negotiation request on our srcpad */
2984 GST_DEBUG_OBJECT (src, "Not negotiated");
2985 ret = GST_FLOW_NOT_NEGOTIATED;
2990 GST_DEBUG_OBJECT (src, "we are flushing");
2991 GST_LIVE_UNLOCK (src);
2992 ret = GST_FLOW_FLUSHING;
2997 const gchar *reason = gst_flow_get_name (ret);
3000 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
3001 src->running = FALSE;
3002 gst_pad_pause_task (pad);
3003 if (ret == GST_FLOW_EOS) {
3004 gboolean flag_segment;
3008 flag_segment = (src->segment.flags & GST_SEGMENT_FLAG_SEGMENT) != 0;
3009 format = src->segment.format;
3010 position = src->segment.position;
3012 /* perform EOS logic */
3013 if (src->priv->forced_eos) {
3014 g_assert (g_atomic_int_get (&src->priv->has_pending_eos));
3015 GST_OBJECT_LOCK (src);
3016 event = src->priv->pending_eos;
3017 src->priv->pending_eos = NULL;
3018 GST_OBJECT_UNLOCK (src);
3020 } else if (flag_segment) {
3021 GstMessage *message;
3023 message = gst_message_new_segment_done (GST_OBJECT_CAST (src),
3025 gst_message_set_seqnum (message, src->priv->seqnum);
3026 gst_element_post_message (GST_ELEMENT_CAST (src), message);
3027 event = gst_event_new_segment_done (format, position);
3028 gst_event_set_seqnum (event, src->priv->seqnum);
3031 event = gst_event_new_eos ();
3032 gst_event_set_seqnum (event, src->priv->seqnum);
3035 gst_pad_push_event (pad, event);
3036 src->priv->forced_eos = FALSE;
3038 } else if (ret == GST_FLOW_NOT_LINKED || ret <= GST_FLOW_EOS) {
3039 event = gst_event_new_eos ();
3040 gst_event_set_seqnum (event, src->priv->seqnum);
3041 /* for fatal errors we post an error message, post the error
3042 * first so the app knows about the error first.
3043 * Also don't do this for FLUSHING because it happens
3044 * due to flushing and posting an error message because of
3045 * that is the wrong thing to do, e.g. when we're doing
3046 * a flushing seek. */
3047 GST_ELEMENT_ERROR (src, STREAM, FAILED,
3048 (_("Internal data flow error.")),
3049 ("streaming task paused, reason %s (%d)", reason, ret));
3050 gst_pad_push_event (pad, event);
3056 GST_ELEMENT_ERROR (src, STREAM, FAILED,
3057 (_("Internal data flow error.")), ("element returned NULL buffer"));
3058 GST_LIVE_UNLOCK (src);
3064 gst_base_src_set_allocation (GstBaseSrc * basesrc, GstBufferPool * pool,
3065 GstAllocator * allocator, GstAllocationParams * params)
3067 GstAllocator *oldalloc;
3068 GstBufferPool *oldpool;
3069 GstBaseSrcPrivate *priv = basesrc->priv;
3072 GST_DEBUG_OBJECT (basesrc, "activate pool");
3073 if (!gst_buffer_pool_set_active (pool, TRUE))
3074 goto activate_failed;
3077 GST_OBJECT_LOCK (basesrc);
3078 oldpool = priv->pool;
3081 oldalloc = priv->allocator;
3082 priv->allocator = allocator;
3085 gst_object_ref (priv->pool);
3086 if (priv->allocator)
3087 gst_object_ref (priv->allocator);
3090 priv->params = *params;
3092 gst_allocation_params_init (&priv->params);
3093 GST_OBJECT_UNLOCK (basesrc);
3096 /* only deactivate if the pool is not the one we're using */
3097 if (oldpool != pool) {
3098 GST_DEBUG_OBJECT (basesrc, "deactivate old pool");
3099 gst_buffer_pool_set_active (oldpool, FALSE);
3101 gst_object_unref (oldpool);
3104 gst_object_unref (oldalloc);
3111 GST_ERROR_OBJECT (basesrc, "failed to activate bufferpool.");
3117 gst_base_src_activate_pool (GstBaseSrc * basesrc, gboolean active)
3119 GstBaseSrcPrivate *priv = basesrc->priv;
3120 GstBufferPool *pool;
3121 gboolean res = TRUE;
3123 GST_OBJECT_LOCK (basesrc);
3124 if ((pool = priv->pool))
3125 pool = gst_object_ref (pool);
3126 GST_OBJECT_UNLOCK (basesrc);
3129 res = gst_buffer_pool_set_active (pool, active);
3130 gst_object_unref (pool);
3137 gst_base_src_decide_allocation_default (GstBaseSrc * basesrc, GstQuery * query)
3140 GstBufferPool *pool;
3141 guint size, min, max;
3142 GstAllocator *allocator;
3143 GstAllocationParams params;
3144 GstStructure *config;
3145 gboolean update_allocator;
3147 gst_query_parse_allocation (query, &outcaps, NULL);
3149 /* we got configuration from our peer or the decide_allocation method,
3151 if (gst_query_get_n_allocation_params (query) > 0) {
3152 /* try the allocator */
3153 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
3154 update_allocator = TRUE;
3157 gst_allocation_params_init (¶ms);
3158 update_allocator = FALSE;
3161 if (gst_query_get_n_allocation_pools (query) > 0) {
3162 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
3165 /* no pool, we can make our own */
3166 GST_DEBUG_OBJECT (basesrc, "no pool, making new pool");
3167 pool = gst_buffer_pool_new ();
3171 size = min = max = 0;
3176 config = gst_buffer_pool_get_config (pool);
3177 gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
3178 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
3180 /* buffer pool may have to do some changes */
3181 if (!gst_buffer_pool_set_config (pool, config)) {
3182 config = gst_buffer_pool_get_config (pool);
3184 /* If change are not acceptable, fallback to generic pool */
3185 if (!gst_buffer_pool_config_validate_params (config, outcaps, size, min,
3187 GST_DEBUG_OBJECT (basesrc, "unsupported pool, making new pool");
3189 gst_object_unref (pool);
3190 pool = gst_buffer_pool_new ();
3191 gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
3192 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
3195 if (!gst_buffer_pool_set_config (pool, config))
3200 if (update_allocator)
3201 gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms);
3203 gst_query_add_allocation_param (query, allocator, ¶ms);
3205 gst_object_unref (allocator);
3208 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
3209 gst_object_unref (pool);
3215 GST_ELEMENT_ERROR (basesrc, RESOURCE, SETTINGS,
3216 ("Failed to configure the buffer pool"),
3217 ("Configuration is most likely invalid, please report this issue."));
3218 gst_object_unref (pool);
3223 gst_base_src_prepare_allocation (GstBaseSrc * basesrc, GstCaps * caps)
3225 GstBaseSrcClass *bclass;
3226 gboolean result = TRUE;
3228 GstBufferPool *pool = NULL;
3229 GstAllocator *allocator = NULL;
3230 GstAllocationParams params;
3232 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
3234 /* make query and let peer pad answer, we don't really care if it worked or
3235 * not, if it failed, the allocation query would contain defaults and the
3236 * subclass would then set better values if needed */
3237 query = gst_query_new_allocation (caps, TRUE);
3238 if (!gst_pad_peer_query (basesrc->srcpad, query)) {
3239 /* not a problem, just debug a little */
3240 GST_DEBUG_OBJECT (basesrc, "peer ALLOCATION query failed");
3243 g_assert (bclass->decide_allocation != NULL);
3244 result = bclass->decide_allocation (basesrc, query);
3246 GST_DEBUG_OBJECT (basesrc, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, result,
3250 goto no_decide_allocation;
3252 /* we got configuration from our peer or the decide_allocation method,
3254 if (gst_query_get_n_allocation_params (query) > 0) {
3255 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
3258 gst_allocation_params_init (¶ms);
3261 if (gst_query_get_n_allocation_pools (query) > 0)
3262 gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
3264 result = gst_base_src_set_allocation (basesrc, pool, allocator, ¶ms);
3267 gst_object_unref (allocator);
3269 gst_object_unref (pool);
3271 gst_query_unref (query);
3276 no_decide_allocation:
3278 GST_WARNING_OBJECT (basesrc, "Subclass failed to decide allocation");
3279 gst_query_unref (query);
3285 /* default negotiation code.
3287 * Take intersection between src and sink pads, take first
3291 gst_base_src_default_negotiate (GstBaseSrc * basesrc)
3294 GstCaps *caps = NULL;
3295 GstCaps *peercaps = NULL;
3296 gboolean result = FALSE;
3298 /* first see what is possible on our source pad */
3299 thiscaps = gst_pad_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
3300 GST_DEBUG_OBJECT (basesrc, "caps of src: %" GST_PTR_FORMAT, thiscaps);
3301 /* nothing or anything is allowed, we're done */
3302 if (thiscaps == NULL || gst_caps_is_any (thiscaps))
3303 goto no_nego_needed;
3305 if (G_UNLIKELY (gst_caps_is_empty (thiscaps)))
3308 /* get the peer caps */
3309 peercaps = gst_pad_peer_query_caps (GST_BASE_SRC_PAD (basesrc), thiscaps);
3310 GST_DEBUG_OBJECT (basesrc, "caps of peer: %" GST_PTR_FORMAT, peercaps);
3312 /* The result is already a subset of our caps */
3314 gst_caps_unref (thiscaps);
3316 /* no peer, work with our own caps then */
3319 if (caps && !gst_caps_is_empty (caps)) {
3321 GST_DEBUG_OBJECT (basesrc, "have caps: %" GST_PTR_FORMAT, caps);
3322 if (gst_caps_is_any (caps)) {
3323 GST_DEBUG_OBJECT (basesrc, "any caps, we stop");
3324 /* hmm, still anything, so element can do anything and
3325 * nego is not needed */
3328 caps = gst_base_src_fixate (basesrc, caps);
3329 GST_DEBUG_OBJECT (basesrc, "fixated to: %" GST_PTR_FORMAT, caps);
3330 if (gst_caps_is_fixed (caps)) {
3331 /* yay, fixed caps, use those then, it's possible that the subclass does
3332 * not accept this caps after all and we have to fail. */
3333 result = gst_base_src_set_caps (basesrc, caps);
3336 gst_caps_unref (caps);
3339 gst_caps_unref (caps);
3340 GST_DEBUG_OBJECT (basesrc, "no common caps");
3346 GST_DEBUG_OBJECT (basesrc, "no negotiation needed");
3348 gst_caps_unref (thiscaps);
3353 GST_ELEMENT_ERROR (basesrc, STREAM, FORMAT,
3354 ("No supported formats found"),
3355 ("This element did not produce valid caps"));
3357 gst_caps_unref (thiscaps);
3363 gst_base_src_negotiate (GstBaseSrc * basesrc)
3365 GstBaseSrcClass *bclass;
3368 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
3370 GST_DEBUG_OBJECT (basesrc, "starting negotiation");
3372 if (G_LIKELY (bclass->negotiate))
3373 result = bclass->negotiate (basesrc);
3377 if (G_LIKELY (result)) {
3380 caps = gst_pad_get_current_caps (basesrc->srcpad);
3382 result = gst_base_src_prepare_allocation (basesrc, caps);
3385 gst_caps_unref (caps);
3391 gst_base_src_start (GstBaseSrc * basesrc)
3393 GstBaseSrcClass *bclass;
3396 GST_LIVE_LOCK (basesrc);
3398 GST_OBJECT_LOCK (basesrc);
3399 if (GST_BASE_SRC_IS_STARTING (basesrc))
3401 if (GST_BASE_SRC_IS_STARTED (basesrc))
3404 basesrc->priv->start_result = GST_FLOW_FLUSHING;
3405 GST_OBJECT_FLAG_SET (basesrc, GST_BASE_SRC_FLAG_STARTING);
3406 gst_segment_init (&basesrc->segment, basesrc->segment.format);
3407 GST_OBJECT_UNLOCK (basesrc);
3409 basesrc->num_buffers_left = basesrc->num_buffers;
3410 basesrc->running = FALSE;
3411 basesrc->priv->segment_pending = FALSE;
3412 basesrc->priv->segment_seqnum = gst_util_seqnum_next ();
3413 basesrc->priv->forced_eos = FALSE;
3414 GST_LIVE_UNLOCK (basesrc);
3416 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
3418 result = bclass->start (basesrc);
3423 goto could_not_start;
3425 if (!gst_base_src_is_async (basesrc)) {
3426 gst_base_src_start_complete (basesrc, GST_FLOW_OK);
3427 /* not really waiting here, we call this to get the result
3428 * from the start_complete call */
3429 result = gst_base_src_start_wait (basesrc) == GST_FLOW_OK;
3437 GST_DEBUG_OBJECT (basesrc, "was starting");
3438 GST_OBJECT_UNLOCK (basesrc);
3439 GST_LIVE_UNLOCK (basesrc);
3444 GST_DEBUG_OBJECT (basesrc, "was started");
3445 GST_OBJECT_UNLOCK (basesrc);
3446 GST_LIVE_UNLOCK (basesrc);
3451 GST_DEBUG_OBJECT (basesrc, "could not start");
3452 /* subclass is supposed to post a message. We don't have to call _stop. */
3453 gst_base_src_start_complete (basesrc, GST_FLOW_ERROR);
3459 * gst_base_src_start_complete:
3460 * @basesrc: base source instance
3461 * @ret: a #GstFlowReturn
3463 * Complete an asynchronous start operation. When the subclass overrides the
3464 * start method, it should call gst_base_src_start_complete() when the start
3465 * operation completes either from the same thread or from an asynchronous
3469 gst_base_src_start_complete (GstBaseSrc * basesrc, GstFlowReturn ret)
3478 if (ret != GST_FLOW_OK)
3481 GST_DEBUG_OBJECT (basesrc, "starting source");
3482 format = basesrc->segment.format;
3484 /* figure out the size */
3487 if (format == GST_FORMAT_BYTES) {
3488 GstBaseSrcClass *bclass = GST_BASE_SRC_GET_CLASS (basesrc);
3490 if (bclass->get_size) {
3491 if (!(have_size = bclass->get_size (basesrc, &size)))
3494 GST_DEBUG_OBJECT (basesrc, "setting size %" G_GUINT64_FORMAT, size);
3495 /* only update the size when operating in bytes, subclass is supposed
3496 * to set duration in the start method for other formats */
3497 GST_OBJECT_LOCK (basesrc);
3498 basesrc->segment.duration = size;
3499 GST_OBJECT_UNLOCK (basesrc);
3502 GST_DEBUG_OBJECT (basesrc,
3503 "format: %s, have size: %d, size: %" G_GUINT64_FORMAT ", duration: %"
3504 G_GINT64_FORMAT, gst_format_get_name (format), have_size, size,
3505 basesrc->segment.duration);
3507 seekable = gst_base_src_seekable (basesrc);
3508 GST_DEBUG_OBJECT (basesrc, "is seekable: %d", seekable);
3510 /* update for random access flag */
3511 basesrc->random_access = seekable && format == GST_FORMAT_BYTES;
3513 GST_DEBUG_OBJECT (basesrc, "is random_access: %d", basesrc->random_access);
3515 /* stop flushing now but for live sources, still block in the LIVE lock when
3516 * we are not yet PLAYING */
3517 gst_base_src_set_flushing (basesrc, FALSE, FALSE, NULL);
3519 gst_pad_mark_reconfigure (GST_BASE_SRC_PAD (basesrc));
3521 GST_OBJECT_LOCK (basesrc->srcpad);
3522 mode = GST_PAD_MODE (basesrc->srcpad);
3523 GST_OBJECT_UNLOCK (basesrc->srcpad);
3525 /* take the stream lock here, we only want to let the task run when we have
3526 * set the STARTED flag */
3527 GST_PAD_STREAM_LOCK (basesrc->srcpad);
3529 case GST_PAD_MODE_PUSH:
3530 /* do initial seek, which will start the task */
3531 GST_OBJECT_LOCK (basesrc);
3532 event = basesrc->pending_seek;
3533 basesrc->pending_seek = NULL;
3534 GST_OBJECT_UNLOCK (basesrc);
3536 /* The perform seek code will start the task when finished. We don't have to
3537 * unlock the streaming thread because it is not running yet */
3538 if (G_UNLIKELY (!gst_base_src_perform_seek (basesrc, event, FALSE)))
3542 gst_event_unref (event);
3544 case GST_PAD_MODE_PULL:
3545 /* if not random_access, we cannot operate in pull mode for now */
3546 if (G_UNLIKELY (!basesrc->random_access))
3550 goto not_activated_yet;
3554 GST_OBJECT_LOCK (basesrc);
3555 GST_OBJECT_FLAG_SET (basesrc, GST_BASE_SRC_FLAG_STARTED);
3556 GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTING);
3557 basesrc->priv->start_result = ret;
3558 GST_ASYNC_SIGNAL (basesrc);
3559 GST_OBJECT_UNLOCK (basesrc);
3561 GST_PAD_STREAM_UNLOCK (basesrc->srcpad);
3567 GST_PAD_STREAM_UNLOCK (basesrc->srcpad);
3568 GST_ERROR_OBJECT (basesrc, "Failed to perform initial seek");
3569 gst_base_src_stop (basesrc);
3571 gst_event_unref (event);
3572 ret = GST_FLOW_ERROR;
3577 GST_PAD_STREAM_UNLOCK (basesrc->srcpad);
3578 gst_base_src_stop (basesrc);
3579 GST_ERROR_OBJECT (basesrc, "Cannot operate in pull mode, stopping");
3580 ret = GST_FLOW_ERROR;
3585 GST_PAD_STREAM_UNLOCK (basesrc->srcpad);
3586 gst_base_src_stop (basesrc);
3587 GST_WARNING_OBJECT (basesrc, "pad not activated yet");
3588 ret = GST_FLOW_ERROR;
3593 GST_OBJECT_LOCK (basesrc);
3594 basesrc->priv->start_result = ret;
3595 GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTING);
3596 GST_ASYNC_SIGNAL (basesrc);
3597 GST_OBJECT_UNLOCK (basesrc);
3603 * gst_base_src_start_wait:
3604 * @basesrc: base source instance
3606 * Wait until the start operation completes.
3608 * Returns: a #GstFlowReturn.
3611 gst_base_src_start_wait (GstBaseSrc * basesrc)
3613 GstFlowReturn result;
3615 GST_OBJECT_LOCK (basesrc);
3616 while (GST_BASE_SRC_IS_STARTING (basesrc)) {
3617 GST_ASYNC_WAIT (basesrc);
3619 result = basesrc->priv->start_result;
3620 GST_OBJECT_UNLOCK (basesrc);
3622 GST_DEBUG_OBJECT (basesrc, "got %s", gst_flow_get_name (result));
3628 gst_base_src_stop (GstBaseSrc * basesrc)
3630 GstBaseSrcClass *bclass;
3631 gboolean result = TRUE;
3633 GST_DEBUG_OBJECT (basesrc, "stopping source");
3636 gst_base_src_set_flushing (basesrc, TRUE, FALSE, NULL);
3638 gst_pad_stop_task (basesrc->srcpad);
3640 GST_OBJECT_LOCK (basesrc);
3641 if (!GST_BASE_SRC_IS_STARTED (basesrc) && !GST_BASE_SRC_IS_STARTING (basesrc))
3644 GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTING);
3645 GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTED);
3646 basesrc->priv->start_result = GST_FLOW_FLUSHING;
3647 GST_ASYNC_SIGNAL (basesrc);
3648 GST_OBJECT_UNLOCK (basesrc);
3650 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
3652 result = bclass->stop (basesrc);
3654 gst_base_src_set_allocation (basesrc, NULL, NULL, NULL);
3660 GST_DEBUG_OBJECT (basesrc, "was stopped");
3661 GST_OBJECT_UNLOCK (basesrc);
3666 /* start or stop flushing dataprocessing
3669 gst_base_src_set_flushing (GstBaseSrc * basesrc,
3670 gboolean flushing, gboolean live_play, gboolean * playing)
3672 GstBaseSrcClass *bclass;
3674 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
3676 GST_DEBUG_OBJECT (basesrc, "flushing %d, live_play %d", flushing, live_play);
3679 gst_base_src_activate_pool (basesrc, FALSE);
3680 /* unlock any subclasses, we need to do this before grabbing the
3681 * LIVE_LOCK since we hold this lock before going into ::create. We pass an
3682 * unlock to the params because of backwards compat (see seek handler)*/
3684 bclass->unlock (basesrc);
3687 /* the live lock is released when we are blocked, waiting for playing or
3688 * when we sync to the clock. */
3689 GST_LIVE_LOCK (basesrc);
3691 *playing = basesrc->live_running;
3692 basesrc->priv->flushing = flushing;
3694 /* if we are locked in the live lock, signal it to make it flush */
3695 basesrc->live_running = TRUE;
3697 /* clear pending EOS if any */
3698 if (g_atomic_int_get (&basesrc->priv->has_pending_eos)) {
3699 GST_OBJECT_LOCK (basesrc);
3700 CLEAR_PENDING_EOS (basesrc);
3701 basesrc->priv->forced_eos = FALSE;
3702 GST_OBJECT_UNLOCK (basesrc);
3705 /* step 1, now that we have the LIVE lock, clear our unlock request */
3706 if (bclass->unlock_stop)
3707 bclass->unlock_stop (basesrc);
3709 /* step 2, unblock clock sync (if any) or any other blocking thing */
3710 if (basesrc->clock_id)
3711 gst_clock_id_unschedule (basesrc->clock_id);
3713 /* signal the live source that it can start playing */
3714 basesrc->live_running = live_play;
3716 gst_base_src_activate_pool (basesrc, TRUE);
3718 /* Drop all delayed events */
3719 GST_OBJECT_LOCK (basesrc);
3720 if (basesrc->priv->pending_events) {
3721 g_list_foreach (basesrc->priv->pending_events, (GFunc) gst_event_unref,
3723 g_list_free (basesrc->priv->pending_events);
3724 basesrc->priv->pending_events = NULL;
3725 g_atomic_int_set (&basesrc->priv->have_events, FALSE);
3727 GST_OBJECT_UNLOCK (basesrc);
3729 GST_LIVE_SIGNAL (basesrc);
3730 GST_LIVE_UNLOCK (basesrc);
3735 /* the purpose of this function is to make sure that a live source blocks in the
3736 * LIVE lock or leaves the LIVE lock and continues playing. */
3738 gst_base_src_set_playing (GstBaseSrc * basesrc, gboolean live_play)
3740 GstBaseSrcClass *bclass;
3742 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
3744 /* unlock subclasses locked in ::create, we only do this when we stop playing. */
3746 GST_DEBUG_OBJECT (basesrc, "unlock");
3748 bclass->unlock (basesrc);
3751 /* we are now able to grab the LIVE lock, when we get it, we can be
3752 * waiting for PLAYING while blocked in the LIVE cond or we can be waiting
3754 GST_LIVE_LOCK (basesrc);
3755 GST_DEBUG_OBJECT (basesrc, "unschedule clock");
3757 /* unblock clock sync (if any) */
3758 if (basesrc->clock_id)
3759 gst_clock_id_unschedule (basesrc->clock_id);
3761 /* configure what to do when we get to the LIVE lock. */
3762 GST_DEBUG_OBJECT (basesrc, "live running %d", live_play);
3763 basesrc->live_running = live_play;
3768 /* clear our unlock request when going to PLAYING */
3769 GST_DEBUG_OBJECT (basesrc, "unlock stop");
3770 if (bclass->unlock_stop)
3771 bclass->unlock_stop (basesrc);
3773 /* for live sources we restart the timestamp correction */
3774 basesrc->priv->latency = -1;
3775 /* have to restart the task in case it stopped because of the unlock when
3776 * we went to PAUSED. Only do this if we operating in push mode. */
3777 GST_OBJECT_LOCK (basesrc->srcpad);
3778 start = (GST_PAD_MODE (basesrc->srcpad) == GST_PAD_MODE_PUSH);
3779 GST_OBJECT_UNLOCK (basesrc->srcpad);
3781 gst_pad_start_task (basesrc->srcpad, (GstTaskFunction) gst_base_src_loop,
3782 basesrc->srcpad, NULL);
3783 GST_DEBUG_OBJECT (basesrc, "signal");
3784 GST_LIVE_SIGNAL (basesrc);
3786 GST_LIVE_UNLOCK (basesrc);
3792 gst_base_src_activate_push (GstPad * pad, GstObject * parent, gboolean active)
3794 GstBaseSrc *basesrc;
3796 basesrc = GST_BASE_SRC (parent);
3798 /* prepare subclass first */
3800 GST_DEBUG_OBJECT (basesrc, "Activating in push mode");
3802 if (G_UNLIKELY (!basesrc->can_activate_push))
3803 goto no_push_activation;
3805 if (G_UNLIKELY (!gst_base_src_start (basesrc)))
3808 GST_DEBUG_OBJECT (basesrc, "Deactivating in push mode");
3809 /* now we can stop the source */
3810 if (G_UNLIKELY (!gst_base_src_stop (basesrc)))
3818 GST_WARNING_OBJECT (basesrc, "Subclass disabled push-mode activation");
3823 GST_WARNING_OBJECT (basesrc, "Failed to start in push mode");
3828 GST_DEBUG_OBJECT (basesrc, "Failed to stop in push mode");
3834 gst_base_src_activate_pull (GstPad * pad, GstObject * parent, gboolean active)
3836 GstBaseSrc *basesrc;
3838 basesrc = GST_BASE_SRC (parent);
3840 /* prepare subclass first */
3842 GST_DEBUG_OBJECT (basesrc, "Activating in pull mode");
3843 if (G_UNLIKELY (!gst_base_src_start (basesrc)))
3846 GST_DEBUG_OBJECT (basesrc, "Deactivating in pull mode");
3847 if (G_UNLIKELY (!gst_base_src_stop (basesrc)))
3855 GST_ERROR_OBJECT (basesrc, "Failed to start in pull mode");
3860 GST_ERROR_OBJECT (basesrc, "Failed to stop in pull mode");
3866 gst_base_src_activate_mode (GstPad * pad, GstObject * parent,
3867 GstPadMode mode, gboolean active)
3870 GstBaseSrc *src = GST_BASE_SRC (parent);
3872 src->priv->stream_start_pending = FALSE;
3874 GST_DEBUG_OBJECT (pad, "activating in mode %d", mode);
3877 case GST_PAD_MODE_PULL:
3878 res = gst_base_src_activate_pull (pad, parent, active);
3880 case GST_PAD_MODE_PUSH:
3881 src->priv->stream_start_pending = active;
3882 res = gst_base_src_activate_push (pad, parent, active);
3885 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
3893 static GstStateChangeReturn
3894 gst_base_src_change_state (GstElement * element, GstStateChange transition)
3896 GstBaseSrc *basesrc;
3897 GstStateChangeReturn result;
3898 gboolean no_preroll = FALSE;
3900 basesrc = GST_BASE_SRC (element);
3902 switch (transition) {
3903 case GST_STATE_CHANGE_NULL_TO_READY:
3905 case GST_STATE_CHANGE_READY_TO_PAUSED:
3906 no_preroll = gst_base_src_is_live (basesrc);
3908 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
3909 GST_DEBUG_OBJECT (basesrc, "PAUSED->PLAYING");
3910 if (gst_base_src_is_live (basesrc)) {
3911 /* now we can start playback */
3912 gst_base_src_set_playing (basesrc, TRUE);
3920 GST_ELEMENT_CLASS (parent_class)->change_state (element,
3921 transition)) == GST_STATE_CHANGE_FAILURE)
3924 switch (transition) {
3925 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3926 GST_DEBUG_OBJECT (basesrc, "PLAYING->PAUSED");
3927 if (gst_base_src_is_live (basesrc)) {
3928 /* make sure we block in the live lock in PAUSED */
3929 gst_base_src_set_playing (basesrc, FALSE);
3933 case GST_STATE_CHANGE_PAUSED_TO_READY:
3935 /* we don't need to unblock anything here, the pad deactivation code
3936 * already did this */
3937 if (g_atomic_int_get (&basesrc->priv->has_pending_eos)) {
3938 GST_OBJECT_LOCK (basesrc);
3939 CLEAR_PENDING_EOS (basesrc);
3940 GST_OBJECT_UNLOCK (basesrc);
3942 gst_event_replace (&basesrc->pending_seek, NULL);
3945 case GST_STATE_CHANGE_READY_TO_NULL:
3951 if (no_preroll && result == GST_STATE_CHANGE_SUCCESS)
3952 result = GST_STATE_CHANGE_NO_PREROLL;
3959 GST_DEBUG_OBJECT (basesrc, "parent failed state change");
3965 * gst_base_src_get_buffer_pool:
3966 * @src: a #GstBaseSrc
3968 * Returns: (transfer full): the instance of the #GstBufferPool used
3969 * by the src; unref it after usage.
3972 gst_base_src_get_buffer_pool (GstBaseSrc * src)
3974 g_return_val_if_fail (GST_IS_BASE_SRC (src), NULL);
3976 if (src->priv->pool)
3977 return gst_object_ref (src->priv->pool);
3983 * gst_base_src_get_allocator:
3984 * @src: a #GstBaseSrc
3985 * @allocator: (out) (allow-none) (transfer full): the #GstAllocator
3987 * @params: (out) (allow-none) (transfer full): the
3988 * #GstAllocationParams of @allocator
3990 * Lets #GstBaseSrc sub-classes to know the memory @allocator
3991 * used by the base class and its @params.
3993 * Unref the @allocator after usage.
3996 gst_base_src_get_allocator (GstBaseSrc * src,
3997 GstAllocator ** allocator, GstAllocationParams * params)
3999 g_return_if_fail (GST_IS_BASE_SRC (src));
4002 *allocator = src->priv->allocator ?
4003 gst_object_ref (src->priv->allocator) : NULL;
4006 *params = src->priv->params;