From fa99a885585972ab12fed2fc74bdc451061566aa Mon Sep 17 00:00:00 2001 From: Aaron Boxer Date: Sat, 26 Jan 2019 10:40:19 -0500 Subject: [PATCH] gstbasesink: add stats getter method fixes #355 --- docs/libs/gstreamer-libs-sections.txt | 1 + libs/gst/base/gstbasesink.c | 50 +++++++++++++++++++++++++++ libs/gst/base/gstbasesink.h | 3 ++ 3 files changed, 54 insertions(+) diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index 3b46a76444..bff129aa7e 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -401,6 +401,7 @@ gst_base_sink_set_last_sample_enabled gst_base_sink_is_last_sample_enabled gst_base_sink_get_drop_out_of_segment gst_base_sink_set_drop_out_of_segment +gst_base_sink_get_stats GST_BASE_SINK_PAD GST_BASE_SINK_GET_PREROLL_COND diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index 4368c1a34c..60460fd372 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -305,6 +305,7 @@ enum PROP_THROTTLE_TIME, PROP_MAX_BITRATE, PROP_PROCESSING_DEADLINE, + PROP_STATS, PROP_LAST }; @@ -554,6 +555,24 @@ gst_base_sink_class_init (GstBaseSinkClass * klass) DEFAULT_PROCESSING_DEADLINE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + /** + * GstBaseSink::stats: + * + * Various #GstBaseSink statistics. This property returns a #GstStructure + * with name `application/x-gst-base-sink-stats` with the following fields: + * + * - "average-rate" G_TYPE_DOUBLE average frame rate + * - "dropped" G_TYPE_UINT64 Number of dropped frames + * - "rendered" G_TYPE_UINT64 Number of rendered frames + * + * Since: 1.18 + */ + g_object_class_install_property (gobject_class, PROP_STATS, + g_param_spec_boxed ("stats", "Statistics", + "Sink Statistics", GST_TYPE_STRUCTURE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_base_sink_change_state); gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_base_sink_send_event); @@ -1600,6 +1619,9 @@ gst_base_sink_get_property (GObject * object, guint prop_id, GValue * value, case PROP_PROCESSING_DEADLINE: g_value_set_uint64 (value, gst_base_sink_get_processing_deadline (sink)); break; + case PROP_STATS: + g_value_take_boxed (value, gst_base_sink_get_stats (sink)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -5375,3 +5397,31 @@ activate_failed: return GST_STATE_CHANGE_FAILURE; } } + +/** + * gst_base_sink_get_stats: + * @sink: #GstBaseSink + * + * Return various #GstBaseSink statistics. This function returns a #GstStructure + * with name `application/x-gst-base-sink-stats` with the following fields: + * + * - "average-rate" G_TYPE_DOUBLE average frame rate + * - "dropped" G_TYPE_UINT64 Number of dropped frames + * - "rendered" G_TYPE_UINT64 Number of rendered frames + * + * Returns: (transfer full) pointer to #GstStructure + * + * Since: 1.18 + */ +GstStructure * +gst_base_sink_get_stats (GstBaseSink * sink) +{ + GstBaseSinkPrivate *priv = NULL; + + g_return_val_if_fail (sink != NULL, NULL); + priv = sink->priv; + return gst_structure_new ("application/x-gst-base-sink-stats", + "average-rate", G_TYPE_DOUBLE, priv->avg_rate, + "dropped", G_TYPE_UINT64, priv->dropped, + "rendered", G_TYPE_UINT64, priv->rendered, NULL); +} diff --git a/libs/gst/base/gstbasesink.h b/libs/gst/base/gstbasesink.h index 05401257e9..5287670711 100644 --- a/libs/gst/base/gstbasesink.h +++ b/libs/gst/base/gstbasesink.h @@ -324,6 +324,9 @@ GST_BASE_API GstFlowReturn gst_base_sink_wait (GstBaseSink *sink, GstClockTime time, GstClockTimeDiff *jitter); +GST_BASE_API +GstStructure *gst_base_sink_get_stats (GstBaseSink * sink); + #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstBaseSink, gst_object_unref) #endif