mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-29 13:11:06 +00:00
I think this makes a little more sense
Original commit message from CVS: I think this makes a little more sense
This commit is contained in:
parent
e720f95202
commit
2ef7c8b385
4 changed files with 81 additions and 43 deletions
|
@ -39,6 +39,8 @@ enum {
|
|||
|
||||
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 };
|
||||
|
@ -108,6 +110,8 @@ gst_index_init (GstIndex *index)
|
|||
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);
|
||||
|
||||
|
@ -320,7 +324,7 @@ gst_index_add_format (GstIndex *index, gint id, GstFormat format)
|
|||
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);
|
||||
|
@ -360,7 +364,7 @@ gst_index_add_id (GstIndex *index, gint id, gchar *description)
|
|||
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);
|
||||
|
@ -378,6 +382,15 @@ gst_index_add_id (GstIndex *index, gint id, gchar *description)
|
|||
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
|
||||
|
@ -388,8 +401,9 @@ gst_index_add_id (GstIndex *index, gint id, gchar *description)
|
|||
* 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.
|
||||
*/
|
||||
|
@ -397,9 +411,9 @@ gboolean
|
|||
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);
|
||||
|
@ -407,28 +421,50 @@ gst_index_get_writer_id (GstIndex *index, GstObject *writer, gint *id)
|
|||
|
||||
*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++;
|
||||
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_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);
|
||||
}
|
||||
|
||||
iclass = GST_INDEX_GET_CLASS (index);
|
||||
|
||||
if (index->resolver) {
|
||||
success = index->resolver (index, writer, id, &writer_string, index->resolver_user_data);
|
||||
else {
|
||||
*id = entry->id;
|
||||
}
|
||||
|
||||
if (iclass->resolve_writer) {
|
||||
success = iclass->resolve_writer (index, writer, id, &writer_string);
|
||||
}
|
||||
|
||||
return success;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -462,7 +498,7 @@ gst_index_add_association (GstIndex *index, gint id, GstAssocFlags flags,
|
|||
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);
|
||||
|
@ -528,7 +564,7 @@ GstIndexEntry*
|
|||
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;
|
||||
|
@ -563,6 +599,9 @@ gst_index_get_assoc_entry (GstIndex *index, gint id,
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
@ -595,6 +634,9 @@ gst_index_get_assoc_entry_full (GstIndex *index, gint id,
|
|||
|
||||
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)
|
||||
|
|
|
@ -84,6 +84,8 @@ typedef enum {
|
|||
#define GST_INDEX_FORMAT_FORMAT(entry) ((entry)->data.format.format)
|
||||
#define GST_INDEX_FORMAT_KEY(entry) ((entry)->data.format.key)
|
||||
|
||||
#define GST_INDEX_ID_INVALID (-1)
|
||||
|
||||
#define GST_INDEX_ID_DESCRIPTION(entry) ((entry)->data.id.description)
|
||||
|
||||
struct _GstIndexEntry {
|
||||
|
@ -131,7 +133,6 @@ typedef gboolean (*GstIndexFilter) (GstIndex *index,
|
|||
|
||||
typedef gboolean (*GstIndexResolver) (GstIndex *index,
|
||||
GstObject *writer,
|
||||
gint *writer_id,
|
||||
gchar **writer_string,
|
||||
gpointer user_data);
|
||||
typedef enum {
|
||||
|
@ -166,8 +167,7 @@ struct _GstIndex {
|
|||
struct _GstIndexClass {
|
||||
GstObjectClass parent_class;
|
||||
|
||||
gboolean (*resolve_writer) (GstIndex *index, GstObject *writer,
|
||||
gint *writer_id, gchar **writer_string);
|
||||
gboolean (*get_writer_id) (GstIndex *index, gint *writer_id, gchar *writer_string);
|
||||
|
||||
void (*commit) (GstIndex *index, gint id);
|
||||
|
||||
|
|
|
@ -126,8 +126,7 @@ gst_file_index_get_property (GObject *object,
|
|||
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);
|
||||
|
@ -182,7 +181,7 @@ gst_file_index_class_init (GstFileIndexClass *klass)
|
|||
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",
|
||||
|
@ -212,8 +211,8 @@ gst_file_index_dispose (GObject *object)
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -225,23 +224,22 @@ gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
|
|||
|
||||
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;
|
||||
|
|
|
@ -126,8 +126,7 @@ gst_file_index_get_property (GObject *object,
|
|||
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);
|
||||
|
@ -182,7 +181,7 @@ gst_file_index_class_init (GstFileIndexClass *klass)
|
|||
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",
|
||||
|
@ -212,8 +211,8 @@ gst_file_index_dispose (GObject *object)
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -225,23 +224,22 @@ gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
|
|||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue