2009-04-16 15:36:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Nokia Corporation <multimedia@maemo.org>
|
|
|
|
* 2006 Zeeshan Ali <zeeshan.ali@nokia.com>.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-11-03 20:38:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2009-04-16 15:36:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-05-01 13:25:40 +00:00
|
|
|
* SECTION:element-fpsdisplaysink
|
2009-04-16 15:36:13 +00:00
|
|
|
*
|
2009-04-20 07:24:37 +00:00
|
|
|
* Can display the current and average framerate as a testoverlay or on stdout.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch lines</title>
|
2009-04-16 15:36:13 +00:00
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 videotestsrc ! fpsdisplaysink
|
|
|
|
* gst-launch-1.0 videotestsrc ! fpsdisplaysink text-overlay=false
|
|
|
|
* gst-launch-1.0 filesrc location=video.avi ! decodebin name=d ! queue ! fpsdisplaysink d. ! queue ! fakesink sync=true
|
|
|
|
* gst-launch-1.0 playbin uri=file:///path/to/video.avi video-sink="fpsdisplaysink" audio-sink=fakesink
|
2009-04-16 15:36:13 +00:00
|
|
|
* ]|
|
2009-04-20 07:24:37 +00:00
|
|
|
* </refsect2>
|
2009-04-16 15:36:13 +00:00
|
|
|
*/
|
|
|
|
/* FIXME:
|
2009-04-20 07:24:37 +00:00
|
|
|
* - can we avoid plugging the textoverlay?
|
|
|
|
* - gst-seek 15 "videotestsrc ! fpsdisplaysink" dies when closing gst-seek
|
2009-12-17 10:54:04 +00:00
|
|
|
*
|
|
|
|
* NOTE:
|
|
|
|
* - if we make ourself RANK_PRIMARY+10 or something that autovideosink would
|
|
|
|
* select and fpsdisplaysink is set to use autovideosink as its internal sink
|
|
|
|
* it doesn't work. Reason: autovideosink creates a fpsdisplaysink, that
|
|
|
|
* creates an autovideosink, that...
|
2009-04-16 15:36:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fpsdisplaysink.h"
|
|
|
|
|
2010-06-24 15:37:36 +00:00
|
|
|
#define DEFAULT_SIGNAL_FPS_MEASUREMENTS FALSE
|
2010-06-24 13:23:02 +00:00
|
|
|
#define DEFAULT_FPS_UPDATE_INTERVAL_MS 500 /* 500 ms */
|
2010-08-18 08:35:44 +00:00
|
|
|
#define DEFAULT_FONT "Sans 15"
|
2011-04-09 07:50:23 +00:00
|
|
|
#define DEFAULT_SILENT FALSE
|
2011-04-09 08:03:00 +00:00
|
|
|
#define DEFAULT_LAST_MESSAGE NULL
|
2009-04-16 15:36:13 +00:00
|
|
|
|
|
|
|
/* generic templates */
|
|
|
|
static GstStaticPadTemplate fps_display_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (fps_display_sink_debug);
|
|
|
|
#define GST_CAT_DEFAULT fps_display_sink_debug
|
|
|
|
|
2011-02-28 10:51:54 +00:00
|
|
|
#define DEFAULT_SYNC TRUE
|
|
|
|
|
2010-06-24 15:37:36 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
SIGNAL_FPS_MEASUREMENTS,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2009-04-16 15:36:13 +00:00
|
|
|
enum
|
|
|
|
{
|
2011-04-08 12:08:10 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_SYNC,
|
|
|
|
PROP_TEXT_OVERLAY,
|
|
|
|
PROP_VIDEO_SINK,
|
|
|
|
PROP_FPS_UPDATE_INTERVAL,
|
|
|
|
PROP_MAX_FPS,
|
|
|
|
PROP_MIN_FPS,
|
|
|
|
PROP_SIGNAL_FPS_MEASUREMENTS,
|
|
|
|
PROP_FRAMES_DROPPED,
|
|
|
|
PROP_FRAMES_RENDERED,
|
2011-04-09 08:03:00 +00:00
|
|
|
PROP_SILENT,
|
|
|
|
PROP_LAST_MESSAGE
|
2010-06-24 13:23:02 +00:00
|
|
|
/* FILL ME */
|
2009-04-16 15:36:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GstBinClass *parent_class = NULL;
|
|
|
|
|
|
|
|
static GstStateChangeReturn fps_display_sink_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
static void fps_display_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void fps_display_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void fps_display_sink_dispose (GObject * object);
|
2015-06-18 05:59:18 +00:00
|
|
|
static void fps_display_sink_handle_message (GstBin * bin,
|
|
|
|
GstMessage * message);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
static gboolean display_current_fps (gpointer data);
|
|
|
|
|
2010-06-24 15:37:36 +00:00
|
|
|
static guint fpsdisplaysink_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2011-04-09 08:03:00 +00:00
|
|
|
static GParamSpec *pspec_last_message = NULL;
|
|
|
|
|
2009-04-16 15:36:13 +00:00
|
|
|
static void
|
2009-05-01 01:21:10 +00:00
|
|
|
fps_display_sink_class_init (GstFPSDisplaySinkClass * klass)
|
2009-04-16 15:36:13 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_klass = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *gstelement_klass = GST_ELEMENT_CLASS (klass);
|
2015-06-18 05:59:18 +00:00
|
|
|
GstBinClass *bin_class = GST_BIN_CLASS (klass);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
gobject_klass->set_property = fps_display_sink_set_property;
|
|
|
|
gobject_klass->get_property = fps_display_sink_get_property;
|
|
|
|
gobject_klass->dispose = fps_display_sink_dispose;
|
|
|
|
|
2015-06-18 05:59:18 +00:00
|
|
|
bin_class->handle_message = fps_display_sink_handle_message;
|
|
|
|
|
2011-04-08 12:08:10 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_SYNC,
|
2009-04-16 15:36:13 +00:00
|
|
|
g_param_spec_boolean ("sync",
|
2009-12-15 12:08:08 +00:00
|
|
|
"Sync", "Sync on the clock (if the internally used sink doesn't "
|
2011-02-28 10:51:54 +00:00
|
|
|
"have this property it will be ignored", DEFAULT_SYNC,
|
2009-04-30 10:45:30 +00:00
|
|
|
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2011-04-08 12:08:10 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_TEXT_OVERLAY,
|
2009-04-16 15:36:13 +00:00
|
|
|
g_param_spec_boolean ("text-overlay",
|
|
|
|
"text-overlay",
|
2009-12-13 13:53:14 +00:00
|
|
|
"Whether to use text-overlay", TRUE,
|
2009-04-30 10:45:30 +00:00
|
|
|
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2011-04-08 12:08:10 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_VIDEO_SINK,
|
2009-12-11 01:49:13 +00:00
|
|
|
g_param_spec_object ("video-sink",
|
|
|
|
"video-sink",
|
2009-12-17 14:04:28 +00:00
|
|
|
"Video sink to use (Must only be called on NULL state)",
|
2010-06-24 13:24:27 +00:00
|
|
|
GST_TYPE_ELEMENT, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
|
2009-12-11 01:49:13 +00:00
|
|
|
|
2011-04-08 12:08:10 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_FPS_UPDATE_INTERVAL,
|
2010-06-24 13:23:02 +00:00
|
|
|
g_param_spec_int ("fps-update-interval", "Fps update interval",
|
|
|
|
"Time between consecutive frames per second measures and update "
|
|
|
|
" (in ms). Should be set on NULL state", 1, G_MAXINT,
|
2010-06-24 13:24:27 +00:00
|
|
|
DEFAULT_FPS_UPDATE_INTERVAL_MS,
|
|
|
|
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
|
2010-06-24 15:37:36 +00:00
|
|
|
|
2011-04-08 12:08:10 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_MAX_FPS,
|
2010-06-24 13:59:32 +00:00
|
|
|
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));
|
2010-06-24 15:37:36 +00:00
|
|
|
|
2011-04-08 12:08:10 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_MIN_FPS,
|
2010-06-24 13:59:32 +00:00
|
|
|
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));
|
2010-06-24 13:23:02 +00:00
|
|
|
|
2011-04-08 12:08:10 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_FRAMES_DROPPED,
|
2011-03-16 08:50:34 +00:00
|
|
|
g_param_spec_uint ("frames-dropped", "dropped frames",
|
|
|
|
"Number of frames dropped by the sink", 0, G_MAXUINT, 0,
|
|
|
|
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
|
|
|
|
|
2011-04-08 12:08:10 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_FRAMES_RENDERED,
|
2011-03-16 08:50:34 +00:00
|
|
|
g_param_spec_uint ("frames-rendered", "rendered frames",
|
|
|
|
"Number of frames rendered", 0, G_MAXUINT, 0,
|
|
|
|
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
|
|
|
|
|
2011-04-09 07:50:23 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_SILENT,
|
|
|
|
g_param_spec_boolean ("silent", "enable stdout output",
|
|
|
|
"Don't produce last_message events", DEFAULT_SILENT,
|
2011-04-07 13:15:57 +00:00
|
|
|
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
|
2011-03-16 08:50:34 +00:00
|
|
|
|
2011-04-08 12:08:10 +00:00
|
|
|
g_object_class_install_property (gobject_klass, PROP_SIGNAL_FPS_MEASUREMENTS,
|
2010-06-24 15:37:36 +00:00
|
|
|
g_param_spec_boolean ("signal-fps-measurements",
|
|
|
|
"Signal fps measurements",
|
|
|
|
"If the fps-measurements signal should be emited.",
|
|
|
|
DEFAULT_SIGNAL_FPS_MEASUREMENTS,
|
2010-07-01 19:28:57 +00:00
|
|
|
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
|
2010-06-24 15:37:36 +00:00
|
|
|
|
2011-04-09 08:03:00 +00:00
|
|
|
pspec_last_message = g_param_spec_string ("last-message", "Last Message",
|
|
|
|
"The message describing current status", DEFAULT_LAST_MESSAGE,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
g_object_class_install_property (gobject_klass, PROP_LAST_MESSAGE,
|
|
|
|
pspec_last_message);
|
|
|
|
|
2010-06-24 15:37:36 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
fpsdisplaysink_signals[SIGNAL_FPS_MEASUREMENTS] =
|
|
|
|
g_signal_new ("fps-measurements", G_TYPE_FROM_CLASS (klass),
|
2016-02-03 21:13:58 +00:00
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,
|
2010-06-24 15:37:36 +00:00
|
|
|
G_TYPE_NONE, 3, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
|
|
|
|
2009-04-16 15:36:13 +00:00
|
|
|
gstelement_klass->change_state = fps_display_sink_change_state;
|
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_klass,
|
|
|
|
&fps_display_sink_template);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_klass,
|
2010-03-18 16:30:26 +00:00
|
|
|
"Measure and show framerate on videosink", "Sink/Video",
|
|
|
|
"Shows the current frame-rate and drop-rate of the videosink as overlay or text on stdout",
|
|
|
|
"Zeeshan Ali <zeeshan.ali@nokia.com>, Stefan Kost <stefan.kost@nokia.com>");
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 22:21:50 +00:00
|
|
|
static GstPadProbeReturn
|
|
|
|
on_video_sink_data_flow (GstPad * pad, GstPadProbeInfo * info,
|
2009-04-16 15:36:13 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-02-02 22:21:50 +00:00
|
|
|
GstMiniObject *mini_obj = GST_PAD_PROBE_INFO_DATA (info);
|
2009-05-01 01:21:10 +00:00
|
|
|
GstFPSDisplaySink *self = GST_FPS_DISPLAY_SINK (user_data);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
|
|
|
if (GST_IS_BUFFER (mini_obj)) {
|
2015-06-18 05:59:18 +00:00
|
|
|
GstClockTime ts;
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2015-06-18 05:59:18 +00:00
|
|
|
/* assume the frame is going to be rendered. If it isnt', we'll get a qos
|
|
|
|
* message and reset ->frames_rendered from there.
|
|
|
|
*/
|
|
|
|
g_atomic_int_inc (&self->frames_rendered);
|
2010-08-23 14:51:25 +00:00
|
|
|
|
2015-06-18 05:59:18 +00:00
|
|
|
ts = gst_util_get_timestamp ();
|
|
|
|
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (self->start_ts))) {
|
|
|
|
self->interval_ts = self->last_ts = self->start_ts = ts;
|
|
|
|
}
|
|
|
|
if (GST_CLOCK_DIFF (self->interval_ts, ts) > self->fps_update_interval) {
|
|
|
|
display_current_fps (self);
|
|
|
|
self->interval_ts = ts;
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-18 05:59:18 +00:00
|
|
|
|
2012-02-02 22:21:50 +00:00
|
|
|
return GST_PAD_PROBE_OK;
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-16 21:32:42 +00:00
|
|
|
update_sub_sync (GstElement * sink, gpointer data)
|
2009-12-11 01:49:13 +00:00
|
|
|
{
|
2009-12-15 12:08:08 +00:00
|
|
|
/* Some sinks (like autovideosink) don't have the sync property so
|
|
|
|
* we check it exists before setting it to avoid a warning at
|
|
|
|
* runtime. */
|
|
|
|
if (g_object_class_find_property (G_OBJECT_GET_CLASS (sink), "sync"))
|
|
|
|
g_object_set (sink, "sync", *((gboolean *) data), NULL);
|
|
|
|
else
|
|
|
|
GST_WARNING ("Internal sink doesn't have sync property");
|
2009-12-11 01:49:13 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 22:21:50 +00:00
|
|
|
static void
|
|
|
|
update_sub_sync_foreach (const GValue * item, gpointer data)
|
|
|
|
{
|
|
|
|
GstElement *sink = g_value_get_object (item);
|
|
|
|
|
|
|
|
update_sub_sync (sink, data);
|
|
|
|
}
|
|
|
|
|
2009-12-16 21:32:42 +00:00
|
|
|
static void
|
|
|
|
fps_display_sink_update_sink_sync (GstFPSDisplaySink * self)
|
|
|
|
{
|
|
|
|
GstIterator *iterator;
|
|
|
|
|
|
|
|
if (self->video_sink == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (GST_IS_BIN (self->video_sink)) {
|
|
|
|
iterator = gst_bin_iterate_sinks (GST_BIN (self->video_sink));
|
2012-02-02 22:21:50 +00:00
|
|
|
gst_iterator_foreach (iterator,
|
|
|
|
(GstIteratorForeachFunction) update_sub_sync_foreach,
|
2009-12-16 21:32:42 +00:00
|
|
|
(void *) &self->sync);
|
|
|
|
gst_iterator_free (iterator);
|
|
|
|
} else
|
|
|
|
update_sub_sync (self->video_sink, (void *) &self->sync);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-12-11 01:49:13 +00:00
|
|
|
static void
|
|
|
|
update_video_sink (GstFPSDisplaySink * self, GstElement * video_sink)
|
2009-04-16 15:36:13 +00:00
|
|
|
{
|
2009-04-30 10:45:30 +00:00
|
|
|
GstPad *sink_pad;
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2009-12-11 01:49:13 +00:00
|
|
|
if (self->video_sink) {
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2009-12-11 01:49:13 +00:00
|
|
|
/* remove pad probe */
|
|
|
|
sink_pad = gst_element_get_static_pad (self->video_sink, "sink");
|
2012-02-02 22:21:50 +00:00
|
|
|
gst_pad_remove_probe (sink_pad, self->data_probe_id);
|
2009-12-11 01:49:13 +00:00
|
|
|
gst_object_unref (sink_pad);
|
|
|
|
self->data_probe_id = -1;
|
|
|
|
|
2009-12-17 14:04:28 +00:00
|
|
|
/* remove ghost pad target */
|
|
|
|
gst_ghost_pad_set_target (GST_GHOST_PAD (self->ghost_pad), NULL);
|
2009-12-11 01:49:13 +00:00
|
|
|
|
|
|
|
/* remove old sink */
|
|
|
|
gst_bin_remove (GST_BIN (self), self->video_sink);
|
|
|
|
gst_object_unref (self->video_sink);
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
2009-12-11 01:49:13 +00:00
|
|
|
/* create child elements */
|
|
|
|
self->video_sink = video_sink;
|
|
|
|
|
2010-02-19 10:32:33 +00:00
|
|
|
if (self->video_sink == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-12-16 21:32:42 +00:00
|
|
|
fps_display_sink_update_sink_sync (self);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
|
|
|
/* take a ref before bin takes the ownership */
|
2009-05-01 01:21:10 +00:00
|
|
|
gst_object_ref (self->video_sink);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2009-05-01 01:21:10 +00:00
|
|
|
gst_bin_add (GST_BIN (self), self->video_sink);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2009-04-30 10:45:30 +00:00
|
|
|
/* attach or pad probe */
|
2009-05-01 01:21:10 +00:00
|
|
|
sink_pad = gst_element_get_static_pad (self->video_sink, "sink");
|
2012-02-02 22:21:50 +00:00
|
|
|
self->data_probe_id = gst_pad_add_probe (sink_pad,
|
|
|
|
GST_PAD_PROBE_TYPE_DATA_BOTH, on_video_sink_data_flow,
|
|
|
|
(gpointer) self, NULL);
|
2009-04-16 15:36:13 +00:00
|
|
|
gst_object_unref (sink_pad);
|
2009-12-11 01:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fps_display_sink_init (GstFPSDisplaySink * self,
|
|
|
|
GstFPSDisplaySinkClass * g_class)
|
|
|
|
{
|
2011-02-28 10:51:54 +00:00
|
|
|
self->sync = DEFAULT_SYNC;
|
2010-06-24 15:37:36 +00:00
|
|
|
self->signal_measurements = DEFAULT_SIGNAL_FPS_MEASUREMENTS;
|
2009-12-11 01:49:13 +00:00
|
|
|
self->use_text_overlay = TRUE;
|
2010-08-24 08:26:52 +00:00
|
|
|
self->fps_update_interval = GST_MSECOND * DEFAULT_FPS_UPDATE_INTERVAL_MS;
|
2009-12-17 14:04:28 +00:00
|
|
|
self->video_sink = NULL;
|
2010-06-24 13:59:32 +00:00
|
|
|
self->max_fps = -1;
|
|
|
|
self->min_fps = -1;
|
2011-04-09 07:50:23 +00:00
|
|
|
self->silent = DEFAULT_SILENT;
|
2011-04-09 08:03:00 +00:00
|
|
|
self->last_message = g_strdup (DEFAULT_LAST_MESSAGE);
|
2009-12-11 01:49:13 +00:00
|
|
|
|
2009-12-17 14:04:28 +00:00
|
|
|
self->ghost_pad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (self), self->ghost_pad);
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
display_current_fps (gpointer data)
|
|
|
|
{
|
2009-05-01 01:21:10 +00:00
|
|
|
GstFPSDisplaySink *self = GST_FPS_DISPLAY_SINK (data);
|
2010-08-23 14:51:25 +00:00
|
|
|
guint64 frames_rendered, frames_dropped;
|
|
|
|
gdouble rr, dr, average_fps;
|
|
|
|
gchar fps_message[256];
|
|
|
|
gdouble time_diff, time_elapsed;
|
|
|
|
GstClockTime current_ts = gst_util_get_timestamp ();
|
|
|
|
|
2011-03-16 08:50:34 +00:00
|
|
|
frames_rendered = g_atomic_int_get (&self->frames_rendered);
|
|
|
|
frames_dropped = g_atomic_int_get (&self->frames_dropped);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
if ((frames_rendered + frames_dropped) == 0) {
|
|
|
|
/* in case timer fired and we didn't yet get any QOS events */
|
2009-07-20 13:20:15 +00:00
|
|
|
return TRUE;
|
2010-07-01 19:28:57 +00:00
|
|
|
}
|
2009-07-20 13:20:15 +00:00
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
time_diff = (gdouble) (current_ts - self->last_ts) / GST_SECOND;
|
|
|
|
time_elapsed = (gdouble) (current_ts - self->start_ts) / GST_SECOND;
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
rr = (gdouble) (frames_rendered - self->last_frames_rendered) / time_diff;
|
|
|
|
dr = (gdouble) (frames_dropped - self->last_frames_dropped) / time_diff;
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
average_fps = (gdouble) frames_rendered / time_elapsed;
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
if (self->max_fps == -1 || rr > self->max_fps) {
|
|
|
|
self->max_fps = rr;
|
|
|
|
GST_DEBUG_OBJECT (self, "Updated max-fps to %f", rr);
|
|
|
|
}
|
|
|
|
if (self->min_fps == -1 || rr < self->min_fps) {
|
|
|
|
self->min_fps = rr;
|
|
|
|
GST_DEBUG_OBJECT (self, "Updated min-fps to %f", rr);
|
|
|
|
}
|
2010-06-24 13:59:32 +00:00
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
if (self->signal_measurements) {
|
|
|
|
GST_LOG_OBJECT (self, "Signaling measurements: fps:%f droprate:%f "
|
|
|
|
"avg-fps:%f", rr, dr, average_fps);
|
|
|
|
g_signal_emit (G_OBJECT (self),
|
|
|
|
fpsdisplaysink_signals[SIGNAL_FPS_MEASUREMENTS], 0, rr, dr,
|
|
|
|
average_fps);
|
|
|
|
}
|
2010-06-24 15:37:36 +00:00
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
/* Display on a single line to make it easier to read and import
|
|
|
|
* into, for example, excel.. note: it would be nice to show
|
|
|
|
* timestamp too.. need to check if there is a sane way to log
|
|
|
|
* timestamp of last rendered buffer, so we could correlate dips
|
|
|
|
* in framerate to certain positions in the stream.
|
|
|
|
*/
|
|
|
|
if (dr == 0.0) {
|
|
|
|
g_snprintf (fps_message, 255,
|
2011-04-09 08:03:00 +00:00
|
|
|
"rendered: %" G_GUINT64_FORMAT ", dropped: %" G_GUINT64_FORMAT
|
|
|
|
", current: %.2f, average: %.2f", frames_rendered, frames_dropped, rr,
|
2010-09-06 08:29:21 +00:00
|
|
|
average_fps);
|
2010-08-23 14:51:25 +00:00
|
|
|
} else {
|
|
|
|
g_snprintf (fps_message, 255,
|
2011-04-09 08:03:00 +00:00
|
|
|
"rendered: %" G_GUINT64_FORMAT ", dropped: %" G_GUINT64_FORMAT
|
|
|
|
", fps: %.2f, drop rate: %.2f", frames_rendered, frames_dropped, rr,
|
2010-09-06 08:29:21 +00:00
|
|
|
dr);
|
2010-08-23 14:51:25 +00:00
|
|
|
}
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
if (self->use_text_overlay) {
|
|
|
|
g_object_set (self->text_overlay, "text", fps_message, NULL);
|
2011-04-07 13:15:57 +00:00
|
|
|
}
|
|
|
|
|
2011-04-09 07:50:23 +00:00
|
|
|
if (!self->silent) {
|
2011-04-09 08:03:00 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
g_free (self->last_message);
|
|
|
|
self->last_message = g_strdup (fps_message);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
g_object_notify_by_pspec ((GObject *) self, pspec_last_message);
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
2010-08-23 14:51:25 +00:00
|
|
|
self->last_frames_rendered = frames_rendered;
|
|
|
|
self->last_frames_dropped = frames_dropped;
|
2009-05-01 01:21:10 +00:00
|
|
|
self->last_ts = current_ts;
|
2009-04-16 15:36:13 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-01 01:21:10 +00:00
|
|
|
fps_display_sink_start (GstFPSDisplaySink * self)
|
2009-04-16 15:36:13 +00:00
|
|
|
{
|
2009-04-30 16:08:52 +00:00
|
|
|
GstPad *target_pad = NULL;
|
2009-04-30 10:45:30 +00:00
|
|
|
|
2009-04-16 15:36:13 +00:00
|
|
|
/* Init counters */
|
2011-03-16 08:50:34 +00:00
|
|
|
self->frames_rendered = 0;
|
|
|
|
self->frames_dropped = 0;
|
2010-09-23 11:15:08 +00:00
|
|
|
self->last_frames_rendered = G_GUINT64_CONSTANT (0);
|
|
|
|
self->last_frames_dropped = G_GUINT64_CONSTANT (0);
|
2010-06-24 13:59:32 +00:00
|
|
|
self->max_fps = -1;
|
|
|
|
self->min_fps = -1;
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2010-08-24 08:26:52 +00:00
|
|
|
/* init time stamps */
|
|
|
|
self->last_ts = self->start_ts = self->interval_ts = GST_CLOCK_TIME_NONE;
|
|
|
|
|
2009-12-17 10:54:04 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Use text-overlay? %d", self->use_text_overlay);
|
2009-04-30 10:45:30 +00:00
|
|
|
|
2009-05-01 01:21:10 +00:00
|
|
|
if (self->use_text_overlay) {
|
|
|
|
if (!self->text_overlay) {
|
|
|
|
self->text_overlay =
|
2009-04-30 10:45:30 +00:00
|
|
|
gst_element_factory_make ("textoverlay", "fps-display-text-overlay");
|
2009-05-01 01:21:10 +00:00
|
|
|
if (!self->text_overlay) {
|
2009-04-30 10:45:30 +00:00
|
|
|
GST_WARNING_OBJECT (self, "text-overlay element could not be created");
|
2009-05-01 01:21:10 +00:00
|
|
|
self->use_text_overlay = FALSE;
|
2009-04-30 10:45:30 +00:00
|
|
|
goto no_text_overlay;
|
|
|
|
}
|
2009-05-01 01:21:10 +00:00
|
|
|
gst_object_ref (self->text_overlay);
|
|
|
|
g_object_set (self->text_overlay,
|
2009-04-30 10:45:30 +00:00
|
|
|
"font-desc", DEFAULT_FONT, "silent", FALSE, NULL);
|
2009-05-15 09:45:45 +00:00
|
|
|
gst_bin_add (GST_BIN (self), self->text_overlay);
|
2009-04-30 10:45:30 +00:00
|
|
|
|
2009-05-15 09:45:45 +00:00
|
|
|
if (!gst_element_link (self->text_overlay, self->video_sink)) {
|
|
|
|
GST_ERROR_OBJECT (self, "Could not link elements");
|
|
|
|
}
|
2009-04-30 10:45:30 +00:00
|
|
|
}
|
2009-05-01 01:21:10 +00:00
|
|
|
target_pad = gst_element_get_static_pad (self->text_overlay, "video_sink");
|
2009-04-30 10:45:30 +00:00
|
|
|
}
|
|
|
|
no_text_overlay:
|
2009-05-01 01:21:10 +00:00
|
|
|
if (!self->use_text_overlay) {
|
|
|
|
if (self->text_overlay) {
|
|
|
|
gst_element_unlink (self->text_overlay, self->video_sink);
|
|
|
|
gst_bin_remove (GST_BIN (self), self->text_overlay);
|
2009-05-15 09:45:45 +00:00
|
|
|
self->text_overlay = NULL;
|
2009-04-30 10:45:30 +00:00
|
|
|
}
|
2009-05-01 01:21:10 +00:00
|
|
|
target_pad = gst_element_get_static_pad (self->video_sink, "sink");
|
2009-04-30 10:45:30 +00:00
|
|
|
}
|
2009-05-01 01:21:10 +00:00
|
|
|
gst_ghost_pad_set_target (GST_GHOST_PAD (self->ghost_pad), target_pad);
|
2009-04-30 10:45:30 +00:00
|
|
|
gst_object_unref (target_pad);
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-01 01:21:10 +00:00
|
|
|
fps_display_sink_stop (GstFPSDisplaySink * self)
|
2009-04-16 15:36:13 +00:00
|
|
|
{
|
2009-05-15 09:45:45 +00:00
|
|
|
if (self->text_overlay) {
|
|
|
|
gst_element_unlink (self->text_overlay, self->video_sink);
|
|
|
|
gst_bin_remove (GST_BIN (self), self->text_overlay);
|
|
|
|
gst_object_unref (self->text_overlay);
|
|
|
|
self->text_overlay = NULL;
|
2011-04-09 08:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!self->silent) {
|
|
|
|
gchar *str;
|
|
|
|
|
2010-06-24 13:59:32 +00:00
|
|
|
/* print the max and minimum fps values */
|
2011-04-09 08:03:00 +00:00
|
|
|
str =
|
|
|
|
g_strdup_printf ("Max-fps: %0.2f, Min-fps: %0.2f", self->max_fps,
|
|
|
|
self->min_fps);
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
g_free (self->last_message);
|
|
|
|
self->last_message = str;
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
g_object_notify_by_pspec ((GObject *) self, pspec_last_message);
|
2009-05-15 09:45:45 +00:00
|
|
|
}
|
2011-04-09 08:03:00 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
g_free (self->last_message);
|
|
|
|
self->last_message = NULL;
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fps_display_sink_dispose (GObject * object)
|
|
|
|
{
|
2009-05-01 01:21:10 +00:00
|
|
|
GstFPSDisplaySink *self = GST_FPS_DISPLAY_SINK (object);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2009-05-01 01:21:10 +00:00
|
|
|
if (self->video_sink) {
|
|
|
|
gst_object_unref (self->video_sink);
|
|
|
|
self->video_sink = NULL;
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
2009-05-01 01:21:10 +00:00
|
|
|
if (self->text_overlay) {
|
|
|
|
gst_object_unref (self->text_overlay);
|
|
|
|
self->text_overlay = NULL;
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
2011-04-09 08:03:00 +00:00
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
g_free (self->last_message);
|
|
|
|
self->last_message = NULL;
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
|
2009-04-16 15:36:13 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fps_display_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-05-01 01:21:10 +00:00
|
|
|
GstFPSDisplaySink *self = GST_FPS_DISPLAY_SINK (object);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_SYNC:
|
2009-05-01 01:21:10 +00:00
|
|
|
self->sync = g_value_get_boolean (value);
|
2009-12-16 21:32:42 +00:00
|
|
|
fps_display_sink_update_sink_sync (self);
|
2009-04-16 15:36:13 +00:00
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_TEXT_OVERLAY:
|
2009-05-01 01:21:10 +00:00
|
|
|
self->use_text_overlay = g_value_get_boolean (value);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
2009-05-01 01:21:10 +00:00
|
|
|
if (self->text_overlay) {
|
|
|
|
if (!self->use_text_overlay) {
|
2009-04-30 10:45:30 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "text-overlay set to false");
|
2009-05-01 01:21:10 +00:00
|
|
|
g_object_set (self->text_overlay, "text", "", "silent", TRUE, NULL);
|
2009-04-30 10:45:30 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (self, "text-overlay set to true");
|
2009-05-01 01:21:10 +00:00
|
|
|
g_object_set (self->text_overlay, "silent", FALSE, NULL);
|
2009-04-30 10:45:30 +00:00
|
|
|
}
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_VIDEO_SINK:
|
2009-12-17 14:04:28 +00:00
|
|
|
/* FIXME should we add a state-lock or a lock around here?
|
|
|
|
* need to check if it is possible that a state change NULL->READY can
|
|
|
|
* happen while this code is executing on a different thread */
|
|
|
|
if (GST_STATE (self) != GST_STATE_NULL) {
|
|
|
|
g_warning ("Can't set video-sink property of fpsdisplaysink if not on "
|
|
|
|
"NULL state");
|
|
|
|
break;
|
|
|
|
}
|
2009-12-11 01:49:13 +00:00
|
|
|
update_video_sink (self, (GstElement *) g_value_get_object (value));
|
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_FPS_UPDATE_INTERVAL:
|
2010-08-24 08:26:52 +00:00
|
|
|
self->fps_update_interval =
|
|
|
|
GST_MSECOND * (GstClockTime) g_value_get_int (value);
|
2010-06-24 13:23:02 +00:00
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_SIGNAL_FPS_MEASUREMENTS:
|
2010-06-24 15:37:36 +00:00
|
|
|
self->signal_measurements = g_value_get_boolean (value);
|
|
|
|
break;
|
2011-04-09 07:50:23 +00:00
|
|
|
case PROP_SILENT:
|
|
|
|
self->silent = g_value_get_boolean (value);
|
2011-04-07 13:15:57 +00:00
|
|
|
break;
|
2009-04-16 15:36:13 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fps_display_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-05-01 01:21:10 +00:00
|
|
|
GstFPSDisplaySink *self = GST_FPS_DISPLAY_SINK (object);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_SYNC:
|
2009-05-01 01:21:10 +00:00
|
|
|
g_value_set_boolean (value, self->sync);
|
2009-04-16 15:36:13 +00:00
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_TEXT_OVERLAY:
|
2009-05-01 01:21:10 +00:00
|
|
|
g_value_set_boolean (value, self->use_text_overlay);
|
2009-04-16 15:36:13 +00:00
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_VIDEO_SINK:
|
2009-12-11 01:49:13 +00:00
|
|
|
g_value_set_object (value, self->video_sink);
|
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_FPS_UPDATE_INTERVAL:
|
2010-08-24 08:26:52 +00:00
|
|
|
g_value_set_int (value, (gint) (self->fps_update_interval / GST_MSECOND));
|
2010-06-24 13:23:02 +00:00
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_MAX_FPS:
|
2010-06-24 13:59:32 +00:00
|
|
|
g_value_set_double (value, self->max_fps);
|
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_MIN_FPS:
|
2010-06-24 13:59:32 +00:00
|
|
|
g_value_set_double (value, self->min_fps);
|
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_FRAMES_DROPPED:
|
2011-03-16 08:50:34 +00:00
|
|
|
g_value_set_uint (value, g_atomic_int_get (&self->frames_dropped));
|
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_FRAMES_RENDERED:
|
2011-03-16 08:50:34 +00:00
|
|
|
g_value_set_uint (value, g_atomic_int_get (&self->frames_rendered));
|
|
|
|
break;
|
2011-04-08 12:08:10 +00:00
|
|
|
case PROP_SIGNAL_FPS_MEASUREMENTS:
|
2010-06-24 15:37:36 +00:00
|
|
|
g_value_set_boolean (value, self->signal_measurements);
|
|
|
|
break;
|
2011-04-09 07:50:23 +00:00
|
|
|
case PROP_SILENT:
|
|
|
|
g_value_set_boolean (value, self->silent);
|
2011-04-07 13:15:57 +00:00
|
|
|
break;
|
2011-04-09 08:03:00 +00:00
|
|
|
case PROP_LAST_MESSAGE:
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
g_value_set_string (value, self->last_message);
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
break;
|
2009-04-16 15:36:13 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
fps_display_sink_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
2009-05-01 01:21:10 +00:00
|
|
|
GstFPSDisplaySink *self = GST_FPS_DISPLAY_SINK (element);
|
2009-04-16 15:36:13 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2009-12-17 14:04:28 +00:00
|
|
|
|
|
|
|
if (self->video_sink == NULL) {
|
|
|
|
GstElement *video_sink;
|
2010-02-19 10:32:33 +00:00
|
|
|
|
2009-12-17 14:04:28 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "No video sink set, creating autovideosink");
|
|
|
|
video_sink = gst_element_factory_make ("autovideosink",
|
|
|
|
"fps-display-video_sink");
|
|
|
|
update_video_sink (self, video_sink);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->video_sink != NULL) {
|
|
|
|
fps_display_sink_start (self);
|
|
|
|
} else {
|
2010-02-19 10:32:33 +00:00
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, INIT,
|
|
|
|
("No video sink set and autovideosink is not available"), (NULL));
|
2009-12-17 14:04:28 +00:00
|
|
|
ret = GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
2009-04-16 15:36:13 +00:00
|
|
|
break;
|
2009-12-16 21:32:42 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
/* reinforce our sync to children, as they might have changed
|
|
|
|
* internally */
|
|
|
|
fps_display_sink_update_sink_sync (self);
|
|
|
|
break;
|
2009-04-16 15:36:13 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_CALL_PARENT_WITH_DEFAULT (GST_ELEMENT_CLASS, change_state,
|
|
|
|
(element, transition), GST_STATE_CHANGE_SUCCESS);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2009-04-20 08:38:01 +00:00
|
|
|
fps_display_sink_stop (self);
|
2009-04-16 15:36:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-18 05:59:18 +00:00
|
|
|
static void
|
|
|
|
fps_display_sink_handle_message (GstBin * bin, GstMessage * message)
|
|
|
|
{
|
|
|
|
GstFPSDisplaySink *self = (GstFPSDisplaySink *) bin;
|
|
|
|
|
|
|
|
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS) {
|
|
|
|
GstFormat format;
|
|
|
|
guint64 rendered, dropped;
|
|
|
|
|
|
|
|
gst_message_parse_qos_stats (message, &format, &rendered, &dropped);
|
|
|
|
if (format != GST_FORMAT_UNDEFINED) {
|
|
|
|
if (rendered != -1)
|
|
|
|
g_atomic_int_set (&self->frames_rendered, rendered);
|
|
|
|
|
|
|
|
if (dropped != -1)
|
|
|
|
g_atomic_int_set (&self->frames_dropped, dropped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BIN_CLASS (parent_class)->handle_message (bin, message);
|
|
|
|
}
|
|
|
|
|
2009-04-16 15:36:13 +00:00
|
|
|
GType
|
|
|
|
fps_display_sink_get_type (void)
|
|
|
|
{
|
|
|
|
static GType fps_display_sink_type = 0;
|
|
|
|
|
|
|
|
if (!fps_display_sink_type) {
|
|
|
|
static const GTypeInfo fps_display_sink_info = {
|
2009-05-01 01:21:10 +00:00
|
|
|
sizeof (GstFPSDisplaySinkClass),
|
2009-04-20 07:24:37 +00:00
|
|
|
NULL,
|
2009-04-16 15:36:13 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) fps_display_sink_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-05-01 01:21:10 +00:00
|
|
|
sizeof (GstFPSDisplaySink),
|
2009-04-16 15:36:13 +00:00
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) fps_display_sink_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
fps_display_sink_type = g_type_register_static (GST_TYPE_BIN,
|
2009-05-01 01:21:10 +00:00
|
|
|
"GstFPSDisplaySink", &fps_display_sink_info, 0);
|
2009-05-01 00:59:56 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (fps_display_sink_debug, "fpsdisplaysink", 0,
|
|
|
|
"FPS Display Sink");
|
2009-04-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fps_display_sink_type;
|
|
|
|
}
|