summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/gstvaapicodec_objects.h
blob: a064c1595a98263ec353758eeca55bf404a595e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/*
 *  gstvaapicodec_objects.h - VA codec objects abstraction
 *
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
 *  Copyright (C) 2011-2012 Intel Corporation
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301 USA
 */

#ifndef GST_VAAPI_CODEC_COMMON_H
#define GST_VAAPI_CODEC_COMMON_H

#include <gst/gstminiobject.h>
#include <gst/vaapi/gstvaapidecoder.h>

G_BEGIN_DECLS

typedef gpointer                                GstVaapiCodecBase;
typedef struct _GstVaapiCodecObject             GstVaapiCodecObject;
typedef struct _GstVaapiCodecObjectClass        GstVaapiCodecObjectClass;
typedef struct _GstVaapiIqMatrix                GstVaapiIqMatrix;
typedef struct _GstVaapiIqMatrixClass           GstVaapiIqMatrixClass;
typedef struct _GstVaapiBitPlane                GstVaapiBitPlane;
typedef struct _GstVaapiBitPlaneClass           GstVaapiBitPlaneClass;
typedef struct _GstVaapiHuffmanTable            GstVaapiHuffmanTable;
typedef struct _GstVaapiHuffmanTableClass       GstVaapiHuffmanTableClass;

/* ------------------------------------------------------------------------- */
/* --- Base Codec Object                                                 --- */
/* ------------------------------------------------------------------------- */

/* XXX: remove when a common base class for decoder and encoder is available */
#define GST_VAAPI_CODEC_BASE(obj) \
    ((GstVaapiCodecBase *)(obj))

#define GST_VAAPI_TYPE_CODEC_OBJECT \
    (gst_vaapi_codec_object_get_type())

#define GST_VAAPI_CODEC_OBJECT(obj)                             \
    (G_TYPE_CHECK_INSTANCE_CAST((obj),                          \
                                GST_VAAPI_TYPE_CODEC_OBJECT,    \
                                GstVaapiCodecObject))

#define GST_VAAPI_CODEC_OBJECT_CLASS(klass)                     \
    (G_TYPE_CHECK_CLASS_CAST((klass),                           \
                             GST_VAAPI_TYPE_CODEC_OBJECT,       \
                             GstVaapiCodecObjectClass))

#define GST_VAAPI_IS_CODEC_OBJECT(obj) \
    (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_CODEC_OBJECT))

#define GST_VAAPI_IS_CODEC_OBJECT_CLASS(klass) \
    (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_CODEC_OBJECT))

#define GST_VAAPI_CODEC_OBJECT_GET_CLASS(obj)                   \
    (G_TYPE_INSTANCE_GET_CLASS((obj),                           \
                               GST_VAAPI_TYPE_CODEC_OBJECT,     \
                               GstVaapiCodecObjectClass))

enum {
    GST_VAAPI_CODEC_OBJECT_FLAG_CONSTRUCTED = (GST_MINI_OBJECT_FLAG_LAST << 0),
    GST_VAAPI_CODEC_OBJECT_FLAG_LAST        = (GST_MINI_OBJECT_FLAG_LAST << 1)
};

typedef struct {
    GstVaapiCodecObject        *obj;
    GstVaapiCodecBase          *codec;
    gconstpointer               param;
    guint                       param_size;
    gconstpointer               data;
    guint                       data_size;
    guint                       flags;
} GstVaapiCodecObjectConstructorArgs;

/**
 * GstVaapiCodecObject:
 *
 * A #GstMiniObject holding the base codec object data
 */
struct _GstVaapiCodecObject {
    /*< private >*/
    GstMiniObject               parent_instance;
    GstVaapiCodecBase          *codec;
};

/**
 * GstVaapiCodecObjectClass:
 *
 * The #GstVaapiCodecObject base class.
 */
struct _GstVaapiCodecObjectClass {
    /*< private >*/
    GstMiniObjectClass          parent_class;

    gboolean (*construct)      (GstVaapiCodecObject *obj,
                                const GstVaapiCodecObjectConstructorArgs *args);
};

G_GNUC_INTERNAL
GType
gst_vaapi_codec_object_get_type(void) G_GNUC_CONST;

G_GNUC_INTERNAL
GstVaapiCodecObject *
gst_vaapi_codec_object_new(
    GType              type,
    GstVaapiCodecBase *codec,
    gconstpointer      param,
    guint              param_size,
    gconstpointer      data,
    guint              data_size
);

G_GNUC_INTERNAL
gboolean
gst_vaapi_codec_object_construct(
    GstVaapiCodecObject                      *obj,
    const GstVaapiCodecObjectConstructorArgs *args
);

/* ------------------------------------------------------------------------- */
/* --- Inverse Quantization Matrices                                     --- */
/* ------------------------------------------------------------------------- */

#define GST_VAAPI_TYPE_IQ_MATRIX \
    (gst_vaapi_iq_matrix_get_type())

#define GST_VAAPI_IQ_MATRIX_CAST(obj) \
    ((GstVaapiIqMatrix *)(obj))

#define GST_VAAPI_IQ_MATRIX(obj)                                \
    (G_TYPE_CHECK_INSTANCE_CAST((obj),                          \
                                GST_VAAPI_TYPE_IQ_MATRIX,       \
                                GstVaapiIqMatrix))

#define GST_VAAPI_IQ_MATRIX_CLASS(klass)                        \
    (G_TYPE_CHECK_CLASS_CAST((klass),                           \
                             GST_VAAPI_TYPE_IQ_MATRIX,          \
                             GstVaapiIqMatrixClass))

#define GST_VAAPI_IS_IQ_MATRIX(obj) \
    (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_IQ_MATRIX))

#define GST_VAAPI_IS_IQ_MATRIX_CLASS(klass) \
    (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_IQ_MATRIX))

#define GST_VAAPI_IQ_MATRIX_GET_CLASS(obj)                      \
    (G_TYPE_INSTANCE_GET_CLASS((obj),                           \
                               GST_VAAPI_TYPE_IQ_MATRIX,        \
                               GstVaapiIqMatrixClass))

/**
 * GstVaapiIqMatrix:
 *
 * A #GstVaapiCodecObject holding an inverse quantization matrix parameter.
 */
struct _GstVaapiIqMatrix {
    /*< private >*/
    GstVaapiCodecObject         parent_instance;
    VABufferID                  param_id;

    /*< public >*/
    gpointer                    param;
};

/**
 * GstVaapiIqMatrixClass:
 *
 * The #GstVaapiIqMatrix base class.
 */
struct _GstVaapiIqMatrixClass {
    /*< private >*/
    GstVaapiCodecObjectClass    parent_class;
};

G_GNUC_INTERNAL
GType
gst_vaapi_iq_matrix_get_type(void) G_GNUC_CONST;

G_GNUC_INTERNAL
GstVaapiIqMatrix *
gst_vaapi_iq_matrix_new(
    GstVaapiDecoder *decoder,
    gconstpointer    param,
    guint            param_size
);

/* ------------------------------------------------------------------------- */
/* --- VC-1 Bit Planes                                                   --- */
/* ------------------------------------------------------------------------- */

#define GST_VAAPI_TYPE_BITPLANE \
    (gst_vaapi_bitplane_get_type())

#define GST_VAAPI_BITPLANE_CAST(obj) \
    ((GstVaapiBitPlane *)(obj))

#define GST_VAAPI_BITPLANE(obj)                                 \
    (G_TYPE_CHECK_INSTANCE_CAST((obj),                          \
                                GST_VAAPI_TYPE_BITPLANE,        \
                                GstVaapiBitPlane))

#define GST_VAAPI_BITPLANE_CLASS(klass)                         \
    (G_TYPE_CHECK_CLASS_CAST((klass),                           \
                             GST_VAAPI_TYPE_BITPLANE,           \
                             GstVaapiBitPlaneClass))

#define GST_VAAPI_IS_BITPLANE(obj) \
    (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_BITPLANE))

#define GST_VAAPI_IS_BITPLANE_CLASS(klass) \
    (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_BITPLANE))

#define GST_VAAPI_BITPLANE_GET_CLASS(obj)                       \
    (G_TYPE_INSTANCE_GET_CLASS((obj),                           \
                               GST_VAAPI_TYPE_BITPLANE,         \
                               GstVaapiBitPlaneClass))

/**
 * GstVaapiBitPlane:
 *
 * A #GstVaapiCodecObject holding a VC-1 bit plane parameter.
 */
struct _GstVaapiBitPlane {
    /*< private >*/
    GstVaapiCodecObject         parent_instance;
    VABufferID                  data_id;

    /*< public >*/
    guint8                     *data;
};

/**
 * GstVaapiBitPlaneClass:
 *
 * The #GstVaapiBitPlane base class.
 */
struct _GstVaapiBitPlaneClass {
    /*< private >*/
    GstVaapiCodecObjectClass    parent_class;
};

G_GNUC_INTERNAL
GType
gst_vaapi_bitplane_get_type(void) G_GNUC_CONST;

G_GNUC_INTERNAL
GstVaapiBitPlane *
gst_vaapi_bitplane_new(GstVaapiDecoder *decoder, guint8 *data, guint data_size);

/* ------------------------------------------------------------------------- */
/* --- JPEG Huffman Tables                                               --- */
/* ------------------------------------------------------------------------- */

#define GST_VAAPI_TYPE_HUFFMAN_TABLE \
    (gst_vaapi_huffman_table_get_type())

#define GST_VAAPI_HUFFMAN_TABLE_CAST(obj) \
    ((GstVaapiHuffmanTable *)(obj))

#define GST_VAAPI_HUFFMAN_TABLE(obj)                            \
    (G_TYPE_CHECK_INSTANCE_CAST((obj),                          \
                                GST_VAAPI_TYPE_HUFFMAN_TABLE,   \
                                GstVaapiHuffmanTable))

#define GST_VAAPI_HUFFMAN_TABLE_CLASS(klass)                    \
    (G_TYPE_CHECK_CLASS_CAST((klass),                           \
                             GST_VAAPI_TYPE_HUFFMAN_TABLE,      \
                             GstVaapiHuffmanTableClass))

#define GST_VAAPI_IS_HUFFMAN_TABLE(obj) \
    (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_HUFFMAN_TABLE))

#define GST_VAAPI_IS_HUFFMAN_TABLE_CLASS(klass) \
    (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_HUFFMAN_TABLE))

#define GST_VAAPI_HUFFMAN_TABLE_GET_CLASS(obj)                  \
    (G_TYPE_INSTANCE_GET_CLASS((obj),                           \
                               GST_VAAPI_TYPE_HUFFMAN_TABLE,    \
                               GstVaapiHuffmanTableClass))

/**
 * GstVaapiHuffmanTable:
 *
 * A #GstVaapiCodecObject holding huffman table.
 */
struct _GstVaapiHuffmanTable {
    /*< private >*/
    GstVaapiCodecObject         parent_instance;
    VABufferID                  param_id;

    /*< public >*/
    gpointer                    param;
};

/**
 * GstVaapiHuffmanTableClass:
 *
 * The #GstVaapiHuffmanTable base class.
 */
struct _GstVaapiHuffmanTableClass {
    /*< private >*/
    GstVaapiCodecObjectClass    parent_class;
};

G_GNUC_INTERNAL
GType
gst_vaapi_huffman_table_get_type(void) G_GNUC_CONST;

G_GNUC_INTERNAL
GstVaapiHuffmanTable *
gst_vaapi_huffman_table_new(
    GstVaapiDecoder *decoder,
    guint8          *data,
    guint            data_size
);

/* ------------------------------------------------------------------------- */
/* --- Helpers to create codec-dependent objects                         --- */
/* ------------------------------------------------------------------------- */

#define GST_VAAPI_CODEC_DEFINE_TYPE(type, prefix, base_type)            \
G_DEFINE_TYPE(type, prefix, base_type)                                  \
                                                                        \
static void                                                             \
prefix##_destroy(type *);                                               \
                                                                        \
static gboolean                                                         \
prefix##_create(                                                        \
    type *,                                                             \
    const GstVaapiCodecObjectConstructorArgs *args                      \
);                                                                      \
                                                                        \
static void                                                             \
prefix##_finalize(GstMiniObject *object)                                \
{                                                                       \
    GstMiniObjectClass *parent_class;                                   \
                                                                        \
    prefix##_destroy((type *)object);                                   \
                                                                        \
    parent_class = GST_MINI_OBJECT_CLASS(prefix##_parent_class);        \
    if (parent_class->finalize)                                         \
        parent_class->finalize(object);                                 \
}                                                                       \
                                                                        \
static gboolean                                                         \
prefix##_construct(                                                     \
    GstVaapiCodecObject                      *object,                   \
    const GstVaapiCodecObjectConstructorArgs *args                      \
)                                                                       \
{                                                                       \
    GstVaapiCodecObjectClass *parent_class;                             \
                                                                        \
    parent_class = GST_VAAPI_CODEC_OBJECT_CLASS(prefix##_parent_class); \
    if (parent_class->construct) {                                      \
        if (!parent_class->construct(object, args))                     \
            return FALSE;                                               \
    }                                                                   \
    return prefix##_create((type *)object, args);                       \
}                                                                       \
                                                                        \
static void                                                             \
prefix##_class_init(type##Class *klass)                                 \
{                                                                       \
    GstMiniObjectClass * const object_class =                           \
        GST_MINI_OBJECT_CLASS(klass);                                   \
    GstVaapiCodecObjectClass * const codec_class =                      \
        GST_VAAPI_CODEC_OBJECT_CLASS(klass);                            \
                                                                        \
    object_class->finalize = prefix##_finalize;                         \
    codec_class->construct = prefix##_construct;                        \
}

#define GST_VAAPI_IQ_MATRIX_NEW(codec, decoder)                         \
    gst_vaapi_iq_matrix_new(GST_VAAPI_DECODER_CAST(decoder),            \
                            NULL, sizeof(VAIQMatrixBuffer##codec))

#define GST_VAAPI_BITPLANE_NEW(decoder, size) \
    gst_vaapi_bitplane_new(GST_VAAPI_DECODER_CAST(decoder), NULL, size)

#define GST_VAAPI_HUFFMAN_TABLE_NEW(codec, decoder)                     \
      gst_vaapi_huffman_table_new(GST_VAAPI_DECODER_CAST(decoder),      \
                            NULL, sizeof(VAHuffmanTableBuffer##codec))

G_END_DECLS

#endif /* GST_VAAPI_CODEC_OBJECTS_H */