decoder: use POC to maintain the DPB.
[vaapi:hkaelbers-gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapidecoder_objects.h
1 /*
2  *  gstvaapidecoder_objects.h - VA decoder objects
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_DECODER_OBJECTS_H
24 #define GST_VAAPI_DECODER_OBJECTS_H
25
26 #include <gst/vaapi/gstvaapicodec_objects.h>
27
28 G_BEGIN_DECLS
29
30 typedef enum _GstVaapiPictureType       GstVaapiPictureType;
31 typedef struct _GstVaapiPicture         GstVaapiPicture;
32 typedef struct _GstVaapiPictureClass    GstVaapiPictureClass;
33 typedef struct _GstVaapiSlice           GstVaapiSlice;
34 typedef struct _GstVaapiSliceClass      GstVaapiSliceClass;
35
36 /* ------------------------------------------------------------------------- */
37 /* --- Pictures                                                          --- */
38 /* ------------------------------------------------------------------------- */
39
40 #define GST_VAAPI_TYPE_PICTURE \
41     (gst_vaapi_picture_get_type())
42
43 #define GST_VAAPI_PICTURE_CAST(obj) \
44     ((GstVaapiPicture *)(obj))
45
46 #define GST_VAAPI_PICTURE(obj)                          \
47     (G_TYPE_CHECK_INSTANCE_CAST((obj),                  \
48                                 GST_VAAPI_TYPE_PICTURE, \
49                                 GstVaapiPicture))
50
51 #define GST_VAAPI_PICTURE_CLASS(klass)                  \
52     (G_TYPE_CHECK_CLASS_CAST((klass),                   \
53                              GST_VAAPI_TYPE_PICTURE,    \
54                              GstVaapiPictureClass))
55
56 #define GST_VAAPI_IS_PICTURE(obj) \
57     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_PICTURE))
58
59 #define GST_VAAPI_IS_PICTURE_CLASS(klass) \
60     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_PICTURE))
61
62 #define GST_VAAPI_PICTURE_GET_CLASS(obj)                \
63     (G_TYPE_INSTANCE_GET_CLASS((obj),                   \
64                                GST_VAAPI_TYPE_PICTURE,  \
65                                GstVaapiPictureClass))
66
67 enum _GstVaapiPictureType {
68     GST_VAAPI_PICTURE_TYPE_NONE = 0,        // Undefined
69     GST_VAAPI_PICTURE_TYPE_I,               // Intra
70     GST_VAAPI_PICTURE_TYPE_P,               // Predicted
71     GST_VAAPI_PICTURE_TYPE_B,               // Bi-directional predicted
72     GST_VAAPI_PICTURE_TYPE_S,               // S(GMC)-VOP (MPEG-4)
73     GST_VAAPI_PICTURE_TYPE_SI,              // Switching Intra
74     GST_VAAPI_PICTURE_TYPE_SP,              // Switching Predicted
75     GST_VAAPI_PICTURE_TYPE_BI,              // BI type (VC-1)
76 };
77
78 /**
79  * Picture flags:
80  * @GST_VAAPI_PICTURE_FLAG_SKIPPED: skipped frame
81  * @GST_VAAPI_PICTURE_FLAG_REFERENCE: reference frame
82  * @GST_VAAPI_PICTURE_FLAG_OUTPUT: frame was output
83  * @GST_VAAPI_PICTURE_FLAG_INTERLACED: interlaced frame
84  * @GST_VAAPI_PICTURE_FLAG_FF: first-field
85  * @GST_VAAPI_PICTURE_FLAG_TFF: top-field-first
86  * @GST_VAAPI_PICTURE_FLAG_LAST: first flag that can be used by subclasses
87  *
88  * Enum values used for #GstVaapiPicture flags.
89  */
90 enum {
91     GST_VAAPI_PICTURE_FLAG_SKIPPED    = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 0),
92     GST_VAAPI_PICTURE_FLAG_REFERENCE  = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 1),
93     GST_VAAPI_PICTURE_FLAG_OUTPUT     = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 2),
94     GST_VAAPI_PICTURE_FLAG_INTERLACED = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 3),
95     GST_VAAPI_PICTURE_FLAG_FF         = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 4),
96     GST_VAAPI_PICTURE_FLAG_TFF        = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 5),
97     GST_VAAPI_PICTURE_FLAG_LAST       = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 6),
98 };
99
100 #define GST_VAAPI_PICTURE_FLAGS         GST_MINI_OBJECT_FLAGS
101 #define GST_VAAPI_PICTURE_FLAG_IS_SET   GST_MINI_OBJECT_FLAG_IS_SET
102 #define GST_VAAPI_PICTURE_FLAG_SET      GST_MINI_OBJECT_FLAG_SET
103 #define GST_VAAPI_PICTURE_FLAG_UNSET    GST_MINI_OBJECT_FLAG_UNSET
104
105 #define GST_VAAPI_PICTURE_IS_SKIPPED(picture) \
106     GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_SKIPPED)
107
108 #define GST_VAAPI_PICTURE_IS_REFERENCE(picture) \
109     GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_REFERENCE)
110
111 #define GST_VAAPI_PICTURE_IS_OUTPUT(picture) \
112     GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_OUTPUT)
113
114 #define GST_VAAPI_PICTURE_IS_INTERLACED(picture) \
115     GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_INTERLACED)
116
117 #define GST_VAAPI_PICTURE_IS_FIRST_FIELD(picture) \
118     GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_FF)
119
120 #define GST_VAAPI_PICTURE_IS_TFF(picture) \
121     GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_TFF)
122
123 #define GST_VAAPI_PICTURE_IS_FRAME(picture) \
124     (GST_VAAPI_PICTURE(picture)->structure == GST_VAAPI_PICTURE_STRUCTURE_FRAME)
125
126 #define GST_VAAPI_PICTURE_IS_COMPLETE(picture)          \
127     (GST_VAAPI_PICTURE_IS_FRAME(picture) ||             \
128      !GST_VAAPI_PICTURE_IS_FIRST_FIELD(picture))
129
130 /**
131  * GstVaapiPicture:
132  *
133  * A #GstVaapiCodecObject holding a picture parameter.
134  */
135 struct _GstVaapiPicture {
136     /*< private >*/
137     GstVaapiCodecObject         parent_instance;
138     GstVaapiSurface            *surface;
139     GstVaapiSurfaceProxy       *proxy;
140     VABufferID                  param_id;
141     guint                       param_size;
142
143     /*< public >*/
144     GstVaapiPictureType         type;
145     VASurfaceID                 surface_id;
146     gpointer                    param;
147     GPtrArray                  *slices;
148     GstVaapiIqMatrix           *iq_matrix;
149     GstVaapiBitPlane           *bitplane;
150     GstClockTime                pts;
151     gint32                      poc;
152     guint                       structure;
153 };
154
155 /**
156  * GstVaapiPictureClass:
157  *
158  * The #GstVaapiPicture base class.
159  */
160 struct _GstVaapiPictureClass {
161     /*< private >*/
162     GstVaapiCodecObjectClass    parent_class;
163 };
164
165 GType
166 gst_vaapi_picture_get_type(void)
167     attribute_hidden;
168
169 GstVaapiPicture *
170 gst_vaapi_picture_new(
171     GstVaapiDecoder *decoder,
172     gconstpointer    param,
173     guint            param_size
174 ) attribute_hidden;
175
176 GstVaapiPicture *
177 gst_vaapi_picture_new_field(GstVaapiPicture *picture)
178     attribute_hidden;
179
180 void
181 gst_vaapi_picture_add_slice(GstVaapiPicture *picture, GstVaapiSlice *slice)
182     attribute_hidden;
183
184 gboolean
185 gst_vaapi_picture_decode(GstVaapiPicture *picture)
186     attribute_hidden;
187
188 gboolean
189 gst_vaapi_picture_output(GstVaapiPicture *picture)
190     attribute_hidden;
191
192 static inline gpointer
193 gst_vaapi_picture_ref(gpointer ptr)
194 {
195     return gst_mini_object_ref(GST_MINI_OBJECT(ptr));
196 }
197
198 static inline void
199 gst_vaapi_picture_unref(gpointer ptr)
200 {
201     gst_mini_object_unref(GST_MINI_OBJECT(ptr));
202 }
203
204 #define gst_vaapi_picture_replace(old_picture_p, new_picture)   \
205     gst_mini_object_replace((GstMiniObject **)(old_picture_p),  \
206                             (GstMiniObject *)(new_picture))
207
208 /* ------------------------------------------------------------------------- */
209 /* --- Slices                                                            --- */
210 /* ------------------------------------------------------------------------- */
211
212 #define GST_VAAPI_TYPE_SLICE \
213     (gst_vaapi_slice_get_type())
214
215 #define GST_VAAPI_SLICE_CAST(obj) \
216     ((GstVaapiSlice *)(obj))
217
218 #define GST_VAAPI_SLICE(obj)                            \
219     (G_TYPE_CHECK_INSTANCE_CAST((obj),                  \
220                                 GST_VAAPI_TYPE_SLICE,   \
221                                 GstVaapiSlice))
222
223 #define GST_VAAPI_SLICE_CLASS(klass)                    \
224     (G_TYPE_CHECK_CLASS_CAST((klass),                   \
225                              GST_VAAPI_TYPE_SLICE,      \
226                              GstVaapiSliceClass))
227
228 #define GST_VAAPI_IS_SLICE(obj) \
229     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_SLICE))
230
231 #define GST_VAAPI_IS_SLICE_CLASS(klass) \
232     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_SLICE))
233
234 #define GST_VAAPI_SLICE_GET_CLASS(obj)                  \
235     (G_TYPE_INSTANCE_GET_CLASS((obj),                   \
236                                GST_VAAPI_TYPE_SLICE,    \
237                                GstVaapiSliceClass))
238
239 /**
240  * GstVaapiSlice:
241  *
242  * A #GstVaapiCodecObject holding a slice parameter.
243  */
244 struct _GstVaapiSlice {
245     /*< private >*/
246     GstVaapiCodecObject         parent_instance;
247
248     /*< public >*/
249     VABufferID                  param_id;
250     VABufferID                  data_id;
251     gpointer                    param;
252 };
253
254 /**
255  * GstVaapiSliceClass:
256  *
257  * The #GstVaapiSlice base class.
258  */
259 struct _GstVaapiSliceClass {
260     /*< private >*/
261     GstVaapiCodecObjectClass    parent_class;
262 };
263
264 GType
265 gst_vaapi_slice_get_type(void)
266     attribute_hidden;
267
268 GstVaapiSlice *
269 gst_vaapi_slice_new(
270     GstVaapiDecoder *decoder,
271     gconstpointer    param,
272     guint            param_size,
273     const guchar    *data,
274     guint            data_size
275 ) attribute_hidden;
276
277 /* ------------------------------------------------------------------------- */
278 /* --- Helpers to create codec-dependent objects                         --- */
279 /* ------------------------------------------------------------------------- */
280
281 #define GST_VAAPI_PICTURE_NEW(codec, decoder)                           \
282     gst_vaapi_picture_new(GST_VAAPI_DECODER_CAST(decoder),              \
283                           NULL, sizeof(VAPictureParameterBuffer##codec))
284
285 #define GST_VAAPI_SLICE_NEW(codec, decoder, buf, buf_size)              \
286     gst_vaapi_slice_new(GST_VAAPI_DECODER_CAST(decoder),                \
287                         NULL, sizeof(VASliceParameterBuffer##codec),    \
288                         buf, buf_size)
289
290 G_END_DECLS
291
292 #endif /* GST_VAAPI_DECODER_OBJECTS_H */