From patchwork Wed May 29 17:00:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 13324 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 4F3E4444B1E for ; Wed, 29 May 2019 12:01:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1B8F068A449; Wed, 29 May 2019 12:01:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 958CB680278 for ; Wed, 29 May 2019 12:01:04 +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 fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 May 2019 02:01:02 -0700 X-ExtLoop1: 1 Received: from media_lj_kbl.sh.intel.com ([10.239.13.115]) by fmsmga007.fm.intel.com with ESMTP; 29 May 2019 02:01:02 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 May 2019 01:00:53 +0800 Message-Id: <20190529170053.15968-1-linjie.fu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH, v2 1/2] lavf/qsvvpp: allocate continuous memory 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. Use av_image_fill_pointers to arrange data according to pixfmt. Signed-off-by: Linjie Fu --- [v2]: use av_image_fill_pointers libavfilter/qsvvpp.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index 06efdf5089..6eeed7e632 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,24 @@ 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; + + av_image_fill_pointers(out_frame->frame->data, out_frame->frame->format, + FFALIGN(outlink->h, 64), out_frame->frame->buf[0]->data, + out_frame->frame->linesize); if (!out_frame->frame) return NULL; @@ -483,8 +499,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 +695,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);