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