blob: fa5d159e21df2689726f0a7d9f405ebe6cae1cc2 [file] [log] [blame]
/* GStreamer
* Copyright (C) <2006> Edward Hervey <edward@fluendo.com>
* Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
* Copyright (C) <2011> Hewlett-Packard Development Company, L.P.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
* Copyright (C) <2013> Collabora Ltd.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* SECTION:element-decodebin
*
* #GstBin that auto-magically constructs a decoding pipeline using available
* decoders and demuxers via auto-plugging.
*
* decodebin is considered stable now and replaces the old #decodebin element.
* #uridecodebin uses decodebin internally and is often more convenient to
* use, as it creates a suitable source element as well.
*/
/* Implementation notes:
*
* The following section describes how decodebin works internally.
*
* The first part of decodebin is its typefind element, which tries
* to determine the media type of the input stream. If the type is found
* autoplugging starts.
*
* decodebin internally organizes the elements it autoplugged into GstDecodeChains
* and GstDecodeGroups. A decode chain is a single chain of decoding, this
* means that if decodebin every autoplugs an element with two+ srcpads
* (e.g. a demuxer) this will end the chain and everything following this
* demuxer will be put into decode groups below the chain. Otherwise,
* if an element has a single srcpad that outputs raw data the decode chain
* is ended too and a GstDecodePad is stored and blocked.
*
* A decode group combines a number of chains that are created by a
* demuxer element. All those chains are connected through a multiqueue to
* the demuxer. A new group for the same demuxer is only created if the
* demuxer has signaled no-more-pads, in which case all following pads
* create a new chain in the new group.
*
* This continues until the top-level decode chain is complete. A decode
* chain is complete if it either ends with a blocked endpad, if autoplugging
* stopped because no suitable plugins could be found or if the active group
* is complete. A decode group on the other hand is complete if all child
* chains are complete.
*
* If this happens at some point, all endpads of all active groups are exposed.
* For this decodebin adds the endpads, signals no-more-pads and then unblocks
* them. Now playback starts.
*
* If one of the chains that end on a endpad receives EOS decodebin checks
* if all chains and groups are drained. In that case everything goes into EOS.
* If there is a chain where the active group is drained but there exist next
* groups, the active group is hidden (endpads are removed) and the next group
* is exposed. This means that in some cases more pads may be created even
* after the initial no-more-pads signal. This happens for example with
* so-called "chained oggs", most commonly found among ogg/vorbis internet
* radio streams.
*
* Note 1: If we're talking about blocked endpads this really means that the
* *target* pads of the endpads are blocked. Pads that are exposed to the outside
* should never ever be blocked!
*
* Note 2: If a group is complete and the parent's chain demuxer adds new pads
* but never signaled no-more-pads this additional pads will be ignored!
*
*/
/* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
* with newer GLib versions (>= 2.31.0) */
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst-i18n-plugin.h>
#include <string.h>
#include <gst/gst.h>
#include <gst/pbutils/pbutils.h>
#include "gstplay-enum.h"
#include "gstplayback.h"
#include "gstrawcaps.h"
#include "gstplaybackutils.h"
/* generic templates */
static GstStaticPadTemplate decoder_bin_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY);
static GstStaticPadTemplate decoder_bin_src_template =
GST_STATIC_PAD_TEMPLATE ("src_%u",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
GST_STATIC_CAPS_ANY);
GST_DEBUG_CATEGORY_STATIC (gst_decode_bin_debug);
#define GST_CAT_DEFAULT gst_decode_bin_debug
typedef struct _GstPendingPad GstPendingPad;
typedef struct _GstDecodeElement GstDecodeElement;
typedef struct _GstDecodeChain GstDecodeChain;
typedef struct _GstDecodeGroup GstDecodeGroup;
typedef struct _GstDecodePad GstDecodePad;
typedef GstGhostPadClass GstDecodePadClass;
typedef struct _GstDecodeBin GstDecodeBin;
typedef struct _GstDecodeBinClass GstDecodeBinClass;
#define GST_TYPE_DECODE_BIN (gst_decode_bin_get_type())
#define GST_DECODE_BIN_CAST(obj) ((GstDecodeBin*)(obj))
#define GST_DECODE_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECODE_BIN,GstDecodeBin))
#define GST_DECODE_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DECODE_BIN,GstDecodeBinClass))
#define GST_IS_DECODE_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DECODE_BIN))
#define GST_IS_DECODE_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DECODE_BIN))
/**
* GstDecodeBin:
*
* The opaque #GstDecodeBin data structure
*/
struct _GstDecodeBin
{
GstBin bin; /* we extend GstBin */
/* properties */
GstCaps *caps; /* caps on which to stop decoding */
gchar *encoding; /* encoding of subtitles */
gboolean use_buffering; /* configure buffering on multiqueues */
gint low_percent;
gint high_percent;
guint max_size_bytes;
guint max_size_buffers;
guint64 max_size_time;
gboolean post_stream_topology;
guint64 connection_speed;
GstElement *typefind; /* this holds the typefind object */
GMutex expose_lock; /* Protects exposal and removal of groups */
GstDecodeChain *decode_chain; /* Top level decode chain */
guint nbpads; /* unique identifier for source pads */
GMutex factories_lock;
guint32 factories_cookie; /* Cookie from last time when factories was updated */
GList *factories; /* factories we can use for selecting elements */
GMutex subtitle_lock; /* Protects changes to subtitles and encoding */
GList *subtitles; /* List of elements with subtitle-encoding,
* protected by above mutex! */
gboolean have_type; /* if we received the have_type signal */
guint have_type_id; /* signal id for have-type from typefind */
gboolean async_pending; /* async-start has been emitted */
GMutex dyn_lock; /* lock protecting pad blocking */
gboolean shutdown; /* if we are shutting down */
GList *blocked_pads; /* pads that have set to block */
gboolean expose_allstreams; /* Whether to expose unknow type streams or not */
GList *filtered; /* elements for which error messages are filtered */
GList *filtered_errors; /* filtered error messages */
GList *buffering_status; /* element currently buffering messages */
GMutex buffering_lock;
GMutex buffering_post_lock;
};
struct _GstDecodeBinClass
{
GstBinClass parent_class;
/* signal fired when we found a pad that we cannot decode */
void (*unknown_type) (GstElement * element, GstPad * pad, GstCaps * caps);
/* signal fired to know if we continue trying to decode the given caps */
gboolean (*autoplug_continue) (GstElement * element, GstPad * pad,
GstCaps * caps);
/* signal fired to get a list of factories to try to autoplug */
GValueArray *(*autoplug_factories) (GstElement * element, GstPad * pad,
GstCaps * caps);
/* signal fired to sort the factories */
GValueArray *(*autoplug_sort) (GstElement * element, GstPad * pad,
GstCaps * caps, GValueArray * factories);
/* signal fired to select from the proposed list of factories */
GstAutoplugSelectResult (*autoplug_select) (GstElement * element,
GstPad * pad, GstCaps * caps, GstElementFactory * factory);
/* signal fired when a autoplugged element that is not linked downstream
* or exposed wants to query something */
gboolean (*autoplug_query) (GstElement * element, GstPad * pad,
GstQuery * query);
/* fired when the last group is drained */
void (*drained) (GstElement * element);
};
/* signals */
enum
{
SIGNAL_UNKNOWN_TYPE,
SIGNAL_AUTOPLUG_CONTINUE,
SIGNAL_AUTOPLUG_FACTORIES,
SIGNAL_AUTOPLUG_SELECT,
SIGNAL_AUTOPLUG_SORT,
SIGNAL_AUTOPLUG_QUERY,
SIGNAL_DRAINED,
LAST_SIGNAL
};
/* automatic sizes, while prerolling we buffer up to 2MB, we ignore time
* and buffers in this case. */
#define AUTO_PREROLL_SIZE_BYTES 2 * 1024 * 1024
#define AUTO_PREROLL_SIZE_BUFFERS 0
#define AUTO_PREROLL_NOT_SEEKABLE_SIZE_TIME 10 * GST_SECOND
#define AUTO_PREROLL_SEEKABLE_SIZE_TIME 0
/* when playing, keep a max of 2MB of data but try to keep the number of buffers
* as low as possible (try to aim for 5 buffers) */
#define AUTO_PLAY_SIZE_BYTES 2 * 1024 * 1024
#define AUTO_PLAY_SIZE_BUFFERS 5
#define AUTO_PLAY_SIZE_TIME 0
#define DEFAULT_SUBTITLE_ENCODING NULL
#define DEFAULT_USE_BUFFERING FALSE
#define DEFAULT_LOW_PERCENT 10
#define DEFAULT_HIGH_PERCENT 99
/* by default we use the automatic values above */
#define DEFAULT_MAX_SIZE_BYTES 0
#define DEFAULT_MAX_SIZE_BUFFERS 0
#define DEFAULT_MAX_SIZE_TIME 0
#define DEFAULT_POST_STREAM_TOPOLOGY FALSE
#define DEFAULT_EXPOSE_ALL_STREAMS TRUE
#define DEFAULT_CONNECTION_SPEED 0
/* Properties */
enum
{
PROP_0,
PROP_CAPS,
PROP_SUBTITLE_ENCODING,
PROP_SINK_CAPS,
PROP_USE_BUFFERING,
PROP_LOW_PERCENT,
PROP_HIGH_PERCENT,
PROP_MAX_SIZE_BYTES,
PROP_MAX_SIZE_BUFFERS,
PROP_MAX_SIZE_TIME,
PROP_POST_STREAM_TOPOLOGY,
PROP_EXPOSE_ALL_STREAMS,
PROP_CONNECTION_SPEED
};
static GstBinClass *parent_class;
static guint gst_decode_bin_signals[LAST_SIGNAL] = { 0 };
static GstStaticCaps default_raw_caps = GST_STATIC_CAPS (DEFAULT_RAW_CAPS);
static void do_async_start (GstDecodeBin * dbin);
static void do_async_done (GstDecodeBin * dbin);
static void type_found (GstElement * typefind, guint probability,
GstCaps * caps, GstDecodeBin * decode_bin);
static void decodebin_set_queue_size (GstDecodeBin * dbin,
GstElement * multiqueue, gboolean preroll, gboolean seekable);
static void decodebin_set_queue_size_full (GstDecodeBin * dbin,
GstElement * multiqueue, gboolean use_buffering, gboolean preroll,
gboolean seekable);
static gboolean gst_decode_bin_autoplug_continue (GstElement * element,
GstPad * pad, GstCaps * caps);
static GValueArray *gst_decode_bin_autoplug_factories (GstElement *
element, GstPad * pad, GstCaps * caps);
static GValueArray *gst_decode_bin_autoplug_sort (GstElement * element,
GstPad * pad, GstCaps * caps, GValueArray * factories);
static GstAutoplugSelectResult gst_decode_bin_autoplug_select (GstElement *
element, GstPad * pad, GstCaps * caps, GstElementFactory * factory);
static gboolean gst_decode_bin_autoplug_query (GstElement * element,
GstPad * pad, GstQuery * query);
static void gst_decode_bin_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_decode_bin_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_decode_bin_set_caps (GstDecodeBin * dbin, GstCaps * caps);
static GstCaps *gst_decode_bin_get_caps (GstDecodeBin * dbin);
static void caps_notify_cb (GstPad * pad, GParamSpec * unused,
GstDecodeChain * chain);
static void flush_chain (GstDecodeChain * chain, gboolean flushing);
static void flush_group (GstDecodeGroup * group, gboolean flushing);
static GstPad *find_sink_pad (GstElement * element);
static GstStateChangeReturn gst_decode_bin_change_state (GstElement * element,
GstStateChange transition);
static void gst_decode_bin_handle_message (GstBin * bin, GstMessage * message);
static gboolean gst_decode_bin_remove_element (GstBin * bin,
GstElement * element);
static gboolean check_upstream_seekable (GstDecodeBin * dbin, GstPad * pad);
static GstCaps *get_pad_caps (GstPad * pad);
#define EXPOSE_LOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"expose locking from thread %p", \
g_thread_self ()); \
g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->expose_lock); \
GST_LOG_OBJECT (dbin, \
"expose locked from thread %p", \
g_thread_self ()); \
} G_STMT_END
#define EXPOSE_UNLOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"expose unlocking from thread %p", \
g_thread_self ()); \
g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->expose_lock); \
} G_STMT_END
#define DYN_LOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"dynlocking from thread %p", \
g_thread_self ()); \
g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->dyn_lock); \
GST_LOG_OBJECT (dbin, \
"dynlocked from thread %p", \
g_thread_self ()); \
} G_STMT_END
#define DYN_UNLOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"dynunlocking from thread %p", \
g_thread_self ()); \
g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->dyn_lock); \
} G_STMT_END
#define SUBTITLE_LOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"subtitle locking from thread %p", \
g_thread_self ()); \
g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->subtitle_lock); \
GST_LOG_OBJECT (dbin, \
"subtitle lock from thread %p", \
g_thread_self ()); \
} G_STMT_END
#define SUBTITLE_UNLOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"subtitle unlocking from thread %p", \
g_thread_self ()); \
g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->subtitle_lock); \
} G_STMT_END
#define BUFFERING_LOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"buffering locking from thread %p", \
g_thread_self ()); \
g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->buffering_lock); \
GST_LOG_OBJECT (dbin, \
"buffering lock from thread %p", \
g_thread_self ()); \
} G_STMT_END
#define BUFFERING_UNLOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"buffering unlocking from thread %p", \
g_thread_self ()); \
g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->buffering_lock); \
} G_STMT_END
struct _GstPendingPad
{
GstPad *pad;
GstDecodeChain *chain;
gulong event_probe_id;
gulong notify_caps_id;
};
struct _GstDecodeElement
{
GstElement *element;
GstElement *capsfilter; /* Optional capsfilter for Parser/Convert */
gulong pad_added_id;
gulong pad_removed_id;
gulong no_more_pads_id;
};
/* GstDecodeGroup
*
* Streams belonging to the same group/chain of a media file
*
* When changing something here lock the parent chain!
*/
struct _GstDecodeGroup
{
GstDecodeBin *dbin;
GstDecodeChain *parent;
GstElement *multiqueue; /* Used for linking all child chains */
gulong overrunsig; /* the overrun signal for multiqueue */
gboolean overrun; /* TRUE if the multiqueue signaled overrun. This
* means that we should really expose the group */
gboolean no_more_pads; /* TRUE if the demuxer signaled no-more-pads */
gboolean drained; /* TRUE if the all children are drained */
GList *children; /* List of GstDecodeChains in this group */
GList *reqpads; /* List of RequestPads for multiqueue, there is
* exactly one RequestPad per child chain */
};
struct _GstDecodeChain
{
GstDecodeGroup *parent;
GstDecodeBin *dbin;
gint refs; /* Number of references to this object */
GMutex lock; /* Protects this chain and its groups */
GstPad *pad; /* srcpad that caused creation of this chain */
gboolean drained; /* TRUE if the all children are drained */
gboolean demuxer; /* TRUE if elements->data is a demuxer */
gboolean adaptive_demuxer; /* TRUE if elements->data is an adaptive streaming demuxer */
gboolean seekable; /* TRUE if this chain ends on a demuxer and is seekable */
GList *elements; /* All elements in this group, first
is the latest and most downstream element */
/* Note: there are only groups if the last element of this chain
* is a demuxer, otherwise the chain will end with an endpad.
* The other way around this means, that endpad only exists if this
* chain doesn't end with a demuxer! */
GstDecodeGroup *active_group; /* Currently active group */
GList *next_groups; /* head is newest group, tail is next group.
a new group will be created only if the head
group had no-more-pads. If it's only exposed
all new pads will be ignored! */
GList *pending_pads; /* Pads that have no fixed caps yet */
GstDecodePad *current_pad; /* Current ending pad of the chain that can't
* be exposed yet but would be the same as endpad
* once it can be exposed */
GstDecodePad *endpad; /* Pad of this chain that could be exposed */
gboolean deadend; /* This chain is incomplete and can't be completed,
e.g. no suitable decoder could be found
e.g. stream got EOS without buffers
*/
gchar *deadend_details;
GstCaps *endcaps; /* Caps that were used when linking to the endpad
or that resulted in the deadend
*/
/* FIXME: This should be done directly via a thread! */
GList *old_groups; /* Groups that should be freed later */
};
static GstDecodeChain *gst_decode_chain_ref (GstDecodeChain * chain);
static void gst_decode_chain_unref (GstDecodeChain * chain);
static void gst_decode_chain_free (GstDecodeChain * chain);
static GstDecodeChain *gst_decode_chain_new (GstDecodeBin * dbin,
GstDecodeGroup * group, GstPad * pad);
static void gst_decode_group_hide (GstDecodeGroup * group);
static void gst_decode_group_free (GstDecodeGroup * group);
static GstDecodeGroup *gst_decode_group_new (GstDecodeBin * dbin,
GstDecodeChain * chain);
static gboolean gst_decode_chain_is_complete (GstDecodeChain * chain);
static gboolean gst_decode_chain_expose (GstDecodeChain * chain,
GList ** endpads, gboolean * missing_plugin,
GString * missing_plugin_details, gboolean * last_group);
static gboolean gst_decode_chain_is_drained (GstDecodeChain * chain);
static gboolean gst_decode_chain_reset_buffering (GstDecodeChain * chain);
static gboolean gst_decode_group_is_complete (GstDecodeGroup * group);
static GstPad *gst_decode_group_control_demuxer_pad (GstDecodeGroup * group,
GstPad * pad);
static gboolean gst_decode_group_is_drained (GstDecodeGroup * group);
static gboolean gst_decode_group_reset_buffering (GstDecodeGroup * group);
static gboolean gst_decode_bin_expose (GstDecodeBin * dbin);
static void gst_decode_bin_reset_buffering (GstDecodeBin * dbin);
#define CHAIN_MUTEX_LOCK(chain) G_STMT_START { \
GST_LOG_OBJECT (chain->dbin, \
"locking chain %p from thread %p", \
chain, g_thread_self ()); \
g_mutex_lock (&chain->lock); \
GST_LOG_OBJECT (chain->dbin, \
"locked chain %p from thread %p", \
chain, g_thread_self ()); \
} G_STMT_END
#define CHAIN_MUTEX_UNLOCK(chain) G_STMT_START { \
GST_LOG_OBJECT (chain->dbin, \
"unlocking chain %p from thread %p", \
chain, g_thread_self ()); \
g_mutex_unlock (&chain->lock); \
} G_STMT_END
/* GstDecodePad
*
* GstPad private used for source pads of chains
*/
struct _GstDecodePad
{
GstGhostPad parent;
GstDecodeBin *dbin;
GstDecodeChain *chain;
gboolean blocked; /* the *target* pad is blocked */
gboolean exposed; /* the pad is exposed */
gboolean drained; /* an EOS has been seen on the pad */
gulong block_id;
};
GType gst_decode_pad_get_type (void);
G_DEFINE_TYPE (GstDecodePad, gst_decode_pad, GST_TYPE_GHOST_PAD);
#define GST_TYPE_DECODE_PAD (gst_decode_pad_get_type ())
#define GST_DECODE_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECODE_PAD,GstDecodePad))
static GstDecodePad *gst_decode_pad_new (GstDecodeBin * dbin,
GstDecodeChain * chain);
static void gst_decode_pad_activate (GstDecodePad * dpad,
GstDecodeChain * chain);
static void gst_decode_pad_unblock (GstDecodePad * dpad);
static void gst_decode_pad_set_blocked (GstDecodePad * dpad, gboolean blocked);
static gboolean gst_decode_pad_query (GstPad * pad, GstObject * parent,
GstQuery * query);
static gboolean gst_decode_pad_is_exposable (GstDecodePad * endpad);
static void gst_pending_pad_free (GstPendingPad * ppad);
static GstPadProbeReturn pad_event_cb (GstPad * pad, GstPadProbeInfo * info,
gpointer data);
/********************************
* Standard GObject boilerplate *
********************************/
static void gst_decode_bin_class_init (GstDecodeBinClass * klass);
static void gst_decode_bin_init (GstDecodeBin * decode_bin);
static void gst_decode_bin_dispose (GObject * object);
static void gst_decode_bin_finalize (GObject * object);
static GType
gst_decode_bin_get_type (void)
{
static GType gst_decode_bin_type = 0;
if (!gst_decode_bin_type) {
static const GTypeInfo gst_decode_bin_info = {
sizeof (GstDecodeBinClass),
NULL,
NULL,
(GClassInitFunc) gst_decode_bin_class_init,
NULL,
NULL,
sizeof (GstDecodeBin),
0,
(GInstanceInitFunc) gst_decode_bin_init,
NULL
};
gst_decode_bin_type =
g_type_register_static (GST_TYPE_BIN, "GstDecodeBin",
&gst_decode_bin_info, 0);
}
return gst_decode_bin_type;
}
static gboolean
_gst_boolean_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
gboolean myboolean;
myboolean = g_value_get_boolean (handler_return);
if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
g_value_set_boolean (return_accu, myboolean);
/* stop emission if FALSE */
return myboolean;
}
static gboolean
_gst_boolean_or_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
gboolean myboolean;
gboolean retboolean;
myboolean = g_value_get_boolean (handler_return);
retboolean = g_value_get_boolean (return_accu);
if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
g_value_set_boolean (return_accu, myboolean || retboolean);
return TRUE;
}
/* we collect the first result */
static gboolean
_gst_array_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
gpointer array;
array = g_value_get_boxed (handler_return);
if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
g_value_set_boxed (return_accu, array);
return FALSE;
}
static gboolean
_gst_select_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
GstAutoplugSelectResult res;
res = g_value_get_enum (handler_return);
if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
g_value_set_enum (return_accu, res);
/* Call the next handler in the chain (if any) when the current callback
* returns TRY. This makes it possible to register separate autoplug-select
* handlers that implement different TRY/EXPOSE/SKIP strategies.
*/
if (res == GST_AUTOPLUG_SELECT_TRY)
return TRUE;
return FALSE;
}
static gboolean
_gst_array_hasvalue_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
gpointer array;
array = g_value_get_boxed (handler_return);
if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
g_value_set_boxed (return_accu, array);
if (array != NULL)
return FALSE;
return TRUE;
}
static void
gst_decode_bin_class_init (GstDecodeBinClass * klass)
{
GObjectClass *gobject_klass;
GstElementClass *gstelement_klass;
GstBinClass *gstbin_klass;
gobject_klass = (GObjectClass *) klass;
gstelement_klass = (GstElementClass *) klass;
gstbin_klass = (GstBinClass *) klass;
parent_class = g_type_class_peek_parent (klass);
gobject_klass->dispose = gst_decode_bin_dispose;
gobject_klass->finalize = gst_decode_bin_finalize;
gobject_klass->set_property = gst_decode_bin_set_property;
gobject_klass->get_property = gst_decode_bin_get_property;
/**
* GstDecodeBin::unknown-type:
* @bin: The decodebin.
* @pad: The new pad containing caps that cannot be resolved to a 'final'
* stream type.
* @caps: The #GstCaps of the pad that cannot be resolved.
*
* This signal is emitted when a pad for which there is no further possible
* decoding is added to the decodebin.
*/
gst_decode_bin_signals[SIGNAL_UNKNOWN_TYPE] =
g_signal_new ("unknown-type", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, unknown_type),
NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2,
GST_TYPE_PAD, GST_TYPE_CAPS);
/**
* GstDecodeBin::autoplug-continue:
* @bin: The decodebin.
* @pad: The #GstPad.
* @caps: The #GstCaps found.
*
* This signal is emitted whenever decodebin finds a new stream. It is
* emitted before looking for any elements that can handle that stream.
*
* <note>
* Invocation of signal handlers stops after the first signal handler
* returns #FALSE. Signal handlers are invoked in the order they were
* connected in.
* </note>
*
* Returns: #TRUE if you wish decodebin to look for elements that can
* handle the given @caps. If #FALSE, those caps will be considered as
* final and the pad will be exposed as such (see 'pad-added' signal of
* #GstElement).
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE] =
g_signal_new ("autoplug-continue", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_continue),
_gst_boolean_accumulator, NULL, g_cclosure_marshal_generic,
G_TYPE_BOOLEAN, 2, GST_TYPE_PAD, GST_TYPE_CAPS);
/**
* GstDecodeBin::autoplug-factories:
* @bin: The decodebin.
* @pad: The #GstPad.
* @caps: The #GstCaps found.
*
* This function is emited when an array of possible factories for @caps on
* @pad is needed. Decodebin will by default return an array with all
* compatible factories, sorted by rank.
*
* If this function returns NULL, @pad will be exposed as a final caps.
*
* If this function returns an empty array, the pad will be considered as
* having an unhandled type media type.
*
* <note>
* Only the signal handler that is connected first will ever by invoked.
* Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
* signal, they will never be invoked!
* </note>
*
* Returns: a #GValueArray* with a list of factories to try. The factories are
* by default tried in the returned order or based on the index returned by
* "autoplug-select".
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES] =
g_signal_new ("autoplug-factories", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass,
autoplug_factories), _gst_array_accumulator, NULL,
g_cclosure_marshal_generic, G_TYPE_VALUE_ARRAY, 2,
GST_TYPE_PAD, GST_TYPE_CAPS);
/**
* GstDecodeBin::autoplug-sort:
* @bin: The decodebin.
* @pad: The #GstPad.
* @caps: The #GstCaps.
* @factories: A #GValueArray of possible #GstElementFactory to use.
*
* Once decodebin has found the possible #GstElementFactory objects to try
* for @caps on @pad, this signal is emited. The purpose of the signal is for
* the application to perform additional sorting or filtering on the element
* factory array.
*
* The callee should copy and modify @factories or return #NULL if the
* order should not change.
*
* <note>
* Invocation of signal handlers stops after one signal handler has
* returned something else than #NULL. Signal handlers are invoked in
* the order they were connected in.
* Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
* signal, they will never be invoked!
* </note>
*
* Returns: A new sorted array of #GstElementFactory objects.
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_SORT] =
g_signal_new ("autoplug-sort", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_sort),
_gst_array_hasvalue_accumulator, NULL,
g_cclosure_marshal_generic, G_TYPE_VALUE_ARRAY, 3, GST_TYPE_PAD,
GST_TYPE_CAPS, G_TYPE_VALUE_ARRAY | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* GstDecodeBin::autoplug-select:
* @bin: The decodebin.
* @pad: The #GstPad.
* @caps: The #GstCaps.
* @factory: A #GstElementFactory to use.
*
* This signal is emitted once decodebin has found all the possible
* #GstElementFactory that can be used to handle the given @caps. For each of
* those factories, this signal is emitted.
*
* The signal handler should return a #GST_TYPE_AUTOPLUG_SELECT_RESULT enum
* value indicating what decodebin should do next.
*
* A value of #GST_AUTOPLUG_SELECT_TRY will try to autoplug an element from
* @factory.
*
* A value of #GST_AUTOPLUG_SELECT_EXPOSE will expose @pad without plugging
* any element to it.
*
* A value of #GST_AUTOPLUG_SELECT_SKIP will skip @factory and move to the
* next factory.
*
* <note>
* The signal handler will not be invoked if any of the previously
* registered signal handlers (if any) return a value other than
* GST_AUTOPLUG_SELECT_TRY. Which also means that if you return
* GST_AUTOPLUG_SELECT_TRY from one signal handler, handlers that get
* registered next (again, if any) can override that decision.
* </note>
*
* Returns: a #GST_TYPE_AUTOPLUG_SELECT_RESULT that indicates the required
* operation. the default handler will always return
* #GST_AUTOPLUG_SELECT_TRY.
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT] =
g_signal_new ("autoplug-select", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_select),
_gst_select_accumulator, NULL,
g_cclosure_marshal_generic,
GST_TYPE_AUTOPLUG_SELECT_RESULT, 3, GST_TYPE_PAD, GST_TYPE_CAPS,
GST_TYPE_ELEMENT_FACTORY);
/**
* GstDecodeBin::autoplug-query:
* @bin: The decodebin.
* @pad: The #GstPad.
* @child: The child element doing the query
* @query: The #GstQuery.
*
* This signal is emitted whenever an autoplugged element that is
* not linked downstream yet and not exposed does a query. It can
* be used to tell the element about the downstream supported caps
* for example.
*
* Returns: #TRUE if the query was handled, #FALSE otherwise.
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_QUERY] =
g_signal_new ("autoplug-query", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_query),
_gst_boolean_or_accumulator, NULL, g_cclosure_marshal_generic,
G_TYPE_BOOLEAN, 3, GST_TYPE_PAD, GST_TYPE_ELEMENT,
GST_TYPE_QUERY | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* GstDecodeBin::drained
* @bin: The decodebin
*
* This signal is emitted once decodebin has finished decoding all the data.
*/
gst_decode_bin_signals[SIGNAL_DRAINED] =
g_signal_new ("drained", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, drained),
NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 0, G_TYPE_NONE);
g_object_class_install_property (gobject_klass, PROP_CAPS,
g_param_spec_boxed ("caps", "Caps", "The caps on which to stop decoding.",
GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
g_param_spec_string ("subtitle-encoding", "subtitle encoding",
"Encoding to assume if input subtitles are not in UTF-8 encoding. "
"If not set, the GST_SUBTITLE_ENCODING environment variable will "
"be checked for an encoding to use. If that is not set either, "
"ISO-8859-15 will be assumed.", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_SINK_CAPS,
g_param_spec_boxed ("sink-caps", "Sink Caps",
"The caps of the input data. (NULL = use typefind element)",
GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin::use-buffering
*
* Activate buffering in decodebin. This will instruct the multiqueues behind
* decoders to emit BUFFERING messages.
*/
g_object_class_install_property (gobject_klass, PROP_USE_BUFFERING,
g_param_spec_boolean ("use-buffering", "Use Buffering",
"Emit GST_MESSAGE_BUFFERING based on low-/high-percent thresholds",
DEFAULT_USE_BUFFERING, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:low-percent
*
* Low threshold percent for buffering to start.
*/
g_object_class_install_property (gobject_klass, PROP_LOW_PERCENT,
g_param_spec_int ("low-percent", "Low percent",
"Low threshold for buffering to start", 0, 100,
DEFAULT_LOW_PERCENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:high-percent
*
* High threshold percent for buffering to finish.
*/
g_object_class_install_property (gobject_klass, PROP_HIGH_PERCENT,
g_param_spec_int ("high-percent", "High percent",
"High threshold for buffering to finish", 0, 100,
DEFAULT_HIGH_PERCENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:max-size-bytes
*
* Max amount of bytes in the queue (0=automatic).
*/
g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_BYTES,
g_param_spec_uint ("max-size-bytes", "Max. size (bytes)",
"Max. amount of bytes in the queue (0=automatic)",
0, G_MAXUINT, DEFAULT_MAX_SIZE_BYTES,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:max-size-buffers
*
* Max amount of buffers in the queue (0=automatic).
*/
g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_BUFFERS,
g_param_spec_uint ("max-size-buffers", "Max. size (buffers)",
"Max. number of buffers in the queue (0=automatic)",
0, G_MAXUINT, DEFAULT_MAX_SIZE_BUFFERS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:max-size-time
*
* Max amount of time in the queue (in ns, 0=automatic).
*/
g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_TIME,
g_param_spec_uint64 ("max-size-time", "Max. size (ns)",
"Max. amount of data in the queue (in ns, 0=automatic)",
0, G_MAXUINT64,
DEFAULT_MAX_SIZE_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin::post-stream-topology
*
* Post stream-topology messages on the bus every time the topology changes.
*/
g_object_class_install_property (gobject_klass, PROP_POST_STREAM_TOPOLOGY,
g_param_spec_boolean ("post-stream-topology", "Post Stream Topology",
"Post stream-topology messages",
DEFAULT_POST_STREAM_TOPOLOGY,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin::expose-all-streams
*
* Expose streams of unknown type.
*
* If set to %FALSE, then only the streams that can be decoded to the final
* caps (see 'caps' property) will have a pad exposed. Streams that do not
* match those caps but could have been decoded will not have decoder plugged
* in internally and will not have a pad exposed.
*/
g_object_class_install_property (gobject_klass, PROP_EXPOSE_ALL_STREAMS,
g_param_spec_boolean ("expose-all-streams", "Expose All Streams",
"Expose all streams, including those of unknown type or that don't match the 'caps' property",
DEFAULT_EXPOSE_ALL_STREAMS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin2::connection-speed
*
* Network connection speed in kbps (0 = unknownw)
*/
g_object_class_install_property (gobject_klass, PROP_CONNECTION_SPEED,
g_param_spec_uint64 ("connection-speed", "Connection Speed",
"Network connection speed in kbps (0 = unknown)",
0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
klass->autoplug_continue =
GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_continue);
klass->autoplug_factories =
GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_factories);
klass->autoplug_sort = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_sort);
klass->autoplug_select = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_select);
klass->autoplug_query = GST_DEBUG_FUNCPTR (gst_decode_bin_autoplug_query);
gst_element_class_add_static_pad_template (gstelement_klass,
&decoder_bin_sink_template);
gst_element_class_add_static_pad_template (gstelement_klass,
&decoder_bin_src_template);
gst_element_class_set_static_metadata (gstelement_klass,
"Decoder Bin", "Generic/Bin/Decoder",
"Autoplug and decode to raw media",
"Edward Hervey <edward.hervey@collabora.co.uk>, "
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
gstelement_klass->change_state =
GST_DEBUG_FUNCPTR (gst_decode_bin_change_state);
gstbin_klass->handle_message =
GST_DEBUG_FUNCPTR (gst_decode_bin_handle_message);
gstbin_klass->remove_element =
GST_DEBUG_FUNCPTR (gst_decode_bin_remove_element);
g_type_class_ref (GST_TYPE_DECODE_PAD);
}
/* Must be called with factories lock! */
static void
gst_decode_bin_update_factories_list (GstDecodeBin * dbin)
{
guint cookie;
cookie = gst_registry_get_feature_list_cookie (gst_registry_get ());
if (!dbin->factories || dbin->factories_cookie != cookie) {
if (dbin->factories)
gst_plugin_feature_list_free (dbin->factories);
dbin->factories =
gst_element_factory_list_get_elements
(GST_ELEMENT_FACTORY_TYPE_DECODABLE, GST_RANK_MARGINAL);
dbin->factories =
g_list_sort (dbin->factories,
gst_playback_utils_compare_factories_func);
dbin->factories_cookie = cookie;
}
}
static void
gst_decode_bin_init (GstDecodeBin * decode_bin)
{
/* first filter out the interesting element factories */
g_mutex_init (&decode_bin->factories_lock);
/* we create the typefind element only once */
decode_bin->typefind = gst_element_factory_make ("typefind", "typefind");
if (!decode_bin->typefind) {
g_warning ("can't find typefind element, decodebin will not work");
} else {
GstPad *pad;
GstPad *gpad;
GstPadTemplate *pad_tmpl;
/* add the typefind element */
if (!gst_bin_add (GST_BIN (decode_bin), decode_bin->typefind)) {
g_warning ("Could not add typefind element, decodebin will not work");
gst_object_unref (decode_bin->typefind);
decode_bin->typefind = NULL;
}
/* get the sinkpad */
pad = gst_element_get_static_pad (decode_bin->typefind, "sink");
/* get the pad template */
pad_tmpl = gst_static_pad_template_get (&decoder_bin_sink_template);
/* ghost the sink pad to ourself */
gpad = gst_ghost_pad_new_from_template ("sink", pad, pad_tmpl);
gst_pad_set_active (gpad, TRUE);
gst_element_add_pad (GST_ELEMENT (decode_bin), gpad);
gst_object_unref (pad_tmpl);
gst_object_unref (pad);
}
g_mutex_init (&decode_bin->expose_lock);
decode_bin->decode_chain = NULL;
g_mutex_init (&decode_bin->dyn_lock);
decode_bin->shutdown = FALSE;
decode_bin->blocked_pads = NULL;
g_mutex_init (&decode_bin->subtitle_lock);
g_mutex_init (&decode_bin->buffering_lock);
g_mutex_init (&decode_bin->buffering_post_lock);
decode_bin->encoding = g_strdup (DEFAULT_SUBTITLE_ENCODING);
decode_bin->caps = gst_static_caps_get (&default_raw_caps);
decode_bin->use_buffering = DEFAULT_USE_BUFFERING;
decode_bin->low_percent = DEFAULT_LOW_PERCENT;
decode_bin->high_percent = DEFAULT_HIGH_PERCENT;
decode_bin->max_size_bytes = DEFAULT_MAX_SIZE_BYTES;
decode_bin->max_size_buffers = DEFAULT_MAX_SIZE_BUFFERS;
decode_bin->max_size_time = DEFAULT_MAX_SIZE_TIME;
decode_bin->expose_allstreams = DEFAULT_EXPOSE_ALL_STREAMS;
decode_bin->connection_speed = DEFAULT_CONNECTION_SPEED;
}
static void
gst_decode_bin_dispose (GObject * object)
{
GstDecodeBin *decode_bin;
decode_bin = GST_DECODE_BIN (object);
if (decode_bin->factories)
gst_plugin_feature_list_free (decode_bin->factories);
decode_bin->factories = NULL;
if (decode_bin->decode_chain)
gst_decode_chain_free (decode_bin->decode_chain);
decode_bin->decode_chain = NULL;
if (decode_bin->caps)
gst_caps_unref (decode_bin->caps);
decode_bin->caps = NULL;
g_free (decode_bin->encoding);
decode_bin->encoding = NULL;
g_list_free (decode_bin->subtitles);
decode_bin->subtitles = NULL;
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gst_decode_bin_finalize (GObject * object)
{
GstDecodeBin *decode_bin;
decode_bin = GST_DECODE_BIN (object);
g_mutex_clear (&decode_bin->expose_lock);
g_mutex_clear (&decode_bin->dyn_lock);
g_mutex_clear (&decode_bin->subtitle_lock);
g_mutex_clear (&decode_bin->buffering_lock);
g_mutex_clear (&decode_bin->buffering_post_lock);
g_mutex_clear (&decode_bin->factories_lock);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/* _set_caps
* Changes the caps on which decodebin will stop decoding.
* Will unref the previously set one. The refcount of the given caps will be
* increased.
* @caps can be NULL.
*
* MT-safe
*/
static void
gst_decode_bin_set_caps (GstDecodeBin * dbin, GstCaps * caps)
{
GST_DEBUG_OBJECT (dbin, "Setting new caps: %" GST_PTR_FORMAT, caps);
GST_OBJECT_LOCK (dbin);
gst_caps_replace (&dbin->caps, caps);
GST_OBJECT_UNLOCK (dbin);
}
/* _get_caps
* Returns the currently configured caps on which decodebin will stop decoding.
* The returned caps (if not NULL), will have its refcount incremented.
*
* MT-safe
*/
static GstCaps *
gst_decode_bin_get_caps (GstDecodeBin * dbin)
{
GstCaps *caps;
GST_DEBUG_OBJECT (dbin, "Getting currently set caps");
GST_OBJECT_LOCK (dbin);
caps = dbin->caps;
if (caps)
gst_caps_ref (caps);
GST_OBJECT_UNLOCK (dbin);
return caps;
}
static void
gst_decode_bin_set_sink_caps (GstDecodeBin * dbin, GstCaps * caps)
{
GST_DEBUG_OBJECT (dbin, "Setting new caps: %" GST_PTR_FORMAT, caps);
g_object_set (dbin->typefind, "force-caps", caps, NULL);
}
static GstCaps *
gst_decode_bin_get_sink_caps (GstDecodeBin * dbin)
{
GstCaps *caps;
GST_DEBUG_OBJECT (dbin, "Getting currently set caps");
g_object_get (dbin->typefind, "force-caps", &caps, NULL);
return caps;
}
static void
gst_decode_bin_set_subs_encoding (GstDecodeBin * dbin, const gchar * encoding)
{
GList *walk;
GST_DEBUG_OBJECT (dbin, "Setting new encoding: %s", GST_STR_NULL (encoding));
SUBTITLE_LOCK (dbin);
g_free (dbin->encoding);
dbin->encoding = g_strdup (encoding);
/* set the subtitle encoding on all added elements */
for (walk = dbin->subtitles; walk; walk = g_list_next (walk)) {
g_object_set (G_OBJECT (walk->data), "subtitle-encoding", dbin->encoding,
NULL);
}
SUBTITLE_UNLOCK (dbin);
}
static gchar *
gst_decode_bin_get_subs_encoding (GstDecodeBin * dbin)
{
gchar *encoding;
GST_DEBUG_OBJECT (dbin, "Getting currently set encoding");
SUBTITLE_LOCK (dbin);
encoding = g_strdup (dbin->encoding);
SUBTITLE_UNLOCK (dbin);
return encoding;
}
static void
gst_decode_bin_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstDecodeBin *dbin;
dbin = GST_DECODE_BIN (object);
switch (prop_id) {
case PROP_CAPS:
gst_decode_bin_set_caps (dbin, g_value_get_boxed (value));
break;
case PROP_SUBTITLE_ENCODING:
gst_decode_bin_set_subs_encoding (dbin, g_value_get_string (value));
break;
case PROP_SINK_CAPS:
gst_decode_bin_set_sink_caps (dbin, g_value_get_boxed (value));
break;
case PROP_USE_BUFFERING:
dbin->use_buffering = g_value_get_boolean (value);
break;
case PROP_LOW_PERCENT:
dbin->low_percent = g_value_get_int (value);
break;
case PROP_HIGH_PERCENT:
dbin->high_percent = g_value_get_int (value);
break;
case PROP_MAX_SIZE_BYTES:
dbin->max_size_bytes = g_value_get_uint (value);
break;
case PROP_MAX_SIZE_BUFFERS:
dbin->max_size_buffers = g_value_get_uint (value);
break;
case PROP_MAX_SIZE_TIME:
dbin->max_size_time = g_value_get_uint64 (value);
break;
case PROP_POST_STREAM_TOPOLOGY:
dbin->post_stream_topology = g_value_get_boolean (value);
break;
case PROP_EXPOSE_ALL_STREAMS:
dbin->expose_allstreams = g_value_get_boolean (value);
break;
case PROP_CONNECTION_SPEED:
GST_OBJECT_LOCK (dbin);
dbin->connection_speed = g_value_get_uint64 (value) * 1000;
GST_OBJECT_UNLOCK (dbin);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_decode_bin_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstDecodeBin *dbin;
dbin = GST_DECODE_BIN (object);
switch (prop_id) {
case PROP_CAPS:
g_value_take_boxed (value, gst_decode_bin_get_caps (dbin));
break;
case PROP_SUBTITLE_ENCODING:
g_value_take_string (value, gst_decode_bin_get_subs_encoding (dbin));
break;
case PROP_SINK_CAPS:
g_value_take_boxed (value, gst_decode_bin_get_sink_caps (dbin));
break;
case PROP_USE_BUFFERING:
g_value_set_boolean (value, dbin->use_buffering);
break;
case PROP_LOW_PERCENT:
g_value_set_int (value, dbin->low_percent);
break;
case PROP_HIGH_PERCENT:
g_value_set_int (value, dbin->high_percent);
break;
case PROP_MAX_SIZE_BYTES:
g_value_set_uint (value, dbin->max_size_bytes);
break;
case PROP_MAX_SIZE_BUFFERS:
g_value_set_uint (value, dbin->max_size_buffers);
break;
case PROP_MAX_SIZE_TIME:
g_value_set_uint64 (value, dbin->max_size_time);
break;
case PROP_POST_STREAM_TOPOLOGY:
g_value_set_boolean (value, dbin->post_stream_topology);
break;
case PROP_EXPOSE_ALL_STREAMS:
g_value_set_boolean (value, dbin->expose_allstreams);
break;
case PROP_CONNECTION_SPEED:
GST_OBJECT_LOCK (dbin);
g_value_set_uint64 (value, dbin->connection_speed / 1000);
GST_OBJECT_UNLOCK (dbin);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/*****
* Default autoplug signal handlers
*****/
static gboolean
gst_decode_bin_autoplug_continue (GstElement * element, GstPad * pad,
GstCaps * caps)
{
GST_DEBUG_OBJECT (element, "autoplug-continue returns TRUE");
/* by default we always continue */
return TRUE;
}
static GValueArray *
gst_decode_bin_autoplug_factories (GstElement * element, GstPad * pad,
GstCaps * caps)
{
GList *list, *tmp;
GValueArray *result;
GstDecodeBin *dbin = GST_DECODE_BIN_CAST (element);
GST_DEBUG_OBJECT (element, "finding factories");
/* return all compatible factories for caps */
g_mutex_lock (&dbin->factories_lock);
gst_decode_bin_update_factories_list (dbin);
list =
gst_element_factory_list_filter (dbin->factories, caps, GST_PAD_SINK,
gst_caps_is_fixed (caps));
g_mutex_unlock (&dbin->factories_lock);
result = g_value_array_new (g_list_length (list));
for (tmp = list; tmp; tmp = tmp->next) {
GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (tmp->data);
GValue val = { 0, };
g_value_init (&val, G_TYPE_OBJECT);
g_value_set_object (&val, factory);
g_value_array_append (result, &val);
g_value_unset (&val);
}
gst_plugin_feature_list_free (list);
GST_DEBUG_OBJECT (element, "autoplug-factories returns %p", result);
return result;
}
static GValueArray *
gst_decode_bin_autoplug_sort (GstElement * element, GstPad * pad,
GstCaps * caps, GValueArray * factories)
{
return NULL;
}
static GstAutoplugSelectResult
gst_decode_bin_autoplug_select (GstElement * element, GstPad * pad,
GstCaps * caps, GstElementFactory * factory)
{
GST_DEBUG_OBJECT (element, "default autoplug-select returns TRY");
/* Try factory. */
return GST_AUTOPLUG_SELECT_TRY;
}
static gboolean
gst_decode_bin_autoplug_query (GstElement * element, GstPad * pad,
GstQuery * query)
{
/* No query handled here */
return FALSE;
}
/********
* Discovery methods
*****/
static gboolean are_final_caps (GstDecodeBin * dbin, GstCaps * caps);
static gboolean is_demuxer_element (GstElement * srcelement);
static gboolean is_adaptive_demuxer_element (GstElement * srcelement);
static gboolean connect_pad (GstDecodeBin * dbin, GstElement * src,
GstDecodePad * dpad, GstPad * pad, GstCaps * caps, GValueArray * factories,
GstDecodeChain * chain, gchar ** deadend_details);
static GList *connect_element (GstDecodeBin * dbin, GstDecodeElement * delem,
GstDecodeChain * chain);
static void expose_pad (GstDecodeBin * dbin, GstElement * src,
GstDecodePad * dpad, GstPad * pad, GstCaps * caps, GstDecodeChain * chain);
static void pad_added_cb (GstElement * element, GstPad * pad,
GstDecodeChain * chain);
static void pad_removed_cb (GstElement * element, GstPad * pad,
GstDecodeChain * chain);
static void no_more_pads_cb (GstElement * element, GstDecodeChain * chain);
static GstDecodeGroup *gst_decode_chain_get_current_group (GstDecodeChain *
chain);
static gboolean
clear_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
{
GST_DEBUG_OBJECT (pad, "clearing sticky event %" GST_PTR_FORMAT, *event);
gst_event_unref (*event);
*event = NULL;
return TRUE;
}
static gboolean
copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
{
GstPad *gpad = GST_PAD_CAST (user_data);
GST_DEBUG_OBJECT (gpad, "store sticky event %" GST_PTR_FORMAT, *event);
gst_pad_store_sticky_event (gpad, *event);
return TRUE;
}
static void
decode_pad_set_target (GstDecodePad * dpad, GstPad * target)
{
gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (dpad), target);
if (target == NULL)
gst_pad_sticky_events_foreach (GST_PAD_CAST (dpad), clear_sticky_events,
NULL);
else
gst_pad_sticky_events_foreach (target, copy_sticky_events, dpad);
}
/* called when a new pad is discovered. It will perform some basic actions
* before trying to link something to it.
*
* - Check the caps, don't do anything when there are no caps or when they have
* no good type.
* - signal AUTOPLUG_CONTINUE to check if we need to continue autoplugging this
* pad.
* - if the caps are non-fixed, setup a handler to continue autoplugging when
* the caps become fixed (connect to notify::caps).
* - get list of factories to autoplug.
* - continue autoplugging to one of the factories.
*/
/* returns whether to expose the pad */
static gboolean
analyze_new_pad (GstDecodeBin * dbin, GstElement * src, GstPad * pad,
GstCaps * caps, GstDecodeChain * chain, GstDecodeChain ** new_chain)
{
gboolean apcontinue = TRUE;
GValueArray *factories = NULL, *result = NULL;
GstDecodePad *dpad;
GstElementFactory *factory;
const gchar *classification;
gboolean is_parser_converter = FALSE;
gboolean res;
gchar *deadend_details = NULL;
GST_DEBUG_OBJECT (dbin, "Pad %s:%s caps:%" GST_PTR_FORMAT,
GST_DEBUG_PAD_NAME (pad), caps);
if (new_chain)
*new_chain = chain;
if (chain->elements
&& src != ((GstDecodeElement *) chain->elements->data)->element
&& src != ((GstDecodeElement *) chain->elements->data)->capsfilter) {
GST_ERROR_OBJECT (dbin, "New pad from not the last element in this chain");
return FALSE;
}
if (chain->endpad) {
GST_ERROR_OBJECT (dbin, "New pad in a chain that is already complete");
return FALSE;
}
if (chain->demuxer) {
GstDecodeGroup *group;
GstDecodeChain *oldchain = chain;
GstDecodeElement *demux = (chain->elements ? chain->elements->data : NULL);
if (chain->current_pad)
gst_object_unref (chain->current_pad);
chain->current_pad = NULL;
/* we are adding a new pad for a demuxer (see is_demuxer_element(),
* start a new chain for it */
CHAIN_MUTEX_LOCK (oldchain);
group = gst_decode_chain_get_current_group (chain);
if (group && !g_list_find (group->children, chain)) {
g_assert (new_chain != NULL);
*new_chain = chain = gst_decode_chain_new (dbin, group, pad);
group->children = g_list_prepend (group->children, chain);
}
CHAIN_MUTEX_UNLOCK (oldchain);
if (!group) {
GST_WARNING_OBJECT (dbin, "No current group");
return FALSE;
}
/* If this is not a dynamic pad demuxer, we're no-more-pads
* already before anything else happens
*/
if (demux == NULL || !demux->no_more_pads_id)
group->no_more_pads = TRUE;
}
/* From here on we own a reference to the caps as
* we might create new caps below and would need
* to unref them later */
if (caps)
gst_caps_ref (caps);
if ((caps == NULL) || gst_caps_is_empty (caps))
goto unknown_type;
if (gst_caps_is_any (caps))
goto any_caps;
if (!chain->current_pad)
chain->current_pad = gst_decode_pad_new (dbin, chain);
dpad = gst_object_ref (chain->current_pad);
gst_pad_set_active (GST_PAD_CAST (dpad), TRUE);
decode_pad_set_target (dpad, pad);
/* 1. Emit 'autoplug-continue' the result will tell us if this pads needs
* further autoplugging. Only do this for fixed caps, for unfixed caps
* we will later come here again from the notify::caps handler. The
* problem with unfixed caps is that, we can't reliably tell if the output
* is e.g. accepted by a sink because only parts of the possible final
* caps might be accepted by the sink. */
if (gst_caps_is_fixed (caps))
g_signal_emit (G_OBJECT (dbin),
gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE], 0, dpad, caps,
&apcontinue);
else
apcontinue = TRUE;
/* 1.a if autoplug-continue is FALSE or caps is a raw format, goto pad_is_final */
if ((!apcontinue) || are_final_caps (dbin, caps))
goto expose_pad;
/* 1.b For Parser/Converter that can output different stream formats
* we insert a capsfilter with the sorted caps of all possible next
* elements and continue with the capsfilter srcpad */
factory = gst_element_get_factory (src);
classification =
gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
is_parser_converter = (strstr (classification, "Parser")
&& strstr (classification, "Converter"));
/* 1.c when the caps are not fixed yet, we can't be sure what element to
* connect. We delay autoplugging until the caps are fixed */
if (!is_parser_converter && !gst_caps_is_fixed (caps)) {
goto non_fixed;
} else if (!is_parser_converter) {
gst_caps_unref (caps);
caps = gst_pad_get_current_caps (pad);
if (!caps) {
GST_DEBUG_OBJECT (dbin, "No final caps set yet, delaying autoplugging");
gst_object_unref (dpad);
goto setup_caps_delay;
}
}
/* 1.d else get the factories and if there's no compatible factory goto
* unknown_type */
g_signal_emit (G_OBJECT (dbin),
gst_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES], 0, dpad, caps,
&factories);
/* NULL means that we can expose the pad */
if (factories == NULL)
goto expose_pad;
/* if the array is empty, we have a type for which we have no decoder */
if (factories->n_values == 0) {
if (!dbin->expose_allstreams) {
GstCaps *raw = gst_static_caps_get (&default_raw_caps);
/* If the caps are raw, this just means we don't want to expose them */
if (gst_caps_is_subset (caps, raw)) {
g_value_array_free (factories);
gst_caps_unref (raw);
gst_object_unref (dpad);
goto discarded_type;
}
gst_caps_unref (raw);
}
/* if not we have a unhandled type with no compatible factories */
g_value_array_free (factories);
gst_object_unref (dpad);
goto unknown_type;
}
/* 1.e sort some more. */
g_signal_emit (G_OBJECT (dbin),
gst_decode_bin_signals[SIGNAL_AUTOPLUG_SORT], 0, dpad, caps, factories,
&result);
if (result) {
g_value_array_free (factories);
factories = result;
}
/* At this point we have a potential decoder, but we might not need it
* if it doesn't match the output caps */
if (!dbin->expose_allstreams && gst_caps_is_fixed (caps)) {
guint i;
const GList *tmps;
gboolean dontuse = FALSE;
GST_DEBUG ("Checking if we can abort early");
/* 1.f Do an early check to see if the candidates are potential decoders, but
* due to the fact that they decode to a mediatype that is not final we don't
* need them */
for (i = 0; i < factories->n_values && !dontuse; i++) {
GstElementFactory *factory =
g_value_get_object (g_value_array_get_nth (factories, i));
GstCaps *tcaps;
/* We are only interested in skipping decoders */
if (strstr (gst_element_factory_get_metadata (factory,
GST_ELEMENT_METADATA_KLASS), "Decoder")) {
GST_DEBUG ("Trying factory %s",
gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
/* Check the source pad template caps to see if they match raw caps but don't match
* our final caps*/
for (tmps = gst_element_factory_get_static_pad_templates (factory);
tmps && !dontuse; tmps = tmps->next) {
GstStaticPadTemplate *st = (GstStaticPadTemplate *) tmps->data;
if (st->direction != GST_PAD_SRC)
continue;
tcaps = gst_static_pad_template_get_caps (st);
apcontinue = TRUE;
/* Emit autoplug-continue to see if the caps are considered to be raw caps */
g_signal_emit (G_OBJECT (dbin),
gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE], 0, dpad, tcaps,
&apcontinue);
/* If autoplug-continue returns TRUE and the caps are not final, don't use them */
if (apcontinue && !are_final_caps (dbin, tcaps))
dontuse = TRUE;
gst_caps_unref (tcaps);
}
}
}
if (dontuse) {
gst_object_unref (dpad);
g_value_array_free (factories);
goto discarded_type;
}
}
/* 1.g now get the factory template caps and insert the capsfilter if this
* is a parser/converter
*/
if (is_parser_converter) {
GstCaps *filter_caps;
gint i;
GstElement *capsfilter;
GstPad *p;
GstDecodeElement *delem;
filter_caps = gst_caps_new_empty ();
for (i = 0; i < factories->n_values; i++) {
GstElementFactory *factory =
g_value_get_object (g_value_array_get_nth (factories, i));
GstCaps *tcaps, *intersection;
const GList *tmps;
GST_DEBUG ("Trying factory %s",
gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
if (gst_element_get_factory (src) == factory ||
gst_element_factory_list_is_type (factory,
GST_ELEMENT_FACTORY_TYPE_PARSER)) {
GST_DEBUG ("Skipping factory");
continue;
}
for (tmps = gst_element_factory_get_static_pad_templates (factory); tmps;
tmps = tmps->next) {
GstStaticPadTemplate *st = (GstStaticPadTemplate *) tmps->data;
if (st->direction != GST_PAD_SINK || st->presence != GST_PAD_ALWAYS)
continue;
tcaps = gst_static_pad_template_get_caps (st);
intersection =
gst_caps_intersect_full (tcaps, caps, GST_CAPS_INTERSECT_FIRST);
filter_caps = gst_caps_merge (filter_caps, intersection);
gst_caps_unref (tcaps);
}
}
/* Append the parser caps to prevent any not-negotiated errors */
filter_caps = gst_caps_merge (filter_caps, gst_caps_ref (caps));
if (chain->elements) {
delem = (GstDecodeElement *) chain->elements->data;
capsfilter = delem->capsfilter =
gst_element_factory_make ("capsfilter", NULL);
} else {
delem = g_slice_new0 (GstDecodeElement);
capsfilter = delem->element =
gst_element_factory_make ("capsfilter", NULL);
delem->capsfilter = NULL;
chain->elements = g_list_prepend (chain->elements, delem);
}
g_object_set (G_OBJECT (capsfilter), "caps", filter_caps, NULL);
gst_caps_unref (filter_caps);
gst_element_set_state (capsfilter, GST_STATE_PAUSED);
gst_bin_add (GST_BIN_CAST (dbin), gst_object_ref (capsfilter));
decode_pad_set_target (dpad, NULL);
p = gst_element_get_static_pad (capsfilter, "sink");
gst_pad_link_full (pad, p, GST_PAD_LINK_CHECK_NOTHING);
gst_object_unref (p);
p = gst_element_get_static_pad (capsfilter, "src");
decode_pad_set_target (dpad, p);
pad = p;
gst_caps_unref (caps);
caps = gst_pad_get_current_caps (pad);
if (!caps) {
GST_DEBUG_OBJECT (dbin, "No final caps set yet, delaying autoplugging");
gst_object_unref (dpad);
g_value_array_free (factories);
goto setup_caps_delay;
}
}
/* 1.h else continue autoplugging something from the list. */
GST_LOG_OBJECT (pad, "Let's continue discovery on this pad");
res =
connect_pad (dbin, src, dpad, pad, caps, factories, chain,
&deadend_details);
/* Need to unref the capsfilter srcpad here if
* we inserted a capsfilter */
if (is_parser_converter)
gst_object_unref (pad);
gst_object_unref (dpad);
g_value_array_free (factories);
if (!res)
goto unknown_type;
gst_caps_unref (caps);
return FALSE;
expose_pad:
{
GST_LOG_OBJECT (dbin, "Pad is final and should expose the pad. "
"autoplug-continue:%d", apcontinue);
gst_object_unref (dpad);
gst_caps_unref (caps);
return TRUE;
}
discarded_type:
{
GST_LOG_OBJECT (pad, "Known type, but discarded because not final caps");
chain->deadend = TRUE;
chain->endcaps = caps;
gst_object_replace ((GstObject **) & chain->current_pad, NULL);
/* Try to expose anything */
EXPOSE_LOCK (dbin);
if (dbin->decode_chain) {
if (gst_decode_chain_is_complete (dbin->decode_chain)) {
gst_decode_bin_expose (dbin);
}
}
EXPOSE_UNLOCK (dbin);
do_async_done (dbin);
return FALSE;
}
unknown_type:
{
GST_LOG_OBJECT (pad, "Unknown type, posting message and firing signal");
chain->deadend_details = deadend_details;
chain->deadend = TRUE;
chain->endcaps = caps;
gst_object_replace ((GstObject **) & chain->current_pad, NULL);
gst_element_post_message (GST_ELEMENT_CAST (dbin),
gst_missing_decoder_message_new (GST_ELEMENT_CAST (dbin), caps));
g_signal_emit (G_OBJECT (dbin),
gst_decode_bin_signals[SIGNAL_UNKNOWN_TYPE], 0, pad, caps);
/* Try to expose anything */
EXPOSE_LOCK (dbin);
if (dbin->decode_chain) {
if (gst_decode_chain_is_complete (dbin->decode_chain)) {
gst_decode_bin_expose (dbin);
}
}
EXPOSE_UNLOCK (dbin);
if (src == dbin->typefind) {
if (!caps || gst_caps_is_empty (caps)) {
GST_ELEMENT_ERROR (dbin, STREAM, TYPE_NOT_FOUND,
(_("Could not determine type of stream")), (NULL));
}
do_async_done (dbin);
}
return FALSE;
}
non_fixed:
{
GST_DEBUG_OBJECT (pad, "pad has non-fixed caps delay autoplugging");
gst_object_unref (dpad);
goto setup_caps_delay;
}
any_caps:
{
GST_DEBUG_OBJECT (pad, "pad has ANY caps, delaying auto-pluggin");
goto setup_caps_delay;
}
setup_caps_delay:
{
GstPendingPad *ppad;
/* connect to caps notification */
CHAIN_MUTEX_LOCK (chain);
GST_LOG_OBJECT (dbin, "Chain %p has now %d dynamic pads", chain,
g_list_length (chain->pending_pads));
ppad = g_slice_new0 (GstPendingPad);
ppad->pad = gst_object_ref (pad);
ppad->chain = chain;
ppad->event_probe_id =
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
pad_event_cb, ppad, NULL);
chain->pending_pads = g_list_prepend (chain->pending_pads, ppad);
ppad->notify_caps_id = g_signal_connect (pad, "notify::caps",
G_CALLBACK (caps_notify_cb), chain);
CHAIN_MUTEX_UNLOCK (chain);
/* If we're here because we have a Parser/Converter
* we have to unref the pad */
if (is_parser_converter)
gst_object_unref (pad);
if (caps)
gst_caps_unref (caps);
return FALSE;
}
}
static void
add_error_filter (GstDecodeBin * dbin, GstElement * element)
{
GST_OBJECT_LOCK (dbin);
dbin->filtered = g_list_prepend (dbin->filtered, element);
GST_OBJECT_UNLOCK (dbin);
}
static void
remove_error_filter (GstDecodeBin * dbin, GstElement * element,
GstMessage ** error)
{
GList *l;
GST_OBJECT_LOCK (dbin);
dbin->filtered = g_list_remove (dbin->filtered, element);
if (error)
*error = NULL;
l = dbin->filtered_errors;
while (l) {
GstMessage *msg = l->data;
if (GST_MESSAGE_SRC (msg) == GST_OBJECT_CAST (element)) {
/* Get the last error of this element, i.e. the earliest */
if (error)
gst_message_replace (error, msg);
gst_message_unref (msg);
l = dbin->filtered_errors = g_list_delete_link (dbin->filtered_errors, l);
} else {
l = l->next;
}
}
GST_OBJECT_UNLOCK (dbin);
}
typedef struct
{
gboolean ret;
GstPad *peer;
} SendStickyEventsData;
static gboolean
send_sticky_event (GstPad * pad, GstEvent ** event, gpointer user_data)
{
SendStickyEventsData *data = user_data;
gboolean ret;
ret = gst_pad_send_event (data->peer, gst_event_ref (*event));
if (!ret)
data->ret = FALSE;
return data->ret;
}
static gboolean
send_sticky_events (GstDecodeBin * dbin, GstPad * pad)
{
SendStickyEventsData data;
data.ret = TRUE;
data.peer = gst_pad_get_peer (pad);
gst_pad_sticky_events_foreach (pad, send_sticky_event, &data);
gst_object_unref (data.peer);
return data.ret;
}
static gchar *
error_message_to_string (GstMessage * msg)
{
GError *err;
gchar *debug, *message, *full_message;
gst_message_parse_error (msg, &err, &debug);
message = gst_error_get_message (err->domain, err->code);
if (debug)
full_message = g_strdup_printf ("%s\n%s\n%s", message, err->message, debug);
else
full_message = g_strdup_printf ("%s\n%s", message, err->message);
g_free (message);
g_free (debug);
g_clear_error (&err);
return full_message;
}
static GstPadProbeReturn
demuxer_source_pad_probe (GstPad * pad, GstPadProbeInfo * info,
gpointer user_data)
{
GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info);
GstDecodeGroup *group = (GstDecodeGroup *) user_data;
GstDecodeChain *parent_chain = group->parent;
GST_DEBUG_OBJECT (pad, "Saw event %s", GST_EVENT_TYPE_NAME (event));
/* Check if we are the active group, if not we need to proxy the flush
* events to the other groups (of which at least one is exposed, ensuring
* flushing properly propagates downstream of decodebin */
if (parent_chain->active_group == group)
return GST_PAD_PROBE_OK;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
case GST_EVENT_FLUSH_STOP:
{
GList *tmp;
GST_DEBUG_OBJECT (pad, "Proxying flush events to inactive groups");
/* Proxy to active group */
for (tmp = parent_chain->active_group->reqpads; tmp; tmp = tmp->next) {
GstPad *reqpad = (GstPad *) tmp->data;
gst_pad_send_event (reqpad, gst_event_ref (event));
}
/* Proxy to other non-active groups (except ourself) */
for (tmp = parent_chain->next_groups; tmp; tmp = tmp->next) {
GList *tmp2;
GstDecodeGroup *tmpgroup = (GstDecodeGroup *) tmp->data;
if (tmpgroup != group) {
for (tmp2 = tmpgroup->reqpads; tmp2; tmp2 = tmp2->next) {
GstPad *reqpad = (GstPad *) tmp2->data;
gst_pad_send_event (reqpad, gst_event_ref (event));
}
}
}
flush_chain (parent_chain,
GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START);
}
break;
default:
break;
}
return GST_PAD_PROBE_OK;
}
typedef struct
{
GstDecodeChain *chain;
GstPad *pad;
} PadExposeData;
/* connect_pad:
*
* Try to connect the given pad to an element created from one of the factories,
* and recursively.
*
* Note that dpad is ghosting pad, and so pad is linked; be sure to unset dpad's
* target before trying to link pad.
*
* Returns TRUE if an element was properly created and linked
*/
static gboolean
connect_pad (GstDecodeBin * dbin, GstElement * src, GstDecodePad * dpad,
GstPad * pad, GstCaps * caps, GValueArray * factories,
GstDecodeChain * chain, gchar ** deadend_details)
{
gboolean res = FALSE;
GstPad *mqpad = NULL;
gboolean is_demuxer = chain->parent && !chain->elements; /* First pad after the demuxer */
GString *error_details = NULL;
g_return_val_if_fail (factories != NULL, FALSE);
g_return_val_if_fail (factories->n_values > 0, FALSE);
GST_DEBUG_OBJECT (dbin,
"pad %s:%s , chain:%p, %d factories, caps %" GST_PTR_FORMAT,
GST_DEBUG_PAD_NAME (pad), chain, factories->n_values, caps);
/* 1. is element demuxer or parser */
if (is_demuxer) {
GST_LOG_OBJECT (src,
"is a demuxer, connecting the pad through multiqueue '%s'",
GST_OBJECT_NAME (chain->parent->multiqueue));
/* Set a flush-start/-stop probe on the downstream events */
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_FLUSH,
demuxer_source_pad_probe, chain->parent, NULL);
decode_pad_set_target (dpad, NULL);
if (!(mqpad = gst_decode_group_control_demuxer_pad (chain->parent, pad)))
goto beach;
src = chain->parent->multiqueue;
/* Forward sticky events to mq src pad to allow factory initialization */
gst_pad_sticky_events_foreach (pad, copy_sticky_events, mqpad);
pad = mqpad;
decode_pad_set_target (dpad, pad);
}
error_details = g_string_new ("");
/* 2. Try to create an element and link to it */
while (factories->n_values > 0) {
GstAutoplugSelectResult ret;
GstElementFactory *factory;
GstDecodeElement *delem;
GstElement *element;
GstPad *sinkpad;
GParamSpec *pspec;
gboolean subtitle;
GList *to_connect = NULL;
GList *to_expose = NULL;
gboolean is_parser = FALSE;
gboolean is_decoder = FALSE;
/* Set dpad target to pad again, it might've been unset
* below but we came back here because something failed
*/
decode_pad_set_target (dpad, pad);
/* take first factory */
factory = g_value_get_object (g_value_array_get_nth (factories, 0));
/* Remove selected factory from the list. */
g_value_array_remove (factories, 0);
GST_LOG_OBJECT (src, "trying factory %" GST_PTR_FORMAT, factory);
/* Check if the caps are really supported by the factory. The
* factory list is non-empty-subset filtered while caps
* are only accepted by a pad if they are a subset of the
* pad caps.
*
* FIXME: Only do this for fixed caps here. Non-fixed caps
* can happen if a Parser/Converter was autoplugged before
* this. We then assume that it will be able to convert to
* everything that the decoder would want.
*
* A subset check will fail here because the parser caps
* will be generic and while the decoder will only
* support a subset of the parser caps.
*/
if (gst_caps_is_fixed (caps)) {
const GList *templs;
gboolean skip = FALSE;
templs = gst_element_factory_get_static_pad_templates (factory);
while (templs) {
GstStaticPadTemplate *templ = (GstStaticPadTemplate *) templs->data;
if (templ->direction == GST_PAD_SINK) {
GstCaps *templcaps = gst_static_caps_get (&templ->static_caps);
if (!gst_caps_is_subset (caps, templcaps)) {
GST_DEBUG_OBJECT (src,
"caps %" GST_PTR_FORMAT " not subset of %" GST_PTR_FORMAT, caps,
templcaps);
gst_caps_unref (templcaps);
skip = TRUE;
break;
}
gst_caps_unref (templcaps);
}
templs = g_list_next (templs);
}
if (skip)
continue;
}
/* If the factory is for a parser we first check if the factory
* was already used for the current chain. If it was used already
* we would otherwise create an infinite loop here because the
* parser apparently accepts its own output as input.
* This is only done for parsers because it's perfectly valid
* to have other element classes after each other because a
* parser is the only one that does not change the data. A
* valid example for this would be multiple id3demux in a row.
*/
is_parser = strstr (gst_element_factory_get_metadata (factory,
GST_ELEMENT_METADATA_KLASS), "Parser") != NULL;
if (is_parser) {
gboolean skip = FALSE;
GList *l;
CHAIN_MUTEX_LOCK (chain);
for (l = chain->elements; l; l = l->next) {
GstDecodeElement *delem = (GstDecodeElement *) l->data;
GstElement *otherelement = delem->element;
if (gst_element_get_factory (otherelement) == factory) {
skip = TRUE;
break;
}
}
if (!skip && chain->parent && chain->parent->parent) {
GstDecodeChain *parent_chain = chain->parent->parent;
GstDecodeElement *pelem =
parent_chain->elements ? parent_chain->elements->data : NULL;
if (pelem && gst_element_get_factory (pelem->element) == factory)
skip = TRUE;
}
CHAIN_MUTEX_UNLOCK (chain);
if (skip) {
GST_DEBUG_OBJECT (dbin,
"Skipping factory '%s' because it was already used in this chain",
gst_plugin_feature_get_name (GST_PLUGIN_FEATURE_CAST (factory)));
continue;
}
}
/* emit autoplug-select to see what we should do with it. */
g_signal_emit (G_OBJECT (dbin),
gst_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT],
0, dpad, caps, factory, &ret);
switch (ret) {
case GST_AUTOPLUG_SELECT_TRY:
GST_DEBUG_OBJECT (dbin, "autoplug select requested try");
break;
case GST_AUTOPLUG_SELECT_EXPOSE:
GST_DEBUG_OBJECT (dbin, "autoplug select requested expose");
/* expose the pad, we don't have the source element */
expose_pad (dbin, src, dpad, pad, caps, chain);
res = TRUE;
goto beach;
case GST_AUTOPLUG_SELECT_SKIP:
GST_DEBUG_OBJECT (dbin, "autoplug select requested skip");
continue;
default:
GST_WARNING_OBJECT (dbin, "autoplug select returned unhandled %d", ret);
break;
}
/* 2.0. Unlink pad */
decode_pad_set_target (dpad, NULL);
/* 2.1. Try to create an element */
if ((element = gst_element_factory_create (factory, NULL)) == NULL) {
GST_WARNING_OBJECT (dbin, "Could not create an element from %s",
gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
g_string_append_printf (error_details,
"Could not create an element from %s\n",
gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
continue;
}
/* Filter errors, this will prevent the element from causing the pipeline
* to error while we test it using READY state. */
add_error_filter (dbin, element);
/* We don't yet want the bin to control the element's state */
gst_element_set_locked_state (element, TRUE);
/* ... add it ... */
if (!(gst_bin_add (GST_BIN_CAST (dbin), element))) {
GST_WARNING_OBJECT (dbin, "Couldn't add %s to the bin",
GST_ELEMENT_NAME (element));
remove_error_filter (dbin, element, NULL);
g_string_append_printf (error_details, "Couldn't add %s to the bin\n",
GST_ELEMENT_NAME (element));
gst_object_unref (element);
continue;
}
/* Find its sink pad. */
if (!(sinkpad = find_sink_pad (element))) {
GST_WARNING_OBJECT (dbin, "Element %s doesn't have a sink pad",
GST_ELEMENT_NAME (element));
remove_error_filter (dbin, element, NULL);
g_string_append_printf (error_details,
"Element %s doesn't have a sink pad", GST_ELEMENT_NAME (element));
gst_bin_remove (GST_BIN (dbin), element);
continue;
}
/* ... and try to link */
if ((gst_pad_link_full (pad, sinkpad,
GST_PAD_LINK_CHECK_NOTHING)) != GST_PAD_LINK_OK) {
GST_WARNING_OBJECT (dbin, "Link failed on pad %s:%s",
GST_DEBUG_PAD_NAME (sinkpad));
remove_error_filter (dbin, element, NULL);
g_string_append_printf (error_details, "Link failed on pad %s:%s",
GST_DEBUG_PAD_NAME (sinkpad));
gst_object_unref (sinkpad);
gst_bin_remove (GST_BIN (dbin), element);
continue;
}
/* ... activate it ... */
if ((gst_element_set_state (element,
GST_STATE_READY)) == GST_STATE_CHANGE_FAILURE) {
GstMessage *error_msg;
GST_WARNING_OBJECT (dbin, "Couldn't set %s to READY",
GST_ELEMENT_NAME (element));
remove_error_filter (dbin, element, &error_msg);
if (error_msg) {
gchar *error_string = error_message_to_string (error_msg);
g_string_append_printf (error_details, "Couldn't set %s to READY:\n%s",
GST_ELEMENT_NAME (element), error_string);
gst_message_unref (error_msg);
g_free (error_string);
} else {
g_string_append_printf (error_details, "Couldn't set %s to READY",
GST_ELEMENT_NAME (element));
}
gst_object_unref (sinkpad);
gst_bin_remove (GST_BIN (dbin), element);
continue;
}
/* check if we still accept the caps on the pad after setting
* the element to READY */
if (!gst_pad_query_accept_caps (sinkpad, caps)) {
GstMessage *error_msg;
GST_WARNING_OBJECT (dbin, "Element %s does not accept caps",
GST_ELEMENT_NAME (element));
remove_error_filter (dbin, element, &error_msg);
if (error_msg) {
gchar *error_string = error_message_to_string (error_msg);
g_string_append_printf (error_details,
"Element %s does not accept caps:\n%s", GST_ELEMENT_NAME (element),
error_string);
gst_message_unref (error_msg);
g_free (error_string);
} else {
g_string_append_printf (error_details,
"Element %s does not accept caps", GST_ELEMENT_NAME (element));
}
gst_element_set_state (element, GST_STATE_NULL);
gst_object_unref (sinkpad);
gst_bin_remove (GST_BIN (dbin), element);
continue;
}
gst_object_unref (sinkpad);
GST_LOG_OBJECT (dbin, "linked on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
CHAIN_MUTEX_LOCK (chain);
delem = g_slice_new0 (GstDecodeElement);
delem->element = gst_object_ref (element);
delem->capsfilter = NULL;
chain->elements = g_list_prepend (chain->elements, delem);
chain->demuxer = is_demuxer_element (element);
chain->adaptive_demuxer = is_adaptive_demuxer_element (element);
is_decoder = strstr (gst_element_factory_get_metadata (factory,
GST_ELEMENT_METADATA_KLASS), "Decoder") != NULL;
/* For adaptive streaming demuxer we insert a multiqueue after
* this demuxer.
* Now for the case where we have a container stream inside these
* buffers, another demuxer will be plugged and after this second
* demuxer there will be a second multiqueue. This second multiqueue
* will get smaller buffers and will be the one emitting buffering
* messages.
* If we don't have a container stream inside the fragment buffers,
* we'll insert a multiqueue below right after the next element after
* the adaptive streaming demuxer. This is going to be a parser or
* decoder, and will output smaller buffers.
*/
if (chain->parent && chain->parent->parent) {
GstDecodeChain *parent_chain = chain->parent->parent;
if (parent_chain->adaptive_demuxer && (is_parser || is_decoder))
chain->demuxer = TRUE;
}
/* If we are configured to use buffering and there is no demuxer in the
* chain, we still want a multiqueue, otherwise we will ignore the
* use-buffering property. In that case, we will insert a multiqueue after
* the parser or decoder - not elsewhere, otherwise we won't have
* timestamps.
*/
if (!chain->parent && (is_parser || is_decoder) && dbin->use_buffering) {
chain->demuxer = TRUE;
if (is_decoder) {
GST_WARNING_OBJECT (dbin,
"Buffering messages used for decoded and non-parsed data");
}
}
CHAIN_MUTEX_UNLOCK (chain);
/* Set connection-speed property if needed */
if (chain->demuxer) {
GParamSpec *pspec;
if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element),
"connection-speed"))) {
guint64 speed = dbin->connection_speed / 1000;
gboolean wrong_type = FALSE;
if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_UINT) {
GParamSpecUInt *pspecuint = G_PARAM_SPEC_UINT (pspec);
speed = CLAMP (speed, pspecuint->minimum, pspecuint->maximum);
} else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT) {
GParamSpecInt *pspecint = G_PARAM_SPEC_INT (pspec);
speed = CLAMP (speed, pspecint->minimum, pspecint->maximum);
} else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_UINT64) {
GParamSpecUInt64 *pspecuint = G_PARAM_SPEC_UINT64 (pspec);
speed = CLAMP (speed, pspecuint->minimum, pspecuint->maximum);
} else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT64) {
GParamSpecInt64 *pspecint = G_PARAM_SPEC_INT64 (pspec);
speed = CLAMP (speed, pspecint->minimum, pspecint->maximum);
} else {
GST_WARNING_OBJECT (dbin,
"The connection speed property %" G_GUINT64_FORMAT " of type %s"
" is not usefull not setting it", speed,
g_type_name (G_PARAM_SPEC_TYPE (pspec)));
wrong_type = TRUE;
}
if (!wrong_type) {
GST_DEBUG_OBJECT (dbin, "setting connection-speed=%" G_GUINT64_FORMAT
" to demuxer element", speed);
g_object_set (element, "connection-speed", speed, NULL);
}
}
}
/* try to configure the subtitle encoding property when we can */
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element),
"subtitle-encoding");
if (pspec && G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_STRING) {
SUBTITLE_LOCK (dbin);
GST_DEBUG_OBJECT (dbin,
"setting subtitle-encoding=%s to element", dbin->encoding);
g_object_set (G_OBJECT (element), "subtitle-encoding", dbin->encoding,
NULL);
SUBTITLE_UNLOCK (dbin);
subtitle = TRUE;
} else {
subtitle = FALSE;
}
/* link this element further */
to_connect = connect_element (dbin, delem, chain);
while (to_connect) {
GstPad *opad = to_connect->data;
gboolean expose_pad = FALSE;
GstDecodeChain *new_chain;
GstCaps *ocaps;
ocaps = get_pad_caps (opad);
expose_pad =
analyze_new_pad (dbin, delem->element, opad, ocaps, chain,
&new_chain);
if (ocaps)
gst_caps_unref (ocaps);
if (expose_pad) {
PadExposeData *expose_data = g_new0 (PadExposeData, 1);
expose_data->chain = new_chain;
expose_data->pad = gst_object_ref (opad);
to_expose = g_list_prepend (to_expose, expose_data);
}
gst_object_unref (opad);
to_connect = g_list_delete_link (to_connect, to_connect);
}
/* any pads left in to_expose are to be exposed */
/* Bring the element to the state of the parent */
/* First lock element's sinkpad stream lock so no data reaches
* the possible new element added when caps are sent by element
* while we're still sending sticky events */
GST_PAD_STREAM_LOCK (sinkpad);
if ((gst_element_set_state (element,
GST_STATE_PAUSED)) == GST_STATE_CHANGE_FAILURE ||
!send_sticky_events (dbin, pad)) {
GstDecodeElement *dtmp = NULL;
GstElement *tmp = NULL;
GstMessage *error_msg;
GST_PAD_STREAM_UNLOCK (sinkpad);
GST_WARNING_OBJECT (dbin, "Couldn't set %s to PAUSED",
GST_ELEMENT_NAME (element));
while (to_expose) {
PadExposeData *expose_data = to_expose->data;
gst_object_unref (expose_data->pad);
g_free (expose_data);
to_expose = g_list_delete_link (to_expose, to_expose);
}
remove_error_filter (dbin, element, &error_msg);
if (error_msg) {
gchar *error_string = error_message_to_string (error_msg);
g_string_append_printf (error_details, "Couldn't set %s to PAUSED:\n%s",
GST_ELEMENT_NAME (element), error_string);
gst_message_unref (error_msg);
g_free (error_string);
} else {
g_string_append_printf (error_details, "Couldn't set %s to PAUSED",
GST_ELEMENT_NAME (element));
}
/* Remove all elements in this chain that were just added. No
* other thread could've added elements in the meantime */
CHAIN_MUTEX_LOCK (chain);
do {
GList *l;
dtmp = chain->elements->data;
tmp = dtmp->element;
/* Disconnect any signal handlers that might be connected
* in connect_element() or analyze_pad() */
if (dtmp->pad_added_id)
g_signal_handler_disconnect (tmp, dtmp->pad_added_id);
if (dtmp->pad_removed_id)
g_signal_handler_disconnect (tmp, dtmp->pad_removed_id);
if (dtmp->no_more_pads_id)
g_signal_handler_disconnect (tmp, dtmp->no_more_pads_id);
for (l = chain->pending_pads; l;) {
GstPendingPad *pp = l->data;
GList *n;
if (GST_PAD_PARENT (pp->pad) != tmp) {
l = l->next;
continue;
}
gst_pending_pad_free (pp);
/* Remove element from the list, update list head and go to the
* next element in the list */
n = l->next;
chain->pending_pads = g_list_delete_link (chain->pending_pads, l);
l = n;
}
if (dtmp->capsfilter) {
gst_bin_remove (GST_BIN (dbin), dtmp->capsfilter);
gst_element_set_state (dtmp->capsfilter, GST_STATE_NULL);
gst_object_unref (dtmp->capsfilter);
}
gst_bin_remove (GST_BIN (dbin), tmp);
gst_element_set_state (tmp, GST_STATE_NULL);
gst_object_unref (tmp);
g_slice_free (GstDecodeElement, dtmp);
chain->elements = g_list_delete_link (chain->elements, chain->elements);
} while (tmp != element);
CHAIN_MUTEX_UNLOCK (chain);
continue;
} else {
/* Everything went well, the spice must flow now */
GST_PAD_STREAM_UNLOCK (sinkpad);
}
/* Remove error filter now, from now on we can't gracefully
* handle errors of the element anymore */
remove_error_filter (dbin, element, NULL);
/* Now let the bin handle the state */
gst_element_set_locked_state (element, FALSE);
if (subtitle) {
SUBTITLE_LOCK (dbin);
/* we added the element now, add it to the list of subtitle-encoding
* elements when we can set the property */
dbin->subtitles = g_list_prepend (dbin->subtitles, element);
SUBTITLE_UNLOCK (dbin);
}
while (to_expose) {
PadExposeData *expose_data = to_expose->data;
GstCaps *ocaps;
ocaps = get_pad_caps (expose_data->pad);
expose_pad (dbin, delem->element, expose_data->chain->current_pad,
expose_data->pad, ocaps, expose_data->chain);
if (ocaps)
gst_caps_unref (ocaps);
gst_object_unref (expose_data->pad);
g_free (expose_data);
to_expose = g_list_delete_link (to_expose, to_expose);
}
res = TRUE;
break;
}
beach:
if (mqpad)
gst_object_unref (mqpad);
if (error_details)
*deadend_details = g_string_free (error_details, (error_details->len == 0
|| res));
else
*deadend_details = NULL;
return res;
}
static GstCaps *
get_pad_caps (GstPad * pad)
{
GstCaps *caps;
/* first check the pad caps, if this is set, we are positively sure it is
* fixed and exactly what the element will produce. */
caps = gst_pad_get_current_caps (pad);
/* then use the getcaps function if we don't have caps. These caps might not
* be fixed in some cases, in which case analyze_new_pad will set up a
* notify::caps signal to continue autoplugging. */
if (caps == NULL)
caps = gst_pad_query_caps (pad, NULL);
return caps;
}
/* Returns a list of pads that can be connected to already and
* connects to pad-added and related signals */
static GList *
connect_element (GstDecodeBin * dbin, GstDecodeElement * delem,
GstDecodeChain * chain)
{
GstElement *element = delem->element;
GList *pads;
gboolean dynamic = FALSE;
GList *to_connect = NULL;
GST_DEBUG_OBJECT (dbin, "Attempting to connect element %s [chain:%p] further",
GST_ELEMENT_NAME (element), chain);
/* 1. Loop over pad templates, grabbing existing pads along the way */
for (pads = GST_ELEMENT_GET_CLASS (element)->padtemplates; pads;
pads = g_list_next (pads)) {
GstPadTemplate *templ = GST_PAD_TEMPLATE (pads->data);
const gchar *templ_name;
/* we are only interested in source pads */
if (GST_PAD_TEMPLATE_DIRECTION (templ) != GST_PAD_SRC)
continue;
templ_name = GST_PAD_TEMPLATE_NAME_TEMPLATE (templ);
GST_DEBUG_OBJECT (dbin, "got a source pad template %s", templ_name);
/* figure out what kind of pad this is */
switch (GST_PAD_TEMPLATE_PRESENCE (templ)) {
case GST_PAD_ALWAYS:
{
/* get the pad that we need to autoplug */
GstPad *pad = gst_element_get_static_pad (element, templ_name);
if (pad) {
GST_DEBUG_OBJECT (dbin, "got the pad for always template %s",
templ_name);
/* here is the pad, we need to autoplug it */
to_connect = g_list_prepend (to_connect, pad);
} else {
/* strange, pad is marked as always but it's not
* there. Fix the element */
GST_WARNING_OBJECT (dbin,
"could not get the pad for always template %s", templ_name);
}
break;
}
case GST_PAD_SOMETIMES:
{
/* try to get the pad to see if it is already created or
* not */
GstPad *pad = gst_element_get_static_pad (element, templ_name);
if (pad) {
GST_DEBUG_OBJECT (dbin, "got the pad for sometimes template %s",
templ_name);
/* the pad is created, we need to autoplug it */
to_connect = g_list_prepend (to_connect, pad);
} else {
GST_DEBUG_OBJECT (dbin,
"did not get the sometimes pad of template %s", templ_name);
/* we have an element that will create dynamic pads */
dynamic = TRUE;
}
break;
}
case GST_PAD_REQUEST:
/* ignore request pads */
GST_DEBUG_OBJECT (dbin, "ignoring request padtemplate %s", templ_name);
break;
}
}
/* 2. if there are more potential pads, connect to relevant signals */
if (dynamic) {
GST_LOG_OBJECT (dbin, "Adding signals to element %s in chain %p",
GST_ELEMENT_NAME (element), chain);
delem->pad_added_id = g_signal_connect (element, "pad-added",
G_CALLBACK (pad_added_cb), chain);
delem->pad_removed_id = g_signal_connect (element, "pad-removed",
G_CALLBACK (pad_removed_cb), chain);
delem->no_more_pads_id = g_signal_connect (element, "no-more-pads",
G_CALLBACK (no_more_pads_cb), chain);
}
/* 3. return all pads that can be connected to already */
return to_connect;
}
/* expose_pad:
*
* Expose the given pad on the chain as a decoded pad.
*/
static void
expose_pad (GstDecodeBin * dbin, GstElement * src, GstDecodePad * dpad,
GstPad * pad, GstCaps * caps, GstDecodeChain * chain)
{
GstPad *mqpad = NULL;
GST_DEBUG_OBJECT (dbin, "pad %s:%s, chain:%p",
GST_DEBUG_PAD_NAME (pad), chain);
/* If this is the first pad for this chain, there are no other elements
* and the source element is not the multiqueue we must link through the
* multiqueue.
*
* This is the case if a demuxer directly exposed a raw pad.
*/
if (chain->parent && !chain->elements && src != chain->parent->multiqueue) {
GST_LOG_OBJECT (src, "connecting the pad through multiqueue");
decode_pad_set_target (dpad, NULL);
if (!(mqpad = gst_decode_group_control_demuxer_pad (chain->parent, pad)))
goto beach;
pad = mqpad;
decode_pad_set_target (dpad, pad);
}
gst_decode_pad_activate (dpad, chain);
chain->endpad = gst_object_ref (dpad);
chain->endcaps = gst_caps_ref (caps);
EXPOSE_LOCK (dbin);
if (dbin->decode_chain) {
if (gst_decode_chain_is_complete (dbin->decode_chain)) {
gst_decode_bin_expose (dbin);
}
}
EXPOSE_UNLOCK (dbin);
if (mqpad)
gst_object_unref (mqpad);
beach:
return;
}
/* check_upstream_seekable:
*
* Check if upstream is seekable.
*/
static gboolean
check_upstream_seekable (GstDecodeBin * dbin, GstPad * pad)
{
GstQuery *query;
gint64 start = -1, stop = -1;
gboolean seekable = FALSE;
query = gst_query_new_seeking (GST_FORMAT_BYTES);
if (!gst_pad_peer_query (pad, query)) {
GST_DEBUG_OBJECT (dbin, "seeking query failed");
goto done;
}
gst_query_parse_seeking (query, NULL, &seekable, &start, &stop);
/* try harder to query upstream size if we didn't get it the first time */
if (seekable && stop == -1) {
GST_DEBUG_OBJECT (dbin, "doing duration query to fix up unset stop");
gst_pad_peer_query_duration (pad, GST_FORMAT_BYTES, &stop);
}
/* if upstream doesn't know the size, it's likely that it's not seekable in
* practice even if it technically may be seekable */
if (seekable && (start != 0 || stop <= start)) {
GST_DEBUG_OBJECT (dbin, "seekable but unknown start/stop -> disable");
seekable = FALSE;
} else {
GST_DEBUG_OBJECT (dbin, "upstream seekable: %d", seekable);
}
done:
gst_query_unref (query);
return seekable;
}
static void
type_found (GstElement * typefind, guint probability,
GstCaps * caps, GstDecodeBin * decode_bin)
{
GstPad *pad, *sink_pad;
GstDecodeChain *chain;
GST_DEBUG_OBJECT (decode_bin, "typefind found caps %" GST_PTR_FORMAT, caps);
/* If the typefinder (but not something else) finds text/plain - i.e. that's
* the top-level type of the file - then error out.
*/
if (gst_structure_has_name (gst_caps_get_structure (caps, 0), "text/plain")) {
GST_ELEMENT_ERROR (decode_bin, STREAM, WRONG_TYPE,
(_("This appears to be a text file")),