1 /* GStreamer
2  * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <locale.h>
25 
26 #include <stdlib.h>
27 #include <glib.h>
28 #include <gst/gst.h>
29 #include <gst/pbutils/pbutils.h>
30 #include <gst/audio/audio.h>
31 
32 #define MAX_INDENT 40
33 
34 /* *INDENT-OFF* */
35 static void my_g_string_append_printf (GString * str, int depth, const gchar * format, ...) G_GNUC_PRINTF (3, 4);
36 /* *INDENT-ON* */
37 
38 static gboolean async = FALSE;
39 static gboolean show_toc = FALSE;
40 static gboolean verbose = FALSE;
41 
42 typedef struct
43 {
44   GstDiscoverer *dc;
45   int argc;
46   char **argv;
47 } PrivStruct;
48 
49 static void
my_g_string_append_printf(GString * str,int depth,const gchar * format,...)50 my_g_string_append_printf (GString * str, int depth, const gchar * format, ...)
51 {
52   va_list args;
53 
54   while (depth-- > 0) {
55     g_string_append (str, "  ");
56   }
57 
58   va_start (args, format);
59   g_string_append_vprintf (str, format, args);
60   va_end (args);
61 }
62 
63 static void
gst_stream_information_to_string(GstDiscovererStreamInfo * info,GString * s,guint depth)64 gst_stream_information_to_string (GstDiscovererStreamInfo * info, GString * s,
65     guint depth)
66 {
67   gchar *tmp;
68   GstCaps *caps;
69 #ifndef GST_DISABLE_DEPRECATED
70   const GstStructure *misc;
71 #endif
72 
73   my_g_string_append_printf (s, depth, "Codec:\n");
74   caps = gst_discoverer_stream_info_get_caps (info);
75   tmp = gst_caps_to_string (caps);
76   gst_caps_unref (caps);
77   my_g_string_append_printf (s, depth, "  %s\n", tmp);
78   g_free (tmp);
79 
80 #ifndef GST_DISABLE_DEPRECATED
81   my_g_string_append_printf (s, depth, "Additional info:\n");
82   if ((misc = gst_discoverer_stream_info_get_misc (info))) {
83     tmp = gst_structure_to_string (misc);
84     my_g_string_append_printf (s, depth, "  %s\n", tmp);
85     g_free (tmp);
86   } else {
87     my_g_string_append_printf (s, depth, "  None\n");
88   }
89 #endif
90 
91   my_g_string_append_printf (s, depth, "Stream ID: %s\n",
92       gst_discoverer_stream_info_get_stream_id (info));
93 }
94 
95 static void
print_tag_foreach(const GstTagList * tags,const gchar * tag,gpointer user_data)96 print_tag_foreach (const GstTagList * tags, const gchar * tag,
97     gpointer user_data)
98 {
99   GValue val = { 0, };
100   gchar *str;
101   guint depth = GPOINTER_TO_UINT (user_data);
102 
103   if (!gst_tag_list_copy_value (&val, tags, tag))
104     return;
105 
106   if (G_VALUE_HOLDS_STRING (&val)) {
107     str = g_value_dup_string (&val);
108   } else if (G_VALUE_TYPE (&val) == GST_TYPE_SAMPLE) {
109     GstSample *sample = gst_value_get_sample (&val);
110     GstBuffer *img = gst_sample_get_buffer (sample);
111     GstCaps *caps = gst_sample_get_caps (sample);
112 
113     if (img) {
114       if (caps) {
115         gchar *caps_str;
116 
117         caps_str = gst_caps_to_string (caps);
118         str = g_strdup_printf ("buffer of %" G_GSIZE_FORMAT " bytes, "
119             "type: %s", gst_buffer_get_size (img), caps_str);
120         g_free (caps_str);
121       } else {
122         str = g_strdup_printf ("buffer of %" G_GSIZE_FORMAT " bytes",
123             gst_buffer_get_size (img));
124       }
125     } else {
126       str = g_strdup ("NULL buffer");
127     }
128   } else {
129     str = gst_value_serialize (&val);
130   }
131 
132   g_print ("%*s%s: %s\n", 2 * depth, " ", gst_tag_get_nick (tag), str);
133   g_free (str);
134 
135   g_value_unset (&val);
136 }
137 
138 static void
print_tags_topology(guint depth,const GstTagList * tags)139 print_tags_topology (guint depth, const GstTagList * tags)
140 {
141   g_print ("%*sTags:\n", 2 * depth, " ");
142   if (tags) {
143     gst_tag_list_foreach (tags, print_tag_foreach,
144         GUINT_TO_POINTER (depth + 1));
145   } else {
146     g_print ("%*sNone\n", 2 * (depth + 1), " ");
147   }
148   if (verbose)
149     g_print ("%*s\n", 2 * depth, " ");
150 }
151 
152 static gchar *
format_channel_mask(GstDiscovererAudioInfo * ainfo)153 format_channel_mask (GstDiscovererAudioInfo * ainfo)
154 {
155   GString *s = g_string_sized_new (32);
156   GstAudioChannelPosition position[64];
157   guint channels = gst_discoverer_audio_info_get_channels (ainfo);
158   GEnumClass *enum_class = g_type_class_ref (GST_TYPE_AUDIO_CHANNEL_POSITION);
159   guint i;
160   guint64 channel_mask;
161 
162   if (channels == 0)
163     goto done;
164 
165   channel_mask = gst_discoverer_audio_info_get_channel_mask (ainfo);
166 
167   if (channel_mask != 0) {
168     gst_audio_channel_positions_from_mask (channels, channel_mask, position);
169 
170     for (i = 0; i < channels; i++) {
171       GEnumValue *value = g_enum_get_value (enum_class, position[i]);
172       my_g_string_append_printf (s, 0, "%s%s", value->value_nick,
173           i + 1 == channels ? "" : ", ");
174     }
175   } else {
176     g_string_append (s, "unknown layout");
177   }
178 
179   g_type_class_unref (enum_class);
180 
181 done:
182   return g_string_free (s, FALSE);
183 }
184 
185 static gchar *
gst_stream_audio_information_to_string(GstDiscovererStreamInfo * info,guint depth)186 gst_stream_audio_information_to_string (GstDiscovererStreamInfo * info,
187     guint depth)
188 {
189   GstDiscovererAudioInfo *audio_info;
190   GString *s;
191   const gchar *ctmp;
192   int len = 400;
193   const GstTagList *tags;
194   gchar *channel_positions;
195 
196   g_return_val_if_fail (info != NULL, NULL);
197 
198   s = g_string_sized_new (len);
199 
200   gst_stream_information_to_string (info, s, depth);
201 
202   audio_info = (GstDiscovererAudioInfo *) info;
203   ctmp = gst_discoverer_audio_info_get_language (audio_info);
204   my_g_string_append_printf (s, depth, "Language: %s\n",
205       ctmp ? ctmp : "<unknown>");
206 
207   channel_positions = format_channel_mask (audio_info);
208   my_g_string_append_printf (s, depth, "Channels: %u (%s)\n",
209       gst_discoverer_audio_info_get_channels (audio_info), channel_positions);
210   g_free (channel_positions);
211 
212   my_g_string_append_printf (s, depth, "Sample rate: %u\n",
213       gst_discoverer_audio_info_get_sample_rate (audio_info));
214   my_g_string_append_printf (s, depth, "Depth: %u\n",
215       gst_discoverer_audio_info_get_depth (audio_info));
216 
217   my_g_string_append_printf (s, depth, "Bitrate: %u\n",
218       gst_discoverer_audio_info_get_bitrate (audio_info));
219   my_g_string_append_printf (s, depth, "Max bitrate: %u\n",
220       gst_discoverer_audio_info_get_max_bitrate (audio_info));
221 
222   tags = gst_discoverer_stream_info_get_tags (info);
223   print_tags_topology (depth, tags);
224 
225   return g_string_free (s, FALSE);
226 }
227 
228 static gchar *
gst_stream_video_information_to_string(GstDiscovererStreamInfo * info,guint depth)229 gst_stream_video_information_to_string (GstDiscovererStreamInfo * info,
230     guint depth)
231 {
232   GstDiscovererVideoInfo *video_info;
233   GString *s;
234   int len = 500;
235   const GstTagList *tags;
236 
237   g_return_val_if_fail (info != NULL, NULL);
238 
239   s = g_string_sized_new (len);
240 
241   gst_stream_information_to_string (info, s, depth);
242 
243   video_info = (GstDiscovererVideoInfo *) info;
244   my_g_string_append_printf (s, depth, "Width: %u\n",
245       gst_discoverer_video_info_get_width (video_info));
246   my_g_string_append_printf (s, depth, "Height: %u\n",
247       gst_discoverer_video_info_get_height (video_info));
248   my_g_string_append_printf (s, depth, "Depth: %u\n",
249       gst_discoverer_video_info_get_depth (video_info));
250 
251   my_g_string_append_printf (s, depth, "Frame rate: %u/%u\n",
252       gst_discoverer_video_info_get_framerate_num (video_info),
253       gst_discoverer_video_info_get_framerate_denom (video_info));
254 
255   my_g_string_append_printf (s, depth, "Pixel aspect ratio: %u/%u\n",
256       gst_discoverer_video_info_get_par_num (video_info),
257       gst_discoverer_video_info_get_par_denom (video_info));
258 
259   my_g_string_append_printf (s, depth, "Interlaced: %s\n",
260       gst_discoverer_video_info_is_interlaced (video_info) ? "true" : "false");
261 
262   my_g_string_append_printf (s, depth, "Bitrate: %u\n",
263       gst_discoverer_video_info_get_bitrate (video_info));
264   my_g_string_append_printf (s, depth, "Max bitrate: %u\n",
265       gst_discoverer_video_info_get_max_bitrate (video_info));
266 
267   tags = gst_discoverer_stream_info_get_tags (info);
268   print_tags_topology (depth, tags);
269 
270   return g_string_free (s, FALSE);
271 }
272 
273 static gchar *
gst_stream_subtitle_information_to_string(GstDiscovererStreamInfo * info,guint depth)274 gst_stream_subtitle_information_to_string (GstDiscovererStreamInfo * info,
275     guint depth)
276 {
277   GstDiscovererSubtitleInfo *subtitle_info;
278   GString *s;
279   const gchar *ctmp;
280   int len = 400;
281   const GstTagList *tags;
282 
283   g_return_val_if_fail (info != NULL, NULL);
284 
285   s = g_string_sized_new (len);
286 
287   gst_stream_information_to_string (info, s, depth);
288 
289   subtitle_info = (GstDiscovererSubtitleInfo *) info;
290   ctmp = gst_discoverer_subtitle_info_get_language (subtitle_info);
291   my_g_string_append_printf (s, depth, "Language: %s\n",
292       ctmp ? ctmp : "<unknown>");
293 
294   tags = gst_discoverer_stream_info_get_tags (info);
295   print_tags_topology (depth, tags);
296 
297   return g_string_free (s, FALSE);
298 }
299 
300 static void
print_stream_info(GstDiscovererStreamInfo * info,void * depth)301 print_stream_info (GstDiscovererStreamInfo * info, void *depth)
302 {
303   gchar *desc = NULL;
304   GstCaps *caps;
305 
306   caps = gst_discoverer_stream_info_get_caps (info);
307 
308   if (caps) {
309     if (gst_caps_is_fixed (caps) && !verbose)
310       desc = gst_pb_utils_get_codec_description (caps);
311     else
312       desc = gst_caps_to_string (caps);
313     gst_caps_unref (caps);
314   }
315 
316   g_print ("%*s%s: %s\n", 2 * GPOINTER_TO_INT (depth), " ",
317       gst_discoverer_stream_info_get_stream_type_nick (info), desc);
318 
319   if (desc) {
320     g_free (desc);
321     desc = NULL;
322   }
323 
324   if (verbose) {
325     if (GST_IS_DISCOVERER_AUDIO_INFO (info))
326       desc =
327           gst_stream_audio_information_to_string (info,
328           GPOINTER_TO_INT (depth) + 1);
329     else if (GST_IS_DISCOVERER_VIDEO_INFO (info))
330       desc =
331           gst_stream_video_information_to_string (info,
332           GPOINTER_TO_INT (depth) + 1);
333     else if (GST_IS_DISCOVERER_SUBTITLE_INFO (info))
334       desc =
335           gst_stream_subtitle_information_to_string (info,
336           GPOINTER_TO_INT (depth) + 1);
337     if (desc) {
338       g_print ("%s", desc);
339       g_free (desc);
340     }
341   }
342 }
343 
344 static void
print_topology(GstDiscovererStreamInfo * info,guint depth)345 print_topology (GstDiscovererStreamInfo * info, guint depth)
346 {
347   GstDiscovererStreamInfo *next;
348 
349   if (!info)
350     return;
351 
352   print_stream_info (info, GINT_TO_POINTER (depth));
353 
354   next = gst_discoverer_stream_info_get_next (info);
355   if (next) {
356     print_topology (next, depth + 1);
357     gst_discoverer_stream_info_unref (next);
358   } else if (GST_IS_DISCOVERER_CONTAINER_INFO (info)) {
359     GList *tmp, *streams;
360 
361     streams =
362         gst_discoverer_container_info_get_streams (GST_DISCOVERER_CONTAINER_INFO
363         (info));
364     for (tmp = streams; tmp; tmp = tmp->next) {
365       GstDiscovererStreamInfo *tmpinf = (GstDiscovererStreamInfo *) tmp->data;
366       print_topology (tmpinf, depth + 1);
367     }
368     gst_discoverer_stream_info_list_free (streams);
369   }
370 }
371 
372 static void
print_toc_entry(gpointer data,gpointer user_data)373 print_toc_entry (gpointer data, gpointer user_data)
374 {
375   GstTocEntry *entry = (GstTocEntry *) data;
376   guint depth = GPOINTER_TO_UINT (user_data);
377   guint indent = MIN (GPOINTER_TO_UINT (user_data), MAX_INDENT);
378   GstTagList *tags;
379   GList *subentries;
380   gint64 start, stop;
381 
382   gst_toc_entry_get_start_stop_times (entry, &start, &stop);
383   g_print ("%*s%s: start: %" GST_TIME_FORMAT " stop: %" GST_TIME_FORMAT "\n",
384       depth, " ",
385       gst_toc_entry_type_get_nick (gst_toc_entry_get_entry_type (entry)),
386       GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
387   indent += 2;
388 
389   /* print tags */
390   tags = gst_toc_entry_get_tags (entry);
391   if (tags) {
392     g_print ("%*sTags:\n", 2 * depth, " ");
393     gst_tag_list_foreach (tags, print_tag_foreach, GUINT_TO_POINTER (indent));
394   }
395 
396   /* loop over sub-toc entries */
397   subentries = gst_toc_entry_get_sub_entries (entry);
398   g_list_foreach (subentries, print_toc_entry, GUINT_TO_POINTER (indent));
399 }
400 
401 static void
print_properties(GstDiscovererInfo * info,gint tab)402 print_properties (GstDiscovererInfo * info, gint tab)
403 {
404   const GstTagList *tags;
405   const GstToc *toc;
406 
407   g_print ("%*sDuration: %" GST_TIME_FORMAT "\n", tab + 1, " ",
408       GST_TIME_ARGS (gst_discoverer_info_get_duration (info)));
409   g_print ("%*sSeekable: %s\n", tab + 1, " ",
410       (gst_discoverer_info_get_seekable (info) ? "yes" : "no"));
411   g_print ("%*sLive: %s\n", tab + 1, " ",
412       (gst_discoverer_info_get_live (info) ? "yes" : "no"));
413   if ((tags = gst_discoverer_info_get_tags (info))) {
414     g_print ("%*sTags: \n", tab + 1, " ");
415     gst_tag_list_foreach (tags, print_tag_foreach, GUINT_TO_POINTER (tab + 2));
416   }
417   if (show_toc && (toc = gst_discoverer_info_get_toc (info))) {
418     GList *entries;
419 
420     g_print ("%*sTOC: \n", tab + 1, " ");
421     entries = gst_toc_get_entries (toc);
422     g_list_foreach (entries, print_toc_entry, GUINT_TO_POINTER (tab + 5));
423   }
424 }
425 
426 static void
print_info(GstDiscovererInfo * info,GError * err)427 print_info (GstDiscovererInfo * info, GError * err)
428 {
429   GstDiscovererResult result;
430   GstDiscovererStreamInfo *sinfo;
431 
432   if (!info) {
433     g_print ("Could not discover URI\n");
434     g_print (" %s\n", err->message);
435     return;
436   }
437 
438   result = gst_discoverer_info_get_result (info);
439   g_print ("Done discovering %s\n", gst_discoverer_info_get_uri (info));
440   switch (result) {
441     case GST_DISCOVERER_OK:
442     {
443       break;
444     }
445     case GST_DISCOVERER_URI_INVALID:
446     {
447       g_print ("URI is not valid\n");
448       break;
449     }
450     case GST_DISCOVERER_ERROR:
451     {
452       g_print ("An error was encountered while discovering the file\n");
453       g_print (" %s\n", err->message);
454       break;
455     }
456     case GST_DISCOVERER_TIMEOUT:
457     {
458       g_print ("Analyzing URI timed out\n");
459       break;
460     }
461     case GST_DISCOVERER_BUSY:
462     {
463       g_print ("Discoverer was busy\n");
464       break;
465     }
466     case GST_DISCOVERER_MISSING_PLUGINS:
467     {
468       g_print ("Missing plugins\n");
469       if (verbose) {
470         gint i = 0;
471         const gchar **installer_details =
472             gst_discoverer_info_get_missing_elements_installer_details (info);
473 
474         while (installer_details[i]) {
475           g_print (" (%s)\n", installer_details[i]);
476 
477           i++;
478         }
479       }
480       break;
481     }
482   }
483 
484   if ((sinfo = gst_discoverer_info_get_stream_info (info))) {
485     g_print ("\nTopology:\n");
486     print_topology (sinfo, 1);
487     g_print ("\nProperties:\n");
488     print_properties (info, 1);
489     gst_discoverer_stream_info_unref (sinfo);
490   }
491 
492   g_print ("\n");
493 }
494 
495 static void
process_file(GstDiscoverer * dc,const gchar * filename)496 process_file (GstDiscoverer * dc, const gchar * filename)
497 {
498   GError *err = NULL;
499   GDir *dir;
500   gchar *uri, *path;
501   GstDiscovererInfo *info;
502 
503   if (!gst_uri_is_valid (filename)) {
504     /* Recurse into directories */
505     if ((dir = g_dir_open (filename, 0, NULL))) {
506       const gchar *entry;
507 
508       while ((entry = g_dir_read_name (dir))) {
509         gchar *path;
510         path = g_strconcat (filename, G_DIR_SEPARATOR_S, entry, NULL);
511         process_file (dc, path);
512         g_free (path);
513       }
514 
515       g_dir_close (dir);
516       return;
517     }
518 
519     if (!g_path_is_absolute (filename)) {
520       gchar *cur_dir;
521 
522       cur_dir = g_get_current_dir ();
523       path = g_build_filename (cur_dir, filename, NULL);
524       g_free (cur_dir);
525     } else {
526       path = g_strdup (filename);
527     }
528 
529     uri = g_filename_to_uri (path, NULL, &err);
530     g_free (path);
531     path = NULL;
532 
533     if (err) {
534       g_warning ("Couldn't convert filename to URI: %s\n", err->message);
535       g_clear_error (&err);
536       return;
537     }
538   } else {
539     uri = g_strdup (filename);
540   }
541 
542   if (!async) {
543     g_print ("Analyzing %s\n", uri);
544     info = gst_discoverer_discover_uri (dc, uri, &err);
545     print_info (info, err);
546     g_clear_error (&err);
547     if (info)
548       gst_discoverer_info_unref (info);
549   } else {
550     gst_discoverer_discover_uri_async (dc, uri);
551   }
552 
553   g_free (uri);
554 }
555 
556 static void
_new_discovered_uri(GstDiscoverer * dc,GstDiscovererInfo * info,GError * err)557 _new_discovered_uri (GstDiscoverer * dc, GstDiscovererInfo * info, GError * err)
558 {
559   print_info (info, err);
560 }
561 
562 static gboolean
_run_async(PrivStruct * ps)563 _run_async (PrivStruct * ps)
564 {
565   gint i;
566 
567   for (i = 1; i < ps->argc; i++)
568     process_file (ps->dc, ps->argv[i]);
569 
570   return FALSE;
571 }
572 
573 static void
_discoverer_finished(GstDiscoverer * dc,GMainLoop * ml)574 _discoverer_finished (GstDiscoverer * dc, GMainLoop * ml)
575 {
576   g_main_loop_quit (ml);
577 }
578 
579 int
main(int argc,char ** argv)580 main (int argc, char **argv)
581 {
582   GError *err = NULL;
583   GstDiscoverer *dc;
584   gint timeout = 10;
585   gboolean use_cache = FALSE, print_cache_dir = FALSE;
586   GOptionEntry options[] = {
587     {"async", 'a', 0, G_OPTION_ARG_NONE, &async,
588         "Run asynchronously", NULL},
589     {"use-cache", 'a', 0, G_OPTION_ARG_NONE, &use_cache,
590         "Use GstDiscovererInfo from our cache.", NULL},
591     {"print-cache-dir", 0, 0, G_OPTION_ARG_NONE, &print_cache_dir,
592         "Print the directory of the discoverer cache.", NULL},
593     {"timeout", 't', 0, G_OPTION_ARG_INT, &timeout,
594         "Specify timeout (in seconds, default 10)", "T"},
595     /* {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek, */
596     /*     "Seek on elements instead of pads", NULL}, */
597     {"toc", 'c', 0, G_OPTION_ARG_NONE, &show_toc,
598         "Output TOC (chapters and editions)", NULL},
599     {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
600         "Verbose properties", NULL},
601     {NULL}
602   };
603   GOptionContext *ctx;
604 
605   setlocale (LC_ALL, "");
606 
607   ctx =
608       g_option_context_new
609       ("- discover files synchronously with GstDiscoverer");
610   g_option_context_add_main_entries (ctx, options, NULL);
611   g_option_context_add_group (ctx, gst_init_get_option_group ());
612 
613   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
614     g_print ("Error initializing: %s\n", err->message);
615     g_option_context_free (ctx);
616     g_clear_error (&err);
617     exit (1);
618   }
619 
620   g_option_context_free (ctx);
621 
622   if (argc < 2) {
623     g_print ("usage: %s <uris>\n", argv[0]);
624     exit (-1);
625   }
626 
627   if (print_cache_dir) {
628     gchar *cache_dir =
629         g_build_filename (g_get_user_cache_dir (), "gstreamer-" GST_API_VERSION,
630         "discoverer", NULL);
631     g_print ("\nGstDiscoverer cache directory:\n\n    %s\n\n", cache_dir);
632     g_free (cache_dir);
633     exit (0);
634   }
635 
636   dc = gst_discoverer_new (timeout * GST_SECOND, &err);
637   if (G_UNLIKELY (dc == NULL)) {
638     g_print ("Error initializing: %s\n", err->message);
639     g_clear_error (&err);
640     exit (1);
641   }
642 
643   g_object_set (dc, "use-cache", use_cache, NULL);
644 
645   if (!async) {
646     gint i;
647     for (i = 1; i < argc; i++)
648       process_file (dc, argv[i]);
649   } else {
650     PrivStruct *ps = g_new0 (PrivStruct, 1);
651     GMainLoop *ml = g_main_loop_new (NULL, FALSE);
652 
653     ps->dc = dc;
654     ps->argc = argc;
655     ps->argv = argv;
656 
657     /* adding uris will be started when the mainloop runs */
658     g_idle_add ((GSourceFunc) _run_async, ps);
659 
660     /* connect signals */
661     g_signal_connect (dc, "discovered", G_CALLBACK (_new_discovered_uri), NULL);
662     g_signal_connect (dc, "finished", G_CALLBACK (_discoverer_finished), ml);
663 
664     gst_discoverer_start (dc);
665     /* run mainloop */
666     g_main_loop_run (ml);
667 
668     gst_discoverer_stop (dc);
669     g_free (ps);
670     g_main_loop_unref (ml);
671   }
672   g_object_unref (dc);
673 
674   return 0;
675 }
676