2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVCODEC_VAAPI_ENCODE_H
20 #define AVCODEC_VAAPI_ENCODE_H
26 #include "libavutil/hwcontext.h"
27 #include "libavutil/hwcontext_vaapi.h"
31 struct VAAPIEncodeType;
32 struct VAAPIEncodePicture;
35 MAX_CONFIG_ATTRIBUTES = 4,
36 MAX_GLOBAL_PARAMS = 4,
37 MAX_PICTURE_REFERENCES = 2,
38 MAX_PICTURE_SLICES = 1,
39 MAX_PARAM_BUFFERS = 16,
40 MAX_REORDER_DELAY = 16,
41 MAX_PARAM_BUFFER_SIZE = 1024,
42 MAX_OUTPUT_BUFFER_SIZE = 1024 * 1024,
53 // All encode operations are done independently.
54 ISSUE_MODE_SERIALISE_EVERYTHING = 0,
55 // Overlap as many operations as possible.
56 ISSUE_MODE_MAXIMISE_THROUGHPUT,
57 // Overlap operations only when satisfying parallel dependencies.
58 ISSUE_MODE_MINIMISE_LATENCY,
61 typedef struct VAAPIEncodeSlice {
63 void *codec_slice_params;
66 typedef struct VAAPIEncodePicture {
67 struct VAAPIEncodePicture *next;
69 int64_t display_order;
79 VASurfaceID input_surface;
82 VASurfaceID recon_surface;
85 VABufferID param_buffers[MAX_PARAM_BUFFERS];
87 VABufferID output_buffer;
90 void *codec_picture_params;
93 struct VAAPIEncodePicture *refs[MAX_PICTURE_REFERENCES];
96 VAAPIEncodeSlice *slices[MAX_PICTURE_SLICES];
99 typedef struct VAAPIEncodeContext {
100 const AVClass *class;
102 // Codec-specific hooks.
103 const struct VAAPIEncodeType *codec;
105 // Codec-specific state.
108 VAProfile va_profile;
109 VAEntrypoint va_entrypoint;
110 VAConfigID va_config;
111 VAContextID va_context;
115 AVBufferRef *device_ref;
116 AVHWDeviceContext *device;
117 AVVAAPIDeviceContext *hwctx;
119 AVBufferRef *input_frames_ref;
120 AVHWFramesContext *input_frames;
122 // Input size, set from input frames.
125 // Aligned size, set by codec init, becomes hwframe size.
130 AVBufferRef *recon_frames_ref;
131 AVHWFramesContext *recon_frames;
133 VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES];
134 int nb_config_attributes;
136 VAEncMiscParameterBuffer *global_params[MAX_GLOBAL_PARAMS];
137 size_t global_params_size[MAX_GLOBAL_PARAMS];
138 int nb_global_params;
140 // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
141 void *codec_sequence_params;
143 // Per-sequence parameters found in the per-picture parameter
144 // structure (VAEncPictureParameterBuffer*).
145 void *codec_picture_params;
147 // Current encoding window, in display (input) order.
148 VAAPIEncodePicture *pic_start, *pic_end;
150 // Next input order index (display 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;
161 // Timestamp handling.
163 int64_t dts_pts_diff;
164 int64_t ts_ring[MAX_REORDER_DELAY * 3];
166 // Frame type decision.
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)).
179 char codec_options_data[0];
180 } VAAPIEncodeContext;
183 typedef struct VAAPIEncodeType {
184 size_t priv_data_size;
186 int (*init)(AVCodecContext *avctx);
187 int (*close)(AVCodecContext *avctx);
189 size_t sequence_params_size;
190 size_t picture_params_size;
191 size_t slice_params_size;
193 int (*init_sequence_params)(AVCodecContext *avctx);
194 int (*init_picture_params)(AVCodecContext *avctx,
195 VAAPIEncodePicture *pic);
196 int (*init_slice_params)(AVCodecContext *avctx,
197 VAAPIEncodePicture *pic,
198 VAAPIEncodeSlice *slice);
200 int sequence_header_type;
201 int picture_header_type;
202 int slice_header_type;
204 int (*write_sequence_header)(AVCodecContext *avctx,
205 char *data, size_t *data_len);
206 int (*write_picture_header)(AVCodecContext *avctx,
207 VAAPIEncodePicture *pic,
208 char *data, size_t *data_len);
209 int (*write_slice_header)(AVCodecContext *avctx,
210 VAAPIEncodePicture *pic,
211 VAAPIEncodeSlice *slice,
212 char *data, size_t *data_len);
214 int (*write_extra_buffer)(AVCodecContext *avctx,
215 VAAPIEncodePicture *pic,
216 int index, int *type,
217 char *data, size_t *data_len);
221 int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
222 const AVFrame *input_image, int *got_packet);
224 int ff_vaapi_encode_init(AVCodecContext *avctx,
225 const VAAPIEncodeType *type);
226 int ff_vaapi_encode_close(AVCodecContext *avctx);
228 #endif /* AVCODEC_VAAPI_ENCODE_H */