History

vaapi_encode: Convert to send/receive API

This attaches the logic of picking the mode of for the next picture to the output, which simplifies some choices by removing the concept of the picture for which input is not yet available. At the same time, we allow more complex reference structures and track more reference metadata (particularly the contents of the DPB) for use in the codec-specific code. It also adds flags to explicitly track the available features of the different codecs. The new structure also allows open-GOP support, so that is now available for codecs which can do it.

Mark Thompson committed 7 years ago

Commit 5fdcf851 parent 26ce3a49 files · +433 −331Browse files

Showing the changes to libavcodec/vaapi_encode.h (1 of 9 files). Show all

Unified · Split

libavcodec/vaapi_encode.h+59−15
@@ -38,6 +38,7 @@ struct VAAPIEncodePicture; · 37 unmodified lines
38enum {38enum {
39 MAX_CONFIG_ATTRIBUTES = 4,39 MAX_CONFIG_ATTRIBUTES = 4,
40 MAX_GLOBAL_PARAMS = 4,40 MAX_GLOBAL_PARAMS = 4,
41 MAX_DPB_SIZE = 16,
41 MAX_PICTURE_REFERENCES = 2,42 MAX_PICTURE_REFERENCES = 2,
42 MAX_REORDER_DELAY = 16,43 MAX_REORDER_DELAY = 16,
43 MAX_PARAM_BUFFER_SIZE = 1024,44 MAX_PARAM_BUFFER_SIZE = 1024,
@@ -66,9 +67,10 @@ typedef struct VAAPIEncodePicture { · 22 unmodified lines
66 int64_t display_order;67 int64_t display_order;
67 int64_t encode_order;68 int64_t encode_order;
68 int64_t pts;69 int64_t pts;
70 int force_idr;
69 71
70 int type;72 int type;
71 int input_available;73 int b_depth;
72 int encode_issued;74 int encode_issued;
73 int encode_complete;75 int encode_complete;
74 76
@@ -87,8 +89,26 @@ typedef struct VAAPIEncodePicture { · 12 unmodified lines
87 void *priv_data;89 void *priv_data;
88 void *codec_picture_params;90 void *codec_picture_params;
89 91
90 int nb_refs;92 // Whether this picture is a reference picture.
93 int is_reference;
94
95 // The contents of the DPB after this picture has been decoded.
96 // This will contain the picture itself if it is a reference picture,
97 // but not if it isn't.
98 int nb_dpb_pics;
99 struct VAAPIEncodePicture *dpb[MAX_DPB_SIZE];
100 // The reference pictures used in decoding this picture. If they are
101 // used by later pictures they will also appear in the DPB.
102 int nb_refs;
91 struct VAAPIEncodePicture *refs[MAX_PICTURE_REFERENCES];103 struct VAAPIEncodePicture *refs[MAX_PICTURE_REFERENCES];
104 // The previous reference picture in encode order. Must be in at least
105 // one of the reference list and DPB list.
106 struct VAAPIEncodePicture *prev;
107 // Reference count for other pictures referring to this one through
108 // the above pointers, directly from incomplete pictures and indirectly
109 // through completed pictures.
110 int ref_count[2];
111 int ref_removed[2];
92 112
93 int nb_slices;113 int nb_slices;
94 VAAPIEncodeSlice *slices;114 VAAPIEncodeSlice *slices;
@@ -120,6 +140,12 @@ typedef struct VAAPIEncodeContext { · 25 unmodified lines
120 // Use low power encoding mode.140 // Use low power encoding mode.
121 int low_power;141 int low_power;
122 142
143 // Number of I frames between IDR frames.
144 int idr_interval;
145
146 // Desired B frame reference depth.
147 int desired_b_depth;
148
123 // Desired packed headers.149 // Desired packed headers.
124 unsigned int desired_packed_headers;150 unsigned int desired_packed_headers;
125 151
@@ -207,26 +233,21 @@ typedef struct VAAPIEncodeContext { · 81 unmodified lines
207 233
208 // Current encoding window, in display (input) order.234 // Current encoding window, in display (input) order.
209 VAAPIEncodePicture *pic_start, *pic_end;235 VAAPIEncodePicture *pic_start, *pic_end;
236 // The next picture to use as the previous reference picture in
237 // encoding order.
238 VAAPIEncodePicture *next_prev;
210 239
211 // Next input order index (display order).240 // Next input order index (display order).
212 int64_t input_order;241 int64_t input_order;
213 // Number of frames that output is behind input.242 // Number of frames that output is behind input.
214 int64_t output_delay;243 int64_t output_delay;
244 // Next encode order index.
245 int64_t encode_order;
215 // Number of frames decode output will need to be delayed.246 // Number of frames decode output will need to be delayed.
216 int64_t decode_delay;247 int64_t decode_delay;
217 // Next output order index (encode order).248 // Next output order index (in encode order).
218 int64_t output_order;249 int64_t output_order;
219 250
220 enum {
221 // All encode operations are done independently (synchronise
222 // immediately after every operation).
223 ISSUE_MODE_SERIALISE_EVERYTHING = 0,
224 // Overlap as many operations as possible.
225 ISSUE_MODE_MAXIMISE_THROUGHPUT,
226 // Overlap operations only when satisfying parallel dependencies.
227 ISSUE_MODE_MINIMISE_LATENCY,
228 } issue_mode;
229
230 // Timestamp handling.251 // Timestamp handling.
231 int64_t first_pts;252 int64_t first_pts;
232 int64_t dts_pts_diff;253 int64_t dts_pts_diff;
@@ -240,11 +261,14 @@ typedef struct VAAPIEncodeContext { · 7 unmodified lines
240 261
241 // Frame type decision.262 // Frame type decision.
242 int gop_size;263 int gop_size;
264 int closed_gop;
265 int gop_per_idr;
243 int p_per_i;266 int p_per_i;
267 int max_b_depth;
244 int b_per_p;268 int b_per_p;
245 int force_idr;269 int force_idr;
270 int idr_counter;
246 int gop_counter;271 int gop_counter;
247 int p_counter;
248 int end_of_stream;272 int end_of_stream;
249} VAAPIEncodeContext;273} VAAPIEncodeContext;
250 274
@@ -253,6 +277,15 @@ enum { · 2 unmodified lines
253 FLAG_SLICE_CONTROL = 1 << 0,277 FLAG_SLICE_CONTROL = 1 << 0,
254 // Codec only supports constant quality (no rate control).278 // Codec only supports constant quality (no rate control).
255 FLAG_CONSTANT_QUALITY_ONLY = 1 << 1,279 FLAG_CONSTANT_QUALITY_ONLY = 1 << 1,
280 // Codec is intra-only.
281 FLAG_INTRA_ONLY = 1 << 2,
282 // Codec supports B-pictures.
283 FLAG_B_PICTURES = 1 << 3,
284 // Codec supports referencing B-pictures.
285 FLAG_B_PICTURE_REFERENCES = 1 << 4,
286 // Codec supports non-IDR key pictures (that is, key pictures do
287 // not necessarily empty the DPB).
288 FLAG_NON_IDR_KEY_PICTURES = 1 << 5,
256};289};
257 290
258typedef struct VAAPIEncodeType {291typedef struct VAAPIEncodeType {
@@ -327,6 +360,9 @@ typedef struct VAAPIEncodeType { · 68 unmodified lines
327int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,360int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
328 const AVFrame *input_image, int *got_packet);361 const AVFrame *input_image, int *got_packet);
329 362
363int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame);
364int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
365
330int ff_vaapi_encode_init(AVCodecContext *avctx);366int ff_vaapi_encode_init(AVCodecContext *avctx);
331int ff_vaapi_encode_close(AVCodecContext *avctx);367int ff_vaapi_encode_close(AVCodecContext *avctx);
332 368
@@ -336,7 +372,15 @@ int ff_vaapi_encode_close(AVCodecContext *avctx); · 3 unmodified lines
336 "Use low-power encoding mode (only available on some platforms; " \372 "Use low-power encoding mode (only available on some platforms; " \
337 "may not support all encoding features)", \373 "may not support all encoding features)", \
338 OFFSET(common.low_power), AV_OPT_TYPE_BOOL, \374 OFFSET(common.low_power), AV_OPT_TYPE_BOOL, \
339 { .i64 = 0 }, 0, 1, FLAGS }375 { .i64 = 0 }, 0, 1, FLAGS }, \
376 { "idr_interval", \
377 "Distance (in I-frames) between IDR frames", \
378 OFFSET(common.idr_interval), AV_OPT_TYPE_INT, \
379 { .i64 = 0 }, 0, INT_MAX, FLAGS }, \
380 { "b_depth", \
381 "Maximum B-frame reference depth", \
382 OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \
383 { .i64 = 1 }, 1, INT_MAX, FLAGS }
340 384
341 385
342#endif /* AVCODEC_VAAPI_ENCODE_H */386#endif /* AVCODEC_VAAPI_ENCODE_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t