2003-11-03 09:10:07 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2003 David A. Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* gststructure.c: lists of { GQuark, GValue } tuples
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gobject/gvaluecollector.h>
|
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
typedef struct _GstStructureField GstStructureField;
|
2004-03-12 19:35:40 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
struct _GstStructureField
|
|
|
|
{
|
2003-12-22 01:39:35 +00:00
|
|
|
GQuark name;
|
|
|
|
GValue value;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GST_STRUCTURE_FIELD(structure, index) \
|
|
|
|
&g_array_index((structure)->fields, GstStructureField, (index))
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
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 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);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-12 19:35:40 +00:00
|
|
|
GType
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_type (void)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2004-03-12 19:35:40 +00:00
|
|
|
static GType gst_structure_type;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-12 19:35:40 +00:00
|
|
|
if (!gst_structure_type) {
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_type = g_boxed_type_register_static ("GstStructure",
|
2004-03-15 19:27:17 +00:00
|
|
|
(GBoxedCopyFunc) gst_structure_copy_conditional,
|
|
|
|
(GBoxedFreeFunc) gst_structure_free);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
g_value_register_transform_func (gst_structure_type, G_TYPE_STRING,
|
2004-03-15 19:27:17 +00:00
|
|
|
gst_structure_transform_to_string);
|
2004-03-12 19:35:40 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-03-12 19:35:40 +00:00
|
|
|
return gst_structure_type;
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2003-11-24 02:09:23 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_id_empty_new:
|
2004-01-30 19:06:13 +00:00
|
|
|
* @quark: name of new structure
|
2003-11-24 02:09:23 +00:00
|
|
|
*
|
|
|
|
* Creates a new, empty #GstStructure with the given name.
|
|
|
|
*
|
|
|
|
* Returns: a new, empty #GstStructure
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
GstStructure *
|
|
|
|
gst_structure_id_empty_new (GQuark quark)
|
2003-11-24 02:09:23 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (quark != 0, NULL);
|
2003-11-24 02:09:23 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
structure = g_new0 (GstStructure, 1);
|
2003-11-24 02:09:23 +00:00
|
|
|
structure->name = quark;
|
2004-03-13 15:27:01 +00:00
|
|
|
structure->fields = g_array_new (FALSE, TRUE, sizeof (GstStructureField));
|
2003-11-24 02:09:23 +00:00
|
|
|
|
|
|
|
return structure;
|
|
|
|
}
|
|
|
|
|
2003-11-03 09:10:07 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_empty_new:
|
|
|
|
* @name: name of new structure
|
|
|
|
*
|
|
|
|
* Creates a new, empty #GstStructure with the given name.
|
|
|
|
*
|
|
|
|
* Returns: a new, empty #GstStructure
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
GstStructure *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_empty_new (const gchar * name)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
structure = g_new0 (GstStructure, 1);
|
|
|
|
structure->name = g_quark_from_string (name);
|
|
|
|
structure->fields = g_array_new (FALSE, TRUE, sizeof (GstStructureField));
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return structure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_new:
|
|
|
|
* @name: name of new structure
|
|
|
|
* @firstfield: name of first field to set
|
|
|
|
* @...: additional arguments
|
|
|
|
*
|
|
|
|
* Creates a new #GstStructure with the given name. Parses the
|
|
|
|
* list of variable arguments and sets fields to the values listed.
|
|
|
|
* Variable arguments should be passed as field name, field type,
|
|
|
|
* and value. Last variable argument should be NULL.
|
|
|
|
*
|
|
|
|
* Returns: a new #GstStructure
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstStructure *
|
|
|
|
gst_structure_new (const gchar * name, const gchar * firstfield, ...)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
va_list varargs;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
va_start (varargs, firstfield);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
structure = gst_structure_new_valist (name, firstfield, varargs);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
va_end (varargs);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return structure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_new_valist:
|
|
|
|
* @name: name of new structure
|
|
|
|
* @firstfield: name of first field to set
|
2004-01-30 19:06:13 +00:00
|
|
|
* @varargs: variable argument list
|
2003-11-03 09:10:07 +00:00
|
|
|
*
|
|
|
|
* Creates a new #GstStructure with the given name. Structure fields
|
|
|
|
* are set according to the varargs in a manner similar to
|
|
|
|
* @gst_structure_new.
|
|
|
|
*
|
|
|
|
* Returns: a new #GstStructure
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
GstStructure *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_new_valist (const gchar * name,
|
|
|
|
const gchar * firstfield, va_list varargs)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
structure = gst_structure_empty_new (name);
|
|
|
|
gst_structure_set_valist (structure, firstfield, varargs);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return structure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-11-04 05:54:24 +00:00
|
|
|
* gst_structure_copy:
|
2003-11-03 09:10:07 +00:00
|
|
|
* @structure: a #GstStructure to duplicate
|
|
|
|
*
|
|
|
|
* Duplicates a #GstStructure and all its fields and values.
|
|
|
|
*
|
|
|
|
* Returns: a new #GstStructure.
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
GstStructure *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_copy (const GstStructure * structure)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructure *new_structure;
|
|
|
|
GstStructureField *field;
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
new_structure = gst_structure_empty_new (g_quark_to_string (structure->name));
|
2003-11-03 09:10:07 +00:00
|
|
|
new_structure->name = structure->name;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < structure->fields->len; i++) {
|
2003-11-03 09:10:07 +00:00
|
|
|
GstStructureField new_field = { 0 };
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = GST_STRUCTURE_FIELD (structure, i);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
new_field.name = field->name;
|
2003-12-22 07:00:25 +00:00
|
|
|
gst_value_init_and_copy (&new_field.value, &field->value);
|
2004-03-13 15:27:01 +00:00
|
|
|
g_array_append_val (new_structure->fields, new_field);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2003-12-30 04:59:48 +00:00
|
|
|
return new_structure;
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_free:
|
|
|
|
* @structure: the #GstStructure to free
|
|
|
|
*
|
|
|
|
* Frees a #GstStructure and all its fields and values.
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_free (GstStructure * structure)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (structure != NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < structure->fields->len; i++) {
|
|
|
|
field = GST_STRUCTURE_FIELD (structure, i);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (G_IS_VALUE (&field->value)) {
|
|
|
|
g_value_unset (&field->value);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-02 23:14:42 +00:00
|
|
|
g_array_free (structure->fields, TRUE);
|
2003-12-22 01:39:35 +00:00
|
|
|
#ifdef USE_POISONING
|
2004-03-13 15:27:01 +00:00
|
|
|
memset (structure, 0xff, sizeof (GstStructure));
|
2003-12-22 01:39:35 +00:00
|
|
|
#endif
|
2004-03-13 15:27:01 +00:00
|
|
|
g_free (structure);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_get_name:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
*
|
|
|
|
* Accessor fuction.
|
|
|
|
*
|
|
|
|
* Returns: the name of the structure.
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
const gchar *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_name (const GstStructure * structure)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return g_quark_to_string (structure->name);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_set_name:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @name: the new name of the structure
|
|
|
|
*
|
|
|
|
* Sets the name of the structure to the given name. The string
|
|
|
|
* provided is copied before being used.
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_set_name (GstStructure * structure, const gchar * name)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (structure != NULL);
|
|
|
|
g_return_if_fail (name != NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
structure->name = g_quark_from_string (name);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_id_set_value:
|
|
|
|
* @structure: a #GstStructure
|
2004-01-30 19:06:13 +00:00
|
|
|
* @field: a #GQuark representing a field
|
2003-11-03 09:10:07 +00:00
|
|
|
* @value: the new value of the field
|
|
|
|
*
|
|
|
|
* Sets the field with the given ID to the provided value. If the field
|
|
|
|
* does not exist, it is created. If the field exists, the previous
|
|
|
|
* value is freed.
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_id_set_value (GstStructure * structure,
|
|
|
|
GQuark field, const GValue * value)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GstStructureField gsfield = { 0, {0,} };
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (structure != NULL);
|
|
|
|
g_return_if_fail (G_IS_VALUE (value));
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-01-30 19:11:50 +00:00
|
|
|
gsfield.name = field;
|
|
|
|
gst_value_init_and_copy (&gsfield.value, value);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_set_field (structure, &gsfield);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_set_value:
|
|
|
|
* @structure: a #GstStructure
|
2004-01-30 19:06:13 +00:00
|
|
|
* @fieldname: the name of the field to set
|
2003-11-03 09:10:07 +00:00
|
|
|
* @value: the new value of the field
|
|
|
|
*
|
|
|
|
* Sets the field with the given name to the provided value. If the field
|
|
|
|
* does not exist, it is created. If the field exists, the previous
|
|
|
|
* value is freed.
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_set_value (GstStructure * structure,
|
|
|
|
const gchar * fieldname, const GValue * value)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (structure != NULL);
|
|
|
|
g_return_if_fail (fieldname != NULL);
|
|
|
|
g_return_if_fail (G_IS_VALUE (value));
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_id_set_value (structure, g_quark_from_string (fieldname),
|
|
|
|
value);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_set:
|
|
|
|
* @structure: a #GstStructure
|
2004-01-30 19:06:13 +00:00
|
|
|
* @fieldname: the name of the field to set
|
2003-11-03 09:10:07 +00:00
|
|
|
* @...: variable arguments
|
|
|
|
*
|
|
|
|
* Parses the variable arguments and sets fields accordingly.
|
|
|
|
* Variable arguments should be in the form field name, field type
|
|
|
|
* (as a GType), value. The last variable argument should be NULL.
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_set (GstStructure * structure, const gchar * field, ...)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
va_list varargs;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (structure != NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
va_start (varargs, field);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_set_valist (structure, field, varargs);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
va_end (varargs);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-12-22 01:39:35 +00:00
|
|
|
* gst_structure_set_valist:
|
2003-11-03 09:10:07 +00:00
|
|
|
* @structure: a #GstStructure
|
2004-01-30 19:06:13 +00:00
|
|
|
* @fieldname: the name of the field to set
|
2003-11-03 09:10:07 +00:00
|
|
|
* @varargs: variable arguments
|
|
|
|
*
|
|
|
|
* va_list form of #gst_structure_set.
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_set_valist (GstStructure * structure,
|
|
|
|
const gchar * fieldname, va_list varargs)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GType type;
|
|
|
|
int i;
|
|
|
|
double d;
|
|
|
|
char *s;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (structure != NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (fieldname) {
|
2003-11-03 09:10:07 +00:00
|
|
|
GstStructureField field = { 0 };
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field.name = g_quark_from_string (fieldname);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
type = va_arg (varargs, GType);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
switch (type) {
|
2003-11-03 09:10:07 +00:00
|
|
|
case G_TYPE_INT:
|
2004-03-15 19:27:17 +00:00
|
|
|
i = va_arg (varargs, int);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_init (&field.value, G_TYPE_INT);
|
|
|
|
g_value_set_int (&field.value, i);
|
|
|
|
break;
|
2003-11-03 09:10:07 +00:00
|
|
|
case G_TYPE_DOUBLE:
|
2004-03-15 19:27:17 +00:00
|
|
|
d = va_arg (varargs, double);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_init (&field.value, G_TYPE_DOUBLE);
|
|
|
|
g_value_set_double (&field.value, d);
|
|
|
|
break;
|
2003-11-03 09:10:07 +00:00
|
|
|
case G_TYPE_BOOLEAN:
|
2004-03-15 19:27:17 +00:00
|
|
|
i = va_arg (varargs, int);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_init (&field.value, G_TYPE_BOOLEAN);
|
|
|
|
g_value_set_boolean (&field.value, i);
|
|
|
|
break;
|
2003-11-03 09:10:07 +00:00
|
|
|
case G_TYPE_STRING:
|
2004-03-15 19:27:17 +00:00
|
|
|
s = va_arg (varargs, char *);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_init (&field.value, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&field.value, s);
|
|
|
|
break;
|
2003-11-03 09:10:07 +00:00
|
|
|
default:
|
2004-03-15 19:27:17 +00:00
|
|
|
if (type == GST_TYPE_FOURCC) {
|
|
|
|
i = va_arg (varargs, int);
|
|
|
|
|
|
|
|
g_value_init (&field.value, GST_TYPE_FOURCC);
|
|
|
|
gst_value_set_fourcc (&field.value, i);
|
|
|
|
} else if (type == GST_TYPE_INT_RANGE) {
|
|
|
|
int min, max;
|
|
|
|
min = va_arg (varargs, int);
|
|
|
|
max = va_arg (varargs, int);
|
|
|
|
|
|
|
|
g_value_init (&field.value, GST_TYPE_INT_RANGE);
|
|
|
|
gst_value_set_int_range (&field.value, min, max);
|
|
|
|
} else if (type == GST_TYPE_DOUBLE_RANGE) {
|
|
|
|
double min, max;
|
|
|
|
min = va_arg (varargs, double);
|
|
|
|
max = va_arg (varargs, double);
|
|
|
|
|
|
|
|
g_value_init (&field.value, GST_TYPE_DOUBLE_RANGE);
|
|
|
|
gst_value_set_double_range (&field.value, min, max);
|
2004-04-13 02:22:02 +00:00
|
|
|
} else if (type == GST_TYPE_BUFFER) {
|
|
|
|
GstBuffer *buffer = va_arg (varargs, GstBuffer *);
|
|
|
|
|
|
|
|
g_value_init (&field.value, GST_TYPE_BUFFER);
|
|
|
|
g_value_set_boxed (&field.value, buffer);
|
2004-03-15 19:27:17 +00:00
|
|
|
} else {
|
|
|
|
g_critical ("unimplemented vararg field type %d\n", (int) type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_set_field (structure, &field);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
fieldname = va_arg (varargs, gchar *);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_set_field:
|
|
|
|
* @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 not deeply copied.
|
|
|
|
*
|
|
|
|
* This function is intended mainly for internal use. The function
|
|
|
|
* #gst_structure_set() is recommended instead of this one.
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_set_field (GstStructure * structure, GstStructureField * field)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *f;
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < structure->fields->len; i++) {
|
|
|
|
f = GST_STRUCTURE_FIELD (structure, i);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (f->name == field->name) {
|
|
|
|
g_value_unset (&f->value);
|
|
|
|
memcpy (f, field, sizeof (GstStructureField));
|
2003-11-03 09:10:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_array_append_val (structure->fields, *field);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2004-01-30 19:06:13 +00:00
|
|
|
/* FIXME: is this private ? if so remove gtk-doc
|
2003-11-03 09:10:07 +00:00
|
|
|
* gst_structure_id_get_field:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @field_id: the GQuark of the field to get
|
|
|
|
*
|
|
|
|
* Gets the specified field from the structure. If there is no
|
|
|
|
* field with the given ID, NULL is returned.
|
|
|
|
*
|
|
|
|
* Returns: the #GstStructureField with the given ID
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
static GstStructureField *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_id_get_field (const GstStructure * structure, GQuark field_id)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < structure->fields->len; i++) {
|
|
|
|
field = GST_STRUCTURE_FIELD (structure, i);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (field->name == field_id)
|
|
|
|
return field;
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_get_field:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of the field to get
|
|
|
|
*
|
|
|
|
* Gets the specified field from the structure. If there is no
|
|
|
|
* field with the given ID, NULL is returned.
|
|
|
|
*
|
|
|
|
* Returns: the #GstStructureField with the given name
|
|
|
|
*/
|
2003-12-22 01:39:35 +00:00
|
|
|
static GstStructureField *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_field (const GstStructure * structure,
|
|
|
|
const gchar * fieldname)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, NULL);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return gst_structure_id_get_field (structure,
|
|
|
|
g_quark_from_string (fieldname));
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-11-04 05:54:24 +00:00
|
|
|
* gst_structure_get_value:
|
2003-11-03 09:10:07 +00:00
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of the field to get
|
|
|
|
*
|
|
|
|
* Accessor function.
|
|
|
|
*
|
|
|
|
* Returns: the #GValue corresponding to the field with the given name.
|
|
|
|
*/
|
|
|
|
const GValue *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_value (const GstStructure * structure,
|
|
|
|
const gchar * fieldname)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, NULL);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = gst_structure_get_field (structure, fieldname);
|
|
|
|
if (field == NULL)
|
|
|
|
return NULL;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return &field->value;
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_id_get_value:
|
|
|
|
* @structure: a #GstStructure
|
2004-01-30 19:06:13 +00:00
|
|
|
* @field: the #GQuark of the field to get
|
2003-12-22 01:39:35 +00:00
|
|
|
*
|
|
|
|
* Accessor function.
|
|
|
|
*
|
|
|
|
* Returns: the #GValue corresponding to the field with the given name
|
|
|
|
* identifier.
|
|
|
|
*/
|
|
|
|
const GValue *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_id_get_value (const GstStructure * structure, GQuark field)
|
2003-12-22 01:39:35 +00:00
|
|
|
{
|
2004-01-30 19:11:50 +00:00
|
|
|
GstStructureField *gsfield;
|
2003-12-22 01:39:35 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, NULL);
|
2003-12-22 01:39:35 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gsfield = gst_structure_id_get_field (structure, field);
|
|
|
|
if (gsfield == NULL)
|
|
|
|
return NULL;
|
2003-12-22 01:39:35 +00:00
|
|
|
|
2004-01-30 19:11:50 +00:00
|
|
|
return &gsfield->value;
|
2003-12-22 01:39:35 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 09:10:07 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_remove_field:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of the field to remove
|
|
|
|
*
|
|
|
|
* Removes the field with the given name. If the field with the given
|
|
|
|
* name does not exist, the structure is unchanged.
|
|
|
|
*/
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_remove_field (GstStructure * structure, const gchar * fieldname)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
GQuark id;
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (structure != NULL);
|
|
|
|
g_return_if_fail (fieldname != NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
id = g_quark_from_string (fieldname);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < structure->fields->len; i++) {
|
|
|
|
field = GST_STRUCTURE_FIELD (structure, i);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (field->name == id) {
|
|
|
|
if (G_IS_VALUE (&field->value)) {
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_unset (&field->value);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
structure->fields = g_array_remove_index (structure->fields, i);
|
2003-11-03 09:10:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-29 02:24:52 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_remove_fields:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of the field to remove
|
|
|
|
* @...: NULL-terminated list of more fieldnames to remove
|
|
|
|
*
|
|
|
|
* Removes the field with the given names. If a field does not exist, the
|
|
|
|
* argument is ignored.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
void
|
|
|
|
gst_structure_remove_fields (GstStructure * structure,
|
|
|
|
const gchar * fieldname, ...)
|
2004-01-29 02:24:52 +00:00
|
|
|
{
|
|
|
|
va_list varargs;
|
|
|
|
|
|
|
|
g_return_if_fail (structure != NULL);
|
|
|
|
g_return_if_fail (fieldname != NULL);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
va_start (varargs, fieldname);
|
2004-01-29 02:24:52 +00:00
|
|
|
|
|
|
|
gst_structure_remove_fields_valist (structure, fieldname, varargs);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
va_end (varargs);
|
2004-01-29 02:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_remove_fields_valist:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of the field to remove
|
|
|
|
* @varargs: NULL-terminated list of more fieldnames to remove
|
|
|
|
*
|
|
|
|
* Removes the field with the given names. If a field does not exist, the
|
|
|
|
* argument is ignored.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
void
|
|
|
|
gst_structure_remove_fields_valist (GstStructure * structure,
|
|
|
|
const gchar * fieldname, va_list varargs)
|
2004-01-29 02:24:52 +00:00
|
|
|
{
|
|
|
|
gchar *field = (gchar *) fieldname;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-01-29 02:24:52 +00:00
|
|
|
g_return_if_fail (structure != NULL);
|
|
|
|
g_return_if_fail (fieldname != NULL);
|
|
|
|
|
|
|
|
while (field) {
|
|
|
|
gst_structure_remove_field (structure, field);
|
2004-03-13 15:27:01 +00:00
|
|
|
field = va_arg (varargs, char *);
|
2004-01-29 02:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-24 02:09:23 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_remove_all_fields:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
*
|
|
|
|
* Removes all fields in a GstStructure.
|
|
|
|
*/
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_remove_all_fields (GstStructure * structure)
|
2003-11-24 02:09:23 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
int i;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (structure != NULL);
|
2003-11-24 02:09:23 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = structure->fields->len - 1; i >= 0; i--) {
|
|
|
|
field = GST_STRUCTURE_FIELD (structure, i);
|
2003-11-24 02:09:23 +00:00
|
|
|
|
|
|
|
if (G_IS_VALUE (&field->value)) {
|
2004-03-13 15:27:01 +00:00
|
|
|
g_value_unset (&field->value);
|
2003-11-24 02:09:23 +00:00
|
|
|
}
|
|
|
|
structure->fields = g_array_remove_index (structure->fields, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-03 09:10:07 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_get_field_type:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of the field
|
|
|
|
*
|
|
|
|
* Finds the field with the given name, and returns the type of the
|
2003-11-29 06:31:10 +00:00
|
|
|
* value it contains. If the field is not found, G_TYPE_INVALID is
|
2003-11-03 09:10:07 +00:00
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* Returns: the #GValue of the field
|
|
|
|
*/
|
|
|
|
GType
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_field_type (const GstStructure * structure,
|
|
|
|
const gchar * fieldname)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, G_TYPE_INVALID);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, G_TYPE_INVALID);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = gst_structure_get_field (structure, fieldname);
|
|
|
|
if (field == NULL)
|
|
|
|
return G_TYPE_INVALID;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return G_VALUE_TYPE (&field->value);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_n_fields:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
*
|
|
|
|
* Accessor function.
|
|
|
|
*
|
|
|
|
* Returns: the number of fields in the structure
|
|
|
|
*/
|
|
|
|
gint
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_n_fields (const GstStructure * structure)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, 0);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return structure->fields->len;
|
|
|
|
}
|
|
|
|
|
2003-11-04 19:00:54 +00:00
|
|
|
/**
|
2003-12-22 01:39:35 +00:00
|
|
|
* gst_structure_foreach:
|
2003-11-04 19:00:54 +00:00
|
|
|
* @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.
|
2004-01-30 19:06:13 +00:00
|
|
|
*
|
|
|
|
* Returns: TRUE if the supplied function returns TRUE For each of the fields,
|
|
|
|
* FALSE otherwise.
|
2003-11-04 19:00:54 +00:00
|
|
|
*/
|
2003-12-22 01:39:35 +00:00
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_foreach (GstStructure * structure,
|
|
|
|
GstStructureForeachFunc func, gpointer user_data)
|
2003-11-04 19:00:54 +00:00
|
|
|
{
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2003-11-04 19:00:54 +00:00
|
|
|
GstStructureField *field;
|
2003-12-22 01:39:35 +00:00
|
|
|
gboolean ret;
|
2003-11-04 19:00:54 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < structure->fields->len; i++) {
|
|
|
|
field = GST_STRUCTURE_FIELD (structure, i);
|
2003-11-04 19:00:54 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
ret = func (field->name, &field->value, user_data);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!ret)
|
|
|
|
return FALSE;
|
2003-11-04 19:00:54 +00:00
|
|
|
}
|
2003-12-22 01:39:35 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2003-11-04 19:00:54 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 09:10:07 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_has_field:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of a field
|
|
|
|
*
|
|
|
|
* Accessor function.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the structure contains a field with the given name
|
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_has_field (const GstStructure * structure,
|
|
|
|
const gchar * fieldname)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, 0);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, 0);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = gst_structure_get_field (structure, fieldname);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return (field != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-01-30 19:06:13 +00:00
|
|
|
* gst_structure_has_field_typed:
|
2003-11-03 09:10:07 +00:00
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of a field
|
|
|
|
* @type: the type of a value
|
|
|
|
*
|
|
|
|
* Accessor function.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the structure contains a field with the given name and type
|
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_has_field_typed (const GstStructure * structure,
|
|
|
|
const gchar * fieldname, GType type)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, 0);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, 0);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = gst_structure_get_field (structure, fieldname);
|
|
|
|
if (field == NULL)
|
|
|
|
return FALSE;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return (G_VALUE_TYPE (&field->value) == type);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* utility functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_get_boolean:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of a field
|
2004-01-30 19:06:13 +00:00
|
|
|
* @value: a pointer to a #gboolean to set
|
2003-11-03 09:10:07 +00:00
|
|
|
*
|
2004-01-30 19:06:13 +00:00
|
|
|
* Sets the boolean pointed to by @value corresponding to the value of the
|
2003-11-03 09:10:07 +00:00
|
|
|
* given field. Caller is responsible for making sure the field exists
|
|
|
|
* and has the correct type.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the value could be set correctly
|
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_boolean (const GstStructure * structure,
|
|
|
|
const gchar * fieldname, gboolean * value)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, FALSE);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = gst_structure_get_field (structure, fieldname);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (field == NULL)
|
|
|
|
return FALSE;
|
|
|
|
if (!G_VALUE_HOLDS_BOOLEAN (&field->value))
|
|
|
|
return FALSE;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
*value = g_value_get_boolean (&field->value);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_get_int:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of a field
|
2004-01-30 19:06:13 +00:00
|
|
|
* @value: a pointer to an int to set
|
2003-11-03 09:10:07 +00:00
|
|
|
*
|
2004-01-30 19:06:13 +00:00
|
|
|
* Sets the int pointed to by @value corresponding to the value of the
|
2003-11-03 09:10:07 +00:00
|
|
|
* given field. Caller is responsible for making sure the field exists
|
|
|
|
* and has the correct type.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the value could be set correctly
|
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_int (const GstStructure * structure,
|
|
|
|
const gchar * fieldname, gint * value)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = gst_structure_get_field (structure, fieldname);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (field == NULL)
|
|
|
|
return FALSE;
|
|
|
|
if (!G_VALUE_HOLDS_INT (&field->value))
|
|
|
|
return FALSE;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
*value = g_value_get_int (&field->value);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_get_fourcc:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of a field
|
2004-01-30 19:06:13 +00:00
|
|
|
* @value: a pointer to a #GstFourcc to set
|
2003-11-03 09:10:07 +00:00
|
|
|
*
|
2004-01-30 19:06:13 +00:00
|
|
|
* Sets the #GstFourcc pointed to by @value corresponding to the value of the
|
2003-11-03 09:10:07 +00:00
|
|
|
* given field. Caller is responsible for making sure the field exists
|
|
|
|
* and has the correct type.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the value could be set correctly
|
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_fourcc (const GstStructure * structure,
|
|
|
|
const gchar * fieldname, guint32 * value)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = gst_structure_get_field (structure, fieldname);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (field == NULL)
|
|
|
|
return FALSE;
|
|
|
|
if (!GST_VALUE_HOLDS_FOURCC (&field->value))
|
|
|
|
return FALSE;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
*value = gst_value_get_fourcc (&field->value);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_get_double:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of a field
|
2004-01-30 19:06:13 +00:00
|
|
|
* @value: a pointer to a #GstFourcc to set
|
2003-11-03 09:10:07 +00:00
|
|
|
*
|
2004-01-30 19:06:13 +00:00
|
|
|
* Sets the double pointed to by @value corresponding to the value of the
|
2003-11-03 09:10:07 +00:00
|
|
|
* given field. Caller is responsible for making sure the field exists
|
|
|
|
* and has the correct type.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the value could be set correctly
|
|
|
|
*/
|
2004-03-12 19:35:40 +00:00
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_double (const GstStructure * structure,
|
|
|
|
const gchar * fieldname, gdouble * value)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = gst_structure_get_field (structure, fieldname);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (field == NULL)
|
|
|
|
return FALSE;
|
|
|
|
if (!G_VALUE_HOLDS_DOUBLE (&field->value))
|
|
|
|
return FALSE;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
*value = g_value_get_double (&field->value);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_structure_get_string:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @fieldname: the name of a field
|
|
|
|
*
|
|
|
|
* Finds the field corresponding to @fieldname, and returns the string
|
|
|
|
* contained in the field's value. Caller is responsible for making
|
|
|
|
* sure the field exists and has the correct type.
|
|
|
|
*
|
|
|
|
* The string should not be modified, and remains valid until the next
|
|
|
|
* call to a gst_structure_*() function with the given structure.
|
|
|
|
*
|
|
|
|
* Returns: a pointer to the string
|
|
|
|
*/
|
|
|
|
const gchar *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_get_string (const GstStructure * structure,
|
|
|
|
const gchar * fieldname)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, NULL);
|
|
|
|
g_return_val_if_fail (fieldname != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = gst_structure_get_field (structure, fieldname);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (field == NULL)
|
|
|
|
return FALSE;
|
|
|
|
if (!G_VALUE_HOLDS_STRING (&field->value))
|
|
|
|
return FALSE;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return g_value_get_string (&field->value);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
typedef struct _GstStructureAbbreviation
|
|
|
|
{
|
2003-11-29 06:31:10 +00:00
|
|
|
char *type_name;
|
|
|
|
GType type;
|
2004-03-15 19:27:17 +00:00
|
|
|
}
|
|
|
|
GstStructureAbbreviation;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-12 19:35:40 +00:00
|
|
|
static GstStructureAbbreviation gst_structure_abbrs[] = {
|
2004-03-13 15:27:01 +00:00
|
|
|
{"int", G_TYPE_INT},
|
|
|
|
{"i", G_TYPE_INT},
|
|
|
|
{"float", G_TYPE_FLOAT},
|
|
|
|
{"f", G_TYPE_FLOAT},
|
|
|
|
{"double", G_TYPE_DOUBLE},
|
|
|
|
{"d", G_TYPE_DOUBLE},
|
|
|
|
//{ "fourcc", GST_TYPE_FOURCC },
|
|
|
|
{"boolean", G_TYPE_BOOLEAN},
|
|
|
|
{"bool", G_TYPE_BOOLEAN},
|
|
|
|
{"b", G_TYPE_BOOLEAN},
|
|
|
|
{"string", G_TYPE_STRING},
|
|
|
|
{"str", G_TYPE_STRING},
|
|
|
|
{"s", G_TYPE_STRING}
|
2003-11-29 06:31:10 +00:00
|
|
|
};
|
|
|
|
|
2004-03-12 19:35:40 +00:00
|
|
|
static GType
|
|
|
|
gst_structure_from_abbr (const char *type_name)
|
2003-11-29 06:31:10 +00:00
|
|
|
{
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (type_name != NULL, G_TYPE_INVALID);
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (gst_structure_abbrs); i++) {
|
|
|
|
if (strcmp (type_name, gst_structure_abbrs[i].type_name) == 0) {
|
2004-03-12 19:35:40 +00:00
|
|
|
return gst_structure_abbrs[i].type;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME shouldn't be a special case */
|
2004-03-13 15:27:01 +00:00
|
|
|
if (strcmp (type_name, "fourcc") == 0 || strcmp (type_name, "4") == 0) {
|
2003-11-29 06:31:10 +00:00
|
|
|
return GST_TYPE_FOURCC;
|
|
|
|
}
|
2004-04-13 02:22:02 +00:00
|
|
|
if (strcmp (type_name, "buffer") == 0) {
|
|
|
|
return GST_TYPE_BUFFER;
|
|
|
|
}
|
2003-11-29 06:31:10 +00:00
|
|
|
|
|
|
|
return g_type_from_name (type_name);
|
|
|
|
}
|
|
|
|
|
2004-03-12 19:35:40 +00:00
|
|
|
static const char *
|
|
|
|
gst_structure_to_abbr (GType type)
|
2003-11-29 06:31:10 +00:00
|
|
|
{
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (gst_structure_abbrs); i++) {
|
|
|
|
if (type == gst_structure_abbrs[i].type) {
|
2004-03-12 19:35:40 +00:00
|
|
|
return gst_structure_abbrs[i].type_name;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME shouldn't be a special case */
|
|
|
|
if (type == GST_TYPE_FOURCC) {
|
|
|
|
return "fourcc";
|
|
|
|
}
|
2004-04-13 02:22:02 +00:00
|
|
|
if (type == GST_TYPE_BUFFER) {
|
|
|
|
return "buffer";
|
|
|
|
}
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return g_type_name (type);
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
#define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
|
|
|
|
((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
|
|
|
|
((c) == '.'))
|
|
|
|
|
2003-11-03 09:10:07 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_to_string:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
*
|
|
|
|
* Converts @structure to a human-readable representation.
|
|
|
|
*
|
|
|
|
* Returns: a pointer to string allocated by g_malloc()
|
|
|
|
*/
|
|
|
|
gchar *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_to_string (const GstStructure * structure)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
|
|
|
GstStructureField *field;
|
|
|
|
GString *s;
|
2004-02-07 15:51:39 +00:00
|
|
|
int i;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
configure.ac: Add detection for HAVE_PRINTF_EXTENSION and
Original commit message from CVS:
* configure.ac: Add detection for HAVE_PRINTF_EXTENSION and
GST_PRINTF_EXTENSION_FORMAT_DEFINE.
* docs/random/ds/0.9-suggested-changes: Notes from Company.
* gst/gstcaps.c: (gst_caps_to_string): Add comment.
* gst/gstconfig.h.in: Add define for GST_PTR_FORMAT
* gst/gstinfo.c: (_gst_debug_init), (gst_debug_print_object),
(gst_debug_log_default), (_gst_info_printf_extension),
(_gst_info_printf_extension_arginfo): Add printf extension.
* gst/gstinfo.h: remove G_GNUC_PRINTF, because it doesn't work with %P
* gst/gststructure.c: (gst_structure_to_string),
(_gst_structure_parse_value): Use gst_value_deserialize() and
remove old code.
* gst/gstvalue.c: (gst_value_deserialize_fourcc),
(gst_value_deserialize_boolean), (gst_strtoi),
(gst_value_deserialize_int), (gst_value_deserialize_double),
(gst_value_deserialize_string), (gst_value_deserialize): Implement
a bunch of deserialize functions and gst_value_deserialize.
* gst/gstvalue.h: er, _de_serialize, not unserialize
* testsuite/caps/string-conversions.c: (main): We don't currently
handle (float) in caps, so convert these to (double).
* testsuite/debug/Makefile.am: Add new test for the printf extension
* testsuite/debug/printf_extension.c: (main): same
2004-01-29 01:20:23 +00:00
|
|
|
/* NOTE: This function is potentially called by the debug system,
|
|
|
|
* so any calls to gst_log() (and GST_DEBUG(), GST_LOG(), etc.)
|
|
|
|
* should be careful to avoid recursion. This includes any functions
|
|
|
|
* called by gst_structure_to_string. In particular, calls should
|
|
|
|
* not use the GST_PTR_FORMAT extension. */
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (structure != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
s = g_string_new ("");
|
2003-12-22 01:39:35 +00:00
|
|
|
/* FIXME this string may need to be escaped */
|
2004-03-13 15:27:01 +00:00
|
|
|
g_string_append_printf (s, "%s", g_quark_to_string (structure->name));
|
|
|
|
for (i = 0; i < structure->fields->len; i++) {
|
gst/gststructure.c: Convert function to use gst_value_serialize().
Original commit message from CVS:
* gst/gststructure.c: (gst_structure_to_string):
Convert function to use gst_value_serialize().
* gst/gstvalue.c: (gst_value_serialize_list),
(gst_value_serialize_fourcc), (gst_value_serialize_int_range),
(gst_value_serialize_double_range), (gst_value_serialize_boolean),
(gst_value_serialize_int), (gst_value_serialize_double),
(gst_string_wrap), (gst_value_serialize_string),
(gst_value_serialize), (gst_value_deserialize):
* gst/gstvalue.h:
Add implementations for serialize.
2004-01-20 09:14:25 +00:00
|
|
|
char *t;
|
2003-11-29 06:31:10 +00:00
|
|
|
GType type;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
field = GST_STRUCTURE_FIELD (structure, i);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
gst/gststructure.c: Convert function to use gst_value_serialize().
Original commit message from CVS:
* gst/gststructure.c: (gst_structure_to_string):
Convert function to use gst_value_serialize().
* gst/gstvalue.c: (gst_value_serialize_list),
(gst_value_serialize_fourcc), (gst_value_serialize_int_range),
(gst_value_serialize_double_range), (gst_value_serialize_boolean),
(gst_value_serialize_int), (gst_value_serialize_double),
(gst_string_wrap), (gst_value_serialize_string),
(gst_value_serialize), (gst_value_deserialize):
* gst/gstvalue.h:
Add implementations for serialize.
2004-01-20 09:14:25 +00:00
|
|
|
t = gst_value_serialize (&field->value);
|
2003-11-29 06:31:10 +00:00
|
|
|
type = G_VALUE_TYPE (&field->value);
|
|
|
|
|
|
|
|
if (type == GST_TYPE_LIST) {
|
2003-12-22 01:39:35 +00:00
|
|
|
GArray *array = g_value_peek_pointer (&field->value);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
if (array->len > 0) {
|
2004-03-15 19:27:17 +00:00
|
|
|
GValue *value = &g_array_index (array, GValue, 0);
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-15 19:27:17 +00:00
|
|
|
type = G_VALUE_TYPE (value);
|
2003-11-29 06:31:10 +00:00
|
|
|
} else {
|
2004-03-15 19:27:17 +00:00
|
|
|
type = G_TYPE_INT;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
} else if (G_VALUE_TYPE (&field->value) == GST_TYPE_INT_RANGE) {
|
2003-11-29 06:31:10 +00:00
|
|
|
type = G_TYPE_INT;
|
2004-03-13 15:27:01 +00:00
|
|
|
} else if (G_VALUE_TYPE (&field->value) == GST_TYPE_DOUBLE_RANGE) {
|
2003-11-29 06:31:10 +00:00
|
|
|
type = G_TYPE_DOUBLE;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_string_append_printf (s, ", %s=(%s)%s", g_quark_to_string (field->name),
|
2004-03-15 19:27:17 +00:00
|
|
|
gst_structure_to_abbr (type), t);
|
2004-03-13 15:27:01 +00:00
|
|
|
g_free (t);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
return g_string_free (s, FALSE);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2003-11-29 06:31:10 +00:00
|
|
|
/*
|
|
|
|
* r will still point to the string. if end == next, the string will not be
|
|
|
|
* null-terminated. In all other cases it will be.
|
|
|
|
* end = pointer to char behind end of string, next = pointer to start of
|
|
|
|
* unread data.
|
|
|
|
* THIS FUNCTION MODIFIES THE STRING AND DETECTS INSIDE A NONTERMINATED STRING
|
|
|
|
*/
|
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_parse_string (gchar * s, gchar ** end, gchar ** next)
|
2003-11-29 06:31:10 +00:00
|
|
|
{
|
|
|
|
gchar *w;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (*s == 0)
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
if (*s != '"') {
|
|
|
|
int ret;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-12 19:35:40 +00:00
|
|
|
ret = gst_structure_parse_simple_string (s, end);
|
2003-12-22 01:39:35 +00:00
|
|
|
*next = *end;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
w = s;
|
|
|
|
s++;
|
|
|
|
while (*s != '"') {
|
2004-03-13 15:27:01 +00:00
|
|
|
if (*s == 0)
|
|
|
|
return FALSE;
|
2003-12-22 01:39:35 +00:00
|
|
|
|
|
|
|
if (*s == '\\') {
|
|
|
|
s++;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
2003-12-22 01:39:35 +00:00
|
|
|
|
|
|
|
*w = *s;
|
|
|
|
w++;
|
|
|
|
s++;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
2003-12-22 01:39:35 +00:00
|
|
|
s++;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
|
|
|
*end = w;
|
2003-12-22 01:39:35 +00:00
|
|
|
*next = s;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
return TRUE;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_parse_range (gchar * s, gchar ** after, GValue * value,
|
|
|
|
GType type)
|
2003-11-29 06:31:10 +00:00
|
|
|
{
|
|
|
|
GValue value1 = { 0 };
|
|
|
|
GValue value2 = { 0 };
|
|
|
|
GType range_type;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (*s != '[')
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
s++;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
ret = gst_structure_parse_value (s, &s, &value1, type);
|
|
|
|
if (ret == FALSE)
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
|
|
|
|
|
|
|
if (*s != ',')
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
s++;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
ret = gst_structure_parse_value (s, &s, &value2, type);
|
|
|
|
if (ret == FALSE)
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (*s != ']')
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
s++;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value2))
|
|
|
|
return FALSE;
|
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
if (G_VALUE_TYPE (&value1) == G_TYPE_DOUBLE) {
|
|
|
|
range_type = GST_TYPE_DOUBLE_RANGE;
|
|
|
|
} else if (G_VALUE_TYPE (&value1) == G_TYPE_INT) {
|
|
|
|
range_type = GST_TYPE_INT_RANGE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_value_init (value, range_type);
|
2003-11-29 06:31:10 +00:00
|
|
|
if (range_type == GST_TYPE_DOUBLE_RANGE) {
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_value_set_double_range (value, g_value_get_double (&value1),
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_get_double (&value2));
|
2003-11-29 06:31:10 +00:00
|
|
|
} else {
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_value_set_int_range (value, g_value_get_int (&value1),
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_get_int (&value2));
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*after = s;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_parse_list (gchar * s, gchar ** after, GValue * value, GType type)
|
2003-11-29 06:31:10 +00:00
|
|
|
{
|
|
|
|
GValue list_value = { 0 };
|
|
|
|
gboolean ret;
|
2003-12-22 01:39:35 +00:00
|
|
|
GArray *array;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_value_init (value, GST_TYPE_LIST);
|
2003-12-22 01:39:35 +00:00
|
|
|
array = g_value_peek_pointer (value);
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (*s != '{')
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
s++;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-12-22 01:39:35 +00:00
|
|
|
if (*s == '}') {
|
2003-11-29 06:31:10 +00:00
|
|
|
s++;
|
|
|
|
*after = s;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
ret = gst_structure_parse_value (s, &s, &list_value, type);
|
|
|
|
if (ret == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
g_array_append_val (array, list_value);
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
while (*s != '}') {
|
2004-03-13 15:27:01 +00:00
|
|
|
if (*s != ',')
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
s++;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
|
|
|
memset (&list_value, 0, sizeof (list_value));
|
2004-03-13 15:27:01 +00:00
|
|
|
ret = gst_structure_parse_value (s, &s, &list_value, type);
|
|
|
|
if (ret == FALSE)
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
g_array_append_val (array, list_value);
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s++;
|
|
|
|
|
|
|
|
*after = s;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_parse_simple_string (gchar * str, gchar ** end)
|
2003-12-22 01:39:35 +00:00
|
|
|
{
|
|
|
|
char *s = str;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (GST_ASCII_IS_STRING (*s)) {
|
2003-12-22 01:39:35 +00:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*end = s;
|
|
|
|
|
|
|
|
return (s != str);
|
|
|
|
}
|
|
|
|
|
2003-11-29 06:31:10 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_parse_field (gchar * str,
|
|
|
|
gchar ** after, GstStructureField * field)
|
2003-11-29 06:31:10 +00:00
|
|
|
{
|
|
|
|
gchar *name;
|
2003-12-22 01:39:35 +00:00
|
|
|
gchar *name_end;
|
|
|
|
gchar *s;
|
|
|
|
gchar c;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
s = str;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-12-22 01:39:35 +00:00
|
|
|
name = s;
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!gst_structure_parse_simple_string (s, &name_end))
|
|
|
|
return FALSE;
|
2003-12-22 01:39:35 +00:00
|
|
|
|
|
|
|
s = name_end;
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-12-22 01:39:35 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (*s != '=')
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
s++;
|
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
c = *name_end;
|
|
|
|
*name_end = 0;
|
2003-11-29 06:31:10 +00:00
|
|
|
field->name = g_quark_from_string (name);
|
2003-12-22 01:39:35 +00:00
|
|
|
*name_end = c;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-12 19:35:40 +00:00
|
|
|
if (!gst_structure_parse_value (s, &s, &field->value, G_TYPE_INVALID))
|
2003-12-22 01:39:35 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*after = s;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_parse_value (gchar * str,
|
|
|
|
gchar ** after, GValue * value, GType default_type)
|
2003-12-22 01:39:35 +00:00
|
|
|
{
|
|
|
|
gchar *type_name;
|
|
|
|
gchar *type_end;
|
|
|
|
gchar *value_s;
|
|
|
|
gchar *value_end;
|
|
|
|
gchar *s;
|
|
|
|
gchar c;
|
2004-01-07 13:13:03 +00:00
|
|
|
int ret = 0;
|
2003-12-22 01:39:35 +00:00
|
|
|
GType type = default_type;
|
|
|
|
|
|
|
|
|
|
|
|
s = str;
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-12-22 01:39:35 +00:00
|
|
|
|
|
|
|
type_name = NULL;
|
|
|
|
if (*s == '(') {
|
|
|
|
type = G_TYPE_INVALID;
|
|
|
|
|
|
|
|
s++;
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-11-29 06:31:10 +00:00
|
|
|
type_name = s;
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!gst_structure_parse_simple_string (s, &type_end))
|
|
|
|
return FALSE;
|
2003-12-22 01:39:35 +00:00
|
|
|
s = type_end;
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
|
|
|
if (*s != ')')
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
s++;
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-12-22 01:39:35 +00:00
|
|
|
|
|
|
|
c = *type_end;
|
|
|
|
*type_end = 0;
|
2004-03-13 15:27:01 +00:00
|
|
|
type = gst_structure_from_abbr (type_name);
|
2003-12-22 01:39:35 +00:00
|
|
|
*type_end = c;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (type == G_TYPE_INVALID)
|
|
|
|
return FALSE;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (g_ascii_isspace (*s))
|
|
|
|
s++;
|
2003-11-29 06:31:10 +00:00
|
|
|
if (*s == '[') {
|
2004-03-12 19:35:40 +00:00
|
|
|
ret = gst_structure_parse_range (s, &s, value, type);
|
2003-12-22 01:39:35 +00:00
|
|
|
} else if (*s == '{') {
|
2004-03-12 19:35:40 +00:00
|
|
|
ret = gst_structure_parse_list (s, &s, value, type);
|
2003-11-29 06:31:10 +00:00
|
|
|
} else {
|
2003-12-22 01:39:35 +00:00
|
|
|
value_s = s;
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!gst_structure_parse_string (s, &value_end, &s))
|
|
|
|
return FALSE;
|
2003-12-22 01:39:35 +00:00
|
|
|
|
|
|
|
c = *value_end;
|
|
|
|
*value_end = 0;
|
|
|
|
if (type == G_TYPE_INVALID) {
|
|
|
|
GType try_types[] = { G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_STRING };
|
|
|
|
int i;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_init (value, try_types[i]);
|
|
|
|
ret = gst_value_deserialize (value, value_s);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
g_value_unset (value);
|
2003-12-22 01:39:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-03-13 15:27:01 +00:00
|
|
|
g_value_init (value, type);
|
2003-12-22 01:39:35 +00:00
|
|
|
|
configure.ac: Add detection for HAVE_PRINTF_EXTENSION and
Original commit message from CVS:
* configure.ac: Add detection for HAVE_PRINTF_EXTENSION and
GST_PRINTF_EXTENSION_FORMAT_DEFINE.
* docs/random/ds/0.9-suggested-changes: Notes from Company.
* gst/gstcaps.c: (gst_caps_to_string): Add comment.
* gst/gstconfig.h.in: Add define for GST_PTR_FORMAT
* gst/gstinfo.c: (_gst_debug_init), (gst_debug_print_object),
(gst_debug_log_default), (_gst_info_printf_extension),
(_gst_info_printf_extension_arginfo): Add printf extension.
* gst/gstinfo.h: remove G_GNUC_PRINTF, because it doesn't work with %P
* gst/gststructure.c: (gst_structure_to_string),
(_gst_structure_parse_value): Use gst_value_deserialize() and
remove old code.
* gst/gstvalue.c: (gst_value_deserialize_fourcc),
(gst_value_deserialize_boolean), (gst_strtoi),
(gst_value_deserialize_int), (gst_value_deserialize_double),
(gst_value_deserialize_string), (gst_value_deserialize): Implement
a bunch of deserialize functions and gst_value_deserialize.
* gst/gstvalue.h: er, _de_serialize, not unserialize
* testsuite/caps/string-conversions.c: (main): We don't currently
handle (float) in caps, so convert these to (double).
* testsuite/debug/Makefile.am: Add new test for the printf extension
* testsuite/debug/printf_extension.c: (main): same
2004-01-29 01:20:23 +00:00
|
|
|
ret = gst_value_deserialize (value, value_s);
|
2003-12-22 01:39:35 +00:00
|
|
|
}
|
|
|
|
*value_end = c;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-29 06:31:10 +00:00
|
|
|
*after = s;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-11-03 09:10:07 +00:00
|
|
|
/**
|
|
|
|
* gst_structure_from_string:
|
2004-01-30 19:06:13 +00:00
|
|
|
* @string: a string representation of a #GstStructure.
|
|
|
|
* @end: FIXME, deduce from code
|
2003-11-03 09:10:07 +00:00
|
|
|
*
|
|
|
|
* Creates a #GstStructure from a string representation.
|
|
|
|
*
|
|
|
|
* Returns: a new #GstStructure
|
|
|
|
*/
|
|
|
|
GstStructure *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_from_string (const gchar * string, gchar ** end)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2003-11-29 06:31:10 +00:00
|
|
|
char *name;
|
|
|
|
char *copy;
|
|
|
|
char *w;
|
|
|
|
char *r;
|
|
|
|
char save;
|
2004-02-05 23:46:13 +00:00
|
|
|
GstStructure *structure = NULL;
|
2003-11-29 06:31:10 +00:00
|
|
|
GstStructureField field = { 0 };
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_val_if_fail (string != NULL, NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
copy = g_strdup (string);
|
2003-11-29 06:31:10 +00:00
|
|
|
r = copy;
|
2003-11-03 09:10:07 +00:00
|
|
|
|
2003-11-29 06:31:10 +00:00
|
|
|
name = r;
|
2004-03-12 19:35:40 +00:00
|
|
|
if (!gst_structure_parse_string (r, &w, &r))
|
2004-02-05 23:46:13 +00:00
|
|
|
goto error;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
while (g_ascii_isspace (*r))
|
|
|
|
r++;
|
|
|
|
if (*r != 0 && *r != ';' && *r != ',')
|
|
|
|
goto error;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
|
|
|
save = *w;
|
|
|
|
*w = 0;
|
2004-03-13 15:27:01 +00:00
|
|
|
structure = gst_structure_empty_new (name);
|
2003-11-29 06:31:10 +00:00
|
|
|
*w = save;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (*r && (*r != ';')) {
|
|
|
|
if (*r != ',')
|
2004-02-05 23:46:13 +00:00
|
|
|
goto error;
|
2003-11-29 06:31:10 +00:00
|
|
|
r++;
|
2004-03-13 15:27:01 +00:00
|
|
|
while (*r && g_ascii_isspace (*r))
|
|
|
|
r++;
|
2003-11-29 06:31:10 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
memset (&field, 0, sizeof (field));
|
2004-03-12 19:35:40 +00:00
|
|
|
if (!gst_structure_parse_field (r, &r, &field))
|
2004-02-05 23:46:13 +00:00
|
|
|
goto error;
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_set_field (structure, &field);
|
|
|
|
while (*r && g_ascii_isspace (*r))
|
|
|
|
r++;
|
2003-11-29 06:31:10 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
if (end)
|
|
|
|
*end = (char *) string + (r - copy);
|
2004-02-05 23:46:13 +00:00
|
|
|
|
|
|
|
g_free (copy);
|
2003-11-29 06:31:10 +00:00
|
|
|
return structure;
|
2004-02-05 23:46:13 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (structure)
|
|
|
|
gst_structure_free (structure);
|
|
|
|
g_free (copy);
|
|
|
|
return NULL;
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_transform_to_string (const GValue * src_value,
|
|
|
|
GValue * dest_value)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (src_value != NULL);
|
|
|
|
g_return_if_fail (dest_value != NULL);
|
2003-11-03 09:10:07 +00:00
|
|
|
|
|
|
|
dest_value->data[0].v_pointer =
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_to_string (src_value->data[0].v_pointer);
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2004-03-12 19:35:40 +00:00
|
|
|
static GstStructure *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_structure_copy_conditional (const GstStructure * structure)
|
2003-11-03 09:10:07 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
if (structure)
|
|
|
|
return gst_structure_copy (structure);
|
2004-02-18 05:26:59 +00:00
|
|
|
return NULL;
|
2003-11-03 09:10:07 +00:00
|
|
|
}
|