gst/gststructure.c (gst_structure_get_type): Ditto

Original commit message from CVS:
* gst/gststructure.c (gst_structure_get_type): Ditto

* gst/gststructure.h: Ditto
This commit is contained in:
Johan Dahlin 2004-03-12 19:35:40 +00:00
parent 37d2e6d087
commit 3798f1c4fa
4 changed files with 229 additions and 164 deletions

View file

@ -1,14 +1,18 @@
2004-03-12 Johan Dahlin <johan@gnome.org> 2004-03-12 Johan Dahlin <johan@gnome.org>
* gst/gstcaps.h (GST_CAPS_IS_SIMPLE): Capitalize macro
* gst/gstcaps.h: Clean up
* gst/gst.c (init_post): call gst_caps_get_type() instead of * gst/gst.c (init_post): call gst_caps_get_type() instead of
_gst_caps_initalize() _gst_caps_initalize()
* gst/gstcaps.c: Style fixes, stay closer to glib and friends * gst/gstcaps.c: Style fixes, stay closer to glib and friends
(_gst_caps_initialize): Remove, in favor for gst_caps_get_type() (_gst_caps_initialize): Remove, in favor for gst_caps_get_type()
* gst/gstcaps.h (GST_CAPS_IS_SIMPLE): Capitalize macro * gst/gststructure.c (gst_structure_get_type): Ditto
* gst/gstcaps.h: Clean up
* gst/gststructure.h: Ditto
2004-03-11 Ronald Bultje <rbultje@ronald.bitfreak.net> 2004-03-11 Ronald Bultje <rbultje@ronald.bitfreak.net>
* gst/gstqueue.c: (gst_queue_init): * gst/gstqueue.c: (gst_queue_init):

View file

@ -539,7 +539,7 @@ init_post (void)
_gst_plugin_register_static (&plugin_desc); _gst_plugin_register_static (&plugin_desc);
_gst_cpu_initialize (_gst_enable_cpu_opt); _gst_cpu_initialize (_gst_enable_cpu_opt);
_gst_structure_initialize (); gst_structure_get_type ();
_gst_value_initialize (); _gst_value_initialize ();
gst_caps_get_type (); gst_caps_get_type ();
_gst_plugin_initialize (); _gst_plugin_initialize ();

View file

@ -28,9 +28,8 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gobject/gvaluecollector.h> #include <gobject/gvaluecollector.h>
static GType _gst_structure_type;
typedef struct _GstStructureField GstStructureField; typedef struct _GstStructureField GstStructureField;
struct _GstStructureField { struct _GstStructureField {
GQuark name; GQuark name;
GValue value; GValue value;
@ -39,32 +38,37 @@ struct _GstStructureField {
#define GST_STRUCTURE_FIELD(structure, index) \ #define GST_STRUCTURE_FIELD(structure, index) \
&g_array_index((structure)->fields, GstStructureField, (index)) &g_array_index((structure)->fields, GstStructureField, (index))
static void gst_structure_set_field (GstStructure *structure, static void gst_structure_set_field (GstStructure *structure,
GstStructureField *field); GstStructureField *field);
static GstStructureField *gst_structure_get_field(const GstStructure *structure, static GstStructureField * gst_structure_get_field (const GstStructure *structure,
const gchar *fieldname); const gchar *fieldname);
static GstStructureField *gst_structure_id_get_field(const GstStructure *structure, static GstStructureField * gst_structure_id_get_field (const GstStructure *structure,
GQuark field); GQuark field);
static void gst_structure_transform_to_string (const GValue *src_value,
GValue *dest_value);
static GstStructure * gst_structure_copy_conditional (const GstStructure *structure);
static gboolean gst_structure_parse_value (gchar *str,
gchar **after,
GValue *value,
GType default_type);
static gboolean gst_structure_parse_simple_string (gchar *s,
gchar **end);
static void _gst_structure_transform_to_string(const GValue *src_value, GType
GValue *dest_value); gst_structure_get_type(void)
static GstStructure *_gst_structure_copy_conditional (const GstStructure *structure);
GType gst_structure_get_type(void)
{ {
return _gst_structure_type; static GType gst_structure_type;
}
void _gst_structure_initialize(void) if (!gst_structure_type) {
{ gst_structure_type = g_boxed_type_register_static("GstStructure",
_gst_structure_type = g_boxed_type_register_static("GstStructure", (GBoxedCopyFunc) gst_structure_copy_conditional,
(GBoxedCopyFunc) _gst_structure_copy_conditional, (GBoxedFreeFunc) gst_structure_free);
(GBoxedFreeFunc) gst_structure_free);
g_value_register_transform_func(gst_structure_type, G_TYPE_STRING,
g_value_register_transform_func(_gst_structure_type, G_TYPE_STRING, gst_structure_transform_to_string);
_gst_structure_transform_to_string); }
return gst_structure_type;
} }
/** /**
@ -75,7 +79,8 @@ void _gst_structure_initialize(void)
* *
* Returns: a new, empty #GstStructure * Returns: a new, empty #GstStructure
*/ */
GstStructure *gst_structure_id_empty_new(GQuark quark) GstStructure *
gst_structure_id_empty_new (GQuark quark)
{ {
GstStructure *structure; GstStructure *structure;
@ -96,7 +101,8 @@ GstStructure *gst_structure_id_empty_new(GQuark quark)
* *
* Returns: a new, empty #GstStructure * Returns: a new, empty #GstStructure
*/ */
GstStructure *gst_structure_empty_new(const gchar *name) GstStructure *
gst_structure_empty_new (const gchar *name)
{ {
GstStructure *structure; GstStructure *structure;
@ -123,7 +129,7 @@ GstStructure *gst_structure_empty_new(const gchar *name)
* Returns: a new #GstStructure * Returns: a new #GstStructure
*/ */
GstStructure *gst_structure_new(const gchar *name, GstStructure *gst_structure_new(const gchar *name,
const gchar *firstfield, ...) const gchar *firstfield, ...)
{ {
GstStructure *structure; GstStructure *structure;
va_list varargs; va_list varargs;
@ -151,8 +157,10 @@ GstStructure *gst_structure_new(const gchar *name,
* *
* Returns: a new #GstStructure * Returns: a new #GstStructure
*/ */
GstStructure *gst_structure_new_valist(const gchar *name, GstStructure *
const gchar *firstfield, va_list varargs) gst_structure_new_valist (const gchar *name,
const gchar *firstfield,
va_list varargs)
{ {
GstStructure *structure; GstStructure *structure;
@ -172,7 +180,8 @@ GstStructure *gst_structure_new_valist(const gchar *name,
* *
* Returns: a new #GstStructure. * Returns: a new #GstStructure.
*/ */
GstStructure *gst_structure_copy(const GstStructure *structure) GstStructure *
gst_structure_copy (const GstStructure *structure)
{ {
GstStructure *new_structure; GstStructure *new_structure;
GstStructureField *field; GstStructureField *field;
@ -202,7 +211,8 @@ GstStructure *gst_structure_copy(const GstStructure *structure)
* *
* Frees a #GstStructure and all its fields and values. * Frees a #GstStructure and all its fields and values.
*/ */
void gst_structure_free(GstStructure *structure) void
gst_structure_free (GstStructure *structure)
{ {
GstStructureField *field; GstStructureField *field;
int i; int i;
@ -230,7 +240,8 @@ void gst_structure_free(GstStructure *structure)
* *
* Returns: the name of the structure. * Returns: the name of the structure.
*/ */
const gchar *gst_structure_get_name(const GstStructure *structure) const gchar *
gst_structure_get_name (const GstStructure *structure)
{ {
g_return_val_if_fail(structure != NULL, NULL); g_return_val_if_fail(structure != NULL, NULL);
@ -245,7 +256,8 @@ const gchar *gst_structure_get_name(const GstStructure *structure)
* Sets the name of the structure to the given name. The string * Sets the name of the structure to the given name. The string
* provided is copied before being used. * provided is copied before being used.
*/ */
void gst_structure_set_name(GstStructure *structure, const gchar *name) void
gst_structure_set_name (GstStructure *structure, const gchar *name)
{ {
g_return_if_fail(structure != NULL); g_return_if_fail(structure != NULL);
g_return_if_fail(name != NULL); g_return_if_fail(name != NULL);
@ -263,8 +275,10 @@ void gst_structure_set_name(GstStructure *structure, const gchar *name)
* does not exist, it is created. If the field exists, the previous * does not exist, it is created. If the field exists, the previous
* value is freed. * value is freed.
*/ */
void gst_structure_id_set_value(GstStructure *structure, GQuark field, void
const GValue *value) gst_structure_id_set_value(GstStructure *structure,
GQuark field,
const GValue *value)
{ {
GstStructureField gsfield = { 0, { 0, } }; GstStructureField gsfield = { 0, { 0, } };
@ -287,8 +301,10 @@ void gst_structure_id_set_value(GstStructure *structure, GQuark field,
* does not exist, it is created. If the field exists, the previous * does not exist, it is created. If the field exists, the previous
* value is freed. * value is freed.
*/ */
void gst_structure_set_value(GstStructure *structure, const gchar *fieldname, void
const GValue *value) gst_structure_set_value(GstStructure *structure,
const gchar *fieldname,
const GValue *value)
{ {
g_return_if_fail(structure != NULL); g_return_if_fail(structure != NULL);
g_return_if_fail(fieldname != NULL); g_return_if_fail(fieldname != NULL);
@ -307,7 +323,9 @@ void gst_structure_set_value(GstStructure *structure, const gchar *fieldname,
* Variable arguments should be in the form field name, field type * Variable arguments should be in the form field name, field type
* (as a GType), value. The last variable argument should be NULL. * (as a GType), value. The last variable argument should be NULL.
*/ */
void gst_structure_set(GstStructure *structure, const gchar *field, ...) void
gst_structure_set(GstStructure *structure,
const gchar *field, ...)
{ {
va_list varargs; va_list varargs;
@ -328,8 +346,10 @@ void gst_structure_set(GstStructure *structure, const gchar *field, ...)
* *
* va_list form of #gst_structure_set. * va_list form of #gst_structure_set.
*/ */
void gst_structure_set_valist(GstStructure *structure, const gchar *fieldname, void
va_list varargs) gst_structure_set_valist(GstStructure *structure,
const gchar *fieldname,
va_list varargs)
{ {
GType type; GType type;
int i; int i;
@ -409,7 +429,9 @@ void gst_structure_set_valist(GstStructure *structure, const gchar *fieldname,
* This function is intended mainly for internal use. The function * This function is intended mainly for internal use. The function
* #gst_structure_set() is recommended instead of this one. * #gst_structure_set() is recommended instead of this one.
*/ */
static void gst_structure_set_field(GstStructure *structure, GstStructureField *field) static void
gst_structure_set_field(GstStructure *structure,
GstStructureField *field)
{ {
GstStructureField *f; GstStructureField *f;
int i; int i;
@ -437,8 +459,9 @@ static void gst_structure_set_field(GstStructure *structure, GstStructureField *
* *
* Returns: the #GstStructureField with the given ID * Returns: the #GstStructureField with the given ID
*/ */
static GstStructureField *gst_structure_id_get_field(const GstStructure *structure, static GstStructureField *
GQuark field_id) gst_structure_id_get_field(const GstStructure *structure,
GQuark field_id)
{ {
GstStructureField *field; GstStructureField *field;
int i; int i;
@ -465,13 +488,14 @@ static GstStructureField *gst_structure_id_get_field(const GstStructure *structu
* Returns: the #GstStructureField with the given name * Returns: the #GstStructureField with the given name
*/ */
static GstStructureField * static GstStructureField *
gst_structure_get_field(const GstStructure *structure, const gchar *fieldname) gst_structure_get_field(const GstStructure *structure,
const gchar *fieldname)
{ {
g_return_val_if_fail(structure != NULL, NULL); g_return_val_if_fail(structure != NULL, NULL);
g_return_val_if_fail(fieldname != NULL, NULL); g_return_val_if_fail(fieldname != NULL, NULL);
return gst_structure_id_get_field(structure, return gst_structure_id_get_field(structure,
g_quark_from_string(fieldname)); g_quark_from_string(fieldname));
} }
/** /**
@ -484,7 +508,8 @@ gst_structure_get_field(const GstStructure *structure, const gchar *fieldname)
* Returns: the #GValue corresponding to the field with the given name. * Returns: the #GValue corresponding to the field with the given name.
*/ */
const GValue * const GValue *
gst_structure_get_value(const GstStructure *structure, const gchar *fieldname) gst_structure_get_value(const GstStructure *structure,
const gchar *fieldname)
{ {
GstStructureField *field; GstStructureField *field;
@ -529,7 +554,8 @@ gst_structure_id_get_value(const GstStructure *structure, GQuark field)
* name does not exist, the structure is unchanged. * name does not exist, the structure is unchanged.
*/ */
void void
gst_structure_remove_field(GstStructure *structure, const gchar *fieldname) gst_structure_remove_field(GstStructure *structure,
const gchar *fieldname)
{ {
GstStructureField *field; GstStructureField *field;
GQuark id; GQuark id;
@ -563,7 +589,8 @@ gst_structure_remove_field(GstStructure *structure, const gchar *fieldname)
* argument is ignored. * argument is ignored.
*/ */
void void
gst_structure_remove_fields(GstStructure *structure, const gchar *fieldname, ...) gst_structure_remove_fields(GstStructure *structure,
const gchar *fieldname, ...)
{ {
va_list varargs; va_list varargs;
@ -587,8 +614,9 @@ gst_structure_remove_fields(GstStructure *structure, const gchar *fieldname, ...
* argument is ignored. * argument is ignored.
*/ */
void void
gst_structure_remove_fields_valist(GstStructure *structure, gst_structure_remove_fields_valist (GstStructure *structure,
const gchar *fieldname, va_list varargs) const gchar *fieldname,
va_list varargs)
{ {
gchar *field = (gchar *) fieldname; gchar *field = (gchar *) fieldname;
g_return_if_fail (structure != NULL); g_return_if_fail (structure != NULL);
@ -607,7 +635,7 @@ gst_structure_remove_fields_valist(GstStructure *structure,
* Removes all fields in a GstStructure. * Removes all fields in a GstStructure.
*/ */
void void
gst_structure_remove_all_fields(GstStructure *structure) gst_structure_remove_all_fields (GstStructure *structure)
{ {
GstStructureField *field; GstStructureField *field;
int i; int i;
@ -636,7 +664,8 @@ gst_structure_remove_all_fields(GstStructure *structure)
* Returns: the #GValue of the field * Returns: the #GValue of the field
*/ */
GType GType
gst_structure_get_field_type(const GstStructure *structure, const gchar *fieldname) gst_structure_get_field_type (const GstStructure *structure,
const gchar *fieldname)
{ {
GstStructureField *field; GstStructureField *field;
@ -658,7 +687,7 @@ gst_structure_get_field_type(const GstStructure *structure, const gchar *fieldna
* Returns: the number of fields in the structure * Returns: the number of fields in the structure
*/ */
gint gint
gst_structure_n_fields(const GstStructure *structure) gst_structure_n_fields (const GstStructure *structure)
{ {
g_return_val_if_fail(structure != NULL, 0); g_return_val_if_fail(structure != NULL, 0);
@ -677,8 +706,9 @@ gst_structure_n_fields(const GstStructure *structure)
* FALSE otherwise. * FALSE otherwise.
*/ */
gboolean gboolean
gst_structure_foreach (GstStructure *structure, gst_structure_foreach (GstStructure *structure,
GstStructureForeachFunc func, gpointer user_data) GstStructureForeachFunc func,
gpointer user_data)
{ {
int i; int i;
GstStructureField *field; GstStructureField *field;
@ -704,7 +734,8 @@ gst_structure_foreach (GstStructure *structure,
* Returns: TRUE if the structure contains a field with the given name * Returns: TRUE if the structure contains a field with the given name
*/ */
gboolean gboolean
gst_structure_has_field(const GstStructure *structure, const gchar *fieldname) gst_structure_has_field(const GstStructure *structure,
const gchar *fieldname)
{ {
GstStructureField *field; GstStructureField *field;
@ -757,8 +788,9 @@ gst_structure_has_field_typed(const GstStructure *structure, const gchar *fieldn
* Returns: TRUE if the value could be set correctly * Returns: TRUE if the value could be set correctly
*/ */
gboolean gboolean
gst_structure_get_boolean(const GstStructure *structure, const gchar *fieldname, gst_structure_get_boolean(const GstStructure *structure,
gboolean *value) const gchar *fieldname,
gboolean *value)
{ {
GstStructureField *field; GstStructureField *field;
@ -788,8 +820,9 @@ gst_structure_get_boolean(const GstStructure *structure, const gchar *fieldname,
* Returns: TRUE if the value could be set correctly * Returns: TRUE if the value could be set correctly
*/ */
gboolean gboolean
gst_structure_get_int(const GstStructure *structure, const gchar *fieldname, gst_structure_get_int(const GstStructure *structure,
gint *value) const gchar *fieldname,
gint *value)
{ {
GstStructureField *field; GstStructureField *field;
@ -820,8 +853,9 @@ gst_structure_get_int(const GstStructure *structure, const gchar *fieldname,
* Returns: TRUE if the value could be set correctly * Returns: TRUE if the value could be set correctly
*/ */
gboolean gboolean
gst_structure_get_fourcc(const GstStructure *structure, const gchar *fieldname, gst_structure_get_fourcc(const GstStructure *structure,
guint32 *value) const gchar *fieldname,
guint32 *value)
{ {
GstStructureField *field; GstStructureField *field;
@ -851,8 +885,10 @@ gst_structure_get_fourcc(const GstStructure *structure, const gchar *fieldname,
* *
* Returns: TRUE if the value could be set correctly * Returns: TRUE if the value could be set correctly
*/ */
gboolean gst_structure_get_double(const GstStructure *structure, gboolean
const gchar *fieldname, gdouble *value) gst_structure_get_double(const GstStructure *structure,
const gchar *fieldname,
gdouble *value)
{ {
GstStructureField *field; GstStructureField *field;
@ -885,7 +921,8 @@ gboolean gst_structure_get_double(const GstStructure *structure,
* Returns: a pointer to the string * Returns: a pointer to the string
*/ */
const gchar * const gchar *
gst_structure_get_string(const GstStructure *structure, const gchar *fieldname) gst_structure_get_string (const GstStructure *structure,
const gchar *fieldname)
{ {
GstStructureField *field; GstStructureField *field;
@ -905,7 +942,7 @@ typedef struct _GstStructureAbbreviation {
GType type; GType type;
} GstStructureAbbreviation; } GstStructureAbbreviation;
static GstStructureAbbreviation _gst_structure_abbrs[] = { static GstStructureAbbreviation gst_structure_abbrs[] = {
{ "int", G_TYPE_INT }, { "int", G_TYPE_INT },
{ "i", G_TYPE_INT }, { "i", G_TYPE_INT },
{ "float", G_TYPE_FLOAT }, { "float", G_TYPE_FLOAT },
@ -921,15 +958,16 @@ static GstStructureAbbreviation _gst_structure_abbrs[] = {
{ "s", G_TYPE_STRING } { "s", G_TYPE_STRING }
}; };
static GType _gst_structure_from_abbr(const char *type_name) static GType
gst_structure_from_abbr (const char *type_name)
{ {
int i; int i;
g_return_val_if_fail(type_name != NULL, G_TYPE_INVALID); g_return_val_if_fail(type_name != NULL, G_TYPE_INVALID);
for(i=0;i<G_N_ELEMENTS(_gst_structure_abbrs);i++){ for(i=0;i<G_N_ELEMENTS(gst_structure_abbrs);i++){
if(strcmp(type_name,_gst_structure_abbrs[i].type_name)==0){ if(strcmp(type_name,gst_structure_abbrs[i].type_name)==0){
return _gst_structure_abbrs[i].type; return gst_structure_abbrs[i].type;
} }
} }
@ -941,15 +979,16 @@ static GType _gst_structure_from_abbr(const char *type_name)
return g_type_from_name (type_name); return g_type_from_name (type_name);
} }
static const char *_gst_structure_to_abbr(GType type) static const char *
gst_structure_to_abbr (GType type)
{ {
int i; int i;
g_return_val_if_fail(type != G_TYPE_INVALID, NULL); g_return_val_if_fail(type != G_TYPE_INVALID, NULL);
for(i=0;i<G_N_ELEMENTS(_gst_structure_abbrs);i++){ for(i=0;i<G_N_ELEMENTS(gst_structure_abbrs);i++){
if(type == _gst_structure_abbrs[i].type){ if(type == gst_structure_abbrs[i].type){
return _gst_structure_abbrs[i].type_name; return gst_structure_abbrs[i].type_name;
} }
} }
@ -974,7 +1013,7 @@ static const char *_gst_structure_to_abbr(GType type)
* Returns: a pointer to string allocated by g_malloc() * Returns: a pointer to string allocated by g_malloc()
*/ */
gchar * gchar *
gst_structure_to_string(const GstStructure *structure) gst_structure_to_string (const GstStructure *structure)
{ {
GstStructureField *field; GstStructureField *field;
GString *s; GString *s;
@ -1015,7 +1054,7 @@ gst_structure_to_string(const GstStructure *structure)
type = G_TYPE_DOUBLE; type = G_TYPE_DOUBLE;
} }
g_string_append_printf(s, ", %s=(%s)%s", g_quark_to_string(field->name), g_string_append_printf(s, ", %s=(%s)%s", g_quark_to_string(field->name),
_gst_structure_to_abbr(type), t); gst_structure_to_abbr(type), t);
g_free(t); g_free(t);
} }
return g_string_free(s, FALSE); return g_string_free(s, FALSE);
@ -1028,9 +1067,8 @@ gst_structure_to_string(const GstStructure *structure)
* unread data. * unread data.
* THIS FUNCTION MODIFIES THE STRING AND DETECTS INSIDE A NONTERMINATED STRING * THIS FUNCTION MODIFIES THE STRING AND DETECTS INSIDE A NONTERMINATED STRING
*/ */
static gboolean _gst_structure_parse_simple_string (gchar *s, gchar **end);
static gboolean static gboolean
_gst_structure_parse_string (gchar *s, gchar **end, gchar **next) gst_structure_parse_string (gchar *s, gchar **end, gchar **next)
{ {
gchar *w; gchar *w;
@ -1039,7 +1077,7 @@ _gst_structure_parse_string (gchar *s, gchar **end, gchar **next)
if (*s != '"') { if (*s != '"') {
int ret; int ret;
ret = _gst_structure_parse_simple_string (s, end); ret = gst_structure_parse_simple_string (s, end);
*next = *end; *next = *end;
return ret; return ret;
@ -1066,11 +1104,8 @@ _gst_structure_parse_string (gchar *s, gchar **end, gchar **next)
return TRUE; return TRUE;
} }
static gboolean _gst_structure_parse_value (gchar *str, gchar **after,
GValue *value, GType default_type);
static gboolean static gboolean
_gst_structure_parse_range (gchar *s, gchar **after, GValue *value, GType type) gst_structure_parse_range (gchar *s, gchar **after, GValue *value, GType type)
{ {
GValue value1 = { 0 }; GValue value1 = { 0 };
GValue value2 = { 0 }; GValue value2 = { 0 };
@ -1081,7 +1116,7 @@ _gst_structure_parse_range (gchar *s, gchar **after, GValue *value, GType type)
if (*s != '[') return FALSE; if (*s != '[') return FALSE;
s++; s++;
ret = _gst_structure_parse_value(s, &s, &value1, type); ret = gst_structure_parse_value(s, &s, &value1, type);
if (ret == FALSE) return FALSE; if (ret == FALSE) return FALSE;
while (g_ascii_isspace (*s)) s++; while (g_ascii_isspace (*s)) s++;
@ -1091,7 +1126,7 @@ _gst_structure_parse_range (gchar *s, gchar **after, GValue *value, GType type)
while (g_ascii_isspace (*s)) s++; while (g_ascii_isspace (*s)) s++;
ret = _gst_structure_parse_value(s, &s, &value2, type); ret = gst_structure_parse_value(s, &s, &value2, type);
if (ret == FALSE) return FALSE; if (ret == FALSE) return FALSE;
while (g_ascii_isspace (*s)) s++; while (g_ascii_isspace (*s)) s++;
@ -1123,7 +1158,7 @@ _gst_structure_parse_range (gchar *s, gchar **after, GValue *value, GType type)
} }
static gboolean static gboolean
_gst_structure_parse_list (gchar *s, gchar **after, GValue *value, GType type) gst_structure_parse_list (gchar *s, gchar **after, GValue *value, GType type)
{ {
GValue list_value = { 0 }; GValue list_value = { 0 };
gboolean ret; gboolean ret;
@ -1142,7 +1177,7 @@ _gst_structure_parse_list (gchar *s, gchar **after, GValue *value, GType type)
return TRUE; return TRUE;
} }
ret = _gst_structure_parse_value(s, &s, &list_value, type); ret = gst_structure_parse_value(s, &s, &list_value, type);
if (ret == FALSE) return FALSE; if (ret == FALSE) return FALSE;
g_array_append_val (array, list_value); g_array_append_val (array, list_value);
@ -1156,7 +1191,7 @@ _gst_structure_parse_list (gchar *s, gchar **after, GValue *value, GType type)
while (g_ascii_isspace (*s)) s++; while (g_ascii_isspace (*s)) s++;
memset (&list_value, 0, sizeof (list_value)); memset (&list_value, 0, sizeof (list_value));
ret = _gst_structure_parse_value(s, &s, &list_value, type); ret = gst_structure_parse_value(s, &s, &list_value, type);
if (ret == FALSE) return FALSE; if (ret == FALSE) return FALSE;
g_array_append_val (array, list_value); g_array_append_val (array, list_value);
@ -1170,7 +1205,7 @@ _gst_structure_parse_list (gchar *s, gchar **after, GValue *value, GType type)
} }
static gboolean static gboolean
_gst_structure_parse_simple_string (gchar *str, gchar **end) gst_structure_parse_simple_string (gchar *str, gchar **end)
{ {
char *s = str; char *s = str;
@ -1184,7 +1219,9 @@ _gst_structure_parse_simple_string (gchar *str, gchar **end)
} }
static gboolean static gboolean
_gst_structure_parse_field (gchar *str, gchar **after, GstStructureField *field) gst_structure_parse_field (gchar *str,
gchar **after,
GstStructureField *field)
{ {
gchar *name; gchar *name;
gchar *name_end; gchar *name_end;
@ -1195,7 +1232,7 @@ _gst_structure_parse_field (gchar *str, gchar **after, GstStructureField *field)
while(g_ascii_isspace (*s)) s++; while(g_ascii_isspace (*s)) s++;
name = s; name = s;
if (!_gst_structure_parse_simple_string (s, &name_end)) return FALSE; if (!gst_structure_parse_simple_string (s, &name_end)) return FALSE;
s = name_end; s = name_end;
while(g_ascii_isspace (*s)) s++; while(g_ascii_isspace (*s)) s++;
@ -1208,7 +1245,7 @@ _gst_structure_parse_field (gchar *str, gchar **after, GstStructureField *field)
field->name = g_quark_from_string (name); field->name = g_quark_from_string (name);
*name_end = c; *name_end = c;
if (!_gst_structure_parse_value (s, &s, &field->value, G_TYPE_INVALID)) if (!gst_structure_parse_value (s, &s, &field->value, G_TYPE_INVALID))
return FALSE; return FALSE;
*after = s; *after = s;
@ -1216,8 +1253,10 @@ _gst_structure_parse_field (gchar *str, gchar **after, GstStructureField *field)
} }
static gboolean static gboolean
_gst_structure_parse_value (gchar *str, gchar **after, GValue *value, gst_structure_parse_value (gchar *str,
GType default_type) gchar **after,
GValue *value,
GType default_type)
{ {
gchar *type_name; gchar *type_name;
gchar *type_end; gchar *type_end;
@ -1239,7 +1278,7 @@ _gst_structure_parse_value (gchar *str, gchar **after, GValue *value,
s++; s++;
while(g_ascii_isspace (*s)) s++; while(g_ascii_isspace (*s)) s++;
type_name = s; type_name = s;
if (!_gst_structure_parse_simple_string (s, &type_end)) return FALSE; if (!gst_structure_parse_simple_string (s, &type_end)) return FALSE;
s = type_end; s = type_end;
while(g_ascii_isspace (*s)) s++; while(g_ascii_isspace (*s)) s++;
if (*s != ')') return FALSE; if (*s != ')') return FALSE;
@ -1248,7 +1287,7 @@ _gst_structure_parse_value (gchar *str, gchar **after, GValue *value,
c = *type_end; c = *type_end;
*type_end = 0; *type_end = 0;
type = _gst_structure_from_abbr(type_name); type = gst_structure_from_abbr(type_name);
*type_end = c; *type_end = c;
if (type == G_TYPE_INVALID) return FALSE; if (type == G_TYPE_INVALID) return FALSE;
@ -1256,12 +1295,12 @@ _gst_structure_parse_value (gchar *str, gchar **after, GValue *value,
while(g_ascii_isspace (*s)) s++; while(g_ascii_isspace (*s)) s++;
if (*s == '[') { if (*s == '[') {
ret = _gst_structure_parse_range (s, &s, value, type); ret = gst_structure_parse_range (s, &s, value, type);
} else if (*s == '{') { } else if (*s == '{') {
ret = _gst_structure_parse_list (s, &s, value, type); ret = gst_structure_parse_list (s, &s, value, type);
} else { } else {
value_s = s; value_s = s;
if (!_gst_structure_parse_string (s, &value_end, &s)) return FALSE; if (!gst_structure_parse_string (s, &value_end, &s)) return FALSE;
c = *value_end; c = *value_end;
*value_end = 0; *value_end = 0;
@ -1298,7 +1337,8 @@ _gst_structure_parse_value (gchar *str, gchar **after, GValue *value,
* Returns: a new #GstStructure * Returns: a new #GstStructure
*/ */
GstStructure * GstStructure *
gst_structure_from_string (const gchar *string, gchar **end) gst_structure_from_string (const gchar *string,
gchar **end)
{ {
char *name; char *name;
char *copy; char *copy;
@ -1314,7 +1354,7 @@ gst_structure_from_string (const gchar *string, gchar **end)
r = copy; r = copy;
name = r; name = r;
if (!_gst_structure_parse_string (r, &w, &r)) if (!gst_structure_parse_string (r, &w, &r))
goto error; goto error;
while (g_ascii_isspace(*r)) r++; while (g_ascii_isspace(*r)) r++;
@ -1332,7 +1372,7 @@ gst_structure_from_string (const gchar *string, gchar **end)
while (*r && g_ascii_isspace(*r)) r++; while (*r && g_ascii_isspace(*r)) r++;
memset(&field,0,sizeof(field)); memset(&field,0,sizeof(field));
if (!_gst_structure_parse_field (r, &r, &field)) if (!gst_structure_parse_field (r, &r, &field))
goto error; goto error;
gst_structure_set_field(structure, &field); gst_structure_set_field(structure, &field);
while (*r && g_ascii_isspace(*r)) r++; while (*r && g_ascii_isspace(*r)) r++;
@ -1351,7 +1391,8 @@ error:
} }
static void static void
_gst_structure_transform_to_string(const GValue *src_value, GValue *dest_value) gst_structure_transform_to_string(const GValue *src_value,
GValue *dest_value)
{ {
g_return_if_fail(src_value != NULL); g_return_if_fail(src_value != NULL);
g_return_if_fail(dest_value != NULL); g_return_if_fail(dest_value != NULL);
@ -1360,7 +1401,8 @@ _gst_structure_transform_to_string(const GValue *src_value, GValue *dest_value)
gst_structure_to_string (src_value->data[0].v_pointer); gst_structure_to_string (src_value->data[0].v_pointer);
} }
static GstStructure *_gst_structure_copy_conditional (const GstStructure *structure) static GstStructure *
gst_structure_copy_conditional (const GstStructure *structure)
{ {
if (structure) return gst_structure_copy (structure); if (structure) return gst_structure_copy (structure);
return NULL; return NULL;

View file

@ -1,5 +1,5 @@
/* GStreamer /* GStreamer
* Copyright (C) <2003> David A. Schleef <ds@schleef.org> * Copyright (C) 2003 David A. Schleef <ds@schleef.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -25,10 +25,15 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_STRUCTURE (gst_structure_get_type ())
#define GST_STRUCTURE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GST_TYPE_STRUCTURE, GstStructure))
#define GST_IS_STRUCTURE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GST_TYPE_STRUCTURE))
typedef struct _GstStructure GstStructure; typedef struct _GstStructure GstStructure;
typedef gboolean (*GstStructureForeachFunc) (GQuark field_id, GValue *value, typedef gboolean (*GstStructureForeachFunc) (GQuark field_id,
gpointer user_data); GValue * value,
gpointer user_data);
struct _GstStructure { struct _GstStructure {
GType type; GType type;
@ -38,66 +43,80 @@ struct _GstStructure {
GArray *fields; GArray *fields;
}; };
#define GST_TYPE_STRUCTURE (gst_structure_get_type()) GType gst_structure_get_type (void) G_GNUC_CONST;
GType gst_structure_get_type(void); GstStructure * gst_structure_empty_new (const gchar * name);
void _gst_structure_initialize(void); GstStructure * gst_structure_id_empty_new (GQuark quark);
GstStructure * gst_structure_new (const gchar * name,
const gchar * firstfield,
...);
GstStructure * gst_structure_new_valist (const gchar * name,
const gchar * firstfield,
va_list varargs);
GstStructure * gst_structure_copy (const GstStructure *structure);
void gst_structure_free (GstStructure *structure);
GstStructure *gst_structure_empty_new(const gchar *name); G_CONST_RETURN gchar * gst_structure_get_name (const GstStructure *structure);
GstStructure *gst_structure_id_empty_new(GQuark quark); void gst_structure_set_name (GstStructure *structure,
GstStructure *gst_structure_new(const gchar *name, const gchar *name);
const gchar *firstfield, ...);
GstStructure *gst_structure_new_valist(const gchar *name,
const gchar *firstfield, va_list varargs);
GstStructure *gst_structure_copy(const GstStructure *structure);
void gst_structure_free(GstStructure *structure);
G_CONST_RETURN gchar *gst_structure_get_name(const GstStructure *structure); void gst_structure_id_set_value (GstStructure *structure,
void gst_structure_set_name(GstStructure *structure, const gchar *name); GQuark field,
const GValue *value);
void gst_structure_set_value (GstStructure *structure,
const gchar *fieldname,
const GValue *value);
void gst_structure_set (GstStructure *structure,
const gchar *fieldname,
...);
void gst_structure_set_valist (GstStructure *structure,
const gchar *fieldname,
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 *fieldname);
void gst_structure_remove_field (GstStructure *structure,
const gchar *fieldname);
void gst_structure_remove_fields (GstStructure *structure,
const gchar *fieldname,
...);
void gst_structure_remove_fields_valist (GstStructure *structure,
const gchar *fieldname,
va_list varargs);
void gst_structure_remove_all_fields (GstStructure *structure);
void gst_structure_id_set_value(GstStructure *structure, GQuark field, GType gst_structure_get_field_type (const GstStructure *structure,
const GValue *value); const gchar *fieldname);
void gst_structure_set_value(GstStructure *structure, const gchar *fieldname, gboolean gst_structure_foreach (GstStructure *structure,
const GValue *value); GstStructureForeachFunc func,
void gst_structure_set(GstStructure *structure, const gchar *fieldname, ...); gpointer user_data);
void gst_structure_set_valist(GstStructure *structure, const gchar *fieldname, gint gst_structure_n_fields (const GstStructure *structure);
va_list varargs); gboolean gst_structure_has_field (const GstStructure *structure,
G_CONST_RETURN GValue *gst_structure_id_get_value(const GstStructure *structure, const gchar *fieldname);
GQuark field); gboolean gst_structure_has_field_typed (const GstStructure *structure,
G_CONST_RETURN GValue *gst_structure_get_value(const GstStructure *structure, const gchar *fieldname,
const gchar *fieldname); GType type);
void gst_structure_remove_field(GstStructure *structure, const gchar *fieldname);
void gst_structure_remove_fields(GstStructure *structure,
const gchar *fieldname, ...);
void gst_structure_remove_fields_valist(GstStructure *structure,
const gchar *fieldname, va_list varargs);
void gst_structure_remove_all_fields(GstStructure *structure);
GType gst_structure_get_field_type(const GstStructure *structure,
const gchar *fieldname);
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 *fieldname);
gboolean gst_structure_has_field_typed(const GstStructure *structure,
const gchar *fieldname, GType type);
/* utility functions */ /* utility functions */
gboolean gst_structure_get_boolean (const GstStructure *structure,
const gchar *fieldname,
gboolean *value);
gboolean gst_structure_get_int (const GstStructure *structure,
const gchar *fieldname,
gint *value);
gboolean gst_structure_get_fourcc (const GstStructure *structure,
const gchar *fieldname,
guint32 *value);
gboolean gst_structure_get_double (const GstStructure *structure,
const gchar *fieldname,
gdouble *value);
G_CONST_RETURN gchar * gst_structure_get_string (const GstStructure *structure,
const gchar *fieldname);
gboolean gst_structure_get_boolean(const GstStructure *structure, const gchar *fieldname, gchar * gst_structure_to_string (const GstStructure *structure);
gboolean *value); GstStructure * gst_structure_from_string (const gchar *string,
gboolean gst_structure_get_int(const GstStructure *structure, const gchar *fieldname, gchar **end);
gint *value);
gboolean gst_structure_get_fourcc(const GstStructure *structure, const gchar *fieldname,
guint32 *value);
gboolean gst_structure_get_double(const GstStructure *structure, const gchar *fieldname,
gdouble *value);
G_CONST_RETURN gchar *gst_structure_get_string(const GstStructure *structure,
const gchar *fieldname);
gchar * gst_structure_to_string(const GstStructure *structure);
GstStructure * gst_structure_from_string (const gchar *string, gchar **end);
G_END_DECLS G_END_DECLS