gst_plugins_base/gst/playback/gsturidecodebin.c
changeset 16 8e837d1bf446
parent 0 0e761a78d257
child 30 7e817e7e631c
equal deleted inserted replaced
15:4b0c6ed43234 16:8e837d1bf446
    17  * Boston, MA 02111-1307, USA.
    17  * Boston, MA 02111-1307, USA.
    18  */
    18  */
    19 
    19 
    20 /**
    20 /**
    21  * SECTION:element-uridecodebin
    21  * SECTION:element-uridecodebin
    22  * @short_description: decoder for an uri
       
    23  *
    22  *
    24  * Decodes data from a URI into raw media.
    23  * Decodes data from a URI into raw media.
    25  */
    24  */
    26 
    25 
    27 #ifdef HAVE_CONFIG_H
    26 #ifdef HAVE_CONFIG_H
    31 #include <string.h>
    30 #include <string.h>
    32 
    31 
    33 #include <gst/gst.h>
    32 #include <gst/gst.h>
    34 #include <gst/gst-i18n-plugin.h>
    33 #include <gst/gst-i18n-plugin.h>
    35 
    34 
       
    35 #include "gstfactorylists.h"
    36 #include "gstplay-marshal.h"
    36 #include "gstplay-marshal.h"
    37 #include "gstplay-enum.h"
    37 #include "gstplay-enum.h"
    38 
    38 
    39 #ifdef __SYMBIAN32__
       
    40 #include <glib_global.h>
       
    41 #endif
       
    42 #define GST_TYPE_URI_DECODE_BIN \
    39 #define GST_TYPE_URI_DECODE_BIN \
    43   (gst_uri_decode_bin_get_type())
    40   (gst_uri_decode_bin_get_type())
    44 #define GST_URI_DECODE_BIN(obj) \
    41 #define GST_URI_DECODE_BIN(obj) \
    45   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_URI_DECODE_BIN,GstURIDecodeBin))
    42   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_URI_DECODE_BIN,GstURIDecodeBin))
    46 #define GST_URI_DECODE_BIN_CLASS(klass) \
    43 #define GST_URI_DECODE_BIN_CLASS(klass) \
    47   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_URI_DECODE_BIN,GstURIDecodeBinClass))
    44   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_URI_DECODE_BIN,GstURIDecodeBinClass))
    48 #define GST_IS_URI_DECODE_BIN(obj) \
    45 #define GST_IS_URI_DECODE_BIN(obj) \
    49   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_URI_DECODE_BIN))
    46   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_URI_DECODE_BIN))
    50 #define GST_IS_URI_DECODE_BIN_CLASS(klass) \
    47 #define GST_IS_URI_DECODE_BIN_CLASS(klass) \
    51   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_URI_DECODE_BIN))
    48   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_URI_DECODE_BIN))
       
    49 #define GST_URI_DECODE_BIN_CAST(obj) ((GstURIDecodeBin *) (obj))
    52 
    50 
    53 typedef struct _GstURIDecodeBin GstURIDecodeBin;
    51 typedef struct _GstURIDecodeBin GstURIDecodeBin;
    54 typedef struct _GstURIDecodeBinClass GstURIDecodeBinClass;
    52 typedef struct _GstURIDecodeBinClass GstURIDecodeBinClass;
    55 
    53 
       
    54 #define GST_URI_DECODE_BIN_GET_LOCK(dec) (((GstURIDecodeBin*)(dec))->lock)
       
    55 #define GST_URI_DECODE_BIN_LOCK(dec) (g_mutex_lock(GST_URI_DECODE_BIN_GET_LOCK(dec)))
       
    56 #define GST_URI_DECODE_BIN_UNLOCK(dec) (g_mutex_unlock(GST_URI_DECODE_BIN_GET_LOCK(dec)))
       
    57 
       
    58 /**
       
    59  * GstURIDecodeBin
       
    60  *
       
    61  * uridecodebin element struct
       
    62  */
    56 struct _GstURIDecodeBin
    63 struct _GstURIDecodeBin
    57 {
    64 {
    58   GstBin parent_instance;
    65   GstBin parent_instance;
       
    66 
       
    67   GMutex *lock;                 /* lock for constructing */
       
    68 
       
    69   GValueArray *factories;       /* factories we can use for selecting elements */
    59 
    70 
    60   gchar *uri;
    71   gchar *uri;
    61   guint connection_speed;
    72   guint connection_speed;
    62   GstCaps *caps;
    73   GstCaps *caps;
    63   gchar *encoding;
    74   gchar *encoding;
    64 
    75 
    65   gboolean is_stream;
    76   gboolean is_stream;
       
    77   gboolean need_queue;
       
    78   guint64 buffer_duration;      /* When streaming, buffer duration (ns) */
       
    79   guint buffer_size;            /* When streaming, buffer size (bytes) */
       
    80   gboolean download;
       
    81 
    66   GstElement *source;
    82   GstElement *source;
    67   GstElement *queue;
    83   GstElement *typefind;
    68   GSList *decoders;
    84   guint have_type_id;           /* have-type signal id from typefind */
       
    85   GSList *decodebins;
    69   GSList *srcpads;
    86   GSList *srcpads;
    70   gint numpads;
    87   gint numpads;
    71 
    88 
    72   /* for dynamic sources */
    89   /* for dynamic sources */
    73   guint src_np_sig_id;          /* new-pad signal id */
    90   guint src_np_sig_id;          /* new-pad signal id */
    74   guint src_nmp_sig_id;         /* no-more-pads signal id */
    91   guint src_nmp_sig_id;         /* no-more-pads signal id */
    75   gint pending;
    92   gint pending;
       
    93 
       
    94   gboolean async_pending;       /* async-start has been emited */
    76 };
    95 };
    77 
    96 
    78 struct _GstURIDecodeBinClass
    97 struct _GstURIDecodeBinClass
    79 {
    98 {
    80   GstBinClass parent_class;
    99   GstBinClass parent_class;
   121   LAST_SIGNAL
   140   LAST_SIGNAL
   122 };
   141 };
   123 
   142 
   124 /* properties */
   143 /* properties */
   125 #define DEFAULT_PROP_URI	    NULL
   144 #define DEFAULT_PROP_URI	    NULL
       
   145 #define DEFAULT_PROP_SOURCE	    NULL
   126 #define DEFAULT_CONNECTION_SPEED    0
   146 #define DEFAULT_CONNECTION_SPEED    0
   127 #define DEFAULT_CAPS                NULL
   147 #define DEFAULT_CAPS                NULL
   128 #define DEFAULT_SUBTITLE_ENCODING   NULL
   148 #define DEFAULT_SUBTITLE_ENCODING   NULL
       
   149 #define DEFAULT_BUFFER_DURATION     -1
       
   150 #define DEFAULT_BUFFER_SIZE         -1
       
   151 #define DEFAULT_DOWNLOAD            FALSE
   129 
   152 
   130 enum
   153 enum
   131 {
   154 {
   132   PROP_0,
   155   PROP_0,
   133   PROP_URI,
   156   PROP_URI,
       
   157   PROP_SOURCE,
   134   PROP_CONNECTION_SPEED,
   158   PROP_CONNECTION_SPEED,
   135   PROP_CAPS,
   159   PROP_CAPS,
   136   PROP_SUBTITLE_ENCODING,
   160   PROP_SUBTITLE_ENCODING,
       
   161   PROP_BUFFER_SIZE,
       
   162   PROP_BUFFER_DURATION,
       
   163   PROP_DOWNLOAD,
   137   PROP_LAST
   164   PROP_LAST
   138 };
   165 };
   139 
   166 
   140 static guint gst_uri_decode_bin_signals[LAST_SIGNAL] = { 0 };
   167 static guint gst_uri_decode_bin_signals[LAST_SIGNAL] = { 0 };
   141 
   168 
   210 {
   237 {
   211   /* by default we always continue */
   238   /* by default we always continue */
   212   return TRUE;
   239   return TRUE;
   213 }
   240 }
   214 
   241 
       
   242 static GValueArray *
       
   243 gst_uri_decode_bin_autoplug_factories (GstElement * element, GstPad * pad,
       
   244     GstCaps * caps)
       
   245 {
       
   246   GValueArray *result;
       
   247 
       
   248   GST_DEBUG_OBJECT (element, "finding factories");
       
   249 
       
   250   /* return all compatible factories for caps */
       
   251   result =
       
   252       gst_factory_list_filter (GST_URI_DECODE_BIN_CAST (element)->factories,
       
   253       caps);
       
   254 
       
   255   GST_DEBUG_OBJECT (element, "autoplug-factories returns %p", result);
       
   256 
       
   257   return result;
       
   258 }
       
   259 
       
   260 
   215 static void
   261 static void
   216 gst_uri_decode_bin_class_init (GstURIDecodeBinClass * klass)
   262 gst_uri_decode_bin_class_init (GstURIDecodeBinClass * klass)
   217 {
   263 {
   218   GObjectClass *gobject_class;
   264   GObjectClass *gobject_class;
   219   GstElementClass *gstelement_class;
   265   GstElementClass *gstelement_class;
   227   gobject_class->get_property = gst_uri_decode_bin_get_property;
   273   gobject_class->get_property = gst_uri_decode_bin_get_property;
   228   gobject_class->finalize = gst_uri_decode_bin_finalize;
   274   gobject_class->finalize = gst_uri_decode_bin_finalize;
   229 
   275 
   230   g_object_class_install_property (gobject_class, PROP_URI,
   276   g_object_class_install_property (gobject_class, PROP_URI,
   231       g_param_spec_string ("uri", "URI", "URI to decode",
   277       g_param_spec_string ("uri", "URI", "URI to decode",
   232           DEFAULT_PROP_URI, G_PARAM_READWRITE));
   278           DEFAULT_PROP_URI, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
       
   279 
       
   280   g_object_class_install_property (gobject_class, PROP_SOURCE,
       
   281       g_param_spec_object ("source", "Source", "Source object used",
       
   282           GST_TYPE_ELEMENT, G_PARAM_READABLE));
   233 
   283 
   234   g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
   284   g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
   235       g_param_spec_uint ("connection-speed", "Connection Speed",
   285       g_param_spec_uint ("connection-speed", "Connection Speed",
   236           "Network connection speed in kbps (0 = unknown)",
   286           "Network connection speed in kbps (0 = unknown)",
   237           0, G_MAXUINT, DEFAULT_CONNECTION_SPEED, G_PARAM_READWRITE));
   287           0, G_MAXUINT / 1000, DEFAULT_CONNECTION_SPEED,
       
   288           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   238 
   289 
   239   g_object_class_install_property (gobject_class, PROP_CAPS,
   290   g_object_class_install_property (gobject_class, PROP_CAPS,
   240       g_param_spec_boxed ("caps", "Caps",
   291       g_param_spec_boxed ("caps", "Caps",
   241           "The caps on which to stop decoding. (NULL = default)",
   292           "The caps on which to stop decoding. (NULL = default)",
   242           GST_TYPE_CAPS, G_PARAM_READWRITE));
   293           GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   243 
   294 
   244   g_object_class_install_property (gobject_class, PROP_SUBTITLE_ENCODING,
   295   g_object_class_install_property (gobject_class, PROP_SUBTITLE_ENCODING,
   245       g_param_spec_string ("subtitle-encoding", "subtitle encoding",
   296       g_param_spec_string ("subtitle-encoding", "subtitle encoding",
   246           "Encoding to assume if input subtitles are not in UTF-8 encoding. "
   297           "Encoding to assume if input subtitles are not in UTF-8 encoding. "
   247           "If not set, the GST_SUBTITLE_ENCODING environment variable will "
   298           "If not set, the GST_SUBTITLE_ENCODING environment variable will "
   248           "be checked for an encoding to use. If that is not set either, "
   299           "be checked for an encoding to use. If that is not set either, "
   249           "ISO-8859-15 will be assumed.", NULL, G_PARAM_READWRITE));
   300           "ISO-8859-15 will be assumed.", NULL,
       
   301           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
       
   302 
       
   303   g_object_class_install_property (gobject_class, PROP_BUFFER_SIZE,
       
   304       g_param_spec_int ("buffer-size", "Buffer size (bytes)",
       
   305           "Buffer size when buffering network streams",
       
   306           -1, G_MAXINT, DEFAULT_BUFFER_SIZE,
       
   307           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
       
   308   g_object_class_install_property (gobject_class, PROP_BUFFER_DURATION,
       
   309       g_param_spec_int64 ("buffer-duration", "Buffer duration (ns)",
       
   310           "Buffer duration when buffering network streams",
       
   311           -1, G_MAXINT64, DEFAULT_BUFFER_DURATION,
       
   312           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
       
   313 
       
   314   g_object_class_install_property (gobject_class, PROP_DOWNLOAD,
       
   315       g_param_spec_boolean ("download", "Download",
       
   316           "Attempt download buffering when buffering network streams",
       
   317           DEFAULT_DOWNLOAD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   250 
   318 
   251   /**
   319   /**
   252    * GstURIDecodeBin::unknown-type:
   320    * GstURIDecodeBin::unknown-type:
   253    * @pad: the new pad containing caps that cannot be resolved to a 'final' stream type.
   321    * @bin: The uridecodebin
       
   322    * @pad: the new pad containing caps that cannot be resolved to a 'final'
       
   323    * stream type.
   254    * @caps: the #GstCaps of the pad that cannot be resolved.
   324    * @caps: the #GstCaps of the pad that cannot be resolved.
   255    *
   325    *
   256    * This signal is emitted when a pad for which there is no further possible
   326    * This signal is emitted when a pad for which there is no further possible
   257    * decoding is added to the uridecodebin.
   327    * decoding is added to the uridecodebin.
   258    */
   328    */
   259   gst_uri_decode_bin_signals[SIGNAL_UNKNOWN_TYPE] =
   329   gst_uri_decode_bin_signals[SIGNAL_UNKNOWN_TYPE] =
   260       g_signal_new ("unknown-type", G_TYPE_FROM_CLASS (klass),
   330       g_signal_new ("unknown-type", G_TYPE_FROM_CLASS (klass),
   261       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstURIDecodeBinClass, unknown_type),
   331       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstURIDecodeBinClass, unknown_type),
   262       NULL, NULL, gst_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2,
   332       NULL, NULL, gst_marshal_VOID__OBJECT_BOXED, G_TYPE_NONE, 2,
   263       GST_TYPE_PAD, GST_TYPE_CAPS);
   333       GST_TYPE_PAD, GST_TYPE_CAPS);
   264 
   334 
   265   /**
   335   /**
   266    * GstURIDecodeBin::autoplug-continue:
   336    * GstURIDecodeBin::autoplug-continue:
       
   337    * @bin: The uridecodebin
   267    * @pad: The #GstPad.
   338    * @pad: The #GstPad.
   268    * @caps: The #GstCaps found.
   339    * @caps: The #GstCaps found.
   269    *
   340    *
   270    * This signal is emitted whenever uridecodebin finds a new stream. It is
   341    * This signal is emitted whenever uridecodebin finds a new stream. It is
   271    * emitted before looking for any elements that can handle that stream.
   342    * emitted before looking for any elements that can handle that stream.
   277    */
   348    */
   278   gst_uri_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE] =
   349   gst_uri_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE] =
   279       g_signal_new ("autoplug-continue", G_TYPE_FROM_CLASS (klass),
   350       g_signal_new ("autoplug-continue", G_TYPE_FROM_CLASS (klass),
   280       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstURIDecodeBinClass,
   351       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstURIDecodeBinClass,
   281           autoplug_continue), _gst_boolean_accumulator, NULL,
   352           autoplug_continue), _gst_boolean_accumulator, NULL,
   282       gst_play_marshal_BOOLEAN__OBJECT_OBJECT, G_TYPE_BOOLEAN, 2, GST_TYPE_PAD,
   353       gst_play_marshal_BOOLEAN__OBJECT_BOXED, G_TYPE_BOOLEAN, 2, GST_TYPE_PAD,
   283       GST_TYPE_CAPS);
   354       GST_TYPE_CAPS);
   284 
   355 
   285   /**
   356   /**
   286    * GstURIDecodeBin::autoplug-factories:
   357    * GstURIDecodeBin::autoplug-factories:
       
   358    * @bin: The decodebin
   287    * @pad: The #GstPad.
   359    * @pad: The #GstPad.
   288    * @caps: The #GstCaps found.
   360    * @caps: The #GstCaps found.
   289    *
   361    *
   290    * This function is emited when an array of possible factories for @caps on
   362    * This function is emited when an array of possible factories for @caps on
   291    * @pad is needed. Decodebin2 will by default return 
   363    * @pad is needed. Uridecodebin will by default return an array with all
       
   364    * compatible factories, sorted by rank.
       
   365    *
       
   366    * If this function returns NULL, @pad will be exposed as a final caps.
       
   367    *
       
   368    * If this function returns an empty array, the pad will be considered as
       
   369    * having an unhandled type media type.
   292    *
   370    *
   293    * Returns: a #GValueArray* with a list of factories to try. The factories are
   371    * Returns: a #GValueArray* with a list of factories to try. The factories are
   294    * by default tried in the returned order or based on the index returned by
   372    * by default tried in the returned order or based on the index returned by
   295    * "autoplug-select".
   373    * "autoplug-select".
   296    */
   374    */
   297   gst_uri_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES] =
   375   gst_uri_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES] =
   298       g_signal_new ("autoplug-factories", G_TYPE_FROM_CLASS (klass),
   376       g_signal_new ("autoplug-factories", G_TYPE_FROM_CLASS (klass),
   299       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstURIDecodeBinClass,
   377       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstURIDecodeBinClass,
   300           autoplug_factories), _gst_array_accumulator, NULL,
   378           autoplug_factories), _gst_array_accumulator, NULL,
   301       gst_play_marshal_BOXED__OBJECT_OBJECT, G_TYPE_VALUE_ARRAY, 2,
   379       gst_play_marshal_BOXED__OBJECT_BOXED, G_TYPE_VALUE_ARRAY, 2,
   302       GST_TYPE_PAD, GST_TYPE_CAPS);
   380       GST_TYPE_PAD, GST_TYPE_CAPS);
   303 
   381 
   304   /**
   382   /**
   305    * GstURIDecodeBin::autoplug-select:
   383    * GstURIDecodeBin::autoplug-select:
   306    * @pad: The #GstPad.
   384    * @pad: The #GstPad.
   307    * @caps: The #GstCaps.
   385    * @caps: The #GstCaps.
   308    * @factories: A #GValueArray of possible #GstElementFactory to use, sorted by
   386    * @factory: A #GstElementFactory to use
   309    * rank (higher ranks come first).
       
   310    *
   387    *
   311    * This signal is emitted once uridecodebin has found all the possible
   388    * This signal is emitted once uridecodebin has found all the possible
   312    * #GstElementFactory that can be used to handle the given @caps.
   389    * #GstElementFactory that can be used to handle the given @caps. For each of
       
   390    * those factories, this signal is emited.
   313    *
   391    *
   314    * Returns: A #gint indicating what factory index from the @factories array
   392    * The signal handler should return a #GST_TYPE_AUTOPLUG_SELECT_RESULT enum
   315    * that you wish uridecodebin to use for trying to decode the given @caps.
   393    * value indicating what decodebin2 should do next.
   316    * -1 to stop selection of a factory. The default handler always
   394    *
   317    * returns the first possible factory.
   395    * A value of #GST_AUTOPLUG_SELECT_TRY will try to autoplug an element from
       
   396    * @factory.
       
   397    *
       
   398    * A value of #GST_AUTOPLUG_SELECT_EXPOSE will expose @pad without plugging
       
   399    * any element to it.
       
   400    *
       
   401    * A value of #GST_AUTOPLUG_SELECT_SKIP will skip @factory and move to the
       
   402    * next factory.
       
   403    *
       
   404    * Returns: a #GST_TYPE_AUTOPLUG_SELECT_RESULT that indicates the required
       
   405    * operation. The default handler will always return
       
   406    * #GST_AUTOPLUG_SELECT_TRY.
   318    */
   407    */
   319   gst_uri_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT] =
   408   gst_uri_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT] =
   320       g_signal_new ("autoplug-select", G_TYPE_FROM_CLASS (klass),
   409       g_signal_new ("autoplug-select", G_TYPE_FROM_CLASS (klass),
   321       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstURIDecodeBinClass,
   410       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstURIDecodeBinClass,
   322           autoplug_select), _gst_select_accumulator, NULL,
   411           autoplug_select), _gst_select_accumulator, NULL,
   323       gst_play_marshal_ENUM__OBJECT_OBJECT_OBJECT,
   412       gst_play_marshal_ENUM__OBJECT_BOXED_OBJECT,
   324       GST_TYPE_AUTOPLUG_SELECT_RESULT, 3, GST_TYPE_PAD, GST_TYPE_CAPS,
   413       GST_TYPE_AUTOPLUG_SELECT_RESULT, 3, GST_TYPE_PAD, GST_TYPE_CAPS,
   325       GST_TYPE_ELEMENT_FACTORY);
   414       GST_TYPE_ELEMENT_FACTORY);
   326 
   415 
   327   /**
   416   /**
   328    * GstURIDecodeBin::drained:
   417    * GstURIDecodeBin::drained:
   341 
   430 
   342   gstbin_class->handle_message = GST_DEBUG_FUNCPTR (handle_message);
   431   gstbin_class->handle_message = GST_DEBUG_FUNCPTR (handle_message);
   343 
   432 
   344   klass->autoplug_continue =
   433   klass->autoplug_continue =
   345       GST_DEBUG_FUNCPTR (gst_uri_decode_bin_autoplug_continue);
   434       GST_DEBUG_FUNCPTR (gst_uri_decode_bin_autoplug_continue);
       
   435   klass->autoplug_factories =
       
   436       GST_DEBUG_FUNCPTR (gst_uri_decode_bin_autoplug_factories);
   346 }
   437 }
   347 
   438 
   348 static void
   439 static void
   349 gst_uri_decode_bin_init (GstURIDecodeBin * dec, GstURIDecodeBinClass * klass)
   440 gst_uri_decode_bin_init (GstURIDecodeBin * dec, GstURIDecodeBinClass * klass)
   350 {
   441 {
       
   442   /* first filter out the interesting element factories */
       
   443   dec->factories = gst_factory_list_get_elements (GST_FACTORY_LIST_DECODER);
       
   444 
       
   445   dec->lock = g_mutex_new ();
       
   446 
   351   dec->uri = g_strdup (DEFAULT_PROP_URI);
   447   dec->uri = g_strdup (DEFAULT_PROP_URI);
   352   dec->connection_speed = DEFAULT_CONNECTION_SPEED;
   448   dec->connection_speed = DEFAULT_CONNECTION_SPEED;
   353   dec->caps = DEFAULT_CAPS;
   449   dec->caps = DEFAULT_CAPS;
   354   dec->encoding = g_strdup (DEFAULT_SUBTITLE_ENCODING);
   450   dec->encoding = g_strdup (DEFAULT_SUBTITLE_ENCODING);
       
   451 
       
   452   dec->buffer_duration = DEFAULT_BUFFER_DURATION;
       
   453   dec->buffer_size = DEFAULT_BUFFER_SIZE;
       
   454   dec->download = DEFAULT_DOWNLOAD;
   355 }
   455 }
   356 
   456 
   357 static void
   457 static void
   358 gst_uri_decode_bin_finalize (GObject * obj)
   458 gst_uri_decode_bin_finalize (GObject * obj)
   359 {
   459 {
   360   GstURIDecodeBin *dec = GST_URI_DECODE_BIN (obj);
   460   GstURIDecodeBin *dec = GST_URI_DECODE_BIN (obj);
   361 
   461 
       
   462   g_mutex_free (dec->lock);
   362   g_free (dec->uri);
   463   g_free (dec->uri);
   363   g_free (dec->encoding);
   464   g_free (dec->encoding);
       
   465   if (dec->factories)
       
   466     g_value_array_free (dec->factories);
       
   467   if (dec->caps)
       
   468     gst_caps_unref (dec->caps);
   364 
   469 
   365   G_OBJECT_CLASS (parent_class)->finalize (obj);
   470   G_OBJECT_CLASS (parent_class)->finalize (obj);
       
   471 }
       
   472 
       
   473 static void
       
   474 gst_uri_decode_bin_set_encoding (GstURIDecodeBin * dec, const gchar * encoding)
       
   475 {
       
   476   GSList *walk;
       
   477 
       
   478   GST_URI_DECODE_BIN_LOCK (dec);
       
   479 
       
   480   /* set property first */
       
   481   GST_OBJECT_LOCK (dec);
       
   482   g_free (dec->encoding);
       
   483   dec->encoding = g_strdup (encoding);
       
   484   GST_OBJECT_UNLOCK (dec);
       
   485 
       
   486   /* set the property on all decodebins now */
       
   487   for (walk = dec->decodebins; walk; walk = g_slist_next (walk)) {
       
   488     GObject *decodebin = G_OBJECT (walk->data);
       
   489 
       
   490     g_object_set (decodebin, "subtitle-encoding", encoding, NULL);
       
   491   }
       
   492   GST_URI_DECODE_BIN_UNLOCK (dec);
   366 }
   493 }
   367 
   494 
   368 static void
   495 static void
   369 gst_uri_decode_bin_set_property (GObject * object, guint prop_id,
   496 gst_uri_decode_bin_set_property (GObject * object, guint prop_id,
   370     const GValue * value, GParamSpec * pspec)
   497     const GValue * value, GParamSpec * pspec)
   389         gst_caps_unref (dec->caps);
   516         gst_caps_unref (dec->caps);
   390       dec->caps = g_value_dup_boxed (value);
   517       dec->caps = g_value_dup_boxed (value);
   391       GST_OBJECT_UNLOCK (dec);
   518       GST_OBJECT_UNLOCK (dec);
   392       break;
   519       break;
   393     case PROP_SUBTITLE_ENCODING:
   520     case PROP_SUBTITLE_ENCODING:
   394       GST_OBJECT_LOCK (dec);
   521       gst_uri_decode_bin_set_encoding (dec, g_value_get_string (value));
   395       g_free (dec->encoding);
   522       break;
   396       dec->encoding = g_value_dup_string (value);
   523     case PROP_BUFFER_SIZE:
   397       GST_OBJECT_UNLOCK (dec);
   524       dec->buffer_size = g_value_get_int (value);
       
   525       break;
       
   526     case PROP_BUFFER_DURATION:
       
   527       dec->buffer_duration = g_value_get_int64 (value);
       
   528       break;
       
   529     case PROP_DOWNLOAD:
       
   530       dec->download = g_value_get_boolean (value);
   398       break;
   531       break;
   399     default:
   532     default:
   400       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   533       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   401       break;
   534       break;
   402   }
   535   }
   412     case PROP_URI:
   545     case PROP_URI:
   413       GST_OBJECT_LOCK (dec);
   546       GST_OBJECT_LOCK (dec);
   414       g_value_set_string (value, dec->uri);
   547       g_value_set_string (value, dec->uri);
   415       GST_OBJECT_UNLOCK (dec);
   548       GST_OBJECT_UNLOCK (dec);
   416       break;
   549       break;
       
   550     case PROP_SOURCE:
       
   551       GST_OBJECT_LOCK (dec);
       
   552       g_value_set_object (value, dec->source);
       
   553       GST_OBJECT_UNLOCK (dec);
       
   554       break;
   417     case PROP_CONNECTION_SPEED:
   555     case PROP_CONNECTION_SPEED:
   418       GST_OBJECT_LOCK (dec);
   556       GST_OBJECT_LOCK (dec);
   419       g_value_set_uint (value, dec->connection_speed / 1000);
   557       g_value_set_uint (value, dec->connection_speed / 1000);
   420       GST_OBJECT_UNLOCK (dec);
   558       GST_OBJECT_UNLOCK (dec);
   421       break;
   559       break;
   427     case PROP_SUBTITLE_ENCODING:
   565     case PROP_SUBTITLE_ENCODING:
   428       GST_OBJECT_LOCK (dec);
   566       GST_OBJECT_LOCK (dec);
   429       g_value_set_string (value, dec->encoding);
   567       g_value_set_string (value, dec->encoding);
   430       GST_OBJECT_UNLOCK (dec);
   568       GST_OBJECT_UNLOCK (dec);
   431       break;
   569       break;
       
   570     case PROP_BUFFER_SIZE:
       
   571       GST_OBJECT_LOCK (dec);
       
   572       g_value_set_int (value, dec->buffer_size);
       
   573       GST_OBJECT_UNLOCK (dec);
       
   574       break;
       
   575     case PROP_BUFFER_DURATION:
       
   576       GST_OBJECT_LOCK (dec);
       
   577       g_value_set_int64 (value, dec->buffer_duration);
       
   578       GST_OBJECT_UNLOCK (dec);
       
   579       break;
       
   580     case PROP_DOWNLOAD:
       
   581       g_value_set_boolean (value, dec->download);
       
   582       break;
   432     default:
   583     default:
   433       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   584       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   434       break;
   585       break;
       
   586   }
       
   587 }
       
   588 
       
   589 static void
       
   590 do_async_start (GstURIDecodeBin * dbin)
       
   591 {
       
   592   GstMessage *message;
       
   593 
       
   594   dbin->async_pending = TRUE;
       
   595 
       
   596   message = gst_message_new_async_start (GST_OBJECT_CAST (dbin), FALSE);
       
   597   parent_class->handle_message (GST_BIN_CAST (dbin), message);
       
   598 }
       
   599 
       
   600 static void
       
   601 do_async_done (GstURIDecodeBin * dbin)
       
   602 {
       
   603   GstMessage *message;
       
   604 
       
   605   if (dbin->async_pending) {
       
   606     GST_DEBUG_OBJECT (dbin, "posting ASYNC_DONE");
       
   607     message = gst_message_new_async_done (GST_OBJECT_CAST (dbin));
       
   608     parent_class->handle_message (GST_BIN_CAST (dbin), message);
       
   609 
       
   610     dbin->async_pending = FALSE;
   435   }
   611   }
   436 }
   612 }
   437 
   613 
   438 #define DEFAULT_QUEUE_SIZE          (3 * GST_SECOND)
   614 #define DEFAULT_QUEUE_SIZE          (3 * GST_SECOND)
   439 #define DEFAULT_QUEUE_MIN_THRESHOLD ((DEFAULT_QUEUE_SIZE * 30) / 100)
   615 #define DEFAULT_QUEUE_MIN_THRESHOLD ((DEFAULT_QUEUE_SIZE * 30) / 100)
   472   gboolean final;
   648   gboolean final;
   473 
   649 
   474   /* setup phase */
   650   /* setup phase */
   475   GST_DEBUG_OBJECT (element, "no more pads, %d pending", decoder->pending);
   651   GST_DEBUG_OBJECT (element, "no more pads, %d pending", decoder->pending);
   476 
   652 
   477   GST_OBJECT_LOCK (decoder);
   653   GST_URI_DECODE_BIN_LOCK (decoder);
   478   final = (decoder->pending == 0);
   654   final = (decoder->pending == 0);
   479 
   655 
   480   /* nothing pending, we can exit */
   656   /* nothing pending, we can exit */
   481   if (final)
   657   if (final)
   482     goto done;
   658     goto done;
   488 
   664 
   489   decoder->pending--;
   665   decoder->pending--;
   490   final = (decoder->pending == 0);
   666   final = (decoder->pending == 0);
   491 
   667 
   492 done:
   668 done:
   493   GST_OBJECT_UNLOCK (decoder);
   669   GST_URI_DECODE_BIN_UNLOCK (decoder);
   494 
   670 
   495   if (final)
   671   if (final)
   496     gst_element_no_more_pads (GST_ELEMENT_CAST (decoder));
   672     gst_element_no_more_pads (GST_ELEMENT_CAST (decoder));
   497 
   673 
   498   return;
   674   return;
   529   gchar *padname;
   705   gchar *padname;
   530 
   706 
   531   GST_DEBUG_OBJECT (element, "new decoded pad, name: <%s>. Last: %d",
   707   GST_DEBUG_OBJECT (element, "new decoded pad, name: <%s>. Last: %d",
   532       GST_PAD_NAME (pad), last);
   708       GST_PAD_NAME (pad), last);
   533 
   709 
   534   GST_OBJECT_LOCK (decoder);
   710   GST_URI_DECODE_BIN_LOCK (decoder);
   535   padname = g_strdup_printf ("src%d", decoder->numpads);
   711   padname = g_strdup_printf ("src%d", decoder->numpads);
   536   decoder->numpads++;
   712   decoder->numpads++;
   537   GST_OBJECT_UNLOCK (decoder);
   713   GST_URI_DECODE_BIN_UNLOCK (decoder);
   538 
   714 
   539   newpad = gst_ghost_pad_new (padname, pad);
   715   newpad = gst_ghost_pad_new (padname, pad);
   540   g_free (padname);
   716   g_free (padname);
   541 
   717 
   542   /* store ref to the ghostpad so we can remove it */
   718   /* store ref to the ghostpad so we can remove it */
   551 {
   727 {
   552   GstPad *ghost;
   728   GstPad *ghost;
   553 
   729 
   554   GST_DEBUG_OBJECT (element, "pad removed name: <%s:%s>",
   730   GST_DEBUG_OBJECT (element, "pad removed name: <%s:%s>",
   555       GST_DEBUG_PAD_NAME (pad));
   731       GST_DEBUG_PAD_NAME (pad));
       
   732 
       
   733   /* we only care about srcpads */
       
   734   if (!GST_PAD_IS_SRC (pad))
       
   735     return;
   556 
   736 
   557   if (!(ghost = g_object_get_data (G_OBJECT (pad), "uridecodebin.ghostpad")))
   737   if (!(ghost = g_object_get_data (G_OBJECT (pad), "uridecodebin.ghostpad")))
   558     goto no_ghost;
   738     goto no_ghost;
   559 
   739 
   560   /* unghost the pad */
   740   /* unghost the pad */
   585       return TRUE;
   765       return TRUE;
   586   }
   766   }
   587   return FALSE;
   767   return FALSE;
   588 }
   768 }
   589 
   769 
       
   770 static gboolean
       
   771 array_has_uri_value (const gchar * values[], const gchar * value)
       
   772 {
       
   773   gint i;
       
   774 
       
   775   for (i = 0; values[i]; i++) {
       
   776     if (!g_ascii_strncasecmp (value, values[i], strlen (values[i])))
       
   777       return TRUE;
       
   778   }
       
   779   return FALSE;
       
   780 }
       
   781 
   590 /* list of URIs that we consider to be streams and that need buffering.
   782 /* list of URIs that we consider to be streams and that need buffering.
   591  * We have no mechanism yet to figure this out with a query. */
   783  * We have no mechanism yet to figure this out with a query. */
   592 static const gchar *stream_uris[] = { "http://", "mms://", "mmsh://",
   784 static const gchar *stream_uris[] = { "http://", "mms://", "mmsh://",
   593   "mmsu://", "mmst://", NULL
   785   "mmsu://", "mmst://", "fd://", NULL
   594 };
   786 };
       
   787 
       
   788 /* list of URIs that need a queue because they are pretty bursty */
       
   789 static const gchar *queue_uris[] = { "cdda://", NULL };
   595 
   790 
   596 /* blacklisted URIs, we know they will always fail. */
   791 /* blacklisted URIs, we know they will always fail. */
   597 static const gchar *blacklisted_uris[] = { NULL };
   792 static const gchar *blacklisted_uris[] = { NULL };
   598 
   793 
   599 /* mime types that we don't consider to be media types */
   794 /* mime types that we don't consider to be media types */
   602   "application/x-executable", "application/x-bzip", "application/x-gzip",
   797   "application/x-executable", "application/x-bzip", "application/x-gzip",
   603   "application/zip", "application/x-compress", NULL
   798   "application/zip", "application/x-compress", NULL
   604 };
   799 };
   605 #endif
   800 #endif
   606 
   801 
   607 /* mime types we consider raw media */
   802 /* media types we consider raw media */
   608 static const gchar *raw_mimes[] = {
   803 static const gchar *raw_media[] = {
   609   "audio/x-raw", "video/x-raw", NULL
   804   "audio/x-raw", "video/x-raw", "text/plain", "text/x-pango-markup",
       
   805   "video/x-dvd-subpicture", "subpicture/x-", NULL
   610 };
   806 };
   611 
   807 
   612 #define IS_STREAM_URI(uri)          (array_has_value (stream_uris, uri))
   808 /* media types we can download */
   613 #define IS_BLACKLISTED_URI(uri)     (array_has_value (blacklisted_uris, uri))
   809 static const gchar *download_media[] = {
       
   810   "video/quicktime", "video/x-flv", NULL
       
   811 };
       
   812 
       
   813 #define IS_STREAM_URI(uri)          (array_has_uri_value (stream_uris, uri))
       
   814 #define IS_QUEUE_URI(uri)           (array_has_uri_value (queue_uris, uri))
       
   815 #define IS_BLACKLISTED_URI(uri)     (array_has_uri_value (blacklisted_uris, uri))
   614 #define IS_NO_MEDIA_MIME(mime)      (array_has_value (no_media_mimes, mime))
   816 #define IS_NO_MEDIA_MIME(mime)      (array_has_value (no_media_mimes, mime))
   615 #define IS_RAW_MIME(mime)           (array_has_value (raw_mimes, mime))
   817 #define IS_RAW_MEDIA(media)         (array_has_value (raw_media, media))
       
   818 #define IS_DOWNLOAD_MEDIA(media)    (array_has_value (download_media, media))
   616 
   819 
   617 /*
   820 /*
   618  * Generate and configure a source element.
   821  * Generate and configure a source element.
   619  */
   822  */
   620 static GstElement *
   823 static GstElement *
   623   GstElement *source;
   826   GstElement *source;
   624 
   827 
   625   if (!decoder->uri)
   828   if (!decoder->uri)
   626     goto no_uri;
   829     goto no_uri;
   627 
   830 
       
   831   GST_LOG_OBJECT (decoder, "finding source for %s", decoder->uri);
       
   832 
   628   if (!gst_uri_is_valid (decoder->uri))
   833   if (!gst_uri_is_valid (decoder->uri))
   629     goto invalid_uri;
   834     goto invalid_uri;
   630 
   835 
   631   if (IS_BLACKLISTED_URI (decoder->uri))
   836   if (IS_BLACKLISTED_URI (decoder->uri))
   632     goto uri_blacklisted;
   837     goto uri_blacklisted;
   633 
   838 
   634   source = gst_element_make_from_uri (GST_URI_SRC, decoder->uri, "source");
   839   source = gst_element_make_from_uri (GST_URI_SRC, decoder->uri, "source");
   635   if (!source)
   840   if (!source)
   636     goto no_source;
   841     goto no_source;
   637 
   842 
       
   843   GST_LOG_OBJECT (decoder, "found source type %s", G_OBJECT_TYPE_NAME (source));
       
   844 
   638   decoder->is_stream = IS_STREAM_URI (decoder->uri);
   845   decoder->is_stream = IS_STREAM_URI (decoder->uri);
       
   846   GST_LOG_OBJECT (decoder, "source is stream: %d", decoder->is_stream);
       
   847 
       
   848   decoder->need_queue = IS_QUEUE_URI (decoder->uri);
       
   849   GST_LOG_OBJECT (decoder, "source needs queue: %d", decoder->need_queue);
   639 
   850 
   640   /* make HTTP sources send extra headers so we get icecast
   851   /* make HTTP sources send extra headers so we get icecast
   641    * metadata in case the stream is an icecast stream */
   852    * metadata in case the stream is an icecast stream */
   642   if (!strncmp (decoder->uri, "http://", 7) &&
   853   if (!strncmp (decoder->uri, "http://", 7) &&
   643       g_object_class_find_property (G_OBJECT_GET_CLASS (source),
   854       g_object_class_find_property (G_OBJECT_GET_CLASS (source),
   644           "iradio-mode")) {
   855           "iradio-mode")) {
       
   856     GST_LOG_OBJECT (decoder, "configuring iradio-mode");
   645     g_object_set (source, "iradio-mode", TRUE, NULL);
   857     g_object_set (source, "iradio-mode", TRUE, NULL);
   646   }
   858   }
   647 
   859 
   648   if (g_object_class_find_property (G_OBJECT_GET_CLASS (source),
   860   if (g_object_class_find_property (G_OBJECT_GET_CLASS (source),
   649           "connection-speed")) {
   861           "connection-speed")) {
   651         "setting connection-speed=%d to source element",
   863         "setting connection-speed=%d to source element",
   652         decoder->connection_speed / 1000);
   864         decoder->connection_speed / 1000);
   653     g_object_set (source, "connection-speed",
   865     g_object_set (source, "connection-speed",
   654         decoder->connection_speed / 1000, NULL);
   866         decoder->connection_speed / 1000, NULL);
   655   }
   867   }
   656 
   868   if (g_object_class_find_property (G_OBJECT_GET_CLASS (source),
       
   869           "subtitle-encoding")) {
       
   870     GST_DEBUG_OBJECT (decoder,
       
   871         "setting subtitle-encoding=%s to source element", decoder->encoding);
       
   872     g_object_set (G_OBJECT (source), "subtitle-encoding", decoder->encoding,
       
   873         NULL);
       
   874   }
   657   return source;
   875   return source;
   658 
   876 
   659   /* ERRORS */
   877   /* ERRORS */
   660 no_uri:
   878 no_uri:
   661   {
   879   {
   712 
   930 
   713   caps = gst_pad_get_caps (pad);
   931   caps = gst_pad_get_caps (pad);
   714   if (caps == NULL)
   932   if (caps == NULL)
   715     return FALSE;
   933     return FALSE;
   716 
   934 
       
   935   GST_DEBUG_OBJECT (pad, "have caps %" GST_PTR_FORMAT, caps);
       
   936 
   717   capssize = gst_caps_get_size (caps);
   937   capssize = gst_caps_get_size (caps);
   718   /* no caps, skip and move to the next pad */
   938   /* no caps, skip and move to the next pad */
   719   if (capssize == 0 || gst_caps_is_empty (caps) || gst_caps_is_any (caps))
   939   if (capssize == 0 || gst_caps_is_empty (caps) || gst_caps_is_any (caps))
   720     goto done;
   940     goto done;
   721 
   941 
   722   /* count the number of raw formats in the caps */
   942   /* count the number of raw formats in the caps */
   723   for (i = 0; i < capssize; ++i) {
   943   for (i = 0; i < capssize; ++i) {
   724     GstStructure *s;
   944     GstStructure *s;
   725     const gchar *mime_type;
   945     const gchar *media_type;
   726 
   946 
   727     s = gst_caps_get_structure (caps, i);
   947     s = gst_caps_get_structure (caps, i);
   728     mime_type = gst_structure_get_name (s);
   948     media_type = gst_structure_get_name (s);
   729 
   949 
   730     if (IS_RAW_MIME (mime_type))
   950     GST_DEBUG_OBJECT (pad, "check media-type %s", media_type);
       
   951 
       
   952     if (IS_RAW_MEDIA (media_type))
   731       ++num_raw;
   953       ++num_raw;
   732   }
   954   }
   733 
   955 
   734   *all_raw = (num_raw == capssize);
   956   *all_raw = (num_raw == capssize);
   735   res = TRUE;
   957   res = TRUE;
   743  * analyse_source:
   965  * analyse_source:
   744  * @decoder: a #GstURIDecodeBin
   966  * @decoder: a #GstURIDecodeBin
   745  * @is_raw: are all pads raw data
   967  * @is_raw: are all pads raw data
   746  * @have_out: does the source have output
   968  * @have_out: does the source have output
   747  * @is_dynamic: is this a dynamic source
   969  * @is_dynamic: is this a dynamic source
       
   970  * @use_queue: put a queue before raw output pads
   748  *
   971  *
   749  * Check the source of @decoder and collect information about it.
   972  * Check the source of @decoder and collect information about it.
   750  *
   973  *
   751  * @is_raw will be set to TRUE if the source only produces raw pads. When this
   974  * @is_raw will be set to TRUE if the source only produces raw pads. When this
   752  * function returns, all of the raw pad of the source will be added
   975  * function returns, all of the raw pad of the source will be added
   759  *
   982  *
   760  * Returns: FALSE if a fatal error occured while scanning.
   983  * Returns: FALSE if a fatal error occured while scanning.
   761  */
   984  */
   762 static gboolean
   985 static gboolean
   763 analyse_source (GstURIDecodeBin * decoder, gboolean * is_raw,
   986 analyse_source (GstURIDecodeBin * decoder, gboolean * is_raw,
   764     gboolean * have_out, gboolean * is_dynamic)
   987     gboolean * have_out, gboolean * is_dynamic, gboolean use_queue)
   765 {
   988 {
   766   GstIterator *pads_iter;
   989   GstIterator *pads_iter;
   767   gboolean done = FALSE;
   990   gboolean done = FALSE;
   768   gboolean res = TRUE;
   991   gboolean res = TRUE;
   769 
   992 
   792       case GST_ITERATOR_OK:
  1015       case GST_ITERATOR_OK:
   793         /* we now officially have an ouput pad */
  1016         /* we now officially have an ouput pad */
   794         *have_out = TRUE;
  1017         *have_out = TRUE;
   795 
  1018 
   796         /* if FALSE, this pad has no caps and we continue with the next pad. */
  1019         /* if FALSE, this pad has no caps and we continue with the next pad. */
   797         if (!has_all_raw_caps (pad, is_raw))
  1020         if (!has_all_raw_caps (pad, is_raw)) {
       
  1021           gst_object_unref (pad);
   798           break;
  1022           break;
       
  1023         }
   799 
  1024 
   800         /* caps on source pad are all raw, we can add the pad */
  1025         /* caps on source pad are all raw, we can add the pad */
   801         if (*is_raw)
  1026         if (*is_raw) {
   802           new_decoded_pad_cb (decoder->source, pad, FALSE, decoder);
  1027           GstElement *outelem;
       
  1028 
       
  1029           if (use_queue) {
       
  1030             GstPad *sinkpad;
       
  1031 
       
  1032             /* insert a queue element right before the raw pad */
       
  1033             outelem = gst_element_factory_make ("queue2", "queue");
       
  1034             gst_bin_add (GST_BIN_CAST (decoder), outelem);
       
  1035 
       
  1036             sinkpad = gst_element_get_static_pad (outelem, "sink");
       
  1037             gst_pad_link (pad, sinkpad);
       
  1038             gst_object_unref (sinkpad);
       
  1039             gst_object_unref (pad);
       
  1040 
       
  1041             /* get the new raw srcpad */
       
  1042             pad = gst_element_get_static_pad (outelem, "src");
       
  1043           } else {
       
  1044             outelem = decoder->source;
       
  1045           }
       
  1046           new_decoded_pad_cb (outelem, pad, FALSE, decoder);
       
  1047         }
       
  1048         gst_object_unref (pad);
   803         break;
  1049         break;
   804     }
  1050     }
   805   }
  1051   }
   806   gst_iterator_free (pads_iter);
  1052   gst_iterator_free (pads_iter);
   807 
  1053 
   833 static void
  1079 static void
   834 remove_decoders (GstURIDecodeBin * bin)
  1080 remove_decoders (GstURIDecodeBin * bin)
   835 {
  1081 {
   836   GSList *walk;
  1082   GSList *walk;
   837 
  1083 
   838   for (walk = bin->decoders; walk; walk = g_slist_next (walk)) {
  1084   for (walk = bin->decodebins; walk; walk = g_slist_next (walk)) {
   839     GstElement *decoder = GST_ELEMENT_CAST (walk->data);
  1085     GstElement *decoder = GST_ELEMENT_CAST (walk->data);
   840 
  1086 
   841     GST_DEBUG_OBJECT (bin, "removing old decoder element");
  1087     GST_DEBUG_OBJECT (bin, "removing old decoder element");
   842     gst_element_set_state (decoder, GST_STATE_NULL);
  1088     gst_element_set_state (decoder, GST_STATE_NULL);
   843     gst_bin_remove (GST_BIN_CAST (bin), decoder);
  1089     gst_bin_remove (GST_BIN_CAST (bin), decoder);
   844   }
  1090   }
   845   g_slist_free (bin->decoders);
  1091   g_slist_free (bin->decodebins);
   846   bin->decoders = NULL;
  1092   bin->decodebins = NULL;
   847 }
  1093 }
   848 
  1094 
   849 static void
  1095 static void
   850 remove_pads (GstURIDecodeBin * bin)
  1096 remove_pads (GstURIDecodeBin * bin)
   851 {
  1097 {
   889 
  1135 
   890 static GValueArray *
  1136 static GValueArray *
   891 proxy_autoplug_factories_signal (GstElement * element, GstPad * pad,
  1137 proxy_autoplug_factories_signal (GstElement * element, GstPad * pad,
   892     GstCaps * caps, GstURIDecodeBin * dec)
  1138     GstCaps * caps, GstURIDecodeBin * dec)
   893 {
  1139 {
   894   GValueArray *result = NULL;
  1140   GValueArray *result;
   895 
  1141 
   896   g_signal_emit (G_OBJECT (dec),
  1142   g_signal_emit (G_OBJECT (dec),
   897       gst_uri_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES], 0, pad, caps,
  1143       gst_uri_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES], 0, pad, caps,
   898       &result);
  1144       &result);
   899 
  1145 
   924 
  1170 
   925   g_signal_emit (G_OBJECT (dec),
  1171   g_signal_emit (G_OBJECT (dec),
   926       gst_uri_decode_bin_signals[SIGNAL_DRAINED], 0, NULL);
  1172       gst_uri_decode_bin_signals[SIGNAL_DRAINED], 0, NULL);
   927 }
  1173 }
   928 
  1174 
       
  1175 /* make a decodebin and connect to all the signals */
   929 static GstElement *
  1176 static GstElement *
   930 make_decoder (GstURIDecodeBin * decoder, gboolean use_queue)
  1177 make_decoder (GstURIDecodeBin * decoder)
   931 {
  1178 {
   932   GstElement *result, *decodebin;
  1179   GstElement *decodebin;
       
  1180 
       
  1181   GST_LOG_OBJECT (decoder, "making new decodebin2");
   933 
  1182 
   934   /* now create the decoder element */
  1183   /* now create the decoder element */
   935   decodebin = gst_element_factory_make ("decodebin2", NULL);
  1184   decodebin = gst_element_factory_make ("decodebin2", NULL);
   936   if (!decodebin)
  1185   if (!decodebin)
   937     goto no_decodebin;
  1186     goto no_decodebin;
       
  1187 
       
  1188   /* configure caps if we have any */
       
  1189   if (decoder->caps)
       
  1190     g_object_set (decodebin, "caps", decoder->caps, NULL);
   938 
  1191 
   939   /* connect signals to proxy */
  1192   /* connect signals to proxy */
   940   g_signal_connect (G_OBJECT (decodebin), "unknown-type",
  1193   g_signal_connect (G_OBJECT (decodebin), "unknown-type",
   941       G_CALLBACK (proxy_unknown_type_signal), decoder);
  1194       G_CALLBACK (proxy_unknown_type_signal), decoder);
   942   g_signal_connect (G_OBJECT (decodebin), "autoplug-continue",
  1195   g_signal_connect (G_OBJECT (decodebin), "autoplug-continue",
   946   g_signal_connect (G_OBJECT (decodebin), "autoplug-select",
  1199   g_signal_connect (G_OBJECT (decodebin), "autoplug-select",
   947       G_CALLBACK (proxy_autoplug_select_signal), decoder);
  1200       G_CALLBACK (proxy_autoplug_select_signal), decoder);
   948   g_signal_connect (G_OBJECT (decodebin), "drained",
  1201   g_signal_connect (G_OBJECT (decodebin), "drained",
   949       G_CALLBACK (proxy_drained_signal), decoder);
  1202       G_CALLBACK (proxy_drained_signal), decoder);
   950 
  1203 
   951   if (use_queue) {
       
   952     GstElement *queue;
       
   953     GstPad *gpad, *pad;
       
   954 
       
   955     queue = gst_element_factory_make ("queue2", NULL);
       
   956     if (!queue)
       
   957       goto no_queue2;
       
   958 
       
   959     /* configure the queue as a buffering element */
       
   960     g_object_set (G_OBJECT (queue), "use-buffering", TRUE, NULL);
       
   961 
       
   962     result = gst_bin_new ("source-bin");
       
   963 
       
   964     gst_bin_add (GST_BIN_CAST (result), queue);
       
   965     gst_bin_add (GST_BIN_CAST (result), decodebin);
       
   966 
       
   967     gst_element_link (queue, decodebin);
       
   968 
       
   969     pad = gst_element_get_pad (queue, "sink");
       
   970     gpad = gst_ghost_pad_new (GST_PAD_NAME (pad), pad);
       
   971     gst_object_unref (pad);
       
   972 
       
   973     gst_pad_set_active (gpad, TRUE);
       
   974     gst_element_add_pad (GST_ELEMENT_CAST (result), gpad);
       
   975   } else {
       
   976     result = decodebin;
       
   977   }
       
   978 
       
   979   /* set up callbacks to create the links between decoded data
  1204   /* set up callbacks to create the links between decoded data
   980    * and video/audio/subtitle rendering/output. */
  1205    * and video/audio/subtitle rendering/output. */
   981   g_signal_connect (G_OBJECT (decodebin),
  1206   g_signal_connect (G_OBJECT (decodebin),
   982       "new-decoded-pad", G_CALLBACK (new_decoded_pad_cb), decoder);
  1207       "new-decoded-pad", G_CALLBACK (new_decoded_pad_cb), decoder);
   983   g_signal_connect (G_OBJECT (decodebin),
  1208   g_signal_connect (G_OBJECT (decodebin),
   985   g_signal_connect (G_OBJECT (decodebin), "no-more-pads",
  1210   g_signal_connect (G_OBJECT (decodebin), "no-more-pads",
   986       G_CALLBACK (no_more_pads), decoder);
  1211       G_CALLBACK (no_more_pads), decoder);
   987   g_signal_connect (G_OBJECT (decodebin),
  1212   g_signal_connect (G_OBJECT (decodebin),
   988       "unknown-type", G_CALLBACK (unknown_type_cb), decoder);
  1213       "unknown-type", G_CALLBACK (unknown_type_cb), decoder);
   989   g_object_set_data (G_OBJECT (decodebin), "pending", "1");
  1214   g_object_set_data (G_OBJECT (decodebin), "pending", "1");
       
  1215   g_object_set (G_OBJECT (decodebin), "subtitle-encoding", decoder->encoding,
       
  1216       NULL);
   990   decoder->pending++;
  1217   decoder->pending++;
   991 
  1218   GST_LOG_OBJECT (decoder, "have %d pending dynamic objects", decoder->pending);
   992   gst_bin_add (GST_BIN_CAST (decoder), result);
  1219 
   993 
  1220   gst_bin_add (GST_BIN_CAST (decoder), decodebin);
   994   decoder->decoders = g_slist_prepend (decoder->decoders, result);
  1221 
   995 
  1222   decoder->decodebins = g_slist_prepend (decoder->decodebins, decodebin);
   996   return result;
  1223 
       
  1224   return decodebin;
   997 
  1225 
   998   /* ERRORS */
  1226   /* ERRORS */
   999 no_decodebin:
  1227 no_decodebin:
  1000   {
  1228   {
  1001     GST_ELEMENT_ERROR (decoder, CORE, MISSING_PLUGIN,
  1229     GST_ELEMENT_ERROR (decoder, CORE, MISSING_PLUGIN,
  1002         (_("Could not create \"decodebin2\" element.")), (NULL));
  1230         (_("Could not create \"decodebin2\" element.")), (NULL));
  1003     return NULL;
  1231     return NULL;
  1004   }
  1232   }
       
  1233 }
       
  1234 
       
  1235 static void
       
  1236 type_found (GstElement * typefind, guint probability,
       
  1237     GstCaps * caps, GstURIDecodeBin * decoder)
       
  1238 {
       
  1239   GstElement *dec_elem, *queue;
       
  1240   GstStructure *s;
       
  1241   const gchar *media_type;
       
  1242 
       
  1243   GST_DEBUG_OBJECT (decoder, "typefind found caps %" GST_PTR_FORMAT, caps);
       
  1244 
       
  1245   dec_elem = make_decoder (decoder);
       
  1246   if (!dec_elem)
       
  1247     goto no_decodebin;
       
  1248 
       
  1249   queue = gst_element_factory_make ("queue2", NULL);
       
  1250   if (!queue)
       
  1251     goto no_queue2;
       
  1252 
       
  1253   g_object_set (G_OBJECT (queue), "use-buffering", TRUE, NULL);
       
  1254 
       
  1255   s = gst_caps_get_structure (caps, 0);
       
  1256   media_type = gst_structure_get_name (s);
       
  1257 
       
  1258   GST_DEBUG_OBJECT (decoder, "check media-type %s, %d", media_type,
       
  1259       decoder->download);
       
  1260 
       
  1261   if (IS_DOWNLOAD_MEDIA (media_type) && decoder->download) {
       
  1262     gchar *temp_template, *filename;
       
  1263     const gchar *tmp_dir, *prgname;
       
  1264 
       
  1265     tmp_dir = g_get_tmp_dir ();
       
  1266     prgname = g_get_prgname ();
       
  1267     if (prgname == NULL)
       
  1268       prgname = "GStreamer";
       
  1269 
       
  1270     filename = g_strdup_printf ("%s-XXXXXX", prgname);
       
  1271 
       
  1272     /* build our filename */
       
  1273     temp_template = g_build_filename (tmp_dir, filename, NULL);
       
  1274 
       
  1275     GST_DEBUG_OBJECT (decoder, "enable download buffering in %s (%s, %s, %s)",
       
  1276         temp_template, tmp_dir, prgname, filename);
       
  1277 
       
  1278     /* configure progressive download for selected media types */
       
  1279     g_object_set (G_OBJECT (queue), "temp-template", temp_template, NULL);
       
  1280 
       
  1281     g_free (filename);
       
  1282     g_free (temp_template);
       
  1283   }
       
  1284 
       
  1285   /* Disable max-size-buffers */
       
  1286   g_object_set (G_OBJECT (queue), "max-size-buffers", 0, NULL);
       
  1287 
       
  1288   /* If buffer size or duration are set, set them on the queue2 element */
       
  1289   if (decoder->buffer_size != -1)
       
  1290     g_object_set (G_OBJECT (queue), "max-size-bytes",
       
  1291         decoder->buffer_size, NULL);
       
  1292   if (decoder->buffer_duration != -1)
       
  1293     g_object_set (G_OBJECT (queue), "max-size-time",
       
  1294         decoder->buffer_duration, NULL);
       
  1295 
       
  1296   gst_bin_add (GST_BIN_CAST (decoder), queue);
       
  1297 
       
  1298   if (!gst_element_link_pads (typefind, "src", queue, "sink"))
       
  1299     goto could_not_link;
       
  1300 
       
  1301   /* to force caps on the decodebin element and avoid reparsing stuff by
       
  1302    * typefind. It also avoids a deadlock in the way typefind activates pads in
       
  1303    * the state change */
       
  1304   g_object_set (G_OBJECT (dec_elem), "sink-caps", caps, NULL);
       
  1305 
       
  1306   if (!gst_element_link_pads (queue, "src", dec_elem, "sink"))
       
  1307     goto could_not_link;
       
  1308 
       
  1309   gst_element_set_state (dec_elem, GST_STATE_PLAYING);
       
  1310   gst_element_set_state (queue, GST_STATE_PLAYING);
       
  1311 
       
  1312   do_async_done (decoder);
       
  1313 
       
  1314   return;
       
  1315 
       
  1316   /* ERRORS */
       
  1317 no_decodebin:
       
  1318   {
       
  1319     /* error was posted */
       
  1320     return;
       
  1321   }
       
  1322 could_not_link:
       
  1323   {
       
  1324     GST_ELEMENT_ERROR (decoder, CORE, NEGOTIATION,
       
  1325         (NULL), ("Can't link typefind to decodebin2 element"));
       
  1326     return;
       
  1327   }
  1005 no_queue2:
  1328 no_queue2:
  1006   {
  1329   {
  1007     GST_ELEMENT_ERROR (decoder, CORE, MISSING_PLUGIN,
  1330     GST_ELEMENT_ERROR (decoder, CORE, MISSING_PLUGIN,
  1008         (_("Could not create \"queue2\" element.")), (NULL));
  1331         (_("Could not create \"queue2\" element.")), (NULL));
  1009     return NULL;
  1332     return;
       
  1333   }
       
  1334 }
       
  1335 
       
  1336 /* setup a streaming source. This will first plug a typefind element to the
       
  1337  * source. After we find the type, we decide to plug a queue2 and continue to
       
  1338  * plug a decodebin2 starting from the found caps */
       
  1339 static gboolean
       
  1340 setup_streaming (GstURIDecodeBin * decoder)
       
  1341 {
       
  1342   GstElement *typefind;
       
  1343 
       
  1344   /* now create the decoder element */
       
  1345   typefind = gst_element_factory_make ("typefind", NULL);
       
  1346   if (!typefind)
       
  1347     goto no_typefind;
       
  1348 
       
  1349   gst_bin_add (GST_BIN_CAST (decoder), typefind);
       
  1350 
       
  1351   if (!gst_element_link (decoder->source, typefind))
       
  1352     goto could_not_link;
       
  1353 
       
  1354   decoder->typefind = typefind;
       
  1355 
       
  1356   /* connect a signal to find out when the typefind element found
       
  1357    * a type */
       
  1358   decoder->have_type_id =
       
  1359       g_signal_connect (G_OBJECT (decoder->typefind), "have-type",
       
  1360       G_CALLBACK (type_found), decoder);
       
  1361 
       
  1362   do_async_start (decoder);
       
  1363 
       
  1364   return TRUE;
       
  1365 
       
  1366   /* ERRORS */
       
  1367 no_typefind:
       
  1368   {
       
  1369     GST_ELEMENT_ERROR (decoder, CORE, MISSING_PLUGIN,
       
  1370         (_("Could not create \"typefind\" element.")), (NULL));
       
  1371     return FALSE;
       
  1372   }
       
  1373 could_not_link:
       
  1374   {
       
  1375     GST_ELEMENT_ERROR (decoder, CORE, NEGOTIATION,
       
  1376         (NULL), ("Can't link source to typefind element"));
       
  1377     return FALSE;
  1010   }
  1378   }
  1011 }
  1379 }
  1012 
  1380 
  1013 static void
  1381 static void
  1014 remove_source (GstURIDecodeBin * bin)
  1382 remove_source (GstURIDecodeBin * bin)
  1037 source_new_pad (GstElement * element, GstPad * pad, GstURIDecodeBin * bin)
  1405 source_new_pad (GstElement * element, GstPad * pad, GstURIDecodeBin * bin)
  1038 {
  1406 {
  1039   GstElement *decoder;
  1407   GstElement *decoder;
  1040   gboolean is_raw;
  1408   gboolean is_raw;
  1041 
  1409 
       
  1410   GST_URI_DECODE_BIN_LOCK (bin);
  1042   GST_DEBUG_OBJECT (bin, "Found new pad %s.%s in source element %s",
  1411   GST_DEBUG_OBJECT (bin, "Found new pad %s.%s in source element %s",
  1043       GST_DEBUG_PAD_NAME (pad), GST_ELEMENT_NAME (element));
  1412       GST_DEBUG_PAD_NAME (pad), GST_ELEMENT_NAME (element));
  1044 
  1413 
  1045   /* if this is a pad with all raw caps, we can expose it */
  1414   /* if this is a pad with all raw caps, we can expose it */
  1046   if (has_all_raw_caps (pad, &is_raw) && is_raw) {
  1415   if (has_all_raw_caps (pad, &is_raw) && is_raw) {
  1047     /* it's all raw, create output pads. */
  1416     /* it's all raw, create output pads. */
       
  1417     GST_URI_DECODE_BIN_UNLOCK (bin);
  1048     new_decoded_pad_cb (element, pad, FALSE, bin);
  1418     new_decoded_pad_cb (element, pad, FALSE, bin);
  1049     return;
  1419     return;
  1050   }
  1420   }
  1051 
  1421 
  1052   /* not raw, create decoder */
  1422   /* not raw, create decoder */
  1053   decoder = make_decoder (bin, FALSE);
  1423   decoder = make_decoder (bin);
  1054   if (!decoder)
  1424   if (!decoder)
  1055     goto no_decodebin;
  1425     goto no_decodebin;
  1056 
  1426 
  1057   /* and link to decoder */
  1427   /* and link to decoder */
  1058   if (!gst_element_link (bin->source, decoder))
  1428   if (!gst_element_link (bin->source, decoder))
  1059     goto could_not_link;
  1429     goto could_not_link;
  1060 
  1430 
  1061   GST_DEBUG_OBJECT (bin, "linked decoder to new pad");
  1431   GST_DEBUG_OBJECT (bin, "linked decoder to new pad");
  1062 
  1432 
  1063   gst_element_set_state (decoder, GST_STATE_PLAYING);
  1433   gst_element_set_state (decoder, GST_STATE_PLAYING);
       
  1434   GST_URI_DECODE_BIN_UNLOCK (bin);
  1064 
  1435 
  1065   return;
  1436   return;
  1066 
  1437 
  1067   /* ERRORS */
  1438   /* ERRORS */
  1068 no_decodebin:
  1439 no_decodebin:
  1069   {
  1440   {
  1070     /* error was posted */
  1441     /* error was posted */
       
  1442     GST_URI_DECODE_BIN_UNLOCK (bin);
  1071     return;
  1443     return;
  1072   }
  1444   }
  1073 could_not_link:
  1445 could_not_link:
  1074   {
  1446   {
  1075     GST_ELEMENT_ERROR (bin, CORE, NEGOTIATION,
  1447     GST_ELEMENT_ERROR (bin, CORE, NEGOTIATION,
  1076         (NULL), ("Can't link source to decoder element"));
  1448         (NULL), ("Can't link source to decoder element"));
       
  1449     GST_URI_DECODE_BIN_UNLOCK (bin);
  1077     return;
  1450     return;
  1078   }
  1451   }
  1079 }
  1452 }
  1080 
  1453 
  1081 /* construct and run the source and decoder elements until we found
  1454 /* construct and run the source and decoder elements until we found
  1089   GST_DEBUG_OBJECT (decoder, "setup source");
  1462   GST_DEBUG_OBJECT (decoder, "setup source");
  1090 
  1463 
  1091   /* delete old src */
  1464   /* delete old src */
  1092   remove_source (decoder);
  1465   remove_source (decoder);
  1093 
  1466 
       
  1467   decoder->pending = 0;
       
  1468 
  1094   /* create and configure an element that can handle the uri */
  1469   /* create and configure an element that can handle the uri */
  1095   if (!(decoder->source = gen_source_element (decoder)))
  1470   if (!(decoder->source = gen_source_element (decoder)))
  1096     goto no_source;
  1471     goto no_source;
  1097 
  1472 
  1098   /* state will be merged later - if file is not found, error will be
  1473   /* state will be merged later - if file is not found, error will be
  1099    * handled by the application right after. */
  1474    * handled by the application right after. */
  1100   gst_bin_add (GST_BIN_CAST (decoder), decoder->source);
  1475   gst_bin_add (GST_BIN_CAST (decoder), decoder->source);
       
  1476 
       
  1477   /* notify of the new source used */
       
  1478   g_object_notify (G_OBJECT (decoder), "source");
  1101 
  1479 
  1102   /* remove the old decoders now, if any */
  1480   /* remove the old decoders now, if any */
  1103   remove_decoders (decoder);
  1481   remove_decoders (decoder);
  1104 
  1482 
  1105   /* see if the source element emits raw audio/video all by itself,
  1483   /* see if the source element emits raw audio/video all by itself,
  1106    * if so, we can create streams for the pads and be done with it.
  1484    * if so, we can create streams for the pads and be done with it.
  1107    * Also check that is has source pads, if not, we assume it will
  1485    * Also check that is has source pads, if not, we assume it will
  1108    * do everything itself.  */
  1486    * do everything itself.  */
  1109   if (!analyse_source (decoder, &is_raw, &have_out, &is_dynamic))
  1487   if (!analyse_source (decoder, &is_raw, &have_out, &is_dynamic,
       
  1488           decoder->need_queue))
  1110     goto invalid_source;
  1489     goto invalid_source;
  1111 
  1490 
  1112   if (is_raw) {
  1491   if (is_raw) {
  1113     GST_DEBUG_OBJECT (decoder, "Source provides all raw data");
  1492     GST_DEBUG_OBJECT (decoder, "Source provides all raw data");
  1114     /* source provides raw data, we added the pads and we can now signal a
  1493     /* source provides raw data, we added the pads and we can now signal a
  1115      * no_more pads because we are done. */
  1494      * no_more pads because we are done. */
  1116     /* FIXME, actually do this... */
  1495     gst_element_no_more_pads (GST_ELEMENT_CAST (decoder));
  1117     return TRUE;
  1496     return TRUE;
  1118   }
  1497   }
  1119   if (!have_out && !is_dynamic) {
  1498   if (!have_out && !is_dynamic) {
  1120     GST_DEBUG_OBJECT (decoder, "Source has no output pads");
  1499     GST_DEBUG_OBJECT (decoder, "Source has no output pads");
  1121     /* create a stream to indicate that this uri is handled by a self
  1500     /* create a stream to indicate that this uri is handled by a self
  1133         g_signal_connect (G_OBJECT (decoder->source), "no-more-pads",
  1512         g_signal_connect (G_OBJECT (decoder->source), "no-more-pads",
  1134         G_CALLBACK (source_no_more_pads), decoder);
  1513         G_CALLBACK (source_no_more_pads), decoder);
  1135     g_object_set_data (G_OBJECT (decoder->source), "pending", "1");
  1514     g_object_set_data (G_OBJECT (decoder->source), "pending", "1");
  1136     decoder->pending++;
  1515     decoder->pending++;
  1137   } else {
  1516   } else {
  1138     GstElement *dec_elem;
  1517     if (decoder->is_stream) {
  1139 
  1518       GST_DEBUG_OBJECT (decoder, "Setting up streaming");
  1140     GST_DEBUG_OBJECT (decoder, "Pluggin decodebin to source");
  1519       /* do the stream things here */
  1141 
  1520       if (!setup_streaming (decoder))
  1142     /* no dynamic source, we can link now */
  1521         goto streaming_failed;
  1143     dec_elem = make_decoder (decoder, decoder->is_stream);
  1522     } else {
  1144     if (!dec_elem)
  1523       GstElement *dec_elem;
  1145       goto no_decoder;
  1524 
  1146 
  1525       /* no streaming source, we can link now */
  1147     if (!gst_element_link (decoder->source, dec_elem))
  1526       GST_DEBUG_OBJECT (decoder, "Plugging decodebin to source");
  1148       goto could_not_link;
  1527 
       
  1528       dec_elem = make_decoder (decoder);
       
  1529       if (!dec_elem)
       
  1530         goto no_decoder;
       
  1531 
       
  1532       if (!gst_element_link (decoder->source, dec_elem))
       
  1533         goto could_not_link;
       
  1534     }
  1149   }
  1535   }
  1150   return TRUE;
  1536   return TRUE;
  1151 
  1537 
  1152   /* ERRORS */
  1538   /* ERRORS */
  1153 no_source:
  1539 no_source:
  1160     GST_ELEMENT_ERROR (decoder, CORE, FAILED,
  1546     GST_ELEMENT_ERROR (decoder, CORE, FAILED,
  1161         (_("Source element is invalid.")), (NULL));
  1547         (_("Source element is invalid.")), (NULL));
  1162     return FALSE;
  1548     return FALSE;
  1163   }
  1549   }
  1164 no_decoder:
  1550 no_decoder:
       
  1551   {
       
  1552     /* message was posted */
       
  1553     return FALSE;
       
  1554   }
       
  1555 streaming_failed:
  1165   {
  1556   {
  1166     /* message was posted */
  1557     /* message was posted */
  1167     return FALSE;
  1558     return FALSE;
  1168   }
  1559   }
  1169 could_not_link:
  1560 could_not_link:
  1317       fold->max = duration;
  1708       fold->max = duration;
  1318   }
  1709   }
  1319   gst_object_unref (item);
  1710   gst_object_unref (item);
  1320   return TRUE;
  1711   return TRUE;
  1321 }
  1712 }
       
  1713 
  1322 static void
  1714 static void
  1323 decoder_query_duration_done (GstURIDecodeBin * dec, QueryFold * fold)
  1715 decoder_query_duration_done (GstURIDecodeBin * dec, QueryFold * fold)
  1324 {
  1716 {
  1325   GstFormat format;
  1717   GstFormat format;
  1326 
  1718 
  1348   }
  1740   }
  1349 
  1741 
  1350   gst_object_unref (item);
  1742   gst_object_unref (item);
  1351   return TRUE;
  1743   return TRUE;
  1352 }
  1744 }
       
  1745 
  1353 static void
  1746 static void
  1354 decoder_query_position_done (GstURIDecodeBin * dec, QueryFold * fold)
  1747 decoder_query_position_done (GstURIDecodeBin * dec, QueryFold * fold)
  1355 {
  1748 {
  1356   GstFormat format;
  1749   GstFormat format;
  1357 
  1750 
  1390   }
  1783   }
  1391 
  1784 
  1392   gst_object_unref (item);
  1785   gst_object_unref (item);
  1393   return TRUE;
  1786   return TRUE;
  1394 }
  1787 }
       
  1788 
  1395 static void
  1789 static void
  1396 decoder_query_latency_done (GstURIDecodeBin * dec, QueryFold * fold)
  1790 decoder_query_latency_done (GstURIDecodeBin * dec, QueryFold * fold)
  1397 {
  1791 {
  1398   /* store max in query result */
  1792   /* store max in query result */
  1399   gst_query_set_latency (fold->query, fold->live, fold->min, fold->max);
  1793   gst_query_set_latency (fold->query, fold->live, fold->min, fold->max);
  1421   }
  1815   }
  1422   gst_object_unref (item);
  1816   gst_object_unref (item);
  1423 
  1817 
  1424   return TRUE;
  1818   return TRUE;
  1425 }
  1819 }
       
  1820 
  1426 static void
  1821 static void
  1427 decoder_query_seeking_done (GstURIDecodeBin * dec, QueryFold * fold)
  1822 decoder_query_seeking_done (GstURIDecodeBin * dec, QueryFold * fold)
  1428 {
  1823 {
  1429   GstFormat format;
  1824   GstFormat format;
  1430 
  1825 
  1569     case GST_STATE_CHANGE_PAUSED_TO_READY:
  1964     case GST_STATE_CHANGE_PAUSED_TO_READY:
  1570       GST_DEBUG ("paused to ready");
  1965       GST_DEBUG ("paused to ready");
  1571       remove_decoders (decoder);
  1966       remove_decoders (decoder);
  1572       remove_pads (decoder);
  1967       remove_pads (decoder);
  1573       remove_source (decoder);
  1968       remove_source (decoder);
       
  1969       do_async_done (decoder);
       
  1970       break;
       
  1971     case GST_STATE_CHANGE_READY_TO_NULL:
       
  1972       GST_DEBUG ("ready to null");
       
  1973       remove_decoders (decoder);
       
  1974       remove_pads (decoder);
       
  1975       remove_source (decoder);
  1574       break;
  1976       break;
  1575     default:
  1977     default:
  1576       break;
  1978       break;
  1577   }
  1979   }
  1578   return ret;
  1980   return ret;
  1599 
  2001 
  1600 #ifdef ENABLE_NLS
  2002 #ifdef ENABLE_NLS
  1601   GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
  2003   GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
  1602       LOCALEDIR);
  2004       LOCALEDIR);
  1603   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  2005   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
       
  2006   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  1604 #endif /* ENABLE_NLS */
  2007 #endif /* ENABLE_NLS */
  1605 
  2008 
  1606   return gst_element_register (plugin, "uridecodebin", GST_RANK_NONE,
  2009   return gst_element_register (plugin, "uridecodebin", GST_RANK_NONE,
  1607       GST_TYPE_URI_DECODE_BIN);
  2010       GST_TYPE_URI_DECODE_BIN);
  1608 }
  2011 }