gstbasesink: add stats getter method
authorAaron Boxer <aaron.boxer@collabora.com>
Sat, 26 Jan 2019 15:40:19 +0000 (10:40 -0500)
committerAaron Boxer <aaron.boxer@collabora.com>
Wed, 8 May 2019 18:45:42 +0000 (14:45 -0400)
fixes #355

docs/libs/gstreamer-libs-sections.txt
libs/gst/base/gstbasesink.c
libs/gst/base/gstbasesink.h

index 3b46a76..bff129a 100644 (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
index 4368c1a..60460fd 100644 (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);
+}
index 0540125..5287670 100644 (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