mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 01:30:38 +00:00
videomaxrate: Make period over which to average configurable
This commit is contained in:
parent
3449d16566
commit
b9601e2096
2 changed files with 64 additions and 6 deletions
|
@ -44,6 +44,11 @@ static GstStaticPadTemplate gst_video_max_rate_sink_template =
|
|||
GST_STATIC_CAPS ("video/x-raw-yuv; video/x-raw-rgb")
|
||||
);
|
||||
|
||||
static void gst_video_max_rate_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_video_max_rate_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
static gboolean gst_video_max_rate_start (GstBaseTransform * trans);
|
||||
static gboolean gst_video_max_rate_sink_event (GstBaseTransform * trans,
|
||||
GstEvent * event);
|
||||
|
@ -57,6 +62,14 @@ static GstFlowReturn gst_video_max_rate_transform_ip (GstBaseTransform * trans,
|
|||
GST_BOILERPLATE (GstVideoMaxRate, gst_video_max_rate, GstBaseTransform,
|
||||
GST_TYPE_BASE_TRANSFORM);
|
||||
|
||||
#define DEFAULT_AVERAGE_PERIOD GST_SECOND
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_AVERAGE_PERIOD
|
||||
};
|
||||
|
||||
static void
|
||||
gst_video_max_rate_base_init (gpointer gclass)
|
||||
{
|
||||
|
@ -76,8 +89,12 @@ gst_video_max_rate_base_init (gpointer gclass)
|
|||
static void
|
||||
gst_video_max_rate_class_init (GstVideoMaxRateClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GstBaseTransformClass *base_class = GST_BASE_TRANSFORM_CLASS (klass);
|
||||
|
||||
gobject_class->set_property = gst_video_max_rate_set_property;
|
||||
gobject_class->get_property = gst_video_max_rate_get_property;
|
||||
|
||||
base_class->transform_caps =
|
||||
GST_DEBUG_FUNCPTR (gst_video_max_rate_transform_caps);
|
||||
base_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_max_rate_set_caps);
|
||||
|
@ -85,6 +102,12 @@ gst_video_max_rate_class_init (GstVideoMaxRateClass * klass)
|
|||
GST_DEBUG_FUNCPTR (gst_video_max_rate_transform_ip);
|
||||
base_class->event = GST_DEBUG_FUNCPTR (gst_video_max_rate_sink_event);
|
||||
base_class->start = GST_DEBUG_FUNCPTR (gst_video_max_rate_start);
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_AVERAGE_PERIOD,
|
||||
g_param_spec_uint64 ("average-period", "Period over which to average",
|
||||
"Period over which to average the framerate (in ns)",
|
||||
1, G_MAXINT64, DEFAULT_AVERAGE_PERIOD,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -100,11 +123,46 @@ gst_video_max_rate_init (GstVideoMaxRate * videomaxrate,
|
|||
{
|
||||
gst_video_max_rate_reset (videomaxrate);
|
||||
videomaxrate->wanted_diff = 0;
|
||||
videomaxrate->average_period = DEFAULT_AVERAGE_PERIOD;
|
||||
|
||||
gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (videomaxrate), TRUE);
|
||||
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (videomaxrate), TRUE);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gst_video_max_rate_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstVideoMaxRate *videomaxrate = GST_VIDEO_MAX_RATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_AVERAGE_PERIOD:
|
||||
videomaxrate->average_period = g_value_get_uint64 (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gst_video_max_rate_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstVideoMaxRate *videomaxrate = GST_VIDEO_MAX_RATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_AVERAGE_PERIOD:
|
||||
g_value_set_uint64 (value, videomaxrate->average_period);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_video_max_rate_start (GstBaseTransform * trans)
|
||||
{
|
||||
|
@ -184,7 +242,6 @@ gst_video_max_rate_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||
{
|
||||
GstVideoMaxRate *videomaxrate = GST_VIDEO_MAX_RATE (trans);
|
||||
GstClockTime ts = GST_BUFFER_TIMESTAMP (buf);
|
||||
const GstClockTime average_period = GST_SECOND;
|
||||
|
||||
if (!GST_BUFFER_TIMESTAMP_IS_VALID (buf) || videomaxrate->wanted_diff == 0)
|
||||
return GST_FLOW_OK;
|
||||
|
@ -204,17 +261,17 @@ gst_video_max_rate_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||
if (videomaxrate->average) {
|
||||
GstClockTimeDiff wanted_diff;
|
||||
|
||||
if (G_LIKELY (average_period > videomaxrate->wanted_diff))
|
||||
if (G_LIKELY (videomaxrate->average_period > videomaxrate->wanted_diff))
|
||||
wanted_diff = videomaxrate->wanted_diff;
|
||||
else
|
||||
wanted_diff = average_period * 10;
|
||||
wanted_diff = videomaxrate->average_period * 10;
|
||||
|
||||
videomaxrate->average =
|
||||
gst_util_uint64_scale_round (videomaxrate->average,
|
||||
average_period - wanted_diff,
|
||||
average_period) +
|
||||
videomaxrate->average_period - wanted_diff,
|
||||
videomaxrate->average_period) +
|
||||
gst_util_uint64_scale_round (diff, wanted_diff,
|
||||
average_period);
|
||||
videomaxrate->average_period);
|
||||
} else {
|
||||
videomaxrate->average = diff;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ struct _GstVideoMaxRate
|
|||
GstBaseTransform parent;
|
||||
|
||||
GstClockTimeDiff wanted_diff;
|
||||
GstClockTime average_period;
|
||||
|
||||
GstClockTime last_ts;
|
||||
GstClockTimeDiff average;
|
||||
|
|
Loading…
Reference in a new issue