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"
30 #include "gst/vaapi/gstvaapidisplay.h"
31 #include "gst/vaapi/gstvaapicontext.h"
35 #define ENCODER_NO_ERROR 0
36 #define ENCODER_BUFFER_WAITING 1
37 #define ENCODER_BUFFER_EMPTY 2
40 #define ENCODER_MEM_ERR -1
41 #define ENCODER_DISPLAY_ERR -2
42 #define ENCODER_CONFIG_ERR -3
43 #define ENCODER_CONTEXT_ERR -3
44 #define ENCODER_STATE_ERR -4
45 #define ENCODER_ENC_RES_ERR -5
46 #define ENCODER_PICTURE_ERR -6
47 #define ENCODER_SURFACE_ERR -7
48 #define ENCODER_QUERY_STATUS_ERR -8
49 #define ENCODER_DATA_NOT_READY -9
50 #define ENCODER_DATA_ERR -10
51 #define ENCODER_PROFILE_ERR -11
52 #define ENCODER_PARAMETER_ERR -12
53 #define ENCODER_FUNC_PTR_ERR -13
56 #define ENCODER_LOG_ERROR(str_fmt,...) fprintf(stdout, str_fmt "\n", ## __VA_ARGS__)
57 #define ENCODER_LOG_WARNING(str_fmt,...) fprintf(stdout, str_fmt "\n", ## __VA_ARGS__)
58 #define ENCODER_LOG_DEBUG(str_fmt,...) fprintf(stdout, str_fmt "\n", ## __VA_ARGS__)
59 #define ENCODER_LOG_INFO(str_fmt,...) fprintf(stdout, str_fmt "\n", ## __VA_ARGS__)
61 #define ENCODER_LOG_ERROR(...) GST_ERROR( __VA_ARGS__)
62 #define ENCODER_LOG_WARNING(...) GST_WARNING( __VA_ARGS__)
63 #define ENCODER_LOG_DEBUG(...) GST_DEBUG( __VA_ARGS__)
64 #define ENCODER_LOG_INFO(...) GST_INFO( __VA_ARGS__)
67 #define VAAPI_UNUSED_ARG(arg) (void)(arg)
71 #define ENCODER_ASSERT(exp) assert(exp)
73 #define ENCODER_ASSERT(exp) g_assert(exp)
76 #define ENCODER_CHECK_STATUS(exp, err_num, err_reason, ...) \
78 ENCODER_ASSERT(FALSE); \
80 ENCODER_LOG_ERROR(err_reason, ## __VA_ARGS__); \
84 /* must have <gboolean is_locked = FALSE;> declared first*/
85 #define ENCODER_ACQUIRE_DISPLAY_LOCK(display) \
87 GST_VAAPI_DISPLAY_LOCK(display); \
91 #define ENCODER_RELEASE_DISPLAY_LOCK(display) \
93 GST_VAAPI_DISPLAY_UNLOCK(display); \
103 } VAAPI_Encode_State;
105 typedef int EncoderStatus;
106 typedef struct _GstVaapiEncoder GstVaapiEncoder;
107 typedef struct _GstVaapiEncoderPrivate GstVaapiEncoderPrivate;
108 typedef struct _GstVaapiEncoderClass GstVaapiEncoderClass;
110 #define GST_TYPE_VAAPI_ENCODER (gst_vaapi_encoder_get_type())
111 #define GST_IS_VAAPI_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VAAPI_ENCODER))
112 #define GST_IS_VAAPI_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VAAPI_ENCODER))
113 #define GST_VAAPI_ENCODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VAAPI_ENCODER, GstVaapiEncoderClass))
114 #define GST_VAAPI_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VAAPI_ENCODER, GstVaapiEncoder))
115 #define GST_VAAPI_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VAAPI_ENCODER, GstVaapiEncoderClass))
116 #define GST_VAAPI_ENCODER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),GST_TYPE_VAAPI_ENCODER, GstVaapiEncoderPrivate))
118 #define ENCODER_DISPLAY(encoder) (GST_VAAPI_ENCODER_GET_PRIVATE(encoder)->display)
119 #define ENCODER_CONTEXT(encoder) (GST_VAAPI_ENCODER_GET_PRIVATE(encoder)->context)
120 #define ENCODER_WIDTH(encoder) (((GstVaapiEncoder*)(encoder))->width)
121 #define ENCODER_HEIGHT(encoder) (((GstVaapiEncoder*)(encoder))->height)
122 #define ENCODER_FPS(encoder) (((GstVaapiEncoder*)(encoder))->frame_rate)
124 struct _GstVaapiEncoder {
132 struct _GstVaapiEncoderClass {
133 GObjectClass parent_class;
135 EncoderStatus (*initialize) (GstVaapiEncoder* encoder, GstVaapiDisplay *display); /* can be NULL */
136 EncoderStatus (*uninitialize) (GstVaapiEncoder* encoder, GstVaapiDisplay *display); /* can be NULL */
139 EncoderStatus (*open) (GstVaapiEncoder* encoder, GstVaapiDisplay *display,
140 void* private_data, GstVaapiContext **context);
142 EncoderStatus (*close) (GstVaapiEncoder* encoder, GstVaapiDisplay *display, GstVaapiContext *context);
143 /* coded_pics [out] */
144 EncoderStatus (*encode) (GstVaapiEncoder* encoder, GstVaapiDisplay *display,
145 GstVaapiContext *context, GstBuffer *raw_pic, GList **coded_pics);
146 /* coded_pics [out] */
147 EncoderStatus (*flush) (GstVaapiEncoder* encoder, GstVaapiDisplay *display,
148 GstVaapiContext *context, GList **coded_pics);
150 EncoderStatus (*get_codec_data)(GstVaapiEncoder* encoder, GstBuffer **codec_data); /* can be NULL */
153 struct _GstVaapiEncoderPrivate {
154 GstVaapiDisplay *display;
155 GstVaapiContext *context;
156 VAAPI_Encode_State state;
159 GType gst_vaapi_encoder_get_type(void);
161 /* set/get display */
162 gboolean gst_vaapi_encoder_set_display(GstVaapiEncoder* encoder, GstVaapiDisplay *display);
163 GstVaapiDisplay *gst_vaapi_encoder_get_display(GstVaapiEncoder* encoder);
166 GstVaapiContext *gst_vaapi_encoder_get_context(GstVaapiEncoder* encoder);
168 /* get encoding state */
169 VAAPI_Encode_State gst_vaapi_encoder_get_state(GstVaapiEncoder* encoder);
171 /* check/open display */
172 EncoderStatus gst_vaapi_encoder_initialize(GstVaapiEncoder* encoder);
174 /* check/open context */
175 EncoderStatus gst_vaapi_encoder_open(GstVaapiEncoder* encoder, void* private_data);
177 /* encode one frame */
178 EncoderStatus gst_vaapi_encoder_encode(GstVaapiEncoder* encoder, GstBuffer *raw_pic, GList **coded_pics);
180 EncoderStatus gst_vaapi_encoder_get_codec_data(GstVaapiEncoder* encoder, GstBuffer **codec_data);
182 /* flush all frames */
183 EncoderStatus gst_vaapi_encoder_flush(GstVaapiEncoder* encoder, GList **coded_pics);
186 EncoderStatus gst_vaapi_encoder_close(GstVaapiEncoder* encoder);
189 EncoderStatus gst_vaapi_encoder_uninitialize(GstVaapiEncoder* encoder);
191 static inline void gst_vaapi_encoder_unref (GstVaapiEncoder *encoder)
193 g_object_unref (encoder);
196 /* other functions */
197 char *vaapi_encoder_dump_bytes(const guint8 *buf, guint32 num);