From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A6F5844136 for ; Sat, 28 Jan 2023 06:05:08 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E54C968BC6F; Sat, 28 Jan 2023 08:05:03 +0200 (EET) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 35FC6689B11 for ; Sat, 28 Jan 2023 08:04:54 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674885901; x=1706421901; h=from:to:subject:date:message-id:references:in-reply-to: content-id:content-transfer-encoding:mime-version; bh=ie5V1/TXgTyHSGcHMPTO4Bygw1uHJMDDFBizbYlcRfo=; b=CCmI+8zruAimQvMhBc41zbtHyU1ghsB/rX4STBtOV40x67cxBli0et+R TXDg7IBJox2g83IjKVPb3Th7u6AARgUGccYaJrydF1QcFFa3426q7igQ2 uE5z2cvj/NAmIoz2Cdni3rxC0t4tD/6UIZoWV+oyt2ik9+i+s8qvhQIDK LsJeAggyWmZuDkuLZjm1cjglphxhKVZ9bTZ7xBTNODVUAGP+i9rv/7cPu aTb3zTCIeQp/uI590F9WmNjS9xSTsyNhq7cxTWHD4w2h+1pIaXt54fRxP C9BdVN9GO9BhN2jEQGXPP8A7ajtzombVNoSC+iZcCTzeNF434tkxtJmmH Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10603"; a="389647045" X-IronPort-AV: E=Sophos;i="5.97,253,1669104000"; d="scan'208";a="389647045" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2023 22:04:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10603"; a="992320959" X-IronPort-AV: E=Sophos;i="5.97,253,1669104000"; d="scan'208";a="992320959" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga005.fm.intel.com with ESMTP; 27 Jan 2023 22:04:51 -0800 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 27 Jan 2023 22:04:50 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 27 Jan 2023 22:04:50 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Fri, 27 Jan 2023 22:04:50 -0800 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.168) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Fri, 27 Jan 2023 22:04:49 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ARCkMye9kF+IGoVHiA8K+P5hzdmHNqdpWYUpWaDOAZBvxntdj9zUdG1pDUW6bS3tfJ0ODqGKSxmiYj3rM0QqMtJVTl6RHhLrLUXe8hLjEXzK0YK9Pbdj3rgKLNRYh3OTc49l/rCeqqZyeos1yBAgtSEwGJwhEO7fIdnYrJgYCZXyuRbz2U1M2b7tqVN1r1h3AGJ3+N7J+KYjA1tj1VfWM5/40ukuc6TRA1whoyIBNVbg5oQUVPim1aym5edjxvTpDmTEH8VJ6hX7WIZK0d3hLRaooBOrrE/pF3lbdkn8jCkSmlICM2Xkm8rwkckt6Kagpn0x665cnWxVX0k/1gEMzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ie5V1/TXgTyHSGcHMPTO4Bygw1uHJMDDFBizbYlcRfo=; b=Rdn7O3Td28muAQ8KFgSOdgDrJnG5w8c2R+iDqYAnvmGIKgT5kVa9+bhpmDbx90ONmL2IIZo+/2tOq2IWx9LISemsPV/PekPYN9ZmabXihZKgiKLpuJTPh7yAr7KILyrqfCzkJ90pLlLOVV3SltdVldqmEWtbxWeGo1BIvSWIaMviPgN0vC0eycpizqFoGyKYw6r/KjdkWYFs/1ZEOO0szdUf40VojJBiFTaX0AmA8/IeEoci97LiHWdqHZWhDOZqYFanxMwqm4zBAS9GANq0p1MHcnNRuLeivhCRHsJ//pDPISWuMR7kyIh8wW+RbL7gjJwY5QSy3ddCciLfR48b+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from BN9PR11MB5515.namprd11.prod.outlook.com (2603:10b6:408:104::8) by SA1PR11MB6991.namprd11.prod.outlook.com (2603:10b6:806:2b8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.28; Sat, 28 Jan 2023 06:04:47 +0000 Received: from BN9PR11MB5515.namprd11.prod.outlook.com ([fe80::36ba:13c8:6a29:c7af]) by BN9PR11MB5515.namprd11.prod.outlook.com ([fe80::36ba:13c8:6a29:c7af%7]) with mapi id 15.20.6043.028; Sat, 28 Jan 2023 06:04:47 +0000 From: "Xiang, Haihao" To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [FFmpeg-devel][PATCH 1/3] lavfi/scale_qsv: simplify scale_qsv filter Thread-Index: AQHZKjvVgfokzKjjIU2Yl1oNZIxq8K6zaFyA Date: Sat, 28 Jan 2023 06:04:46 +0000 Message-ID: <5a93914e174bd1b2ca45e63ecf000f69aeb54d42.camel@intel.com> References: <20230117062027.28073-1-haihao.xiang@intel.com> In-Reply-To: <20230117062027.28073-1-haihao.xiang@intel.com> Accept-Language: en-AS, zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Evolution 3.36.5-0ubuntu1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BN9PR11MB5515:EE_|SA1PR11MB6991:EE_ x-ms-office365-filtering-correlation-id: da5e41b9-b409-44fe-6d2f-08db00f58ee8 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: viZA+qB6Hgkb+Hmw2dmB34zeI40QPVCcg/zrslUG3cuJaLNo4r9vTlhPMQMNydQMGkfYrVssZq9epkll63KgJ2VhFPMzDIXMoVvllNMZG47FLg02Wt+pey5szH8lBUe5u0PgMLttbd8l8DLUGOrMkiHNin0LjdqoDKPfOoSnOcIPTsEUv5kfJkBZLfMlTZSAatBGpicOn8P2jaa0FAXU3CSgjJrPuDbroC1M8wTUvVtlrfnThE+a1WCcwW2N1aKCUGYQjjhwDInM4wMSPauMYMSs/NjkM899SzfLfGYNJymmnCtH21qZHc4cy8QR7HwggumTWyAQN/LutU/dzIlqy5h4cutiN3Uluh1iyw2FKNb13t9vdBAHPiLg3APOujUSmY6wJmBVcB9p0CbNBbFL+EEe8fZtuQXTOqboPlTNQsfVHKBx9befC6x+a+IZwXJWcm7SRQ5ipd8xfntKBXJt4PE9cdJrcQVYlLY5xZjxYB1c2FL0R7ogzbA1nC+MvMkmgnqpBHCplrro13ibGSuEnMDuoxrdu5h+gFoW6ZfYSXQ1/juXz2ahqqKFwc70VXBwQwKlo3ZuwijE2FCV7/qGQaYEpuay/Hnt4NUkNu/JFBuruoKVstk8RPWLEWTltpwPJK9RK20xVaWt1ZHe6gvlKC/DN16MtWI2s8m/X1qm8nlclQrJ3Bbn4hV1we60p6MNszeKd+xqrO7A/9ufsSk4KQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN9PR11MB5515.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(136003)(346002)(376002)(396003)(39860400002)(366004)(451199018)(36756003)(478600001)(6486002)(71200400001)(26005)(186003)(6512007)(2906002)(6506007)(41300700001)(66476007)(66446008)(30864003)(64756008)(8676002)(66556008)(66946007)(6916009)(91956017)(76116006)(8936002)(316002)(5660300002)(122000001)(38100700002)(86362001)(82960400001)(38070700005)(2616005)(83380400001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?d1ErQzRYZFU5SCtVWHo3dEF5M1JnTjd6YzVuc1FHMm5LRjl2eWFFNTl5cXhp?= =?utf-8?B?ZHErUEM4MHJEL0JBaDUyeW00c3ZET2hncWtpS1hsV2FaTSsybWF2aVZ6azlr?= =?utf-8?B?eG5Ib3NDVXNma2U4UGtpTlliVTBnVnFqUDJIbGs4Z3RvUXp1em1idmE4Mnly?= =?utf-8?B?SkVtWWo4ZTZnaWw1QTNhTjE4OUdaVGEvOUgzcWoyOUdpemtaM2tjZVliRDJi?= =?utf-8?B?Z0JuLzR6YjlMWDl3YVgzaHJROW9DcUovVWt4UGZZR2pnSG9MbldQUFY4S0tS?= =?utf-8?B?VWZpR2wyU3Q0LytSUmxJNjh4K1pkYmlXTzYwaUR1ZDI2ZWpQ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BuRnpsdFdNbVFUcmNJaFJzMExSV2NSUHNU?= =?utf-8?B?bUE9PQ==?= Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5515.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: da5e41b9-b409-44fe-6d2f-08db00f58ee8 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jan 2023 06:04:46.7016 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: x5ds+eV17ZjKSTC8xDKiOhzlH+J/wFYWz4EBWznSl1aa6cIb6r3fyk8b7DYnVEgdulmwcVxlSzQBY2emdEqg5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR11MB6991 X-OriginatorOrg: intel.com Subject: Re: [FFmpeg-devel] [PATCH 1/3] lavfi/scale_qsv: simplify scale_qsv filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Di, 2023-01-17 at 14:20 +0800, Xiang, Haihao wrote: > From: Haihao Xiang > > Use QSVVPPContext as a base context of QSVScaleContext, hence we may > re-use functions defined for QSVVPPContext to manage MFX session for > scale_qsv filter. > > In addition, system memory has been taken into account in > QSVVVPPContext, we may add support for non-QSV pixel formats in the > future. > > Signed-off-by: Haihao Xiang > --- > configure | 1 + > libavfilter/vf_scale_qsv.c | 441 +++---------------------------------- > 2 files changed, 35 insertions(+), 407 deletions(-) > > diff --git a/configure b/configure > index 6e88c32223..86f930024b 100755 > --- a/configure > +++ b/configure > @@ -3721,6 +3721,7 @@ sab_filter_deps="gpl swscale" > scale2ref_filter_deps="swscale" > scale_filter_deps="swscale" > scale_qsv_filter_deps="libmfx" > +scale_qsv_filter_select="qsvvpp" > scdet_filter_select="scene_sad" > select_filter_select="scene_sad" > sharpness_vaapi_filter_deps="vaapi" > diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c > index a89a3ba6e6..8eb8bc9ec1 100644 > --- a/libavfilter/vf_scale_qsv.c > +++ b/libavfilter/vf_scale_qsv.c > @@ -66,35 +66,11 @@ enum var_name { > #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) > > typedef struct QSVScaleContext { > - const AVClass *class; > - > - /* a clone of the main session, used internally for scaling */ > - mfxSession session; > - > - mfxMemId *mem_ids_in; > - int nb_mem_ids_in; > - > - mfxMemId *mem_ids_out; > - int nb_mem_ids_out; > - > - mfxFrameSurface1 **surface_ptrs_in; > - int nb_surface_ptrs_in; > - > - mfxFrameSurface1 **surface_ptrs_out; > - int nb_surface_ptrs_out; > - > -#if QSV_HAVE_OPAQUE > - mfxExtOpaqueSurfaceAlloc opaque_alloc; > -#endif > + QSVVPPContext qsv; > > mfxExtVPPScaling scale_conf; > int mode; > > - mfxExtBuffer *ext_buffers[2]; > - int num_ext_buf; > - > - int shift_width, shift_height; > - > /** > * New dimensions. Special values are: > * 0 = original width/height > @@ -131,338 +107,21 @@ static av_cold int qsvscale_init(AVFilterContext *ctx) > > static av_cold void qsvscale_uninit(AVFilterContext *ctx) > { > - QSVScaleContext *s = ctx->priv; > - > - if (s->session) { > - MFXClose(s->session); > - s->session = NULL; > - } > - > - av_freep(&s->mem_ids_in); > - av_freep(&s->mem_ids_out); > - s->nb_mem_ids_in = 0; > - s->nb_mem_ids_out = 0; > - > - av_freep(&s->surface_ptrs_in); > - av_freep(&s->surface_ptrs_out); > - s->nb_surface_ptrs_in = 0; > - s->nb_surface_ptrs_out = 0; > -} > - > -static int init_out_pool(AVFilterContext *ctx, > - int out_width, int out_height) > -{ > - QSVScaleContext *s = ctx->priv; > - AVFilterLink *outlink = ctx->outputs[0]; > - > - AVHWFramesContext *in_frames_ctx; > - AVHWFramesContext *out_frames_ctx; > - AVQSVFramesContext *in_frames_hwctx; > - AVQSVFramesContext *out_frames_hwctx; > - enum AVPixelFormat in_format; > - enum AVPixelFormat out_format; > - int i, ret; > - > - /* check that we have a hw context */ > - if (!ctx->inputs[0]->hw_frames_ctx) { > - av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n"); > - return AVERROR(EINVAL); > - } > - in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx- > >data; > - in_frames_hwctx = in_frames_ctx->hwctx; > - > - in_format = in_frames_ctx->sw_format; > - out_format = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format; > - > - outlink->hw_frames_ctx = av_hwframe_ctx_alloc(in_frames_ctx->device_ref); > - if (!outlink->hw_frames_ctx) > - return AVERROR(ENOMEM); > - out_frames_ctx = (AVHWFramesContext*)outlink->hw_frames_ctx->data; > - out_frames_hwctx = out_frames_ctx->hwctx; > - > - out_frames_ctx->format = AV_PIX_FMT_QSV; > - out_frames_ctx->width = FFALIGN(out_width, 16); > - out_frames_ctx->height = FFALIGN(out_height, 16); > - out_frames_ctx->sw_format = out_format; > - out_frames_ctx->initial_pool_size = 4; > - > - out_frames_hwctx->frame_type = in_frames_hwctx->frame_type | > MFX_MEMTYPE_FROM_VPPOUT; > - > - ret = ff_filter_init_hw_frames(ctx, outlink, 32); > - if (ret < 0) > - return ret; > - > - ret = av_hwframe_ctx_init(outlink->hw_frames_ctx); > - if (ret < 0) > - return ret; > - > - for (i = 0; i < out_frames_hwctx->nb_surfaces; i++) { > - mfxFrameInfo *info = &out_frames_hwctx->surfaces[i].Info; > - info->CropW = out_width; > - info->CropH = out_height; > - } > - > - return 0; > -} > - > -static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, > - mfxFrameAllocResponse *resp) > -{ > - AVFilterContext *ctx = pthis; > - QSVScaleContext *s = ctx->priv; > - > - if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) || > - !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) || > - !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME)) > - return MFX_ERR_UNSUPPORTED; > - > - if (req->Type & MFX_MEMTYPE_FROM_VPPIN) { > - resp->mids = s->mem_ids_in; > - resp->NumFrameActual = s->nb_mem_ids_in; > - } else { > - resp->mids = s->mem_ids_out; > - resp->NumFrameActual = s->nb_mem_ids_out; > - } > - > - return MFX_ERR_NONE; > -} > - > -static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp) > -{ > - return MFX_ERR_NONE; > -} > - > -static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) > -{ > - return MFX_ERR_UNSUPPORTED; > -} > - > -static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) > -{ > - return MFX_ERR_UNSUPPORTED; > -} > - > -static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl) > -{ > - mfxHDLPair *pair_dst = (mfxHDLPair*)hdl; > - mfxHDLPair *pair_src = (mfxHDLPair*)mid; > - > - pair_dst->first = pair_src->first; > - > - if (pair_src->second != (mfxMemId)MFX_INFINITE) > - pair_dst->second = pair_src->second; > - return MFX_ERR_NONE; > -} > - > -static int init_out_session(AVFilterContext *ctx) > -{ > - > - QSVScaleContext *s = ctx->priv; > - AVHWFramesContext *in_frames_ctx = (AVHWFramesContext*)ctx- > >inputs[0]->hw_frames_ctx->data; > - AVHWFramesContext *out_frames_ctx = (AVHWFramesContext*)ctx- > >outputs[0]->hw_frames_ctx->data; > - AVQSVFramesContext *in_frames_hwctx = in_frames_ctx->hwctx; > - AVQSVFramesContext *out_frames_hwctx = out_frames_ctx->hwctx; > - AVQSVDeviceContext *device_hwctx = in_frames_ctx->device_ctx->hwctx; > - > - int opaque = 0; > - > - mfxHDL handle = NULL; > - mfxHandleType handle_type; > - mfxVersion ver; > - mfxIMPL impl; > - mfxVideoParam par; > - mfxStatus err; > - int i, ret; > - > -#if QSV_HAVE_OPAQUE > - opaque = !!(in_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); > -#endif > - 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) > - err = MFXQueryVersion(device_hwctx->session, &ver); > - if (err != MFX_ERR_NONE) { > - av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n"); > - return AVERROR_UNKNOWN; > - } > - > - if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) { > - handle_type = MFX_HANDLE_VA_DISPLAY; > - } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) { > - handle_type = MFX_HANDLE_D3D11_DEVICE; > - } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) { > - handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER; > - } else { > - av_log(ctx, AV_LOG_ERROR, "Error unsupported handle type\n"); > - return AVERROR_UNKNOWN; > - } > - > - err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, > &handle); > - if (err < 0) > - return ff_qsvvpp_print_error(ctx, err, "Error getting the session > handle"); > - else if (err > 0) { > - ff_qsvvpp_print_warning(ctx, err, "Warning in getting the session > handle"); > - return AVERROR_UNKNOWN; > - } > - > - /* create a "slave" session with those same properties, to be used for > - * actual scaling */ > - ret = ff_qsvvpp_create_mfx_session(ctx, device_hwctx->loader, impl, &ver, > - &s->session); > - if (ret) > - return ret; > - > - if (handle) { > - err = MFXVideoCORE_SetHandle(s->session, handle_type, handle); > - if (err != MFX_ERR_NONE) > - return AVERROR_UNKNOWN; > - } > - > - if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) { > - err = MFXJoinSession(device_hwctx->session, s->session); > - if (err != MFX_ERR_NONE) > - return AVERROR_UNKNOWN; > - } > - > - memset(&par, 0, sizeof(par)); > - > - if (!opaque) { > - mfxFrameAllocator frame_allocator = { > - .pthis = ctx, > - .Alloc = frame_alloc, > - .Lock = frame_lock, > - .Unlock = frame_unlock, > - .GetHDL = frame_get_hdl, > - .Free = frame_free, > - }; > - > - s->mem_ids_in = av_calloc(in_frames_hwctx->nb_surfaces, > - sizeof(*s->mem_ids_in)); > - if (!s->mem_ids_in) > - return AVERROR(ENOMEM); > - for (i = 0; i < in_frames_hwctx->nb_surfaces; i++) > - s->mem_ids_in[i] = in_frames_hwctx->surfaces[i].Data.MemId; > - s->nb_mem_ids_in = in_frames_hwctx->nb_surfaces; > - > - s->mem_ids_out = av_calloc(out_frames_hwctx->nb_surfaces, > - sizeof(*s->mem_ids_out)); > - if (!s->mem_ids_out) > - return AVERROR(ENOMEM); > - for (i = 0; i < out_frames_hwctx->nb_surfaces; i++) > - s->mem_ids_out[i] = out_frames_hwctx->surfaces[i].Data.MemId; > - s->nb_mem_ids_out = out_frames_hwctx->nb_surfaces; > - > - err = MFXVideoCORE_SetFrameAllocator(s->session, &frame_allocator); > - if (err != MFX_ERR_NONE) > - return AVERROR_UNKNOWN; > - > - par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | > MFX_IOPATTERN_OUT_VIDEO_MEMORY; > - } > -#if QSV_HAVE_OPAQUE > - else { > - s->surface_ptrs_in = av_calloc(in_frames_hwctx->nb_surfaces, > - sizeof(*s->surface_ptrs_in)); > - if (!s->surface_ptrs_in) > - return AVERROR(ENOMEM); > - for (i = 0; i < in_frames_hwctx->nb_surfaces; i++) > - s->surface_ptrs_in[i] = in_frames_hwctx->surfaces + i; > - s->nb_surface_ptrs_in = in_frames_hwctx->nb_surfaces; > - > - s->surface_ptrs_out = av_calloc(out_frames_hwctx->nb_surfaces, > - sizeof(*s->surface_ptrs_out)); > - if (!s->surface_ptrs_out) > - return AVERROR(ENOMEM); > - for (i = 0; i < out_frames_hwctx->nb_surfaces; i++) > - s->surface_ptrs_out[i] = out_frames_hwctx->surfaces + i; > - s->nb_surface_ptrs_out = out_frames_hwctx->nb_surfaces; > - > - s->opaque_alloc.In.Surfaces = s->surface_ptrs_in; > - s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs_in; > - s->opaque_alloc.In.Type = in_frames_hwctx->frame_type; > - > - s->opaque_alloc.Out.Surfaces = s->surface_ptrs_out; > - s->opaque_alloc.Out.NumSurface = s->nb_surface_ptrs_out; > - s->opaque_alloc.Out.Type = out_frames_hwctx->frame_type; > - > - s->opaque_alloc.Header.BufferId = > MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION; > - s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc); > - > - s->ext_buffers[s->num_ext_buf++] = (mfxExtBuffer*)&s->opaque_alloc; > - > - par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | > MFX_IOPATTERN_OUT_OPAQUE_MEMORY; > - } > -#endif > - > - 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: %d\n", s->mode); > - > - 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; > - par.vpp.Out = out_frames_hwctx->surfaces[0].Info; > - > - /* Apparently VPP requires the frame rate to be set to some value, > otherwise > - * init will fail (probably for the framerate conversion filter). Since > we > - * are only doing scaling here, we just invent an arbitrary > - * value */ > - par.vpp.In.FrameRateExtN = 25; > - par.vpp.In.FrameRateExtD = 1; > - par.vpp.Out.FrameRateExtN = 25; > - par.vpp.Out.FrameRateExtD = 1; > - > - /* Print input memory mode */ > - ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0x0F, "VPP"); > - /* Print output memory mode */ > - ff_qsvvpp_print_iopattern(ctx, par.IOPattern & 0xF0, "VPP"); > - err = MFXVideoVPP_Init(s->session, &par); > - if (err < 0) > - return ff_qsvvpp_print_error(ctx, err, > - "Error opening the VPP for scaling"); > - else if (err > 0) { > - ff_qsvvpp_print_warning(ctx, err, > - "Warning in VPP initialization"); > - return AVERROR_UNKNOWN; > - } > - > - return 0; > -} > - > -static int init_scale_session(AVFilterContext *ctx, int in_width, int > in_height, > - int out_width, int out_height) > -{ > - int ret; > - > - qsvscale_uninit(ctx); > - > - ret = init_out_pool(ctx, out_width, out_height); > - if (ret < 0) > - return ret; > - > - ret = init_out_session(ctx); > - if (ret < 0) > - return ret; > - > - return 0; > + ff_qsvvpp_close(ctx); > } > > static int qsvscale_config_props(AVFilterLink *outlink) > { > AVFilterContext *ctx = outlink->src; > AVFilterLink *inlink = outlink->src->inputs[0]; > - QSVScaleContext *s = ctx->priv; > + QSVScaleContext *s = ctx->priv; > + QSVVPPParam param = { NULL }; > + mfxExtBuffer *ext_buf[1]; > int64_t w, h; > double var_values[VARS_NB], res; > char *expr; > int ret; > + enum AVPixelFormat in_format; > > var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; > var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; > @@ -518,7 +177,30 @@ static int qsvscale_config_props(AVFilterLink *outlink) > outlink->w = w; > outlink->h = h; > > - ret = init_scale_session(ctx, inlink->w, inlink->h, w, h); > + if (inlink->format == AV_PIX_FMT_QSV) { > + if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data) > + return AVERROR(EINVAL); > + else > + in_format = ((AVHWFramesContext*)inlink->hw_frames_ctx->data)- > >sw_format; > + } else > + in_format = inlink->format; > + > + if (s->format == AV_PIX_FMT_NONE) > + s->format = in_format; > + > + outlink->frame_rate = inlink->frame_rate; > + outlink->time_base = av_inv_q(inlink->frame_rate); > + param.out_sw_format = s->format; > + > + param.ext_buf = ext_buf; > + 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; > + param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&s->scale_conf; > + av_log(ctx, AV_LOG_VERBOSE, "Scaling mode: %d\n", s->mode); > + > + ret = ff_qsvvpp_init(ctx, ¶m); > if (ret < 0) > return ret; > > @@ -542,67 +224,12 @@ fail: > > static int qsvscale_filter_frame(AVFilterLink *link, AVFrame *in) > { > - AVFilterContext *ctx = link->dst; > - QSVScaleContext *s = ctx->priv; > - AVFilterLink *outlink = ctx->outputs[0]; > - > - mfxSyncPoint sync = NULL; > - mfxStatus err; > - > - AVFrame *out = NULL; > - int ret = 0; > - > - out = ff_get_video_buffer(outlink, outlink->w, outlink->h); > - if (!out) { > - ret = AVERROR(ENOMEM); > - goto fail; > - } > + int ret = 0; > + AVFilterContext *ctx = link->dst; > + QSVVPPContext *qsv = ctx->priv; > > - do { > - err = MFXVideoVPP_RunFrameVPPAsync(s->session, > - (mfxFrameSurface1*)in->data[3], > - (mfxFrameSurface1*)out->data[3], > - NULL, &sync); > - if (err == MFX_WRN_DEVICE_BUSY) > - av_usleep(1); > - } while (err == MFX_WRN_DEVICE_BUSY); > - > - if (err < 0) { > - ret = ff_qsvvpp_print_error(ctx, err, "Error during scaling"); > - goto fail; > - } > - > - if (!sync) { > - av_log(ctx, AV_LOG_ERROR, "No sync during scaling\n"); > - ret = AVERROR_UNKNOWN; > - goto fail; > - } > - > - do { > - err = MFXVideoCORE_SyncOperation(s->session, sync, 1000); > - } while (err == MFX_WRN_IN_EXECUTION); > - if (err < 0) { > - ret = ff_qsvvpp_print_error(ctx, err, "Error synchronizing the > operation"); > - goto fail; > - } > - > - ret = av_frame_copy_props(out, in); > - if (ret < 0) > - goto fail; > - > - out->width = outlink->w; > - out->height = outlink->h; > - > - av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den, > - (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w, > - (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h, > - INT_MAX); > - > - av_frame_free(&in); > - return ff_filter_frame(outlink, out); > -fail: > + ret = ff_qsvvpp_filter_frame(qsv, link, in); > av_frame_free(&in); > - av_frame_free(&out); > return ret; > } > Will apply, -Haihao _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".