2 * Copyright (C) <2006> Edward Hervey <edward@fluendo.com>
3 * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
4 * Copyright (C) <2011> Hewlett-Packard Development Company, L.P.
5 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
6 * Copyright (C) <2013> Collabora Ltd.
7 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 * SECTION:element-decodebin
28 * #GstBin that auto-magically constructs a decoding pipeline using available
29 * decoders and demuxers via auto-plugging.
31 * decodebin is considered stable now and replaces the old #decodebin element.
32 * #uridecodebin uses decodebin internally and is often more convenient to
33 * use, as it creates a suitable source element as well.
36 /* Implementation notes:
38 * The following section describes how decodebin works internally.
40 * The first part of decodebin is its typefind element, which tries
41 * to determine the media type of the input stream. If the type is found
42 * autoplugging starts.
44 * decodebin internally organizes the elements it autoplugged into GstDecodeChains
45 * and GstDecodeGroups. A decode chain is a single chain of decoding, this
46 * means that if decodebin every autoplugs an element with two+ srcpads
47 * (e.g. a demuxer) this will end the chain and everything following this
48 * demuxer will be put into decode groups below the chain. Otherwise,
49 * if an element has a single srcpad that outputs raw data the decode chain
50 * is ended too and a GstDecodePad is stored and blocked.
52 * A decode group combines a number of chains that are created by a
53 * demuxer element. All those chains are connected through a multiqueue to
54 * the demuxer. A new group for the same demuxer is only created if the
55 * demuxer has signaled no-more-pads, in which case all following pads
56 * create a new chain in the new group.
58 * This continues until the top-level decode chain is complete. A decode
59 * chain is complete if it either ends with a blocked endpad, if autoplugging
60 * stopped because no suitable plugins could be found or if the active group
61 * is complete. A decode group on the other hand is complete if all child
62 * chains are complete.
64 * If this happens at some point, all endpads of all active groups are exposed.
65 * For this decodebin adds the endpads, signals no-more-pads and then unblocks
66 * them. Now playback starts.
68 * If one of the chains that end on a endpad receives EOS decodebin checks
69 * if all chains and groups are drained. In that case everything goes into EOS.
70 * If there is a chain where the active group is drained but there exist next
71 * groups, the active group is hidden (endpads are removed) and the next group
72 * is exposed. This means that in some cases more pads may be created even
73 * after the initial no-more-pads signal. This happens for example with
74 * so-called "chained oggs", most commonly found among ogg/vorbis internet
77 * Note 1: If we're talking about blocked endpads this really means that the
78 * *target* pads of the endpads are blocked. Pads that are exposed to the outside
79 * should never ever be blocked!
81 * Note 2: If a group is complete and the parent's chain demuxer adds new pads
82 * but never signaled no-more-pads this additional pads will be ignored!
86 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
87 * with newer GLib versions (>= 2.31.0) */
88 #define GLIB_DISABLE_DEPRECATION_WARNINGS
94 #include <gst/gst-i18n-plugin.h>
98 #include <gst/pbutils/pbutils.h>
100 #include "gstplay-enum.h"
101 #include "gstplayback.h"
102 #include "gstrawcaps.h"
104 /* Also used by gsturidecodebin.c */
105 gint _decode_bin_compare_factories_func (gconstpointer p1, gconstpointer p2);
107 /* generic templates */
108 static GstStaticPadTemplate decoder_bin_sink_template =
109 GST_STATIC_PAD_TEMPLATE ("sink",
112 GST_STATIC_CAPS_ANY);
114 static GstStaticPadTemplate decoder_bin_src_template =
115 GST_STATIC_PAD_TEMPLATE ("src_%u",
118 GST_STATIC_CAPS_ANY);
120 GST_DEBUG_CATEGORY_STATIC (gst_decode_bin_debug);
121 #define GST_CAT_DEFAULT gst_decode_bin_debug
123 typedef struct _GstPendingPad GstPendingPad;
124 typedef struct _GstDecodeElement GstDecodeElement;
125 typedef struct _GstDecodeChain GstDecodeChain;
126 typedef struct _GstDecodeGroup GstDecodeGroup;
127 typedef struct _GstDecodePad GstDecodePad;
128 typedef GstGhostPadClass GstDecodePadClass;
129 typedef struct _GstDecodeBin GstDecodeBin;
130 typedef struct _GstDecodeBinClass GstDecodeBinClass;
132 #define GST_TYPE_DECODE_BIN (gst_decode_bin_get_type())
133 #define GST_DECODE_BIN_CAST(obj) ((GstDecodeBin*)(obj))
134 #define GST_DECODE_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECODE_BIN,GstDecodeBin))
135 #define GST_DECODE_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DECODE_BIN,GstDecodeBinClass))
136 #define GST_IS_DECODE_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DECODE_BIN))
137 #define GST_IS_DECODE_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DECODE_BIN))
142 * The opaque #GstDecodeBin data structure
146 GstBin bin; /* we extend GstBin */
149 GstCaps *caps; /* caps on which to stop decoding */
150 gchar *encoding; /* encoding of subtitles */
151 gboolean use_buffering; /* configure buffering on multiqueues */
154 guint max_size_bytes;
155 guint max_size_buffers;
156 guint64 max_size_time;
157 gboolean post_stream_topology;
158 guint64 connection_speed;
160 GstElement *typefind; /* this holds the typefind object */
162 GMutex expose_lock; /* Protects exposal and removal of groups */
163 GstDecodeChain *decode_chain; /* Top level decode chain */
164 guint nbpads; /* unique identifier for source pads */
166 GMutex factories_lock;
167 guint32 factories_cookie; /* Cookie from last time when factories was updated */
168 GList *factories; /* factories we can use for selecting elements */
170 GMutex subtitle_lock; /* Protects changes to subtitles and encoding */
171 GList *subtitles; /* List of elements with subtitle-encoding,
172 * protected by above mutex! */
174 gboolean have_type; /* if we received the have_type signal */
175 guint have_type_id; /* signal id for have-type from typefind */
177 gboolean async_pending; /* async-start has been emitted */
179 GMutex dyn_lock; /* lock protecting pad blocking */
180 gboolean shutdown; /* if we are shutting down */
181 GList *blocked_pads; /* pads that have set to block */
183 gboolean expose_allstreams; /* Whether to expose unknow type streams or not */
185 GList *filtered; /* elements for which error messages are filtered */
188 struct _GstDecodeBinClass
190 GstBinClass parent_class;
192 /* signal fired when we found a pad that we cannot decode */
193 void (*unknown_type) (GstElement * element, GstPad * pad, GstCaps * caps);
195 /* signal fired to know if we continue trying to decode the given caps */
196 gboolean (*autoplug_continue) (GstElement * element, GstPad * pad,
198 /* signal fired to get a list of factories to try to autoplug */
199 GValueArray *(*autoplug_factories) (GstElement * element, GstPad * pad,
201 /* signal fired to sort the factories */
202 GValueArray *(*autoplug_sort) (GstElement * element, GstPad * pad,
203 GstCaps * caps, GValueArray * factories);
204 /* signal fired to select from the proposed list of factories */
205 GstAutoplugSelectResult (*autoplug_select) (GstElement * element,
206 GstPad * pad, GstCaps * caps, GstElementFactory * factory);
207 /* signal fired when a autoplugged element that is not linked downstream
208 * or exposed wants to query something */
209 gboolean (*autoplug_query) (GstElement * element, GstPad * pad,
212 /* fired when the last group is drained */
213 void (*drained) (GstElement * element);
220 SIGNAL_AUTOPLUG_CONTINUE,
221 SIGNAL_AUTOPLUG_FACTORIES,
222 SIGNAL_AUTOPLUG_SELECT,
223 SIGNAL_AUTOPLUG_SORT,
224 SIGNAL_AUTOPLUG_QUERY,
229 /* automatic sizes, while prerolling we buffer up to 2MB, we ignore time
230 * and buffers in this case. */
231 #define AUTO_PREROLL_SIZE_BYTES 2 * 1024 * 1024
232 #define AUTO_PREROLL_SIZE_BUFFERS 0
233 #define AUTO_PREROLL_NOT_SEEKABLE_SIZE_TIME 10 * GST_SECOND
234 #define AUTO_PREROLL_SEEKABLE_SIZE_TIME 0
236 /* whan playing, keep a max of 2MB of data but try to keep the number of buffers
237 * as low as possible (try to aim for 5 buffers) */
238 #define AUTO_PLAY_SIZE_BYTES 2 * 1024 * 1024
239 #define AUTO_PLAY_SIZE_BUFFERS 5
240 #define AUTO_PLAY_SIZE_TIME 0
242 #define DEFAULT_SUBTITLE_ENCODING NULL
243 #define DEFAULT_USE_BUFFERING FALSE
244 #define DEFAULT_LOW_PERCENT 10
245 #define DEFAULT_HIGH_PERCENT 99
246 /* by default we use the automatic values above */
247 #define DEFAULT_MAX_SIZE_BYTES 0
248 #define DEFAULT_MAX_SIZE_BUFFERS 0
249 #define DEFAULT_MAX_SIZE_TIME 0
250 #define DEFAULT_POST_STREAM_TOPOLOGY FALSE
251 #define DEFAULT_EXPOSE_ALL_STREAMS TRUE
252 #define DEFAULT_CONNECTION_SPEED 0
259 PROP_SUBTITLE_ENCODING,
265 PROP_MAX_SIZE_BUFFERS,
267 PROP_POST_STREAM_TOPOLOGY,
268 PROP_EXPOSE_ALL_STREAMS,
269 PROP_CONNECTION_SPEED,
273 static GstBinClass *parent_class;
274 static guint gst_decode_bin_signals[LAST_SIGNAL] = { 0 };
276 static GstStaticCaps default_raw_caps = GST_STATIC_CAPS (DEFAULT_RAW_CAPS);
278 static void do_async_start (GstDecodeBin * dbin);
279 static void do_async_done (GstDecodeBin * dbin);
281 static void type_found (GstElement * typefind, guint probability,
282 GstCaps * caps, GstDecodeBin * decode_bin);
284 static void decodebin_set_queue_size (GstDecodeBin * dbin,
285 GstElement * multiqueue, gboolean preroll, gboolean seekable);
287 static gboolean gst_decode_bin_autoplug_continue (GstElement * element,
288 GstPad * pad, GstCaps * caps);
289 static GValueArray *gst_decode_bin_autoplug_factories (GstElement *
290 element, GstPad * pad, GstCaps * caps);
291 static GValueArray *gst_decode_bin_autoplug_sort (GstElement * element,
292 GstPad * pad, GstCaps * caps, GValueArray * factories);
293 static GstAutoplugSelectResult gst_decode_bin_autoplug_select (GstElement *
294 element, GstPad * pad, GstCaps * caps, GstElementFactory * factory);
295 static gboolean gst_decode_bin_autoplug_query (GstElement * element,
296 GstPad * pad, GstQuery * query);
298 static void gst_decode_bin_set_property (GObject * object, guint prop_id,
299 const GValue * value, GParamSpec * pspec);
300 static void gst_decode_bin_get_property (GObject * object, guint prop_id,
301 GValue * value, GParamSpec * pspec);
302 static void gst_decode_bin_set_caps (GstDecodeBin * dbin, GstCaps * caps);
303 static GstCaps *gst_decode_bin_get_caps (GstDecodeBin * dbin);
304 static void caps_notify_cb (GstPad * pad, GParamSpec * unused,
305 GstDecodeChain * chain);
307 static GstPad *find_sink_pad (GstElement * element);
308 static GstStateChangeReturn gst_decode_bin_change_state (GstElement * element,
309 GstStateChange transition);
310 static void gst_decode_bin_handle_message (GstBin * bin, GstMessage * message);
312 static gboolean check_upstream_seekable (GstDecodeBin * dbin, GstPad * pad);
314 #define EXPOSE_LOCK(dbin) G_STMT_START { \
315 GST_LOG_OBJECT (dbin, \
316 "expose locking from thread %p", \
318 g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->expose_lock); \
319 GST_LOG_OBJECT (dbin, \
320 "expose locked from thread %p", \
324 #define EXPOSE_UNLOCK(dbin) G_STMT_START { \
325 GST_LOG_OBJECT (dbin, \
326 "expose unlocking from thread %p", \
328 g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->expose_lock); \
331 #define DYN_LOCK(dbin) G_STMT_START { \
332 GST_LOG_OBJECT (dbin, \
333 "dynlocking from thread %p", \
335 g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->dyn_lock); \
336 GST_LOG_OBJECT (dbin, \
337 "dynlocked from thread %p", \
341 #define DYN_UNLOCK(dbin) G_STMT_START { \
342 GST_LOG_OBJECT (dbin, \
343 "dynunlocking from thread %p", \
345 g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->dyn_lock); \
348 #define SUBTITLE_LOCK(dbin) G_STMT_START { \
349 GST_LOG_OBJECT (dbin, \
350 "subtitle locking from thread %p", \
352 g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->subtitle_lock); \
353 GST_LOG_OBJECT (dbin, \
354 "subtitle lock from thread %p", \
358 #define SUBTITLE_UNLOCK(dbin) G_STMT_START { \
359 GST_LOG_OBJECT (dbin, \
360 "subtitle unlocking from thread %p", \
362 g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->subtitle_lock); \
365 struct _GstPendingPad
368 GstDecodeChain *chain;
369 gulong event_probe_id;
372 struct _GstDecodeElement
375 GstElement *capsfilter; /* Optional capsfilter for Parser/Convert */
380 * Streams belonging to the same group/chain of a media file
382 * When changing something here lock the parent chain!
384 struct _GstDecodeGroup
387 GstDecodeChain *parent;
389 GstElement *multiqueue; /* Used for linking all child chains */
390 gulong overrunsig; /* the overrun signal for multiqueue */
392 gboolean overrun; /* TRUE if the multiqueue signaled overrun. This
393 * means that we should really expose the group */
395 gboolean no_more_pads; /* TRUE if the demuxer signaled no-more-pads */
396 gboolean drained; /* TRUE if the all children are drained */
398 GList *children; /* List of GstDecodeChains in this group */
400 GList *reqpads; /* List of RequestPads for multiqueue, there is
401 * exactly one RequestPad per child chain */
404 struct _GstDecodeChain
406 GstDecodeGroup *parent;
409 GMutex lock; /* Protects this chain and its groups */
411 GstPad *pad; /* srcpad that caused creation of this chain */
413 gboolean drained; /* TRUE if the all children are drained */
414 gboolean demuxer; /* TRUE if elements->data is a demuxer */
415 gboolean seekable; /* TRUE if this chain ends on a demuxer and is seekable */
416 GList *elements; /* All elements in this group, first
417 is the latest and most downstream element */
419 /* Note: there are only groups if the last element of this chain
420 * is a demuxer, otherwise the chain will end with an endpad.
421 * The other way around this means, that endpad only exists if this
422 * chain doesn't end with a demuxer! */
424 GstDecodeGroup *active_group; /* Currently active group */
425 GList *next_groups; /* head is newest group, tail is next group.
426 a new group will be created only if the head
427 group had no-more-pads. If it's only exposed
428 all new pads will be ignored! */
429 GList *pending_pads; /* Pads that have no fixed caps yet */
431 GstDecodePad *current_pad; /* Current ending pad of the chain that can't
432 * be exposed yet but would be the same as endpad
433 * once it can be exposed */
434 GstDecodePad *endpad; /* Pad of this chain that could be exposed */
435 gboolean deadend; /* This chain is incomplete and can't be completed,
436 e.g. no suitable decoder could be found
437 e.g. stream got EOS without buffers
439 GstCaps *endcaps; /* Caps that were used when linking to the endpad
440 or that resulted in the deadend
443 /* FIXME: This should be done directly via a thread! */
444 GList *old_groups; /* Groups that should be freed later */
447 static void gst_decode_chain_free (GstDecodeChain * chain);
448 static GstDecodeChain *gst_decode_chain_new (GstDecodeBin * dbin,
449 GstDecodeGroup * group, GstPad * pad);
450 static void gst_decode_group_hide (GstDecodeGroup * group);
451 static void gst_decode_group_free (GstDecodeGroup * group);
452 static GstDecodeGroup *gst_decode_group_new (GstDecodeBin * dbin,
453 GstDecodeChain * chain);
454 static gboolean gst_decode_chain_is_complete (GstDecodeChain * chain);
455 static gboolean gst_decode_chain_expose (GstDecodeChain * chain,
456 GList ** endpads, gboolean * missing_plugin);
457 static gboolean gst_decode_chain_is_drained (GstDecodeChain * chain);
458 static gboolean gst_decode_group_is_complete (GstDecodeGroup * group);
459 static GstPad *gst_decode_group_control_demuxer_pad (GstDecodeGroup * group,
461 static gboolean gst_decode_group_is_drained (GstDecodeGroup * group);
463 static gboolean gst_decode_bin_expose (GstDecodeBin * dbin);
465 #define CHAIN_MUTEX_LOCK(chain) G_STMT_START { \
466 GST_LOG_OBJECT (chain->dbin, \
467 "locking chain %p from thread %p", \
468 chain, g_thread_self ()); \
469 g_mutex_lock (&chain->lock); \
470 GST_LOG_OBJECT (chain->dbin, \
471 "locked chain %p from thread %p", \
472 chain, g_thread_self ()); \
475 #define CHAIN_MUTEX_UNLOCK(chain) G_STMT_START { \
476 GST_LOG_OBJECT (chain->dbin, \
477 "unlocking chain %p from thread %p", \
478 chain, g_thread_self ()); \
479 g_mutex_unlock (&chain->lock); \
484 * GstPad private used for source pads of chains
490 GstDecodeChain *chain;
492 gboolean blocked; /* the *target* pad is blocked */
493 gboolean exposed; /* the pad is exposed */
494 gboolean drained; /* an EOS has been seen on the pad */
499 GType gst_decode_pad_get_type (void);
500 G_DEFINE_TYPE (GstDecodePad, gst_decode_pad, GST_TYPE_GHOST_PAD);
501 #define GST_TYPE_DECODE_PAD (gst_decode_pad_get_type ())
502 #define GST_DECODE_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECODE_PAD,GstDecodePad))
504 static GstDecodePad *gst_decode_pad_new (GstDecodeBin * dbin,
505 GstDecodeChain * chain);
506 static void gst_decode_pad_activate (GstDecodePad * dpad,
507 GstDecodeChain * chain);
508 static void gst_decode_pad_unblock (GstDecodePad * dpad);
509 static void gst_decode_pad_set_blocked (GstDecodePad * dpad, gboolean blocked);
510 static gboolean gst_decode_pad_query (GstPad * pad, GstObject * parent,
513 static void gst_pending_pad_free (GstPendingPad * ppad);
514 static GstPadProbeReturn pad_event_cb (GstPad * pad, GstPadProbeInfo * info,
517 /********************************
518 * Standard GObject boilerplate *
519 ********************************/
521 static void gst_decode_bin_class_init (GstDecodeBinClass * klass);
522 static void gst_decode_bin_init (GstDecodeBin * decode_bin);
523 static void gst_decode_bin_dispose (GObject * object);
524 static void gst_decode_bin_finalize (GObject * object);
527 gst_decode_bin_get_type (void)
529 static GType gst_decode_bin_type = 0;
531 if (!gst_decode_bin_type) {
532 static const GTypeInfo gst_decode_bin_info = {
533 sizeof (GstDecodeBinClass),
536 (GClassInitFunc) gst_decode_bin_class_init,
539 sizeof (GstDecodeBin),
541 (GInstanceInitFunc) gst_decode_bin_init,
545 gst_decode_bin_type =
546 g_type_register_static (GST_TYPE_BIN, "GstDecodeBin",
547 &gst_decode_bin_info, 0);
550 return gst_decode_bin_type;
554 _gst_boolean_accumulator (GSignalInvocationHint * ihint,
555 GValue * return_accu, const GValue * handler_return, gpointer dummy)
559 myboolean = g_value_get_boolean (handler_return);
560 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
561 g_value_set_boolean (return_accu, myboolean);
563 /* stop emission if FALSE */
568 _gst_boolean_or_accumulator (GSignalInvocationHint * ihint,
569 GValue * return_accu, const GValue * handler_return, gpointer dummy)
574 myboolean = g_value_get_boolean (handler_return);
575 retboolean = g_value_get_boolean (return_accu);
577 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
578 g_value_set_boolean (return_accu, myboolean || retboolean);
583 /* we collect the first result */
585 _gst_array_accumulator (GSignalInvocationHint * ihint,
586 GValue * return_accu, const GValue * handler_return, gpointer dummy)
590 array = g_value_get_boxed (handler_return);
591 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
592 g_value_set_boxed (return_accu, array);
598 _gst_select_accumulator (GSignalInvocationHint * ihint,
599 GValue * return_accu, const GValue * handler_return, gpointer dummy)
601 GstAutoplugSelectResult res;
603 res = g_value_get_enum (handler_return);
604 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
605 g_value_set_enum (return_accu, res);
611 _gst_array_hasvalue_accumulator (GSignalInvocationHint * ihint,
612 GValue * return_accu, const GValue * handler_return, gpointer dummy)
616 array = g_value_get_boxed (handler_return);
617 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
618 g_value_set_boxed (return_accu, array);
627 gst_decode_bin_class_init (GstDecodeBinClass * klass)
629 GObjectClass *gobject_klass;
630 GstElementClass *gstelement_klass;
631 GstBinClass *gstbin_klass;
633 gobject_klass = (GObjectClass *) klass;
634 gstelement_klass = (GstElementClass *) klass;
635 gstbin_klass = (GstBinClass *) klass;
637 parent_class = g_type_class_peek_parent (klass);
639 gobject_klass->dispose = gst_decode_bin_dispose;
640 gobject_klass->finalize = gst_decode_bin_finalize;
641 gobject_klass->set_property = gst_decode_bin_set_property;
642 gobject_klass->get_property = gst_decode_bin_get_property;
645 * GstDecodeBin::unknown-type:
646 * @bin: The decodebin.
647 * @pad: The new pad containing caps that cannot be resolved to a 'final'
649 * @caps: The #GstCaps of the pad that cannot be resolved.
651 * This signal is emitted when a pad for which there is no further possible
652 * decoding is added to the decodebin.
654 gst_decode_bin_signals[SIGNAL_UNKNOWN_TYPE] =
655 g_signal_new ("unknown-type", G_TYPE_FROM_CLASS (klass),
656 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, unknown_type),
657 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2,
658 GST_TYPE_PAD, GST_TYPE_CAPS);
661 * GstDecodeBin::autoplug-continue:
662 * @bin: The decodebin.
664 * @caps: The #GstCaps found.
666 * This signal is emitted whenever decodebin finds a new stream. It is
667 * emitted before looking for any elements that can handle that stream.
670 * Invocation of signal handlers stops after the first signal handler
671 * returns #FALSE. Signal handlers are invoked in the order they were
675 * Returns: #TRUE if you wish decodebin to look for elements that can
676 * handle the given @caps. If #FALSE, those caps will be considered as
677 * final and the pad will be exposed as such (see 'pad-added' signal of
680 gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE] =
681 g_signal_new ("autoplug-continue", G_TYPE_FROM_CLASS (klass),
682 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_continue),
683 _gst_boolean_accumulator, NULL, g_cclosure_marshal_generic,
684 G_TYPE_BOOLEAN, 2, GST_TYPE_PAD, GST_TYPE_CAPS);
687 * GstDecodeBin::autoplug-factories:
688 * @bin: The decodebin.
690 * @caps: The #GstCaps found.
692 * This function is emited when an array of possible factories for @caps on
693 * @pad is needed. Decodebin will by default return an array with all
694 * compatible factories, sorted by rank.
696 * If this function returns NULL, @pad will be exposed as a final caps.
698 * If this function returns an empty array, the pad will be considered as
699 * having an unhandled type media type.
702 * Only the signal handler that is connected first will ever by invoked.
703 * Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
704 * signal, they will never be invoked!
707 * Returns: a #GValueArray* with a list of factories to try. The factories are
708 * by default tried in the returned order or based on the index returned by
711 gst_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES] =
712 g_signal_new ("autoplug-factories", G_TYPE_FROM_CLASS (klass),
713 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass,
714 autoplug_factories), _gst_array_accumulator, NULL,
715 g_cclosure_marshal_generic, G_TYPE_VALUE_ARRAY, 2,
716 GST_TYPE_PAD, GST_TYPE_CAPS);
719 * GstDecodeBin::autoplug-sort:
720 * @bin: The decodebin.
722 * @caps: The #GstCaps.
723 * @factories: A #GValueArray of possible #GstElementFactory to use.
725 * Once decodebin has found the possible #GstElementFactory objects to try
726 * for @caps on @pad, this signal is emited. The purpose of the signal is for
727 * the application to perform additional sorting or filtering on the element
730 * The callee should copy and modify @factories or return #NULL if the
731 * order should not change.
734 * Invocation of signal handlers stops after one signal handler has
735 * returned something else than #NULL. Signal handlers are invoked in
736 * the order they were connected in.
737 * Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
738 * signal, they will never be invoked!
741 * Returns: A new sorted array of #GstElementFactory objects.
743 gst_decode_bin_signals[SIGNAL_AUTOPLUG_SORT] =
744 g_signal_new ("autoplug-sort", G_TYPE_FROM_CLASS (klass),
745 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_sort),
746 _gst_array_hasvalue_accumulator, NULL,
747 g_cclosure_marshal_generic, G_TYPE_VALUE_ARRAY, 3, GST_TYPE_PAD,
748 GST_TYPE_CAPS, G_TYPE_VALUE_ARRAY | G_SIGNAL_TYPE_STATIC_SCOPE);
751 * GstDecodeBin::autoplug-select:
752 * @bin: The decodebin.
754 * @caps: The #GstCaps.
755 * @factory: A #GstElementFactory to use.
757 * This signal is emitted once decodebin has found all the possible
758 * #GstElementFactory that can be used to handle the given @caps. For each of
759 * those factories, this signal is emitted.
761 * The signal handler should return a #GST_TYPE_AUTOPLUG_SELECT_RESULT enum
762 * value indicating what decodebin should do next.
764 * A value of #GST_AUTOPLUG_SELECT_TRY will try to autoplug an element from
767 * A value of #GST_AUTOPLUG_SELECT_EXPOSE will expose @pad without plugging
770 * A value of #GST_AUTOPLUG_SELECT_SKIP will skip @factory and move to the
774 * Only the signal handler that is connected first will ever by invoked.
775 * Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
776 * signal, they will never be invoked!
779 * Returns: a #GST_TYPE_AUTOPLUG_SELECT_RESULT that indicates the required
780 * operation. the default handler will always return
781 * #GST_AUTOPLUG_SELECT_TRY.
783 gst_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT] =
784 g_signal_new ("autoplug-select", G_TYPE_FROM_CLASS (klass),
785 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_select),
786 _gst_select_accumulator, NULL,
787 g_cclosure_marshal_generic,
788 GST_TYPE_AUTOPLUG_SELECT_RESULT, 3, GST_TYPE_PAD, GST_TYPE_CAPS,
789 GST_TYPE_ELEMENT_FACTORY);
792 * GstDecodeBin::autoplug-query:
793 * @bin: The decodebin.
794 * @child: The child element doing the query
796 * @query: The #GstQuery.
798 * This signal is emitted whenever an autoplugged element that is
799 * not linked downstream yet and not exposed does a query. It can
800 * be used to tell the element about the downstream supported caps
803 * Returns: #TRUE if the query was handled, #FALSE otherwise.
805 gst_decode_bin_signals[SIGNAL_AUTOPLUG_QUERY] =
806 g_signal_new ("autoplug-query", G_TYPE_FROM_CLASS (klass),
807 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_query),
808 _gst_boolean_or_accumulator, NULL, g_cclosure_marshal_generic,
809 G_TYPE_BOOLEAN, 2, GST_TYPE_PAD,
810 GST_TYPE_QUERY | G_SIGNAL_TYPE_STATIC_SCOPE);
813 * GstDecodeBin::drained
814 * @bin: The decodebin
816 * This signal is emitted once decodebin has finished decoding all the data.
820 gst_decode_bin_signals[SIGNAL_DRAINED] =
821 g_signal_new ("drained", G_TYPE_FROM_CLASS (klass),
822 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, drained),
823 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 0, G_TYPE_NONE);
825 g_object_class_install_property (gobject_klass, PROP_CAPS,
826 g_param_spec_boxed ("caps", "Caps", "The caps on which to stop decoding.",
827 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
829 g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
830 g_param_spec_string ("subtitle-encoding", "subtitle encoding",
831 "Encoding to assume if input subtitles are not in UTF-8 encoding. "
832 "If not set, the GST_SUBTITLE_ENCODING environment variable will "
833 "be checked for an encoding to use. If that is not set either, "
834 "ISO-8859-15 will be assumed.", NULL,
835 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
837 g_object_class_install_property (gobject_klass, PROP_SINK_CAPS,
838 g_param_spec_boxed ("sink-caps", "Sink Caps",
839 "The caps of the input data. (NULL = use typefind element)",
840 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
843 * GstDecodeBin::use-buffering
845 * Activate buffering in decodebin. This will instruct the multiqueues behind
846 * decoders to emit BUFFERING messages.
850 g_object_class_install_property (gobject_klass, PROP_USE_BUFFERING,
851 g_param_spec_boolean ("use-buffering", "Use Buffering",
852 "Emit GST_MESSAGE_BUFFERING based on low-/high-percent thresholds",
853 DEFAULT_USE_BUFFERING, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
856 * GstDecodeBin:low-percent
858 * Low threshold percent for buffering to start.
862 g_object_class_install_property (gobject_klass, PROP_LOW_PERCENT,
863 g_param_spec_int ("low-percent", "Low percent",
864 "Low threshold for buffering to start", 0, 100,
865 DEFAULT_LOW_PERCENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
867 * GstDecodeBin:high-percent
869 * High threshold percent for buffering to finish.
873 g_object_class_install_property (gobject_klass, PROP_HIGH_PERCENT,
874 g_param_spec_int ("high-percent", "High percent",
875 "High threshold for buffering to finish", 0, 100,
876 DEFAULT_HIGH_PERCENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
879 * GstDecodeBin:max-size-bytes
881 * Max amount of bytes in the queue (0=automatic).
885 g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_BYTES,
886 g_param_spec_uint ("max-size-bytes", "Max. size (bytes)",
887 "Max. amount of bytes in the queue (0=automatic)",
888 0, G_MAXUINT, DEFAULT_MAX_SIZE_BYTES,
889 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
891 * GstDecodeBin:max-size-buffers
893 * Max amount of buffers in the queue (0=automatic).
897 g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_BUFFERS,
898 g_param_spec_uint ("max-size-buffers", "Max. size (buffers)",
899 "Max. number of buffers in the queue (0=automatic)",
900 0, G_MAXUINT, DEFAULT_MAX_SIZE_BUFFERS,
901 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
903 * GstDecodeBin:max-size-time
905 * Max amount of time in the queue (in ns, 0=automatic).
909 g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_TIME,
910 g_param_spec_uint64 ("max-size-time", "Max. size (ns)",
911 "Max. amount of data in the queue (in ns, 0=automatic)",
913 DEFAULT_MAX_SIZE_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
916 * GstDecodeBin::post-stream-topology
918 * Post stream-topology messages on the bus every time the topology changes.
922 g_object_class_install_property (gobject_klass, PROP_POST_STREAM_TOPOLOGY,
923 g_param_spec_boolean ("post-stream-topology", "Post Stream Topology",
924 "Post stream-topology messages",
925 DEFAULT_POST_STREAM_TOPOLOGY,
926 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
929 * GstDecodeBin::expose-all-streams
931 * Expose streams of unknown type.
933 * If set to %FALSE, then only the streams that can be decoded to the final
934 * caps (see 'caps' property) will have a pad exposed. Streams that do not
935 * match those caps but could have been decoded will not have decoder plugged
936 * in internally and will not have a pad exposed.
940 g_object_class_install_property (gobject_klass, PROP_EXPOSE_ALL_STREAMS,
941 g_param_spec_boolean ("expose-all-streams", "Expose All Streams",
942 "Expose all streams, including those of unknown type or that don't match the 'caps' property",
943 DEFAULT_EXPOSE_ALL_STREAMS,
944 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
947 * GstDecodeBin2::connection-speed
949 * Network connection speed in kbps (0 = unknownw)
953 g_object_class_install_property (gobject_klass, PROP_CONNECTION_SPEED,
954 g_param_spec_uint64 ("connection-speed", "Connection Speed",
955 "Network connection speed in kbps (0 = unknown)",
956 0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
957 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
961 klass->autoplug_continue =
962 GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_continue);
963 klass->autoplug_factories =
964 GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_factories);
965 klass->autoplug_sort = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_sort);
966 klass->autoplug_select = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_select);
967 klass->autoplug_query = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_query);
969 gst_element_class_add_pad_template (gstelement_klass,
970 gst_static_pad_template_get (&decoder_bin_sink_template));
971 gst_element_class_add_pad_template (gstelement_klass,
972 gst_static_pad_template_get (&decoder_bin_src_template));
974 gst_element_class_set_static_metadata (gstelement_klass,
975 "Decoder Bin", "Generic/Bin/Decoder",
976 "Autoplug and decode to raw media",
977 "Edward Hervey <edward.hervey@collabora.co.uk>, "
978 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
980 gstelement_klass->change_state =
981 GST_DEBUG_FUNCPTR (gst_decode_bin_change_state);
983 gstbin_klass->handle_message =
984 GST_DEBUG_FUNCPTR (gst_decode_bin_handle_message);
986 g_type_class_ref (GST_TYPE_DECODE_PAD);
990 _decode_bin_compare_factories_func (gconstpointer p1, gconstpointer p2)
992 GstPluginFeature *f1, *f2;
994 gboolean is_parser1, is_parser2;
996 f1 = (GstPluginFeature *) p1;
997 f2 = (GstPluginFeature *) p2;
999 is_parser1 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f1),
1000 GST_ELEMENT_FACTORY_TYPE_PARSER);
1001 is_parser2 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f2),
1002 GST_ELEMENT_FACTORY_TYPE_PARSER);
1005 /* We want all parsers first as we always want to plug parsers
1006 * before decoders */
1007 if (is_parser1 && !is_parser2)
1009 else if (!is_parser1 && is_parser2)
1012 /* And if it's a both a parser we first sort by rank
1013 * and then by factory name */
1014 diff = gst_plugin_feature_get_rank (f2) - gst_plugin_feature_get_rank (f1);
1018 diff = strcmp (GST_OBJECT_NAME (f2), GST_OBJECT_NAME (f1));
1023 /* Must be called with factories lock! */
1025 gst_decode_bin_update_factories_list (GstDecodeBin * dbin)
1029 cookie = gst_registry_get_feature_list_cookie (gst_registry_get ());
1030 if (!dbin->factories || dbin->factories_cookie != cookie) {
1031 if (dbin->factories)
1032 gst_plugin_feature_list_free (dbin->factories);
1034 gst_element_factory_list_get_elements
1035 (GST_ELEMENT_FACTORY_TYPE_DECODABLE, GST_RANK_MARGINAL);
1037 g_list_sort (dbin->factories, _decode_bin_compare_factories_func);
1038 dbin->factories_cookie = cookie;
1043 gst_decode_bin_init (GstDecodeBin * decode_bin)
1045 GST_OBJECT_FLAG_SET (decode_bin, GST_BIN_FLAG_NO_RESYNC);
1047 /* first filter out the interesting element factories */
1048 g_mutex_init (&decode_bin->factories_lock);
1050 /* we create the typefind element only once */
1051 decode_bin->typefind = gst_element_factory_make ("typefind", "typefind");
1052 if (!decode_bin->typefind) {
1053 g_warning ("can't find typefind element, decodebin will not work");
1057 GstPadTemplate *pad_tmpl;
1059 /* add the typefind element */
1060 if (!gst_bin_add (GST_BIN (decode_bin), decode_bin->typefind)) {
1061 g_warning ("Could not add typefind element, decodebin will not work");
1062 gst_object_unref (decode_bin->typefind);
1063 decode_bin->typefind = NULL;
1066 /* get the sinkpad */
1067 pad = gst_element_get_static_pad (decode_bin->typefind, "sink");
1069 /* get the pad template */
1070 pad_tmpl = gst_static_pad_template_get (&decoder_bin_sink_template);
1072 /* ghost the sink pad to ourself */
1073 gpad = gst_ghost_pad_new_from_template ("sink", pad, pad_tmpl);
1074 gst_pad_set_active (gpad, TRUE);
1075 gst_element_add_pad (GST_ELEMENT (decode_bin), gpad);
1077 gst_object_unref (pad_tmpl);
1078 gst_object_unref (pad);
1080 /* connect a signal to find out when the typefind element found
1082 decode_bin->have_type_id =
1083 g_signal_connect (G_OBJECT (decode_bin->typefind), "have-type",
1084 G_CALLBACK (type_found), decode_bin);
1087 g_mutex_init (&decode_bin->expose_lock);
1088 decode_bin->decode_chain = NULL;
1090 g_mutex_init (&decode_bin->dyn_lock);
1091 decode_bin->shutdown = FALSE;
1092 decode_bin->blocked_pads = NULL;
1094 g_mutex_init (&decode_bin->subtitle_lock);
1096 decode_bin->encoding = g_strdup (DEFAULT_SUBTITLE_ENCODING);
1097 decode_bin->caps = gst_static_caps_get (&default_raw_caps);
1098 decode_bin->use_buffering = DEFAULT_USE_BUFFERING;
1099 decode_bin->low_percent = DEFAULT_LOW_PERCENT;
1100 decode_bin->high_percent = DEFAULT_HIGH_PERCENT;
1102 decode_bin->max_size_bytes = DEFAULT_MAX_SIZE_BYTES;
1103 decode_bin->max_size_buffers = DEFAULT_MAX_SIZE_BUFFERS;
1104 decode_bin->max_size_time = DEFAULT_MAX_SIZE_TIME;
1106 decode_bin->expose_allstreams = DEFAULT_EXPOSE_ALL_STREAMS;
1107 decode_bin->connection_speed = DEFAULT_CONNECTION_SPEED;
1111 gst_decode_bin_dispose (GObject * object)
1113 GstDecodeBin *decode_bin;
1115 decode_bin = GST_DECODE_BIN (object);
1117 if (decode_bin->factories)
1118 gst_plugin_feature_list_free (decode_bin->factories);
1119 decode_bin->factories = NULL;
1121 if (decode_bin->decode_chain)
1122 gst_decode_chain_free (decode_bin->decode_chain);
1123 decode_bin->decode_chain = NULL;
1125 if (decode_bin->caps)
1126 gst_caps_unref (decode_bin->caps);
1127 decode_bin->caps = NULL;
1129 g_free (decode_bin->encoding);
1130 decode_bin->encoding = NULL;
1132 g_list_free (decode_bin->subtitles);
1133 decode_bin->subtitles = NULL;
1135 G_OBJECT_CLASS (parent_class)->dispose (object);
1139 gst_decode_bin_finalize (GObject * object)
1141 GstDecodeBin *decode_bin;
1143 decode_bin = GST_DECODE_BIN (object);
1145 g_mutex_clear (&decode_bin->expose_lock);
1146 g_mutex_clear (&decode_bin->dyn_lock);
1147 g_mutex_clear (&decode_bin->subtitle_lock);
1148 g_mutex_clear (&decode_bin->factories_lock);
1150 G_OBJECT_CLASS (parent_class)->finalize (object);
1154 * Changes the caps on which decodebin will stop decoding.
1155 * Will unref the previously set one. The refcount of the given caps will be
1157 * @caps can be NULL.
1162 gst_decode_bin_set_caps (GstDecodeBin * dbin, GstCaps * caps)
1164 GST_DEBUG_OBJECT (dbin, "Setting new caps: %" GST_PTR_FORMAT, caps);
1166 GST_OBJECT_LOCK (dbin);
1167 gst_caps_replace (&dbin->caps, caps);
1168 GST_OBJECT_UNLOCK (dbin);
1172 * Returns the currently configured caps on which decodebin will stop decoding.
1173 * The returned caps (if not NULL), will have its refcount incremented.
1178 gst_decode_bin_get_caps (GstDecodeBin * dbin)
1182 GST_DEBUG_OBJECT (dbin, "Getting currently set caps");
1184 GST_OBJECT_LOCK (dbin);
1187 gst_caps_ref (caps);
1188 GST_OBJECT_UNLOCK (dbin);
1194 gst_decode_bin_set_sink_caps (GstDecodeBin * dbin, GstCaps * caps)
1196 GST_DEBUG_OBJECT (dbin, "Setting new caps: %" GST_PTR_FORMAT, caps);
1198 g_object_set (dbin->typefind, "force-caps", caps, NULL);
1202 gst_decode_bin_get_sink_caps (GstDecodeBin * dbin)
1206 GST_DEBUG_OBJECT (dbin, "Getting currently set caps");
1208 g_object_get (dbin->typefind, "force-caps", &caps, NULL);
1214 gst_decode_bin_set_subs_encoding (GstDecodeBin * dbin, const gchar * encoding)
1218 GST_DEBUG_OBJECT (dbin, "Setting new encoding: %s", GST_STR_NULL (encoding));
1220 SUBTITLE_LOCK (dbin);
1221 g_free (dbin->encoding);
1222 dbin->encoding = g_strdup (encoding);
1224 /* set the subtitle encoding on all added elements */
1225 for (walk = dbin->subtitles; walk; walk = g_list_next (walk)) {
1226 g_object_set (G_OBJECT (walk->data), "subtitle-encoding", dbin->encoding,
1229 SUBTITLE_UNLOCK (dbin);
1233 gst_decode_bin_get_subs_encoding (GstDecodeBin * dbin)
1237 GST_DEBUG_OBJECT (dbin, "Getting currently set encoding");
1239 SUBTITLE_LOCK (dbin);
1240 encoding = g_strdup (dbin->encoding);
1241 SUBTITLE_UNLOCK (dbin);
1247 gst_decode_bin_set_property (GObject * object, guint prop_id,
1248 const GValue * value, GParamSpec * pspec)
1252 dbin = GST_DECODE_BIN (object);
1256 gst_decode_bin_set_caps (dbin, g_value_get_boxed (value));
1258 case PROP_SUBTITLE_ENCODING:
1259 gst_decode_bin_set_subs_encoding (dbin, g_value_get_string (value));
1261 case PROP_SINK_CAPS:
1262 gst_decode_bin_set_sink_caps (dbin, g_value_get_boxed (value));
1264 case PROP_USE_BUFFERING:
1265 dbin->use_buffering = g_value_get_boolean (value);
1267 case PROP_LOW_PERCENT:
1268 dbin->low_percent = g_value_get_int (value);
1270 case PROP_HIGH_PERCENT:
1271 dbin->high_percent = g_value_get_int (value);
1273 case PROP_MAX_SIZE_BYTES:
1274 dbin->max_size_bytes = g_value_get_uint (value);
1276 case PROP_MAX_SIZE_BUFFERS:
1277 dbin->max_size_buffers = g_value_get_uint (value);
1279 case PROP_MAX_SIZE_TIME:
1280 dbin->max_size_time = g_value_get_uint64 (value);
1282 case PROP_POST_STREAM_TOPOLOGY:
1283 dbin->post_stream_topology = g_value_get_boolean (value);
1285 case PROP_EXPOSE_ALL_STREAMS:
1286 dbin->expose_allstreams = g_value_get_boolean (value);
1288 case PROP_CONNECTION_SPEED:
1289 GST_OBJECT_LOCK (dbin);
1290 dbin->connection_speed = g_value_get_uint64 (value) * 1000;
1291 GST_OBJECT_UNLOCK (dbin);
1294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1300 gst_decode_bin_get_property (GObject * object, guint prop_id,
1301 GValue * value, GParamSpec * pspec)
1305 dbin = GST_DECODE_BIN (object);
1308 g_value_take_boxed (value, gst_decode_bin_get_caps (dbin));
1310 case PROP_SUBTITLE_ENCODING:
1311 g_value_take_string (value, gst_decode_bin_get_subs_encoding (dbin));
1313 case PROP_SINK_CAPS:
1314 g_value_take_boxed (value, gst_decode_bin_get_sink_caps (dbin));
1316 case PROP_USE_BUFFERING:
1317 g_value_set_boolean (value, dbin->use_buffering);
1319 case PROP_LOW_PERCENT:
1320 g_value_set_int (value, dbin->low_percent);
1322 case PROP_HIGH_PERCENT:
1323 g_value_set_int (value, dbin->high_percent);
1325 case PROP_MAX_SIZE_BYTES:
1326 g_value_set_uint (value, dbin->max_size_bytes);
1328 case PROP_MAX_SIZE_BUFFERS:
1329 g_value_set_uint (value, dbin->max_size_buffers);
1331 case PROP_MAX_SIZE_TIME:
1332 g_value_set_uint64 (value, dbin->max_size_time);
1334 case PROP_POST_STREAM_TOPOLOGY:
1335 g_value_set_boolean (value, dbin->post_stream_topology);
1337 case PROP_EXPOSE_ALL_STREAMS:
1338 g_value_set_boolean (value, dbin->expose_allstreams);
1340 case PROP_CONNECTION_SPEED:
1341 GST_OBJECT_LOCK (dbin);
1342 g_value_set_uint64 (value, dbin->connection_speed / 1000);
1343 GST_OBJECT_UNLOCK (dbin);
1346 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1353 * Default autoplug signal handlers
1356 gst_decode_bin_autoplug_continue (GstElement * element, GstPad * pad,
1359 GST_DEBUG_OBJECT (element, "autoplug-continue returns TRUE");
1361 /* by default we always continue */
1365 static GValueArray *
1366 gst_decode_bin_autoplug_factories (GstElement * element, GstPad * pad,
1370 GValueArray *result;
1371 GstDecodeBin *dbin = GST_DECODE_BIN_CAST (element);
1373 GST_DEBUG_OBJECT (element, "finding factories");
1375 /* return all compatible factories for caps */
1376 g_mutex_lock (&dbin->factories_lock);
1377 gst_decode_bin_update_factories_list (dbin);
1379 gst_element_factory_list_filter (dbin->factories, caps, GST_PAD_SINK,
1381 g_mutex_unlock (&dbin->factories_lock);
1383 result = g_value_array_new (g_list_length (list));
1384 for (tmp = list; tmp; tmp = tmp->next) {
1385 GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (tmp->data);
1386 GValue val = { 0, };
1388 g_value_init (&val, G_TYPE_OBJECT);
1389 g_value_set_object (&val, factory);
1390 g_value_array_append (result, &val);
1391 g_value_unset (&val);
1393 gst_plugin_feature_list_free (list);
1395 GST_DEBUG_OBJECT (element, "autoplug-factories returns %p", result);
1400 static GValueArray *
1401 gst_decode_bin_autoplug_sort (GstElement * element, GstPad * pad,
1402 GstCaps * caps, GValueArray * factories)
1407 static GstAutoplugSelectResult
1408 gst_decode_bin_autoplug_select (GstElement * element, GstPad * pad,
1409 GstCaps * caps, GstElementFactory * factory)
1411 GST_DEBUG_OBJECT (element, "default autoplug-select returns TRY");
1414 return GST_AUTOPLUG_SELECT_TRY;
1418 gst_decode_bin_autoplug_query (GstElement * element, GstPad * pad,
1421 /* No query handled here */
1429 static gboolean are_final_caps (GstDecodeBin * dbin, GstCaps * caps);
1430 static gboolean is_demuxer_element (GstElement * srcelement);
1432 static gboolean connect_pad (GstDecodeBin * dbin, GstElement * src,
1433 GstDecodePad * dpad, GstPad * pad, GstCaps * caps, GValueArray * factories,
1434 GstDecodeChain * chain);
1435 static gboolean connect_element (GstDecodeBin * dbin, GstElement * element,
1436 GstDecodeChain * chain);
1437 static void expose_pad (GstDecodeBin * dbin, GstElement * src,
1438 GstDecodePad * dpad, GstPad * pad, GstCaps * caps, GstDecodeChain * chain);
1440 static void pad_added_cb (GstElement * element, GstPad * pad,
1441 GstDecodeChain * chain);
1442 static void pad_removed_cb (GstElement * element, GstPad * pad,
1443 GstDecodeChain * chain);
1444 static void no_more_pads_cb (GstElement * element, GstDecodeChain * chain);
1446 static GstDecodeGroup *gst_decode_chain_get_current_group (GstDecodeChain *
1449 /* called when a new pad is discovered. It will perform some basic actions
1450 * before trying to link something to it.
1452 * - Check the caps, don't do anything when there are no caps or when they have
1454 * - signal AUTOPLUG_CONTINUE to check if we need to continue autoplugging this
1456 * - if the caps are non-fixed, setup a handler to continue autoplugging when
1457 * the caps become fixed (connect to notify::caps).
1458 * - get list of factories to autoplug.
1459 * - continue autoplugging to one of the factories.
1462 analyze_new_pad (GstDecodeBin * dbin, GstElement * src, GstPad * pad,
1463 GstCaps * caps, GstDecodeChain * chain)
1465 gboolean apcontinue = TRUE;
1466 GValueArray *factories = NULL, *result = NULL;
1468 GstElementFactory *factory;
1469 const gchar *classification;
1470 gboolean is_parser_converter = FALSE;
1473 GST_DEBUG_OBJECT (dbin, "Pad %s:%s caps:%" GST_PTR_FORMAT,
1474 GST_DEBUG_PAD_NAME (pad), caps);
1477 && src != ((GstDecodeElement *) chain->elements->data)->element
1478 && src != ((GstDecodeElement *) chain->elements->data)->capsfilter) {
1479 GST_ERROR_OBJECT (dbin, "New pad from not the last element in this chain");
1483 if (chain->endpad) {
1484 GST_ERROR_OBJECT (dbin, "New pad in a chain that is already complete");
1488 if (chain->demuxer) {
1489 GstDecodeGroup *group;
1490 GstDecodeChain *oldchain = chain;
1492 if (chain->current_pad)
1493 gst_object_unref (chain->current_pad);
1494 chain->current_pad = NULL;
1496 /* we are adding a new pad for a demuxer (see is_demuxer_element(),
1497 * start a new chain for it */
1498 CHAIN_MUTEX_LOCK (oldchain);
1499 group = gst_decode_chain_get_current_group (chain);
1500 if (group && !g_list_find (group->children, chain)) {
1501 chain = gst_decode_chain_new (dbin, group, pad);
1502 group->children = g_list_prepend (group->children, chain);
1504 CHAIN_MUTEX_UNLOCK (oldchain);
1506 GST_WARNING_OBJECT (dbin, "No current group");
1511 if ((caps == NULL) || gst_caps_is_empty (caps))
1514 if (gst_caps_is_any (caps))
1517 if (!chain->current_pad)
1518 chain->current_pad = gst_decode_pad_new (dbin, chain);
1520 dpad = gst_object_ref (chain->current_pad);
1521 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), pad);
1523 /* 1. Emit 'autoplug-continue' the result will tell us if this pads needs
1524 * further autoplugging. Only do this for fixed caps, for unfixed caps
1525 * we will later come here again from the notify::caps handler. The
1526 * problem with unfixed caps is that we can reliably tell if the output
1527 * is e.g. accepted by a sink because only parts of the possible final
1528 * caps might be accepted by the sink. */
1529 if (gst_caps_is_fixed (caps))
1530 g_signal_emit (G_OBJECT (dbin),
1531 gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE], 0, dpad, caps,
1536 /* 1.a if autoplug-continue is FALSE or caps is a raw format, goto pad_is_final */
1537 if ((!apcontinue) || are_final_caps (dbin, caps))
1540 /* 1.b For Parser/Converter that can output different stream formats
1541 * we insert a capsfilter with the sorted caps of all possible next
1542 * elements and continue with the capsfilter srcpad */
1543 factory = gst_element_get_factory (src);
1545 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1546 is_parser_converter = (strstr (classification, "Parser")
1547 && strstr (classification, "Converter"));
1549 /* 1.c when the caps are not fixed yet, we can't be sure what element to
1550 * connect. We delay autoplugging until the caps are fixed */
1551 if (!is_parser_converter && !gst_caps_is_fixed (caps))
1554 /* 1.d else get the factories and if there's no compatible factory goto
1556 g_signal_emit (G_OBJECT (dbin),
1557 gst_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES], 0, dpad, caps,
1560 /* NULL means that we can expose the pad */
1561 if (factories == NULL)
1564 /* if the array is empty, we have a type for which we have no decoder */
1565 if (factories->n_values == 0) {
1566 if (!dbin->expose_allstreams) {
1567 GstCaps *raw = gst_static_caps_get (&default_raw_caps);
1569 /* If the caps are raw, this just means we don't want to expose them */
1570 if (gst_caps_can_intersect (raw, caps)) {
1571 g_value_array_free (factories);
1572 gst_caps_unref (raw);
1573 gst_object_unref (dpad);
1574 goto discarded_type;
1576 gst_caps_unref (raw);
1579 /* if not we have a unhandled type with no compatible factories */
1580 g_value_array_free (factories);
1581 gst_object_unref (dpad);
1585 /* 1.e sort some more. */
1586 g_signal_emit (G_OBJECT (dbin),
1587 gst_decode_bin_signals[SIGNAL_AUTOPLUG_SORT], 0, dpad, caps, factories,
1590 g_value_array_free (factories);
1594 /* At this point we have a potential decoder, but we might not need it
1595 * if it doesn't match the output caps */
1596 if (!dbin->expose_allstreams && gst_caps_is_fixed (caps)) {
1599 gboolean dontuse = FALSE;
1601 GST_DEBUG ("Checking if we can abort early");
1603 /* 1.f Do an early check to see if the candidates are potential decoders, but
1604 * due to the fact that they decode to a mediatype that is not final we don't
1607 for (i = 0; i < factories->n_values && !dontuse; i++) {
1608 GstElementFactory *factory =
1609 g_value_get_object (g_value_array_get_nth (factories, i));
1612 /* We are only interested in skipping decoders */
1613 if (strstr (gst_element_factory_get_metadata (factory,
1614 GST_ELEMENT_METADATA_KLASS), "Decoder")) {
1616 GST_DEBUG ("Trying factory %s",
1617 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
1619 /* Check the source pad template caps to see if they match raw caps but don't match
1621 for (tmps = gst_element_factory_get_static_pad_templates (factory);
1622 tmps && !dontuse; tmps = tmps->next) {
1623 GstStaticPadTemplate *st = (GstStaticPadTemplate *) tmps->data;
1624 if (st->direction != GST_PAD_SRC)
1626 tcaps = gst_static_pad_template_get_caps (st);
1630 /* Emit autoplug-continue to see if the caps are considered to be raw caps */
1631 g_signal_emit (G_OBJECT (dbin),
1632 gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE], 0, dpad, tcaps,
1635 /* If autoplug-continue returns TRUE and the caps are not final, don't use them */
1636 if (apcontinue && !are_final_caps (dbin, tcaps))
1638 gst_caps_unref (tcaps);
1644 gst_object_unref (dpad);
1645 g_value_array_free (factories);
1646 goto discarded_type;
1650 /* 1.g now get the factory template caps and insert the capsfilter if this
1651 * is a parser/converter
1653 if (is_parser_converter) {
1654 GstCaps *filter_caps;
1657 GstDecodeElement *delem;
1659 g_assert (chain->elements != NULL);
1660 delem = (GstDecodeElement *) chain->elements->data;
1662 filter_caps = gst_caps_new_empty ();
1663 for (i = 0; i < factories->n_values; i++) {
1664 GstElementFactory *factory =
1665 g_value_get_object (g_value_array_get_nth (factories, i));
1666 GstCaps *tcaps, *intersection;
1669 GST_DEBUG ("Trying factory %s",
1670 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
1672 if (gst_element_get_factory (src) == factory) {
1673 GST_DEBUG ("Skipping factory");
1677 for (tmps = gst_element_factory_get_static_pad_templates (factory); tmps;
1678 tmps = tmps->next) {
1679 GstStaticPadTemplate *st = (GstStaticPadTemplate *) tmps->data;
1680 if (st->direction != GST_PAD_SINK || st->presence != GST_PAD_ALWAYS)
1682 tcaps = gst_static_pad_template_get_caps (st);
1684 gst_caps_intersect_full (tcaps, caps, GST_CAPS_INTERSECT_FIRST);
1685 filter_caps = gst_caps_merge (filter_caps, intersection);
1686 gst_caps_unref (tcaps);
1690 /* Append the parser caps to prevent any not-negotiated errors */
1691 filter_caps = gst_caps_merge (filter_caps, gst_caps_ref (caps));
1693 delem->capsfilter = gst_element_factory_make ("capsfilter", NULL);
1694 g_object_set (G_OBJECT (delem->capsfilter), "caps", filter_caps, NULL);
1695 gst_caps_unref (filter_caps);
1696 gst_element_set_state (delem->capsfilter, GST_STATE_PAUSED);
1697 gst_bin_add (GST_BIN_CAST (dbin), gst_object_ref (delem->capsfilter));
1699 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), NULL);
1700 p = gst_element_get_static_pad (delem->capsfilter, "sink");
1701 gst_pad_link_full (pad, p, GST_PAD_LINK_CHECK_NOTHING);
1702 gst_object_unref (p);
1703 p = gst_element_get_static_pad (delem->capsfilter, "src");
1704 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), p);
1707 if (!gst_caps_is_fixed (caps)) {
1708 g_value_array_free (factories);
1713 /* 1.h else continue autoplugging something from the list. */
1714 GST_LOG_OBJECT (pad, "Let's continue discovery on this pad");
1715 res = connect_pad (dbin, src, dpad, pad, caps, factories, chain);
1717 /* Need to unref the capsfilter srcpad here if
1718 * we inserted a capsfilter */
1719 if (is_parser_converter)
1720 gst_object_unref (pad);
1722 gst_object_unref (dpad);
1723 g_value_array_free (factories);
1732 GST_LOG_OBJECT (dbin, "Pad is final. autoplug-continue:%d", apcontinue);
1733 expose_pad (dbin, src, dpad, pad, caps, chain);
1734 gst_object_unref (dpad);
1740 GST_LOG_OBJECT (pad, "Known type, but discarded because not final caps");
1741 chain->deadend = TRUE;
1742 chain->endcaps = gst_caps_ref (caps);
1743 gst_object_replace ((GstObject **) & chain->current_pad, NULL);
1745 /* Try to expose anything */
1747 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
1748 gst_decode_bin_expose (dbin);
1750 EXPOSE_UNLOCK (dbin);
1751 do_async_done (dbin);
1758 GST_LOG_OBJECT (pad, "Unknown type, posting message and firing signal");
1760 chain->deadend = TRUE;
1761 chain->endcaps = gst_caps_ref (caps);
1762 gst_object_replace ((GstObject **) & chain->current_pad, NULL);
1764 gst_element_post_message (GST_ELEMENT_CAST (dbin),
1765 gst_missing_decoder_message_new (GST_ELEMENT_CAST (dbin), caps));
1767 g_signal_emit (G_OBJECT (dbin),
1768 gst_decode_bin_signals[SIGNAL_UNKNOWN_TYPE], 0, pad, caps);
1770 /* Try to expose anything */
1772 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
1773 gst_decode_bin_expose (dbin);
1775 EXPOSE_UNLOCK (dbin);
1777 if (src == dbin->typefind) {
1780 if (caps && !gst_caps_is_empty (caps)) {
1781 desc = gst_pb_utils_get_decoder_description (caps);
1782 GST_ELEMENT_ERROR (dbin, STREAM, CODEC_NOT_FOUND,
1783 (_("A %s plugin is required to play this stream, "
1784 "but not installed."), desc),
1785 ("No decoder to handle media type '%s'",
1786 gst_structure_get_name (gst_caps_get_structure (caps, 0))));
1789 GST_ELEMENT_ERROR (dbin, STREAM, TYPE_NOT_FOUND,
1790 (_("Could not determine type of stream")),
1791 ("Stream caps %" GST_PTR_FORMAT, caps));
1793 do_async_done (dbin);
1799 GST_DEBUG_OBJECT (pad, "pad has non-fixed caps delay autoplugging");
1800 gst_object_unref (dpad);
1801 goto setup_caps_delay;
1805 GST_DEBUG_OBJECT (pad, "pad has ANY caps, delaying auto-pluggin");
1806 goto setup_caps_delay;
1810 GstPendingPad *ppad;
1812 /* connect to caps notification */
1813 CHAIN_MUTEX_LOCK (chain);
1814 GST_LOG_OBJECT (dbin, "Chain %p has now %d dynamic pads", chain,
1815 g_list_length (chain->pending_pads));
1816 ppad = g_slice_new0 (GstPendingPad);
1817 ppad->pad = gst_object_ref (pad);
1818 ppad->chain = chain;
1819 ppad->event_probe_id =
1820 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
1821 pad_event_cb, ppad, NULL);
1822 chain->pending_pads = g_list_prepend (chain->pending_pads, ppad);
1823 g_signal_connect (G_OBJECT (pad), "notify::caps",
1824 G_CALLBACK (caps_notify_cb), chain);
1825 CHAIN_MUTEX_UNLOCK (chain);
1827 /* If we're here because we have a Parser/Converter
1828 * we have to unref the pad */
1829 if (is_parser_converter)
1830 gst_object_unref (pad);
1837 add_error_filter (GstDecodeBin * dbin, GstElement * element)
1839 GST_OBJECT_LOCK (dbin);
1840 dbin->filtered = g_list_prepend (dbin->filtered, element);
1841 GST_OBJECT_UNLOCK (dbin);
1845 remove_error_filter (GstDecodeBin * dbin, GstElement * element)
1847 GST_OBJECT_LOCK (dbin);
1848 dbin->filtered = g_list_remove (dbin->filtered, element);
1849 GST_OBJECT_UNLOCK (dbin);
1854 * Try to connect the given pad to an element created from one of the factories,
1857 * Note that dpad is ghosting pad, and so pad is linked; be sure to unset dpad's
1858 * target before trying to link pad.
1860 * Returns TRUE if an element was properly created and linked
1863 connect_pad (GstDecodeBin * dbin, GstElement * src, GstDecodePad * dpad,
1864 GstPad * pad, GstCaps * caps, GValueArray * factories,
1865 GstDecodeChain * chain)
1867 gboolean res = FALSE;
1868 GstPad *mqpad = NULL;
1869 gboolean is_demuxer = chain->parent && !chain->elements; /* First pad after the demuxer */
1871 g_return_val_if_fail (factories != NULL, FALSE);
1872 g_return_val_if_fail (factories->n_values > 0, FALSE);
1874 GST_DEBUG_OBJECT (dbin,
1875 "pad %s:%s , chain:%p, %d factories, caps %" GST_PTR_FORMAT,
1876 GST_DEBUG_PAD_NAME (pad), chain, factories->n_values, caps);
1878 /* 1. is element demuxer or parser */
1880 GST_LOG_OBJECT (src,
1881 "is a demuxer, connecting the pad through multiqueue '%s'",
1882 GST_OBJECT_NAME (chain->parent->multiqueue));
1884 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), NULL);
1885 if (!(mqpad = gst_decode_group_control_demuxer_pad (chain->parent, pad)))
1887 src = chain->parent->multiqueue;
1889 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), pad);
1892 /* 2. Try to create an element and link to it */
1893 while (factories->n_values > 0) {
1894 GstAutoplugSelectResult ret;
1895 GstElementFactory *factory;
1896 GstDecodeElement *delem;
1897 GstElement *element;
1902 /* Set dpad target to pad again, it might've been unset
1903 * below but we came back here because something failed
1905 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), pad);
1907 /* take first factory */
1908 factory = g_value_get_object (g_value_array_get_nth (factories, 0));
1909 /* Remove selected factory from the list. */
1910 g_value_array_remove (factories, 0);
1912 GST_LOG_OBJECT (src, "trying factory %" GST_PTR_FORMAT, factory);
1914 /* Check if the caps are really supported by the factory. The
1915 * factory list is non-empty-subset filtered while caps
1916 * are only accepted by a pad if they are a subset of the
1919 * FIXME: Only do this for fixed caps here. Non-fixed caps
1920 * can happen if a Parser/Converter was autoplugged before
1921 * this. We then assume that it will be able to convert to
1922 * everything that the decoder would want.
1924 * A subset check will fail here because the parser caps
1925 * will be generic and while the decoder will only
1926 * support a subset of the parser caps.
1928 if (gst_caps_is_fixed (caps)) {
1929 const GList *templs;
1930 gboolean skip = FALSE;
1932 templs = gst_element_factory_get_static_pad_templates (factory);
1935 GstStaticPadTemplate *templ = (GstStaticPadTemplate *) templs->data;
1937 if (templ->direction == GST_PAD_SINK) {
1938 GstCaps *templcaps = gst_static_caps_get (&templ->static_caps);
1940 if (!gst_caps_is_subset (caps, templcaps)) {
1941 GST_DEBUG_OBJECT (src,
1942 "caps %" GST_PTR_FORMAT " not subset of %" GST_PTR_FORMAT, caps,
1944 gst_caps_unref (templcaps);
1949 gst_caps_unref (templcaps);
1951 templs = g_list_next (templs);
1957 /* If the factory is for a parser we first check if the factory
1958 * was already used for the current chain. If it was used already
1959 * we would otherwise create an infinite loop here because the
1960 * parser apparently accepts its own output as input.
1961 * This is only done for parsers because it's perfectly valid
1962 * to have other element classes after each other because a
1963 * parser is the only one that does not change the data. A
1964 * valid example for this would be multiple id3demux in a row.
1966 if (strstr (gst_element_factory_get_metadata (factory,
1967 GST_ELEMENT_METADATA_KLASS), "Parser")) {
1968 gboolean skip = FALSE;
1971 CHAIN_MUTEX_LOCK (chain);
1972 for (l = chain->elements; l; l = l->next) {
1973 GstDecodeElement *delem = (GstDecodeElement *) l->data;
1974 GstElement *otherelement = delem->element;
1976 if (gst_element_get_factory (otherelement) == factory) {
1981 CHAIN_MUTEX_UNLOCK (chain);
1983 GST_DEBUG_OBJECT (dbin,
1984 "Skipping factory '%s' because it was already used in this chain",
1985 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE_CAST (factory)));
1990 /* emit autoplug-select to see what we should do with it. */
1991 g_signal_emit (G_OBJECT (dbin),
1992 gst_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT],
1993 0, dpad, caps, factory, &ret);
1996 case GST_AUTOPLUG_SELECT_TRY:
1997 GST_DEBUG_OBJECT (dbin, "autoplug select requested try");
1999 case GST_AUTOPLUG_SELECT_EXPOSE:
2000 GST_DEBUG_OBJECT (dbin, "autoplug select requested expose");
2001 /* expose the pad, we don't have the source element */
2002 expose_pad (dbin, src, dpad, pad, caps, chain);
2005 case GST_AUTOPLUG_SELECT_SKIP:
2006 GST_DEBUG_OBJECT (dbin, "autoplug select requested skip");
2009 GST_WARNING_OBJECT (dbin, "autoplug select returned unhandled %d", ret);
2013 /* 2.0. Unlink pad */
2014 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), NULL);
2016 /* 2.1. Try to create an element */
2017 if ((element = gst_element_factory_create (factory, NULL)) == NULL) {
2018 GST_WARNING_OBJECT (dbin, "Could not create an element from %s",
2019 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
2023 /* Filter errors, this will prevent the element from causing the pipeline
2024 * to error while we test it using READY state. */
2025 add_error_filter (dbin, element);
2027 /* ... add it ... */
2028 if (!(gst_bin_add (GST_BIN_CAST (dbin), element))) {
2029 GST_WARNING_OBJECT (dbin, "Couldn't add %s to the bin",
2030 GST_ELEMENT_NAME (element));
2031 remove_error_filter (dbin, element);
2032 gst_object_unref (element);
2036 /* Find its sink pad. */
2037 if (!(sinkpad = find_sink_pad (element))) {
2038 GST_WARNING_OBJECT (dbin, "Element %s doesn't have a sink pad",
2039 GST_ELEMENT_NAME (element));
2040 remove_error_filter (dbin, element);
2041 gst_bin_remove (GST_BIN (dbin), element);
2045 /* ... and try to link */
2046 if ((gst_pad_link (pad, sinkpad)) != GST_PAD_LINK_OK) {
2047 GST_WARNING_OBJECT (dbin, "Link failed on pad %s:%s",
2048 GST_DEBUG_PAD_NAME (sinkpad));
2049 remove_error_filter (dbin, element);
2050 gst_object_unref (sinkpad);
2051 gst_bin_remove (GST_BIN (dbin), element);
2055 /* ... activate it ... */
2056 if ((gst_element_set_state (element,
2057 GST_STATE_READY)) == GST_STATE_CHANGE_FAILURE) {
2058 GST_WARNING_OBJECT (dbin, "Couldn't set %s to READY",
2059 GST_ELEMENT_NAME (element));
2060 remove_error_filter (dbin, element);
2061 gst_object_unref (sinkpad);
2062 gst_bin_remove (GST_BIN (dbin), element);
2066 /* Stop filtering errors. */
2067 remove_error_filter (dbin, element);
2069 /* check if we still accept the caps on the pad after setting
2070 * the element to READY */
2071 if (!gst_pad_query_accept_caps (sinkpad, caps)) {
2072 GST_WARNING_OBJECT (dbin, "Element %s does not accept caps",
2073 GST_ELEMENT_NAME (element));
2074 gst_element_set_state (element, GST_STATE_NULL);
2075 gst_object_unref (sinkpad);
2076 gst_bin_remove (GST_BIN (dbin), element);
2080 gst_object_unref (sinkpad);
2081 GST_LOG_OBJECT (dbin, "linked on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2083 CHAIN_MUTEX_LOCK (chain);
2084 delem = g_slice_new (GstDecodeElement);
2085 delem->element = gst_object_ref (element);
2086 delem->capsfilter = NULL;
2087 chain->elements = g_list_prepend (chain->elements, delem);
2088 chain->demuxer = is_demuxer_element (element);
2089 CHAIN_MUTEX_UNLOCK (chain);
2091 /* Set connection-speed property if needed */
2092 if (chain->demuxer == TRUE) {
2095 if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2096 "connection-speed"))) {
2097 guint64 speed = dbin->connection_speed / 1000;
2098 gboolean wrong_type = FALSE;
2100 if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_UINT) {
2101 GParamSpecUInt *pspecuint = G_PARAM_SPEC_UINT (pspec);
2103 speed = CLAMP (speed, pspecuint->minimum, pspecuint->maximum);
2104 } else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT) {
2105 GParamSpecInt *pspecint = G_PARAM_SPEC_INT (pspec);
2107 speed = CLAMP (speed, pspecint->minimum, pspecint->maximum);
2108 } else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_UINT64) {
2109 GParamSpecUInt64 *pspecuint = G_PARAM_SPEC_UINT64 (pspec);
2111 speed = CLAMP (speed, pspecuint->minimum, pspecuint->maximum);
2112 } else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT64) {
2113 GParamSpecInt64 *pspecint = G_PARAM_SPEC_INT64 (pspec);
2115 speed = CLAMP (speed, pspecint->minimum, pspecint->maximum);
2117 GST_WARNING_OBJECT (dbin,
2118 "The connection speed property %" G_GUINT64_FORMAT " of type %s"
2119 " is not usefull not setting it", speed,
2120 g_type_name (G_PARAM_SPEC_TYPE (pspec)));
2124 if (wrong_type == FALSE) {
2125 GST_DEBUG_OBJECT (dbin, "setting connection-speed=%" G_GUINT64_FORMAT
2126 " to demuxer element", speed);
2128 g_object_set (element, "connection-speed", speed, NULL);
2133 /* link this element further */
2134 connect_element (dbin, element, chain);
2136 /* try to configure the subtitle encoding property when we can */
2137 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2138 "subtitle-encoding");
2139 if (pspec && G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_STRING) {
2140 SUBTITLE_LOCK (dbin);
2141 GST_DEBUG_OBJECT (dbin,
2142 "setting subtitle-encoding=%s to element", dbin->encoding);
2143 g_object_set (G_OBJECT (element), "subtitle-encoding", dbin->encoding,
2145 SUBTITLE_UNLOCK (dbin);
2151 /* Bring the element to the state of the parent */
2152 if ((gst_element_set_state (element,
2153 GST_STATE_PAUSED)) == GST_STATE_CHANGE_FAILURE) {
2154 GstDecodeElement *dtmp = NULL;
2155 GstElement *tmp = NULL;
2157 GST_WARNING_OBJECT (dbin, "Couldn't set %s to PAUSED",
2158 GST_ELEMENT_NAME (element));
2160 /* Remove all elements in this chain that were just added. No
2161 * other thread could've added elements in the meantime */
2162 CHAIN_MUTEX_LOCK (chain);
2166 dtmp = chain->elements->data;
2167 tmp = dtmp->element;
2169 /* Disconnect any signal handlers that might be connected
2170 * in connect_element() or analyze_pad() */
2171 g_signal_handlers_disconnect_by_func (tmp, pad_added_cb, chain);
2172 g_signal_handlers_disconnect_by_func (tmp, pad_removed_cb, chain);
2173 g_signal_handlers_disconnect_by_func (tmp, no_more_pads_cb, chain);
2175 for (l = chain->pending_pads; l;) {
2176 GstPendingPad *pp = l->data;
2179 if (GST_PAD_PARENT (pp->pad) != tmp) {
2184 g_signal_handlers_disconnect_by_func (pp->pad, caps_notify_cb, chain);
2185 gst_pad_remove_probe (pp->pad, pp->event_probe_id);
2186 gst_object_unref (pp->pad);
2187 g_slice_free (GstPendingPad, pp);
2189 /* Remove element from the list, update list head and go to the
2190 * next element in the list */
2192 chain->pending_pads = g_list_delete_link (chain->pending_pads, l);
2196 if (dtmp->capsfilter) {
2197 gst_bin_remove (GST_BIN (dbin), dtmp->capsfilter);
2198 gst_element_set_state (dtmp->capsfilter, GST_STATE_NULL);
2199 gst_object_unref (dtmp->capsfilter);
2202 gst_bin_remove (GST_BIN (dbin), tmp);
2203 gst_element_set_state (tmp, GST_STATE_NULL);
2205 gst_object_unref (tmp);
2206 g_slice_free (GstDecodeElement, dtmp);
2208 chain->elements = g_list_delete_link (chain->elements, chain->elements);
2209 } while (tmp != element);
2210 CHAIN_MUTEX_UNLOCK (chain);
2215 SUBTITLE_LOCK (dbin);
2216 /* we added the element now, add it to the list of subtitle-encoding
2217 * elements when we can set the property */
2218 dbin->subtitles = g_list_prepend (dbin->subtitles, element);
2219 SUBTITLE_UNLOCK (dbin);
2228 gst_object_unref (mqpad);
2234 get_pad_caps (GstPad * pad)
2238 /* first check the pad caps, if this is set, we are positively sure it is
2239 * fixed and exactly what the element will produce. */
2240 caps = gst_pad_get_current_caps (pad);
2242 /* then use the getcaps function if we don't have caps. These caps might not
2243 * be fixed in some cases, in which case analyze_new_pad will set up a
2244 * notify::caps signal to continue autoplugging. */
2246 caps = gst_pad_query_caps (pad, NULL);
2252 connect_element (GstDecodeBin * dbin, GstElement * element,
2253 GstDecodeChain * chain)
2256 gboolean res = TRUE;
2257 gboolean dynamic = FALSE;
2258 GList *to_connect = NULL;
2260 GST_DEBUG_OBJECT (dbin, "Attempting to connect element %s [chain:%p] further",
2261 GST_ELEMENT_NAME (element), chain);
2263 /* 1. Loop over pad templates, grabbing existing pads along the way */
2264 for (pads = GST_ELEMENT_GET_CLASS (element)->padtemplates; pads;
2265 pads = g_list_next (pads)) {
2266 GstPadTemplate *templ = GST_PAD_TEMPLATE (pads->data);
2267 const gchar *templ_name;
2269 /* we are only interested in source pads */
2270 if (GST_PAD_TEMPLATE_DIRECTION (templ) != GST_PAD_SRC)
2273 templ_name = GST_PAD_TEMPLATE_NAME_TEMPLATE (templ);
2274 GST_DEBUG_OBJECT (dbin, "got a source pad template %s", templ_name);
2276 /* figure out what kind of pad this is */
2277 switch (GST_PAD_TEMPLATE_PRESENCE (templ)) {
2278 case GST_PAD_ALWAYS:
2280 /* get the pad that we need to autoplug */
2281 GstPad *pad = gst_element_get_static_pad (element, templ_name);
2284 GST_DEBUG_OBJECT (dbin, "got the pad for always template %s",
2286 /* here is the pad, we need to autoplug it */
2287 to_connect = g_list_prepend (to_connect, pad);
2289 /* strange, pad is marked as always but it's not
2290 * there. Fix the element */
2291 GST_WARNING_OBJECT (dbin,
2292 "could not get the pad for always template %s", templ_name);
2296 case GST_PAD_SOMETIMES:
2298 /* try to get the pad to see if it is already created or
2300 GstPad *pad = gst_element_get_static_pad (element, templ_name);
2303 GST_DEBUG_OBJECT (dbin, "got the pad for sometimes template %s",
2305 /* the pad is created, we need to autoplug it */
2306 to_connect = g_list_prepend (to_connect, pad);
2308 GST_DEBUG_OBJECT (dbin,
2309 "did not get the sometimes pad of template %s", templ_name);
2310 /* we have an element that will create dynamic pads */
2315 case GST_PAD_REQUEST:
2316 /* ignore request pads */
2317 GST_DEBUG_OBJECT (dbin, "ignoring request padtemplate %s", templ_name);
2322 /* 2. if there are more potential pads, connect to relevant signals */
2324 GST_LOG_OBJECT (dbin, "Adding signals to element %s in chain %p",
2325 GST_ELEMENT_NAME (element), chain);
2326 g_signal_connect (G_OBJECT (element), "pad-added",
2327 G_CALLBACK (pad_added_cb), chain);
2328 g_signal_connect (G_OBJECT (element), "pad-removed",
2329 G_CALLBACK (pad_removed_cb), chain);
2330 g_signal_connect (G_OBJECT (element), "no-more-pads",
2331 G_CALLBACK (no_more_pads_cb), chain);
2334 /* 3. for every available pad, connect it */
2335 for (pads = to_connect; pads; pads = g_list_next (pads)) {
2336 GstPad *pad = GST_PAD_CAST (pads->data);
2339 caps = get_pad_caps (pad);
2340 analyze_new_pad (dbin, element, pad, caps, chain);
2342 gst_caps_unref (caps);
2344 gst_object_unref (pad);
2346 g_list_free (to_connect);
2353 * Expose the given pad on the chain as a decoded pad.
2356 expose_pad (GstDecodeBin * dbin, GstElement * src, GstDecodePad * dpad,
2357 GstPad * pad, GstCaps * caps, GstDecodeChain * chain)
2359 GstPad *mqpad = NULL;
2361 GST_DEBUG_OBJECT (dbin, "pad %s:%s, chain:%p",
2362 GST_DEBUG_PAD_NAME (pad), chain);
2364 /* If this is the first pad for this chain, there are no other elements
2365 * and the source element is not the multiqueue we must link through the
2368 * This is the case if a demuxer directly exposed a raw pad.
2370 if (chain->parent && !chain->elements && src != chain->parent->multiqueue) {
2371 GST_LOG_OBJECT (src, "connecting the pad through multiqueue");
2373 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), NULL);
2374 if (!(mqpad = gst_decode_group_control_demuxer_pad (chain->parent, pad)))
2377 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), pad);
2380 gst_decode_pad_activate (dpad, chain);
2381 chain->endpad = gst_object_ref (dpad);
2382 chain->endcaps = gst_caps_ref (caps);
2385 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
2386 gst_decode_bin_expose (dbin);
2388 EXPOSE_UNLOCK (dbin);
2391 gst_object_unref (mqpad);
2397 /* check_upstream_seekable:
2399 * Check if upstream is seekable.
2402 check_upstream_seekable (GstDecodeBin * dbin, GstPad * pad)
2405 gint64 start = -1, stop = -1;
2406 gboolean seekable = FALSE;
2408 query = gst_query_new_seeking (GST_FORMAT_BYTES);
2409 if (!gst_pad_peer_query (pad, query)) {
2410 GST_DEBUG_OBJECT (dbin, "seeking query failed");
2411 gst_query_unref (query);
2415 gst_query_parse_seeking (query, NULL, &seekable, &start, &stop);
2417 gst_query_unref (query);
2419 /* try harder to query upstream size if we didn't get it the first time */
2420 if (seekable && stop == -1) {
2421 GST_DEBUG_OBJECT (dbin, "doing duration query to fix up unset stop");
2422 gst_pad_peer_query_duration (pad, GST_FORMAT_BYTES, &stop);
2425 /* if upstream doesn't know the size, it's likely that it's not seekable in
2426 * practice even if it technically may be seekable */
2427 if (seekable && (start != 0 || stop <= start)) {
2428 GST_DEBUG_OBJECT (dbin, "seekable but unknown start/stop -> disable");
2432 GST_DEBUG_OBJECT (dbin, "upstream seekable: %d", seekable);
2437 type_found (GstElement * typefind, guint probability,
2438 GstCaps * caps, GstDecodeBin * decode_bin)
2440 GstPad *pad, *sink_pad;
2442 GST_DEBUG_OBJECT (decode_bin, "typefind found caps %" GST_PTR_FORMAT, caps);
2444 /* If the typefinder (but not something else) finds text/plain - i.e. that's
2445 * the top-level type of the file - then error out.
2447 if (gst_structure_has_name (gst_caps_get_structure (caps, 0), "text/plain")) {
2448 GST_ELEMENT_ERROR (decode_bin, STREAM, WRONG_TYPE,
2449 (_("This appears to be a text file")),
2450 ("decodebin cannot decode plain text files"));
2454 /* FIXME: we can only deal with one type, we don't yet support dynamically changing
2455 * caps from the typefind element */
2456 if (decode_bin->have_type || decode_bin->decode_chain)
2459 decode_bin->have_type = TRUE;
2461 pad = gst_element_get_static_pad (typefind, "src");
2462 sink_pad = gst_element_get_static_pad (typefind, "sink");
2464 /* need some lock here to prevent race with shutdown state change
2465 * which might yank away e.g. decode_chain while building stuff here.
2466 * In typical cases, STREAM_LOCK is held and handles that, it need not
2467 * be held (if called from a proxied setcaps), so grab it anyway */
2468 GST_PAD_STREAM_LOCK (sink_pad);
2469 decode_bin->decode_chain = gst_decode_chain_new (decode_bin, NULL, pad);
2470 analyze_new_pad (decode_bin, typefind, pad, caps, decode_bin->decode_chain);
2471 GST_PAD_STREAM_UNLOCK (sink_pad);
2473 gst_object_unref (sink_pad);
2474 gst_object_unref (pad);
2480 static GstPadProbeReturn
2481 pad_event_cb (GstPad * pad, GstPadProbeInfo * info, gpointer data)
2483 GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info);
2484 GstPendingPad *ppad = (GstPendingPad *) data;
2485 GstDecodeChain *chain = ppad->chain;
2486 GstDecodeBin *dbin = chain->dbin;
2491 switch (GST_EVENT_TYPE (event)) {
2493 GST_DEBUG_OBJECT (dbin, "Received EOS on a non final pad, this stream "
2495 chain->deadend = TRUE;
2496 gst_object_replace ((GstObject **) & chain->current_pad, NULL);
2497 /* we don't set the endcaps because NULL endcaps means early EOS */
2499 if (gst_decode_chain_is_complete (dbin->decode_chain))
2500 gst_decode_bin_expose (dbin);
2501 EXPOSE_UNLOCK (dbin);
2506 return GST_PAD_PROBE_OK;
2510 pad_added_cb (GstElement * element, GstPad * pad, GstDecodeChain * chain)
2517 GST_DEBUG_OBJECT (pad, "pad added, chain:%p", chain);
2519 caps = get_pad_caps (pad);
2520 analyze_new_pad (dbin, element, pad, caps, chain);
2522 gst_caps_unref (caps);
2525 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
2526 GST_LOG_OBJECT (dbin,
2527 "That was the last dynamic object, now attempting to expose the group");
2528 if (!gst_decode_bin_expose (dbin))
2529 GST_WARNING_OBJECT (dbin, "Couldn't expose group");
2531 EXPOSE_UNLOCK (dbin);
2535 pad_removed_cb (GstElement * element, GstPad * pad, GstDecodeChain * chain)
2539 GST_LOG_OBJECT (pad, "pad removed, chain:%p", chain);
2541 /* In fact, we don't have to do anything here, the active group will be
2542 * removed when the group's multiqueue is drained */
2543 CHAIN_MUTEX_LOCK (chain);
2544 for (l = chain->pending_pads; l; l = l->next) {
2545 GstPendingPad *ppad = l->data;
2546 GstPad *opad = ppad->pad;
2549 g_signal_handlers_disconnect_by_func (pad, caps_notify_cb, chain);
2550 gst_pending_pad_free (ppad);
2551 chain->pending_pads = g_list_delete_link (chain->pending_pads, l);
2555 CHAIN_MUTEX_UNLOCK (chain);
2559 no_more_pads_cb (GstElement * element, GstDecodeChain * chain)
2561 GstDecodeGroup *group = NULL;
2563 GST_LOG_OBJECT (element, "got no more pads");
2565 CHAIN_MUTEX_LOCK (chain);
2566 if (!chain->elements
2567 || ((GstDecodeElement *) chain->elements->data)->element != element) {
2568 GST_LOG_OBJECT (chain->dbin, "no-more-pads from old chain element '%s'",
2569 GST_OBJECT_NAME (element));
2570 CHAIN_MUTEX_UNLOCK (chain);
2572 } else if (!chain->demuxer) {
2573 GST_LOG_OBJECT (chain->dbin, "no-more-pads from a non-demuxer element '%s'",
2574 GST_OBJECT_NAME (element));
2575 CHAIN_MUTEX_UNLOCK (chain);
2579 /* when we received no_more_pads, we can complete the pads of the chain */
2580 if (!chain->next_groups && chain->active_group) {
2581 group = chain->active_group;
2582 } else if (chain->next_groups) {
2583 group = chain->next_groups->data;
2586 GST_ERROR_OBJECT (chain->dbin, "can't find group for element");
2587 CHAIN_MUTEX_UNLOCK (chain);
2591 GST_DEBUG_OBJECT (element, "Setting group %p to complete", group);
2593 group->no_more_pads = TRUE;
2594 /* this group has prerolled enough to not need more pads,
2595 * we can probably set its buffering state to playing now */
2596 GST_DEBUG_OBJECT (group->dbin, "Setting group %p multiqueue to "
2597 "'playing' buffering mode", group);
2598 decodebin_set_queue_size (group->dbin, group->multiqueue, FALSE,
2599 (group->parent ? group->parent->seekable : TRUE));
2600 CHAIN_MUTEX_UNLOCK (chain);
2602 EXPOSE_LOCK (chain->dbin);
2603 if (gst_decode_chain_is_complete (chain->dbin->decode_chain)) {
2604 gst_decode_bin_expose (chain->dbin);
2606 EXPOSE_UNLOCK (chain->dbin);
2610 caps_notify_cb (GstPad * pad, GParamSpec * unused, GstDecodeChain * chain)
2612 GstElement *element;
2615 GST_LOG_OBJECT (pad, "Notified caps for pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2617 /* Disconnect this; if we still need it, we'll reconnect to this in
2618 * analyze_new_pad */
2619 g_signal_handlers_disconnect_by_func (pad, caps_notify_cb, chain);
2621 element = GST_ELEMENT_CAST (gst_pad_get_parent (pad));
2623 CHAIN_MUTEX_LOCK (chain);
2624 for (l = chain->pending_pads; l; l = l->next) {
2625 GstPendingPad *ppad = l->data;
2626 if (ppad->pad == pad) {
2627 gst_pending_pad_free (ppad);
2628 chain->pending_pads = g_list_delete_link (chain->pending_pads, l);
2632 CHAIN_MUTEX_UNLOCK (chain);
2634 pad_added_cb (element, pad, chain);
2636 gst_object_unref (element);
2639 /* Decide whether an element is a demuxer based on the
2640 * klass and number/type of src pad templates it has */
2642 is_demuxer_element (GstElement * srcelement)
2644 GstElementFactory *srcfactory;
2645 GstElementClass *elemclass;
2648 gint potential_src_pads = 0;
2650 srcfactory = gst_element_get_factory (srcelement);
2652 gst_element_factory_get_metadata (srcfactory, GST_ELEMENT_METADATA_KLASS);
2654 /* Can't be a demuxer unless it has Demux in the klass name */
2655 if (!strstr (klass, "Demux"))
2658 /* Walk the src pad templates and count how many the element
2660 elemclass = GST_ELEMENT_GET_CLASS (srcelement);
2662 walk = gst_element_class_get_pad_template_list (elemclass);
2663 while (walk != NULL) {
2664 GstPadTemplate *templ;
2666 templ = (GstPadTemplate *) walk->data;
2667 if (GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) {
2668 switch (GST_PAD_TEMPLATE_PRESENCE (templ)) {
2669 case GST_PAD_ALWAYS:
2670 case GST_PAD_SOMETIMES:
2671 if (strstr (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ), "%"))
2672 potential_src_pads += 2; /* Might make multiple pads */
2674 potential_src_pads += 1;
2676 case GST_PAD_REQUEST:
2677 potential_src_pads += 2;
2681 walk = g_list_next (walk);
2684 if (potential_src_pads < 2)
2690 /* Returns TRUE if the caps are compatible with the caps specified in the 'caps'
2691 * property (which by default are the raw caps)
2693 * The decodebin_lock should be taken !
2696 are_final_caps (GstDecodeBin * dbin, GstCaps * caps)
2700 GST_LOG_OBJECT (dbin, "Checking with caps %" GST_PTR_FORMAT, caps);
2702 /* lock for getting the caps */
2703 GST_OBJECT_LOCK (dbin);
2704 res = gst_caps_can_intersect (dbin->caps, caps);
2705 GST_OBJECT_UNLOCK (dbin);
2707 GST_LOG_OBJECT (dbin, "Caps are %sfinal caps", res ? "" : "not ");
2713 * GstDecodeChain functions
2716 /* gst_decode_chain_get_current_group:
2718 * Returns the current group of this chain, to which
2719 * new chains should be attached or NULL if the last
2720 * group didn't have no-more-pads.
2722 * Not MT-safe: Call with parent chain lock!
2724 static GstDecodeGroup *
2725 gst_decode_chain_get_current_group (GstDecodeChain * chain)
2727 GstDecodeGroup *group;
2729 if (!chain->next_groups && chain->active_group
2730 && chain->active_group->overrun && !chain->active_group->no_more_pads) {
2731 GST_WARNING_OBJECT (chain->dbin,
2732 "Currently active group %p is exposed"
2733 " and wants to add a new pad without having signaled no-more-pads",
2734 chain->active_group);
2738 if (chain->next_groups && (group = chain->next_groups->data) && group->overrun
2739 && !group->no_more_pads) {
2740 GST_WARNING_OBJECT (chain->dbin,
2741 "Currently newest pending group %p "
2742 "had overflow but didn't signal no-more-pads", group);
2746 /* Now we know that we can really return something useful */
2747 if (!chain->active_group) {
2748 chain->active_group = group = gst_decode_group_new (chain->dbin, chain);
2749 } else if (!chain->active_group->overrun
2750 && !chain->active_group->no_more_pads) {
2751 group = chain->active_group;
2752 } else if (chain->next_groups && (group = chain->next_groups->data)
2753 && !group->overrun && !group->no_more_pads) {
2754 /* group = chain->next_groups->data */
2756 group = gst_decode_group_new (chain->dbin, chain);
2757 chain->next_groups = g_list_prepend (chain->next_groups, group);
2763 static void gst_decode_group_free_internal (GstDecodeGroup * group,
2767 gst_decode_chain_free_internal (GstDecodeChain * chain, gboolean hide)
2771 CHAIN_MUTEX_LOCK (chain);
2773 GST_DEBUG_OBJECT (chain->dbin, "%s chain %p", (hide ? "Hiding" : "Freeing"),
2776 if (chain->active_group) {
2777 gst_decode_group_free_internal (chain->active_group, hide);
2779 chain->active_group = NULL;
2782 for (l = chain->next_groups; l; l = l->next) {
2783 gst_decode_group_free_internal ((GstDecodeGroup *) l->data, hide);
2788 g_list_free (chain->next_groups);
2789 chain->next_groups = NULL;
2793 for (l = chain->old_groups; l; l = l->next) {
2794 GstDecodeGroup *group = l->data;
2796 gst_decode_group_free (group);
2798 g_list_free (chain->old_groups);
2799 chain->old_groups = NULL;
2802 for (l = chain->pending_pads; l; l = l->next) {
2803 GstPendingPad *ppad = l->data;
2804 GstPad *pad = ppad->pad;
2806 g_signal_handlers_disconnect_by_func (pad, caps_notify_cb, chain);
2807 gst_pending_pad_free (ppad);
2810 g_list_free (chain->pending_pads);
2811 chain->pending_pads = NULL;
2813 for (l = chain->elements; l; l = l->next) {
2814 GstDecodeElement *delem = l->data;
2815 GstElement *element = delem->element;
2817 g_signal_handlers_disconnect_by_func (element, pad_added_cb, chain);
2818 g_signal_handlers_disconnect_by_func (element, pad_removed_cb, chain);
2819 g_signal_handlers_disconnect_by_func (element, no_more_pads_cb, chain);
2821 if (delem->capsfilter) {
2822 if (GST_OBJECT_PARENT (delem->capsfilter) ==
2823 GST_OBJECT_CAST (chain->dbin))
2824 gst_bin_remove (GST_BIN_CAST (chain->dbin), delem->capsfilter);
2826 gst_element_set_state (delem->capsfilter, GST_STATE_NULL);
2830 if (GST_OBJECT_PARENT (element) == GST_OBJECT_CAST (chain->dbin))
2831 gst_bin_remove (GST_BIN_CAST (chain->dbin), element);
2833 gst_element_set_state (element, GST_STATE_NULL);
2836 SUBTITLE_LOCK (chain->dbin);
2837 /* remove possible subtitle element */
2838 chain->dbin->subtitles = g_list_remove (chain->dbin->subtitles, element);
2839 SUBTITLE_UNLOCK (chain->dbin);
2842 if (delem->capsfilter) {
2843 gst_object_unref (delem->capsfilter);
2844 delem->capsfilter = NULL;
2847 gst_object_unref (element);
2850 g_slice_free (GstDecodeElement, delem);
2854 g_list_free (chain->elements);
2855 chain->elements = NULL;
2858 if (chain->endpad) {
2859 if (chain->endpad->exposed) {
2860 gst_element_remove_pad (GST_ELEMENT_CAST (chain->dbin),
2861 GST_PAD_CAST (chain->endpad));
2864 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (chain->endpad), NULL);
2865 chain->endpad->exposed = FALSE;
2867 gst_object_unref (chain->endpad);
2868 chain->endpad = NULL;
2872 if (!hide && chain->current_pad) {
2873 gst_object_unref (chain->current_pad);
2874 chain->current_pad = NULL;
2878 gst_object_unref (chain->pad);
2882 if (chain->endcaps) {
2883 gst_caps_unref (chain->endcaps);
2884 chain->endcaps = NULL;
2887 GST_DEBUG_OBJECT (chain->dbin, "%s chain %p", (hide ? "Hidden" : "Freed"),
2889 CHAIN_MUTEX_UNLOCK (chain);
2891 g_mutex_clear (&chain->lock);
2892 g_slice_free (GstDecodeChain, chain);
2896 /* gst_decode_chain_free:
2898 * Completely frees and removes the chain and all
2899 * child groups from decodebin.
2901 * MT-safe, don't hold the chain lock or any child chain's lock
2902 * when calling this!
2905 gst_decode_chain_free (GstDecodeChain * chain)
2907 gst_decode_chain_free_internal (chain, FALSE);
2910 /* gst_decode_chain_new:
2912 * Creates a new decode chain and initializes it.
2914 * It's up to the caller to add it to the list of child chains of
2917 static GstDecodeChain *
2918 gst_decode_chain_new (GstDecodeBin * dbin, GstDecodeGroup * parent,
2921 GstDecodeChain *chain = g_slice_new0 (GstDecodeChain);
2923 GST_DEBUG_OBJECT (dbin, "Creating new chain %p with parent group %p", chain,
2927 chain->parent = parent;
2928 g_mutex_init (&chain->lock);
2929 chain->pad = gst_object_ref (pad);
2935 * GstDecodeGroup functions
2938 /* The overrun callback is used to expose groups that have not yet had their
2939 * no_more_pads called while the (large) multiqueue overflowed. When this
2940 * happens we must assume that the no_more_pads will not arrive anymore and we
2941 * must expose the pads that we have.
2944 multi_queue_overrun_cb (GstElement * queue, GstDecodeGroup * group)
2950 GST_LOG_OBJECT (dbin, "multiqueue '%s' (%p) is full", GST_OBJECT_NAME (queue),
2953 group->overrun = TRUE;
2954 /* this group has prerolled enough to not need more pads,
2955 * we can probably set its buffering state to playing now */
2956 GST_DEBUG_OBJECT (group->dbin, "Setting group %p multiqueue to "
2957 "'playing' buffering mode", group);
2958 decodebin_set_queue_size (group->dbin, group->multiqueue, FALSE,
2959 (group->parent ? group->parent->seekable : TRUE));
2961 /* FIXME: We should make sure that everything gets exposed now
2962 * even if child chains are not complete because the will never
2963 * be complete! Ignore any non-complete chains when exposing
2964 * and never expose them later
2968 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
2969 if (!gst_decode_bin_expose (dbin))
2970 GST_WARNING_OBJECT (dbin, "Couldn't expose group");
2972 EXPOSE_UNLOCK (group->dbin);
2976 gst_decode_group_free_internal (GstDecodeGroup * group, gboolean hide)
2980 GST_DEBUG_OBJECT (group->dbin, "%s group %p", (hide ? "Hiding" : "Freeing"),
2982 for (l = group->children; l; l = l->next) {
2983 GstDecodeChain *chain = (GstDecodeChain *) l->data;
2985 gst_decode_chain_free_internal (chain, hide);
2990 g_list_free (group->children);
2991 group->children = NULL;
2995 for (l = group->reqpads; l; l = l->next) {
2996 GstPad *pad = l->data;
2998 gst_element_release_request_pad (group->multiqueue, pad);
2999 gst_object_unref (pad);
3002 g_list_free (group->reqpads);
3003 group->reqpads = NULL;
3006 if (group->multiqueue) {
3007 if (group->overrunsig) {
3008 g_signal_handler_disconnect (group->multiqueue, group->overrunsig);
3009 group->overrunsig = 0;
3012 if (GST_OBJECT_PARENT (group->multiqueue) == GST_OBJECT_CAST (group->dbin))
3013 gst_bin_remove (GST_BIN_CAST (group->dbin), group->multiqueue);
3015 gst_element_set_state (group->multiqueue, GST_STATE_NULL);
3016 gst_object_unref (group->multiqueue);
3017 group->multiqueue = NULL;
3021 GST_DEBUG_OBJECT (group->dbin, "%s group %p", (hide ? "Hided" : "Freed"),
3024 g_slice_free (GstDecodeGroup, group);
3027 /* gst_decode_group_free:
3029 * Completely frees and removes the decode group and all
3032 * Never call this from any streaming thread!
3034 * Not MT-safe, call with parent's chain lock!
3037 gst_decode_group_free (GstDecodeGroup * group)
3039 gst_decode_group_free_internal (group, FALSE);
3042 /* gst_decode_group_hide:
3044 * Hide the decode group only, this means that
3045 * all child endpads are removed from decodebin
3046 * and all signals are unconnected.
3048 * No element is set to NULL state and completely
3051 * Can be called from streaming threads.
3053 * Not MT-safe, call with parent's chain lock!
3056 gst_decode_group_hide (GstDecodeGroup * group)
3058 gst_decode_group_free_internal (group, TRUE);
3061 /* configure queue sizes, this depends on the buffering method and if we are
3062 * playing or prerolling. */
3064 decodebin_set_queue_size (GstDecodeBin * dbin, GstElement * multiqueue,
3065 gboolean preroll, gboolean seekable)
3067 guint max_bytes, max_buffers;
3070 if (preroll || dbin->use_buffering) {
3071 /* takes queue limits, initially we only queue up up to the max bytes limit,
3072 * with a default of 2MB. we use the same values for buffering mode. */
3073 if ((max_bytes = dbin->max_size_bytes) == 0)
3074 max_bytes = AUTO_PREROLL_SIZE_BYTES;
3075 if ((max_buffers = dbin->max_size_buffers) == 0)
3076 max_buffers = AUTO_PREROLL_SIZE_BUFFERS;
3077 if ((max_time = dbin->max_size_time) == 0)
3078 max_time = seekable ? AUTO_PREROLL_SEEKABLE_SIZE_TIME :
3079 AUTO_PREROLL_NOT_SEEKABLE_SIZE_TIME;
3081 /* update runtime limits. At runtime, we try to keep the amount of buffers
3082 * in the queues as low as possible (but at least 5 buffers). */
3083 if ((max_bytes = dbin->max_size_bytes) == 0)
3084 max_bytes = AUTO_PLAY_SIZE_BYTES;
3085 if ((max_buffers = dbin->max_size_buffers) == 0)
3086 max_buffers = AUTO_PLAY_SIZE_BUFFERS;
3087 if ((max_time = dbin->max_size_time) == 0)
3088 max_time = AUTO_PLAY_SIZE_TIME;
3091 g_object_set (multiqueue,
3092 "max-size-bytes", max_bytes, "max-size-time", max_time,
3093 "max-size-buffers", max_buffers, NULL);
3096 /* gst_decode_group_new:
3097 * @dbin: Parent decodebin
3098 * @parent: Parent chain or %NULL
3100 * Creates a new GstDecodeGroup. It is up to the caller to add it to the list
3103 static GstDecodeGroup *
3104 gst_decode_group_new (GstDecodeBin * dbin, GstDecodeChain * parent)
3106 GstDecodeGroup *group = g_slice_new0 (GstDecodeGroup);
3110 GST_DEBUG_OBJECT (dbin, "Creating new group %p with parent chain %p", group,
3114 group->parent = parent;
3116 mq = group->multiqueue = gst_element_factory_make ("multiqueue", NULL);
3117 if (G_UNLIKELY (!group->multiqueue))
3118 goto missing_multiqueue;
3120 /* default is for use-buffering is FALSE */
3121 if (dbin->use_buffering) {
3123 "use-buffering", TRUE,
3124 "low-percent", dbin->low_percent,
3125 "high-percent", dbin->high_percent, NULL);
3128 /* configure queue sizes for preroll */
3130 if (parent && parent->demuxer) {
3131 GstElement *element =
3132 ((GstDecodeElement *) parent->elements->data)->element;
3133 GstPad *pad = gst_element_get_static_pad (element, "sink");
3135 seekable = parent->seekable = check_upstream_seekable (dbin, pad);
3136 gst_object_unref (pad);
3139 decodebin_set_queue_size (dbin, mq, TRUE, seekable);
3141 group->overrunsig = g_signal_connect (G_OBJECT (mq), "overrun",
3142 G_CALLBACK (multi_queue_overrun_cb), group);
3144 gst_bin_add (GST_BIN (dbin), gst_object_ref (mq));
3145 gst_element_set_state (mq, GST_STATE_PAUSED);
3152 gst_element_post_message (GST_ELEMENT_CAST (dbin),
3153 gst_missing_element_message_new (GST_ELEMENT_CAST (dbin),
3155 GST_ELEMENT_ERROR (dbin, CORE, MISSING_PLUGIN, (NULL), ("no multiqueue!"));
3156 g_slice_free (GstDecodeGroup, group);
3161 /* gst_decode_group_control_demuxer_pad
3163 * Adds a new demuxer srcpad to the given group.
3165 * Returns the srcpad of the multiqueue corresponding the given pad.
3166 * Returns NULL if there was an error.
3169 gst_decode_group_control_demuxer_pad (GstDecodeGroup * group, GstPad * pad)
3172 GstPad *srcpad, *sinkpad;
3173 GstIterator *it = NULL;
3174 GValue item = { 0, };
3178 GST_LOG_OBJECT (dbin, "group:%p pad %s:%s", group, GST_DEBUG_PAD_NAME (pad));
3182 if (G_UNLIKELY (!group->multiqueue))
3185 if (!(sinkpad = gst_element_get_request_pad (group->multiqueue, "sink_%u"))) {
3186 GST_ERROR_OBJECT (dbin, "Couldn't get sinkpad from multiqueue");
3190 if ((gst_pad_link (pad, sinkpad) != GST_PAD_LINK_OK)) {
3191 GST_ERROR_OBJECT (dbin, "Couldn't link demuxer and multiqueue");
3195 it = gst_pad_iterate_internal_links (sinkpad);
3197 if (!it || (gst_iterator_next (it, &item)) != GST_ITERATOR_OK
3198 || ((srcpad = g_value_dup_object (&item)) == NULL)) {
3199 GST_ERROR_OBJECT (dbin,
3200 "Couldn't get srcpad from multiqueue for sinkpad %" GST_PTR_FORMAT,
3204 CHAIN_MUTEX_LOCK (group->parent);
3205 group->reqpads = g_list_prepend (group->reqpads, gst_object_ref (sinkpad));
3206 CHAIN_MUTEX_UNLOCK (group->parent);
3209 if (G_IS_VALUE (&item))
3210 g_value_unset (&item);
3212 gst_iterator_free (it);
3213 gst_object_unref (sinkpad);
3217 gst_element_release_request_pad (group->multiqueue, sinkpad);
3221 /* gst_decode_group_is_complete:
3223 * Checks if the group is complete, this means that
3224 * a) overrun of the multiqueue or no-more-pads happened
3225 * b) all child chains are complete
3227 * Not MT-safe, always call with decodebin expose lock
3230 gst_decode_group_is_complete (GstDecodeGroup * group)
3233 gboolean complete = TRUE;
3235 if (!group->overrun && !group->no_more_pads) {
3240 for (l = group->children; l; l = l->next) {
3241 GstDecodeChain *chain = l->data;
3243 if (!gst_decode_chain_is_complete (chain)) {
3250 GST_DEBUG_OBJECT (group->dbin, "Group %p is complete: %d", group, complete);
3254 /* gst_decode_chain_is_complete:
3256 * Returns TRUE if the chain is complete, this means either
3257 * a) This chain is a dead end, i.e. we have no suitable plugins
3258 * b) This chain ends in an endpad and this is blocked or exposed
3260 * Not MT-safe, always call with decodebin expose lock
3263 gst_decode_chain_is_complete (GstDecodeChain * chain)
3265 gboolean complete = FALSE;
3267 CHAIN_MUTEX_LOCK (chain);
3268 if (chain->deadend) {
3273 if (chain->endpad && (chain->endpad->blocked || chain->endpad->exposed)) {
3278 if (chain->demuxer) {
3279 if (chain->active_group
3280 && gst_decode_group_is_complete (chain->active_group)) {
3287 CHAIN_MUTEX_UNLOCK (chain);
3288 GST_DEBUG_OBJECT (chain->dbin, "Chain %p is complete: %d", chain, complete);
3293 drain_and_switch_chains (GstDecodeChain * chain, GstDecodePad * drainpad,
3294 gboolean * last_group, gboolean * drained, gboolean * switched);
3295 /* drain_and_switch_chains/groups:
3297 * CALL WITH CHAIN LOCK (or group parent) TAKEN !
3299 * Goes down the chains/groups until it finds the chain
3300 * to which the drainpad belongs.
3302 * It marks that pad/chain as drained and then will figure
3303 * out which group to switch to or not.
3305 * last_chain will be set to TRUE if the group to which the
3306 * pad belongs is the last one.
3308 * drained will be set to TRUE if the chain/group is drained.
3310 * Returns: TRUE if the chain contained the target pad */
3312 drain_and_switch_group (GstDecodeGroup * group, GstDecodePad * drainpad,
3313 gboolean * last_group, gboolean * drained, gboolean * switched)
3315 gboolean handled = FALSE;
3318 GST_DEBUG ("Checking group %p (target pad %s:%s)",
3319 group, GST_DEBUG_PAD_NAME (drainpad));
3321 /* Definitely can't be in drained groups */
3322 if (G_UNLIKELY (group->drained)) {
3326 /* Figure out if all our chains are drained with the
3327 * new information */
3328 group->drained = TRUE;
3329 for (tmp = group->children; tmp; tmp = tmp->next) {
3330 GstDecodeChain *chain = (GstDecodeChain *) tmp->data;
3331 gboolean subdrained = FALSE;
3334 drain_and_switch_chains (chain, drainpad, last_group, &subdrained,
3337 group->drained = FALSE;
3341 GST_DEBUG ("group %p (last_group:%d, drained:%d, switched:%d, handled:%d)",
3342 group, *last_group, group->drained, *switched, handled);
3343 *drained = group->drained;
3348 drain_and_switch_chains (GstDecodeChain * chain, GstDecodePad * drainpad,
3349 gboolean * last_group, gboolean * drained, gboolean * switched)
3351 gboolean handled = FALSE;
3352 GstDecodeBin *dbin = chain->dbin;
3354 GST_DEBUG ("Checking chain %p (target pad %s:%s)",
3355 chain, GST_DEBUG_PAD_NAME (drainpad));
3357 CHAIN_MUTEX_LOCK (chain);
3359 /* Definitely can't be in drained chains */
3360 if (G_UNLIKELY (chain->drained)) {
3364 if (chain->endpad) {
3365 /* Check if we're reached the target endchain */
3366 if (chain == drainpad->chain) {
3367 GST_DEBUG ("Found the target chain");
3368 drainpad->drained = TRUE;
3372 chain->drained = chain->endpad->drained;
3376 /* We known there are groups to switch to */
3377 if (chain->next_groups)
3378 *last_group = FALSE;
3380 /* Check the active group */
3381 if (chain->active_group) {
3382 gboolean subdrained = FALSE;
3383 handled = drain_and_switch_group (chain->active_group, drainpad,
3384 last_group, &subdrained, switched);
3386 /* The group is drained, see if we can switch to another */
3387 if (handled && subdrained && !*switched) {
3388 if (chain->next_groups) {
3389 /* Switch to next group */
3390 GST_DEBUG_OBJECT (dbin, "Hiding current group %p", chain->active_group);
3391 gst_decode_group_hide (chain->active_group);
3393 g_list_prepend (chain->old_groups, chain->active_group);
3394 GST_DEBUG_OBJECT (dbin, "Switching to next group %p",
3395 chain->next_groups->data);
3396 chain->active_group = chain->next_groups->data;
3397 chain->next_groups =
3398 g_list_delete_link (chain->next_groups, chain->next_groups);
3400 chain->drained = FALSE;
3402 GST_DEBUG ("Group %p was the last in chain %p", chain->active_group,
3404 chain->drained = TRUE;
3405 /* We're drained ! */
3411 CHAIN_MUTEX_UNLOCK (chain);
3413 GST_DEBUG ("Chain %p (handled:%d, last_group:%d, drained:%d, switched:%d)",
3414 chain, handled, *last_group, chain->drained, *switched);
3416 *drained = chain->drained;
3419 g_signal_emit (dbin, gst_decode_bin_signals[SIGNAL_DRAINED], 0, NULL);
3424 /* check if the group is drained, meaning all pads have seen an EOS
3427 gst_decode_pad_handle_eos (GstDecodePad * pad)
3429 gboolean last_group = TRUE;
3430 gboolean switched = FALSE;
3431 gboolean drained = FALSE;
3432 GstDecodeChain *chain = pad->chain;
3433 GstDecodeBin *dbin = chain->dbin;
3435 GST_LOG_OBJECT (dbin, "pad %p", pad);
3436 drain_and_switch_chains (dbin->decode_chain, pad, &last_group, &drained,
3440 /* If we resulted in a group switch, expose what's needed */
3442 if (gst_decode_chain_is_complete (dbin->decode_chain))
3443 gst_decode_bin_expose (dbin);
3444 EXPOSE_UNLOCK (dbin);
3450 /* gst_decode_group_is_drained:
3452 * Check is this group is drained and cache this result.
3453 * The group is drained if all child chains are drained.
3455 * Not MT-safe, call with group->parent's lock */
3457 gst_decode_group_is_drained (GstDecodeGroup * group)
3460 gboolean drained = TRUE;
3462 if (group->drained) {
3467 for (l = group->children; l; l = l->next) {
3468 GstDecodeChain *chain = l->data;
3470 CHAIN_MUTEX_LOCK (chain);
3471 if (!gst_decode_chain_is_drained (chain))
3473 CHAIN_MUTEX_UNLOCK (chain);
3477 group->drained = drained;
3480 GST_DEBUG_OBJECT (group->dbin, "Group %p is drained: %d", group, drained);
3484 /* gst_decode_chain_is_drained:
3486 * Check is the chain is drained, which means that
3489 * a) it's endpad is drained
3490 * b) there are no pending pads, the active group is drained
3491 * and there are no next groups
3493 * Not MT-safe, call with chain lock
3496 gst_decode_chain_is_drained (GstDecodeChain * chain)
3498 gboolean drained = FALSE;
3500 if (chain->endpad) {
3501 drained = chain->endpad->drained;
3505 if (chain->pending_pads) {
3510 if (chain->active_group && gst_decode_group_is_drained (chain->active_group)
3511 && !chain->next_groups) {
3517 GST_DEBUG_OBJECT (chain->dbin, "Chain %p is drained: %d", chain, drained);
3522 * GCompareFunc to use with lists of GstPad.
3523 * Sorts pads by mime type.
3524 * First video (raw, then non-raw), then audio (raw, then non-raw),
3527 * Return: negative if a<b, 0 if a==b, positive if a>b
3530 sort_end_pads (GstDecodePad * da, GstDecodePad * db)
3533 GstCaps *capsa, *capsb;
3534 GstStructure *sa, *sb;
3535 const gchar *namea, *nameb;
3539 capsa = get_pad_caps (GST_PAD_CAST (da));
3540 capsb = get_pad_caps (GST_PAD_CAST (db));
3542 sa = gst_caps_get_structure ((const GstCaps *) capsa, 0);
3543 sb = gst_caps_get_structure ((const GstCaps *) capsb, 0);
3545 namea = gst_structure_get_name (sa);
3546 nameb = gst_structure_get_name (sb);
3548 if (g_strrstr (namea, "video/x-raw"))
3550 else if (g_strrstr (namea, "video/"))
3552 else if (g_strrstr (namea, "audio/x-raw"))
3554 else if (g_strrstr (namea, "audio/"))
3559 if (g_strrstr (nameb, "video/x-raw"))
3561 else if (g_strrstr (nameb, "video/"))
3563 else if (g_strrstr (nameb, "audio/x-raw"))
3565 else if (g_strrstr (nameb, "audio/"))
3570 gst_caps_unref (capsa);
3571 gst_caps_unref (capsb);
3576 /* if otherwise the same, sort by stream-id */
3577 ida = gst_pad_get_stream_id (GST_PAD_CAST (da));
3578 idb = gst_pad_get_stream_id (GST_PAD_CAST (db));
3579 ret = (ida) ? ((idb) ? strcmp (ida, idb) : -1) : 1;
3587 _gst_element_get_linked_caps (GstElement * src, GstElement * sink,
3593 gboolean done = FALSE;
3594 GstCaps *caps = NULL;
3595 GValue item = { 0, };
3597 it = gst_element_iterate_src_pads (src);
3599 switch (gst_iterator_next (it, &item)) {
3600 case GST_ITERATOR_OK:
3601 pad = g_value_get_object (&item);
3602 peer = gst_pad_get_peer (pad);
3604 parent = gst_pad_get_parent_element (peer);
3605 if (parent == sink) {
3606 caps = gst_pad_get_current_caps (pad);
3608 gst_object_ref (pad);
3615 gst_object_unref (parent);
3616 gst_object_unref (peer);
3618 g_value_reset (&item);
3620 case GST_ITERATOR_RESYNC:
3621 gst_iterator_resync (it);
3623 case GST_ITERATOR_ERROR:
3624 case GST_ITERATOR_DONE:
3629 g_value_unset (&item);
3630 gst_iterator_free (it);
3635 static GQuark topology_structure_name = 0;
3636 static GQuark topology_caps = 0;
3637 static GQuark topology_next = 0;
3638 static GQuark topology_pad = 0;
3639 static GQuark topology_element_srcpad = 0;
3641 /* FIXME: Invent gst_structure_take_structure() to prevent all the
3642 * structure copying for nothing
3644 static GstStructure *
3645 gst_decode_chain_get_topology (GstDecodeChain * chain)
3647 GstStructure *s, *u;
3651 if (G_UNLIKELY ((chain->endpad || chain->deadend)
3652 && (chain->endcaps == NULL))) {
3653 GST_WARNING ("End chain without valid caps !");
3657 u = gst_structure_new_id_empty (topology_structure_name);
3659 /* Now at the last element */
3660 if ((chain->elements || !chain->active_group) &&
3661 (chain->endpad || chain->deadend)) {
3662 s = gst_structure_new_id_empty (topology_structure_name);
3663 gst_structure_id_set (u, topology_caps, GST_TYPE_CAPS, chain->endcaps,
3666 if (chain->endpad) {
3667 gst_structure_id_set (u, topology_pad, GST_TYPE_PAD, chain->endpad, NULL);
3668 gst_structure_id_set (u, topology_element_srcpad, GST_TYPE_PAD,
3669 chain->endpad, NULL);
3671 gst_structure_id_set (s, topology_next, GST_TYPE_STRUCTURE, u, NULL);
3672 gst_structure_free (u);
3674 } else if (chain->active_group) {
3675 GValue list = { 0, };
3676 GValue item = { 0, };
3678 g_value_init (&list, GST_TYPE_LIST);
3679 g_value_init (&item, GST_TYPE_STRUCTURE);
3680 for (l = chain->active_group->children; l; l = l->next) {
3681 s = gst_decode_chain_get_topology (l->data);
3683 gst_value_set_structure (&item, s);
3684 gst_value_list_append_value (&list, &item);
3685 g_value_reset (&item);
3686 gst_structure_free (s);
3689 gst_structure_id_set_value (u, topology_next, &list);
3690 g_value_unset (&list);
3691 g_value_unset (&item);
3694 /* Get caps between all elements in this chain */
3695 l = (chain->elements && chain->elements->next) ? chain->elements : NULL;
3696 for (; l && l->next; l = l->next) {
3697 GstDecodeElement *delem, *delem_next;
3698 GstElement *elem, *elem_next;
3703 elem = delem->element;
3704 delem_next = l->next->data;
3705 elem_next = delem_next->element;
3708 caps = _gst_element_get_linked_caps (elem_next, elem, &srcpad);
3711 s = gst_structure_new_id_empty (topology_structure_name);
3712 gst_structure_id_set (u, topology_caps, GST_TYPE_CAPS, caps, NULL);
3713 gst_caps_unref (caps);
3715 gst_structure_id_set (s, topology_next, GST_TYPE_STRUCTURE, u, NULL);
3716 gst_structure_free (u);
3721 gst_structure_id_set (u, topology_element_srcpad, GST_TYPE_PAD, srcpad,
3723 gst_object_unref (srcpad);
3727 /* Caps that resulted in this chain */
3728 caps = gst_pad_get_current_caps (chain->pad);
3730 caps = get_pad_caps (chain->pad);
3731 if (G_UNLIKELY (!gst_caps_is_fixed (caps))) {
3732 GST_ERROR_OBJECT (chain->pad,
3733 "Couldn't get fixed caps, got %" GST_PTR_FORMAT, caps);
3734 gst_caps_unref (caps);
3738 gst_structure_id_set (u, topology_caps, GST_TYPE_CAPS, caps, NULL);
3739 gst_structure_id_set (u, topology_element_srcpad, GST_TYPE_PAD, chain->pad,
3741 gst_caps_unref (caps);
3747 gst_decode_bin_post_topology_message (GstDecodeBin * dbin)
3752 s = gst_decode_chain_get_topology (dbin->decode_chain);
3754 msg = gst_message_new_element (GST_OBJECT (dbin), s);
3755 gst_element_post_message (GST_ELEMENT (dbin), msg);
3758 /* Must only be called if the toplevel chain is complete and blocked! */
3759 /* Not MT-safe, call with decodebin expose lock! */
3761 gst_decode_bin_expose (GstDecodeBin * dbin)
3763 GList *tmp, *endpads = NULL;
3764 gboolean missing_plugin = FALSE;
3765 gboolean already_exposed = TRUE;
3767 GST_DEBUG_OBJECT (dbin, "Exposing currently active chains/groups");
3769 /* Don't expose if we're currently shutting down */
3771 if (G_UNLIKELY (dbin->shutdown == TRUE)) {
3772 GST_WARNING_OBJECT (dbin, "Currently, shutting down, aborting exposing");
3778 /* Get the pads that we're going to expose and mark things as exposed */
3779 if (!gst_decode_chain_expose (dbin->decode_chain, &endpads, &missing_plugin)) {
3780 g_list_foreach (endpads, (GFunc) gst_object_unref, NULL);
3781 g_list_free (endpads);
3782 GST_ERROR_OBJECT (dbin, "Broken chain/group tree");
3783 g_return_val_if_reached (FALSE);
3786 if (endpads == NULL) {
3787 if (missing_plugin) {
3788 GST_WARNING_OBJECT (dbin, "No suitable plugins found");
3789 GST_ELEMENT_ERROR (dbin, CORE, MISSING_PLUGIN, (NULL),
3790 ("no suitable plugins found"));
3792 /* in this case, the stream ended without buffers,
3793 * just post a warning */
3794 GST_WARNING_OBJECT (dbin, "All streams finished without buffers");
3795 GST_ELEMENT_ERROR (dbin, STREAM, FAILED, (NULL),
3796 ("all streams without buffers"));
3801 /* Check if this was called when everything was exposed already */
3802 for (tmp = endpads; tmp && already_exposed; tmp = tmp->next) {
3803 GstDecodePad *dpad = tmp->data;
3805 already_exposed &= dpad->exposed;
3806 if (!already_exposed)
3809 if (already_exposed) {
3810 GST_DEBUG_OBJECT (dbin, "Everything was exposed already!");
3811 g_list_foreach (endpads, (GFunc) gst_object_unref, NULL);
3812 g_list_free (endpads);
3816 /* Set all already exposed pads to blocked */
3817 for (tmp = endpads; tmp; tmp = tmp->next) {
3818 GstDecodePad *dpad = tmp->data;
3820 if (dpad->exposed) {
3821 GST_DEBUG_OBJECT (dpad, "blocking exposed pad");
3822 gst_decode_pad_set_blocked (dpad, TRUE);
3826 /* re-order pads : video, then audio, then others */
3827 endpads = g_list_sort (endpads, (GCompareFunc) sort_end_pads);
3830 for (tmp = endpads; tmp; tmp = tmp->next) {
3831 GstDecodePad *dpad = (GstDecodePad *) tmp->data;
3834 /* 1. rewrite name */
3835 padname = g_strdup_printf ("src_%u", dbin->nbpads);
3837 GST_DEBUG_OBJECT (dbin, "About to expose dpad %s as %s",
3838 GST_OBJECT_NAME (dpad), padname);
3839 gst_object_set_name (GST_OBJECT (dpad), padname);
3842 /* 2. activate and add */
3843 if (!dpad->exposed) {
3844 dpad->exposed = TRUE;
3845 if (!gst_element_add_pad (GST_ELEMENT (dbin), GST_PAD_CAST (dpad))) {
3846 /* not really fatal, we can try to add the other pads */
3847 g_warning ("error adding pad to decodebin");
3848 dpad->exposed = FALSE;
3853 /* 3. emit signal */
3854 GST_INFO_OBJECT (dpad, "added new decoded pad");
3857 /* 4. Signal no-more-pads. This allows the application to hook stuff to the
3859 GST_LOG_OBJECT (dbin, "signaling no-more-pads");
3860 gst_element_no_more_pads (GST_ELEMENT (dbin));
3862 /* 5. Send a custom element message with the stream topology */
3863 if (dbin->post_stream_topology)
3864 gst_decode_bin_post_topology_message (dbin);
3866 /* 6. Unblock internal pads. The application should have connected stuff now
3867 * so that streaming can continue. */
3868 for (tmp = endpads; tmp; tmp = tmp->next) {
3869 GstDecodePad *dpad = (GstDecodePad *) tmp->data;
3871 GST_DEBUG_OBJECT (dpad, "unblocking");
3872 gst_decode_pad_unblock (dpad);
3873 GST_DEBUG_OBJECT (dpad, "unblocked");
3874 gst_object_unref (dpad);
3876 g_list_free (endpads);
3878 do_async_done (dbin);
3879 GST_DEBUG_OBJECT (dbin, "Exposed everything");
3883 /* gst_decode_chain_expose:
3885 * Check if the chain can be exposed and add all endpads
3886 * to the endpads list.
3888 * Also update the active group's multiqueue to the
3891 * Not MT-safe, call with decodebin expose lock! *
3894 gst_decode_chain_expose (GstDecodeChain * chain, GList ** endpads,
3895 gboolean * missing_plugin)
3897 GstDecodeGroup *group;
3901 if (chain->deadend) {
3903 *missing_plugin = TRUE;
3907 if (chain->endpad) {
3908 if (!chain->endpad->blocked && !chain->endpad->exposed)
3910 *endpads = g_list_prepend (*endpads, gst_object_ref (chain->endpad));
3914 group = chain->active_group;
3917 if (!group->no_more_pads && !group->overrun)
3922 /* configure queues for playback */
3923 decodebin_set_queue_size (dbin, group->multiqueue, FALSE, TRUE);
3925 /* we can now disconnect any overrun signal, which is used to expose the
3927 if (group->overrunsig) {
3928 GST_LOG_OBJECT (dbin, "Disconnecting overrun");
3929 g_signal_handler_disconnect (group->multiqueue, group->overrunsig);
3930 group->overrunsig = 0;
3933 for (l = group->children; l; l = l->next) {
3934 GstDecodeChain *childchain = l->data;
3936 if (!gst_decode_chain_expose (childchain, endpads, missing_plugin))
3943 /*************************
3944 * GstDecodePad functions
3945 *************************/
3948 gst_decode_pad_class_init (GstDecodePadClass * klass)
3953 gst_decode_pad_init (GstDecodePad * pad)
3956 pad->blocked = FALSE;
3957 pad->exposed = FALSE;
3958 pad->drained = FALSE;
3959 gst_object_ref_sink (pad);
3962 static GstPadProbeReturn
3963 source_pad_blocked_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
3965 GstDecodePad *dpad = user_data;
3966 GstDecodeChain *chain;
3969 if (GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) {
3970 GST_LOG_OBJECT (pad, "Seeing event '%s'",
3971 GST_EVENT_TYPE_NAME (GST_PAD_PROBE_INFO_EVENT (info)));
3973 if (GST_EVENT_TYPE (GST_PAD_PROBE_INFO_EVENT (info)) == GST_EVENT_CAPS) {
3974 /* manually push event to ghost pad to avoid exposing pads
3975 * that don't have the sticky caps event */
3976 gst_pad_push_event (GST_PAD_CAST (dpad),
3977 gst_event_ref (GST_PAD_PROBE_INFO_EVENT (info)));
3978 } else if ((GST_EVENT_IS_STICKY (GST_PAD_PROBE_INFO_EVENT (info))
3979 || !GST_EVENT_IS_SERIALIZED (GST_PAD_PROBE_INFO_EVENT (info)))) {
3980 /* do not block on sticky or out of band events otherwise the allocation query
3981 from demuxer might block the loop thread */
3982 GST_LOG_OBJECT (pad, "Letting event through");
3983 return GST_PAD_PROBE_PASS;
3986 chain = dpad->chain;
3989 GST_LOG_OBJECT (dpad, "blocked: dpad->chain:%p", chain);
3991 dpad->blocked = TRUE;
3994 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
3995 if (!gst_decode_bin_expose (dbin))
3996 GST_WARNING_OBJECT (dbin, "Couldn't expose group");
3998 EXPOSE_UNLOCK (dbin);
4000 /* If we unblocked due to a caps event, let it go through */
4001 if ((GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) &&
4002 (GST_EVENT_TYPE (GST_PAD_PROBE_INFO_EVENT (info)) == GST_EVENT_CAPS))
4003 return GST_PAD_PROBE_PASS;
4005 return GST_PAD_PROBE_OK;
4008 static GstPadProbeReturn
4009 source_pad_event_probe (GstPad * pad, GstPadProbeInfo * info,
4012 GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info);
4013 GstDecodePad *dpad = user_data;
4014 gboolean res = TRUE;
4016 GST_LOG_OBJECT (pad, "%s dpad:%p", GST_EVENT_TYPE_NAME (event), dpad);
4018 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
4019 GST_DEBUG_OBJECT (pad, "we received EOS");
4021 /* Check if all pads are drained.
4022 * * If there is no next group, we will let the EOS go through.
4023 * * If there is a next group but the current group isn't completely
4024 * drained, we will drop the EOS event.
4025 * * If there is a next group to expose and this was the last non-drained
4026 * pad for that group, we will remove the ghostpad of the current group
4027 * first, which unlinks the peer and so drops the EOS. */
4028 res = gst_decode_pad_handle_eos (dpad);
4031 return GST_PAD_PROBE_OK;
4033 return GST_PAD_PROBE_DROP;
4037 gst_decode_pad_set_blocked (GstDecodePad * dpad, gboolean blocked)
4039 GstDecodeBin *dbin = dpad->dbin;
4044 GST_DEBUG_OBJECT (dpad, "blocking pad: %d", blocked);
4046 opad = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (dpad));
4050 /* do not block if shutting down.
4051 * we do not consider/expect it blocked further below, but use other trick */
4052 if (!blocked || !dbin->shutdown) {
4054 if (dpad->block_id == 0)
4056 gst_pad_add_probe (opad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
4057 source_pad_blocked_cb, gst_object_ref (dpad),
4058 (GDestroyNotify) gst_object_unref);
4060 if (dpad->block_id != 0) {
4061 gst_pad_remove_probe (opad, dpad->block_id);
4064 dpad->blocked = FALSE;
4069 if (dbin->shutdown) {
4070 /* deactivate to force flushing state to prevent NOT_LINKED errors */
4071 gst_pad_set_active (GST_PAD_CAST (dpad), FALSE);
4072 /* note that deactivating the target pad would have no effect here,
4073 * since elements are typically connected first (and pads exposed),
4074 * and only then brought to PAUSED state (so pads activated) */
4076 gst_object_ref (dpad);
4077 dbin->blocked_pads = g_list_prepend (dbin->blocked_pads, dpad);
4082 if ((l = g_list_find (dbin->blocked_pads, dpad))) {
4083 gst_object_unref (dpad);
4084 dbin->blocked_pads = g_list_delete_link (dbin->blocked_pads, l);
4087 gst_object_unref (opad);
4093 gst_decode_pad_add_drained_check (GstDecodePad * dpad)
4095 gst_pad_add_probe (GST_PAD_CAST (dpad), GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
4096 source_pad_event_probe, dpad, NULL);
4100 gst_decode_pad_activate (GstDecodePad * dpad, GstDecodeChain * chain)
4102 g_return_if_fail (chain != NULL);
4104 dpad->chain = chain;
4105 gst_pad_set_active (GST_PAD_CAST (dpad), TRUE);
4106 gst_decode_pad_set_blocked (dpad, TRUE);
4107 gst_decode_pad_add_drained_check (dpad);
4111 gst_decode_pad_unblock (GstDecodePad * dpad)
4113 gst_decode_pad_set_blocked (dpad, FALSE);
4117 gst_decode_pad_query (GstPad * pad, GstObject * parent, GstQuery * query)
4119 GstDecodePad *dpad = GST_DECODE_PAD (parent);
4120 gboolean ret = FALSE;
4122 if (!dpad->exposed && !dpad->chain->deadend) {
4124 g_signal_emit (G_OBJECT (dpad->dbin),
4125 gst_decode_bin_signals[SIGNAL_AUTOPLUG_QUERY], 0, dpad, query, &ret);
4126 GST_DEBUG_OBJECT (dpad->dbin, "autoplug-query returned %d", ret);
4128 GstCaps *result, *filter;
4129 GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD (dpad));
4131 gst_query_parse_caps (query, &filter);
4132 gst_query_parse_caps_result (query, &result);
4134 gst_caps_merge (gst_caps_ref (result),
4135 gst_pad_get_pad_template_caps (target));
4137 GstCaps *intersection =
4138 gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
4139 gst_caps_unref (result);
4140 result = intersection;
4142 gst_query_set_caps_result (query, result);
4143 gst_caps_unref (result);
4145 gst_object_unref (target);
4149 /* If exposed or nothing handled the query use the default handler */
4151 ret = gst_pad_query_default (pad, parent, query);
4156 /*gst_decode_pad_new:
4158 * Creates a new GstDecodePad for the given pad.
4160 static GstDecodePad *
4161 gst_decode_pad_new (GstDecodeBin * dbin, GstDecodeChain * chain)
4165 GstPadTemplate *pad_tmpl;
4167 GST_DEBUG_OBJECT (dbin, "making new decodepad");
4168 pad_tmpl = gst_static_pad_template_get (&decoder_bin_src_template);
4170 g_object_new (GST_TYPE_DECODE_PAD, "direction", GST_PAD_SRC,
4171 "template", pad_tmpl, NULL);
4172 gst_ghost_pad_construct (GST_GHOST_PAD_CAST (dpad));
4173 dpad->chain = chain;
4175 gst_object_unref (pad_tmpl);
4177 ppad = gst_proxy_pad_get_internal (GST_PROXY_PAD (dpad));
4178 gst_pad_set_query_function (GST_PAD_CAST (ppad), gst_decode_pad_query);
4179 gst_object_unref (ppad);
4185 gst_pending_pad_free (GstPendingPad * ppad)
4188 g_assert (ppad->pad);
4190 if (ppad->event_probe_id != 0)
4191 gst_pad_remove_probe (ppad->pad, ppad->event_probe_id);
4192 gst_object_unref (ppad->pad);
4193 g_slice_free (GstPendingPad, ppad);
4197 * Element add/remove
4201 do_async_start (GstDecodeBin * dbin)
4203 GstMessage *message;
4205 dbin->async_pending = TRUE;
4207 message = gst_message_new_async_start (GST_OBJECT_CAST (dbin));
4208 parent_class->handle_message (GST_BIN_CAST (dbin), message);
4212 do_async_done (GstDecodeBin * dbin)
4214 GstMessage *message;
4216 if (dbin->async_pending) {
4218 gst_message_new_async_done (GST_OBJECT_CAST (dbin),
4219 GST_CLOCK_TIME_NONE);
4220 parent_class->handle_message (GST_BIN_CAST (dbin), message);
4222 dbin->async_pending = FALSE;
4227 * convenience functions
4232 * Returns the first sink pad of the given element, or NULL if it doesn't have
4237 find_sink_pad (GstElement * element)
4241 GValue item = { 0, };
4243 it = gst_element_iterate_sink_pads (element);
4245 if ((gst_iterator_next (it, &item)) == GST_ITERATOR_OK)
4246 pad = g_value_dup_object (&item);
4247 g_value_unset (&item);
4248 gst_iterator_free (it);
4253 /* call with dyn_lock held */
4255 unblock_pads (GstDecodeBin * dbin)
4259 GST_LOG_OBJECT (dbin, "unblocking pads");
4261 for (tmp = dbin->blocked_pads; tmp; tmp = tmp->next) {
4262 GstDecodePad *dpad = (GstDecodePad *) tmp->data;
4265 opad = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (dpad));
4269 GST_DEBUG_OBJECT (dpad, "unblocking");
4270 if (dpad->block_id != 0) {
4271 gst_pad_remove_probe (opad, dpad->block_id);
4274 dpad->blocked = FALSE;
4275 /* make flushing, prevent NOT_LINKED */
4276 GST_PAD_SET_FLUSHING (GST_PAD_CAST (dpad));
4277 gst_object_unref (dpad);
4278 gst_object_unref (opad);
4279 GST_DEBUG_OBJECT (dpad, "unblocked");
4282 /* clear, no more blocked pads */
4283 g_list_free (dbin->blocked_pads);
4284 dbin->blocked_pads = NULL;
4287 static GstStateChangeReturn
4288 gst_decode_bin_change_state (GstElement * element, GstStateChange transition)
4290 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
4291 GstDecodeBin *dbin = GST_DECODE_BIN (element);
4293 switch (transition) {
4294 case GST_STATE_CHANGE_NULL_TO_READY:
4295 if (dbin->typefind == NULL)
4296 goto missing_typefind;
4298 case GST_STATE_CHANGE_READY_TO_PAUSED:
4299 /* Make sure we've cleared all existing chains */
4300 if (dbin->decode_chain) {
4301 gst_decode_chain_free (dbin->decode_chain);
4302 dbin->decode_chain = NULL;
4305 GST_LOG_OBJECT (dbin, "clearing shutdown flag");
4306 dbin->shutdown = FALSE;
4308 dbin->have_type = FALSE;
4309 ret = GST_STATE_CHANGE_ASYNC;
4310 do_async_start (dbin);
4312 case GST_STATE_CHANGE_PAUSED_TO_READY:
4314 GST_LOG_OBJECT (dbin, "setting shutdown flag");
4315 dbin->shutdown = TRUE;
4316 unblock_pads (dbin);
4323 GstStateChangeReturn bret;
4325 bret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
4326 if (G_UNLIKELY (bret == GST_STATE_CHANGE_FAILURE))
4327 goto activate_failed;
4328 else if (G_UNLIKELY (bret == GST_STATE_CHANGE_NO_PREROLL)) {
4329 do_async_done (dbin);
4333 switch (transition) {
4334 case GST_STATE_CHANGE_PAUSED_TO_READY:
4335 do_async_done (dbin);
4336 if (dbin->decode_chain) {
4337 gst_decode_chain_free (dbin->decode_chain);
4338 dbin->decode_chain = NULL;
4341 case GST_STATE_CHANGE_READY_TO_NULL:
4351 gst_element_post_message (element,
4352 gst_missing_element_message_new (element, "typefind"));
4353 GST_ELEMENT_ERROR (dbin, CORE, MISSING_PLUGIN, (NULL), ("no typefind!"));
4354 return GST_STATE_CHANGE_FAILURE;
4358 GST_DEBUG_OBJECT (element,
4359 "element failed to change states -- activation problem?");
4360 return GST_STATE_CHANGE_FAILURE;
4365 gst_decode_bin_handle_message (GstBin * bin, GstMessage * msg)
4367 GstDecodeBin *dbin = GST_DECODE_BIN (bin);
4368 gboolean drop = FALSE;
4370 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
4371 GST_OBJECT_LOCK (dbin);
4372 drop = (g_list_find (dbin->filtered, GST_MESSAGE_SRC (msg)) != NULL);
4373 GST_OBJECT_UNLOCK (dbin);
4377 gst_message_unref (msg);
4379 GST_BIN_CLASS (parent_class)->handle_message (bin, msg);
4383 gst_decode_bin_plugin_init (GstPlugin * plugin)
4385 GST_DEBUG_CATEGORY_INIT (gst_decode_bin_debug, "decodebin", 0, "decoder bin");
4387 /* Register some quarks here for the stream topology message */
4388 topology_structure_name = g_quark_from_static_string ("stream-topology");
4389 topology_caps = g_quark_from_static_string ("caps");
4390 topology_next = g_quark_from_static_string ("next");
4391 topology_pad = g_quark_from_static_string ("pad");
4392 topology_element_srcpad = g_quark_from_static_string ("element-srcpad");
4394 return gst_element_register (plugin, "decodebin", GST_RANK_NONE,
4395 GST_TYPE_DECODE_BIN);