summaryrefslogtreecommitdiff
path: root/plugins/indexers/gstfileindex.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/indexers/gstfileindex.c')
-rw-r--r--plugins/indexers/gstfileindex.c202
1 files changed, 102 insertions, 100 deletions
diff --git a/plugins/indexers/gstfileindex.c b/plugins/indexers/gstfileindex.c
index 56a09e38b..0c8d8fa26 100644
--- a/plugins/indexers/gstfileindex.c
+++ b/plugins/indexers/gstfileindex.c
@@ -78,7 +78,8 @@ typedef struct
gint nformats;
GstFormat *format;
GArray *array;
-} GstFileIndexId;
+}
+GstFileIndexId;
typedef struct _GstFileIndex GstFileIndex;
typedef struct _GstFileIndexClass GstFileIndexClass;
@@ -106,7 +107,7 @@ struct _GstFileIndex
gint next_id;
GHashTable *id_index;
- GstIndexEntry *ret_entry; /* hack to avoid leaking memory */
+ GstIndexEntry *ret_entry; /* hack to avoid leaking memory */
};
struct _GstFileIndexClass
@@ -164,9 +165,10 @@ gst_file_index_get_type (void)
(GInstanceInitFunc) gst_file_index_init,
NULL
};
+
file_index_type =
- g_type_register_static (GST_TYPE_INDEX, "GstFileIndex",
- &file_index_info, 0);
+ g_type_register_static (GST_TYPE_INDEX, "GstFileIndex",
+ &file_index_info, 0);
}
return file_index_type;
}
@@ -193,7 +195,7 @@ gst_file_index_class_init (GstFileIndexClass * klass)
g_object_class_install_property (gobject_class, ARG_LOCATION,
g_param_spec_string ("location", "File Location",
- "Location of the index file", NULL, G_PARAM_READWRITE));
+ "Location of the index file", NULL, G_PARAM_READWRITE));
}
static void
@@ -251,7 +253,7 @@ gst_file_index_dispose (GObject * object)
g_hash_table_destroy (index->id_index);
index->id_index = NULL;
- gst_index_entry_free (index->ret_entry); /* hack */
+ gst_index_entry_free (index->ret_entry); /* hack */
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@@ -299,7 +301,7 @@ gst_file_index_get_writer_id (GstIndex * _index,
if (match) {
GST_CAT_WARNING_OBJECT (DC, index, "Duplicate matches for writer '%s'",
- writer_string);
+ writer_string);
continue;
}
@@ -320,10 +322,10 @@ gst_file_index_get_writer_id (GstIndex * _index,
if (cx.ii) {
match = TRUE;
GST_CAT_DEBUG_OBJECT (DC, index, "Resolved writer '%s' again",
- writer_string);
+ writer_string);
} else
GST_CAT_WARNING_OBJECT (DC, index, "Can't resolve writer '%s'",
- writer_string);
+ writer_string);
}
return match;
@@ -384,73 +386,73 @@ gst_file_index_load (GstFileIndex * index)
xmlNodePtr writer;
for (writer = part->children; writer; writer = writer->next) {
- xmlChar *datafile = xmlGetProp (writer, "datafile");
- gchar *path = g_strdup_printf ("%s/%s", index->location, datafile);
- int fd;
- GstFileIndexId *id_index;
- xmlNodePtr wpart;
- xmlChar *entries_str;
- gpointer array_data;
-
- free (datafile);
-
- fd = open (path, O_RDONLY);
- g_free (path);
- if (fd < 0) {
- GST_CAT_ERROR_OBJECT (DC, index,
- "Can't open '%s': %s", path, strerror (errno));
- continue;
- }
-
- id_index = g_new0 (GstFileIndexId, 1);
- id_index->id_desc = xmlGetProp (writer, "id");
-
- for (wpart = writer->children; wpart; wpart = wpart->next) {
- if (strcmp (wpart->name, "formats") == 0) {
- xmlChar *count_str = xmlGetProp (wpart, "count");
- gint fx = 0;
- xmlNodePtr format;
-
- id_index->nformats = atoi (count_str);
- free (count_str);
-
- id_index->format = g_new (GstFormat, id_index->nformats);
-
- for (format = wpart->children; format; format = format->next) {
- xmlChar *nick = xmlGetProp (format, "nick");
- GstFormat fmt = gst_format_get_by_nick (nick);
-
- if (fmt == GST_FORMAT_UNDEFINED)
- GST_CAT_ERROR_OBJECT (DC, index, "format '%s' undefined", nick);
- g_assert (fx < id_index->nformats);
- id_index->format[fx++] = fmt;
- free (nick);
- }
- } else
- GST_CAT_INFO_OBJECT (DC, index, "unknown wpart '%s'", wpart->name);
- }
-
- g_assert (id_index->nformats > 0);
- _fc_alloc_array (id_index);
- g_assert (id_index->array->data == NULL); /* little bit risky */
-
- entries_str = xmlGetProp (writer, "entries");
- id_index->array->len = atoi (entries_str);
- free (entries_str);
-
- array_data =
- mmap (NULL, ARRAY_TOTAL_SIZE (id_index), PROT_READ, MAP_SHARED, fd,
- 0);
- close (fd);
- if (array_data == MAP_FAILED) {
- GST_CAT_ERROR_OBJECT (DC, index,
- "mmap %s failed: %s", path, strerror (errno));
- continue;
- }
-
- id_index->array->data = array_data;
-
- index->unresolved = g_slist_prepend (index->unresolved, id_index);
+ xmlChar *datafile = xmlGetProp (writer, "datafile");
+ gchar *path = g_strdup_printf ("%s/%s", index->location, datafile);
+ int fd;
+ GstFileIndexId *id_index;
+ xmlNodePtr wpart;
+ xmlChar *entries_str;
+ gpointer array_data;
+
+ free (datafile);
+
+ fd = open (path, O_RDONLY);
+ g_free (path);
+ if (fd < 0) {
+ GST_CAT_ERROR_OBJECT (DC, index,
+ "Can't open '%s': %s", path, strerror (errno));
+ continue;
+ }
+
+ id_index = g_new0 (GstFileIndexId, 1);
+ id_index->id_desc = xmlGetProp (writer, "id");
+
+ for (wpart = writer->children; wpart; wpart = wpart->next) {
+ if (strcmp (wpart->name, "formats") == 0) {
+ xmlChar *count_str = xmlGetProp (wpart, "count");
+ gint fx = 0;
+ xmlNodePtr format;
+
+ id_index->nformats = atoi (count_str);
+ free (count_str);
+
+ id_index->format = g_new (GstFormat, id_index->nformats);
+
+ for (format = wpart->children; format; format = format->next) {
+ xmlChar *nick = xmlGetProp (format, "nick");
+ GstFormat fmt = gst_format_get_by_nick (nick);
+
+ if (fmt == GST_FORMAT_UNDEFINED)
+ GST_CAT_ERROR_OBJECT (DC, index, "format '%s' undefined", nick);
+ g_assert (fx < id_index->nformats);
+ id_index->format[fx++] = fmt;
+ free (nick);
+ }
+ } else
+ GST_CAT_INFO_OBJECT (DC, index, "unknown wpart '%s'", wpart->name);
+ }
+
+ g_assert (id_index->nformats > 0);
+ _fc_alloc_array (id_index);
+ g_assert (id_index->array->data == NULL); /* little bit risky */
+
+ entries_str = xmlGetProp (writer, "entries");
+ id_index->array->len = atoi (entries_str);
+ free (entries_str);
+
+ array_data =
+ mmap (NULL, ARRAY_TOTAL_SIZE (id_index), PROT_READ, MAP_SHARED, fd,
+ 0);
+ close (fd);
+ if (array_data == MAP_FAILED) {
+ GST_CAT_ERROR_OBJECT (DC, index,
+ "mmap %s failed: %s", path, strerror (errno));
+ continue;
+ }
+
+ id_index->array->data = array_data;
+
+ index->unresolved = g_slist_prepend (index->unresolved, id_index);
}
} else
GST_CAT_INFO_OBJECT (DC, index, "unknown part '%s'", part->name);
@@ -472,11 +474,11 @@ gst_file_index_set_property (GObject * object,
switch (prop_id) {
case ARG_LOCATION:
if (index->location)
- g_free (index->location);
+ g_free (index->location);
index->location = g_value_dup_string (value);
if (index->location && !g_hash_table_size (index->id_index))
- gst_file_index_load (index);
+ gst_file_index_load (index);
break;
}
}
@@ -512,7 +514,7 @@ _file_index_id_save_xml (gpointer _key, GstFileIndexId * ii, xmlNodePtr writers)
xmlSetProp (writer, "id", ii->id_desc);
g_snprintf (buf, bufsize, "%d", ii->array->len);
xmlSetProp (writer, "entries", buf);
- g_snprintf (buf, bufsize, "%d", ii->id); /* any unique number is OK */
+ g_snprintf (buf, bufsize, "%d", ii->id); /* any unique number is OK */
xmlSetProp (writer, "datafile", buf);
formats = xmlNewChild (writer, NULL, "formats", NULL);
@@ -604,7 +606,7 @@ gst_file_index_commit (GstIndex * _index, gint _writer_id)
if (mkdir (index->location, 0777) && errno != EEXIST) {
GST_CAT_ERROR_OBJECT (DC, index,
- "mkdir %s: %s", index->location, strerror (errno));
+ "mkdir %s: %s", index->location, strerror (errno));
return;
}
@@ -705,11 +707,11 @@ _fc_bsearch (GArray * ary,
if (cmp == 0) {
/* if there are multiple matches then scan for the first match */
while (mid > 0 &&
- (*compare) (sample, ary->data + (mid - 1) * stride, user_data) == 0)
- --mid;
+ (*compare) (sample, ary->data + (mid - 1) * stride, user_data) == 0)
+ --mid;
if (ret)
- *ret = mid;
+ *ret = mid;
return TRUE;
}
@@ -726,12 +728,12 @@ _fc_bsearch (GArray * ary,
if (cmp < 0) {
if (ret)
- *ret = tx;
+ *ret = tx;
return FALSE;
}
if (cmp == 0) {
if (ret)
- *ret = tx;
+ *ret = tx;
return TRUE;
}
}
@@ -772,7 +774,7 @@ gst_file_index_add_association (GstIndex * index, GstIndexEntry * entry)
id_index->nformats = GST_INDEX_NASSOCS (entry);
GST_CAT_LOG_OBJECT (DC, fileindex, "creating %d formats for %d",
- id_index->nformats, entry->id);
+ id_index->nformats, entry->id);
id_index->format = g_new (GstFormat, id_index->nformats);
for (fx = 0; fx < id_index->nformats; fx++)
id_index->format[fx] = GST_INDEX_ASSOC_FORMAT (entry, fx);
@@ -781,14 +783,14 @@ gst_file_index_add_association (GstIndex * index, GstIndexEntry * entry)
/* only sanity checking */
if (id_index->nformats != GST_INDEX_NASSOCS (entry))
GST_CAT_WARNING_OBJECT (DC, fileindex, "arity change %d -> %d",
- id_index->nformats, GST_INDEX_NASSOCS (entry));
+ id_index->nformats, GST_INDEX_NASSOCS (entry));
else {
gint fx;
for (fx = 0; fx < id_index->nformats; fx++)
- if (id_index->format[fx] != GST_INDEX_ASSOC_FORMAT (entry, fx))
- GST_CAT_WARNING_OBJECT (DC, fileindex, "format[%d] changed %d -> %d",
- fx, id_index->format[fx], GST_INDEX_ASSOC_FORMAT (entry, fx));
+ if (id_index->format[fx] != GST_INDEX_ASSOC_FORMAT (entry, fx))
+ GST_CAT_WARNING_OBJECT (DC, fileindex, "format[%d] changed %d -> %d",
+ fx, id_index->format[fx], GST_INDEX_ASSOC_FORMAT (entry, fx));
}
}
@@ -803,8 +805,8 @@ gst_file_index_add_association (GstIndex * index, GstIndexEntry * entry)
if (exact) {
/* maybe overwrite instead? */
GST_CAT_DEBUG_OBJECT (DC, index,
- "Ignoring duplicate index association at %lld",
- GST_INDEX_ASSOC_VALUE (entry, 0));
+ "Ignoring duplicate index association at %lld",
+ GST_INDEX_ASSOC_VALUE (entry, 0));
return;
}
@@ -872,7 +874,7 @@ gst_file_index_add_entry (GstIndex * index, GstIndexEntry * entry)
break;
case GST_INDEX_ENTRY_OBJECT:
GST_CAT_ERROR_OBJECT (DC, index,
- "gst_file_index_add_object not implemented");
+ "gst_file_index_add_object not implemented");
break;
case GST_INDEX_ENTRY_FORMAT:
/*
@@ -880,7 +882,7 @@ gst_file_index_add_entry (GstIndex * index, GstIndexEntry * entry)
GST_INDEX_ENTRY_* can probably go away.
*/
GST_CAT_DEBUG_OBJECT (DC, index,
- "gst_file_index_add_format not implemented");
+ "gst_file_index_add_format not implemented");
break;
default:
break;
@@ -922,7 +924,7 @@ gst_file_index_get_assoc_entry (GstIndex * index,
if (formatx == -1) {
GST_CAT_WARNING_OBJECT (DC, fileindex,
- "%s, format %d not available", __FUNCTION__, format);
+ "%s, format %d not available", __FUNCTION__, format);
return NULL;
}
@@ -938,11 +940,11 @@ gst_file_index_get_assoc_entry (GstIndex * index,
return NULL;
else if (method == GST_INDEX_LOOKUP_BEFORE) {
if (mx == 0)
- return NULL;
+ return NULL;
mx -= 1;
} else if (method == GST_INDEX_LOOKUP_AFTER) {
if (mx == id_index->array->len)
- return NULL;
+ return NULL;
}
}
@@ -952,11 +954,11 @@ gst_file_index_get_assoc_entry (GstIndex * index,
if (method != GST_INDEX_LOOKUP_EXACT)
while ((GINT32_FROM_BE (ARRAY_ROW_FLAGS (row_data)) & flags) != flags) {
if (method == GST_INDEX_LOOKUP_BEFORE)
- mx -= 1;
+ mx -= 1;
else if (method == GST_INDEX_LOOKUP_AFTER)
- mx += 1;
+ mx += 1;
if (mx < 0 || mx >= id_index->array->len)
- return NULL;
+ return NULL;
row_data = id_index->array->data + mx * ARRAY_ROW_SIZE (id_index);
}