From 6af014f4028238b4c50f1731b3369a41d65fa9c4 Mon Sep 17 00:00:00 2001 From: Mark Thompson Date: Sun, 2 Apr 2017 23:05:13 +0100 Subject: [PATCH 1/3] vaapi_encode: Use gop_size consistently in RC parameters The non-H.26[45] codecs already use this form. Since we don't currently generate I frames for codecs which support them separately to IDR, the p_per_i variable is set to infinity by default so that it doesn't interfere with any other calculation. (All the code for I frames still exists, and it works for H.264 if set manually.) --- libavcodec/vaapi_encode.c | 3 +-- libavcodec/vaapi_encode_h264.c | 4 ++-- libavcodec/vaapi_encode_h265.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 411d879091..6205184190 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -1429,8 +1429,7 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) ctx->output_order = - ctx->output_delay - 1; // Currently we never generate I frames, only IDR. - ctx->p_per_i = ((avctx->gop_size + avctx->max_b_frames) / - (avctx->max_b_frames + 1)); + ctx->p_per_i = INT_MAX; ctx->b_per_p = avctx->max_b_frames; if (ctx->codec->sequence_params_size > 0) { diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index b918e0d75e..0c3ac34411 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -905,8 +905,8 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) mseq->nal_hrd_parameters_present_flag = 0; } - vseq->intra_period = ctx->p_per_i * (ctx->b_per_p + 1); - vseq->intra_idr_period = vseq->intra_period; + vseq->intra_period = avctx->gop_size; + vseq->intra_idr_period = avctx->gop_size; vseq->ip_period = ctx->b_per_p + 1; } diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index e9133b4313..9b029e2e20 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -832,8 +832,8 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) vseq->vui_time_scale = avctx->time_base.den; } - vseq->intra_period = ctx->p_per_i * (ctx->b_per_p + 1); - vseq->intra_idr_period = vseq->intra_period; + vseq->intra_period = avctx->gop_size; + vseq->intra_idr_period = avctx->gop_size; vseq->ip_period = ctx->b_per_p + 1; } From 64a5260c695dd8051509d3270295fd64eac56587 Mon Sep 17 00:00:00 2001 From: Mark Thompson Date: Mon, 27 Mar 2017 20:45:21 +0100 Subject: [PATCH 2/3] lavc: Add flag to allow profile mismatch with hardware decoding --- doc/APIchanges | 3 +++ libavcodec/avcodec.h | 14 ++++++++++++++ libavcodec/version.h | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index a0ca3b7ac0..58d59dd08c 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2017-03-23 API changes, most recent first: +2017-04-26 - xxxxxxx - lavc 58.3.1 - avcodec.h + Add AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH. + 2017-03-xx - xxxxxxx - lavc 57.37.0 - avcodec.h Add AVCodecContext.hwaccel_flags field. This will control some hwaccels at a later point. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 3118b10e9b..162f1abe4b 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3005,6 +3005,20 @@ typedef struct AVHWAccel { */ #define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1) +/** + * Hardware acceleration should still be attempted for decoding when the + * codec profile does not match the reported capabilities of the hardware. + * + * For example, this can be used to try to decode baseline profile H.264 + * streams in hardware - it will often succeed, because many streams marked + * as baseline profile actually conform to constrained baseline profile. + * + * @warning If the stream is actually not supported then the behaviour is + * undefined, and may include returning entirely incorrect output + * while indicating success. + */ +#define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH (1 << 2) + /** * @} */ diff --git a/libavcodec/version.h b/libavcodec/version.h index 2a61bbd718..88f17a1f78 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 3 -#define LIBAVCODEC_VERSION_MICRO 0 +#define LIBAVCODEC_VERSION_MICRO 1 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ From 7acb90333a187b0e847b66f9d3511245423dc0ce Mon Sep 17 00:00:00 2001 From: Mark Thompson Date: Mon, 27 Mar 2017 20:46:11 +0100 Subject: [PATCH 3/3] vaapi: Add external control of allow-profile-mismatch Uses the just-added ALLOW_PROFILE_MISMATCH flag. --- libavcodec/vaapi_decode.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index 0db79d401d..a63c4c62ec 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -283,14 +283,6 @@ static int vaapi_decode_make_config(AVCodecContext *avctx) int profile_count, exact_match, alt_profile; const AVPixFmtDescriptor *sw_desc, *desc; - // Allowing a profile mismatch can be useful because streams may - // over-declare their required capabilities - in particular, many - // H.264 baseline profile streams (notably some of those in FATE) - // only use the feature set of constrained baseline. This flag - // would have to be be set by some external means in order to - // actually be useful. (AV_HWACCEL_FLAG_IGNORE_PROFILE?) - int allow_profile_mismatch = 0; - codec_desc = avcodec_descriptor_get(avctx->codec_id); if (!codec_desc) { err = AVERROR(EINVAL); @@ -346,7 +338,8 @@ static int vaapi_decode_make_config(AVCodecContext *avctx) goto fail; } if (!exact_match) { - if (allow_profile_mismatch) { + if (avctx->hwaccel_flags & + AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) { av_log(avctx, AV_LOG_VERBOSE, "Codec %s profile %d not " "supported for hardware decode.\n", codec_desc->name, avctx->profile);