From patchwork Wed Jul 31 08:33:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50826 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:12d6:0:b0:489:2eb3:e4c4 with SMTP id 205csp315659vqs; Wed, 31 Jul 2024 01:33:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUGJD1J2HVGCxuIaKvb4NpePbp5YxnOlJj9B167t9T52kZs9uAMi4Yqurq3ej0K5eK+O81LenLgG4uLiAKng2YJCXhjbqC8HtBTqA== X-Google-Smtp-Source: AGHT+IGtLx3gI0URwKDJbGL+/dCZU7+68nOhbihX4/EEp+jI/EESjawDy5M9byoJpoo4HyujEQ+h X-Received: by 2002:a50:9b02:0:b0:5a2:a0d9:c1a6 with SMTP id 4fb4d7f45d1cf-5b0205d638fmr8835802a12.11.1722414821771; Wed, 31 Jul 2024 01:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722414821; cv=none; d=google.com; s=arc-20160816; b=mFtD2dH3zyp3N2h8/FU5LEb35sOziz7bqMQtiZpcMwN4PSWHNwPck1wrLgLNR7sO58 girt7jfvbEdqgpUzVjwVSg860xgg8kKV/KnQhDdyYksO8iULWDjvIEEaiKhrTgb/z/XA FSdK/HEQgofhsoBKoeMaEI7nZMQdYAU/+aNOroAo5KaN6Xjoh+4nxCs/2dqsF8dIJ49d 2MgMFVdwaR/s9+u1EV8Z5rWlTyWJMZQhfFK5s8y3Kmc511dMV8eLqGZIwn9wnXsstSQQ exneSZiYU6CktFxVGKOVQLaBviD6kJds5ndROZHQNUUlxLAPQhpd8Zc63wR2VK6sFwRE 4K5A== 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:dkim-signature:delivered-to; bh=uvYltWf2rQX7GZKqqbcPHU/rCLhMQ+/UIxDKsMx3DWU=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=UmfbDAGvJBiwguwHz9MG8ASTv2Q8lx140jXILci9iUH14R3dW8j5J5snC17UAH4ivD kr0rXOzXDkr6ubT/xxnKVHtRUC9tz8BtXqmCELkw+iybH8nTqFFai3WhLpuBuNKlD9yx w68rsaTrtNlK+m0/vbQGhanamFHT6M1kEKD8GESKqmbzlHhFNK3N9QYMA69gZRJuZ93G PFGNJ+rFnFFW2PtTJYkeoioXBH9FquIMBftvQ2TewHVYA9PNbfZA7jopE3P+llErfQ02 j0KRfkkIxFSmZHeAUUBqOmaRhpAaQ03bxaegzEuFCFsgxNNTtlrmcmenYTrGBTI19LYW k5Mw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=CZOKREZp; 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 4fb4d7f45d1cf-5ac6613da6bsi8564172a12.588.2024.07.31.01.33.41; Wed, 31 Jul 2024 01:33:41 -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; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=CZOKREZp; 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 0B74E68D6FD; Wed, 31 Jul 2024 11:33:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1764368D260 for ; Wed, 31 Jul 2024 11:33:30 +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=CZOKREZp; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 24FDF4DBC for ; Wed, 31 Jul 2024 10:33:29 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id B1FE3E660KbK for ; Wed, 31 Jul 2024 10:33:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1722414808; bh=whN4Je0yPhNhAYTQZMKpeV+eltcfkgfqQI5uHoXqAqg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CZOKREZpvAcwJ4CXiuQYkAGPHQtwQdsx+C6nsPCxbf+hQ161eKmeN3g3M+AZzbDS6 ctg25qdb6IFpMEfJMERI552QOW9Ydr6YP7Ss8BXRJZY8gPibWja+sVlsV7oTQyK7mg ZNnUJKjDcVmKDDXsmrsgjbgbsO6pybO54cELkEPlltG+Dl8MFo8TTA4iHGyQkMvJxe QTtr83HIP5XeAreNIGxjEjxfCzWWaduPbSVGiAxsYaMAEMrlkPvKL7Q/U9CfynqJTS fI3T4DX3BJ18w/rcOgsAcT0rZHK7mhNgxUwYXvTczbTOubtI7/UtyTsiO1jQum1857 JxKs39s9FtZjQ== 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 0C49A998 for ; Wed, 31 Jul 2024 10:33:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E5B433A0212 for ; Wed, 31 Jul 2024 10:33:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Jul 2024 10:33:09 +0200 Message-ID: <20240731083308.24396-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240724192335.GX4991@pb2> References: <20240724192335.GX4991@pb2> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 17/39] lavc/ffv1: always use the main context values of ac 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Vxcw4yLMjb67 It cannot change between slices. --- libavcodec/ffv1.c | 6 +++--- libavcodec/ffv1dec.c | 19 +++++++++---------- libavcodec/ffv1dec_template.c | 14 ++++++++------ libavcodec/ffv1enc.c | 11 ++++++----- libavcodec/ffv1enc_template.c | 12 +++++++----- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 06a77c3a26..581e775ae2 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -59,7 +59,7 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs) for (j = 0; j < f->plane_count; j++) { PlaneContext *const p = &fs->plane[j]; - if (fs->ac != AC_GOLOMB_RICE) { + if (f->ac != AC_GOLOMB_RICE) { if (!p->state) p->state = av_malloc_array(p->context_count, CONTEXT_SIZE * sizeof(uint8_t)); @@ -78,7 +78,7 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs) } } - if (fs->ac == AC_RANGE_CUSTOM_TAB) { + if (f->ac == AC_RANGE_CUSTOM_TAB) { //FIXME only redo if state_transition changed for (j = 1; j < 256; j++) { fs->c. one_state[ j] = f->state_transition[j]; @@ -167,7 +167,7 @@ void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs) for (i = 0; i < f->plane_count; i++) { PlaneContext *p = &fs->plane[i]; - if (fs->ac != AC_GOLOMB_RICE) { + if (f->ac != AC_GOLOMB_RICE) { if (f->initial_states[p->quant_table_index]) { memcpy(p->state, f->initial_states[p->quant_table_index], CONTEXT_SIZE * p->context_count); diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 8464697fd3..992b6596ab 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -94,10 +94,9 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state, return ret; } -static int is_input_end(FFV1Context *s, GetBitContext *gb) +static int is_input_end(RangeCoder *c, GetBitContext *gb, int ac) { - if (s->ac != AC_GOLOMB_RICE) { - RangeCoder *const c = &s->c; + if (ac != AC_GOLOMB_RICE) { if (c->overread > MAX_OVERREAD) return AVERROR_INVALIDDATA; } else { @@ -123,6 +122,7 @@ static int decode_plane(FFV1Context *f, uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride) { + const int ac = f->ac; int x, y; int16_t *sample[2]; sample[0] = sc->sample_buffer + 3; @@ -142,13 +142,13 @@ static int decode_plane(FFV1Context *f, sample[0][w] = sample[0][w - 1]; if (s->avctx->bits_per_raw_sample <= 8) { - int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8); + int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8, ac); if (ret < 0) return ret; for (x = 0; x < w; x++) src[x*pixel_stride + stride * y] = sample[1][x]; } else { - int ret = decode_line(f, s, sc, gb, w, sample, plane_index, s->avctx->bits_per_raw_sample); + int ret = decode_line(f, s, sc, gb, w, sample, plane_index, s->avctx->bits_per_raw_sample, ac); if (ret < 0) return ret; if (s->packed_at_lsb) { @@ -197,7 +197,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, av_assert0 ( (unsigned)sc->slice_x + (uint64_t)sc->slice_width <= f->width && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height); - if (fs->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23)) + if (f->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23)) return AVERROR_INVALIDDATA; for (unsigned i = 0; i < f->plane_count; i++) { @@ -284,7 +284,7 @@ static int decode_slice(AVCodecContext *c, void *arg) pdst->state = NULL; pdst->vlc_state = NULL; - if (fssrc->ac) { + if (f->ac) { pdst->state = av_malloc_array(CONTEXT_SIZE, psrc->context_count); memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count); } else { @@ -319,7 +319,7 @@ static int decode_slice(AVCodecContext *c, void *arg) x = sc->slice_x; y = sc->slice_y; - if (fs->ac == AC_GOLOMB_RICE) { + if (f->ac == AC_GOLOMB_RICE) { if (f->version == 3 && f->micro_version > 1 || f->version > 3) get_rac(&fs->c, (uint8_t[]) { 129 }); fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0; @@ -358,7 +358,7 @@ static int decode_slice(AVCodecContext *c, void *arg) p->data[3] + ps * x + y * p->linesize[3] }; decode_rgb_frame(f, fs, sc, &gb, planes, width, height, p->linesize); } - if (fs->ac != AC_GOLOMB_RICE && f->version > 2) { + if (f->ac != AC_GOLOMB_RICE && f->version > 2) { int v; get_rac(&fs->c, (uint8_t[]) { 129 }); v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec; @@ -791,7 +791,6 @@ static int read_header(FFV1Context *f) for (int j = 0; j < f->slice_count; j++) { FFV1Context *fs = f->slice_context[j]; FFV1SliceContext *sc = &f->slices[j]; - fs->ac = f->ac; fs->packed_at_lsb = f->packed_at_lsb; fs->slice_damaged = 0; diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index dbcd4861ac..2e1cad47ac 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -26,7 +26,8 @@ static av_always_inline int RENAME(decode_line)(FFV1Context *f, FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, - int w, TYPE *sample[2], int plane_index, int bits) + int w, TYPE *sample[2], int plane_index, int bits, + int ac) { PlaneContext *const p = &s->plane[plane_index]; RangeCoder *const c = &s->c; @@ -36,7 +37,7 @@ RENAME(decode_line)(FFV1Context *f, int run_mode = 0; int run_index = sc->run_index; - if (is_input_end(s, gb)) + if (is_input_end(c, gb, ac)) return AVERROR_INVALIDDATA; if (sc->slice_coding_mode == 1) { @@ -56,7 +57,7 @@ RENAME(decode_line)(FFV1Context *f, int diff, context, sign; if (!(x & 1023)) { - if (is_input_end(s, gb)) + if (is_input_end(c, gb, ac)) return AVERROR_INVALIDDATA; } @@ -70,7 +71,7 @@ RENAME(decode_line)(FFV1Context *f, av_assert2(context < p->context_count); - if (s->ac != AC_GOLOMB_RICE) { + if (ac != AC_GOLOMB_RICE) { diff = get_symbol_inline(c, p->state[context], 1); } else { if (context == 0 && run_mode == 0) @@ -142,6 +143,7 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f, int bits = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8; int offset = 1 << bits; int transparency = f->transparency; + int ac = f->ac; for (x = 0; x < 4; x++) { sample[x][0] = RENAME(sc->sample_buffer) + x * 2 * (w + 6) + 3; @@ -163,9 +165,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f, sample[p][1][-1]= sample[p][0][0 ]; sample[p][0][ w]= sample[p][0][w-1]; if (lbd && sc->slice_coding_mode == 0) - ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, 9); + ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, 9, ac); else - ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, bits + (sc->slice_coding_mode != 1)); + ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, bits + (sc->slice_coding_mode != 1), ac); if (ret < 0) return ret; } diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index fb373b598b..a6b9ac3d62 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -275,6 +275,7 @@ static int encode_plane(FFV1Context *f, int stride, int plane_index, int pixel_stride) { int x, y, i, ret; + const int ac = f->ac; const int ring_size = s->context_model ? 3 : 2; int16_t *sample[3]; sc->run_index = 0; @@ -290,7 +291,7 @@ static int encode_plane(FFV1Context *f, if (s->bits_per_raw_sample <= 8) { for (x = 0; x < w; x++) sample[0][x] = src[x * pixel_stride + stride * y]; - if((ret = encode_line(f, s, sc, w, sample, plane_index, 8)) < 0) + if((ret = encode_line(f, s, sc, w, sample, plane_index, 8, ac)) < 0) return ret; } else { if (s->packed_at_lsb) { @@ -302,7 +303,7 @@ static int encode_plane(FFV1Context *f, sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - s->bits_per_raw_sample); } } - if((ret = encode_line(f, s, sc, w, sample, plane_index, s->bits_per_raw_sample)) < 0) + if((ret = encode_line(f, s, sc, w, sample, plane_index, s->bits_per_raw_sample, ac)) < 0) return ret; } } @@ -1053,7 +1054,7 @@ retry: if (f->version > 2) { encode_slice_header(f, fs, sc); } - if (fs->ac == AC_GOLOMB_RICE) { + if (f->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(&sc->pb, fs->c.bytestream_start + fs->ac_byte_count, @@ -1085,7 +1086,7 @@ retry: if (ret < 0) { av_assert0(sc->slice_coding_mode == 0); - if (fs->version < 4 || !fs->ac) { + if (fs->version < 4 || !f->ac) { av_log(c, AV_LOG_ERROR, "Buffer too small\n"); return ret; } @@ -1210,7 +1211,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, FFV1SliceContext *sc = &f->slices[i]; int bytes; - if (fs->ac != AC_GOLOMB_RICE) { + if (f->ac != AC_GOLOMB_RICE) { bytes = ff_rac_terminate(&fs->c, 1); } else { flush_put_bits(&sc->pb); // FIXME: nicer padding diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 29b50637f4..9f9d658da1 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -25,7 +25,8 @@ static av_always_inline int RENAME(encode_line)(FFV1Context *f, FFV1Context *s, FFV1SliceContext *sc, - int w, TYPE *sample[3], int plane_index, int bits) + int w, TYPE *sample[3], int plane_index, int bits, + int ac) { PlaneContext *const p = &s->plane[plane_index]; RangeCoder *const c = &s->c; @@ -34,7 +35,7 @@ RENAME(encode_line)(FFV1Context *f, int run_count = 0; int run_mode = 0; - if (s->ac != AC_GOLOMB_RICE) { + if (ac != AC_GOLOMB_RICE) { if (c->bytestream_end - c->bytestream < w * 35) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; @@ -72,7 +73,7 @@ RENAME(encode_line)(FFV1Context *f, diff = fold(diff, bits); - if (s->ac != AC_GOLOMB_RICE) { + if (ac != AC_GOLOMB_RICE) { if (s->flags & AV_CODEC_FLAG_PASS1) { put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat, s->rc_stat2[p->quant_table_index][context]); @@ -134,6 +135,7 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, int x, y, p, i; const int ring_size = s->context_model ? 3 : 2; TYPE *sample[4][3]; + const int ac = f->ac; int lbd = s->bits_per_raw_sample <= 8; int packed = !src[1]; int bits = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8; @@ -196,9 +198,9 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, sample[p][0][-1] = sample[p][1][0 ]; sample[p][1][ w] = sample[p][1][w-1]; if (lbd && sc->slice_coding_mode == 0) - ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, 9); + ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, 9, ac); else - ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, bits + (sc->slice_coding_mode != 1)); + ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, bits + (sc->slice_coding_mode != 1), ac); if (ret < 0) return ret; } From patchwork Wed Jul 31 08:50:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50827 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:12d6:0:b0:489:2eb3:e4c4 with SMTP id 205csp323114vqs; Wed, 31 Jul 2024 01:50:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVMl7oMCQE28pZyNzSY7a502p/pSxjLWOaTF1UMA++KwjgoIzc8q7x8tyFkFuKJP0QPA6L3t+L3gsihYmBtRJVACGfF81qEO6lCMA== X-Google-Smtp-Source: AGHT+IH2sXa7We5dZ2ivjp5bkjCpJmFuEYHylOk51+tdJKiTez4X3WqMLYKPromkdE6p3mHWrndS X-Received: by 2002:a19:e056:0:b0:52c:e17c:cd7b with SMTP id 2adb3069b0e04-5309b28045bmr10353182e87.22.1722415834308; Wed, 31 Jul 2024 01:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722415834; cv=none; d=google.com; s=arc-20160816; b=EamBKOXcbsiH772ZNrCVxR4SFzRDwtYs2stoIdPJdC15P9+NoXOX+m3IIAsfYGiYw/ ebzcXYU5teS9e4NmsFpOfkhV8HVSB2EhldT+kfDbBw3W9l1viu4mXBTvgTl7DILc+f/e WhuYpMhSsJEY70dahkDgFjFwMR0IJPl06fvVkhMYa6/5MsrTmhM8Wl+gYWE1DI3F7nL7 m5iPX/oVhE+tyDOn3/uIWGaSQHQKvrhwqd11w0l/sTRpJdLTY2LHDkwLFGs7ynufkelh BW9qJj5xvncY/bpUlGbOSNdAXkxLns9d3A2QCCJ4rjU73iA7IjQbRpnwix/A2aNK1nuw 1S7g== 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:dkim-signature:delivered-to; bh=JKTfasCcSI/52PPMCEBIfqyiFcjOPqBhs7ptnDaPR2Y=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=loROjdLnYLbB8VKMTO+r0sIcfTiYxZxF0vzp9/XJsHgUZz0EEwWAPVp1n4KsPz/eGC rKRB58p+gd6om7q/Bb/IAwJ1mtdGh9HrVR9etQBr24nyxw7e98BQl8kDGhfeIl+PTZ6Z sJhQUGr5ALa7yqqOr+jCIjUEwuumzufCVz14dWp5wCg5YzKK5+C2553MxjWjsGqwWG7G gmo5IhtET5lyX2HNWK2MfinLnysYsZHvzDLH/PV1XyNlwQnTBM7H82M0eJu/gt7yaJaK dWlnx6vuq4eeSLq3uz0cEsWrPgb2cjJBRW3zqSHNFTkt7KAJLWV+G+0ohgnSM/eR5Bwp rIew==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=Fcie4krO; 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 a640c23a62f3a-a7acac8db93si878183366b.768.2024.07.31.01.50.33; Wed, 31 Jul 2024 01:50:34 -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; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=Fcie4krO; 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 B0D0D68D720; Wed, 31 Jul 2024 11:50:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7348568D3FA for ; Wed, 31 Jul 2024 11:50:24 +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=Fcie4krO; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 0F6B94DE2 for ; Wed, 31 Jul 2024 10:50:24 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id FVyAxSQBczyb for ; Wed, 31 Jul 2024 10:50:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1722415823; bh=kD2uUvaEuNx5JfhN3JxTqeqCRK+hgBpHdkw2TYw0ilE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Fcie4krOnEF6t4/FbU0rg3xe5L7n3cPZm1PL8424JzeKerXg12VYHEE7NcAN0O/Gw IvBbBwGYWKWrb3q6K66X0Wm34OQX2lE0nwMysg/LbNyY6uoXRxiEDWIhkL0XPHp3Fc eGubF+4qlj1oXi0j4tRmJ2Vb9quBOxBQZQWnpL85r/0GyrwjKOVS44O091lKRPFcKv DwMWqqxrk/GEVwt6Mu3m7e/aG2XQFu4B12dMNh3cq5U6w/T0Ucw1qhLS478ZUcilgr e0dMnUKxZf7GXaf2lLmIJvtwpA1pS0pyLOTMAZn4owive9WmcPLAP3RWxY2sAoQFmr Eq13+gWBRb3QQ== 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 5AC62998 for ; Wed, 31 Jul 2024 10:50:23 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3F80E3A0212 for ; Wed, 31 Jul 2024 10:50:23 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Jul 2024 10:50:11 +0200 Message-ID: <20240731085010.18792-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240724194251.GB4991@pb2> References: <20240724194251.GB4991@pb2> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 22/39] lavc/ffv1enc: stop using per-slice FFV1Context 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: DWrSUQ3qJbg1 All remaining accesses to them are for fields that have the same value in the main encoder context. --- libavcodec/ffv1enc.c | 55 +++++++++++++++++------------------ libavcodec/ffv1enc_template.c | 29 +++++++++--------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index b861210462..23d757e5c6 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -269,14 +269,14 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState *const state, #define RENAME(name) name ## 32 #include "ffv1enc_template.c" -static int encode_plane(FFV1Context *f, - FFV1Context *s, FFV1SliceContext *sc, +static int encode_plane(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride) { int x, y, i, ret; const int ac = f->ac; - const int ring_size = s->context_model ? 3 : 2; + const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1); + const int ring_size = f->context_model ? 3 : 2; int16_t *sample[3]; sc->run_index = 0; @@ -288,22 +288,22 @@ static int encode_plane(FFV1Context *f, sample[0][-1]= sample[1][0 ]; sample[1][ w]= sample[1][w-1]; - if (s->bits_per_raw_sample <= 8) { + if (f->bits_per_raw_sample <= 8) { for (x = 0; x < w; x++) sample[0][x] = src[x * pixel_stride + stride * y]; - if((ret = encode_line(f, s, sc, w, sample, plane_index, 8, ac)) < 0) + if((ret = encode_line(f, sc, f->avctx, w, sample, plane_index, 8, ac, pass1)) < 0) return ret; } else { - if (s->packed_at_lsb) { + if (f->packed_at_lsb) { for (x = 0; x < w; x++) { sample[0][x] = ((uint16_t*)(src + stride*y))[x]; } } else { for (x = 0; x < w; x++) { - sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - s->bits_per_raw_sample); + sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - f->bits_per_raw_sample); } } - if((ret = encode_line(f, s, sc, w, sample, plane_index, s->bits_per_raw_sample, ac)) < 0) + if((ret = encode_line(f, sc, f->avctx, w, sample, plane_index, f->bits_per_raw_sample, ac, pass1)) < 0) return ret; } } @@ -909,8 +909,7 @@ slices_ok: return 0; } -static void encode_slice_header(FFV1Context *f, FFV1Context *fs, - FFV1SliceContext *sc) +static void encode_slice_header(FFV1Context *f, FFV1SliceContext *sc) { RangeCoder *c = &sc->c; uint8_t state[CONTEXT_SIZE]; @@ -943,7 +942,7 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs, } } -static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc, +static void choose_rct_params(const FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[3], const int stride[3], int w, int h) { #define NB_Y_COEFF 15 @@ -969,7 +968,7 @@ static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc, int stat[NB_Y_COEFF] = {0}; int x, y, i, p, best; int16_t *sample[3]; - int lbd = fs->bits_per_raw_sample <= 8; + int lbd = f->bits_per_raw_sample <= 8; for (y = 0; y < h; y++) { int lastr=0, lastg=0, lastb=0; @@ -1028,10 +1027,8 @@ static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc, static int encode_slice(AVCodecContext *c, void *arg) { - FFV1Context *fs = *(void **)arg; - FFV1Context *f = fs->avctx->priv_data; - const int si = (FFV1Context**)arg - f->slice_context; - FFV1SliceContext *sc = &f->slices[si]; + FFV1SliceContext *sc = arg; + FFV1Context *f = c->priv_data; int width = sc->slice_width; int height = sc->slice_height; int x = sc->slice_x; @@ -1047,7 +1044,7 @@ static int encode_slice(AVCodecContext *c, void *arg) sc->slice_coding_mode = 0; if (f->version > 3) { - choose_rct_params(fs, sc, planes, p->linesize, width, height); + choose_rct_params(f, sc, planes, p->linesize, width, height); } else { sc->slice_rct_by_coef = 1; sc->slice_rct_ry_coef = 1; @@ -1057,7 +1054,7 @@ retry: if (f->key_frame) ff_ffv1_clear_slice_state(f, sc); if (f->version > 2) { - encode_slice_header(f, fs, sc); + encode_slice_header(f, sc); } if (f->ac == AC_GOLOMB_RICE) { sc->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&sc->c, f->version > 2) : 0; @@ -1072,26 +1069,26 @@ retry: const int cx = x >> f->chroma_h_shift; const int cy = y >> f->chroma_v_shift; - ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); + ret = encode_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); if (f->chroma_planes) { - ret |= encode_plane(f, fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); - ret |= encode_plane(f, fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); + ret |= encode_plane(f, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); + ret |= encode_plane(f, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } if (f->transparency) - ret |= encode_plane(f, fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1); + ret |= encode_plane(f, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1); } else if (c->pix_fmt == AV_PIX_FMT_YA8) { - ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); - ret |= encode_plane(f, fs, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); + ret = encode_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); + ret |= encode_plane(f, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); } else if (f->use32bit) { - ret = encode_rgb_frame32(f, fs, sc, planes, width, height, p->linesize); + ret = encode_rgb_frame32(f, sc, planes, width, height, p->linesize); } else { - ret = encode_rgb_frame(f, fs, sc, planes, width, height, p->linesize); + ret = encode_rgb_frame(f, sc, planes, width, height, p->linesize); } if (ret < 0) { av_assert0(sc->slice_coding_mode == 0); - if (fs->version < 4 || !f->ac) { + if (f->version < 4 || !f->ac) { av_log(c, AV_LOG_ERROR, "Buffer too small\n"); return ret; } @@ -1207,8 +1204,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, sc->c.bytestream_end = sc->c.bytestream_start + len; } } - avctx->execute(avctx, encode_slice, &f->slice_context[0], NULL, - f->slice_count, sizeof(void *)); + avctx->execute(avctx, encode_slice, f->slices, NULL, + f->slice_count, sizeof(*f->slices)); buf_p = pkt->data; for (i = 0; i < f->slice_count; i++) { diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 24dcf2a68e..bc14926ab9 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -23,10 +23,10 @@ #include "ffv1_template.c" static av_always_inline int -RENAME(encode_line)(FFV1Context *f, - FFV1Context *s, FFV1SliceContext *sc, +RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc, + void *logctx, int w, TYPE *sample[3], int plane_index, int bits, - int ac) + int ac, int pass1) { PlaneContext *const p = &sc->plane[plane_index]; RangeCoder *const c = &sc->c; @@ -37,12 +37,12 @@ RENAME(encode_line)(FFV1Context *f, if (ac != AC_GOLOMB_RICE) { if (c->bytestream_end - c->bytestream < w * 35) { - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + av_log(logctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } } else { if (put_bytes_left(&sc->pb, 0) < w * 4) { - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + av_log(logctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } } @@ -74,7 +74,7 @@ RENAME(encode_line)(FFV1Context *f, diff = fold(diff, bits); if (ac != AC_GOLOMB_RICE) { - if (s->flags & AV_CODEC_FLAG_PASS1) { + if (pass1) { put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat, sc->rc_stat2[p->quant_table_index][context]); } else { @@ -104,7 +104,7 @@ RENAME(encode_line)(FFV1Context *f, } } - ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", + ff_dlog(logctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", run_count, run_index, run_mode, x, (int)put_bits_count(&sc->pb)); @@ -127,18 +127,18 @@ RENAME(encode_line)(FFV1Context *f, return 0; } -static int RENAME(encode_rgb_frame)(FFV1Context *f, - FFV1Context *s, FFV1SliceContext *sc, +static int RENAME(encode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], int w, int h, const int stride[4]) { int x, y, p, i; - const int ring_size = s->context_model ? 3 : 2; + const int ring_size = f->context_model ? 3 : 2; TYPE *sample[4][3]; const int ac = f->ac; - int lbd = s->bits_per_raw_sample <= 8; + const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1); + int lbd = f->bits_per_raw_sample <= 8; int packed = !src[1]; - int bits = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8; + int bits = f->bits_per_raw_sample > 0 ? f->bits_per_raw_sample : 8; int offset = 1 << bits; int transparency = f->transparency; int packed_size = (3 + transparency)*2; @@ -198,9 +198,10 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, sample[p][0][-1] = sample[p][1][0 ]; sample[p][1][ w] = sample[p][1][w-1]; if (lbd && sc->slice_coding_mode == 0) - ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, 9, ac); + ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2, 9, ac, pass1); else - ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, bits + (sc->slice_coding_mode != 1), ac); + ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2, + bits + (sc->slice_coding_mode != 1), ac, pass1); if (ret < 0) return ret; }