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 2F1284BDEB for ; Tue, 16 Jul 2024 18:34:19 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5167068DB48; Tue, 16 Jul 2024 21:34:11 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 84B2A68DAD0 for ; Tue, 16 Jul 2024 21:33:59 +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=WRaFoATX; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 67F8A998 for ; Tue, 16 Jul 2024 19:16:37 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id apIfHEsWJUXW for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=13sCUGjR8+qncJEOf7ucR+c891l4HzQczWW3lmvr764=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WRaFoATXp5OS1RDBaoBV1svtrHWZAEnA/C3CtCw9u+VHWOwtTHIykXxJqVDF4+69f xuDTtrEq8Hi5LcSPMD+pnjyK+BL7Qu3iAbOevBXdPDdu6PE2qK56r8WSOHNZmlz71i QNCzvhewn87ctgZEchVTn/JE2XJKHfCAzWt2KEQXt7iJiqqv7hCSfDdzre9t63sIcq TFNVMNYlRxfW/otSiuzEYYFciSqRi05ZM2li72KuLWnP6PR91DtMzCCXqX0o3LoO83 3vgOBs1eQq2M2DfxKQxe58R8a8ge2ZXCGl36TyWTiWqaFBdG5Dohj9tyAY3desT4pT A65rr5GXVHEig== 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 71F1F4E16 for ; Tue, 16 Jul 2024 19:16:30 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 328363A2D11 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:37 +0200 Message-ID: <20240716171155.31838-22-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 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 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: All remaining accesses to them are for fields that have the same value in the main encoder context. --- libavcodec/ffv1enc.c | 57 ++++++++++++++++------------------- libavcodec/ffv1enc_template.c | 24 +++++++-------- 2 files changed, 37 insertions(+), 44 deletions(-) diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 3a6a0e6d90..ba378a54a4 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -269,13 +269,12 @@ 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 ring_size = s->context_model ? 3 : 2; + const int ring_size = f->context_model ? 3 : 2; int16_t *sample[3]; sc->run_index = 0; @@ -287,22 +286,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)) < 0) + if((ret = encode_line(f, sc, w, sample, plane_index, 8)) < 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)) < 0) + if((ret = encode_line(f, sc, w, sample, plane_index, f->bits_per_raw_sample)) < 0) return ret; } } @@ -908,8 +907,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]; @@ -942,7 +940,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 @@ -968,7 +966,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; @@ -1027,10 +1025,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; @@ -1046,7 +1042,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; @@ -1056,7 +1052,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; @@ -1071,26 +1067,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; } @@ -1206,12 +1202,11 @@ 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++) { - FFV1Context *fs = f->slice_context[i]; FFV1SliceContext *sc = &f->slices[i]; int bytes; @@ -1219,7 +1214,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, bytes = ff_rac_terminate(&sc->c, 1); } else { flush_put_bits(&sc->pb); // FIXME: nicer padding - bytes = fs->ac_byte_count + put_bytes_output(&sc->pb); + bytes = sc->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 c79146d619..0bb0070d37 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -23,8 +23,7 @@ #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, int w, TYPE *sample[3], int plane_index, int bits) { PlaneContext *const p = &sc->plane[plane_index]; @@ -36,12 +35,12 @@ RENAME(encode_line)(FFV1Context *f, if (f->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(f->avctx, 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(f->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } } @@ -73,7 +72,7 @@ RENAME(encode_line)(FFV1Context *f, diff = fold(diff, bits); if (f->ac != AC_GOLOMB_RICE) { - if (s->flags & AV_CODEC_FLAG_PASS1) { + if (f->flags & AV_CODEC_FLAG_PASS1) { put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat, sc->rc_stat2[p->quant_table_index][context]); } else { @@ -103,7 +102,7 @@ RENAME(encode_line)(FFV1Context *f, } } - ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", + ff_dlog(f->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", run_count, run_index, run_mode, x, (int)put_bits_count(&sc->pb)); @@ -126,17 +125,16 @@ 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]; - int lbd = s->bits_per_raw_sample <= 8; + 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; @@ -196,9 +194,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, sc, w, sample[p], (p + 1) / 2, 9); 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, sc, w, sample[p], (p + 1) / 2, bits + (sc->slice_coding_mode != 1)); if (ret < 0) return ret; } -- 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".