From patchwork Fri Nov 9 09:05:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 10963 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 DC3A244D266 for ; Fri, 9 Nov 2018 11:05:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 46061689FA4; Fri, 9 Nov 2018 11:05:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 74FAF689FA0 for ; Fri, 9 Nov 2018 11:05:05 +0200 (EET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Nov 2018 01:05:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,482,1534834800"; d="scan'208";a="98890637" Received: from kubernetes-master.sh.intel.com ([10.239.159.155]) by orsmga003.jf.intel.com with ESMTP; 09 Nov 2018 01:05:38 -0800 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Nov 2018 17:05:34 +0800 Message-Id: <20181109090534.27330-1-linjie.fu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH v3] fftools/ffmpeg: add an option to forbid the fallback to software path 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 path if the hardware init fails. Provided an option "-require_hwaccel 1" in user-code to detect frame->format and hwaccel_get_buffer in get_buffer. If hardware init fails, returns an error. Signed-off-by: Linjie Fu --- [v2] detect hardware init failures in get_buffer and modify in user-code [v3] changed the option name, add error message fftools/ffmpeg.c | 4 ++++ fftools/ffmpeg.h | 3 +++ fftools/ffmpeg_opt.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index da4259a9a8..113ab6312a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2890,6 +2890,10 @@ static int get_buffer(AVCodecContext *s, AVFrame *frame, int flags) if (ist->hwaccel_get_buffer && frame->format == ist->hwaccel_pix_fmt) return ist->hwaccel_get_buffer(s, frame, flags); + else if (ist->require_hwaccel) { + av_log(s, AV_LOG_ERROR, "Hardware acceleration is required and will not fallback to try software path.\n"); + return AVERROR(EINVAL); + } return avcodec_default_get_buffer2(s, frame, flags); } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index eb1eaf6363..a5c85daa67 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -133,6 +133,8 @@ typedef struct OptionsContext { int nb_hwaccel_output_formats; SpecifierOpt *autorotate; int nb_autorotate; + SpecifierOpt *require_hwaccel; + int nb_require_hwaccel; /* output options */ StreamMap *stream_maps; @@ -365,6 +367,7 @@ typedef struct InputStream { enum AVHWDeviceType hwaccel_device_type; char *hwaccel_device; enum AVPixelFormat hwaccel_output_format; + int require_hwaccel; /* hwaccel context */ void *hwaccel_ctx; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index d4851a2cd8..6890bb7fcf 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -730,6 +730,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) ist->autorotate = 1; MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st); + MATCH_PER_STREAM_OPT(require_hwaccel, i, ist->require_hwaccel, ic, st); MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st); if (codec_tag) { uint32_t tag = strtol(codec_tag, &next, 0); @@ -3600,6 +3601,9 @@ const OptionDef options[] = { { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(autorotate) }, "automatically insert correct rotate filters" }, + { "require_hwaccel", HAS_ARG | OPT_BOOL | OPT_SPEC | + OPT_EXPERT | OPT_INPUT, { .off = OFFSET(require_hwaccel)}, + "forbid the fallback to default software path when hardware init fails"}, /* audio options */ { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames },