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_PICTURE_REFERENCES = 2,
36 MAX_PICTURE_SLICES = 1,
37 MAX_PARAM_BUFFERS = 16,
38 MAX_REORDER_DELAY = 16,
39 MAX_PARAM_BUFFER_SIZE = 1024,
40 MAX_OUTPUT_BUFFER_SIZE = 1024 * 1024,
51 // All encode operations are done independently.
52 ISSUE_MODE_SERIALISE_EVERYTHING = 0,
53 // Overlap as many operations as possible.
54 ISSUE_MODE_MAXIMISE_THROUGHPUT,
55 // Overlap operations only when satisfying parallel dependencies.
56 ISSUE_MODE_MINIMISE_LATENCY,
59 typedef struct VAAPIEncodeSlice {
61 void *codec_slice_params;
64 typedef struct VAAPIEncodePicture {
65 struct VAAPIEncodePicture *next;
67 int64_t display_order;
77 VASurfaceID input_surface;
80 VASurfaceID recon_surface;
83 VABufferID param_buffers[MAX_PARAM_BUFFERS];
85 VABufferID output_buffer;
88 void *codec_picture_params;
91 struct VAAPIEncodePicture *refs[MAX_PICTURE_REFERENCES];
94 VAAPIEncodeSlice *slices[MAX_PICTURE_SLICES];
97 typedef struct VAAPIEncodeContext {
100 // Codec-specific hooks.
101 const struct VAAPIEncodeType *codec;
103 // Codec-specific state.
106 VAProfile va_profile;
107 VAEntrypoint va_entrypoint;
108 VAConfigID va_config;
109 VAContextID va_context;
113 AVBufferRef *device_ref;
114 AVHWDeviceContext *device;
115 AVVAAPIDeviceContext *hwctx;
117 AVBufferRef *input_frames_ref;
118 AVHWFramesContext *input_frames;
120 // Input size, set from input frames.
123 // Aligned size, set by codec init, becomes hwframe size.
128 AVBufferRef *recon_frames_ref;
129 AVHWFramesContext *recon_frames;
131 VAConfigAttrib *config_attributes;
132 int nb_config_attributes;
134 // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
135 void *codec_sequence_params;
137 // Per-sequence parameters found in the per-picture parameter
138 // structure (VAEncPictureParameterBuffer*).
139 void *codec_picture_params;
141 // Current encoding window, in display (input) order.
142 VAAPIEncodePicture *pic_start, *pic_end;
144 // Next input order index (display order).
146 // Number of frames that output is behind input.
147 int64_t output_delay;
148 // Number of frames decode output will need to be delayed.
149 int64_t decode_delay;
150 // Next output order index (encode order).
151 int64_t output_order;
155 // Timestamp handling.
157 int64_t dts_pts_diff;
158 int64_t ts_ring[MAX_REORDER_DELAY * 3];
160 // Frame type decision.
169 } VAAPIEncodeContext;
172 typedef struct VAAPIEncodeType {
173 size_t priv_data_size;
175 int (*init)(AVCodecContext *avctx);
176 int (*close)(AVCodecContext *avctx);
178 size_t sequence_params_size;
179 size_t picture_params_size;
180 size_t slice_params_size;
182 int (*init_sequence_params)(AVCodecContext *avctx);
183 int (*init_picture_params)(AVCodecContext *avctx,
184 VAAPIEncodePicture *pic);
185 int (*init_slice_params)(AVCodecContext *avctx,
186 VAAPIEncodePicture *pic,
187 VAAPIEncodeSlice *slice);
189 int sequence_header_type;
190 int picture_header_type;
191 int slice_header_type;
193 int (*write_sequence_header)(AVCodecContext *avctx,
194 char *data, size_t *data_len);
195 int (*write_picture_header)(AVCodecContext *avctx,
196 VAAPIEncodePicture *pic,
197 char *data, size_t *data_len);
198 int (*write_slice_header)(AVCodecContext *avctx,
199 VAAPIEncodePicture *pic,
200 VAAPIEncodeSlice *slice,
201 char *data, size_t *data_len);
203 int (*write_extra_buffer)(AVCodecContext *avctx,
204 VAAPIEncodePicture *pic,
205 int index, int *type,
206 char *data, size_t *data_len);
210 int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
211 const AVFrame *input_image, int *got_packet);
213 int ff_vaapi_encode_init(AVCodecContext *avctx,
214 const VAAPIEncodeType *type);
215 int ff_vaapi_encode_close(AVCodecContext *avctx);
217 #endif /* AVCODEC_VAAPI_ENCODE_H */