2 * Copyright (C) 2007 David Schleef <ds@schleef.org>
3 * (C) 2008 Wim Taymans <wim.taymans@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:element-appsrc
24 * The appsrc element can be used by applications to insert data into a
25 * GStreamer pipeline. Unlike most GStreamer elements, Appsrc provides
26 * external API functions.
28 * For the documentation of the API, please see the
29 * <link linkend="gst-plugins-base-libs-appsrc">libgstapp</link> section in the
30 * GStreamer Plugins Base Libraries documentation.
37 * @short_description: Easy way for applications to inject buffers into a
39 * @see_also: #GstBaseSrc, appsink
41 * The appsrc element can be used by applications to insert data into a
42 * GStreamer pipeline. Unlike most GStreamer elements, Appsrc provides
43 * external API functions.
45 * appsrc can be used by linking with the libgstapp library to access the
46 * methods directly or by using the appsrc action signals.
48 * Before operating appsrc, the caps property must be set to a fixed caps
49 * describing the format of the data that will be pushed with appsrc. An
50 * exception to this is when pushing buffers with unknown caps, in which case no
51 * caps should be set. This is typically true of file-like sources that push raw
54 * The main way of handing data to the appsrc element is by calling the
55 * gst_app_src_push_buffer() method or by emiting the push-buffer action signal.
56 * This will put the buffer onto a queue from which appsrc will read from in its
57 * streaming thread. It is important to note that data transport will not happen
58 * from the thread that performed the push-buffer call.
60 * The "max-bytes" property controls how much data can be queued in appsrc
61 * before appsrc considers the queue full. A filled internal queue will always
62 * signal the "enough-data" signal, which signals the application that it should
63 * stop pushing data into appsrc. The "block" property will cause appsrc to
64 * block the push-buffer method until free data becomes available again.
66 * When the internal queue is running out of data, the "need-data" signal is
67 * emited, which signals the application that it should start pushing more data
70 * In addition to the "need-data" and "enough-data" signals, appsrc can emit the
71 * "seek-data" signal when the "stream-mode" property is set to "seekable" or
72 * "random-access". The signal argument will contain the new desired position in
73 * the stream expressed in the unit set with the "format" property. After
74 * receiving the seek-data signal, the application should push-buffers from the
77 * These signals allow the application to operate the appsrc in two different
80 * The push model, in which the application repeadedly calls the push-buffer method
81 * with a new buffer. Optionally, the queue size in the appsrc can be controlled
82 * with the enough-data and need-data signals by respectively stopping/starting
83 * the push-buffer calls. This is a typical mode of operation for the
84 * stream-type "stream" and "seekable". Use this model when implementing various
85 * network protocols or hardware devices.
87 * The pull model where the need-data signal triggers the next push-buffer call.
88 * This mode is typically used in the "random-access" stream-type. Use this
89 * model for file access or other randomly accessable sources. In this mode, a
90 * buffer of exactly the amount of bytes given by the need-data signal should be
93 * In all modes, the size property on appsrc should contain the total stream
94 * size in bytes. Setting this property is mandatory in the random-access mode.
95 * For the stream and seekable modes, setting this property is optional but
98 * When the application is finished pushing data into appsrc, it should call
99 * gst_app_src_end_of_stream() or emit the end-of-stream action signal. After
100 * this call, no more buffers can be pushed into appsrc until a flushing seek
101 * happened or the state of the appsrc has gone through READY.
103 * Last reviewed on 2008-12-17 (0.10.10)
113 #include <gst/base/gstbasesrc.h>
117 #include "gstapp-marshal.h"
118 #include "gstappsrc.h"
120 struct _GstAppSrcPrivate
128 GstAppStreamType stream_type;
136 guint64 queued_bytes;
138 GstAppStreamType current_type;
142 gboolean emit_signals;
145 GstAppSrcCallbacks callbacks;
147 GDestroyNotify notify;
150 GST_DEBUG_CATEGORY_STATIC (app_src_debug);
151 #define GST_CAT_DEFAULT app_src_debug
162 SIGNAL_END_OF_STREAM,
167 #define DEFAULT_PROP_SIZE -1
168 #define DEFAULT_PROP_STREAM_TYPE GST_APP_STREAM_TYPE_STREAM
169 #define DEFAULT_PROP_MAX_BYTES 200000
170 #define DEFAULT_PROP_FORMAT GST_FORMAT_BYTES
171 #define DEFAULT_PROP_BLOCK FALSE
172 #define DEFAULT_PROP_IS_LIVE FALSE
173 #define DEFAULT_PROP_MIN_LATENCY -1
174 #define DEFAULT_PROP_MAX_LATENCY -1
175 #define DEFAULT_PROP_EMIT_SIGNALS TRUE
176 #define DEFAULT_PROP_MIN_PERCENT 0
195 static GstStaticPadTemplate gst_app_src_template =
196 GST_STATIC_PAD_TEMPLATE ("src",
199 GST_STATIC_CAPS_ANY);
202 gst_app_stream_type_get_type (void)
204 static volatile gsize stream_type_type = 0;
205 static const GEnumValue stream_type[] = {
206 {GST_APP_STREAM_TYPE_STREAM, "GST_APP_STREAM_TYPE_STREAM", "stream"},
207 {GST_APP_STREAM_TYPE_SEEKABLE, "GST_APP_STREAM_TYPE_SEEKABLE", "seekable"},
208 {GST_APP_STREAM_TYPE_RANDOM_ACCESS, "GST_APP_STREAM_TYPE_RANDOM_ACCESS",
213 if (g_once_init_enter (&stream_type_type)) {
214 GType tmp = g_enum_register_static ("GstAppStreamType", stream_type);
215 g_once_init_leave (&stream_type_type, tmp);
218 return (GType) stream_type_type;
221 static void gst_app_src_uri_handler_init (gpointer g_iface,
222 gpointer iface_data);
224 static void gst_app_src_dispose (GObject * object);
225 static void gst_app_src_finalize (GObject * object);
227 static void gst_app_src_set_property (GObject * object, guint prop_id,
228 const GValue * value, GParamSpec * pspec);
229 static void gst_app_src_get_property (GObject * object, guint prop_id,
230 GValue * value, GParamSpec * pspec);
232 static void gst_app_src_set_latencies (GstAppSrc * appsrc,
233 gboolean do_min, guint64 min, gboolean do_max, guint64 max);
235 static GstFlowReturn gst_app_src_create (GstBaseSrc * bsrc,
236 guint64 offset, guint size, GstBuffer ** buf);
237 static gboolean gst_app_src_start (GstBaseSrc * bsrc);
238 static gboolean gst_app_src_stop (GstBaseSrc * bsrc);
239 static gboolean gst_app_src_unlock (GstBaseSrc * bsrc);
240 static gboolean gst_app_src_unlock_stop (GstBaseSrc * bsrc);
241 static gboolean gst_app_src_do_seek (GstBaseSrc * src, GstSegment * segment);
242 static gboolean gst_app_src_is_seekable (GstBaseSrc * src);
243 static gboolean gst_app_src_check_get_range (GstBaseSrc * src);
244 static gboolean gst_app_src_do_get_size (GstBaseSrc * src, guint64 * size);
245 static gboolean gst_app_src_query (GstBaseSrc * src, GstQuery * query);
247 static GstFlowReturn gst_app_src_push_buffer_action (GstAppSrc * appsrc,
250 static guint gst_app_src_signals[LAST_SIGNAL] = { 0 };
253 _do_init (GType filesrc_type)
255 static const GInterfaceInfo urihandler_info = {
256 gst_app_src_uri_handler_init,
260 g_type_add_interface_static (filesrc_type, GST_TYPE_URI_HANDLER,
264 GST_BOILERPLATE_FULL (GstAppSrc, gst_app_src, GstBaseSrc, GST_TYPE_BASE_SRC,
268 gst_app_src_base_init (gpointer g_class)
270 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
272 GST_DEBUG_CATEGORY_INIT (app_src_debug, "appsrc", 0, "appsrc element");
274 gst_element_class_set_details_simple (element_class, "AppSrc",
275 "Generic/Source", "Allow the application to feed buffers to a pipeline",
276 "David Schleef <ds@schleef.org>, Wim Taymans <wim.taymans@gmail.com>");
278 gst_element_class_add_pad_template (element_class,
279 gst_static_pad_template_get (&gst_app_src_template));
283 gst_app_src_class_init (GstAppSrcClass * klass)
285 GObjectClass *gobject_class = (GObjectClass *) klass;
286 GstBaseSrcClass *basesrc_class = (GstBaseSrcClass *) klass;
288 gobject_class->dispose = gst_app_src_dispose;
289 gobject_class->finalize = gst_app_src_finalize;
291 gobject_class->set_property = gst_app_src_set_property;
292 gobject_class->get_property = gst_app_src_get_property;
297 * The GstCaps that will negotiated downstream and will be put
298 * on outgoing buffers.
300 g_object_class_install_property (gobject_class, PROP_CAPS,
301 g_param_spec_boxed ("caps", "Caps",
302 "The allowed caps for the src pad", GST_TYPE_CAPS,
303 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
307 * The format to use for segment events. When the source is producing
308 * timestamped buffers this property should be set to GST_FORMAT_TIME.
310 g_object_class_install_property (gobject_class, PROP_FORMAT,
311 g_param_spec_enum ("format", "Format",
312 "The format of the segment events and seek", GST_TYPE_FORMAT,
313 DEFAULT_PROP_FORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
317 * The total size in bytes of the data stream. If the total size is known, it
318 * is recommended to configure it with this property.
320 g_object_class_install_property (gobject_class, PROP_SIZE,
321 g_param_spec_int64 ("size", "Size",
322 "The size of the data stream in bytes (-1 if unknown)",
323 -1, G_MAXINT64, DEFAULT_PROP_SIZE,
324 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
326 * GstAppSrc::stream-type
328 * The type of stream that this source is producing. For seekable streams the
329 * application should connect to the seek-data signal.
331 g_object_class_install_property (gobject_class, PROP_STREAM_TYPE,
332 g_param_spec_enum ("stream-type", "Stream Type",
333 "the type of the stream", GST_TYPE_APP_STREAM_TYPE,
334 DEFAULT_PROP_STREAM_TYPE,
335 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
337 * GstAppSrc::max-bytes
339 * The maximum amount of bytes that can be queued internally.
340 * After the maximum amount of bytes are queued, appsrc will emit the
341 * "enough-data" signal.
343 g_object_class_install_property (gobject_class, PROP_MAX_BYTES,
344 g_param_spec_uint64 ("max-bytes", "Max bytes",
345 "The maximum number of bytes to queue internally (0 = unlimited)",
346 0, G_MAXUINT64, DEFAULT_PROP_MAX_BYTES,
347 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
351 * When max-bytes are queued and after the enough-data signal has been emited,
352 * block any further push-buffer calls until the amount of queued bytes drops
353 * below the max-bytes limit.
355 g_object_class_install_property (gobject_class, PROP_BLOCK,
356 g_param_spec_boolean ("block", "Block",
357 "Block push-buffer when max-bytes are queued",
358 DEFAULT_PROP_BLOCK, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
363 * Instruct the source to behave like a live source. This includes that it
364 * will only push out buffers in the PLAYING state.
366 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
367 g_param_spec_boolean ("is-live", "Is Live",
368 "Whether to act as a live source",
369 DEFAULT_PROP_IS_LIVE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
371 * GstAppSrc::min-latency
373 * The minimum latency of the source. A value of -1 will use the default
374 * latency calculations of #GstBaseSrc.
376 g_object_class_install_property (gobject_class, PROP_MIN_LATENCY,
377 g_param_spec_int64 ("min-latency", "Min Latency",
378 "The minimum latency (-1 = default)",
379 -1, G_MAXINT64, DEFAULT_PROP_MIN_LATENCY,
380 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
382 * GstAppSrc::max-latency
384 * The maximum latency of the source. A value of -1 means an unlimited amout
387 g_object_class_install_property (gobject_class, PROP_MAX_LATENCY,
388 g_param_spec_int64 ("max-latency", "Max Latency",
389 "The maximum latency (-1 = unlimited)",
390 -1, G_MAXINT64, DEFAULT_PROP_MAX_LATENCY,
391 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
394 * GstAppSrc::emit-signals
396 * Make appsrc emit the "need-data", "enough-data" and "seek-data" signals.
397 * This option is by default enabled for backwards compatibility reasons but
398 * can disabled when needed because signal emission is expensive.
402 g_object_class_install_property (gobject_class, PROP_EMIT_SIGNALS,
403 g_param_spec_boolean ("emit-signals", "Emit signals",
404 "Emit need-data, enough-data and seek-data signals",
405 DEFAULT_PROP_EMIT_SIGNALS,
406 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
409 * GstAppSrc::empty-percent
411 * Make appsrc emit the "need-data" signal when the amount of bytes in the
412 * queue drops below this percentage of max-bytes.
416 g_object_class_install_property (gobject_class, PROP_MIN_PERCENT,
417 g_param_spec_uint ("min-percent", "Min Percent",
418 "Emit need-data when queued bytes drops below this percent of max-bytes",
419 0, 100, DEFAULT_PROP_MIN_PERCENT,
420 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
423 * GstAppSrc::need-data:
424 * @appsrc: the appsrc element that emited the signal
425 * @length: the amount of bytes needed.
427 * Signal that the source needs more data. In the callback or from another
428 * thread you should call push-buffer or end-of-stream.
430 * @length is just a hint and when it is set to -1, any number of bytes can be
431 * pushed into @appsrc.
433 * You can call push-buffer multiple times until the enough-data signal is
436 gst_app_src_signals[SIGNAL_NEED_DATA] =
437 g_signal_new ("need-data", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
438 G_STRUCT_OFFSET (GstAppSrcClass, need_data),
439 NULL, NULL, __gst_app_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
442 * GstAppSrc::enough-data:
443 * @appsrc: the appsrc element that emited the signal
445 * Signal that the source has enough data. It is recommended that the
446 * application stops calling push-buffer until the need-data signal is
447 * emited again to avoid excessive buffer queueing.
449 gst_app_src_signals[SIGNAL_ENOUGH_DATA] =
450 g_signal_new ("enough-data", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
451 G_STRUCT_OFFSET (GstAppSrcClass, enough_data),
452 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
455 * GstAppSrc::seek-data:
456 * @appsrc: the appsrc element that emited the signal
457 * @offset: the offset to seek to
459 * Seek to the given offset. The next push-buffer should produce buffers from
461 * This callback is only called for seekable stream types.
463 * Returns: %TRUE if the seek succeeded.
465 gst_app_src_signals[SIGNAL_SEEK_DATA] =
466 g_signal_new ("seek-data", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
467 G_STRUCT_OFFSET (GstAppSrcClass, seek_data),
468 NULL, NULL, __gst_app_marshal_BOOLEAN__UINT64, G_TYPE_BOOLEAN, 1,
472 * GstAppSrc::push-buffer:
473 * @appsrc: the appsrc
474 * @buffer: a buffer to push
476 * Adds a buffer to the queue of buffers that the appsrc element will
477 * push to its source pad. This function does not take ownership of the
478 * buffer so the buffer needs to be unreffed after calling this function.
480 * When the block property is TRUE, this function can block until free space
481 * becomes available in the queue.
483 gst_app_src_signals[SIGNAL_PUSH_BUFFER] =
484 g_signal_new ("push-buffer", G_TYPE_FROM_CLASS (klass),
485 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstAppSrcClass,
486 push_buffer), NULL, NULL, __gst_app_marshal_ENUM__OBJECT,
487 GST_TYPE_FLOW_RETURN, 1, GST_TYPE_BUFFER);
490 * GstAppSrc::end-of-stream:
491 * @appsrc: the appsrc
493 * Notify @appsrc that no more buffer are available.
495 gst_app_src_signals[SIGNAL_END_OF_STREAM] =
496 g_signal_new ("end-of-stream", G_TYPE_FROM_CLASS (klass),
497 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstAppSrcClass,
498 end_of_stream), NULL, NULL, __gst_app_marshal_ENUM__VOID,
499 GST_TYPE_FLOW_RETURN, 0, G_TYPE_NONE);
501 basesrc_class->create = gst_app_src_create;
502 basesrc_class->start = gst_app_src_start;
503 basesrc_class->stop = gst_app_src_stop;
504 basesrc_class->unlock = gst_app_src_unlock;
505 basesrc_class->unlock_stop = gst_app_src_unlock_stop;
506 basesrc_class->do_seek = gst_app_src_do_seek;
507 basesrc_class->is_seekable = gst_app_src_is_seekable;
508 basesrc_class->check_get_range = gst_app_src_check_get_range;
509 basesrc_class->get_size = gst_app_src_do_get_size;
510 basesrc_class->get_size = gst_app_src_do_get_size;
511 basesrc_class->query = gst_app_src_query;
513 klass->push_buffer = gst_app_src_push_buffer_action;
514 klass->end_of_stream = gst_app_src_end_of_stream;
516 g_type_class_add_private (klass, sizeof (GstAppSrcPrivate));
520 gst_app_src_init (GstAppSrc * appsrc, GstAppSrcClass * klass)
522 GstAppSrcPrivate *priv;
524 priv = appsrc->priv = G_TYPE_INSTANCE_GET_PRIVATE (appsrc, GST_TYPE_APP_SRC,
527 priv->mutex = g_mutex_new ();
528 priv->cond = g_cond_new ();
529 priv->queue = g_queue_new ();
531 priv->size = DEFAULT_PROP_SIZE;
532 priv->stream_type = DEFAULT_PROP_STREAM_TYPE;
533 priv->max_bytes = DEFAULT_PROP_MAX_BYTES;
534 priv->format = DEFAULT_PROP_FORMAT;
535 priv->block = DEFAULT_PROP_BLOCK;
536 priv->min_latency = DEFAULT_PROP_MIN_LATENCY;
537 priv->max_latency = DEFAULT_PROP_MAX_LATENCY;
538 priv->emit_signals = DEFAULT_PROP_EMIT_SIGNALS;
539 priv->min_percent = DEFAULT_PROP_MIN_PERCENT;
541 gst_base_src_set_live (GST_BASE_SRC (appsrc), DEFAULT_PROP_IS_LIVE);
545 gst_app_src_flush_queued (GstAppSrc * src)
548 GstAppSrcPrivate *priv = src->priv;
550 while ((buf = g_queue_pop_head (priv->queue)))
551 gst_buffer_unref (buf);
552 priv->queued_bytes = 0;
556 gst_app_src_dispose (GObject * obj)
558 GstAppSrc *appsrc = GST_APP_SRC_CAST (obj);
559 GstAppSrcPrivate *priv = appsrc->priv;
562 gst_caps_unref (priv->caps);
565 gst_app_src_flush_queued (appsrc);
567 G_OBJECT_CLASS (parent_class)->dispose (obj);
571 gst_app_src_finalize (GObject * obj)
573 GstAppSrc *appsrc = GST_APP_SRC_CAST (obj);
574 GstAppSrcPrivate *priv = appsrc->priv;
576 g_mutex_free (priv->mutex);
577 g_cond_free (priv->cond);
578 g_queue_free (priv->queue);
580 G_OBJECT_CLASS (parent_class)->finalize (obj);
584 gst_app_src_set_property (GObject * object, guint prop_id,
585 const GValue * value, GParamSpec * pspec)
587 GstAppSrc *appsrc = GST_APP_SRC_CAST (object);
588 GstAppSrcPrivate *priv = appsrc->priv;
592 gst_app_src_set_caps (appsrc, gst_value_get_caps (value));
595 gst_app_src_set_size (appsrc, g_value_get_int64 (value));
597 case PROP_STREAM_TYPE:
598 gst_app_src_set_stream_type (appsrc, g_value_get_enum (value));
601 gst_app_src_set_max_bytes (appsrc, g_value_get_uint64 (value));
604 priv->format = g_value_get_enum (value);
607 priv->block = g_value_get_boolean (value);
610 gst_base_src_set_live (GST_BASE_SRC (appsrc),
611 g_value_get_boolean (value));
613 case PROP_MIN_LATENCY:
614 gst_app_src_set_latencies (appsrc, TRUE, g_value_get_int64 (value),
617 case PROP_MAX_LATENCY:
618 gst_app_src_set_latencies (appsrc, FALSE, -1, TRUE,
619 g_value_get_int64 (value));
621 case PROP_EMIT_SIGNALS:
622 gst_app_src_set_emit_signals (appsrc, g_value_get_boolean (value));
624 case PROP_MIN_PERCENT:
625 priv->min_percent = g_value_get_uint (value);
628 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
634 gst_app_src_get_property (GObject * object, guint prop_id, GValue * value,
637 GstAppSrc *appsrc = GST_APP_SRC_CAST (object);
638 GstAppSrcPrivate *priv = appsrc->priv;
645 /* we're missing a _take_caps() function to transfer ownership */
646 caps = gst_app_src_get_caps (appsrc);
647 gst_value_set_caps (value, caps);
649 gst_caps_unref (caps);
653 g_value_set_int64 (value, gst_app_src_get_size (appsrc));
655 case PROP_STREAM_TYPE:
656 g_value_set_enum (value, gst_app_src_get_stream_type (appsrc));
659 g_value_set_uint64 (value, gst_app_src_get_max_bytes (appsrc));
662 g_value_set_enum (value, priv->format);
665 g_value_set_boolean (value, priv->block);
668 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (appsrc)));
670 case PROP_MIN_LATENCY:
674 gst_app_src_get_latency (appsrc, &min, NULL);
675 g_value_set_int64 (value, min);
678 case PROP_MAX_LATENCY:
682 gst_app_src_get_latency (appsrc, &max, NULL);
683 g_value_set_int64 (value, max);
686 case PROP_EMIT_SIGNALS:
687 g_value_set_boolean (value, gst_app_src_get_emit_signals (appsrc));
689 case PROP_MIN_PERCENT:
690 g_value_set_uint (value, priv->min_percent);
693 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
699 gst_app_src_unlock (GstBaseSrc * bsrc)
701 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
702 GstAppSrcPrivate *priv = appsrc->priv;
704 g_mutex_lock (priv->mutex);
705 GST_DEBUG_OBJECT (appsrc, "unlock start");
706 priv->flushing = TRUE;
707 g_cond_broadcast (priv->cond);
708 g_mutex_unlock (priv->mutex);
714 gst_app_src_unlock_stop (GstBaseSrc * bsrc)
716 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
717 GstAppSrcPrivate *priv = appsrc->priv;
719 g_mutex_lock (priv->mutex);
720 GST_DEBUG_OBJECT (appsrc, "unlock stop");
721 priv->flushing = FALSE;
722 g_cond_broadcast (priv->cond);
723 g_mutex_unlock (priv->mutex);
729 gst_app_src_start (GstBaseSrc * bsrc)
731 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
732 GstAppSrcPrivate *priv = appsrc->priv;
734 g_mutex_lock (priv->mutex);
735 GST_DEBUG_OBJECT (appsrc, "starting");
736 priv->started = TRUE;
737 /* set the offset to -1 so that we always do a first seek. This is only used
738 * in random-access mode. */
740 priv->flushing = FALSE;
741 g_mutex_unlock (priv->mutex);
743 gst_base_src_set_format (bsrc, priv->format);
749 gst_app_src_stop (GstBaseSrc * bsrc)
751 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
752 GstAppSrcPrivate *priv = appsrc->priv;
754 g_mutex_lock (priv->mutex);
755 GST_DEBUG_OBJECT (appsrc, "stopping");
756 priv->is_eos = FALSE;
757 priv->flushing = TRUE;
758 priv->started = FALSE;
759 gst_app_src_flush_queued (appsrc);
760 g_mutex_unlock (priv->mutex);
766 gst_app_src_is_seekable (GstBaseSrc * src)
768 GstAppSrc *appsrc = GST_APP_SRC_CAST (src);
769 GstAppSrcPrivate *priv = appsrc->priv;
770 gboolean res = FALSE;
772 switch (priv->stream_type) {
773 case GST_APP_STREAM_TYPE_STREAM:
775 case GST_APP_STREAM_TYPE_SEEKABLE:
776 case GST_APP_STREAM_TYPE_RANDOM_ACCESS:
784 gst_app_src_check_get_range (GstBaseSrc * src)
786 GstAppSrc *appsrc = GST_APP_SRC_CAST (src);
787 GstAppSrcPrivate *priv = appsrc->priv;
788 gboolean res = FALSE;
790 switch (priv->stream_type) {
791 case GST_APP_STREAM_TYPE_STREAM:
792 case GST_APP_STREAM_TYPE_SEEKABLE:
794 case GST_APP_STREAM_TYPE_RANDOM_ACCESS:
802 gst_app_src_do_get_size (GstBaseSrc * src, guint64 * size)
804 GstAppSrc *appsrc = GST_APP_SRC_CAST (src);
806 *size = gst_app_src_get_size (appsrc);
812 gst_app_src_query (GstBaseSrc * src, GstQuery * query)
814 GstAppSrc *appsrc = GST_APP_SRC_CAST (src);
815 GstAppSrcPrivate *priv = appsrc->priv;
818 switch (GST_QUERY_TYPE (query)) {
819 case GST_QUERY_LATENCY:
821 GstClockTime min, max;
824 /* Query the parent class for the defaults */
825 res = gst_base_src_query_latency (src, &live, &min, &max);
827 /* overwrite with our values when we need to */
828 g_mutex_lock (priv->mutex);
829 if (priv->min_latency != -1)
830 min = priv->min_latency;
831 if (priv->max_latency != -1)
832 max = priv->max_latency;
833 g_mutex_unlock (priv->mutex);
835 gst_query_set_latency (query, live, min, max);
839 res = GST_BASE_SRC_CLASS (parent_class)->query (src, query);
846 /* will be called in push mode */
848 gst_app_src_do_seek (GstBaseSrc * src, GstSegment * segment)
850 GstAppSrc *appsrc = GST_APP_SRC_CAST (src);
851 GstAppSrcPrivate *priv = appsrc->priv;
852 gint64 desired_position;
853 gboolean res = FALSE;
855 desired_position = segment->last_stop;
857 GST_DEBUG_OBJECT (appsrc, "seeking to %" G_GINT64_FORMAT ", format %s",
858 desired_position, gst_format_get_name (segment->format));
860 /* no need to try to seek in streaming mode */
861 if (priv->stream_type == GST_APP_STREAM_TYPE_STREAM)
864 if (priv->callbacks.seek_data)
865 res = priv->callbacks.seek_data (appsrc, desired_position, priv->user_data);
869 g_mutex_lock (priv->mutex);
870 emit = priv->emit_signals;
871 g_mutex_unlock (priv->mutex);
874 g_signal_emit (appsrc, gst_app_src_signals[SIGNAL_SEEK_DATA], 0,
875 desired_position, &res);
879 GST_DEBUG_OBJECT (appsrc, "flushing queue");
880 gst_app_src_flush_queued (appsrc);
881 priv->is_eos = FALSE;
883 GST_WARNING_OBJECT (appsrc, "seek failed");
889 /* must be called with the appsrc mutex */
891 gst_app_src_emit_seek (GstAppSrc * appsrc, guint64 offset)
893 gboolean res = FALSE;
895 GstAppSrcPrivate *priv = appsrc->priv;
897 emit = priv->emit_signals;
898 g_mutex_unlock (priv->mutex);
900 GST_DEBUG_OBJECT (appsrc,
901 "we are at %" G_GINT64_FORMAT ", seek to %" G_GINT64_FORMAT,
902 priv->offset, offset);
904 if (priv->callbacks.seek_data)
905 res = priv->callbacks.seek_data (appsrc, offset, priv->user_data);
907 g_signal_emit (appsrc, gst_app_src_signals[SIGNAL_SEEK_DATA], 0,
910 g_mutex_lock (priv->mutex);
915 /* must be called with the appsrc mutex. After this call things can be
918 gst_app_src_emit_need_data (GstAppSrc * appsrc, guint size)
921 GstAppSrcPrivate *priv = appsrc->priv;
923 emit = priv->emit_signals;
924 g_mutex_unlock (priv->mutex);
926 /* we have no data, we need some. We fire the signal with the size hint. */
927 if (priv->callbacks.need_data)
928 priv->callbacks.need_data (appsrc, size, priv->user_data);
930 g_signal_emit (appsrc, gst_app_src_signals[SIGNAL_NEED_DATA], 0, size,
933 g_mutex_lock (priv->mutex);
934 /* we can be flushing now because we released the lock */
938 gst_app_src_create (GstBaseSrc * bsrc, guint64 offset, guint size,
941 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
942 GstAppSrcPrivate *priv = appsrc->priv;
946 GST_OBJECT_LOCK (appsrc);
947 caps = priv->caps ? gst_caps_ref (priv->caps) : NULL;
948 if (G_UNLIKELY (priv->size != bsrc->segment.duration &&
949 bsrc->segment.format == GST_FORMAT_BYTES)) {
950 GST_DEBUG_OBJECT (appsrc,
951 "Size changed from %" G_GINT64_FORMAT " to %" G_GINT64_FORMAT,
952 bsrc->segment.duration, priv->size);
953 gst_segment_set_duration (&bsrc->segment, GST_FORMAT_BYTES, priv->size);
954 GST_OBJECT_UNLOCK (appsrc);
956 gst_element_post_message (GST_ELEMENT (appsrc),
957 gst_message_new_duration (GST_OBJECT (appsrc), GST_FORMAT_BYTES,
960 GST_OBJECT_UNLOCK (appsrc);
963 g_mutex_lock (priv->mutex);
964 /* check flushing first */
965 if (G_UNLIKELY (priv->flushing))
968 if (priv->stream_type == GST_APP_STREAM_TYPE_RANDOM_ACCESS) {
969 /* if we are dealing with a random-access stream, issue a seek if the offset
971 if (G_UNLIKELY (priv->offset != offset)) {
975 res = gst_app_src_emit_seek (appsrc, offset);
977 if (G_UNLIKELY (!res))
978 /* failing to seek is fatal */
981 priv->offset = offset;
986 /* return data as long as we have some */
987 if (!g_queue_is_empty (priv->queue)) {
990 *buf = g_queue_pop_head (priv->queue);
991 buf_size = GST_BUFFER_SIZE (*buf);
993 GST_DEBUG_OBJECT (appsrc, "we have buffer %p of size %u", *buf, buf_size);
995 priv->queued_bytes -= buf_size;
997 /* only update the offset when in random_access mode */
998 if (priv->stream_type == GST_APP_STREAM_TYPE_RANDOM_ACCESS)
999 priv->offset += buf_size;
1001 *buf = gst_buffer_make_metadata_writable (*buf);
1002 gst_buffer_set_caps (*buf, caps);
1005 /* signal that we removed an item */
1006 g_cond_broadcast (priv->cond);
1008 /* see if we go lower than the empty-percent */
1009 if (priv->min_percent && priv->max_bytes) {
1010 if (priv->queued_bytes * 100 / priv->max_bytes <= priv->min_percent)
1011 /* ignore flushing state, we got a buffer and we will return it now.
1012 * Errors will be handled in the next round */
1013 gst_app_src_emit_need_data (appsrc, size);
1018 gst_app_src_emit_need_data (appsrc, size);
1020 /* we can be flushing now because we released the lock above */
1021 if (G_UNLIKELY (priv->flushing))
1024 /* if we have a buffer now, continue the loop and try to return it. In
1025 * random-access mode (where a buffer is normally pushed in the above
1026 * signal) we can still be empty because the pushed buffer got flushed or
1027 * when the application pushes the requested buffer later, we support both
1029 if (!g_queue_is_empty (priv->queue))
1032 /* no buffer yet, maybe we are EOS, if not, block for more data. */
1036 if (G_UNLIKELY (priv->is_eos))
1039 /* nothing to return, wait a while for new data or flushing. */
1040 g_cond_wait (priv->cond, priv->mutex);
1042 g_mutex_unlock (priv->mutex);
1044 gst_caps_unref (caps);
1050 GST_DEBUG_OBJECT (appsrc, "we are flushing");
1051 g_mutex_unlock (priv->mutex);
1053 gst_caps_unref (caps);
1054 return GST_FLOW_WRONG_STATE;
1058 GST_DEBUG_OBJECT (appsrc, "we are EOS");
1059 g_mutex_unlock (priv->mutex);
1061 gst_caps_unref (caps);
1062 return GST_FLOW_UNEXPECTED;
1066 g_mutex_unlock (priv->mutex);
1068 gst_caps_unref (caps);
1069 GST_ELEMENT_ERROR (appsrc, RESOURCE, READ, ("failed to seek"),
1071 return GST_FLOW_ERROR;
1078 * gst_app_src_set_caps:
1079 * @appsrc: a #GstAppSrc
1080 * @caps: caps to set
1082 * Set the capabilities on the appsrc element. This function takes
1083 * a copy of the caps structure. After calling this method, the source will
1084 * only produce caps that match @caps. @caps must be fixed and the caps on the
1085 * buffers must match the caps or left NULL.
1090 gst_app_src_set_caps (GstAppSrc * appsrc, const GstCaps * caps)
1093 GstAppSrcPrivate *priv;
1095 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1097 priv = appsrc->priv;
1099 GST_OBJECT_LOCK (appsrc);
1100 GST_DEBUG_OBJECT (appsrc, "setting caps to %" GST_PTR_FORMAT, caps);
1101 if ((old = priv->caps) != caps) {
1103 priv->caps = gst_caps_copy (caps);
1107 gst_caps_unref (old);
1109 GST_OBJECT_UNLOCK (appsrc);
1113 * gst_app_src_get_caps:
1114 * @appsrc: a #GstAppSrc
1116 * Get the configured caps on @appsrc.
1118 * Returns: the #GstCaps produced by the source. gst_caps_unref() after usage.
1123 gst_app_src_get_caps (GstAppSrc * appsrc)
1126 GstAppSrcPrivate *priv;
1128 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), NULL);
1130 priv = appsrc->priv;
1132 GST_OBJECT_LOCK (appsrc);
1133 if ((caps = priv->caps))
1134 gst_caps_ref (caps);
1135 GST_DEBUG_OBJECT (appsrc, "getting caps of %" GST_PTR_FORMAT, caps);
1136 GST_OBJECT_UNLOCK (appsrc);
1142 * gst_app_src_set_size:
1143 * @appsrc: a #GstAppSrc
1144 * @size: the size to set
1146 * Set the size of the stream in bytes. A value of -1 means that the size is
1152 gst_app_src_set_size (GstAppSrc * appsrc, gint64 size)
1154 GstAppSrcPrivate *priv;
1156 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1158 priv = appsrc->priv;
1160 GST_OBJECT_LOCK (appsrc);
1161 GST_DEBUG_OBJECT (appsrc, "setting size of %" G_GINT64_FORMAT, size);
1163 GST_OBJECT_UNLOCK (appsrc);
1167 * gst_app_src_get_size:
1168 * @appsrc: a #GstAppSrc
1170 * Get the size of the stream in bytes. A value of -1 means that the size is
1173 * Returns: the size of the stream previously set with gst_app_src_set_size();
1178 gst_app_src_get_size (GstAppSrc * appsrc)
1181 GstAppSrcPrivate *priv;
1183 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), -1);
1185 priv = appsrc->priv;
1187 GST_OBJECT_LOCK (appsrc);
1189 GST_DEBUG_OBJECT (appsrc, "getting size of %" G_GINT64_FORMAT, size);
1190 GST_OBJECT_UNLOCK (appsrc);
1196 * gst_app_src_set_stream_type:
1197 * @appsrc: a #GstAppSrc
1198 * @type: the new state
1200 * Set the stream type on @appsrc. For seekable streams, the "seek" signal must
1203 * A stream_type stream
1208 gst_app_src_set_stream_type (GstAppSrc * appsrc, GstAppStreamType type)
1210 GstAppSrcPrivate *priv;
1212 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1214 priv = appsrc->priv;
1216 GST_OBJECT_LOCK (appsrc);
1217 GST_DEBUG_OBJECT (appsrc, "setting stream_type of %d", type);
1218 priv->stream_type = type;
1219 GST_OBJECT_UNLOCK (appsrc);
1223 * gst_app_src_get_stream_type:
1224 * @appsrc: a #GstAppSrc
1226 * Get the stream type. Control the stream type of @appsrc
1227 * with gst_app_src_set_stream_type().
1229 * Returns: the stream type.
1234 gst_app_src_get_stream_type (GstAppSrc * appsrc)
1236 gboolean stream_type;
1237 GstAppSrcPrivate *priv;
1239 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), FALSE);
1241 priv = appsrc->priv;
1243 GST_OBJECT_LOCK (appsrc);
1244 stream_type = priv->stream_type;
1245 GST_DEBUG_OBJECT (appsrc, "getting stream_type of %d", stream_type);
1246 GST_OBJECT_UNLOCK (appsrc);
1252 * gst_app_src_set_max_bytes:
1253 * @appsrc: a #GstAppSrc
1254 * @max: the maximum number of bytes to queue
1256 * Set the maximum amount of bytes that can be queued in @appsrc.
1257 * After the maximum amount of bytes are queued, @appsrc will emit the
1258 * "enough-data" signal.
1263 gst_app_src_set_max_bytes (GstAppSrc * appsrc, guint64 max)
1265 GstAppSrcPrivate *priv;
1267 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1269 priv = appsrc->priv;
1271 g_mutex_lock (priv->mutex);
1272 if (max != priv->max_bytes) {
1273 GST_DEBUG_OBJECT (appsrc, "setting max-bytes to %" G_GUINT64_FORMAT, max);
1274 priv->max_bytes = max;
1275 /* signal the change */
1276 g_cond_broadcast (priv->cond);
1278 g_mutex_unlock (priv->mutex);
1282 * gst_app_src_get_max_bytes:
1283 * @appsrc: a #GstAppSrc
1285 * Get the maximum amount of bytes that can be queued in @appsrc.
1287 * Returns: The maximum amount of bytes that can be queued.
1292 gst_app_src_get_max_bytes (GstAppSrc * appsrc)
1295 GstAppSrcPrivate *priv;
1297 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), 0);
1299 priv = appsrc->priv;
1301 g_mutex_lock (priv->mutex);
1302 result = priv->max_bytes;
1303 GST_DEBUG_OBJECT (appsrc, "getting max-bytes of %" G_GUINT64_FORMAT, result);
1304 g_mutex_unlock (priv->mutex);
1310 gst_app_src_set_latencies (GstAppSrc * appsrc, gboolean do_min, guint64 min,
1311 gboolean do_max, guint64 max)
1313 GstAppSrcPrivate *priv = appsrc->priv;
1314 gboolean changed = FALSE;
1316 g_mutex_lock (priv->mutex);
1317 if (do_min && priv->min_latency != min) {
1318 priv->min_latency = min;
1321 if (do_max && priv->max_latency != max) {
1322 priv->max_latency = max;
1325 g_mutex_unlock (priv->mutex);
1328 GST_DEBUG_OBJECT (appsrc, "posting latency changed");
1329 gst_element_post_message (GST_ELEMENT_CAST (appsrc),
1330 gst_message_new_latency (GST_OBJECT_CAST (appsrc)));
1335 * gst_app_src_set_latency:
1336 * @appsrc: a #GstAppSrc
1337 * @min: the min latency
1338 * @max: the min latency
1340 * Configure the @min and @max latency in @src. If @min is set to -1, the
1341 * default latency calculations for pseudo-live sources will be used.
1346 gst_app_src_set_latency (GstAppSrc * appsrc, guint64 min, guint64 max)
1348 gst_app_src_set_latencies (appsrc, TRUE, min, TRUE, max);
1352 * gst_app_src_get_latency:
1353 * @appsrc: a #GstAppSrc
1354 * @min: the min latency
1355 * @max: the min latency
1357 * Retrieve the min and max latencies in @min and @max respectively.
1362 gst_app_src_get_latency (GstAppSrc * appsrc, guint64 * min, guint64 * max)
1364 GstAppSrcPrivate *priv;
1366 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1368 priv = appsrc->priv;
1370 g_mutex_lock (priv->mutex);
1372 *min = priv->min_latency;
1374 *max = priv->max_latency;
1375 g_mutex_unlock (priv->mutex);
1379 * gst_app_src_set_emit_signals:
1380 * @appsrc: a #GstAppSrc
1381 * @emit: the new state
1383 * Make appsrc emit the "new-preroll" and "new-buffer" signals. This option is
1384 * by default disabled because signal emission is expensive and unneeded when
1385 * the application prefers to operate in pull mode.
1390 gst_app_src_set_emit_signals (GstAppSrc * appsrc, gboolean emit)
1392 GstAppSrcPrivate *priv;
1394 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1396 priv = appsrc->priv;
1398 g_mutex_lock (priv->mutex);
1399 priv->emit_signals = emit;
1400 g_mutex_unlock (priv->mutex);
1404 * gst_app_src_get_emit_signals:
1405 * @appsrc: a #GstAppSrc
1407 * Check if appsrc will emit the "new-preroll" and "new-buffer" signals.
1409 * Returns: %TRUE if @appsrc is emiting the "new-preroll" and "new-buffer"
1415 gst_app_src_get_emit_signals (GstAppSrc * appsrc)
1418 GstAppSrcPrivate *priv;
1420 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), FALSE);
1422 priv = appsrc->priv;
1424 g_mutex_lock (priv->mutex);
1425 result = priv->emit_signals;
1426 g_mutex_unlock (priv->mutex);
1431 static GstFlowReturn
1432 gst_app_src_push_buffer_full (GstAppSrc * appsrc, GstBuffer * buffer,
1435 gboolean first = TRUE;
1436 GstAppSrcPrivate *priv;
1438 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), GST_FLOW_ERROR);
1439 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
1441 priv = appsrc->priv;
1443 g_mutex_lock (priv->mutex);
1446 /* can't accept buffers when we are flushing or EOS */
1453 if (priv->max_bytes && priv->queued_bytes >= priv->max_bytes) {
1454 GST_DEBUG_OBJECT (appsrc,
1455 "queue filled (%" G_GUINT64_FORMAT " >= %" G_GUINT64_FORMAT ")",
1456 priv->queued_bytes, priv->max_bytes);
1461 emit = priv->emit_signals;
1462 /* only signal on the first push */
1463 g_mutex_unlock (priv->mutex);
1465 if (priv->callbacks.enough_data)
1466 priv->callbacks.enough_data (appsrc, priv->user_data);
1468 g_signal_emit (appsrc, gst_app_src_signals[SIGNAL_ENOUGH_DATA], 0,
1471 g_mutex_lock (priv->mutex);
1472 /* continue to check for flushing/eos after releasing the lock */
1477 GST_DEBUG_OBJECT (appsrc, "waiting for free space");
1478 /* we are filled, wait until a buffer gets popped or when we
1480 g_cond_wait (priv->cond, priv->mutex);
1482 /* no need to wait for free space, we just pump more data into the
1483 * queue hoping that the caller reacts to the enough-data signal and
1484 * stops pushing buffers. */
1491 GST_DEBUG_OBJECT (appsrc, "queueing buffer %p", buffer);
1493 gst_buffer_ref (buffer);
1494 g_queue_push_tail (priv->queue, buffer);
1495 priv->queued_bytes += GST_BUFFER_SIZE (buffer);
1496 g_cond_broadcast (priv->cond);
1497 g_mutex_unlock (priv->mutex);
1504 GST_DEBUG_OBJECT (appsrc, "refuse buffer %p, we are flushing", buffer);
1506 gst_buffer_unref (buffer);
1507 g_mutex_unlock (priv->mutex);
1508 return GST_FLOW_WRONG_STATE;
1512 GST_DEBUG_OBJECT (appsrc, "refuse buffer %p, we are EOS", buffer);
1514 gst_buffer_unref (buffer);
1515 g_mutex_unlock (priv->mutex);
1516 return GST_FLOW_UNEXPECTED;
1521 * gst_app_src_push_buffer:
1522 * @appsrc: a #GstAppSrc
1523 * @buffer: a #GstBuffer to push
1525 * Adds a buffer to the queue of buffers that the appsrc element will
1526 * push to its source pad. This function takes ownership of the buffer.
1528 * When the block property is TRUE, this function can block until free
1529 * space becomes available in the queue.
1531 * Returns: #GST_FLOW_OK when the buffer was successfuly queued.
1532 * #GST_FLOW_WRONG_STATE when @appsrc is not PAUSED or PLAYING.
1533 * #GST_FLOW_UNEXPECTED when EOS occured.
1538 gst_app_src_push_buffer (GstAppSrc * appsrc, GstBuffer * buffer)
1540 return gst_app_src_push_buffer_full (appsrc, buffer, TRUE);
1543 /* push a buffer without stealing the ref of the buffer. This is used for the
1545 static GstFlowReturn
1546 gst_app_src_push_buffer_action (GstAppSrc * appsrc, GstBuffer * buffer)
1548 return gst_app_src_push_buffer_full (appsrc, buffer, FALSE);
1552 * gst_app_src_end_of_stream:
1553 * @appsrc: a #GstAppSrc
1555 * Indicates to the appsrc element that the last buffer queued in the
1556 * element is the last buffer of the stream.
1558 * Returns: #GST_FLOW_OK when the EOS was successfuly queued.
1559 * #GST_FLOW_WRONG_STATE when @appsrc is not PAUSED or PLAYING.
1564 gst_app_src_end_of_stream (GstAppSrc * appsrc)
1566 GstAppSrcPrivate *priv;
1568 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), GST_FLOW_ERROR);
1570 priv = appsrc->priv;
1572 g_mutex_lock (priv->mutex);
1573 /* can't accept buffers when we are flushing. We can accept them when we are
1574 * EOS although it will not do anything. */
1578 GST_DEBUG_OBJECT (appsrc, "sending EOS");
1579 priv->is_eos = TRUE;
1580 g_cond_broadcast (priv->cond);
1581 g_mutex_unlock (priv->mutex);
1588 g_mutex_unlock (priv->mutex);
1589 GST_DEBUG_OBJECT (appsrc, "refuse EOS, we are flushing");
1590 return GST_FLOW_WRONG_STATE;
1595 * gst_app_src_set_callbacks:
1596 * @appsrc: a #GstAppSrc
1597 * @callbacks: the callbacks
1598 * @user_data: a user_data argument for the callbacks
1599 * @notify: a destroy notify function
1601 * Set callbacks which will be executed when data is needed, enough data has
1602 * been collected or when a seek should be performed.
1603 * This is an alternative to using the signals, it has lower overhead and is thus
1604 * less expensive, but also less flexible.
1606 * If callbacks are installed, no signals will be emited for performance
1612 gst_app_src_set_callbacks (GstAppSrc * appsrc,
1613 GstAppSrcCallbacks * callbacks, gpointer user_data, GDestroyNotify notify)
1615 GDestroyNotify old_notify;
1616 GstAppSrcPrivate *priv;
1618 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1619 g_return_if_fail (callbacks != NULL);
1621 priv = appsrc->priv;
1623 GST_OBJECT_LOCK (appsrc);
1624 old_notify = priv->notify;
1629 old_data = priv->user_data;
1631 priv->user_data = NULL;
1632 priv->notify = NULL;
1633 GST_OBJECT_UNLOCK (appsrc);
1635 old_notify (old_data);
1637 GST_OBJECT_LOCK (appsrc);
1639 priv->callbacks = *callbacks;
1640 priv->user_data = user_data;
1641 priv->notify = notify;
1642 GST_OBJECT_UNLOCK (appsrc);
1645 /*** GSTURIHANDLER INTERFACE *************************************************/
1648 gst_app_src_uri_get_type (void)
1654 gst_app_src_uri_get_protocols (void)
1656 static gchar *protocols[] = { (char *) "appsrc", NULL };
1661 static const gchar *
1662 gst_app_src_uri_get_uri (GstURIHandler * handler)
1668 gst_app_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1673 protocol = gst_uri_get_protocol (uri);
1674 ret = !strcmp (protocol, "appsrc");
1681 gst_app_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1683 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1685 iface->get_type = gst_app_src_uri_get_type;
1686 iface->get_protocols = gst_app_src_uri_get_protocols;
1687 iface->get_uri = gst_app_src_uri_get_uri;
1688 iface->set_uri = gst_app_src_uri_set_uri;