8a8df723cec45a8a9f86aa964b9067c2d6b3816c
[platform/upstream/gstreamer.git] / gst / vaapi / gstvaapipostproc.h
1 /*
2  *  gstvaapipostproc.h - VA-API video post processing
3  *
4  *  Copyright (C) 2012-2014 Intel Corporation
5  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
6  *
7  *  This program is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU Lesser General Public License
9  *  as published by the Free Software Foundation; either version 2.1
10  *  of the License, or (at your option) any later version.
11  *
12  *  This program 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  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public
18  *  License along with this program; if not, write to the Free
19  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  *  Boston, MA 02110-1301 USA
21 */
22
23 #ifndef GST_VAAPIPOSTPROC_H
24 #define GST_VAAPIPOSTPROC_H
25
26 #include "gstvaapipluginbase.h"
27 #include <gst/vaapi/gstvaapisurface.h>
28 #include <gst/vaapi/gstvaapisurfacepool.h>
29 #include <gst/vaapi/gstvaapifilter.h>
30
31 G_BEGIN_DECLS
32
33 #define GST_TYPE_VAAPIPOSTPROC \
34   (gst_vaapipostproc_get_type ())
35 #define GST_VAAPIPOSTPROC(obj) \
36   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VAAPIPOSTPROC, GstVaapiPostproc))
37 #define GST_VAAPIPOSTPROC_CLASS(klass) \
38   (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VAAPIPOSTPROC, \
39        GstVaapiPostprocClass))
40 #define GST_IS_VAAPIPOSTPROC(obj) \
41   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VAAPIPOSTPROC))
42 #define GST_IS_VAAPIPOSTPROC_CLASS(klass) \
43   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VAAPIPOSTPROC))
44 #define GST_VAAPIPOSTPROC_GET_CLASS(obj) \
45   (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_VAAPIPOSTPROC, \
46        GstVaapiPostprocClass))
47
48 typedef struct _GstVaapiPostproc GstVaapiPostproc;
49 typedef struct _GstVaapiPostprocClass GstVaapiPostprocClass;
50 typedef struct _GstVaapiDeinterlaceState GstVaapiDeinterlaceState;
51
52 /**
53  * GstVaapiDeinterlaceMode:
54  * @GST_VAAPI_DEINTERLACE_MODE_AUTO: Auto detect needs for deinterlacing.
55  * @GST_VAAPI_DEINTERLACE_MODE_INTERLACED: Force deinterlacing.
56  * @GST_VAAPI_DEINTERLACE_MODE_DISABLED: Never perform deinterlacing.
57  */
58 typedef enum
59 {
60   GST_VAAPI_DEINTERLACE_MODE_AUTO = 0,
61   GST_VAAPI_DEINTERLACE_MODE_INTERLACED,
62   GST_VAAPI_DEINTERLACE_MODE_DISABLED,
63 } GstVaapiDeinterlaceMode;
64
65 /*
66  * GST_VAAPI_DEINTERLACE_MAX_REFERENCES:
67  *
68  * This represents the maximum number of VA surfaces we could keep as
69  * references for advanced deinterlacing.
70  *
71  * Note: if the upstream element is vaapidecode, then the maximum
72  * number of allowed surfaces used as references shall be less than
73  * the actual number of scratch surfaces used for decoding (4).
74  */
75 #define GST_VAAPI_DEINTERLACE_MAX_REFERENCES 2
76
77 /**
78  * GstVaapiPostprocFlags:
79  * @GST_VAAPI_POSTPROC_FLAG_FORMAT: Pixel format conversion.
80  * @GST_VAAPI_POSTPROC_FLAG_DENOISE: Noise reduction.
81  * @GST_VAAPI_POSTPROC_FLAG_SHARPEN: Sharpening.
82  * @GST_VAAPI_POSTPROC_FLAG_HUE: Change color hue.
83  * @GST_VAAPI_POSTPROC_FLAG_SATURATION: Change saturation.
84  * @GST_VAAPI_POSTPROC_FLAG_BRIGHTNESS: Change brightness.
85  * @GST_VAAPI_POSTPROC_FLAG_CONTRAST: Change contrast.
86  * @GST_VAAPI_POSTPROC_FLAG_DEINTERLACE: Deinterlacing.
87  * @GST_VAAPI_POSTPROC_FLAG_SIZE: Video scaling.
88  * @GST_VAAPI_POSTPROC_FLAG_SCALE: Video scaling mode.
89  * @GST_VAAPI_POSTPROC_FLAG_VIDEO_DIRECTION: Video rotation and flip/mirroring.
90  * @GST_VAAPI_POSTPROC_FLAG_SKINTONE: Skin tone enhancement.
91  *
92  * The set of operations that are to be performed for each frame.
93  */
94 typedef enum
95 {
96   GST_VAAPI_POSTPROC_FLAG_FORMAT      = 1 << GST_VAAPI_FILTER_OP_FORMAT,
97   GST_VAAPI_POSTPROC_FLAG_DENOISE     = 1 << GST_VAAPI_FILTER_OP_DENOISE,
98   GST_VAAPI_POSTPROC_FLAG_SHARPEN     = 1 << GST_VAAPI_FILTER_OP_SHARPEN,
99   GST_VAAPI_POSTPROC_FLAG_HUE         = 1 << GST_VAAPI_FILTER_OP_HUE,
100   GST_VAAPI_POSTPROC_FLAG_SATURATION  = 1 << GST_VAAPI_FILTER_OP_SATURATION,
101   GST_VAAPI_POSTPROC_FLAG_BRIGHTNESS  = 1 << GST_VAAPI_FILTER_OP_BRIGHTNESS,
102   GST_VAAPI_POSTPROC_FLAG_CONTRAST    = 1 << GST_VAAPI_FILTER_OP_CONTRAST,
103   GST_VAAPI_POSTPROC_FLAG_DEINTERLACE = 1 << GST_VAAPI_FILTER_OP_DEINTERLACING,
104   GST_VAAPI_POSTPROC_FLAG_SCALE       = 1 << GST_VAAPI_FILTER_OP_SCALING,
105   GST_VAAPI_POSTPROC_FLAG_VIDEO_DIRECTION =
106       1 << GST_VAAPI_FILTER_OP_VIDEO_DIRECTION,
107   GST_VAAPI_POSTPROC_FLAG_CROP        = 1 << GST_VAAPI_FILTER_OP_CROP,
108   GST_VAAPI_POSTPROC_FLAG_SKINTONE    = 1 << GST_VAAPI_FILTER_OP_SKINTONE,
109
110   /* Additional custom flags */
111   GST_VAAPI_POSTPROC_FLAG_CUSTOM      = 1 << 20,
112   GST_VAAPI_POSTPROC_FLAG_SIZE        = GST_VAAPI_POSTPROC_FLAG_CUSTOM,
113 } GstVaapiPostprocFlags;
114
115 /*
116  * GstVaapiDeinterlaceState:
117  * @buffers: history buffer, maintained as a cyclic array
118  * @buffers_index: next free slot in the history buffer
119  * @surfaces: array of surfaces used as references
120  * @num_surfaces: number of active surfaces in that array
121  * @deint: flag: previous buffers were interlaced?
122  * @tff: flag: previous buffers were organized as top-field-first?
123  *
124  * Context used to maintain deinterlacing state.
125  */
126 struct _GstVaapiDeinterlaceState
127 {
128   GstBuffer *buffers[GST_VAAPI_DEINTERLACE_MAX_REFERENCES];
129   guint buffers_index;
130   GstVaapiSurface *surfaces[GST_VAAPI_DEINTERLACE_MAX_REFERENCES];
131   guint num_surfaces;
132   guint deint:1;
133   guint tff:1;
134 };
135
136 struct _GstVaapiPostproc
137 {
138   /*< private >*/
139   GstVaapiPluginBase parent_instance;
140
141   GMutex postproc_lock;
142   GstVaapiFilter *filter;
143   GPtrArray *filter_ops;
144   GstVaapiVideoPool *filter_pool;
145   GstVideoInfo filter_pool_info;
146   GArray *filter_formats;
147   GstVideoFormat format;        /* output video format (encoded) */
148   guint width;
149   guint height;
150   guint flags;
151
152   GstCaps *allowed_sinkpad_caps;
153   GstVideoInfo sinkpad_info;
154   GstCaps *allowed_srcpad_caps;
155   GstVideoInfo srcpad_info;
156
157   /* Deinterlacing */
158   GstVaapiDeinterlaceMode deinterlace_mode;
159   GstVaapiDeinterlaceMethod deinterlace_method;
160   GstVaapiDeinterlaceState deinterlace_state;
161   GstClockTime field_duration;
162
163   /* Basic filter values */
164   gfloat denoise_level;
165   gfloat sharpen_level;
166
167   GstVaapiScaleMethod scale_method;
168
169   GstVideoOrientationMethod video_direction;
170   GstVideoOrientationMethod tag_video_direction;
171
172   /* Cropping */
173   guint crop_left;
174   guint crop_right;
175   guint crop_top;
176   guint crop_bottom;
177
178   /* Color balance filter values */
179   gfloat hue;
180   gfloat saturation;
181   gfloat brightness;
182   gfloat contrast;
183
184   gboolean skintone_enhance;
185   gboolean forward_crop;
186
187   guint get_va_surfaces:1;
188   guint has_vpp:1;
189   guint use_vpp:1;
190   guint keep_aspect:1;
191
192   /* color balance's channel list */
193   GList *cb_channels;
194   gboolean same_caps;
195 };
196
197 struct _GstVaapiPostprocClass
198 {
199   /*< private >*/
200   GstVaapiPluginBaseClass parent_class;
201 };
202
203 GType
204 gst_vaapipostproc_get_type (void) G_GNUC_CONST;
205
206 G_END_DECLS
207
208 #endif /* GST_VAAPIPOSTPROC_H */