1 /*
2  *  gstvaapidecoder_objects.h - VA decoder objects
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_DECODER_OBJECTS_H
26 #define GST_VAAPI_DECODER_OBJECTS_H
27 
28 #include <gst/vaapi/gstvaapicodec_objects.h>
29 
30 G_BEGIN_DECLS
31 
32 typedef struct _GstVaapiPicture         GstVaapiPicture;
33 typedef struct _GstVaapiSlice           GstVaapiSlice;
34 
35 /* ------------------------------------------------------------------------- */
36 /* --- Pictures                                                          --- */
37 /* ------------------------------------------------------------------------- */
38 
39 #define GST_VAAPI_PICTURE_CAST(obj) \
40   ((GstVaapiPicture *) (obj))
41 
42 #define GST_VAAPI_PICTURE(obj) \
43   GST_VAAPI_PICTURE_CAST (obj)
44 
45 #define GST_VAAPI_IS_PICTURE(obj) \
46   (GST_VAAPI_PICTURE (obj) != NULL)
47 
48 typedef enum
49 {
50   GST_VAAPI_PICTURE_TYPE_NONE = 0,      // Undefined
51   GST_VAAPI_PICTURE_TYPE_I,             // Intra
52   GST_VAAPI_PICTURE_TYPE_P,             // Predicted
53   GST_VAAPI_PICTURE_TYPE_B,             // Bi-directional predicted
54   GST_VAAPI_PICTURE_TYPE_S,             // S(GMC)-VOP (MPEG-4)
55   GST_VAAPI_PICTURE_TYPE_SI,            // Switching Intra
56   GST_VAAPI_PICTURE_TYPE_SP,            // Switching Predicted
57   GST_VAAPI_PICTURE_TYPE_BI,            // BI type (VC-1)
58 } GstVaapiPictureType;
59 
60 /**
61  * GstVaapiPictureFlags:
62  * @GST_VAAPI_PICTURE_FLAG_SKIPPED: skipped frame
63  * @GST_VAAPI_PICTURE_FLAG_REFERENCE: reference frame
64  * @GST_VAAPI_PICTURE_FLAG_OUTPUT: frame was output
65  * @GST_VAAPI_PICTURE_FLAG_INTERLACED: interlaced frame
66  * @GST_VAAPI_PICTURE_FLAG_FF: first-field
67  * @GST_VAAPI_PICTURE_FLAG_TFF: top-field-first
68  * @GST_VAAPI_PICTURE_FLAG_ONEFIELD: only one field is valid
69  * @GST_VAAPI_PICTURE_FLAG_MVC: multiview component
70  * @GST_VAAPI_PICTURE_FLAG_RFF: repeat-first-field
71  * @GST_VAAPI_PICTURE_FLAG_CORRUPTED: picture was reconstructed from
72  *   corrupted references
73  * @GST_VAAPI_PICTURE_FLAG_LAST: first flag that can be used by subclasses
74  *
75  * Enum values used for #GstVaapiPicture flags.
76  */
77 typedef enum
78 {
79   GST_VAAPI_PICTURE_FLAG_SKIPPED    = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 0),
80   GST_VAAPI_PICTURE_FLAG_REFERENCE  = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 1),
81   GST_VAAPI_PICTURE_FLAG_OUTPUT     = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 2),
82   GST_VAAPI_PICTURE_FLAG_INTERLACED = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 3),
83   GST_VAAPI_PICTURE_FLAG_FF         = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 4),
84   GST_VAAPI_PICTURE_FLAG_TFF        = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 5),
85   GST_VAAPI_PICTURE_FLAG_ONEFIELD   = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 6),
86   GST_VAAPI_PICTURE_FLAG_MVC        = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 7),
87   GST_VAAPI_PICTURE_FLAG_RFF        = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 8),
88   GST_VAAPI_PICTURE_FLAG_CORRUPTED  = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 9),
89   GST_VAAPI_PICTURE_FLAG_LAST       = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 10),
90 } GstVaapiPictureFlags;
91 
92 #define GST_VAAPI_PICTURE_FLAGS         GST_VAAPI_MINI_OBJECT_FLAGS
93 #define GST_VAAPI_PICTURE_FLAG_IS_SET   GST_VAAPI_MINI_OBJECT_FLAG_IS_SET
94 #define GST_VAAPI_PICTURE_FLAG_SET      GST_VAAPI_MINI_OBJECT_FLAG_SET
95 #define GST_VAAPI_PICTURE_FLAG_UNSET    GST_VAAPI_MINI_OBJECT_FLAG_UNSET
96 
97 #define GST_VAAPI_PICTURE_IS_SKIPPED(picture) \
98   GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_SKIPPED)
99 
100 #define GST_VAAPI_PICTURE_IS_REFERENCE(picture) \
101   GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_REFERENCE)
102 
103 #define GST_VAAPI_PICTURE_IS_OUTPUT(picture) \
104   GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_OUTPUT)
105 
106 #define GST_VAAPI_PICTURE_IS_INTERLACED(picture) \
107   GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_INTERLACED)
108 
109 #define GST_VAAPI_PICTURE_IS_FIRST_FIELD(picture) \
110   GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_FF)
111 
112 #define GST_VAAPI_PICTURE_IS_TFF(picture) \
113   GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_TFF)
114 
115 #define GST_VAAPI_PICTURE_IS_RFF(picture) \
116   GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_RFF)
117 
118 #define GST_VAAPI_PICTURE_IS_ONEFIELD(picture) \
119   GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_ONEFIELD)
120 
121 #define GST_VAAPI_PICTURE_IS_FRAME(picture) \
122   (GST_VAAPI_PICTURE (picture)->structure == GST_VAAPI_PICTURE_STRUCTURE_FRAME)
123 
124 #define GST_VAAPI_PICTURE_IS_COMPLETE(picture)          \
125   (GST_VAAPI_PICTURE_IS_FRAME (picture) ||              \
126    GST_VAAPI_PICTURE_IS_ONEFIELD (picture) ||           \
127    !GST_VAAPI_PICTURE_IS_FIRST_FIELD (picture))
128 
129 #define GST_VAAPI_PICTURE_IS_MVC(picture) \
130   (GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_MVC))
131 
132 #define GST_VAAPI_PICTURE_IS_CORRUPTED(picture) \
133   (GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_CORRUPTED))
134 
135 /**
136  * GstVaapiPicture:
137  *
138  * A #GstVaapiCodecObject holding a picture parameter.
139  */
140 struct _GstVaapiPicture
141 {
142   /*< private >*/
143   GstVaapiCodecObject parent_instance;
144   GstVaapiPicture *parent_picture;
145   GstVideoCodecFrame *frame;
146   GstVaapiSurface *surface;
147   GstVaapiSurfaceProxy *proxy;
148   VABufferID param_id;
149   guint param_size;
150 
151   /*< public >*/
152   GstVaapiPictureType type;
153   VASurfaceID surface_id;
154   gpointer param;
155   GPtrArray *slices;
156   GstVaapiIqMatrix *iq_matrix;
157   GstVaapiHuffmanTable *huf_table;
158   GstVaapiBitPlane *bitplane;
159   GstVaapiProbabilityTable *prob_table;
160   GstClockTime pts;
161   gint32 poc;
162   guint16 voc;
163   guint16 view_id;
164   guint structure;
165   GstVaapiRectangle crop_rect;
166   guint has_crop_rect:1;
167 };
168 
169 G_GNUC_INTERNAL
170 void
171 gst_vaapi_picture_destroy (GstVaapiPicture * picture);
172 
173 G_GNUC_INTERNAL
174 gboolean
175 gst_vaapi_picture_create (GstVaapiPicture * picture,
176     const GstVaapiCodecObjectConstructorArgs * args);
177 
178 G_GNUC_INTERNAL
179 GstVaapiPicture *
180 gst_vaapi_picture_new (GstVaapiDecoder * decoder,
181     gconstpointer param, guint param_size);
182 
183 G_GNUC_INTERNAL
184 GstVaapiPicture *
185 gst_vaapi_picture_new_field (GstVaapiPicture * picture);
186 
187 G_GNUC_INTERNAL
188 GstVaapiPicture *
189 gst_vaapi_picture_new_clone (GstVaapiPicture * picture);
190 
191 G_GNUC_INTERNAL
192 void
193 gst_vaapi_picture_add_slice (GstVaapiPicture * picture, GstVaapiSlice * slice);
194 
195 G_GNUC_INTERNAL
196 gboolean
197 gst_vaapi_picture_decode (GstVaapiPicture * picture);
198 
199 G_GNUC_INTERNAL
200 gboolean
201 gst_vaapi_picture_output (GstVaapiPicture * picture);
202 
203 G_GNUC_INTERNAL
204 void
205 gst_vaapi_picture_set_crop_rect (GstVaapiPicture * picture,
206     const GstVaapiRectangle * crop_rect);
207 
208 #define gst_vaapi_picture_ref(picture) \
209   gst_vaapi_codec_object_ref (picture)
210 
211 #define gst_vaapi_picture_unref(picture) \
212   gst_vaapi_codec_object_unref (picture)
213 
214 #define gst_vaapi_picture_replace(old_picture_ptr, new_picture) \
215   gst_vaapi_codec_object_replace (old_picture_ptr, new_picture)
216 
217 /* ------------------------------------------------------------------------- */
218 /* --- Slices                                                            --- */
219 /* ------------------------------------------------------------------------- */
220 
221 #define GST_VAAPI_SLICE_CAST(obj) \
222   ((GstVaapiSlice *) (obj))
223 
224 #define GST_VAAPI_SLICE(obj) \
225   GST_VAAPI_SLICE_CAST (obj)
226 
227 #define GST_VAAPI_IS_SLICE(obj) \
228   (GST_VAAPI_SLICE (obj) != NULL)
229 
230 /**
231  * GstVaapiSlice:
232  *
233  * A #GstVaapiCodecObject holding a slice parameter.
234  */
235 struct _GstVaapiSlice
236 {
237   /*< private >*/
238   GstVaapiCodecObject parent_instance;
239 
240   /*< public >*/
241   VABufferID param_id;
242   VABufferID data_id;
243   gpointer param;
244 
245   /* Per-slice overrides */
246   GstVaapiHuffmanTable *huf_table;
247 };
248 
249 G_GNUC_INTERNAL
250 void
251 gst_vaapi_slice_destroy (GstVaapiSlice * slice);
252 
253 G_GNUC_INTERNAL
254 gboolean
255 gst_vaapi_slice_create (GstVaapiSlice * slice,
256     const GstVaapiCodecObjectConstructorArgs * args);
257 
258 G_GNUC_INTERNAL
259 GstVaapiSlice *
260 gst_vaapi_slice_new (GstVaapiDecoder * decoder, gconstpointer param,
261     guint param_size, const guchar * data, guint data_size);
262 
263 /* ------------------------------------------------------------------------- */
264 /* --- Helpers to create codec-dependent objects                         --- */
265 /* ------------------------------------------------------------------------- */
266 
267 #define GST_VAAPI_PICTURE_NEW(codec, decoder)                   \
268   gst_vaapi_picture_new (GST_VAAPI_DECODER_CAST (decoder),      \
269       NULL, sizeof (G_PASTE (VAPictureParameterBuffer, codec)))
270 
271 #define GST_VAAPI_SLICE_NEW(codec, decoder, buf, buf_size)      \
272   gst_vaapi_slice_new (GST_VAAPI_DECODER_CAST (decoder),        \
273       NULL, sizeof (G_PASTE (VASliceParameterBuffer, codec)),   \
274       buf, buf_size)
275 
276 G_END_DECLS
277 
278 #endif /* GST_VAAPI_DECODER_OBJECTS_H */
279