Next big merge.
[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 gchar *filename = NULL;
16
17 void
18 gst_caps_print (const char *filename, const GstCaps * caps)
19 {
20   gchar *caps_str = gst_caps_to_string (caps);
21
22   g_print ("%s - %s\n", filename, caps_str);
23   g_free (caps_str);
24 }
25
26 void
27 have_type_handler (GstElement * typefind, guint probability,
28     const GstCaps * caps, gpointer unused)
29 {
30   gst_caps_print (filename, caps);
31   FOUND = TRUE;
32 }
33
34 int
35 main (int argc, char *argv[])
36 {
37   guint i = 1;
38   GstElement *pipeline;
39   GstElement *source, *typefind;
40
41   setlocale (LC_ALL, "");
42
43   gst_init (&argc, &argv);
44
45   if (argc < 2) {
46     g_print ("Please give a filename to typefind\n\n");
47     return 1;
48   }
49
50   pipeline = gst_pipeline_new (NULL);
51   source = gst_element_factory_make ("filesrc", "source");
52   g_assert (GST_IS_ELEMENT (source));
53   typefind = gst_element_factory_make ("typefind", "typefind");
54   g_assert (GST_IS_ELEMENT (typefind));
55   gst_bin_add (GST_BIN (pipeline), source);
56   gst_bin_add (GST_BIN (pipeline), typefind);
57   gst_pad_link (gst_element_get_pad (source, "src"),
58       gst_element_get_pad (typefind, "sink"));
59   g_signal_connect (G_OBJECT (typefind), "have-type",
60       G_CALLBACK (have_type_handler), NULL);
61
62   while (i < argc) {
63     FOUND = FALSE;
64     gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
65     filename = argv[i];
66     g_object_set (source, "location", filename, NULL);
67     /* set to play */
68     gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
69
70     while (!FOUND) {
71     }
72     if (!FOUND) {
73       g_print ("%s - No type found\n", argv[i]);
74     }
75     i++;
76   }
77   g_object_unref (pipeline);
78   return 0;
79 }