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>
6 * gst-typefind.c: Use GStreamer to find the type of a file
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.
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.
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.
35 char *filename = NULL;
39 have_type_handler (GstElement * typefind, guint probability,
40 const GstCaps * caps, gpointer unused)
44 caps_str = gst_caps_to_string (caps);
45 g_print ("%s - %s\n", filename, caps_str);
50 main (int argc, char *argv[])
54 GstElement *source, *typefind, *fakesink;
56 setlocale (LC_ALL, "");
58 gst_init (&argc, &argv);
61 g_print ("Please give a filename to typefind\n\n");
65 pipeline = gst_pipeline_new (NULL);
67 source = gst_element_factory_make ("filesrc", "source");
68 g_assert (GST_IS_ELEMENT (source));
69 typefind = gst_element_factory_make ("typefind", "typefind");
70 g_assert (GST_IS_ELEMENT (typefind));
71 fakesink = gst_element_factory_make ("fakesink", "fakesink");
72 g_assert (GST_IS_ELEMENT (typefind));
74 gst_bin_add_many (GST_BIN (pipeline), source, typefind, fakesink, NULL);
75 gst_element_link_many (source, typefind, fakesink, NULL);
77 g_signal_connect (G_OBJECT (typefind), "have-type",
78 G_CALLBACK (have_type_handler), NULL);
81 GstStateChangeReturn sret;
85 g_object_set (source, "location", filename, NULL);
87 GST_DEBUG ("Starting typefinding for %s", filename);
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);
93 if (GST_STATE_CHANGE_ASYNC == sret) {
94 if (GST_STATE_CHANGE_FAILURE ==
95 gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL, NULL))
97 } else if (sret != GST_STATE_CHANGE_SUCCESS)
98 g_print ("%s - No type found\n", argv[i]);
100 if (GST_STATE_CHANGE_ASYNC ==
101 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL)) {
102 if (GST_STATE_CHANGE_FAILURE ==
103 gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL, NULL))
110 gst_object_unref (pipeline);