summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/gstvaapicodec_objects.h
blob: 2d081bde442633dbe89ca44598a8c936d98644a6 (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
/*
 *  gstvaapicodec_objects.h - VA codec objects abstraction
 *
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
 *  Copyright (C) 2011-2014 Intel Corporation
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
 *
 *  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/vaapi/gstvaapiminiobject.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 _GstVaapiBitPlane                GstVaapiBitPlane;
typedef struct _GstVaapiHuffmanTable            GstVaapiHuffmanTable;
typedef struct _GstVaapiProbabilityTable        GstVaapiProbabilityTable;

/* ------------------------------------------------------------------------- */
/* --- 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_CODEC_OBJECT(obj) \
  ((GstVaapiCodecObject *) (obj))

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

typedef struct
{
  gconstpointer param;
  guint param_size;
  gconstpointer data;
  guint data_size;
  guint flags;
} GstVaapiCodecObjectConstructorArgs;

typedef gboolean
(*GstVaapiCodecObjectCreateFunc)(GstVaapiCodecObject * object,
    const GstVaapiCodecObjectConstructorArgs * args);

typedef GDestroyNotify GstVaapiCodecObjectDestroyFunc;

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

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

  GstVaapiCodecObjectCreateFunc create;
};

G_GNUC_INTERNAL
const GstVaapiCodecObjectClass *
gst_vaapi_codec_object_get_class (GstVaapiCodecObject * object) G_GNUC_CONST;

G_GNUC_INTERNAL
GstVaapiCodecObject *
gst_vaapi_codec_object_new (const GstVaapiCodecObjectClass * object_class,
    GstVaapiCodecBase * codec, gconstpointer param, guint param_size,
    gconstpointer data, guint data_size, guint flags);

#define gst_vaapi_codec_object_ref(object) \
  ((gpointer) gst_vaapi_mini_object_ref (GST_VAAPI_MINI_OBJECT (object)))

#define gst_vaapi_codec_object_unref(object) \
  gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (object))

#define gst_vaapi_codec_object_replace(old_object_ptr, new_object) \
  gst_vaapi_mini_object_replace ((GstVaapiMiniObject **) (old_object_ptr), \
      GST_VAAPI_MINI_OBJECT (new_object))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* ------------------------------------------------------------------------- */
/* ---                   Probability (Update) Table                      --- */
/* ------------------------------------------------------------------------- */

#define GST_VAAPI_PROBABILITY_TABLE_CAST(obj) \
    ((GstVaapiProbabilityTable *)(obj))

/**
 * GstVaapiProbabilityTable:
 *
 * A #GstVaapiCodecObject holding an Probability (Update) Table for RAC decoding
 */
struct _GstVaapiProbabilityTable
{
  /*< private > */
  GstVaapiCodecObject parent_instance;
  VABufferID param_id;

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

G_GNUC_INTERNAL
GstVaapiProbabilityTable *
gst_vaapi_probability_table_new (GstVaapiDecoder * decoder,
    gconstpointer param, guint param_size);

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

#define GST_VAAPI_CODEC_DEFINE_TYPE(type, prefix)                       \
G_GNUC_INTERNAL                                                         \
void                                                                    \
G_PASTE (prefix, _destroy) (type *);                                    \
                                                                        \
G_GNUC_INTERNAL                                                         \
gboolean                                                                \
G_PASTE (prefix, _create) (type *,                                      \
    const GstVaapiCodecObjectConstructorArgs * args);                   \
                                                                        \
static const GstVaapiCodecObjectClass G_PASTE (type, Class) = {         \
  .parent_class = {                                                     \
    .size = sizeof (type),                                              \
    .finalize = (GstVaapiCodecObjectDestroyFunc)                        \
        G_PASTE (prefix, _destroy)                                      \
  },                                                                    \
  .create = (GstVaapiCodecObjectCreateFunc)                             \
      G_PASTE (prefix, _create),                                        \
}

#define GST_VAAPI_IQ_MATRIX_NEW(codec, decoder)                         \
  gst_vaapi_iq_matrix_new (GST_VAAPI_DECODER_CAST (decoder),            \
      NULL, sizeof (G_PASTE (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 (G_PASTE (VAHuffmanTableBuffer, codec)))

#define GST_VAAPI_PROBABILITY_TABLE_NEW(codec, decoder)                 \
  gst_vaapi_probability_table_new (GST_VAAPI_DECODER_CAST (decoder),    \
      NULL, sizeof (G_PASTE (VAProbabilityDataBuffer, codec)))

G_END_DECLS

#endif /* GST_VAAPI_CODEC_OBJECTS_H */