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
3838 enum {
3939 MAX_CONFIG_ATTRIBUTES = 4,
4040 MAX_GLOBAL_PARAMS = 4,
41+ MAX_DPB_SIZE = 16,
4142 MAX_PICTURE_REFERENCES = 2,
4243 MAX_REORDER_DELAY = 16,
4344 MAX_PARAM_BUFFER_SIZE = 1024,
@@ -66,9 +67,10 @@ typedef struct VAAPIEncodePicture { · 22 unmodified lines
6667 int64_t display_order;
6768 int64_t encode_order;
6869 int64_t pts;
70+ int force_idr;
6971
7072 int type;
71− int input_available;
73+ int b_depth;
7274 int encode_issued;
7375 int encode_complete;
7476
@@ -87,8 +89,26 @@ typedef struct VAAPIEncodePicture { · 12 unmodified lines
8789 void *priv_data;
8890 void *codec_picture_params;
8991
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;
91103 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];
92112
93113 int nb_slices;
94114 VAAPIEncodeSlice *slices;
@@ -120,6 +140,12 @@ typedef struct VAAPIEncodeContext { · 25 unmodified lines
120140 // Use low power encoding mode.
121141 int low_power;
122142
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+
123149 // Desired packed headers.
124150 unsigned int desired_packed_headers;
125151
@@ -207,26 +233,21 @@ typedef struct VAAPIEncodeContext { · 81 unmodified lines
207233
208234 // Current encoding window, in display (input) order.
209235 VAAPIEncodePicture *pic_start, *pic_end;
236+ // The next picture to use as the previous reference picture in
237+ // encoding order.
238+ VAAPIEncodePicture *next_prev;
210239
211240 // Next input order index (display order).
212241 int64_t input_order;
213242 // Number of frames that output is behind input.
214243 int64_t output_delay;
244+ // Next encode order index.
245+ int64_t encode_order;
215246 // Number of frames decode output will need to be delayed.
216247 int64_t decode_delay;
217− // Next output order index (encode order).
248+ // Next output order index (in encode order).
218249 int64_t output_order;
219250
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−
230251 // Timestamp handling.
231252 int64_t first_pts;
232253 int64_t dts_pts_diff;
@@ -240,11 +261,14 @@ typedef struct VAAPIEncodeContext { · 7 unmodified lines
240261
241262 // Frame type decision.
242263 int gop_size;
264+ int closed_gop;
265+ int gop_per_idr;
243266 int p_per_i;
267+ int max_b_depth;
244268 int b_per_p;
245269 int force_idr;
270+ int idr_counter;
246271 int gop_counter;
247− int p_counter;
248272 int end_of_stream;
249273 } VAAPIEncodeContext;
250274
@@ -253,6 +277,15 @@ enum { · 2 unmodified lines
253277 FLAG_SLICE_CONTROL = 1 << 0,
254278 // Codec only supports constant quality (no rate control).
255279 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,
256289 };
257290
258291 typedef struct VAAPIEncodeType {
@@ -327,6 +360,9 @@ typedef struct VAAPIEncodeType { · 68 unmodified lines
327360 int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
328361 const AVFrame *input_image, int *got_packet);
329362
363+int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame);
364+int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
365+
330366 int ff_vaapi_encode_init(AVCodecContext *avctx);
331367 int ff_vaapi_encode_close(AVCodecContext *avctx);
332368
@@ -336,7 +372,15 @@ int ff_vaapi_encode_close(AVCodecContext *avctx); · 3 unmodified lines
336372 "Use low-power encoding mode (only available on some platforms; " \
337373 "may not support all encoding features)", \
338374 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 }
340384
341385
342386 #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