Use gst_caps_to_string to print caps. Add max_iterations.
[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 int iterations;
16 int max_iterations = 100;
17
18 void
19 gst_caps_print (GstCaps *caps)
20 {
21   g_print ("%s\n", gst_caps_to_string (caps));
22 }
23
24 void
25 have_type_handler (GstElement *typefind, gpointer data)
26 {
27   GstCaps *caps = (GstCaps *) data;
28   gst_caps_print (caps);
29   FOUND = TRUE;
30 }
31
32 int
33 main (int argc, char *argv[])
34 {
35   GstElement *pipeline;
36   GstElement *source, *typefind;
37
38   setlocale (LC_ALL, "");
39
40   gst_init (&argc, &argv);
41
42   if (argc < 2) { 
43     g_print ("Please give a filename to typefind\n\n");
44     exit (1);
45   }
46   pipeline = gst_pipeline_new (NULL);
47   source = gst_element_factory_make ("filesrc", "source");
48   g_assert (GST_IS_ELEMENT (source));
49   g_object_set (source, "location", argv[1], NULL);
50   typefind = gst_element_factory_make ("typefind", "typefind");
51   g_assert (GST_IS_ELEMENT (typefind));
52   gst_bin_add_many (GST_BIN (pipeline), source, typefind, NULL);
53   gst_element_link (source, typefind);
54   g_signal_connect (G_OBJECT (typefind), "have-type", 
55                     G_CALLBACK (have_type_handler), NULL);
56
57   /* set to play */
58   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
59
60   while (!FOUND){
61     gst_bin_iterate (GST_BIN (pipeline));
62     iterations++;
63     if(iterations >= max_iterations){
64       break;
65     }
66   }
67   if (!FOUND) {
68     g_print ("No type found\n");
69     return 1;
70   }
71   return 0;
72 }