From patchwork Tue Oct 30 09:07:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 10846 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2162B44C861 for ; Tue, 30 Oct 2018 11:08:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8480468A72E; Tue, 30 Oct 2018 11:07:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F3B1168A55E for ; Tue, 30 Oct 2018 11:07:35 +0200 (EET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2018 02:08:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,443,1534834800"; d="scan'208";a="86692842" Received: from kubernetes-master.sh.intel.com ([10.239.159.155]) by orsmga006.jf.intel.com with ESMTP; 30 Oct 2018 02:08:04 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Oct 2018 17:07:56 +0800 Message-Id: <20181030090756.14936-1-linjie.fu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] add an option to forbid the fallback to sw when hardware init fails X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- 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}, };