Userful gstreamer-vaapi
[vaapi:cpu-gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapiencoder_objects.h
1 /*
2  *  gstvaapiencoder_objects.h - VA encoder objects abstraction
3  *
4  *  Copyright (C) 2013-2014 Intel Corporation
5  *    Author: Wind Yuan <feng.yuan@intel.com>
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_ENCODER_OBJECTS_H
24 #define GST_VAAPI_ENCODER_OBJECTS_H
25
26 #include <gst/vaapi/gstvaapicodec_objects.h>
27 #include <gst/vaapi/gstvaapidecoder_objects.h>
28 #include <gst/vaapi/gstvaapiencoder.h>
29
30 G_BEGIN_DECLS
31
32 typedef struct _GstVaapiEncPicture GstVaapiEncPicture;
33 typedef struct _GstVaapiEncSequence GstVaapiEncSequence;
34 typedef struct _GstVaapiEncMiscParam GstVaapiEncMiscParam;
35 typedef struct _GstVaapiEncSlice GstVaapiEncSlice;
36 //typedef struct _GstVaapiCodedBuffer GstVaapiCodedBuffer;
37 typedef struct _GstVaapiEncPackedHeader GstVaapiEncPackedHeader;
38
39 /* ------------------------------------------------------------------------- */
40 /* --- Encoder Packed Header                                             --- */
41 /* ------------------------------------------------------------------------- */
42
43 #define GST_VAAPI_ENC_PACKED_HEADER(obj) \
44   ((GstVaapiEncPackedHeader *) (obj))
45
46 /**
47  * GstVaapiEncPackedHeader:
48  *
49  * A #GstVaapiCodecObject holding a packed header (param/data) for the
50  * encoder.
51  */
52 struct _GstVaapiEncPackedHeader
53 {
54   /*< private >*/
55   GstVaapiCodecObject parent_instance;
56
57   /*< public >*/
58   VABufferID param_id;
59   gpointer param;
60   VABufferID data_id;
61   gpointer data;
62 };
63
64 G_GNUC_INTERNAL
65 GstVaapiEncPackedHeader *
66 gst_vaapi_enc_packed_header_new (GstVaapiEncoder * encoder,
67     gconstpointer param, guint param_size, gconstpointer data, guint data_size);
68
69 G_GNUC_INTERNAL
70 gboolean
71 gst_vaapi_enc_packed_header_set_data (GstVaapiEncPackedHeader * header,
72     gconstpointer data, guint data_size);
73
74 /* ------------------------------------------------------------------------- */
75 /* --- Encoder Sequence                                                  --- */
76 /* ------------------------------------------------------------------------- */
77
78 #define GST_VAAPI_ENC_SEQUENCE(obj) \
79   ((GstVaapiEncSequence *) (obj))
80
81 /**
82  * GstVaapiEncSequence:
83  *
84  * A #GstVaapiCodecObject holding a sequence parameter for encoding.
85  */
86 struct _GstVaapiEncSequence
87 {
88   /*< private >*/
89   GstVaapiCodecObject parent_instance;
90
91   /*< public >*/
92   VABufferID param_id;
93   gpointer param;
94 };
95
96 G_GNUC_INTERNAL
97 GstVaapiEncSequence *
98 gst_vaapi_enc_sequence_new (GstVaapiEncoder * encoder,
99     gconstpointer param, guint param_size);
100
101 /* ------------------------------------------------------------------------- */
102 /* --- Encoder Slice                                                     --- */
103 /* ------------------------------------------------------------------------- */
104
105 #define GST_VAAPI_ENC_SLICE(obj) \
106   ((GstVaapiEncSlice *) (obj))
107
108 /**
109  * GstVaapiEncSlice:
110  *
111  * A #GstVaapiCodecObject holding a slice parameter used for encoding.
112  */
113 struct _GstVaapiEncSlice
114 {
115   /*< private >*/
116   GstVaapiCodecObject parent_instance;
117
118   /*< public >*/
119   VABufferID param_id;
120   gpointer param;
121 };
122
123 G_GNUC_INTERNAL
124 GstVaapiEncSlice *
125 gst_vaapi_enc_slice_new (GstVaapiEncoder * encoder,
126     gconstpointer param, guint param_size);
127
128 /* ------------------------------------------------------------------------- */
129 /* --- Encoder Misc Parameter Buffer                                     --- */
130 /* ------------------------------------------------------------------------- */
131
132 #define GST_VAAPI_ENC_MISC_PARAM(obj) \
133   ((GstVaapiEncMiscParam *) (obj))
134
135 /**
136  * GstVaapiEncMiscParam:
137  *
138  * A #GstVaapiCodecObject holding a misc parameter and associated data
139  * used for controlling the encoder dynamically.
140  */
141 struct _GstVaapiEncMiscParam
142 {
143   /*< private >*/
144   GstVaapiCodecObject parent_instance;
145   gpointer param;
146
147   /*< public >*/
148   VABufferID param_id;
149   gpointer data;
150 };
151
152 G_GNUC_INTERNAL
153 GstVaapiEncMiscParam *
154 gst_vaapi_enc_misc_param_new (GstVaapiEncoder * encoder,
155     VAEncMiscParameterType type, guint data_size);
156
157 /* ------------------------------------------------------------------------- */
158 /* --- Encoder Picture                                                   --- */
159 /* ------------------------------------------------------------------------- */
160
161 #define GST_VAAPI_ENC_PICTURE(obj) \
162   ((GstVaapiEncPicture *) (obj))
163
164 typedef enum
165 {
166   GST_VAAPI_ENC_PICTURE_FLAG_IDR    = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 0),
167   GST_VAAPI_ENC_PICTURE_FLAG_LAST   = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 1),
168 } GstVaapiEncPictureFlags;
169
170 #define GST_VAAPI_ENC_PICTURE_FLAGS         GST_VAAPI_MINI_OBJECT_FLAGS
171 #define GST_VAAPI_ENC_PICTURE_FLAG_IS_SET   GST_VAAPI_MINI_OBJECT_FLAG_IS_SET
172 #define GST_VAAPI_ENC_PICTURE_FLAG_SET      GST_VAAPI_MINI_OBJECT_FLAG_SET
173 #define GST_VAAPI_ENC_PICTURE_FLAG_UNSET    GST_VAAPI_MINI_OBJECT_FLAG_UNSET
174
175 #define GST_VAAPI_ENC_PICTURE_IS_IDR(picture) \
176     GST_VAAPI_ENC_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_ENC_PICTURE_FLAG_IDR)
177
178 /**
179  * GstVaapiEncPicture:
180  *
181  * A #GstVaapiCodecObject holding a picture parameter for encoding.
182  */
183 struct _GstVaapiEncPicture
184 {
185   /*< private >*/
186   GstVaapiCodecObject parent_instance;
187   GstVideoCodecFrame *frame;
188   GstVaapiSurfaceProxy *proxy;
189   GstVaapiSurface *surface;
190   VABufferID param_id;
191   guint param_size;
192
193   /* Additional data to pass down */
194   GstVaapiEncSequence *sequence;
195   GPtrArray *packed_headers;
196   GPtrArray *misc_params;
197
198   /*< public >*/
199   GstVaapiPictureType type;
200   VASurfaceID surface_id;
201   gpointer param;
202   GPtrArray *slices;
203   GstClockTime pts;
204   guint frame_num;
205   guint poc;
206 };
207
208 G_GNUC_INTERNAL
209 GstVaapiEncPicture *
210 gst_vaapi_enc_picture_new (GstVaapiEncoder * encoder,
211     gconstpointer param, guint param_size, GstVideoCodecFrame * frame);
212
213 G_GNUC_INTERNAL
214 void
215 gst_vaapi_enc_picture_set_sequence (GstVaapiEncPicture * picture,
216     GstVaapiEncSequence * sequence);
217
218 G_GNUC_INTERNAL
219 void
220 gst_vaapi_enc_picture_add_packed_header (GstVaapiEncPicture * picture,
221     GstVaapiEncPackedHeader * header);
222
223 G_GNUC_INTERNAL
224 void
225 gst_vaapi_enc_picture_add_misc_param (GstVaapiEncPicture * picture,
226     GstVaapiEncMiscParam * misc);
227
228 G_GNUC_INTERNAL
229 void
230 gst_vaapi_enc_picture_add_slice (GstVaapiEncPicture * picture,
231     GstVaapiEncSlice * slice);
232
233 G_GNUC_INTERNAL
234 gboolean
235 gst_vaapi_enc_picture_encode (GstVaapiEncPicture * picture);
236
237 #define gst_vaapi_enc_picture_ref(picture) \
238   gst_vaapi_codec_object_ref (picture)
239 #define gst_vaapi_enc_picture_unref(picture) \
240   gst_vaapi_codec_object_unref (picture)
241 #define gst_vaapi_enc_picture_replace(old_picture_ptr, new_picture) \
242   gst_vaapi_codec_object_replace (old_picture_ptr, new_picture)
243
244 /* ------------------------------------------------------------------------- */
245 /* --- Helpers to create codec-dependent objects                         --- */
246 /* ------------------------------------------------------------------------- */
247
248 /* GstVaapiEncSequence */
249 #define GST_VAAPI_ENC_SEQUENCE_NEW(codec, encoder)                      \
250   gst_vaapi_enc_sequence_new (GST_VAAPI_ENCODER_CAST (encoder),         \
251       NULL, sizeof (G_PASTE (VAEncSequenceParameterBuffer, codec)))
252
253 /* GstVaapiEncMiscParam */
254 #define GST_VAAPI_ENC_MISC_PARAM_NEW(type, encoder)                     \
255   gst_vaapi_enc_misc_param_new (GST_VAAPI_ENCODER_CAST (encoder),       \
256       G_PASTE (VAEncMiscParameterType, type),                           \
257       sizeof (G_PASTE (VAEncMiscParameter, type)))
258
259 /* GstVaapiEncPicture  */
260 #define GST_VAAPI_ENC_PICTURE_NEW(codec, encoder, frame)                \
261   gst_vaapi_enc_picture_new (GST_VAAPI_ENCODER_CAST (encoder),          \
262       NULL, sizeof (G_PASTE (VAEncPictureParameterBuffer, codec)), frame)
263
264 /* GstVaapiEncSlice */
265 #define GST_VAAPI_ENC_SLICE_NEW(codec, encoder)                         \
266   gst_vaapi_enc_slice_new (GST_VAAPI_ENCODER_CAST (encoder),            \
267       NULL, sizeof(G_PASTE (VAEncSliceParameterBuffer, codec)))
268
269 G_END_DECLS
270
271 #endif /* GST_VAAPI_ENCODER_OBJECTS_H */