Currently ff_get_format will go through all usable choices if the chosen format was not supported. It will fallback to software if the hardware init fails.
According to the comment in ticket #7519, provided an option "-fallback_forbid 1" to return directly if hardware init fails and forbid the fallback to software. Signed-off-by: Linjie Fu <linjie...@intel.com> --- libavcodec/avcodec.h | 8 ++++++++ libavcodec/decode.c | 11 +++++++++-- libavcodec/options_table.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 705a3ce4f3..fac3c6acb2 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3312,6 +3312,14 @@ typedef struct AVCodecContext { * used as reference pictures). */ int extra_hw_frames; + + /** + * - forbid the fallback to software path in ff_get_format + * - when the hardware init fails. (0 -> disabled) + * - encoding: unused. + * - decoding: Set by user. + */ + int fallback_forbid; } AVCodecContext; #if FF_API_CODEC_GET_SET diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 4607e9f318..edadbd7e03 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1441,8 +1441,15 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel " "initialisation.\n", desc->name); err = hwaccel_init(avctx, hw_config); - if (err < 0) - goto try_again; + if (err < 0) { + if (avctx->fallback_forbid) { + av_log(avctx, AV_LOG_ERROR, "Format %s not usable, fallback " + "was forbidden.\n", desc->name); + ret = AV_PIX_FMT_NONE; + break; + } else + goto try_again; + } } ret = user_choice; break; diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index 099261e168..73f0333eeb 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -479,6 +479,7 @@ static const AVOption avcodec_options[] = { {"allow_high_depth", "allow to output YUV pixel formats with a different chroma sampling than 4:2:0 and/or other than 8 bits per component", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"}, {"allow_profile_mismatch", "attempt to decode anyway if HW accelerated decoder's supported profiles do not exactly match the stream", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH }, INT_MIN, INT_MAX, V | D, "hwaccel_flags"}, {"extra_hw_frames", "Number of extra hardware frames to allocate for the user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, V|D }, +{"fallback_forbid", "forbid the fallback to software path when hardware init fails", OFFSET(fallback_forbid), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, V|D }, {NULL}, }; -- 2.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel