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  MAX_OUTPUT_BUFFER_SIZE = 1024 * 1024,
43 };
44 
45 enum {
50 };
51 
52 enum {
53  // All encode operations are done independently.
55  // Overlap as many operations as possible.
57  // Overlap operations only when satisfying parallel dependencies.
59 };
60 
61 typedef struct VAAPIEncodeSlice {
62  void *priv_data;
65 
66 typedef struct VAAPIEncodePicture {
68 
69  int64_t display_order;
70  int64_t encode_order;
71  int64_t pts;
72 
73  int type;
77 
79  VASurfaceID input_surface;
80 
82  VASurfaceID recon_surface;
83 
86 
87  VABufferID output_buffer;
88 
89  void *priv_data;
91 
92  int nb_refs;
94 
95  int nb_slices;
98 
99 typedef struct VAAPIEncodeContext {
100  const AVClass *class;
101 
102  // Codec-specific hooks.
103  const struct VAAPIEncodeType *codec;
104 
105  // Codec-specific state.
106  void *priv_data;
107 
108  VAProfile va_profile;
109  VAEntrypoint va_entrypoint;
110  VAConfigID va_config;
111  VAContextID va_context;
112 
114 
118 
121 
122  // Input size, set from input frames.
125  // Aligned size, set by codec init, becomes hwframe size.
128 
132 
135 
136  VAEncMiscParameterBuffer *global_params[MAX_GLOBAL_PARAMS];
139 
140  // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
142 
143  // Per-sequence parameters found in the per-picture parameter
144  // structure (VAEncPictureParameterBuffer*).
146 
147  // Current encoding window, in display (input) order.
149 
150  // Next input order index (display order).
151  int64_t input_order;
152  // Number of frames that output is behind input.
153  int64_t output_delay;
154  // Number of frames decode output will need to be delayed.
155  int64_t decode_delay;
156  // Next output order index (encode order).
157  int64_t output_order;
158 
160 
161  // Timestamp handling.
162  int64_t first_pts;
163  int64_t dts_pts_diff;
165 
166  // Frame type decision.
168  int p_per_i;
169  int b_per_p;
174 
175  // Codec-local options are allocated to follow this structure in
176  // memory (in the AVCodec definition, set priv_data_size to
177  // sizeof(VAAPIEncodeContext) + sizeof(VAAPIEncodeFooOptions)).
181 
182 
183 typedef struct VAAPIEncodeType {
185 
186  int (*init)(AVCodecContext *avctx);
187  int (*close)(AVCodecContext *avctx);
188 
192 
195  VAAPIEncodePicture *pic);
197  VAAPIEncodePicture *pic,
198  VAAPIEncodeSlice *slice);
199 
203 
205  char *data, size_t *data_len);
207  VAAPIEncodePicture *pic,
208  char *data, size_t *data_len);
210  VAAPIEncodePicture *pic,
211  VAAPIEncodeSlice *slice,
212  char *data, size_t *data_len);
213 
215  VAAPIEncodePicture *pic,
216  int index, int *type,
217  char *data, size_t *data_len);
219 
220 
222  const AVFrame *input_image, int *got_packet);
223 
225  const VAAPIEncodeType *type);
227 
228 #endif /* AVCODEC_VAAPI_ENCODE_H */
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:53
VASurfaceID input_surface
Definition: vaapi_encode.h:79
VAProfile va_profile
Definition: vaapi_encode.h:108
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
VAAPIEncodeSlice * slices[MAX_PICTURE_SLICES]
Definition: vaapi_encode.h:96
VAEntrypoint va_entrypoint
Definition: vaapi_encode.h:109
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
char codec_options_data[0]
Definition: vaapi_encode.h:179
size_t priv_data_size
Definition: vaapi_encode.h:184
int(* write_slice_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
Definition: vaapi_encode.h:209
void * codec_sequence_params
Definition: vaapi_encode.h:141
AVBufferRef * input_frames_ref
Definition: vaapi_encode.h:119
static AVPacket pkt
size_t picture_params_size
Definition: vaapi_encode.h:190
AVHWDeviceContext * device
Definition: vaapi_encode.h:116
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
int(* write_picture_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, char *data, size_t *data_len)
Definition: vaapi_encode.h:206
VAContextID va_context
Definition: vaapi_encode.h:111
VASurfaceID recon_surface
Definition: vaapi_encode.h:82
VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES]
Definition: vaapi_encode.h:133
AVHWFramesContext * input_frames
Definition: vaapi_encode.h:120
VAEncMiscParameterBuffer * global_params[MAX_GLOBAL_PARAMS]
Definition: vaapi_encode.h:136
int ff_vaapi_encode_close(AVCodecContext *avctx)
int(* init_picture_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic)
Definition: vaapi_encode.h:194
void * codec_picture_params
Definition: vaapi_encode.h:90
VAConfigID va_config
Definition: vaapi_encode.h:110
AVHWFramesContext * recon_frames
Definition: vaapi_encode.h:131
int(* close)(AVCodecContext *avctx)
Definition: vaapi_encode.h:187
struct VAAPIEncodePicture * next
Definition: vaapi_encode.h:67
AVFrame * input_image
Definition: vaapi_encode.h:78
void * codec_picture_params
Definition: vaapi_encode.h:145
int64_t ts_ring[MAX_REORDER_DELAY *3]
Definition: vaapi_encode.h:164
int ff_vaapi_encode_init(AVCodecContext *avctx, const VAAPIEncodeType *type)
int(* write_sequence_header)(AVCodecContext *avctx, char *data, size_t *data_len)
Definition: vaapi_encode.h:204
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
Definition: vaapi_encode.h:93
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
Definition: vaapi_encode.c:788
const struct VAAPIEncodeType * codec
Definition: vaapi_encode.h:103
Libavcodec external API header.
VAAPIEncodePicture * pic_start
Definition: vaapi_encode.h:148
main external API structure.
Definition: avcodec.h:1649
int(* write_extra_buffer)(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
Definition: vaapi_encode.h:214
VABufferID param_buffers[MAX_PARAM_BUFFERS]
Definition: vaapi_encode.h:85
size_t slice_params_size
Definition: vaapi_encode.h:191
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:116
AVBufferRef * recon_frames_ref
Definition: vaapi_encode.h:130
AVBufferRef * device_ref
Definition: vaapi_encode.h:115
VAAPIEncodePicture * pic_end
Definition: vaapi_encode.h:148
size_t global_params_size[MAX_GLOBAL_PARAMS]
Definition: vaapi_encode.h:137
A reference to a data buffer.
Definition: buffer.h:81
size_t sequence_params_size
Definition: vaapi_encode.h:189
void * codec_slice_params
Definition: vaapi_encode.h:63
AVFrame * recon_image
Definition: vaapi_encode.h:81
int(* init_slice_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
Definition: vaapi_encode.h:196
VAAPI connection details.
int(* init_sequence_params)(AVCodecContext *avctx)
Definition: vaapi_encode.h:193
VABufferID output_buffer
Definition: vaapi_encode.h:87
This structure stores compressed data.
Definition: avcodec.h:1557
int(* init)(AVCodecContext *avctx)
Definition: vaapi_encode.h:186
AVVAAPIDeviceContext * hwctx
Definition: vaapi_encode.h:117