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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/615>
This commit is contained in:
Olivier Crête 2017-09-08 19:59:27 -04:00 committed by GStreamer Merge Bot
parent c6c6ad2667
commit 3d5c849a6c
3 changed files with 70 additions and 1 deletions

View file

@ -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,

View file

@ -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:
*
* <itemizedlist>
* <listitem>
* <para>
* #guint64
* <classname>&quot;num-buffers&quot;</classname>:
* the number of buffers that passed through.
* </para>
* </listitem>
* <listitem>
* <para>
* #guint64
* <classname>&quot;num-bytes&quot;</classname>:
* the number of bytes that passed through.
* </para>
* </listitem>
* </itemizedlist>
*
* 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);

View file

@ -83,6 +83,8 @@ struct _GstIdentity {
gboolean drop_allocation;
gint eos_after;
gint eos_after_counter;
guint64 num_bytes;
guint64 num_buffers;
};
struct _GstIdentityClass {