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; |
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) |
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) |
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")) { |
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 |
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: |