Tizen 2.1 base
[framework/multimedia/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapicodec_objects.h
1 /*
2  *  gstvaapicodec_objects.h - VA codec objects abstraction
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *  Copyright (C) 2011-2012 Intel Corporation
6  *
7  *  This library 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 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  *  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 library; 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_VAAPI_CODEC_COMMON_H
24 #define GST_VAAPI_CODEC_COMMON_H
25
26 #include <gst/gstminiobject.h>
27 #include <gst/vaapi/gstvaapidecoder.h>
28
29 G_BEGIN_DECLS
30
31 typedef gpointer                                GstVaapiCodecBase;
32 typedef struct _GstVaapiCodecObject             GstVaapiCodecObject;
33 typedef struct _GstVaapiCodecObjectClass        GstVaapiCodecObjectClass;
34 typedef struct _GstVaapiIqMatrix                GstVaapiIqMatrix;
35 typedef struct _GstVaapiIqMatrixClass           GstVaapiIqMatrixClass;
36 typedef struct _GstVaapiBitPlane                GstVaapiBitPlane;
37 typedef struct _GstVaapiBitPlaneClass           GstVaapiBitPlaneClass;
38 typedef struct _GstVaapiHuffmanTable            GstVaapiHuffmanTable;
39 typedef struct _GstVaapiHuffmanTableClass       GstVaapiHuffmanTableClass;
40
41 /* ------------------------------------------------------------------------- */
42 /* --- Base Codec Object                                                 --- */
43 /* ------------------------------------------------------------------------- */
44
45 /* XXX: remove when a common base class for decoder and encoder is available */
46 #define GST_VAAPI_CODEC_BASE(obj) \
47     ((GstVaapiCodecBase *)(obj))
48
49 #define GST_VAAPI_TYPE_CODEC_OBJECT \
50     (gst_vaapi_codec_object_get_type())
51
52 #define GST_VAAPI_CODEC_OBJECT(obj)                             \
53     (G_TYPE_CHECK_INSTANCE_CAST((obj),                          \
54                                 GST_VAAPI_TYPE_CODEC_OBJECT,    \
55                                 GstVaapiCodecObject))
56
57 #define GST_VAAPI_CODEC_OBJECT_CLASS(klass)                     \
58     (G_TYPE_CHECK_CLASS_CAST((klass),                           \
59                              GST_VAAPI_TYPE_CODEC_OBJECT,       \
60                              GstVaapiCodecObjectClass))
61
62 #define GST_VAAPI_IS_CODEC_OBJECT(obj) \
63     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_CODEC_OBJECT))
64
65 #define GST_VAAPI_IS_CODEC_OBJECT_CLASS(klass) \
66     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_CODEC_OBJECT))
67
68 #define GST_VAAPI_CODEC_OBJECT_GET_CLASS(obj)                   \
69     (G_TYPE_INSTANCE_GET_CLASS((obj),                           \
70                                GST_VAAPI_TYPE_CODEC_OBJECT,     \
71                                GstVaapiCodecObjectClass))
72
73 enum {
74     GST_VAAPI_CODEC_OBJECT_FLAG_CONSTRUCTED = (GST_MINI_OBJECT_FLAG_LAST << 0),
75     GST_VAAPI_CODEC_OBJECT_FLAG_LAST        = (GST_MINI_OBJECT_FLAG_LAST << 1)
76 };
77
78 typedef struct {
79     GstVaapiCodecObject        *obj;
80     GstVaapiCodecBase          *codec;
81     gconstpointer               param;
82     guint                       param_size;
83     gconstpointer               data;
84     guint                       data_size;
85     guint                       flags;
86 } GstVaapiCodecObjectConstructorArgs;
87
88 /**
89  * GstVaapiCodecObject:
90  *
91  * A #GstMiniObject holding the base codec object data
92  */
93 struct _GstVaapiCodecObject {
94     /*< private >*/
95     GstMiniObject               parent_instance;
96     GstVaapiCodecBase          *codec;
97 };
98
99 /**
100  * GstVaapiCodecObjectClass:
101  *
102  * The #GstVaapiCodecObject base class.
103  */
104 struct _GstVaapiCodecObjectClass {
105     /*< private >*/
106     GstMiniObjectClass          parent_class;
107
108     gboolean (*construct)      (GstVaapiCodecObject *obj,
109                                 const GstVaapiCodecObjectConstructorArgs *args);
110 };
111
112 G_GNUC_INTERNAL
113 GType
114 gst_vaapi_codec_object_get_type(void) G_GNUC_CONST;
115
116 G_GNUC_INTERNAL
117 GstVaapiCodecObject *
118 gst_vaapi_codec_object_new(
119     GType              type,
120     GstVaapiCodecBase *codec,
121     gconstpointer      param,
122     guint              param_size,
123     gconstpointer      data,
124     guint              data_size
125 );
126
127 G_GNUC_INTERNAL
128 gboolean
129 gst_vaapi_codec_object_construct(
130     GstVaapiCodecObject                      *obj,
131     const GstVaapiCodecObjectConstructorArgs *args
132 );
133
134 /* ------------------------------------------------------------------------- */
135 /* --- Inverse Quantization Matrices                                     --- */
136 /* ------------------------------------------------------------------------- */
137
138 #define GST_VAAPI_TYPE_IQ_MATRIX \
139     (gst_vaapi_iq_matrix_get_type())
140
141 #define GST_VAAPI_IQ_MATRIX_CAST(obj) \
142     ((GstVaapiIqMatrix *)(obj))
143
144 #define GST_VAAPI_IQ_MATRIX(obj)                                \
145     (G_TYPE_CHECK_INSTANCE_CAST((obj),                          \
146                                 GST_VAAPI_TYPE_IQ_MATRIX,       \
147                                 GstVaapiIqMatrix))
148
149 #define GST_VAAPI_IQ_MATRIX_CLASS(klass)                        \
150     (G_TYPE_CHECK_CLASS_CAST((klass),                           \
151                              GST_VAAPI_TYPE_IQ_MATRIX,          \
152                              GstVaapiIqMatrixClass))
153
154 #define GST_VAAPI_IS_IQ_MATRIX(obj) \
155     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_IQ_MATRIX))
156
157 #define GST_VAAPI_IS_IQ_MATRIX_CLASS(klass) \
158     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_IQ_MATRIX))
159
160 #define GST_VAAPI_IQ_MATRIX_GET_CLASS(obj)                      \
161     (G_TYPE_INSTANCE_GET_CLASS((obj),                           \
162                                GST_VAAPI_TYPE_IQ_MATRIX,        \
163                                GstVaapiIqMatrixClass))
164
165 /**
166  * GstVaapiIqMatrix:
167  *
168  * A #GstVaapiCodecObject holding an inverse quantization matrix parameter.
169  */
170 struct _GstVaapiIqMatrix {
171     /*< private >*/
172     GstVaapiCodecObject         parent_instance;
173     VABufferID                  param_id;
174
175     /*< public >*/
176     gpointer                    param;
177 };
178
179 /**
180  * GstVaapiIqMatrixClass:
181  *
182  * The #GstVaapiIqMatrix base class.
183  */
184 struct _GstVaapiIqMatrixClass {
185     /*< private >*/
186     GstVaapiCodecObjectClass    parent_class;
187 };
188
189 G_GNUC_INTERNAL
190 GType
191 gst_vaapi_iq_matrix_get_type(void) G_GNUC_CONST;
192
193 G_GNUC_INTERNAL
194 GstVaapiIqMatrix *
195 gst_vaapi_iq_matrix_new(
196     GstVaapiDecoder *decoder,
197     gconstpointer    param,
198     guint            param_size
199 );
200
201 /* ------------------------------------------------------------------------- */
202 /* --- VC-1 Bit Planes                                                   --- */
203 /* ------------------------------------------------------------------------- */
204
205 #define GST_VAAPI_TYPE_BITPLANE \
206     (gst_vaapi_bitplane_get_type())
207
208 #define GST_VAAPI_BITPLANE_CAST(obj) \
209     ((GstVaapiBitPlane *)(obj))
210
211 #define GST_VAAPI_BITPLANE(obj)                                 \
212     (G_TYPE_CHECK_INSTANCE_CAST((obj),                          \
213                                 GST_VAAPI_TYPE_BITPLANE,        \
214                                 GstVaapiBitPlane))
215
216 #define GST_VAAPI_BITPLANE_CLASS(klass)                         \
217     (G_TYPE_CHECK_CLASS_CAST((klass),                           \
218                              GST_VAAPI_TYPE_BITPLANE,           \
219                              GstVaapiBitPlaneClass))
220
221 #define GST_VAAPI_IS_BITPLANE(obj) \
222     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_BITPLANE))
223
224 #define GST_VAAPI_IS_BITPLANE_CLASS(klass) \
225     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_BITPLANE))
226
227 #define GST_VAAPI_BITPLANE_GET_CLASS(obj)                       \
228     (G_TYPE_INSTANCE_GET_CLASS((obj),                           \
229                                GST_VAAPI_TYPE_BITPLANE,         \
230                                GstVaapiBitPlaneClass))
231
232 /**
233  * GstVaapiBitPlane:
234  *
235  * A #GstVaapiCodecObject holding a VC-1 bit plane parameter.
236  */
237 struct _GstVaapiBitPlane {
238     /*< private >*/
239     GstVaapiCodecObject         parent_instance;
240     VABufferID                  data_id;
241
242     /*< public >*/
243     guint8                     *data;
244 };
245
246 /**
247  * GstVaapiBitPlaneClass:
248  *
249  * The #GstVaapiBitPlane base class.
250  */
251 struct _GstVaapiBitPlaneClass {
252     /*< private >*/
253     GstVaapiCodecObjectClass    parent_class;
254 };
255
256 G_GNUC_INTERNAL
257 GType
258 gst_vaapi_bitplane_get_type(void) G_GNUC_CONST;
259
260 G_GNUC_INTERNAL
261 GstVaapiBitPlane *
262 gst_vaapi_bitplane_new(GstVaapiDecoder *decoder, guint8 *data, guint data_size);
263
264 /* ------------------------------------------------------------------------- */
265 /* --- JPEG Huffman Tables                                               --- */
266 /* ------------------------------------------------------------------------- */
267
268 #define GST_VAAPI_TYPE_HUFFMAN_TABLE \
269     (gst_vaapi_huffman_table_get_type())
270
271 #define GST_VAAPI_HUFFMAN_TABLE_CAST(obj) \
272     ((GstVaapiHuffmanTable *)(obj))
273
274 #define GST_VAAPI_HUFFMAN_TABLE(obj)                            \
275     (G_TYPE_CHECK_INSTANCE_CAST((obj),                          \
276                                 GST_VAAPI_TYPE_HUFFMAN_TABLE,   \
277                                 GstVaapiHuffmanTable))
278
279 #define GST_VAAPI_HUFFMAN_TABLE_CLASS(klass)                    \
280     (G_TYPE_CHECK_CLASS_CAST((klass),                           \
281                              GST_VAAPI_TYPE_HUFFMAN_TABLE,      \
282                              GstVaapiHuffmanTableClass))
283
284 #define GST_VAAPI_IS_HUFFMAN_TABLE(obj) \
285     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_HUFFMAN_TABLE))
286
287 #define GST_VAAPI_IS_HUFFMAN_TABLE_CLASS(klass) \
288     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_HUFFMAN_TABLE))
289
290 #define GST_VAAPI_HUFFMAN_TABLE_GET_CLASS(obj)                  \
291     (G_TYPE_INSTANCE_GET_CLASS((obj),                           \
292                                GST_VAAPI_TYPE_HUFFMAN_TABLE,    \
293                                GstVaapiHuffmanTableClass))
294
295 /**
296  * GstVaapiHuffmanTable:
297  *
298  * A #GstVaapiCodecObject holding huffman table.
299  */
300 struct _GstVaapiHuffmanTable {
301     /*< private >*/
302     GstVaapiCodecObject         parent_instance;
303     VABufferID                  param_id;
304
305     /*< public >*/
306     gpointer                    param;
307 };
308
309 /**
310  * GstVaapiHuffmanTableClass:
311  *
312  * The #GstVaapiHuffmanTable base class.
313  */
314 struct _GstVaapiHuffmanTableClass {
315     /*< private >*/
316     GstVaapiCodecObjectClass    parent_class;
317 };
318
319 G_GNUC_INTERNAL
320 GType
321 gst_vaapi_huffman_table_get_type(void) G_GNUC_CONST;
322
323 G_GNUC_INTERNAL
324 GstVaapiHuffmanTable *
325 gst_vaapi_huffman_table_new(
326     GstVaapiDecoder *decoder,
327     guint8          *data,
328     guint            data_size
329 );
330
331 /* ------------------------------------------------------------------------- */
332 /* --- Helpers to create codec-dependent objects                         --- */
333 /* ------------------------------------------------------------------------- */
334
335 #define GST_VAAPI_CODEC_DEFINE_TYPE(type, prefix, base_type)            \
336 G_DEFINE_TYPE(type, prefix, base_type)                                  \
337                                                                         \
338 static void                                                             \
339 prefix##_destroy(type *);                                               \
340                                                                         \
341 static gboolean                                                         \
342 prefix##_create(                                                        \
343     type *,                                                             \
344     const GstVaapiCodecObjectConstructorArgs *args                      \
345 );                                                                      \
346                                                                         \
347 static void                                                             \
348 prefix##_finalize(GstMiniObject *object)                                \
349 {                                                                       \
350     GstMiniObjectClass *parent_class;                                   \
351                                                                         \
352     prefix##_destroy((type *)object);                                   \
353                                                                         \
354     parent_class = GST_MINI_OBJECT_CLASS(prefix##_parent_class);        \
355     if (parent_class->finalize)                                         \
356         parent_class->finalize(object);                                 \
357 }                                                                       \
358                                                                         \
359 static gboolean                                                         \
360 prefix##_construct(                                                     \
361     GstVaapiCodecObject                      *object,                   \
362     const GstVaapiCodecObjectConstructorArgs *args                      \
363 )                                                                       \
364 {                                                                       \
365     GstVaapiCodecObjectClass *parent_class;                             \
366                                                                         \
367     parent_class = GST_VAAPI_CODEC_OBJECT_CLASS(prefix##_parent_class); \
368     if (parent_class->construct) {                                      \
369         if (!parent_class->construct(object, args))                     \
370             return FALSE;                                               \
371     }                                                                   \
372     return prefix##_create((type *)object, args);                       \
373 }                                                                       \
374                                                                         \
375 static void                                                             \
376 prefix##_class_init(type##Class *klass)                                 \
377 {                                                                       \
378     GstMiniObjectClass * const object_class =                           \
379         GST_MINI_OBJECT_CLASS(klass);                                   \
380     GstVaapiCodecObjectClass * const codec_class =                      \
381         GST_VAAPI_CODEC_OBJECT_CLASS(klass);                            \
382                                                                         \
383     object_class->finalize = prefix##_finalize;                         \
384     codec_class->construct = prefix##_construct;                        \
385 }
386
387 #define GST_VAAPI_IQ_MATRIX_NEW(codec, decoder)                         \
388     gst_vaapi_iq_matrix_new(GST_VAAPI_DECODER_CAST(decoder),            \
389                             NULL, sizeof(VAIQMatrixBuffer##codec))
390
391 #define GST_VAAPI_BITPLANE_NEW(decoder, size) \
392     gst_vaapi_bitplane_new(GST_VAAPI_DECODER_CAST(decoder), NULL, size)
393
394 #define GST_VAAPI_HUFFMAN_TABLE_NEW(codec, decoder)                     \
395       gst_vaapi_huffman_table_new(GST_VAAPI_DECODER_CAST(decoder),      \
396                             NULL, sizeof(VAHuffmanTableBuffer##codec))
397
398 G_END_DECLS
399
400 #endif /* GST_VAAPI_CODEC_OBJECTS_H */