/** * gst_index_add_associationv: * @index: the index to add the entry to * @id: the id of the index writer * @flags: optinal flags for this entry * @n: number of associations * @list: list of associations * * Associate given format/value pairs with each other. * * Returns: a pointer to the newly added entry in the index. */ GstIndexEntry * gst_index_add_associationv (GstIndex * index, gint id, GstIndexAssociationFlags flags, gint n, const GstIndexAssociation * list) { GstIndexEntry *entry; g_return_val_if_fail (n > 0, NULL); g_return_val_if_fail (list != NULL, NULL); g_return_val_if_fail (GST_IS_INDEX (index), NULL); if (!GST_INDEX_IS_WRITABLE (index) || id == -1) return NULL; entry = g_slice_new (GstIndexEntry); entry->type = GST_INDEX_ENTRY_ASSOCIATION; entry->id = id; entry->data.assoc.flags = flags; entry->data.assoc.assocs = g_memdup (list, sizeof (GstIndexAssociation) * n); entry->data.assoc.nassocs = n; gst_index_add_entry (index, entry); return entry; }
EXPORT_C #endif GstIndexEntry * gst_index_add_format (GstIndex * index, gint id, GstFormat format) { GstIndexEntry *entry; const GstFormatDefinition *def; g_return_val_if_fail (GST_IS_INDEX (index), NULL); g_return_val_if_fail (format != 0, NULL); if (!GST_INDEX_IS_WRITABLE (index) || id == -1) return NULL; entry = g_new0 (GstIndexEntry, 1); entry->type = GST_INDEX_ENTRY_FORMAT; entry->id = id; entry->data.format.format = format; def = gst_format_get_details (format); entry->data.format.key = def->nick; gst_index_add_entry (index, entry); return entry; }
/** * gst_index_get_writer_id: * @index: the index to get a unique write id for * @writer: the GstObject to allocate an id for * @id: a pointer to a gint to hold the id * * Before entries can be added to the index, a writer * should obtain a unique id. The methods to add new entries * to the index require this id as an argument. * * 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. * * <note> * The caller must not hold @writer's #GST_OBJECT_LOCK, as the default * resolver may call functions that take the object lock as well, and * the lock is not recursive. * </note> * * Returns: TRUE if the writer would be mapped to an id. */ gboolean gst_index_get_writer_id (GstIndex * index, GstObject * writer, gint * id) { gchar *writer_string = NULL; 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); g_return_val_if_fail (id, FALSE); *id = -1; /* first try to get a previously cached id */ entry = g_hash_table_lookup (index->writers, writer); if (entry == NULL) { iclass = GST_INDEX_GET_CLASS (index); /* let the app make a string */ if (index->resolver) { gboolean res; 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; } 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_slice_new (GstIndexEntry); 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 TRUE; }
/** * gst_index_set_filter: * @index: the index to register the filter on * @filter: the filter to register * @user_data: data passed to the filter function * * Lets the app register a custom filter function so that * it can select what entries should be stored in the index. */ void gst_index_set_filter (GstIndex * index, GstIndexFilter filter, gpointer user_data) { g_return_if_fail (GST_IS_INDEX (index)); gst_index_set_filter_full (index, filter, user_data, NULL); }
/** * gst_index_get_assoc_entry: * @index: the index to search * @id: the id of the index writer * @method: The lookup method to use * @flags: Flags for the entry * @format: the format of the value * @value: the value to find * * Finds the given format/value in the index * * Returns: the entry associated with the value or NULL if the * value was not found. */ GstIndexEntry * gst_index_get_assoc_entry (GstIndex * index, gint id, GstIndexLookupMethod method, GstIndexAssociationFlags flags, GstFormat format, gint64 value) { 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); }
/** * gst_index_set_filter_full: * @index: the index to register the filter on * @filter: the filter to register * @user_data: data passed to the filter function * @user_data_destroy: function to call when @user_data is unset * * Lets the app register a custom filter function so that * it can select what entries should be stored in the index. */ void gst_index_set_filter_full (GstIndex * index, GstIndexFilter filter, gpointer user_data, GDestroyNotify user_data_destroy) { g_return_if_fail (GST_IS_INDEX (index)); if (index->filter_user_data && index->filter_user_data_destroy) index->filter_user_data_destroy (index->filter_user_data); index->filter = filter; index->filter_user_data = user_data; index->filter_user_data_destroy = user_data_destroy; }
EXPORT_C #endif GstIndexEntry * gst_index_add_association (GstIndex * index, gint id, GstAssocFlags flags, GstFormat format, gint64 value, ...) { va_list args; GstIndexEntry *entry; GstIndexAssociation *list; gint n_assocs = 0; GstFormat cur_format; GArray *array; g_return_val_if_fail (GST_IS_INDEX (index), NULL); g_return_val_if_fail (format != 0, NULL); if (!GST_INDEX_IS_WRITABLE (index) || id == -1) return NULL; array = g_array_new (FALSE, FALSE, sizeof (GstIndexAssociation)); { GstIndexAssociation a; a.format = format; a.value = value; n_assocs = 1; g_array_append_val (array, a); } va_start (args, value); while ((cur_format = va_arg (args, GstFormat))) { GstIndexAssociation a; a.format = cur_format; a.value = va_arg (args, gint64); n_assocs++; g_array_append_val (array, a); } va_end (args); list = (GstIndexAssociation *) g_array_free (array, FALSE); entry = gst_index_add_associationv (index, id, flags, n_assocs, list); g_free (list); return entry; }
/** * gst_index_set_resolver_full: * @index: the index to register the resolver on * @resolver: the resolver to register * @user_data: data passed to the resolver function * @user_data_destroy: destroy function for @user_data * * Lets the app register a custom function to map index * ids to writer descriptions. * * Since: 0.10.18 */ void gst_index_set_resolver_full (GstIndex * index, GstIndexResolver resolver, gpointer user_data, GDestroyNotify user_data_destroy) { g_return_if_fail (GST_IS_INDEX (index)); if (index->resolver_user_data && index->resolver_user_data_destroy) index->resolver_user_data_destroy (index->resolver_user_data); index->resolver = resolver; index->resolver_user_data = user_data; index->resolver_user_data_destroy = user_data_destroy; index->method = GST_INDEX_RESOLVER_CUSTOM; }
/** * gst_index_get_assoc_entry_full: * @index: the index to search * @id: the id of the index writer * @method: The lookup method to use * @flags: Flags for the entry * @format: the format of the value * @value: the value to find * @func: the function used to compare entries * @user_data: user data passed to the compare function * * Finds the given format/value in the index with the given * compare function and user_data. * * Returns: the entry associated with the value or NULL if the * value was not found. */ GstIndexEntry * gst_index_get_assoc_entry_full (GstIndex * index, gint id, GstIndexLookupMethod method, GstIndexAssociationFlags flags, GstFormat format, gint64 value, GCompareDataFunc func, gpointer user_data) { GstIndexClass *iclass; 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) return iclass->get_assoc_entry (index, id, method, flags, format, value, func, user_data); return NULL; }
/** * gst_index_add_id: * @index: the index to add the entry to * @id: the id of the index writer * @description: the description of the index writer * * Add an id entry into the index. * * Returns: a pointer to the newly added entry in the index. */ GstIndexEntry * gst_index_add_id (GstIndex * index, gint id, gchar * description) { GstIndexEntry *entry; g_return_val_if_fail (GST_IS_INDEX (index), NULL); g_return_val_if_fail (description != NULL, NULL); if (!GST_INDEX_IS_WRITABLE (index) || id == -1) return NULL; entry = g_slice_new (GstIndexEntry); entry->type = GST_INDEX_ENTRY_ID; entry->id = id; entry->data.id.description = description; gst_index_add_entry (index, entry); return entry; }