From patchwork Tue May 21 01:42:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 13216 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 996DB44807D for ; Tue, 21 May 2019 04:49:00 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7595468A775; Tue, 21 May 2019 04:49:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D3366883B3 for ; Tue, 21 May 2019 04:48:54 +0300 (EEST) Received: by mail-pf1-f193.google.com with SMTP id y11so8134837pfm.13 for ; Mon, 20 May 2019 18:48:54 -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; bh=XHmrTITz6szn+OzKsNgKMsyvdW8dlVD6T05m/kB3zs8=; b=QixLidXgXooGS8Btf8Uq9FRsXbuMrJjeQ7eP9AiJ0SOCrhab3j5+J1buF1v+oJlYS8 RR92LdWX5Sp/I64pSKnY2bMqCT0m1RQ8nlRlY3tGBQCEAU/o+kc1sXOwUVvozbQM4Gxh HHj15fn5GfHYrIKqc6sCEfbxd9/sfXBBSioWNiREPYi01lkypiBn6d3PkHGXNO1a4Q3M hl/4YaM6HEsJWZ+qLRbv9vKzRWuYUdWf9n0laxxIfFoB3NeyQUHO3Hu4ZigWi1oX9/Xg cKHwMatjbsyt2JISR55GyG5d/x12rT9BnyQFvJFBRhiGO70MhC2Zuk5UxtQRk9y8Ea05 rBrA== 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; bh=XHmrTITz6szn+OzKsNgKMsyvdW8dlVD6T05m/kB3zs8=; b=BidPw5NGI9ZJvDpkpW4x4BNe7ipyXJNg4Gi+YmMSN0cRmroBN69N4jDIN5a4nVlA4B mfKAUxLOOm7Pv7qI1HQSqiDgVCref7DwE5U31xp0ED03xuzBIjK9XHEeWIxFFFPh+6Is ZTL8ovrO6iKEeECOWb6ePHU15Hn5Up2liwaSZxDVLx9HEmTLEklcKpwOGLhC3IeCP6dC KDhuXwlIXQ1s6ThmiZni+F1QCee0Cxwj8ZZ5mvNtXo1vtsttw+ajK6a7OvtHaUWvBfQX xqxO655BJNQ4Xyu1KTrJHTnrRvr4FTw2dQuGBtPF5rcRcAuJO101LTrcKHn/065qCBYh vIQg== X-Gm-Message-State: APjAAAXx6lg7kfQfciCRnJH0WEmcslZWB/6bBUrV/sDsbn+p/yCVQtJY BpU66mTb5QZ216movyk49rmy/TYJ X-Google-Smtp-Source: APXvYqwQWNGd53J4s4MsSZTZskxkfWOXvtEdZ+TN7XTg6dMTYp8lnQ7/NpT74SNsixP5o3ClsBD26w== X-Received: by 2002:aa7:9577:: with SMTP id x23mr83589716pfq.164.1558402952121; Mon, 20 May 2019 18:42:32 -0700 (PDT) Received: from localhost.localdomain ([47.90.47.25]) by smtp.gmail.com with ESMTPSA id e5sm41575716pgh.35.2019.05.20.18.42.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 May 2019 18:42:31 -0700 (PDT) From: Jun Zhao To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 May 2019 09:42:24 +0800 Message-Id: <1558402944-30451-1-git-send-email-mypopydev@gmail.com> X-Mailer: git-send-email 1.7.1 Subject: [FFmpeg-devel] [PATCH] 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 colorlevel with 1080p h264 clip, the fps from 39 fps to 79 fps in the local Signed-off-by: Jun Zhao --- libavfilter/vf_colorlevels.c | 125 +++++++++++++++++++++++++++++++++++------ 1 files changed, 106 insertions(+), 19 deletions(-) diff --git a/libavfilter/vf_colorlevels.c b/libavfilter/vf_colorlevels.c index 5385a5e..68668e7 100644 --- a/libavfilter/vf_colorlevels.c +++ b/libavfilter/vf_colorlevels.c @@ -105,6 +105,83 @@ 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; +}; + +static int colorlevel_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) +{ + 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; + + for (y = slice_start; y < slice_end; 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 += td->dst_linesize; + srcrow += td->src_linesize; + } + + return 0; +} + +static int colorlevel_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) +{ + 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; + + for (y = slice_start; y < slice_end; 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_uint8((src[x + offset] - imin) * coeff + omin); + dstrow += td->dst_linesize; + srcrow += td->src_linesize; + } + + return 0; +} + static int filter_frame(AVFilterLink *inlink, AVFrame *in) { AVFilterContext *ctx = inlink->dst; @@ -137,6 +214,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 +240,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 +266,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 +292,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 +339,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, };