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