From patchwork Sun Aug 16 14:55:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 21680 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 74EA5448596 for ; Sun, 16 Aug 2020 17:55:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4505D68AD55; Sun, 16 Aug 2020 17:55:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 07237689AD2 for ; Sun, 16 Aug 2020 17:55:21 +0300 (EEST) Received: by mail-pj1-f66.google.com with SMTP id ha11so6456028pjb.1 for ; Sun, 16 Aug 2020 07:55:20 -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=4+1AYk7IIQto4Ph6cweC+9iNpj3/DY4plqrS4FGhBTY=; b=gFCzPgRt0aeWcOHxl+e3QmFxMDFW26mn6kaZpaPs13NwFM5lqG+G5klwKP+E391DeE d/B5eod8zeQeGuc1nt2c/cALAGqd9XOruRCCHjwIszyrMRKkjHit8uwm1idwx65CqDGS QrF+OqypwdKRH6eGVV4/IZbBwxBkF/sedwqRvjUe9pdfc6h5BRLfQSz+5Be4NjiNQvPX s19rGF4+BuM6wukH0y7HVQRlLCNsO/oIndluKXPiQ4KgTl1rBnkw1KgA0V5pNVOVnWE/ m0D4z/e/2Z95xcHLt3wr7S0DiQTQyHCVolYSoRONx82RpKsRo6//5H26GcRl90l4VK5Z XrmQ== 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=4+1AYk7IIQto4Ph6cweC+9iNpj3/DY4plqrS4FGhBTY=; b=dP8rYWggViGjAI1dZPxrB1qhFW80IETjQ+3SSYlyFATmeX20MW2Z2PWRSYxlGZvwwR hHSWT3HOvwl3OpcF/GLuEl62lT1jjQ2fLxCSYn3yfU65x37QeUpCT3slc3jAroTTVgdm 0lN2hs8V1pvKczuqsUfsjIxgCn68d83LH80t6SlV/bI+3YL0gQqB3ghRzFyWrGQusdZW S3iSP8ZVjGFcA5W29mntc0JCnt5J7b0UxCcBLKqCQi6KEIn0REDEy0M4qYJYRCIJWrM0 IpacqlNCH/bD/4aUB15CfOUECl4yss8Np6zNSLTifLbxD+5yHUekcCW2HBjOBdKfpxCj iDRQ== X-Gm-Message-State: AOAM531OvGNq/Gpui492bbNOE2GBJnZDZ0uXl4nFXO4zuI7snyPJG0qg soxOJfoWuuAdhNJnSKzscWrY4bS5Uyg= X-Google-Smtp-Source: ABdhPJz92WcIccNlFemYkY0w2kUgx6loTSy45xjB8POVJhMC6fjJZnMrFk0pdSfqg1kcJC+peGRUjA== X-Received: by 2002:a17:90a:4e8f:: with SMTP id o15mr8940390pjh.220.1597589718932; Sun, 16 Aug 2020 07:55:18 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id c192sm15688271pfc.154.2020.08.16.07.55.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Aug 2020 07:55:18 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 16 Aug 2020 22:55:13 +0800 Message-Id: <1597589713-10776-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 Subject: [FFmpeg-devel] [PATCH] avfilter/yadif: simplify the code for better readability 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavfilter/vf_bwdif.c | 13 ++++++------- libavfilter/vf_yadif.c | 16 ++++++++++------ libavfilter/x86/vf_bwdif_init.c | 2 +- libavfilter/x86/vf_yadif_init.c | 3 +-- libavfilter/yadif.h | 5 ++++- libavfilter/yadif_common.c | 2 +- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/libavfilter/vf_bwdif.c b/libavfilter/vf_bwdif.c index b6aed7a..583a965 100644 --- a/libavfilter/vf_bwdif.c +++ b/libavfilter/vf_bwdif.c @@ -219,8 +219,8 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) YADIFContext *yadif = &s->yadif; ThreadData *td = arg; int linesize = yadif->cur->linesize[td->plane]; - int clip_max = (1 << (yadif->csp->comp[td->plane].depth)) - 1; - int df = (yadif->csp->comp[td->plane].depth + 7) / 8; + int clip_max = (1 << (yadif->depth)) - 1; + int df = (yadif->depth + 7) / 8; int refs = linesize / df; int slice_start = (td->h * jobnr ) / nb_jobs; int slice_end = (td->h * (jobnr+1)) / nb_jobs; @@ -267,13 +267,13 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic, ThreadData td = { .frame = dstpic, .parity = parity, .tff = tff }; int i; - for (i = 0; i < yadif->csp->nb_components; i++) { + for (i = 0; i < yadif->nb_components; i++) { int w = dstpic->width; int h = dstpic->height; if (i == 1 || i == 2) { - w = AV_CEIL_RSHIFT(w, yadif->csp->log2_chroma_w); - h = AV_CEIL_RSHIFT(h, yadif->csp->log2_chroma_h); + w = AV_CEIL_RSHIFT(w, yadif->hsub); + h = AV_CEIL_RSHIFT(h, yadif->vsub); } td.w = w; @@ -348,9 +348,8 @@ static int config_props(AVFilterLink *link) return AVERROR(EINVAL); } - yadif->csp = av_pix_fmt_desc_get(link->format); yadif->filter = filter; - if (yadif->csp->comp[0].depth > 8) { + if (yadif->depth > 8) { s->filter_intra = filter_intra_16bit; s->filter_line = filter_line_c_16bit; s->filter_edge = filter_edge_16bit; diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index 43dea67..acc55a4 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -192,7 +192,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) YADIFContext *s = ctx->priv; ThreadData *td = arg; int refs = s->cur->linesize[td->plane]; - int df = (s->csp->comp[td->plane].depth + 7) / 8; + int df = (s->depth + 7) / 8; int pix_3 = 3 * df; int slice_start = (td->h * jobnr ) / nb_jobs; int slice_end = (td->h * (jobnr+1)) / nb_jobs; @@ -233,13 +233,13 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic, ThreadData td = { .frame = dstpic, .parity = parity, .tff = tff }; int i; - for (i = 0; i < yadif->csp->nb_components; i++) { + for (i = 0; i < yadif->nb_components; i++) { int w = dstpic->width; int h = dstpic->height; if (i == 1 || i == 2) { - w = AV_CEIL_RSHIFT(w, yadif->csp->log2_chroma_w); - h = AV_CEIL_RSHIFT(h, yadif->csp->log2_chroma_h); + w = AV_CEIL_RSHIFT(w, yadif->hsub); + h = AV_CEIL_RSHIFT(h, yadif->vsub); } @@ -292,6 +292,7 @@ static int config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; YADIFContext *s = ctx->priv; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format); outlink->time_base.num = ctx->inputs[0]->time_base.num; outlink->time_base.den = ctx->inputs[0]->time_base.den * 2; @@ -307,9 +308,12 @@ static int config_output(AVFilterLink *outlink) return AVERROR(EINVAL); } - s->csp = av_pix_fmt_desc_get(outlink->format); s->filter = filter; - if (s->csp->comp[0].depth > 8) { + s->depth = desc->comp[0].depth; + s->nb_components = desc->nb_components; + s->hsub = desc->log2_chroma_w; + s->vsub = desc->log2_chroma_h; + if (s->depth > 8) { s->filter_line = filter_line_c_16bit; s->filter_edges = filter_edges_16bit; } else { diff --git a/libavfilter/x86/vf_bwdif_init.c b/libavfilter/x86/vf_bwdif_init.c index b1e70b3..817bd84 100644 --- a/libavfilter/x86/vf_bwdif_init.c +++ b/libavfilter/x86/vf_bwdif_init.c @@ -55,7 +55,7 @@ av_cold void ff_bwdif_init_x86(BWDIFContext *bwdif) { YADIFContext *yadif = &bwdif->yadif; int cpu_flags = av_get_cpu_flags(); - int bit_depth = (!yadif->csp) ? 8 : yadif->csp->comp[0].depth; + int bit_depth = yadif->depth; if (bit_depth <= 8) { #if ARCH_X86_32 diff --git a/libavfilter/x86/vf_yadif_init.c b/libavfilter/x86/vf_yadif_init.c index c39bc44..ecf012a 100644 --- a/libavfilter/x86/vf_yadif_init.c +++ b/libavfilter/x86/vf_yadif_init.c @@ -60,8 +60,7 @@ void ff_yadif_filter_line_10bit_ssse3(void *dst, void *prev, void *cur, av_cold void ff_yadif_init_x86(YADIFContext *yadif) { int cpu_flags = av_get_cpu_flags(); - int bit_depth = (!yadif->csp) ? 8 - : yadif->csp->comp[0].depth; + int bit_depth = yadif->depth; if (bit_depth >= 15) { #if ARCH_X86_32 diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h index c928911..773f29b 100644 --- a/libavfilter/yadif.h +++ b/libavfilter/yadif.h @@ -72,7 +72,10 @@ typedef struct YADIFContext { void (*filter_edges)(void *dst, void *prev, void *cur, void *next, int w, int prefs, int mrefs, int parity, int mode); - const AVPixFmtDescriptor *csp; + int nb_components; + int depth; + int hsub; + int vsub; int eof; uint8_t *temp_line; int temp_line_size; diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c index a10cf7a..8c20e22 100644 --- a/libavfilter/yadif_common.c +++ b/libavfilter/yadif_common.c @@ -69,7 +69,7 @@ static int return_frame(AVFilterContext *ctx, int is_second) static int checkstride(YADIFContext *yadif, const AVFrame *a, const AVFrame *b) { int i; - for (i = 0; i < yadif->csp->nb_components; i++) + for (i = 0; i < yadif->nb_components; i++) if (a->linesize[i] != b->linesize[i]) return 1; return 0;