From patchwork Wed Sep 25 17:05:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 15287 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 A544C448531 for ; Wed, 25 Sep 2019 20:05:21 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 842F7689E00; Wed, 25 Sep 2019 20:05:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D7E7F688357 for ; Wed, 25 Sep 2019 20:05:14 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id b24so5765083wmj.5 for ; Wed, 25 Sep 2019 10:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=73egIPp1vs13kpoBbdldQ4QloC8RJuE+zFwld2gTM0g=; b=r8XKn0f1o3n0Mq00g3bTRDs7SA7iSwacz0Cu5fSlkguUCPjFUimR8H9PXu66vM030g qlagd7e9+pu1tNEw4avUWpdvdMCIu1d2/qRqwTULHfHERmED0v7hkgfGaEdyqmIziM2V 2Q9Z5MLbaHOycQdOUrYLqKAwbqg8UF7INzMd/0Seg76DZFBizjpjVWQ4JCbPiXBXfSCT kIor6w8gJ/yoYgDSWZ6eRAY2pMfGAbuT1VMzCmPD8GnebsP6WzT827FPfh/ASdtIMfwk hxKLXI0cZ1SbGb50oTVRYT/DsELSsqco2mlcoEi4vDVtPg0apxau3r/mDn440PRubP+S /+Gw== 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; bh=73egIPp1vs13kpoBbdldQ4QloC8RJuE+zFwld2gTM0g=; b=kxlDOZt8KxrJEH8YsgBDO9iqfqHYomCYbQV9sX6T4AG3KTUo9PkDsyxY3c+JrurIBo TPknchJIZyN84qLwVkHOh3aBMwpkiOaSPvF2as8ZNSjjHQyPaAlnkEj8dd16FcTRkpOs waUXXe9bbq1+6b/OUUsp0oPfVqTHTOk4ZEYZ9m637muJlPZ9jBQElYzN2Vhbc4fSm5wG 8V1YYmRQhp/RG+A9mk82cBvD6UvcwV98ZEl6RpRGDsEDfuW1KKiA6T0cAoP6G9KADogG PpjdQtW5NkXt5f9tLVidHY9hYOZiwAk7LwpvVU1GXrKLVeX2Mc/pSvc47UhOkD7IeFFP 3Rvg== X-Gm-Message-State: APjAAAXBoUJVrgvASLmY2yoGxswRzo3Y+H1gEHxupQhHFQh4SE/ibTpg aqabA3+0LcQHAPgoM0foTZVJresR X-Google-Smtp-Source: APXvYqyvPNDo0HDUIa5O+WuwBqY9FMAo1Xcj6Kk1Thw4pEfarAlYhZhDAh9Ffza48VNDUeqdG1HvOw== X-Received: by 2002:a7b:cd99:: with SMTP id y25mr8786990wmj.152.1569431114007; Wed, 25 Sep 2019 10:05:14 -0700 (PDT) Received: from localhost.localdomain ([109.227.33.147]) by smtp.gmail.com with ESMTPSA id l13sm4998668wmj.25.2019.09.25.10.05.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2019 10:05:12 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Wed, 25 Sep 2019 19:05:03 +0200 Message-Id: <20190925170504.18987-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_stack: simplify main processing path 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" Signed-off-by: Paul B Mahol --- libavfilter/vf_stack.c | 93 ++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/libavfilter/vf_stack.c b/libavfilter/vf_stack.c index 4d254e0013..3b05807a95 100644 --- a/libavfilter/vf_stack.c +++ b/libavfilter/vf_stack.c @@ -82,6 +82,10 @@ static av_cold int init(AVFilterContext *ctx) if (!s->frames) return AVERROR(ENOMEM); + s->items = av_calloc(s->nb_inputs, sizeof(*s->items)); + if (!s->items) + return AVERROR(ENOMEM); + if (!strcmp(ctx->filter->name, "xstack")) { if (!s->layout) { if (s->nb_inputs == 2) { @@ -93,10 +97,6 @@ static av_cold int init(AVFilterContext *ctx) return AVERROR(EINVAL); } } - - s->items = av_calloc(s->nb_inputs, sizeof(*s->items)); - if (!s->items) - return AVERROR(ENOMEM); } for (i = 0; i < s->nb_inputs; i++) { @@ -123,7 +123,7 @@ static int process_frame(FFFrameSync *fs) StackContext *s = fs->opaque; AVFrame **in = s->frames; AVFrame *out; - int i, p, ret, offset[4] = { 0 }; + int i, p, ret; for (i = 0; i < s->nb_inputs; i++) { if ((ret = ff_framesync_get_frame(&s->fs, i, &in[i], 0)) < 0) @@ -137,44 +137,14 @@ static int process_frame(FFFrameSync *fs) out->sample_aspect_ratio = outlink->sample_aspect_ratio; for (i = 0; i < s->nb_inputs; i++) { - AVFilterLink *inlink = ctx->inputs[i]; - int linesize[4]; - int height[4]; - - if (s->is_horizontal || s->is_vertical) { - if ((ret = av_image_fill_linesizes(linesize, inlink->format, inlink->w)) < 0) { - av_frame_free(&out); - return ret; - } - - height[1] = height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); - height[0] = height[3] = inlink->h; - } + StackItem *item = &s->items[i]; for (p = 0; p < s->nb_planes; p++) { - if (s->is_vertical) { - av_image_copy_plane(out->data[p] + offset[p] * out->linesize[p], - out->linesize[p], - in[i]->data[p], - in[i]->linesize[p], - linesize[p], height[p]); - offset[p] += height[p]; - } else if (s->is_horizontal) { - av_image_copy_plane(out->data[p] + offset[p], - out->linesize[p], - in[i]->data[p], - in[i]->linesize[p], - linesize[p], height[p]); - offset[p] += linesize[p]; - } else { - StackItem *item = &s->items[i]; - - av_image_copy_plane(out->data[p] + out->linesize[p] * item->y[p] + item->x[p], - out->linesize[p], - in[i]->data[p], - in[i]->linesize[p], - item->linesize[p], item->height[p]); - } + av_image_copy_plane(out->data[p] + out->linesize[p] * item->y[p] + item->x[p], + out->linesize[p], + in[i]->data[p], + in[i]->linesize[p], + item->linesize[p], item->height[p]); } } @@ -197,20 +167,53 @@ static int config_output(AVFilterLink *outlink) return AVERROR_BUG; if (s->is_vertical) { - for (i = 1; i < s->nb_inputs; i++) { + for (i = 0; i < s->nb_inputs; i++) { + AVFilterLink *inlink = ctx->inputs[i]; + StackItem *item = &s->items[i]; + if (ctx->inputs[i]->w != width) { av_log(ctx, AV_LOG_ERROR, "Input %d width %d does not match input %d width %d.\n", i, ctx->inputs[i]->w, 0, width); return AVERROR(EINVAL); } - height += ctx->inputs[i]->h; + + if ((ret = av_image_fill_linesizes(item->linesize, inlink->format, inlink->w)) < 0) { + return ret; + } + + item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); + item->height[0] = item->height[3] = inlink->h; + + if (i) { + item->y[1] = item->y[2] = AV_CEIL_RSHIFT(height, s->desc->log2_chroma_h); + item->y[0] = item->y[3] = height; + + height += ctx->inputs[i]->h; + } } } else if (s->is_horizontal) { - for (i = 1; i < s->nb_inputs; i++) { + for (i = 0; i < s->nb_inputs; i++) { + AVFilterLink *inlink = ctx->inputs[i]; + StackItem *item = &s->items[i]; + if (ctx->inputs[i]->h != height) { av_log(ctx, AV_LOG_ERROR, "Input %d height %d does not match input %d height %d.\n", i, ctx->inputs[i]->h, 0, height); return AVERROR(EINVAL); } - width += ctx->inputs[i]->w; + + if ((ret = av_image_fill_linesizes(item->linesize, inlink->format, inlink->w)) < 0) { + return ret; + } + + item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); + item->height[0] = item->height[3] = inlink->h; + + if (i) { + if ((ret = av_image_fill_linesizes(item->x, inlink->format, width)) < 0) { + return ret; + } + + width += ctx->inputs[i]->w; + } } } else { char *arg, *p = s->layout, *saveptr = NULL;