Libav
vaapi_encode.h
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; 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 enum {
52  // All encode operations are done independently.
54  // Overlap as many operations as possible.
56  // Overlap operations only when satisfying parallel dependencies.
58 };
59 
60 typedef struct VAAPIEncodeSlice {
61  void *priv_data;
64 
65 typedef struct VAAPIEncodePicture {
67 
68  int64_t display_order;
69  int64_t encode_order;
70  int64_t pts;
71 
72  int type;
76 
78  VASurfaceID input_surface;
79 
81  VASurfaceID recon_surface;
82 
85 
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 
134 
135  VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES];
137 
138  VAEncMiscParameterBuffer *global_params[MAX_GLOBAL_PARAMS];
139  size_t global_params_size[MAX_GLOBAL_PARAMS];
141 
142  // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
144 
145  // Per-sequence parameters found in the per-picture parameter
146  // structure (VAEncPictureParameterBuffer*).
148 
149  // Current encoding window, in display (input) order.
151 
152  // Next input order index (display order).
153  int64_t input_order;
154  // Number of frames that output is behind input.
155  int64_t output_delay;
156  // Number of frames decode output will need to be delayed.
157  int64_t decode_delay;
158  // Next output order index (encode order).
159  int64_t output_order;
160 
162 
163  // Timestamp handling.
164  int64_t first_pts;
165  int64_t dts_pts_diff;
166  int64_t ts_ring[MAX_REORDER_DELAY * 3];
167 
168  // Frame type decision.
170  int p_per_i;
171  int b_per_p;
176 
177  // Codec-local options are allocated to follow this structure in
178  // memory (in the AVCodec definition, set priv_data_size to
179  // sizeof(VAAPIEncodeContext) + sizeof(VAAPIEncodeFooOptions)).
181  char codec_options_data[0];
183 
184 
185 typedef struct VAAPIEncodeType {
187 
188  int (*init)(AVCodecContext *avctx);
189  int (*close)(AVCodecContext *avctx);
190 
194 
195  int (*init_sequence_params)(AVCodecContext *avctx);
196  int (*init_picture_params)(AVCodecContext *avctx,
197  VAAPIEncodePicture *pic);
198  int (*init_slice_params)(AVCodecContext *avctx,
199  VAAPIEncodePicture *pic,
200  VAAPIEncodeSlice *slice);
201 
205 
206  int (*write_sequence_header)(AVCodecContext *avctx,
207  char *data, size_t *data_len);
208  int (*write_picture_header)(AVCodecContext *avctx,
209  VAAPIEncodePicture *pic,
210  char *data, size_t *data_len);
211  int (*write_slice_header)(AVCodecContext *avctx,
212  VAAPIEncodePicture *pic,
213  VAAPIEncodeSlice *slice,
214  char *data, size_t *data_len);
215 
216  int (*write_extra_buffer)(AVCodecContext *avctx,
217  VAAPIEncodePicture *pic,
218  int index, int *type,
219  char *data, size_t *data_len);
220  int (*write_extra_header)(AVCodecContext *avctx,
221  VAAPIEncodePicture *pic,
222  int index, int *type,
223  char *data, size_t *data_len);
225 
226 
227 int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
228  const AVFrame *input_image, int *got_packet);
229 
231  const VAAPIEncodeType *type);
233 
234 #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:78
VAProfile va_profile
Definition: vaapi_encode.h:108
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
VAAPIEncodeSlice * slices[MAX_PICTURE_SLICES]
Definition: vaapi_encode.h:96
VAEntrypoint va_entrypoint
Definition: vaapi_encode.h:109
size_t priv_data_size
Definition: vaapi_encode.h:186
void * codec_sequence_params
Definition: vaapi_encode.h:143
AVBufferRef * input_frames_ref
Definition: vaapi_encode.h:119
size_t picture_params_size
Definition: vaapi_encode.h:192
AVHWDeviceContext * device
Definition: vaapi_encode.h:116
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
AVBufferRef * output_buffer_ref
Definition: vaapi_encode.h:86
const char data[16]
Definition: mxf.c:70
VAContextID va_context
Definition: vaapi_encode.h:111
VASurfaceID recon_surface
Definition: vaapi_encode.h:81
The buffer pool.
AVHWFramesContext * input_frames
Definition: vaapi_encode.h:120
int ff_vaapi_encode_close(AVCodecContext *avctx)
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
struct VAAPIEncodePicture * next
Definition: vaapi_encode.h:66
AVFrame * input_image
Definition: vaapi_encode.h:77
void * codec_picture_params
Definition: vaapi_encode.h:147
AVBufferPool * output_buffer_pool
Definition: vaapi_encode.h:133
int ff_vaapi_encode_init(AVCodecContext *avctx, const VAAPIEncodeType *type)
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:822
const struct VAAPIEncodeType * codec
Definition: vaapi_encode.h:103
Libavcodec external API header.
VAAPIEncodePicture * pic_start
Definition: vaapi_encode.h:150
main external API structure.
Definition: avcodec.h:1409
VABufferID param_buffers[MAX_PARAM_BUFFERS]
Definition: vaapi_encode.h:84
size_t slice_params_size
Definition: vaapi_encode.h:193
Describe the class of an AVClass context structure.
Definition: log.h:34
int index
Definition: gxfenc.c:72
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:117
AVBufferRef * recon_frames_ref
Definition: vaapi_encode.h:130
AVBufferRef * device_ref
Definition: vaapi_encode.h:115
A reference to a data buffer.
Definition: buffer.h:81
size_t sequence_params_size
Definition: vaapi_encode.h:191
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:582
void * codec_slice_params
Definition: vaapi_encode.h:62
AVFrame * recon_image
Definition: vaapi_encode.h:80
VAAPI connection details.
VABufferID output_buffer
Definition: vaapi_encode.h:87
This structure stores compressed data.
Definition: avcodec.h:1323
AVVAAPIDeviceContext * hwctx
Definition: vaapi_encode.h:117