From patchwork Fri Oct 2 18:03:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22718 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c650:0:0:0:0:0 with SMTP id k77csp1482046ybf; Fri, 2 Oct 2020 11:05:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMA66DpL/1DOEiQRdSD1waU5uh2dMD41xyi8aFScZEFFi8MJusFl8Jp22EpqVb5omccf0Z X-Received: by 2002:a7b:c183:: with SMTP id y3mr4186516wmi.84.1601661909482; Fri, 02 Oct 2020 11:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601661909; cv=none; d=google.com; s=arc-20160816; b=ZuHVYOLVcQaEmeBLIHNctBnsWT4ehWx2kFF4ywMgm+txm/yKF5yZW6oSPdPKY6AsFf 3gAydP56EK9Tt5AEn50I5N/AJGivXZb9RU6jU9nTN/sOfNfsxyAlSBO+C/NGFWVaWaUI uDX27A8qaTkBYXMzBkYAP8awmj3tnZHiOYkCOBvISsgKpAVAag/CuSzti6O/dsXqhIq0 tPiFgJNYJa4xUeOMrJtCDfDHVA1RwdlN/kO4mYKJs5Lup4bKPkm+BRqDP64FqWayaOtu KlphvGy6fegmderQiwVThjs+EkpNON1dEvKGvwwxBWA9dRHAFzXCEzvJ0IvX+i9Yve6F fV4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=u7eWRPnRJlB4xAQ7YmmHlrS7qMuQBq0dMZ1M6yO3yNo=; b=gmCCCrmrocp0AbbetGh9XqDYTkYsOhYreqOuByDnVKplg2qMZq7pfRaWiIulKKP1G/ b/bLU43dvqBk+0GatV341NTTqkKa3y09BTyF3kJCvchzOtUBiLbVVRhMUejFjVNP3TAT G/dPYYJbnwkcwutBAKChytl2skecBc4RnoKtb1O/M3jONwzfkuVMFyvtEojqyM/NfLaP ZCr3TQwdHcUO68yAVs+KYiAF+r4hvJrESJJJVpfDEgrrY6muIgQe5L5Upu9YtNEQHy9D zJiT7OJ4ZO6Vj9xk97HbU944dG9vS8GRBzzmmsywN4w4GgfI6i4baxcn87p3nSY6RvgO 1EtA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a184si2164119wmd.103.2020.10.02.11.05.08; Fri, 02 Oct 2020 11:05:09 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C56F768AA60; Fri, 2 Oct 2020 21:04:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD85A68A0F0 for ; Fri, 2 Oct 2020 21:03:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 10BDE296115 for ; Fri, 2 Oct 2020 20:03:52 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id eU3b_kOy7kGE for ; Fri, 2 Oct 2020 20:03:51 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id BC007296116 for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 08C9C20E00C0; Fri, 2 Oct 2020 20:03:46 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Oct 2020 20:03:30 +0200 Message-Id: <20201002180331.20416-6-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002180331.20416-1-anton@khirnov.net> References: <20201002180331.20416-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7] lavfi/vf_fspp: convert to the video_enc_params API 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: zjYnsLKfWm6c Content-Length: 8649 --- libavfilter/Makefile | 2 +- libavfilter/vf_fspp.c | 59 +++++++++++++++++-------------------------- libavfilter/vf_fspp.h | 2 +- 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index dcbb867265..be2c3e3156 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -263,7 +263,7 @@ OBJS-$(CONFIG_FRAMESTEP_FILTER) += vf_framestep.o OBJS-$(CONFIG_FREEZEDETECT_FILTER) += vf_freezedetect.o OBJS-$(CONFIG_FREEZEFRAMES_FILTER) += vf_freezeframes.o OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o -OBJS-$(CONFIG_FSPP_FILTER) += vf_fspp.o +OBJS-$(CONFIG_FSPP_FILTER) += vf_fspp.o qp_table.o OBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o OBJS-$(CONFIG_GEQ_FILTER) += vf_geq.o OBJS-$(CONFIG_GRADFUN_FILTER) += vf_gradfun.o diff --git a/libavfilter/vf_fspp.c b/libavfilter/vf_fspp.c index c6989046c4..cc743752d3 100644 --- a/libavfilter/vf_fspp.c +++ b/libavfilter/vf_fspp.c @@ -40,6 +40,7 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "internal.h" +#include "qp_table.h" #include "vf_fspp.h" #define OFFSET(x) offsetof(FSPPContext, x) @@ -206,7 +207,7 @@ static void filter(FSPPContext *p, uint8_t *dst, uint8_t *src, if (t < 0) t = 0; //t always < width-2 t = qp_store[qy + (t >> qpsh)]; - t = ff_norm_qscale(t, p->qscale_type); + t = ff_norm_qscale(t, FF_QSCALE_TYPE_MPEG2); if (t != p->prev_q) p->prev_q = t, p->mul_thrmat((int16_t *)(&p->threshold_mtx_noq[0]), (int16_t *)(&p->threshold_mtx[0]), t); p->column_fidct((int16_t *)(&p->threshold_mtx[0]), block + x * 8, block3 + x * 8, 8); //yes, this is a HOTSPOT @@ -525,13 +526,6 @@ static int config_input(AVFilterLink *inlink) if (!fspp->temp || !fspp->src) return AVERROR(ENOMEM); - if (!fspp->use_bframe_qp && !fspp->qp) { - fspp->non_b_qp_alloc_size = AV_CEIL_RSHIFT(inlink->w, 4) * AV_CEIL_RSHIFT(inlink->h, 4); - fspp->non_b_qp_table = av_calloc(fspp->non_b_qp_alloc_size, sizeof(*fspp->non_b_qp_table)); - if (!fspp->non_b_qp_table) - return AVERROR(ENOMEM); - } - fspp->store_slice = store_slice_c; fspp->store_slice2 = store_slice2_c; fspp->mul_thrmat = mul_thrmat_c; @@ -555,6 +549,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) int qp_stride = 0; uint8_t *qp_table = NULL; int i, bias; + int ret = 0; int custom_threshold_m[64]; bias = (1 << 4) + fspp->strength; @@ -581,38 +576,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) * the quantizers from the B-frames (B-frames often have a higher QP), we * need to save the qp table from the last non B-frame; this is what the * following code block does */ - if (!fspp->qp) { - qp_table = av_frame_get_qp_table(in, &qp_stride, &fspp->qscale_type); - - if (qp_table && !fspp->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) { - int w, h; - - /* if the qp stride is not set, it means the QP are only defined on - * a line basis */ - if (!qp_stride) { - w = AV_CEIL_RSHIFT(inlink->w, 4); - h = 1; - } else { - w = qp_stride; - h = AV_CEIL_RSHIFT(inlink->h, 4); - } - if (w * h > fspp->non_b_qp_alloc_size) { - int ret = av_reallocp_array(&fspp->non_b_qp_table, w, h); - if (ret < 0) { - fspp->non_b_qp_alloc_size = 0; - return ret; - } - fspp->non_b_qp_alloc_size = w * h; - } + if (!fspp->qp && (fspp->use_bframe_qp || in->pict_type != AV_PICTURE_TYPE_B)) { + ret = ff_qp_table_extract(in, &qp_table, &qp_stride, NULL); + if (ret < 0) { + av_frame_free(&in); + return ret; + } - av_assert0(w * h <= fspp->non_b_qp_alloc_size); - memcpy(fspp->non_b_qp_table, qp_table, w * h); + if (!fspp->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) { + av_freep(&fspp->non_b_qp_table); + fspp->non_b_qp_table = qp_table; + fspp->non_b_qp_stride = qp_stride; } } if (fspp->log2_count && !ctx->is_disabled) { - if (!fspp->use_bframe_qp && fspp->non_b_qp_table) + if (!fspp->use_bframe_qp && fspp->non_b_qp_table) { qp_table = fspp->non_b_qp_table; + qp_stride = fspp->non_b_qp_stride; + } if (qp_table || fspp->qp) { const int cw = AV_CEIL_RSHIFT(inlink->w, fspp->hsub); @@ -627,7 +609,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) out = ff_get_video_buffer(outlink, aligned_w, aligned_h); if (!out) { av_frame_free(&in); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto finish; } av_frame_copy_props(out, in); out->width = in->width; @@ -651,7 +634,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) inlink->w, inlink->h); av_frame_free(&in); } - return ff_filter_frame(outlink, out); + ret = ff_filter_frame(outlink, out); +finish: + if (qp_table != fspp->non_b_qp_table) + av_freep(&qp_table); + return ret; } static av_cold void uninit(AVFilterContext *ctx) diff --git a/libavfilter/vf_fspp.h b/libavfilter/vf_fspp.h index 73d8c7c771..6529f678ea 100644 --- a/libavfilter/vf_fspp.h +++ b/libavfilter/vf_fspp.h @@ -66,7 +66,7 @@ typedef struct FSPPContext { uint8_t *src; int16_t *temp; uint8_t *non_b_qp_table; - int non_b_qp_alloc_size; + int non_b_qp_stride; int use_bframe_qp; void (*store_slice)(uint8_t *dst, int16_t *src,