Revert "event: example of how to optimize events"

This reverts commit fa28e2c5e6.

The optimization only has minimal impact on the performance and
makes everything more complex.
This commit is contained in:
Sebastian Dröge 2011-05-17 11:45:46 +02:00
parent b7482263cc
commit 50f91c0825
2 changed files with 33 additions and 34 deletions

View file

@ -87,28 +87,14 @@
GType _gst_event_type = 0;
typedef struct
{
GstQOSType type;
gdouble proportion;
gint64 diff;
GstClockTime timestamp;
} GstEventQOSData;
typedef struct
{
GstEvent event;
GstStructure *structure;
union
{
GstEventQOSData qos;
};
} GstEventImpl;
#define GST_EVENT_STRUCTURE(e) (((GstEventImpl *)(e))->structure)
#define GST_EVENT_IMPL(e,data,field) (((GstEventImpl *)(e))->data.field)
#define GST_EVENT_STRUCTURE(e) (((GstEventImpl *)(e))->structure)
typedef struct
{
@ -236,25 +222,26 @@ _gst_event_free (GstEvent * event)
g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event);
}
static void gst_event_init (GstEventImpl * event, gsize size,
GstEventType type);
static GstEvent *
_gst_event_copy (GstEventImpl * event)
_gst_event_copy (GstEvent * event)
{
GstEventImpl *copy;
GstStructure *s;
copy = g_slice_dup (GstEventImpl, event);
gst_mini_object_init (GST_MINI_OBJECT_CAST (copy), _gst_event_type,
sizeof (GstEventImpl));
copy = g_slice_new0 (GstEventImpl);
gst_event_init (copy, sizeof (GstEventImpl), GST_EVENT_TYPE (event));
GST_EVENT_TYPE (copy) = GST_EVENT_TYPE (event);
GST_EVENT_TIMESTAMP (copy) = GST_EVENT_TIMESTAMP (event);
GST_EVENT_SEQNUM (copy) = GST_EVENT_SEQNUM (event);
s = GST_EVENT_STRUCTURE (event);
if (s) {
GST_EVENT_STRUCTURE (copy) = gst_structure_copy (s);
gst_structure_set_parent_refcount (GST_EVENT_STRUCTURE (copy),
&copy->event.mini_object.refcount);
gst_structure_set_parent_refcount (s, &copy->event.mini_object.refcount);
}
return GST_EVENT_CAST (copy);
}
@ -858,6 +845,7 @@ gst_event_new_qos (GstQOSType type, gdouble proportion,
GstClockTimeDiff diff, GstClockTime timestamp)
{
GstEvent *event;
GstStructure *structure;
/* diff must be positive or timestamp + diff must be positive */
g_return_val_if_fail (diff >= 0 || -diff <= timestamp, NULL);
@ -867,12 +855,12 @@ gst_event_new_qos (GstQOSType type, gdouble proportion,
", timestamp %" GST_TIME_FORMAT, type, proportion,
diff, GST_TIME_ARGS (timestamp));
event = gst_event_new (GST_EVENT_QOS);
GST_EVENT_IMPL (event, qos, type) = type;
GST_EVENT_IMPL (event, qos, proportion) = proportion;
GST_EVENT_IMPL (event, qos, diff) = diff;
GST_EVENT_IMPL (event, qos, timestamp) = timestamp;
structure = gst_structure_id_new (GST_QUARK (EVENT_QOS),
GST_QUARK (TYPE), GST_TYPE_QOS_TYPE, type,
GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
GST_QUARK (DIFF), G_TYPE_INT64, diff,
GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp, NULL);
event = gst_event_new_custom (GST_EVENT_QOS, structure);
return event;
}
@ -892,17 +880,28 @@ void
gst_event_parse_qos (GstEvent * event, GstQOSType * type,
gdouble * proportion, GstClockTimeDiff * diff, GstClockTime * timestamp)
{
const GstStructure *structure;
g_return_if_fail (GST_IS_EVENT (event));
g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_QOS);
structure = GST_EVENT_STRUCTURE (event);
if (type)
*type = GST_EVENT_IMPL (event, qos, type);
*type =
g_value_get_enum (gst_structure_id_get_value (structure,
GST_QUARK (TYPE)));
if (proportion)
*proportion = GST_EVENT_IMPL (event, qos, proportion);
*proportion =
g_value_get_double (gst_structure_id_get_value (structure,
GST_QUARK (PROPORTION)));
if (diff)
*diff = GST_EVENT_IMPL (event, qos, diff);
*diff =
g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (DIFF)));
if (timestamp)
*timestamp = GST_EVENT_IMPL (event, qos, timestamp);
*timestamp =
g_value_get_uint64 (gst_structure_id_get_value (structure,
GST_QUARK (TIMESTAMP)));
}
/**

View file

@ -123,7 +123,7 @@ GST_START_TEST (create_events)
fail_unless (ctd1 == ctd2);
fail_unless (ct1 == ct2);
gst_event_parse_qos (event, &t2, &p2, &ctd2, &ct2);
fail_unless (t2 == GST_QOS_TYPE_THROTTLE);
fail_unless (t2 == GST_QOS_TYPE_UNDERFLOW);
fail_unless (p1 == p2);
fail_unless (ctd1 == ctd2);
fail_unless (ct1 == ct2);
@ -132,7 +132,7 @@ GST_START_TEST (create_events)
ctd1 = G_GINT64_CONSTANT (-10);
event = gst_event_new_qos (t1, p1, ctd1, ct1);
gst_event_parse_qos (event, &t2, &p2, &ctd2, &ct2);
fail_unless (t2 == GST_QOS_TYPE_THROTTLE);
fail_unless (t2 == GST_QOS_TYPE_OVERFLOW);
gst_event_unref (event);
event = gst_event_new_qos (t1, p1, ctd1, ct1);