From patchwork Sun Sep 30 09:15:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhong Li X-Patchwork-Id: 10518 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:ab0:73d2:0:0:0:0:0 with SMTP id m18csp430049uaq; Sun, 30 Sep 2018 02:14:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV61T3EyloPvDJBdYwwjgUP3uqojDhOTdgwDB9Tn7mW4097gA8e0VR3ikVTVJjpWEAVwjjzKP X-Received: by 2002:a1c:f53:: with SMTP id 80-v6mr5746406wmp.58.1538298856460; Sun, 30 Sep 2018 02:14:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538298856; cv=none; d=google.com; s=arc-20160816; b=Jnlyk2uo0RJY3Xtq5MzNCugoh/KljWiDqsW2mmT8hh7ilAcLjYDMbPCtCx0Ajce75l wKWSjmbJg52f/gHru3Y/eUB8DNPDLt1XDECRKIiqKalZby6kOHwruz4Bdg4YKm5e5UTa 8uN6pOjJV3P4o3X3dXnvAWd4FoHokInXHR+ElLyi22lORrCsol5zcFnFSQIIyDx3lehi ghcwaMxs91CnDXWTysNWJ4czIizg4pR0ZfW0cSV+lIIRW9obguYm4xGfdo+5TC/A7ngN jHS+ZmxV/KjCdv+/FQGb/p5Il2KXA7F1pKcVBBVYDITvjrPEZX6t1CyGMQ9Jkm6ngQUL kXng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=ZULAFGXQqb+yoPWb6VfjqyKcolf1JjbqUQgIpPyh4/g=; b=JSKLLzPcDm/aP9WlLKBmeQ/mHrjOxwR2UAni8QhEPDDJ4roxcgEgb+iT4JzFavVLWO qqbVVQcqdKBfWPBH/ZdjX9yov5RH+sRnKfLf/ObfRMckeWR0eSk3zuadOWHF8gb2gCEc OulMYVGU3aMP8n3cswDzzYVRdgoQFhRdlzPvKlRNXUwU/mioJdjf0y50YibtvQw9f3rr ZV8gzA4CosuEMblVJ9m388aJ4D/1GEpzef/3hjcp/HjZ4PNYj269gS1oQ7DU78q9uDRd 0uciwqDyKEsnoukwjMwfvmQc2bObOgo2fnFx3mAA/okasNgzBgXYzgJ3gZ8+pDwHCXoP xX7Q== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a81-v6si2171512wma.111.2018.09.30.02.14.16; Sun, 30 Sep 2018 02:14:16 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 738C268A19A; Sun, 30 Sep 2018 12:13:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 00CFF68A0F5 for ; Sun, 30 Sep 2018 12:13:45 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Sep 2018 02:13:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,323,1534834800"; d="scan'208";a="94727308" Received: from media_ffmpeg_skl_e3.sh.intel.com ([10.239.156.42]) by fmsmga001.fm.intel.com with ESMTP; 30 Sep 2018 02:13:55 -0700 From: Zhong Li To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Sep 2018 17:15:11 +0800 Message-Id: <1538298911-27149-2-git-send-email-zhong.li@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1538298911-27149-1-git-send-email-zhong.li@intel.com> References: <1538298911-27149-1-git-send-email-zhong.li@intel.com> Subject: [FFmpeg-devel] [PATCH 2/2] lavu/qsv: make a copy as libmfx alignment requirement for uploading 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" Libmfx requires 16 bytes aligned input/output for uploading. Currently only output is 16 byte aligned and assigning same width/height to input with smaller buffer size actually, thus definitely will cause segment fault. Can reproduce with any 1080p nv12 rawvideo input: ffmpeg -init_hw_device qsv=qsv:hw -hwaccel qsv -filter_hw_device qsv -f rawvideo -pix_fmt nv12 -s:v 1920x1080 -i 1080p_nv12.yuv -vf 'format=nv12,hwupload=extra_hw_frames=16,hwdownload,format=nv12' -an -y out_nv12.yuv It can fix #7418 Signed-off-by: Zhong Li --- libavutil/hwcontext_qsv.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 33e121b..3039cfa 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -862,6 +862,10 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, mfxSyncPoint sync = NULL; mfxStatus err; int ret = 0; + /* make a copy if the input is not padded as libmfx requires */ + AVFrame tmp_frame, *src_frame; + int realigned = 0; + while (!s->session_upload_init && !s->session_upload && !ret) { #if HAVE_PTHREADS @@ -887,16 +891,36 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, if (ret < 0) return ret; + + if (src->height & 16 || src->linesize[0] & 16) { + realigned = 1; + memset(&tmp_frame, 0, sizeof(tmp_frame)); + tmp_frame.format = src->format; + tmp_frame.width = FFALIGN(src->width, 16); + tmp_frame.height = FFALIGN(src->height, 16); + ret = av_frame_get_buffer(&tmp_frame, 32); + if (ret < 0) + return ret; + + ret = av_frame_copy(&tmp_frame, src); + if (ret < 0) { + av_frame_unref(&tmp_frame); + return ret; + } + } + + src_frame = realigned ? &tmp_frame : src; + if (!s->session_upload) { if (s->child_frames_ref) - return qsv_transfer_data_child(ctx, dst, src); + return qsv_transfer_data_child(ctx, dst, src_frame); av_log(ctx, AV_LOG_ERROR, "Surface upload not possible\n"); return AVERROR(ENOSYS); } in.Info = out->Info; - map_frame_to_surface(src, &in); + map_frame_to_surface(src_frame, &in); do { err = MFXVideoVPP_RunFrameVPPAsync(s->session_upload, &in, out, NULL, &sync); @@ -917,6 +941,9 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, return AVERROR_UNKNOWN; } + if (realigned) + av_frame_unref(&tmp_frame); + return 0; }