Commit 9597545d authored by Wim Taymans's avatar Wim Taymans

structure: more cleanups

gst_structure_get_type() -> _gst_structure_type to avoid method calls for
getting the GType that initialized at the start.
Hide some structure fields in private data so that we can change the
implementation.
Move structure equality check from caps.c to structure.c where it belongs.
parent a59bc0ab
......@@ -668,6 +668,7 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
_gst_memory_init ();
_gst_format_initialize ();
_gst_query_initialize ();
_gst_structure_initialize ();
_gst_caps_initialize ();
_gst_meta_init ();
......@@ -755,7 +756,6 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
g_type_class_ref (gst_map_flags_get_type ());
g_type_class_ref (gst_caps_intersect_mode_get_type ());
gst_structure_get_type ();
_gst_event_initialize ();
_gst_buffer_initialize ();
_gst_message_initialize ();
......
......@@ -98,6 +98,7 @@ void _priv_gst_quarks_initialize (void);
* we want enterprise edition packagers dancing on our heads) */
void _gst_buffer_initialize (void);
void _gst_buffer_list_initialize (void);
void _gst_structure_initialize (void);
void _gst_caps_initialize (void);
void _gst_event_initialize (void);
void _gst_format_initialize (void);
......@@ -115,7 +116,7 @@ gboolean _gst_plugin_loader_client_run (void);
void _priv_gst_pad_invalidate_cache (GstPad *pad);
/* used in both gststructure.c and gstcaps.c; numbers are completely made up */
#define STRUCTURE_ESTIMATED_STRING_LEN(s) (16 + (s)->fields->len * 22)
#define STRUCTURE_ESTIMATED_STRING_LEN(s) (16 + gst_structure_n_fields(s) * 22)
gboolean priv_gst_structure_append_to_gstring (const GstStructure * structure,
GString * s);
......
......@@ -464,22 +464,6 @@ gst_caps_steal_structure (GstCaps * caps, guint index)
return gst_caps_remove_and_get_structure (caps, index);
}
static gboolean
gst_structure_is_equal_foreach (GQuark field_id, const GValue * val2,
gpointer data)
{
GstStructure *struct1 = (GstStructure *) data;
const GValue *val1 = gst_structure_id_get_value (struct1, field_id);
if (G_UNLIKELY (val1 == NULL))
return FALSE;
if (gst_value_compare (val1, val2) == GST_VALUE_EQUAL) {
return TRUE;
}
return FALSE;
}
static gboolean
gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value,
gpointer user_data)
......@@ -530,8 +514,8 @@ static gboolean
gst_caps_structure_is_subset (const GstStructure * minuend,
const GstStructure * subtrahend)
{
if ((minuend->name != subtrahend->name) ||
(gst_structure_n_fields (minuend) !=
if ((minuend->name != subtrahend->name)
|| (gst_structure_n_fields (minuend) !=
gst_structure_n_fields (subtrahend))) {
return FALSE;
}
......@@ -643,7 +627,6 @@ gst_caps_append_structure (GstCaps * caps, GstStructure * structure)
g_return_if_fail (IS_WRITABLE (caps));
if (G_LIKELY (structure)) {
g_return_if_fail (structure->parent_refcount == NULL);
gst_caps_append_structure_unchecked (caps, structure);
}
}
......@@ -688,7 +671,6 @@ gst_caps_merge_structure (GstCaps * caps, GstStructure * structure)
int i;
gboolean unique = TRUE;
g_return_if_fail (structure->parent_refcount == NULL);
/* check each structure */
for (i = caps->structs->len - 1; i >= 0; i--) {
structure1 = gst_caps_get_structure_unchecked (caps, i);
......@@ -1000,15 +982,7 @@ gst_caps_is_equal_fixed (const GstCaps * caps1, const GstCaps * caps2)
struct1 = gst_caps_get_structure_unchecked (caps1, 0);
struct2 = gst_caps_get_structure_unchecked (caps2, 0);
if (struct1->name != struct2->name) {
return FALSE;
}
if (struct1->fields->len != struct2->fields->len) {
return FALSE;
}
return gst_structure_foreach (struct1, gst_structure_is_equal_foreach,
struct2);
return gst_structure_is_equal (struct1, struct2);
}
/**
......
......@@ -312,15 +312,23 @@ gst_event_new_custom (GstEventType type, GstStructure * structure)
GstEvent *event;
/* structure must not have a parent */
if (structure)
g_return_val_if_fail (structure->parent_refcount == NULL, NULL);
event = gst_event_new (type);
if (structure) {
gst_structure_set_parent_refcount (structure, &event->mini_object.refcount);
if (!gst_structure_set_parent_refcount (structure,
&event->mini_object.refcount))
goto had_parent;
GST_EVENT_STRUCTURE (event) = structure;
}
return event;
/* ERRORS */
had_parent:
{
gst_event_unref (event);
g_warning ("structure is already owned by another object");
return NULL;
}
}
static inline GstStructure *
......
This diff is collapsed.
......@@ -28,12 +28,16 @@
G_BEGIN_DECLS
#define GST_TYPE_STRUCTURE (gst_structure_get_type ())
#define GST_STRUCTURE(object) ((GstStructure *)(object))
#define GST_IS_STRUCTURE(object) ((object) && (GST_STRUCTURE(object)->type == GST_TYPE_STRUCTURE))
extern GType _gst_structure_type;
typedef struct _GstStructure GstStructure;
#define GST_TYPE_STRUCTURE (_gst_structure_type)
#define GST_IS_STRUCTURE(object) ((object) && (GST_STRUCTURE(object)->type == GST_TYPE_STRUCTURE))
#define GST_STRUCTURE_CAST(object) ((GstStructure *)(object))
#define GST_STRUCTURE(object) (GST_STRUCTURE_CAST(object))
/**
* GstStructureForeachFunc:
* @field_id: the #GQuark of the field name
......@@ -77,17 +81,8 @@ struct _GstStructure {
/*< private >*/
GQuark name;
/* owned by parent structure, NULL if no parent */
gint *parent_refcount;
GArray *fields;
gpointer _gst_reserved;
};
GType gst_structure_get_type (void);
GstStructure * gst_structure_empty_new (const gchar * name);
GstStructure * gst_structure_id_empty_new (GQuark quark);
GstStructure * gst_structure_new (const gchar * name,
......@@ -100,8 +95,8 @@ GstStructure * gst_structure_id_new (GQuark
GQuark field_quark,
...);
GstStructure * gst_structure_copy (const GstStructure *structure);
void gst_structure_set_parent_refcount (GstStructure *structure,
gint *refcount);
gboolean gst_structure_set_parent_refcount (GstStructure *structure,
gint *refcount);
void gst_structure_free (GstStructure *structure);
G_CONST_RETURN gchar * gst_structure_get_name (const GstStructure *structure);
......@@ -111,6 +106,9 @@ gboolean gst_structure_has_name (const GstStructure
void gst_structure_set_name (GstStructure *structure,
const gchar *name);
gboolean gst_structure_is_equal (GstStructure *struct1,
GstStructure *struct2);
void gst_structure_id_set_value (GstStructure *structure,
GQuark field,
const GValue *value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment