static void gst_index_class_init (GstIndexClass *klass);
static void gst_index_init (GstIndex *index);
+static gboolean gst_index_default_path_resolver (GstIndex *index, GstObject *writer,
+ gchar **writer_string, gpointer data);
static GstObject *parent_class = NULL;
static guint gst_index_signals[LAST_SIGNAL] = { 0 };
index->writers = g_hash_table_new (NULL, NULL);
index->last_id = 0;
+ gst_index_set_resolver (index, gst_index_default_path_resolver, NULL);
+
GST_FLAG_SET (index, GST_INDEX_WRITABLE);
GST_FLAG_SET (index, GST_INDEX_READABLE);
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
g_return_val_if_fail (format != 0, NULL);
- if (!GST_INDEX_IS_WRITABLE (index))
+ if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
return NULL;
entry = g_new0 (GstIndexEntry, 1);
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
g_return_val_if_fail (description != NULL, NULL);
- if (!GST_INDEX_IS_WRITABLE (index))
+ if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
return NULL;
entry = g_new0 (GstIndexEntry, 1);
return entry;
}
+static gboolean
+gst_index_default_path_resolver (GstIndex *index, GstObject *writer,
+ gchar **writer_string, gpointer data)
+{
+ *writer_string = gst_object_get_path_string (writer);
+
+ return TRUE;
+}
+
/**
* gst_index_get_writer_id:
* @index: the index to get a unique write id for
* should obtain a unique id. The methods to add new entries
* to the index require this id as an argument.
*
- * The application or a GstIndex subclass can implement
- * custom functions to map the writer object to an id.
+ * The application can implement a custom function to map the writer object
+ * to a string. That string will be used to register or look up an id
+ * in the index.
*
* Returns: TRUE if the writer would be mapped to an id.
*/
gst_index_get_writer_id (GstIndex *index, GstObject *writer, gint *id)
{
gchar *writer_string = NULL;
- gboolean success = FALSE;
GstIndexEntry *entry;
GstIndexClass *iclass;
+ gboolean success = FALSE;
g_return_val_if_fail (GST_IS_INDEX (index), FALSE);
g_return_val_if_fail (GST_IS_OBJECT (writer), FALSE);
*id = -1;
+ /* first try to get a previously cached id */
entry = g_hash_table_lookup (index->writers, writer);
if (entry == NULL) {
- *id = index->last_id;
- writer_string = gst_object_get_path_string (writer);
-
- gst_index_add_id (index, *id, writer_string);
- index->last_id++;
- g_hash_table_insert (index->writers, writer, entry);
- }
+ iclass = GST_INDEX_GET_CLASS (index);
- iclass = GST_INDEX_GET_CLASS (index);
+ /* let the app make a string */
+ if (index->resolver) {
+ gboolean res;
- if (index->resolver) {
- success = index->resolver (index, writer, id, &writer_string, index->resolver_user_data);
- }
+ res = index->resolver (index, writer, &writer_string, index->resolver_user_data);
+ if (!res)
+ return FALSE;
+ }
+ else {
+ g_warning ("no resolver found");
+ return FALSE;
+ }
+
+ /* if the index has a resolver, make it map this string to an id */
+ if (iclass->get_writer_id) {
+ success = iclass->get_writer_id (index, id, writer_string);
+ }
+ /* if the index could not resolve, we allocate one ourselves */
+ if (!success) {
+ *id = index->last_id++;
+ }
- if (iclass->resolve_writer) {
- success = iclass->resolve_writer (index, writer, id, &writer_string);
+ entry = gst_index_add_id (index, *id, writer_string);
+ if (!entry) {
+ /* index is probably not writable, make an entry anyway
+ * to keep it in our cache */
+ entry = g_new0 (GstIndexEntry, 1);
+ entry->type = GST_INDEX_ENTRY_ID;
+ entry->id = *id;
+ entry->data.id.description = writer_string;
+ }
+ g_hash_table_insert (index->writers, writer, entry);
+ }
+ else {
+ *id = entry->id;
}
- return success;
+ return TRUE;
}
/**
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
g_return_val_if_fail (format != 0, NULL);
- if (!GST_INDEX_IS_WRITABLE (index))
+ if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
return NULL;
va_start (args, value);
gst_index_add_object (GstIndex *index, gint id, gchar *key,
GType type, gpointer object)
{
- if (!GST_INDEX_IS_WRITABLE (index))
+ if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
return NULL;
return NULL;
{
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
+ if (id == -1)
+ return NULL;
+
return gst_index_get_assoc_entry_full (index, id, method, flags, format, value,
gst_index_compare_func, NULL);
}
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
+ if (id == -1)
+ return NULL;
+
iclass = GST_INDEX_GET_CLASS (index);
if (iclass->get_assoc_entry)
GParamSpec *pspec);
static gboolean
-gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
- gint *id, gchar **writer_string);
+gst_file_index_get_writer_id (GstIndex *_index, gint *id, gchar *writer_string);
static void gst_file_index_commit (GstIndex *index, gint writer_id);
static void gst_file_index_add_entry (GstIndex *index, GstIndexEntry *entry);
gstindex_class->add_entry = gst_file_index_add_entry;
gstindex_class->get_assoc_entry = gst_file_index_get_assoc_entry;
gstindex_class->commit = gst_file_index_commit;
- gstindex_class->resolve_writer = gst_file_index_resolve_writer;
+ gstindex_class->get_writer_id = gst_file_index_get_writer_id ;
g_object_class_install_property (gobject_class, ARG_LOCATION,
g_param_spec_string ("location", "File Location",
}
static gboolean
-gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
- gint *id, gchar **writer_string)
+gst_file_index_get_writer_id (GstIndex *_index,
+ gint *id, gchar *writer_string)
{
GstFileIndex *index = GST_FILE_INDEX (_index);
GSList *pending = index->unresolved;
g_return_val_if_fail (id, FALSE);
g_return_val_if_fail (writer_string, FALSE);
- g_return_val_if_fail (*writer_string, FALSE);
index->unresolved = NULL;
for (elem = pending; elem; elem = g_slist_next (elem)) {
GstFileIndexId *ii = elem->data;
- if (strcmp (ii->id_desc, *writer_string) != 0) {
+ if (strcmp (ii->id_desc, writer_string) != 0) {
index->unresolved = g_slist_prepend (index->unresolved, ii);
continue;
}
if (match) {
- g_warning ("Duplicate matches for writer '%s'", *writer_string);
+ g_warning ("Duplicate matches for writer '%s'", writer_string);
continue;
}
- //g_warning ("resolve %d %s", *id, *writer_string);
+ //g_warning ("resolve %d %s", *id, writer_string);
ii->id = *id;
g_hash_table_insert (index->id_index, id, ii);
match = TRUE;
GParamSpec *pspec);
static gboolean
-gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
- gint *id, gchar **writer_string);
+gst_file_index_get_writer_id (GstIndex *_index, gint *id, gchar *writer_string);
static void gst_file_index_commit (GstIndex *index, gint writer_id);
static void gst_file_index_add_entry (GstIndex *index, GstIndexEntry *entry);
gstindex_class->add_entry = gst_file_index_add_entry;
gstindex_class->get_assoc_entry = gst_file_index_get_assoc_entry;
gstindex_class->commit = gst_file_index_commit;
- gstindex_class->resolve_writer = gst_file_index_resolve_writer;
+ gstindex_class->get_writer_id = gst_file_index_get_writer_id ;
g_object_class_install_property (gobject_class, ARG_LOCATION,
g_param_spec_string ("location", "File Location",
}
static gboolean
-gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
- gint *id, gchar **writer_string)
+gst_file_index_get_writer_id (GstIndex *_index,
+ gint *id, gchar *writer_string)
{
GstFileIndex *index = GST_FILE_INDEX (_index);
GSList *pending = index->unresolved;
g_return_val_if_fail (id, FALSE);
g_return_val_if_fail (writer_string, FALSE);
- g_return_val_if_fail (*writer_string, FALSE);
index->unresolved = NULL;
for (elem = pending; elem; elem = g_slist_next (elem)) {
GstFileIndexId *ii = elem->data;
- if (strcmp (ii->id_desc, *writer_string) != 0) {
+ if (strcmp (ii->id_desc, writer_string) != 0) {
index->unresolved = g_slist_prepend (index->unresolved, ii);
continue;
}
if (match) {
- g_warning ("Duplicate matches for writer '%s'", *writer_string);
+ g_warning ("Duplicate matches for writer '%s'", writer_string);
continue;
}
- //g_warning ("resolve %d %s", *id, *writer_string);
+ //g_warning ("resolve %d %s", *id, writer_string);
ii->id = *id;
g_hash_table_insert (index->id_index, id, ii);
match = TRUE;