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 * @short_description: Easy way for applications to inject buffers into a
24 * @see_also: #GstBaseSrc, appsink
26 * The appsrc element can be used by applications to insert data into a
27 * GStreamer pipeline. Unlike most GStreamer elements, Appsrc provides
28 * external API functions.
30 * appsrc can be used by linking with the libgstapp library to access the
31 * methods directly or by using the appsrc action signals.
33 * Before operating appsrc, the caps property must be set to a fixed caps
34 * describing the format of the data that will be pushed with appsrc. An
35 * exception to this is when pushing buffers with unknown caps, in which case no
36 * caps should be set. This is typically true of file-like sources that push raw
39 * The main way of handing data to the appsrc element is by calling the
40 * gst_app_src_push_buffer() method or by emiting the push-buffer action signal.
41 * This will put the buffer onto a queue from which appsrc will read from in its
42 * streaming thread. It is important to note that data transport will not happen
43 * from the thread that performed the push-buffer call.
45 * The "max-bytes" property controls how much data can be queued in appsrc
46 * before appsrc considers the queue full. A filled internal queue will always
47 * signal the "enough-data" signal, which signals the application that it should
48 * stop pushing data into appsrc. The "block" property will cause appsrc to
49 * block the push-buffer method until free data becomes available again.
51 * When the internal queue is running out of data, the "need-data" signal is
52 * emited, which signals the application that it should start pushing more data
55 * In addition to the "need-data" and "enough-data" signals, appsrc can emit the
56 * "seek-data" signal when the "stream-mode" property is set to "seekable" or
57 * "random-access". The signal argument will contain the new desired position in
58 * the stream expressed in the unit set with the "format" property. After
59 * receiving the seek-data signal, the application should push-buffers from the
62 * These signals allow the application to operate the appsrc in two different
65 * The push model, in which the application repeadedly calls the push-buffer method
66 * with a new buffer. Optionally, the queue size in the appsrc can be controlled
67 * with the enough-data and need-data signals by respectively stopping/starting
68 * the push-buffer calls. This is a typical mode of operation for the
69 * stream-type "stream" and "seekable". Use this model when implementing various
70 * network protocols or hardware devices.
72 * The pull model where the need-data signal triggers the next push-buffer call.
73 * This mode is typically used in the "random-access" stream-type. Use this
74 * model for file access or other randomly accessable sources. In this mode, a
75 * buffer of exactly the amount of bytes given by the need-data signal should be
78 * In all modes, the size property on appsrc should contain the total stream
79 * size in bytes. Setting this property is mandatory in the random-access mode.
80 * For the stream and seekable modes, setting this property is optional but
83 * When the application is finished pushing data into appsrc, it should call
84 * gst_app_src_end_of_stream() or emit the end-of-stream action signal. After
85 * this call, no more buffers can be pushed into appsrc until a flushing seek
86 * happened or the state of the appsrc has gone through READY.
88 * Last reviewed on 2008-12-17 (0.10.10)
98 #include <gst/base/gstbasesrc.h>
102 #include "gstapp-marshal.h"
103 #include "gstappsrc.h"
105 struct _GstAppSrcPrivate
113 GstAppStreamType stream_type;
121 guint64 queued_bytes;
123 GstAppStreamType current_type;
127 gboolean emit_signals;
130 GstAppSrcCallbacks callbacks;
132 GDestroyNotify notify;
135 GST_DEBUG_CATEGORY_STATIC (app_src_debug);
136 #define GST_CAT_DEFAULT app_src_debug
147 SIGNAL_END_OF_STREAM,
152 #define DEFAULT_PROP_SIZE -1
153 #define DEFAULT_PROP_STREAM_TYPE GST_APP_STREAM_TYPE_STREAM
154 #define DEFAULT_PROP_MAX_BYTES 200000
155 #define DEFAULT_PROP_FORMAT GST_FORMAT_BYTES
156 #define DEFAULT_PROP_BLOCK FALSE
157 #define DEFAULT_PROP_IS_LIVE FALSE
158 #define DEFAULT_PROP_MIN_LATENCY -1
159 #define DEFAULT_PROP_MAX_LATENCY -1
160 #define DEFAULT_PROP_EMIT_SIGNALS TRUE
161 #define DEFAULT_PROP_MIN_PERCENT 0
180 static GstStaticPadTemplate gst_app_src_template =
181 GST_STATIC_PAD_TEMPLATE ("src",
184 GST_STATIC_CAPS_ANY);
187 gst_app_stream_type_get_type (void)
189 static volatile gsize stream_type_type = 0;
190 static const GEnumValue stream_type[] = {
191 {GST_APP_STREAM_TYPE_STREAM, "GST_APP_STREAM_TYPE_STREAM", "stream"},
192 {GST_APP_STREAM_TYPE_SEEKABLE, "GST_APP_STREAM_TYPE_SEEKABLE", "seekable"},
193 {GST_APP_STREAM_TYPE_RANDOM_ACCESS, "GST_APP_STREAM_TYPE_RANDOM_ACCESS",
198 if (g_once_init_enter (&stream_type_type)) {
199 GType tmp = g_enum_register_static ("GstAppStreamType", stream_type);
200 g_once_init_leave (&stream_type_type, tmp);
203 return (GType) stream_type_type;
206 static void gst_app_src_uri_handler_init (gpointer g_iface,
207 gpointer iface_data);
209 static void gst_app_src_dispose (GObject * object);
210 static void gst_app_src_finalize (GObject * object);
212 static void gst_app_src_set_property (GObject * object, guint prop_id,
213 const GValue * value, GParamSpec * pspec);
214 static void gst_app_src_get_property (GObject * object, guint prop_id,
215 GValue * value, GParamSpec * pspec);
217 static void gst_app_src_set_latencies (GstAppSrc * appsrc,
218 gboolean do_min, guint64 min, gboolean do_max, guint64 max);
220 static GstFlowReturn gst_app_src_create (GstBaseSrc * bsrc,
221 guint64 offset, guint size, GstBuffer ** buf);
222 static gboolean gst_app_src_start (GstBaseSrc * bsrc);
223 static gboolean gst_app_src_stop (GstBaseSrc * bsrc);
224 static gboolean gst_app_src_unlock (GstBaseSrc * bsrc);
225 static gboolean gst_app_src_unlock_stop (GstBaseSrc * bsrc);
226 static gboolean gst_app_src_do_seek (GstBaseSrc * src, GstSegment * segment);
227 static gboolean gst_app_src_is_seekable (GstBaseSrc * src);
228 static gboolean gst_app_src_do_get_size (GstBaseSrc * src, guint64 * size);
229 static gboolean gst_app_src_query (GstBaseSrc * src, GstQuery * query);
231 static GstFlowReturn gst_app_src_push_buffer_action (GstAppSrc * appsrc,
234 static guint gst_app_src_signals[LAST_SIGNAL] = { 0 };
236 #define gst_app_src_parent_class parent_class
237 G_DEFINE_TYPE_WITH_CODE (GstAppSrc, gst_app_src, GST_TYPE_BASE_SRC,
238 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_app_src_uri_handler_init));
241 gst_app_src_class_init (GstAppSrcClass * klass)
243 GObjectClass *gobject_class = (GObjectClass *) klass;
244 GstElementClass *element_class = (GstElementClass *) klass;
245 GstBaseSrcClass *basesrc_class = (GstBaseSrcClass *) klass;
247 GST_DEBUG_CATEGORY_INIT (app_src_debug, "appsrc", 0, "appsrc element");
249 gobject_class->dispose = gst_app_src_dispose;
250 gobject_class->finalize = gst_app_src_finalize;
252 gobject_class->set_property = gst_app_src_set_property;
253 gobject_class->get_property = gst_app_src_get_property;
258 * The GstCaps that will negotiated downstream and will be put
259 * on outgoing buffers.
261 g_object_class_install_property (gobject_class, PROP_CAPS,
262 g_param_spec_boxed ("caps", "Caps",
263 "The allowed caps for the src pad", GST_TYPE_CAPS,
264 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
268 * The format to use for segment events. When the source is producing
269 * timestamped buffers this property should be set to GST_FORMAT_TIME.
271 g_object_class_install_property (gobject_class, PROP_FORMAT,
272 g_param_spec_enum ("format", "Format",
273 "The format of the segment events and seek", GST_TYPE_FORMAT,
274 DEFAULT_PROP_FORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
278 * The total size in bytes of the data stream. If the total size is known, it
279 * is recommended to configure it with this property.
281 g_object_class_install_property (gobject_class, PROP_SIZE,
282 g_param_spec_int64 ("size", "Size",
283 "The size of the data stream in bytes (-1 if unknown)",
284 -1, G_MAXINT64, DEFAULT_PROP_SIZE,
285 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
287 * GstAppSrc::stream-type
289 * The type of stream that this source is producing. For seekable streams the
290 * application should connect to the seek-data signal.
292 g_object_class_install_property (gobject_class, PROP_STREAM_TYPE,
293 g_param_spec_enum ("stream-type", "Stream Type",
294 "the type of the stream", GST_TYPE_APP_STREAM_TYPE,
295 DEFAULT_PROP_STREAM_TYPE,
296 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
298 * GstAppSrc::max-bytes
300 * The maximum amount of bytes that can be queued internally.
301 * After the maximum amount of bytes are queued, appsrc will emit the
302 * "enough-data" signal.
304 g_object_class_install_property (gobject_class, PROP_MAX_BYTES,
305 g_param_spec_uint64 ("max-bytes", "Max bytes",
306 "The maximum number of bytes to queue internally (0 = unlimited)",
307 0, G_MAXUINT64, DEFAULT_PROP_MAX_BYTES,
308 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
312 * When max-bytes are queued and after the enough-data signal has been emited,
313 * block any further push-buffer calls until the amount of queued bytes drops
314 * below the max-bytes limit.
316 g_object_class_install_property (gobject_class, PROP_BLOCK,
317 g_param_spec_boolean ("block", "Block",
318 "Block push-buffer when max-bytes are queued",
319 DEFAULT_PROP_BLOCK, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
324 * Instruct the source to behave like a live source. This includes that it
325 * will only push out buffers in the PLAYING state.
327 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
328 g_param_spec_boolean ("is-live", "Is Live",
329 "Whether to act as a live source",
330 DEFAULT_PROP_IS_LIVE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
332 * GstAppSrc::min-latency
334 * The minimum latency of the source. A value of -1 will use the default
335 * latency calculations of #GstBaseSrc.
337 g_object_class_install_property (gobject_class, PROP_MIN_LATENCY,
338 g_param_spec_int64 ("min-latency", "Min Latency",
339 "The minimum latency (-1 = default)",
340 -1, G_MAXINT64, DEFAULT_PROP_MIN_LATENCY,
341 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
343 * GstAppSrc::max-latency
345 * The maximum latency of the source. A value of -1 means an unlimited amout
348 g_object_class_install_property (gobject_class, PROP_MAX_LATENCY,
349 g_param_spec_int64 ("max-latency", "Max Latency",
350 "The maximum latency (-1 = unlimited)",
351 -1, G_MAXINT64, DEFAULT_PROP_MAX_LATENCY,
352 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
355 * GstAppSrc::emit-signals
357 * Make appsrc emit the "need-data", "enough-data" and "seek-data" signals.
358 * This option is by default enabled for backwards compatibility reasons but
359 * can disabled when needed because signal emission is expensive.
363 g_object_class_install_property (gobject_class, PROP_EMIT_SIGNALS,
364 g_param_spec_boolean ("emit-signals", "Emit signals",
365 "Emit need-data, enough-data and seek-data signals",
366 DEFAULT_PROP_EMIT_SIGNALS,
367 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
370 * GstAppSrc::empty-percent
372 * Make appsrc emit the "need-data" signal when the amount of bytes in the
373 * queue drops below this percentage of max-bytes.
377 g_object_class_install_property (gobject_class, PROP_MIN_PERCENT,
378 g_param_spec_uint ("min-percent", "Min Percent",
379 "Emit need-data when queued bytes drops below this percent of max-bytes",
380 0, 100, DEFAULT_PROP_MIN_PERCENT,
381 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
384 * GstAppSrc::need-data:
385 * @appsrc: the appsrc element that emited the signal
386 * @length: the amount of bytes needed.
388 * Signal that the source needs more data. In the callback or from another
389 * thread you should call push-buffer or end-of-stream.
391 * @length is just a hint and when it is set to -1, any number of bytes can be
392 * pushed into @appsrc.
394 * You can call push-buffer multiple times until the enough-data signal is
397 gst_app_src_signals[SIGNAL_NEED_DATA] =
398 g_signal_new ("need-data", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
399 G_STRUCT_OFFSET (GstAppSrcClass, need_data),
400 NULL, NULL, __gst_app_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
403 * GstAppSrc::enough-data:
404 * @appsrc: the appsrc element that emited the signal
406 * Signal that the source has enough data. It is recommended that the
407 * application stops calling push-buffer until the need-data signal is
408 * emited again to avoid excessive buffer queueing.
410 gst_app_src_signals[SIGNAL_ENOUGH_DATA] =
411 g_signal_new ("enough-data", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
412 G_STRUCT_OFFSET (GstAppSrcClass, enough_data),
413 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
416 * GstAppSrc::seek-data:
417 * @appsrc: the appsrc element that emited the signal
418 * @offset: the offset to seek to
420 * Seek to the given offset. The next push-buffer should produce buffers from
422 * This callback is only called for seekable stream types.
424 * Returns: %TRUE if the seek succeeded.
426 gst_app_src_signals[SIGNAL_SEEK_DATA] =
427 g_signal_new ("seek-data", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
428 G_STRUCT_OFFSET (GstAppSrcClass, seek_data),
429 NULL, NULL, __gst_app_marshal_BOOLEAN__UINT64, G_TYPE_BOOLEAN, 1,
433 * GstAppSrc::push-buffer:
434 * @appsrc: the appsrc
435 * @buffer: a buffer to push
437 * Adds a buffer to the queue of buffers that the appsrc element will
438 * push to its source pad. This function does not take ownership of the
439 * buffer so the buffer needs to be unreffed after calling this function.
441 * When the block property is TRUE, this function can block until free space
442 * becomes available in the queue.
444 gst_app_src_signals[SIGNAL_PUSH_BUFFER] =
445 g_signal_new ("push-buffer", G_TYPE_FROM_CLASS (klass),
446 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstAppSrcClass,
447 push_buffer), NULL, NULL, __gst_app_marshal_ENUM__OBJECT,
448 GST_TYPE_FLOW_RETURN, 1, GST_TYPE_BUFFER);
451 * GstAppSrc::end-of-stream:
452 * @appsrc: the appsrc
454 * Notify @appsrc that no more buffer are available.
456 gst_app_src_signals[SIGNAL_END_OF_STREAM] =
457 g_signal_new ("end-of-stream", G_TYPE_FROM_CLASS (klass),
458 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstAppSrcClass,
459 end_of_stream), NULL, NULL, __gst_app_marshal_ENUM__VOID,
460 GST_TYPE_FLOW_RETURN, 0, G_TYPE_NONE);
462 gst_element_class_set_details_simple (element_class, "AppSrc",
463 "Generic/Source", "Allow the application to feed buffers to a pipeline",
464 "David Schleef <ds@schleef.org>, Wim Taymans <wim.taymans@gmail.com>");
466 gst_element_class_add_pad_template (element_class,
467 gst_static_pad_template_get (&gst_app_src_template));
469 basesrc_class->create = gst_app_src_create;
470 basesrc_class->start = gst_app_src_start;
471 basesrc_class->stop = gst_app_src_stop;
472 basesrc_class->unlock = gst_app_src_unlock;
473 basesrc_class->unlock_stop = gst_app_src_unlock_stop;
474 basesrc_class->do_seek = gst_app_src_do_seek;
475 basesrc_class->is_seekable = gst_app_src_is_seekable;
476 basesrc_class->get_size = gst_app_src_do_get_size;
477 basesrc_class->get_size = gst_app_src_do_get_size;
478 basesrc_class->query = gst_app_src_query;
480 klass->push_buffer = gst_app_src_push_buffer_action;
481 klass->end_of_stream = gst_app_src_end_of_stream;
483 g_type_class_add_private (klass, sizeof (GstAppSrcPrivate));
487 gst_app_src_init (GstAppSrc * appsrc)
489 GstAppSrcPrivate *priv;
491 priv = appsrc->priv = G_TYPE_INSTANCE_GET_PRIVATE (appsrc, GST_TYPE_APP_SRC,
494 priv->mutex = g_mutex_new ();
495 priv->cond = g_cond_new ();
496 priv->queue = g_queue_new ();
498 priv->size = DEFAULT_PROP_SIZE;
499 priv->stream_type = DEFAULT_PROP_STREAM_TYPE;
500 priv->max_bytes = DEFAULT_PROP_MAX_BYTES;
501 priv->format = DEFAULT_PROP_FORMAT;
502 priv->block = DEFAULT_PROP_BLOCK;
503 priv->min_latency = DEFAULT_PROP_MIN_LATENCY;
504 priv->max_latency = DEFAULT_PROP_MAX_LATENCY;
505 priv->emit_signals = DEFAULT_PROP_EMIT_SIGNALS;
506 priv->min_percent = DEFAULT_PROP_MIN_PERCENT;
508 gst_base_src_set_live (GST_BASE_SRC (appsrc), DEFAULT_PROP_IS_LIVE);
512 gst_app_src_flush_queued (GstAppSrc * src)
515 GstAppSrcPrivate *priv = src->priv;
517 while ((buf = g_queue_pop_head (priv->queue)))
518 gst_buffer_unref (buf);
519 priv->queued_bytes = 0;
523 gst_app_src_dispose (GObject * obj)
525 GstAppSrc *appsrc = GST_APP_SRC_CAST (obj);
526 GstAppSrcPrivate *priv = appsrc->priv;
529 gst_caps_unref (priv->caps);
532 gst_app_src_flush_queued (appsrc);
534 G_OBJECT_CLASS (parent_class)->dispose (obj);
538 gst_app_src_finalize (GObject * obj)
540 GstAppSrc *appsrc = GST_APP_SRC_CAST (obj);
541 GstAppSrcPrivate *priv = appsrc->priv;
543 g_mutex_free (priv->mutex);
544 g_cond_free (priv->cond);
545 g_queue_free (priv->queue);
547 G_OBJECT_CLASS (parent_class)->finalize (obj);
551 gst_app_src_set_property (GObject * object, guint prop_id,
552 const GValue * value, GParamSpec * pspec)
554 GstAppSrc *appsrc = GST_APP_SRC_CAST (object);
555 GstAppSrcPrivate *priv = appsrc->priv;
559 gst_app_src_set_caps (appsrc, gst_value_get_caps (value));
562 gst_app_src_set_size (appsrc, g_value_get_int64 (value));
564 case PROP_STREAM_TYPE:
565 gst_app_src_set_stream_type (appsrc, g_value_get_enum (value));
568 gst_app_src_set_max_bytes (appsrc, g_value_get_uint64 (value));
571 priv->format = g_value_get_enum (value);
574 priv->block = g_value_get_boolean (value);
577 gst_base_src_set_live (GST_BASE_SRC (appsrc),
578 g_value_get_boolean (value));
580 case PROP_MIN_LATENCY:
581 gst_app_src_set_latencies (appsrc, TRUE, g_value_get_int64 (value),
584 case PROP_MAX_LATENCY:
585 gst_app_src_set_latencies (appsrc, FALSE, -1, TRUE,
586 g_value_get_int64 (value));
588 case PROP_EMIT_SIGNALS:
589 gst_app_src_set_emit_signals (appsrc, g_value_get_boolean (value));
591 case PROP_MIN_PERCENT:
592 priv->min_percent = g_value_get_uint (value);
595 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
601 gst_app_src_get_property (GObject * object, guint prop_id, GValue * value,
604 GstAppSrc *appsrc = GST_APP_SRC_CAST (object);
605 GstAppSrcPrivate *priv = appsrc->priv;
612 /* we're missing a _take_caps() function to transfer ownership */
613 caps = gst_app_src_get_caps (appsrc);
614 gst_value_set_caps (value, caps);
616 gst_caps_unref (caps);
620 g_value_set_int64 (value, gst_app_src_get_size (appsrc));
622 case PROP_STREAM_TYPE:
623 g_value_set_enum (value, gst_app_src_get_stream_type (appsrc));
626 g_value_set_uint64 (value, gst_app_src_get_max_bytes (appsrc));
629 g_value_set_enum (value, priv->format);
632 g_value_set_boolean (value, priv->block);
635 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (appsrc)));
637 case PROP_MIN_LATENCY:
641 gst_app_src_get_latency (appsrc, &min, NULL);
642 g_value_set_int64 (value, min);
645 case PROP_MAX_LATENCY:
649 gst_app_src_get_latency (appsrc, &max, NULL);
650 g_value_set_int64 (value, max);
653 case PROP_EMIT_SIGNALS:
654 g_value_set_boolean (value, gst_app_src_get_emit_signals (appsrc));
656 case PROP_MIN_PERCENT:
657 g_value_set_uint (value, priv->min_percent);
660 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
666 gst_app_src_unlock (GstBaseSrc * bsrc)
668 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
669 GstAppSrcPrivate *priv = appsrc->priv;
671 g_mutex_lock (priv->mutex);
672 GST_DEBUG_OBJECT (appsrc, "unlock start");
673 priv->flushing = TRUE;
674 g_cond_broadcast (priv->cond);
675 g_mutex_unlock (priv->mutex);
681 gst_app_src_unlock_stop (GstBaseSrc * bsrc)
683 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
684 GstAppSrcPrivate *priv = appsrc->priv;
686 g_mutex_lock (priv->mutex);
687 GST_DEBUG_OBJECT (appsrc, "unlock stop");
688 priv->flushing = FALSE;
689 g_cond_broadcast (priv->cond);
690 g_mutex_unlock (priv->mutex);
696 gst_app_src_start (GstBaseSrc * bsrc)
698 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
699 GstAppSrcPrivate *priv = appsrc->priv;
701 g_mutex_lock (priv->mutex);
702 GST_DEBUG_OBJECT (appsrc, "starting");
703 priv->started = TRUE;
704 /* set the offset to -1 so that we always do a first seek. This is only used
705 * in random-access mode. */
707 priv->flushing = FALSE;
708 g_mutex_unlock (priv->mutex);
710 gst_base_src_set_format (bsrc, priv->format);
716 gst_app_src_stop (GstBaseSrc * bsrc)
718 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
719 GstAppSrcPrivate *priv = appsrc->priv;
721 g_mutex_lock (priv->mutex);
722 GST_DEBUG_OBJECT (appsrc, "stopping");
723 priv->is_eos = FALSE;
724 priv->flushing = TRUE;
725 priv->started = FALSE;
726 gst_app_src_flush_queued (appsrc);
727 g_mutex_unlock (priv->mutex);
733 gst_app_src_is_seekable (GstBaseSrc * src)
735 GstAppSrc *appsrc = GST_APP_SRC_CAST (src);
736 GstAppSrcPrivate *priv = appsrc->priv;
737 gboolean res = FALSE;
739 switch (priv->stream_type) {
740 case GST_APP_STREAM_TYPE_STREAM:
742 case GST_APP_STREAM_TYPE_SEEKABLE:
743 case GST_APP_STREAM_TYPE_RANDOM_ACCESS:
751 gst_app_src_do_get_size (GstBaseSrc * src, guint64 * size)
753 GstAppSrc *appsrc = GST_APP_SRC_CAST (src);
755 *size = gst_app_src_get_size (appsrc);
761 gst_app_src_query (GstBaseSrc * src, GstQuery * query)
763 GstAppSrc *appsrc = GST_APP_SRC_CAST (src);
764 GstAppSrcPrivate *priv = appsrc->priv;
767 switch (GST_QUERY_TYPE (query)) {
768 case GST_QUERY_LATENCY:
770 GstClockTime min, max;
773 /* Query the parent class for the defaults */
774 res = gst_base_src_query_latency (src, &live, &min, &max);
776 /* overwrite with our values when we need to */
777 g_mutex_lock (priv->mutex);
778 if (priv->min_latency != -1)
779 min = priv->min_latency;
780 if (priv->max_latency != -1)
781 max = priv->max_latency;
782 g_mutex_unlock (priv->mutex);
784 gst_query_set_latency (query, live, min, max);
787 case GST_QUERY_SCHEDULING:
789 gboolean pull_mode = FALSE;
791 switch (priv->stream_type) {
792 case GST_APP_STREAM_TYPE_STREAM:
793 case GST_APP_STREAM_TYPE_SEEKABLE:
795 case GST_APP_STREAM_TYPE_RANDOM_ACCESS:
799 gst_query_set_scheduling (query, pull_mode, TRUE, FALSE, 1, -1, 1);
804 res = GST_BASE_SRC_CLASS (parent_class)->query (src, query);
811 /* will be called in push mode */
813 gst_app_src_do_seek (GstBaseSrc * src, GstSegment * segment)
815 GstAppSrc *appsrc = GST_APP_SRC_CAST (src);
816 GstAppSrcPrivate *priv = appsrc->priv;
817 gint64 desired_position;
818 gboolean res = FALSE;
820 desired_position = segment->position;
822 GST_DEBUG_OBJECT (appsrc, "seeking to %" G_GINT64_FORMAT ", format %s",
823 desired_position, gst_format_get_name (segment->format));
825 /* no need to try to seek in streaming mode */
826 if (priv->stream_type == GST_APP_STREAM_TYPE_STREAM)
829 if (priv->callbacks.seek_data)
830 res = priv->callbacks.seek_data (appsrc, desired_position, priv->user_data);
834 g_mutex_lock (priv->mutex);
835 emit = priv->emit_signals;
836 g_mutex_unlock (priv->mutex);
839 g_signal_emit (appsrc, gst_app_src_signals[SIGNAL_SEEK_DATA], 0,
840 desired_position, &res);
844 GST_DEBUG_OBJECT (appsrc, "flushing queue");
845 gst_app_src_flush_queued (appsrc);
846 priv->is_eos = FALSE;
848 GST_WARNING_OBJECT (appsrc, "seek failed");
854 /* must be called with the appsrc mutex */
856 gst_app_src_emit_seek (GstAppSrc * appsrc, guint64 offset)
858 gboolean res = FALSE;
860 GstAppSrcPrivate *priv = appsrc->priv;
862 emit = priv->emit_signals;
863 g_mutex_unlock (priv->mutex);
865 GST_DEBUG_OBJECT (appsrc,
866 "we are at %" G_GINT64_FORMAT ", seek to %" G_GINT64_FORMAT,
867 priv->offset, offset);
869 if (priv->callbacks.seek_data)
870 res = priv->callbacks.seek_data (appsrc, offset, priv->user_data);
872 g_signal_emit (appsrc, gst_app_src_signals[SIGNAL_SEEK_DATA], 0,
875 g_mutex_lock (priv->mutex);
880 /* must be called with the appsrc mutex. After this call things can be
883 gst_app_src_emit_need_data (GstAppSrc * appsrc, guint size)
886 GstAppSrcPrivate *priv = appsrc->priv;
888 emit = priv->emit_signals;
889 g_mutex_unlock (priv->mutex);
891 /* we have no data, we need some. We fire the signal with the size hint. */
892 if (priv->callbacks.need_data)
893 priv->callbacks.need_data (appsrc, size, priv->user_data);
895 g_signal_emit (appsrc, gst_app_src_signals[SIGNAL_NEED_DATA], 0, size,
898 g_mutex_lock (priv->mutex);
899 /* we can be flushing now because we released the lock */
903 gst_app_src_create (GstBaseSrc * bsrc, guint64 offset, guint size,
906 GstAppSrc *appsrc = GST_APP_SRC_CAST (bsrc);
907 GstAppSrcPrivate *priv = appsrc->priv;
911 GST_OBJECT_LOCK (appsrc);
912 caps = priv->caps ? gst_caps_ref (priv->caps) : NULL;
913 if (G_UNLIKELY (priv->size != bsrc->segment.duration &&
914 bsrc->segment.format == GST_FORMAT_BYTES)) {
915 GST_DEBUG_OBJECT (appsrc,
916 "Size changed from %" G_GINT64_FORMAT " to %" G_GINT64_FORMAT,
917 bsrc->segment.duration, priv->size);
918 bsrc->segment.duration = priv->size;
919 GST_OBJECT_UNLOCK (appsrc);
921 gst_element_post_message (GST_ELEMENT (appsrc),
922 gst_message_new_duration (GST_OBJECT (appsrc), GST_FORMAT_BYTES,
925 GST_OBJECT_UNLOCK (appsrc);
928 g_mutex_lock (priv->mutex);
929 /* check flushing first */
930 if (G_UNLIKELY (priv->flushing))
933 if (priv->stream_type == GST_APP_STREAM_TYPE_RANDOM_ACCESS) {
934 /* if we are dealing with a random-access stream, issue a seek if the offset
936 if (G_UNLIKELY (priv->offset != offset)) {
940 res = gst_app_src_emit_seek (appsrc, offset);
942 if (G_UNLIKELY (!res))
943 /* failing to seek is fatal */
946 priv->offset = offset;
951 /* return data as long as we have some */
952 if (!g_queue_is_empty (priv->queue)) {
955 *buf = g_queue_pop_head (priv->queue);
956 buf_size = gst_buffer_get_size (*buf);
958 GST_DEBUG_OBJECT (appsrc, "we have buffer %p of size %u", *buf, buf_size);
960 priv->queued_bytes -= buf_size;
962 /* only update the offset when in random_access mode */
963 if (priv->stream_type == GST_APP_STREAM_TYPE_RANDOM_ACCESS)
964 priv->offset += buf_size;
966 /* signal that we removed an item */
967 g_cond_broadcast (priv->cond);
969 /* see if we go lower than the empty-percent */
970 if (priv->min_percent && priv->max_bytes) {
971 if (priv->queued_bytes * 100 / priv->max_bytes <= priv->min_percent)
972 /* ignore flushing state, we got a buffer and we will return it now.
973 * Errors will be handled in the next round */
974 gst_app_src_emit_need_data (appsrc, size);
979 gst_app_src_emit_need_data (appsrc, size);
981 /* we can be flushing now because we released the lock above */
982 if (G_UNLIKELY (priv->flushing))
985 /* if we have a buffer now, continue the loop and try to return it. In
986 * random-access mode (where a buffer is normally pushed in the above
987 * signal) we can still be empty because the pushed buffer got flushed or
988 * when the application pushes the requested buffer later, we support both
990 if (!g_queue_is_empty (priv->queue))
993 /* no buffer yet, maybe we are EOS, if not, block for more data. */
997 if (G_UNLIKELY (priv->is_eos))
1000 /* nothing to return, wait a while for new data or flushing. */
1001 g_cond_wait (priv->cond, priv->mutex);
1003 g_mutex_unlock (priv->mutex);
1005 gst_caps_unref (caps);
1011 GST_DEBUG_OBJECT (appsrc, "we are flushing");
1012 g_mutex_unlock (priv->mutex);
1014 gst_caps_unref (caps);
1015 return GST_FLOW_WRONG_STATE;
1019 GST_DEBUG_OBJECT (appsrc, "we are EOS");
1020 g_mutex_unlock (priv->mutex);
1022 gst_caps_unref (caps);
1023 return GST_FLOW_UNEXPECTED;
1027 g_mutex_unlock (priv->mutex);
1029 gst_caps_unref (caps);
1030 GST_ELEMENT_ERROR (appsrc, RESOURCE, READ, ("failed to seek"),
1032 return GST_FLOW_ERROR;
1039 * gst_app_src_set_caps:
1040 * @appsrc: a #GstAppSrc
1041 * @caps: caps to set
1043 * Set the capabilities on the appsrc element. This function takes
1044 * a copy of the caps structure. After calling this method, the source will
1045 * only produce caps that match @caps. @caps must be fixed and the caps on the
1046 * buffers must match the caps or left NULL.
1051 gst_app_src_set_caps (GstAppSrc * appsrc, const GstCaps * caps)
1054 GstAppSrcPrivate *priv;
1056 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1058 priv = appsrc->priv;
1060 GST_OBJECT_LOCK (appsrc);
1061 GST_DEBUG_OBJECT (appsrc, "setting caps to %" GST_PTR_FORMAT, caps);
1062 if ((old = priv->caps) != caps) {
1064 priv->caps = gst_caps_copy (caps);
1068 gst_caps_unref (old);
1070 GST_OBJECT_UNLOCK (appsrc);
1074 * gst_app_src_get_caps:
1075 * @appsrc: a #GstAppSrc
1077 * Get the configured caps on @appsrc.
1079 * Returns: the #GstCaps produced by the source. gst_caps_unref() after usage.
1084 gst_app_src_get_caps (GstAppSrc * appsrc)
1087 GstAppSrcPrivate *priv;
1089 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), NULL);
1091 priv = appsrc->priv;
1093 GST_OBJECT_LOCK (appsrc);
1094 if ((caps = priv->caps))
1095 gst_caps_ref (caps);
1096 GST_DEBUG_OBJECT (appsrc, "getting caps of %" GST_PTR_FORMAT, caps);
1097 GST_OBJECT_UNLOCK (appsrc);
1103 * gst_app_src_set_size:
1104 * @appsrc: a #GstAppSrc
1105 * @size: the size to set
1107 * Set the size of the stream in bytes. A value of -1 means that the size is
1113 gst_app_src_set_size (GstAppSrc * appsrc, gint64 size)
1115 GstAppSrcPrivate *priv;
1117 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1119 priv = appsrc->priv;
1121 GST_OBJECT_LOCK (appsrc);
1122 GST_DEBUG_OBJECT (appsrc, "setting size of %" G_GINT64_FORMAT, size);
1124 GST_OBJECT_UNLOCK (appsrc);
1128 * gst_app_src_get_size:
1129 * @appsrc: a #GstAppSrc
1131 * Get the size of the stream in bytes. A value of -1 means that the size is
1134 * Returns: the size of the stream previously set with gst_app_src_set_size();
1139 gst_app_src_get_size (GstAppSrc * appsrc)
1142 GstAppSrcPrivate *priv;
1144 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), -1);
1146 priv = appsrc->priv;
1148 GST_OBJECT_LOCK (appsrc);
1150 GST_DEBUG_OBJECT (appsrc, "getting size of %" G_GINT64_FORMAT, size);
1151 GST_OBJECT_UNLOCK (appsrc);
1157 * gst_app_src_set_stream_type:
1158 * @appsrc: a #GstAppSrc
1159 * @type: the new state
1161 * Set the stream type on @appsrc. For seekable streams, the "seek" signal must
1164 * A stream_type stream
1169 gst_app_src_set_stream_type (GstAppSrc * appsrc, GstAppStreamType type)
1171 GstAppSrcPrivate *priv;
1173 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1175 priv = appsrc->priv;
1177 GST_OBJECT_LOCK (appsrc);
1178 GST_DEBUG_OBJECT (appsrc, "setting stream_type of %d", type);
1179 priv->stream_type = type;
1180 GST_OBJECT_UNLOCK (appsrc);
1184 * gst_app_src_get_stream_type:
1185 * @appsrc: a #GstAppSrc
1187 * Get the stream type. Control the stream type of @appsrc
1188 * with gst_app_src_set_stream_type().
1190 * Returns: the stream type.
1195 gst_app_src_get_stream_type (GstAppSrc * appsrc)
1197 gboolean stream_type;
1198 GstAppSrcPrivate *priv;
1200 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), FALSE);
1202 priv = appsrc->priv;
1204 GST_OBJECT_LOCK (appsrc);
1205 stream_type = priv->stream_type;
1206 GST_DEBUG_OBJECT (appsrc, "getting stream_type of %d", stream_type);
1207 GST_OBJECT_UNLOCK (appsrc);
1213 * gst_app_src_set_max_bytes:
1214 * @appsrc: a #GstAppSrc
1215 * @max: the maximum number of bytes to queue
1217 * Set the maximum amount of bytes that can be queued in @appsrc.
1218 * After the maximum amount of bytes are queued, @appsrc will emit the
1219 * "enough-data" signal.
1224 gst_app_src_set_max_bytes (GstAppSrc * appsrc, guint64 max)
1226 GstAppSrcPrivate *priv;
1228 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1230 priv = appsrc->priv;
1232 g_mutex_lock (priv->mutex);
1233 if (max != priv->max_bytes) {
1234 GST_DEBUG_OBJECT (appsrc, "setting max-bytes to %" G_GUINT64_FORMAT, max);
1235 priv->max_bytes = max;
1236 /* signal the change */
1237 g_cond_broadcast (priv->cond);
1239 g_mutex_unlock (priv->mutex);
1243 * gst_app_src_get_max_bytes:
1244 * @appsrc: a #GstAppSrc
1246 * Get the maximum amount of bytes that can be queued in @appsrc.
1248 * Returns: The maximum amount of bytes that can be queued.
1253 gst_app_src_get_max_bytes (GstAppSrc * appsrc)
1256 GstAppSrcPrivate *priv;
1258 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), 0);
1260 priv = appsrc->priv;
1262 g_mutex_lock (priv->mutex);
1263 result = priv->max_bytes;
1264 GST_DEBUG_OBJECT (appsrc, "getting max-bytes of %" G_GUINT64_FORMAT, result);
1265 g_mutex_unlock (priv->mutex);
1271 gst_app_src_set_latencies (GstAppSrc * appsrc, gboolean do_min, guint64 min,
1272 gboolean do_max, guint64 max)
1274 GstAppSrcPrivate *priv = appsrc->priv;
1275 gboolean changed = FALSE;
1277 g_mutex_lock (priv->mutex);
1278 if (do_min && priv->min_latency != min) {
1279 priv->min_latency = min;
1282 if (do_max && priv->max_latency != max) {
1283 priv->max_latency = max;
1286 g_mutex_unlock (priv->mutex);
1289 GST_DEBUG_OBJECT (appsrc, "posting latency changed");
1290 gst_element_post_message (GST_ELEMENT_CAST (appsrc),
1291 gst_message_new_latency (GST_OBJECT_CAST (appsrc)));
1296 * gst_app_src_set_latency:
1297 * @appsrc: a #GstAppSrc
1298 * @min: the min latency
1299 * @max: the min latency
1301 * Configure the @min and @max latency in @src. If @min is set to -1, the
1302 * default latency calculations for pseudo-live sources will be used.
1307 gst_app_src_set_latency (GstAppSrc * appsrc, guint64 min, guint64 max)
1309 gst_app_src_set_latencies (appsrc, TRUE, min, TRUE, max);
1313 * gst_app_src_get_latency:
1314 * @appsrc: a #GstAppSrc
1315 * @min: the min latency
1316 * @max: the min latency
1318 * Retrieve the min and max latencies in @min and @max respectively.
1323 gst_app_src_get_latency (GstAppSrc * appsrc, guint64 * min, guint64 * max)
1325 GstAppSrcPrivate *priv;
1327 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1329 priv = appsrc->priv;
1331 g_mutex_lock (priv->mutex);
1333 *min = priv->min_latency;
1335 *max = priv->max_latency;
1336 g_mutex_unlock (priv->mutex);
1340 * gst_app_src_set_emit_signals:
1341 * @appsrc: a #GstAppSrc
1342 * @emit: the new state
1344 * Make appsrc emit the "new-preroll" and "new-buffer" signals. This option is
1345 * by default disabled because signal emission is expensive and unneeded when
1346 * the application prefers to operate in pull mode.
1351 gst_app_src_set_emit_signals (GstAppSrc * appsrc, gboolean emit)
1353 GstAppSrcPrivate *priv;
1355 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1357 priv = appsrc->priv;
1359 g_mutex_lock (priv->mutex);
1360 priv->emit_signals = emit;
1361 g_mutex_unlock (priv->mutex);
1365 * gst_app_src_get_emit_signals:
1366 * @appsrc: a #GstAppSrc
1368 * Check if appsrc will emit the "new-preroll" and "new-buffer" signals.
1370 * Returns: %TRUE if @appsrc is emiting the "new-preroll" and "new-buffer"
1376 gst_app_src_get_emit_signals (GstAppSrc * appsrc)
1379 GstAppSrcPrivate *priv;
1381 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), FALSE);
1383 priv = appsrc->priv;
1385 g_mutex_lock (priv->mutex);
1386 result = priv->emit_signals;
1387 g_mutex_unlock (priv->mutex);
1392 static GstFlowReturn
1393 gst_app_src_push_buffer_full (GstAppSrc * appsrc, GstBuffer * buffer,
1396 gboolean first = TRUE;
1397 GstAppSrcPrivate *priv;
1399 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), GST_FLOW_ERROR);
1400 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
1402 priv = appsrc->priv;
1404 g_mutex_lock (priv->mutex);
1407 /* can't accept buffers when we are flushing or EOS */
1414 if (priv->max_bytes && priv->queued_bytes >= priv->max_bytes) {
1415 GST_DEBUG_OBJECT (appsrc,
1416 "queue filled (%" G_GUINT64_FORMAT " >= %" G_GUINT64_FORMAT ")",
1417 priv->queued_bytes, priv->max_bytes);
1422 emit = priv->emit_signals;
1423 /* only signal on the first push */
1424 g_mutex_unlock (priv->mutex);
1426 if (priv->callbacks.enough_data)
1427 priv->callbacks.enough_data (appsrc, priv->user_data);
1429 g_signal_emit (appsrc, gst_app_src_signals[SIGNAL_ENOUGH_DATA], 0,
1432 g_mutex_lock (priv->mutex);
1433 /* continue to check for flushing/eos after releasing the lock */
1438 GST_DEBUG_OBJECT (appsrc, "waiting for free space");
1439 /* we are filled, wait until a buffer gets popped or when we
1441 g_cond_wait (priv->cond, priv->mutex);
1443 /* no need to wait for free space, we just pump more data into the
1444 * queue hoping that the caller reacts to the enough-data signal and
1445 * stops pushing buffers. */
1452 GST_DEBUG_OBJECT (appsrc, "queueing buffer %p", buffer);
1454 gst_buffer_ref (buffer);
1455 g_queue_push_tail (priv->queue, buffer);
1456 priv->queued_bytes += gst_buffer_get_size (buffer);
1457 g_cond_broadcast (priv->cond);
1458 g_mutex_unlock (priv->mutex);
1465 GST_DEBUG_OBJECT (appsrc, "refuse buffer %p, we are flushing", buffer);
1467 gst_buffer_unref (buffer);
1468 g_mutex_unlock (priv->mutex);
1469 return GST_FLOW_WRONG_STATE;
1473 GST_DEBUG_OBJECT (appsrc, "refuse buffer %p, we are EOS", buffer);
1475 gst_buffer_unref (buffer);
1476 g_mutex_unlock (priv->mutex);
1477 return GST_FLOW_UNEXPECTED;
1482 * gst_app_src_push_buffer:
1483 * @appsrc: a #GstAppSrc
1484 * @buffer: a #GstBuffer to push
1486 * Adds a buffer to the queue of buffers that the appsrc element will
1487 * push to its source pad. This function takes ownership of the buffer.
1489 * When the block property is TRUE, this function can block until free
1490 * space becomes available in the queue.
1492 * Returns: #GST_FLOW_OK when the buffer was successfuly queued.
1493 * #GST_FLOW_WRONG_STATE when @appsrc is not PAUSED or PLAYING.
1494 * #GST_FLOW_UNEXPECTED when EOS occured.
1499 gst_app_src_push_buffer (GstAppSrc * appsrc, GstBuffer * buffer)
1501 return gst_app_src_push_buffer_full (appsrc, buffer, TRUE);
1504 /* push a buffer without stealing the ref of the buffer. This is used for the
1506 static GstFlowReturn
1507 gst_app_src_push_buffer_action (GstAppSrc * appsrc, GstBuffer * buffer)
1509 return gst_app_src_push_buffer_full (appsrc, buffer, FALSE);
1513 * gst_app_src_end_of_stream:
1514 * @appsrc: a #GstAppSrc
1516 * Indicates to the appsrc element that the last buffer queued in the
1517 * element is the last buffer of the stream.
1519 * Returns: #GST_FLOW_OK when the EOS was successfuly queued.
1520 * #GST_FLOW_WRONG_STATE when @appsrc is not PAUSED or PLAYING.
1525 gst_app_src_end_of_stream (GstAppSrc * appsrc)
1527 GstAppSrcPrivate *priv;
1529 g_return_val_if_fail (GST_IS_APP_SRC (appsrc), GST_FLOW_ERROR);
1531 priv = appsrc->priv;
1533 g_mutex_lock (priv->mutex);
1534 /* can't accept buffers when we are flushing. We can accept them when we are
1535 * EOS although it will not do anything. */
1539 GST_DEBUG_OBJECT (appsrc, "sending EOS");
1540 priv->is_eos = TRUE;
1541 g_cond_broadcast (priv->cond);
1542 g_mutex_unlock (priv->mutex);
1549 g_mutex_unlock (priv->mutex);
1550 GST_DEBUG_OBJECT (appsrc, "refuse EOS, we are flushing");
1551 return GST_FLOW_WRONG_STATE;
1556 * gst_app_src_set_callbacks:
1557 * @appsrc: a #GstAppSrc
1558 * @callbacks: the callbacks
1559 * @user_data: a user_data argument for the callbacks
1560 * @notify: a destroy notify function
1562 * Set callbacks which will be executed when data is needed, enough data has
1563 * been collected or when a seek should be performed.
1564 * This is an alternative to using the signals, it has lower overhead and is thus
1565 * less expensive, but also less flexible.
1567 * If callbacks are installed, no signals will be emited for performance
1573 gst_app_src_set_callbacks (GstAppSrc * appsrc,
1574 GstAppSrcCallbacks * callbacks, gpointer user_data, GDestroyNotify notify)
1576 GDestroyNotify old_notify;
1577 GstAppSrcPrivate *priv;
1579 g_return_if_fail (GST_IS_APP_SRC (appsrc));
1580 g_return_if_fail (callbacks != NULL);
1582 priv = appsrc->priv;
1584 GST_OBJECT_LOCK (appsrc);
1585 old_notify = priv->notify;
1590 old_data = priv->user_data;
1592 priv->user_data = NULL;
1593 priv->notify = NULL;
1594 GST_OBJECT_UNLOCK (appsrc);
1596 old_notify (old_data);
1598 GST_OBJECT_LOCK (appsrc);
1600 priv->callbacks = *callbacks;
1601 priv->user_data = user_data;
1602 priv->notify = notify;
1603 GST_OBJECT_UNLOCK (appsrc);
1606 /*** GSTURIHANDLER INTERFACE *************************************************/
1609 gst_app_src_uri_get_type (GType type)
1615 gst_app_src_uri_get_protocols (GType type)
1617 static gchar *protocols[] = { (char *) "appsrc", NULL };
1622 static const gchar *
1623 gst_app_src_uri_get_uri (GstURIHandler * handler)
1629 gst_app_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1634 protocol = gst_uri_get_protocol (uri);
1635 ret = !strcmp (protocol, "appsrc");
1642 gst_app_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1644 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1646 iface->get_type = gst_app_src_uri_get_type;
1647 iface->get_protocols = gst_app_src_uri_get_protocols;
1648 iface->get_uri = gst_app_src_uri_get_uri;
1649 iface->set_uri = gst_app_src_uri_set_uri;