Unified · Split
| @@ -50,7 +50,15 @@ enum { · 49 unmodified lines | ||
| 50 | 50 | |
| 51 | 51 | typedef struct FFHWBaseEncodeContext { |
| 52 | 52 | const AVClass *class; |
| 53 | + | |
| 54 | + // Max number of frame buffered in encoder. | |
| 55 | + int async_depth; | |
| 53 | 56 | } FFHWBaseEncodeContext; |
| 54 | 57 | |
| 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 } | |
| 56 | 63 | |
| 64 | +#endif /* AVCODEC_HW_BASE_ENCODE_H */ | |
| @@ -669,7 +669,8 @@ static int vaapi_encode_set_output_property(AVCodecContext *avctx, · 668 unmodified lines | ||
| 669 | 669 | VAAPIEncodePicture *pic, |
| 670 | 670 | AVPacket *pkt) |
| 671 | 671 | { |
| 672 | − VAAPIEncodeContext *ctx = avctx->priv_data; | |
| 672 | + FFHWBaseEncodeContext *base_ctx = avctx->priv_data; | |
| 673 | + VAAPIEncodeContext *ctx = avctx->priv_data; | |
| 673 | 674 | |
| 674 | 675 | if (pic->type == FF_HW_PICTURE_TYPE_IDR) |
| 675 | 676 | pkt->flags |= AV_PKT_FLAG_KEY; |
| @@ -699,7 +700,7 @@ static int vaapi_encode_set_output_property(AVCodecContext *avctx, · 23 unmodified lines | ||
| 699 | 700 | pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff; |
| 700 | 701 | } else { |
| 701 | 702 | 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)]; | |
| 703 | 704 | } |
| 704 | 705 | |
| 705 | 706 | return 0; |
| @@ -1320,6 +1321,7 @@ static int vaapi_encode_check_frame(AVCodecContext *avctx, · 614 unmodified lines | ||
| 1320 | 1321 | |
| 1321 | 1322 | static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame) |
| 1322 | 1323 | { |
| 1324 | + FFHWBaseEncodeContext *base_ctx = avctx->priv_data; | |
| 1323 | 1325 | VAAPIEncodeContext *ctx = avctx->priv_data; |
| 1324 | 1326 | VAAPIEncodePicture *pic; |
| 1325 | 1327 | int err; |
| @@ -1365,7 +1367,7 @@ static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame) · 39 unmodified lines | ||
| 1365 | 1367 | ctx->dts_pts_diff = pic->pts - ctx->first_pts; |
| 1366 | 1368 | if (ctx->output_delay > 0) |
| 1367 | 1369 | 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; | |
| 1369 | 1371 | |
| 1370 | 1372 | pic->display_order = ctx->input_order; |
| 1371 | 1373 | ++ctx->input_order; |
| @@ -2773,7 +2775,8 @@ static av_cold int vaapi_encode_create_recon_frames(AVCodecContext *avctx) · 1401 unmodified lines | ||
| 2773 | 2775 | |
| 2774 | 2776 | av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) |
| 2775 | 2777 | { |
| 2776 | − VAAPIEncodeContext *ctx = avctx->priv_data; | |
| 2778 | + FFHWBaseEncodeContext *base_ctx = avctx->priv_data; | |
| 2779 | + VAAPIEncodeContext *ctx = avctx->priv_data; | |
| 2777 | 2780 | AVVAAPIFramesContext *recon_hwctx = NULL; |
| 2778 | 2781 | VAStatus vas; |
| 2779 | 2782 | int err; |
| @@ -2966,7 +2969,7 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) · 186 unmodified lines | ||
| 2966 | 2969 | vas = vaSyncBuffer(ctx->hwctx->display, VA_INVALID_ID, 0); |
| 2967 | 2970 | if (vas != VA_STATUS_ERROR_UNIMPLEMENTED) { |
| 2968 | 2971 | 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, | |
| 2970 | 2973 | sizeof(VAAPIEncodePicture *), |
| 2971 | 2974 | 0); |
| 2972 | 2975 | if (!ctx->encode_fifo) |
| @@ -374,8 +374,6 @@ typedef struct VAAPIEncodeContext { · 373 unmodified lines | ||
| 374 | 374 | int has_sync_buffer_func; |
| 375 | 375 | // Store buffered pic |
| 376 | 376 | AVFifo *encode_fifo; |
| 377 | − // Max number of frame buffered in encoder. | |
| 378 | − int async_depth; | |
| 379 | 377 | |
| 380 | 378 | /** Head data for current output pkt, used only for AV1. */ |
| 381 | 379 | //void *header_data; |
| @@ -491,11 +489,6 @@ int ff_vaapi_encode_close(AVCodecContext *avctx); · 109 unmodified lines | ||
| 491 | 489 | "Maximum B-frame reference depth", \ |
| 492 | 490 | OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \ |
| 493 | 491 | { .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 }, \ | |
| 499 | 492 | { "max_frame_size", \ |
| 500 | 493 | "Maximum frame size (in bytes)",\ |
| 501 | 494 | OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \ |
| @@ -965,6 +965,7 @@ static av_cold int vaapi_encode_av1_close(AVCodecContext *avctx) · 964 unmodified lines | ||
| 965 | 965 | #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) |
| 966 | 966 | |
| 967 | 967 | static const AVOption vaapi_encode_av1_options[] = { |
| 968 | + HW_BASE_ENCODE_COMMON_OPTIONS, | |
| 968 | 969 | VAAPI_ENCODE_COMMON_OPTIONS, |
| 969 | 970 | VAAPI_ENCODE_RC_OPTIONS, |
| 970 | 971 | { "profile", "Set profile (seq_profile)", |
| @@ -1276,6 +1276,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx) · 1275 unmodified lines | ||
| 1276 | 1276 | #define OFFSET(x) offsetof(VAAPIEncodeH264Context, x) |
| 1277 | 1277 | #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) |
| 1278 | 1278 | static const AVOption vaapi_encode_h264_options[] = { |
| 1279 | + HW_BASE_ENCODE_COMMON_OPTIONS, | |
| 1279 | 1280 | VAAPI_ENCODE_COMMON_OPTIONS, |
| 1280 | 1281 | VAAPI_ENCODE_RC_OPTIONS, |
| 1281 | 1282 | |
| @@ -1395,6 +1395,7 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx) · 1394 unmodified lines | ||
| 1395 | 1395 | #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x) |
| 1396 | 1396 | #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) |
| 1397 | 1397 | static const AVOption vaapi_encode_h265_options[] = { |
| 1398 | + HW_BASE_ENCODE_COMMON_OPTIONS, | |
| 1398 | 1399 | VAAPI_ENCODE_COMMON_OPTIONS, |
| 1399 | 1400 | VAAPI_ENCODE_RC_OPTIONS, |
| 1400 | 1401 | |
| @@ -540,6 +540,7 @@ static av_cold int vaapi_encode_mjpeg_close(AVCodecContext *avctx) · 539 unmodified lines | ||
| 540 | 540 | #define OFFSET(x) offsetof(VAAPIEncodeMJPEGContext, x) |
| 541 | 541 | #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) |
| 542 | 542 | static const AVOption vaapi_encode_mjpeg_options[] = { |
| 543 | + HW_BASE_ENCODE_COMMON_OPTIONS, | |
| 543 | 544 | VAAPI_ENCODE_COMMON_OPTIONS, |
| 544 | 545 | |
| 545 | 546 | { "jfif", "Include JFIF header", |
| @@ -639,6 +639,7 @@ static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx) · 638 unmodified lines | ||
| 639 | 639 | #define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x) |
| 640 | 640 | #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) |
| 641 | 641 | static const AVOption vaapi_encode_mpeg2_options[] = { |
| 642 | + HW_BASE_ENCODE_COMMON_OPTIONS, | |
| 642 | 643 | VAAPI_ENCODE_COMMON_OPTIONS, |
| 643 | 644 | VAAPI_ENCODE_RC_OPTIONS, |
| 644 | 645 | |
| @@ -216,6 +216,7 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext *avctx) · 215 unmodified lines | ||
| 216 | 216 | #define OFFSET(x) offsetof(VAAPIEncodeVP8Context, x) |
| 217 | 217 | #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) |
| 218 | 218 | static const AVOption vaapi_encode_vp8_options[] = { |
| 219 | + HW_BASE_ENCODE_COMMON_OPTIONS, | |
| 219 | 220 | VAAPI_ENCODE_COMMON_OPTIONS, |
| 220 | 221 | VAAPI_ENCODE_RC_OPTIONS, |
| 221 | 222 | |
| @@ -273,6 +273,7 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx) · 272 unmodified lines | ||
| 273 | 273 | #define OFFSET(x) offsetof(VAAPIEncodeVP9Context, x) |
| 274 | 274 | #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) |
| 275 | 275 | static const AVOption vaapi_encode_vp9_options[] = { |
| 276 | + HW_BASE_ENCODE_COMMON_OPTIONS, | |
| 276 | 277 | VAAPI_ENCODE_COMMON_OPTIONS, |
| 277 | 278 | VAAPI_ENCODE_RC_OPTIONS, |
| 278 | 279 | |