From patchwork Mon Feb 24 12:37:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 17907 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 5D9C044A135 for ; Mon, 24 Feb 2020 14:39:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F86968B522; Mon, 24 Feb 2020 14:39:31 +0200 (EET) 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 ESMTP id 6FF9568B4A2 for ; Mon, 24 Feb 2020 14:39:27 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 3A8F12951A9 for ; Mon, 24 Feb 2020 13:39:27 +0100 (CET) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 8c2L00KE3zrE for ; Mon, 24 Feb 2020 13:39:26 +0100 (CET) Received: from quelana.khirnov.net (unknown [IPv6:2a00:c500:61:23b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "quelana.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id C3B752951A8 for ; Mon, 24 Feb 2020 13:39:26 +0100 (CET) Received: from localhost (quelana.khirnov.net [IPv6:::1]) by quelana.khirnov.net (Postfix) with ESMTP id 835D42522B for ; Mon, 24 Feb 2020 13:39:26 +0100 (CET) Received: from quelana.khirnov.net ([IPv6:::1]) by localhost (quelana.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id xnkTe3OJfcNo for ; Mon, 24 Feb 2020 13:39:24 +0100 (CET) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) by quelana.khirnov.net (Postfix) with ESMTP id 758B625231 for ; Mon, 24 Feb 2020 13:39:14 +0100 (CET) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 6E13C20E035A; Mon, 24 Feb 2020 13:39:11 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 24 Feb 2020 13:37:35 +0100 Message-Id: <20200224123739.31154-9-anton@khirnov.net> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200224123739.31154-1-anton@khirnov.net> References: <20200224123739.31154-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/12] vf_spp: drop the option to use frame-attached QP tables 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" This API has been deprecated for five years. --- doc/filters.texi | 7 +-- libavfilter/vf_spp.c | 100 +++++++++++-------------------------------- libavfilter/vf_spp.h | 3 -- 3 files changed, 26 insertions(+), 84 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 3b1470ed0f..5fa1663426 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -17221,8 +17221,7 @@ that value the speed drops by a factor of approximately 2. Default value is @code{3}. @item qp -Force a constant quantization parameter. If not set, the filter will use the QP -from the video stream (if available). +Force a constant quantization parameter. @item mode Set thresholding mode. Available modes are: @@ -17234,10 +17233,6 @@ Set hard thresholding (default). Set soft thresholding (better de-ringing effect, but likely blurrier). @end table -@item use_bframe_qp -Enable the use of the QP from the B-Frames if set to @code{1}. Using this -option may cause flicker since the B-Frames have often larger QP. Default is -@code{0} (not enabled). @end table @subsection Commands diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c index 7381938f7f..ba6138f08e 100644 --- a/libavfilter/vf_spp.c +++ b/libavfilter/vf_spp.c @@ -64,7 +64,6 @@ static const AVOption spp_options[] = { { "mode", "set thresholding mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = MODE_HARD}, 0, NB_MODES - 1, FLAGS, "mode" }, { "hard", "hard thresholding", 0, AV_OPT_TYPE_CONST, {.i64 = MODE_HARD}, INT_MIN, INT_MAX, FLAGS, "mode" }, { "soft", "soft thresholding", 0, AV_OPT_TYPE_CONST, {.i64 = MODE_SOFT}, INT_MIN, INT_MAX, FLAGS, "mode" }, - { "use_bframe_qp", "use B-frames' QP", OFFSET(use_bframe_qp), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, { NULL } }; @@ -232,7 +231,7 @@ static inline void add_block(uint16_t *dst, int linesize, const int16_t block[64 static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, int dst_linesize, int src_linesize, int width, int height, - const uint8_t *qp_table, int qp_stride, int is_luma, int depth) + int is_luma, int depth) { int x, y, i; const int count = 1 << p->log2_count; @@ -266,15 +265,8 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, for (y = 0; y < height + 8; y += 8) { memset(p->temp + (8 + y) * linesize, 0, 8 * linesize * sizeof(*p->temp)); for (x = 0; x < width + 8; x += 8) { - int qp; - - if (p->qp) { - qp = p->qp; - } else{ - const int qps = 3 + is_luma; - qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); - } + int qp = p->qp; + for (i = 0; i < count; i++) { const int x1 = x + offset[i + count - 1][0]; const int y1 = y + offset[i + count - 1][1]; @@ -357,77 +349,36 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) SPPContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; AVFrame *out = in; - int qp_stride = 0; - const int8_t *qp_table = NULL; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); const int depth = desc->comp[0].depth; - /* if we are not in a constant user quantizer mode and we don't want to use - * 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 (!s->qp) { - qp_table = av_frame_get_qp_table(in, &qp_stride, &s->qscale_type); - - if (qp_table && !s->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 > s->non_b_qp_alloc_size) { - int ret = av_reallocp_array(&s->non_b_qp_table, w, h); - if (ret < 0) { - s->non_b_qp_alloc_size = 0; - return ret; - } - s->non_b_qp_alloc_size = w * h; - } - - av_assert0(w * h <= s->non_b_qp_alloc_size); - memcpy(s->non_b_qp_table, qp_table, w * h); - } - } - if (s->log2_count && !ctx->is_disabled) { - if (!s->use_bframe_qp && s->non_b_qp_table) - qp_table = s->non_b_qp_table; - - if (qp_table || s->qp) { - const int cw = AV_CEIL_RSHIFT(inlink->w, s->hsub); - const int ch = AV_CEIL_RSHIFT(inlink->h, s->vsub); - - /* get a new frame if in-place is not possible or if the dimensions - * are not multiple of 8 */ - if (!av_frame_is_writable(in) || (inlink->w & 7) || (inlink->h & 7)) { - const int aligned_w = FFALIGN(inlink->w, 8); - const int aligned_h = FFALIGN(inlink->h, 8); - - out = ff_get_video_buffer(outlink, aligned_w, aligned_h); - if (!out) { - av_frame_free(&in); - return AVERROR(ENOMEM); - } - av_frame_copy_props(out, in); - out->width = in->width; - out->height = in->height; + const int cw = AV_CEIL_RSHIFT(inlink->w, s->hsub); + const int ch = AV_CEIL_RSHIFT(inlink->h, s->vsub); + + /* get a new frame if in-place is not possible or if the dimensions + * are not multiple of 8 */ + if (!av_frame_is_writable(in) || (inlink->w & 7) || (inlink->h & 7)) { + const int aligned_w = FFALIGN(inlink->w, 8); + const int aligned_h = FFALIGN(inlink->h, 8); + + out = ff_get_video_buffer(outlink, aligned_w, aligned_h); + if (!out) { + av_frame_free(&in); + return AVERROR(ENOMEM); } + av_frame_copy_props(out, in); + out->width = in->width; + out->height = in->height; + } - filter(s, out->data[0], in->data[0], out->linesize[0], in->linesize[0], inlink->w, inlink->h, qp_table, qp_stride, 1, depth); + filter(s, out->data[0], in->data[0], out->linesize[0], in->linesize[0], inlink->w, inlink->h, 1, depth); - if (out->data[2]) { - filter(s, out->data[1], in->data[1], out->linesize[1], in->linesize[1], cw, ch, qp_table, qp_stride, 0, depth); - filter(s, out->data[2], in->data[2], out->linesize[2], in->linesize[2], cw, ch, qp_table, qp_stride, 0, depth); - } - emms_c(); + if (out->data[2]) { + filter(s, out->data[1], in->data[1], out->linesize[1], in->linesize[1], cw, ch, 0, depth); + filter(s, out->data[2], in->data[2], out->linesize[2], in->linesize[2], cw, ch, 0, depth); } + emms_c(); } if (in != out) { @@ -494,7 +445,6 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&s->avctx); } av_freep(&s->dct); - av_freep(&s->non_b_qp_table); } static const AVFilterPad spp_inputs[] = { diff --git a/libavfilter/vf_spp.h b/libavfilter/vf_spp.h index c03073a4e1..f038201e53 100644 --- a/libavfilter/vf_spp.h +++ b/libavfilter/vf_spp.h @@ -40,9 +40,6 @@ typedef struct SPPContext { uint16_t *temp; AVCodecContext *avctx; AVDCT *dct; - int8_t *non_b_qp_table; - int non_b_qp_alloc_size; - int use_bframe_qp; int hsub, vsub; void (*store_slice)(uint8_t *dst, const int16_t *src,