From patchwork Wed Apr 6 10:10:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Wenbin" X-Patchwork-Id: 35226 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp795114pzb; Wed, 6 Apr 2022 03:10:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhN4sgWT9PlaheDsCqem3MIuMhpji/LMEryvk63746fyrxFqKldFqlUCxsLZWdLK0nbIGu X-Received: by 2002:a05:6402:1616:b0:41c:d241:cb5f with SMTP id f22-20020a056402161600b0041cd241cb5fmr7919323edv.215.1649239847313; Wed, 06 Apr 2022 03:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649239847; cv=none; d=google.com; s=arc-20160816; b=fBGFuERo/KiPRk73W0Lxk9thnorOGTP/yljnApn1BkCNGvJfJfAt0Lo8sNhHyGBPeL 4ZmS2nTaSjEOHKbWH+vCEyvbehBgxeypV2iYeIafUjbUheHazSVFDJnYSOm7mROfGVES IR3tM7L2dutK6STHJj9xDDxTqWn6qsaCSO1je9dQnWvyIOIwH3Bypm1HcjcAox1Zp/42 eqfKu0YRIO4Yp2u6LoWmTpFA5VFeFIcIXiXs9ymciDhedH7u3BnYHtVbS16c9dHHLakb GYqimFPr/43d3cO/pBuK/7UWZtYCcUfIf5GRYCO5GqQQfzQ9/UWkjsj1g34rxirz6NlQ FYFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=vsZuQOmOoE/4tjMayUIzPa4H3wrIUEX+mkE+6XDQoI0=; b=wAj0Hs8XzGC4HHe7xwz1xPFDpM+XpmrSLcolTIs9cweUjkVugPmvRZE/j/oI7idi2p sbYJdfsV5SMV5E/MSS7ECKML3IRNyZZQH1iFoNvRmDa0lejOfE4hZrs5PUz6/gNbFL6o UgiSwTUDnyUwSBR/GeYDQc6dAi/2lFjkHsDCC3cIocJH6U1N/fzPGzz+ZUuT/Mn9Vzma RlIQlICOHkxgjFDlcs7Z87sNeIj25+rZr6SHKeOK4qPopukYFxkWHU2B7Yw/pZocLlcg k2S8elArap6zpmMZJWc3v8c9LLlXmnGX5I+NKK/gQNrRjxRGIuwGViZT9VZkYS9TEZak f9Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=BeKvLT37; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q5-20020a1709066b0500b006e810a39e29si2573804ejr.783.2022.04.06.03.10.46; Wed, 06 Apr 2022 03:10:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=BeKvLT37; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1645368B250; Wed, 6 Apr 2022 13:10:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7174568AF91 for ; Wed, 6 Apr 2022 13:10:35 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649239841; x=1680775841; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=z+ncxklR0+ioTD5apP9e9f16MaEQKNtekhwgdDfWvFM=; b=BeKvLT377Xptf/5kBl5G1nXmfGRI30NiBixiftK3jDexlIgp9WB69TCr MMK1Th4tLZg/OlpchXKYuF92QgWkOhB6rF2XUnlhs80RkUjgeFSNltf45 KOIrjWwUFfhXzgMrUDKp7a2cR+6JsO64pBdskumKLS7lwPmq4rx9wvlVu knvRxYosjdHObY8COyUvLvPoI5QVrVrywfAEUIh1X36Pens4seZCf0lxj 4U7qtLEhn5nVFnLAmxZ7eb5tRS+R9IXeEWsnJoh1/8f8NrOW2CdslwuKa l0BoAksEo3PqWyRCGRQhQNIdDEjn3a5FRcOtClgGLxqaO4cCQ3lJS7MRA A==; X-IronPort-AV: E=McAfee;i="6200,9189,10308"; a="260702173" X-IronPort-AV: E=Sophos;i="5.90,239,1643702400"; d="scan'208";a="260702173" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2022 03:10:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,239,1643702400"; d="scan'208";a="588311072" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.4]) by orsmga001.jf.intel.com with ESMTP; 06 Apr 2022 03:10:31 -0700 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Apr 2022 18:10:08 +0800 Message-Id: <20220406101008.1128823-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] libavutil/hwcontext_qsv: Align width and heigh when download qsv frame 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UWPQZ7s0LQoD The width and height for qsv frame to download need to be aligned with 16. Add the alignment operation. Now the following command works: ffmpeg -hwaccel qsv -f rawvideo -s 1920x1080 -pix_fmt yuv420p -i \ input.yuv -vf "hwupload=extra_hw_frames=16,format=qsv,hwdownload, \ format=nv12" -f null - Signed-off-by: Wenbin Chen --- libavutil/hwcontext_qsv.c | 47 ++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 95f8071abe..66c0e38955 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -91,7 +91,8 @@ typedef struct QSVFramesContext { mfxExtOpaqueSurfaceAlloc opaque_alloc; mfxExtBuffer *ext_buffers[1]; - AVFrame realigned_tmp_frame; + AVFrame realigned_upload_frame; + AVFrame realigned_download_frame; } QSVFramesContext; static const struct { @@ -303,7 +304,8 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx) av_freep(&s->surface_ptrs); av_freep(&s->surfaces_internal); av_freep(&s->handle_pairs_internal); - av_frame_unref(&s->realigned_tmp_frame); + av_frame_unref(&s->realigned_upload_frame); + av_frame_unref(&s->realigned_download_frame); av_buffer_unref(&s->child_frames_ref); } @@ -1058,21 +1060,46 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, mfxSyncPoint sync = NULL; mfxStatus err; int ret = 0; + /* download to temp frame if the output is not padded as libmfx requires */ + AVFrame *tmp_frame = &s->realigned_download_frame; + AVFrame *dst_frame; + int realigned = 0; ret = qsv_internal_session_check_init(ctx, 0); if (ret < 0) return ret; + /* According to MSDK spec for mfxframeinfo, "Width must be a multiple of 16. + * Height must be a multiple of 16 for progressive frame sequence and a + * multiple of 32 otherwise.", so allign all frames to 16 before downloading. */ + if (dst->height & 15 || dst->linesize[0] & 15) { + realigned = 1; + if (tmp_frame->format != dst->format || + tmp_frame->width != FFALIGN(dst->linesize[0], 16) || + tmp_frame->height != FFALIGN(dst->height, 16)) { + av_frame_unref(tmp_frame); + + tmp_frame->format = dst->format; + tmp_frame->width = FFALIGN(dst->linesize[0], 16); + tmp_frame->height = FFALIGN(dst->height, 16); + ret = av_frame_get_buffer(tmp_frame, 0); + if (ret < 0) + return ret; + } + } + + dst_frame = realigned ? tmp_frame : dst; + if (!s->session_download) { if (s->child_frames_ref) - return qsv_transfer_data_child(ctx, dst, src); + return qsv_transfer_data_child(ctx, dst_frame, src); av_log(ctx, AV_LOG_ERROR, "Surface download not possible\n"); return AVERROR(ENOSYS); } out.Info = in->Info; - map_frame_to_surface(dst, &out); + map_frame_to_surface(dst_frame, &out); do { err = MFXVideoVPP_RunFrameVPPAsync(s->session_download, in, &out, NULL, &sync); @@ -1093,6 +1120,16 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, return AVERROR_UNKNOWN; } + if (realigned) { + tmp_frame->width = dst->width; + tmp_frame->height = dst->height; + ret = av_frame_copy(dst, tmp_frame); + tmp_frame->width = FFALIGN(dst->linesize[0], 16); + tmp_frame->height = FFALIGN(dst->height, 16); + if (ret < 0) + return ret; + } + return 0; } @@ -1108,7 +1145,7 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, mfxStatus err; int ret = 0; /* make a copy if the input is not padded as libmfx requires */ - AVFrame *tmp_frame = &s->realigned_tmp_frame; + AVFrame *tmp_frame = &s->realigned_upload_frame; const AVFrame *src_frame; int realigned = 0;