From patchwork Tue Jun 18 07:52:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhong Li X-Patchwork-Id: 13597 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 3333E448BBE for ; Tue, 18 Jun 2019 10:52:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0BC9A680C91; Tue, 18 Jun 2019 10:52:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21137680C91 for ; Tue, 18 Jun 2019 10:52:30 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jun 2019 00:52:27 -0700 X-ExtLoop1: 1 Received: from media_ffmpeg_skl_e3.sh.intel.com ([10.239.159.38]) by fmsmga007.fm.intel.com with ESMTP; 18 Jun 2019 00:52:26 -0700 From: Zhong Li To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Jun 2019 15:52:29 +0800 Message-Id: <1560844349-22359-1-git-send-email-zhong.li@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [Patch V2] lavf/qsv_scale: add scaling modes support 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: Zhong Li MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" low_power mode will use a fixed HW engine (SFC), thus can offload EU usage. high quality mode will take EU usage (AVS sampler). Performance and EU usage (Render usage) comparsion on Intel(R) Xeon(R) CPU E3-1225 v5 @ 3.30GHz: High quality mode : ffmpeg -hwaccel qsv -c:v h264_qsv -i bbb_sunflower_1080p_30fps_normal_2000frames.h264 \ -vf scale_qsv=w=1280:h=736:mode=hq -f null - fps=389 RENDER usage: 28.10 (provided by MSDK metrics_monitor) Low Power mode: ffmpeg -hwaccel qsv -c:v h264_qsv -i ~/bbb_sunflower_1080p_30fps_normal_2000frames.h264 \ -vf scale_qsv=w=1280:h=736:mode=low_power -f null - fps=343 RENDER usage: 0.00 Low power mode (SFC) may be disabled if not supported by MSDK/Driver/HW, and replaced by AVS mode interanlly. Signed-off-by: Zhong Li --- libavfilter/vf_scale_qsv.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c index db7715f..499534e 100644 --- a/libavfilter/vf_scale_qsv.c +++ b/libavfilter/vf_scale_qsv.c @@ -69,6 +69,8 @@ enum var_name { VARS_NB }; +#define QSV_HAVE_SCALING_CONFIG QSV_VERSION_ATLEAST(1, 19) + typedef struct QSVScaleContext { const AVClass *class; @@ -88,7 +90,14 @@ typedef struct QSVScaleContext { int nb_surface_ptrs_out; mfxExtOpaqueSurfaceAlloc opaque_alloc; - mfxExtBuffer *ext_buffers[1]; + +#if QSV_HAVE_SCALING_CONFIG + mfxExtVPPScaling scale_conf; +#endif + int mode; + + mfxExtBuffer *ext_buffers[1 + QSV_HAVE_SCALING_CONFIG]; + int num_ext_buf; int shift_width, shift_height; @@ -285,6 +294,8 @@ static int init_out_session(AVFilterContext *ctx) mfxStatus err; int i; + s->num_ext_buf = 0; + /* extract the properties of the "master" session given to us */ err = MFXQueryIMPL(device_hwctx->session, &impl); if (err == MFX_ERR_NONE) @@ -357,10 +368,7 @@ static int init_out_session(AVFilterContext *ctx) s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION; s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc); - s->ext_buffers[0] = (mfxExtBuffer*)&s->opaque_alloc; - - par.ExtParam = s->ext_buffers; - par.NumExtParam = FF_ARRAY_ELEMS(s->ext_buffers); + s->ext_buffers[s->num_ext_buf++] = (mfxExtBuffer*)&s->opaque_alloc; par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY; } else { @@ -396,6 +404,18 @@ static int init_out_session(AVFilterContext *ctx) par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY; } +#if QSV_HAVE_SCALING_CONFIG + memset(&s->scale_conf, 0, sizeof(mfxExtVPPScaling)); + s->scale_conf.Header.BufferId = MFX_EXTBUFF_VPP_SCALING; + s->scale_conf.Header.BufferSz = sizeof(mfxExtVPPScaling); + s->scale_conf.ScalingMode = s->mode; + s->ext_buffers[s->num_ext_buf++] = (mfxExtBuffer*)&s->scale_conf; + av_log(ctx, AV_LOG_VERBOSE, "Scaling mode: %"PRIu16"\n", s->mode); +#endif + + par.ExtParam = s->ext_buffers; + par.NumExtParam = s->num_ext_buf; + par.AsyncDepth = 1; // TODO async par.vpp.In = in_frames_hwctx->surfaces[0].Info; @@ -595,6 +615,16 @@ static const AVOption options[] = { { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS }, { "format", "Output pixel format", OFFSET(format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS }, +#if QSV_HAVE_SCALING_CONFIG + { "mode", "set scaling mode", OFFSET(mode), AV_OPT_TYPE_INT, { .i64 = MFX_SCALING_MODE_DEFAULT}, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY, FLAGS, "mode"}, + { "low_power", "low power mode", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX, FLAGS, "mode"}, + { "hq", "high quality mode", 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCALING_MODE_QUALITY}, INT_MIN, INT_MAX, FLAGS, "mode"}, +#else + { "mode", "(not supported)", OFFSET(mode), AV_OPT_TYPE_INT, { .i64 = 0}, 0, INT_MAX, FLAGS, "mode"}, + { "low_power", "", 0, AV_OPT_TYPE_CONST, { .i64 = 1}, 0, 0, FLAGS, "mode"}, + { "hq", "", 0, AV_OPT_TYPE_CONST, { .i64 = 2}, 0, 0, FLAGS, "mode"}, +#endif + { NULL }, };