videorate: fix caps negotiation function
[platform/upstream/gstreamer.git] / gst / videorate / gstvideorate.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /**
21  * SECTION:element-videorate
22  *
23  * This element takes an incoming stream of timestamped video frames.
24  * It will produce a perfect stream that matches the source pad's framerate.
25  *
26  * The correction is performed by dropping and duplicating frames, no fancy
27  * algorithm is used to interpolate frames (yet).
28  *
29  * By default the element will simply negotiate the same framerate on its
30  * source and sink pad.
31  *
32  * This operation is useful to link to elements that require a perfect stream.
33  * Typical examples are formats that do not store timestamps for video frames,
34  * but only store a framerate, like Ogg and AVI.
35  *
36  * A conversion to a specific framerate can be forced by using filtered caps on
37  * the source pad.
38  *
39  * The properties #GstVideoRate:in, #GstVideoRate:out, #GstVideoRate:duplicate
40  * and #GstVideoRate:drop can be read to obtain information about number of
41  * input frames, output frames, dropped frames (i.e. the number of unused input
42  * frames) and duplicated frames (i.e. the number of times an input frame was
43  * duplicated, beside being used normally).
44  *
45  * An input stream that needs no adjustments will thus never have dropped or
46  * duplicated frames.
47  *
48  * When the #GstVideoRate:silent property is set to FALSE, a GObject property
49  * notification will be emitted whenever one of the #GstVideoRate:duplicate or
50  * #GstVideoRate:drop values changes.
51  * This can potentially cause performance degradation.
52  * Note that property notification will happen from the streaming thread, so
53  * applications should be prepared for this.
54  *
55  * <refsect2>
56  * <title>Example pipelines</title>
57  * |[
58  * gst-launch -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! videorate ! video/x-raw,framerate=15/1 ! xvimagesink
59  * ]| Decode an Ogg/Theora file and adjust the framerate to 15 fps before playing.
60  * To create the test Ogg/Theora file refer to the documentation of theoraenc.
61  * |[
62  * gst-launch -v v4l2src ! videorate ! video/x-raw,framerate=25/2 ! theoraenc ! oggmux ! filesink location=recording.ogg
63  * ]| Capture video from a V4L device, and adjust the stream to 12.5 fps before
64  * encoding to Ogg/Theora.
65  * </refsect2>
66  *
67  * Last reviewed on 2006-09-02 (0.10.11)
68  */
69
70 #ifdef HAVE_CONFIG_H
71 #include "config.h"
72 #endif
73
74 #include "gstvideorate.h"
75
76 GST_DEBUG_CATEGORY_STATIC (video_rate_debug);
77 #define GST_CAT_DEFAULT video_rate_debug
78
79 /* GstVideoRate signals and args */
80 enum
81 {
82   /* FILL ME */
83   LAST_SIGNAL
84 };
85
86 #define DEFAULT_SILENT          TRUE
87 #define DEFAULT_NEW_PREF        1.0
88 #define DEFAULT_SKIP_TO_FIRST   FALSE
89 #define DEFAULT_DROP_ONLY       FALSE
90 #define DEFAULT_AVERAGE_PERIOD  0
91 #define DEFAULT_MAX_RATE        G_MAXINT
92
93 enum
94 {
95   PROP_0,
96   PROP_IN,
97   PROP_OUT,
98   PROP_DUP,
99   PROP_DROP,
100   PROP_SILENT,
101   PROP_NEW_PREF,
102   PROP_SKIP_TO_FIRST,
103   PROP_DROP_ONLY,
104   PROP_AVERAGE_PERIOD,
105   PROP_MAX_RATE
106 };
107
108 static GstStaticPadTemplate gst_video_rate_src_template =
109     GST_STATIC_PAD_TEMPLATE ("src",
110     GST_PAD_SRC,
111     GST_PAD_ALWAYS,
112     GST_STATIC_CAPS ("video/x-raw;" "image/jpeg;" "image/png")
113     );
114
115 static GstStaticPadTemplate gst_video_rate_sink_template =
116     GST_STATIC_PAD_TEMPLATE ("sink",
117     GST_PAD_SINK,
118     GST_PAD_ALWAYS,
119     GST_STATIC_CAPS ("video/x-raw;" "image/jpeg;" "image/png")
120     );
121
122 static void gst_video_rate_swap_prev (GstVideoRate * videorate,
123     GstBuffer * buffer, gint64 time);
124 static gboolean gst_video_rate_sink_event (GstBaseTransform * trans,
125     GstEvent * event);
126 static gboolean gst_video_rate_query (GstBaseTransform * trans,
127     GstPadDirection direction, GstQuery * query);
128
129 static gboolean gst_video_rate_setcaps (GstBaseTransform * trans,
130     GstCaps * in_caps, GstCaps * out_caps);
131
132 static GstCaps *gst_video_rate_transform_caps (GstBaseTransform * trans,
133     GstPadDirection direction, GstCaps * caps, GstCaps * filter);
134
135 static void gst_video_rate_fixate_caps (GstBaseTransform * trans,
136     GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
137
138 static GstFlowReturn gst_video_rate_transform_ip (GstBaseTransform * trans,
139     GstBuffer * buf);
140
141 static gboolean gst_video_rate_start (GstBaseTransform * trans);
142 static gboolean gst_video_rate_stop (GstBaseTransform * trans);
143
144
145 static void gst_video_rate_set_property (GObject * object,
146     guint prop_id, const GValue * value, GParamSpec * pspec);
147 static void gst_video_rate_get_property (GObject * object,
148     guint prop_id, GValue * value, GParamSpec * pspec);
149
150 static GParamSpec *pspec_drop = NULL;
151 static GParamSpec *pspec_duplicate = NULL;
152
153 #define gst_video_rate_parent_class parent_class
154 G_DEFINE_TYPE (GstVideoRate, gst_video_rate, GST_TYPE_BASE_TRANSFORM);
155
156 static void
157 gst_video_rate_class_init (GstVideoRateClass * klass)
158 {
159   GObjectClass *object_class = G_OBJECT_CLASS (klass);
160   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
161   GstBaseTransformClass *base_class = GST_BASE_TRANSFORM_CLASS (klass);
162
163   object_class->set_property = gst_video_rate_set_property;
164   object_class->get_property = gst_video_rate_get_property;
165
166   base_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_rate_setcaps);
167   base_class->transform_caps =
168       GST_DEBUG_FUNCPTR (gst_video_rate_transform_caps);
169   base_class->transform_ip = GST_DEBUG_FUNCPTR (gst_video_rate_transform_ip);
170   base_class->sink_event = GST_DEBUG_FUNCPTR (gst_video_rate_sink_event);
171   base_class->start = GST_DEBUG_FUNCPTR (gst_video_rate_start);
172   base_class->stop = GST_DEBUG_FUNCPTR (gst_video_rate_stop);
173   base_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_video_rate_fixate_caps);
174   base_class->query = GST_DEBUG_FUNCPTR (gst_video_rate_query);
175
176   g_object_class_install_property (object_class, PROP_IN,
177       g_param_spec_uint64 ("in", "In",
178           "Number of input frames", 0, G_MAXUINT64, 0,
179           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
180   g_object_class_install_property (object_class, PROP_OUT,
181       g_param_spec_uint64 ("out", "Out", "Number of output frames", 0,
182           G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
183   pspec_duplicate = g_param_spec_uint64 ("duplicate", "Duplicate",
184       "Number of duplicated frames", 0, G_MAXUINT64, 0,
185       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
186   g_object_class_install_property (object_class, PROP_DUP, pspec_duplicate);
187   pspec_drop = g_param_spec_uint64 ("drop", "Drop", "Number of dropped frames",
188       0, G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
189   g_object_class_install_property (object_class, PROP_DROP, pspec_drop);
190   g_object_class_install_property (object_class, PROP_SILENT,
191       g_param_spec_boolean ("silent", "silent",
192           "Don't emit notify for dropped and duplicated frames", DEFAULT_SILENT,
193           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
194   g_object_class_install_property (object_class, PROP_NEW_PREF,
195       g_param_spec_double ("new-pref", "New Pref",
196           "Value indicating how much to prefer new frames (unused)", 0.0, 1.0,
197           DEFAULT_NEW_PREF, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
198
199   /**
200    * GstVideoRate:skip-to-first:
201    * 
202    * Don't produce buffers before the first one we receive.
203    *
204    * Since: 0.10.25
205    */
206   g_object_class_install_property (object_class, PROP_SKIP_TO_FIRST,
207       g_param_spec_boolean ("skip-to-first", "Skip to first buffer",
208           "Don't produce buffers before the first one we receive",
209           DEFAULT_SKIP_TO_FIRST, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
210
211   /**
212    * GstVideoRate:drop-only:
213    *
214    * Only drop frames, no duplicates are produced.
215    *
216    * Since: 0.10.36
217    */
218   g_object_class_install_property (object_class, PROP_DROP_ONLY,
219       g_param_spec_boolean ("drop-only", "Only Drop",
220           "Only drop frames, no duplicates are produced",
221           DEFAULT_DROP_ONLY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
222
223   /**
224    * GstVideoRate:average-period:
225    *
226    * Arrange for maximum framerate by dropping frames beyond a certain framerate,
227    * where the framerate is calculated using a moving average over the
228    * configured.
229    *
230    * Since: 0.10.36
231    */
232   g_object_class_install_property (object_class, PROP_AVERAGE_PERIOD,
233       g_param_spec_uint64 ("average-period", "Period over which to average",
234           "Period over which to average the framerate (in ns) (0 = disabled)",
235           0, G_MAXINT64, DEFAULT_AVERAGE_PERIOD,
236           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
237
238   /**
239    * GstVideoRate:max-rate:
240    *
241    * maximum framerate to pass through
242    *
243    * Since: 0.10.36
244    */
245   g_object_class_install_property (object_class, PROP_MAX_RATE,
246       g_param_spec_int ("max-rate", "maximum framerate",
247           "Maximum framerate allowed to pass through "
248           "(in frames per second, implies drop-only)",
249           1, G_MAXINT, DEFAULT_MAX_RATE,
250           G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
251
252   gst_element_class_set_details_simple (element_class,
253       "Video rate adjuster", "Filter/Effect/Video",
254       "Drops/duplicates/adjusts timestamps on video frames to make a perfect stream",
255       "Wim Taymans <wim@fluendo.com>");
256
257   gst_element_class_add_pad_template (element_class,
258       gst_static_pad_template_get (&gst_video_rate_sink_template));
259   gst_element_class_add_pad_template (element_class,
260       gst_static_pad_template_get (&gst_video_rate_src_template));
261 }
262
263 static void
264 gst_value_fraction_get_extremes (const GValue * v,
265     gint * min_num, gint * min_denom, gint * max_num, gint * max_denom)
266 {
267   if (GST_VALUE_HOLDS_FRACTION (v)) {
268     *min_num = *max_num = gst_value_get_fraction_numerator (v);
269     *min_denom = *max_denom = gst_value_get_fraction_denominator (v);
270   } else if (GST_VALUE_HOLDS_FRACTION_RANGE (v)) {
271     const GValue *min, *max;
272
273     min = gst_value_get_fraction_range_min (v);
274     *min_num = gst_value_get_fraction_numerator (min);
275     *min_denom = gst_value_get_fraction_denominator (min);
276
277     max = gst_value_get_fraction_range_max (v);
278     *max_num = gst_value_get_fraction_numerator (max);
279     *max_denom = gst_value_get_fraction_denominator (max);
280   } else if (GST_VALUE_HOLDS_LIST (v)) {
281     gint min_n = G_MAXINT, min_d = 1, max_n = 0, max_d = 1;
282     int i, n;
283
284     *min_num = G_MAXINT;
285     *min_denom = 1;
286     *max_num = 0;
287     *max_denom = 1;
288
289     n = gst_value_list_get_size (v);
290
291     g_assert (n > 0);
292
293     for (i = 0; i < n; i++) {
294       const GValue *t = gst_value_list_get_value (v, i);
295
296       gst_value_fraction_get_extremes (t, &min_n, &min_d, &max_n, &max_d);
297       if (gst_util_fraction_compare (min_n, min_d, *min_num, *min_denom) < 0) {
298         *min_num = min_n;
299         *min_denom = min_d;
300       }
301
302       if (gst_util_fraction_compare (max_n, max_d, *max_num, *max_denom) > 0) {
303         *max_num = max_n;
304         *max_denom = max_d;
305       }
306     }
307   } else {
308     g_warning ("Unknown type for framerate");
309     *min_num = 0;
310     *min_denom = 1;
311     *max_num = G_MAXINT;
312     *max_denom = 1;
313   }
314 }
315
316 /* Clamp the framerate in a caps structure to be a smaller range then
317  * [1...max_rate], otherwise return false */
318 static gboolean
319 gst_video_max_rate_clamp_structure (GstStructure * s, gint maxrate,
320     gint * min_num, gint * min_denom, gint * max_num, gint * max_denom)
321 {
322   gboolean ret = FALSE;
323
324   if (!gst_structure_has_field (s, "framerate")) {
325     /* No framerate field implies any framerate, clamping would result in
326      * [1..max_rate] so not a real subset */
327     goto out;
328   } else {
329     const GValue *v;
330     GValue intersection = { 0, };
331     GValue clamp = { 0, };
332     gint tmp_num, tmp_denom;
333
334     g_value_init (&clamp, GST_TYPE_FRACTION_RANGE);
335     gst_value_set_fraction_range_full (&clamp, 0, 1, maxrate, 1);
336
337     v = gst_structure_get_value (s, "framerate");
338     ret = gst_value_intersect (&intersection, v, &clamp);
339     g_value_unset (&clamp);
340
341     if (!ret)
342       goto out;
343
344     gst_value_fraction_get_extremes (&intersection,
345         min_num, min_denom, max_num, max_denom);
346
347     gst_value_fraction_get_extremes (v,
348         &tmp_num, &tmp_denom, max_num, max_denom);
349
350     if (gst_util_fraction_compare (*max_num, *max_denom, maxrate, 1) > 0) {
351       *max_num = maxrate;
352       *max_denom = 1;
353     }
354
355     gst_structure_take_value (s, "framerate", &intersection);
356   }
357
358 out:
359   return ret;
360 }
361
362 static GstCaps *
363 gst_video_rate_transform_caps (GstBaseTransform * trans,
364     GstPadDirection direction, GstCaps * caps, GstCaps * filter)
365 {
366   GstVideoRate *videorate = GST_VIDEO_RATE (trans);
367   GstCaps *ret;
368   GstStructure *s, *s1, *s2, *s3 = NULL;
369   int maxrate = g_atomic_int_get (&videorate->max_rate);
370   gint i;
371
372   ret = gst_caps_new_empty ();
373
374   for (i = 0; i < gst_caps_get_size (caps); i++) {
375     s = gst_caps_get_structure (caps, i);
376
377     s1 = gst_structure_copy (s);
378     s2 = gst_structure_copy (s);
379
380     if (videorate->drop_only) {
381       gint min_num = 0, min_denom = 1;
382       gint max_num = G_MAXINT, max_denom = 1;
383
384       /* Clamp the caps to our maximum rate as the first caps if possible */
385       if (!gst_video_max_rate_clamp_structure (s1, maxrate,
386               &min_num, &min_denom, &max_num, &max_denom)) {
387         min_num = 0;
388         min_denom = 1;
389         max_num = maxrate;
390         max_denom = 1;
391
392         /* clamp wouldn't be a real subset of 1..maxrate, in this case the sink
393          * caps should become [1..maxrate], [1..maxint] and the src caps just
394          * [1..maxrate].  In case there was a caps incompatibility things will
395          * explode later as appropriate :)
396          *
397          * In case [X..maxrate] == [X..maxint], skip as we'll set it later
398          */
399         if (direction == GST_PAD_SRC && maxrate != G_MAXINT)
400           gst_structure_set (s1, "framerate", GST_TYPE_FRACTION_RANGE,
401               min_num, min_denom, maxrate, 1, NULL);
402         else {
403           gst_structure_free (s1);
404           s1 = NULL;
405         }
406       }
407
408       if (direction == GST_PAD_SRC) {
409         /* We can accept anything as long as it's at least the minimal framerate
410          * the the sink needs */
411         gst_structure_set (s2, "framerate", GST_TYPE_FRACTION_RANGE,
412             min_num, min_denom, G_MAXINT, 1, NULL);
413
414         /* Also allow unknown framerate, if it isn't already */
415         if (min_num != 0 || min_denom != 1) {
416           s3 = gst_structure_copy (s);
417           gst_structure_set (s3, "framerate", GST_TYPE_FRACTION, 0, 1, NULL);
418         }
419       } else if (max_num != 0 || max_denom != 1) {
420         /* We can provide everything upto the maximum framerate at the src */
421         gst_structure_set (s2, "framerate", GST_TYPE_FRACTION_RANGE,
422             0, 1, max_num, max_denom, NULL);
423       }
424     } else if (direction == GST_PAD_SINK) {
425       gint min_num = 0, min_denom = 1;
426       gint max_num = G_MAXINT, max_denom = 1;
427
428       if (!gst_video_max_rate_clamp_structure (s1, maxrate,
429               &min_num, &min_denom, &max_num, &max_denom)) {
430         gst_structure_free (s1);
431         s1 = NULL;
432       }
433       gst_structure_set (s2, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1,
434           maxrate, 1, NULL);
435     } else {
436       /* set the framerate as a range */
437       gst_structure_set (s2, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1,
438           G_MAXINT, 1, NULL);
439     }
440     if (s1 != NULL)
441       gst_caps_merge_structure (ret, s1);
442     gst_caps_merge_structure (ret, s2);
443     if (s3 != NULL)
444       gst_caps_merge_structure (ret, s3);
445   }
446   if (filter) {
447     GstCaps *intersection;
448
449     intersection =
450         gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
451     gst_caps_unref (ret);
452     ret = intersection;
453   }
454   return ret;
455 }
456
457 static void
458 gst_video_rate_fixate_caps (GstBaseTransform * trans,
459     GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
460 {
461   GstStructure *s;
462   gint num, denom;
463
464   s = gst_caps_get_structure (caps, 0);
465   if (G_UNLIKELY (!gst_structure_get_fraction (s, "framerate", &num, &denom)))
466     return;
467
468   gst_caps_truncate (othercaps);
469   s = gst_caps_get_structure (othercaps, 0);
470   gst_structure_fixate_field_nearest_fraction (s, "framerate", num, denom);
471 }
472
473 static gboolean
474 gst_video_rate_setcaps (GstBaseTransform * trans, GstCaps * in_caps,
475     GstCaps * out_caps)
476 {
477   GstVideoRate *videorate = GST_VIDEO_RATE (trans);
478   GstStructure *structure;
479   gboolean ret = TRUE;
480   gint rate_numerator, rate_denominator;
481
482   videorate = GST_VIDEO_RATE (trans);
483
484   GST_DEBUG_OBJECT (trans, "setcaps called in: %" GST_PTR_FORMAT
485       " out: %" GST_PTR_FORMAT, in_caps, out_caps);
486
487   structure = gst_caps_get_structure (in_caps, 0);
488   if (!gst_structure_get_fraction (structure, "framerate",
489           &rate_numerator, &rate_denominator))
490     goto no_framerate;
491
492   videorate->from_rate_numerator = rate_numerator;
493   videorate->from_rate_denominator = rate_denominator;
494
495   structure = gst_caps_get_structure (out_caps, 0);
496   if (!gst_structure_get_fraction (structure, "framerate",
497           &rate_numerator, &rate_denominator))
498     goto no_framerate;
499
500   /* out_frame_count is scaled by the frame rate caps when calculating next_ts.
501    * when the frame rate caps change, we must update base_ts and reset
502    * out_frame_count */
503   if (videorate->to_rate_numerator) {
504     videorate->base_ts +=
505         gst_util_uint64_scale (videorate->out_frame_count,
506         videorate->to_rate_denominator * GST_SECOND,
507         videorate->to_rate_numerator);
508   }
509   videorate->out_frame_count = 0;
510   videorate->to_rate_numerator = rate_numerator;
511   videorate->to_rate_denominator = rate_denominator;
512
513   if (rate_numerator)
514     videorate->wanted_diff = gst_util_uint64_scale_int (GST_SECOND,
515         rate_denominator, rate_numerator);
516   else
517     videorate->wanted_diff = 0;
518
519 done:
520   /* After a setcaps, our caps may have changed. In that case, we can't use
521    * the old buffer, if there was one (it might have different dimensions) */
522   GST_DEBUG_OBJECT (videorate, "swapping old buffers");
523   gst_video_rate_swap_prev (videorate, NULL, GST_CLOCK_TIME_NONE);
524   videorate->last_ts = GST_CLOCK_TIME_NONE;
525   videorate->average = 0;
526
527   return ret;
528
529 no_framerate:
530   {
531     GST_DEBUG_OBJECT (videorate, "no framerate specified");
532     ret = FALSE;
533     goto done;
534   }
535 }
536
537 static void
538 gst_video_rate_reset (GstVideoRate * videorate)
539 {
540   GST_DEBUG_OBJECT (videorate, "resetting internal variables");
541
542   videorate->in = 0;
543   videorate->out = 0;
544   videorate->base_ts = 0;
545   videorate->out_frame_count = 0;
546   videorate->drop = 0;
547   videorate->dup = 0;
548   videorate->next_ts = GST_CLOCK_TIME_NONE;
549   videorate->last_ts = GST_CLOCK_TIME_NONE;
550   videorate->discont = TRUE;
551   videorate->average = 0;
552   gst_video_rate_swap_prev (videorate, NULL, 0);
553
554   gst_segment_init (&videorate->segment, GST_FORMAT_TIME);
555 }
556
557 static void
558 gst_video_rate_init (GstVideoRate * videorate)
559 {
560   gst_video_rate_reset (videorate);
561   videorate->silent = DEFAULT_SILENT;
562   videorate->new_pref = DEFAULT_NEW_PREF;
563   videorate->drop_only = DEFAULT_DROP_ONLY;
564   videorate->average_period = DEFAULT_AVERAGE_PERIOD;
565   videorate->average_period_set = DEFAULT_AVERAGE_PERIOD;
566   videorate->max_rate = DEFAULT_MAX_RATE;
567
568   videorate->from_rate_numerator = 0;
569   videorate->from_rate_denominator = 0;
570   videorate->to_rate_numerator = 0;
571   videorate->to_rate_denominator = 0;
572
573   gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (videorate), TRUE);
574 }
575
576 /* flush the oldest buffer */
577 static GstFlowReturn
578 gst_video_rate_flush_prev (GstVideoRate * videorate, gboolean duplicate)
579 {
580   GstFlowReturn res;
581   GstBuffer *outbuf;
582   GstClockTime push_ts;
583
584   if (!videorate->prevbuf)
585     goto eos_before_buffers;
586
587   /* make sure we can write to the metadata */
588   outbuf = gst_buffer_make_writable (gst_buffer_ref (videorate->prevbuf));
589
590   GST_BUFFER_OFFSET (outbuf) = videorate->out;
591   GST_BUFFER_OFFSET_END (outbuf) = videorate->out + 1;
592
593   if (videorate->discont) {
594     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
595     videorate->discont = FALSE;
596   } else
597     GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_DISCONT);
598
599   if (duplicate)
600     GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
601   else
602     GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_GAP);
603
604   /* this is the timestamp we put on the buffer */
605   push_ts = videorate->next_ts;
606
607   videorate->out++;
608   videorate->out_frame_count++;
609   if (videorate->to_rate_numerator) {
610     /* interpolate next expected timestamp in the segment */
611     videorate->next_ts =
612         videorate->segment.base + videorate->segment.start +
613         videorate->base_ts + gst_util_uint64_scale (videorate->out_frame_count,
614         videorate->to_rate_denominator * GST_SECOND,
615         videorate->to_rate_numerator);
616     GST_BUFFER_DURATION (outbuf) = videorate->next_ts - push_ts;
617   }
618
619   /* We do not need to update time in VFR (variable frame rate) mode */
620   if (!videorate->drop_only) {
621     /* adapt for looping, bring back to time in current segment. */
622     GST_BUFFER_TIMESTAMP (outbuf) = push_ts - videorate->segment.base;
623   }
624
625   GST_LOG_OBJECT (videorate,
626       "old is best, dup, pushing buffer outgoing ts %" GST_TIME_FORMAT,
627       GST_TIME_ARGS (push_ts));
628
629   res = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (videorate), outbuf);
630
631   return res;
632
633   /* WARNINGS */
634 eos_before_buffers:
635   {
636     GST_INFO_OBJECT (videorate, "got EOS before any buffer was received");
637     return GST_FLOW_OK;
638   }
639 }
640
641 static void
642 gst_video_rate_swap_prev (GstVideoRate * videorate, GstBuffer * buffer,
643     gint64 time)
644 {
645   GST_LOG_OBJECT (videorate, "swap_prev: storing buffer %p in prev", buffer);
646   if (videorate->prevbuf)
647     gst_buffer_unref (videorate->prevbuf);
648   videorate->prevbuf = buffer != NULL ? gst_buffer_ref (buffer) : NULL;
649   videorate->prev_ts = time;
650 }
651
652 static void
653 gst_video_rate_notify_drop (GstVideoRate * videorate)
654 {
655 #if !GLIB_CHECK_VERSION(2,26,0)
656   g_object_notify ((GObject *) videorate, "drop");
657 #else
658   g_object_notify_by_pspec ((GObject *) videorate, pspec_drop);
659 #endif
660 }
661
662 static void
663 gst_video_rate_notify_duplicate (GstVideoRate * videorate)
664 {
665 #if !GLIB_CHECK_VERSION(2,26,0)
666   g_object_notify ((GObject *) videorate, "duplicate");
667 #else
668   g_object_notify_by_pspec ((GObject *) videorate, pspec_duplicate);
669 #endif
670 }
671
672 #define MAGIC_LIMIT  25
673 static gboolean
674 gst_video_rate_sink_event (GstBaseTransform * trans, GstEvent * event)
675 {
676   GstVideoRate *videorate;
677
678   videorate = GST_VIDEO_RATE (trans);
679
680   switch (GST_EVENT_TYPE (event)) {
681     case GST_EVENT_SEGMENT:
682     {
683       const GstSegment *segment;
684
685       gst_event_parse_segment (event, &segment);
686
687       if (segment->format != GST_FORMAT_TIME)
688         goto format_error;
689
690       GST_DEBUG_OBJECT (videorate, "handle NEWSEGMENT");
691
692       /* close up the previous segment, if appropriate */
693       if (videorate->prevbuf) {
694         gint count = 0;
695         GstFlowReturn res;
696
697         res = GST_FLOW_OK;
698         /* fill up to the end of current segment,
699          * or only send out the stored buffer if there is no specific stop.
700          * regardless, prevent going loopy in strange cases */
701         while (res == GST_FLOW_OK && count <= MAGIC_LIMIT &&
702             ((GST_CLOCK_TIME_IS_VALID (videorate->segment.stop) &&
703                     videorate->next_ts - videorate->segment.base
704                     < videorate->segment.stop)
705                 || count < 1)) {
706           res = gst_video_rate_flush_prev (videorate, count > 0);
707           count++;
708         }
709         if (count > 1) {
710           videorate->dup += count - 1;
711           if (!videorate->silent)
712             gst_video_rate_notify_duplicate (videorate);
713         } else if (count == 0) {
714           videorate->drop++;
715           if (!videorate->silent)
716             gst_video_rate_notify_drop (videorate);
717         }
718         /* clean up for the new one; _chain will resume from the new start */
719         videorate->base_ts = 0;
720         videorate->out_frame_count = 0;
721         gst_video_rate_swap_prev (videorate, NULL, 0);
722         videorate->next_ts = GST_CLOCK_TIME_NONE;
723       }
724
725       /* We just want to update the accumulated stream_time  */
726       gst_segment_copy_into (segment, &videorate->segment);
727
728       GST_DEBUG_OBJECT (videorate, "updated segment: %" GST_SEGMENT_FORMAT,
729           &videorate->segment);
730       break;
731     }
732     case GST_EVENT_EOS:{
733       gint count = 0;
734       GstFlowReturn res = GST_FLOW_OK;
735
736       GST_DEBUG_OBJECT (videorate, "Got EOS");
737
738       /* If the segment has a stop position, fill the segment */
739       if (GST_CLOCK_TIME_IS_VALID (videorate->segment.stop)) {
740         /* fill up to the end of current segment,
741          * or only send out the stored buffer if there is no specific stop.
742          * regardless, prevent going loopy in strange cases */
743         while (res == GST_FLOW_OK && count <= MAGIC_LIMIT &&
744             ((videorate->next_ts - videorate->segment.base <
745                     videorate->segment.stop)
746                 || count < 1)) {
747           res = gst_video_rate_flush_prev (videorate, count > 0);
748           count++;
749         }
750       } else if (videorate->prevbuf) {
751         /* Output at least one frame but if the buffer duration is valid, output
752          * enough frames to use the complete buffer duration */
753         if (GST_BUFFER_DURATION_IS_VALID (videorate->prevbuf)) {
754           GstClockTime end_ts =
755               videorate->next_ts + GST_BUFFER_DURATION (videorate->prevbuf);
756
757           while (res == GST_FLOW_OK && count <= MAGIC_LIMIT &&
758               ((videorate->next_ts - videorate->segment.base < end_ts)
759                   || count < 1)) {
760             res = gst_video_rate_flush_prev (videorate, count > 0);
761             count++;
762           }
763         } else {
764           res = gst_video_rate_flush_prev (videorate, FALSE);
765           count = 1;
766         }
767       }
768
769       if (count > 1) {
770         videorate->dup += count - 1;
771         if (!videorate->silent)
772           gst_video_rate_notify_duplicate (videorate);
773       } else if (count == 0) {
774         videorate->drop++;
775         if (!videorate->silent)
776           gst_video_rate_notify_drop (videorate);
777       }
778
779       break;
780     }
781     case GST_EVENT_FLUSH_STOP:
782       /* also resets the segment */
783       GST_DEBUG_OBJECT (videorate, "Got FLUSH_STOP");
784       gst_video_rate_reset (videorate);
785       break;
786     default:
787       break;
788   }
789
790   return TRUE;
791
792   /* ERRORS */
793 format_error:
794   {
795     GST_WARNING_OBJECT (videorate,
796         "Got segment but doesn't have GST_FORMAT_TIME value");
797     return FALSE;
798   }
799 }
800
801 static gboolean
802 gst_video_rate_query (GstBaseTransform * trans, GstPadDirection direction,
803     GstQuery * query)
804 {
805   GstVideoRate *videorate = GST_VIDEO_RATE (trans);
806   gboolean res = FALSE;
807   GstPad *otherpad;
808
809   otherpad = (direction == GST_PAD_SRC) ?
810       GST_BASE_TRANSFORM_SINK_PAD (trans) : GST_BASE_TRANSFORM_SRC_PAD (trans);
811
812   switch (GST_QUERY_TYPE (query)) {
813     case GST_QUERY_LATENCY:
814     {
815       GstClockTime min, max;
816       gboolean live;
817       guint64 latency;
818       guint64 avg_period;
819       GstPad *peer;
820
821       GST_OBJECT_LOCK (videorate);
822       avg_period = videorate->average_period_set;
823       GST_OBJECT_UNLOCK (videorate);
824
825       if (avg_period == 0 && (peer = gst_pad_get_peer (otherpad))) {
826         if ((res = gst_pad_query (peer, query))) {
827           gst_query_parse_latency (query, &live, &min, &max);
828
829           GST_DEBUG_OBJECT (videorate, "Peer latency: min %"
830               GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
831               GST_TIME_ARGS (min), GST_TIME_ARGS (max));
832
833           if (videorate->from_rate_numerator != 0) {
834             /* add latency. We don't really know since we hold on to the frames
835              * until we get a next frame, which can be anything. We assume
836              * however that this will take from_rate time. */
837             latency = gst_util_uint64_scale (GST_SECOND,
838                 videorate->from_rate_denominator,
839                 videorate->from_rate_numerator);
840           } else {
841             /* no input framerate, we don't know */
842             latency = 0;
843           }
844
845           GST_DEBUG_OBJECT (videorate, "Our latency: %"
846               GST_TIME_FORMAT, GST_TIME_ARGS (latency));
847
848           min += latency;
849           if (max != -1)
850             max += latency;
851
852           GST_DEBUG_OBJECT (videorate, "Calculated total latency : min %"
853               GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
854               GST_TIME_ARGS (min), GST_TIME_ARGS (max));
855
856           gst_query_set_latency (query, live, min, max);
857         }
858         gst_object_unref (peer);
859         break;
860       }
861       /* Simple fallthrough if we don't have a latency or not a peer that we
862        * can't ask about its latency yet.. */
863     }
864     default:
865       res =
866           GST_BASE_TRANSFORM_CLASS (parent_class)->query (trans, direction,
867           query);
868       break;
869   }
870
871   return res;
872 }
873
874 static GstFlowReturn
875 gst_video_rate_trans_ip_max_avg (GstVideoRate * videorate, GstBuffer * buf)
876 {
877   GstClockTime ts = GST_BUFFER_TIMESTAMP (buf);
878
879   videorate->in++;
880
881   if (!GST_CLOCK_TIME_IS_VALID (ts) || videorate->wanted_diff == 0)
882     goto push;
883
884   /* drop frames if they exceed our output rate */
885   if (GST_CLOCK_TIME_IS_VALID (videorate->last_ts)) {
886     GstClockTimeDiff diff = ts - videorate->last_ts;
887
888     /* Drop buffer if its early compared to the desired frame rate and
889      * the current average is higher than the desired average
890      */
891     if (diff < videorate->wanted_diff &&
892         videorate->average < videorate->wanted_diff)
893       goto drop;
894
895     /* Update average */
896     if (videorate->average) {
897       GstClockTimeDiff wanted_diff;
898
899       if (G_LIKELY (videorate->average_period > videorate->wanted_diff))
900         wanted_diff = videorate->wanted_diff;
901       else
902         wanted_diff = videorate->average_period * 10;
903
904       videorate->average =
905           gst_util_uint64_scale_round (videorate->average,
906           videorate->average_period - wanted_diff,
907           videorate->average_period) +
908           gst_util_uint64_scale_round (diff, wanted_diff,
909           videorate->average_period);
910     } else {
911       videorate->average = diff;
912     }
913   }
914
915   videorate->last_ts = ts;
916
917 push:
918   videorate->out++;
919   return GST_FLOW_OK;
920
921 drop:
922   if (!videorate->silent)
923     gst_video_rate_notify_drop (videorate);
924   return GST_BASE_TRANSFORM_FLOW_DROPPED;
925 }
926
927 static GstFlowReturn
928 gst_video_rate_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
929 {
930   GstVideoRate *videorate;
931   GstFlowReturn res = GST_BASE_TRANSFORM_FLOW_DROPPED;
932   GstClockTime intime, in_ts, in_dur;
933   GstClockTime avg_period;
934   gboolean skip = FALSE;
935
936   videorate = GST_VIDEO_RATE (trans);
937
938   /* make sure the denominators are not 0 */
939   if (videorate->from_rate_denominator == 0 ||
940       videorate->to_rate_denominator == 0)
941     goto not_negotiated;
942
943   GST_OBJECT_LOCK (videorate);
944   avg_period = videorate->average_period_set;
945   GST_OBJECT_UNLOCK (videorate);
946
947   /* MT-safe switching between modes */
948   if (G_UNLIKELY (avg_period != videorate->average_period)) {
949     gboolean switch_mode = (avg_period == 0 || videorate->average_period == 0);
950     videorate->average_period = avg_period;
951     videorate->last_ts = GST_CLOCK_TIME_NONE;
952
953     if (switch_mode) {
954       if (avg_period) {
955         /* enabling average mode */
956         videorate->average = 0;
957         /* make sure no cached buffers from regular mode are left */
958         gst_video_rate_swap_prev (videorate, NULL, 0);
959       } else {
960         /* enable regular mode */
961         videorate->next_ts = GST_CLOCK_TIME_NONE;
962         skip = TRUE;
963       }
964
965       /* max averaging mode has a no latency, normal mode does */
966       gst_element_post_message (GST_ELEMENT (videorate),
967           gst_message_new_latency (GST_OBJECT (videorate)));
968     }
969   }
970
971   if (videorate->average_period > 0)
972     return gst_video_rate_trans_ip_max_avg (videorate, buffer);
973
974   in_ts = GST_BUFFER_TIMESTAMP (buffer);
975   in_dur = GST_BUFFER_DURATION (buffer);
976
977   if (G_UNLIKELY (in_ts == GST_CLOCK_TIME_NONE)) {
978     in_ts = videorate->last_ts;
979     if (G_UNLIKELY (in_ts == GST_CLOCK_TIME_NONE))
980       goto invalid_buffer;
981   }
982
983   /* get the time of the next expected buffer timestamp, we use this when the
984    * next buffer has -1 as a timestamp */
985   videorate->last_ts = in_ts;
986   if (in_dur != GST_CLOCK_TIME_NONE)
987     videorate->last_ts += in_dur;
988
989   GST_DEBUG_OBJECT (videorate, "got buffer with timestamp %" GST_TIME_FORMAT,
990       GST_TIME_ARGS (in_ts));
991
992   /* the input time is the time in the segment + all previously accumulated
993    * segments */
994   intime = in_ts + videorate->segment.base;
995
996   /* we need to have two buffers to compare */
997   if (videorate->prevbuf == NULL) {
998     gst_video_rate_swap_prev (videorate, buffer, intime);
999     videorate->in++;
1000     if (!GST_CLOCK_TIME_IS_VALID (videorate->next_ts)) {
1001       /* new buffer, we expect to output a buffer that matches the first
1002        * timestamp in the segment */
1003       if (videorate->skip_to_first || skip) {
1004         videorate->next_ts = intime;
1005         videorate->base_ts = in_ts - videorate->segment.start;
1006         videorate->out_frame_count = 0;
1007       } else {
1008         videorate->next_ts = videorate->segment.start + videorate->segment.base;
1009       }
1010     }
1011   } else {
1012     GstClockTime prevtime;
1013     gint count = 0;
1014     gint64 diff1, diff2;
1015
1016     prevtime = videorate->prev_ts;
1017
1018     GST_LOG_OBJECT (videorate,
1019         "BEGINNING prev buf %" GST_TIME_FORMAT " new buf %" GST_TIME_FORMAT
1020         " outgoing ts %" GST_TIME_FORMAT, GST_TIME_ARGS (prevtime),
1021         GST_TIME_ARGS (intime), GST_TIME_ARGS (videorate->next_ts));
1022
1023     videorate->in++;
1024
1025     /* drop new buffer if it's before previous one */
1026     if (intime < prevtime) {
1027       GST_DEBUG_OBJECT (videorate,
1028           "The new buffer (%" GST_TIME_FORMAT
1029           ") is before the previous buffer (%"
1030           GST_TIME_FORMAT "). Dropping new buffer.",
1031           GST_TIME_ARGS (intime), GST_TIME_ARGS (prevtime));
1032       videorate->drop++;
1033       if (!videorate->silent)
1034         gst_video_rate_notify_drop (videorate);
1035       goto done;
1036     }
1037
1038     /* got 2 buffers, see which one is the best */
1039     do {
1040
1041       diff1 = prevtime - videorate->next_ts;
1042       diff2 = intime - videorate->next_ts;
1043
1044       /* take absolute values, beware: abs and ABS don't work for gint64 */
1045       if (diff1 < 0)
1046         diff1 = -diff1;
1047       if (diff2 < 0)
1048         diff2 = -diff2;
1049
1050       GST_LOG_OBJECT (videorate,
1051           "diff with prev %" GST_TIME_FORMAT " diff with new %"
1052           GST_TIME_FORMAT " outgoing ts %" GST_TIME_FORMAT,
1053           GST_TIME_ARGS (diff1), GST_TIME_ARGS (diff2),
1054           GST_TIME_ARGS (videorate->next_ts));
1055
1056       /* output first one when its the best */
1057       if (diff1 <= diff2) {
1058         GstFlowReturn r;
1059         count++;
1060
1061         /* on error the _flush function posted a warning already */
1062         if ((r = gst_video_rate_flush_prev (videorate,
1063                     count > 1)) != GST_FLOW_OK) {
1064           res = r;
1065           goto done;
1066         }
1067       }
1068
1069       /* Do not produce any dups. We can exit loop now */
1070       if (videorate->drop_only)
1071         break;
1072       /* continue while the first one was the best, if they were equal avoid
1073        * going into an infinite loop */
1074     }
1075     while (diff1 < diff2);
1076
1077     /* if we outputed the first buffer more then once, we have dups */
1078     if (count > 1) {
1079       videorate->dup += count - 1;
1080       if (!videorate->silent)
1081         gst_video_rate_notify_duplicate (videorate);
1082     }
1083     /* if we didn't output the first buffer, we have a drop */
1084     else if (count == 0) {
1085       videorate->drop++;
1086
1087       if (!videorate->silent)
1088         gst_video_rate_notify_drop (videorate);
1089
1090       GST_LOG_OBJECT (videorate,
1091           "new is best, old never used, drop, outgoing ts %"
1092           GST_TIME_FORMAT, GST_TIME_ARGS (videorate->next_ts));
1093     }
1094     GST_LOG_OBJECT (videorate,
1095         "END, putting new in old, diff1 %" GST_TIME_FORMAT
1096         ", diff2 %" GST_TIME_FORMAT ", next_ts %" GST_TIME_FORMAT
1097         ", in %" G_GUINT64_FORMAT ", out %" G_GUINT64_FORMAT ", drop %"
1098         G_GUINT64_FORMAT ", dup %" G_GUINT64_FORMAT, GST_TIME_ARGS (diff1),
1099         GST_TIME_ARGS (diff2), GST_TIME_ARGS (videorate->next_ts),
1100         videorate->in, videorate->out, videorate->drop, videorate->dup);
1101
1102     /* swap in new one when it's the best */
1103     gst_video_rate_swap_prev (videorate, buffer, intime);
1104   }
1105 done:
1106   return res;
1107
1108   /* ERRORS */
1109 not_negotiated:
1110   {
1111     GST_WARNING_OBJECT (videorate, "no framerate negotiated");
1112     res = GST_FLOW_NOT_NEGOTIATED;
1113     goto done;
1114   }
1115
1116 invalid_buffer:
1117   {
1118     GST_WARNING_OBJECT (videorate,
1119         "Got buffer with GST_CLOCK_TIME_NONE timestamp, discarding it");
1120     res = GST_BASE_TRANSFORM_FLOW_DROPPED;
1121     goto done;
1122   }
1123 }
1124
1125 static gboolean
1126 gst_video_rate_start (GstBaseTransform * trans)
1127 {
1128   gst_video_rate_reset (GST_VIDEO_RATE (trans));
1129   return TRUE;
1130 }
1131
1132 static gboolean
1133 gst_video_rate_stop (GstBaseTransform * trans)
1134 {
1135   gst_video_rate_reset (GST_VIDEO_RATE (trans));
1136   return TRUE;
1137 }
1138
1139 static void
1140 gst_video_rate_set_property (GObject * object,
1141     guint prop_id, const GValue * value, GParamSpec * pspec)
1142 {
1143   GstVideoRate *videorate = GST_VIDEO_RATE (object);
1144
1145   GST_OBJECT_LOCK (videorate);
1146   switch (prop_id) {
1147     case PROP_SILENT:
1148       videorate->silent = g_value_get_boolean (value);
1149       break;
1150     case PROP_NEW_PREF:
1151       videorate->new_pref = g_value_get_double (value);
1152       break;
1153     case PROP_SKIP_TO_FIRST:
1154       videorate->skip_to_first = g_value_get_boolean (value);
1155       break;
1156     case PROP_DROP_ONLY:
1157       videorate->drop_only = g_value_get_boolean (value);
1158       goto reconfigure;
1159       break;
1160     case PROP_AVERAGE_PERIOD:
1161       videorate->average_period_set = g_value_get_uint64 (value);
1162       break;
1163     case PROP_MAX_RATE:
1164       g_atomic_int_set (&videorate->max_rate, g_value_get_int (value));
1165       goto reconfigure;
1166       break;
1167     default:
1168       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1169       break;
1170   }
1171   GST_OBJECT_UNLOCK (videorate);
1172   return;
1173
1174 reconfigure:
1175   GST_OBJECT_UNLOCK (videorate);
1176   gst_base_transform_reconfigure (GST_BASE_TRANSFORM (videorate));
1177 }
1178
1179 static void
1180 gst_video_rate_get_property (GObject * object,
1181     guint prop_id, GValue * value, GParamSpec * pspec)
1182 {
1183   GstVideoRate *videorate = GST_VIDEO_RATE (object);
1184
1185   GST_OBJECT_LOCK (videorate);
1186   switch (prop_id) {
1187     case PROP_IN:
1188       g_value_set_uint64 (value, videorate->in);
1189       break;
1190     case PROP_OUT:
1191       g_value_set_uint64 (value, videorate->out);
1192       break;
1193     case PROP_DUP:
1194       g_value_set_uint64 (value, videorate->dup);
1195       break;
1196     case PROP_DROP:
1197       g_value_set_uint64 (value, videorate->drop);
1198       break;
1199     case PROP_SILENT:
1200       g_value_set_boolean (value, videorate->silent);
1201       break;
1202     case PROP_NEW_PREF:
1203       g_value_set_double (value, videorate->new_pref);
1204       break;
1205     case PROP_SKIP_TO_FIRST:
1206       g_value_set_boolean (value, videorate->skip_to_first);
1207       break;
1208     case PROP_DROP_ONLY:
1209       g_value_set_boolean (value, videorate->drop_only);
1210       break;
1211     case PROP_AVERAGE_PERIOD:
1212       g_value_set_uint64 (value, videorate->average_period_set);
1213       break;
1214     case PROP_MAX_RATE:
1215       g_value_set_int (value, g_atomic_int_get (&videorate->max_rate));
1216       break;
1217     default:
1218       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1219       break;
1220   }
1221   GST_OBJECT_UNLOCK (videorate);
1222 }
1223
1224 static gboolean
1225 plugin_init (GstPlugin * plugin)
1226 {
1227   GST_DEBUG_CATEGORY_INIT (video_rate_debug, "videorate", 0,
1228       "VideoRate stream fixer");
1229
1230   return gst_element_register (plugin, "videorate", GST_RANK_NONE,
1231       GST_TYPE_VIDEO_RATE);
1232 }
1233
1234 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1235     GST_VERSION_MINOR,
1236     "videorate",
1237     "Adjusts video frames",
1238     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)