From patchwork Sat Feb 2 02:33:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruiling Song X-Patchwork-Id: 11952 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 2E927445D3E for ; Sat, 2 Feb 2019 04:36:52 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0D34468A7B1; Sat, 2 Feb 2019 04:36:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 67E2668A601 for ; Sat, 2 Feb 2019 04:36:45 +0200 (EET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Feb 2019 18:36:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,550,1539673200"; d="scan'208";a="123330067" Received: from ruiling-skl2.sh.intel.com ([10.239.158.154]) by orsmga003.jf.intel.com with ESMTP; 01 Feb 2019 18:36:42 -0800 From: Ruiling Song To: ffmpeg-devel@ffmpeg.org Date: Sat, 2 Feb 2019 10:33:54 +0800 Message-Id: <1549074834-17138-1-git-send-email-ruiling.song@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH] lavfi/vf_hwmap: move some code into seperate function 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: Ruiling Song MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This is just code fine. No functional change. Signed-off-by: Ruiling Song --- libavfilter/vf_hwmap.c | 83 ++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/libavfilter/vf_hwmap.c b/libavfilter/vf_hwmap.c index 290559a..14276ce 100644 --- a/libavfilter/vf_hwmap.c +++ b/libavfilter/vf_hwmap.c @@ -50,6 +50,37 @@ static int hwmap_query_formats(AVFilterContext *avctx) return 0; } +static int create_hwframe_context(AVFilterContext *avctx, AVBufferRef *device, + int format, int sw_format, + int width, int height) +{ + HWMapContext *ctx = avctx->priv; + int err; + AVHWFramesContext *frames; + + ctx->hwframes_ref = av_hwframe_ctx_alloc(device); + if (!ctx->hwframes_ref) { + return AVERROR(ENOMEM); + } + frames = (AVHWFramesContext*)ctx->hwframes_ref->data; + + frames->format = format; + frames->sw_format = sw_format; + frames->width = width; + frames->height = height; + + if (avctx->extra_hw_frames >= 0) + frames->initial_pool_size = 2 + avctx->extra_hw_frames; + + err = av_hwframe_ctx_init(ctx->hwframes_ref); + if (err < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed to initialise " + "hardware frames context: %d.\n", err); + return err; + } + return 0; +} + static int hwmap_config_output(AVFilterLink *outlink) { AVFilterContext *avctx = outlink->src; @@ -130,29 +161,12 @@ static int hwmap_config_output(AVFilterLink *outlink) // overwrite the input hwframe context with a derived context // mapped from that back to the source type. AVBufferRef *source; - AVHWFramesContext *frames; - - ctx->hwframes_ref = av_hwframe_ctx_alloc(device); - if (!ctx->hwframes_ref) { - err = AVERROR(ENOMEM); - goto fail; - } - frames = (AVHWFramesContext*)ctx->hwframes_ref->data; - - frames->format = outlink->format; - frames->sw_format = hwfc->sw_format; - frames->width = hwfc->width; - frames->height = hwfc->height; - - if (avctx->extra_hw_frames >= 0) - frames->initial_pool_size = 2 + avctx->extra_hw_frames; - err = av_hwframe_ctx_init(ctx->hwframes_ref); - if (err < 0) { - av_log(avctx, AV_LOG_ERROR, "Failed to initialise " - "target frames context: %d.\n", err); - goto fail; - } + err = create_hwframe_context(avctx, device, outlink->format, + hwfc->sw_format, hwfc->width, + hwfc->height); + if (err < 0) + goto fail; err = av_hwframe_ctx_create_derived(&source, inlink->format, @@ -212,29 +226,10 @@ static int hwmap_config_output(AVFilterLink *outlink) } ctx->reverse = 1; - - ctx->hwframes_ref = av_hwframe_ctx_alloc(device); - if (!ctx->hwframes_ref) { - err = AVERROR(ENOMEM); - goto fail; - } - hwfc = (AVHWFramesContext*)ctx->hwframes_ref->data; - - hwfc->format = outlink->format; - hwfc->sw_format = inlink->format; - hwfc->width = inlink->w; - hwfc->height = inlink->h; - - if (avctx->extra_hw_frames >= 0) - hwfc->initial_pool_size = 2 + avctx->extra_hw_frames; - - err = av_hwframe_ctx_init(ctx->hwframes_ref); - if (err < 0) { - av_log(avctx, AV_LOG_ERROR, "Failed to create frame " - "context for reverse mapping: %d.\n", err); + err = create_hwframe_context(avctx, device, outlink->format, + inlink->format, inlink->w, inlink->h); + if (err < 0) goto fail; - } - } else { av_log(avctx, AV_LOG_ERROR, "Mapping requires a hardware " "context (a device, or frames on input).\n");