encoder: derive chroma type from video format.
[platform/upstream/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapidecoder_priv.h
1 /*
2  *  gstvaapidecoder_priv.h - VA decoder abstraction (private definitions)
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *    Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6  *  Copyright (C) 2011-2014 Intel Corporation
7  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public License
11  *  as published by the Free Software Foundation; either version 2.1
12  *  of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free
21  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA 02110-1301 USA
23  */
24
25 #ifndef GST_VAAPI_DECODER_PRIV_H
26 #define GST_VAAPI_DECODER_PRIV_H
27
28 #include <glib.h>
29 #include <gst/vaapi/gstvaapidecoder.h>
30 #include <gst/vaapi/gstvaapidecoder_unit.h>
31 #include <gst/vaapi/gstvaapicontext.h>
32 #include "gstvaapiminiobject.h"
33
34 G_BEGIN_DECLS
35
36 #define GST_VAAPI_DECODER_CAST(decoder) \
37     ((GstVaapiDecoder *)(decoder))
38
39 #define GST_VAAPI_DECODER_CLASS(klass) \
40     ((GstVaapiDecoderClass *)(klass))
41
42 #define GST_VAAPI_IS_DECODER_CLASS(klass) \
43     ((klass) != NULL))
44
45 #define GST_VAAPI_DECODER_GET_CLASS(obj) \
46     GST_VAAPI_DECODER_CLASS(GST_VAAPI_MINI_OBJECT_GET_CLASS(obj))
47
48 typedef struct _GstVaapiDecoderClass            GstVaapiDecoderClass;
49         struct _GstVaapiDecoderUnit;
50
51 /**
52  * GST_VAAPI_PARSER_STATE:
53  * @decoder: a #GstVaapiDecoder
54  *
55  * Macro that evaluates to the #GstVaapiParserState of @decoder.
56  * This is an internal macro that does not do any run-time type check.
57  */
58 #undef  GST_VAAPI_PARSER_STATE
59 #define GST_VAAPI_PARSER_STATE(decoder) \
60     (&GST_VAAPI_DECODER_CAST(decoder)->parser_state)
61
62 /**
63  * GST_VAAPI_DECODER_DISPLAY:
64  * @decoder: a #GstVaapiDecoder
65  *
66  * Macro that evaluates to the #GstVaapiDisplay of @decoder.
67  * This is an internal macro that does not do any run-time type check.
68  */
69 #undef  GST_VAAPI_DECODER_DISPLAY
70 #define GST_VAAPI_DECODER_DISPLAY(decoder) \
71     GST_VAAPI_DECODER_CAST(decoder)->display
72
73 /**
74  * GST_VAAPI_DECODER_CONTEXT:
75  * @decoder: a #GstVaapiDecoder
76  *
77  * Macro that evaluates to the #GstVaapiContext of @decoder.
78  * This is an internal macro that does not do any run-time type check.
79  */
80 #undef  GST_VAAPI_DECODER_CONTEXT
81 #define GST_VAAPI_DECODER_CONTEXT(decoder) \
82     GST_VAAPI_DECODER_CAST(decoder)->context
83
84 /**
85  * GST_VAAPI_DECODER_CODEC:
86  * @decoder: a #GstVaapiDecoder
87  *
88  * Macro that evaluates to the #GstVaapiCodec of @decoder.
89  * This is an internal macro that does not do any run-time type check.
90  */
91 #undef  GST_VAAPI_DECODER_CODEC
92 #define GST_VAAPI_DECODER_CODEC(decoder) \
93     GST_VAAPI_DECODER_CAST(decoder)->codec
94
95 /**
96  * GST_VAAPI_DECODER_CODEC_STATE:
97  * @decoder: a #GstVaapiDecoder
98  *
99  * Macro that evaluates to the #GstVideoCodecState holding codec state
100  * for @decoder.
101  * This is an internal macro that does not do any run-time type check.
102  */
103 #undef  GST_VAAPI_DECODER_CODEC_STATE
104 #define GST_VAAPI_DECODER_CODEC_STATE(decoder) \
105     GST_VAAPI_DECODER_CAST(decoder)->codec_state
106
107 /**
108  * GST_VAAPI_DECODER_CODEC_DATA:
109  * @decoder: a #GstVaapiDecoder
110  *
111  * Macro that evaluates to the #GstBuffer holding optional codec data
112  * for @decoder.
113  * This is an internal macro that does not do any run-time type check.
114  */
115 #undef  GST_VAAPI_DECODER_CODEC_DATA
116 #define GST_VAAPI_DECODER_CODEC_DATA(decoder) \
117     GST_VAAPI_DECODER_CODEC_STATE(decoder)->codec_data
118
119 /**
120  * GST_VAAPI_DECODER_CODEC_FRAME:
121  * @decoder: a #GstVaapiDecoder
122  *
123  * Macro that evaluates to the #GstVideoCodecFrame holding decoder
124  * units for the current frame.
125  * This is an internal macro that does not do any run-time type check.
126  */
127 #undef  GST_VAAPI_DECODER_CODEC_FRAME
128 #define GST_VAAPI_DECODER_CODEC_FRAME(decoder) \
129     GST_VAAPI_PARSER_STATE(decoder)->current_frame
130
131 /**
132  * GST_VAAPI_DECODER_WIDTH:
133  * @decoder: a #GstVaapiDecoder
134  *
135  * Macro that evaluates to the coded width of the picture
136  * This is an internal macro that does not do any run-time type check.
137  */
138 #undef  GST_VAAPI_DECODER_WIDTH
139 #define GST_VAAPI_DECODER_WIDTH(decoder) \
140     GST_VAAPI_DECODER_CODEC_STATE(decoder)->info.width
141
142 /**
143  * GST_VAAPI_DECODER_HEIGHT:
144  * @decoder: a #GstVaapiDecoder
145  *
146  * Macro that evaluates to the coded height of the picture
147  * This is an internal macro that does not do any run-time type check.
148  */
149 #undef  GST_VAAPI_DECODER_HEIGHT
150 #define GST_VAAPI_DECODER_HEIGHT(decoder) \
151     GST_VAAPI_DECODER_CODEC_STATE(decoder)->info.height
152
153 /* End-of-Stream buffer */
154 #define GST_BUFFER_FLAG_EOS (GST_BUFFER_FLAG_LAST + 0)
155
156 #define GST_BUFFER_IS_EOS(buffer) \
157     GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_EOS)
158
159 #define GST_VAAPI_DECODER_GET_PRIVATE(obj)                      \
160     (G_TYPE_INSTANCE_GET_PRIVATE((obj),                         \
161                                  GST_VAAPI_TYPE_DECODER,        \
162                                  GstVaapiDecoderPrivate))
163
164 typedef enum {
165     GST_VAAPI_DECODER_STATUS_DROP_FRAME = -2
166 } GstVaapiDecoderStatusPrivate;
167
168 typedef struct _GstVaapiParserState GstVaapiParserState;
169 struct _GstVaapiParserState {
170     GstVideoCodecFrame *current_frame;
171     guint32             current_frame_number;
172     GstAdapter         *current_adapter;
173     GstAdapter         *input_adapter;
174     gint                input_offset1;
175     gint                input_offset2;
176     GstAdapter         *output_adapter;
177     GstVaapiDecoderUnit next_unit;
178     guint               next_unit_pending       : 1;
179     guint               at_eos                  : 1;
180 };
181
182 /**
183  * GstVaapiDecoder:
184  *
185  * A VA decoder base instance.
186  */
187 struct _GstVaapiDecoder {
188     /*< private >*/
189     GstVaapiMiniObject  parent_instance;
190
191     gpointer            user_data;
192     GstVaapiDisplay    *display;
193     VADisplay           va_display;
194     GstVaapiContext    *context;
195     VAContextID         va_context;
196     GstVaapiCodec       codec;
197     GstVideoCodecState *codec_state;
198     GAsyncQueue        *buffers;
199     GAsyncQueue        *frames;
200     GstVaapiParserState parser_state;
201     GstVaapiDecoderStateChangedFunc codec_state_changed_func;
202     gpointer            codec_state_changed_data;
203 };
204
205 /**
206  * GstVaapiDecoderClass:
207  *
208  * A VA decoder base class.
209  */
210 struct _GstVaapiDecoderClass {
211     /*< private >*/
212     GstVaapiMiniObjectClass parent_class;
213
214     gboolean              (*create)(GstVaapiDecoder *decoder);
215     void                  (*destroy)(GstVaapiDecoder *decoder);
216     GstVaapiDecoderStatus (*parse)(GstVaapiDecoder *decoder,
217         GstAdapter *adapter, gboolean at_eos,
218         struct _GstVaapiDecoderUnit *unit);
219     GstVaapiDecoderStatus (*decode)(GstVaapiDecoder *decoder,
220         struct _GstVaapiDecoderUnit *unit);
221     GstVaapiDecoderStatus (*start_frame)(GstVaapiDecoder *decoder,
222         struct _GstVaapiDecoderUnit *unit);
223     GstVaapiDecoderStatus (*end_frame)(GstVaapiDecoder *decoder);
224     GstVaapiDecoderStatus (*flush)(GstVaapiDecoder *decoder);
225     GstVaapiDecoderStatus (*decode_codec_data)(GstVaapiDecoder *decoder,
226         const guchar *buf, guint buf_size);
227 };
228
229 G_GNUC_INTERNAL
230 GstVaapiDecoder *
231 gst_vaapi_decoder_new(const GstVaapiDecoderClass *klass,
232     GstVaapiDisplay *display, GstCaps *caps);
233
234 G_GNUC_INTERNAL
235 void
236 gst_vaapi_decoder_finalize(GstVaapiDecoder *decoder);
237
238 G_GNUC_INTERNAL
239 void
240 gst_vaapi_decoder_set_picture_size(
241     GstVaapiDecoder    *decoder,
242     guint               width,
243     guint               height
244 );
245
246 G_GNUC_INTERNAL
247 void
248 gst_vaapi_decoder_set_framerate(
249     GstVaapiDecoder    *decoder,
250     guint               fps_n,
251     guint               fps_d
252 );
253
254 G_GNUC_INTERNAL
255 void
256 gst_vaapi_decoder_set_pixel_aspect_ratio(
257     GstVaapiDecoder    *decoder,
258     guint               par_n,
259     guint               par_d
260 );
261
262 G_GNUC_INTERNAL
263 void
264 gst_vaapi_decoder_set_interlace_mode(GstVaapiDecoder *decoder,
265     GstVideoInterlaceMode mode);
266
267 G_GNUC_INTERNAL
268 void
269 gst_vaapi_decoder_set_interlaced(GstVaapiDecoder *decoder, gboolean interlaced);
270
271 G_GNUC_INTERNAL
272 gboolean
273 gst_vaapi_decoder_ensure_context(
274     GstVaapiDecoder     *decoder,
275     GstVaapiContextInfo *cip
276 );
277
278 G_GNUC_INTERNAL
279 void
280 gst_vaapi_decoder_push_frame(GstVaapiDecoder *decoder,
281     GstVideoCodecFrame *frame);
282
283 G_GNUC_INTERNAL
284 GstVaapiDecoderStatus
285 gst_vaapi_decoder_check_status(GstVaapiDecoder *decoder);
286
287 G_GNUC_INTERNAL
288 GstVaapiDecoderStatus
289 gst_vaapi_decoder_decode_codec_data(GstVaapiDecoder *decoder);
290
291 G_END_DECLS
292
293 #endif /* GST_VAAPI_DECODER_PRIV_H */