index c3ef4c2403b0affa86bae0cfdc72096f2855fe5f..fd276fae446aa48ce388c003e1a5b5067f603330 100644 (file)
#include <gst/gst.h>
-#define GST_TYPE_MEM_INDEX \
+#include "gstindexers.h"
+
+#define GST_TYPE_MEM_INDEX \
(gst_index_get_type ())
-#define GST_MEM_INDEX(obj) \
+#define GST_MEM_INDEX(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MEM_INDEX, GstMemIndex))
-#define GST_MEM_INDEX_CLASS(klass) \
+#define GST_MEM_INDEX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MEM_INDEX, GstMemIndexClass))
-#define GST_IS_MEM_INDEX(obj) \
+#define GST_IS_MEM_INDEX(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MEM_INDEX))
-#define GST_IS_MEM_INDEX_CLASS(obj) \
+#define GST_IS_MEM_INDEX_CLASS(klass) \
(GST_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MEM_INDEX))
/*
*
* All entries are simply added to a GList first. Then we build
* an index to each entry for each id/format
- *
+ *
*
* memindex
* -----------------------------...
- * ! !
- * id1 id2
+ * ! !
+ * id1 id2
* ------------
* ! !
* format1 format2
* The MemIndexId keeps a MemIndexFormatIndex for each format the
* specific writer wants indexed.
*
- * The MemIndexFormatIndex keeps all the values of the particular
- * format in a GTree, The values of the GTree point back to the entry.
+ * The MemIndexFormatIndex keeps all the values of the particular
+ * format in a GTree, The values of the GTree point back to the entry.
*
* Finding a value for an id/format requires locating the correct GTree,
* then do a lookup in the Tree to get the required value.
/* FILL ME */
};
-static void gst_mem_index_class_init (GstMemIndexClass * klass);
-static void gst_mem_index_init (GstMemIndex * index);
-static void gst_mem_index_dispose (GObject * object);
+static void gst_mem_index_finalize (GObject * object);
static void gst_mem_index_add_entry (GstIndex * index, GstIndexEntry * entry);
static GstIndexEntry *gst_mem_index_get_assoc_entry (GstIndex * index, gint id,
@@ -116,35 +116,11 @@ static GstIndexEntry *gst_mem_index_get_assoc_entry (GstIndex * index, gint id,
#define CLASS(mem_index) GST_MEM_INDEX_CLASS (G_OBJECT_GET_CLASS (mem_index))
-static GstIndex *parent_class = NULL;
-
/*static guint gst_mem_index_signals[LAST_SIGNAL] = { 0 }; */
-GType
-gst_mem_index_get_type (void)
-{
- static GType mem_index_type = 0;
-
- if (!mem_index_type) {
- static const GTypeInfo mem_index_info = {
- sizeof (GstMemIndexClass),
- NULL,
- NULL,
- (GClassInitFunc) gst_mem_index_class_init,
- NULL,
- NULL,
- sizeof (GstMemIndex),
- 1,
- (GInstanceInitFunc) gst_mem_index_init,
- NULL
- };
-
- mem_index_type =
- g_type_register_static (GST_TYPE_INDEX, "GstMemIndex", &mem_index_info,
- 0);
- }
- return mem_index_type;
-}
+GType gst_mem_index_get_type (void);
+
+G_DEFINE_TYPE (GstMemIndex, gst_mem_index, GST_TYPE_INDEX);
static void
gst_mem_index_class_init (GstMemIndexClass * klass)
gobject_class = (GObjectClass *) klass;
gstindex_class = (GstIndexClass *) klass;
- parent_class = g_type_class_ref (GST_TYPE_INDEX);
-
- gobject_class->dispose = gst_mem_index_dispose;
+ gobject_class->finalize = gst_mem_index_finalize;
- gstindex_class->add_entry = gst_mem_index_add_entry;
- gstindex_class->get_assoc_entry = gst_mem_index_get_assoc_entry;
+ gstindex_class->add_entry = GST_DEBUG_FUNCPTR (gst_mem_index_add_entry);
+ gstindex_class->get_assoc_entry =
+ GST_DEBUG_FUNCPTR (gst_mem_index_get_assoc_entry);
}
static void
}
static void
-gst_mem_index_dispose (GObject * object)
+gst_mem_index_free_format (gpointer key, gpointer value, gpointer user_data)
{
- //GstMemIndex *memindex = GST_MEM_INDEX (object);
+ GstMemIndexFormatIndex *index = (GstMemIndexFormatIndex *) value;
- G_OBJECT_CLASS (parent_class)->dispose (object);
+ if (index->tree) {
+ g_tree_destroy (index->tree);
+ }
+
+ g_slice_free (GstMemIndexFormatIndex, index);
+}
+
+static void
+gst_mem_index_free_id (gpointer key, gpointer value, gpointer user_data)
+{
+ GstMemIndexId *id_index = (GstMemIndexId *) value;
+
+ if (id_index->format_index) {
+ g_hash_table_foreach (id_index->format_index, gst_mem_index_free_format,
+ NULL);
+ g_hash_table_destroy (id_index->format_index);
+ id_index->format_index = NULL;
+ }
+
+ g_slice_free (GstMemIndexId, id_index);
+}
+
+static void
+gst_mem_index_finalize (GObject * object)
+{
+ GstMemIndex *memindex = GST_MEM_INDEX (object);
+
+ /* Delete the trees referencing the associations first */
+ if (memindex->id_index) {
+ g_hash_table_foreach (memindex->id_index, gst_mem_index_free_id, NULL);
+ g_hash_table_destroy (memindex->id_index);
+ memindex->id_index = NULL;
+ }
+
+ /* Then delete the associations themselves */
+ if (memindex->associations) {
+ g_list_foreach (memindex->associations, (GFunc) gst_index_entry_free, NULL);
+ g_list_free (memindex->associations);
+ memindex->associations = NULL;
+ }
+
+ G_OBJECT_CLASS (gst_mem_index_parent_class)->finalize (object);
}
static void
id_index = g_hash_table_lookup (memindex->id_index, &entry->id);
if (!id_index) {
- id_index = g_new0 (GstMemIndexId, 1);
+ id_index = g_slice_new0 (GstMemIndexId);
id_index->id = entry->id;
id_index->format_index = g_hash_table_new (g_int_hash, g_int_equal);
index = g_hash_table_lookup (id_index->format_index, format);
if (!index) {
- index = g_new0 (GstMemIndexFormatIndex, 1);
+ index = g_slice_new0 (GstMemIndexFormatIndex);
index->format = *format;
index->offset = assoc;
data.index = format_index;
data.exact = (method == GST_INDEX_LOOKUP_EXACT);
- /* setup data for low/high checks if we are not looking
+ /* setup data for low/high checks if we are not looking
* for an exact match */
if (!data.exact) {
data.low_diff = G_MININT64;
}
}
- if (entry) {
- if ((GST_INDEX_ASSOC_FLAGS (entry) & flags) != flags) {
+ if (entry && ((GST_INDEX_ASSOC_FLAGS (entry) & flags) != flags)) {
+ if (method != GST_INDEX_LOOKUP_EXACT) {
GList *l_entry = g_list_find (memindex->associations, entry);
entry = NULL;
l_entry = g_list_previous (l_entry);
}
}
+ } else {
+ entry = NULL;
}
}
factory = gst_index_factory_new ("memindex",
"A index that stores entries in memory", gst_mem_index_get_type ());
- if (factory != NULL) {
- gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
- } else {
- g_warning ("could not register memindex");
+ if (factory == NULL) {
+ g_warning ("failed to create memindex factory");
+ return FALSE;
}
+
+ GST_PLUGIN_FEATURE (factory)->plugin_name = plugin->desc.name;
+ GST_PLUGIN_FEATURE (factory)->loaded = TRUE;
+
+ gst_registry_add_feature (gst_registry_get_default (),
+ GST_PLUGIN_FEATURE (factory));
+
return TRUE;
}