mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 03:31:05 +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_class_init (GstIndexClass *klass);
|
||||||
static void gst_index_init (GstIndex *index);
|
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 GstObject *parent_class = NULL;
|
||||||
static guint gst_index_signals[LAST_SIGNAL] = { 0 };
|
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->writers = g_hash_table_new (NULL, NULL);
|
||||||
index->last_id = 0;
|
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_WRITABLE);
|
||||||
GST_FLAG_SET (index, GST_INDEX_READABLE);
|
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 (GST_IS_INDEX (index), NULL);
|
||||||
g_return_val_if_fail (format != 0, 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;
|
return NULL;
|
||||||
|
|
||||||
entry = g_new0 (GstIndexEntry, 1);
|
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 (GST_IS_INDEX (index), NULL);
|
||||||
g_return_val_if_fail (description != NULL, 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;
|
return NULL;
|
||||||
|
|
||||||
entry = g_new0 (GstIndexEntry, 1);
|
entry = g_new0 (GstIndexEntry, 1);
|
||||||
|
@ -378,6 +382,15 @@ gst_index_add_id (GstIndex *index, gint id, gchar *description)
|
||||||
return entry;
|
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:
|
* gst_index_get_writer_id:
|
||||||
* @index: the index to get a unique write id for
|
* @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
|
* should obtain a unique id. The methods to add new entries
|
||||||
* to the index require this id as an argument.
|
* to the index require this id as an argument.
|
||||||
*
|
*
|
||||||
* The application or a GstIndex subclass can implement
|
* The application can implement a custom function to map the writer object
|
||||||
* custom functions to map the writer object to an id.
|
* 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.
|
* 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)
|
gst_index_get_writer_id (GstIndex *index, GstObject *writer, gint *id)
|
||||||
{
|
{
|
||||||
gchar *writer_string = NULL;
|
gchar *writer_string = NULL;
|
||||||
gboolean success = FALSE;
|
|
||||||
GstIndexEntry *entry;
|
GstIndexEntry *entry;
|
||||||
GstIndexClass *iclass;
|
GstIndexClass *iclass;
|
||||||
|
gboolean success = FALSE;
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_INDEX (index), 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 (GST_IS_OBJECT (writer), FALSE);
|
||||||
|
@ -407,28 +421,50 @@ gst_index_get_writer_id (GstIndex *index, GstObject *writer, gint *id)
|
||||||
|
|
||||||
*id = -1;
|
*id = -1;
|
||||||
|
|
||||||
|
/* first try to get a previously cached id */
|
||||||
entry = g_hash_table_lookup (index->writers, writer);
|
entry = g_hash_table_lookup (index->writers, writer);
|
||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
*id = index->last_id;
|
|
||||||
|
|
||||||
writer_string = gst_object_get_path_string (writer);
|
iclass = GST_INDEX_GET_CLASS (index);
|
||||||
|
|
||||||
gst_index_add_id (index, *id, writer_string);
|
/* let the app make a string */
|
||||||
index->last_id++;
|
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);
|
g_hash_table_insert (index->writers, writer, entry);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
iclass = GST_INDEX_GET_CLASS (index);
|
*id = entry->id;
|
||||||
|
|
||||||
if (index->resolver) {
|
|
||||||
success = index->resolver (index, writer, id, &writer_string, index->resolver_user_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iclass->resolve_writer) {
|
return TRUE;
|
||||||
success = iclass->resolve_writer (index, writer, id, &writer_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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 (GST_IS_INDEX (index), NULL);
|
||||||
g_return_val_if_fail (format != 0, 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;
|
return NULL;
|
||||||
|
|
||||||
va_start (args, value);
|
va_start (args, value);
|
||||||
|
@ -528,7 +564,7 @@ GstIndexEntry*
|
||||||
gst_index_add_object (GstIndex *index, gint id, gchar *key,
|
gst_index_add_object (GstIndex *index, gint id, gchar *key,
|
||||||
GType type, gpointer object)
|
GType type, gpointer object)
|
||||||
{
|
{
|
||||||
if (!GST_INDEX_IS_WRITABLE (index))
|
if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
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);
|
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,
|
return gst_index_get_assoc_entry_full (index, id, method, flags, format, value,
|
||||||
gst_index_compare_func, NULL);
|
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);
|
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
|
||||||
|
|
||||||
|
if (id == -1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
iclass = GST_INDEX_GET_CLASS (index);
|
iclass = GST_INDEX_GET_CLASS (index);
|
||||||
|
|
||||||
if (iclass->get_assoc_entry)
|
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_FORMAT(entry) ((entry)->data.format.format)
|
||||||
#define GST_INDEX_FORMAT_KEY(entry) ((entry)->data.format.key)
|
#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)
|
#define GST_INDEX_ID_DESCRIPTION(entry) ((entry)->data.id.description)
|
||||||
|
|
||||||
struct _GstIndexEntry {
|
struct _GstIndexEntry {
|
||||||
|
@ -131,7 +133,6 @@ typedef gboolean (*GstIndexFilter) (GstIndex *index,
|
||||||
|
|
||||||
typedef gboolean (*GstIndexResolver) (GstIndex *index,
|
typedef gboolean (*GstIndexResolver) (GstIndex *index,
|
||||||
GstObject *writer,
|
GstObject *writer,
|
||||||
gint *writer_id,
|
|
||||||
gchar **writer_string,
|
gchar **writer_string,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -166,8 +167,7 @@ struct _GstIndex {
|
||||||
struct _GstIndexClass {
|
struct _GstIndexClass {
|
||||||
GstObjectClass parent_class;
|
GstObjectClass parent_class;
|
||||||
|
|
||||||
gboolean (*resolve_writer) (GstIndex *index, GstObject *writer,
|
gboolean (*get_writer_id) (GstIndex *index, gint *writer_id, gchar *writer_string);
|
||||||
gint *writer_id, gchar **writer_string);
|
|
||||||
|
|
||||||
void (*commit) (GstIndex *index, gint id);
|
void (*commit) (GstIndex *index, gint id);
|
||||||
|
|
||||||
|
|
|
@ -126,8 +126,7 @@ gst_file_index_get_property (GObject *object,
|
||||||
GParamSpec *pspec);
|
GParamSpec *pspec);
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
|
gst_file_index_get_writer_id (GstIndex *_index, gint *id, gchar *writer_string);
|
||||||
gint *id, gchar **writer_string);
|
|
||||||
|
|
||||||
static void gst_file_index_commit (GstIndex *index, gint writer_id);
|
static void gst_file_index_commit (GstIndex *index, gint writer_id);
|
||||||
static void gst_file_index_add_entry (GstIndex *index, GstIndexEntry *entry);
|
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->add_entry = gst_file_index_add_entry;
|
||||||
gstindex_class->get_assoc_entry = gst_file_index_get_assoc_entry;
|
gstindex_class->get_assoc_entry = gst_file_index_get_assoc_entry;
|
||||||
gstindex_class->commit = gst_file_index_commit;
|
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_object_class_install_property (gobject_class, ARG_LOCATION,
|
||||||
g_param_spec_string ("location", "File Location",
|
g_param_spec_string ("location", "File Location",
|
||||||
|
@ -212,8 +211,8 @@ gst_file_index_dispose (GObject *object)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
|
gst_file_index_get_writer_id (GstIndex *_index,
|
||||||
gint *id, gchar **writer_string)
|
gint *id, gchar *writer_string)
|
||||||
{
|
{
|
||||||
GstFileIndex *index = GST_FILE_INDEX (_index);
|
GstFileIndex *index = GST_FILE_INDEX (_index);
|
||||||
GSList *pending = index->unresolved;
|
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 (id, FALSE);
|
||||||
g_return_val_if_fail (writer_string, FALSE);
|
g_return_val_if_fail (writer_string, FALSE);
|
||||||
g_return_val_if_fail (*writer_string, FALSE);
|
|
||||||
|
|
||||||
index->unresolved = NULL;
|
index->unresolved = NULL;
|
||||||
|
|
||||||
for (elem = pending; elem; elem = g_slist_next (elem)) {
|
for (elem = pending; elem; elem = g_slist_next (elem)) {
|
||||||
GstFileIndexId *ii = elem->data;
|
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);
|
index->unresolved = g_slist_prepend (index->unresolved, ii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
g_warning ("Duplicate matches for writer '%s'", *writer_string);
|
g_warning ("Duplicate matches for writer '%s'", writer_string);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//g_warning ("resolve %d %s", *id, *writer_string);
|
//g_warning ("resolve %d %s", *id, writer_string);
|
||||||
ii->id = *id;
|
ii->id = *id;
|
||||||
g_hash_table_insert (index->id_index, id, ii);
|
g_hash_table_insert (index->id_index, id, ii);
|
||||||
match = TRUE;
|
match = TRUE;
|
||||||
|
|
|
@ -126,8 +126,7 @@ gst_file_index_get_property (GObject *object,
|
||||||
GParamSpec *pspec);
|
GParamSpec *pspec);
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
|
gst_file_index_get_writer_id (GstIndex *_index, gint *id, gchar *writer_string);
|
||||||
gint *id, gchar **writer_string);
|
|
||||||
|
|
||||||
static void gst_file_index_commit (GstIndex *index, gint writer_id);
|
static void gst_file_index_commit (GstIndex *index, gint writer_id);
|
||||||
static void gst_file_index_add_entry (GstIndex *index, GstIndexEntry *entry);
|
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->add_entry = gst_file_index_add_entry;
|
||||||
gstindex_class->get_assoc_entry = gst_file_index_get_assoc_entry;
|
gstindex_class->get_assoc_entry = gst_file_index_get_assoc_entry;
|
||||||
gstindex_class->commit = gst_file_index_commit;
|
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_object_class_install_property (gobject_class, ARG_LOCATION,
|
||||||
g_param_spec_string ("location", "File Location",
|
g_param_spec_string ("location", "File Location",
|
||||||
|
@ -212,8 +211,8 @@ gst_file_index_dispose (GObject *object)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_file_index_resolve_writer (GstIndex *_index, GstObject *writer,
|
gst_file_index_get_writer_id (GstIndex *_index,
|
||||||
gint *id, gchar **writer_string)
|
gint *id, gchar *writer_string)
|
||||||
{
|
{
|
||||||
GstFileIndex *index = GST_FILE_INDEX (_index);
|
GstFileIndex *index = GST_FILE_INDEX (_index);
|
||||||
GSList *pending = index->unresolved;
|
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 (id, FALSE);
|
||||||
g_return_val_if_fail (writer_string, FALSE);
|
g_return_val_if_fail (writer_string, FALSE);
|
||||||
g_return_val_if_fail (*writer_string, FALSE);
|
|
||||||
|
|
||||||
index->unresolved = NULL;
|
index->unresolved = NULL;
|
||||||
|
|
||||||
for (elem = pending; elem; elem = g_slist_next (elem)) {
|
for (elem = pending; elem; elem = g_slist_next (elem)) {
|
||||||
GstFileIndexId *ii = elem->data;
|
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);
|
index->unresolved = g_slist_prepend (index->unresolved, ii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
g_warning ("Duplicate matches for writer '%s'", *writer_string);
|
g_warning ("Duplicate matches for writer '%s'", writer_string);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//g_warning ("resolve %d %s", *id, *writer_string);
|
//g_warning ("resolve %d %s", *id, writer_string);
|
||||||
ii->id = *id;
|
ii->id = *id;
|
||||||
g_hash_table_insert (index->id_index, id, ii);
|
g_hash_table_insert (index->id_index, id, ii);
|
||||||
match = TRUE;
|
match = TRUE;
|
||||||
|
|
Loading…
Reference in a new issue