2005-07-15 11:04:18 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2003 Thomas Vander Stichele <thomas@apestaart.org>
|
|
|
|
* 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
|
|
|
* 2005 Andy Wingo <wingo@pobox.com>
|
|
|
|
*
|
|
|
|
* gst-typefind.c: Use GStreamer to find the type of a file
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-05-17 23:04:02 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2003-08-19 08:11:58 +00:00
|
|
|
#include <locale.h>
|
2003-05-17 23:04:02 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
|
2005-07-15 11:04:18 +00:00
|
|
|
char *filename = NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-05-17 23:04:02 +00:00
|
|
|
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
have_type_handler (GstElement * typefind, guint probability,
|
|
|
|
const GstCaps * caps, gpointer unused)
|
2003-05-17 23:04:02 +00:00
|
|
|
{
|
2005-07-15 11:04:18 +00:00
|
|
|
gchar *caps_str;
|
|
|
|
|
|
|
|
caps_str = gst_caps_to_string (caps);
|
|
|
|
g_print ("%s - %s\n", filename, caps_str);
|
|
|
|
g_free (caps_str);
|
2003-05-17 23:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2003-10-28 20:25:30 +00:00
|
|
|
guint i = 1;
|
2003-05-17 23:04:02 +00:00
|
|
|
GstElement *pipeline;
|
2005-07-15 11:04:18 +00:00
|
|
|
GstElement *source, *typefind, *fakesink;
|
2003-05-17 23:04:02 +00:00
|
|
|
|
2003-08-19 08:11:58 +00:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
2003-05-17 23:04:02 +00:00
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (argc < 2) {
|
2003-06-29 14:05:49 +00:00
|
|
|
g_print ("Please give a filename to typefind\n\n");
|
2003-10-28 20:25:30 +00:00
|
|
|
return 1;
|
2003-06-29 14:05:49 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-05-17 23:04:02 +00:00
|
|
|
pipeline = gst_pipeline_new (NULL);
|
2005-07-15 11:04:18 +00:00
|
|
|
|
2003-05-17 23:04:02 +00:00
|
|
|
source = gst_element_factory_make ("filesrc", "source");
|
|
|
|
g_assert (GST_IS_ELEMENT (source));
|
|
|
|
typefind = gst_element_factory_make ("typefind", "typefind");
|
|
|
|
g_assert (GST_IS_ELEMENT (typefind));
|
2005-07-15 11:04:18 +00:00
|
|
|
fakesink = gst_element_factory_make ("fakesink", "fakesink");
|
|
|
|
g_assert (GST_IS_ELEMENT (typefind));
|
|
|
|
|
|
|
|
gst_bin_add_many (GST_BIN (pipeline), source, typefind, fakesink, NULL);
|
|
|
|
gst_element_link_many (source, typefind, fakesink, NULL);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_signal_connect (G_OBJECT (typefind), "have-type",
|
|
|
|
G_CALLBACK (have_type_handler), NULL);
|
2003-05-17 23:04:02 +00:00
|
|
|
|
2003-10-28 20:25:30 +00:00
|
|
|
while (i < argc) {
|
2005-07-15 11:04:18 +00:00
|
|
|
GstElementStateReturn sret;
|
2005-08-21 10:54:47 +00:00
|
|
|
GstElementState state;
|
2005-07-15 11:04:18 +00:00
|
|
|
|
2003-10-28 20:25:30 +00:00
|
|
|
filename = argv[i];
|
|
|
|
g_object_set (source, "location", filename, NULL);
|
2003-05-17 23:04:02 +00:00
|
|
|
|
2005-08-21 10:54:47 +00:00
|
|
|
GST_DEBUG ("Starting typefinding for %s", filename);
|
|
|
|
|
2005-07-15 11:04:18 +00:00
|
|
|
/* typefind will only commit to PAUSED if it actually finds a type;
|
|
|
|
* otherwise the state change fails */
|
|
|
|
sret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
|
|
|
|
|
2005-08-21 10:54:47 +00:00
|
|
|
if (GST_STATE_ASYNC == sret) {
|
|
|
|
if (GST_STATE_FAILURE ==
|
|
|
|
gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL, NULL))
|
|
|
|
break;
|
|
|
|
} else if (sret != GST_STATE_SUCCESS)
|
2003-10-28 20:25:30 +00:00
|
|
|
g_print ("%s - No type found\n", argv[i]);
|
2005-07-15 11:04:18 +00:00
|
|
|
|
2005-08-21 10:54:47 +00:00
|
|
|
if (GST_STATE_ASYNC ==
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL)) {
|
|
|
|
if (GST_STATE_FAILURE ==
|
|
|
|
gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL, NULL))
|
|
|
|
break;
|
|
|
|
}
|
2005-07-15 11:04:18 +00:00
|
|
|
|
2003-10-28 20:25:30 +00:00
|
|
|
i++;
|
2003-09-14 11:08:50 +00:00
|
|
|
}
|
2005-07-15 11:04:18 +00:00
|
|
|
|
|
|
|
gst_object_unref (pipeline);
|
2003-05-17 23:04:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|