2 * Copyright (C) <2006> Edward Hervey <edward@fluendo.com>
3 * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:element-decodebin
24 * #GstBin that auto-magically constructs a decoding pipeline using available
25 * decoders and demuxers via auto-plugging.
27 * decodebin is considered stable now and replaces the old #decodebin element.
28 * #uridecodebin uses decodebin internally and is often more convenient to
29 * use, as it creates a suitable source element as well.
32 /* Implementation notes:
34 * The following section describes how decodebin works internally.
36 * The first part of decodebin is its typefind element, which tries
37 * to determine the media type of the input stream. If the type is found
38 * autoplugging starts.
40 * decodebin internally organizes the elements it autoplugged into GstDecodeChains
41 * and GstDecodeGroups. A decode chain is a single chain of decoding, this
42 * means that if decodebin every autoplugs an element with two+ srcpads
43 * (e.g. a demuxer) this will end the chain and everything following this
44 * demuxer will be put into decode groups below the chain. Otherwise,
45 * if an element has a single srcpad that outputs raw data the decode chain
46 * is ended too and a GstDecodePad is stored and blocked.
48 * A decode group combines a number of chains that are created by a
49 * demuxer element. All those chains are connected through a multiqueue to
50 * the demuxer. A new group for the same demuxer is only created if the
51 * demuxer has signaled no-more-pads, in which case all following pads
52 * create a new chain in the new group.
54 * This continues until the top-level decode chain is complete. A decode
55 * chain is complete if it either ends with a blocked endpad, if autoplugging
56 * stopped because no suitable plugins could be found or if the active group
57 * is complete. A decode group on the other hand is complete if all child
58 * chains are complete.
60 * If this happens at some point, all endpads of all active groups are exposed.
61 * For this decodebin adds the endpads, signals no-more-pads and then unblocks
62 * them. Now playback starts.
64 * If one of the chains that end on a endpad receives EOS decodebin checks
65 * if all chains and groups are drained. In that case everything goes into EOS.
66 * If there is a chain where the active group is drained but there exist next
67 * groups, the active group is hidden (endpads are removed) and the next group
68 * is exposed. This means that in some cases more pads may be created even
69 * after the initial no-more-pads signal. This happens for example with
70 * so-called "chained oggs", most commonly found among ogg/vorbis internet
73 * Note 1: If we're talking about blocked endpads this really means that the
74 * *target* pads of the endpads are blocked. Pads that are exposed to the outside
75 * should never ever be blocked!
77 * Note 2: If a group is complete and the parent's chain demuxer adds new pads
78 * but never signaled no-more-pads this additional pads will be ignored!
86 #include <gst/gst-i18n-plugin.h>
90 #include <gst/pbutils/pbutils.h>
92 #include "gstplay-marshal.h"
93 #include "gstplay-enum.h"
94 #include "gstplayback.h"
95 #include "gstrawcaps.h"
97 /* generic templates */
98 static GstStaticPadTemplate decoder_bin_sink_template =
99 GST_STATIC_PAD_TEMPLATE ("sink",
102 GST_STATIC_CAPS_ANY);
104 static GstStaticPadTemplate decoder_bin_src_template =
105 GST_STATIC_PAD_TEMPLATE ("src%d",
108 GST_STATIC_CAPS_ANY);
110 GST_DEBUG_CATEGORY_STATIC (gst_decode_bin_debug);
111 #define GST_CAT_DEFAULT gst_decode_bin_debug
113 typedef struct _GstPendingPad GstPendingPad;
114 typedef struct _GstDecodeChain GstDecodeChain;
115 typedef struct _GstDecodeGroup GstDecodeGroup;
116 typedef struct _GstDecodePad GstDecodePad;
117 typedef GstGhostPadClass GstDecodePadClass;
118 typedef struct _GstDecodeBin GstDecodeBin;
119 typedef struct _GstDecodeBinClass GstDecodeBinClass;
121 #define GST_TYPE_DECODE_BIN (gst_decode_bin_get_type())
122 #define GST_DECODE_BIN_CAST(obj) ((GstDecodeBin*)(obj))
123 #define GST_DECODE_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECODE_BIN,GstDecodeBin))
124 #define GST_DECODE_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DECODE_BIN,GstDecodeBinClass))
125 #define GST_IS_DECODE_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DECODE_BIN))
126 #define GST_IS_DECODE_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DECODE_BIN))
131 * The opaque #GstDecodeBin data structure
135 GstBin bin; /* we extend GstBin */
138 GstCaps *caps; /* caps on which to stop decoding */
139 gchar *encoding; /* encoding of subtitles */
140 gboolean use_buffering; /* configure buffering on multiqueues */
143 guint max_size_bytes;
144 guint max_size_buffers;
145 guint64 max_size_time;
146 gboolean post_stream_topology;
148 GstElement *typefind; /* this holds the typefind object */
150 GMutex *expose_lock; /* Protects exposal and removal of groups */
151 GstDecodeChain *decode_chain; /* Top level decode chain */
152 gint nbpads; /* unique identifier for source pads */
154 GMutex *factories_lock;
155 guint32 factories_cookie; /* Cookie from last time when factories was updated */
156 GList *factories; /* factories we can use for selecting elements */
158 GMutex *subtitle_lock; /* Protects changes to subtitles and encoding */
159 GList *subtitles; /* List of elements with subtitle-encoding,
160 * protected by above mutex! */
162 gboolean have_type; /* if we received the have_type signal */
163 guint have_type_id; /* signal id for have-type from typefind */
165 gboolean async_pending; /* async-start has been emited */
167 GMutex *dyn_lock; /* lock protecting pad blocking */
168 gboolean shutdown; /* if we are shutting down */
169 GList *blocked_pads; /* pads that have set to block */
171 gboolean expose_allstreams; /* Whether to expose unknow type streams or not */
173 gboolean upstream_seekable; /* if upstream is seekable */
176 struct _GstDecodeBinClass
178 GstBinClass parent_class;
180 /* signal fired when we found a pad that we cannot decode */
181 void (*unknown_type) (GstElement * element, GstPad * pad, GstCaps * caps);
183 /* signal fired to know if we continue trying to decode the given caps */
184 gboolean (*autoplug_continue) (GstElement * element, GstPad * pad,
186 /* signal fired to get a list of factories to try to autoplug */
187 GValueArray *(*autoplug_factories) (GstElement * element, GstPad * pad,
189 /* signal fired to sort the factories */
190 GValueArray *(*autoplug_sort) (GstElement * element, GstPad * pad,
191 GstCaps * caps, GValueArray * factories);
192 /* signal fired to select from the proposed list of factories */
193 GstAutoplugSelectResult (*autoplug_select) (GstElement * element,
194 GstPad * pad, GstCaps * caps, GstElementFactory * factory);
196 /* fired when the last group is drained */
197 void (*drained) (GstElement * element);
204 SIGNAL_AUTOPLUG_CONTINUE,
205 SIGNAL_AUTOPLUG_FACTORIES,
206 SIGNAL_AUTOPLUG_SELECT,
207 SIGNAL_AUTOPLUG_SORT,
212 /* automatic sizes, while prerolling we buffer up to 2MB, we ignore time
213 * and buffers in this case. */
214 #define AUTO_PREROLL_SIZE_BYTES 2 * 1024 * 1024
215 #define AUTO_PREROLL_SIZE_BUFFERS 0
216 #define AUTO_PREROLL_NOT_SEEKABLE_SIZE_TIME 0
217 #define AUTO_PREROLL_SEEKABLE_SIZE_TIME 10 * GST_SECOND
219 /* whan playing, keep a max of 2MB of data but try to keep the number of buffers
220 * as low as possible (try to aim for 5 buffers) */
221 #define AUTO_PLAY_SIZE_BYTES 2 * 1024 * 1024
222 #define AUTO_PLAY_SIZE_BUFFERS 5
223 #define AUTO_PLAY_SIZE_TIME 0
225 #define DEFAULT_SUBTITLE_ENCODING NULL
226 #define DEFAULT_USE_BUFFERING FALSE
227 #define DEFAULT_LOW_PERCENT 10
228 #define DEFAULT_HIGH_PERCENT 99
229 /* by default we use the automatic values above */
230 #define DEFAULT_MAX_SIZE_BYTES 0
231 #define DEFAULT_MAX_SIZE_BUFFERS 0
232 #define DEFAULT_MAX_SIZE_TIME 0
233 #define DEFAULT_POST_STREAM_TOPOLOGY FALSE
234 #define DEFAULT_EXPOSE_ALL_STREAMS TRUE
241 PROP_SUBTITLE_ENCODING,
247 PROP_MAX_SIZE_BUFFERS,
249 PROP_POST_STREAM_TOPOLOGY,
250 PROP_EXPOSE_ALL_STREAMS,
254 static GstBinClass *parent_class;
255 static guint gst_decode_bin_signals[LAST_SIGNAL] = { 0 };
257 static GstStaticCaps default_raw_caps = GST_STATIC_CAPS (DEFAULT_RAW_CAPS);
259 static void do_async_start (GstDecodeBin * dbin);
260 static void do_async_done (GstDecodeBin * dbin);
262 static void type_found (GstElement * typefind, guint probability,
263 GstCaps * caps, GstDecodeBin * decode_bin);
265 static void decodebin_set_queue_size (GstDecodeBin * dbin,
266 GstElement * multiqueue, gboolean preroll);
268 static gboolean gst_decode_bin_autoplug_continue (GstElement * element,
269 GstPad * pad, GstCaps * caps);
270 static GValueArray *gst_decode_bin_autoplug_factories (GstElement *
271 element, GstPad * pad, GstCaps * caps);
272 static GValueArray *gst_decode_bin_autoplug_sort (GstElement * element,
273 GstPad * pad, GstCaps * caps, GValueArray * factories);
274 static GstAutoplugSelectResult gst_decode_bin_autoplug_select (GstElement *
275 element, GstPad * pad, GstCaps * caps, GstElementFactory * factory);
277 static void gst_decode_bin_set_property (GObject * object, guint prop_id,
278 const GValue * value, GParamSpec * pspec);
279 static void gst_decode_bin_get_property (GObject * object, guint prop_id,
280 GValue * value, GParamSpec * pspec);
281 static void gst_decode_bin_set_caps (GstDecodeBin * dbin, GstCaps * caps);
282 static GstCaps *gst_decode_bin_get_caps (GstDecodeBin * dbin);
283 static void caps_notify_cb (GstPad * pad, GParamSpec * unused,
284 GstDecodeChain * chain);
286 static GstPad *find_sink_pad (GstElement * element);
287 static GstStateChangeReturn gst_decode_bin_change_state (GstElement * element,
288 GstStateChange transition);
290 #define EXPOSE_LOCK(dbin) G_STMT_START { \
291 GST_LOG_OBJECT (dbin, \
292 "expose locking from thread %p", \
294 g_mutex_lock (GST_DECODE_BIN_CAST(dbin)->expose_lock); \
295 GST_LOG_OBJECT (dbin, \
296 "expose locked from thread %p", \
300 #define EXPOSE_UNLOCK(dbin) G_STMT_START { \
301 GST_LOG_OBJECT (dbin, \
302 "expose unlocking from thread %p", \
304 g_mutex_unlock (GST_DECODE_BIN_CAST(dbin)->expose_lock); \
307 #define DYN_LOCK(dbin) G_STMT_START { \
308 GST_LOG_OBJECT (dbin, \
309 "dynlocking from thread %p", \
311 g_mutex_lock (GST_DECODE_BIN_CAST(dbin)->dyn_lock); \
312 GST_LOG_OBJECT (dbin, \
313 "dynlocked from thread %p", \
317 #define DYN_UNLOCK(dbin) G_STMT_START { \
318 GST_LOG_OBJECT (dbin, \
319 "dynunlocking from thread %p", \
321 g_mutex_unlock (GST_DECODE_BIN_CAST(dbin)->dyn_lock); \
324 #define SUBTITLE_LOCK(dbin) G_STMT_START { \
325 GST_LOG_OBJECT (dbin, \
326 "subtitle locking from thread %p", \
328 g_mutex_lock (GST_DECODE_BIN_CAST(dbin)->subtitle_lock); \
329 GST_LOG_OBJECT (dbin, \
330 "subtitle lock from thread %p", \
334 #define SUBTITLE_UNLOCK(dbin) G_STMT_START { \
335 GST_LOG_OBJECT (dbin, \
336 "subtitle unlocking from thread %p", \
338 g_mutex_unlock (GST_DECODE_BIN_CAST(dbin)->subtitle_lock); \
341 struct _GstPendingPad
344 GstDecodeChain *chain;
345 gulong event_probe_id;
350 * Streams belonging to the same group/chain of a media file
352 * When changing something here lock the parent chain!
354 struct _GstDecodeGroup
357 GstDecodeChain *parent;
359 GstElement *multiqueue; /* Used for linking all child chains */
360 gulong overrunsig; /* the overrun signal for multiqueue */
362 gboolean overrun; /* TRUE if the multiqueue signaled overrun. This
363 * means that we should really expose the group */
365 gboolean no_more_pads; /* TRUE if the demuxer signaled no-more-pads */
366 gboolean drained; /* TRUE if the all children are drained */
368 GList *children; /* List of GstDecodeChains in this group */
370 GList *reqpads; /* List of RequestPads for multiqueue, there is
371 * exactly one RequestPad per child chain */
374 struct _GstDecodeChain
376 GstDecodeGroup *parent;
379 GMutex *lock; /* Protects this chain and its groups */
381 GstPad *pad; /* srcpad that caused creation of this chain */
383 gboolean demuxer; /* TRUE if elements->data is a demuxer */
384 GList *elements; /* All elements in this group, first
385 is the latest and most downstream element */
387 /* Note: there are only groups if the last element of this chain
388 * is a demuxer, otherwise the chain will end with an endpad.
389 * The other way around this means, that endpad only exists if this
390 * chain doesn't end with a demuxer! */
392 GstDecodeGroup *active_group; /* Currently active group */
393 GList *next_groups; /* head is newest group, tail is next group.
394 a new group will be created only if the head
395 group had no-more-pads. If it's only exposed
396 all new pads will be ignored! */
397 GList *pending_pads; /* Pads that have no fixed caps yet */
399 GstDecodePad *endpad; /* Pad of this chain that could be exposed */
400 gboolean deadend; /* This chain is incomplete and can't be completed,
401 e.g. no suitable decoder could be found
402 e.g. stream got EOS without buffers
404 GstCaps *endcaps; /* Caps that were used when linking to the endpad
405 or that resulted in the deadend
408 /* FIXME: This should be done directly via a thread! */
409 GList *old_groups; /* Groups that should be freed later */
412 static void gst_decode_chain_free (GstDecodeChain * chain);
413 static GstDecodeChain *gst_decode_chain_new (GstDecodeBin * dbin,
414 GstDecodeGroup * group, GstPad * pad);
415 static void gst_decode_group_hide (GstDecodeGroup * group);
416 static void gst_decode_group_free (GstDecodeGroup * group);
417 static GstDecodeGroup *gst_decode_group_new (GstDecodeBin * dbin,
418 GstDecodeChain * chain);
419 static gboolean gst_decode_chain_is_complete (GstDecodeChain * chain);
420 static void gst_decode_chain_handle_eos (GstDecodeChain * chain);
421 static gboolean gst_decode_chain_expose (GstDecodeChain * chain,
422 GList ** endpads, gboolean * missing_plugin);
423 static gboolean gst_decode_chain_is_drained (GstDecodeChain * chain);
424 static gboolean gst_decode_group_is_complete (GstDecodeGroup * group);
425 static GstPad *gst_decode_group_control_demuxer_pad (GstDecodeGroup * group,
427 static gboolean gst_decode_group_is_drained (GstDecodeGroup * group);
429 static gboolean gst_decode_bin_expose (GstDecodeBin * dbin);
431 #define CHAIN_MUTEX_LOCK(chain) G_STMT_START { \
432 GST_LOG_OBJECT (chain->dbin, \
433 "locking chain %p from thread %p", \
434 chain, g_thread_self ()); \
435 g_mutex_lock (chain->lock); \
436 GST_LOG_OBJECT (chain->dbin, \
437 "locked chain %p from thread %p", \
438 chain, g_thread_self ()); \
441 #define CHAIN_MUTEX_UNLOCK(chain) G_STMT_START { \
442 GST_LOG_OBJECT (chain->dbin, \
443 "unlocking chain %p from thread %p", \
444 chain, g_thread_self ()); \
445 g_mutex_unlock (chain->lock); \
450 * GstPad private used for source pads of chains
456 GstDecodeChain *chain;
458 gboolean blocked; /* the *target* pad is blocked */
459 gboolean exposed; /* the pad is exposed */
460 gboolean drained; /* an EOS has been seen on the pad */
465 GType gst_decode_pad_get_type (void);
466 G_DEFINE_TYPE (GstDecodePad, gst_decode_pad, GST_TYPE_GHOST_PAD);
467 #define GST_TYPE_DECODE_PAD (gst_decode_pad_get_type ())
468 #define GST_DECODE_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECODE_PAD,GstDecodePad))
470 static GstDecodePad *gst_decode_pad_new (GstDecodeBin * dbin, GstPad * pad,
471 GstDecodeChain * chain);
472 static void gst_decode_pad_activate (GstDecodePad * dpad,
473 GstDecodeChain * chain);
474 static void gst_decode_pad_unblock (GstDecodePad * dpad);
475 static void gst_decode_pad_set_blocked (GstDecodePad * dpad, gboolean blocked);
477 static void gst_pending_pad_free (GstPendingPad * ppad);
478 static GstProbeReturn pad_event_cb (GstPad * pad, GstProbeType type,
479 gpointer type_data, gpointer data);
481 /********************************
482 * Standard GObject boilerplate *
483 ********************************/
485 static void gst_decode_bin_class_init (GstDecodeBinClass * klass);
486 static void gst_decode_bin_init (GstDecodeBin * decode_bin);
487 static void gst_decode_bin_dispose (GObject * object);
488 static void gst_decode_bin_finalize (GObject * object);
491 gst_decode_bin_get_type (void)
493 static GType gst_decode_bin_type = 0;
495 if (!gst_decode_bin_type) {
496 static const GTypeInfo gst_decode_bin_info = {
497 sizeof (GstDecodeBinClass),
500 (GClassInitFunc) gst_decode_bin_class_init,
503 sizeof (GstDecodeBin),
505 (GInstanceInitFunc) gst_decode_bin_init,
509 gst_decode_bin_type =
510 g_type_register_static (GST_TYPE_BIN, "GstDecodeBin",
511 &gst_decode_bin_info, 0);
514 return gst_decode_bin_type;
518 _gst_boolean_accumulator (GSignalInvocationHint * ihint,
519 GValue * return_accu, const GValue * handler_return, gpointer dummy)
523 myboolean = g_value_get_boolean (handler_return);
524 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
525 g_value_set_boolean (return_accu, myboolean);
527 /* stop emission if FALSE */
531 /* we collect the first result */
533 _gst_array_accumulator (GSignalInvocationHint * ihint,
534 GValue * return_accu, const GValue * handler_return, gpointer dummy)
538 array = g_value_get_boxed (handler_return);
539 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
540 g_value_set_boxed (return_accu, array);
546 _gst_select_accumulator (GSignalInvocationHint * ihint,
547 GValue * return_accu, const GValue * handler_return, gpointer dummy)
549 GstAutoplugSelectResult res;
551 res = g_value_get_enum (handler_return);
552 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
553 g_value_set_enum (return_accu, res);
559 _gst_array_hasvalue_accumulator (GSignalInvocationHint * ihint,
560 GValue * return_accu, const GValue * handler_return, gpointer dummy)
564 array = g_value_get_boxed (handler_return);
565 if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
566 g_value_set_boxed (return_accu, array);
575 gst_decode_bin_class_init (GstDecodeBinClass * klass)
577 GObjectClass *gobject_klass;
578 GstElementClass *gstelement_klass;
580 gobject_klass = (GObjectClass *) klass;
581 gstelement_klass = (GstElementClass *) klass;
583 parent_class = g_type_class_peek_parent (klass);
585 gobject_klass->dispose = gst_decode_bin_dispose;
586 gobject_klass->finalize = gst_decode_bin_finalize;
587 gobject_klass->set_property = gst_decode_bin_set_property;
588 gobject_klass->get_property = gst_decode_bin_get_property;
591 * GstDecodeBin::unknown-type:
592 * @bin: The decodebin.
593 * @pad: The new pad containing caps that cannot be resolved to a 'final'
595 * @caps: The #GstCaps of the pad that cannot be resolved.
597 * This signal is emitted when a pad for which there is no further possible
598 * decoding is added to the decodebin.
600 gst_decode_bin_signals[SIGNAL_UNKNOWN_TYPE] =
601 g_signal_new ("unknown-type", G_TYPE_FROM_CLASS (klass),
602 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, unknown_type),
603 NULL, NULL, gst_marshal_VOID__OBJECT_BOXED, G_TYPE_NONE, 2,
604 GST_TYPE_PAD, GST_TYPE_CAPS);
607 * GstDecodeBin::autoplug-continue:
608 * @bin: The decodebin.
610 * @caps: The #GstCaps found.
612 * This signal is emitted whenever decodebin finds a new stream. It is
613 * emitted before looking for any elements that can handle that stream.
616 * Invocation of signal handlers stops after the first signal handler
617 * returns #FALSE. Signal handlers are invoked in the order they were
621 * Returns: #TRUE if you wish decodebin to look for elements that can
622 * handle the given @caps. If #FALSE, those caps will be considered as
623 * final and the pad will be exposed as such (see 'pad-added' signal of
626 gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE] =
627 g_signal_new ("autoplug-continue", G_TYPE_FROM_CLASS (klass),
628 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_continue),
629 _gst_boolean_accumulator, NULL, gst_play_marshal_BOOLEAN__OBJECT_BOXED,
630 G_TYPE_BOOLEAN, 2, GST_TYPE_PAD, GST_TYPE_CAPS);
633 * GstDecodeBin::autoplug-factories:
634 * @bin: The decodebin.
636 * @caps: The #GstCaps found.
638 * This function is emited when an array of possible factories for @caps on
639 * @pad is needed. Decodebin will by default return an array with all
640 * compatible factories, sorted by rank.
642 * If this function returns NULL, @pad will be exposed as a final caps.
644 * If this function returns an empty array, the pad will be considered as
645 * having an unhandled type media type.
648 * Only the signal handler that is connected first will ever by invoked.
649 * Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
650 * signal, they will never be invoked!
653 * Returns: a #GValueArray* with a list of factories to try. The factories are
654 * by default tried in the returned order or based on the index returned by
657 gst_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES] =
658 g_signal_new ("autoplug-factories", G_TYPE_FROM_CLASS (klass),
659 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass,
660 autoplug_factories), _gst_array_accumulator, NULL,
661 gst_play_marshal_BOXED__OBJECT_BOXED, G_TYPE_VALUE_ARRAY, 2,
662 GST_TYPE_PAD, GST_TYPE_CAPS);
665 * GstDecodeBin::autoplug-sort:
666 * @bin: The decodebin.
668 * @caps: The #GstCaps.
669 * @factories: A #GValueArray of possible #GstElementFactory to use.
671 * Once decodebin has found the possible #GstElementFactory objects to try
672 * for @caps on @pad, this signal is emited. The purpose of the signal is for
673 * the application to perform additional sorting or filtering on the element
676 * The callee should copy and modify @factories or return #NULL if the
677 * order should not change.
680 * Invocation of signal handlers stops after one signal handler has
681 * returned something else than #NULL. Signal handlers are invoked in
682 * the order they were connected in.
683 * Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
684 * signal, they will never be invoked!
687 * Returns: A new sorted array of #GstElementFactory objects.
689 gst_decode_bin_signals[SIGNAL_AUTOPLUG_SORT] =
690 g_signal_new ("autoplug-sort", G_TYPE_FROM_CLASS (klass),
691 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_sort),
692 _gst_array_hasvalue_accumulator, NULL,
693 gst_play_marshal_BOXED__OBJECT_BOXED_BOXED, G_TYPE_VALUE_ARRAY, 3,
694 GST_TYPE_PAD, GST_TYPE_CAPS, G_TYPE_VALUE_ARRAY);
697 * GstDecodeBin::autoplug-select:
698 * @bin: The decodebin.
700 * @caps: The #GstCaps.
701 * @factory: A #GstElementFactory to use.
703 * This signal is emitted once decodebin has found all the possible
704 * #GstElementFactory that can be used to handle the given @caps. For each of
705 * those factories, this signal is emited.
707 * The signal handler should return a #GST_TYPE_AUTOPLUG_SELECT_RESULT enum
708 * value indicating what decodebin should do next.
710 * A value of #GST_AUTOPLUG_SELECT_TRY will try to autoplug an element from
713 * A value of #GST_AUTOPLUG_SELECT_EXPOSE will expose @pad without plugging
716 * A value of #GST_AUTOPLUG_SELECT_SKIP will skip @factory and move to the
720 * Only the signal handler that is connected first will ever by invoked.
721 * Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
722 * signal, they will never be invoked!
725 * Returns: a #GST_TYPE_AUTOPLUG_SELECT_RESULT that indicates the required
726 * operation. the default handler will always return
727 * #GST_AUTOPLUG_SELECT_TRY.
729 gst_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT] =
730 g_signal_new ("autoplug-select", G_TYPE_FROM_CLASS (klass),
731 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_select),
732 _gst_select_accumulator, NULL,
733 gst_play_marshal_ENUM__OBJECT_BOXED_OBJECT,
734 GST_TYPE_AUTOPLUG_SELECT_RESULT, 3, GST_TYPE_PAD, GST_TYPE_CAPS,
735 GST_TYPE_ELEMENT_FACTORY);
738 * GstDecodeBin::drained
739 * @bin: The decodebin
741 * This signal is emitted once decodebin has finished decoding all the data.
745 gst_decode_bin_signals[SIGNAL_DRAINED] =
746 g_signal_new ("drained", G_TYPE_FROM_CLASS (klass),
747 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, drained),
748 NULL, NULL, gst_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
750 g_object_class_install_property (gobject_klass, PROP_CAPS,
751 g_param_spec_boxed ("caps", "Caps", "The caps on which to stop decoding.",
752 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
754 g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
755 g_param_spec_string ("subtitle-encoding", "subtitle encoding",
756 "Encoding to assume if input subtitles are not in UTF-8 encoding. "
757 "If not set, the GST_SUBTITLE_ENCODING environment variable will "
758 "be checked for an encoding to use. If that is not set either, "
759 "ISO-8859-15 will be assumed.", NULL,
760 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
762 g_object_class_install_property (gobject_klass, PROP_SINK_CAPS,
763 g_param_spec_boxed ("sink-caps", "Sink Caps",
764 "The caps of the input data. (NULL = use typefind element)",
765 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
768 * GstDecodeBin::use-buffering
770 * Activate buffering in decodebin. This will instruct the multiqueues behind
771 * decoders to emit BUFFERING messages.
775 g_object_class_install_property (gobject_klass, PROP_USE_BUFFERING,
776 g_param_spec_boolean ("use-buffering", "Use Buffering",
777 "Emit GST_MESSAGE_BUFFERING based on low-/high-percent thresholds",
778 DEFAULT_USE_BUFFERING, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
781 * GstDecodeBin:low-percent
783 * Low threshold percent for buffering to start.
787 g_object_class_install_property (gobject_klass, PROP_LOW_PERCENT,
788 g_param_spec_int ("low-percent", "Low percent",
789 "Low threshold for buffering to start", 0, 100,
790 DEFAULT_LOW_PERCENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
792 * GstDecodeBin:high-percent
794 * High threshold percent for buffering to finish.
798 g_object_class_install_property (gobject_klass, PROP_HIGH_PERCENT,
799 g_param_spec_int ("high-percent", "High percent",
800 "High threshold for buffering to finish", 0, 100,
801 DEFAULT_HIGH_PERCENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
804 * GstDecodeBin:max-size-bytes
806 * Max amount amount of bytes in the queue (0=automatic).
810 g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_BYTES,
811 g_param_spec_uint ("max-size-bytes", "Max. size (bytes)",
812 "Max. amount of bytes in the queue (0=automatic)",
813 0, G_MAXUINT, DEFAULT_MAX_SIZE_BYTES,
814 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
816 * GstDecodeBin:max-size-buffers
818 * Max amount amount of buffers in the queue (0=automatic).
822 g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_BUFFERS,
823 g_param_spec_uint ("max-size-buffers", "Max. size (buffers)",
824 "Max. number of buffers in the queue (0=automatic)",
825 0, G_MAXUINT, DEFAULT_MAX_SIZE_BUFFERS,
826 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
828 * GstDecodeBin:max-size-time
830 * Max amount amount of time in the queue (in ns, 0=automatic).
834 g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_TIME,
835 g_param_spec_uint64 ("max-size-time", "Max. size (ns)",
836 "Max. amount of data in the queue (in ns, 0=automatic)",
838 DEFAULT_MAX_SIZE_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
841 * GstDecodeBin::post-stream-topology
843 * Post stream-topology messages on the bus every time the topology changes.
847 g_object_class_install_property (gobject_klass, PROP_POST_STREAM_TOPOLOGY,
848 g_param_spec_boolean ("post-stream-topology", "Post Stream Topology",
849 "Post stream-topology messages",
850 DEFAULT_POST_STREAM_TOPOLOGY,
851 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
854 * GstDecodeBin::expose-all-streams
856 * Expose streams of unknown type.
858 * If set to %FALSE, then only the streams that can be decoded to the final
859 * caps (see 'caps' property) will have a pad exposed. Streams that do not
860 * match those caps but could have been decoded will not have decoder plugged
861 * in internally and will not have a pad exposed.
865 g_object_class_install_property (gobject_klass, PROP_EXPOSE_ALL_STREAMS,
866 g_param_spec_boolean ("expose-all-streams", "Expose All Streams",
867 "Expose all streams, including those of unknown type or that don't match the 'caps' property",
868 DEFAULT_EXPOSE_ALL_STREAMS,
869 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
873 klass->autoplug_continue =
874 GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_continue);
875 klass->autoplug_factories =
876 GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_factories);
877 klass->autoplug_sort = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_sort);
878 klass->autoplug_select = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_select);
880 gst_element_class_add_pad_template (gstelement_klass,
881 gst_static_pad_template_get (&decoder_bin_sink_template));
882 gst_element_class_add_pad_template (gstelement_klass,
883 gst_static_pad_template_get (&decoder_bin_src_template));
885 gst_element_class_set_details_simple (gstelement_klass,
886 "Decoder Bin", "Generic/Bin/Decoder",
887 "Autoplug and decode to raw media",
888 "Edward Hervey <edward.hervey@collabora.co.uk>, "
889 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
891 gstelement_klass->change_state =
892 GST_DEBUG_FUNCPTR (gst_decode_bin_change_state);
895 /* Must be called with factories lock! */
897 gst_decode_bin_update_factories_list (GstDecodeBin * dbin)
900 || dbin->factories_cookie !=
901 gst_default_registry_get_feature_list_cookie ()) {
903 gst_plugin_feature_list_free (dbin->factories);
905 gst_element_factory_list_get_elements
906 (GST_ELEMENT_FACTORY_TYPE_DECODABLE, GST_RANK_MARGINAL);
907 dbin->factories_cookie = gst_default_registry_get_feature_list_cookie ();
912 gst_decode_bin_init (GstDecodeBin * decode_bin)
914 /* first filter out the interesting element factories */
915 decode_bin->factories_lock = g_mutex_new ();
917 /* we create the typefind element only once */
918 decode_bin->typefind = gst_element_factory_make ("typefind", "typefind");
919 if (!decode_bin->typefind) {
920 g_warning ("can't find typefind element, decodebin will not work");
924 GstPadTemplate *pad_tmpl;
926 /* add the typefind element */
927 if (!gst_bin_add (GST_BIN (decode_bin), decode_bin->typefind)) {
928 g_warning ("Could not add typefind element, decodebin will not work");
929 gst_object_unref (decode_bin->typefind);
930 decode_bin->typefind = NULL;
933 /* get the sinkpad */
934 pad = gst_element_get_static_pad (decode_bin->typefind, "sink");
936 /* get the pad template */
937 pad_tmpl = gst_static_pad_template_get (&decoder_bin_sink_template);
939 /* ghost the sink pad to ourself */
940 gpad = gst_ghost_pad_new_from_template ("sink", pad, pad_tmpl);
941 gst_pad_set_active (gpad, TRUE);
942 gst_element_add_pad (GST_ELEMENT (decode_bin), gpad);
944 gst_object_unref (pad_tmpl);
945 gst_object_unref (pad);
947 /* connect a signal to find out when the typefind element found
949 decode_bin->have_type_id =
950 g_signal_connect (G_OBJECT (decode_bin->typefind), "have-type",
951 G_CALLBACK (type_found), decode_bin);
954 decode_bin->expose_lock = g_mutex_new ();
955 decode_bin->decode_chain = NULL;
957 decode_bin->dyn_lock = g_mutex_new ();
958 decode_bin->shutdown = FALSE;
959 decode_bin->blocked_pads = NULL;
961 decode_bin->subtitle_lock = g_mutex_new ();
963 decode_bin->encoding = g_strdup (DEFAULT_SUBTITLE_ENCODING);
964 decode_bin->caps = gst_static_caps_get (&default_raw_caps);
965 decode_bin->use_buffering = DEFAULT_USE_BUFFERING;
966 decode_bin->low_percent = DEFAULT_LOW_PERCENT;
967 decode_bin->high_percent = DEFAULT_HIGH_PERCENT;
969 decode_bin->max_size_bytes = DEFAULT_MAX_SIZE_BYTES;
970 decode_bin->max_size_buffers = DEFAULT_MAX_SIZE_BUFFERS;
971 decode_bin->max_size_time = DEFAULT_MAX_SIZE_TIME;
973 decode_bin->expose_allstreams = DEFAULT_EXPOSE_ALL_STREAMS;
977 gst_decode_bin_dispose (GObject * object)
979 GstDecodeBin *decode_bin;
981 decode_bin = GST_DECODE_BIN (object);
983 if (decode_bin->factories)
984 gst_plugin_feature_list_free (decode_bin->factories);
985 decode_bin->factories = NULL;
987 if (decode_bin->decode_chain)
988 gst_decode_chain_free (decode_bin->decode_chain);
989 decode_bin->decode_chain = NULL;
991 if (decode_bin->caps)
992 gst_caps_unref (decode_bin->caps);
993 decode_bin->caps = NULL;
995 g_free (decode_bin->encoding);
996 decode_bin->encoding = NULL;
998 g_list_free (decode_bin->subtitles);
999 decode_bin->subtitles = NULL;
1001 G_OBJECT_CLASS (parent_class)->dispose (object);
1005 gst_decode_bin_finalize (GObject * object)
1007 GstDecodeBin *decode_bin;
1009 decode_bin = GST_DECODE_BIN (object);
1011 if (decode_bin->expose_lock) {
1012 g_mutex_free (decode_bin->expose_lock);
1013 decode_bin->expose_lock = NULL;
1016 if (decode_bin->dyn_lock) {
1017 g_mutex_free (decode_bin->dyn_lock);
1018 decode_bin->dyn_lock = NULL;
1021 if (decode_bin->subtitle_lock) {
1022 g_mutex_free (decode_bin->subtitle_lock);
1023 decode_bin->subtitle_lock = NULL;
1026 if (decode_bin->factories_lock) {
1027 g_mutex_free (decode_bin->factories_lock);
1028 decode_bin->factories_lock = NULL;
1031 G_OBJECT_CLASS (parent_class)->finalize (object);
1035 * Changes the caps on which decodebin will stop decoding.
1036 * Will unref the previously set one. The refcount of the given caps will be
1038 * @caps can be NULL.
1043 gst_decode_bin_set_caps (GstDecodeBin * dbin, GstCaps * caps)
1045 GST_DEBUG_OBJECT (dbin, "Setting new caps: %" GST_PTR_FORMAT, caps);
1047 GST_OBJECT_LOCK (dbin);
1048 gst_caps_replace (&dbin->caps, caps);
1049 GST_OBJECT_UNLOCK (dbin);
1053 * Returns the currently configured caps on which decodebin will stop decoding.
1054 * The returned caps (if not NULL), will have its refcount incremented.
1059 gst_decode_bin_get_caps (GstDecodeBin * dbin)
1063 GST_DEBUG_OBJECT (dbin, "Getting currently set caps");
1065 GST_OBJECT_LOCK (dbin);
1068 gst_caps_ref (caps);
1069 GST_OBJECT_UNLOCK (dbin);
1075 gst_decode_bin_set_sink_caps (GstDecodeBin * dbin, GstCaps * caps)
1077 GST_DEBUG_OBJECT (dbin, "Setting new caps: %" GST_PTR_FORMAT, caps);
1079 g_object_set (dbin->typefind, "force-caps", caps, NULL);
1083 gst_decode_bin_get_sink_caps (GstDecodeBin * dbin)
1087 GST_DEBUG_OBJECT (dbin, "Getting currently set caps");
1089 g_object_get (dbin->typefind, "force-caps", &caps, NULL);
1095 gst_decode_bin_set_subs_encoding (GstDecodeBin * dbin, const gchar * encoding)
1099 GST_DEBUG_OBJECT (dbin, "Setting new encoding: %s", GST_STR_NULL (encoding));
1101 SUBTITLE_LOCK (dbin);
1102 g_free (dbin->encoding);
1103 dbin->encoding = g_strdup (encoding);
1105 /* set the subtitle encoding on all added elements */
1106 for (walk = dbin->subtitles; walk; walk = g_list_next (walk)) {
1107 g_object_set (G_OBJECT (walk->data), "subtitle-encoding", dbin->encoding,
1110 SUBTITLE_UNLOCK (dbin);
1114 gst_decode_bin_get_subs_encoding (GstDecodeBin * dbin)
1118 GST_DEBUG_OBJECT (dbin, "Getting currently set encoding");
1120 SUBTITLE_LOCK (dbin);
1121 encoding = g_strdup (dbin->encoding);
1122 SUBTITLE_UNLOCK (dbin);
1128 gst_decode_bin_set_property (GObject * object, guint prop_id,
1129 const GValue * value, GParamSpec * pspec)
1133 dbin = GST_DECODE_BIN (object);
1137 gst_decode_bin_set_caps (dbin, g_value_get_boxed (value));
1139 case PROP_SUBTITLE_ENCODING:
1140 gst_decode_bin_set_subs_encoding (dbin, g_value_get_string (value));
1142 case PROP_SINK_CAPS:
1143 gst_decode_bin_set_sink_caps (dbin, g_value_get_boxed (value));
1145 case PROP_USE_BUFFERING:
1146 dbin->use_buffering = g_value_get_boolean (value);
1148 case PROP_LOW_PERCENT:
1149 dbin->low_percent = g_value_get_int (value);
1151 case PROP_HIGH_PERCENT:
1152 dbin->high_percent = g_value_get_int (value);
1154 case PROP_MAX_SIZE_BYTES:
1155 dbin->max_size_bytes = g_value_get_uint (value);
1157 case PROP_MAX_SIZE_BUFFERS:
1158 dbin->max_size_buffers = g_value_get_uint (value);
1160 case PROP_MAX_SIZE_TIME:
1161 dbin->max_size_time = g_value_get_uint64 (value);
1163 case PROP_POST_STREAM_TOPOLOGY:
1164 dbin->post_stream_topology = g_value_get_boolean (value);
1166 case PROP_EXPOSE_ALL_STREAMS:
1167 dbin->expose_allstreams = g_value_get_boolean (value);
1170 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1176 gst_decode_bin_get_property (GObject * object, guint prop_id,
1177 GValue * value, GParamSpec * pspec)
1181 dbin = GST_DECODE_BIN (object);
1184 g_value_take_boxed (value, gst_decode_bin_get_caps (dbin));
1186 case PROP_SUBTITLE_ENCODING:
1187 g_value_take_string (value, gst_decode_bin_get_subs_encoding (dbin));
1189 case PROP_SINK_CAPS:
1190 g_value_take_boxed (value, gst_decode_bin_get_sink_caps (dbin));
1192 case PROP_USE_BUFFERING:
1193 g_value_set_boolean (value, dbin->use_buffering);
1195 case PROP_LOW_PERCENT:
1196 g_value_set_int (value, dbin->low_percent);
1198 case PROP_HIGH_PERCENT:
1199 g_value_set_int (value, dbin->high_percent);
1201 case PROP_MAX_SIZE_BYTES:
1202 g_value_set_uint (value, dbin->max_size_bytes);
1204 case PROP_MAX_SIZE_BUFFERS:
1205 g_value_set_uint (value, dbin->max_size_buffers);
1207 case PROP_MAX_SIZE_TIME:
1208 g_value_set_uint64 (value, dbin->max_size_time);
1210 case PROP_POST_STREAM_TOPOLOGY:
1211 g_value_set_boolean (value, dbin->post_stream_topology);
1213 case PROP_EXPOSE_ALL_STREAMS:
1214 g_value_set_boolean (value, dbin->expose_allstreams);
1217 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1224 * Default autoplug signal handlers
1227 gst_decode_bin_autoplug_continue (GstElement * element, GstPad * pad,
1230 GST_DEBUG_OBJECT (element, "autoplug-continue returns TRUE");
1232 /* by default we always continue */
1236 static GValueArray *
1237 gst_decode_bin_autoplug_factories (GstElement * element, GstPad * pad,
1241 GValueArray *result;
1242 GstDecodeBin *dbin = GST_DECODE_BIN_CAST (element);
1244 GST_DEBUG_OBJECT (element, "finding factories");
1246 /* return all compatible factories for caps */
1247 g_mutex_lock (dbin->factories_lock);
1248 gst_decode_bin_update_factories_list (dbin);
1250 gst_element_factory_list_filter (dbin->factories, caps, GST_PAD_SINK,
1252 g_mutex_unlock (dbin->factories_lock);
1254 result = g_value_array_new (g_list_length (list));
1255 for (tmp = list; tmp; tmp = tmp->next) {
1256 GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (tmp->data);
1257 GValue val = { 0, };
1259 g_value_init (&val, G_TYPE_OBJECT);
1260 g_value_set_object (&val, factory);
1261 g_value_array_append (result, &val);
1262 g_value_unset (&val);
1264 gst_plugin_feature_list_free (list);
1266 GST_DEBUG_OBJECT (element, "autoplug-factories returns %p", result);
1271 static GValueArray *
1272 gst_decode_bin_autoplug_sort (GstElement * element, GstPad * pad,
1273 GstCaps * caps, GValueArray * factories)
1278 static GstAutoplugSelectResult
1279 gst_decode_bin_autoplug_select (GstElement * element, GstPad * pad,
1280 GstCaps * caps, GstElementFactory * factory)
1282 GST_DEBUG_OBJECT (element, "default autoplug-select returns TRY");
1285 return GST_AUTOPLUG_SELECT_TRY;
1292 static gboolean are_final_caps (GstDecodeBin * dbin, GstCaps * caps);
1293 static gboolean is_demuxer_element (GstElement * srcelement);
1295 static gboolean connect_pad (GstDecodeBin * dbin, GstElement * src,
1296 GstDecodePad * dpad, GstPad * pad, GstCaps * caps, GValueArray * factories,
1297 GstDecodeChain * chain);
1298 static gboolean connect_element (GstDecodeBin * dbin, GstElement * element,
1299 GstDecodeChain * chain);
1300 static void expose_pad (GstDecodeBin * dbin, GstElement * src,
1301 GstDecodePad * dpad, GstPad * pad, GstCaps * caps, GstDecodeChain * chain);
1303 static void pad_added_cb (GstElement * element, GstPad * pad,
1304 GstDecodeChain * chain);
1305 static void pad_removed_cb (GstElement * element, GstPad * pad,
1306 GstDecodeChain * chain);
1307 static void no_more_pads_cb (GstElement * element, GstDecodeChain * chain);
1309 static GstDecodeGroup *gst_decode_chain_get_current_group (GstDecodeChain *
1312 /* called when a new pad is discovered. It will perform some basic actions
1313 * before trying to link something to it.
1315 * - Check the caps, don't do anything when there are no caps or when they have
1317 * - signal AUTOPLUG_CONTINUE to check if we need to continue autoplugging this
1319 * - if the caps are non-fixed, setup a handler to continue autoplugging when
1320 * the caps become fixed (connect to notify::caps).
1321 * - get list of factories to autoplug.
1322 * - continue autoplugging to one of the factories.
1325 analyze_new_pad (GstDecodeBin * dbin, GstElement * src, GstPad * pad,
1326 GstCaps * caps, GstDecodeChain * chain)
1328 gboolean apcontinue = TRUE;
1329 GValueArray *factories = NULL, *result = NULL;
1332 GST_DEBUG_OBJECT (dbin, "Pad %s:%s caps:%" GST_PTR_FORMAT,
1333 GST_DEBUG_PAD_NAME (pad), caps);
1335 if (chain->elements && src != chain->elements->data) {
1336 GST_ERROR_OBJECT (dbin, "New pad from not the last element in this chain");
1340 if (chain->endpad) {
1341 GST_ERROR_OBJECT (dbin, "New pad in a chain that is already complete");
1345 if (chain->demuxer) {
1346 GstDecodeGroup *group;
1347 GstDecodeChain *oldchain = chain;
1349 /* we are adding a new pad for a demuxer (see is_demuxer_element(),
1350 * start a new chain for it */
1351 CHAIN_MUTEX_LOCK (oldchain);
1352 group = gst_decode_chain_get_current_group (chain);
1354 chain = gst_decode_chain_new (dbin, group, pad);
1355 group->children = g_list_prepend (group->children, chain);
1357 CHAIN_MUTEX_UNLOCK (oldchain);
1359 GST_WARNING_OBJECT (dbin, "No current group");
1364 if ((caps == NULL) || gst_caps_is_empty (caps))
1367 if (gst_caps_is_any (caps))
1370 dpad = gst_decode_pad_new (dbin, pad, chain);
1372 /* 1. Emit 'autoplug-continue' the result will tell us if this pads needs
1373 * further autoplugging. */
1374 g_signal_emit (G_OBJECT (dbin),
1375 gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE], 0, dpad, caps,
1378 /* 1.a if autoplug-continue is FALSE or caps is a raw format, goto pad_is_final */
1379 if ((!apcontinue) || are_final_caps (dbin, caps))
1382 /* 1.b when the caps are not fixed yet, we can't be sure what element to
1383 * connect. We delay autoplugging until the caps are fixed */
1384 if (!gst_caps_is_fixed (caps))
1387 /* 1.c else get the factories and if there's no compatible factory goto
1389 g_signal_emit (G_OBJECT (dbin),
1390 gst_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES], 0, dpad, caps,
1393 /* NULL means that we can expose the pad */
1394 if (factories == NULL)
1397 /* if the array is empty, we have a type for which we have no decoder */
1398 if (factories->n_values == 0) {
1399 if (!dbin->expose_allstreams) {
1400 GstCaps *raw = gst_static_caps_get (&default_raw_caps);
1402 /* If the caps are raw, this just means we don't want to expose them */
1403 if (gst_caps_can_intersect (raw, caps)) {
1404 gst_caps_unref (raw);
1405 gst_object_unref (dpad);
1406 goto discarded_type;
1408 gst_caps_unref (raw);
1411 /* if not we have a unhandled type with no compatible factories */
1412 g_value_array_free (factories);
1413 gst_object_unref (dpad);
1417 /* 1.d sort some more. */
1418 g_signal_emit (G_OBJECT (dbin),
1419 gst_decode_bin_signals[SIGNAL_AUTOPLUG_SORT], 0, dpad, caps, factories,
1422 g_value_array_free (factories);
1426 /* At this point we have a potential decoder, but we might not need it
1427 * if it doesn't match the output caps */
1428 if (!dbin->expose_allstreams) {
1431 gboolean dontuse = FALSE;
1433 GST_DEBUG ("Checking if we can abort early");
1435 /* 1.e Do an early check to see if the candidates are potential decoders, but
1436 * due to the fact that they decode to a mediatype that is not final we don't
1439 for (i = 0; i < factories->n_values && !dontuse; i++) {
1440 GstElementFactory *factory =
1441 g_value_get_object (g_value_array_get_nth (factories, 0));
1444 /* We are only interested in skipping decoders */
1445 if (strstr (gst_element_factory_get_klass (factory), "Decoder")) {
1447 GST_DEBUG ("Trying factory %s",
1448 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
1450 /* Check the source pad template caps to see if they match raw caps but don't match
1452 for (tmps = gst_element_factory_get_static_pad_templates (factory);
1453 tmps && !dontuse; tmps = tmps->next) {
1454 GstStaticPadTemplate *st = (GstStaticPadTemplate *) tmps->data;
1455 if (st->direction != GST_PAD_SRC)
1457 tcaps = gst_static_pad_template_get_caps (st);
1461 /* Emit autoplug-continue to see if the caps are considered to be raw caps */
1462 g_signal_emit (G_OBJECT (dbin),
1463 gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE], 0, dpad, tcaps,
1466 /* If autoplug-continue returns TRUE and the caps are not final, don't use them */
1467 if (apcontinue && !are_final_caps (dbin, tcaps))
1469 gst_caps_unref (tcaps);
1475 gst_object_unref (dpad);
1476 goto discarded_type;
1480 /* 1.f else continue autoplugging something from the list. */
1481 GST_LOG_OBJECT (pad, "Let's continue discovery on this pad");
1482 connect_pad (dbin, src, dpad, pad, caps, factories, chain);
1484 gst_object_unref (dpad);
1485 g_value_array_free (factories);
1491 GST_LOG_OBJECT (dbin, "Pad is final. autoplug-continue:%d", apcontinue);
1492 expose_pad (dbin, src, dpad, pad, caps, chain);
1493 gst_object_unref (dpad);
1499 GST_LOG_OBJECT (pad, "Known type, but discarded because not final caps");
1500 chain->deadend = TRUE;
1501 chain->endcaps = gst_caps_ref (caps);
1503 /* Try to expose anything */
1505 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
1506 gst_decode_bin_expose (dbin);
1508 EXPOSE_UNLOCK (dbin);
1509 do_async_done (dbin);
1516 GST_LOG_OBJECT (pad, "Unknown type, posting message and firing signal");
1518 chain->deadend = TRUE;
1519 chain->endcaps = gst_caps_ref (caps);
1521 gst_element_post_message (GST_ELEMENT_CAST (dbin),
1522 gst_missing_decoder_message_new (GST_ELEMENT_CAST (dbin), caps));
1524 g_signal_emit (G_OBJECT (dbin),
1525 gst_decode_bin_signals[SIGNAL_UNKNOWN_TYPE], 0, pad, caps);
1527 /* Try to expose anything */
1529 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
1530 gst_decode_bin_expose (dbin);
1532 EXPOSE_UNLOCK (dbin);
1534 if (src == dbin->typefind) {
1537 if (caps && !gst_caps_is_empty (caps)) {
1538 desc = gst_pb_utils_get_decoder_description (caps);
1539 GST_ELEMENT_ERROR (dbin, STREAM, CODEC_NOT_FOUND,
1540 (_("A %s plugin is required to play this stream, "
1541 "but not installed."), desc),
1542 ("No decoder to handle media type '%s'",
1543 gst_structure_get_name (gst_caps_get_structure (caps, 0))));
1546 GST_ELEMENT_ERROR (dbin, STREAM, TYPE_NOT_FOUND,
1547 (_("Could not determine type of stream")),
1548 ("Stream caps %" GST_PTR_FORMAT, caps));
1550 do_async_done (dbin);
1556 GST_DEBUG_OBJECT (pad, "pad has non-fixed caps delay autoplugging");
1557 gst_object_unref (dpad);
1558 goto setup_caps_delay;
1562 GST_WARNING_OBJECT (pad,
1563 "pad has ANY caps, not able to autoplug to anything");
1564 goto setup_caps_delay;
1568 GstPendingPad *ppad;
1570 /* connect to caps notification */
1571 CHAIN_MUTEX_LOCK (chain);
1572 GST_LOG_OBJECT (dbin, "Chain %p has now %d dynamic pads", chain,
1573 g_list_length (chain->pending_pads));
1574 ppad = g_slice_new0 (GstPendingPad);
1575 ppad->pad = gst_object_ref (pad);
1576 ppad->chain = chain;
1577 ppad->event_probe_id =
1578 gst_pad_add_probe (pad, GST_PROBE_TYPE_EVENT, pad_event_cb, ppad, NULL);
1579 chain->pending_pads = g_list_prepend (chain->pending_pads, ppad);
1580 CHAIN_MUTEX_UNLOCK (chain);
1581 g_signal_connect (G_OBJECT (pad), "notify::caps",
1582 G_CALLBACK (caps_notify_cb), chain);
1590 * Try to connect the given pad to an element created from one of the factories,
1593 * Note that dpad is ghosting pad, and so pad is linked; be sure to unset dpad's
1594 * target before trying to link pad.
1596 * Returns TRUE if an element was properly created and linked
1599 connect_pad (GstDecodeBin * dbin, GstElement * src, GstDecodePad * dpad,
1600 GstPad * pad, GstCaps * caps, GValueArray * factories,
1601 GstDecodeChain * chain)
1603 gboolean res = FALSE;
1604 GstPad *mqpad = NULL;
1605 gboolean is_demuxer = chain->parent && !chain->elements; /* First pad after the demuxer */
1607 g_return_val_if_fail (factories != NULL, FALSE);
1608 g_return_val_if_fail (factories->n_values > 0, FALSE);
1610 GST_DEBUG_OBJECT (dbin, "pad %s:%s , chain:%p",
1611 GST_DEBUG_PAD_NAME (pad), chain);
1613 /* 1. is element demuxer or parser */
1615 GST_LOG_OBJECT (src,
1616 "is a demuxer, connecting the pad through multiqueue '%s'",
1617 GST_OBJECT_NAME (chain->parent->multiqueue));
1619 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), NULL);
1620 if (!(mqpad = gst_decode_group_control_demuxer_pad (chain->parent, pad)))
1622 src = chain->parent->multiqueue;
1624 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), pad);
1627 /* 2. Try to create an element and link to it */
1628 while (factories->n_values > 0) {
1629 GstAutoplugSelectResult ret;
1630 GstElementFactory *factory;
1631 GstElement *element;
1635 /* Set dpad target to pad again, it might've been unset
1636 * below but we came back here because something failed
1638 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), pad);
1640 /* take first factory */
1641 factory = g_value_get_object (g_value_array_get_nth (factories, 0));
1642 /* Remove selected factory from the list. */
1643 g_value_array_remove (factories, 0);
1645 /* If the factory is for a parser we first check if the factory
1646 * was already used for the current chain. If it was used already
1647 * we would otherwise create an infinite loop here because the
1648 * parser apparently accepts its own output as input.
1649 * This is only done for parsers because it's perfectly valid
1650 * to have other element classes after each other because a
1651 * parser is the only one that does not change the data. A
1652 * valid example for this would be multiple id3demux in a row.
1654 if (strstr (gst_element_factory_get_klass (factory), "Parser")) {
1655 gboolean skip = FALSE;
1658 CHAIN_MUTEX_LOCK (chain);
1659 for (l = chain->elements; l; l = l->next) {
1660 GstElement *otherelement = GST_ELEMENT_CAST (l->data);
1662 if (gst_element_get_factory (otherelement) == factory) {
1667 CHAIN_MUTEX_UNLOCK (chain);
1669 GST_DEBUG_OBJECT (dbin,
1670 "Skipping factory '%s' because it was already used in this chain",
1671 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE_CAST (factory)));
1676 /* emit autoplug-select to see what we should do with it. */
1677 g_signal_emit (G_OBJECT (dbin),
1678 gst_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT],
1679 0, dpad, caps, factory, &ret);
1682 case GST_AUTOPLUG_SELECT_TRY:
1683 GST_DEBUG_OBJECT (dbin, "autoplug select requested try");
1685 case GST_AUTOPLUG_SELECT_EXPOSE:
1686 GST_DEBUG_OBJECT (dbin, "autoplug select requested expose");
1687 /* expose the pad, we don't have the source element */
1688 expose_pad (dbin, src, dpad, pad, caps, chain);
1691 case GST_AUTOPLUG_SELECT_SKIP:
1692 GST_DEBUG_OBJECT (dbin, "autoplug select requested skip");
1695 GST_WARNING_OBJECT (dbin, "autoplug select returned unhandled %d", ret);
1699 /* 2.0. Unlink pad */
1700 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), NULL);
1702 /* 2.1. Try to create an element */
1703 if ((element = gst_element_factory_create (factory, NULL)) == NULL) {
1704 GST_WARNING_OBJECT (dbin, "Could not create an element from %s",
1705 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
1709 /* ... activate it ... We do this before adding it to the bin so that we
1710 * don't accidentally make it post error messages that will stop
1712 if ((gst_element_set_state (element,
1713 GST_STATE_READY)) == GST_STATE_CHANGE_FAILURE) {
1714 GST_WARNING_OBJECT (dbin, "Couldn't set %s to READY",
1715 GST_ELEMENT_NAME (element));
1716 gst_object_unref (element);
1720 /* 2.3. Find its sink pad, this should work after activating it. */
1721 if (!(sinkpad = find_sink_pad (element))) {
1722 GST_WARNING_OBJECT (dbin, "Element %s doesn't have a sink pad",
1723 GST_ELEMENT_NAME (element));
1724 gst_element_set_state (element, GST_STATE_NULL);
1725 gst_object_unref (element);
1729 /* 2.4 add it ... */
1730 if (!(gst_bin_add (GST_BIN_CAST (dbin), element))) {
1731 GST_WARNING_OBJECT (dbin, "Couldn't add %s to the bin",
1732 GST_ELEMENT_NAME (element));
1733 gst_object_unref (sinkpad);
1734 gst_element_set_state (element, GST_STATE_NULL);
1735 gst_object_unref (element);
1739 /* 2.5 ...and try to link */
1740 if ((gst_pad_link (pad, sinkpad)) != GST_PAD_LINK_OK) {
1741 GST_WARNING_OBJECT (dbin, "Link failed on pad %s:%s",
1742 GST_DEBUG_PAD_NAME (sinkpad));
1743 gst_element_set_state (element, GST_STATE_NULL);
1744 gst_object_unref (sinkpad);
1745 gst_bin_remove (GST_BIN (dbin), element);
1748 gst_object_unref (sinkpad);
1749 GST_LOG_OBJECT (dbin, "linked on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1751 CHAIN_MUTEX_LOCK (chain);
1753 g_list_prepend (chain->elements, gst_object_ref (element));
1754 chain->demuxer = is_demuxer_element (element);
1755 CHAIN_MUTEX_UNLOCK (chain);
1757 /* link this element further */
1758 connect_element (dbin, element, chain);
1760 /* try to configure the subtitle encoding property when we can */
1761 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
1762 "subtitle-encoding")) {
1763 SUBTITLE_LOCK (dbin);
1764 GST_DEBUG_OBJECT (dbin,
1765 "setting subtitle-encoding=%s to element", dbin->encoding);
1766 g_object_set (G_OBJECT (element), "subtitle-encoding", dbin->encoding,
1768 SUBTITLE_UNLOCK (dbin);
1773 /* Bring the element to the state of the parent */
1774 if ((gst_element_set_state (element,
1775 GST_STATE_PAUSED)) == GST_STATE_CHANGE_FAILURE) {
1776 GstElement *tmp = NULL;
1778 GST_WARNING_OBJECT (dbin, "Couldn't set %s to PAUSED",
1779 GST_ELEMENT_NAME (element));
1781 /* Remove all elements in this chain that were just added. No
1782 * other thread could've added elements in the meantime */
1783 CHAIN_MUTEX_LOCK (chain);
1787 tmp = chain->elements->data;
1789 /* Disconnect any signal handlers that might be connected
1790 * in connect_element() or analyze_pad() */
1791 g_signal_handlers_disconnect_by_func (tmp, pad_added_cb, chain);
1792 g_signal_handlers_disconnect_by_func (tmp, pad_removed_cb, chain);
1793 g_signal_handlers_disconnect_by_func (tmp, no_more_pads_cb, chain);
1795 for (l = chain->pending_pads; l;) {
1796 GstPendingPad *pp = l->data;
1799 if (GST_PAD_PARENT (pp->pad) != tmp) {
1804 g_signal_handlers_disconnect_by_func (pp->pad, caps_notify_cb, chain);
1805 gst_pad_remove_probe (pp->pad, pp->event_probe_id);
1806 gst_object_unref (pp->pad);
1807 g_slice_free (GstPendingPad, pp);
1809 /* Remove element from the list, update list head and go to the
1810 * next element in the list */
1812 chain->pending_pads = g_list_delete_link (chain->pending_pads, l);
1816 gst_bin_remove (GST_BIN (dbin), tmp);
1817 gst_element_set_state (tmp, GST_STATE_NULL);
1819 gst_object_unref (tmp);
1820 chain->elements = g_list_delete_link (chain->elements, chain->elements);
1821 } while (tmp != element);
1822 CHAIN_MUTEX_UNLOCK (chain);
1827 SUBTITLE_LOCK (dbin);
1828 /* we added the element now, add it to the list of subtitle-encoding
1829 * elements when we can set the property */
1830 dbin->subtitles = g_list_prepend (dbin->subtitles, element);
1831 SUBTITLE_UNLOCK (dbin);
1840 gst_object_unref (mqpad);
1846 get_pad_caps (GstPad * pad)
1850 /* first check the pad caps, if this is set, we are positively sure it is
1851 * fixed and exactly what the element will produce. */
1852 caps = gst_pad_get_current_caps (pad);
1854 /* then use the getcaps function if we don't have caps. These caps might not
1855 * be fixed in some cases, in which case analyze_new_pad will set up a
1856 * notify::caps signal to continue autoplugging. */
1858 caps = gst_pad_get_caps (pad, NULL);
1864 connect_element (GstDecodeBin * dbin, GstElement * element,
1865 GstDecodeChain * chain)
1868 gboolean res = TRUE;
1869 gboolean dynamic = FALSE;
1870 GList *to_connect = NULL;
1872 GST_DEBUG_OBJECT (dbin, "Attempting to connect element %s [chain:%p] further",
1873 GST_ELEMENT_NAME (element), chain);
1875 /* 1. Loop over pad templates, grabbing existing pads along the way */
1876 for (pads = GST_ELEMENT_GET_CLASS (element)->padtemplates; pads;
1877 pads = g_list_next (pads)) {
1878 GstPadTemplate *templ = GST_PAD_TEMPLATE (pads->data);
1879 const gchar *templ_name;
1881 /* we are only interested in source pads */
1882 if (GST_PAD_TEMPLATE_DIRECTION (templ) != GST_PAD_SRC)
1885 templ_name = GST_PAD_TEMPLATE_NAME_TEMPLATE (templ);
1886 GST_DEBUG_OBJECT (dbin, "got a source pad template %s", templ_name);
1888 /* figure out what kind of pad this is */
1889 switch (GST_PAD_TEMPLATE_PRESENCE (templ)) {
1890 case GST_PAD_ALWAYS:
1892 /* get the pad that we need to autoplug */
1893 GstPad *pad = gst_element_get_static_pad (element, templ_name);
1896 GST_DEBUG_OBJECT (dbin, "got the pad for always template %s",
1898 /* here is the pad, we need to autoplug it */
1899 to_connect = g_list_prepend (to_connect, pad);
1901 /* strange, pad is marked as always but it's not
1902 * there. Fix the element */
1903 GST_WARNING_OBJECT (dbin,
1904 "could not get the pad for always template %s", templ_name);
1908 case GST_PAD_SOMETIMES:
1910 /* try to get the pad to see if it is already created or
1912 GstPad *pad = gst_element_get_static_pad (element, templ_name);
1915 GST_DEBUG_OBJECT (dbin, "got the pad for sometimes template %s",
1917 /* the pad is created, we need to autoplug it */
1918 to_connect = g_list_prepend (to_connect, pad);
1920 GST_DEBUG_OBJECT (dbin,
1921 "did not get the sometimes pad of template %s", templ_name);
1922 /* we have an element that will create dynamic pads */
1927 case GST_PAD_REQUEST:
1928 /* ignore request pads */
1929 GST_DEBUG_OBJECT (dbin, "ignoring request padtemplate %s", templ_name);
1934 /* 2. if there are more potential pads, connect to relevant signals */
1936 GST_LOG_OBJECT (dbin, "Adding signals to element %s in chain %p",
1937 GST_ELEMENT_NAME (element), chain);
1938 g_signal_connect (G_OBJECT (element), "pad-added",
1939 G_CALLBACK (pad_added_cb), chain);
1940 g_signal_connect (G_OBJECT (element), "pad-removed",
1941 G_CALLBACK (pad_removed_cb), chain);
1942 g_signal_connect (G_OBJECT (element), "no-more-pads",
1943 G_CALLBACK (no_more_pads_cb), chain);
1946 /* 3. for every available pad, connect it */
1947 for (pads = to_connect; pads; pads = g_list_next (pads)) {
1948 GstPad *pad = GST_PAD_CAST (pads->data);
1951 caps = get_pad_caps (pad);
1952 analyze_new_pad (dbin, element, pad, caps, chain);
1954 gst_caps_unref (caps);
1956 gst_object_unref (pad);
1958 g_list_free (to_connect);
1965 * Expose the given pad on the chain as a decoded pad.
1968 expose_pad (GstDecodeBin * dbin, GstElement * src, GstDecodePad * dpad,
1969 GstPad * pad, GstCaps * caps, GstDecodeChain * chain)
1971 GstPad *mqpad = NULL;
1973 GST_DEBUG_OBJECT (dbin, "pad %s:%s, chain:%p",
1974 GST_DEBUG_PAD_NAME (pad), chain);
1976 /* If this is the first pad for this chain, there are no other elements
1977 * and the source element is not the multiqueue we must link through the
1980 * This is the case if a demuxer directly exposed a raw pad.
1982 if (chain->parent && !chain->elements && src != chain->parent->multiqueue) {
1983 GST_LOG_OBJECT (src, "connecting the pad through multiqueue");
1985 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), NULL);
1986 if (!(mqpad = gst_decode_group_control_demuxer_pad (chain->parent, pad)))
1989 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), pad);
1992 gst_decode_pad_activate (dpad, chain);
1993 chain->endpad = gst_object_ref (dpad);
1994 chain->endcaps = gst_caps_ref (caps);
1997 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
1998 gst_decode_bin_expose (dbin);
2000 EXPOSE_UNLOCK (dbin);
2003 gst_object_unref (mqpad);
2009 /* check_upstream_seekable:
2011 * Check if upstream is seekable.
2014 check_upstream_seekable (GstDecodeBin * dbin, GstPad * pad)
2017 gint64 start = -1, stop = -1;
2019 dbin->upstream_seekable = FALSE;
2021 query = gst_query_new_seeking (GST_FORMAT_BYTES);
2022 if (!gst_pad_peer_query (pad, query)) {
2023 GST_DEBUG_OBJECT (dbin, "seeking query failed");
2024 gst_query_unref (query);
2028 gst_query_parse_seeking (query, NULL, &dbin->upstream_seekable,
2031 gst_query_unref (query);
2033 /* try harder to query upstream size if we didn't get it the first time */
2034 if (dbin->upstream_seekable && stop == -1) {
2035 GstFormat fmt = GST_FORMAT_BYTES;
2037 GST_DEBUG_OBJECT (dbin, "doing duration query to fix up unset stop");
2038 gst_pad_query_peer_duration (pad, &fmt, &stop);
2041 /* if upstream doesn't know the size, it's likely that it's not seekable in
2042 * practice even if it technically may be seekable */
2043 if (dbin->upstream_seekable && (start != 0 || stop <= start)) {
2044 GST_DEBUG_OBJECT (dbin, "seekable but unknown start/stop -> disable");
2045 dbin->upstream_seekable = FALSE;
2048 GST_DEBUG_OBJECT (dbin, "upstream seekable: %d", dbin->upstream_seekable);
2052 type_found (GstElement * typefind, guint probability,
2053 GstCaps * caps, GstDecodeBin * decode_bin)
2055 GstPad *pad, *sink_pad;
2057 GST_DEBUG_OBJECT (decode_bin, "typefind found caps %" GST_PTR_FORMAT, caps);
2059 /* If the typefinder (but not something else) finds text/plain - i.e. that's
2060 * the top-level type of the file - then error out.
2062 if (gst_structure_has_name (gst_caps_get_structure (caps, 0), "text/plain")) {
2063 GST_ELEMENT_ERROR (decode_bin, STREAM, WRONG_TYPE,
2064 (_("This appears to be a text file")),
2065 ("decodebin cannot decode plain text files"));
2069 /* FIXME: we can only deal with one type, we don't yet support dynamically changing
2070 * caps from the typefind element */
2071 if (decode_bin->have_type || decode_bin->decode_chain)
2074 decode_bin->have_type = TRUE;
2076 pad = gst_element_get_static_pad (typefind, "src");
2077 sink_pad = gst_element_get_static_pad (typefind, "sink");
2079 /* if upstream is seekable we can safely set a limit in time to the queues so
2080 * that streams at low bitrates can preroll */
2081 check_upstream_seekable (decode_bin, sink_pad);
2083 /* need some lock here to prevent race with shutdown state change
2084 * which might yank away e.g. decode_chain while building stuff here.
2085 * In typical cases, STREAM_LOCK is held and handles that, it need not
2086 * be held (if called from a proxied setcaps), so grab it anyway */
2087 GST_PAD_STREAM_LOCK (sink_pad);
2088 decode_bin->decode_chain = gst_decode_chain_new (decode_bin, NULL, pad);
2089 analyze_new_pad (decode_bin, typefind, pad, caps, decode_bin->decode_chain);
2090 GST_PAD_STREAM_UNLOCK (sink_pad);
2092 gst_object_unref (sink_pad);
2093 gst_object_unref (pad);
2099 static GstProbeReturn
2100 pad_event_cb (GstPad * pad, GstProbeType type, gpointer type_data,
2103 GstEvent *event = type_data;
2104 GstPendingPad *ppad = (GstPendingPad *) data;
2105 GstDecodeChain *chain = ppad->chain;
2106 GstDecodeBin *dbin = chain->dbin;
2111 switch (GST_EVENT_TYPE (event)) {
2113 GST_DEBUG_OBJECT (dbin, "Received EOS on a non final pad, this stream "
2115 chain->deadend = TRUE;
2116 /* we don't set the endcaps because NULL endcaps means early EOS */
2118 if (gst_decode_chain_is_complete (dbin->decode_chain))
2119 gst_decode_bin_expose (dbin);
2120 EXPOSE_UNLOCK (dbin);
2125 return GST_PROBE_OK;
2129 pad_added_cb (GstElement * element, GstPad * pad, GstDecodeChain * chain)
2136 GST_DEBUG_OBJECT (pad, "pad added, chain:%p", chain);
2138 caps = get_pad_caps (pad);
2139 analyze_new_pad (dbin, element, pad, caps, chain);
2141 gst_caps_unref (caps);
2144 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
2145 GST_LOG_OBJECT (dbin,
2146 "That was the last dynamic object, now attempting to expose the group");
2147 if (!gst_decode_bin_expose (dbin))
2148 GST_WARNING_OBJECT (dbin, "Couldn't expose group");
2150 EXPOSE_UNLOCK (dbin);
2154 pad_removed_cb (GstElement * element, GstPad * pad, GstDecodeChain * chain)
2158 GST_LOG_OBJECT (pad, "pad removed, chain:%p", chain);
2160 /* In fact, we don't have to do anything here, the active group will be
2161 * removed when the group's multiqueue is drained */
2162 CHAIN_MUTEX_LOCK (chain);
2163 for (l = chain->pending_pads; l; l = l->next) {
2164 GstPendingPad *ppad = l->data;
2165 GstPad *opad = ppad->pad;
2168 g_signal_handlers_disconnect_by_func (pad, caps_notify_cb, chain);
2169 gst_pending_pad_free (ppad);
2170 chain->pending_pads = g_list_delete_link (chain->pending_pads, l);
2174 CHAIN_MUTEX_UNLOCK (chain);
2178 no_more_pads_cb (GstElement * element, GstDecodeChain * chain)
2180 GstDecodeGroup *group = NULL;
2182 GST_LOG_OBJECT (element, "got no more pads");
2184 CHAIN_MUTEX_LOCK (chain);
2185 if (!chain->elements || (GstElement *) chain->elements->data != element) {
2186 GST_LOG_OBJECT (chain->dbin, "no-more-pads from old chain element '%s'",
2187 GST_OBJECT_NAME (element));
2188 CHAIN_MUTEX_UNLOCK (chain);
2190 } else if (!chain->demuxer) {
2191 GST_LOG_OBJECT (chain->dbin, "no-more-pads from a non-demuxer element '%s'",
2192 GST_OBJECT_NAME (element));
2193 CHAIN_MUTEX_UNLOCK (chain);
2197 /* when we received no_more_pads, we can complete the pads of the chain */
2198 if (!chain->next_groups && chain->active_group) {
2199 group = chain->active_group;
2200 } else if (chain->next_groups) {
2201 group = chain->next_groups->data;
2204 GST_ERROR_OBJECT (chain->dbin, "can't find group for element");
2205 CHAIN_MUTEX_UNLOCK (chain);
2209 GST_DEBUG_OBJECT (element, "Setting group %p to complete", group);
2211 group->no_more_pads = TRUE;
2212 /* this group has prerolled enough to not need more pads,
2213 * we can probably set its buffering state to playing now */
2214 GST_DEBUG_OBJECT (group->dbin, "Setting group %p multiqueue to "
2215 "'playing' buffering mode", group);
2216 decodebin_set_queue_size (group->dbin, group->multiqueue, FALSE);
2217 CHAIN_MUTEX_UNLOCK (chain);
2219 EXPOSE_LOCK (chain->dbin);
2220 if (gst_decode_chain_is_complete (chain->dbin->decode_chain)) {
2221 gst_decode_bin_expose (chain->dbin);
2223 EXPOSE_UNLOCK (chain->dbin);
2227 caps_notify_cb (GstPad * pad, GParamSpec * unused, GstDecodeChain * chain)
2229 GstElement *element;
2232 GST_LOG_OBJECT (pad, "Notified caps for pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2234 /* Disconnect this; if we still need it, we'll reconnect to this in
2235 * analyze_new_pad */
2236 g_signal_handlers_disconnect_by_func (pad, caps_notify_cb, chain);
2238 element = GST_ELEMENT_CAST (gst_pad_get_parent (pad));
2240 CHAIN_MUTEX_LOCK (chain);
2241 for (l = chain->pending_pads; l; l = l->next) {
2242 GstPendingPad *ppad = l->data;
2243 if (ppad->pad == pad) {
2244 gst_pending_pad_free (ppad);
2245 chain->pending_pads = g_list_delete_link (chain->pending_pads, l);
2249 CHAIN_MUTEX_UNLOCK (chain);
2251 pad_added_cb (element, pad, chain);
2253 gst_object_unref (element);
2256 /* Decide whether an element is a demuxer based on the
2257 * klass and number/type of src pad templates it has */
2259 is_demuxer_element (GstElement * srcelement)
2261 GstElementFactory *srcfactory;
2262 GstElementClass *elemclass;
2265 gint potential_src_pads = 0;
2267 srcfactory = gst_element_get_factory (srcelement);
2268 klass = gst_element_factory_get_klass (srcfactory);
2270 /* Can't be a demuxer unless it has Demux in the klass name */
2271 if (!strstr (klass, "Demux"))
2274 /* Walk the src pad templates and count how many the element
2276 elemclass = GST_ELEMENT_GET_CLASS (srcelement);
2278 walk = gst_element_class_get_pad_template_list (elemclass);
2279 while (walk != NULL) {
2280 GstPadTemplate *templ;
2282 templ = (GstPadTemplate *) walk->data;
2283 if (GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) {
2284 switch (GST_PAD_TEMPLATE_PRESENCE (templ)) {
2285 case GST_PAD_ALWAYS:
2286 case GST_PAD_SOMETIMES:
2287 if (strstr (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ), "%"))
2288 potential_src_pads += 2; /* Might make multiple pads */
2290 potential_src_pads += 1;
2292 case GST_PAD_REQUEST:
2293 potential_src_pads += 2;
2297 walk = g_list_next (walk);
2300 if (potential_src_pads < 2)
2306 /* Returns TRUE if the caps are compatible with the caps specified in the 'caps'
2307 * property (which by default are the raw caps)
2309 * The decodebin_lock should be taken !
2312 are_final_caps (GstDecodeBin * dbin, GstCaps * caps)
2316 GST_LOG_OBJECT (dbin, "Checking with caps %" GST_PTR_FORMAT, caps);
2318 /* lock for getting the caps */
2319 GST_OBJECT_LOCK (dbin);
2320 res = gst_caps_can_intersect (dbin->caps, caps);
2321 GST_OBJECT_UNLOCK (dbin);
2323 GST_LOG_OBJECT (dbin, "Caps are %sfinal caps", res ? "" : "not ");
2329 * GstDecodeChain functions
2332 /* gst_decode_chain_get_current_group:
2334 * Returns the current group of this chain, to which
2335 * new chains should be attached or NULL if the last
2336 * group didn't have no-more-pads.
2338 * Not MT-safe: Call with parent chain lock!
2340 static GstDecodeGroup *
2341 gst_decode_chain_get_current_group (GstDecodeChain * chain)
2343 GstDecodeGroup *group;
2345 if (!chain->next_groups && chain->active_group
2346 && chain->active_group->overrun && !chain->active_group->no_more_pads) {
2347 GST_WARNING_OBJECT (chain->dbin,
2348 "Currently active group %p is exposed"
2349 " and wants to add a new pad without having signaled no-more-pads",
2350 chain->active_group);
2354 if (chain->next_groups && (group = chain->next_groups->data) && group->overrun
2355 && !group->no_more_pads) {
2356 GST_WARNING_OBJECT (chain->dbin,
2357 "Currently newest pending group %p "
2358 "had overflow but didn't signal no-more-pads", group);
2362 /* Now we know that we can really return something useful */
2363 if (!chain->active_group) {
2364 chain->active_group = group = gst_decode_group_new (chain->dbin, chain);
2365 } else if (!chain->active_group->overrun
2366 && !chain->active_group->no_more_pads) {
2367 group = chain->active_group;
2368 } else if (chain->next_groups && (group = chain->next_groups->data)
2369 && !group->overrun && !group->no_more_pads) {
2370 /* group = chain->next_groups->data */
2372 group = gst_decode_group_new (chain->dbin, chain);
2373 chain->next_groups = g_list_prepend (chain->next_groups, group);
2379 static void gst_decode_group_free_internal (GstDecodeGroup * group,
2383 gst_decode_chain_free_internal (GstDecodeChain * chain, gboolean hide)
2387 CHAIN_MUTEX_LOCK (chain);
2389 GST_DEBUG_OBJECT (chain->dbin, "%s chain %p", (hide ? "Hiding" : "Freeing"),
2392 if (chain->active_group) {
2393 gst_decode_group_free_internal (chain->active_group, hide);
2395 chain->active_group = NULL;
2398 for (l = chain->next_groups; l; l = l->next) {
2399 gst_decode_group_free_internal ((GstDecodeGroup *) l->data, hide);
2404 g_list_free (chain->next_groups);
2405 chain->next_groups = NULL;
2409 for (l = chain->old_groups; l; l = l->next) {
2410 GstDecodeGroup *group = l->data;
2412 gst_decode_group_free (group);
2414 g_list_free (chain->old_groups);
2415 chain->old_groups = NULL;
2418 for (l = chain->pending_pads; l; l = l->next) {
2419 GstPendingPad *ppad = l->data;
2420 GstPad *pad = ppad->pad;
2422 g_signal_handlers_disconnect_by_func (pad, caps_notify_cb, chain);
2423 gst_pending_pad_free (ppad);
2426 g_list_free (chain->pending_pads);
2427 chain->pending_pads = NULL;
2429 for (l = chain->elements; l; l = l->next) {
2430 GstElement *element = GST_ELEMENT (l->data);
2432 g_signal_handlers_disconnect_by_func (element, pad_added_cb, chain);
2433 g_signal_handlers_disconnect_by_func (element, pad_removed_cb, chain);
2434 g_signal_handlers_disconnect_by_func (element, no_more_pads_cb, chain);
2436 if (GST_OBJECT_PARENT (element) == GST_OBJECT_CAST (chain->dbin))
2437 gst_bin_remove (GST_BIN_CAST (chain->dbin), element);
2439 gst_element_set_state (element, GST_STATE_NULL);
2442 SUBTITLE_LOCK (chain->dbin);
2443 /* remove possible subtitle element */
2444 chain->dbin->subtitles = g_list_remove (chain->dbin->subtitles, element);
2445 SUBTITLE_UNLOCK (chain->dbin);
2448 gst_object_unref (element);
2453 g_list_free (chain->elements);
2454 chain->elements = NULL;
2457 if (chain->endpad) {
2458 if (chain->endpad->exposed) {
2459 gst_element_remove_pad (GST_ELEMENT_CAST (chain->dbin),
2460 GST_PAD_CAST (chain->endpad));
2463 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (chain->endpad), NULL);
2464 chain->endpad->exposed = FALSE;
2466 gst_object_unref (chain->endpad);
2467 chain->endpad = NULL;
2472 gst_object_unref (chain->pad);
2476 if (chain->endcaps) {
2477 gst_caps_unref (chain->endcaps);
2478 chain->endcaps = NULL;
2481 GST_DEBUG_OBJECT (chain->dbin, "%s chain %p", (hide ? "Hidden" : "Freed"),
2483 CHAIN_MUTEX_UNLOCK (chain);
2485 g_mutex_free (chain->lock);
2486 g_slice_free (GstDecodeChain, chain);
2490 /* gst_decode_chain_free:
2492 * Completely frees and removes the chain and all
2493 * child groups from decodebin.
2495 * MT-safe, don't hold the chain lock or any child chain's lock
2496 * when calling this!
2499 gst_decode_chain_free (GstDecodeChain * chain)
2501 gst_decode_chain_free_internal (chain, FALSE);
2504 /* gst_decode_chain_new:
2506 * Creates a new decode chain and initializes it.
2508 * It's up to the caller to add it to the list of child chains of
2511 static GstDecodeChain *
2512 gst_decode_chain_new (GstDecodeBin * dbin, GstDecodeGroup * parent,
2515 GstDecodeChain *chain = g_slice_new0 (GstDecodeChain);
2517 GST_DEBUG_OBJECT (dbin, "Creating new chain %p with parent group %p", chain,
2521 chain->parent = parent;
2522 chain->lock = g_mutex_new ();
2523 chain->pad = gst_object_ref (pad);
2529 * GstDecodeGroup functions
2532 /* The overrun callback is used to expose groups that have not yet had their
2533 * no_more_pads called while the (large) multiqueue overflowed. When this
2534 * happens we must assume that the no_more_pads will not arrive anymore and we
2535 * must expose the pads that we have.
2538 multi_queue_overrun_cb (GstElement * queue, GstDecodeGroup * group)
2544 GST_LOG_OBJECT (dbin, "multiqueue '%s' (%p) is full", GST_OBJECT_NAME (queue),
2547 group->overrun = TRUE;
2549 /* FIXME: We should make sure that everything gets exposed now
2550 * even if child chains are not complete because the will never
2551 * be complete! Ignore any non-complete chains when exposing
2552 * and never expose them later
2556 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
2557 if (!gst_decode_bin_expose (dbin))
2558 GST_WARNING_OBJECT (dbin, "Couldn't expose group");
2560 EXPOSE_UNLOCK (group->dbin);
2564 gst_decode_group_free_internal (GstDecodeGroup * group, gboolean hide)
2568 GST_DEBUG_OBJECT (group->dbin, "%s group %p", (hide ? "Hiding" : "Freeing"),
2570 for (l = group->children; l; l = l->next) {
2571 GstDecodeChain *chain = (GstDecodeChain *) l->data;
2573 gst_decode_chain_free_internal (chain, hide);
2578 g_list_free (group->children);
2579 group->children = NULL;
2583 for (l = group->reqpads; l; l = l->next) {
2584 GstPad *pad = l->data;
2586 gst_element_release_request_pad (group->multiqueue, pad);
2587 gst_object_unref (pad);
2590 g_list_free (group->reqpads);
2591 group->reqpads = NULL;
2594 if (group->multiqueue) {
2595 if (group->overrunsig) {
2596 g_signal_handler_disconnect (group->multiqueue, group->overrunsig);
2597 group->overrunsig = 0;
2600 if (GST_OBJECT_PARENT (group->multiqueue) == GST_OBJECT_CAST (group->dbin))
2601 gst_bin_remove (GST_BIN_CAST (group->dbin), group->multiqueue);
2603 gst_element_set_state (group->multiqueue, GST_STATE_NULL);
2604 gst_object_unref (group->multiqueue);
2605 group->multiqueue = NULL;
2609 GST_DEBUG_OBJECT (group->dbin, "%s group %p", (hide ? "Hided" : "Freed"),
2612 g_slice_free (GstDecodeGroup, group);
2615 /* gst_decode_group_free:
2617 * Completely frees and removes the decode group and all
2620 * Never call this from any streaming thread!
2622 * Not MT-safe, call with parent's chain lock!
2625 gst_decode_group_free (GstDecodeGroup * group)
2627 gst_decode_group_free_internal (group, FALSE);
2630 /* gst_decode_group_hide:
2632 * Hide the decode group only, this means that
2633 * all child endpads are removed from decodebin
2634 * and all signals are unconnected.
2636 * No element is set to NULL state and completely
2639 * Can be called from streaming threads.
2641 * Not MT-safe, call with parent's chain lock!
2644 gst_decode_group_hide (GstDecodeGroup * group)
2646 gst_decode_group_free_internal (group, TRUE);
2649 /* configure queue sizes, this depends on the buffering method and if we are
2650 * playing or prerolling. */
2652 decodebin_set_queue_size (GstDecodeBin * dbin, GstElement * multiqueue,
2655 guint max_bytes, max_buffers;
2658 if (preroll || dbin->use_buffering) {
2659 /* takes queue limits, initially we only queue up up to the max bytes limit,
2660 * with a default of 2MB. we use the same values for buffering mode. */
2661 if ((max_bytes = dbin->max_size_bytes) == 0)
2662 max_bytes = AUTO_PREROLL_SIZE_BYTES;
2663 if ((max_buffers = dbin->max_size_buffers) == 0)
2664 max_buffers = AUTO_PREROLL_SIZE_BUFFERS;
2665 if ((max_time = dbin->max_size_time) == 0)
2666 max_time = dbin->upstream_seekable ? AUTO_PREROLL_SEEKABLE_SIZE_TIME :
2667 AUTO_PREROLL_NOT_SEEKABLE_SIZE_TIME;
2669 /* update runtime limits. At runtime, we try to keep the amount of buffers
2670 * in the queues as low as possible (but at least 5 buffers). */
2671 if ((max_bytes = dbin->max_size_bytes) == 0)
2672 max_bytes = AUTO_PLAY_SIZE_BYTES;
2673 if ((max_buffers = dbin->max_size_buffers) == 0)
2674 max_buffers = AUTO_PLAY_SIZE_BUFFERS;
2675 if ((max_time = dbin->max_size_time) == 0)
2676 max_time = AUTO_PLAY_SIZE_TIME;
2679 g_object_set (multiqueue,
2680 "max-size-bytes", max_bytes, "max-size-time", max_time,
2681 "max-size-buffers", max_buffers, NULL);
2684 /* gst_decode_group_new:
2685 * @dbin: Parent decodebin
2686 * @parent: Parent chain or %NULL
2688 * Creates a new GstDecodeGroup. It is up to the caller to add it to the list
2691 static GstDecodeGroup *
2692 gst_decode_group_new (GstDecodeBin * dbin, GstDecodeChain * parent)
2694 GstDecodeGroup *group = g_slice_new0 (GstDecodeGroup);
2697 GST_DEBUG_OBJECT (dbin, "Creating new group %p with parent chain %p", group,
2701 group->parent = parent;
2703 mq = group->multiqueue = gst_element_factory_make ("multiqueue", NULL);
2704 if (G_UNLIKELY (!group->multiqueue))
2705 goto missing_multiqueue;
2707 /* default is for use-buffering is FALSE */
2708 if (dbin->use_buffering) {
2710 "use-buffering", TRUE,
2711 "low-percent", dbin->low_percent,
2712 "high-percent", dbin->high_percent, NULL);
2715 /* configure queue sizes for preroll */
2716 decodebin_set_queue_size (dbin, mq, TRUE);
2718 group->overrunsig = g_signal_connect (G_OBJECT (mq), "overrun",
2719 G_CALLBACK (multi_queue_overrun_cb), group);
2721 gst_bin_add (GST_BIN (dbin), gst_object_ref (mq));
2722 gst_element_set_state (mq, GST_STATE_PAUSED);
2729 gst_element_post_message (GST_ELEMENT_CAST (dbin),
2730 gst_missing_element_message_new (GST_ELEMENT_CAST (dbin),
2732 GST_ELEMENT_ERROR (dbin, CORE, MISSING_PLUGIN, (NULL), ("no multiqueue!"));
2733 g_slice_free (GstDecodeGroup, group);
2738 /* gst_decode_group_control_demuxer_pad
2740 * Adds a new demuxer srcpad to the given group.
2742 * Returns the srcpad of the multiqueue corresponding the given pad.
2743 * Returns NULL if there was an error.
2746 gst_decode_group_control_demuxer_pad (GstDecodeGroup * group, GstPad * pad)
2749 GstPad *srcpad, *sinkpad;
2750 GstIterator *it = NULL;
2751 GValue item = { 0, };
2755 GST_LOG_OBJECT (dbin, "group:%p pad %s:%s", group, GST_DEBUG_PAD_NAME (pad));
2759 if (G_UNLIKELY (!group->multiqueue))
2762 if (!(sinkpad = gst_element_get_request_pad (group->multiqueue, "sink%d"))) {
2763 GST_ERROR_OBJECT (dbin, "Couldn't get sinkpad from multiqueue");
2767 if ((gst_pad_link (pad, sinkpad) != GST_PAD_LINK_OK)) {
2768 GST_ERROR_OBJECT (dbin, "Couldn't link demuxer and multiqueue");
2772 it = gst_pad_iterate_internal_links (sinkpad);
2774 if (!it || (gst_iterator_next (it, &item)) != GST_ITERATOR_OK
2775 || ((srcpad = g_value_dup_object (&item)) == NULL)) {
2776 GST_ERROR_OBJECT (dbin,
2777 "Couldn't get srcpad from multiqueue for sinkpad %" GST_PTR_FORMAT,
2781 CHAIN_MUTEX_LOCK (group->parent);
2782 group->reqpads = g_list_prepend (group->reqpads, gst_object_ref (sinkpad));
2783 CHAIN_MUTEX_UNLOCK (group->parent);
2786 g_value_unset (&item);
2788 gst_iterator_free (it);
2789 gst_object_unref (sinkpad);
2793 gst_element_release_request_pad (group->multiqueue, sinkpad);
2797 /* gst_decode_group_is_complete:
2799 * Checks if the group is complete, this means that
2800 * a) overrun of the multiqueue or no-more-pads happened
2801 * b) all child chains are complete
2803 * Not MT-safe, always call with decodebin expose lock
2806 gst_decode_group_is_complete (GstDecodeGroup * group)
2809 gboolean complete = TRUE;
2811 if (!group->overrun && !group->no_more_pads) {
2816 for (l = group->children; l; l = l->next) {
2817 GstDecodeChain *chain = l->data;
2819 if (!gst_decode_chain_is_complete (chain)) {
2826 GST_DEBUG_OBJECT (group->dbin, "Group %p is complete: %d", group, complete);
2830 /* gst_decode_chain_is_complete:
2832 * Returns TRUE if the chain is complete, this means either
2833 * a) This chain is a dead end, i.e. we have no suitable plugins
2834 * b) This chain ends in an endpad and this is blocked or exposed
2836 * Not MT-safe, always call with decodebin expose lock
2839 gst_decode_chain_is_complete (GstDecodeChain * chain)
2841 gboolean complete = FALSE;
2843 CHAIN_MUTEX_LOCK (chain);
2844 if (chain->deadend) {
2849 if (chain->endpad && (chain->endpad->blocked || chain->endpad->exposed)) {
2854 if (chain->demuxer) {
2855 if (chain->active_group
2856 && gst_decode_group_is_complete (chain->active_group)) {
2863 CHAIN_MUTEX_UNLOCK (chain);
2864 GST_DEBUG_OBJECT (chain->dbin, "Chain %p is complete: %d", chain, complete);
2868 /* check if the group is drained, meaning all pads have seen an EOS
2871 gst_decode_pad_handle_eos (GstDecodePad * pad)
2873 GstDecodeChain *chain = pad->chain;
2875 GST_LOG_OBJECT (pad->dbin, "chain : %p, pad %p", chain, pad);
2876 pad->drained = TRUE;
2877 gst_decode_chain_handle_eos (chain);
2880 /* gst_decode_chain_handle_eos:
2882 * Checks if there are next groups in any parent chain
2883 * to which we can switch or if everything is drained.
2885 * If there are groups to switch to, hide the current active
2886 * one and expose the new one.
2888 * MT-safe, don't call with chain lock!
2891 gst_decode_chain_handle_eos (GstDecodeChain * eos_chain)
2893 GstDecodeBin *dbin = eos_chain->dbin;
2894 GstDecodeGroup *group;
2895 GstDecodeChain *chain = eos_chain;
2898 g_return_if_fail (eos_chain->endpad);
2900 CHAIN_MUTEX_LOCK (chain);
2901 while ((group = chain->parent)) {
2902 CHAIN_MUTEX_UNLOCK (chain);
2903 chain = group->parent;
2904 CHAIN_MUTEX_LOCK (chain);
2906 if (gst_decode_group_is_drained (group)) {
2912 drained = chain->active_group ?
2913 gst_decode_group_is_drained (chain->active_group) : TRUE;
2915 /* Now either group == NULL and chain == dbin->decode_chain
2916 * or chain is the lowest chain that has a non-drained group */
2917 if (chain->active_group && drained && chain->next_groups) {
2918 GST_DEBUG_OBJECT (dbin, "Hiding current group %p", chain->active_group);
2919 gst_decode_group_hide (chain->active_group);
2920 chain->old_groups = g_list_prepend (chain->old_groups, chain->active_group);
2921 GST_DEBUG_OBJECT (dbin, "Switching to next group %p",
2922 chain->next_groups->data);
2923 chain->active_group = chain->next_groups->data;
2924 chain->next_groups =
2925 g_list_delete_link (chain->next_groups, chain->next_groups);
2926 CHAIN_MUTEX_UNLOCK (chain);
2928 if (gst_decode_chain_is_complete (dbin->decode_chain))
2929 gst_decode_bin_expose (dbin);
2930 EXPOSE_UNLOCK (dbin);
2931 } else if (!chain->active_group || drained) {
2932 g_assert (chain == dbin->decode_chain);
2933 CHAIN_MUTEX_UNLOCK (chain);
2935 GST_LOG_OBJECT (dbin, "all groups drained, fire signal");
2936 g_signal_emit (G_OBJECT (dbin), gst_decode_bin_signals[SIGNAL_DRAINED], 0,
2939 CHAIN_MUTEX_UNLOCK (chain);
2940 GST_DEBUG_OBJECT (dbin,
2941 "Current active group in chain %p is not drained yet", chain);
2945 /* gst_decode_group_is_drained:
2947 * Check is this group is drained and cache this result.
2948 * The group is drained if all child chains are drained.
2950 * Not MT-safe, call with group->parent's lock */
2952 gst_decode_group_is_drained (GstDecodeGroup * group)
2955 gboolean drained = TRUE;
2957 if (group->drained) {
2962 for (l = group->children; l; l = l->next) {
2963 GstDecodeChain *chain = l->data;
2965 CHAIN_MUTEX_LOCK (chain);
2966 if (!gst_decode_chain_is_drained (chain))
2968 CHAIN_MUTEX_UNLOCK (chain);
2972 group->drained = drained;
2975 GST_DEBUG_OBJECT (group->dbin, "Group %p is drained: %d", group, drained);
2979 /* gst_decode_chain_is_drained:
2981 * Check is the chain is drained, which means that
2984 * a) it's endpad is drained
2985 * b) there are no pending pads, the active group is drained
2986 * and there are no next groups
2988 * Not MT-safe, call with chain lock
2991 gst_decode_chain_is_drained (GstDecodeChain * chain)
2993 gboolean drained = FALSE;
2995 if (chain->endpad) {
2996 drained = chain->endpad->drained;
3000 if (chain->pending_pads) {
3005 if (chain->active_group && gst_decode_group_is_drained (chain->active_group)
3006 && !chain->next_groups) {
3012 GST_DEBUG_OBJECT (chain->dbin, "Chain %p is drained: %d", chain, drained);
3017 * GCompareFunc to use with lists of GstPad.
3018 * Sorts pads by mime type.
3019 * First video (raw, then non-raw), then audio (raw, then non-raw),
3022 * Return: negative if a<b, 0 if a==b, positive if a>b
3025 sort_end_pads (GstDecodePad * da, GstDecodePad * db)
3028 GstCaps *capsa, *capsb;
3029 GstStructure *sa, *sb;
3030 const gchar *namea, *nameb;
3032 capsa = get_pad_caps (GST_PAD_CAST (da));
3033 capsb = get_pad_caps (GST_PAD_CAST (db));
3035 sa = gst_caps_get_structure ((const GstCaps *) capsa, 0);
3036 sb = gst_caps_get_structure ((const GstCaps *) capsb, 0);
3038 namea = gst_structure_get_name (sa);
3039 nameb = gst_structure_get_name (sb);
3041 if (g_strrstr (namea, "video/x-raw-"))
3043 else if (g_strrstr (namea, "video/"))
3045 else if (g_strrstr (namea, "audio/x-raw"))
3047 else if (g_strrstr (namea, "audio/"))
3052 if (g_strrstr (nameb, "video/x-raw-"))
3054 else if (g_strrstr (nameb, "video/"))
3056 else if (g_strrstr (nameb, "audio/x-raw"))
3058 else if (g_strrstr (nameb, "audio/"))
3063 gst_caps_unref (capsa);
3064 gst_caps_unref (capsb);
3070 _gst_element_get_linked_caps (GstElement * src, GstElement * sink)
3075 gboolean done = FALSE;
3076 GstCaps *caps = NULL;
3077 GValue item = { 0, };
3079 it = gst_element_iterate_src_pads (src);
3081 switch (gst_iterator_next (it, &item)) {
3082 case GST_ITERATOR_OK:
3083 pad = g_value_get_object (&item);
3084 peer = gst_pad_get_peer (pad);
3086 parent = gst_pad_get_parent_element (peer);
3087 if (parent == sink) {
3088 caps = gst_pad_get_negotiated_caps (pad);
3093 gst_object_unref (parent);
3094 gst_object_unref (peer);
3096 g_value_reset (&item);
3098 case GST_ITERATOR_RESYNC:
3099 gst_iterator_resync (it);
3101 case GST_ITERATOR_ERROR:
3102 case GST_ITERATOR_DONE:
3107 g_value_unset (&item);
3108 gst_iterator_free (it);
3113 static GQuark topology_structure_name = 0;
3114 static GQuark topology_caps = 0;
3115 static GQuark topology_next = 0;
3116 static GQuark topology_pad = 0;
3118 /* FIXME: Invent gst_structure_take_structure() to prevent all the
3119 * structure copying for nothing
3121 static GstStructure *
3122 gst_decode_chain_get_topology (GstDecodeChain * chain)
3124 GstStructure *s, *u;
3128 if (G_UNLIKELY ((chain->endpad || chain->deadend)
3129 && (chain->endcaps == NULL))) {
3130 GST_WARNING ("End chain without valid caps !");
3134 u = gst_structure_id_empty_new (topology_structure_name);
3136 /* Now at the last element */
3137 if (chain->elements && (chain->endpad || chain->deadend)) {
3138 s = gst_structure_id_empty_new (topology_structure_name);
3139 gst_structure_id_set (u, topology_caps, GST_TYPE_CAPS, chain->endcaps,
3143 gst_structure_id_set (u, topology_pad, GST_TYPE_PAD, chain->endpad, NULL);
3144 gst_structure_id_set (s, topology_next, GST_TYPE_STRUCTURE, u, NULL);
3145 gst_structure_free (u);
3147 } else if (chain->active_group) {
3148 GValue list = { 0, };
3149 GValue item = { 0, };
3151 g_value_init (&list, GST_TYPE_LIST);
3152 g_value_init (&item, GST_TYPE_STRUCTURE);
3153 for (l = chain->active_group->children; l; l = l->next) {
3154 s = gst_decode_chain_get_topology (l->data);
3156 gst_value_set_structure (&item, s);
3157 gst_value_list_append_value (&list, &item);
3158 g_value_reset (&item);
3159 gst_structure_free (s);
3162 gst_structure_id_set_value (u, topology_next, &list);
3163 g_value_unset (&list);
3164 g_value_unset (&item);
3167 /* Get caps between all elements in this chain */
3168 l = (chain->elements && chain->elements->next) ? chain->elements : NULL;
3169 for (; l && l->next; l = l->next) {
3170 GstCaps *caps = _gst_element_get_linked_caps (l->next->data, l->data);
3173 s = gst_structure_id_empty_new (topology_structure_name);
3174 gst_structure_id_set (u, topology_caps, GST_TYPE_CAPS, caps, NULL);
3175 gst_caps_unref (caps);
3177 gst_structure_id_set (s, topology_next, GST_TYPE_STRUCTURE, u, NULL);
3178 gst_structure_free (u);
3183 /* Caps that resulted in this chain */
3184 caps = gst_pad_get_negotiated_caps (chain->pad);
3186 caps = get_pad_caps (chain->pad);
3187 if (G_UNLIKELY (!gst_caps_is_fixed (caps))) {
3188 GST_ERROR_OBJECT (chain->pad,
3189 "Couldn't get fixed caps, got %" GST_PTR_FORMAT, caps);
3190 gst_caps_unref (caps);
3194 gst_structure_set (u, "caps", GST_TYPE_CAPS, caps, NULL);
3195 gst_caps_unref (caps);
3201 gst_decode_bin_post_topology_message (GstDecodeBin * dbin)
3206 s = gst_decode_chain_get_topology (dbin->decode_chain);
3208 msg = gst_message_new_element (GST_OBJECT (dbin), s);
3209 gst_element_post_message (GST_ELEMENT (dbin), msg);
3212 /* Must only be called if the toplevel chain is complete and blocked! */
3213 /* Not MT-safe, call with decodebin expose lock! */
3215 gst_decode_bin_expose (GstDecodeBin * dbin)
3217 GList *tmp, *endpads = NULL;
3218 gboolean missing_plugin = FALSE;
3219 gboolean already_exposed = TRUE;
3221 GST_DEBUG_OBJECT (dbin, "Exposing currently active chains/groups");
3223 /* Don't expose if we're currently shutting down */
3225 if (G_UNLIKELY (dbin->shutdown == TRUE)) {
3226 GST_WARNING_OBJECT (dbin, "Currently, shutting down, aborting exposing");
3232 /* Get the pads that we're going to expose and mark things as exposed */
3233 if (!gst_decode_chain_expose (dbin->decode_chain, &endpads, &missing_plugin)) {
3234 g_list_foreach (endpads, (GFunc) gst_object_unref, NULL);
3235 g_list_free (endpads);
3236 GST_ERROR_OBJECT (dbin, "Broken chain/group tree");
3237 g_return_val_if_reached (FALSE);
3240 if (endpads == NULL) {
3241 if (missing_plugin) {
3242 GST_WARNING_OBJECT (dbin, "No suitable plugins found");
3243 GST_ELEMENT_ERROR (dbin, CORE, MISSING_PLUGIN, (NULL),
3244 ("no suitable plugins found"));
3246 /* in this case, the stream ended without buffers,
3247 * just post a warning */
3248 GST_WARNING_OBJECT (dbin, "All streams finished without buffers");
3249 GST_ELEMENT_ERROR (dbin, STREAM, FAILED, (NULL),
3250 ("all streams without buffers"));
3255 /* Check if this was called when everything was exposed already */
3256 for (tmp = endpads; tmp && already_exposed; tmp = tmp->next) {
3257 GstDecodePad *dpad = tmp->data;
3259 already_exposed &= dpad->exposed;
3260 if (!already_exposed)
3263 if (already_exposed) {
3264 GST_DEBUG_OBJECT (dbin, "Everything was exposed already!");
3265 g_list_foreach (endpads, (GFunc) gst_object_unref, NULL);
3266 g_list_free (endpads);
3270 /* Set all already exposed pads to blocked */
3271 for (tmp = endpads; tmp; tmp = tmp->next) {
3272 GstDecodePad *dpad = tmp->data;
3274 if (dpad->exposed) {
3275 GST_DEBUG_OBJECT (dpad, "blocking exposed pad");
3276 gst_decode_pad_set_blocked (dpad, TRUE);
3280 /* re-order pads : video, then audio, then others */
3281 endpads = g_list_sort (endpads, (GCompareFunc) sort_end_pads);
3284 for (tmp = endpads; tmp; tmp = tmp->next) {
3285 GstDecodePad *dpad = (GstDecodePad *) tmp->data;
3288 /* 1. rewrite name */
3289 padname = g_strdup_printf ("src%d", dbin->nbpads);
3291 GST_DEBUG_OBJECT (dbin, "About to expose dpad %s as %s",
3292 GST_OBJECT_NAME (dpad), padname);
3293 gst_object_set_name (GST_OBJECT (dpad), padname);
3296 /* 2. activate and add */
3298 && !gst_element_add_pad (GST_ELEMENT (dbin), GST_PAD_CAST (dpad))) {
3299 /* not really fatal, we can try to add the other pads */
3300 g_warning ("error adding pad to decodebin");
3303 dpad->exposed = TRUE;
3305 /* 3. emit signal */
3306 GST_INFO_OBJECT (dpad, "added new decoded pad");
3309 /* 4. Signal no-more-pads. This allows the application to hook stuff to the
3311 GST_LOG_OBJECT (dbin, "signalling no-more-pads");
3312 gst_element_no_more_pads (GST_ELEMENT (dbin));
3314 /* 5. Send a custom element message with the stream topology */
3315 if (dbin->post_stream_topology)
3316 gst_decode_bin_post_topology_message (dbin);
3318 /* 6. Unblock internal pads. The application should have connected stuff now
3319 * so that streaming can continue. */
3320 for (tmp = endpads; tmp; tmp = tmp->next) {
3321 GstDecodePad *dpad = (GstDecodePad *) tmp->data;
3323 GST_DEBUG_OBJECT (dpad, "unblocking");
3324 gst_decode_pad_unblock (dpad);
3325 GST_DEBUG_OBJECT (dpad, "unblocked");
3326 gst_object_unref (dpad);
3328 g_list_free (endpads);
3330 do_async_done (dbin);
3331 GST_DEBUG_OBJECT (dbin, "Exposed everything");
3335 /* gst_decode_chain_expose:
3337 * Check if the chain can be exposed and add all endpads
3338 * to the endpads list.
3340 * Also update the active group's multiqueue to the
3343 * Not MT-safe, call with decodebin expose lock! *
3346 gst_decode_chain_expose (GstDecodeChain * chain, GList ** endpads,
3347 gboolean * missing_plugin)
3349 GstDecodeGroup *group;
3353 if (chain->deadend) {
3355 *missing_plugin = TRUE;
3359 if (chain->endpad) {
3360 if (!chain->endpad->blocked && !chain->endpad->exposed)
3362 *endpads = g_list_prepend (*endpads, gst_object_ref (chain->endpad));
3366 group = chain->active_group;
3369 if (!group->no_more_pads && !group->overrun)
3374 /* configure queues for playback */
3375 decodebin_set_queue_size (dbin, group->multiqueue, FALSE);
3377 /* we can now disconnect any overrun signal, which is used to expose the
3379 if (group->overrunsig) {
3380 GST_LOG_OBJECT (dbin, "Disconnecting overrun");
3381 g_signal_handler_disconnect (group->multiqueue, group->overrunsig);
3382 group->overrunsig = 0;
3385 for (l = group->children; l; l = l->next) {
3386 GstDecodeChain *childchain = l->data;
3388 if (!gst_decode_chain_expose (childchain, endpads, missing_plugin))
3395 /*************************
3396 * GstDecodePad functions
3397 *************************/
3400 gst_decode_pad_class_init (GstDecodePadClass * klass)
3405 gst_decode_pad_init (GstDecodePad * pad)
3408 pad->blocked = FALSE;
3409 pad->exposed = FALSE;
3410 pad->drained = FALSE;
3411 gst_object_ref_sink (pad);
3414 static GstProbeReturn
3415 source_pad_blocked_cb (GstPad * pad, GstProbeType type, gpointer type_data,
3418 GstDecodePad *dpad = user_data;
3419 GstDecodeChain *chain;
3422 chain = dpad->chain;
3425 GST_LOG_OBJECT (dpad, "blocked: dpad->chain:%p", chain);
3427 dpad->blocked = TRUE;
3430 if (gst_decode_chain_is_complete (dbin->decode_chain)) {
3431 if (!gst_decode_bin_expose (dbin))
3432 GST_WARNING_OBJECT (dbin, "Couldn't expose group");
3434 EXPOSE_UNLOCK (dbin);
3436 return GST_PROBE_OK;
3439 static GstProbeReturn
3440 source_pad_event_probe (GstPad * pad, GstProbeType type, gpointer type_data,
3443 GstEvent *event = type_data;
3444 GstDecodePad *dpad = user_data;
3446 GST_LOG_OBJECT (pad, "%s dpad:%p", GST_EVENT_TYPE_NAME (event), dpad);
3448 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
3449 GST_DEBUG_OBJECT (pad, "we received EOS");
3451 /* Check if all pads are drained. If there is a next group to expose, we
3452 * will remove the ghostpad of the current group first, which unlinks the
3453 * peer and so drops the EOS. */
3454 gst_decode_pad_handle_eos (dpad);
3456 /* never drop events */
3457 return GST_PROBE_OK;
3461 gst_decode_pad_set_blocked (GstDecodePad * dpad, gboolean blocked)
3463 GstDecodeBin *dbin = dpad->dbin;
3468 GST_DEBUG_OBJECT (dpad, "blocking pad: %d", blocked);
3470 opad = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (dpad));
3474 /* do not block if shutting down.
3475 * we do not consider/expect it blocked further below, but use other trick */
3476 if (!blocked || !dbin->shutdown) {
3478 if (dpad->block_id == 0)
3479 dpad->block_id = gst_pad_add_probe (opad, GST_PROBE_TYPE_BLOCK,
3480 source_pad_blocked_cb, gst_object_ref (dpad),
3481 (GDestroyNotify) gst_object_unref);
3483 if (dpad->block_id != 0) {
3484 gst_pad_remove_probe (opad, dpad->block_id);
3487 dpad->blocked = FALSE;
3492 if (dbin->shutdown) {
3493 /* deactivate to force flushing state to prevent NOT_LINKED errors */
3494 gst_pad_set_active (GST_PAD_CAST (dpad), FALSE);
3495 /* note that deactivating the target pad would have no effect here,
3496 * since elements are typically connected first (and pads exposed),
3497 * and only then brought to PAUSED state (so pads activated) */
3499 gst_object_ref (dpad);
3500 dbin->blocked_pads = g_list_prepend (dbin->blocked_pads, dpad);
3505 if ((l = g_list_find (dbin->blocked_pads, dpad))) {
3506 gst_object_unref (dpad);
3507 dbin->blocked_pads = g_list_delete_link (dbin->blocked_pads, l);
3510 gst_object_unref (opad);
3516 gst_decode_pad_add_drained_check (GstDecodePad * dpad)
3518 gst_pad_add_probe (GST_PAD_CAST (dpad), GST_PROBE_TYPE_EVENT,
3519 source_pad_event_probe, dpad, NULL);
3523 gst_decode_pad_activate (GstDecodePad * dpad, GstDecodeChain * chain)
3525 g_return_if_fail (chain != NULL);
3527 dpad->chain = chain;
3528 gst_pad_set_active (GST_PAD_CAST (dpad), TRUE);
3529 gst_decode_pad_set_blocked (dpad, TRUE);
3530 gst_decode_pad_add_drained_check (dpad);
3534 gst_decode_pad_unblock (GstDecodePad * dpad)
3536 gst_decode_pad_set_blocked (dpad, FALSE);
3539 /*gst_decode_pad_new:
3541 * Creates a new GstDecodePad for the given pad.
3543 static GstDecodePad *
3544 gst_decode_pad_new (GstDecodeBin * dbin, GstPad * pad, GstDecodeChain * chain)
3547 GstPadTemplate *pad_tmpl;
3549 GST_DEBUG_OBJECT (dbin, "making new decodepad");
3550 pad_tmpl = gst_static_pad_template_get (&decoder_bin_src_template);
3552 g_object_new (GST_TYPE_DECODE_PAD, "direction", GST_PAD_DIRECTION (pad),
3553 "template", pad_tmpl, NULL);
3554 gst_ghost_pad_construct (GST_GHOST_PAD_CAST (dpad));
3555 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), pad);
3556 dpad->chain = chain;
3558 gst_object_unref (pad_tmpl);
3564 gst_pending_pad_free (GstPendingPad * ppad)
3567 g_assert (ppad->pad);
3569 if (ppad->event_probe_id != 0)
3570 gst_pad_remove_probe (ppad->pad, ppad->event_probe_id);
3571 gst_object_unref (ppad->pad);
3572 g_slice_free (GstPendingPad, ppad);
3576 * Element add/remove
3580 do_async_start (GstDecodeBin * dbin)
3582 GstMessage *message;
3584 dbin->async_pending = TRUE;
3586 message = gst_message_new_async_start (GST_OBJECT_CAST (dbin));
3587 parent_class->handle_message (GST_BIN_CAST (dbin), message);
3591 do_async_done (GstDecodeBin * dbin)
3593 GstMessage *message;
3595 if (dbin->async_pending) {
3596 message = gst_message_new_async_done (GST_OBJECT_CAST (dbin), FALSE);
3597 parent_class->handle_message (GST_BIN_CAST (dbin), message);
3599 dbin->async_pending = FALSE;
3604 * convenience functions
3609 * Returns the first sink pad of the given element, or NULL if it doesn't have
3614 find_sink_pad (GstElement * element)
3618 GValue item = { 0, };
3620 it = gst_element_iterate_sink_pads (element);
3622 if ((gst_iterator_next (it, &item)) == GST_ITERATOR_OK)
3623 pad = g_value_dup_object (&item);
3624 g_value_unset (&item);
3625 gst_iterator_free (it);
3630 /* call with dyn_lock held */
3632 unblock_pads (GstDecodeBin * dbin)
3636 GST_LOG_OBJECT (dbin, "unblocking pads");
3638 for (tmp = dbin->blocked_pads; tmp; tmp = tmp->next) {
3639 GstDecodePad *dpad = (GstDecodePad *) tmp->data;
3642 opad = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (dpad));
3646 GST_DEBUG_OBJECT (dpad, "unblocking");
3647 if (dpad->block_id != 0) {
3648 gst_pad_remove_probe (opad, dpad->block_id);
3651 dpad->blocked = FALSE;
3652 /* make flushing, prevent NOT_LINKED */
3653 GST_PAD_SET_FLUSHING (GST_PAD_CAST (dpad));
3654 gst_object_unref (dpad);
3655 gst_object_unref (opad);
3656 GST_DEBUG_OBJECT (dpad, "unblocked");
3659 /* clear, no more blocked pads */
3660 g_list_free (dbin->blocked_pads);
3661 dbin->blocked_pads = NULL;
3664 static GstStateChangeReturn
3665 gst_decode_bin_change_state (GstElement * element, GstStateChange transition)
3667 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
3668 GstDecodeBin *dbin = GST_DECODE_BIN (element);
3670 switch (transition) {
3671 case GST_STATE_CHANGE_NULL_TO_READY:
3672 if (dbin->typefind == NULL)
3673 goto missing_typefind;
3675 case GST_STATE_CHANGE_READY_TO_PAUSED:
3676 /* Make sure we've cleared all existing chains */
3677 if (dbin->decode_chain) {
3678 gst_decode_chain_free (dbin->decode_chain);
3679 dbin->decode_chain = NULL;
3682 GST_LOG_OBJECT (dbin, "clearing shutdown flag");
3683 dbin->shutdown = FALSE;
3685 dbin->have_type = FALSE;
3686 ret = GST_STATE_CHANGE_ASYNC;
3687 do_async_start (dbin);
3689 case GST_STATE_CHANGE_PAUSED_TO_READY:
3691 GST_LOG_OBJECT (dbin, "setting shutdown flag");
3692 dbin->shutdown = TRUE;
3693 unblock_pads (dbin);
3700 GstStateChangeReturn bret;
3702 bret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
3703 if (G_UNLIKELY (bret == GST_STATE_CHANGE_FAILURE))
3704 goto activate_failed;
3705 else if (G_UNLIKELY (bret == GST_STATE_CHANGE_NO_PREROLL)) {
3706 do_async_done (dbin);
3710 switch (transition) {
3711 case GST_STATE_CHANGE_PAUSED_TO_READY:
3712 do_async_done (dbin);
3713 if (dbin->decode_chain) {
3714 gst_decode_chain_free (dbin->decode_chain);
3715 dbin->decode_chain = NULL;
3718 case GST_STATE_CHANGE_READY_TO_NULL:
3728 gst_element_post_message (element,
3729 gst_missing_element_message_new (element, "typefind"));
3730 GST_ELEMENT_ERROR (dbin, CORE, MISSING_PLUGIN, (NULL), ("no typefind!"));
3731 return GST_STATE_CHANGE_FAILURE;
3735 GST_DEBUG_OBJECT (element,
3736 "element failed to change states -- activation problem?");
3737 return GST_STATE_CHANGE_FAILURE;
3742 gst_decode_bin_plugin_init (GstPlugin * plugin)
3744 GST_DEBUG_CATEGORY_INIT (gst_decode_bin_debug, "decodebin", 0, "decoder bin");
3746 /* Register some quarks here for the stream topology message */
3747 topology_structure_name = g_quark_from_static_string ("stream-topology");
3748 topology_caps = g_quark_from_static_string ("caps");
3749 topology_next = g_quark_from_static_string ("next");
3750 topology_pad = g_quark_from_static_string ("pad");
3752 return gst_element_register (plugin, "decodebin", GST_RANK_NONE,
3753 GST_TYPE_DECODE_BIN);