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