2 * gstvaapiencoder.h - VA-API encoder interface
4 * Copyright (C) 2011 Intel Corporation
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #ifndef GST_VAAPI_ENCODER_H
23 #define GST_VAAPI_ENCODER_H
28 #include "gst/gstinfo.h"
29 #include "gst/gstbuffer.h"
31 #include "gst/vaapi/gstvaapidisplay.h"
32 #include "gst/vaapi/gstvaapicontext.h"
36 #define ENCODER_NO_ERROR 0
37 #define ENCODER_NO_DATA 1
38 #define ENCODER_NO_BUSY_BUF 2
39 #define ENCODER_NO_IDLE_BUF 3
40 #define ENCODER_FRAME_IN_ORDER 4
42 #define ENCODER_MEM_ERR -1
43 #define ENCODER_DISPLAY_ERR -2
44 #define ENCODER_CONFIG_ERR -3
45 #define ENCODER_CONTEXT_ERR -3
46 #define ENCODER_STATE_ERR -4
47 #define ENCODER_ENC_RES_ERR -5
48 #define ENCODER_PICTURE_ERR -6
49 #define ENCODER_SURFACE_ERR -7
50 #define ENCODER_QUERY_STATUS_ERR -8
51 #define ENCODER_DATA_NOT_READY -9
52 #define ENCODER_DATA_ERR -10
53 #define ENCODER_PROFILE_ERR -11
54 #define ENCODER_PARAMETER_ERR -12
55 #define ENCODER_FUNC_PTR_ERR -13
58 #define ENCODER_LOG_ERROR(str_fmt,...) \
59 fprintf(stdout, str_fmt "\n", ## __VA_ARGS__)
60 #define ENCODER_LOG_WARNING(str_fmt,...) \
61 fprintf(stdout, str_fmt "\n", ## __VA_ARGS__)
62 #define ENCODER_LOG_DEBUG(str_fmt,...) \
63 fprintf(stdout, str_fmt "\n", ## __VA_ARGS__)
64 #define ENCODER_LOG_INFO(str_fmt,...) \
65 fprintf(stdout, str_fmt "\n", ## __VA_ARGS__)
67 #define ENCODER_LOG_ERROR(...) GST_ERROR( __VA_ARGS__)
68 #define ENCODER_LOG_WARNING(...) GST_WARNING( __VA_ARGS__)
69 #define ENCODER_LOG_DEBUG(...) GST_DEBUG( __VA_ARGS__)
70 #define ENCODER_LOG_INFO(...) GST_INFO( __VA_ARGS__)
73 #define VAAPI_UNUSED_ARG(arg) (void)(arg)
77 #define ENCODER_ASSERT(exp) assert(exp)
79 #define ENCODER_ASSERT(exp) g_assert(exp)
82 #define ENCODER_CHECK_STATUS(exp, err_num, err_reason, ...) \
84 ENCODER_ASSERT(FALSE); \
86 ENCODER_LOG_ERROR(err_reason, ## __VA_ARGS__); \
90 /* must have <gboolean is_locked = FALSE;> declared first*/
91 #define ENCODER_ACQUIRE_DISPLAY_LOCK(display) \
93 GST_VAAPI_DISPLAY_LOCK(display); \
97 #define ENCODER_RELEASE_DISPLAY_LOCK(display) \
99 GST_VAAPI_DISPLAY_UNLOCK(display); \
109 } VAAPI_Encode_State;
111 typedef int EncoderStatus;
112 typedef struct _GstVaapiEncoder GstVaapiEncoder;
113 typedef struct _GstVaapiEncoderPrivate GstVaapiEncoderPrivate;
114 typedef struct _GstVaapiEncoderClass GstVaapiEncoderClass;
116 #define GST_TYPE_VAAPI_ENCODER \
117 (gst_vaapi_encoder_get_type())
119 #define GST_IS_VAAPI_ENCODER(obj) \
120 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VAAPI_ENCODER))
122 #define GST_IS_VAAPI_ENCODER_CLASS(klass) \
123 (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VAAPI_ENCODER))
125 #define GST_VAAPI_ENCODER_GET_CLASS(obj) \
126 (G_TYPE_INSTANCE_GET_CLASS ((obj), \
127 GST_TYPE_VAAPI_ENCODER, \
128 GstVaapiEncoderClass))
130 #define GST_VAAPI_ENCODER(obj) \
131 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
132 GST_TYPE_VAAPI_ENCODER, \
135 #define GST_VAAPI_ENCODER_CLASS(klass) \
136 (G_TYPE_CHECK_CLASS_CAST ((klass), \
137 GST_TYPE_VAAPI_ENCODER, \
138 GstVaapiEncoderClass))
140 #define GST_VAAPI_ENCODER_GET_PRIVATE(obj) \
141 (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
142 GST_TYPE_VAAPI_ENCODER, \
143 GstVaapiEncoderPrivate))
145 #define GST_VAAPI_ENCODER_CAST(encoder) \
146 ((GstVaapiEncoder *)(encoder))
148 /* Get GstVaapiDisplay* */
149 #define ENCODER_DISPLAY(encoder) \
150 (((GstVaapiEncoder*)(encoder))->priv->display)
153 #define ENCODER_VA_DISPLAY(encoder) \
154 (((GstVaapiEncoder*)(encoder))->priv->va_display)
156 /* Get GstVaapiContext* */
157 #define ENCODER_CONTEXT(encoder) \
158 (((GstVaapiEncoder*)(encoder))->priv->context)
161 #define ENCODER_VA_CONTEXT(encoder) \
162 (((GstVaapiEncoder*)(encoder))->priv->va_context)
164 #define ENCODER_WIDTH(encoder) (((GstVaapiEncoder*)(encoder))->width)
165 #define ENCODER_HEIGHT(encoder) (((GstVaapiEncoder*)(encoder))->height)
166 #define ENCODER_FPS(encoder) (((GstVaapiEncoder*)(encoder))->frame_rate)
167 #define ENCODER_RATE_CONTROL(encoder) \
168 (((GstVaapiEncoder*)(encoder))->rate_control)
170 struct _GstVaapiEncoder {
172 GstVaapiEncoderPrivate *priv;
177 GstVaapiRateControl rate_control;
180 struct _GstVaapiEncoderClass {
181 GObjectClass parent_class;
183 EncoderStatus (*initialize) (GstVaapiEncoder* encoder); /* can be NULL */
184 EncoderStatus (*uninitialize) (GstVaapiEncoder* encoder); /* can be NULL */
187 EncoderStatus (*open) (GstVaapiEncoder* encoder,
188 GstVaapiContext **context);
190 EncoderStatus (*close) (GstVaapiEncoder* encoder);
191 EncoderStatus (*encode) (GstVaapiEncoder* encoder,
194 EncoderStatus (*get_buf) (GstVaapiEncoder* encoder,
196 EncoderStatus (*flush) (GstVaapiEncoder* encoder);
198 /* get_codec_data can be NULL */
199 EncoderStatus (*get_codec_data)(GstVaapiEncoder* encoder, GstBuffer **codec_data);
202 struct _GstVaapiEncoderPrivate {
203 GstVaapiDisplay *display;
204 VADisplay va_display;
205 GstVaapiContext *context;
206 VAContextID va_context;
207 VAAPI_Encode_State state;
211 gst_vaapi_encoder_get_type(void);
213 /* set/get display */
215 gst_vaapi_encoder_set_display(
216 GstVaapiEncoder* encoder,
217 GstVaapiDisplay *display
220 gst_vaapi_encoder_get_display(GstVaapiEncoder* encoder);
224 gst_vaapi_encoder_get_context(GstVaapiEncoder* encoder);
226 /* get encoding state */
228 gst_vaapi_encoder_get_state(GstVaapiEncoder* encoder);
230 /* check/open display */
232 gst_vaapi_encoder_initialize(GstVaapiEncoder* encoder);
234 /* check/open context */
236 gst_vaapi_encoder_open(GstVaapiEncoder* encoder);
238 /* encode one frame */
240 gst_vaapi_encoder_encode(
241 GstVaapiEncoder* encoder,
246 gst_vaapi_encoder_get_encoded_buffer(
247 GstVaapiEncoder* encoder,
252 gst_vaapi_encoder_get_codec_data(
253 GstVaapiEncoder* encoder,
254 GstBuffer **codec_data
257 /* flush all frames */
259 gst_vaapi_encoder_flush(GstVaapiEncoder* encoder);
263 gst_vaapi_encoder_close(GstVaapiEncoder* encoder);
266 gst_vaapi_encoder_render_picture(
267 GstVaapiEncoder *encoder,
268 GstVaapiSurface *buffer_surface,
275 gst_vaapi_encoder_uninitialize(GstVaapiEncoder* encoder);
278 gst_vaapi_encoder_unref (GstVaapiEncoder *encoder)
280 g_object_unref (encoder);
283 /* other functions */
284 char *vaapi_encoder_dump_bytes(const guint8 *buf, guint32 num);
288 #endif /* GST_VAAPI_ENCODER_H */