History

avcodec/vaapi_encode: add async_depth to common options

Tong Wu committed 2 years ago

Commit ff063431 parent ab944e010 files · +24 −13Browse files

Unified · Split

10 files
  1. libavcodec/hw_base_encode.h +9 −1
  2. libavcodec/vaapi_encode.c +8 −5
  3. libavcodec/vaapi_encode.h +0 −7
  4. libavcodec/vaapi_encode_av1.c +1 −0
  5. libavcodec/vaapi_encode_h264.c +1 −0
  6. libavcodec/vaapi_encode_h265.c +1 −0
  7. libavcodec/vaapi_encode_mjpeg.c +1 −0
  8. libavcodec/vaapi_encode_mpeg2.c +1 −0
  9. libavcodec/vaapi_encode_vp8.c +1 −0
  10. libavcodec/vaapi_encode_vp9.c +1 −0
libavcodec/hw_base_encode.h+9−1
@@ -50,7 +50,15 @@ enum { · 49 unmodified lines
5050
5151 typedef struct FFHWBaseEncodeContext {
5252 const AVClass *class;
53+
54+ // Max number of frame buffered in encoder.
55+ int async_depth;
5356 } FFHWBaseEncodeContext;
5457
55−#endif /* AVCODEC_HW_BASE_ENCODE_H */
58+#define HW_BASE_ENCODE_COMMON_OPTIONS \
59+ { "async_depth", "Maximum processing parallelism. " \
60+ "Increase this to improve single channel performance.", \
61+ OFFSET(common.base.async_depth), AV_OPT_TYPE_INT, \
62+ { .i64 = 2 }, 1, MAX_ASYNC_DEPTH, FLAGS }
5663
64+#endif /* AVCODEC_HW_BASE_ENCODE_H */
libavcodec/vaapi_encode.c+8−5
@@ -669,7 +669,8 @@ static int vaapi_encode_set_output_property(AVCodecContext *avctx, · 668 unmodified lines
669669 VAAPIEncodePicture *pic,
670670 AVPacket *pkt)
671671 {
672− VAAPIEncodeContext *ctx = avctx->priv_data;
672+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
673+ VAAPIEncodeContext *ctx = avctx->priv_data;
673674
674675 if (pic->type == FF_HW_PICTURE_TYPE_IDR)
675676 pkt->flags |= AV_PKT_FLAG_KEY;
@@ -699,7 +700,7 @@ static int vaapi_encode_set_output_property(AVCodecContext *avctx, · 23 unmodified lines
699700 pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
700701 } else {
701702 pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
702− (3 * ctx->output_delay + ctx->async_depth)];
703+ (3 * ctx->output_delay + base_ctx->async_depth)];
703704 }
704705
705706 return 0;
@@ -1320,6 +1321,7 @@ static int vaapi_encode_check_frame(AVCodecContext *avctx, · 614 unmodified lines
13201321
13211322 static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame)
13221323 {
1324+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
13231325 VAAPIEncodeContext *ctx = avctx->priv_data;
13241326 VAAPIEncodePicture *pic;
13251327 int err;
@@ -1365,7 +1367,7 @@ static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame) · 39 unmodified lines
13651367 ctx->dts_pts_diff = pic->pts - ctx->first_pts;
13661368 if (ctx->output_delay > 0)
13671369 ctx->ts_ring[ctx->input_order %
1368− (3 * ctx->output_delay + ctx->async_depth)] = pic->pts;
1370+ (3 * ctx->output_delay + base_ctx->async_depth)] = pic->pts;
13691371
13701372 pic->display_order = ctx->input_order;
13711373 ++ctx->input_order;
@@ -2773,7 +2775,8 @@ static av_cold int vaapi_encode_create_recon_frames(AVCodecContext *avctx) · 1401 unmodified lines
27732775
27742776 av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
27752777 {
2776− VAAPIEncodeContext *ctx = avctx->priv_data;
2778+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
2779+ VAAPIEncodeContext *ctx = avctx->priv_data;
27772780 AVVAAPIFramesContext *recon_hwctx = NULL;
27782781 VAStatus vas;
27792782 int err;
@@ -2966,7 +2969,7 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) · 186 unmodified lines
29662969 vas = vaSyncBuffer(ctx->hwctx->display, VA_INVALID_ID, 0);
29672970 if (vas != VA_STATUS_ERROR_UNIMPLEMENTED) {
29682971 ctx->has_sync_buffer_func = 1;
2969− ctx->encode_fifo = av_fifo_alloc2(ctx->async_depth,
2972+ ctx->encode_fifo = av_fifo_alloc2(base_ctx->async_depth,
29702973 sizeof(VAAPIEncodePicture *),
29712974 0);
29722975 if (!ctx->encode_fifo)
libavcodec/vaapi_encode.h+0−7
@@ -374,8 +374,6 @@ typedef struct VAAPIEncodeContext { · 373 unmodified lines
374374 int has_sync_buffer_func;
375375 // Store buffered pic
376376 AVFifo *encode_fifo;
377− // Max number of frame buffered in encoder.
378− int async_depth;
379377
380378 /** Head data for current output pkt, used only for AV1. */
381379 //void *header_data;
@@ -491,11 +489,6 @@ int ff_vaapi_encode_close(AVCodecContext *avctx); · 109 unmodified lines
491489 "Maximum B-frame reference depth", \
492490 OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \
493491 { .i64 = 1 }, 1, INT_MAX, FLAGS }, \
494− { "async_depth", "Maximum processing parallelism. " \
495− "Increase this to improve single channel performance. This option " \
496− "doesn't work if driver doesn't implement vaSyncBuffer function.", \
497− OFFSET(common.async_depth), AV_OPT_TYPE_INT, \
498− { .i64 = 2 }, 1, MAX_ASYNC_DEPTH, FLAGS }, \
499492 { "max_frame_size", \
500493 "Maximum frame size (in bytes)",\
501494 OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \
libavcodec/vaapi_encode_av1.c+1−0
@@ -965,6 +965,7 @@ static av_cold int vaapi_encode_av1_close(AVCodecContext *avctx) · 964 unmodified lines
965965 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
966966
967967 static const AVOption vaapi_encode_av1_options[] = {
968+ HW_BASE_ENCODE_COMMON_OPTIONS,
968969 VAAPI_ENCODE_COMMON_OPTIONS,
969970 VAAPI_ENCODE_RC_OPTIONS,
970971 { "profile", "Set profile (seq_profile)",
libavcodec/vaapi_encode_h264.c+1−0
@@ -1276,6 +1276,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx) · 1275 unmodified lines
12761276 #define OFFSET(x) offsetof(VAAPIEncodeH264Context, x)
12771277 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
12781278 static const AVOption vaapi_encode_h264_options[] = {
1279+ HW_BASE_ENCODE_COMMON_OPTIONS,
12791280 VAAPI_ENCODE_COMMON_OPTIONS,
12801281 VAAPI_ENCODE_RC_OPTIONS,
12811282
libavcodec/vaapi_encode_h265.c+1−0
@@ -1395,6 +1395,7 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx) · 1394 unmodified lines
13951395 #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
13961396 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
13971397 static const AVOption vaapi_encode_h265_options[] = {
1398+ HW_BASE_ENCODE_COMMON_OPTIONS,
13981399 VAAPI_ENCODE_COMMON_OPTIONS,
13991400 VAAPI_ENCODE_RC_OPTIONS,
14001401
libavcodec/vaapi_encode_mjpeg.c+1−0
@@ -540,6 +540,7 @@ static av_cold int vaapi_encode_mjpeg_close(AVCodecContext *avctx) · 539 unmodified lines
540540 #define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x)
541541 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
542542 static const AVOption vaapi_encode_mjpeg_options[] = {
543+ HW_BASE_ENCODE_COMMON_OPTIONS,
543544 VAAPI_ENCODE_COMMON_OPTIONS,
544545
545546 { "jfif", "Include JFIF header",
libavcodec/vaapi_encode_mpeg2.c+1−0
@@ -639,6 +639,7 @@ static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx) · 638 unmodified lines
639639 #define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x)
640640 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
641641 static const AVOption vaapi_encode_mpeg2_options[] = {
642+ HW_BASE_ENCODE_COMMON_OPTIONS,
642643 VAAPI_ENCODE_COMMON_OPTIONS,
643644 VAAPI_ENCODE_RC_OPTIONS,
644645
libavcodec/vaapi_encode_vp8.c+1−0
@@ -216,6 +216,7 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext *avctx) · 215 unmodified lines
216216 #define OFFSET(x) offsetof(VAAPIEncodeVP8Context, x)
217217 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
218218 static const AVOption vaapi_encode_vp8_options[] = {
219+ HW_BASE_ENCODE_COMMON_OPTIONS,
219220 VAAPI_ENCODE_COMMON_OPTIONS,
220221 VAAPI_ENCODE_RC_OPTIONS,
221222
libavcodec/vaapi_encode_vp9.c+1−0
@@ -273,6 +273,7 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx) · 272 unmodified lines
273273 #define OFFSET(x) offsetof(VAAPIEncodeVP9Context, x)
274274 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
275275 static const AVOption vaapi_encode_vp9_options[] = {
276+ HW_BASE_ENCODE_COMMON_OPTIONS,
276277 VAAPI_ENCODE_COMMON_OPTIONS,
277278 VAAPI_ENCODE_RC_OPTIONS,
278279

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