From 905100cdbe580d4d182bfd9d5ec9b368a110f464 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 11 May 2011 16:03:40 +0200 Subject: [PATCH] event: update the structure when needed When we get the structure of an event, make sure it also contains the fields that we keep in fast variables, this way we can easily serialize and debug the events. We would probably later simply prefer to register a transform function to G_TYPE_STRING and G_TYPE_BYTEARRAY etc.. --- gst/gstevent.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/gst/gstevent.c b/gst/gstevent.c index af0cf02..14a7405 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -323,6 +323,46 @@ gst_event_new_custom (GstEventType type, GstStructure * structure) return event; } +static inline GstStructure * +add_structure (GstEvent * event, GQuark name) +{ + GstStructure *structure; + + structure = gst_structure_id_empty_new (name); + gst_structure_set_parent_refcount (structure, &event->mini_object.refcount); + /* FIXME, concurrent access can make us leak this */ + GST_EVENT_STRUCTURE (event) = structure; + + return structure; +} + +static GstStructure * +update_structure (GstEvent * event) +{ + GstStructure *structure; + + structure = GST_EVENT_STRUCTURE (event); + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_QOS: + { + if (structure == NULL) + structure = add_structure (event, GST_QUARK (EVENT_QOS)); + + gst_structure_id_set (structure, + GST_QUARK (TYPE), GST_TYPE_QOS_TYPE, GST_EVENT_IMPL (event, qos, + type), GST_QUARK (PROPORTION), G_TYPE_DOUBLE, + GST_EVENT_IMPL (event, qos, proportion), GST_QUARK (DIFF), + G_TYPE_INT64, GST_EVENT_IMPL (event, qos, diff), + GST_QUARK (TIMESTAMP), G_TYPE_UINT64, GST_EVENT_IMPL (event, qos, + timestamp), NULL); + break; + } + default: + break; + } + return structure; +} + /** * gst_event_get_structure: * @event: The #GstEvent. @@ -340,7 +380,7 @@ gst_event_get_structure (GstEvent * event) { g_return_val_if_fail (GST_IS_EVENT (event), NULL); - return GST_EVENT_STRUCTURE (event); + return update_structure (event); } /** @@ -364,15 +404,12 @@ gst_event_writable_structure (GstEvent * event) g_return_val_if_fail (GST_IS_EVENT (event), NULL); g_return_val_if_fail (gst_event_is_writable (event), NULL); - structure = GST_EVENT_STRUCTURE (event); + structure = update_structure (event); - if (structure == NULL) { + if (structure == NULL) structure = - gst_structure_id_empty_new (gst_event_type_to_quark (GST_EVENT_TYPE - (event))); - gst_structure_set_parent_refcount (structure, &event->mini_object.refcount); - GST_EVENT_STRUCTURE (event) = structure; - } + add_structure (event, gst_event_type_to_quark (GST_EVENT_TYPE (event))); + return structure; } -- 2.7.4