Original commit message from CVS:
fixes:
- don't expose GstStructureField anymore
- fix usage of GstStructureField in caps and tagging to use gst_structure_foreach
- s/gst_structure_field_foreach/gst_structure_foreach/
- added some missing API
- little bugfixes
I confirmed that make check works in caps/ and tags/ as I didn't know what else to test
This commit is contained in:
Benjamin Otte 2003-12-11 03:20:10 +00:00
parent 011c7b3a96
commit 888ccf80f2
7 changed files with 154 additions and 160 deletions

View file

@ -316,12 +316,14 @@ gboolean gst_caps2_is_chained (const GstCaps2 *caps)
return (caps->structs->len > 1);
}
static gboolean
one_value_fixed (GQuark field_id, GValue *value, gpointer unused)
{
return G_TYPE_IS_FUNDAMENTAL (G_VALUE_TYPE (value));
}
gboolean gst_caps2_is_fixed (const GstCaps2 *caps)
{
GstStructure *structure;
GstStructureField *field;
GType type;
int i;
g_return_val_if_fail(caps != NULL, FALSE);
@ -329,51 +331,40 @@ gboolean gst_caps2_is_fixed (const GstCaps2 *caps)
structure = gst_caps2_get_nth_cap (caps, 0);
for(i=0;i<structure->fields->len;i++) {
field = GST_STRUCTURE_FIELD(structure, i);
type = G_VALUE_TYPE(&field->value);
if(type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
type == GST_TYPE_LIST || !(G_TYPE_IS_FUNDAMENTAL(type))) {
return FALSE;
}
}
return TRUE;
return gst_structure_foreach (structure, one_value_fixed, NULL);
}
static gboolean
_gst_structure_field_has_compatible (GQuark field_id,
GValue *val2, gpointer data)
{
GValue dest = { 0 };
GstStructure *struct1 = (GstStructure *) data;
const GValue *val1 = gst_structure_id_get_value (struct1, field_id);
if (val1 == NULL) return FALSE;
if (gst_value_compare (val1, val2) ==
GST_VALUE_EQUAL) {
return TRUE;
}
if (gst_value_intersect (&dest, val1, val2)){
g_value_unset (&dest);
return TRUE;
}
return FALSE;
}
static gboolean _gst_cap_is_always_compatible (const GstStructure *struct1,
const GstStructure *struct2)
{
int i;
const GstStructureField *field1;
const GstStructureField *field2;
if(struct1->name != struct2->name){
return FALSE;
}
for(i=0;i<struct2->fields->len;i++){
GValue dest = { 0 };
/* the reversed order is important */
field2 = GST_STRUCTURE_FIELD (struct2, i);
field1 = gst_structure_id_get_field (struct1, field2->name);
if (field1 == NULL) return FALSE;
if (gst_value_compare (&field1->value, &field2->value) ==
GST_VALUE_EQUAL) {
break;
}
if (gst_value_intersect (&dest, &field1->value, &field2->value)){
g_value_unset (&dest);
break;
}
return FALSE;
}
return TRUE;
/* the reversed order is important */
return gst_structure_foreach ((GstStructure *) struct2,
_gst_structure_field_has_compatible, (gpointer) struct1);
}
static gboolean _gst_caps2_cap_is_always_compatible (const GstStructure
@ -409,57 +400,61 @@ gboolean gst_caps2_is_always_compatible (const GstCaps2 *caps1,
return FALSE;
}
typedef struct {
GstStructure *dest;
const GstStructure *intersect;
gboolean first_run;
} IntersectData;
static gboolean
gst_caps2_structure_intersect_field (GQuark id, GValue *val1, gpointer data)
{
IntersectData *idata = (IntersectData *) data;
GValue dest_value = { 0 };
const GValue *val2 = gst_structure_id_get_value (idata->intersect, id);
if (val2 == NULL) {
gst_structure_id_set_value (idata->dest, id, val1);
} else if (idata->first_run) {
if (gst_value_intersect (&dest_value, val1, val2)) {
gst_structure_id_set_value (idata->dest, id, &dest_value);
g_value_unset (&dest_value);
} else {
return FALSE;
}
}
return TRUE;
}
static GstStructure *gst_caps2_structure_intersect (const GstStructure *struct1,
const GstStructure *struct2)
{
int i;
GstStructure *dest;
const GstStructureField *field1;
const GstStructureField *field2;
int ret;
IntersectData data;
g_return_val_if_fail(struct1 != NULL, NULL);
g_return_val_if_fail(struct2 != NULL, NULL);
if (struct1->name != struct2->name) return NULL;
dest = gst_structure_id_empty_new (struct1->name);
data.dest = gst_structure_id_empty_new (struct1->name);
data.intersect = struct2;
data.first_run = TRUE;
if (!gst_structure_foreach ((GstStructure *) struct1,
gst_caps2_structure_intersect_field, &data))
goto error;
data.intersect = struct1;
data.first_run = FALSE;
if (!gst_structure_foreach ((GstStructure *) struct2,
gst_caps2_structure_intersect_field, &data))
goto error;
for(i=0;i<struct1->fields->len;i++){
GValue dest_field = { 0 };
return data.dest;
field1 = GST_STRUCTURE_FIELD (struct1, i);
field2 = gst_structure_id_get_field (struct2, field1->name);
if (field2 == NULL) {
gst_structure_set_field_copy (dest, field1);
} else {
if (gst_value_intersect (&dest_field, &field1->value, &field2->value)) {
gst_structure_set_value (dest, g_quark_to_string(field1->name),
&dest_field);
} else {
ret = gst_value_compare(&field1->value, &field2->value);
if (ret == GST_VALUE_EQUAL){
gst_structure_set_value (dest, g_quark_to_string(field1->name),
&field1->value);
} else {
gst_structure_free (dest);
return NULL;
}
}
}
}
for(i=0;i<struct1->fields->len;i++){
field2 = GST_STRUCTURE_FIELD (struct2, i);
field1 = gst_structure_id_get_field (struct1, field2->name);
if (field1 == NULL) {
gst_structure_set_field_copy (dest, field2);
}
}
return dest;
error:
gst_structure_free (data.dest);
return NULL;
}
#if 0

View file

@ -121,6 +121,6 @@ gboolean gst_caps2_structure_fixate_field_nearest_double (GstStructure
G_END_DECLS
#endif
#endif /* __GST_CAPS2_H__ */

View file

@ -30,6 +30,22 @@
static GType _gst_structure_type;
typedef struct _GstStructureField GstStructureField;
struct _GstStructureField {
GQuark name;
GValue value;
};
#define GST_STRUCTURE_FIELD(structure, index) \
&g_array_index((structure)->fields, GstStructureField, (index))
static void gst_structure_set_field (GstStructure *structure,
GstStructureField *field);
static GstStructureField *gst_structure_get_field(const GstStructure *structure,
const gchar *fieldname);
static GstStructureField *gst_structure_id_get_field(const GstStructure *structure,
GQuark fieldname);
static void _gst_structure_transform_to_string(const GValue *src_value,
GValue *dest_value);
@ -402,32 +418,6 @@ void gst_structure_set_valist(GstStructure *structure, const gchar *fieldname,
}
}
/**
* gst_structure_set_field_copy:
* @structure: a #GstStructure
* @field: the #GstStructureField to set
*
* Sets a field in the structure. If the structure currently contains
* a field with the same name, it is replaced with the provided field.
* Otherwise, the field is added to the structure. The field's value
* is deeply copied.
*
* This function is intended mainly for internal use. The function
* #gst_structure_set() is recommended instead of this one.
*/
void gst_structure_set_field_copy (GstStructure *structure,
const GstStructureField *field)
{
GstStructureField f = { 0 };
GType type = G_VALUE_TYPE (&field->value);
f.name = field->name;
g_value_init (&f.value, type);
g_value_copy (&field->value, &f.value);
gst_structure_set_field (structure, &f);
}
/**
* gst_structure_set_field:
* @structure: a #GstStructure
@ -441,7 +431,7 @@ void gst_structure_set_field_copy (GstStructure *structure,
* This function is intended mainly for internal use. The function
* #gst_structure_set() is recommended instead of this one.
*/
void gst_structure_set_field(GstStructure *structure, GstStructureField *field)
static void gst_structure_set_field(GstStructure *structure, GstStructureField *field)
{
GstStructureField *f;
int i;
@ -469,7 +459,7 @@ void gst_structure_set_field(GstStructure *structure, GstStructureField *field)
*
* Returns: the #GstStructureField with the given ID
*/
GstStructureField *gst_structure_id_get_field(const GstStructure *structure,
static GstStructureField *gst_structure_id_get_field(const GstStructure *structure,
GQuark field_id)
{
GstStructureField *field;
@ -496,7 +486,7 @@ GstStructureField *gst_structure_id_get_field(const GstStructure *structure,
*
* Returns: the #GstStructureField with the given name
*/
GstStructureField *
static GstStructureField *
gst_structure_get_field(const GstStructure *structure, const gchar *fieldname)
{
g_return_val_if_fail(structure != NULL, NULL);
@ -529,6 +519,29 @@ gst_structure_get_value(const GstStructure *structure, const gchar *fieldname)
return &field->value;
}
/**
* gst_structure_id_get_value:
* @structure: a #GstStructure
* @id: the #GQuark of the field to get
*
* Accessor function.
*
* Returns: the #GValue corresponding to the field with the given name
* identifier.
*/
const GValue *
gst_structure_id_get_value(const GstStructure *structure, GQuark id)
{
GstStructureField *field;
g_return_val_if_fail(structure != NULL, NULL);
field = gst_structure_id_get_field(structure, id);
if(field == NULL) return NULL;
return &field->value;
}
#if 0
void gst_structure_get(GstStructure *structure, const gchar *fieldname, ...)
{
@ -635,15 +648,15 @@ gst_structure_n_fields(const GstStructure *structure)
}
/**
* gst_structure_field_foreach:
* gst_structure_foreach:
* @structure: a #GstStructure
* @func: a function to call for each field
* @user_data: private data
*
* Calls the provided function once for each field in the #GstStructure.
*/
void
gst_structure_field_foreach (GstStructure *structure,
gboolean
gst_structure_foreach (GstStructure *structure,
GstStructureForeachFunc func, gpointer user_data)
{
int i;
@ -654,8 +667,10 @@ gst_structure_field_foreach (GstStructure *structure,
field = GST_STRUCTURE_FIELD(structure, i);
ret = func (field->name, &field->value, user_data);
if (!ret) return;
if (!ret) return FALSE;
}
return TRUE;
}
/**

View file

@ -26,28 +26,18 @@
G_BEGIN_DECLS
typedef struct _GstStructure GstStructure;
typedef struct _GstStructureField GstStructureField;
typedef gboolean (*GstStructureForeachFunc) (GQuark field_id, GValue *value,
gpointer user_data);
struct _GstStructureField {
GQuark name;
GValue value;
};
struct _GstStructure {
GType type;
int len;
GQuark name;
GArray *fields;
};
#define GST_STRUCTURE_FIELD(structure, index) \
&g_array_index((structure)->fields, GstStructureField, (index))
GType gst_structure_get_type(void);
void _gst_structure_initialize(void);
@ -62,10 +52,6 @@ void gst_structure_free(GstStructure *structure);
G_CONST_RETURN gchar *gst_structure_get_name(const GstStructure *structure);
void gst_structure_set_name(GstStructure *structure, const gchar *name);
void gst_structure_set_field_copy (GstStructure *structure,
const GstStructureField *field);
void gst_structure_set_field (GstStructure *structure,
GstStructureField *field);
void gst_structure_id_set_value(GstStructure *structure, GQuark field,
const GValue *value);
@ -74,18 +60,16 @@ void gst_structure_set_value(GstStructure *structure, const gchar *field,
void gst_structure_set(GstStructure *structure, const gchar *field, ...);
void gst_structure_set_valist(GstStructure *structure, const gchar *field,
va_list varargs);
G_CONST_RETURN GValue *gst_structure_id_get_value(const GstStructure *structure,
GQuark field);
G_CONST_RETURN GValue *gst_structure_get_value(const GstStructure *structure,
const gchar *field);
GstStructureField *gst_structure_get_field(const GstStructure *structure,
const gchar *fieldname);
GstStructureField *gst_structure_id_get_field(const GstStructure *structure,
GQuark fieldname);
void gst_structure_remove_field(GstStructure *structure, const gchar *field);
void gst_structure_remove_all_fields(GstStructure *structure);
GType gst_structure_get_field_type(const GstStructure *structure,
const gchar *field);
void gst_structure_field_foreach (GstStructure *structure,
gboolean gst_structure_foreach (GstStructure *structure,
GstStructureForeachFunc func, gpointer user_data);
gint gst_structure_n_fields(const GstStructure *structure);
gboolean gst_structure_has_field(const GstStructure *structure, const gchar *field);

View file

@ -390,26 +390,26 @@ static void
gst_tag_list_add_value_internal (GstStructure *list, GstTagMergeMode mode, GQuark tag, GValue *value)
{
GstTagInfo *info = gst_tag_lookup (tag);
GstStructureField *field;
const GValue *value2;
g_assert (info != NULL);
if (info->merge_func && (field = gst_structure_id_get_field (list, tag)) != NULL) {
GValue value2 = { 0, };
if (info->merge_func && (value2 = gst_structure_id_get_value (list, tag)) != NULL) {
GValue dest = { 0, };
switch (mode) {
case GST_TAG_MERGE_REPLACE_ALL:
case GST_TAG_MERGE_REPLACE:
gst_structure_id_set_value (list, tag, value);
break;
case GST_TAG_MERGE_PREPEND:
gst_value_list_concat (&value2, value, &field->value);
gst_structure_id_set_value (list, tag, &value2);
g_value_unset (&value2);
gst_value_list_concat (&dest, value, value2);
gst_structure_id_set_value (list, tag, &dest);
g_value_unset (&dest);
break;
case GST_TAG_MERGE_APPEND:
gst_value_list_concat (&value2, &field->value, value);
gst_structure_id_set_value (list, tag, &value2);
g_value_unset (&value2);
gst_value_list_concat (&dest, value2, value);
gst_structure_id_set_value (list, tag, &dest);
g_value_unset (&dest);
break;
case GST_TAG_MERGE_KEEP:
case GST_TAG_MERGE_KEEP_ALL:
@ -422,7 +422,7 @@ gst_tag_list_add_value_internal (GstStructure *list, GstTagMergeMode mode, GQuar
switch (mode) {
case GST_TAG_MERGE_APPEND:
case GST_TAG_MERGE_KEEP:
if (gst_structure_id_get_field (list, tag) != NULL)
if (gst_structure_id_get_value (list, tag) != NULL)
break;
/* fall through */
case GST_TAG_MERGE_REPLACE_ALL:
@ -438,7 +438,7 @@ gst_tag_list_add_value_internal (GstStructure *list, GstTagMergeMode mode, GQuar
}
}
}
static int
static gboolean
gst_tag_list_copy_foreach (GQuark tag, GValue *value, gpointer user_data)
{
GstTagCopyData *copy = (GstTagCopyData *) user_data;
@ -469,7 +469,7 @@ gst_tag_list_insert (GstTagList *into, const GstTagList *from, GstTagMergeMode m
if (mode == GST_TAG_MERGE_REPLACE_ALL) {
gst_structure_remove_all_fields (data.list);
}
gst_structure_field_foreach ((GstStructure *) from, gst_tag_list_copy_foreach, &data);
gst_structure_foreach ((GstStructure *) from, gst_tag_list_copy_foreach, &data);
}
/**
* gst_tag_list_copy:
@ -664,7 +664,7 @@ gst_tag_list_foreach (GstTagList *list, GstTagForeachFunc func, gpointer user_da
data.func = func;
data.tag_list = list;
data.data = user_data;
gst_structure_field_foreach ((GstStructure *) list, structure_foreach_wrapper, &data);
gst_structure_foreach ((GstStructure *) list, structure_foreach_wrapper, &data);
}
/***** tag events *****/

View file

@ -390,26 +390,26 @@ static void
gst_tag_list_add_value_internal (GstStructure *list, GstTagMergeMode mode, GQuark tag, GValue *value)
{
GstTagInfo *info = gst_tag_lookup (tag);
GstStructureField *field;
const GValue *value2;
g_assert (info != NULL);
if (info->merge_func && (field = gst_structure_id_get_field (list, tag)) != NULL) {
GValue value2 = { 0, };
if (info->merge_func && (value2 = gst_structure_id_get_value (list, tag)) != NULL) {
GValue dest = { 0, };
switch (mode) {
case GST_TAG_MERGE_REPLACE_ALL:
case GST_TAG_MERGE_REPLACE:
gst_structure_id_set_value (list, tag, value);
break;
case GST_TAG_MERGE_PREPEND:
gst_value_list_concat (&value2, value, &field->value);
gst_structure_id_set_value (list, tag, &value2);
g_value_unset (&value2);
gst_value_list_concat (&dest, value, value2);
gst_structure_id_set_value (list, tag, &dest);
g_value_unset (&dest);
break;
case GST_TAG_MERGE_APPEND:
gst_value_list_concat (&value2, &field->value, value);
gst_structure_id_set_value (list, tag, &value2);
g_value_unset (&value2);
gst_value_list_concat (&dest, value2, value);
gst_structure_id_set_value (list, tag, &dest);
g_value_unset (&dest);
break;
case GST_TAG_MERGE_KEEP:
case GST_TAG_MERGE_KEEP_ALL:
@ -422,7 +422,7 @@ gst_tag_list_add_value_internal (GstStructure *list, GstTagMergeMode mode, GQuar
switch (mode) {
case GST_TAG_MERGE_APPEND:
case GST_TAG_MERGE_KEEP:
if (gst_structure_id_get_field (list, tag) != NULL)
if (gst_structure_id_get_value (list, tag) != NULL)
break;
/* fall through */
case GST_TAG_MERGE_REPLACE_ALL:
@ -438,7 +438,7 @@ gst_tag_list_add_value_internal (GstStructure *list, GstTagMergeMode mode, GQuar
}
}
}
static int
static gboolean
gst_tag_list_copy_foreach (GQuark tag, GValue *value, gpointer user_data)
{
GstTagCopyData *copy = (GstTagCopyData *) user_data;
@ -469,7 +469,7 @@ gst_tag_list_insert (GstTagList *into, const GstTagList *from, GstTagMergeMode m
if (mode == GST_TAG_MERGE_REPLACE_ALL) {
gst_structure_remove_all_fields (data.list);
}
gst_structure_field_foreach ((GstStructure *) from, gst_tag_list_copy_foreach, &data);
gst_structure_foreach ((GstStructure *) from, gst_tag_list_copy_foreach, &data);
}
/**
* gst_tag_list_copy:
@ -664,7 +664,7 @@ gst_tag_list_foreach (GstTagList *list, GstTagForeachFunc func, gpointer user_da
data.func = func;
data.tag_list = list;
data.data = user_data;
gst_structure_field_foreach ((GstStructure *) list, structure_foreach_wrapper, &data);
gst_structure_foreach ((GstStructure *) list, structure_foreach_wrapper, &data);
}
/***** tag events *****/

View file

@ -1403,8 +1403,8 @@ gst_xml_registry_save_structure (GstXMLRegistry *xmlregistry, GstStructure *stru
{
CLASS (xmlregistry)->save_func (xmlregistry, "<structure>\n");
PUT_ESCAPED ("name", g_quark_to_string(structure->name));
gst_structure_field_foreach (structure,
gst_xml_registry_save_structure_field, xmlregistry);
gst_structure_foreach ((GstStructure *) structure,
gst_xml_registry_save_structure_field, xmlregistry);
CLASS (xmlregistry)->save_func (xmlregistry, "</structure>\n");
return TRUE;
}