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 {
42 };
43 
44 enum {
49 };
50 
51 typedef struct VAAPIEncodeSlice {
52  int index;
53  void *priv_data;
56 
57 typedef struct VAAPIEncodePicture {
59 
60  int64_t display_order;
61  int64_t encode_order;
62  int64_t pts;
63 
64  int type;
68 
70  VASurfaceID input_surface;
71 
73  VASurfaceID recon_surface;
74 
77 
79  VABufferID output_buffer;
80 
81  void *priv_data;
83 
84  int nb_refs;
86 
87  int nb_slices;
90 
91 typedef struct VAAPIEncodeContext {
92  const AVClass *class;
93 
94  // Codec-specific hooks.
95  const struct VAAPIEncodeType *codec;
96 
97  // Encoding profile (VAProfileXXX).
98  VAProfile va_profile;
99  // Encoding entrypoint (usually VAEntryointEncSlice).
100  VAEntrypoint va_entrypoint;
101  // Surface colour/sampling format (usually VA_RT_FORMAT_YUV420).
102  unsigned int va_rt_format;
103  // Rate control mode.
104  unsigned int va_rc_mode;
105  // Supported packed headers (initially the desired set, modified
106  // later to what is actually supported).
107  unsigned int va_packed_headers;
108 
109  // The required size of surfaces. This is probably the input
110  // size (AVCodecContext.width|height) aligned up to whatever
111  // block size is required by the codec.
114 
115  // Everything above this point must be set before calling
116  // ff_vaapi_encode_init().
117 
118  // Codec-specific state.
119  void *priv_data;
120 
121  // Configuration attributes to use when creating va_config.
124 
125  VAConfigID va_config;
126  VAContextID va_context;
127 
131 
132  // The hardware frame context containing the input frames.
135 
136  // The hardware frame context containing the reconstructed frames.
139 
140  // Pool of (reusable) bitstream output buffers.
142 
143  // Global parameters which will be applied at the start of the
144  // sequence (includes rate control parameters below).
145  VAEncMiscParameterBuffer *global_params[MAX_GLOBAL_PARAMS];
148 
149  // Rate control parameters.
150  struct {
151  VAEncMiscParameterBuffer misc;
152  VAEncMiscParameterRateControl rc;
153  } rc_params;
154  struct {
155  VAEncMiscParameterBuffer misc;
156  VAEncMiscParameterHRD hrd;
157  } hrd_params;
158  struct {
159  VAEncMiscParameterBuffer misc;
160  VAEncMiscParameterFrameRate fr;
161  } fr_params;
162 
163  // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
165 
166  // Per-sequence parameters found in the per-picture parameter
167  // structure (VAEncPictureParameterBuffer*).
169 
170  // Current encoding window, in display (input) order.
172 
173  // Next input order index (display order).
174  int64_t input_order;
175  // Number of frames that output is behind input.
176  int64_t output_delay;
177  // Number of frames decode output will need to be delayed.
178  int64_t decode_delay;
179  // Next output order index (encode order).
180  int64_t output_order;
181 
182  enum {
183  // All encode operations are done independently (synchronise
184  // immediately after every operation).
186  // Overlap as many operations as possible.
188  // Overlap operations only when satisfying parallel dependencies.
190  } issue_mode;
191 
192  // Timestamp handling.
193  int64_t first_pts;
194  int64_t dts_pts_diff;
196 
197  // Frame type decision.
198  int p_per_i;
199  int b_per_p;
204 
205  // Codec-local options are allocated to follow this structure in
206  // memory (in the AVCodec definition, set priv_data_size to
207  // sizeof(VAAPIEncodeContext) + sizeof(VAAPIEncodeFooOptions)).
211 
212 
213 typedef struct VAAPIEncodeType {
215 
216  // Perform any extra codec-specific configuration after the
217  // codec context is initialised (set up the private data and
218  // add any necessary global parameters).
220 
221  // The size of the parameter structures:
222  // sizeof(VAEnc{type}ParameterBuffer{codec}).
226 
227  // Fill the parameter structures.
230  VAAPIEncodePicture *pic);
232  VAAPIEncodePicture *pic,
233  VAAPIEncodeSlice *slice);
234 
235  // The type used by the packed header: this should look like
236  // VAEncPackedHeader{something}.
240 
241  // Write the packed header data to the provided buffer.
242  // The sequence header is also used to fill the codec extradata
243  // when the encoder is starting.
245  char *data, size_t *data_len);
247  VAAPIEncodePicture *pic,
248  char *data, size_t *data_len);
250  VAAPIEncodePicture *pic,
251  VAAPIEncodeSlice *slice,
252  char *data, size_t *data_len);
253 
254  // Fill an extra parameter structure, which will then be
255  // passed to vaRenderPicture(). Will be called repeatedly
256  // with increasing index argument until AVERROR_EOF is
257  // returned.
259  VAAPIEncodePicture *pic,
260  int index, int *type,
261  char *data, size_t *data_len);
262 
263  // Write an extra packed header. Will be called repeatedly
264  // with increasing index argument until AVERROR_EOF is
265  // returned.
267  VAAPIEncodePicture *pic,
268  int index, int *type,
269  char *data, size_t *data_len);
271 
272 
274  const AVFrame *input_image, int *got_packet);
275 
278 
279 #endif /* AVCODEC_VAAPI_ENCODE_H */
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:54
VASurfaceID input_surface
Definition: vaapi_encode.h:70
VAProfile va_profile
Definition: vaapi_encode.h:98
VAEncMiscParameterBuffer misc
Definition: vaapi_encode.h:151
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
VAAPIEncodeSlice * slices[MAX_PICTURE_SLICES]
Definition: vaapi_encode.h:88
VAEntrypoint va_entrypoint
Definition: vaapi_encode.h:100
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
char codec_options_data[0]
Definition: vaapi_encode.h:209
size_t priv_data_size
Definition: vaapi_encode.h:214
int(* write_slice_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
Definition: vaapi_encode.h:249
void * codec_sequence_params
Definition: vaapi_encode.h:164
AVBufferRef * input_frames_ref
Definition: vaapi_encode.h:133
static AVPacket pkt
VAEncMiscParameterHRD hrd
Definition: vaapi_encode.h:156
size_t picture_params_size
Definition: vaapi_encode.h:224
AVHWDeviceContext * device
Definition: vaapi_encode.h:129
struct VAAPIEncodeContext::@129 hrd_params
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
unsigned int va_packed_headers
Definition: vaapi_encode.h:107
VAEncMiscParameterFrameRate fr
Definition: vaapi_encode.h:160
int(* write_picture_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, char *data, size_t *data_len)
Definition: vaapi_encode.h:246
AVBufferRef * output_buffer_ref
Definition: vaapi_encode.h:78
VAContextID va_context
Definition: vaapi_encode.h:126
VASurfaceID recon_surface
Definition: vaapi_encode.h:73
int ff_vaapi_encode_init(AVCodecContext *avctx)
The buffer pool.
unsigned int va_rc_mode
Definition: vaapi_encode.h:104
VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES]
Definition: vaapi_encode.h:122
AVHWFramesContext * input_frames
Definition: vaapi_encode.h:134
VAEncMiscParameterBuffer * global_params[MAX_GLOBAL_PARAMS]
Definition: vaapi_encode.h:145
int(* configure)(AVCodecContext *avctx)
Definition: vaapi_encode.h:219
int ff_vaapi_encode_close(AVCodecContext *avctx)
int(* init_picture_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic)
Definition: vaapi_encode.h:229
void * codec_picture_params
Definition: vaapi_encode.h:82
int(* write_extra_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
Definition: vaapi_encode.h:266
VAConfigID va_config
Definition: vaapi_encode.h:125
AVHWFramesContext * recon_frames
Definition: vaapi_encode.h:138
unsigned int va_rt_format
Definition: vaapi_encode.h:102
struct VAAPIEncodePicture * next
Definition: vaapi_encode.h:58
AVFrame * input_image
Definition: vaapi_encode.h:69
void * codec_picture_params
Definition: vaapi_encode.h:168
int64_t ts_ring[MAX_REORDER_DELAY *3]
Definition: vaapi_encode.h:195
AVBufferPool * output_buffer_pool
Definition: vaapi_encode.h:141
int(* write_sequence_header)(AVCodecContext *avctx, char *data, size_t *data_len)
Definition: vaapi_encode.h:244
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
Definition: vaapi_encode.h:85
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
Definition: vaapi_encode.c:831
const struct VAAPIEncodeType * codec
Definition: vaapi_encode.h:95
Libavcodec external API header.
VAAPIEncodePicture * pic_start
Definition: vaapi_encode.h:171
main external API structure.
Definition: avcodec.h:1732
int(* write_extra_buffer)(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
Definition: vaapi_encode.h:258
VABufferID param_buffers[MAX_PARAM_BUFFERS]
Definition: vaapi_encode.h:76
size_t slice_params_size
Definition: vaapi_encode.h:225
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:117
AVBufferRef * recon_frames_ref
Definition: vaapi_encode.h:137
AVBufferRef * device_ref
Definition: vaapi_encode.h:128
VAAPIEncodePicture * pic_end
Definition: vaapi_encode.h:171
size_t global_params_size[MAX_GLOBAL_PARAMS]
Definition: vaapi_encode.h:146
VAEncMiscParameterRateControl rc
Definition: vaapi_encode.h:152
A reference to a data buffer.
Definition: buffer.h:81
size_t sequence_params_size
Definition: vaapi_encode.h:223
int
void * codec_slice_params
Definition: vaapi_encode.h:54
AVFrame * recon_image
Definition: vaapi_encode.h:72
int(* init_slice_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
Definition: vaapi_encode.h:231
VAAPI connection details.
enum VAAPIEncodeContext::@131 issue_mode
int(* init_sequence_params)(AVCodecContext *avctx)
Definition: vaapi_encode.h:228
struct VAAPIEncodeContext::@128 rc_params
VABufferID output_buffer
Definition: vaapi_encode.h:79
This structure stores compressed data.
Definition: avcodec.h:1634
struct VAAPIEncodeContext::@130 fr_params
AVVAAPIDeviceContext * hwctx
Definition: vaapi_encode.h:130