Add vishnu's index dumping app
authorWim Taymans <wim.taymans@gmail.com>
Sun, 12 Jan 2003 13:27:02 +0000 (13:27 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Sun, 12 Jan 2003 13:27:02 +0000 (13:27 +0000)
Original commit message from CVS:
Add vishnu's index dumping app

tests/old/testsuite/indexers/Makefile.am
tests/old/testsuite/indexers/indexdump.c [new file with mode: 0644]
testsuite/indexers/Makefile.am
testsuite/indexers/indexdump.c [new file with mode: 0644]

index 13a6274..e08c185 100644 (file)
@@ -1,4 +1,4 @@
-testprogs = cache1
+testprogs = cache1 indexdump
 
 TESTS = $(testprogs)
 
diff --git a/tests/old/testsuite/indexers/indexdump.c b/tests/old/testsuite/indexers/indexdump.c
new file mode 100644 (file)
index 0000000..e528e4a
--- /dev/null
@@ -0,0 +1,77 @@
+/* GStreamer
+ * Copyright (C) 2003 Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * 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.
+ */
+
+#include <gst/gst.h>
+
+static void
+my_resolver (GstIndex *index, GstObject *_ign, gchar **writer_string,
+            gpointer user_data)
+{ *writer_string = user_data; }
+
+gint 
+main (gint argc, gchar *argv[]) 
+{
+  GstIndex *index;
+  GstObject *identity;
+  gint id;
+  gint64 cur;
+  
+  gst_init (&argc, &argv);
+
+  if (argc != 3) {
+    g_print ("usage: dumpfileindex /path/to/fileindex writer_id\n");
+    exit (0);
+  }
+
+  index = gst_index_factory_make ("fileindex");
+  g_assert (index != NULL);
+
+  g_object_set (index, "location", argv[1], NULL);
+  gst_index_set_resolver (index, (GstIndexResolver) my_resolver, argv[2]);
+
+  identity = (GstObject*) gst_element_factory_make ("identity", "element");
+  g_assert (identity);
+  gst_index_get_writer_id (index, identity, &id);
+  
+  cur = 0;
+  while (1) {
+    gint fx;
+    GstIndexEntry *entry =
+      gst_index_get_assoc_entry (index, id, GST_INDEX_LOOKUP_AFTER, 0,
+                                GST_FORMAT_TIME, cur);
+    if (!entry)
+      break;
+
+    g_print ("%x", GST_INDEX_ASSOC_FLAGS (entry));
+    for (fx=0; fx < GST_INDEX_NASSOCS (entry); fx++) {
+      GstFormat fmt = GST_INDEX_ASSOC_FORMAT (entry, fx);
+      const GstFormatDefinition* def = gst_format_get_details (fmt);
+      if (fmt == GST_FORMAT_TIME) {
+       cur = GST_INDEX_ASSOC_VALUE (entry, fx) + 1;
+       g_print (" time %.4f",
+                GST_INDEX_ASSOC_VALUE (entry, fx) / (double) GST_SECOND);
+      }
+      else
+       g_print (" %s %lld", def->nick, GST_INDEX_ASSOC_VALUE (entry, fx));
+    }
+    g_print ("\n");
+  }
+
+  return 0;
+}
index 13a6274..e08c185 100644 (file)
@@ -1,4 +1,4 @@
-testprogs = cache1
+testprogs = cache1 indexdump
 
 TESTS = $(testprogs)
 
diff --git a/testsuite/indexers/indexdump.c b/testsuite/indexers/indexdump.c
new file mode 100644 (file)
index 0000000..e528e4a
--- /dev/null
@@ -0,0 +1,77 @@
+/* GStreamer
+ * Copyright (C) 2003 Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * 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.
+ */
+
+#include <gst/gst.h>
+
+static void
+my_resolver (GstIndex *index, GstObject *_ign, gchar **writer_string,
+            gpointer user_data)
+{ *writer_string = user_data; }
+
+gint 
+main (gint argc, gchar *argv[]) 
+{
+  GstIndex *index;
+  GstObject *identity;
+  gint id;
+  gint64 cur;
+  
+  gst_init (&argc, &argv);
+
+  if (argc != 3) {
+    g_print ("usage: dumpfileindex /path/to/fileindex writer_id\n");
+    exit (0);
+  }
+
+  index = gst_index_factory_make ("fileindex");
+  g_assert (index != NULL);
+
+  g_object_set (index, "location", argv[1], NULL);
+  gst_index_set_resolver (index, (GstIndexResolver) my_resolver, argv[2]);
+
+  identity = (GstObject*) gst_element_factory_make ("identity", "element");
+  g_assert (identity);
+  gst_index_get_writer_id (index, identity, &id);
+  
+  cur = 0;
+  while (1) {
+    gint fx;
+    GstIndexEntry *entry =
+      gst_index_get_assoc_entry (index, id, GST_INDEX_LOOKUP_AFTER, 0,
+                                GST_FORMAT_TIME, cur);
+    if (!entry)
+      break;
+
+    g_print ("%x", GST_INDEX_ASSOC_FLAGS (entry));
+    for (fx=0; fx < GST_INDEX_NASSOCS (entry); fx++) {
+      GstFormat fmt = GST_INDEX_ASSOC_FORMAT (entry, fx);
+      const GstFormatDefinition* def = gst_format_get_details (fmt);
+      if (fmt == GST_FORMAT_TIME) {
+       cur = GST_INDEX_ASSOC_VALUE (entry, fx) + 1;
+       g_print (" time %.4f",
+                GST_INDEX_ASSOC_VALUE (entry, fx) / (double) GST_SECOND);
+      }
+      else
+       g_print (" %s %lld", def->nick, GST_INDEX_ASSOC_VALUE (entry, fx));
+    }
+    g_print ("\n");
+  }
+
+  return 0;
+}