Patch 13357 and 13358 from vishnu

Original commit message from CVS:
Patch 13357 and 13358 from vishnu
This commit is contained in:
Wim Taymans 2003-01-05 16:51:46 +00:00
parent d4881f29fd
commit acd487b478
4 changed files with 64 additions and 52 deletions

View file

@ -220,7 +220,7 @@ gst_file_index_get_writer_id (GstIndex *_index,
GSList *elem; GSList *elem;
if (!index->is_loaded) if (!index->is_loaded)
return TRUE; return FALSE;
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);
@ -557,6 +557,7 @@ gst_file_index_add_id (GstIndex *index, GstIndexEntry *entry)
static gboolean static gboolean
_fc_bsearch (GArray * ary, _fc_bsearch (GArray * ary,
gint stride,
gint * ret, gint * ret,
GCompareDataFunc compare, GCompareDataFunc compare,
gconstpointer sample, gconstpointer sample,
@ -584,14 +585,14 @@ _fc_bsearch (GArray * ary,
while (midsize > 1) { while (midsize > 1) {
mid = first + midsize / 2; mid = first + midsize / 2;
cmp = (*compare) (sample, &g_array_index (ary, char, mid), user_data); cmp = (*compare) (sample, ary->data + mid*stride, user_data);
if (cmp == 0) if (cmp == 0)
{ {
// if there are multiple matches then scan for the first match // if there are multiple matches then scan for the first match
while (mid > 0 && while (mid > 0 &&
(*compare) (sample, (*compare) (sample,
&g_array_index (ary, char, mid - 1), ary->data + (mid - 1) * stride,
user_data) == 0) user_data) == 0)
--mid; --mid;
@ -609,7 +610,7 @@ _fc_bsearch (GArray * ary,
for (tx = first; tx <= last; tx++) for (tx = first; tx <= last; tx++)
{ {
cmp = (*compare) (sample, &g_array_index (ary, char, tx), user_data); cmp = (*compare) (sample, ary->data + tx*stride, user_data);
if (cmp < 0) if (cmp < 0)
{ {
@ -635,9 +636,10 @@ file_index_compare (gconstpointer sample,
//GstFileIndexId *id_index = user_data; //GstFileIndexId *id_index = user_data;
const GstIndexAssociation *ca = sample; const GstIndexAssociation *ca = sample;
gint64 val1 = ca->value; gint64 val1 = ca->value;
gint64 val2 = GINT64_FROM_BE (ARRAY_ROW_VALUE (row, ca->format)); gint64 val2_be = ARRAY_ROW_VALUE (row, ca->format);
gint64 val2 = GINT64_FROM_BE (val2_be);
gint64 diff = val2 - val1; gint64 diff = val2 - val1;
return (diff == 0 ? 0 : (diff > 0 ? 1 : -1)); return (diff == 0 ? 0 : (diff < 0 ? 1 : -1));
} }
static void static void
@ -683,7 +685,8 @@ gst_file_index_add_association (GstIndex *index, GstIndexEntry *entry)
sample.value = GST_INDEX_ASSOC_VALUE (entry, 0); sample.value = GST_INDEX_ASSOC_VALUE (entry, 0);
exact = exact =
_fc_bsearch (id_index->array, &mx, file_index_compare, _fc_bsearch (id_index->array, ARRAY_ROW_SIZE (id_index),
&mx, file_index_compare,
&sample, id_index); &sample, id_index);
if (exact) { if (exact) {
@ -698,12 +701,13 @@ gst_file_index_add_association (GstIndex *index, GstIndexEntry *entry)
{ {
gchar row_data[ARRAY_ROW_SIZE (id_index)]; gchar row_data[ARRAY_ROW_SIZE (id_index)];
ARRAY_ROW_FLAGS (row_data) = gint32 flags_host = GST_INDEX_ASSOC_FLAGS (entry);
GINT32_TO_BE (GST_INDEX_ASSOC_FLAGS (entry)); ARRAY_ROW_FLAGS (row_data) = GINT32_TO_BE (flags_host);
for (fx = 0; fx < id_index->nformats; fx++) for (fx = 0; fx < id_index->nformats; fx++) {
ARRAY_ROW_VALUE (row_data, fx) = gint64 val_host = GST_INDEX_ASSOC_VALUE (entry, fx);
GINT64_TO_BE (GST_INDEX_ASSOC_VALUE (entry, fx)); ARRAY_ROW_VALUE (row_data, fx) = GINT64_TO_BE (val_host);
}
g_array_insert_val (id_index->array, mx, row_data); g_array_insert_val (id_index->array, mx, row_data);
} }
@ -806,8 +810,8 @@ gst_file_index_get_assoc_entry (GstIndex *index,
sample.format = formatx; sample.format = formatx;
sample.value = value; sample.value = value;
exact = _fc_bsearch (id_index->array, &mx, file_index_compare, exact = _fc_bsearch (id_index->array, ARRAY_ROW_SIZE (id_index),
&sample, id_index); &mx, file_index_compare, &sample, id_index);
if (!exact) { if (!exact) {
if (method == GST_INDEX_LOOKUP_EXACT) if (method == GST_INDEX_LOOKUP_EXACT)
@ -822,7 +826,7 @@ gst_file_index_get_assoc_entry (GstIndex *index,
} }
} }
row_data = &g_array_index (id_index->array, char, mx); row_data = id_index->array->data + mx * ARRAY_ROW_SIZE (id_index);
// if exact then ignore flags (?) // if exact then ignore flags (?)
if (method != GST_INDEX_LOOKUP_EXACT) if (method != GST_INDEX_LOOKUP_EXACT)
@ -833,7 +837,7 @@ gst_file_index_get_assoc_entry (GstIndex *index,
mx += 1; mx += 1;
if (mx < 0 || mx >= id_index->array->len) if (mx < 0 || mx >= id_index->array->len)
return NULL; return NULL;
row_data = &g_array_index (id_index->array, char, mx); row_data = id_index->array->data + mx * ARRAY_ROW_SIZE (id_index);
} }
// entry memory management needs improvement // entry memory management needs improvement
@ -849,14 +853,16 @@ gst_file_index_get_assoc_entry (GstIndex *index,
entry->data.assoc.assocs = entry->data.assoc.assocs =
g_new (GstIndexAssociation, id_index->nformats); g_new (GstIndexAssociation, id_index->nformats);
GST_INDEX_ASSOC_FLAGS (entry) = {
GINT32_FROM_BE (ARRAY_ROW_FLAGS (row_data)); gint32 flags_be = ARRAY_ROW_FLAGS (row_data);
GST_INDEX_ASSOC_FLAGS (entry) = GINT32_FROM_BE (flags_be);
for (xx=0; xx < id_index->nformats; xx++) for (xx=0; xx < id_index->nformats; xx++)
{ {
gint64 val_be = ARRAY_ROW_VALUE (row_data, xx);
GST_INDEX_ASSOC_FORMAT (entry, xx) = id_index->format[xx]; GST_INDEX_ASSOC_FORMAT (entry, xx) = id_index->format[xx];
GST_INDEX_ASSOC_VALUE (entry, xx) = GST_INDEX_ASSOC_VALUE (entry, xx) = GINT64_FROM_BE (val_be);
GINT64_FROM_BE (ARRAY_ROW_VALUE (row_data, xx)); }
} }
return entry; return entry;

View file

@ -185,7 +185,7 @@ gst_mem_index_add_id (GstIndex *index, GstIndexEntry *entry)
id_index->id = entry->id; id_index->id = entry->id;
id_index->format_index = g_hash_table_new (g_int_hash, g_int_equal); id_index->format_index = g_hash_table_new (g_int_hash, g_int_equal);
g_hash_table_insert (memindex->id_index, &entry->id, id_index); g_hash_table_insert (memindex->id_index, &id_index->id, id_index);
} }
} }
@ -223,7 +223,7 @@ gst_mem_index_index_format (GstMemIndexId *id_index, GstIndexEntry *entry, gint
index->offset = assoc; index->offset = assoc;
index->tree = g_tree_new_with_data (mem_index_compare, index); index->tree = g_tree_new_with_data (mem_index_compare, index);
g_hash_table_insert (id_index->format_index, format, index); g_hash_table_insert (id_index->format_index, &index->format, index);
} }
g_tree_insert (index->tree, entry, entry); g_tree_insert (index->tree, entry, entry);

View file

@ -220,7 +220,7 @@ gst_file_index_get_writer_id (GstIndex *_index,
GSList *elem; GSList *elem;
if (!index->is_loaded) if (!index->is_loaded)
return TRUE; return FALSE;
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);
@ -557,6 +557,7 @@ gst_file_index_add_id (GstIndex *index, GstIndexEntry *entry)
static gboolean static gboolean
_fc_bsearch (GArray * ary, _fc_bsearch (GArray * ary,
gint stride,
gint * ret, gint * ret,
GCompareDataFunc compare, GCompareDataFunc compare,
gconstpointer sample, gconstpointer sample,
@ -584,14 +585,14 @@ _fc_bsearch (GArray * ary,
while (midsize > 1) { while (midsize > 1) {
mid = first + midsize / 2; mid = first + midsize / 2;
cmp = (*compare) (sample, &g_array_index (ary, char, mid), user_data); cmp = (*compare) (sample, ary->data + mid*stride, user_data);
if (cmp == 0) if (cmp == 0)
{ {
// if there are multiple matches then scan for the first match // if there are multiple matches then scan for the first match
while (mid > 0 && while (mid > 0 &&
(*compare) (sample, (*compare) (sample,
&g_array_index (ary, char, mid - 1), ary->data + (mid - 1) * stride,
user_data) == 0) user_data) == 0)
--mid; --mid;
@ -609,7 +610,7 @@ _fc_bsearch (GArray * ary,
for (tx = first; tx <= last; tx++) for (tx = first; tx <= last; tx++)
{ {
cmp = (*compare) (sample, &g_array_index (ary, char, tx), user_data); cmp = (*compare) (sample, ary->data + tx*stride, user_data);
if (cmp < 0) if (cmp < 0)
{ {
@ -635,9 +636,10 @@ file_index_compare (gconstpointer sample,
//GstFileIndexId *id_index = user_data; //GstFileIndexId *id_index = user_data;
const GstIndexAssociation *ca = sample; const GstIndexAssociation *ca = sample;
gint64 val1 = ca->value; gint64 val1 = ca->value;
gint64 val2 = GINT64_FROM_BE (ARRAY_ROW_VALUE (row, ca->format)); gint64 val2_be = ARRAY_ROW_VALUE (row, ca->format);
gint64 val2 = GINT64_FROM_BE (val2_be);
gint64 diff = val2 - val1; gint64 diff = val2 - val1;
return (diff == 0 ? 0 : (diff > 0 ? 1 : -1)); return (diff == 0 ? 0 : (diff < 0 ? 1 : -1));
} }
static void static void
@ -683,7 +685,8 @@ gst_file_index_add_association (GstIndex *index, GstIndexEntry *entry)
sample.value = GST_INDEX_ASSOC_VALUE (entry, 0); sample.value = GST_INDEX_ASSOC_VALUE (entry, 0);
exact = exact =
_fc_bsearch (id_index->array, &mx, file_index_compare, _fc_bsearch (id_index->array, ARRAY_ROW_SIZE (id_index),
&mx, file_index_compare,
&sample, id_index); &sample, id_index);
if (exact) { if (exact) {
@ -698,12 +701,13 @@ gst_file_index_add_association (GstIndex *index, GstIndexEntry *entry)
{ {
gchar row_data[ARRAY_ROW_SIZE (id_index)]; gchar row_data[ARRAY_ROW_SIZE (id_index)];
ARRAY_ROW_FLAGS (row_data) = gint32 flags_host = GST_INDEX_ASSOC_FLAGS (entry);
GINT32_TO_BE (GST_INDEX_ASSOC_FLAGS (entry)); ARRAY_ROW_FLAGS (row_data) = GINT32_TO_BE (flags_host);
for (fx = 0; fx < id_index->nformats; fx++) for (fx = 0; fx < id_index->nformats; fx++) {
ARRAY_ROW_VALUE (row_data, fx) = gint64 val_host = GST_INDEX_ASSOC_VALUE (entry, fx);
GINT64_TO_BE (GST_INDEX_ASSOC_VALUE (entry, fx)); ARRAY_ROW_VALUE (row_data, fx) = GINT64_TO_BE (val_host);
}
g_array_insert_val (id_index->array, mx, row_data); g_array_insert_val (id_index->array, mx, row_data);
} }
@ -806,8 +810,8 @@ gst_file_index_get_assoc_entry (GstIndex *index,
sample.format = formatx; sample.format = formatx;
sample.value = value; sample.value = value;
exact = _fc_bsearch (id_index->array, &mx, file_index_compare, exact = _fc_bsearch (id_index->array, ARRAY_ROW_SIZE (id_index),
&sample, id_index); &mx, file_index_compare, &sample, id_index);
if (!exact) { if (!exact) {
if (method == GST_INDEX_LOOKUP_EXACT) if (method == GST_INDEX_LOOKUP_EXACT)
@ -822,7 +826,7 @@ gst_file_index_get_assoc_entry (GstIndex *index,
} }
} }
row_data = &g_array_index (id_index->array, char, mx); row_data = id_index->array->data + mx * ARRAY_ROW_SIZE (id_index);
// if exact then ignore flags (?) // if exact then ignore flags (?)
if (method != GST_INDEX_LOOKUP_EXACT) if (method != GST_INDEX_LOOKUP_EXACT)
@ -833,7 +837,7 @@ gst_file_index_get_assoc_entry (GstIndex *index,
mx += 1; mx += 1;
if (mx < 0 || mx >= id_index->array->len) if (mx < 0 || mx >= id_index->array->len)
return NULL; return NULL;
row_data = &g_array_index (id_index->array, char, mx); row_data = id_index->array->data + mx * ARRAY_ROW_SIZE (id_index);
} }
// entry memory management needs improvement // entry memory management needs improvement
@ -849,14 +853,16 @@ gst_file_index_get_assoc_entry (GstIndex *index,
entry->data.assoc.assocs = entry->data.assoc.assocs =
g_new (GstIndexAssociation, id_index->nformats); g_new (GstIndexAssociation, id_index->nformats);
GST_INDEX_ASSOC_FLAGS (entry) = {
GINT32_FROM_BE (ARRAY_ROW_FLAGS (row_data)); gint32 flags_be = ARRAY_ROW_FLAGS (row_data);
GST_INDEX_ASSOC_FLAGS (entry) = GINT32_FROM_BE (flags_be);
for (xx=0; xx < id_index->nformats; xx++) for (xx=0; xx < id_index->nformats; xx++)
{ {
gint64 val_be = ARRAY_ROW_VALUE (row_data, xx);
GST_INDEX_ASSOC_FORMAT (entry, xx) = id_index->format[xx]; GST_INDEX_ASSOC_FORMAT (entry, xx) = id_index->format[xx];
GST_INDEX_ASSOC_VALUE (entry, xx) = GST_INDEX_ASSOC_VALUE (entry, xx) = GINT64_FROM_BE (val_be);
GINT64_FROM_BE (ARRAY_ROW_VALUE (row_data, xx)); }
} }
return entry; return entry;

View file

@ -185,7 +185,7 @@ gst_mem_index_add_id (GstIndex *index, GstIndexEntry *entry)
id_index->id = entry->id; id_index->id = entry->id;
id_index->format_index = g_hash_table_new (g_int_hash, g_int_equal); id_index->format_index = g_hash_table_new (g_int_hash, g_int_equal);
g_hash_table_insert (memindex->id_index, &entry->id, id_index); g_hash_table_insert (memindex->id_index, &id_index->id, id_index);
} }
} }
@ -223,7 +223,7 @@ gst_mem_index_index_format (GstMemIndexId *id_index, GstIndexEntry *entry, gint
index->offset = assoc; index->offset = assoc;
index->tree = g_tree_new_with_data (mem_index_compare, index); index->tree = g_tree_new_with_data (mem_index_compare, index);
g_hash_table_insert (id_index->format_index, format, index); g_hash_table_insert (id_index->format_index, &index->format, index);
} }
g_tree_insert (index->tree, entry, entry); g_tree_insert (index->tree, entry, entry);