tools/gst-typefind.c: Update, add copyright block.
[platform/upstream/gstreamer.git] / tools / gst-typefind.c
1 /* GStreamer
2  * Copyright (C) 2003 Thomas Vander Stichele <thomas@apestaart.org>
3  *               2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
4  *               2005 Andy Wingo <wingo@pobox.com>
5  *
6  * gst-typefind.c: Use GStreamer to find the type of a file
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24
25 #ifdef HAVE_CONFIG_H
26 #  include "config.h"
27 #endif
28
29 #include <string.h>
30 #include <stdlib.h>
31 #include <locale.h>
32 #include <gst/gst.h>
33
34
35 char *filename = NULL;
36
37
38 void
39 have_type_handler (GstElement * typefind, guint probability,
40     const GstCaps * caps, gpointer unused)
41 {
42   gchar *caps_str;
43
44   caps_str = gst_caps_to_string (caps);
45   g_print ("%s - %s\n", filename, caps_str);
46   g_free (caps_str);
47 }
48
49 int
50 main (int argc, char *argv[])
51 {
52   guint i = 1;
53   GstElement *pipeline;
54   GstElement *source, *typefind, *fakesink;
55
56   setlocale (LC_ALL, "");
57
58   gst_init (&argc, &argv);
59
60   if (argc < 2) {
61     g_print ("Please give a filename to typefind\n\n");
62     return 1;
63   }
64
65   pipeline = gst_pipeline_new (NULL);
66
67   /* don't hang too long trying to preroll */
68   g_object_set (pipeline, "play-timeout", (gint64) 0.25 * GST_SECOND, NULL);
69
70   source = gst_element_factory_make ("filesrc", "source");
71   g_assert (GST_IS_ELEMENT (source));
72   typefind = gst_element_factory_make ("typefind", "typefind");
73   g_assert (GST_IS_ELEMENT (typefind));
74   fakesink = gst_element_factory_make ("fakesink", "fakesink");
75   g_assert (GST_IS_ELEMENT (typefind));
76
77   gst_bin_add_many (GST_BIN (pipeline), source, typefind, fakesink, NULL);
78   gst_element_link_many (source, typefind, fakesink, NULL);
79
80   g_signal_connect (G_OBJECT (typefind), "have-type",
81       G_CALLBACK (have_type_handler), NULL);
82
83   while (i < argc) {
84     GstElementStateReturn sret;
85
86     filename = argv[i];
87     g_object_set (source, "location", filename, NULL);
88
89     /* typefind will only commit to PAUSED if it actually finds a type;
90      * otherwise the state change fails */
91     sret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
92
93     if (sret != GST_STATE_SUCCESS)
94       g_print ("%s - No type found\n", argv[i]);
95
96     gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
97
98     i++;
99   }
100
101   gst_object_unref (pipeline);
102   return 0;
103 }