merge TYPEFIND branch. Major changes:
[platform/upstream/gstreamer.git] / tools / gst-typefind.c
index 29416b2..fc0551a 100644 (file)
@@ -1,5 +1,10 @@
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <string.h>
 #include <stdlib.h>
+#include <locale.h>
 #include <gst/gst.h>
 
 /*
  **/
 
 gboolean FOUND = FALSE;
+gchar *filename = NULL;
 
 void
-gst_caps_print (GstCaps *caps)
+gst_caps_print (const char *filename, GstCaps *caps)
 {
-  while (caps) {
-    g_print ("%s (%s)\n", caps->name, gst_caps_get_mime (caps));
-    if (caps->properties) {
-           g_print ("has properties\n");
-    }
-    caps = caps->next;
-  }
+  gchar *caps_str = gst_caps_to_string (caps);
+  g_print ("%s - %s\n", filename, caps_str);
+  g_free (caps_str);
 }
 
 void
-have_type_handler (GstElement *typefind, gpointer data)
+have_type_handler (GstElement *typefind, guint probability, GstCaps *caps, gpointer unused)
 {
-  GstCaps *caps = (GstCaps *) data;
-  gst_caps_print (caps);
+  gst_caps_print (filename, caps);
   FOUND = TRUE;
 }
 
 int
 main (int argc, char *argv[])
 {
+  guint i = 1;
   GstElement *pipeline;
   GstElement *source, *typefind;
 
+  setlocale (LC_ALL, "");
+
   gst_init (&argc, &argv);
 
-  if (argc < 2) { g_error ("Please give a filename to typefind"); }
+  if (argc < 2) { 
+    g_print ("Please give a filename to typefind\n\n");
+    return 1;
+  }
+  
   pipeline = gst_pipeline_new (NULL);
   source = gst_element_factory_make ("filesrc", "source");
   g_assert (GST_IS_ELEMENT (source));
-  g_object_set (source, "location", argv[1], NULL);
   typefind = gst_element_factory_make ("typefind", "typefind");
   g_assert (GST_IS_ELEMENT (typefind));
   gst_bin_add_many (GST_BIN (pipeline), source, typefind, NULL);
@@ -48,14 +55,23 @@ main (int argc, char *argv[])
   g_signal_connect (G_OBJECT (typefind), "have-type", 
                    G_CALLBACK (have_type_handler), NULL);
 
-  /* set to play */
-  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
+  while (i < argc) {
+    FOUND = FALSE;
+    gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
+    filename = argv[i];
+    g_object_set (source, "location", filename, NULL);
+    /* set to play */
+    gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
 
-  while (gst_bin_iterate (GST_BIN (pipeline)) && !FOUND) ;
-  if (!FOUND) {
-    g_print ("No type found\n");
-    return 1;
+    while (!FOUND) { 
+      if (!gst_bin_iterate (GST_BIN (pipeline)))
+       break;
+    }
+    if (!FOUND) {
+      g_print ("%s - No type found\n", argv[i]);
+    }
+    i++;
   }
+  g_object_unref (pipeline);
   return 0;
 }
-