FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vaapi_encode.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVCODEC_VAAPI_ENCODE_H
20 #define AVCODEC_VAAPI_ENCODE_H
21 
22 #include <stdint.h>
23 
24 #include <va/va.h>
25 
26 #include "libavutil/hwcontext.h"
28 
29 #include "avcodec.h"
30 
31 struct VAAPIEncodeType;
32 struct VAAPIEncodePicture;
33 
34 enum {
40 };
41 
42 enum {
47 };
48 
49 typedef struct VAAPIEncodeSlice {
50  int index;
51  void *priv_data;
54 
55 typedef struct VAAPIEncodePicture {
57 
58  int64_t display_order;
59  int64_t encode_order;
60  int64_t pts;
61 
62  int type;
66 
68  VASurfaceID input_surface;
69 
71  VASurfaceID recon_surface;
72 
74  VABufferID *param_buffers;
75 
77  VABufferID output_buffer;
78 
79  void *priv_data;
81 
82  int nb_refs;
84 
85  int nb_slices;
88 
89 typedef struct VAAPIEncodeContext {
90  const AVClass *class;
91 
92  // Codec-specific hooks.
93  const struct VAAPIEncodeType *codec;
94 
95  // Encoding profile (VAProfileXXX).
96  VAProfile va_profile;
97  // Encoding entrypoint (usually VAEntryointEncSlice).
98  VAEntrypoint va_entrypoint;
99  // Surface colour/sampling format (usually VA_RT_FORMAT_YUV420).
100  unsigned int va_rt_format;
101  // Rate control mode.
102  unsigned int va_rc_mode;
103  // Supported packed headers (initially the desired set, modified
104  // later to what is actually supported).
105  unsigned int va_packed_headers;
106 
107  // The required size of surfaces. This is probably the input
108  // size (AVCodecContext.width|height) aligned up to whatever
109  // block size is required by the codec.
112 
113  // Everything above this point must be set before calling
114  // ff_vaapi_encode_init().
115 
116  // Codec-specific state.
117  void *priv_data;
118 
119  // Configuration attributes to use when creating va_config.
122 
123  VAConfigID va_config;
124  VAContextID va_context;
125 
129 
130  // The hardware frame context containing the input frames.
133 
134  // The hardware frame context containing the reconstructed frames.
137 
138  // Pool of (reusable) bitstream output buffers.
140 
141  // Global parameters which will be applied at the start of the
142  // sequence (includes rate control parameters below).
143  VAEncMiscParameterBuffer *global_params[MAX_GLOBAL_PARAMS];
146 
147  // Rate control parameters.
148  struct {
149  VAEncMiscParameterBuffer misc;
150  VAEncMiscParameterRateControl rc;
151  } rc_params;
152  struct {
153  VAEncMiscParameterBuffer misc;
154  VAEncMiscParameterHRD hrd;
155  } hrd_params;
156  struct {
157  VAEncMiscParameterBuffer misc;
158  VAEncMiscParameterFrameRate fr;
159  } fr_params;
160 #if VA_CHECK_VERSION(0, 36, 0)
161  struct {
162  VAEncMiscParameterBuffer misc;
163  VAEncMiscParameterBufferQualityLevel quality;
164  } quality_params;
165 #endif
166 
167  // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
169 
170  // Per-sequence parameters found in the per-picture parameter
171  // structure (VAEncPictureParameterBuffer*).
173 
174  // Current encoding window, in display (input) order.
176 
177  // Next input order index (display order).
178  int64_t input_order;
179  // Number of frames that output is behind input.
180  int64_t output_delay;
181  // Number of frames decode output will need to be delayed.
182  int64_t decode_delay;
183  // Next output order index (encode order).
184  int64_t output_order;
185 
186  enum {
187  // All encode operations are done independently (synchronise
188  // immediately after every operation).
190  // Overlap as many operations as possible.
192  // Overlap operations only when satisfying parallel dependencies.
194  } issue_mode;
195 
196  // Timestamp handling.
197  int64_t first_pts;
198  int64_t dts_pts_diff;
200 
201  // Frame type decision.
202  int p_per_i;
203  int b_per_p;
208 
209  // Codec-local options are allocated to follow this structure in
210  // memory (in the AVCodec definition, set priv_data_size to
211  // sizeof(VAAPIEncodeContext) + sizeof(VAAPIEncodeFooOptions)).
215 
216 
217 typedef struct VAAPIEncodeType {
219 
220  // Perform any extra codec-specific configuration after the
221  // codec context is initialised (set up the private data and
222  // add any necessary global parameters).
224 
225  // The size of the parameter structures:
226  // sizeof(VAEnc{type}ParameterBuffer{codec}).
230 
231  // Fill the parameter structures.
234  VAAPIEncodePicture *pic);
236  VAAPIEncodePicture *pic,
237  VAAPIEncodeSlice *slice);
238 
239  // The type used by the packed header: this should look like
240  // VAEncPackedHeader{something}.
244 
245  // Write the packed header data to the provided buffer.
246  // The sequence header is also used to fill the codec extradata
247  // when the encoder is starting.
249  char *data, size_t *data_len);
251  VAAPIEncodePicture *pic,
252  char *data, size_t *data_len);
254  VAAPIEncodePicture *pic,
255  VAAPIEncodeSlice *slice,
256  char *data, size_t *data_len);
257 
258  // Fill an extra parameter structure, which will then be
259  // passed to vaRenderPicture(). Will be called repeatedly
260  // with increasing index argument until AVERROR_EOF is
261  // returned.
263  VAAPIEncodePicture *pic,
264  int index, int *type,
265  char *data, size_t *data_len);
266 
267  // Write an extra packed header. Will be called repeatedly
268  // with increasing index argument until AVERROR_EOF is
269  // returned.
271  VAAPIEncodePicture *pic,
272  int index, int *type,
273  char *data, size_t *data_len);
275 
276 
278  const AVFrame *input_image, int *got_packet);
279 
282 
283 #endif /* AVCODEC_VAAPI_ENCODE_H */
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:58
VASurfaceID input_surface
Definition: vaapi_encode.h:68
VAProfile va_profile
Definition: vaapi_encode.h:96
VAEncMiscParameterBuffer misc
Definition: vaapi_encode.h:149
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
VAEntrypoint va_entrypoint
Definition: vaapi_encode.h:98
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
char codec_options_data[0]
Definition: vaapi_encode.h:213
size_t priv_data_size
Definition: vaapi_encode.h:218
int(* write_slice_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
Definition: vaapi_encode.h:253
void * codec_sequence_params
Definition: vaapi_encode.h:168
AVBufferRef * input_frames_ref
Definition: vaapi_encode.h:131
static AVPacket pkt
VAEncMiscParameterHRD hrd
Definition: vaapi_encode.h:154
size_t picture_params_size
Definition: vaapi_encode.h:228
AVHWDeviceContext * device
Definition: vaapi_encode.h:127
struct VAAPIEncodeContext::@129 hrd_params
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
unsigned int va_packed_headers
Definition: vaapi_encode.h:105
VAEncMiscParameterFrameRate fr
Definition: vaapi_encode.h:158
int(* write_picture_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, char *data, size_t *data_len)
Definition: vaapi_encode.h:250
AVBufferRef * output_buffer_ref
Definition: vaapi_encode.h:76
VABufferID * param_buffers
Definition: vaapi_encode.h:74
VAContextID va_context
Definition: vaapi_encode.h:124
VASurfaceID recon_surface
Definition: vaapi_encode.h:71
int ff_vaapi_encode_init(AVCodecContext *avctx)
The buffer pool.
unsigned int va_rc_mode
Definition: vaapi_encode.h:102
VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES]
Definition: vaapi_encode.h:120
AVHWFramesContext * input_frames
Definition: vaapi_encode.h:132
VAEncMiscParameterBuffer * global_params[MAX_GLOBAL_PARAMS]
Definition: vaapi_encode.h:143
int(* configure)(AVCodecContext *avctx)
Definition: vaapi_encode.h:223
int ff_vaapi_encode_close(AVCodecContext *avctx)
int(* init_picture_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic)
Definition: vaapi_encode.h:233
void * codec_picture_params
Definition: vaapi_encode.h:80
int(* write_extra_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
Definition: vaapi_encode.h:270
VAConfigID va_config
Definition: vaapi_encode.h:123
AVHWFramesContext * recon_frames
Definition: vaapi_encode.h:136
VAAPIEncodeSlice * slices
Definition: vaapi_encode.h:86
unsigned int va_rt_format
Definition: vaapi_encode.h:100
struct VAAPIEncodePicture * next
Definition: vaapi_encode.h:56
AVFrame * input_image
Definition: vaapi_encode.h:67
void * codec_picture_params
Definition: vaapi_encode.h:172
int64_t ts_ring[MAX_REORDER_DELAY *3]
Definition: vaapi_encode.h:199
AVBufferPool * output_buffer_pool
Definition: vaapi_encode.h:139
int(* write_sequence_header)(AVCodecContext *avctx, char *data, size_t *data_len)
Definition: vaapi_encode.h:248
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
Definition: vaapi_encode.h:83
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
Definition: vaapi_encode.c:851
const struct VAAPIEncodeType * codec
Definition: vaapi_encode.h:93
Libavcodec external API header.
VAAPIEncodePicture * pic_start
Definition: vaapi_encode.h:175
main external API structure.
Definition: avcodec.h:1761
int(* write_extra_buffer)(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
Definition: vaapi_encode.h:262
size_t slice_params_size
Definition: vaapi_encode.h:229
GLint GLenum type
Definition: opengl_enc.c:105
Describe the class of an AVClass context structure.
Definition: log.h:67
int index
Definition: gxfenc.c:89
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:121
AVBufferRef * recon_frames_ref
Definition: vaapi_encode.h:135
AVBufferRef * device_ref
Definition: vaapi_encode.h:126
VAAPIEncodePicture * pic_end
Definition: vaapi_encode.h:175
size_t global_params_size[MAX_GLOBAL_PARAMS]
Definition: vaapi_encode.h:144
VAEncMiscParameterRateControl rc
Definition: vaapi_encode.h:150
A reference to a data buffer.
Definition: buffer.h:81
size_t sequence_params_size
Definition: vaapi_encode.h:227
int
void * codec_slice_params
Definition: vaapi_encode.h:52
AVFrame * recon_image
Definition: vaapi_encode.h:70
int(* init_slice_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
Definition: vaapi_encode.h:235
VAAPI connection details.
enum VAAPIEncodeContext::@131 issue_mode
int(* init_sequence_params)(AVCodecContext *avctx)
Definition: vaapi_encode.h:232
struct VAAPIEncodeContext::@128 rc_params
VABufferID output_buffer
Definition: vaapi_encode.h:77
This structure stores compressed data.
Definition: avcodec.h:1656
struct VAAPIEncodeContext::@130 fr_params
AVVAAPIDeviceContext * hwctx
Definition: vaapi_encode.h:128