From 3d5c849a6c8882b825bef48fe1ed6a6d123be3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Fri, 8 Sep 2017 19:59:27 -0400 Subject: [PATCH] identity: Add a stats property This is inspired by the stats on rtpjitterbuffer, it's useful to be able to get some simple stats out of the pipeline without having to write yet another pad probe. Part-of: --- docs/plugins/gst_plugins_cache.json | 12 ++++++ plugins/elements/gstidentity.c | 57 ++++++++++++++++++++++++++++- plugins/elements/gstidentity.h | 2 + 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/docs/plugins/gst_plugins_cache.json b/docs/plugins/gst_plugins_cache.json index 5a64d4830b..ac8c654fcd 100644 --- a/docs/plugins/gst_plugins_cache.json +++ b/docs/plugins/gst_plugins_cache.json @@ -1218,6 +1218,18 @@ "type": "guint", "writable": true }, + "stats": { + "blurb": "Statistics", + "conditionally-available": false, + "construct": false, + "construct-only": false, + "controllable": false, + "default": "application/x-identity-stats, num-bytes=(guint64)0, num-buffers=(guint64)0;", + "mutable": "null", + "readable": true, + "type": "GstStructure", + "writable": false + }, "sync": { "blurb": "Synchronize to pipeline clock", "conditionally-available": false, diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index d5e156e9f5..1359c0e6ee 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -95,7 +95,8 @@ enum PROP_CHECK_IMPERFECT_OFFSET, PROP_SIGNAL_HANDOFFS, PROP_DROP_ALLOCATION, - PROP_EOS_AFTER + PROP_EOS_AFTER, + PROP_STATS }; @@ -267,6 +268,36 @@ gst_identity_class_init (GstIdentityClass * klass) G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE); + /** + * GstIdentity:stats: + + * Various statistics. This property returns a GstStructure + * with name application/x-identity-stats with the following fields: + * + * + * + * + * #guint64 + * "num-buffers": + * the number of buffers that passed through. + * + * + * + * + * #guint64 + * "num-bytes": + * the number of bytes that passed through. + * + * + * + * + * Since: 1.20 + */ + g_object_class_install_property (gobject_class, PROP_STATS, + g_param_spec_boxed ("stats", "Statistics", + "Statistics", GST_TYPE_STRUCTURE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + gobject_class->finalize = gst_identity_finalize; gst_element_class_set_static_metadata (gstelement_class, @@ -786,6 +817,11 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf) GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE; } + GST_OBJECT_LOCK (trans); + identity->num_bytes += gst_buffer_get_size (buf); + identity->num_buffers++; + GST_OBJECT_UNLOCK (trans); + return ret; /* ERRORS */ @@ -883,6 +919,20 @@ gst_identity_set_property (GObject * object, guint prop_id, gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (identity), TRUE); } +static GstStructure * +gst_identity_create_stats (GstIdentity * identity) +{ + GstStructure *s; + + GST_OBJECT_LOCK (identity); + s = gst_structure_new ("application/x-identity-stats", + "num-bytes", G_TYPE_UINT64, identity->num_bytes, + "num-buffers", G_TYPE_UINT64, identity->num_buffers, NULL); + GST_OBJECT_UNLOCK (identity); + + return s; +} + static void gst_identity_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) @@ -942,6 +992,9 @@ gst_identity_get_property (GObject * object, guint prop_id, GValue * value, case PROP_EOS_AFTER: g_value_set_int (value, identity->eos_after); break; + case PROP_STATS: + g_value_take_boxed (value, gst_identity_create_stats (identity)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1080,6 +1133,8 @@ gst_identity_change_state (GstElement * element, GstStateChange transition) GST_OBJECT_UNLOCK (identity); if (identity->sync) no_preroll = TRUE; + identity->num_bytes = 0; + identity->num_buffers = 0; break; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: GST_OBJECT_LOCK (identity); diff --git a/plugins/elements/gstidentity.h b/plugins/elements/gstidentity.h index d81faaa677..20b4727a67 100644 --- a/plugins/elements/gstidentity.h +++ b/plugins/elements/gstidentity.h @@ -83,6 +83,8 @@ struct _GstIdentity { gboolean drop_allocation; gint eos_after; gint eos_after_counter; + guint64 num_bytes; + guint64 num_buffers; }; struct _GstIdentityClass {