From: mkver via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: mkver <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/mpeg12: Inline ff_mpeg1_clean_buffers() into its callers (PR #20942)
Date: Mon, 17 Nov 2025 15:24:04 -0000
Message-ID: <176339304499.25.7312549335973436586@2cb04c0e5124> (raw)
PR #20942 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20942
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20942.patch
>From fd5fbb41ccaf846a3dc1742ba65dfe6714a543aa Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Mon, 17 Nov 2025 15:35:38 +0100
Subject: [PATCH 1/3] avcodec/mpeg12: Inline ff_mpeg1_clean_buffers() into its
callers
This function is extremely small, so inlining it is appropriate (and
actually beneficial size-wise here). It furthermore allows to remove
the mpeg12codecs.h header and the mpeg12-encoders->mpeg12.o dependency.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/Makefile | 4 ++--
libavcodec/mpeg12.c | 10 ----------
libavcodec/mpeg12codecs.h | 29 -----------------------------
libavcodec/mpeg12dec.c | 7 +++++--
libavcodec/mpeg12enc.h | 8 ++++++++
libavcodec/mpegvideo_enc.c | 3 +--
6 files changed, 16 insertions(+), 45 deletions(-)
delete mode 100644 libavcodec/mpeg12codecs.h
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 49c284ef9e..3e6f000868 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -566,14 +566,14 @@ OBJS-$(CONFIG_MPC7_DECODER) += mpc7.o mpc.o
OBJS-$(CONFIG_MPC8_DECODER) += mpc8.o mpc.o
OBJS-$(CONFIG_MPEGVIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
OBJS-$(CONFIG_MPEG1VIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
-OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpeg12.o
+OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o
OBJS-$(CONFIG_MPEG1_CUVID_DECODER) += cuviddec.o
OBJS-$(CONFIG_MPEG1_V4L2M2M_DECODER) += v4l2_m2m_dec.o
OBJS-$(CONFIG_MPEG2_MMAL_DECODER) += mmaldec.o
OBJS-$(CONFIG_MPEG2_QSV_DECODER) += qsvdec.o
OBJS-$(CONFIG_MPEG2_QSV_ENCODER) += qsvenc_mpeg2.o
OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
-OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpeg12.o
+OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o
OBJS-$(CONFIG_MPEG2_CUVID_DECODER) += cuviddec.o
OBJS-$(CONFIG_MPEG2_MEDIACODEC_DECODER) += mediacodecdec.o
OBJS-$(CONFIG_MPEG2_VAAPI_ENCODER) += vaapi_encode_mpeg2.o
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 62a77b6806..61723f3a29 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -30,8 +30,6 @@
#include "libavutil/attributes.h"
#include "libavutil/thread.h"
-#include "mpegvideo.h"
-#include "mpeg12codecs.h"
#include "mpeg12data.h"
#include "mpeg12dec.h"
#include "mpegutils.h"
@@ -122,14 +120,6 @@ av_cold void ff_init_2d_vlc_rl(const uint16_t table_vlc[][2], RL_VLC_ELEM rl_vlc
}
}
-void ff_mpeg1_clean_buffers(MpegEncContext *s)
-{
- s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
- s->last_dc[1] = s->last_dc[0];
- s->last_dc[2] = s->last_dc[0];
- memset(s->last_mv, 0, sizeof(s->last_mv));
-}
-
/******************************************/
/* decoding */
diff --git a/libavcodec/mpeg12codecs.h b/libavcodec/mpeg12codecs.h
deleted file mode 100644
index f8cf5503e2..0000000000
--- a/libavcodec/mpeg12codecs.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * MPEG-1/2 codecs common code
- * Copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVCODEC_MPEG12CODECS_H
-#define AVCODEC_MPEG12CODECS_H
-
-#include "mpegvideo.h"
-
-void ff_mpeg1_clean_buffers(MpegEncContext *s);
-
-#endif /* AVCODEC_MPEG12CODECS_H */
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 3ea8d02e1b..58ff925bfd 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -50,7 +50,6 @@
#include "idctdsp.h"
#include "mpeg_er.h"
#include "mpeg12.h"
-#include "mpeg12codecs.h"
#include "mpeg12data.h"
#include "mpeg12dec.h"
#include "mpegutils.h"
@@ -1375,7 +1374,6 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
if (s->c.codec_id != AV_CODEC_ID_MPEG1VIDEO && s->c.mb_height > 2800/16)
skip_bits(&s->gb, 3);
- ff_mpeg1_clean_buffers(&s->c);
s->c.interlaced_dct = 0;
s->c.qscale = mpeg_get_qscale(&s->gb, s->c.q_scale_type);
@@ -1455,6 +1453,11 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
}
}
+ s->c.last_dc[0] = 128 << s->c.intra_dc_precision;
+ s->c.last_dc[1] = s->c.last_dc[0];
+ s->c.last_dc[2] = s->c.last_dc[0];
+ memset(s->c.last_mv, 0, sizeof(s->c.last_mv));
+
for (int mb_skip_run = 0;;) {
ret = mpeg_decode_mb(s, &mb_skip_run);
if (ret < 0)
diff --git a/libavcodec/mpeg12enc.h b/libavcodec/mpeg12enc.h
index a8aeadbb3e..97007be8fe 100644
--- a/libavcodec/mpeg12enc.h
+++ b/libavcodec/mpeg12enc.h
@@ -36,4 +36,12 @@ static inline void ff_mpeg1_encode_init(MPVEncContext *s)
s->c.c_dc_scale_table = ff_mpeg12_dc_scale_table[s->c.intra_dc_precision];
}
+static inline void ff_mpeg1_clean_buffers(MPVEncContext *s)
+{
+ s->c.last_dc[0] = 128 << s->c.intra_dc_precision;
+ s->c.last_dc[1] = s->c.last_dc[0];
+ s->c.last_dc[2] = s->c.last_dc[0];
+ memset(s->c.last_mv, 0, sizeof(s->c.last_mv));
+}
+
#endif /* AVCODEC_MPEG12ENC_H */
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index ce0ee4bb68..1ca163cac4 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -47,7 +47,6 @@
#include "avcodec.h"
#include "encode.h"
#include "idctdsp.h"
-#include "mpeg12codecs.h"
#include "mpeg12data.h"
#include "mpeg12enc.h"
#include "mpegvideo.h"
@@ -3148,7 +3147,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
case AV_CODEC_ID_MPEG2VIDEO:
if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) {
ff_mpeg1_encode_slice_header(s);
- ff_mpeg1_clean_buffers(&s->c);
+ ff_mpeg1_clean_buffers(s);
}
break;
#if CONFIG_H263P_ENCODER
--
2.49.1
>From e77d0b07f27ea4936d6d856197a52295f6232e83 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Mon, 17 Nov 2025 15:39:47 +0100
Subject: [PATCH 2/3] avcodec/Makefile: Remove mpegvideo_parser->mpeg12.o
dependency
Forgotten in 3ceffe783965767e62d59e8e68ecd265c98460ec.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/Makefile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3e6f000868..0cd2408865 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1275,8 +1275,7 @@ OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o h263.o \
mpeg4videodec.o mpeg4video.o \
ituh263dec.o h263data.o
OBJS-$(CONFIG_MPEGAUDIO_PARSER) += mpegaudio_parser.o
-OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o \
- mpeg12.o mpeg12data.o
+OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o mpeg12data.o
OBJS-$(CONFIG_OPUS_PARSER) += vorbis_data.o
OBJS-$(CONFIG_PNG_PARSER) += png_parser.o
OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o
--
2.49.1
>From 320cf95b1f1bc140b474c9609cce0f39b72463f2 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Mon, 17 Nov 2025 16:15:41 +0100
Subject: [PATCH 3/3] avcodec/mpegvideo: Move last_dc to
{H263Dec,Mpeg12Slice,MPVEnc}Context
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/dnxhdenc.c | 20 ++++++++++----------
libavcodec/h263dec.c | 6 +++---
libavcodec/h263dec.h | 3 +++
libavcodec/ituh263dec.c | 4 ++--
libavcodec/mjpegenc.c | 10 +++++-----
libavcodec/mpeg12dec.c | 22 ++++++++++++----------
libavcodec/mpeg12enc.c | 6 +++---
libavcodec/mpeg12enc.h | 6 +++---
libavcodec/mpeg4videodec.c | 16 ++++++++--------
libavcodec/mpegvideo.h | 1 -
libavcodec/mpegvideo_enc.c | 16 ++++++++--------
libavcodec/mpegvideoenc.h | 1 +
libavcodec/msmpeg4dec.c | 8 ++++----
libavcodec/rv10.c | 10 +++++-----
libavcodec/speedhqenc.c | 4 ++--
15 files changed, 69 insertions(+), 64 deletions(-)
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index edb58ba25f..7994b1d497 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -575,8 +575,8 @@ void dnxhd_encode_block(PutBitContext *pb, DNXHDEncContext *ctx,
int last_non_zero = 0;
int slevel, i, j;
- dnxhd_encode_dc(pb, ctx, block[0] - ctx->m.c.last_dc[n]);
- ctx->m.c.last_dc[n] = block[0];
+ dnxhd_encode_dc(pb, ctx, block[0] - ctx->m.last_dc[n]);
+ ctx->m.last_dc[n] = block[0];
for (i = 1; i <= last_index; i++) {
j = ctx->m.c.intra_scantable.permutated[i];
@@ -822,9 +822,9 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg,
LOCAL_ALIGNED_16(int16_t, block, [64]);
ctx = ctx->thread[threadnr];
- ctx->m.c.last_dc[0] =
- ctx->m.c.last_dc[1] =
- ctx->m.c.last_dc[2] = 1 << (ctx->bit_depth + 2);
+ ctx->m.last_dc[0] =
+ ctx->m.last_dc[1] =
+ ctx->m.last_dc[2] = 1 << (ctx->bit_depth + 2);
for (int mb_x = 0; mb_x < ctx->m.c.mb_width; mb_x++) {
unsigned mb = mb_y * ctx->m.c.mb_width + mb_x;
@@ -846,7 +846,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg,
qscale, &overflow);
ac_bits += dnxhd_calc_ac_bits(ctx, block, last_index);
- diff = block[0] - ctx->m.c.last_dc[n];
+ diff = block[0] - ctx->m.last_dc[n];
if (diff < 0)
nbits = av_log2_16bit(-2 * diff);
else
@@ -855,7 +855,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg,
av_assert1(nbits < ctx->bit_depth + 4);
dc_bits += ctx->cid_table->dc_bits[nbits] + nbits;
- ctx->m.c.last_dc[n] = block[0];
+ ctx->m.last_dc[n] = block[0];
if (avctx->mb_decision == FF_MB_DECISION_RD || !RC_VARIANCE) {
dnxhd_unquantize_c(ctx, block, i, qscale, last_index);
@@ -880,9 +880,9 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg,
init_put_bits(pb, (uint8_t *)arg + ctx->data_offset + ctx->slice_offs[jobnr],
ctx->slice_size[jobnr]);
- ctx->m.c.last_dc[0] =
- ctx->m.c.last_dc[1] =
- ctx->m.c.last_dc[2] = 1 << (ctx->bit_depth + 2);
+ ctx->m.last_dc[0] =
+ ctx->m.last_dc[1] =
+ ctx->m.last_dc[2] = 1 << (ctx->bit_depth + 2);
for (int mb_x = 0; mb_x < ctx->m.c.mb_width; mb_x++) {
unsigned mb = mb_y * ctx->m.c.mb_width + mb_x;
int qscale = ctx->mb_qscale[mb];
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 697fe7e572..b4c8aa38f5 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -247,9 +247,9 @@ static int decode_slice(H263DecContext *const h)
}
if (h->c.msmpeg4_version == MSMP4_V1) {
- h->c.last_dc[0] =
- h->c.last_dc[1] =
- h->c.last_dc[2] = 128;
+ h->last_dc[0] =
+ h->last_dc[1] =
+ h->last_dc[2] = 128;
}
ff_init_block_index(&h->c);
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index ace210b036..4c25a833cf 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -79,6 +79,9 @@ typedef struct H263DecContext {
/* MSMPEG4 specific */
int slice_height; ///< in macroblocks
+ /* MPEG-4 (Studio Profile), MSMPEG4 and RV10 specific */
+ int last_dc[3]; ///< last DC values, used by MPEG4, MSMPEG4V1, RV10
+
/* RV10 specific */
int rv10_version; ///< RV10 version: 0 or 3
int rv10_first_dc_coded[3];
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index dc8847b53b..a1472ce0a0 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -551,14 +551,14 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64],
if (CONFIG_RV10_DECODER && h->c.codec_id == AV_CODEC_ID_RV10) {
if (h->rv10_version == 3 && h->c.pict_type == AV_PICTURE_TYPE_I) {
int component = (n <= 3 ? 0 : n - 4 + 1);
- level = h->c.last_dc[component];
+ level = h->last_dc[component];
if (h->rv10_first_dc_coded[component]) {
int diff = ff_rv_decode_dc(h, n);
if (diff < 0)
return -1;
level += diff;
level = level & 0xff; /* handle wrap round */
- h->c.last_dc[component] = level;
+ h->last_dc[component] = level;
} else {
h->rv10_first_dc_coded[component] = 1;
}
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 214e2b0ec1..c5531b1c9f 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -279,7 +279,7 @@ int ff_mjpeg_encode_stuffing(MPVEncContext *const s)
fail:
for (int i = 0; i < 3; i++)
- s->c.last_dc[i] = 128 << s->c.intra_dc_precision;
+ s->last_dc[i] = 128 << s->c.intra_dc_precision;
return ret;
}
@@ -371,11 +371,11 @@ static void record_block(MPVEncContext *const s, int16_t block[], int n)
component = (n <= 3 ? 0 : (n&1) + 1);
table_id = (n <= 3 ? 0 : 1);
dc = block[0]; /* overflow is impossible */
- val = dc - s->c.last_dc[component];
+ val = dc - s->last_dc[component];
mjpeg_encode_coef(m, table_id, val, 0);
- s->c.last_dc[component] = dc;
+ s->last_dc[component] = dc;
/* AC coefs */
@@ -415,7 +415,7 @@ static void encode_block(MPVEncContext *const s, int16_t block[], int n)
/* DC coef */
component = (n <= 3 ? 0 : (n&1) + 1);
dc = block[0]; /* overflow is impossible */
- val = dc - s->c.last_dc[component];
+ val = dc - s->last_dc[component];
if (n < 4) {
ff_mjpeg_encode_dc(&s->pb, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance);
huff_size_ac = m->huff_size_ac_luminance;
@@ -425,7 +425,7 @@ static void encode_block(MPVEncContext *const s, int16_t block[], int n)
huff_size_ac = m->huff_size_ac_chrominance;
huff_code_ac = m->huff_code_ac_chrominance;
}
- s->c.last_dc[component] = dc;
+ s->last_dc[component] = dc;
/* AC coefs */
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 58ff925bfd..1caa8279bd 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -73,6 +73,8 @@ typedef struct Mpeg12SliceContext {
MPVContext c;
GetBitContext gb;
+ int last_dc[3]; ///< last DC values
+
DECLARE_ALIGNED_32(int16_t, block)[12][64];
} Mpeg12SliceContext;
@@ -326,9 +328,9 @@ static inline int mpeg2_decode_block_intra(Mpeg12SliceContext *const s,
component = (n & 1) + 1;
}
diff = decode_dc(&s->gb, component);
- dc = s->c.last_dc[component];
+ dc = s->last_dc[component];
dc += diff;
- s->c.last_dc[component] = dc;
+ s->last_dc[component] = dc;
block[0] = dc * (1 << (3 - s->c.intra_dc_precision));
ff_tlog(s->c.avctx, "dc=%d\n", block[0]);
mismatch = block[0] ^ 1;
@@ -517,7 +519,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s, int *mb_skip_run)
ret = ff_mpeg1_decode_block_intra(&s->gb,
s->c.intra_matrix,
s->c.intra_scantable.permutated,
- s->c.last_dc, s->block[i],
+ s->last_dc, s->block[i],
i, s->c.qscale);
if (ret < 0) {
av_log(s->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
@@ -713,7 +715,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s, int *mb_skip_run)
}
s->c.mb_intra = 0;
- s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
+ s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->c.intra_dc_precision;
if (HAS_CBP(mb_type)) {
s->c.bdsp.clear_blocks(s->block[0]);
@@ -1453,9 +1455,9 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
}
}
- s->c.last_dc[0] = 128 << s->c.intra_dc_precision;
- s->c.last_dc[1] = s->c.last_dc[0];
- s->c.last_dc[2] = s->c.last_dc[0];
+ s->last_dc[0] = 128 << s->c.intra_dc_precision;
+ s->last_dc[1] = s->last_dc[0];
+ s->last_dc[2] = s->last_dc[0];
memset(s->c.last_mv, 0, sizeof(s->c.last_mv));
for (int mb_skip_run = 0;;) {
@@ -1600,7 +1602,7 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
s->c.mb_intra = 0;
for (i = 0; i < 12; i++)
s->c.block_last_index[i] = -1;
- s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
+ s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->c.intra_dc_precision;
if (s->c.picture_structure == PICT_FRAME)
s->c.mv_type = MV_TYPE_16X16;
else
@@ -2793,7 +2795,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
s->flags & 0x10 ? ff_alternate_vertical_scan : ff_zigzag_direct,
m->idsp.idct_permutation);
- m->last_dc[0] = m->last_dc[1] = m->last_dc[2] = 1 << (7 + (s->flags & 3));
+ s->m.last_dc[0] = s->m.last_dc[1] = s->m.last_dc[2] = 128 << (s->flags & 3);
m->qscale = 1;
for (int y = 0; y < avctx->height; y += 16) {
@@ -2825,7 +2827,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
ret = ff_mpeg1_decode_block_intra(gb,
m->intra_matrix,
m->intra_scantable.permutated,
- m->last_dc, block[n],
+ s->m.last_dc, block[n],
n, m->qscale);
} else {
ret = mpeg2_decode_block_intra(&s->m, block[n], n);
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index fb480d0eec..4b9d186396 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -589,9 +589,9 @@ static void mpeg1_encode_block(MPVEncContext *const s, const int16_t block[], in
if (s->c.mb_intra) {
component = (n <= 3 ? 0 : (n & 1) + 1);
dc = block[0]; /* overflow is impossible */
- diff = dc - s->c.last_dc[component];
+ diff = dc - s->last_dc[component];
encode_dc(s, diff, component);
- s->c.last_dc[component] = dc;
+ s->last_dc[component] = dc;
i = 1;
if (s->c.intra_vlc_format)
table_vlc = ff_mpeg2_vlc_table;
@@ -936,7 +936,7 @@ static void mpeg12_encode_mb(MPVEncContext *const s, int16_t block[][64],
int motion_x, int motion_y)
{
if (!s->c.mb_intra)
- s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
+ s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->c.intra_dc_precision;
if (s->c.chroma_format == CHROMA_420)
mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6, 1);
else
diff --git a/libavcodec/mpeg12enc.h b/libavcodec/mpeg12enc.h
index 97007be8fe..e04c7dea38 100644
--- a/libavcodec/mpeg12enc.h
+++ b/libavcodec/mpeg12enc.h
@@ -38,9 +38,9 @@ static inline void ff_mpeg1_encode_init(MPVEncContext *s)
static inline void ff_mpeg1_clean_buffers(MPVEncContext *s)
{
- s->c.last_dc[0] = 128 << s->c.intra_dc_precision;
- s->c.last_dc[1] = s->c.last_dc[0];
- s->c.last_dc[2] = s->c.last_dc[0];
+ s->last_dc[0] = 128 << s->c.intra_dc_precision;
+ s->last_dc[1] = s->last_dc[0];
+ s->last_dc[2] = s->last_dc[0];
memset(s->c.last_mv, 0, sizeof(s->c.last_mv));
}
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 4a1385ea4d..e4a765d5ec 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -794,11 +794,11 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
{
- MPVContext *const s = &ctx->h.c;
+ H263DecContext *const h = &ctx->h;
/* Reset DC Predictors */
- s->last_dc[0] =
- s->last_dc[1] =
- s->last_dc[2] = 1 << (s->avctx->bits_per_raw_sample + ctx->dct_precision + s->intra_dc_precision - 1);
+ h->last_dc[0] =
+ h->last_dc[1] =
+ h->last_dc[2] = 1 << (h->c.avctx->bits_per_raw_sample + ctx->dct_precision + h->c.intra_dc_precision - 1);
}
/**
@@ -2196,12 +2196,12 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6
}
- h->c.last_dc[cc] += dct_diff;
+ h->last_dc[cc] += dct_diff;
if (ctx->mpeg_quant)
- block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision);
+ block[0] = h->last_dc[cc] * (8 >> h->c.intra_dc_precision);
else
- block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision) * (8 >> ctx->dct_precision);
+ block[0] = h->last_dc[cc] * (8 >> h->c.intra_dc_precision) * (8 >> ctx->dct_precision);
/* TODO: support mpeg_quant for AC coefficients */
block[0] = av_clip(block[0], min, max);
@@ -2283,7 +2283,7 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
return AVERROR_INVALIDDATA;
}
- h->c.last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));
+ h->last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));
rice_parameter = get_bits(&h->gb, 4);
if (rice_parameter == 0) {
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index a04166efa8..cb4b99acd3 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -133,7 +133,6 @@ typedef struct MpegEncContext {
*/
MPVWorkPicture cur_pic;
- int last_dc[3]; ///< last DC values for MPEG-1
int16_t *dc_val_base;
const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 1ca163cac4..4616b6cabc 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2643,13 +2643,13 @@ typedef struct MBBackup {
int mv[2][4][2];
int last_mv[2][2][2];
int mv_type, mv_dir;
- int last_dc[3];
int mb_intra, mb_skipped;
int qscale;
int block_last_index[8];
int interlaced_dct;
} c;
int mb_skip_run;
+ int last_dc[3];
int mv_bits, i_tex_bits, p_tex_bits, i_count, misc_bits, last_bits;
int dquant;
int esc3_level_length;
@@ -2667,7 +2667,7 @@ static inline void BEFORE ##_context_before_encode(DST_TYPE *const d, \
/* MPEG-1 */ \
d->mb_skip_run = s->mb_skip_run; \
for (int i = 0; i < 3; i++) \
- d->c.last_dc[i] = s->c.last_dc[i]; \
+ d->last_dc[i] = s->last_dc[i]; \
\
/* statistics */ \
d->mv_bits = s->mv_bits; \
@@ -2695,7 +2695,7 @@ static inline void AFTER ## _context_after_encode(DST_TYPE *const d, \
/* MPEG-1 */ \
d->mb_skip_run = s->mb_skip_run; \
for (int i = 0; i < 3; i++) \
- d->c.last_dc[i] = s->c.last_dc[i]; \
+ d->last_dc[i] = s->last_dc[i]; \
\
/* statistics */ \
d->mv_bits = s->mv_bits; \
@@ -3013,14 +3013,14 @@ static int encode_thread(AVCodecContext *c, void *arg){
for(i=0; i<3; i++){
/* init last dc values */
/* note: quant matrix value (8) is implied here */
- s->c.last_dc[i] = 128 << s->c.intra_dc_precision;
+ s->last_dc[i] = 128 << s->c.intra_dc_precision;
s->encoding_error[i] = 0;
}
if (s->c.codec_id == AV_CODEC_ID_AMV) {
- s->c.last_dc[0] = 128 * 8 / 13;
- s->c.last_dc[1] = 128 * 8 / 14;
- s->c.last_dc[2] = 128 * 8 / 14;
+ s->last_dc[0] = 128 * 8 / 13;
+ s->last_dc[1] = 128 * 8 / 14;
+ s->last_dc[2] = 128 * 8 / 14;
#if CONFIG_MPEG4_ENCODER
} else if (s->partitioned_frame) {
av_assert1(s->c.codec_id == AV_CODEC_ID_MPEG4);
@@ -3043,7 +3043,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
mb_y = ff_speedhq_mb_y_order_to_mb(mb_y_order, s->c.mb_height, &first_in_slice);
if (first_in_slice && mb_y_order != s->c.start_mb_y)
ff_speedhq_end_slice(s);
- s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 1024 << s->c.intra_dc_precision;
+ s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 1024 << s->c.intra_dc_precision;
} else {
mb_y = mb_y_order;
}
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index ee115c3611..95dbc899c0 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -139,6 +139,7 @@ typedef struct MPVEncContext {
int last_bits; ///< temp var used for calculating the above vars
int mb_skip_run;
+ int last_dc[3]; ///< last DC values
/* H.263 specific */
int gob_index;
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index d2249559c9..f2ab99ecb5 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -48,7 +48,7 @@
static const VLCElem *mv_tables[2];
-static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
+static inline int msmpeg4v1_pred_dc(H263DecContext *const h, int n,
int32_t **dc_val_ptr)
{
int i;
@@ -59,8 +59,8 @@ static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
i= n-3;
}
- *dc_val_ptr= &s->last_dc[i];
- return s->last_dc[i];
+ *dc_val_ptr= &h->last_dc[i];
+ return h->last_dc[i];
}
/****************************************/
@@ -588,7 +588,7 @@ static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
if (h->c.msmpeg4_version == MSMP4_V1) {
int32_t *dc_val;
- pred = msmpeg4v1_pred_dc(&h->c, n, &dc_val);
+ pred = msmpeg4v1_pred_dc(h, n, &dc_val);
level += pred;
/* update predictor */
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index b4545f7624..1958f36c98 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -129,11 +129,11 @@ static int rv10_decode_picture_header(H263DecContext *const h)
if (h->c.pict_type == AV_PICTURE_TYPE_I) {
if (h->rv10_version == 3) {
/* specific MPEG like DC coding not used */
- h->c.last_dc[0] = get_bits(&h->gb, 8);
- h->c.last_dc[1] = get_bits(&h->gb, 8);
- h->c.last_dc[2] = get_bits(&h->gb, 8);
- ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->c.last_dc[0],
- h->c.last_dc[1], h->c.last_dc[2]);
+ h->last_dc[0] = get_bits(&h->gb, 8);
+ h->last_dc[1] = get_bits(&h->gb, 8);
+ h->last_dc[2] = get_bits(&h->gb, 8);
+ ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->last_dc[0],
+ h->last_dc[1], h->last_dc[2]);
}
}
/* if multiple packets per frame are sent, the position at which
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index da7aba6ec9..3041c06864 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -172,9 +172,9 @@ static void encode_block(MPVEncContext *const s, const int16_t block[], int n)
/* DC coef */
component = (n <= 3 ? 0 : (n&1) + 1);
dc = block[0]; /* overflow is impossible */
- val = s->c.last_dc[component] - dc; /* opposite of most codecs */
+ val = s->last_dc[component] - dc; /* opposite of most codecs */
encode_dc(&s->pb, val, component);
- s->c.last_dc[component] = dc;
+ s->last_dc[component] = dc;
/* now quantify & encode AC coefs */
last_non_zero = 0;
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-11-17 15:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=176339304499.25.7312549335973436586@2cb04c0e5124 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git