From patchwork Sat Jun 1 05:16:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 13368 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 49B624474A9 for ; Sat, 1 Jun 2019 08:16:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 36F5768AA28; Sat, 1 Jun 2019 08:16:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6EF2A68A9BE for ; Sat, 1 Jun 2019 08:16:50 +0300 (EEST) Received: by mail-pl1-f195.google.com with SMTP id g21so4833261plq.0 for ; Fri, 31 May 2019 22:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W3rY8BCGrdxJud3LTdM7LDvKsth7WYjAxFg76oiarlo=; b=Hl9BbllKwUJaUVn3txVbgObF16YrRjToC55ghhT8ZQgbeRftaWT41iGk173ByOB+T9 uun0p0U+eoOu2iJuIQrUtcB96irELS4tDyOcVyHjPiOabQO4H6McV3pniPpgpBaGhKtI 0fwrCI8P7Rk+YJha9j9KeNlzVjc4sRIA12mSYZDGEF4f1F5BhmvS7xqAfIfnDdGFxFdE VOPkU2pNT+Wisr46poTpP2J0c5fL8xkKuBvtSryTVT9Tc8Of5cfZTt6BiI2KOrsISqsR I0fU7uCnluCw5k8mBYP5qd3n2jE6OARSKXPOgyHWKViVPr/2Szk3HG/pxSBSdHyqOjdJ isSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=W3rY8BCGrdxJud3LTdM7LDvKsth7WYjAxFg76oiarlo=; b=ThSAY6Yj45kN+u9Iyoouhdovk7R+HE/PF8Yesyd3mnE0+tbBn0jNffBfBfaB9h6PSs 7R9inmRh38m58dXf4kh3jViGSd0IuMnhf5WyjSZJkBcJ3FhGl9/C/trynxkGqG0B5CYC V8dR6/js5r01JLW98QLDcsuuw738JWxTF66c/YQWxx48uUj+gOcEPeAtqoswC/qu0DJT xiilZ+jVcwG/sbBR3nTLUnh5Gijsu40gI9aywI8rvw+ZvSTgjPceW6VEU5oT7M9/LEh3 2nx+7agyrITi+OaLkNf+O6PNssI1qGcyxM2F1PdA6g6SqrWe4HkqKZEifLv3t0V6oroU PIPA== X-Gm-Message-State: APjAAAWahR2L+Fc/wiL8q3wFh0t5WpZR9z807wTpKfoKn06S9/UsSjKS NPMtz6DezVCy1/t9tobWb+kKE5UA X-Google-Smtp-Source: APXvYqzQsdsz72SclD01zs9WUO5tIpC6mHv4wB8k1mGE2qbxNY/Xw+HAQRbmcrCc+2o3SdyvVVzHFA== X-Received: by 2002:a17:902:1125:: with SMTP id d34mr13754507pla.101.1559366208705; Fri, 31 May 2019 22:16:48 -0700 (PDT) Received: from localhost.localdomain ([47.90.47.25]) by smtp.gmail.com with ESMTPSA id p16sm16252362pfq.153.2019.05.31.22.16.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 May 2019 22:16:48 -0700 (PDT) From: Jun Zhao To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Jun 2019 13:16:39 +0800 Message-Id: <1559366200-9889-2-git-send-email-mypopydev@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1559366200-9889-1-git-send-email-mypopydev@gmail.com> References: <1559366200-9889-1-git-send-email-mypopydev@gmail.com> Subject: [FFmpeg-devel] [PATCH V5 1/2] lavfi/colorlevels: Add slice threading support 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: Jun Zhao MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jun Zhao Add slice threading support, use the command like: ./ffmpeg -i input -vf colorlevels -f null /dev/null with 1080p h264 clip, the fps from 39 fps to 79 fps in the local(Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz) Signed-off-by: Jun Zhao --- libavfilter/vf_colorlevels.c | 110 ++++++++++++++++++++++++++++++++++------- 1 files changed, 91 insertions(+), 19 deletions(-) diff --git a/libavfilter/vf_colorlevels.c b/libavfilter/vf_colorlevels.c index 5385a5e..fadb39e 100644 --- a/libavfilter/vf_colorlevels.c +++ b/libavfilter/vf_colorlevels.c @@ -105,6 +105,68 @@ static int config_input(AVFilterLink *inlink) return 0; } +struct thread_data { + const uint8_t *srcrow; + uint8_t *dstrow; + int dst_linesize; + int src_linesize; + + double coeff; + uint8_t offset; + + int h; + + int imin; + int omin; +}; + +#define LOAD_COMMON\ + ColorLevelsContext *s = ctx->priv;\ + const struct thread_data *td = arg;\ +\ + int process_h = td->h;\ + const int slice_start = (process_h * jobnr ) / nb_jobs;\ + const int slice_end = (process_h * (jobnr+1)) / nb_jobs;\ + int x, y;\ + const uint8_t *srcrow = td->srcrow;\ + uint8_t *dstrow = td->dstrow;\ + const int step = s->step;\ + const uint8_t offset = td->offset;\ +\ + int imin = td->imin;\ + int omin = td->omin;\ + double coeff = td->coeff;\ + +static int colorlevel_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) +{ + LOAD_COMMON + + for (y = slice_start; y < slice_end; y++) { + const uint8_t *src = srcrow + y * td->src_linesize; + uint8_t *dst = dstrow + y * td->dst_linesize; + + for (x = 0; x < s->linesize; x += step) + dst[x + offset] = av_clip_uint8((src[x + offset] - imin) * coeff + omin); + } + + return 0; +} + +static int colorlevel_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) +{ + LOAD_COMMON + + for (y = slice_start; y < slice_end; y++) { + const uint16_t *src = (const uint16_t *)(srcrow + y * td->src_linesize); + uint16_t *dst = (uint16_t *)(dstrow + y * td->dst_linesize); + + for (x = 0; x < s->linesize; x += step) + dst[x + offset] = av_clip_uint16((src[x + offset] - imin) * coeff + omin); + } + + return 0; +} + static int filter_frame(AVFilterLink *inlink, AVFrame *in) { AVFilterContext *ctx = inlink->dst; @@ -137,6 +199,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) int omin = lrint(r->out_min * UINT8_MAX); int omax = lrint(r->out_max * UINT8_MAX); double coeff; + struct thread_data td; if (imin < 0) { imin = UINT8_MAX; @@ -162,15 +225,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) srcrow = in->data[0]; coeff = (omax - omin) / (double)(imax - imin); - for (y = 0; y < inlink->h; y++) { - const uint8_t *src = srcrow; - uint8_t *dst = dstrow; - - for (x = 0; x < s->linesize; x += step) - dst[x + offset] = av_clip_uint8((src[x + offset] - imin) * coeff + omin); - dstrow += out->linesize[0]; - srcrow += in->linesize[0]; - } + + td.srcrow = srcrow; + td.dstrow = dstrow; + td.dst_linesize = out->linesize[0]; + td.src_linesize = in->linesize[0]; + td.coeff = coeff; + td.offset = offset; + td.h = inlink->h; + td.imin = imin; + td.omin = omin; + + ctx->internal->execute(ctx, colorlevel_slice_8, &td, NULL, + FFMIN(inlink->h, ff_filter_get_nb_threads(ctx))); } break; case 2: @@ -184,6 +251,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) int omin = lrint(r->out_min * UINT16_MAX); int omax = lrint(r->out_max * UINT16_MAX); double coeff; + struct thread_data td; if (imin < 0) { imin = UINT16_MAX; @@ -209,15 +277,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) srcrow = in->data[0]; coeff = (omax - omin) / (double)(imax - imin); - for (y = 0; y < inlink->h; y++) { - const uint16_t *src = (const uint16_t*)srcrow; - uint16_t *dst = (uint16_t *)dstrow; - - for (x = 0; x < s->linesize; x += step) - dst[x + offset] = av_clip_uint16((src[x + offset] - imin) * coeff + omin); - dstrow += out->linesize[0]; - srcrow += in->linesize[0]; - } + + td.srcrow = srcrow; + td.dstrow = dstrow; + td.dst_linesize = out->linesize[0]; + td.src_linesize = in->linesize[0]; + td.coeff = coeff; + td.offset = offset; + td.h = inlink->h; + td.imin = imin; + td.omin = omin; + + ctx->internal->execute(ctx, colorlevel_slice_16, &td, NULL, + FFMIN(inlink->h, ff_filter_get_nb_threads(ctx))); } } @@ -252,5 +324,5 @@ AVFilter ff_vf_colorlevels = { .query_formats = query_formats, .inputs = colorlevels_inputs, .outputs = colorlevels_outputs, - .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, + .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS, };