gstbasesink: add stats getter method

fixes #355
This commit is contained in:
Aaron Boxer 2019-01-26 10:40:19 -05:00
parent cfca53ce67
commit fa99a88558
3 changed files with 54 additions and 0 deletions

View file

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

View file

@ -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);
}

View file

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