From patchwork Tue Jul 18 13:50:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 4354 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp1605512vsb; Tue, 18 Jul 2017 06:58:49 -0700 (PDT) X-Received: by 10.28.147.137 with SMTP id v131mr2288620wmd.98.1500386329532; Tue, 18 Jul 2017 06:58:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500386329; cv=none; d=google.com; s=arc-20160816; b=V03Mbz8rMJw5CJz7+WpaDo7RFZ0qLNW02o3IglVnAmSWnBca06VBTTrSblXlgozeXY wMXSBaSNtNCf3+nCsbLBqIqD8M9e8WXTKbwpxUT6GF6//f3dQSyUPx4WZv8R3Qi46rB1 ag+jDpYl/cg0HruICrwVtNnOX28Hxkg1Jxi0L/mxA3L8MPG6rQnUfKmncyQN9IjEngvL B/05Y1pfMsSvETeUa2pFr0MaaDFaBIsbZzE3tYbDd6LpBalAsH2xof2luYTupXRyeKxu xU0xeG1vUjrtnlQZPHgC8x+njXTnFmHE2w3Y+xy3xdnORXCpc4ejOB044+K78KNlrZwJ 7/rw== 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: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:dkim-signature:delivered-to:arc-authentication-results; bh=XgkZQDZMMQU9DQEygBC0sQmvAG2FkTZ77YcoP9oZ2yg=; b=piyYpD0Vy/x+Bmj3gCImNuYuPpwcI1/SMDQAhHWyeXwhGn4cqj4SMkTVQ5P8/Kt2K3 i48zsg6jIjQJl3bTEe31JDZ1zSBVapKocgs4YW+rykbrGpLN6pAhyK7H38KhQsJkS6B9 TnCOOcLY6GgdYSBePBuRF7fr5pj1yi3InsrT2Id9f/5bq9fVHPFr1h0Av/aSB6UrUujU 8OxueX0j7kKwRNdz+9hQkNuL1xbS9SCplpvTHk3V3OUSDe8jJGMhxhWMsjf++mPnVbZQ C78zZ8OHADrxlJkPxYQQoFwQhVF8+39SR4a3DJYP3Cj9FhTFV9XYc4qoxN9ftKGX8oGh Gahg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=FYImZNcW; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d80si2571449wmd.182.2017.07.18.06.58.49; Tue, 18 Jul 2017 06:58:49 -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=@gmail.com header.b=FYImZNcW; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D2B6A6891DD; Tue, 18 Jul 2017 16:58:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4850C6805FB for ; Tue, 18 Jul 2017 16:58:33 +0300 (EEST) Received: by mail-qt0-f196.google.com with SMTP id 19so2421864qty.1 for ; Tue, 18 Jul 2017 06:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=gjpn4oXmF2TCCacKT5tTobTsD8YTuKAdaqnevM/C8Wg=; b=FYImZNcW3CrnzZVwzM35402HhI14Rw+FjGADYll74dzeWvli3vFHa00kcI/DEYRheS +RWn6s5fr71YaN+zhiaFZFNt1tjQP1rXPSmu6pKZAGsnIY2RfC/uuSjFy4ru+u4raTHy VQOeEfglgs0auh7yZj5JQf1eVofycDl3KabAal8xGV2do6XxiFjz12+kRF68uwGUlKab eoXe6anjXOP6ZaGBBwlsk2JV5HpUyvJjvID3AwL+1P7eyPuQiyvZuHTtotaECSWMzVJ5 /Fuv9ckaQ0v/5YKgAafMcvnY47o0JywA093DOOXqrfk3Wvem8aTeXb8YQos+ceV19Mb2 G3Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=gjpn4oXmF2TCCacKT5tTobTsD8YTuKAdaqnevM/C8Wg=; b=e+fZFlhEo0G3MmqGPvHIkTCiY9Iwbq+kV3I85Ox/YGOpq29+ZGdGcH/BRBAqSpTbLu ZNX35d8ETvdL7a0MWpNXBdGeA6r0tzEs4hli4DGF5Al/q4jETcXva7s2Xt4Q5SLXDWeG rOXSk4oTWBBHH+aYP1ReOgeh9k7NEdxJaYmFJl83wxLvgqhszfKVMGdnbAY6aTp9nDtR NdOtV2d+aTx9uR2UVD1wDr4U67qTgtYods35K6h9L7tb28k3CR+euIdTU8mn+YW59+cc N+J6czXT96juqYO7VW+suPDxVMEEnxPcRQrQ/dlcoztbPObjTmXtzd1n/gBmZBhMWOhR X9Mg== X-Gm-Message-State: AIVw111RMNW1AturVqIk4R+VUzdfneUNQOvG122WCD7tQ+AI9CX2GnRI Ag+4awhKwTRg7HAf X-Received: by 10.200.3.46 with SMTP id q46mr2240242qtg.3.1500385825553; Tue, 18 Jul 2017 06:50:25 -0700 (PDT) Received: from vimacbookpro.vimeo.iac.corp (93-40-167-184.ip39.fastwebnet.it. [93.40.167.184]) by smtp.gmail.com with ESMTPSA id j39sm1767590qtj.19.2017.07.18.06.50.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 18 Jul 2017 06:50:24 -0700 (PDT) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Jul 2017 15:50:13 +0200 Message-Id: <20170718135015.52683-3-vittorio.giovara@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170718135015.52683-1-vittorio.giovara@gmail.com> References: <20170718135015.52683-1-vittorio.giovara@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/5] zscale: Factor out graph building 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavfilter/vf_zscale.c | 52 +++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c index a128db6267..466689dbc5 100644 --- a/libavfilter/vf_zscale.c +++ b/libavfilter/vf_zscale.c @@ -438,6 +438,34 @@ static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFm format->chroma_location = location == -1 ? convert_chroma_location(frame->chroma_location) : location; } +static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *params, + zimg_image_format *src_format, zimg_image_format *dst_format, + void **tmp, size_t *tmp_size) +{ + int ret; + size_t size; + + zimg_filter_graph_free(*graph); + *graph = zimg_filter_graph_build(src_format, dst_format, params); + if (!*graph) + return print_zimg_error(NULL); + + ret = zimg_filter_graph_get_tmp_size(*graph, &size); + if (ret) + return print_zimg_error(NULL); + + if (size > *tmp_size) { + av_freep(tmp); + *tmp = av_malloc(size); + if (!*tmp) + return AVERROR(ENOMEM); + + *tmp_size = size; + } + + return 0; +} + static int filter_frame(AVFilterLink *link, AVFrame *in) { ZScaleContext *s = link->dst->priv; @@ -447,7 +475,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) zimg_image_buffer_const src_buf = { ZIMG_API_VERSION }; zimg_image_buffer dst_buf = { ZIMG_API_VERSION }; char buf[32]; - size_t tmp_size; int ret = 0, plane; AVFrame *out; @@ -520,27 +547,10 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) if (s->chromal != -1) out->chroma_location = (int)s->dst_format.chroma_location - 1; - zimg_filter_graph_free(s->graph); - s->graph = zimg_filter_graph_build(&s->src_format, &s->dst_format, &s->params); - if (!s->graph) { - ret = print_zimg_error(link->dst); - goto fail; - } - - if ((ret = zimg_filter_graph_get_tmp_size(s->graph, &tmp_size))) { - ret = print_zimg_error(link->dst); + ret = graph_build(&s->graph, &s->params, &s->src_format, &s->dst_format, + &s->tmp, &s->tmp_size); + if (ret < 0) goto fail; - } - - if (tmp_size > s->tmp_size) { - av_freep(&s->tmp); - s->tmp = av_malloc(tmp_size); - if (!s->tmp) { - ret = AVERROR(ENOMEM); - goto fail; - } - s->tmp_size = tmp_size; - } s->in_colorspace = in->colorspace; s->in_trc = in->color_trc;