3 * Copyright (C) 2005 Martin Eikermann <meiker@upb.de>
4 * Copyright (C) 2008-2010 Sebastian Dröge <slomo@collabora.co.uk>
5 * Copyright (C) 2011 Robert Swain <robert.swain@collabora.co.uk>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * SECTION:element-deinterlace
26 * deinterlace deinterlaces interlaced video frames to progressive video frames.
27 * For this different algorithms can be selected which will be described later.
30 * <title>Example launch line</title>
32 * gst-launch -v filesrc location=/path/to/file ! decodebin2 ! ffmpegcolorspace ! deinterlace ! ffmpegcolorspace ! autovideosink
33 * ]| This pipeline deinterlaces a video file with the default deinterlacing options.
37 /* FIXME PORTING 0.11:
38 * - getcaps/setcaps stuff needs revisiting
39 * - reconfiguration needs to be done differently
40 * - bufferalloc -> buffer pool/alloc query
47 #include "gstdeinterlace.h"
48 #include "tvtime/plugins.h"
56 GST_DEBUG_CATEGORY_STATIC (deinterlace_debug);
57 #define GST_CAT_DEFAULT (deinterlace_debug)
61 #define DEFAULT_MODE GST_DEINTERLACE_MODE_AUTO
62 #define DEFAULT_METHOD GST_DEINTERLACE_LINEAR
63 #define DEFAULT_FIELDS GST_DEINTERLACE_ALL
64 #define DEFAULT_FIELD_LAYOUT GST_DEINTERLACE_LAYOUT_AUTO
65 #define DEFAULT_LOCKING GST_DEINTERLACE_LOCKING_NONE
66 #define DEFAULT_IGNORE_OBSCURE TRUE
67 #define DEFAULT_DROP_ORPHANS TRUE
82 #define GST_DEINTERLACE_BUFFER_STATE_P (1<<0)
83 #define GST_DEINTERLACE_BUFFER_STATE_I (1<<1)
84 #define GST_DEINTERLACE_BUFFER_STATE_TC_B (1<<2)
85 #define GST_DEINTERLACE_BUFFER_STATE_TC_T (1<<3)
86 #define GST_DEINTERLACE_BUFFER_STATE_TC_P (1<<4)
87 #define GST_DEINTERLACE_BUFFER_STATE_TC_M (1<<5)
88 #define GST_DEINTERLACE_BUFFER_STATE_RFF (1<<6)
91 (GST_DEINTERLACE_BUFFER_STATE_TC_T | GST_DEINTERLACE_BUFFER_STATE_TC_B)
93 (GST_DEINTERLACE_BUFFER_STATE_P | GST_DEINTERLACE_BUFFER_STATE_TC_P)
95 (GST_DEINTERLACE_BUFFER_STATE_I | GST_DEINTERLACE_BUFFER_STATE_TC_M)
96 #define GST_RFF (GST_DEINTERLACE_BUFFER_STATE_RFF)
98 #define GST_DEINTERLACE_OBSCURE_THRESHOLD 5
100 static const TelecinePattern telecine_patterns[] = {
101 /* 60i -> 60p or 50i -> 50p (NOTE THE WEIRD RATIOS) */
102 {"1:1", 1, 2, 1, {GST_ONE,}},
103 /* 60i -> 30p or 50i -> 25p */
104 {"2:2", 1, 1, 1, {GST_INT,}},
105 /* 60i telecine -> 24p */
106 {"2:3-RFF", 4, 4, 5, {GST_PRG, GST_RFF, GST_PRG, GST_RFF,}},
107 {"2:3", 5, 4, 5, {GST_PRG, GST_PRG, GST_ONE, GST_ONE, GST_PRG,}},
108 {"3:2:2:3-RFF", 4, 4, 5, {GST_RFF, GST_PRG, GST_PRG, GST_RFF,}},
109 {"3:2:2:3", 5, 4, 5, {GST_PRG, GST_ONE, GST_INT, GST_ONE, GST_PRG,}},
110 /* fieldanalysis should indicate this using RFF on the second and fourth
111 * buffers and not send the third buffer at all. it will be identified as
113 /* {"2:3:3:2", 5, 4, 5, {GST_PRG, GST_PRG, GST_DRP, GST_PRG, GST_PRG,}}, */
115 /* The following patterns are obscure and are ignored if ignore-obscure is
116 * set to true. If any patterns are added above this line, check and edit
117 * GST_DEINTERLACE_OBSCURE_THRESHOLD */
119 /* 50i Euro pulldown -> 24p */
120 {"2-11:3", 25, 24, 25, {GST_PRG, GST_PRG, GST_PRG, GST_PRG, GST_PRG,
121 GST_PRG, GST_PRG, GST_PRG, GST_PRG, GST_PRG,
122 GST_PRG, GST_PRG, GST_ONE, GST_INT, GST_INT,
123 GST_INT, GST_INT, GST_INT, GST_INT, GST_INT,
124 GST_INT, GST_INT, GST_INT, GST_ONE, GST_PRG,}},
126 /* haven't figured out how fieldanalysis should handle these yet */
127 /* 60i (NTSC 30000/1001) -> 16p (16000/1001) */
128 {"3:4-3", 15, 8, 15, {GST_PRG, GST_DRP, GST_PRG, GST_DRP, GST_PRG,
129 GST_DRP, GST_PRG, GST_DRP, GST_PRG, GST_DRP,
130 GST_PRG, GST_DRP, GST_PRG, GST_DRP, GST_PRG,}},
131 /* 50i (PAL) -> 16p */
132 {"3-7:4", 25, 16, 25, {GST_PRG, GST_DRP, GST_PRG, GST_PRG, GST_DRP,
133 GST_PRG, GST_PRG, GST_DRP, GST_PRG, GST_PRG,
134 GST_DRP, GST_PRG, GST_DRP, GST_PRG, GST_PRG,
135 GST_DRP, GST_PRG, GST_PRG, GST_DRP, GST_PRG,
136 GST_PRG, GST_DRP, GST_PRG, GST_PRG, GST_DRP,}},
137 /* NTSC 60i -> 18p */
138 {"3:3:4", 5, 3, 5, {GST_PRG, GST_DRP, GST_PRG, GST_DRP, GST_PRG,}},
139 /* NTSC 60i -> 20p */
140 {"3:3", 3, 2, 3, {GST_PRG, GST_DRP, GST_PRG,}},
142 /* NTSC 60i -> 27.5 */
143 {"3:2-4", 11, 10, 11, {GST_PRG, GST_PRG, GST_PRG, GST_PRG, GST_PRG,
144 GST_PRG, GST_ONE, GST_INT, GST_INT, GST_INT,
146 /* PAL 50i -> 27.5 */
147 {"1:2-4", 9, 9, 10, {GST_PRG, GST_PRG, GST_PRG, GST_PRG, GST_INT,
148 GST_INT, GST_INT, GST_INT, GST_INT,}},
151 static const GEnumValue methods_types[] = {
152 {GST_DEINTERLACE_TOMSMOCOMP, "Motion Adaptive: Motion Search",
154 {GST_DEINTERLACE_GREEDY_H, "Motion Adaptive: Advanced Detection",
156 {GST_DEINTERLACE_GREEDY_L, "Motion Adaptive: Simple Detection", "greedyl"},
157 {GST_DEINTERLACE_VFIR, "Blur Vertical", "vfir"},
158 {GST_DEINTERLACE_LINEAR, "Television: Full resolution", "linear"},
159 {GST_DEINTERLACE_LINEAR_BLEND, "Blur: Temporal (Do Not Use)",
161 {GST_DEINTERLACE_SCALER_BOB, "Double lines", "scalerbob"},
162 {GST_DEINTERLACE_WEAVE, "Weave (Do Not Use)", "weave"},
163 {GST_DEINTERLACE_WEAVE_TFF, "Progressive: Top Field First (Do Not Use)",
165 {GST_DEINTERLACE_WEAVE_BFF, "Progressive: Bottom Field First (Do Not Use)",
170 static const GEnumValue locking_types[] = {
171 {GST_DEINTERLACE_LOCKING_NONE,
172 "No pattern locking", "none"},
173 {GST_DEINTERLACE_LOCKING_AUTO,
174 "Choose passive/active locking depending on whether upstream is live",
176 {GST_DEINTERLACE_LOCKING_ACTIVE,
177 "Block until pattern-locked. Use accurate timestamp interpolation within a pattern repeat.",
179 {GST_DEINTERLACE_LOCKING_PASSIVE,
180 "Do not block. Use naïve timestamp adjustment until pattern-locked based on state history.",
186 #define GST_TYPE_DEINTERLACE_METHODS (gst_deinterlace_methods_get_type ())
188 gst_deinterlace_methods_get_type (void)
190 static GType deinterlace_methods_type = 0;
192 if (!deinterlace_methods_type) {
193 deinterlace_methods_type =
194 g_enum_register_static ("GstDeinterlaceMethods", methods_types);
196 return deinterlace_methods_type;
199 #define GST_TYPE_DEINTERLACE_FIELDS (gst_deinterlace_fields_get_type ())
201 gst_deinterlace_fields_get_type (void)
203 static GType deinterlace_fields_type = 0;
205 static const GEnumValue fields_types[] = {
206 {GST_DEINTERLACE_ALL, "All fields", "all"},
207 {GST_DEINTERLACE_TF, "Top fields only", "top"},
208 {GST_DEINTERLACE_BF, "Bottom fields only", "bottom"},
212 if (!deinterlace_fields_type) {
213 deinterlace_fields_type =
214 g_enum_register_static ("GstDeinterlaceFields", fields_types);
216 return deinterlace_fields_type;
219 #define GST_TYPE_DEINTERLACE_FIELD_LAYOUT (gst_deinterlace_field_layout_get_type ())
221 gst_deinterlace_field_layout_get_type (void)
223 static GType deinterlace_field_layout_type = 0;
225 static const GEnumValue field_layout_types[] = {
226 {GST_DEINTERLACE_LAYOUT_AUTO, "Auto detection", "auto"},
227 {GST_DEINTERLACE_LAYOUT_TFF, "Top field first", "tff"},
228 {GST_DEINTERLACE_LAYOUT_BFF, "Bottom field first", "bff"},
232 if (!deinterlace_field_layout_type) {
233 deinterlace_field_layout_type =
234 g_enum_register_static ("GstDeinterlaceFieldLayout",
237 return deinterlace_field_layout_type;
240 #define GST_TYPE_DEINTERLACE_MODES (gst_deinterlace_modes_get_type ())
242 gst_deinterlace_modes_get_type (void)
244 static GType deinterlace_modes_type = 0;
246 static const GEnumValue modes_types[] = {
247 {GST_DEINTERLACE_MODE_AUTO, "Auto detection", "auto"},
248 {GST_DEINTERLACE_MODE_INTERLACED, "Force deinterlacing", "interlaced"},
249 {GST_DEINTERLACE_MODE_DISABLED, "Run in passthrough mode", "disabled"},
253 if (!deinterlace_modes_type) {
254 deinterlace_modes_type =
255 g_enum_register_static ("GstDeinterlaceModes", modes_types);
257 return deinterlace_modes_type;
260 #define GST_TYPE_DEINTERLACE_LOCKING (gst_deinterlace_locking_get_type ())
262 gst_deinterlace_locking_get_type (void)
264 static GType deinterlace_locking_type = 0;
266 if (!deinterlace_locking_type) {
267 deinterlace_locking_type =
268 g_enum_register_static ("GstDeinterlaceLocking", locking_types);
271 return deinterlace_locking_type;
274 #define DEINTERLACE_VIDEO_FORMATS \
275 "{ AYUV, ARGB, ABGR, RGBA, BGRA, Y444, xRGB, xBGR, RGBx, BGRx, RGB, " \
276 "BGR, YUY2, YVYU, UYVY, Y42B, I420, YV12, Y41B, NV12, NV21 }"
278 #define DEINTERLACE_CAPS GST_VIDEO_CAPS_MAKE(DEINTERLACE_VIDEO_FORMATS)
280 static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
283 GST_STATIC_CAPS (DEINTERLACE_CAPS)
286 static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink",
289 GST_STATIC_CAPS (DEINTERLACE_CAPS)
292 static void gst_deinterlace_finalize (GObject * self);
293 static void gst_deinterlace_set_property (GObject * self, guint prop_id,
294 const GValue * value, GParamSpec * pspec);
295 static void gst_deinterlace_get_property (GObject * self, guint prop_id,
296 GValue * value, GParamSpec * pspec);
298 static GstCaps *gst_deinterlace_getcaps (GstDeinterlace * self, GstPad * pad,
300 static gboolean gst_deinterlace_setcaps (GstDeinterlace * self, GstPad * pad,
302 static gboolean gst_deinterlace_sink_event (GstPad * pad, GstObject * parent,
304 static gboolean gst_deinterlace_sink_query (GstPad * pad, GstObject * parent,
306 static GstFlowReturn gst_deinterlace_chain (GstPad * pad, GstObject * parent,
308 static GstStateChangeReturn gst_deinterlace_change_state (GstElement * element,
309 GstStateChange transition);
311 static gboolean gst_deinterlace_src_event (GstPad * pad, GstObject * parent,
313 static gboolean gst_deinterlace_src_query (GstPad * pad, GstObject * parent,
316 static GstFlowReturn gst_deinterlace_output_frame (GstDeinterlace * self,
318 static void gst_deinterlace_reset (GstDeinterlace * self);
319 static void gst_deinterlace_update_qos (GstDeinterlace * self,
320 gdouble proportion, GstClockTimeDiff diff, GstClockTime time);
321 static void gst_deinterlace_reset_qos (GstDeinterlace * self);
322 static void gst_deinterlace_read_qos (GstDeinterlace * self,
323 gdouble * proportion, GstClockTime * time);
325 #define IS_TELECINE(m) ((m) == GST_VIDEO_INTERLACE_MODE_MIXED && self->pattern > 1)
327 /* FIXME: what's the point of the childproxy interface here? What can you
328 * actually do with it? The method objects seem to have no properties */
330 static void gst_deinterlace_child_proxy_interface_init (gpointer g_iface,
331 gpointer iface_data);
334 _do_init (GType object_type)
336 const GInterfaceInfo child_proxy_interface_info = {
337 (GInterfaceInitFunc) gst_deinterlace_child_proxy_interface_init,
338 NULL, /* interface_finalize */
339 NULL /* interface_data */
342 g_type_add_interface_static (object_type, GST_TYPE_CHILD_PROXY,
343 &child_proxy_interface_info);
347 G_DEFINE_TYPE (GstDeinterlace, gst_deinterlace, GST_TYPE_ELEMENT);
349 #define parent_class gst_deinterlace_parent_class
353 GType (*get_type) (void);
354 } _method_types[] = {
356 gst_deinterlace_method_tomsmocomp_get_type}, {
357 gst_deinterlace_method_greedy_h_get_type}, {
358 gst_deinterlace_method_greedy_l_get_type}, {
359 gst_deinterlace_method_vfir_get_type}, {
360 gst_deinterlace_method_linear_get_type}, {
361 gst_deinterlace_method_linear_blend_get_type}, {
362 gst_deinterlace_method_scaler_bob_get_type}, {
363 gst_deinterlace_method_weave_get_type}, {
364 gst_deinterlace_method_weave_tff_get_type}, {
365 gst_deinterlace_method_weave_bff_get_type}
369 gst_deinterlace_set_method (GstDeinterlace * self, GstDeinterlaceMethods method)
373 GstVideoFormat format;
375 GST_DEBUG_OBJECT (self, "Setting new method %d", method);
377 width = GST_VIDEO_INFO_WIDTH (&self->vinfo);
378 height = GST_VIDEO_INFO_HEIGHT (&self->vinfo);
379 format = GST_VIDEO_INFO_FORMAT (&self->vinfo);
382 if (self->method_id == method &&
383 gst_deinterlace_method_supported (G_TYPE_FROM_INSTANCE (self->method),
384 format, width, height)) {
385 GST_DEBUG_OBJECT (self, "Reusing current method");
389 gst_child_proxy_child_removed (GST_OBJECT (self),
390 GST_OBJECT (self->method));
391 gst_object_unparent (GST_OBJECT (self->method));
397 _method_types[method].get_type !=
398 NULL ? _method_types[method].get_type () : G_TYPE_INVALID;
399 if (method_type == G_TYPE_INVALID
400 || !gst_deinterlace_method_supported (method_type, format,
405 method_type = G_TYPE_INVALID;
407 GST_WARNING_OBJECT (self, "Method doesn't support requested format");
408 for (i = 0; i < G_N_ELEMENTS (_method_types); i++) {
409 if (_method_types[i].get_type == NULL)
411 tmp = _method_types[i].get_type ();
412 if (gst_deinterlace_method_supported (tmp, format, width, height)) {
413 GST_DEBUG_OBJECT (self, "Using method %d", i);
419 /* If we get here we must have invalid caps! */
420 g_assert (method_type != G_TYPE_INVALID);
423 self->method = g_object_new (method_type, "name", "method", NULL);
424 self->method_id = method;
426 gst_object_set_parent (GST_OBJECT (self->method), GST_OBJECT (self));
428 gst_child_proxy_child_added (GST_OBJECT (self), GST_OBJECT (self->method));
432 gst_deinterlace_method_setup (self->method, &self->vinfo);
436 gst_deinterlace_clip_buffer (GstDeinterlace * self, GstBuffer * buffer)
439 GstClockTime start, stop;
440 guint64 cstart, cstop;
442 GST_DEBUG_OBJECT (self,
443 "Clipping buffer to the current segment: %" GST_TIME_FORMAT " -- %"
444 GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
445 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
446 GST_DEBUG_OBJECT (self, "Current segment: %" GST_SEGMENT_FORMAT,
449 if (G_UNLIKELY (self->segment.format != GST_FORMAT_TIME))
451 if (G_UNLIKELY (!GST_BUFFER_TIMESTAMP_IS_VALID (buffer)))
454 start = GST_BUFFER_TIMESTAMP (buffer);
455 stop = start + GST_BUFFER_DURATION (buffer);
457 if (!(ret = gst_segment_clip (&self->segment, GST_FORMAT_TIME,
458 start, stop, &cstart, &cstop)))
461 GST_BUFFER_TIMESTAMP (buffer) = cstart;
462 if (GST_CLOCK_TIME_IS_VALID (cstop))
463 GST_BUFFER_DURATION (buffer) = cstop - cstart;
467 GST_DEBUG_OBJECT (self,
468 "Clipped buffer to the current segment: %" GST_TIME_FORMAT " -- %"
469 GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
470 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
472 GST_DEBUG_OBJECT (self, "Buffer outside the current segment -- dropping");
478 gst_deinterlace_class_init (GstDeinterlaceClass * klass)
480 GObjectClass *gobject_class = (GObjectClass *) klass;
482 GstElementClass *element_class = (GstElementClass *) klass;
484 gst_element_class_add_pad_template (element_class,
485 gst_static_pad_template_get (&src_templ));
486 gst_element_class_add_pad_template (element_class,
487 gst_static_pad_template_get (&sink_templ));
489 gst_element_class_set_static_metadata (element_class,
491 "Filter/Effect/Video/Deinterlace",
492 "Deinterlace Methods ported from DScaler/TvTime",
493 "Martin Eikermann <meiker@upb.de>, "
494 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
496 gobject_class->set_property = gst_deinterlace_set_property;
497 gobject_class->get_property = gst_deinterlace_get_property;
498 gobject_class->finalize = gst_deinterlace_finalize;
501 * GstDeinterlace:mode
503 * This selects whether the deinterlacing methods should
504 * always be applied or if they should only be applied
505 * on content that has the "interlaced" flag on the caps.
508 g_object_class_install_property (gobject_class, PROP_MODE,
509 g_param_spec_enum ("mode",
512 GST_TYPE_DEINTERLACE_MODES,
513 DEFAULT_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
517 * GstDeinterlace:method
519 * Selects the different deinterlacing algorithms that can be used.
520 * These provide different quality and CPU usage.
522 * Some methods provide parameters which can be set by getting
523 * the "method" child via the #GstChildProxy interface and
524 * setting the appropiate properties on it.
530 * Motion Adaptive: Motion Search
536 * Motion Adaptive: Advanced Detection
542 * Motion Adaptive: Simple Detection
554 * Linear interpolation
560 * Linear interpolation in time domain. Any motion causes significant
561 * ghosting, so this method should not be used.
573 * Weave. Bad quality, do not use.
579 * Progressive: Top Field First. Bad quality, do not use.
585 * Progressive: Bottom Field First. Bad quality, do not use.
590 g_object_class_install_property (gobject_class, PROP_METHOD,
591 g_param_spec_enum ("method",
593 "Deinterlace Method",
594 GST_TYPE_DEINTERLACE_METHODS,
595 DEFAULT_METHOD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
599 * GstDeinterlace:fields
601 * This selects which fields should be output. If "all" is selected
602 * the output framerate will be double.
605 g_object_class_install_property (gobject_class, PROP_FIELDS,
606 g_param_spec_enum ("fields",
608 "Fields to use for deinterlacing",
609 GST_TYPE_DEINTERLACE_FIELDS,
610 DEFAULT_FIELDS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
614 * GstDeinterlace:layout
616 * This selects which fields is the first in time.
619 g_object_class_install_property (gobject_class, PROP_FIELD_LAYOUT,
620 g_param_spec_enum ("tff",
622 "Deinterlace top field first",
623 GST_TYPE_DEINTERLACE_FIELD_LAYOUT,
624 DEFAULT_FIELD_LAYOUT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
628 * GstDeinterlace:locking
630 * This selects which approach to pattern locking is used which affects
631 * processing latency and accuracy of timestamp adjustment for telecine
637 g_object_class_install_property (gobject_class, PROP_LOCKING,
638 g_param_spec_enum ("locking", "locking", "Pattern locking mode",
639 GST_TYPE_DEINTERLACE_LOCKING, DEFAULT_LOCKING,
640 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
643 * GstDeinterlace:ignore-obscure
645 * This selects whether to ignore obscure/rare telecine patterns.
646 * NTSC 2:3 pulldown variants are the only really common patterns.
651 g_object_class_install_property (gobject_class, PROP_IGNORE_OBSCURE,
652 g_param_spec_boolean ("ignore-obscure", "ignore-obscure",
653 "Ignore obscure telecine patterns (only consider P, I and 2:3 "
654 "variants).", DEFAULT_IGNORE_OBSCURE,
655 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
658 * GstDeinterlace:drop-orphans
660 * This selects whether to drop orphan fields at the beginning of telecine
661 * patterns in active locking mode.
666 g_object_class_install_property (gobject_class, PROP_DROP_ORPHANS,
667 g_param_spec_boolean ("drop-orphans", "drop-orphans",
668 "Drop orphan fields at the beginning of telecine patterns in "
669 "active locking mode.", DEFAULT_DROP_ORPHANS,
670 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
672 element_class->change_state =
673 GST_DEBUG_FUNCPTR (gst_deinterlace_change_state);
678 gst_deinterlace_child_proxy_get_child_by_index (GstChildProxy * child_proxy,
681 GstDeinterlace *self = GST_DEINTERLACE (child_proxy);
683 g_return_val_if_fail (index == 0, NULL);
685 return gst_object_ref (self->method);
689 gst_deinterlace_child_proxy_get_children_count (GstChildProxy * child_proxy)
691 GstDeinterlace *self = GST_DEINTERLACE (child_proxy);
693 return ((self->method) ? 1 : 0);
697 gst_deinterlace_child_proxy_interface_init (gpointer g_iface,
700 GstChildProxyInterface *iface = g_iface;
702 iface->get_child_by_index = gst_deinterlace_child_proxy_get_child_by_index;
703 iface->get_children_count = gst_deinterlace_child_proxy_get_children_count;
708 gst_deinterlace_init (GstDeinterlace * self)
710 self->sinkpad = gst_pad_new_from_static_template (&sink_templ, "sink");
711 gst_pad_set_chain_function (self->sinkpad,
712 GST_DEBUG_FUNCPTR (gst_deinterlace_chain));
713 gst_pad_set_event_function (self->sinkpad,
714 GST_DEBUG_FUNCPTR (gst_deinterlace_sink_event));
715 gst_pad_set_query_function (self->sinkpad,
716 GST_DEBUG_FUNCPTR (gst_deinterlace_sink_query));
717 gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
719 self->srcpad = gst_pad_new_from_static_template (&src_templ, "src");
720 gst_pad_set_event_function (self->srcpad,
721 GST_DEBUG_FUNCPTR (gst_deinterlace_src_event));
722 gst_pad_set_query_function (self->srcpad,
723 GST_DEBUG_FUNCPTR (gst_deinterlace_src_query));
724 gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
726 self->mode = DEFAULT_MODE;
727 self->user_set_method_id = DEFAULT_METHOD;
728 gst_video_info_init (&self->vinfo);
729 gst_deinterlace_set_method (self, self->user_set_method_id);
730 self->fields = DEFAULT_FIELDS;
731 self->field_layout = DEFAULT_FIELD_LAYOUT;
732 self->locking = DEFAULT_LOCKING;
733 self->ignore_obscure = DEFAULT_IGNORE_OBSCURE;
734 self->drop_orphans = DEFAULT_DROP_ORPHANS;
736 self->low_latency = -1;
738 self->pattern_phase = -1;
739 self->pattern_count = 0;
740 self->output_count = 0;
741 self->pattern_base_ts = GST_CLOCK_TIME_NONE;
742 self->pattern_buf_dur = GST_CLOCK_TIME_NONE;
743 self->still_frame_mode = FALSE;
745 gst_deinterlace_reset (self);
748 static GstVideoFrame *
749 gst_video_frame_new_and_map (GstVideoInfo * vinfo, GstBuffer * buffer,
752 GstVideoFrame *frame = g_malloc0 (sizeof (GstVideoFrame));
753 gst_video_frame_map (frame, vinfo, buffer, flags);
758 gst_video_frame_unmap_and_free (GstVideoFrame * frame)
760 gst_video_frame_unmap (frame);
765 gst_deinterlace_reset_history (GstDeinterlace * self, gboolean drop_all)
770 GST_DEBUG_OBJECT (self, "Flushing history (count %d)", self->history_count);
771 while (self->history_count > 0) {
772 if (gst_deinterlace_output_frame (self, TRUE) != GST_FLOW_OK) {
773 /* Encountered error, or flushing -> skip and drop all remaining */
780 GST_DEBUG_OBJECT (self, "Resetting history (count %d)",
781 self->history_count);
783 for (i = 0; i < self->history_count; i++) {
784 if (self->field_history[i].frame) {
785 gst_video_frame_unmap_and_free (self->field_history[i].frame);
786 self->field_history[i].frame = NULL;
790 memset (self->field_history, 0,
791 GST_DEINTERLACE_MAX_FIELD_HISTORY * sizeof (GstDeinterlaceField));
792 self->history_count = 0;
793 memset (self->buf_states, 0,
794 GST_DEINTERLACE_MAX_BUFFER_STATE_HISTORY *
795 sizeof (GstDeinterlaceBufferState));
796 self->state_count = 0;
797 self->pattern_lock = FALSE;
798 self->pattern_refresh = TRUE;
799 self->cur_field_idx = -1;
801 if (!self->still_frame_mode && self->last_buffer) {
802 gst_buffer_unref (self->last_buffer);
803 self->last_buffer = NULL;
808 gst_deinterlace_update_passthrough (GstDeinterlace * self)
810 if (self->mode == GST_DEINTERLACE_MODE_DISABLED)
811 self->passthrough = TRUE;
812 else if (!GST_VIDEO_INFO_IS_INTERLACED (&self->vinfo)
813 && self->mode != GST_DEINTERLACE_MODE_INTERLACED)
814 self->passthrough = TRUE;
816 self->passthrough = FALSE;
818 GST_DEBUG_OBJECT (self, "Passthrough: %d", self->passthrough);
822 gst_deinterlace_reset (GstDeinterlace * self)
824 GST_DEBUG_OBJECT (self, "Resetting internal state");
826 gst_video_info_init (&self->vinfo);
828 self->passthrough = FALSE;
830 self->reconfigure = FALSE;
831 if (self->new_mode != -1)
832 self->mode = self->new_mode;
833 if (self->new_fields != -1)
834 self->fields = self->new_fields;
836 self->new_fields = -1;
838 gst_segment_init (&self->segment, GST_FORMAT_UNDEFINED);
840 if (self->request_caps)
841 gst_caps_unref (self->request_caps);
842 self->request_caps = NULL;
844 gst_deinterlace_reset_history (self, TRUE);
846 gst_deinterlace_reset_qos (self);
848 self->need_more = FALSE;
849 self->have_eos = FALSE;
853 gst_deinterlace_set_property (GObject * object, guint prop_id,
854 const GValue * value, GParamSpec * pspec)
856 GstDeinterlace *self;
858 self = GST_DEINTERLACE (object);
864 GST_OBJECT_LOCK (self);
865 new_mode = g_value_get_enum (value);
866 /* FIXME: reconfiguration should probably be done differently */
867 if (self->mode != new_mode && gst_pad_has_current_caps (self->srcpad)) {
868 self->reconfigure = TRUE;
869 self->new_mode = new_mode;
871 self->mode = new_mode;
872 gst_deinterlace_update_passthrough (self);
874 GST_OBJECT_UNLOCK (self);
878 self->user_set_method_id = g_value_get_enum (value);
879 gst_deinterlace_set_method (self, self->user_set_method_id);
884 GST_OBJECT_LOCK (self);
885 new_fields = g_value_get_enum (value);
886 /* FIXME: reconfiguration should probably be done differently */
887 if (self->fields != new_fields && gst_pad_has_current_caps (self->srcpad)) {
888 self->reconfigure = TRUE;
889 self->new_fields = new_fields;
891 self->fields = new_fields;
893 GST_OBJECT_UNLOCK (self);
896 case PROP_FIELD_LAYOUT:
897 self->field_layout = g_value_get_enum (value);
900 self->locking = g_value_get_enum (value);
902 case PROP_IGNORE_OBSCURE:
903 self->ignore_obscure = g_value_get_boolean (value);
905 case PROP_DROP_ORPHANS:
906 self->drop_orphans = g_value_get_boolean (value);
909 G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
915 gst_deinterlace_get_property (GObject * object, guint prop_id,
916 GValue * value, GParamSpec * pspec)
918 GstDeinterlace *self;
920 self = GST_DEINTERLACE (object);
924 g_value_set_enum (value, self->mode);
927 g_value_set_enum (value, self->user_set_method_id);
930 g_value_set_enum (value, self->fields);
932 case PROP_FIELD_LAYOUT:
933 g_value_set_enum (value, self->field_layout);
936 g_value_set_enum (value, self->locking);
938 case PROP_IGNORE_OBSCURE:
939 g_value_set_boolean (value, self->ignore_obscure);
941 case PROP_DROP_ORPHANS:
942 g_value_set_boolean (value, self->drop_orphans);
945 G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
950 gst_deinterlace_finalize (GObject * object)
952 GstDeinterlace *self = GST_DEINTERLACE (object);
954 gst_deinterlace_reset (self);
957 gst_object_unparent (GST_OBJECT (self->method));
961 G_OBJECT_CLASS (parent_class)->finalize (object);
965 gst_deinterlace_update_pattern_timestamps (GstDeinterlace * self)
968 if (self->low_latency) {
969 /* in low-latency mode the buffer state history contains old buffer
970 * states as well as the current one and perhaps some future ones.
971 * the current buffer's state is given by the number of field pairs
972 * rounded up, minus 1. the below is equivalent */
973 state_idx = (self->history_count - 1) >> 1;
975 /* in high-latency mode state_count - 1 is the current buffer's state */
976 state_idx = self->state_count - 1;
979 self->pattern_base_ts = self->buf_states[state_idx].timestamp;
980 if (self->buf_states[state_idx].state != GST_RFF) {
981 self->pattern_buf_dur =
982 (self->buf_states[state_idx].duration *
983 telecine_patterns[self->pattern].ratio_d) /
984 telecine_patterns[self->pattern].ratio_n;
986 self->pattern_buf_dur =
987 (self->buf_states[state_idx].duration *
988 telecine_patterns[self->pattern].ratio_d * 2) /
989 (telecine_patterns[self->pattern].ratio_n * 3);
991 GST_DEBUG_OBJECT (self,
992 "Starting a new pattern repeat with base ts %" GST_TIME_FORMAT
993 " and dur %" GST_TIME_FORMAT, GST_TIME_ARGS (self->pattern_base_ts),
994 GST_TIME_ARGS (self->pattern_buf_dur));
997 static GstVideoFrame *
998 gst_deinterlace_pop_history (GstDeinterlace * self)
1000 GstVideoFrame *frame;
1002 g_return_val_if_fail (self->history_count > 0, NULL);
1004 GST_DEBUG_OBJECT (self, "Pop last history frame -- current history size %d",
1005 self->history_count);
1007 frame = self->field_history[self->history_count - 1].frame;
1009 self->history_count--;
1010 if (self->locking != GST_DEINTERLACE_LOCKING_NONE && (!self->history_count
1011 || GST_VIDEO_FRAME_PLANE_DATA (frame, 0) !=
1012 GST_VIDEO_FRAME_PLANE_DATA (self->field_history[self->history_count -
1014 if (!self->low_latency)
1015 self->state_count--;
1016 if (self->pattern_lock) {
1017 self->pattern_count++;
1018 if (self->pattern != -1
1019 && self->pattern_count >= telecine_patterns[self->pattern].length) {
1020 self->pattern_count = 0;
1021 self->output_count = 0;
1026 GST_DEBUG_OBJECT (self, "Returning frame: %p %" GST_TIME_FORMAT
1027 " with duration %" GST_TIME_FORMAT " and size %u", frame,
1028 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (frame->buffer)),
1029 GST_TIME_ARGS (GST_BUFFER_DURATION (frame->buffer)),
1030 GST_VIDEO_FRAME_SIZE (frame));
1036 gst_deinterlace_get_buffer_state (GstDeinterlace * self, GstVideoFrame * frame,
1037 guint8 * state, GstVideoInterlaceMode * i_mode)
1039 GstVideoInterlaceMode interlacing_mode;
1041 if (!(i_mode || state))
1044 interlacing_mode = GST_VIDEO_INFO_INTERLACE_MODE (&frame->info);
1047 if (interlacing_mode == GST_VIDEO_INTERLACE_MODE_MIXED) {
1048 if (GST_VIDEO_FRAME_IS_RFF (frame)) {
1049 *state = GST_DEINTERLACE_BUFFER_STATE_RFF;
1050 } else if (GST_VIDEO_FRAME_IS_ONEFIELD (frame)) {
1051 /* tc top if tff, tc bottom otherwise */
1052 if (GST_VIDEO_FRAME_IS_TFF (frame)) {
1053 *state = GST_DEINTERLACE_BUFFER_STATE_TC_T;
1055 *state = GST_DEINTERLACE_BUFFER_STATE_TC_B;
1057 } else if (GST_VIDEO_FRAME_IS_INTERLACED (frame)) {
1058 *state = GST_DEINTERLACE_BUFFER_STATE_TC_M;
1060 *state = GST_DEINTERLACE_BUFFER_STATE_TC_P;
1063 if (interlacing_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED) {
1064 *state = GST_DEINTERLACE_BUFFER_STATE_I;
1066 *state = GST_DEINTERLACE_BUFFER_STATE_P;
1072 *i_mode = interlacing_mode;
1075 #define STATE_TO_STRING(s) ((s) == GST_DEINTERLACE_BUFFER_STATE_P ? "P" : \
1076 (s) == GST_DEINTERLACE_BUFFER_STATE_I ? "I" : \
1077 (s) == GST_DEINTERLACE_BUFFER_STATE_TC_B ? "B" : \
1078 (s) == GST_DEINTERLACE_BUFFER_STATE_TC_T ? "T" : \
1079 (s) == GST_DEINTERLACE_BUFFER_STATE_TC_P ? "TCP" : \
1080 (s) == GST_DEINTERLACE_BUFFER_STATE_TC_M ? "TCM" : "RFF")
1082 #define MODE_TO_STRING(m) ((m) == GST_VIDEO_INTERLACE_MODE_MIXED ? "MIXED" : \
1083 (m) == GST_VIDEO_INTERLACE_MODE_INTERLEAVED ? "I" : \
1084 (m) == GST_VIDEO_INTERLACE_MODE_FIELDS ? "FIELDS" : "P")
1087 gst_deinterlace_push_history (GstDeinterlace * self, GstBuffer * buffer)
1090 GstDeinterlaceFieldLayout field_layout = self->field_layout;
1093 GstVideoFrame *frame = NULL;
1094 GstVideoFrame *field1, *field2 = NULL;
1095 guint fields_to_push;
1096 gint field1_flags, field2_flags;
1097 GstVideoInterlaceMode interlacing_mode;
1100 /* we will only read from this buffer and write into fresh output buffers
1101 * if this is not the case, change the map flags as appropriate
1103 frame = gst_video_frame_new_and_map (&self->vinfo, buffer, GST_MAP_READ);
1104 /* we can manage the buffer ref count using the maps from here on */
1105 gst_buffer_unref (buffer);
1107 tff = GST_VIDEO_FRAME_IS_TFF (frame);
1108 onefield = GST_VIDEO_FRAME_IS_ONEFIELD (frame);
1109 fields_to_push = (onefield) ? 1 : 2;
1111 g_return_if_fail (self->history_count <
1112 GST_DEINTERLACE_MAX_FIELD_HISTORY - fields_to_push);
1114 gst_deinterlace_get_buffer_state (self, frame, &buf_state, &interlacing_mode);
1116 GST_DEBUG_OBJECT (self,
1117 "Pushing new frame as %d fields to the history (count before %d): ptr %p at %"
1118 GST_TIME_FORMAT " with duration %" GST_TIME_FORMAT
1119 ", size %u, state %s, interlacing mode %s", fields_to_push,
1120 self->history_count, frame, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
1121 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
1122 gst_buffer_get_size (buffer),
1123 STATE_TO_STRING (buf_state), MODE_TO_STRING (interlacing_mode));
1125 /* move up for new state */
1126 memmove (&self->buf_states[1], &self->buf_states[0],
1127 (GST_DEINTERLACE_MAX_BUFFER_STATE_HISTORY - 1) *
1128 sizeof (GstDeinterlaceBufferState));
1129 self->buf_states[0].state = buf_state;
1130 self->buf_states[0].timestamp = GST_BUFFER_TIMESTAMP (buffer);
1131 self->buf_states[0].duration = GST_BUFFER_DURATION (buffer);
1132 if (self->state_count < GST_DEINTERLACE_MAX_BUFFER_STATE_HISTORY)
1133 self->state_count++;
1135 for (i = GST_DEINTERLACE_MAX_FIELD_HISTORY - 1; i >= fields_to_push; i--) {
1136 self->field_history[i].frame =
1137 self->field_history[i - fields_to_push].frame;
1138 self->field_history[i].flags =
1139 self->field_history[i - fields_to_push].flags;
1142 if (field_layout == GST_DEINTERLACE_LAYOUT_AUTO) {
1143 if (!GST_VIDEO_INFO_IS_INTERLACED (&self->vinfo)) {
1144 GST_WARNING_OBJECT (self, "Can't detect field layout -- assuming TFF");
1145 field_layout = GST_DEINTERLACE_LAYOUT_TFF;
1147 field_layout = GST_DEINTERLACE_LAYOUT_TFF;
1149 field_layout = GST_DEINTERLACE_LAYOUT_BFF;
1154 field2 = gst_video_frame_new_and_map (&self->vinfo, buffer, GST_MAP_READ);
1155 if (field_layout == GST_DEINTERLACE_LAYOUT_TFF) {
1156 GST_DEBUG_OBJECT (self, "Top field first");
1157 field1_flags = PICTURE_INTERLACED_TOP;
1158 field2_flags = PICTURE_INTERLACED_BOTTOM;
1160 GST_DEBUG_OBJECT (self, "Bottom field first");
1161 field1_flags = PICTURE_INTERLACED_BOTTOM;
1162 field2_flags = PICTURE_INTERLACED_TOP;
1166 GST_DEBUG_OBJECT (self, "Two fields");
1167 self->field_history[1].frame = field1;
1168 self->field_history[1].flags = field1_flags;
1170 self->field_history[0].frame = field2;
1171 self->field_history[0].flags = field2_flags;
1172 } else { /* onefield */
1173 GST_DEBUG_OBJECT (self, "One field");
1174 self->field_history[0].frame = field1;
1175 self->field_history[0].flags = field1_flags;
1176 gst_video_frame_unmap_and_free (field2);
1179 self->history_count += fields_to_push;
1180 self->cur_field_idx += fields_to_push;
1182 GST_DEBUG_OBJECT (self, "Pushed buffer -- current history size %d, index %d",
1183 self->history_count, self->cur_field_idx);
1185 if (self->last_buffer)
1186 gst_buffer_unref (self->last_buffer);
1187 self->last_buffer = gst_buffer_ref (buffer);
1191 gst_deinterlace_update_qos (GstDeinterlace * self, gdouble proportion,
1192 GstClockTimeDiff diff, GstClockTime timestamp)
1194 GST_DEBUG_OBJECT (self,
1195 "Updating QoS: proportion %lf, diff %s%" GST_TIME_FORMAT ", timestamp %"
1196 GST_TIME_FORMAT, proportion, (diff < 0) ? "-" : "",
1197 GST_TIME_ARGS (ABS (diff)), GST_TIME_ARGS (timestamp));
1199 GST_OBJECT_LOCK (self);
1200 self->proportion = proportion;
1201 if (G_LIKELY (timestamp != GST_CLOCK_TIME_NONE)) {
1202 if (G_UNLIKELY (diff > 0))
1203 self->earliest_time =
1204 timestamp + 2 * diff + ((self->fields ==
1205 GST_DEINTERLACE_ALL) ? self->field_duration : 2 *
1206 self->field_duration);
1208 self->earliest_time = timestamp + diff;
1210 self->earliest_time = GST_CLOCK_TIME_NONE;
1212 GST_OBJECT_UNLOCK (self);
1216 gst_deinterlace_reset_qos (GstDeinterlace * self)
1218 gst_deinterlace_update_qos (self, 0.5, 0, GST_CLOCK_TIME_NONE);
1219 self->processed = 0;
1224 gst_deinterlace_read_qos (GstDeinterlace * self, gdouble * proportion,
1225 GstClockTime * time)
1227 GST_OBJECT_LOCK (self);
1228 *proportion = self->proportion;
1229 *time = self->earliest_time;
1230 GST_OBJECT_UNLOCK (self);
1233 /* Perform qos calculations before processing the next frame. Returns TRUE if
1234 * the frame should be processed, FALSE if the frame can be dropped entirely */
1236 gst_deinterlace_do_qos (GstDeinterlace * self, const GstBuffer * buffer)
1238 GstClockTime qostime, earliest_time;
1239 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
1242 /* no timestamp, can't do QoS => process frame */
1243 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (timestamp))) {
1244 GST_LOG_OBJECT (self, "invalid timestamp, can't do QoS, process frame");
1248 /* get latest QoS observation values */
1249 gst_deinterlace_read_qos (self, &proportion, &earliest_time);
1251 /* skip qos if we have no observation (yet) => process frame */
1252 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (earliest_time))) {
1253 GST_LOG_OBJECT (self, "no observation yet, process frame");
1257 /* qos is done on running time */
1258 qostime = gst_segment_to_running_time (&self->segment, GST_FORMAT_TIME,
1261 /* see how our next timestamp relates to the latest qos timestamp */
1262 GST_LOG_OBJECT (self, "qostime %" GST_TIME_FORMAT ", earliest %"
1263 GST_TIME_FORMAT, GST_TIME_ARGS (qostime), GST_TIME_ARGS (earliest_time));
1265 if (qostime != GST_CLOCK_TIME_NONE && qostime <= earliest_time) {
1266 GstClockTime stream_time, jitter;
1267 GstMessage *qos_msg;
1269 GST_DEBUG_OBJECT (self, "we are late, drop frame");
1272 gst_segment_to_stream_time (&self->segment, GST_FORMAT_TIME, timestamp);
1273 jitter = GST_CLOCK_DIFF (qostime, earliest_time);
1275 gst_message_new_qos (GST_OBJECT (self), FALSE, qostime, stream_time,
1276 timestamp, GST_BUFFER_DURATION (buffer));
1277 gst_message_set_qos_values (qos_msg, jitter, proportion, 1000000);
1278 gst_message_set_qos_stats (qos_msg, GST_FORMAT_BUFFERS,
1279 self->processed, self->dropped);
1280 gst_element_post_message (GST_ELEMENT (self), qos_msg);
1284 GST_LOG_OBJECT (self, "process frame");
1291 gst_deinterlace_fix_timestamps (GstDeinterlace * self,
1292 GstVideoFrame * field1, GstVideoFrame * field2)
1294 GstVideoFrame *field3, *field4;
1295 GstVideoInterlaceMode interlacing_mode;
1297 if (self->pattern_lock && self->pattern > -1) {
1298 /* accurate pattern-locked timestamp adjustment */
1299 if (!self->pattern_count)
1300 gst_deinterlace_update_pattern_timestamps (self);
1302 GST_BUFFER_TIMESTAMP (field1->buffer) =
1303 self->pattern_base_ts + self->output_count * self->pattern_buf_dur;
1304 GST_BUFFER_DURATION (field1->buffer) = self->pattern_buf_dur;
1305 self->output_count++;
1307 /* naive (but low-latency) timestamp adjustment based on subsequent
1310 && GST_VIDEO_FRAME_PLANE_DATA (field1,
1311 0) != GST_VIDEO_FRAME_PLANE_DATA (field2, 0)) {
1312 if (GST_BUFFER_TIMESTAMP (field1->buffer) +
1313 GST_BUFFER_DURATION (field1->buffer) ==
1314 GST_BUFFER_TIMESTAMP (field2->buffer)) {
1315 GST_BUFFER_TIMESTAMP (field1->buffer) =
1316 GST_BUFFER_TIMESTAMP (field2->buffer) =
1317 (GST_BUFFER_TIMESTAMP (field1->buffer) +
1318 GST_BUFFER_TIMESTAMP (field2->buffer)) / 2;
1320 GST_BUFFER_TIMESTAMP (field2->buffer) =
1321 GST_BUFFER_TIMESTAMP (field1->buffer);
1325 if (self->history_count < 3) {
1326 GST_DEBUG_OBJECT (self, "Need more fields (have %d, need 3)",
1327 self->history_count);
1331 field3 = self->field_history[self->history_count - 3].frame;
1332 interlacing_mode = GST_VIDEO_INFO_INTERLACE_MODE (&field3->info);
1333 if (IS_TELECINE (interlacing_mode)) {
1334 if (self->history_count < 4) {
1335 GST_DEBUG_OBJECT (self, "Need more fields (have %d, need 4)",
1336 self->history_count);
1340 field4 = self->field_history[self->history_count - 4].frame;
1341 if (GST_VIDEO_FRAME_PLANE_DATA (field3,
1342 0) != GST_VIDEO_FRAME_PLANE_DATA (field4, 0)) {
1343 /* telecine fields in separate buffers */
1344 GST_BUFFER_TIMESTAMP (field3->buffer) =
1345 (GST_BUFFER_TIMESTAMP (field3->buffer) +
1346 GST_BUFFER_TIMESTAMP (field4->buffer)) / 2;
1350 GST_BUFFER_DURATION (field1->buffer) =
1351 GST_BUFFER_TIMESTAMP (field3->buffer) -
1352 GST_BUFFER_TIMESTAMP (field1->buffer);
1355 GST_DEBUG_OBJECT (self,
1356 "Field 1 adjusted to ts %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT,
1357 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (field1->buffer)),
1358 GST_TIME_ARGS (GST_BUFFER_DURATION (field1->buffer)));
1363 gst_deinterlace_get_pattern_lock (GstDeinterlace * self, gboolean * flush_one)
1365 /* loop over all possible patterns and all possible phases
1366 * giving each a score. the highest score gets the lock */
1367 /* the score is calculated as the number of matched buffers in the
1368 * sequence starting at the phase offset with those from the history
1369 * then the longest duration pattern match is taken. if there is more than
1370 * one pattern matching all buffers, we take the longest pattern of those.
1371 * matches to complete patterns are preferred. if no non-trivial pattern is
1372 * matched, trivial patterns are tested. */
1373 gint i, j, k, score, pattern, phase;
1374 const gint state_count = self->state_count;
1375 const gint n_required = self->ignore_obscure ?
1376 GST_DEINTERLACE_OBSCURE_THRESHOLD :
1377 GST_DEINTERLACE_MAX_BUFFER_STATE_HISTORY;
1379 /* set unknown pattern as this is used in logic outside this function */
1382 /* wait for more buffers */
1383 if (!self->have_eos && state_count < n_required) {
1384 GST_DEBUG_OBJECT (self, "Need more buffers in state history - %d/%d",
1385 state_count, n_required);
1389 score = pattern = phase = -1;
1391 /* loop over all patterns */
1392 for (i = 0; i < G_N_ELEMENTS (telecine_patterns); i++) {
1393 const guint8 length = telecine_patterns[i].length;
1395 if (self->ignore_obscure && i >= GST_DEINTERLACE_OBSCURE_THRESHOLD)
1398 if (state_count < length)
1401 /* loop over all phases */
1402 for (j = 0; j < length; j++) {
1403 /* low-latency mode looks at past buffers, high latency at future buffers */
1404 const gint state_idx =
1405 self->low_latency ? (self->history_count - 1) >> 1 : state_count - 1;
1406 /* loop over history, breaking on differing buffer states */
1407 for (k = 0; k < length && k < state_count; k++) {
1408 const guint8 hist = self->buf_states[state_idx - k].state;
1409 const guint8 patt = telecine_patterns[i].states[(j + k) % length];
1414 /* make complete matches more signficant */
1416 k += GST_DEINTERLACE_MAX_BUFFER_STATE_HISTORY;
1418 /* take as new best pattern if the number of matched buffers is more than
1419 * for other patterns */
1428 GST_DEBUG_OBJECT (self,
1429 "Final pattern match result: pa %d, ph %d, l %d, s %d", pattern, phase,
1430 telecine_patterns[pattern].length, score);
1431 self->pattern = pattern;
1432 self->pattern_phase = phase;
1433 self->pattern_count = 0;
1434 self->output_count = 0;
1435 self->pattern_lock = TRUE;
1437 /* check for the case that the first field of the pattern is an orphan */
1439 && telecine_patterns[pattern].states[phase] & (GST_ONE | GST_INT)) {
1440 gint i = phase, field_count = 0;
1441 guint8 state = telecine_patterns[pattern].states[i];
1444 if (state & GST_ONE) {
1447 } else if (!(state & GST_DRP)) {
1453 i %= telecine_patterns[pattern].length;
1454 state = telecine_patterns[pattern].states[i];
1455 } while (!(state & GST_PRG));
1457 /* if field_count is odd, we have an orphan field at the beginning of the
1459 * note - don't do this in low-latency mode as we are somewhere within the
1460 * pattern already */
1461 if (!self->low_latency && (*flush_one = field_count & 1)) {
1462 GST_DEBUG_OBJECT (self, "Orphan field detected at the beginning of the "
1463 "pattern - it will be deinterlaced.");
1468 static GstFlowReturn
1469 gst_deinterlace_output_frame (GstDeinterlace * self, gboolean flushing)
1471 GstClockTime timestamp;
1473 gint fields_required;
1474 GstBuffer *buf, *outbuf;
1475 GstVideoFrame *outframe = NULL;
1476 GstDeinterlaceField *field1, *field2;
1477 GstVideoInterlaceMode interlacing_mode;
1479 gboolean hl_no_lock; /* indicates high latency timestamp adjustment but no pattern lock (could be ONEF or I) */
1480 gboolean same_buffer; /* are field1 and field2 in the same buffer? */
1481 gboolean flush_one; /* used for flushing one field when in high latency mode and not locked */
1482 TelecinePattern pattern;
1483 guint8 phase, count;
1484 const GstDeinterlaceLocking locking = self->locking;
1488 fields_required = 0;
1490 same_buffer = FALSE;
1492 self->need_more = FALSE;
1493 phase = self->pattern_phase;
1494 count = self->pattern_count;
1496 if (!self->history_count) {
1497 GST_DEBUG_OBJECT (self, "History is empty, waiting for more buffers!");
1501 field1 = &self->field_history[self->history_count - 1];
1503 if (locking != GST_DEINTERLACE_LOCKING_NONE) {
1504 if (!self->state_count) {
1505 GST_ERROR_OBJECT (self,
1506 "BROKEN! Fields in history + no states should not happen!");
1507 return GST_FLOW_ERROR;
1510 gst_deinterlace_get_buffer_state (self, field1->frame, &buf_state,
1513 if (self->pattern != -1)
1514 pattern = telecine_patterns[self->pattern];
1516 /* patterns 0 and 1 are interlaced, the rest are telecine */
1517 if (self->pattern > 1)
1518 interlacing_mode = GST_VIDEO_INTERLACE_MODE_MIXED;
1520 if (self->pattern == -1 || self->pattern_refresh
1521 || !(buf_state & pattern.states[(phase + count) % pattern.length])) {
1522 if (self->pattern == -1) {
1523 GST_DEBUG_OBJECT (self, "No pattern lock - refresh lock");
1524 } else if (self->pattern_refresh) {
1525 GST_DEBUG_OBJECT (self, "Pattern refresh - refresh lock");
1527 GST_DEBUG_OBJECT (self, "Unexpected buffer state - refresh lock");
1529 /* no pattern, pattern refresh set or unexpected buffer state */
1530 self->pattern_lock = FALSE;
1531 self->pattern_refresh = TRUE;
1533 /* refresh pattern lock */
1534 gst_deinterlace_get_pattern_lock (self, &flush_one);
1536 if (self->pattern != -1) {
1537 /* locked onto a valid pattern so refresh complete */
1538 GST_DEBUG_OBJECT (self, "Pattern locked! %s starting at %d",
1539 telecine_patterns[self->pattern].nick, self->pattern_phase);
1540 self->pattern_refresh = FALSE;
1541 } else if (!self->low_latency) {
1542 if (!self->pattern_lock) {
1549 /* setcaps on sink and src pads */
1550 gst_deinterlace_setcaps (self, self->sinkpad, gst_pad_get_current_caps (self->sinkpad)); // FIXME
1552 if (flush_one && self->drop_orphans) {
1553 GST_DEBUG_OBJECT (self, "Dropping orphan first field");
1554 self->cur_field_idx--;
1555 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1560 gst_deinterlace_get_buffer_state (self, field1->frame, NULL,
1564 same_buffer = self->history_count >= 2
1565 && (GST_VIDEO_FRAME_PLANE_DATA (field1->frame, 0) ==
1566 GST_VIDEO_FRAME_PLANE_DATA (self->field_history[self->history_count -
1569 if ((flushing && self->history_count == 1) || (flush_one
1570 && !self->drop_orphans) || (hl_no_lock && (self->history_count == 1
1571 || !same_buffer))) {
1572 /* This case is for flushing a single field:
1573 * - flushing and 1 field in the history
1574 * - flush one (due to orphans in the pattern) and do not drop orphans
1575 * - high-latency pattern locking with no possible lock given the current
1576 * state and either only one field in the history or the tip two fields
1577 * are in separate buffers */
1578 GST_DEBUG_OBJECT (self, "Flushing one field using linear method");
1579 gst_deinterlace_set_method (self, GST_DEINTERLACE_LINEAR);
1580 fields_required = gst_deinterlace_method_get_fields_required (self->method);
1581 } else if (interlacing_mode == GST_VIDEO_INTERLACE_MODE_PROGRESSIVE ||
1582 (interlacing_mode == GST_VIDEO_INTERLACE_MODE_MIXED &&
1583 !GST_VIDEO_FRAME_IS_INTERLACED (field1->frame))) {
1584 /* This case is for processing progressive buffers, telecine or plain
1586 GstVideoFrame *field1_frame;
1587 GstBuffer *field1_buffer;
1590 fields_required = 2;
1592 /* Not enough fields in the history */
1593 if (!flushing && self->history_count < fields_required) {
1594 GST_DEBUG_OBJECT (self, "Need more fields (have %d, need %d)",
1595 self->history_count, self->cur_field_idx + fields_required);
1599 field2 = &self->field_history[self->history_count - 2];
1600 if (GST_VIDEO_FRAME_PLANE_DATA (field1->frame,
1601 0) != GST_VIDEO_FRAME_PLANE_DATA (field2->frame, 0)) {
1602 /* ERROR - next two fields in field history are not one progressive buffer - weave? */
1603 GST_ERROR_OBJECT (self,
1604 "Progressive buffer but two fields at tip aren't in the same buffer!");
1607 if (IS_TELECINE (interlacing_mode)
1608 && !gst_deinterlace_fix_timestamps (self, field1->frame, field2->frame)
1612 GST_DEBUG_OBJECT (self,
1613 "Frame type: Progressive; pushing buffer as a frame");
1615 self->cur_field_idx--;
1616 field1_frame = gst_deinterlace_pop_history (self);
1617 field1_buffer = field1_frame->buffer;
1618 gst_buffer_ref (field1_buffer);
1619 gst_video_frame_unmap_and_free (field1_frame);
1620 /* field2 is the same buffer as field1, but we need to remove it from the
1622 self->cur_field_idx--;
1623 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1624 GST_DEBUG_OBJECT (self,
1625 "[OUT] ts %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT ", end %"
1627 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (field1_buffer)),
1628 GST_TIME_ARGS (GST_BUFFER_DURATION (field1_buffer)),
1629 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (field1_buffer) +
1630 GST_BUFFER_DURATION (field1_buffer)));
1631 return gst_pad_push (self->srcpad, field1_buffer);
1632 } else if (IS_TELECINE (interlacing_mode)
1633 && GST_VIDEO_FRAME_IS_INTERLACED (field1->frame) && !same_buffer) {
1634 /* This case needs to identify telecine mixed buffers that require weaving
1635 * of two fields in different buffers.
1636 * - interlacing mode is mixed
1637 * - locked on to a telecine pattern
1638 * - frame is interlaced
1639 * - fields are in separate buffers
1640 * If we don't yet have a pattern lock, we will have to deinterlace as we
1641 * don't explicitly know we have a telecine sequence and so we drop through
1642 * to the plain deinterlace case */
1643 fields_required = 2;
1644 if (!flushing && self->history_count < fields_required) {
1645 GST_DEBUG_OBJECT (self, "Need more fields (have %d, need %d)",
1646 self->history_count, self->cur_field_idx + fields_required);
1650 field2 = &self->field_history[self->history_count - 2];
1651 if (!gst_deinterlace_fix_timestamps (self, field1->frame, field2->frame)
1655 /* check field1 and field2 buffer caps and flags are corresponding */
1656 if (field1->flags == field2->flags) {
1657 /* ERROR - fields are of same parity - what should be done here?
1658 * perhaps deinterlace the tip field and start again? */
1659 GST_ERROR_OBJECT (self, "Telecine mixed with fields of same parity!");
1661 GST_DEBUG_OBJECT (self,
1662 "Frame type: Telecine Mixed; weaving tip two fields into a frame");
1663 /* set method to WEAVE */
1664 gst_deinterlace_set_method (self, GST_DEINTERLACE_WEAVE);
1666 /* This is the final catch-all case that applies the selected deinterlacing
1667 * method. At this point the fields to be processed are either definitely
1668 * interlaced or we do not yet know that we have a telecine pattern lock
1669 * and so the best we can do is to deinterlace the fields. */
1670 gst_deinterlace_set_method (self, self->user_set_method_id);
1671 fields_required = gst_deinterlace_method_get_fields_required (self->method);
1672 if (flushing && self->history_count < fields_required) {
1673 /* note: we already checked for flushing with history count == 1 above
1674 * so we must have 2 or more fields in here */
1675 gst_deinterlace_set_method (self, GST_DEINTERLACE_VFIR);
1677 gst_deinterlace_method_get_fields_required (self->method);
1678 GST_DEBUG_OBJECT (self, "Flushing field(s) using %s method",
1679 methods_types[self->method_id].value_nick);
1682 /* Not enough fields in the history */
1683 if (!flushing && self->history_count < fields_required) {
1684 GST_DEBUG_OBJECT (self, "Need more fields (have %d, need %d)",
1685 self->history_count, self->cur_field_idx + fields_required);
1689 GST_DEBUG_OBJECT (self,
1690 "Frame type: Interlaced; deinterlacing using %s method",
1691 methods_types[self->method_id].value_nick);
1694 if (!flushing && self->cur_field_idx < 1) {
1698 if (self->fields == GST_DEINTERLACE_ALL || IS_TELECINE (interlacing_mode))
1699 GST_DEBUG_OBJECT (self, "All fields");
1700 else if (self->fields == GST_DEINTERLACE_TF)
1701 GST_DEBUG_OBJECT (self, "Top fields");
1702 else if (self->fields == GST_DEINTERLACE_BF)
1703 GST_DEBUG_OBJECT (self, "Bottom fields");
1705 if ((self->field_history[self->cur_field_idx].flags == PICTURE_INTERLACED_TOP
1706 && (self->fields == GST_DEINTERLACE_TF
1707 || IS_TELECINE (interlacing_mode)))
1708 || self->fields == GST_DEINTERLACE_ALL) {
1709 GST_DEBUG_OBJECT (self, "deinterlacing top field");
1711 /* create new buffer */
1712 outbuf = gst_buffer_new_allocate (NULL, GST_VIDEO_INFO_SIZE (&self->vinfo), NULL); // FIXME: pad_alloc_buffer
1715 return GST_FLOW_ERROR; // FIXME: report proper out of mem error?
1718 if (GST_PAD_CAPS (self->srcpad) != GST_BUFFER_CAPS (outbuf) &&
1719 !gst_caps_is_equal (GST_PAD_CAPS (self->srcpad),
1720 GST_BUFFER_CAPS (outbuf))) {
1721 gst_caps_replace (&self->request_caps, GST_BUFFER_CAPS (outbuf));
1722 GST_DEBUG_OBJECT (self, "Upstream wants new caps %" GST_PTR_FORMAT,
1723 self->request_caps);
1725 gst_buffer_unref (outbuf);
1727 gst_buffer_new_allocate (NULL, GST_VIDEO_INFO_SIZE (&self->vinfo),
1731 return GST_FLOW_ERROR;
1735 g_return_val_if_fail (self->history_count >=
1736 1 + gst_deinterlace_method_get_latency (self->method), GST_FLOW_ERROR);
1739 self->field_history[self->history_count - 1 -
1740 gst_deinterlace_method_get_latency (self->method)].frame->buffer;
1742 if (!IS_TELECINE (interlacing_mode)) {
1743 timestamp = GST_BUFFER_TIMESTAMP (buf);
1745 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
1746 if (self->fields == GST_DEINTERLACE_ALL)
1747 GST_BUFFER_DURATION (outbuf) = self->field_duration;
1749 GST_BUFFER_DURATION (outbuf) = 2 * self->field_duration;
1750 GST_DEBUG_OBJECT (self,
1751 "[ADJUST] ts %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT ", end %"
1752 GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
1753 GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)),
1754 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf) +
1755 GST_BUFFER_DURATION (outbuf)));
1757 GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
1758 GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
1761 /* Check if we need to drop the frame because of QoS */
1762 if (!gst_deinterlace_do_qos (self, buf)) {
1763 self->cur_field_idx--;
1764 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1765 gst_buffer_unref (outbuf);
1769 if (self->cur_field_idx < 0 && flushing) {
1770 if (self->history_count == 1) {
1771 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1774 self->cur_field_idx++;
1776 if (self->cur_field_idx < 0) {
1779 if (!flushing && self->cur_field_idx < 1) {
1783 /* map the frame so the deinterlace methods can write the data to the
1784 * correct memory locations */
1786 gst_video_frame_new_and_map (&self->vinfo, outbuf, GST_MAP_WRITE);
1788 /* do magic calculus */
1789 gst_deinterlace_method_deinterlace_frame (self->method,
1790 self->field_history, self->history_count, outframe,
1791 self->cur_field_idx);
1793 gst_video_frame_unmap_and_free (outframe);
1795 self->cur_field_idx--;
1796 if (self->cur_field_idx + 1 +
1797 gst_deinterlace_method_get_latency (self->method)
1798 < self->history_count || flushing) {
1799 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1802 if (gst_deinterlace_clip_buffer (self, outbuf)) {
1803 GST_DEBUG_OBJECT (self,
1804 "[OUT] ts %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT ", end %"
1805 GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
1806 GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)),
1807 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf) +
1808 GST_BUFFER_DURATION (outbuf)));
1809 ret = gst_pad_push (self->srcpad, outbuf);
1812 gst_buffer_unref (outbuf);
1816 if (ret != GST_FLOW_OK)
1818 if (interlacing_mode == GST_VIDEO_INTERLACE_MODE_MIXED
1819 && self->method_id == GST_DEINTERLACE_WEAVE) {
1820 /* pop off the second field */
1821 GST_DEBUG_OBJECT (self, "Removing unused field (count: %d)",
1822 self->history_count);
1823 self->cur_field_idx--;
1824 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1825 interlacing_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
1830 if (flush_one && !self->drop_orphans) {
1831 GST_DEBUG_OBJECT (self, "Orphan field deinterlaced - reconfiguring");
1835 /* no calculation done: remove excess field */
1836 else if (self->field_history[self->cur_field_idx].flags ==
1837 PICTURE_INTERLACED_TOP && (self->fields == GST_DEINTERLACE_BF
1838 && !IS_TELECINE (interlacing_mode))) {
1839 GST_DEBUG_OBJECT (self, "Removing unused top field");
1840 self->cur_field_idx--;
1841 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1843 if (flush_one && !self->drop_orphans) {
1844 GST_DEBUG_OBJECT (self, "Orphan field deinterlaced - reconfiguring");
1849 if (self->history_count < fields_required)
1852 if (self->cur_field_idx < 0)
1855 if (!flushing && self->cur_field_idx < 1) {
1859 /* deinterlace bottom_field */
1860 if ((self->field_history[self->cur_field_idx].flags ==
1861 PICTURE_INTERLACED_BOTTOM && (self->fields == GST_DEINTERLACE_BF
1862 || IS_TELECINE (interlacing_mode)))
1863 || self->fields == GST_DEINTERLACE_ALL) {
1864 GST_DEBUG_OBJECT (self, "deinterlacing bottom field");
1866 /* create new buffer */
1867 outbuf = gst_buffer_new_allocate (NULL, GST_VIDEO_INFO_SIZE (&self->vinfo), NULL); // FIXME: pad_alloc_buffer
1870 return GST_FLOW_ERROR; // FIXME: report out of mem error?
1873 if (GST_PAD_CAPS (self->srcpad) != GST_BUFFER_CAPS (outbuf) &&
1874 !gst_caps_is_equal (GST_PAD_CAPS (self->srcpad),
1875 GST_BUFFER_CAPS (outbuf))) {
1876 gst_caps_replace (&self->request_caps, GST_BUFFER_CAPS (outbuf));
1877 GST_DEBUG_OBJECT (self, "Upstream wants new caps %" GST_PTR_FORMAT,
1878 self->request_caps);
1880 gst_buffer_unref (outbuf);
1882 gst_buffer_new_allocate (NULL, GST_VIDEO_INFO_SIZE (&self->vinfo),
1886 return GST_FLOW_ERROR;
1888 gst_buffer_set_caps (outbuf, GST_PAD_CAPS (self->srcpad));
1892 g_return_val_if_fail (self->history_count - 1 -
1893 gst_deinterlace_method_get_latency (self->method) >= 0, GST_FLOW_ERROR);
1896 self->field_history[self->history_count - 1 -
1897 gst_deinterlace_method_get_latency (self->method)].frame->buffer;
1898 if (!IS_TELECINE (interlacing_mode)) {
1899 timestamp = GST_BUFFER_TIMESTAMP (buf);
1901 if (self->fields == GST_DEINTERLACE_ALL) {
1902 GST_BUFFER_TIMESTAMP (outbuf) = timestamp + self->field_duration;
1903 GST_BUFFER_DURATION (outbuf) = self->field_duration;
1905 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
1906 GST_BUFFER_DURATION (outbuf) = 2 * self->field_duration;
1908 GST_DEBUG_OBJECT (self,
1909 "[ADJUST] ts %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT ", end %"
1910 GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
1911 GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)),
1912 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf) +
1913 GST_BUFFER_DURATION (outbuf)));
1915 GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
1916 GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
1919 /* Check if we need to drop the frame because of QoS */
1920 if (!gst_deinterlace_do_qos (self, buf)) {
1921 self->cur_field_idx--;
1922 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1923 gst_buffer_unref (outbuf);
1927 /* map the frame so the deinterlace methods can write the data to the
1928 * correct memory locations */
1930 gst_video_frame_new_and_map (&self->vinfo, outbuf, GST_MAP_WRITE);
1932 /* do magic calculus */
1933 gst_deinterlace_method_deinterlace_frame (self->method,
1934 self->field_history, self->history_count, outframe,
1935 self->cur_field_idx);
1937 gst_video_frame_unmap_and_free (outframe);
1939 self->cur_field_idx--;
1940 if (self->cur_field_idx + 1 +
1941 gst_deinterlace_method_get_latency (self->method)
1942 < self->history_count) {
1943 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1946 if (gst_deinterlace_clip_buffer (self, outbuf)) {
1947 GST_DEBUG_OBJECT (self,
1948 "[OUT] ts %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT ", end %"
1949 GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
1950 GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)),
1951 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf) +
1952 GST_BUFFER_DURATION (outbuf)));
1953 ret = gst_pad_push (self->srcpad, outbuf);
1956 gst_buffer_unref (outbuf);
1960 if (ret != GST_FLOW_OK)
1962 if (interlacing_mode == GST_VIDEO_INTERLACE_MODE_MIXED
1963 && self->method_id == GST_DEINTERLACE_WEAVE) {
1964 /* pop off the second field */
1965 GST_DEBUG_OBJECT (self, "Removing unused field (count: %d)",
1966 self->history_count);
1967 self->cur_field_idx--;
1968 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1969 interlacing_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
1974 if (flush_one && !self->drop_orphans) {
1975 GST_DEBUG_OBJECT (self, "Orphan field deinterlaced - reconfiguring");
1979 /* no calculation done: remove excess field */
1980 else if (self->field_history[self->cur_field_idx].flags ==
1981 PICTURE_INTERLACED_BOTTOM && (self->fields == GST_DEINTERLACE_TF
1982 && !IS_TELECINE (interlacing_mode))) {
1983 GST_DEBUG_OBJECT (self, "Removing unused bottom field");
1984 self->cur_field_idx--;
1985 gst_video_frame_unmap_and_free (gst_deinterlace_pop_history (self));
1987 if (flush_one && !self->drop_orphans) {
1988 GST_DEBUG_OBJECT (self, "Orphan field deinterlaced - reconfiguring");
1996 self->need_more = TRUE;
2001 gst_deinterlace_get_latency (GstDeinterlace * self)
2003 if (self->locking == GST_DEINTERLACE_LOCKING_AUTO) {
2007 query = gst_query_new_latency ();
2008 if ((res = gst_pad_peer_query (self->sinkpad, query))) {
2010 /* if upstream is live, we use low-latency passive locking mode
2011 * else high-latency active locking mode */
2012 gst_query_parse_latency (query, &is_live, NULL, NULL);
2013 GST_DEBUG_OBJECT (self, "Latency query indicates stream is %s",
2014 is_live ? "live - using passive locking" :
2015 "not live - using active locking");
2016 gst_query_unref (query);
2019 /* conservatively use passive locking if the query fails */
2020 GST_WARNING_OBJECT (self,
2021 "Latency query failed - fall back to using passive locking");
2022 gst_query_unref (query);
2026 return self->locking - 2;
2030 static GstFlowReturn
2031 gst_deinterlace_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
2033 GstDeinterlace *self = GST_DEINTERLACE (parent);
2034 GstFlowReturn ret = GST_FLOW_OK;
2036 GST_OBJECT_LOCK (self);
2037 if (self->reconfigure) { /* FIXME: reconfigure should probably work differently */
2040 if (self->new_fields != -1)
2041 self->fields = self->new_fields;
2042 if (self->new_mode != -1)
2043 self->mode = self->new_mode;
2044 self->new_mode = -1;
2045 self->new_fields = -1;
2047 self->reconfigure = FALSE;
2048 GST_OBJECT_UNLOCK (self);
2049 caps = gst_pad_get_current_caps (self->srcpad);
2051 gst_deinterlace_setcaps (self, self->sinkpad, caps); // FIXME
2052 gst_caps_unref (caps);
2055 GST_OBJECT_UNLOCK (self);
2058 GST_DEBUG_OBJECT (self,
2059 "[IN] ts %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT ", end %"
2060 GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
2061 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)),
2062 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)));
2064 if (self->still_frame_mode || self->passthrough) {
2065 GST_DEBUG_OBJECT (self,
2066 "Frame type: Progressive?; pushing buffer using pass-through");
2067 GST_DEBUG_OBJECT (self,
2068 "[OUT] ts %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT ", end %"
2069 GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
2070 GST_TIME_ARGS (GST_BUFFER_DURATION (buf)),
2071 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)));
2073 return gst_pad_push (self->srcpad, buf);
2076 if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT)) {
2077 GST_DEBUG_OBJECT (self, "DISCONT buffer, resetting history");
2078 gst_deinterlace_reset_history (self, FALSE);
2081 gst_deinterlace_push_history (self, buf);
2085 ret = gst_deinterlace_output_frame (self, FALSE);
2086 } while (!self->need_more && self->history_count > 0 && ret == GST_FLOW_OK);
2092 gst_greatest_common_divisor (gint a, gint b)
2105 gst_fraction_double (gint * n_out, gint * d_out, gboolean half)
2115 if (n == 0 || (n == G_MAXINT && d == 1))
2118 gcd = gst_greatest_common_divisor (n, d);
2123 if (G_MAXINT / 2 >= ABS (n)) {
2125 } else if (d >= 2) {
2131 if (G_MAXINT / 2 >= ABS (d)) {
2133 } else if (n >= 2) {
2146 /* FIXME: use filter in getcaps */
2148 gst_deinterlace_getcaps (GstDeinterlace * self, GstPad * pad, GstCaps * filter)
2156 otherpad = (pad == self->srcpad) ? self->sinkpad : self->srcpad;
2158 ourcaps = gst_pad_get_pad_template_caps (pad);
2159 peercaps = gst_pad_peer_query_caps (otherpad, NULL);
2162 GST_DEBUG_OBJECT (pad, "Peer has caps %" GST_PTR_FORMAT, peercaps);
2163 ret = gst_caps_make_writable (gst_caps_intersect (ourcaps, peercaps));
2164 gst_caps_unref (peercaps);
2165 gst_caps_unref (ourcaps);
2167 ret = gst_caps_make_writable (ourcaps);
2170 for (len = gst_caps_get_size (ret); len > 0; len--) {
2171 GstStructure *s = gst_caps_get_structure (ret, len - 1);
2173 if (pad == self->sinkpad || self->passthrough)
2174 gst_structure_remove_field (s, "interlace-mode");
2176 gst_structure_set (s, "interlace-mode", G_TYPE_STRING, "progressive",
2179 if (!self->passthrough && self->fields == GST_DEINTERLACE_ALL) {
2182 val = gst_structure_get_value (s, "framerate");
2186 if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION) {
2189 n = gst_value_get_fraction_numerator (val);
2190 d = gst_value_get_fraction_denominator (val);
2192 if (!gst_fraction_double (&n, &d, pad != self->srcpad)) {
2196 gst_structure_set (s, "framerate", GST_TYPE_FRACTION, n, d, NULL);
2197 } else if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION_RANGE) {
2198 const GValue *min, *max;
2199 GValue nrange = { 0, }, nmin = {
2204 g_value_init (&nrange, GST_TYPE_FRACTION_RANGE);
2205 g_value_init (&nmin, GST_TYPE_FRACTION);
2206 g_value_init (&nmax, GST_TYPE_FRACTION);
2208 min = gst_value_get_fraction_range_min (val);
2209 max = gst_value_get_fraction_range_max (val);
2211 n = gst_value_get_fraction_numerator (min);
2212 d = gst_value_get_fraction_denominator (min);
2214 if (!gst_fraction_double (&n, &d, pad != self->srcpad)) {
2215 g_value_unset (&nrange);
2216 g_value_unset (&nmax);
2217 g_value_unset (&nmin);
2221 gst_value_set_fraction (&nmin, n, d);
2223 n = gst_value_get_fraction_numerator (max);
2224 d = gst_value_get_fraction_denominator (max);
2226 if (!gst_fraction_double (&n, &d, pad != self->srcpad)) {
2227 g_value_unset (&nrange);
2228 g_value_unset (&nmax);
2229 g_value_unset (&nmin);
2233 gst_value_set_fraction (&nmax, n, d);
2234 gst_value_set_fraction_range (&nrange, &nmin, &nmax);
2236 gst_structure_set_value (s, "framerate", &nrange);
2238 g_value_unset (&nmin);
2239 g_value_unset (&nmax);
2240 g_value_unset (&nrange);
2241 } else if (G_VALUE_TYPE (val) == GST_TYPE_LIST) {
2243 GValue nlist = { 0, };
2244 GValue nval = { 0, };
2247 g_value_init (&nlist, GST_TYPE_LIST);
2248 for (i = gst_value_list_get_size (val); i > 0; i--) {
2251 lval = gst_value_list_get_value (val, i);
2253 if (G_VALUE_TYPE (lval) != GST_TYPE_FRACTION)
2256 n = gst_value_get_fraction_numerator (lval);
2257 d = gst_value_get_fraction_denominator (lval);
2259 /* Double/Half the framerate but if this fails simply
2260 * skip this value from the list */
2261 if (!gst_fraction_double (&n, &d, pad != self->srcpad)) {
2265 g_value_init (&nval, GST_TYPE_FRACTION);
2267 gst_value_set_fraction (&nval, n, d);
2268 gst_value_list_append_value (&nlist, &nval);
2269 g_value_unset (&nval);
2271 gst_structure_set_value (s, "framerate", &nlist);
2272 g_value_unset (&nlist);
2277 GST_DEBUG_OBJECT (pad, "Returning caps %" GST_PTR_FORMAT, ret);
2282 GST_ERROR_OBJECT (pad, "Unable to transform peer caps");
2283 gst_caps_unref (ret);
2288 gst_deinterlace_setcaps (GstDeinterlace * self, GstPad * pad, GstCaps * caps)
2290 gboolean res = TRUE;
2292 GstVideoInterlaceMode interlacing_mode;
2295 if (self->locking != GST_DEINTERLACE_LOCKING_NONE) {
2296 if (self->low_latency == -1)
2297 self->low_latency = gst_deinterlace_get_latency (self);
2299 if (self->pattern_lock) {
2300 /* refresh has been successful - we have a lock now */
2301 self->pattern_refresh = FALSE;
2303 /* if we were not refreshing (!pattern_refresh) the caps have changed
2304 * so we need to refresh and we don't have a lock anymore
2305 * otherwise we have pattern_fresh and !pattern_lock anyway */
2306 self->pattern_refresh = TRUE;
2307 self->pattern_lock = FALSE;
2311 if (!gst_video_info_from_caps (&self->vinfo, caps))
2314 fps_n = GST_VIDEO_INFO_FPS_N (&self->vinfo);
2315 fps_d = GST_VIDEO_INFO_FPS_D (&self->vinfo);
2320 gst_deinterlace_update_passthrough (self);
2322 interlacing_mode = GST_VIDEO_INFO_INTERLACE_MODE (&self->vinfo);
2324 if (self->pattern_lock) {
2325 srccaps = gst_caps_copy (caps);
2326 if (self->pattern != -1
2327 && G_UNLIKELY (!gst_util_fraction_multiply (fps_n, fps_d,
2328 telecine_patterns[self->pattern].ratio_n,
2329 telecine_patterns[self->pattern].ratio_d, &fps_n, &fps_d)))
2330 GST_ERROR_OBJECT (self,
2331 "Multiplying the framerate by the telecine pattern ratio overflowed!");
2332 gst_caps_set_simple (srccaps, "framerate", GST_TYPE_FRACTION, fps_n,
2334 } else if (self->locking == GST_DEINTERLACE_LOCKING_ACTIVE
2335 || self->low_latency == 0) {
2336 /* in high latency pattern locking mode if we don't have a pattern lock,
2337 * the sink pad caps are the best we know */
2338 srccaps = gst_caps_ref (caps);
2339 } else if (self->low_latency > 0
2340 && interlacing_mode == GST_VIDEO_INTERLACE_MODE_MIXED
2341 && self->pattern == -1) {
2342 /* for initial buffers of a telecine pattern, until there is a lock we
2343 * we output naïvely adjusted timestamps in low-latency pattern locking
2345 srccaps = gst_caps_copy (caps);
2346 gst_caps_set_simple (srccaps, "framerate", GST_TYPE_FRACTION, 0, 1, NULL);
2347 } else if (!self->passthrough && self->fields == GST_DEINTERLACE_ALL) {
2348 if (!gst_fraction_double (&fps_n, &fps_d, FALSE))
2351 srccaps = gst_caps_copy (caps);
2353 gst_caps_set_simple (srccaps, "framerate", GST_TYPE_FRACTION, fps_n,
2356 srccaps = gst_caps_ref (caps);
2359 if (self->mode != GST_DEINTERLACE_MODE_DISABLED) {
2360 srccaps = gst_caps_make_writable (srccaps);
2361 gst_caps_set_simple (srccaps, "interlace-method", G_TYPE_STRING,
2362 "progressive", NULL);
2365 if (!gst_pad_set_caps (self->srcpad, srccaps))
2366 goto caps_not_accepted;
2369 self->field_duration = gst_util_uint64_scale (GST_SECOND, fps_d, 2 * fps_n);
2371 self->field_duration = 0;
2374 gst_deinterlace_set_method (self, self->method_id);
2375 gst_deinterlace_method_setup (self->method, &self->vinfo);
2377 GST_DEBUG_OBJECT (pad, "Sink caps: %" GST_PTR_FORMAT, caps);
2378 GST_DEBUG_OBJECT (pad, "Src caps: %" GST_PTR_FORMAT, srccaps);
2380 gst_caps_unref (srccaps);
2388 GST_ERROR_OBJECT (pad, "Invalid caps: %" GST_PTR_FORMAT, caps);
2393 GST_ERROR_OBJECT (pad, "Caps not accepted: %" GST_PTR_FORMAT, srccaps);
2394 gst_caps_unref (srccaps);
2399 gst_deinterlace_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
2401 gboolean res = TRUE;
2402 GstDeinterlace *self = GST_DEINTERLACE (parent);
2404 GST_LOG_OBJECT (pad, "received %s event: %" GST_PTR_FORMAT,
2405 GST_EVENT_TYPE_NAME (event), event);
2407 switch (GST_EVENT_TYPE (event)) {
2408 case GST_EVENT_CAPS:
2410 GstCaps *caps = NULL;
2412 gst_event_parse_caps (event, &caps);
2413 res = gst_deinterlace_setcaps (self, pad, caps);
2414 gst_event_unref (event);
2417 case GST_EVENT_SEGMENT:
2419 const GstSegment *segment;
2421 gst_event_parse_segment (event, &segment);
2423 gst_deinterlace_reset_qos (self);
2424 gst_deinterlace_reset_history (self, FALSE);
2426 if (segment->format == GST_FORMAT_TIME) {
2427 GST_DEBUG_OBJECT (pad,
2428 "Got SEGMENT event in TIME format, passing on (%"
2429 GST_TIME_FORMAT " - %" GST_TIME_FORMAT ")",
2430 GST_TIME_ARGS (segment->start), GST_TIME_ARGS (segment->stop));
2431 gst_segment_copy_into (segment, &self->segment);
2433 GST_WARNING_OBJECT (pad, "Got SEGMENT event in %s format",
2434 gst_format_get_name (segment->format));
2435 gst_segment_init (&self->segment, GST_FORMAT_UNDEFINED);
2438 res = gst_pad_push_event (self->srcpad, event);
2441 case GST_EVENT_CUSTOM_DOWNSTREAM:{
2442 gboolean still_state;
2444 if (gst_video_event_parse_still_frame (event, &still_state)) {
2445 GST_DEBUG_OBJECT (self, "Received still frame event, state %d",
2451 GST_DEBUG_OBJECT (self, "Handling still frame");
2452 self->still_frame_mode = TRUE;
2453 gst_deinterlace_reset_history (self, FALSE);
2454 if (self->last_buffer) {
2456 gst_pad_push (self->srcpad, gst_buffer_ref (self->last_buffer));
2457 GST_DEBUG_OBJECT (self, "Pushed still frame, result: %s",
2458 gst_flow_get_name (ret));
2460 GST_WARNING_OBJECT (self, "No pending buffer!");
2463 GST_DEBUG_OBJECT (self, "Ending still frames");
2464 self->still_frame_mode = FALSE;
2470 self->have_eos = TRUE;
2471 gst_deinterlace_reset_history (self, FALSE);
2475 res = gst_pad_push_event (self->srcpad, event);
2478 case GST_EVENT_FLUSH_STOP:
2479 if (self->still_frame_mode) {
2480 GST_DEBUG_OBJECT (self, "Ending still frames");
2481 self->still_frame_mode = FALSE;
2483 gst_deinterlace_reset_qos (self);
2484 res = gst_pad_push_event (self->srcpad, event);
2485 gst_deinterlace_reset_history (self, TRUE);
2493 gst_deinterlace_sink_query (GstPad * pad, GstObject * parent, GstQuery * query)
2495 GstDeinterlace *self = GST_DEINTERLACE (parent);
2496 gboolean res = FALSE;
2498 GST_LOG_OBJECT (pad, "%s query", GST_QUERY_TYPE_NAME (query));
2500 switch (GST_QUERY_TYPE (query)) {
2501 case GST_QUERY_CAPS:{
2502 GstCaps *filter, *caps;
2504 gst_query_parse_caps (query, &filter);
2505 caps = gst_deinterlace_getcaps (self, pad, filter);
2506 gst_query_set_caps_result (query, caps);
2511 GstPad *peer = gst_pad_get_peer (self->srcpad);
2514 res = gst_pad_query (peer, query);
2515 gst_object_unref (peer);
2526 static GstStateChangeReturn
2527 gst_deinterlace_change_state (GstElement * element, GstStateChange transition)
2529 GstStateChangeReturn ret;
2530 GstDeinterlace *self = GST_DEINTERLACE (element);
2532 switch (transition) {
2533 case GST_STATE_CHANGE_NULL_TO_READY:
2535 case GST_STATE_CHANGE_READY_TO_PAUSED:
2537 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
2543 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
2544 if (ret != GST_STATE_CHANGE_SUCCESS)
2547 switch (transition) {
2548 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
2550 case GST_STATE_CHANGE_PAUSED_TO_READY:
2551 gst_deinterlace_reset (self);
2553 case GST_STATE_CHANGE_READY_TO_NULL:
2562 gst_deinterlace_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
2564 GstDeinterlace *self = GST_DEINTERLACE (parent);
2567 GST_DEBUG_OBJECT (pad, "received %s event", GST_EVENT_TYPE_NAME (event));
2569 switch (GST_EVENT_TYPE (event)) {
2570 case GST_EVENT_QOS:{
2571 GstClockTimeDiff diff;
2572 GstClockTime timestamp;
2576 gst_event_parse_qos (event, &type, &proportion, &diff, ×tamp);
2578 gst_deinterlace_update_qos (self, proportion, diff, timestamp);
2582 res = gst_pad_push_event (self->sinkpad, event);
2590 gst_deinterlace_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
2592 GstDeinterlace *self = GST_DEINTERLACE (parent);
2593 gboolean res = FALSE;
2595 GST_LOG_OBJECT (pad, "%s query", GST_QUERY_TYPE_NAME (query));
2597 switch (GST_QUERY_TYPE (query)) {
2598 case GST_QUERY_LATENCY:
2599 if (!self->passthrough) {
2600 GstClockTime min, max;
2604 if ((peer = gst_pad_get_peer (self->sinkpad))) {
2605 if ((res = gst_pad_query (peer, query))) {
2606 GstClockTime latency;
2607 gint fields_required = 0;
2608 gint method_latency = 0;
2612 gst_deinterlace_method_get_fields_required (self->method);
2614 gst_deinterlace_method_get_latency (self->method);
2617 gst_query_parse_latency (query, &live, &min, &max);
2619 GST_DEBUG_OBJECT (self, "Peer latency: min %"
2620 GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
2621 GST_TIME_ARGS (min), GST_TIME_ARGS (max));
2623 /* add our own latency */
2624 latency = (fields_required + method_latency) * self->field_duration;
2626 GST_DEBUG_OBJECT (self, "Our latency: min %" GST_TIME_FORMAT
2627 ", max %" GST_TIME_FORMAT,
2628 GST_TIME_ARGS (latency), GST_TIME_ARGS (latency));
2631 if (max != GST_CLOCK_TIME_NONE)
2634 GST_DEBUG_OBJECT (self, "Calculated total latency : min %"
2635 GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
2636 GST_TIME_ARGS (min), GST_TIME_ARGS (max));
2638 gst_query_set_latency (query, live, min, max);
2640 gst_object_unref (peer);
2647 GstPad *peer = gst_pad_get_peer (self->sinkpad);
2650 res = gst_pad_query (peer, query);
2651 gst_object_unref (peer);
2662 /* FIXME: buffer alloc */
2664 static GstFlowReturn
2665 gst_deinterlace_alloc_buffer (GstPad * pad, guint64 offset, guint size,
2666 GstCaps * caps, GstBuffer ** buf)
2668 GstDeinterlace *self = GST_DEINTERLACE (gst_pad_get_parent (pad));
2669 GstFlowReturn ret = GST_FLOW_OK;
2673 GST_DEBUG_OBJECT (pad, "alloc with caps %" GST_PTR_FORMAT ", size %u", caps,
2676 if (self->still_frame_mode || self->passthrough) {
2677 ret = gst_pad_alloc_buffer (self->srcpad, offset, size, caps, buf);
2678 } else if (G_LIKELY (!self->request_caps)) {
2679 *buf = gst_buffer_try_new_and_alloc (size);
2680 if (G_UNLIKELY (!*buf)) {
2681 ret = GST_FLOW_ERROR;
2683 gst_buffer_set_caps (*buf, caps);
2684 GST_BUFFER_OFFSET (*buf) = offset;
2689 guint new_frame_size;
2690 GstCaps *new_caps = gst_caps_copy (self->request_caps);
2692 if (self->fields == GST_DEINTERLACE_ALL) {
2694 GstStructure *s = gst_caps_get_structure (new_caps, 0);
2696 gst_structure_get_fraction (s, "framerate", &n, &d);
2698 if (!gst_fraction_double (&n, &d, TRUE)) {
2699 gst_object_unref (self);
2700 gst_caps_unref (new_caps);
2704 gst_structure_set (s, "framerate", GST_TYPE_FRACTION, n, d, NULL);
2707 if (G_UNLIKELY (!gst_video_format_parse_caps (new_caps, &fmt, &width,
2709 gst_object_unref (self);
2710 gst_caps_unref (new_caps);
2714 new_frame_size = gst_video_format_get_size (fmt, width, height);
2716 *buf = gst_buffer_try_new_and_alloc (new_frame_size);
2717 if (G_UNLIKELY (!*buf)) {
2718 ret = GST_FLOW_ERROR;
2720 gst_buffer_set_caps (*buf, new_caps);
2721 gst_caps_unref (self->request_caps);
2722 self->request_caps = NULL;
2723 gst_caps_unref (new_caps);
2727 gst_object_unref (self);
2734 plugin_init (GstPlugin * plugin)
2736 GST_DEBUG_CATEGORY_INIT (deinterlace_debug, "deinterlace", 0, "Deinterlacer");
2742 if (!gst_element_register (plugin, "deinterlace", GST_RANK_NONE,
2743 GST_TYPE_DEINTERLACE)) {
2750 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
2753 "Deinterlacer", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
2754 GST_PACKAGE_ORIGIN);