2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * 2009 Nokia Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:gstdiscoverer
23 * @short_description: Utility for discovering information on URIs.
25 * The #GstDiscoverer is a utility object which allows to get as much
26 * information as possible from one or many URIs.
28 * It provides two APIs, allowing usage in blocking or non-blocking mode.
30 * The blocking mode just requires calling gst_discoverer_discover_uri()
31 * with the URI one wishes to discover.
33 * The non-blocking mode requires a running #GMainLoop in the default
34 * #GMainContext, where one connects to the various signals, appends the
35 * URIs to be processed (through gst_discoverer_discover_uri_async()) and then
36 * asks for the discovery to begin (through gst_discoverer_start()).
38 * All the information is returned in a #GstDiscovererInfo structure.
47 #include <gst/video/video.h>
50 #include "pbutils-marshal.h"
51 #include "pbutils-private.h"
53 #include "gst/glib-compat-private.h"
55 GST_DEBUG_CATEGORY_STATIC (discoverer_debug);
56 #define GST_CAT_DEFAULT discoverer_debug
58 static GQuark _CAPS_QUARK;
59 static GQuark _TAGS_QUARK;
60 static GQuark _MISSING_PLUGIN_QUARK;
61 static GQuark _STREAM_TOPOLOGY_QUARK;
62 static GQuark _TOPOLOGY_PAD_QUARK;
74 struct _GstDiscovererPrivate
78 /* allowed time to discover each uri in nanoseconds */
81 /* list of pending URI to process (current excluded) */
86 /* TRUE if processing a URI */
89 /* TRUE if discoverer has been started */
93 GstDiscovererInfo *current_info;
94 GError *current_error;
95 GstStructure *current_topology;
97 /* List of private streams */
100 /* Global elements */
102 GstElement *uridecodebin;
105 GType decodebin_type;
107 /* Custom main context variables */
112 /* reusable queries */
113 GstQuery *seeking_query;
115 /* Handler ids for various callbacks */
117 gulong pad_remove_id;
118 gulong element_added_id;
122 #define DISCO_LOCK(dc) g_mutex_lock (dc->priv->lock);
123 #define DISCO_UNLOCK(dc) g_mutex_unlock (dc->priv->lock);
128 GST_DEBUG_CATEGORY_INIT (discoverer_debug, "discoverer", 0, "Discoverer");
130 _CAPS_QUARK = g_quark_from_static_string ("caps");
131 _TAGS_QUARK = g_quark_from_static_string ("tags");
132 _MISSING_PLUGIN_QUARK = g_quark_from_static_string ("missing-plugin");
133 _STREAM_TOPOLOGY_QUARK = g_quark_from_static_string ("stream-topology");
134 _TOPOLOGY_PAD_QUARK = g_quark_from_static_string ("pad");
137 G_DEFINE_TYPE_EXTENDED (GstDiscoverer, gst_discoverer, G_TYPE_OBJECT, 0,
148 #define DEFAULT_PROP_TIMEOUT 15 * GST_SECOND
156 static guint gst_discoverer_signals[LAST_SIGNAL] = { 0 };
158 static void gst_discoverer_set_timeout (GstDiscoverer * dc,
159 GstClockTime timeout);
160 static gboolean async_timeout_cb (GstDiscoverer * dc);
162 static void discoverer_bus_cb (GstBus * bus, GstMessage * msg,
164 static void uridecodebin_pad_added_cb (GstElement * uridecodebin, GstPad * pad,
166 static void uridecodebin_pad_removed_cb (GstElement * uridecodebin,
167 GstPad * pad, GstDiscoverer * dc);
169 static void gst_discoverer_dispose (GObject * dc);
170 static void gst_discoverer_set_property (GObject * object, guint prop_id,
171 const GValue * value, GParamSpec * pspec);
172 static void gst_discoverer_get_property (GObject * object, guint prop_id,
173 GValue * value, GParamSpec * pspec);
176 gst_discoverer_class_init (GstDiscovererClass * klass)
178 GObjectClass *gobject_class = (GObjectClass *) klass;
180 gobject_class->dispose = gst_discoverer_dispose;
182 gobject_class->set_property = gst_discoverer_set_property;
183 gobject_class->get_property = gst_discoverer_get_property;
185 g_type_class_add_private (klass, sizeof (GstDiscovererPrivate));
189 * GstDiscoverer:timeout
191 * The duration (in nanoseconds) after which the discovery of an individual
194 * If the discovery of a URI times out, the %GST_DISCOVERER_TIMEOUT will be
195 * set on the result flags.
197 g_object_class_install_property (gobject_class, PROP_TIMEOUT,
198 g_param_spec_uint64 ("timeout", "timeout", "Timeout",
199 GST_SECOND, 3600 * GST_SECOND, DEFAULT_PROP_TIMEOUT,
200 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
204 * GstDiscoverer::finished:
205 * @discoverer: the #GstDiscoverer
207 * Will be emitted when all pending URIs have been processed.
209 gst_discoverer_signals[SIGNAL_FINISHED] =
210 g_signal_new ("finished", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
211 G_STRUCT_OFFSET (GstDiscovererClass, finished),
212 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
215 * GstDiscoverer::starting:
216 * @discoverer: the #GstDiscoverer
218 * Will be emitted when the discover starts analyzing the pending URIs
220 gst_discoverer_signals[SIGNAL_STARTING] =
221 g_signal_new ("starting", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
222 G_STRUCT_OFFSET (GstDiscovererClass, starting),
223 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
226 * GstDiscoverer::discovered:
227 * @discoverer: the #GstDiscoverer
228 * @info: the results #GstDiscovererInfo
229 * @error: (type GLib.Error): #GError, which will be non-NULL if an error
230 * occurred during discovery
232 * Will be emitted when all information on a URI could be discovered.
234 gst_discoverer_signals[SIGNAL_DISCOVERED] =
235 g_signal_new ("discovered", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
236 G_STRUCT_OFFSET (GstDiscovererClass, discovered),
237 NULL, NULL, pbutils_marshal_VOID__POINTER_BOXED,
238 G_TYPE_NONE, 2, GST_TYPE_DISCOVERER_INFO,
239 G_TYPE_ERROR | G_SIGNAL_TYPE_STATIC_SCOPE);
243 uridecodebin_element_added_cb (GstElement * uridecodebin,
244 GstElement * child, GstDiscoverer * dc)
246 GST_DEBUG ("New element added to uridecodebin : %s",
247 GST_ELEMENT_NAME (child));
249 if (G_OBJECT_TYPE (child) == dc->priv->decodebin_type) {
250 g_object_set (child, "post-stream-topology", TRUE, NULL);
255 gst_discoverer_init (GstDiscoverer * dc)
258 GstFormat format = GST_FORMAT_TIME;
260 dc->priv = G_TYPE_INSTANCE_GET_PRIVATE (dc, GST_TYPE_DISCOVERER,
261 GstDiscovererPrivate);
263 dc->priv->timeout = DEFAULT_PROP_TIMEOUT;
264 dc->priv->async = FALSE;
266 dc->priv->lock = g_mutex_new ();
268 GST_LOG ("Creating pipeline");
269 dc->priv->pipeline = (GstBin *) gst_pipeline_new ("Discoverer");
270 GST_LOG_OBJECT (dc, "Creating uridecodebin");
271 dc->priv->uridecodebin =
272 gst_element_factory_make ("uridecodebin", "discoverer-uri");
273 if (G_UNLIKELY (dc->priv->uridecodebin == NULL)) {
274 GST_ERROR ("Can't create uridecodebin");
277 GST_LOG_OBJECT (dc, "Adding uridecodebin to pipeline");
278 gst_bin_add (dc->priv->pipeline, dc->priv->uridecodebin);
280 dc->priv->pad_added_id =
281 g_signal_connect_object (dc->priv->uridecodebin, "pad-added",
282 G_CALLBACK (uridecodebin_pad_added_cb), dc, 0);
283 dc->priv->pad_remove_id =
284 g_signal_connect_object (dc->priv->uridecodebin, "pad-removed",
285 G_CALLBACK (uridecodebin_pad_removed_cb), dc, 0);
287 GST_LOG_OBJECT (dc, "Getting pipeline bus");
288 dc->priv->bus = gst_pipeline_get_bus ((GstPipeline *) dc->priv->pipeline);
290 dc->priv->bus_cb_id =
291 g_signal_connect_object (dc->priv->bus, "message",
292 G_CALLBACK (discoverer_bus_cb), dc, 0);
294 GST_DEBUG_OBJECT (dc, "Done initializing Discoverer");
296 /* This is ugly. We get the GType of decodebin so we can quickly detect
297 * when a decodebin is added to uridecodebin so we can set the
298 * post-stream-topology setting to TRUE */
299 dc->priv->element_added_id =
300 g_signal_connect_object (dc->priv->uridecodebin, "element-added",
301 G_CALLBACK (uridecodebin_element_added_cb), dc, 0);
302 tmp = gst_element_factory_make ("decodebin", NULL);
303 dc->priv->decodebin_type = G_OBJECT_TYPE (tmp);
304 gst_object_unref (tmp);
307 dc->priv->seeking_query = gst_query_new_seeking (format);
311 discoverer_reset (GstDiscoverer * dc)
313 GST_DEBUG_OBJECT (dc, "Resetting");
315 if (dc->priv->pending_uris) {
316 g_list_foreach (dc->priv->pending_uris, (GFunc) g_free, NULL);
317 g_list_free (dc->priv->pending_uris);
318 dc->priv->pending_uris = NULL;
321 if (dc->priv->pipeline)
322 gst_element_set_state ((GstElement *) dc->priv->pipeline, GST_STATE_NULL);
325 #define DISCONNECT_SIGNAL(o,i) G_STMT_START{ \
326 if ((i) && g_signal_handler_is_connected ((o), (i))) \
327 g_signal_handler_disconnect ((o), (i)); \
332 gst_discoverer_dispose (GObject * obj)
334 GstDiscoverer *dc = (GstDiscoverer *) obj;
336 GST_DEBUG_OBJECT (dc, "Disposing");
338 discoverer_reset (dc);
340 if (G_LIKELY (dc->priv->pipeline)) {
341 /* Workaround for bug #118536 */
342 DISCONNECT_SIGNAL (dc->priv->uridecodebin, dc->priv->pad_added_id);
343 DISCONNECT_SIGNAL (dc->priv->uridecodebin, dc->priv->pad_remove_id);
344 DISCONNECT_SIGNAL (dc->priv->uridecodebin, dc->priv->element_added_id);
345 DISCONNECT_SIGNAL (dc->priv->bus, dc->priv->bus_cb_id);
347 /* pipeline was set to NULL in _reset */
348 gst_object_unref (dc->priv->pipeline);
349 gst_object_unref (dc->priv->bus);
351 dc->priv->pipeline = NULL;
352 dc->priv->uridecodebin = NULL;
353 dc->priv->bus = NULL;
356 gst_discoverer_stop (dc);
358 if (dc->priv->lock) {
359 g_mutex_free (dc->priv->lock);
360 dc->priv->lock = NULL;
363 if (dc->priv->seeking_query) {
364 gst_query_unref (dc->priv->seeking_query);
365 dc->priv->seeking_query = NULL;
368 G_OBJECT_CLASS (gst_discoverer_parent_class)->dispose (obj);
372 gst_discoverer_set_property (GObject * object, guint prop_id,
373 const GValue * value, GParamSpec * pspec)
375 GstDiscoverer *dc = (GstDiscoverer *) object;
379 gst_discoverer_set_timeout (dc, g_value_get_uint64 (value));
382 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
388 gst_discoverer_get_property (GObject * object, guint prop_id,
389 GValue * value, GParamSpec * pspec)
391 GstDiscoverer *dc = (GstDiscoverer *) object;
396 g_value_set_uint64 (value, dc->priv->timeout);
400 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
406 gst_discoverer_set_timeout (GstDiscoverer * dc, GstClockTime timeout)
408 GST_DEBUG_OBJECT (dc, "timeout : %" GST_TIME_FORMAT, GST_TIME_ARGS (timeout));
410 /* FIXME : update current pending timeout if we're running */
412 dc->priv->timeout = timeout;
416 static GstPadProbeReturn
417 _event_probe (GstPad * pad, GstPadProbeInfo * info, PrivateStream * ps)
419 GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info);
421 if (GST_EVENT_TYPE (event) == GST_EVENT_TAG) {
422 GstTagList *tl = NULL, *tmp;
424 gst_event_parse_tag (event, &tl);
425 GST_DEBUG_OBJECT (pad, "tags %" GST_PTR_FORMAT, tl);
427 /* If preroll is complete, drop these tags - the collected information is
428 * possibly already being processed and adding more tags would be racy */
429 if (G_LIKELY (ps->dc->priv->processing)) {
430 GST_DEBUG_OBJECT (pad, "private stream %p old tags %" GST_PTR_FORMAT, ps,
432 tmp = gst_tag_list_merge (ps->tags, tl, GST_TAG_MERGE_APPEND);
434 gst_tag_list_free (ps->tags);
436 GST_DEBUG_OBJECT (pad, "private stream %p new tags %" GST_PTR_FORMAT, ps,
439 GST_DEBUG_OBJECT (pad, "Dropping tags since preroll is done");
440 DISCO_UNLOCK (ps->dc);
443 return GST_PAD_PROBE_OK;
446 static GstStaticCaps subtitle_caps = GST_STATIC_CAPS ("text/plain; "
447 "text/x-pango-markup; subpicture/x-pgs; subpicture/x-dvb; "
448 "application/x-subtitle-unknown; application/x-ssa; application/x-ass; "
449 "subtitle/x-kate; application/x-kate; video/x-dvd-subpicture");
452 is_subtitle_caps (const GstCaps * caps)
457 subs_caps = gst_static_caps_get (&subtitle_caps);
458 ret = gst_caps_can_intersect (caps, subs_caps);
459 gst_caps_unref (subs_caps);
465 uridecodebin_pad_added_cb (GstElement * uridecodebin, GstPad * pad,
469 GstPad *sinkpad = NULL;
472 GST_DEBUG_OBJECT (dc, "pad %s:%s", GST_DEBUG_PAD_NAME (pad));
474 ps = g_slice_new0 (PrivateStream);
478 ps->queue = gst_element_factory_make ("queue", NULL);
479 ps->sink = gst_element_factory_make ("fakesink", NULL);
481 if (G_UNLIKELY (ps->queue == NULL || ps->sink == NULL))
484 g_object_set (ps->sink, "silent", TRUE, NULL);
485 g_object_set (ps->queue, "max-size-buffers", 1, "silent", TRUE, NULL);
487 caps = gst_pad_query_caps (pad, NULL);
489 if (is_subtitle_caps (caps)) {
490 /* Subtitle streams are sparse and may not provide any information - don't
491 * wait for data to preroll */
492 g_object_set (ps->sink, "async", FALSE, NULL);
495 gst_caps_unref (caps);
497 gst_bin_add_many (dc->priv->pipeline, ps->queue, ps->sink, NULL);
499 if (!gst_element_link_pads_full (ps->queue, "src", ps->sink, "sink",
500 GST_PAD_LINK_CHECK_NOTHING))
502 if (!gst_element_sync_state_with_parent (ps->sink))
504 if (!gst_element_sync_state_with_parent (ps->queue))
507 sinkpad = gst_element_get_static_pad (ps->queue, "sink");
510 if (gst_pad_link_full (pad, sinkpad,
511 GST_PAD_LINK_CHECK_NOTHING) != GST_PAD_LINK_OK)
513 gst_object_unref (sinkpad);
515 /* Add an event probe */
516 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
517 (GstPadProbeCallback) _event_probe, ps, NULL);
520 dc->priv->streams = g_list_append (dc->priv->streams, ps);
523 GST_DEBUG_OBJECT (dc, "Done handling pad");
528 GST_ERROR_OBJECT (dc, "Error while handling pad");
530 gst_object_unref (sinkpad);
532 gst_object_unref (ps->queue);
534 gst_object_unref (ps->sink);
535 g_slice_free (PrivateStream, ps);
540 uridecodebin_pad_removed_cb (GstElement * uridecodebin, GstPad * pad,
547 GST_DEBUG_OBJECT (dc, "pad %s:%s", GST_DEBUG_PAD_NAME (pad));
549 /* Find the PrivateStream */
551 for (tmp = dc->priv->streams; tmp; tmp = tmp->next) {
552 ps = (PrivateStream *) tmp->data;
559 GST_DEBUG ("The removed pad wasn't controlled by us !");
563 dc->priv->streams = g_list_delete_link (dc->priv->streams, tmp);
566 gst_element_set_state (ps->sink, GST_STATE_NULL);
567 gst_element_set_state (ps->queue, GST_STATE_NULL);
568 gst_element_unlink (ps->queue, ps->sink);
570 sinkpad = gst_element_get_static_pad (ps->queue, "sink");
571 gst_pad_unlink (pad, sinkpad);
572 gst_object_unref (sinkpad);
574 /* references removed here */
575 gst_bin_remove_many (dc->priv->pipeline, ps->sink, ps->queue, NULL);
578 gst_tag_list_free (ps->tags);
581 g_slice_free (PrivateStream, ps);
583 GST_DEBUG ("Done handling pad");
586 static GstStructure *
587 collect_stream_information (GstDiscoverer * dc, PrivateStream * ps, guint idx)
593 stname = g_strdup_printf ("stream-%02d", idx);
594 st = gst_structure_new_empty (stname);
598 caps = gst_pad_get_current_caps (ps->pad);
600 GST_WARNING ("Couldn't get negotiated caps from %s:%s",
601 GST_DEBUG_PAD_NAME (ps->pad));
602 caps = gst_pad_query_caps (ps->pad, NULL);
605 GST_DEBUG ("Got caps %" GST_PTR_FORMAT, caps);
606 gst_structure_id_set (st, _CAPS_QUARK, GST_TYPE_CAPS, caps, NULL);
608 gst_caps_unref (caps);
611 gst_structure_id_set (st, _TAGS_QUARK, GST_TYPE_TAG_LIST, ps->tags, NULL);
616 /* takes ownership of new_tags, may replace *taglist with a new one */
618 gst_discoverer_merge_and_replace_tags (GstTagList ** taglist,
619 GstTagList * new_tags)
621 if (new_tags == NULL)
624 if (*taglist == NULL) {
629 gst_tag_list_insert (*taglist, new_tags, GST_TAG_MERGE_REPLACE);
630 gst_tag_list_free (new_tags);
633 /* Parses a set of caps and tags in st and populates a GstDiscovererStreamInfo
634 * structure (parent, if !NULL, otherwise it allocates one)
636 static GstDiscovererStreamInfo *
637 collect_information (GstDiscoverer * dc, const GstStructure * st,
638 GstDiscovererStreamInfo * parent)
641 GstStructure *caps_st;
647 if (!st || !gst_structure_id_has_field (st, _CAPS_QUARK)) {
648 GST_WARNING ("Couldn't find caps !");
650 return gst_discoverer_stream_info_ref (parent);
652 return (GstDiscovererStreamInfo *)
653 g_object_new (GST_TYPE_DISCOVERER_STREAM_INFO, NULL);
656 gst_structure_id_get (st, _CAPS_QUARK, GST_TYPE_CAPS, &caps, NULL);
657 caps_st = gst_caps_get_structure (caps, 0);
658 name = gst_structure_get_name (caps_st);
660 if (g_str_has_prefix (name, "audio/")) {
661 GstDiscovererAudioInfo *info;
664 info = (GstDiscovererAudioInfo *) gst_discoverer_stream_info_ref (parent);
666 info = (GstDiscovererAudioInfo *)
667 g_object_new (GST_TYPE_DISCOVERER_AUDIO_INFO, NULL);
668 info->parent.caps = gst_caps_ref (caps);
671 if (gst_structure_get_int (caps_st, "rate", &tmp))
672 info->sample_rate = (guint) tmp;
674 if (gst_structure_get_int (caps_st, "channels", &tmp))
675 info->channels = (guint) tmp;
677 if (gst_structure_get_int (caps_st, "depth", &tmp))
678 info->depth = (guint) tmp;
680 if (gst_structure_id_has_field (st, _TAGS_QUARK)) {
681 gst_structure_id_get (st, _TAGS_QUARK, GST_TYPE_TAG_LIST, &tags_st, NULL);
682 if (gst_tag_list_get_uint (tags_st, GST_TAG_BITRATE, &utmp) ||
683 gst_tag_list_get_uint (tags_st, GST_TAG_NOMINAL_BITRATE, &utmp))
684 info->bitrate = utmp;
686 if (gst_tag_list_get_uint (tags_st, GST_TAG_MAXIMUM_BITRATE, &utmp))
687 info->max_bitrate = utmp;
689 /* FIXME: Is it worth it to remove the tags we've parsed? */
690 gst_discoverer_merge_and_replace_tags (&info->parent.tags, tags_st);
693 if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) {
695 if (gst_tag_list_get_string (((GstDiscovererStreamInfo *) info)->tags,
696 GST_TAG_LANGUAGE_CODE, &language)) {
697 info->language = language;
701 gst_caps_unref (caps);
702 return (GstDiscovererStreamInfo *) info;
704 } else if (g_str_has_prefix (name, "video/") ||
705 g_str_has_prefix (name, "image/")) {
706 GstDiscovererVideoInfo *info;
710 info = (GstDiscovererVideoInfo *) gst_discoverer_stream_info_ref (parent);
712 info = (GstDiscovererVideoInfo *)
713 g_object_new (GST_TYPE_DISCOVERER_VIDEO_INFO, NULL);
714 info->parent.caps = gst_caps_ref (caps);
717 /* FIXME : gst_video_info_from_caps only works with raw caps,
718 * wouldn't we want to get all the info below for non-raw caps ?
720 if (g_str_has_prefix (name, "video/x-raw") &&
721 gst_video_info_from_caps (&vinfo, caps)) {
722 info->width = (guint) vinfo.width;
723 info->height = (guint) vinfo.height;
725 info->depth = (guint) 0;
727 info->par_num = vinfo.par_n;
728 info->par_denom = vinfo.par_d;
730 info->framerate_num = vinfo.fps_n;
731 info->framerate_denom = vinfo.fps_d;
733 info->interlaced = (vinfo.flags & GST_VIDEO_FLAG_INTERLACED) != 0;
736 if (gst_structure_id_has_field (st, _TAGS_QUARK)) {
737 gst_structure_id_get (st, _TAGS_QUARK, GST_TYPE_TAG_LIST, &tags_st, NULL);
738 if (gst_tag_list_get_uint (tags_st, GST_TAG_BITRATE, &utmp) ||
739 gst_tag_list_get_uint (tags_st, GST_TAG_NOMINAL_BITRATE, &utmp))
740 info->bitrate = utmp;
742 if (gst_tag_list_get_uint (tags_st, GST_TAG_MAXIMUM_BITRATE, &utmp))
743 info->max_bitrate = utmp;
745 /* FIXME: Is it worth it to remove the tags we've parsed? */
746 gst_discoverer_merge_and_replace_tags (&info->parent.tags,
747 (GstTagList *) tags_st);
750 gst_caps_unref (caps);
751 return (GstDiscovererStreamInfo *) info;
753 } else if (is_subtitle_caps (caps)) {
754 GstDiscovererSubtitleInfo *info;
758 (GstDiscovererSubtitleInfo *) gst_discoverer_stream_info_ref (parent);
760 info = (GstDiscovererSubtitleInfo *)
761 g_object_new (GST_TYPE_DISCOVERER_SUBTITLE_INFO, NULL);
762 info->parent.caps = gst_caps_ref (caps);
765 if (gst_structure_id_has_field (st, _TAGS_QUARK)) {
766 const gchar *language;
768 gst_structure_id_get (st, _TAGS_QUARK, GST_TYPE_TAG_LIST, &tags_st, NULL);
770 language = gst_structure_get_string (caps_st, GST_TAG_LANGUAGE_CODE);
772 info->language = g_strdup (language);
774 /* FIXME: Is it worth it to remove the tags we've parsed? */
775 gst_discoverer_merge_and_replace_tags (&info->parent.tags, tags_st);
778 if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) {
780 if (gst_tag_list_get_string (((GstDiscovererStreamInfo *) info)->tags,
781 GST_TAG_LANGUAGE_CODE, &language)) {
782 info->language = language;
786 gst_caps_unref (caps);
787 return (GstDiscovererStreamInfo *) info;
790 /* None of the above - populate what information we can */
791 GstDiscovererStreamInfo *info;
794 info = gst_discoverer_stream_info_ref (parent);
796 info = (GstDiscovererStreamInfo *)
797 g_object_new (GST_TYPE_DISCOVERER_STREAM_INFO, NULL);
798 info->caps = gst_caps_ref (caps);
801 if (gst_structure_id_get (st, _TAGS_QUARK,
802 GST_TYPE_TAG_LIST, &tags_st, NULL)) {
803 gst_discoverer_merge_and_replace_tags (&info->tags, tags_st);
806 gst_caps_unref (caps);
812 static GstStructure *
813 find_stream_for_node (GstDiscoverer * dc, const GstStructure * topology)
816 GstPad *target_pad = NULL;
817 GstStructure *st = NULL;
822 if (!gst_structure_id_has_field (topology, _TOPOLOGY_PAD_QUARK)) {
823 GST_DEBUG ("Could not find pad for node %" GST_PTR_FORMAT "\n", topology);
827 gst_structure_id_get (topology, _TOPOLOGY_PAD_QUARK,
828 GST_TYPE_PAD, &pad, NULL);
830 if (!dc->priv->streams) {
831 gst_object_unref (pad);
835 for (i = 0, tmp = dc->priv->streams; tmp; tmp = tmp->next, i++) {
836 ps = (PrivateStream *) tmp->data;
838 target_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (ps->pad));
839 gst_object_unref (target_pad);
841 if (target_pad == pad)
846 st = collect_stream_information (dc, ps, i);
848 gst_object_unref (pad);
854 child_is_raw_stream (const GstCaps * parent, const GstCaps * child)
856 const GstStructure *st1, *st2;
857 const gchar *name1, *name2;
859 st1 = gst_caps_get_structure (parent, 0);
860 name1 = gst_structure_get_name (st1);
861 st2 = gst_caps_get_structure (child, 0);
862 name2 = gst_structure_get_name (st2);
864 if ((g_str_has_prefix (name1, "audio/") &&
865 g_str_has_prefix (name2, "audio/x-raw")) ||
866 ((g_str_has_prefix (name1, "video/") ||
867 g_str_has_prefix (name1, "image/")) &&
868 g_str_has_prefix (name2, "video/x-raw"))) {
869 /* child is the "raw" sub-stream corresponding to parent */
873 if (is_subtitle_caps (parent))
879 /* If a parent is non-NULL, collected stream information will be appended to it
880 * (and where the information exists, it will be overriden)
882 static GstDiscovererStreamInfo *
883 parse_stream_topology (GstDiscoverer * dc, const GstStructure * topology,
884 GstDiscovererStreamInfo * parent)
886 GstDiscovererStreamInfo *res = NULL;
887 GstCaps *caps = NULL;
888 const GValue *nval = NULL;
890 GST_DEBUG ("parsing: %" GST_PTR_FORMAT, topology);
892 nval = gst_structure_get_value (topology, "next");
894 if (nval == NULL || GST_VALUE_HOLDS_STRUCTURE (nval)) {
895 GstStructure *st = find_stream_for_node (dc, topology);
896 gboolean add_to_list = TRUE;
899 res = collect_information (dc, st, parent);
900 gst_structure_free (st);
902 /* Didn't find a stream structure, so let's just use the caps we have */
903 res = collect_information (dc, topology, parent);
907 /* FIXME : aggregate with information from main streams */
908 GST_DEBUG ("Coudn't find 'next' ! might be the last entry");
911 const GstStructure *st;
913 st = gst_value_get_structure (nval);
915 GST_DEBUG ("next is a structure %" GST_PTR_FORMAT, st);
920 if (gst_structure_id_get (st, _CAPS_QUARK, GST_TYPE_CAPS, &caps, NULL)) {
921 if (gst_caps_can_intersect (parent->caps, caps)) {
922 /* We sometimes get an extra sub-stream from the parser. If this is
923 * the case, we just replace the parent caps with this stream's caps
924 * since they might contain more information */
925 gst_caps_replace (&parent->caps, caps);
927 parse_stream_topology (dc, st, parent);
929 } else if (child_is_raw_stream (parent->caps, caps)) {
930 /* This is the "raw" stream corresponding to the parent. This
931 * contains more information than the parent, tags etc. */
932 parse_stream_topology (dc, st, parent);
935 GstDiscovererStreamInfo *next = parse_stream_topology (dc, st, NULL);
937 next->previous = res;
939 gst_caps_unref (caps);
944 dc->priv->current_info->stream_list =
945 g_list_append (dc->priv->current_info->stream_list, res);
947 gst_discoverer_stream_info_unref (res);
950 } else if (GST_VALUE_HOLDS_LIST (nval)) {
952 GstDiscovererContainerInfo *cont;
955 if (!gst_structure_id_get (topology, _CAPS_QUARK,
956 GST_TYPE_CAPS, &caps, NULL))
957 GST_WARNING ("Couldn't find caps !");
959 len = gst_value_list_get_size (nval);
960 GST_DEBUG ("next is a list of %d entries", len);
962 cont = (GstDiscovererContainerInfo *)
963 g_object_new (GST_TYPE_DISCOVERER_CONTAINER_INFO, NULL);
964 cont->parent.caps = caps;
965 res = (GstDiscovererStreamInfo *) cont;
967 if (gst_structure_id_has_field (topology, _TAGS_QUARK)) {
970 gst_structure_id_get (topology, _TAGS_QUARK,
971 GST_TYPE_TAG_LIST, &tags, NULL);
973 GST_DEBUG ("Merge tags %" GST_PTR_FORMAT, tags);
976 gst_tag_list_merge (cont->parent.tags, (GstTagList *) tags,
977 GST_TAG_MERGE_APPEND);
978 gst_tag_list_free (tags);
979 if (cont->parent.tags)
980 gst_tag_list_free (cont->parent.tags);
981 cont->parent.tags = tmp;
982 GST_DEBUG ("Container info tags %" GST_PTR_FORMAT, tmp);
985 for (i = 0; i < len; i++) {
986 const GValue *subv = gst_value_list_get_value (nval, i);
987 const GstStructure *subst = gst_value_get_structure (subv);
988 GstDiscovererStreamInfo *substream;
990 GST_DEBUG ("%d %" GST_PTR_FORMAT, i, subst);
992 substream = parse_stream_topology (dc, subst, NULL);
994 substream->previous = res;
996 g_list_append (cont->streams,
997 gst_discoverer_stream_info_ref (substream));
1004 /* Called when pipeline is pre-rolled */
1006 discoverer_collect (GstDiscoverer * dc)
1008 GST_DEBUG ("Collecting information");
1010 /* Stop the timeout handler if present */
1011 if (dc->priv->timeoutid) {
1012 g_source_remove (dc->priv->timeoutid);
1013 dc->priv->timeoutid = 0;
1016 if (dc->priv->streams) {
1017 /* FIXME : Make this querying optional */
1019 GstElement *pipeline = (GstElement *) dc->priv->pipeline;
1022 GST_DEBUG ("Attempting to query duration");
1024 if (gst_element_query_duration (pipeline, GST_FORMAT_TIME, &dur)) {
1025 GST_DEBUG ("Got duration %" GST_TIME_FORMAT, GST_TIME_ARGS (dur));
1026 dc->priv->current_info->duration = (guint64) dur;
1028 GstStateChangeReturn sret;
1030 /* Some parsers may not even return a rough estimate right away, e.g.
1031 * because they've only processed a single frame so far, so if we
1032 * didn't get a duration the first time, spin a bit and try again.
1033 * Ugly, but still better than making parsers or other elements return
1034 * completely bogus values. We need some API extensions to solve this
1036 GST_INFO ("No duration yet, try a bit harder..");
1037 sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
1038 if (sret != GST_STATE_CHANGE_FAILURE) {
1041 for (i = 0; i < 2; ++i) {
1042 g_usleep (G_USEC_PER_SEC / 20);
1043 if (gst_element_query_duration (pipeline, GST_FORMAT_TIME, &dur)
1045 GST_DEBUG ("Got duration %" GST_TIME_FORMAT, GST_TIME_ARGS (dur));
1046 dc->priv->current_info->duration = (guint64) dur;
1050 gst_element_set_state (pipeline, GST_STATE_PAUSED);
1054 if (dc->priv->seeking_query) {
1055 if (gst_element_query (pipeline, dc->priv->seeking_query)) {
1059 gst_query_parse_seeking (dc->priv->seeking_query, &format,
1060 &seekable, NULL, NULL);
1061 if (format == GST_FORMAT_TIME) {
1062 GST_DEBUG ("Got seekable %d", seekable);
1063 dc->priv->current_info->seekable = seekable;
1069 if (dc->priv->current_topology)
1070 dc->priv->current_info->stream_info = parse_stream_topology (dc,
1071 dc->priv->current_topology, NULL);
1074 * Images need some special handling. They do not have a duration, have
1075 * caps named image/<foo> (th exception being MJPEG video which is also
1076 * type image/jpeg), and should consist of precisely one stream (actually
1077 * initially there are 2, the image and raw stream, but we squash these
1078 * while parsing the stream topology). At some point, if we find that these
1079 * conditions are not sufficient, we can count the number of decoders and
1080 * parsers in the chain, and if there's more than one decoder, or any
1081 * parser at all, we should not mark this as an image.
1083 if (dc->priv->current_info->duration == 0 &&
1084 dc->priv->current_info->stream_info != NULL &&
1085 dc->priv->current_info->stream_info->next == NULL) {
1087 gst_caps_get_structure (dc->priv->current_info->stream_info->caps, 0);
1089 if (g_str_has_prefix (gst_structure_get_name (st), "image/"))
1090 ((GstDiscovererVideoInfo *) dc->priv->current_info->
1091 stream_info)->is_image = TRUE;
1095 if (dc->priv->async) {
1096 GST_DEBUG ("Emitting 'discoverered'");
1097 g_signal_emit (dc, gst_discoverer_signals[SIGNAL_DISCOVERED], 0,
1098 dc->priv->current_info, dc->priv->current_error);
1099 /* Clients get a copy of current_info since it is a boxed type */
1100 gst_discoverer_info_unref (dc->priv->current_info);
1105 get_async_cb (gpointer cb_data, GSource * source, GSourceFunc * func,
1108 *func = (GSourceFunc) async_timeout_cb;
1112 /* Wrapper since GSourceCallbackFuncs don't expect a return value from ref() */
1114 _void_g_object_ref (gpointer object)
1116 g_object_ref (G_OBJECT (object));
1120 handle_current_async (GstDiscoverer * dc)
1123 static GSourceCallbackFuncs cb_funcs = {
1129 /* Attach a timeout to the main context */
1130 source = g_timeout_source_new (dc->priv->timeout / GST_MSECOND);
1131 g_source_set_callback_indirect (source, g_object_ref (dc), &cb_funcs);
1132 dc->priv->timeoutid = g_source_attach (source, dc->priv->ctx);
1133 g_source_unref (source);
1137 /* Returns TRUE if processing should stop */
1139 handle_message (GstDiscoverer * dc, GstMessage * msg)
1141 gboolean done = FALSE;
1143 GST_DEBUG_OBJECT (GST_MESSAGE_SRC (msg), "got a %s message",
1144 GST_MESSAGE_TYPE_NAME (msg));
1146 switch (GST_MESSAGE_TYPE (msg)) {
1147 case GST_MESSAGE_ERROR:{
1151 gst_message_parse_error (msg, &gerr, &debug);
1152 GST_WARNING_OBJECT (GST_MESSAGE_SRC (msg),
1153 "Got an error [debug:%s], [message:%s]", debug, gerr->message);
1154 dc->priv->current_error = gerr;
1157 /* We need to stop */
1160 GST_DEBUG ("Setting result to ERROR");
1161 dc->priv->current_info->result = GST_DISCOVERER_ERROR;
1165 case GST_MESSAGE_EOS:
1166 GST_DEBUG ("Got EOS !");
1170 case GST_MESSAGE_ASYNC_DONE:
1171 if (GST_MESSAGE_SRC (msg) == (GstObject *) dc->priv->pipeline) {
1172 GST_DEBUG ("Finished changing state asynchronously");
1178 case GST_MESSAGE_ELEMENT:
1181 const GstStructure *structure;
1183 structure = gst_message_get_structure (msg);
1184 sttype = gst_structure_get_name_id (structure);
1185 GST_DEBUG_OBJECT (GST_MESSAGE_SRC (msg),
1186 "structure %" GST_PTR_FORMAT, structure);
1187 if (sttype == _MISSING_PLUGIN_QUARK) {
1188 GST_DEBUG_OBJECT (GST_MESSAGE_SRC (msg),
1189 "Setting result to MISSING_PLUGINS");
1190 dc->priv->current_info->result = GST_DISCOVERER_MISSING_PLUGINS;
1191 if (dc->priv->current_info->misc)
1192 gst_structure_free (dc->priv->current_info->misc);
1193 dc->priv->current_info->misc = gst_structure_copy (structure);
1194 } else if (sttype == _STREAM_TOPOLOGY_QUARK) {
1195 if (dc->priv->current_topology)
1196 gst_structure_free (dc->priv->current_topology);
1197 dc->priv->current_topology = gst_structure_copy (structure);
1202 case GST_MESSAGE_TAG:
1204 GstTagList *tl, *tmp;
1206 gst_message_parse_tag (msg, &tl);
1207 GST_DEBUG_OBJECT (GST_MESSAGE_SRC (msg), "Got tags %" GST_PTR_FORMAT, tl);
1208 /* Merge with current tags */
1210 gst_tag_list_merge (dc->priv->current_info->tags, tl,
1211 GST_TAG_MERGE_APPEND);
1212 gst_tag_list_free (tl);
1213 if (dc->priv->current_info->tags)
1214 gst_tag_list_free (dc->priv->current_info->tags);
1215 dc->priv->current_info->tags = tmp;
1216 GST_DEBUG_OBJECT (GST_MESSAGE_SRC (msg), "Current info %p, tags %"
1217 GST_PTR_FORMAT, dc->priv->current_info, tmp);
1230 handle_current_sync (GstDiscoverer * dc)
1233 gdouble deadline = ((gdouble) dc->priv->timeout) / GST_SECOND;
1235 gboolean done = FALSE;
1237 timer = g_timer_new ();
1238 g_timer_start (timer);
1241 /* poll bus with timeout */
1242 /* FIXME : make the timeout more fine-tuned */
1243 if ((msg = gst_bus_timed_pop (dc->priv->bus, GST_SECOND / 2))) {
1244 done = handle_message (dc, msg);
1245 gst_message_unref (msg);
1247 } while (!done && (g_timer_elapsed (timer, NULL) < deadline));
1251 GST_DEBUG ("we timed out! Setting result to TIMEOUT");
1252 dc->priv->current_info->result = GST_DISCOVERER_TIMEOUT;
1257 g_timer_stop (timer);
1258 g_timer_destroy (timer);
1262 _setup_locked (GstDiscoverer * dc)
1264 GstStateChangeReturn ret;
1266 GST_DEBUG ("Setting up");
1268 /* Pop URI off the pending URI list */
1269 dc->priv->current_info =
1270 (GstDiscovererInfo *) g_object_new (GST_TYPE_DISCOVERER_INFO, NULL);
1271 dc->priv->current_info->uri = (gchar *) dc->priv->pending_uris->data;
1272 dc->priv->pending_uris =
1273 g_list_delete_link (dc->priv->pending_uris, dc->priv->pending_uris);
1275 /* set uri on uridecodebin */
1276 g_object_set (dc->priv->uridecodebin, "uri", dc->priv->current_info->uri,
1279 GST_DEBUG ("Current is now %s", dc->priv->current_info->uri);
1281 dc->priv->processing = TRUE;
1283 /* set pipeline to PAUSED */
1285 GST_DEBUG ("Setting pipeline to PAUSED");
1287 gst_element_set_state ((GstElement *) dc->priv->pipeline,
1291 GST_DEBUG_OBJECT (dc, "Pipeline going to PAUSED : %s",
1292 gst_element_state_change_return_get_name (ret));
1296 discoverer_cleanup (GstDiscoverer * dc)
1298 GST_DEBUG ("Cleaning up");
1300 gst_bus_set_flushing (dc->priv->bus, TRUE);
1301 gst_element_set_state ((GstElement *) dc->priv->pipeline, GST_STATE_READY);
1302 gst_bus_set_flushing (dc->priv->bus, FALSE);
1305 if (dc->priv->current_error)
1306 g_error_free (dc->priv->current_error);
1307 dc->priv->current_error = NULL;
1308 if (dc->priv->current_topology) {
1309 gst_structure_free (dc->priv->current_topology);
1310 dc->priv->current_topology = NULL;
1313 dc->priv->current_info = NULL;
1315 /* Try popping the next uri */
1316 if (dc->priv->async) {
1317 if (dc->priv->pending_uris != NULL) {
1321 handle_current_async (dc);
1325 g_signal_emit (dc, gst_discoverer_signals[SIGNAL_FINISHED], 0);
1334 discoverer_bus_cb (GstBus * bus, GstMessage * msg, GstDiscoverer * dc)
1336 if (dc->priv->processing) {
1337 if (handle_message (dc, msg)) {
1338 GST_DEBUG ("Stopping asynchronously");
1339 /* Serialise with _event_probe() */
1341 dc->priv->processing = FALSE;
1343 discoverer_collect (dc);
1344 discoverer_cleanup (dc);
1350 async_timeout_cb (GstDiscoverer * dc)
1352 if (!g_source_is_destroyed (g_main_current_source ())) {
1353 dc->priv->timeoutid = 0;
1354 GST_DEBUG ("Setting result to TIMEOUT");
1355 dc->priv->current_info->result = GST_DISCOVERER_TIMEOUT;
1356 dc->priv->processing = FALSE;
1357 discoverer_collect (dc);
1358 discoverer_cleanup (dc);
1363 /* If there is a pending URI, it will pop it from the list of pending
1364 * URIs and start the discovery on it.
1366 * Returns GST_DISCOVERER_OK if the next URI was popped and is processing,
1367 * else a error flag.
1369 static GstDiscovererResult
1370 start_discovering (GstDiscoverer * dc)
1372 GstDiscovererResult res = GST_DISCOVERER_OK;
1374 GST_DEBUG ("Starting");
1377 if (dc->priv->pending_uris == NULL) {
1378 GST_WARNING ("No URI to process");
1379 res = GST_DISCOVERER_URI_INVALID;
1384 if (dc->priv->current_info != NULL) {
1385 GST_WARNING ("Already processing a file");
1386 res = GST_DISCOVERER_BUSY;
1391 g_signal_emit (dc, gst_discoverer_signals[SIGNAL_STARTING], 0);
1397 if (dc->priv->async)
1398 handle_current_async (dc);
1400 handle_current_sync (dc);
1408 * gst_discoverer_start:
1409 * @discoverer: A #GstDiscoverer
1411 * Allow asynchronous discovering of URIs to take place.
1412 * A #GMainLoop must be available for #GstDiscoverer to properly work in
1413 * asynchronous mode.
1418 gst_discoverer_start (GstDiscoverer * discoverer)
1421 GMainContext *ctx = NULL;
1423 GST_DEBUG_OBJECT (discoverer, "Starting...");
1425 if (discoverer->priv->async) {
1426 GST_DEBUG_OBJECT (discoverer, "We were already started");
1430 discoverer->priv->async = TRUE;
1431 discoverer->priv->running = TRUE;
1433 ctx = g_main_context_get_thread_default ();
1435 /* Connect to bus signals */
1437 ctx = g_main_context_default ();
1439 source = gst_bus_create_watch (discoverer->priv->bus);
1440 g_source_set_callback (source, (GSourceFunc) gst_bus_async_signal_func,
1442 discoverer->priv->sourceid = g_source_attach (source, ctx);
1443 g_source_unref (source);
1444 discoverer->priv->ctx = g_main_context_ref (ctx);
1446 start_discovering (discoverer);
1447 GST_DEBUG_OBJECT (discoverer, "Started");
1451 * gst_discoverer_stop:
1452 * @discoverer: A #GstDiscoverer
1454 * Stop the discovery of any pending URIs and clears the list of
1455 * pending URIS (if any).
1460 gst_discoverer_stop (GstDiscoverer * discoverer)
1462 GST_DEBUG_OBJECT (discoverer, "Stopping...");
1464 if (!discoverer->priv->async) {
1465 GST_DEBUG_OBJECT (discoverer,
1466 "We were already stopped, or running synchronously");
1470 DISCO_LOCK (discoverer);
1471 if (discoverer->priv->processing) {
1472 /* We prevent any further processing by setting the bus to
1473 * flushing and setting the pipeline to READY.
1474 * _reset() will take care of the rest of the cleanup */
1475 if (discoverer->priv->bus)
1476 gst_bus_set_flushing (discoverer->priv->bus, TRUE);
1477 if (discoverer->priv->pipeline)
1478 gst_element_set_state ((GstElement *) discoverer->priv->pipeline,
1481 discoverer->priv->running = FALSE;
1482 DISCO_UNLOCK (discoverer);
1484 /* Remove timeout handler */
1485 if (discoverer->priv->timeoutid) {
1486 g_source_remove (discoverer->priv->timeoutid);
1487 discoverer->priv->timeoutid = 0;
1489 /* Remove signal watch */
1490 if (discoverer->priv->sourceid) {
1491 g_source_remove (discoverer->priv->sourceid);
1492 discoverer->priv->sourceid = 0;
1494 /* Unref main context */
1495 if (discoverer->priv->ctx) {
1496 g_main_context_unref (discoverer->priv->ctx);
1497 discoverer->priv->ctx = NULL;
1499 discoverer_reset (discoverer);
1501 discoverer->priv->async = FALSE;
1503 GST_DEBUG_OBJECT (discoverer, "Stopped");
1507 * gst_discoverer_discover_uri_async:
1508 * @discoverer: A #GstDiscoverer
1509 * @uri: the URI to add.
1511 * Appends the given @uri to the list of URIs to discoverer. The actual
1512 * discovery of the @uri will only take place if gst_discoverer_start() has
1515 * A copy of @uri will be made internally, so the caller can safely g_free()
1518 * Returns: %TRUE if the @uri was successfully appended to the list of pending
1524 gst_discoverer_discover_uri_async (GstDiscoverer * discoverer,
1529 GST_DEBUG_OBJECT (discoverer, "uri : %s", uri);
1531 DISCO_LOCK (discoverer);
1532 can_run = (discoverer->priv->pending_uris == NULL);
1533 discoverer->priv->pending_uris =
1534 g_list_append (discoverer->priv->pending_uris, g_strdup (uri));
1535 DISCO_UNLOCK (discoverer);
1538 start_discovering (discoverer);
1544 /* Synchronous mode */
1546 * gst_discoverer_discover_uri:
1547 * @discoverer: A #GstDiscoverer
1548 * @uri: The URI to run on.
1549 * @err: (out) (allow-none): If an error occurred, this field will be filled in.
1551 * Synchronously discovers the given @uri.
1553 * A copy of @uri will be made internally, so the caller can safely g_free()
1556 * Returns: (transfer full): the result of the scanning. Can be %NULL if an
1562 gst_discoverer_discover_uri (GstDiscoverer * discoverer, const gchar * uri,
1565 GstDiscovererResult res = 0;
1566 GstDiscovererInfo *info;
1568 GST_DEBUG_OBJECT (discoverer, "uri:%s", uri);
1570 DISCO_LOCK (discoverer);
1571 if (G_UNLIKELY (discoverer->priv->current_info)) {
1572 DISCO_UNLOCK (discoverer);
1573 GST_WARNING_OBJECT (discoverer, "Already handling a uri");
1577 discoverer->priv->pending_uris =
1578 g_list_append (discoverer->priv->pending_uris, g_strdup (uri));
1579 DISCO_UNLOCK (discoverer);
1581 res = start_discovering (discoverer);
1582 discoverer_collect (discoverer);
1586 if (discoverer->priv->current_error)
1587 *err = g_error_copy (discoverer->priv->current_error);
1591 if (res != GST_DISCOVERER_OK) {
1592 GST_DEBUG ("Setting result to %d (was %d)", res,
1593 discoverer->priv->current_info->result);
1594 discoverer->priv->current_info->result = res;
1596 info = discoverer->priv->current_info;
1598 discoverer_cleanup (discoverer);
1604 * gst_discoverer_new:
1605 * @timeout: timeout per file, in nanoseconds. Allowed are values between
1606 * one second (#GST_SECOND) and one hour (3600 * #GST_SECOND)
1607 * @err: a pointer to a #GError. can be %NULL
1609 * Creates a new #GstDiscoverer with the provided timeout.
1611 * Returns: (transfer full): The new #GstDiscoverer.
1612 * If an error occurred when creating the discoverer, @err will be set
1613 * accordingly and %NULL will be returned. If @err is set, the caller must
1614 * free it when no longer needed using g_error_free().
1619 gst_discoverer_new (GstClockTime timeout, GError ** err)
1623 res = g_object_new (GST_TYPE_DISCOVERER, "timeout", timeout, NULL);
1624 if (res->priv->uridecodebin == NULL) {
1626 *err = g_error_new (GST_CORE_ERROR, GST_CORE_ERROR_MISSING_PLUGIN,
1627 "Couldn't create 'uridecodebin' element");
1628 gst_object_unref (res);