further i18n: call setlocale()
[platform/upstream/gstreamer.git] / tools / gst-typefind.c
1 #ifdef HAVE_CONFIG_H
2 #  include "config.h"
3 #endif
4
5 #include <string.h>
6 #include <stdlib.h>
7 #include <locale.h>
8 #include <gst/gst.h>
9
10 /*
11  * find the type of a media file and display it's properties
12  **/
13
14 gboolean FOUND = FALSE;
15
16 void
17 gst_caps_print (GstCaps *caps)
18 {
19   while (caps) {
20     g_print ("%s (%s)\n", caps->name, gst_caps_get_mime (caps));
21     if (caps->properties) {
22             g_print ("has properties\n");
23     }
24     caps = caps->next;
25   }
26 }
27
28 void
29 have_type_handler (GstElement *typefind, gpointer data)
30 {
31   GstCaps *caps = (GstCaps *) data;
32   gst_caps_print (caps);
33   FOUND = TRUE;
34 }
35
36 int
37 main (int argc, char *argv[])
38 {
39   GstElement *pipeline;
40   GstElement *source, *typefind;
41
42   setlocale (LC_ALL, "");
43
44   gst_init (&argc, &argv);
45
46   if (argc < 2) { 
47     g_print ("Please give a filename to typefind\n\n");
48     exit (1);
49   }
50   pipeline = gst_pipeline_new (NULL);
51   source = gst_element_factory_make ("filesrc", "source");
52   g_assert (GST_IS_ELEMENT (source));
53   g_object_set (source, "location", argv[1], NULL);
54   typefind = gst_element_factory_make ("typefind", "typefind");
55   g_assert (GST_IS_ELEMENT (typefind));
56   gst_bin_add_many (GST_BIN (pipeline), source, typefind, NULL);
57   gst_element_link (source, typefind);
58   g_signal_connect (G_OBJECT (typefind), "have-type", 
59                     G_CALLBACK (have_type_handler), NULL);
60
61   /* set to play */
62   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
63
64   while (gst_bin_iterate (GST_BIN (pipeline)) && !FOUND) ;
65   if (!FOUND) {
66     g_print ("No type found\n");
67     return 1;
68   }
69   return 0;
70 }