event: add QoS event type

Add a parameter to the QoS event to specify the QoS event type.
Update docs and add unit test.

See #638891
This commit is contained in:
Wim Taymans 2011-02-10 12:02:03 +01:00
parent aa32e1fab1
commit 56826a5ee6
6 changed files with 131 additions and 9 deletions

View file

@ -796,8 +796,11 @@ gst_event_parse_tag
gst_event_new_buffer_size
gst_event_parse_buffer_size
GstQOSType
gst_event_new_qos
gst_event_new_qos_full
gst_event_parse_qos
gst_event_parse_qos_full
GstSeekType
GstSeekFlags
@ -826,6 +829,7 @@ GST_TYPE_EVENT
GST_TYPE_EVENT_TYPE
GST_TYPE_SEEK_TYPE
GST_TYPE_SEEK_FLAGS
GST_TYPE_QOS_TYPE
GST_TYPE_EVENT_TYPE_FLAGS
<SUBSECTION Private>
GST_EVENT_TYPE_SHIFT
@ -834,6 +838,7 @@ gst_event_get_type
gst_event_type_get_type
gst_seek_type_get_type
gst_seek_flags_get_type
gst_qos_type_get_type
gst_event_type_flags_get_type
</SECTION>

View file

@ -705,6 +705,7 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
g_type_class_ref (gst_event_type_get_type ());
g_type_class_ref (gst_seek_type_get_type ());
g_type_class_ref (gst_seek_flags_get_type ());
g_type_class_ref (gst_qos_type_get_type ());
g_type_class_ref (gst_format_get_type ());
g_type_class_ref (gst_index_certainty_get_type ());
g_type_class_ref (gst_index_entry_type_get_type ());
@ -1071,6 +1072,7 @@ gst_deinit (void)
g_type_class_unref (g_type_class_peek (gst_event_type_get_type ()));
g_type_class_unref (g_type_class_peek (gst_seek_type_get_type ()));
g_type_class_unref (g_type_class_peek (gst_seek_flags_get_type ()));
g_type_class_unref (g_type_class_peek (gst_qos_type_get_type ()));
g_type_class_unref (g_type_class_peek (gst_format_get_type ()));
g_type_class_unref (g_type_class_peek (gst_index_certainty_get_type ()));
g_type_class_unref (g_type_class_peek (gst_index_entry_type_get_type ()));

View file

@ -799,11 +799,47 @@ gst_event_parse_buffer_size (GstEvent * event, GstFormat * format,
* @diff: The time difference of the last Clock sync
* @timestamp: The timestamp of the buffer
*
* Allocate a new qos event with the given values. This function calls
* gst_event_new_qos_full() with the type set to #GST_QOS_TYPE_OVERFLOW
* when diff is negative (buffers are in time) and #GST_QOS_TYPE_UNDERFLOW
* when @diff is positive (buffers are late).
*
* Returns: (transfer full): a new QOS event.
*/
GstEvent *
gst_event_new_qos (gdouble proportion, GstClockTimeDiff diff,
GstClockTime timestamp)
{
GstQOSType type;
if (diff <= 0)
type = GST_QOS_TYPE_OVERFLOW;
else
type = GST_QOS_TYPE_UNDERFLOW;
return gst_event_new_qos_full (type, proportion, diff, timestamp);
}
/**
* gst_event_new_qos_full:
* @type: the QoS type
* @proportion: the proportion of the qos message
* @diff: The time difference of the last Clock sync
* @timestamp: The timestamp of the buffer
*
* Allocate a new qos event with the given values.
* The QOS event is generated in an element that wants an upstream
* element to either reduce or increase its rate because of
* high/low CPU load or other resource usage such as network performance.
* Typically sinks generate these events for each buffer they receive.
* high/low CPU load or other resource usage such as network performance or
* throttling. Typically sinks generate these events for each buffer
* they receive.
*
* @type indicates the reason for the QoS event. #GST_QOS_TYPE_OVERFLOW is
* used when a buffer arrived in time or when the sink cannot keep up with
* the upstream datarate. #GST_QOS_TYPE_UNDERFLOW is when the sink is not
* receiving buffers fast enough and thus has to drop late buffers.
* #GST_QOS_TYPE_THROTTLE is used when the datarate is artificially limited
* by the application, for example to reduce power consumption.
*
* @proportion indicates the real-time performance of the streaming in the
* element that generated the QoS event (usually the sink). The value is
@ -818,7 +854,8 @@ gst_event_parse_buffer_size (GstEvent * event, GstFormat * format,
* @diff is the difference against the clock in running time of the last
* buffer that caused the element to generate the QOS event. A negative value
* means that the buffer with @timestamp arrived in time. A positive value
* indicates how late the buffer with @timestamp was.
* indicates how late the buffer with @timestamp was. When throttling is
* enabled, @diff will be set to the requested throttling interval.
*
* @timestamp is the timestamp of the last buffer that cause the element
* to generate the QOS event. It is expressed in running time and thus an ever
@ -834,10 +871,12 @@ gst_event_parse_buffer_size (GstEvent * event, GstFormat * format,
* event and implement custom application specific QoS handling.
*
* Returns: (transfer full): a new QOS event.
*
* Since: 0.10.33
*/
GstEvent *
gst_event_new_qos (gdouble proportion, GstClockTimeDiff diff,
GstClockTime timestamp)
gst_event_new_qos_full (GstQOSType type, gdouble proportion,
GstClockTimeDiff diff, GstClockTime timestamp)
{
GstEvent *event;
GstStructure *structure;
@ -846,11 +885,12 @@ gst_event_new_qos (gdouble proportion, GstClockTimeDiff diff,
g_return_val_if_fail (diff >= 0 || -diff <= timestamp, NULL);
GST_CAT_INFO (GST_CAT_EVENT,
"creating qos proportion %lf, diff %" G_GINT64_FORMAT
", timestamp %" GST_TIME_FORMAT, proportion,
"creating qos type %d, proportion %lf, diff %" G_GINT64_FORMAT
", timestamp %" GST_TIME_FORMAT, type, proportion,
diff, GST_TIME_ARGS (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);
@ -872,6 +912,26 @@ gst_event_new_qos (gdouble proportion, GstClockTimeDiff diff,
void
gst_event_parse_qos (GstEvent * event, gdouble * proportion,
GstClockTimeDiff * diff, GstClockTime * timestamp)
{
gst_event_parse_qos_full (event, NULL, proportion, diff, timestamp);
}
/**
* gst_event_parse_qos_full:
* @event: The event to query
* @type: (out): A pointer to store the QoS type in
* @proportion: (out): A pointer to store the proportion in
* @diff: (out): A pointer to store the diff in
* @timestamp: (out): A pointer to store the timestamp in
*
* Get the type, proportion, diff and timestamp in the qos event. See
* gst_event_new_qos_full() for more information about the different QoS values.
*
* Since: 0.10.33
*/
void
gst_event_parse_qos_full (GstEvent * event, GstQOSType * type,
gdouble * proportion, GstClockTimeDiff * diff, GstClockTime * timestamp)
{
const GstStructure *structure;
@ -879,6 +939,10 @@ gst_event_parse_qos (GstEvent * event, gdouble * proportion,
g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_QOS);
structure = event->structure;
if (type)
*type =
g_value_get_enum (gst_structure_id_get_value (structure,
GST_QUARK (TYPE)));
if (proportion)
*proportion =
g_value_get_double (gst_structure_id_get_value (structure,

View file

@ -94,8 +94,8 @@ typedef enum {
* send messages that should be emitted in sync with
* rendering.
* @GST_EVENT_QOS: A quality message. Used to indicate to upstream elements
* that the downstream elements are being starved of or
* flooded with data.
* that the downstream elements should adjust their processing
* rate.
* @GST_EVENT_SEEK: A request for a new playback position and rate.
* @GST_EVENT_NAVIGATION: Navigation events are usually used for communicating
* user requests, such as mouse or keyboard movements,
@ -308,6 +308,29 @@ typedef enum {
GST_SEEK_FLAG_SKIP = (1 << 4)
} GstSeekFlags;
/**
* GstQOSType:
* @GST_QOS_TYPE_OVERFLOW: The QoS event type that is produced when downstream
* elements are producing data too quickly and the element can't keep up
* processing the data. Upstream should reduce their processing rate. This
* type is also used when buffers arrive early or in time.
* @GST_QOS_TYPE_UNDERFLOW: The QoS event type that is produced when downstream
* elements are producing data too slowly and need to speed up their processing
* rate.
* @GST_QOS_TYPE_THROTTLE: The QoS event type that is produced when the
* application enabled throttling to limit the datarate.
*
* The different types of QoS events that can be given to the
* gst_event_new_qos_full() method.
*
* Since: 0.10.33
*/
typedef enum {
GST_QOS_TYPE_OVERFLOW = 0,
GST_QOS_TYPE_UNDERFLOW = 1,
GST_QOS_TYPE_THROTTLE = 2
} GstQOSType;
/**
* GstEvent:
* @mini_object: the parent structure
@ -461,8 +484,13 @@ void gst_event_parse_buffer_size (GstEvent *event, GstFormat *for
/* QOS events */
GstEvent* gst_event_new_qos (gdouble proportion, GstClockTimeDiff diff,
GstClockTime timestamp);
GstEvent* gst_event_new_qos_full (GstQOSType type, gdouble proportion,
GstClockTimeDiff diff, GstClockTime timestamp);
void gst_event_parse_qos (GstEvent *event, gdouble *proportion, GstClockTimeDiff *diff,
GstClockTime *timestamp);
void gst_event_parse_qos_full (GstEvent *event, GstQOSType *type,
gdouble *proportion, GstClockTimeDiff *diff,
GstClockTime *timestamp);
/* seek event */
GstEvent* gst_event_new_seek (gdouble rate, GstFormat format, GstSeekFlags flags,
GstSeekType start_type, gint64 start,

View file

@ -138,6 +138,7 @@ GST_START_TEST (create_events)
/* QOS */
{
GstQOSType t1 = GST_QOS_TYPE_THROTTLE, t2;
gdouble p1 = 1.0, p2;
GstClockTimeDiff ctd1 = G_GINT64_CONSTANT (10), ctd2;
GstClockTime ct1 = G_GUINT64_CONSTANT (20), ct2;
@ -153,6 +154,25 @@ GST_START_TEST (create_events)
fail_unless (p1 == p2);
fail_unless (ctd1 == ctd2);
fail_unless (ct1 == ct2);
gst_event_parse_qos_full (event, &t2, &p2, &ctd2, &ct2);
fail_unless (t2 == GST_QOS_TYPE_UNDERFLOW);
fail_unless (p1 == p2);
fail_unless (ctd1 == ctd2);
fail_unless (ct1 == ct2);
gst_event_unref (event);
ctd1 = G_GINT64_CONSTANT (-10);
event = gst_event_new_qos (p1, ctd1, ct1);
gst_event_parse_qos_full (event, &t2, &p2, &ctd2, &ct2);
fail_unless (t2 == GST_QOS_TYPE_OVERFLOW);
gst_event_unref (event);
event = gst_event_new_qos_full (t1, p1, ctd1, ct1);
gst_event_parse_qos_full (event, &t2, &p2, &ctd2, &ct2);
fail_unless (t2 == GST_QOS_TYPE_THROTTLE);
fail_unless (p1 == p2);
fail_unless (ctd1 == ctd2);
fail_unless (ct1 == ct2);
gst_event_unref (event);
}

View file

@ -392,6 +392,7 @@ EXPORTS
gst_event_new_new_segment
gst_event_new_new_segment_full
gst_event_new_qos
gst_event_new_qos_full
gst_event_new_seek
gst_event_new_sink_message
gst_event_new_step
@ -401,6 +402,7 @@ EXPORTS
gst_event_parse_new_segment
gst_event_parse_new_segment_full
gst_event_parse_qos
gst_event_parse_qos_full
gst_event_parse_seek
gst_event_parse_sink_message
gst_event_parse_step
@ -812,6 +814,7 @@ EXPORTS
gst_print_element_args
gst_print_pad_caps
gst_proxy_pad_get_type
gst_qos_type_get_type
gst_query_add_buffering_range
gst_query_get_n_buffering_ranges
gst_query_get_structure