From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1DBB44BD9A for ; Tue, 16 Jul 2024 18:15:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D821568DB27; Tue, 16 Jul 2024 21:14:20 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 84DCF68DA38 for ; Tue, 16 Jul 2024 21:14:04 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=oM86FmLX; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id DDD0F4DF5 for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id YRY_qPvl97YX for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150188; bh=Qw2kyh5MElUzmcAt70EAsd6r7vSsH8da6CaRAeF1tHQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oM86FmLXsfdAHmFHhzJzy+hmU4IpAwgn+NPRf/E9wIRIfq+heuhUbqvyDfUP18Yb/ WTO/EnAgFi7IaZ/caPyBW0JGykhgMLv63Wuyf3QUa4cZZRnRgAKnbvvulrPFCUVCkJ +WNVKZ8HfjsDl8Zu3dmb18d5usUtEKm8xkLN/R6sSKVZ3lqgAsnQaP6JdEScWJiR1v /JbIkwXyDunJ5T4N8NHVV3tCtgA/gjFe3QHs4lQ0DjAic4/+cJrQw1PnUehiX3EgHb rLmPLyABbnh8sCAHcsHWO3HciQvH9u9DermIRaUw8uIkqf33Vyn/5rQmj9GY61KFgc 48oBOBGuktB/w== Received: from libav.khirnov.net (libav.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.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 6621C4DF2 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A6A323A25B7 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:26 +0200 Message-ID: <20240716171155.31838-11-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/39] lavc/ffv1enc: move bit writer to per-slice context X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavcodec/ffv1.h | 3 ++- libavcodec/ffv1enc.c | 7 ++++--- libavcodec/ffv1enc_template.c | 14 +++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index c88aa8c30d..dce6e177eb 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -79,13 +79,14 @@ typedef struct FFV1SliceContext { int slice_y; int run_index; + + PutBitContext pb; } FFV1SliceContext; typedef struct FFV1Context { AVClass *class; AVCodecContext *avctx; RangeCoder c; - PutBitContext pb; uint64_t rc_stat[256][2]; uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; int version; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 8bb9174a1d..5692bfa1fc 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -1057,7 +1057,7 @@ retry: } if (fs->ac == AC_GOLOMB_RICE) { fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0; - init_put_bits(&fs->pb, + init_put_bits(&sc->pb, fs->c.bytestream_start + fs->ac_byte_count, fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count); } @@ -1209,13 +1209,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, buf_p = pkt->data; for (i = 0; i < f->slice_count; i++) { FFV1Context *fs = f->slice_context[i]; + FFV1SliceContext *sc = &f->slices[i]; int bytes; if (fs->ac != AC_GOLOMB_RICE) { bytes = ff_rac_terminate(&fs->c, 1); } else { - flush_put_bits(&fs->pb); // FIXME: nicer padding - bytes = fs->ac_byte_count + put_bytes_output(&fs->pb); + flush_put_bits(&sc->pb); // FIXME: nicer padding + bytes = fs->ac_byte_count + put_bytes_output(&sc->pb); } if (i > 0 || f->version > 2) { av_assert0(bytes < pkt->size / f->slice_count); diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 4dccd531a8..8b9e53fa1b 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -39,7 +39,7 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, return AVERROR_INVALIDDATA; } } else { - if (put_bytes_left(&s->pb, 0) < w * 4) { + if (put_bytes_left(&sc->pb, 0) < w * 4) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } @@ -86,10 +86,10 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, while (run_count >= 1 << ff_log2_run[run_index]) { run_count -= 1 << ff_log2_run[run_index]; run_index++; - put_bits(&s->pb, 1, 1); + put_bits(&sc->pb, 1, 1); } - put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count); + put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count); if (run_index) run_index--; run_count = 0; @@ -103,21 +103,21 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", run_count, run_index, run_mode, x, - (int)put_bits_count(&s->pb)); + (int)put_bits_count(&sc->pb)); if (run_mode == 0) - put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits); + put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits); } } if (run_mode) { while (run_count >= 1 << ff_log2_run[run_index]) { run_count -= 1 << ff_log2_run[run_index]; run_index++; - put_bits(&s->pb, 1, 1); + put_bits(&sc->pb, 1, 1); } if (run_count) - put_bits(&s->pb, 1, 1); + put_bits(&sc->pb, 1, 1); } sc->run_index = run_index; -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".