2002-12-13 17:40:56 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> 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
|
2004-03-13 15:27:01 +00:00
|
|
|
lookup (GstIndex * index, GstIndexLookupMethod method,
|
|
|
|
GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat dest_format, gint64 expecting)
|
2002-12-13 17:40:56 +00:00
|
|
|
{
|
2003-01-05 16:50:35 +00:00
|
|
|
GstIndexEntry *entry;
|
2002-12-13 17:40:56 +00:00
|
|
|
gint64 result;
|
|
|
|
|
2003-01-05 16:50:35 +00:00
|
|
|
entry = gst_index_get_assoc_entry (index, 0, method, 0,
|
2004-03-13 15:27:01 +00:00
|
|
|
src_format, src_value);
|
2002-12-13 17:40:56 +00:00
|
|
|
if (entry) {
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_entry_assoc_map (entry, dest_format, &result);
|
2002-12-13 17:40:56 +00:00
|
|
|
|
2003-01-05 16:50:35 +00:00
|
|
|
if (result == expecting) {
|
2005-05-02 15:31:35 +00:00
|
|
|
g_print ("OK (%" G_GINT64_FORMAT ")\n", result);
|
2003-01-05 16:50:35 +00:00
|
|
|
} else {
|
2005-05-02 15:31:35 +00:00
|
|
|
g_print ("FAIL - expecting %" G_GINT64_FORMAT ", got %" G_GINT64_FORMAT
|
|
|
|
"\n", expecting, result);
|
2003-01-05 16:50:35 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
} else {
|
2002-12-13 17:40:56 +00:00
|
|
|
const GstFormatDefinition *def = gst_format_get_details (src_format);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
if (expecting == -1)
|
2003-01-05 16:50:35 +00:00
|
|
|
g_print ("OK (not found)\n");
|
|
|
|
else
|
2005-05-02 15:31:35 +00:00
|
|
|
g_print ("FAIL - no index entry found for %" G_GINT64_FORMAT
|
|
|
|
" %s, expecting %" G_GINT64_FORMAT "\n", src_value, def->nick,
|
|
|
|
expecting);
|
2002-12-13 17:40:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-05 16:50:35 +00:00
|
|
|
typedef struct _GstIndexTestCase
|
2002-12-13 17:40:56 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexLookupMethod method;
|
|
|
|
GstFormat src_format;
|
|
|
|
gint64 src_value;
|
|
|
|
GstFormat dest_format;
|
|
|
|
gint64 expecting;
|
2004-03-15 19:27:17 +00:00
|
|
|
}
|
|
|
|
GstIndexTestCase;
|
2002-12-13 17:40:56 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
const static GstIndexTestCase cases[] = {
|
|
|
|
{GST_INDEX_LOOKUP_EXACT, GST_FORMAT_BYTES, 3, GST_FORMAT_TIME, 3000},
|
|
|
|
{GST_INDEX_LOOKUP_EXACT, GST_FORMAT_TIME, 5000, GST_FORMAT_BYTES, 5},
|
|
|
|
{GST_INDEX_LOOKUP_EXACT, GST_FORMAT_TIME, 5010, GST_FORMAT_BYTES, -1},
|
|
|
|
{GST_INDEX_LOOKUP_BEFORE, GST_FORMAT_TIME, 5010, GST_FORMAT_BYTES, 5},
|
|
|
|
{GST_INDEX_LOOKUP_AFTER, GST_FORMAT_TIME, 5010, GST_FORMAT_BYTES, 6},
|
|
|
|
{GST_INDEX_LOOKUP_BEFORE, GST_FORMAT_TIME, 0, GST_FORMAT_BYTES, 0},
|
|
|
|
{GST_INDEX_LOOKUP_AFTER, GST_FORMAT_TIME, G_MAXINT64, GST_FORMAT_BYTES, -1},
|
|
|
|
{GST_INDEX_LOOKUP_AFTER, GST_FORMAT_TIME, 0, GST_FORMAT_BYTES, 0},
|
|
|
|
{GST_INDEX_LOOKUP_BEFORE, GST_FORMAT_TIME, -1, GST_FORMAT_BYTES, -1},
|
|
|
|
{GST_INDEX_LOOKUP_BEFORE, GST_FORMAT_TIME, G_MAXINT64, GST_FORMAT_BYTES,
|
2004-03-15 19:27:17 +00:00
|
|
|
99999},
|
2004-03-13 15:27:01 +00:00
|
|
|
{GST_INDEX_LOOKUP_AFTER, GST_FORMAT_TIME, G_MAXINT64, GST_FORMAT_BYTES, -1},
|
2002-12-13 17:40:56 +00:00
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gint
|
|
|
|
main (gint argc, gchar * argv[])
|
2002-12-13 17:40:56 +00:00
|
|
|
{
|
2003-01-05 16:50:35 +00:00
|
|
|
GstIndex *index;
|
2002-12-13 17:40:56 +00:00
|
|
|
GstElement *element;
|
|
|
|
gint i, id;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-12-13 17:40:56 +00:00
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (argc != 2) {
|
|
|
|
g_print ("usage: cache1 (memindex | fileindex)\n");
|
|
|
|
exit (0);
|
|
|
|
}
|
2003-01-05 16:50:35 +00:00
|
|
|
|
|
|
|
index = gst_index_factory_make (argv[1]);
|
|
|
|
g_assert (index != NULL);
|
2002-12-13 17:40:56 +00:00
|
|
|
|
|
|
|
element = gst_element_factory_make ("identity", "element");
|
|
|
|
g_assert (element != NULL);
|
|
|
|
|
2003-01-05 16:50:35 +00:00
|
|
|
gst_index_get_writer_id (index, GST_OBJECT (element), &id);
|
|
|
|
|
|
|
|
g_print ("Building index...\n");
|
2002-12-13 17:40:56 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 100000; i++) {
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_add_association (index, 0, 0, GST_FORMAT_BYTES, (gint64) i,
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_FORMAT_TIME, (gint64) (i * 1000), 0);
|
2002-12-13 17:40:56 +00:00
|
|
|
}
|
|
|
|
|
2003-01-05 16:50:35 +00:00
|
|
|
g_print ("Testing index...\n");
|
|
|
|
|
|
|
|
for (i = 0; i < (sizeof (cases) / sizeof (GstIndexTestCase)); i++) {
|
2004-03-13 15:27:01 +00:00
|
|
|
lookup (index, cases[i].method, cases[i].src_format, cases[i].src_value,
|
2004-03-15 19:27:17 +00:00
|
|
|
cases[i].dest_format, cases[i].expecting);
|
2002-12-13 17:40:56 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-12-13 17:40:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|