videomaxrate: Use basetransform correctly

This commit is contained in:
Olivier Crête 2010-06-10 20:14:01 -04:00
parent 6aa71af0ec
commit ed74d385bc

View file

@ -44,7 +44,9 @@ static GstStaticPadTemplate gst_video_max_rate_sink_template =
GST_STATIC_CAPS ("video/x-raw-yuv; video/x-raw-rgb") GST_STATIC_CAPS ("video/x-raw-yuv; video/x-raw-rgb")
); );
static gboolean gst_video_max_rate_sink_event (GstPad * pad, GstEvent * event); static gboolean gst_video_max_rate_start (GstBaseTransform * trans);
static gboolean gst_video_max_rate_sink_event (GstBaseTransform * trans,
GstEvent * event);
static GstCaps *gst_video_max_rate_transform_caps (GstBaseTransform * trans, static GstCaps *gst_video_max_rate_transform_caps (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * caps); GstPadDirection direction, GstCaps * caps);
static gboolean gst_video_max_rate_set_caps (GstBaseTransform * trans, static gboolean gst_video_max_rate_set_caps (GstBaseTransform * trans,
@ -81,42 +83,53 @@ gst_video_max_rate_class_init (GstVideoMaxRateClass * klass)
base_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_max_rate_set_caps); base_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_max_rate_set_caps);
base_class->transform_ip = base_class->transform_ip =
GST_DEBUG_FUNCPTR (gst_video_max_rate_transform_ip); 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);
}
static void
gst_video_max_rate_reset (GstVideoMaxRate * videomaxrate)
{
videomaxrate->last_ts = GST_CLOCK_TIME_NONE;
videomaxrate->average = 0;
} }
static void static void
gst_video_max_rate_init (GstVideoMaxRate * videomaxrate, gst_video_max_rate_init (GstVideoMaxRate * videomaxrate,
GstVideoMaxRateClass * gclass) GstVideoMaxRateClass * gclass)
{ {
videomaxrate->last_ts = GST_CLOCK_TIME_NONE; gst_video_max_rate_reset (videomaxrate);
videomaxrate->average = 0;
videomaxrate->wanted_diff = 0; videomaxrate->wanted_diff = 0;
gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (videomaxrate), TRUE); gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (videomaxrate), TRUE);
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (videomaxrate), TRUE);
}
gst_pad_set_event_function (GST_BASE_TRANSFORM_SINK_PAD (videomaxrate), static gboolean
GST_DEBUG_FUNCPTR (gst_video_max_rate_sink_event)); gst_video_max_rate_start (GstBaseTransform * trans)
{
GstVideoMaxRate *videomaxrate = GST_VIDEO_MAX_RATE (trans);
gst_video_max_rate_reset (videomaxrate);
return TRUE;
} }
gboolean gboolean
gst_video_max_rate_sink_event (GstPad * pad, GstEvent * event) gst_video_max_rate_sink_event (GstBaseTransform * trans, GstEvent * event)
{ {
GstVideoMaxRate *videomaxrate = GST_VIDEO_MAX_RATE (gst_pad_get_parent (pad)); GstVideoMaxRate *videomaxrate = GST_VIDEO_MAX_RATE (trans);
gboolean ret;
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NEWSEGMENT: case GST_EVENT_NEWSEGMENT:
case GST_EVENT_FLUSH_STOP: case GST_EVENT_FLUSH_STOP:
videomaxrate->last_ts = GST_CLOCK_TIME_NONE; gst_video_max_rate_reset (videomaxrate);
videomaxrate->average = 0;
break; break;
default: default:
break; break;
} }
ret = gst_pad_push_event (GST_BASE_TRANSFORM_SRC_PAD (videomaxrate), event); return TRUE;
gst_object_unref (videomaxrate);
return ret;
} }
GstCaps * GstCaps *
@ -159,8 +172,8 @@ gst_video_max_rate_set_caps (GstBaseTransform * trans, GstCaps * incaps,
denominator, numerator); denominator, numerator);
else else
videomaxrate->wanted_diff = 0; videomaxrate->wanted_diff = 0;
videomaxrate->last_ts = GST_CLOCK_TIME_NONE;
videomaxrate->average = 0; gst_video_max_rate_reset (videomaxrate);
return TRUE; return TRUE;
} }