3b81830da6392780aa688934366c464a6fd00135
[profile/ivi/gstreamer-vaapi.git] / gst / vaapi / gstvaapipostproc.c
1 /*
2  *  gstvaapipostproc.c - VA-API video postprocessing
3  *
4  *  Copyright (C) 2012 Intel Corporation
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public License
8  *  as published by the Free Software Foundation; either version 2.1
9  *  of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301 USA
20  */
21
22 /**
23  * SECTION:gstvaapipostproc
24  * @short_description: A video postprocessing filter
25  *
26  * vaapipostproc consists in various postprocessing algorithms to be
27  * applied to VA surfaces. So far, only basic bob deinterlacing is
28  * implemented.
29  */
30
31 #include "config.h"
32 #include <gst/video/video.h>
33 #include <gst/video/videocontext.h>
34 #include <gst/vaapi/gstvaapivideosink.h>
35 #include <gst/vaapi/gstvaapivideobuffer.h>
36
37 #include "gstvaapipluginutil.h"
38 #include "gstvaapipostproc.h"
39
40 #define GST_PLUGIN_NAME "vaapipostproc"
41 #define GST_PLUGIN_DESC "A video postprocessing filter"
42
43 GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapipostproc);
44 #define GST_CAT_DEFAULT gst_debug_vaapipostproc
45
46 /* ElementFactory information */
47 static const GstElementDetails gst_vaapipostproc_details =
48     GST_ELEMENT_DETAILS(
49         "VA-API video postprocessing",
50         "Filter/Converter/Video",
51         GST_PLUGIN_DESC,
52         "Gwenole Beauchesne <gwenole.beauchesne@intel.com>");
53
54 /* Default templates */
55 static const char gst_vaapipostproc_sink_caps_str[] =
56     GST_VAAPI_SURFACE_CAPS ", "
57     "interlaced = (boolean) { true, false }";
58
59 static const char gst_vaapipostproc_src_caps_str[] =
60     GST_VAAPI_SURFACE_CAPS ", "
61     "interlaced = (boolean) false";
62
63 static GstStaticPadTemplate gst_vaapipostproc_sink_factory =
64     GST_STATIC_PAD_TEMPLATE(
65         "sink",
66         GST_PAD_SINK,
67         GST_PAD_ALWAYS,
68         GST_STATIC_CAPS(gst_vaapipostproc_sink_caps_str));
69
70 static GstStaticPadTemplate gst_vaapipostproc_src_factory =
71     GST_STATIC_PAD_TEMPLATE(
72         "src",
73         GST_PAD_SRC,
74         GST_PAD_ALWAYS,
75         GST_STATIC_CAPS(gst_vaapipostproc_src_caps_str));
76
77 static void
78 gst_vaapipostproc_implements_iface_init(GstImplementsInterfaceClass *iface);
79
80 static void
81 gst_video_context_interface_init(GstVideoContextInterface *iface);
82
83 #define GstVideoContextClass GstVideoContextInterface
84 G_DEFINE_TYPE_WITH_CODE(
85     GstVaapiPostproc,
86     gst_vaapipostproc,
87     GST_TYPE_ELEMENT,
88     G_IMPLEMENT_INTERFACE(GST_TYPE_IMPLEMENTS_INTERFACE,
89                           gst_vaapipostproc_implements_iface_init);
90     G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT,
91                           gst_video_context_interface_init));
92
93 enum {
94     PROP_0,
95
96     PROP_DEINTERLACE_MODE,
97     PROP_DEINTERLACE_METHOD,
98 };
99
100 #define DEFAULT_DEINTERLACE_MODE        GST_VAAPI_DEINTERLACE_MODE_AUTO
101 #define DEFAULT_DEINTERLACE_METHOD      GST_VAAPI_DEINTERLACE_METHOD_BOB
102
103 #define GST_TYPE_VAAPI_DEINTERLACE_MODES \
104     gst_vaapi_deinterlace_modes_get_type()
105
106 static GType
107 gst_vaapi_deinterlace_modes_get_type(void)
108 {
109     static GType deinterlace_modes_type = 0;
110
111     static const GEnumValue modes_types[] = {
112         { GST_VAAPI_DEINTERLACE_MODE_AUTO,
113           "Auto detection", "auto" },
114         { GST_VAAPI_DEINTERLACE_MODE_INTERLACED,
115           "Force deinterlacing", "interlaced" },
116         { GST_VAAPI_DEINTERLACE_MODE_DISABLED,
117           "Never deinterlace", "disabled" },
118         { 0, NULL, NULL },
119     };
120
121     if (!deinterlace_modes_type) {
122         deinterlace_modes_type =
123             g_enum_register_static("GstVaapiDeinterlaceModes", modes_types);
124     }
125     return deinterlace_modes_type;
126 }
127
128 #define GST_TYPE_VAAPI_DEINTERLACE_METHODS \
129     gst_vaapi_deinterlace_methods_get_type()
130
131 static GType
132 gst_vaapi_deinterlace_methods_get_type(void)
133 {
134     static GType deinterlace_methods_type = 0;
135
136     static const GEnumValue methods_types[] = {
137         { GST_VAAPI_DEINTERLACE_METHOD_BOB,
138           "Bob deinterlacing", "bob" },
139 #if 0
140         /* VA/VPP */
141         { GST_VAAPI_DEINTERLACE_METHOD_WEAVE,
142           "Weave deinterlacing", "weave" },
143         { GST_VAAPI_DEINTERLACE_METHOD_MOTION_ADAPTIVE,
144           "Motion adaptive deinterlacing", "motion-adaptive" },
145         { GST_VAAPI_DEINTERLACE_METHOD_MOTION_COMPENSATED,
146           "Motion compensated deinterlacing", "motion-compensated" },
147 #endif
148         { 0, NULL, NULL },
149     };
150
151     if (!deinterlace_methods_type) {
152         deinterlace_methods_type =
153             g_enum_register_static("GstVaapiDeinterlaceMethods", methods_types);
154     }
155     return deinterlace_methods_type;
156 }
157
158 static inline GstVaapiPostproc *
159 get_vaapipostproc_from_pad(GstPad *pad)
160 {
161     return GST_VAAPIPOSTPROC(gst_pad_get_parent_element(pad));
162 }
163
164 /* GstImplementsInterface interface */
165
166 static gboolean
167 gst_vaapipostproc_implements_interface_supported(
168     GstImplementsInterface *iface,
169     GType                   type
170 )
171 {
172     return (type == GST_TYPE_VIDEO_CONTEXT);
173 }
174
175 static void
176 gst_vaapipostproc_implements_iface_init(GstImplementsInterfaceClass *iface)
177 {
178     iface->supported = gst_vaapipostproc_implements_interface_supported;
179 }
180
181 /* GstVideoContext interface */
182
183 static void
184 gst_vaapipostproc_set_video_context(
185     GstVideoContext *context,
186     const gchar     *type,
187     const GValue    *value
188 )
189 {
190     GstVaapiPostproc * const postproc = GST_VAAPIPOSTPROC(context);
191
192     gst_vaapi_set_display(type, value, &postproc->display);
193 }
194
195 static void
196 gst_video_context_interface_init(GstVideoContextInterface *iface)
197 {
198     iface->set_context = gst_vaapipostproc_set_video_context;
199 }
200
201 static gboolean
202 gst_vaapipostproc_create(GstVaapiPostproc *postproc, GstCaps *caps)
203 {
204     if (!gst_vaapi_ensure_display(postproc, &postproc->display))
205         return FALSE;
206
207     gst_caps_replace(&postproc->postproc_caps, caps);
208     return TRUE;
209 }
210
211 static void
212 gst_vaapipostproc_destroy(GstVaapiPostproc *postproc)
213 {
214     gst_caps_replace(&postproc->postproc_caps, NULL);
215
216     g_clear_object(&postproc->display);
217 }
218
219 static gboolean
220 gst_vaapipostproc_reset(GstVaapiPostproc *postproc, GstCaps *caps)
221 {
222     if (postproc->postproc_caps &&
223         gst_caps_is_always_compatible(caps, postproc->postproc_caps))
224         return TRUE;
225
226     gst_vaapipostproc_destroy(postproc);
227     return gst_vaapipostproc_create(postproc, caps);
228 }
229
230 static gboolean
231 gst_vaapipostproc_start(GstVaapiPostproc *postproc)
232 {
233     if (!gst_vaapi_ensure_display(postproc, &postproc->display))
234         return FALSE;
235     return TRUE;
236 }
237
238 static gboolean
239 gst_vaapipostproc_stop(GstVaapiPostproc *postproc)
240 {
241     if (postproc->display) {
242         g_object_unref(postproc->display);
243         postproc->display = NULL;
244     }
245     return TRUE;
246 }
247
248 static GstFlowReturn
249 gst_vaapipostproc_process(GstVaapiPostproc *postproc, GstBuffer *buf)
250 {
251     GstVaapiVideoBuffer *vbuf = GST_VAAPI_VIDEO_BUFFER(buf);
252     GstVaapiSurfaceProxy *proxy;
253     GstClockTime timestamp;
254     GstFlowReturn ret;
255     GstBuffer *outbuf = NULL;
256     guint outbuf_flags, flags;
257     gboolean interlaced, tff;
258
259     flags = gst_vaapi_video_buffer_get_render_flags(vbuf);
260
261     /* Deinterlacing disabled, push frame */
262     if (!postproc->deinterlace) {
263         gst_vaapi_video_buffer_set_render_flags(vbuf, flags);
264         ret = gst_pad_push(postproc->srcpad, buf);
265         if (ret != GST_FLOW_OK)
266             goto error_push_buffer;
267         return GST_FLOW_OK;
268     }
269
270     timestamp  = GST_BUFFER_TIMESTAMP(buf);
271     proxy      = gst_vaapi_video_buffer_get_surface_proxy(vbuf);
272     interlaced = gst_vaapi_surface_proxy_get_interlaced(proxy);
273     tff        = gst_vaapi_surface_proxy_get_tff(proxy);
274
275     flags &= ~(GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD|
276                GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD);
277
278     /* First field */
279     outbuf = gst_vaapi_video_buffer_new_with_surface_proxy(proxy);
280     if (!outbuf)
281         goto error_create_buffer;
282
283     vbuf = GST_VAAPI_VIDEO_BUFFER(outbuf);
284     outbuf_flags = flags;
285     outbuf_flags |= interlaced ? (
286         tff ?
287         GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD :
288         GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD) :
289         GST_VAAPI_PICTURE_STRUCTURE_FRAME;
290     gst_vaapi_video_buffer_set_render_flags(vbuf, outbuf_flags);
291
292     GST_BUFFER_TIMESTAMP(outbuf) = timestamp;
293     GST_BUFFER_DURATION(outbuf)  = postproc->field_duration;
294     gst_buffer_set_caps(outbuf, postproc->srcpad_caps);
295     ret = gst_pad_push(postproc->srcpad, outbuf);
296     if (ret != GST_FLOW_OK)
297         goto error_push_buffer;
298
299     /* Second field */
300     outbuf = gst_vaapi_video_buffer_new_with_surface_proxy(proxy);
301     if (!outbuf)
302         goto error_create_buffer;
303
304     vbuf = GST_VAAPI_VIDEO_BUFFER(outbuf);
305     outbuf_flags = flags;
306     outbuf_flags |= interlaced ? (
307         tff ?
308         GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD :
309         GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD) :
310         GST_VAAPI_PICTURE_STRUCTURE_FRAME;
311     gst_vaapi_video_buffer_set_render_flags(vbuf, outbuf_flags);
312
313     GST_BUFFER_TIMESTAMP(outbuf) = timestamp + postproc->field_duration;
314     GST_BUFFER_DURATION(outbuf)  = postproc->field_duration;
315     gst_buffer_set_caps(outbuf, postproc->srcpad_caps);
316     ret = gst_pad_push(postproc->srcpad, outbuf);
317     if (ret != GST_FLOW_OK)
318         goto error_push_buffer;
319
320     gst_buffer_unref(buf);
321     return GST_FLOW_OK;
322
323     /* ERRORS */
324 error_create_buffer:
325     {
326         GST_ERROR("failed to create output buffer");
327         gst_buffer_unref(buf);
328         return GST_FLOW_UNEXPECTED;
329     }
330 error_push_buffer:
331     {
332         if (ret != GST_FLOW_WRONG_STATE)
333             GST_ERROR("failed to push output buffer to video sink");
334         gst_buffer_unref(buf);
335         return GST_FLOW_UNEXPECTED;
336     }
337 }
338
339 static gboolean
340 gst_vaapipostproc_update_sink_caps(GstVaapiPostproc *postproc, GstCaps *caps)
341 {
342     gint fps_n, fps_d;
343     gboolean interlaced;
344
345     if (!gst_video_parse_caps_framerate(caps, &fps_n, &fps_d))
346         return FALSE;
347     postproc->fps_n = fps_n;
348     postproc->fps_d = fps_d;
349
350     switch (postproc->deinterlace_mode) {
351     case GST_VAAPI_DEINTERLACE_MODE_AUTO:
352         if (!gst_video_format_parse_caps_interlaced(caps, &interlaced))
353             return FALSE;
354         postproc->deinterlace = interlaced;
355         break;
356     case GST_VAAPI_DEINTERLACE_MODE_INTERLACED:
357         postproc->deinterlace = TRUE;
358         break;
359     case GST_VAAPI_DEINTERLACE_MODE_DISABLED:
360         postproc->deinterlace = FALSE;
361         break;
362     }
363
364     postproc->field_duration = gst_util_uint64_scale(
365         GST_SECOND,
366         postproc->fps_d,
367         (1 + postproc->deinterlace) * postproc->fps_n
368     );
369
370     gst_caps_replace(&postproc->sinkpad_caps, caps);
371     return TRUE;
372 }
373
374 static gboolean
375 gst_vaapipostproc_update_src_caps(GstVaapiPostproc *postproc, GstCaps *caps)
376 {
377     GstCaps *src_caps;
378     GstStructure *structure;
379     const GValue *v_width, *v_height, *v_par;
380     gint fps_n, fps_d;
381
382     if (postproc->srcpad_caps)
383         src_caps = gst_caps_make_writable(postproc->srcpad_caps);
384     else
385         src_caps = gst_caps_from_string(GST_VAAPI_SURFACE_CAPS_NAME);
386     if (!src_caps)
387         return FALSE;
388     postproc->srcpad_caps = src_caps;
389
390     structure    = gst_caps_get_structure(caps, 0);
391     v_width      = gst_structure_get_value(structure, "width");
392     v_height     = gst_structure_get_value(structure, "height");
393     v_par        = gst_structure_get_value(structure, "pixel-aspect-ratio");
394
395     structure = gst_caps_get_structure(src_caps, 0);
396     if (v_width && v_height) {
397         gst_structure_set_value(structure, "width", v_width);
398         gst_structure_set_value(structure, "height", v_height);
399     }
400     if (v_par)
401         gst_structure_set_value(structure, "pixel-aspect-ratio", v_par);
402
403     gst_structure_set(structure, "type", G_TYPE_STRING, "vaapi", NULL);
404     gst_structure_set(structure, "opengl", G_TYPE_BOOLEAN, USE_GLX, NULL);
405
406     if (!postproc->deinterlace)
407         gst_structure_remove_field(structure, "interlaced");
408     else {
409         /* Set double framerate in interlaced mode */
410         if (!gst_util_fraction_multiply(postproc->fps_n, postproc->fps_d,
411                                         2, 1,
412                                         &fps_n, &fps_d))
413             return FALSE;
414
415         gst_structure_set(
416             structure,
417             "interlaced", G_TYPE_BOOLEAN, FALSE,
418             "framerate", GST_TYPE_FRACTION, fps_n, fps_d,
419             NULL
420         );
421     }
422     return gst_pad_set_caps(postproc->srcpad, src_caps);
423 }
424
425 static gboolean
426 gst_vaapipostproc_ensure_allowed_caps(GstVaapiPostproc *postproc)
427 {
428     if (postproc->allowed_caps)
429         return TRUE;
430
431     postproc->allowed_caps =
432         gst_caps_from_string(gst_vaapipostproc_sink_caps_str);
433     if (!postproc->allowed_caps)
434         return FALSE;
435
436     /* XXX: append VA/VPP filters */
437     return TRUE;
438 }
439
440 static GstCaps *
441 gst_vaapipostproc_get_caps(GstPad *pad)
442 {
443     GstVaapiPostproc * const postproc = get_vaapipostproc_from_pad(pad);
444     GstCaps *out_caps;
445
446     if (gst_vaapipostproc_ensure_allowed_caps(postproc))
447         out_caps = gst_caps_ref(postproc->allowed_caps);
448     else
449         out_caps = gst_caps_new_empty();
450
451     gst_object_unref(postproc);
452     return out_caps;
453 }
454
455 static gboolean
456 gst_vaapipostproc_set_caps(GstPad *pad, GstCaps *caps)
457 {
458     GstVaapiPostproc * const postproc = get_vaapipostproc_from_pad(pad);
459     gboolean success = FALSE;
460
461     g_return_val_if_fail(pad == postproc->sinkpad, FALSE);
462
463     do {
464         if (!gst_vaapipostproc_update_sink_caps(postproc, caps))
465             break;
466         if (!gst_vaapipostproc_update_src_caps(postproc, caps))
467             break;
468         if (!gst_vaapipostproc_reset(postproc, postproc->sinkpad_caps))
469             break;
470         success = TRUE;
471     } while (0);
472     gst_object_unref(postproc);
473     return success;
474 }
475
476 static GstFlowReturn
477 gst_vaapipostproc_chain(GstPad *pad, GstBuffer *buf)
478 {
479     GstVaapiPostproc * const postproc = get_vaapipostproc_from_pad(pad);
480     GstFlowReturn ret;
481
482     ret = gst_vaapipostproc_process(postproc, buf);
483     gst_object_unref(postproc);
484     return ret;
485 }
486
487 static gboolean
488 gst_vaapipostproc_sink_event(GstPad *pad, GstEvent *event)
489 {
490     GstVaapiPostproc * const postproc = get_vaapipostproc_from_pad(pad);
491     gboolean success;
492
493     GST_DEBUG("handle sink event '%s'", GST_EVENT_TYPE_NAME(event));
494
495     /* Propagate event downstream */
496     success = gst_pad_push_event(postproc->srcpad, event);
497     gst_object_unref(postproc);
498     return success;
499 }
500
501 static gboolean
502 gst_vaapipostproc_src_event(GstPad *pad, GstEvent *event)
503 {
504     GstVaapiPostproc * const postproc = get_vaapipostproc_from_pad(pad);
505     gboolean success;
506
507     GST_DEBUG("handle src event '%s'", GST_EVENT_TYPE_NAME(event));
508
509     /* Propagate event upstream */
510     success = gst_pad_push_event(postproc->sinkpad, event);
511     gst_object_unref(postproc);
512     return success;
513 }
514
515 static gboolean
516 gst_vaapipostproc_query(GstPad *pad, GstQuery *query)
517 {
518     GstVaapiPostproc * const postproc = get_vaapipostproc_from_pad(pad);
519     gboolean success;
520
521     GST_DEBUG("sharing display %p", postproc->display);
522
523     if (gst_vaapi_reply_to_query(query, postproc->display))
524         success = TRUE;
525     else
526         success = gst_pad_query_default(pad, query);
527
528     gst_object_unref(postproc);
529     return success;
530 }
531
532 static void
533 gst_vaapipostproc_finalize(GObject *object)
534 {
535     GstVaapiPostproc * const postproc = GST_VAAPIPOSTPROC(object);
536
537     gst_vaapipostproc_destroy(postproc);
538
539     gst_caps_replace(&postproc->sinkpad_caps, NULL);
540     gst_caps_replace(&postproc->srcpad_caps,  NULL);
541     gst_caps_replace(&postproc->allowed_caps, NULL);
542
543     G_OBJECT_CLASS(gst_vaapipostproc_parent_class)->finalize(object);
544 }
545
546 static void
547 gst_vaapipostproc_set_property(
548     GObject      *object,
549     guint         prop_id,
550     const GValue *value,
551     GParamSpec   *pspec
552 )
553 {
554     GstVaapiPostproc * const postproc = GST_VAAPIPOSTPROC(object);
555
556     switch (prop_id) {
557     case PROP_DEINTERLACE_MODE:
558         postproc->deinterlace_mode = g_value_get_enum(value);
559         break;
560     case PROP_DEINTERLACE_METHOD:
561         postproc->deinterlace_method = g_value_get_enum(value);
562         break;
563     default:
564         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
565         break;
566     }
567 }
568
569 static void
570 gst_vaapipostproc_get_property(
571     GObject    *object,
572     guint       prop_id,
573     GValue     *value,
574     GParamSpec *pspec
575 )
576 {
577     GstVaapiPostproc * const postproc = GST_VAAPIPOSTPROC(object);
578
579     switch (prop_id) {
580     case PROP_DEINTERLACE_MODE:
581         g_value_set_enum(value, postproc->deinterlace_mode);
582         break;
583     case PROP_DEINTERLACE_METHOD:
584         g_value_set_enum(value, postproc->deinterlace_method);
585         break;
586     default:
587         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
588         break;
589     }
590 }
591
592 static GstStateChangeReturn
593 gst_vaapipostproc_change_state(GstElement *element, GstStateChange transition)
594 {
595     GstVaapiPostproc * const postproc = GST_VAAPIPOSTPROC(element);
596     GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
597
598     switch (transition) {
599     case GST_STATE_CHANGE_NULL_TO_READY:
600         if (!gst_vaapipostproc_start(postproc))
601             return GST_STATE_CHANGE_FAILURE;
602         break;
603     case GST_STATE_CHANGE_READY_TO_PAUSED:
604         break;
605     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
606         break;
607     default:
608         break;
609     }
610
611     ret = GST_ELEMENT_CLASS(gst_vaapipostproc_parent_class)->change_state(element, transition);
612     if (ret != GST_STATE_CHANGE_SUCCESS)
613         return ret;
614
615     switch (transition) {
616     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
617         break;
618     case GST_STATE_CHANGE_PAUSED_TO_READY:
619         break;
620     case GST_STATE_CHANGE_READY_TO_NULL:
621         if (!gst_vaapipostproc_stop(postproc))
622             return GST_STATE_CHANGE_FAILURE;
623         break;
624     default:
625         break;
626     }
627     return GST_STATE_CHANGE_SUCCESS;
628 }
629
630 static void
631 gst_vaapipostproc_class_init(GstVaapiPostprocClass *klass)
632 {
633     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
634     GstElementClass * const element_class = GST_ELEMENT_CLASS(klass);
635     GstPadTemplate *pad_template;
636
637     GST_DEBUG_CATEGORY_INIT(gst_debug_vaapipostproc,
638                             GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
639
640     object_class->finalize      = gst_vaapipostproc_finalize;
641     object_class->set_property  = gst_vaapipostproc_set_property;
642     object_class->get_property  = gst_vaapipostproc_get_property;
643
644     element_class->change_state = gst_vaapipostproc_change_state;
645
646     gst_element_class_set_details_simple(
647         element_class,
648         gst_vaapipostproc_details.longname,
649         gst_vaapipostproc_details.klass,
650         gst_vaapipostproc_details.description,
651         gst_vaapipostproc_details.author
652     );
653
654     /* sink pad */
655     pad_template = gst_static_pad_template_get(&gst_vaapipostproc_sink_factory);
656     gst_element_class_add_pad_template(element_class, pad_template);
657     gst_object_unref(pad_template);
658
659     /* src pad */
660     pad_template = gst_static_pad_template_get(&gst_vaapipostproc_src_factory);
661     gst_element_class_add_pad_template(element_class, pad_template);
662     gst_object_unref(pad_template);
663
664     /**
665      * GstVaapiPostproc:deinterlace-mode:
666      *
667      * This selects whether the deinterlacing should always be applied or if
668      * they should only be applied on content that has the "interlaced" flag
669      * on the caps.
670      */
671     g_object_class_install_property
672         (object_class,
673          PROP_DEINTERLACE_MODE,
674          g_param_spec_enum("deinterlace",
675                            "Deinterlace",
676                            "Deinterlace mode to use",
677                            GST_TYPE_VAAPI_DEINTERLACE_MODES,
678                            DEFAULT_DEINTERLACE_MODE,
679                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
680
681     /**
682      * GstVaapiPostproc:deinterlace-method:
683      *
684      * This selects the deinterlacing method to apply.
685      */
686     g_object_class_install_property
687         (object_class,
688          PROP_DEINTERLACE_METHOD,
689          g_param_spec_enum("deinterlace-method",
690                            "Deinterlace method",
691                            "Deinterlace method to use",
692                            GST_TYPE_VAAPI_DEINTERLACE_METHODS,
693                            DEFAULT_DEINTERLACE_METHOD,
694                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
695 }
696
697 static void
698 gst_vaapipostproc_init(GstVaapiPostproc *postproc)
699 {
700     GstVaapiPostprocClass *klass = GST_VAAPIPOSTPROC_GET_CLASS(postproc);
701     GstElementClass * const element_class = GST_ELEMENT_CLASS(klass);
702
703     postproc->allowed_caps              = NULL;
704     postproc->postproc_caps             = NULL;
705     postproc->display                   = NULL;
706     postproc->surface_width             = 0;
707     postproc->surface_height            = 0;
708     postproc->deinterlace               = FALSE;
709     postproc->deinterlace_mode          = DEFAULT_DEINTERLACE_MODE;
710     postproc->deinterlace_method        = DEFAULT_DEINTERLACE_METHOD;
711     postproc->field_duration            = GST_CLOCK_TIME_NONE;
712     postproc->fps_n                     = 0;
713     postproc->fps_d                     = 0;
714
715     /* Pad through which data comes in to the element */
716     postproc->sinkpad = gst_pad_new_from_template(
717         gst_element_class_get_pad_template(element_class, "sink"),
718         "sink"
719     );
720     postproc->sinkpad_caps = NULL;
721
722     gst_pad_set_getcaps_function(postproc->sinkpad, gst_vaapipostproc_get_caps);
723     gst_pad_set_setcaps_function(postproc->sinkpad, gst_vaapipostproc_set_caps);
724     gst_pad_set_chain_function(postproc->sinkpad, gst_vaapipostproc_chain);
725     gst_pad_set_event_function(postproc->sinkpad, gst_vaapipostproc_sink_event);
726     gst_pad_set_query_function(postproc->sinkpad, gst_vaapipostproc_query);
727     gst_element_add_pad(GST_ELEMENT(postproc), postproc->sinkpad);
728
729     /* Pad through which data goes out of the element */
730     postproc->srcpad = gst_pad_new_from_template(
731         gst_element_class_get_pad_template(element_class, "src"),
732         "src"
733     );
734     postproc->srcpad_caps = NULL;
735
736     gst_pad_set_event_function(postproc->srcpad, gst_vaapipostproc_src_event);
737     gst_pad_set_query_function(postproc->srcpad, gst_vaapipostproc_query);
738     gst_element_add_pad(GST_ELEMENT(postproc), postproc->srcpad);
739 }