From patchwork Thu Mar 25 15:49:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26607 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 8827F44B722 for ; Thu, 25 Mar 2021 17:50:51 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6E92768AB70; Thu, 25 Mar 2021 17:50:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 05EB768A9A8 for ; Thu, 25 Mar 2021 17:50:38 +0200 (EET) Received: by mail-ed1-f51.google.com with SMTP id y6so2987557eds.1 for ; Thu, 25 Mar 2021 08:50:37 -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:reply-to :mime-version:content-transfer-encoding; bh=thoSxlu+qDVshOwCoLuXWg2yxhKLva84X2lW+CGd33o=; b=JOe+xSv7YHN+rizaqhQrmblCX/+FhK/9ESY4bW+rCtR9JQQObNBqDpWFCbjBh76+xe CaMtB7JvRDGUfXjJFslKilZG3Jlrss8ImPwPNK470rLeHiYQQwqpCKkS3KtLgUU54jVG pwnwYIl02e8XeXRI5rfIRvBednZkWbuCsHXX6QkroANxRvRcD6UBK77s/s6bUj1pKICr i4jYee81Lz2hNTvhsdSNAfaXXMOfky7RTFdCWC9Ge3Vt+f8XUfRhgavLELP0G7gBakNw k/T7oe3wOOEfC1onFwJoiM736KTHsl4yJA3hcv6TqQaHPNyg/gdLa8lNzBbBymR/90eq L01A== 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:reply-to:mime-version:content-transfer-encoding; bh=thoSxlu+qDVshOwCoLuXWg2yxhKLva84X2lW+CGd33o=; b=hVWqyTft6rtOIIh1BV64gU9Riij1LY3glysveo6Js3HtXDSK4APdDTfF0OjPxFfI7U lFwFEbnI0wjg8RIHHRAGquC30mis3khKcY1ntHmYewAoAzvqjfrxC8Nf+gsX7nju5H3U s8xSPlFLQ8GKgcc+0RwJCfWPFU+j/3Fds2cYm8iw6MwxIY56Pzwkzd2JrJvassZnkctx ivdW7rNZ96mFZ6DxJ6aYRNPmqWew4YT1HVvoLCPwWljAYmeh3F6SAhulGoywK0C/anij h6j0jeEmd938OxLyHmbczpvduSXPXpMG+yySd1E5hUDYRJW/p3XAhhMtYME2LcMeixRk /y0A== X-Gm-Message-State: AOAM531D8oftRQNSblZxwKq4yW2Q3LzCB81KRPL3P4IJEbz/yFJ9n/WI Ua/d0r+53E/lP44qiK97vXrAMwY/7uGONg== X-Google-Smtp-Source: ABdhPJxlfuNwET+T2ZbobH3m9cGyhWCKakwjm1SyCYM7xpFbLpH646PWy+oXJTZ2CK8417j95wZCWw== X-Received: by 2002:a05:6402:1d19:: with SMTP id dg25mr9924823edb.218.1616687437379; Thu, 25 Mar 2021 08:50:37 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08960.dynamic.kabel-deutschland.de. [188.192.137.96]) by smtp.gmail.com with ESMTPSA id o6sm2859103edw.24.2021.03.25.08.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 08:50:36 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Mar 2021 16:49:53 +0100 Message-Id: <20210325154956.2405162-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210325154956.2405162-1-andreas.rheinhardt@gmail.com> References: <20210325154956.2405162-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/12] avcodec/proresenc_kostya: Factor flushing PutBitContext out 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The function to write an ordinary (luma or chroma) plane as well as the function for writing an alpha plane have some similarities: They record the initial bitposition (despite said position always being byte-aligned), flush the PutBitContext themselves and return the amount of bytes they wrote. This commit factors this out; it also replaces bitpositions by bytepositions and it avoids recording the initial byteposition because said information is already available from the position at the end of the last plane. Signed-off-by: Andreas Rheinhardt --- libavcodec/proresenc_kostya.c | 36 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c index 0e70163bcc..d8edd12f34 100644 --- a/libavcodec/proresenc_kostya.c +++ b/libavcodec/proresenc_kostya.c @@ -464,23 +464,17 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, } } -static int encode_slice_plane(ProresContext *ctx, PutBitContext *pb, +static void encode_slice_plane(ProresContext *ctx, PutBitContext *pb, const uint16_t *src, ptrdiff_t linesize, int mbs_per_slice, int16_t *blocks, int blocks_per_mb, int plane_size_factor, const int16_t *qmat) { - int blocks_per_slice, saved_pos; - - saved_pos = put_bits_count(pb); - blocks_per_slice = mbs_per_slice * blocks_per_mb; + int blocks_per_slice = mbs_per_slice * blocks_per_mb; encode_dcs(pb, blocks, blocks_per_slice, qmat[0]); encode_acs(pb, blocks, blocks_per_slice, plane_size_factor, ctx->scantable, qmat); - flush_put_bits(pb); - - return (put_bits_count(pb) - saved_pos) >> 3; } static void put_alpha_diff(PutBitContext *pb, int cur, int prev, int abits) @@ -516,14 +510,13 @@ static void put_alpha_run(PutBitContext *pb, int run) } // todo alpha quantisation for high quants -static int encode_alpha_plane(ProresContext *ctx, PutBitContext *pb, +static void encode_alpha_plane(ProresContext *ctx, PutBitContext *pb, int mbs_per_slice, uint16_t *blocks, int quant) { const int abits = ctx->alpha_bits; const int mask = (1 << abits) - 1; const int num_coeffs = mbs_per_slice * 256; - int saved_pos = put_bits_count(pb); int prev = mask, cur; int idx = 0; int run = 0; @@ -544,8 +537,6 @@ static int encode_alpha_plane(ProresContext *ctx, PutBitContext *pb, } while (idx < num_coeffs); if (run) put_alpha_run(pb, run); - flush_put_bits(pb); - return (put_bits_count(pb) - saved_pos) >> 3; } static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, @@ -611,24 +602,23 @@ static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, ctx->blocks[0], ctx->emu_buf, mbs_per_slice, num_cblocks, is_chroma); if (!is_chroma) {/* luma quant */ - sizes[i] = encode_slice_plane(ctx, pb, src, linesize, - mbs_per_slice, ctx->blocks[0], - num_cblocks, plane_factor, - qmat); + encode_slice_plane(ctx, pb, src, linesize, + mbs_per_slice, ctx->blocks[0], + num_cblocks, plane_factor, qmat); } else { /* chroma plane */ - sizes[i] = encode_slice_plane(ctx, pb, src, linesize, - mbs_per_slice, ctx->blocks[0], - num_cblocks, plane_factor, - qmat_chroma); + encode_slice_plane(ctx, pb, src, linesize, + mbs_per_slice, ctx->blocks[0], + num_cblocks, plane_factor, qmat_chroma); } } else { get_alpha_data(ctx, src, linesize, xp, yp, pwidth, avctx->height / ctx->pictures_per_frame, ctx->blocks[0], mbs_per_slice, ctx->alpha_bits); - sizes[i] = encode_alpha_plane(ctx, pb, mbs_per_slice, - ctx->blocks[0], quant); + encode_alpha_plane(ctx, pb, mbs_per_slice, ctx->blocks[0], quant); } - total_size += sizes[i]; + flush_put_bits(pb); + sizes[i] = put_bytes_output(pb) - total_size; + total_size = put_bytes_output(pb); if (put_bits_left(pb) < 0) { av_log(avctx, AV_LOG_ERROR, "Underestimated required buffer size.\n");