1 /*
2  *  gstvaapicodec_objects.h - VA codec objects abstraction
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_CODEC_COMMON_H
26 #define GST_VAAPI_CODEC_COMMON_H
27 
28 #include <gst/vaapi/gstvaapiminiobject.h>
29 #include <gst/vaapi/gstvaapidecoder.h>
30 
31 G_BEGIN_DECLS
32 
33 typedef gpointer                                GstVaapiCodecBase;
34 typedef struct _GstVaapiCodecObject             GstVaapiCodecObject;
35 typedef struct _GstVaapiCodecObjectClass        GstVaapiCodecObjectClass;
36 typedef struct _GstVaapiIqMatrix                GstVaapiIqMatrix;
37 typedef struct _GstVaapiBitPlane                GstVaapiBitPlane;
38 typedef struct _GstVaapiHuffmanTable            GstVaapiHuffmanTable;
39 typedef struct _GstVaapiProbabilityTable        GstVaapiProbabilityTable;
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_CODEC_OBJECT(obj) \
50   ((GstVaapiCodecObject *) (obj))
51 
52 enum
53 {
54   GST_VAAPI_CODEC_OBJECT_FLAG_CONSTRUCTED = (1 << 0),
55   GST_VAAPI_CODEC_OBJECT_FLAG_LAST        = (1 << 1)
56 };
57 
58 typedef struct
59 {
60   gconstpointer param;
61   guint param_size;
62   gconstpointer data;
63   guint data_size;
64   guint flags;
65 } GstVaapiCodecObjectConstructorArgs;
66 
67 typedef gboolean
68 (*GstVaapiCodecObjectCreateFunc)(GstVaapiCodecObject * object,
69     const GstVaapiCodecObjectConstructorArgs * args);
70 
71 typedef GDestroyNotify GstVaapiCodecObjectDestroyFunc;
72 
73 /**
74  * GstVaapiCodecObject:
75  *
76  * A #GstVaapiMiniObject holding the base codec object data
77  */
78 struct _GstVaapiCodecObject
79 {
80   /*< private >*/
81   GstVaapiMiniObject parent_instance;
82   GstVaapiCodecBase *codec;
83 };
84 
85 /**
86  * GstVaapiCodecObjectClass:
87  *
88  * The #GstVaapiCodecObject base class.
89  */
90 struct _GstVaapiCodecObjectClass
91 {
92   /*< private >*/
93   GstVaapiMiniObjectClass parent_class;
94 
95   GstVaapiCodecObjectCreateFunc create;
96 };
97 
98 G_GNUC_INTERNAL
99 const GstVaapiCodecObjectClass *
100 gst_vaapi_codec_object_get_class (GstVaapiCodecObject * object) G_GNUC_CONST;
101 
102 G_GNUC_INTERNAL
103 GstVaapiCodecObject *
104 gst_vaapi_codec_object_new (const GstVaapiCodecObjectClass * object_class,
105     GstVaapiCodecBase * codec, gconstpointer param, guint param_size,
106     gconstpointer data, guint data_size, guint flags);
107 
108 #define gst_vaapi_codec_object_ref(object) \
109   ((gpointer) gst_vaapi_mini_object_ref (GST_VAAPI_MINI_OBJECT (object)))
110 
111 #define gst_vaapi_codec_object_unref(object) \
112   gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (object))
113 
114 #define gst_vaapi_codec_object_replace(old_object_ptr, new_object) \
115   gst_vaapi_mini_object_replace ((GstVaapiMiniObject **) (old_object_ptr), \
116       GST_VAAPI_MINI_OBJECT (new_object))
117 
118 /* ------------------------------------------------------------------------- */
119 /* --- Inverse Quantization Matrices                                     --- */
120 /* ------------------------------------------------------------------------- */
121 
122 #define GST_VAAPI_IQ_MATRIX_CAST(obj) \
123   ((GstVaapiIqMatrix *) (obj))
124 
125 /**
126  * GstVaapiIqMatrix:
127  *
128  * A #GstVaapiCodecObject holding an inverse quantization matrix parameter.
129  */
130 struct _GstVaapiIqMatrix
131 {
132   /*< private >*/
133   GstVaapiCodecObject parent_instance;
134   VABufferID param_id;
135 
136   /*< public >*/
137   gpointer param;
138 };
139 
140 G_GNUC_INTERNAL
141 GstVaapiIqMatrix *
142 gst_vaapi_iq_matrix_new (GstVaapiDecoder * decoder, gconstpointer param,
143     guint param_size);
144 
145 /* ------------------------------------------------------------------------- */
146 /* --- VC-1 Bit Planes                                                   --- */
147 /* ------------------------------------------------------------------------- */
148 
149 #define GST_VAAPI_BITPLANE_CAST(obj) \
150   ((GstVaapiBitPlane *) (obj))
151 
152 /**
153  * GstVaapiBitPlane:
154  *
155  * A #GstVaapiCodecObject holding a VC-1 bit plane parameter.
156  */
157 struct _GstVaapiBitPlane
158 {
159   /*< private >*/
160   GstVaapiCodecObject parent_instance;
161   VABufferID data_id;
162 
163   /*< public >*/
164   guint8 *data;
165 };
166 
167 G_GNUC_INTERNAL
168 GstVaapiBitPlane *
169 gst_vaapi_bitplane_new (GstVaapiDecoder * decoder, guint8 * data,
170     guint data_size);
171 
172 /* ------------------------------------------------------------------------- */
173 /* --- JPEG Huffman Tables                                               --- */
174 /* ------------------------------------------------------------------------- */
175 
176 #define GST_VAAPI_HUFFMAN_TABLE_CAST(obj) \
177   ((GstVaapiHuffmanTable *) (obj))
178 
179 /**
180  * GstVaapiHuffmanTable:
181  *
182  * A #GstVaapiCodecObject holding huffman table.
183  */
184 struct _GstVaapiHuffmanTable
185 {
186   /*< private >*/
187   GstVaapiCodecObject parent_instance;
188   VABufferID param_id;
189 
190   /*< public >*/
191   gpointer param;
192 };
193 
194 G_GNUC_INTERNAL
195 GstVaapiHuffmanTable *
196 gst_vaapi_huffman_table_new (GstVaapiDecoder * decoder, guint8 * data,
197     guint data_size);
198 
199 /* ------------------------------------------------------------------------- */
200 /* ---                   Probability (Update) Table                      --- */
201 /* ------------------------------------------------------------------------- */
202 
203 #define GST_VAAPI_PROBABILITY_TABLE_CAST(obj) \
204     ((GstVaapiProbabilityTable *)(obj))
205 
206 /**
207  * GstVaapiProbabilityTable:
208  *
209  * A #GstVaapiCodecObject holding an Probability (Update) Table for RAC decoding
210  */
211 struct _GstVaapiProbabilityTable
212 {
213   /*< private > */
214   GstVaapiCodecObject parent_instance;
215   VABufferID param_id;
216 
217   /*< public > */
218   gpointer param;
219 };
220 
221 G_GNUC_INTERNAL
222 GstVaapiProbabilityTable *
223 gst_vaapi_probability_table_new (GstVaapiDecoder * decoder,
224     gconstpointer param, guint param_size);
225 
226 /* ------------------------------------------------------------------------- */
227 /* --- Helpers to create codec-dependent objects                         --- */
228 /* ------------------------------------------------------------------------- */
229 
230 #define GST_VAAPI_CODEC_DEFINE_TYPE(type, prefix)                       \
231 G_GNUC_INTERNAL                                                         \
232 void                                                                    \
233 G_PASTE (prefix, _destroy) (type *);                                    \
234                                                                         \
235 G_GNUC_INTERNAL                                                         \
236 gboolean                                                                \
237 G_PASTE (prefix, _create) (type *,                                      \
238     const GstVaapiCodecObjectConstructorArgs * args);                   \
239                                                                         \
240 static const GstVaapiCodecObjectClass G_PASTE (type, Class) = {         \
241   .parent_class = {                                                     \
242     .size = sizeof (type),                                              \
243     .finalize = (GstVaapiCodecObjectDestroyFunc)                        \
244         G_PASTE (prefix, _destroy)                                      \
245   },                                                                    \
246   .create = (GstVaapiCodecObjectCreateFunc)                             \
247       G_PASTE (prefix, _create),                                        \
248 }
249 
250 #define GST_VAAPI_IQ_MATRIX_NEW(codec, decoder)                         \
251   gst_vaapi_iq_matrix_new (GST_VAAPI_DECODER_CAST (decoder),            \
252       NULL, sizeof (G_PASTE (VAIQMatrixBuffer, codec)))
253 
254 #define GST_VAAPI_BITPLANE_NEW(decoder, size) \
255   gst_vaapi_bitplane_new (GST_VAAPI_DECODER_CAST (decoder), NULL, size)
256 
257 #define GST_VAAPI_HUFFMAN_TABLE_NEW(codec, decoder)                     \
258   gst_vaapi_huffman_table_new (GST_VAAPI_DECODER_CAST (decoder),        \
259       NULL, sizeof (G_PASTE (VAHuffmanTableBuffer, codec)))
260 
261 #define GST_VAAPI_PROBABILITY_TABLE_NEW(codec, decoder)                 \
262   gst_vaapi_probability_table_new (GST_VAAPI_DECODER_CAST (decoder),    \
263       NULL, sizeof (G_PASTE (VAProbabilityDataBuffer, codec)))
264 
265 G_END_DECLS
266 
267 #endif /* GST_VAAPI_CODEC_OBJECTS_H */
268