From patchwork Fri Mar 15 16:36:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 12317 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 A6630448B4F for ; Fri, 15 Mar 2019 10:36:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8EBE268A6E7; Fri, 15 Mar 2019 10:36:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 327FD68A551 for ; Fri, 15 Mar 2019 10:36:12 +0200 (EET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Mar 2019 01:36:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,481,1544515200"; d="scan'208";a="155280000" Received: from media_lj_kbl.sh.intel.com ([10.239.13.124]) by fmsmga001.fm.intel.com with ESMTP; 15 Mar 2019 01:36:09 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Sat, 16 Mar 2019 00:36:00 +0800 Message-Id: <20190315163600.29075-1-linjie.fu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 2/2] lavf/qsvvpp: allocate continuous memory across Y and UV 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" Mediasdk calls CMRT to copy from video to system memory and requires memory to be continuously allocated across Y and UV. Add a new path to allocate continuous memory when using system out Fix the segmentation fault when enabling QSV mirror through video memory -> system memory. [#1223 in MediaSDK] Signed-off-by: Linjie Fu --- libavfilter/qsvvpp.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index 06efdf5089..0edd10044a 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -27,6 +27,7 @@ #include "libavutil/hwcontext_qsv.h" #include "libavutil/time.h" #include "libavutil/pixdesc.h" +#include "libavutil/imgutils.h" #include "internal.h" #include "qsvvpp.h" @@ -51,6 +52,7 @@ struct QSVVPPContext { enum AVPixelFormat out_sw_format; /* Real output format */ mfxVideoParam vpp_param; mfxFrameInfo *frame_infos; /* frame info for each input */ + AVBufferPool *pool; /* members related to the input/output surface */ int in_mem_mode; @@ -375,10 +377,26 @@ static QSVFrame *query_frame(QSVVPPContext *s, AVFilterLink *outlink) out_frame->surface = (mfxFrameSurface1 *)out_frame->frame->data[3]; } else { /* Get a frame with aligned dimensions. - * Libmfx need system memory being 128x64 aligned */ - out_frame->frame = ff_get_video_buffer(outlink, - FFALIGN(outlink->w, 128), - FFALIGN(outlink->h, 64)); + * Libmfx need system memory being 128x64 aligned + * and continuously allocated across Y and UV */ + out_frame->frame = av_frame_alloc(); + if (!out_frame->frame) { + return NULL; + } + + out_frame->frame->linesize[0] = FFALIGN(outlink->w, 128); + out_frame->frame->linesize[1] = out_frame->frame->linesize[0]; + out_frame->frame->buf[0] = av_buffer_pool_get(s->pool); + out_frame->frame->format = outlink->format; + + if (!out_frame->frame->buf[0]) + return NULL; + + out_frame->frame->data[0] = out_frame->frame->buf[0]->data; + out_frame->frame->data[1] = out_frame->frame->data[0] + + out_frame->frame->linesize[0] * + FFALIGN(outlink->h, 64); + if (!out_frame->frame) return NULL; @@ -483,8 +501,13 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) av_buffer_unref(&outlink->hw_frames_ctx); outlink->hw_frames_ctx = out_frames_ref; - } else + } else { s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY; + s->pool = av_buffer_pool_init(av_image_get_buffer_size(outlink->format, + FFALIGN(outlink->w, 128), + FFALIGN(outlink->h, 64), 1), + av_buffer_allocz); + } /* extract the properties of the "master" session given to us */ ret = MFXQueryIMPL(device_hwctx->session, &impl); @@ -674,6 +697,7 @@ int ff_qsvvpp_free(QSVVPPContext **vpp) /* release all the resources */ clear_frame_list(&s->in_frame_list); clear_frame_list(&s->out_frame_list); + av_buffer_pool_uninit(&s->pool); av_freep(&s->surface_ptrs_in); av_freep(&s->surface_ptrs_out); av_freep(&s->ext_buffers);