fpsdisplaysink: Adds a signal to inform measurements to apps
authorThiago Santos <thiago.sousa.santos@collabora.co.uk>
Thu, 24 Jun 2010 15:37:36 +0000 (12:37 -0300)
committerThiago Santos <thiago.sousa.santos@collabora.co.uk>
Thu, 24 Jun 2010 16:53:08 +0000 (13:53 -0300)
Adds a signal for applications to receive the fps measurements made
instead of only printing them to the frame/stdout.

This signal is only emited if the signal-fps-measurements property
is set to TRUE

gst/debugutils/.gitignore [new file with mode: 0644]
gst/debugutils/Makefile.am
gst/debugutils/debugutils-marshal.list [new file with mode: 0644]
gst/debugutils/fpsdisplaysink.c
gst/debugutils/fpsdisplaysink.h

diff --git a/gst/debugutils/.gitignore b/gst/debugutils/.gitignore
new file mode 100644 (file)
index 0000000..69e91a9
--- /dev/null
@@ -0,0 +1,2 @@
+debugutils-marshal.c
+debugutils-marshal.h
index 3b93fa9..70e8400 100644 (file)
@@ -1,6 +1,21 @@
+glib_gen_prefix = __gst_debugutils
+glib_gen_basename = debugutils
+
+include $(top_srcdir)/common/gst-glib-gen.mak
+
+built_sources = debugutils-marshal.c
+built_headers = debugutils-marshal.h
+
+BUILT_SOURCES = $(built_sources) $(built_headers)
+
+CLEANFILES = $(BUILT_SOURCES)
+
+EXTRA_DIST = debugutils-marshal.list
+
 plugin_LTLIBRARIES = libgstdebugutilsbad.la
 
 libgstdebugutilsbad_la_SOURCES = fpsdisplaysink.c debugutilsbad.c
+nodist_libgstdebugutilsbad_la_SOURCES = $(BUILT_SOURCES)
 libgstdebugutilsbad_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
 libgstdebugutilsbad_la_LIBADD = $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) -lgstinterfaces-$(GST_MAJORMINOR)
 libgstdebugutilsbad_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
diff --git a/gst/debugutils/debugutils-marshal.list b/gst/debugutils/debugutils-marshal.list
new file mode 100644 (file)
index 0000000..8073fd3
--- /dev/null
@@ -0,0 +1,2 @@
+VOID:DOUBLE,DOUBLE,DOUBLE
+
index ea6e8a2..89199b4 100644 (file)
 #include "config.h"
 #endif
 
+#include "debugutils-marshal.h"
 #include "fpsdisplaysink.h"
 #include <gst/interfaces/xoverlay.h>
 
+#define DEFAULT_SIGNAL_FPS_MEASUREMENTS FALSE
 #define DEFAULT_FPS_UPDATE_INTERVAL_MS 500      /* 500 ms */
 #define DEFAULT_FONT "Sans 20"
 
@@ -64,13 +66,21 @@ GST_DEBUG_CATEGORY_STATIC (fps_display_sink_debug);
 
 enum
 {
+  /* FILL ME */
+  SIGNAL_FPS_MEASUREMENTS,
+  LAST_SIGNAL
+};
+
+enum
+{
   ARG_0,
   ARG_SYNC,
   ARG_TEXT_OVERLAY,
   ARG_VIDEO_SINK,
   ARG_FPS_UPDATE_INTERVAL,
   ARG_MAX_FPS,
-  ARG_MIN_FPS
+  ARG_MIN_FPS,
+  ARG_SIGNAL_FPS_MEASUREMENTS
       /* FILL ME */
 };
 
@@ -84,6 +94,8 @@ static void fps_display_sink_get_property (GObject * object, guint prop_id,
     GValue * value, GParamSpec * pspec);
 static void fps_display_sink_dispose (GObject * object);
 
+static guint fpsdisplaysink_signals[LAST_SIGNAL] = { 0 };
+
 static void
 fps_display_sink_class_init (GstFPSDisplaySinkClass * klass)
 {
@@ -120,17 +132,43 @@ fps_display_sink_class_init (GstFPSDisplaySinkClass * klass)
           " (in ms). Should be set on NULL state", 1, G_MAXINT,
           DEFAULT_FPS_UPDATE_INTERVAL_MS,
           G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
+
   g_object_class_install_property (gobject_klass, ARG_MAX_FPS,
       g_param_spec_double ("max-fps", "Max fps",
           "Maximum fps rate measured. Reset when going from NULL to READY."
           "-1 means no measurement has yet been done", -1, G_MAXDOUBLE, -1,
           G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
   g_object_class_install_property (gobject_klass, ARG_MIN_FPS,
       g_param_spec_double ("min-fps", "Min fps",
           "Minimum fps rate measured. Reset when going from NULL to READY."
           "-1 means no measurement has yet been done", -1, G_MAXDOUBLE, -1,
           G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
 
+  g_object_class_install_property (gobject_klass, ARG_SIGNAL_FPS_MEASUREMENTS,
+      g_param_spec_boolean ("signal-fps-measurements",
+          "Signal fps measurements",
+          "If the fps-measurements signal should be emited.",
+          DEFAULT_SIGNAL_FPS_MEASUREMENTS,
+          G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
+  /**
+   * GstFPSDisplaySink::fps-measurements:
+   * @fpsdisplaysink: a #GstFPSDisplaySink
+   * @fps: The current measured fps
+   * @droprate: The rate at which buffers are being dropped
+   * @avgfps: The average fps
+   *
+   * Signals the application about the measured fps
+   *
+   * Since: 0.10.20
+   */
+  fpsdisplaysink_signals[SIGNAL_FPS_MEASUREMENTS] =
+      g_signal_new ("fps-measurements", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+      __gst_debugutils_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
+      G_TYPE_NONE, 3, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
+
   gstelement_klass->change_state = fps_display_sink_change_state;
 
   gst_element_class_add_pad_template (gstelement_klass,
@@ -262,6 +300,7 @@ fps_display_sink_init (GstFPSDisplaySink * self,
     GstFPSDisplaySinkClass * g_class)
 {
   self->sync = FALSE;
+  self->signal_measurements = DEFAULT_SIGNAL_FPS_MEASUREMENTS;
   self->use_text_overlay = TRUE;
   self->fps_update_interval = DEFAULT_FPS_UPDATE_INTERVAL_MS;
   self->video_sink = NULL;
@@ -307,6 +346,12 @@ display_current_fps (gpointer data)
       GST_DEBUG_OBJECT (self, "Updated min-fps to %f", rr);
     }
 
+    if (self->signal_measurements) {
+      g_signal_emit (G_OBJECT (self),
+          fpsdisplaysink_signals[SIGNAL_FPS_MEASUREMENTS], 0, rr, dr,
+          average_fps);
+    }
+
     if (dr == 0.0) {
       g_snprintf (fps_message, 255, "current: %.2f\naverage: %.2f", rr,
           average_fps);
@@ -462,6 +507,9 @@ fps_display_sink_set_property (GObject * object, guint prop_id,
     case ARG_FPS_UPDATE_INTERVAL:
       self->fps_update_interval = g_value_get_int (value);
       break;
+    case ARG_SIGNAL_FPS_MEASUREMENTS:
+      self->signal_measurements = g_value_get_boolean (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -493,6 +541,9 @@ fps_display_sink_get_property (GObject * object, guint prop_id,
     case ARG_MIN_FPS:
       g_value_set_double (value, self->min_fps);
       break;
+    case ARG_SIGNAL_FPS_MEASUREMENTS:
+      g_value_set_boolean (value, self->signal_measurements);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
index b2cc50f..590b6d9 100644 (file)
@@ -63,6 +63,7 @@ struct _GstFPSDisplaySink
   /* properties */
   gboolean sync;
   gboolean use_text_overlay;
+  gboolean signal_measurements;
   gint fps_update_interval;
   gdouble max_fps;
   gdouble min_fps;