* [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice
@ 2025-06-15 16:53 ffmpegagent
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 01/47] " Andreas Rheinhardt
` (46 more replies)
0 siblings, 47 replies; 48+ messages in thread
From: ffmpegagent @ 2025-06-15 16:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: mkver
This patchset is a mix of mpegvideo-related patches. The second half
(beginning with avcodec/ituh263dec: Simplify AIC handling) mostly has a
theme, namely improving dc_val and ac_val handling in mpegvideo. The first
is just other stuff which I found while investigating the latter.
Andreas Rheinhardt (47):
avcodec/mpeg4videodec: Don't zero blocks twice
avcodec/rv10: Perform RV20 initialization during init
avcodec/rv10: Perform RV20 check only for RV20
avcodec/ituh263dec: Don't process unnecessarily many coefficients
avcodec/ituh263dec: Remove redundant store
avcodec/ituh263enc: Don't use array unnecessarily
avcodec/ituh263enc: Fix indentation
avcodec/mpeg12dec: Don't store block_last_index unnecessarily
avcodec/rv10: Avoid indirection when reading VLC codes
avcodec/mpeg_er: Mark ff_mpeg_er_init() as av_cold
avcodec/mpegvideo_enc: Remove always-true branch
avcodec/motion_est: Fix indentation
avcodec/svq1enc: Don't free scratchbuf upon error
avcodec/svq1enc: Allocate motion_val{8,16} during init
avcodec/svq1enc: Stop calling ff_mpv_common_init()
avcodec/svq1enc: Remove write-only c_block_{width,height}
avcodec/svq1enc: Set MpegEncContext.avctx only once
avcodec/svq1enc: Don't initialize unneeded block_index
configure: Factor mpegvideoencdsp out of mpegvideoenc
configure: Relax svq1enc->mpegvideoenc dependency
configure: Relax diracdec->mpegvideoenc dependency
configure: Relax snowenc->mpegvideoenc dependency
avcodec/mpegvideo: Don't reset thread_context ptrs unnecessarily
avcodec/mpegvideo: Don't zero unnecessarily
avcodec/mpegvideo: Defer init of enc slice ctxs in
ff_mpv_common_init()
avcodec/mpegvideo_enc: Simplify allocating non-slice buffers
avcodec/ituh263dec: Simplify AIC handling
avcodec/ituh263enc: Simplify AIC handling
avcodec/flvenc: Combine writing bits
avcodec/flvenc: Move ff_flv2_encode_ac_esc() to ituh263enc.c
avcodec/mpegvideo: Redo resetting intra table entry
avcodec/mpegvideo: Avoid {a,d}c_val[{1,2}]
avcodec/mpegvideo: Provide alignment hint to compiler
avcodec/mpegvideo: Don't reset AC values of upper-left luma block
avcodec/mpegvideo: Combine stores
avcodec/mpeg4video: Don't use ac_val[1], ac_val[2] when cleaning
buffers
avcodec/mpegvideo: Only use a single ac_val pointer
avcodec/mpegvideo: Allocate ac_val jointly
avcodec/mpegvideo: Zero-init mbintra_table
avcodec/mpegvideo: Only keep MpegEncContext.dc_val[0]
avcodec/vc1: Only keep mb_type[0]
avcodec/mpegvideo: Allocate dc_val for each encoder slice
avcodec/{ituh263,mpeg4video}enc: Simplify out-of-slice DC prediction
avcodec/mpeg4video: Move ff_mpeg4_pred_dc() to decoder
avcodec/ituh263enc: Simplify encoding umotion vectors
avcodec/mpegvideo: Reduce stack usage when copying MpegEncContext
avcodec/mpeg4videoenc: Fix data race when using AC prediction
configure | 9 +-
libavcodec/Makefile | 9 +-
libavcodec/aarch64/Makefile | 4 +-
libavcodec/arm/Makefile | 4 +-
libavcodec/flvenc.c | 19 ----
libavcodec/flvenc.h | 4 -
libavcodec/h263.c | 5 +-
libavcodec/h263.h | 8 ++
libavcodec/h263dec.c | 3 +-
libavcodec/h263enc.h | 1 +
libavcodec/ituh263dec.c | 47 ++++-----
libavcodec/ituh263enc.c | 181 ++++++++++++++++++-----------------
libavcodec/mathops.h | 1 +
libavcodec/mathtables.c | 39 ++++++++
libavcodec/me_cmp.c | 36 -------
libavcodec/me_cmp.h | 5 -
libavcodec/mips/Makefile | 6 +-
libavcodec/motion_est.c | 180 +++++++++++++++++-----------------
libavcodec/mpeg12.c | 4 +-
libavcodec/mpeg12dec.c | 3 -
libavcodec/mpeg4video.c | 13 ++-
libavcodec/mpeg4video.h | 45 ---------
libavcodec/mpeg4videodec.c | 65 ++++++++++---
libavcodec/mpeg4videoenc.c | 40 +++++++-
libavcodec/mpeg_er.c | 10 +-
libavcodec/mpegvideo.c | 155 +++++++++++++++---------------
libavcodec/mpegvideo.h | 4 +-
libavcodec/mpegvideo_enc.c | 179 +++++++++++++++++++---------------
libavcodec/mpegvideoencdsp.c | 2 +-
libavcodec/msmpeg4.c | 3 +-
libavcodec/ppc/Makefile | 2 +-
libavcodec/riscv/Makefile | 4 +-
libavcodec/rv10.c | 53 +++++-----
libavcodec/svq1enc.c | 65 ++++---------
libavcodec/vc1.h | 2 +-
libavcodec/vc1_block.c | 138 +++++++++++++-------------
libavcodec/vc1_loopfilter.c | 10 +-
libavcodec/vc1_mc.c | 8 +-
libavcodec/vc1_pred.c | 14 +--
libavcodec/vc1dec.c | 4 +-
libavcodec/x86/Makefile | 6 +-
tests/checkasm/Makefile | 2 +-
tests/checkasm/checkasm.c | 2 +-
43 files changed, 697 insertions(+), 697 deletions(-)
base-commit: fb65ecbc9b805571e5ff707b935c343803137e54
Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-98%2Fmkver%2Fmpv_dc_val-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-98/mkver/mpv_dc_val-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/98
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 01/47] avcodec/mpeg4videodec: Don't zero blocks twice
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
@ 2025-06-15 16:53 ` Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 02/47] avcodec/rv10: Perform RV20 initialization during init Andreas Rheinhardt
` (45 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videodec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 313d73157f..32b2dec1d6 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1745,11 +1745,11 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
}
} while (cbpc == 20);
- s->bdsp.clear_blocks(s->block[0]);
dquant = cbpc & 8;
s->mb_intra = ((cbpc & 4) != 0);
if (s->mb_intra)
goto intra;
+ s->bdsp.clear_blocks(s->block[0]);
if (s->pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 02/47] avcodec/rv10: Perform RV20 initialization during init
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 01/47] " Andreas Rheinhardt
@ 2025-06-15 16:53 ` Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 03/47] avcodec/rv10: Perform RV20 check only for RV20 Andreas Rheinhardt
` (44 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv10.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 482af8e52a..1aae92a358 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -284,7 +284,6 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
skip_bits(&s->gb, 5);
s->h263_aic = s->pict_type == AV_PICTURE_TYPE_I;
- s->modified_quant = 1;
if (!s->avctx->lowres)
s->loop_filter = 1;
@@ -370,6 +369,10 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
s->h263_long_vectors = avctx->extradata[3] & 1;
rv->sub_id = AV_RB32A(avctx->extradata + 4);
+ if (avctx->codec_id == AV_CODEC_ID_RV20) {
+ s->modified_quant = 1;
+ s->chroma_qscale_table = ff_h263_chroma_qscale_table;
+ }
major_ver = RV_GET_MAJOR_VER(rv->sub_id);
minor_ver = RV_GET_MINOR_VER(rv->sub_id);
@@ -475,9 +478,6 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
}
- if (s->modified_quant)
- s->chroma_qscale_table = ff_h263_chroma_qscale_table;
-
ff_set_qscale(s, s->qscale);
s->rv10_first_dc_coded[0] = 0;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 03/47] avcodec/rv10: Perform RV20 check only for RV20
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 01/47] " Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 02/47] avcodec/rv10: Perform RV20 initialization during init Andreas Rheinhardt
@ 2025-06-15 16:53 ` Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 04/47] avcodec/ituh263dec: Don't process unnecessarily many coefficients Andreas Rheinhardt
` (43 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv10.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 1aae92a358..7f7f7aeba2 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -284,6 +284,13 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
skip_bits(&s->gb, 5);
s->h263_aic = s->pict_type == AV_PICTURE_TYPE_I;
+ if (s->h263_aic) {
+ s->y_dc_scale_table =
+ s->c_dc_scale_table = ff_aic_dc_scale_table;
+ } else {
+ s->y_dc_scale_table =
+ s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
+ }
if (!s->avctx->lowres)
s->loop_filter = 1;
@@ -470,13 +477,6 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
}
start_mb_x = s->mb_x;
s->resync_mb_y = s->mb_y;
- if (s->h263_aic) {
- s->y_dc_scale_table =
- s->c_dc_scale_table = ff_aic_dc_scale_table;
- } else {
- s->y_dc_scale_table =
- s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
- }
ff_set_qscale(s, s->qscale);
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 04/47] avcodec/ituh263dec: Don't process unnecessarily many coefficients
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (2 preceding siblings ...)
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 03/47] avcodec/rv10: Perform RV20 check only for RV20 Andreas Rheinhardt
@ 2025-06-15 16:53 ` Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 05/47] avcodec/ituh263dec: Remove redundant store Andreas Rheinhardt
` (42 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Overriding the number of coefficients is only necessary if
ac_pred is in used, not for h263_aic alone (for which only
the DC coefficient is predicted) as it is done here.
And since d50635cd247e17fe16c63219b9ae80d45a8185b1
the H.263 unquantize-intra functions override the number of
coefficients in case of ac_pred, so we don't have to do this here.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263dec.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 21c78f3cb5..5e1d15e557 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -542,10 +542,10 @@ static int h263_decode_block(MpegEncContext * s, int16_t * block,
scan_table = s->intra_scantable.permutated;
if (s->h263_aic && s->mb_intra) {
+ i = 0;
if (!coded)
goto not_coded;
rl = &ff_rl_intra_aic;
- i = 0;
if (s->ac_pred) {
if (s->h263_aic_dir)
scan_table = s->permutated_intra_v_scantable; /* left */
@@ -672,7 +672,6 @@ retry:
if (s->mb_intra && s->h263_aic) {
not_coded:
h263_pred_acdc(s, block, n);
- i = 63;
}
s->block_last_index[n] = i;
return 0;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 05/47] avcodec/ituh263dec: Remove redundant store
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (3 preceding siblings ...)
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 04/47] avcodec/ituh263dec: Don't process unnecessarily many coefficients Andreas Rheinhardt
@ 2025-06-15 16:53 ` Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 06/47] avcodec/ituh263enc: Don't use array unnecessarily Andreas Rheinhardt
` (41 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263dec.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 5e1d15e557..896556edfb 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -434,15 +434,16 @@ end:
static void h263_decode_dquant(MpegEncContext *s){
static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
+ int qscale;
if(s->modified_quant){
if(get_bits1(&s->gb))
- s->qscale= ff_modified_quant_tab[get_bits1(&s->gb)][ s->qscale ];
+ qscale = ff_modified_quant_tab[get_bits1(&s->gb)][s->qscale];
else
- s->qscale= get_bits(&s->gb, 5);
+ qscale = get_bits(&s->gb, 5);
}else
- s->qscale += quant_tab[get_bits(&s->gb, 2)];
- ff_set_qscale(s, s->qscale);
+ qscale = s->qscale + quant_tab[get_bits(&s->gb, 2)];
+ ff_set_qscale(s, qscale);
}
static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 06/47] avcodec/ituh263enc: Don't use array unnecessarily
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (4 preceding siblings ...)
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 05/47] avcodec/ituh263dec: Remove redundant store Andreas Rheinhardt
@ 2025-06-15 16:53 ` Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 07/47] avcodec/ituh263enc: Fix indentation Andreas Rheinhardt
` (40 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263enc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 4fdf9cf402..a1eee8cded 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -615,7 +615,6 @@ static void h263_encode_mb(MPVEncContext *const s,
int cbpc, cbpy, i, cbp, pred_x, pred_y;
int16_t pred_dc;
int16_t rec_intradc[6];
- int16_t *dc_ptr[6];
const int interleaved_stats = s->c.avctx->flags & AV_CODEC_FLAG_PASS1;
if (!s->c.mb_intra) {
@@ -709,9 +708,10 @@ static void h263_encode_mb(MPVEncContext *const s,
/* Predict DC */
for(i=0; i<6; i++) {
int16_t level = block[i][0];
+ int16_t *dc_ptr;
int scale = i < 4 ? s->c.y_dc_scale : s->c.c_dc_scale;
- pred_dc = h263_pred_dc(s, i, &dc_ptr[i]);
+ pred_dc = h263_pred_dc(s, i, &dc_ptr);
level -= pred_dc;
/* Quant */
if (level >= 0)
@@ -740,7 +740,7 @@ static void h263_encode_mb(MPVEncContext *const s,
rec_intradc[i] = 2047;
/* Update AC/DC tables */
- *dc_ptr[i] = rec_intradc[i];
+ *dc_ptr = rec_intradc[i];
/* AIC can change CBP */
if (s->c.block_last_index[i] > 0 ||
(s->c.block_last_index[i] == 0 && level !=0))
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 07/47] avcodec/ituh263enc: Fix indentation
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (5 preceding siblings ...)
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 06/47] avcodec/ituh263enc: Don't use array unnecessarily Andreas Rheinhardt
@ 2025-06-15 16:53 ` Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 08/47] avcodec/mpeg12dec: Don't store block_last_index unnecessarily Andreas Rheinhardt
` (39 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263enc.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index a1eee8cded..ab6edafd4d 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -505,22 +505,22 @@ static void h263_encode_block(MPVEncContext *const s, int16_t block[], int n)
code = get_rl_index(rl, last, run, level);
put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
if (code == rl->n) {
- if(!CONFIG_FLV_ENCODER || s->c.h263_flv <= 1){
- put_bits(&s->pb, 1, last);
- put_bits(&s->pb, 6, run);
-
- av_assert2(slevel != 0);
-
- if(level < 128)
- put_sbits(&s->pb, 8, slevel);
- else{
- put_bits(&s->pb, 8, 128);
- put_sbits(&s->pb, 5, slevel);
- put_sbits(&s->pb, 6, slevel>>5);
- }
- }else{
+ if (!CONFIG_FLV_ENCODER || s->c.h263_flv <= 1) {
+ put_bits(&s->pb, 1, last);
+ put_bits(&s->pb, 6, run);
+
+ av_assert2(slevel != 0);
+
+ if (level < 128) {
+ put_sbits(&s->pb, 8, slevel);
+ } else {
+ put_bits(&s->pb, 8, 128);
+ put_sbits(&s->pb, 5, slevel);
+ put_sbits(&s->pb, 6, slevel>>5);
+ }
+ } else {
ff_flv2_encode_ac_esc(&s->pb, slevel, level, run, last);
- }
+ }
} else {
put_bits(&s->pb, 1, sign);
}
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 08/47] avcodec/mpeg12dec: Don't store block_last_index unnecessarily
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (6 preceding siblings ...)
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 07/47] avcodec/ituh263enc: Fix indentation Andreas Rheinhardt
@ 2025-06-15 16:53 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 09/47] avcodec/rv10: Avoid indirection when reading VLC codes Andreas Rheinhardt
` (38 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:53 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Given that the MPEG-1/2 decoders unquantize the blocks
on their own, block_last_index is only used to signal
to ff_mpv_reconstruct_mb() whether a block is skipped
or not; but this is only checked for inter macroblocks,
so it is unnecessary to set block_last_index for intra
macroblocks.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12.c | 4 ++--
libavcodec/mpeg12dec.c | 3 ---
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 3056c53c7c..62a77b6806 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -276,7 +276,7 @@ end:
}
if (i > MAX_INDEX)
- i = AVERROR_INVALIDDATA;
+ return AVERROR_INVALIDDATA;
- return i;
+ return 0;
}
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 9cf1bb9b28..5d2719d0f0 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -377,7 +377,6 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s,
check_scantable_index(s, i);
- s->block_last_index[n] = i;
return 0;
}
@@ -518,8 +517,6 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
s->mb_x, s->mb_y);
return ret;
}
-
- s->block_last_index[i] = ret;
}
}
} else {
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 09/47] avcodec/rv10: Avoid indirection when reading VLC codes
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (7 preceding siblings ...)
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 08/47] avcodec/mpeg12dec: Don't store block_last_index unnecessarily Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 10/47] avcodec/mpeg_er: Mark ff_mpeg_er_init() as av_cold Andreas Rheinhardt
` (37 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv10.c | 31 +++++++++++++------------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 7f7f7aeba2..9f4dea6141 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -78,16 +78,16 @@ static const uint16_t rv_chrom_len_count[15] = {
1, 2, 4, 0, 8, 0, 16, 0, 32, 0, 64, 0, 128, 0, 256,
};
-static VLC rv_dc_lum, rv_dc_chrom;
+static VLCElem rv_dc_lum[1472], rv_dc_chrom[992];
int ff_rv_decode_dc(MpegEncContext *s, int n)
{
int code;
if (n < 4) {
- code = get_vlc2(&s->gb, rv_dc_lum.table, DC_VLC_BITS, 2);
+ code = get_vlc2(&s->gb, rv_dc_lum, DC_VLC_BITS, 2);
} else {
- code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2);
+ code = get_vlc2(&s->gb, rv_dc_chrom, DC_VLC_BITS, 2);
if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
return -1;
@@ -306,7 +306,8 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
return s->mb_width * s->mb_height - mb_pos;
}
-static av_cold void rv10_build_vlc(VLC *vlc, const uint16_t len_count[15],
+static av_cold void rv10_build_vlc(VLCElem vlc[], int table_size,
+ const uint16_t len_count[15],
const uint8_t sym_rl[][2], int sym_rl_elems)
{
uint16_t syms[MAX_VLC_ENTRIES];
@@ -323,32 +324,26 @@ static av_cold void rv10_build_vlc(VLC *vlc, const uint16_t len_count[15],
for (unsigned tmp = nb_lens + len_count[i]; nb_lens < tmp; nb_lens++)
lens[nb_lens] = i + 2;
av_assert1(nb_lens == nb_syms);
- ff_vlc_init_from_lengths(vlc, DC_VLC_BITS, nb_lens, lens, 1,
- syms, 2, 2, 0, VLC_INIT_STATIC_OVERLONG, NULL);
+ ff_vlc_init_table_from_lengths(vlc, table_size, DC_VLC_BITS, nb_lens,
+ lens, 1, syms, 2, 2, 0, 0);
}
static av_cold void rv10_init_static(void)
{
- static VLCElem table[1472 + 992];
-
- rv_dc_lum.table = table;
- rv_dc_lum.table_allocated = 1472;
- rv10_build_vlc(&rv_dc_lum, rv_lum_len_count,
+ rv10_build_vlc(rv_dc_lum, FF_ARRAY_ELEMS(rv_dc_lum), rv_lum_len_count,
rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len));
for (int i = 0; i < 1 << (DC_VLC_BITS - 7 /* Length of skip prefix */); i++) {
/* All codes beginning with 0x7F have the same length and value.
* Modifying the table directly saves us the useless subtables. */
- rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i].sym = 255;
- rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i].len = 18;
+ rv_dc_lum[(0x7F << (DC_VLC_BITS - 7)) + i].sym = 255;
+ rv_dc_lum[(0x7F << (DC_VLC_BITS - 7)) + i].len = 18;
}
- rv_dc_chrom.table = &table[1472];
- rv_dc_chrom.table_allocated = 992;
- rv10_build_vlc(&rv_dc_chrom, rv_chrom_len_count,
+ rv10_build_vlc(rv_dc_chrom, FF_ARRAY_ELEMS(rv_dc_chrom), rv_chrom_len_count,
rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len) - 2);
for (int i = 0; i < 1 << (DC_VLC_BITS - 9 /* Length of skip prefix */); i++) {
/* Same as above. */
- rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i].sym = 255;
- rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i].len = 18;
+ rv_dc_chrom[(0x1FE << (DC_VLC_BITS - 9)) + i].sym = 255;
+ rv_dc_chrom[(0x1FE << (DC_VLC_BITS - 9)) + i].len = 18;
}
}
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 10/47] avcodec/mpeg_er: Mark ff_mpeg_er_init() as av_cold
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (8 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 09/47] avcodec/rv10: Avoid indirection when reading VLC codes Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 11/47] avcodec/mpegvideo_enc: Remove always-true branch Andreas Rheinhardt
` (36 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg_er.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c
index 4b171354c7..0b919f0ced 100644
--- a/libavcodec/mpeg_er.c
+++ b/libavcodec/mpeg_er.c
@@ -96,7 +96,7 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
ff_mpv_reconstruct_mb(s, s->block);
}
-int ff_mpeg_er_init(MpegEncContext *s)
+av_cold int ff_mpeg_er_init(MpegEncContext *s)
{
ERContext *er = &s->er;
int mb_array_size = s->mb_height * s->mb_stride;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 11/47] avcodec/mpegvideo_enc: Remove always-true branch
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (9 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 10/47] avcodec/mpeg_er: Mark ff_mpeg_er_init() as av_cold Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 12/47] avcodec/motion_est: Fix indentation Andreas Rheinhardt
` (35 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Always-true since 1c40a179222f638e88c8e7b1a374753a00b0f979
which made 4863671d888273392e9dcc2429f3852c00330498 superfluous.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 46901fc506..af1e77cfec 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1824,10 +1824,8 @@ static int select_input_picture(MPVMainEncContext *const m)
ret = av_frame_ref(s->new_pic, m->reordered_input_picture[0]->f);
if (ret < 0)
goto fail;
- for (int i = 0; i < MPV_MAX_PLANES; i++) {
- if (s->new_pic->data[i])
- s->new_pic->data[i] += INPLACE_OFFSET;
- }
+ for (int i = 0; i < MPV_MAX_PLANES; i++)
+ s->new_pic->data[i] += INPLACE_OFFSET;
}
s->c.cur_pic.ptr = m->reordered_input_picture[0];
m->reordered_input_picture[0] = NULL;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 12/47] avcodec/motion_est: Fix indentation
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (10 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 11/47] avcodec/mpegvideo_enc: Remove always-true branch Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 13/47] avcodec/svq1enc: Don't free scratchbuf upon error Andreas Rheinhardt
` (34 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Forgotten after 919e749772d09900b41877e21ccb994fab0013ab.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/motion_est.c | 180 ++++++++++++++++++++--------------------
1 file changed, 90 insertions(+), 90 deletions(-)
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index 93aa909fb5..333048d1c8 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -118,64 +118,64 @@ static av_always_inline int cmp_direct_inline(MPVEncContext *const s, const int
const uint8_t * const * const src = c->src[src_index];
int d;
//FIXME check chroma 4mv, (no crashes ...)
- av_assert2(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));
- if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){
- const int time_pp = s->c.pp_time;
- const int time_pb = s->c.pb_time;
- const int mask= 2*qpel+1;
- if (s->c.mv_type == MV_TYPE_8X8) {
- int i;
- for(i=0; i<4; i++){
- int fx = c->direct_basis_mv[i][0] + hx;
- int fy = c->direct_basis_mv[i][1] + hy;
- int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));
- int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));
- int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
- int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
-
- uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);
- if(qpel){
- c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);
- c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);
- }else{
- c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);
- c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);
- }
- }
- }else{
- int fx = c->direct_basis_mv[0][0] + hx;
- int fy = c->direct_basis_mv[0][1] + hy;
- int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);
- int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);
- int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
- int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
-
- if(qpel){
- c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);
- c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);
- c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);
- c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);
- c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);
- c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);
- c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);
- c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);
- }else{
- av_assert2((fx>>1) + 16*s->c.mb_x >= -16);
- av_assert2((fy>>1) + 16*s->c.mb_y >= -16);
- av_assert2((fx>>1) + 16*s->c.mb_x <= s->c.width);
- av_assert2((fy>>1) + 16*s->c.mb_y <= s->c.height);
- av_assert2((bx>>1) + 16*s->c.mb_x >= -16);
- av_assert2((by>>1) + 16*s->c.mb_y >= -16);
- av_assert2((bx>>1) + 16*s->c.mb_x <= s->c.width);
- av_assert2((by>>1) + 16*s->c.mb_y <= s->c.height);
-
- c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
- c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
+ av_assert2(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));
+ if (x >= c->xmin && hx <= c->xmax << (qpel + 1) &&
+ y >= c->ymin && hy <= c->ymax << (qpel + 1)) {
+ const int time_pp = s->c.pp_time;
+ const int time_pb = s->c.pb_time;
+ const int mask = 2 * qpel + 1;
+ if (s->c.mv_type == MV_TYPE_8X8) {
+ for(int i = 0; i < 4; ++i) {
+ int fx = c->direct_basis_mv[i][0] + hx;
+ int fy = c->direct_basis_mv[i][1] + hy;
+ int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0] * (time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));
+ int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1] * (time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));
+ int fxy = (fx & mask) + ((fy & mask) << (qpel + 1));
+ int bxy = (bx & mask) + ((by & mask) << (qpel + 1));
+
+ uint8_t *dst = c->temp + 8 * (i & 1) + 8 * stride * (i >> 1);
+ if (qpel) {
+ c->qpel_put[1][fxy](dst, ref[0] + (fx >> 2) + (fy >> 2) * stride, stride);
+ c->qpel_avg[1][bxy](dst, ref[8] + (bx >> 2) + (by >> 2) * stride, stride);
+ } else {
+ c->hpel_put[1][fxy](dst, ref[0] + (fx >> 1) + (fy >> 1) * stride, stride, 8);
+ c->hpel_avg[1][bxy](dst, ref[8] + (bx >> 1) + (by >> 1) * stride, stride, 8);
}
}
- d = cmp_func(s, c->temp, src[0], stride, 16);
- }else
- d= 256*256*256*32;
+ } else {
+ int fx = c->direct_basis_mv[0][0] + hx;
+ int fy = c->direct_basis_mv[0][1] + hy;
+ int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0] * (time_pb - time_pp)/time_pp);
+ int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1] * (time_pb - time_pp)/time_pp);
+ int fxy = (fx & mask) + ((fy & mask) << (qpel + 1));
+ int bxy = (bx & mask) + ((by & mask) << (qpel + 1));
+
+ if (qpel) {
+ c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);
+ c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);
+ c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);
+ c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);
+ c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);
+ c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);
+ c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);
+ c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);
+ } else {
+ av_assert2((fx >> 1) + 16 * s->c.mb_x >= -16);
+ av_assert2((fy >> 1) + 16 * s->c.mb_y >= -16);
+ av_assert2((fx >> 1) + 16 * s->c.mb_x <= s->c.width);
+ av_assert2((fy >> 1) + 16 * s->c.mb_y <= s->c.height);
+ av_assert2((bx >> 1) + 16 * s->c.mb_x >= -16);
+ av_assert2((by >> 1) + 16 * s->c.mb_y >= -16);
+ av_assert2((bx >> 1) + 16 * s->c.mb_x <= s->c.width);
+ av_assert2((by >> 1) + 16 * s->c.mb_y <= s->c.height);
+
+ c->hpel_put[0][fxy](c->temp, ref[0] + (fx >> 1) + (fy >> 1) * stride, stride, 16);
+ c->hpel_avg[0][bxy](c->temp, ref[8] + (bx >> 1) + (by >> 1) * stride, stride, 16);
+ }
+ }
+ d = cmp_func(s, c->temp, src[0], stride, 16);
+ } else
+ d = 256 * 256 * 256 * 32;
return d;
}
@@ -192,42 +192,42 @@ static av_always_inline int cmp_inline(MPVEncContext *const s, const int x, cons
const uint8_t * const * const src = c->src[src_index];
int d;
//FIXME check chroma 4mv, (no crashes ...)
- int uvdxy; /* no, it might not be used uninitialized */
- if(dxy){
- if(qpel){
- if (h << size == 16) {
- c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride); //FIXME prototype (add h)
- } else if (size == 0 && h == 8) {
- c->qpel_put[1][dxy](c->temp , ref[0] + x + y*stride , stride);
- c->qpel_put[1][dxy](c->temp + 8, ref[0] + x + y*stride + 8, stride);
- } else
- av_assert2(0);
- if(chroma){
- int cx= hx/2;
- int cy= hy/2;
- cx= (cx>>1)|(cx&1);
- cy= (cy>>1)|(cy&1);
- uvdxy= (cx&1) + 2*(cy&1);
- // FIXME x/y wrong, but MPEG-4 qpel is sick anyway, we should drop as much of it as possible in favor for H.264
- }
- }else{
- c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h);
- if(chroma)
- uvdxy= dxy | (x&1) | (2*(y&1));
+ int uvdxy; /* no, it might not be used uninitialized */
+ if (dxy) {
+ if (qpel) {
+ if (h << size == 16) {
+ c->qpel_put[size][dxy](c->temp, ref[0] + x + y * stride, stride); //FIXME prototype (add h)
+ } else if (size == 0 && h == 8) {
+ c->qpel_put[1][dxy](c->temp , ref[0] + x + y * stride , stride);
+ c->qpel_put[1][dxy](c->temp + 8, ref[0] + x + y * stride + 8, stride);
+ } else
+ av_assert2(0);
+ if (chroma) {
+ int cx = hx / 2;
+ int cy = hy / 2;
+ cx = (cx >> 1) | (cx & 1);
+ cy = (cy >> 1) | (cy & 1);
+ uvdxy = (cx & 1) + 2 * (cy & 1);
+ // FIXME x/y wrong, but MPEG-4 qpel is sick anyway, we should drop as much of it as possible in favor for H.264
}
- d = cmp_func(s, c->temp, src[0], stride, h);
- }else{
- d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);
- if(chroma)
- uvdxy= (x&1) + 2*(y&1);
- }
- if(chroma){
- uint8_t * const uvtemp= c->temp + 16*stride;
- c->hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
- c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
- d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1);
- d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1);
+ } else {
+ c->hpel_put[size][dxy](c->temp, ref[0] + x + y * stride, stride, h);
+ if (chroma)
+ uvdxy = dxy | (x & 1) | (2 * (y & 1));
}
+ d = cmp_func(s, c->temp, src[0], stride, h);
+ } else {
+ d = cmp_func(s, src[0], ref[0] + x + y * stride, stride, h);
+ if (chroma)
+ uvdxy = (x & 1) + 2 * (y & 1);
+ }
+ if (chroma) {
+ uint8_t *const uvtemp = c->temp + 16 * stride;
+ c->hpel_put[size + 1][uvdxy](uvtemp , ref[1] + (x >> 1) + (y >> 1) * uvstride, uvstride, h >> 1);
+ c->hpel_put[size + 1][uvdxy](uvtemp + 8, ref[2] + (x >> 1) + (y >> 1) * uvstride, uvstride, h >> 1);
+ d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h >> 1);
+ d += chroma_cmp_func(s, uvtemp + 8, src[2], uvstride, h >> 1);
+ }
return d;
}
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 13/47] avcodec/svq1enc: Don't free scratchbuf upon error
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (11 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 12/47] avcodec/motion_est: Fix indentation Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 14/47] avcodec/svq1enc: Allocate motion_val{8, 16} during init Andreas Rheinhardt
` (33 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Forgotten in 65015003f5c4b83a8202abfa7420ccf37cde6ce3;
after said commit, freeing scratchbuf on error in svq1_encode_frame()
could lead to segfaults lateron, because the buffer will not
be allocated again.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1enc.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 3b8738c14f..dae931fb10 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -681,7 +681,6 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
av_freep(&s->motion_val8[j]);
av_freep(&s->motion_val16[j]);
}
- av_freep(&s->scratchbuf);
return -1;
}
}
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 14/47] avcodec/svq1enc: Allocate motion_val{8, 16} during init
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (12 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 13/47] avcodec/svq1enc: Don't free scratchbuf upon error Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 15/47] avcodec/svq1enc: Stop calling ff_mpv_common_init() Andreas Rheinhardt
` (32 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It only depends upon the dimensions (which do not change).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1enc.c | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index dae931fb10..948a7c41eb 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -350,17 +350,6 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
FF_LAMBDA_SCALE / 2 >>
FF_LAMBDA_SHIFT;
- if (!s->motion_val8[plane]) {
- s->motion_val8[plane] = av_mallocz((s2->b8_stride *
- block_height * 2 + 2) *
- 2 * sizeof(int16_t));
- s->motion_val16[plane] = av_mallocz((s2->mb_stride *
- (block_height + 2) + 1) *
- 2 * sizeof(int16_t));
- if (!s->motion_val8[plane] || !s->motion_val16[plane])
- return AVERROR(ENOMEM);
- }
-
s->m.mb_type = s->mb_type;
// dummies, to avoid segfaults
@@ -620,6 +609,19 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
if (ret < 0)
return ret;
+ for (size_t plane = 0; plane < FF_ARRAY_ELEMS(s->motion_val16); ++plane) {
+ const int shift = plane ? 2 : 0;
+ unsigned block_height = ((s->frame_height >> shift) + 15U) / 16;
+ unsigned block_width = ((s->frame_width >> shift) + 15U) / 16;
+
+ s->motion_val8[plane] = av_calloc((2 * block_width + 1) * block_height * 2 + 2,
+ 2 * sizeof(int16_t));
+ s->motion_val16[plane] = av_calloc((block_width + 1) * (block_height + 2) + 1,
+ 2 * sizeof(int16_t));
+ if (!s->motion_val8[plane] || !s->motion_val16[plane])
+ return AVERROR(ENOMEM);
+ }
+
s->m.c.picture_structure = PICT_FRAME;
s->m.me.temp =
s->m.me.scratchpad = av_mallocz((avctx->width + 64) *
@@ -675,14 +677,8 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
pict->linesize[i],
s->current_picture->linesize[i]);
emms_c();
- if (ret < 0) {
- int j;
- for (j = 0; j < i; j++) {
- av_freep(&s->motion_val8[j]);
- av_freep(&s->motion_val16[j]);
- }
- return -1;
- }
+ if (ret < 0)
+ return ret;
}
// align_put_bits(&pb);
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 15/47] avcodec/svq1enc: Stop calling ff_mpv_common_init()
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (13 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 14/47] avcodec/svq1enc: Allocate motion_val{8, 16} during init Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 16/47] avcodec/svq1enc: Remove write-only c_block_{width, height} Andreas Rheinhardt
` (31 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It is not really needed, as none of the buffers allocated
in ff_mpv_common_init() are used lateron; in fact, ff_mpv_common_init()
is called with MpegEncContext.width and height equal to zero
(as well as encoding equal to zero, so that the error resilience
parts are initialized...), so that all the buffers are too small
anyway.
The call to ff_mpv_common_init() has been added in commit
f6774f905fb3cfdc319523ac640be30b14c1bc55 in order to allocate
{current,last,new}_picture.f (an AVFrame). Yet this is unnecessary
since 7814dd77aa61703e3d43fc72bfaf6a9fbc42ff9c.
The only task that ff_mpv_common_init() does that may be used
is initializing the HpelDSPContext embedded in the MpegEncContext.
In fact, it was not initialized before
f6774f905fb3cfdc319523ac640be30b14c1bc55 and not initializing
it passes FATE, yet I can't prove that it is indeed unnecessary.
Therefore it is still initialized and used instead of
SVQ1EncContext.hdsp.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1enc.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 948a7c41eb..e3061baff4 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -62,7 +62,6 @@ typedef struct SVQ1EncContext {
MPVEncContext m;
AVCodecContext *avctx;
MECmpContext mecc;
- HpelDSPContext hdsp;
AVFrame *current_picture;
AVFrame *last_picture;
@@ -468,10 +467,10 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
dxy = (mx & 1) + 2 * (my & 1);
- s->hdsp.put_pixels_tab[0][dxy](temp + 16*stride,
- ref + (mx >> 1) +
- stride * (my >> 1),
- stride, 16);
+ s2->hdsp.put_pixels_tab[0][dxy](temp + 16*stride,
+ ref + (mx >> 1) +
+ stride * (my >> 1),
+ stride, 16);
score[1] += encode_block(s, src + 16 * x, temp + 16*stride,
decoded, stride, 5, 64, lambda, 0);
@@ -482,7 +481,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
score[2] += SVQ1_BLOCK_SKIP_LEN * lambda;
if (score[2] < score[best] && mx == 0 && my == 0) {
best = 2;
- s->hdsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
+ s2->hdsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
put_bits(pb, SVQ1_BLOCK_SKIP_LEN, SVQ1_BLOCK_SKIP_CODE);
}
}
@@ -511,7 +510,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
ff_copy_bits(pb, reorder_buffer[best][i],
count[best][i]);
if (best == 0)
- s->hdsp.put_pixels_tab[0][0](decoded, temp, stride, 16);
+ s2->hdsp.put_pixels_tab[0][0](decoded, temp, stride, 16);
}
s2->first_slice_line = 0;
}
@@ -533,9 +532,6 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx)
av_freep(&s->dummy);
av_freep(&s->scratchbuf);
- s->m.mb_type = NULL;
- ff_mpv_common_end(&s->m.c);
-
for (i = 0; i < 3; i++) {
av_freep(&s->motion_val8[i]);
av_freep(&s->motion_val16[i]);
@@ -571,7 +567,7 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- ff_hpeldsp_init(&s->hdsp, avctx->flags);
+ ff_hpeldsp_init(&s->m.c.hdsp, avctx->flags);
ff_me_cmp_init(&s->mecc, avctx);
ret = ff_me_init(&s->m.me, avctx, &s->mecc, 0);
if (ret < 0)
@@ -605,10 +601,6 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
s->avctx = avctx;
s->m.c.avctx = avctx;
- ret = ff_mpv_common_init(&s->m.c);
- if (ret < 0)
- return ret;
-
for (size_t plane = 0; plane < FF_ARRAY_ELEMS(s->motion_val16); ++plane) {
const int shift = plane ? 2 : 0;
unsigned block_height = ((s->frame_height >> shift) + 15U) / 16;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 16/47] avcodec/svq1enc: Remove write-only c_block_{width, height}
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (14 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 15/47] avcodec/svq1enc: Stop calling ff_mpv_common_init() Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 17/47] avcodec/svq1enc: Set MpegEncContext.avctx only once Andreas Rheinhardt
` (30 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1enc.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index e3061baff4..cdcf1de712 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -80,10 +80,6 @@ typedef struct SVQ1EncContext {
int y_block_width;
int y_block_height;
- /* U & V plane (C planes) block dimensions */
- int c_block_width;
- int c_block_height;
-
DECLARE_ALIGNED(16, int16_t, encoded_block_levels)[6][7][256];
uint16_t *mb_type;
@@ -595,9 +591,6 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
s->y_block_width = (s->frame_width + 15) / 16;
s->y_block_height = (s->frame_height + 15) / 16;
- s->c_block_width = (s->frame_width / 4 + 15) / 16;
- s->c_block_height = (s->frame_height / 4 + 15) / 16;
-
s->avctx = avctx;
s->m.c.avctx = avctx;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 17/47] avcodec/svq1enc: Set MpegEncContext.avctx only once
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (15 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 16/47] avcodec/svq1enc: Remove write-only c_block_{width, height} Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 18/47] avcodec/svq1enc: Don't initialize unneeded block_index Andreas Rheinhardt
` (29 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It is already set during init.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1enc.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index cdcf1de712..0caed73097 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -320,7 +320,6 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
block_height = (height + 15) / 16;
if (s->pict_type == AV_PICTURE_TYPE_P) {
- s2->avctx = s->avctx;
s2->last_pic.data[0] = ref_plane;
s2->linesize =
s2->last_pic.linesize[0] =
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 18/47] avcodec/svq1enc: Don't initialize unneeded block_index
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (16 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 17/47] avcodec/svq1enc: Set MpegEncContext.avctx only once Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 19/47] configure: Factor mpegvideoencdsp out of mpegvideoenc Andreas Rheinhardt
` (28 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The motion estimation code only uses block_index[0..3],
so only initialize that (just like estimate_motion_thread()
in mpegvideo_enc.c).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1enc.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 0caed73097..0816252c2f 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -290,8 +290,6 @@ static void init_block_index(MpegEncContext *const s)
s->block_index[1]= s->b8_stride*(s->mb_y*2 ) + 1 + s->mb_x*2;
s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) + s->mb_x*2;
s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) + 1 + s->mb_x*2;
- s->block_index[4]= s->mb_stride*(s->mb_y + 1) + s->b8_stride*s->mb_height*2 + s->mb_x;
- s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x;
}
static int svq1_encode_plane(SVQ1EncContext *s, int plane,
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 19/47] configure: Factor mpegvideoencdsp out of mpegvideoenc
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (17 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 18/47] avcodec/svq1enc: Don't initialize unneeded block_index Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 20/47] configure: Relax svq1enc->mpegvideoenc dependency Andreas Rheinhardt
` (27 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This will allow to relax the dependency on mpegvideoenc
for several codecs.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
configure | 3 ++-
libavcodec/Makefile | 4 ++--
libavcodec/aarch64/Makefile | 4 ++--
libavcodec/arm/Makefile | 4 ++--
libavcodec/mathops.h | 1 +
libavcodec/mathtables.c | 39 ++++++++++++++++++++++++++++++++++++
libavcodec/me_cmp.c | 36 ---------------------------------
libavcodec/me_cmp.h | 5 -----
libavcodec/mips/Makefile | 6 +++---
libavcodec/mpegvideoencdsp.c | 2 +-
libavcodec/ppc/Makefile | 2 +-
libavcodec/riscv/Makefile | 4 ++--
libavcodec/x86/Makefile | 6 +++---
tests/checkasm/Makefile | 2 +-
tests/checkasm/checkasm.c | 2 +-
15 files changed, 60 insertions(+), 60 deletions(-)
diff --git a/configure b/configure
index 534b443f7d..a32bbc3f90 100755
--- a/configure
+++ b/configure
@@ -2629,6 +2629,7 @@ CONFIG_EXTRA="
mpegvideo
mpegvideodec
mpegvideoenc
+ mpegvideoencdsp
msmpeg4dec
msmpeg4enc
mss34dsp
@@ -2906,7 +2907,7 @@ mpeg_er_select="error_resilience"
mpegaudio_select="mpegaudiodsp mpegaudioheader"
mpegvideo_select="blockdsp hpeldsp idctdsp videodsp"
mpegvideodec_select="h264chroma mpegvideo mpeg_er"
-mpegvideoenc_select="aandcttables fdctdsp me_cmp mpegvideo pixblockdsp"
+mpegvideoenc_select="aandcttables fdctdsp me_cmp mpegvideo mpegvideoencdsp pixblockdsp"
msmpeg4dec_select="h263_decoder"
msmpeg4enc_select="h263_encoder"
vc1dsp_select="h264chroma qpeldsp startcode"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cfbec99889..faffed1c34 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -151,8 +151,8 @@ OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o rl.o \
to_upper4.o
OBJS-$(CONFIG_MPEGVIDEODEC) += mpegvideo_dec.o mpegutils.o
OBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideo_enc.o mpeg12data.o \
- motion_est.o ratecontrol.o \
- mpegvideoencdsp.o
+ motion_est.o ratecontrol.o
+OBJS-$(CONFIG_MPEGVIDEOENCDSP) += mpegvideoencdsp.o
OBJS-$(CONFIG_MSMPEG4DEC) += msmpeg4dec.o msmpeg4.o msmpeg4data.o \
msmpeg4_vc1_data.o
OBJS-$(CONFIG_MSMPEG4ENC) += msmpeg4enc.o msmpeg4.o msmpeg4data.o \
diff --git a/libavcodec/aarch64/Makefile b/libavcodec/aarch64/Makefile
index a67e53bffb..2bf48dfa28 100644
--- a/libavcodec/aarch64/Makefile
+++ b/libavcodec/aarch64/Makefile
@@ -10,7 +10,7 @@ OBJS-$(CONFIG_HPELDSP) += aarch64/hpeldsp_init_aarch64.o
OBJS-$(CONFIG_IDCTDSP) += aarch64/idctdsp_init_aarch64.o
OBJS-$(CONFIG_ME_CMP) += aarch64/me_cmp_init_aarch64.o
OBJS-$(CONFIG_MPEGAUDIODSP) += aarch64/mpegaudiodsp_init.o
-OBJS-$(CONFIG_MPEGVIDEOENC) += aarch64/mpegvideoencdsp_init.o
+OBJS-$(CONFIG_MPEGVIDEOENCDSP) += aarch64/mpegvideoencdsp_init.o
OBJS-$(CONFIG_NEON_CLOBBER_TEST) += aarch64/neontest.o
OBJS-$(CONFIG_PIXBLOCKDSP) += aarch64/pixblockdsp_init_aarch64.o
OBJS-$(CONFIG_VIDEODSP) += aarch64/videodsp_init.o
@@ -54,7 +54,7 @@ NEON-OBJS-$(CONFIG_IDCTDSP) += aarch64/idctdsp_neon.o \
aarch64/simple_idct_neon.o
NEON-OBJS-$(CONFIG_ME_CMP) += aarch64/me_cmp_neon.o
NEON-OBJS-$(CONFIG_MPEGAUDIODSP) += aarch64/mpegaudiodsp_neon.o
-NEON-OBJS-$(CONFIG_MPEGVIDEOENC) += aarch64/mpegvideoencdsp_neon.o
+NEON-OBJS-$(CONFIG_MPEGVIDEOENCDSP) += aarch64/mpegvideoencdsp_neon.o
NEON-OBJS-$(CONFIG_PIXBLOCKDSP) += aarch64/pixblockdsp_neon.o
NEON-OBJS-$(CONFIG_VC1DSP) += aarch64/vc1dsp_neon.o
NEON-OBJS-$(CONFIG_VP8DSP) += aarch64/vp8dsp_neon.o
diff --git a/libavcodec/arm/Makefile b/libavcodec/arm/Makefile
index becf316eb6..811b364195 100644
--- a/libavcodec/arm/Makefile
+++ b/libavcodec/arm/Makefile
@@ -21,7 +21,7 @@ OBJS-$(CONFIG_LLAUDDSP) += arm/lossless_audiodsp_init_arm.o
OBJS-$(CONFIG_ME_CMP) += arm/me_cmp_init_arm.o
OBJS-$(CONFIG_MPEGAUDIODSP) += arm/mpegaudiodsp_init_arm.o
OBJS-$(CONFIG_MPEGVIDEO) += arm/mpegvideo_arm.o
-OBJS-$(CONFIG_MPEGVIDEOENC) += arm/mpegvideoencdsp_init_arm.o
+OBJS-$(CONFIG_MPEGVIDEOENCDSP) += arm/mpegvideoencdsp_init_arm.o
OBJS-$(CONFIG_NEON_CLOBBER_TEST) += arm/neontest.o
OBJS-$(CONFIG_PIXBLOCKDSP) += arm/pixblockdsp_init_arm.o
OBJS-$(CONFIG_RV34DSP) += arm/rv34dsp_init_arm.o
@@ -72,7 +72,7 @@ ARMV6-OBJS-$(CONFIG_IDCTDSP) += arm/idctdsp_init_armv6.o \
arm/simple_idct_armv6.o
ARMV6-OBJS-$(CONFIG_ME_CMP) += arm/me_cmp_armv6.o
ARMV6-OBJS-$(CONFIG_MPEGAUDIODSP) += arm/mpegaudiodsp_fixed_armv6.o
-ARMV6-OBJS-$(CONFIG_MPEGVIDEOENC) += arm/mpegvideoencdsp_armv6.o
+ARMV6-OBJS-$(CONFIG_MPEGVIDEOENCDSP) += arm/mpegvideoencdsp_armv6.o
ARMV6-OBJS-$(CONFIG_PIXBLOCKDSP) += arm/pixblockdsp_armv6.o
ARMV6-OBJS-$(CONFIG_STARTCODE) += arm/startcode_armv6.o
ARMV6-OBJS-$(CONFIG_VP8DSP) += arm/vp8_armv6.o \
diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h
index 3e074ddf47..aa0bdfe956 100644
--- a/libavcodec/mathops.h
+++ b/libavcodec/mathops.h
@@ -32,6 +32,7 @@
extern const uint32_t ff_inverse[257];
extern const uint8_t ff_log2_run[41];
+EXTERN const uint32_t ff_square_tab[512];
extern const uint8_t ff_sqrt_tab[256];
EXTERN const uint8_t ff_crop_tab[256 + 2 * MAX_NEG_CROP];
extern const uint8_t ff_zigzag_direct[64];
diff --git a/libavcodec/mathtables.c b/libavcodec/mathtables.c
index 3ebc146b06..9a25da4964 100644
--- a/libavcodec/mathtables.c
+++ b/libavcodec/mathtables.c
@@ -20,8 +20,47 @@
#include <stdint.h>
+#include "config.h"
#include "mathops.h"
+#if CONFIG_ME_CMP || CONFIG_MPEGVIDEOENCDSP
+/* (i - 256) * (i - 256) */
+const uint32_t ff_square_tab[512] = {
+ 65536, 65025, 64516, 64009, 63504, 63001, 62500, 62001, 61504, 61009, 60516, 60025, 59536, 59049, 58564, 58081,
+ 57600, 57121, 56644, 56169, 55696, 55225, 54756, 54289, 53824, 53361, 52900, 52441, 51984, 51529, 51076, 50625,
+ 50176, 49729, 49284, 48841, 48400, 47961, 47524, 47089, 46656, 46225, 45796, 45369, 44944, 44521, 44100, 43681,
+ 43264, 42849, 42436, 42025, 41616, 41209, 40804, 40401, 40000, 39601, 39204, 38809, 38416, 38025, 37636, 37249,
+ 36864, 36481, 36100, 35721, 35344, 34969, 34596, 34225, 33856, 33489, 33124, 32761, 32400, 32041, 31684, 31329,
+ 30976, 30625, 30276, 29929, 29584, 29241, 28900, 28561, 28224, 27889, 27556, 27225, 26896, 26569, 26244, 25921,
+ 25600, 25281, 24964, 24649, 24336, 24025, 23716, 23409, 23104, 22801, 22500, 22201, 21904, 21609, 21316, 21025,
+ 20736, 20449, 20164, 19881, 19600, 19321, 19044, 18769, 18496, 18225, 17956, 17689, 17424, 17161, 16900, 16641,
+ 16384, 16129, 15876, 15625, 15376, 15129, 14884, 14641, 14400, 14161, 13924, 13689, 13456, 13225, 12996, 12769,
+ 12544, 12321, 12100, 11881, 11664, 11449, 11236, 11025, 10816, 10609, 10404, 10201, 10000, 9801, 9604, 9409,
+ 9216, 9025, 8836, 8649, 8464, 8281, 8100, 7921, 7744, 7569, 7396, 7225, 7056, 6889, 6724, 6561,
+ 6400, 6241, 6084, 5929, 5776, 5625, 5476, 5329, 5184, 5041, 4900, 4761, 4624, 4489, 4356, 4225,
+ 4096, 3969, 3844, 3721, 3600, 3481, 3364, 3249, 3136, 3025, 2916, 2809, 2704, 2601, 2500, 2401,
+ 2304, 2209, 2116, 2025, 1936, 1849, 1764, 1681, 1600, 1521, 1444, 1369, 1296, 1225, 1156, 1089,
+ 1024, 961, 900, 841, 784, 729, 676, 625, 576, 529, 484, 441, 400, 361, 324, 289,
+ 256, 225, 196, 169, 144, 121, 100, 81, 64, 49, 36, 25, 16, 9, 4, 1,
+ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225,
+ 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961,
+ 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209,
+ 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969,
+ 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241,
+ 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025,
+ 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449, 11664, 11881, 12100, 12321,
+ 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884, 15129, 15376, 15625, 15876, 16129,
+ 16384, 16641, 16900, 17161, 17424, 17689, 17956, 18225, 18496, 18769, 19044, 19321, 19600, 19881, 20164, 20449,
+ 20736, 21025, 21316, 21609, 21904, 22201, 22500, 22801, 23104, 23409, 23716, 24025, 24336, 24649, 24964, 25281,
+ 25600, 25921, 26244, 26569, 26896, 27225, 27556, 27889, 28224, 28561, 28900, 29241, 29584, 29929, 30276, 30625,
+ 30976, 31329, 31684, 32041, 32400, 32761, 33124, 33489, 33856, 34225, 34596, 34969, 35344, 35721, 36100, 36481,
+ 36864, 37249, 37636, 38025, 38416, 38809, 39204, 39601, 40000, 40401, 40804, 41209, 41616, 42025, 42436, 42849,
+ 43264, 43681, 44100, 44521, 44944, 45369, 45796, 46225, 46656, 47089, 47524, 47961, 48400, 48841, 49284, 49729,
+ 50176, 50625, 51076, 51529, 51984, 52441, 52900, 53361, 53824, 54289, 54756, 55225, 55696, 56169, 56644, 57121,
+ 57600, 58081, 58564, 59049, 59536, 60025, 60516, 61009, 61504, 62001, 62500, 63001, 63504, 64009, 64516, 65025,
+};
+#endif
+
/* a*inverse[b]>>32 == a/b for all 0<=a<=16909558 && 2<=b<=256
* for a>16909558, is an overestimate by less than 1 part in 1<<24 */
const uint32_t ff_inverse[257]={
diff --git a/libavcodec/me_cmp.c b/libavcodec/me_cmp.c
index 2a8ede5955..419b8d30c9 100644
--- a/libavcodec/me_cmp.c
+++ b/libavcodec/me_cmp.c
@@ -33,42 +33,6 @@
#include "config.h"
#include "config_components.h"
-/* (i - 256) * (i - 256) */
-const uint32_t ff_square_tab[512] = {
- 65536, 65025, 64516, 64009, 63504, 63001, 62500, 62001, 61504, 61009, 60516, 60025, 59536, 59049, 58564, 58081,
- 57600, 57121, 56644, 56169, 55696, 55225, 54756, 54289, 53824, 53361, 52900, 52441, 51984, 51529, 51076, 50625,
- 50176, 49729, 49284, 48841, 48400, 47961, 47524, 47089, 46656, 46225, 45796, 45369, 44944, 44521, 44100, 43681,
- 43264, 42849, 42436, 42025, 41616, 41209, 40804, 40401, 40000, 39601, 39204, 38809, 38416, 38025, 37636, 37249,
- 36864, 36481, 36100, 35721, 35344, 34969, 34596, 34225, 33856, 33489, 33124, 32761, 32400, 32041, 31684, 31329,
- 30976, 30625, 30276, 29929, 29584, 29241, 28900, 28561, 28224, 27889, 27556, 27225, 26896, 26569, 26244, 25921,
- 25600, 25281, 24964, 24649, 24336, 24025, 23716, 23409, 23104, 22801, 22500, 22201, 21904, 21609, 21316, 21025,
- 20736, 20449, 20164, 19881, 19600, 19321, 19044, 18769, 18496, 18225, 17956, 17689, 17424, 17161, 16900, 16641,
- 16384, 16129, 15876, 15625, 15376, 15129, 14884, 14641, 14400, 14161, 13924, 13689, 13456, 13225, 12996, 12769,
- 12544, 12321, 12100, 11881, 11664, 11449, 11236, 11025, 10816, 10609, 10404, 10201, 10000, 9801, 9604, 9409,
- 9216, 9025, 8836, 8649, 8464, 8281, 8100, 7921, 7744, 7569, 7396, 7225, 7056, 6889, 6724, 6561,
- 6400, 6241, 6084, 5929, 5776, 5625, 5476, 5329, 5184, 5041, 4900, 4761, 4624, 4489, 4356, 4225,
- 4096, 3969, 3844, 3721, 3600, 3481, 3364, 3249, 3136, 3025, 2916, 2809, 2704, 2601, 2500, 2401,
- 2304, 2209, 2116, 2025, 1936, 1849, 1764, 1681, 1600, 1521, 1444, 1369, 1296, 1225, 1156, 1089,
- 1024, 961, 900, 841, 784, 729, 676, 625, 576, 529, 484, 441, 400, 361, 324, 289,
- 256, 225, 196, 169, 144, 121, 100, 81, 64, 49, 36, 25, 16, 9, 4, 1,
- 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225,
- 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961,
- 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209,
- 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969,
- 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241,
- 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025,
- 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449, 11664, 11881, 12100, 12321,
- 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884, 15129, 15376, 15625, 15876, 16129,
- 16384, 16641, 16900, 17161, 17424, 17689, 17956, 18225, 18496, 18769, 19044, 19321, 19600, 19881, 20164, 20449,
- 20736, 21025, 21316, 21609, 21904, 22201, 22500, 22801, 23104, 23409, 23716, 24025, 24336, 24649, 24964, 25281,
- 25600, 25921, 26244, 26569, 26896, 27225, 27556, 27889, 28224, 28561, 28900, 29241, 29584, 29929, 30276, 30625,
- 30976, 31329, 31684, 32041, 32400, 32761, 33124, 33489, 33856, 34225, 34596, 34969, 35344, 35721, 36100, 36481,
- 36864, 37249, 37636, 38025, 38416, 38809, 39204, 39601, 40000, 40401, 40804, 41209, 41616, 42025, 42436, 42849,
- 43264, 43681, 44100, 44521, 44944, 45369, 45796, 46225, 46656, 47089, 47524, 47961, 48400, 48841, 49284, 49729,
- 50176, 50625, 51076, 51529, 51984, 52441, 52900, 53361, 53824, 54289, 54756, 55225, 55696, 56169, 56644, 57121,
- 57600, 58081, 58564, 59049, 59536, 60025, 60516, 61009, 61504, 62001, 62500, 63001, 63504, 64009, 64516, 65025,
-};
-
static int sse4_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2,
ptrdiff_t stride, int h)
{
diff --git a/libavcodec/me_cmp.h b/libavcodec/me_cmp.h
index f1dbcd5146..49f81e1901 100644
--- a/libavcodec/me_cmp.h
+++ b/libavcodec/me_cmp.h
@@ -21,13 +21,8 @@
#include <stdint.h>
-#include "libavutil/attributes_internal.h"
-
#include "avcodec.h"
-EXTERN const uint32_t ff_square_tab[512];
-
-
/* minimum alignment rules ;)
* If you notice errors in the align stuff, need more alignment for some ASM code
* for some CPU or need to use a function with less aligned data then send a mail
diff --git a/libavcodec/mips/Makefile b/libavcodec/mips/Makefile
index 569d1db4a3..0eadc3bfe8 100644
--- a/libavcodec/mips/Makefile
+++ b/libavcodec/mips/Makefile
@@ -30,8 +30,8 @@ OBJS-$(CONFIG_BLOCKDSP) += mips/blockdsp_init_mips.o
OBJS-$(CONFIG_PIXBLOCKDSP) += mips/pixblockdsp_init_mips.o
OBJS-$(CONFIG_IDCTDSP) += mips/idctdsp_init_mips.o
OBJS-$(CONFIG_MPEGVIDEO) += mips/mpegvideo_init_mips.o
-OBJS-$(CONFIG_MPEGVIDEOENC) += mips/mpegvideoenc_init_mips.o \
- mips/mpegvideoencdsp_init_mips.o
+OBJS-$(CONFIG_MPEGVIDEOENC) += mips/mpegvideoenc_init_mips.o
+OBJS-$(CONFIG_MPEGVIDEOENCDSP) += mips/mpegvideoencdsp_init_mips.o
OBJS-$(CONFIG_ME_CMP) += mips/me_cmp_init_mips.o
OBJS-$(CONFIG_MPEG4_DECODER) += mips/xvididct_init_mips.o
OBJS-$(CONFIG_VC1DSP) += mips/vc1dsp_init_mips.o
@@ -67,7 +67,7 @@ MSA-OBJS-$(CONFIG_PIXBLOCKDSP) += mips/pixblockdsp_msa.o
MSA-OBJS-$(CONFIG_IDCTDSP) += mips/idctdsp_msa.o \
mips/simple_idct_msa.o
MSA-OBJS-$(CONFIG_MPEGVIDEO) += mips/mpegvideo_msa.o
-MSA-OBJS-$(CONFIG_MPEGVIDEOENC) += mips/mpegvideoencdsp_msa.o
+MSA-OBJS-$(CONFIG_MPEGVIDEOENCDSP) += mips/mpegvideoencdsp_msa.o
MSA-OBJS-$(CONFIG_ME_CMP) += mips/me_cmp_msa.o
MSA-OBJS-$(CONFIG_VC1_DECODER) += mips/vc1dsp_msa.o
diff --git a/libavcodec/mpegvideoencdsp.c b/libavcodec/mpegvideoencdsp.c
index 5e4c446d99..b4fd2af915 100644
--- a/libavcodec/mpegvideoencdsp.c
+++ b/libavcodec/mpegvideoencdsp.c
@@ -25,7 +25,7 @@
#include "libavutil/attributes.h"
#include "libavutil/imgutils.h"
#include "avcodec.h"
-#include "me_cmp.h"
+#include "mathops.h"
#include "mpegvideoencdsp.h"
static int try_8x8basis_c(const int16_t rem[64], const int16_t weight[64],
diff --git a/libavcodec/ppc/Makefile b/libavcodec/ppc/Makefile
index 10b9ca60da..cbd9621e05 100644
--- a/libavcodec/ppc/Makefile
+++ b/libavcodec/ppc/Makefile
@@ -12,7 +12,7 @@ OBJS-$(CONFIG_LLVIDDSP) += ppc/lossless_videodsp_altivec.o
OBJS-$(CONFIG_ME_CMP) += ppc/me_cmp.o
OBJS-$(CONFIG_MPEGAUDIODSP) += ppc/mpegaudiodsp_altivec.o
OBJS-$(CONFIG_MPEGVIDEO) += ppc/mpegvideo_altivec.o
-OBJS-$(CONFIG_MPEGVIDEOENC) += ppc/mpegvideoencdsp.o
+OBJS-$(CONFIG_MPEGVIDEOENCDSP) += ppc/mpegvideoencdsp.o
OBJS-$(CONFIG_PIXBLOCKDSP) += ppc/pixblockdsp.o
OBJS-$(CONFIG_VC1DSP) += ppc/vc1dsp_altivec.o
OBJS-$(CONFIG_VIDEODSP) += ppc/videodsp.o
diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index a80d2fa2e7..736f873fe8 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -51,8 +51,8 @@ OBJS-$(CONFIG_LPC) += riscv/lpc_init.o
RVV-OBJS-$(CONFIG_LPC) += riscv/lpc_rvv.o
OBJS-$(CONFIG_ME_CMP) += riscv/me_cmp_init.o
RVV-OBJS-$(CONFIG_ME_CMP) += riscv/me_cmp_rvv.o
-OBJS-$(CONFIG_MPEGVIDEOENC) += riscv/mpegvideoencdsp_init.o
-RVV-OBJS-$(CONFIG_MPEGVIDEOENC) += riscv/mpegvideoencdsp_rvv.o
+OBJS-$(CONFIG_MPEGVIDEOENCDSP) += riscv/mpegvideoencdsp_init.o
+RVV-OBJS-$(CONFIG_MPEGVIDEOENCDSP) += riscv/mpegvideoencdsp_rvv.o
OBJS-$(CONFIG_OPUS_DECODER) += riscv/opusdsp_init.o
RVV-OBJS-$(CONFIG_OPUS_DECODER) += riscv/opusdsp_rvv.o
OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_init.o
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index 89ee8dc726..53e8ec38ef 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -25,8 +25,8 @@ OBJS-$(CONFIG_LPC) += x86/lpc_init.o
OBJS-$(CONFIG_ME_CMP) += x86/me_cmp_init.o
OBJS-$(CONFIG_MPEGAUDIODSP) += x86/mpegaudiodsp.o
OBJS-$(CONFIG_MPEGVIDEO) += x86/mpegvideo.o
-OBJS-$(CONFIG_MPEGVIDEOENC) += x86/mpegvideoenc.o \
- x86/mpegvideoencdsp_init.o
+OBJS-$(CONFIG_MPEGVIDEOENC) += x86/mpegvideoenc.o
+OBJS-$(CONFIG_MPEGVIDEOENCDSP) += x86/mpegvideoencdsp_init.o
OBJS-$(CONFIG_PIXBLOCKDSP) += x86/pixblockdsp_init.o
OBJS-$(CONFIG_QPELDSP) += x86/qpeldsp_init.o
OBJS-$(CONFIG_RV34DSP) += x86/rv34dsp_init.o
@@ -122,7 +122,7 @@ X86ASM-OBJS-$(CONFIG_LLVIDENCDSP) += x86/lossless_videoencdsp.o
X86ASM-OBJS-$(CONFIG_LPC) += x86/lpc.o
X86ASM-OBJS-$(CONFIG_ME_CMP) += x86/me_cmp.o
X86ASM-OBJS-$(CONFIG_MPEGAUDIODSP) += x86/dct32.o x86/imdct36.o
-X86ASM-OBJS-$(CONFIG_MPEGVIDEOENC) += x86/mpegvideoencdsp.o
+X86ASM-OBJS-$(CONFIG_MPEGVIDEOENCDSP) += x86/mpegvideoencdsp.o
X86ASM-OBJS-$(CONFIG_OPUS_DECODER) += x86/opusdsp.o
X86ASM-OBJS-$(CONFIG_OPUS_ENCODER) += x86/celt_pvq_search.o
X86ASM-OBJS-$(CONFIG_PIXBLOCKDSP) += x86/pixblockdsp.o
diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index fabbf595b4..afd62d95ba 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -18,7 +18,7 @@ AVCODECOBJS-$(CONFIG_LLVIDDSP) += llviddsp.o
AVCODECOBJS-$(CONFIG_LLVIDENCDSP) += llviddspenc.o
AVCODECOBJS-$(CONFIG_LPC) += lpc.o
AVCODECOBJS-$(CONFIG_ME_CMP) += motion.o
-AVCODECOBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideoencdsp.o
+AVCODECOBJS-$(CONFIG_MPEGVIDEOENCDSP) += mpegvideoencdsp.o
AVCODECOBJS-$(CONFIG_VC1DSP) += vc1dsp.o
AVCODECOBJS-$(CONFIG_VP8DSP) += vp8dsp.o
AVCODECOBJS-$(CONFIG_VIDEODSP) += videodsp.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 0734cd26bf..f4e3d4f433 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -208,7 +208,7 @@ static const struct {
#if CONFIG_ME_CMP
{ "motion", checkasm_check_motion },
#endif
- #if CONFIG_MPEGVIDEOENC
+ #if CONFIG_MPEGVIDEOENCDSP
{ "mpegvideoencdsp", checkasm_check_mpegvideoencdsp },
#endif
#if CONFIG_OPUS_DECODER
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 20/47] configure: Relax svq1enc->mpegvideoenc dependency
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (18 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 19/47] configure: Factor mpegvideoencdsp out of mpegvideoenc Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 21/47] configure: Relax diracdec->mpegvideoenc dependency Andreas Rheinhardt
` (26 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It only needs mpegvideoencdsp, motion_est.o and
some H.263 specific parts.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
configure | 2 +-
libavcodec/Makefile | 2 +-
libavcodec/h263.c | 5 ++++-
libavcodec/ituh263enc.c | 41 ++++++++++++++++++++++-------------------
4 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/configure b/configure
index a32bbc3f90..2a1961b61a 100755
--- a/configure
+++ b/configure
@@ -3113,7 +3113,7 @@ speedhq_decoder_select="blockdsp idctdsp"
speedhq_encoder_select="mpegvideoenc"
srgc_decoder_select="inflate_wrapper"
svq1_decoder_select="hpeldsp"
-svq1_encoder_select="hpeldsp me_cmp mpegvideoenc"
+svq1_encoder_select="hpeldsp me_cmp mpegvideoencdsp"
svq3_decoder_select="golomb h264dsp h264parse h264pred hpeldsp tpeldsp videodsp"
svq3_decoder_suggest="zlib"
tak_decoder_select="audiodsp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index faffed1c34..8aa0309e09 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -721,7 +721,7 @@ OBJS-$(CONFIG_SBC_DECODER) += sbcdec.o sbc.o
OBJS-$(CONFIG_SBC_ENCODER) += sbcenc.o sbc.o sbcdsp.o
OBJS-$(CONFIG_SVQ1_DECODER) += svq1dec.o svq1.o h263data.o
OBJS-$(CONFIG_SVQ1_ENCODER) += svq1enc.o svq1.o h263data.o \
- h263.o ituh263enc.o
+ h263.o ituh263enc.o motion_est.o
OBJS-$(CONFIG_SVQ3_DECODER) += svq3.o mpegutils.o h264data.o
OBJS-$(CONFIG_TEXT_DECODER) += textdec.o ass.o
OBJS-$(CONFIG_TEXT_ENCODER) += srtenc.o ass_split.o
diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index 19eb3ba52f..6d2de715ab 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -27,17 +27,19 @@
* H.263/MPEG-4 codec.
*/
+#include "config.h"
+
#include "libavutil/thread.h"
#include "mpegvideo.h"
#include "h263.h"
#include "h263data.h"
#include "h263dsp.h"
-#include "idctdsp.h"
#include "mathops.h"
#include "mpegpicture.h"
#include "mpegutils.h"
#include "rl.h"
+#if CONFIG_MPEGVIDEO
static av_cold void h263_init_rl_inter(void)
{
static uint8_t h263_rl_inter_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
@@ -49,6 +51,7 @@ av_cold void ff_h263_init_rl_inter(void)
static AVOnce init_static_once = AV_ONCE_INIT;
ff_thread_once(&init_static_once, h263_init_rl_inter);
}
+#endif
void ff_h263_update_motion_val(MpegEncContext * s){
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index ab6edafd4d..ae67907722 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -53,21 +53,7 @@
*/
static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV*2+1];
-/**
- * Minimal fcode that a motion vector component would need in umv.
- * All entries in this table are 1.
- */
-static uint8_t umv_fcode_tab[MAX_MV*2+1];
-
-//unified encoding tables for run length encoding of coefficients
-//unified in the sense that the specification specifies the encoding in several steps.
-static uint8_t uni_h263_intra_aic_rl_len [64*64*2*2];
-static uint8_t uni_h263_inter_rl_len [64*64*2*2];
-//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level))
-//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64)
-#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
-
-static av_cold void init_mv_penalty_and_fcode(void)
+static av_cold void init_mv_penalty(void)
{
for (int f_code = 1; f_code <= MAX_FCODE; f_code++) {
for (int mv = -MAX_DMV; mv <= MAX_DMV; mv++) {
@@ -94,10 +80,23 @@ static av_cold void init_mv_penalty_and_fcode(void)
mv_penalty[f_code][mv + MAX_DMV] = len;
}
}
-
- memset(umv_fcode_tab, 1, sizeof(umv_fcode_tab));
}
+#if CONFIG_H263_ENCODER
+/**
+ * Minimal fcode that a motion vector component would need in umv.
+ * All entries in this table are 1.
+ */
+static uint8_t umv_fcode_tab[MAX_MV*2+1];
+
+//unified encoding tables for run length encoding of coefficients
+//unified in the sense that the specification specifies the encoding in several steps.
+static uint8_t uni_h263_intra_aic_rl_len [64*64*2*2];
+static uint8_t uni_h263_inter_rl_len [64*64*2*2];
+//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level))
+//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64)
+#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
+
static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
{
av_assert0(MAX_LEVEL >= 64);
@@ -137,18 +136,22 @@ static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
}
}
}
+#endif
static av_cold void h263_encode_init_static(void)
{
+#if CONFIG_H263_ENCODER
static uint8_t rl_intra_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
-
ff_rl_init(&ff_rl_intra_aic, rl_intra_table);
ff_h263_init_rl_inter();
init_uni_h263_rl_tab(&ff_rl_intra_aic, uni_h263_intra_aic_rl_len);
init_uni_h263_rl_tab(&ff_h263_rl_inter, uni_h263_inter_rl_len);
- init_mv_penalty_and_fcode();
+ memset(umv_fcode_tab, 1, sizeof(umv_fcode_tab));
+#endif
+
+ init_mv_penalty();
}
av_cold const uint8_t (*ff_h263_get_mv_penalty(void))[MAX_DMV*2+1]
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 21/47] configure: Relax diracdec->mpegvideoenc dependency
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (19 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 20/47] configure: Relax svq1enc->mpegvideoenc dependency Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 22/47] configure: Relax snowenc->mpegvideoenc dependency Andreas Rheinhardt
` (25 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
configure | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure b/configure
index 2a1961b61a..24960ec00a 100755
--- a/configure
+++ b/configure
@@ -2959,7 +2959,7 @@ cook_decoder_select="audiodsp sinewin"
cri_decoder_select="mjpeg_decoder"
cscd_decoder_suggest="zlib"
dds_decoder_select="texturedsp"
-dirac_decoder_select="dirac_parse dwt golomb mpegvideoenc qpeldsp videodsp"
+dirac_decoder_select="dirac_parse dwt golomb mpegvideoencdsp qpeldsp videodsp"
dnxhd_decoder_select="blockdsp idctdsp"
dnxhd_encoder_select="blockdsp fdctdsp idctdsp mpegvideoenc pixblockdsp videodsp"
dvvideo_decoder_select="dvprofile idctdsp"
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 22/47] configure: Relax snowenc->mpegvideoenc dependency
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (20 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 21/47] configure: Relax diracdec->mpegvideoenc dependency Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 23/47] avcodec/mpegvideo: Don't reset thread_context ptrs unnecessarily Andreas Rheinhardt
` (24 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It only needs mpegvideoencdsp, motion_est.o and ratecontrol.o.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
configure | 2 +-
libavcodec/Makefile | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
index 24960ec00a..6d7a89d8e7 100755
--- a/configure
+++ b/configure
@@ -3104,7 +3104,7 @@ shorten_decoder_select="bswapdsp"
sipr_decoder_select="lsp"
smvjpeg_decoder_select="mjpeg_decoder"
snow_decoder_select="dwt h264qpel rangecoder videodsp"
-snow_encoder_select="dwt h264qpel hpeldsp me_cmp mpegvideoenc rangecoder videodsp"
+snow_encoder_select="dwt h264qpel hpeldsp me_cmp mpegvideoencdsp rangecoder videodsp"
sonic_decoder_select="golomb rangecoder"
sonic_encoder_select="golomb rangecoder"
sonic_ls_encoder_select="golomb rangecoder"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 8aa0309e09..b64b33cd50 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -697,7 +697,8 @@ OBJS-$(CONFIG_SMC_DECODER) += smc.o
OBJS-$(CONFIG_SMC_ENCODER) += smcenc.o
OBJS-$(CONFIG_SNOW_DECODER) += snowdec.o snow.o snow_dwt.o
OBJS-$(CONFIG_SNOW_ENCODER) += snowenc.o snow.o snow_dwt.o \
- h263.o h263data.o ituh263enc.o
+ h263data.o ituh263enc.o \
+ motion_est.o ratecontrol.o
OBJS-$(CONFIG_SOL_DPCM_DECODER) += dpcm.o
OBJS-$(CONFIG_SONIC_DECODER) += sonic.o
OBJS-$(CONFIG_SONIC_ENCODER) += sonic.o
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 23/47] avcodec/mpegvideo: Don't reset thread_context ptrs unnecessarily
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (21 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 22/47] configure: Relax snowenc->mpegvideoenc dependency Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 24/47] avcodec/mpegvideo: Don't zero unnecessarily Andreas Rheinhardt
` (23 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
They are freed with av_freep(), so the pointers are already consistent.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index f3e4d4c386..84736f8b5b 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -427,7 +427,6 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
}
s->context_initialized = 1;
- memset(s->thread_context, 0, sizeof(s->thread_context));
s->thread_context[0] = s;
s->slice_context_count = nb_slices;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 24/47] avcodec/mpegvideo: Don't zero unnecessarily
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (22 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 23/47] avcodec/mpegvideo: Don't reset thread_context ptrs unnecessarily Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 25/47] avcodec/mpegvideo: Defer init of enc slice ctxs in ff_mpv_common_init() Andreas Rheinhardt
` (22 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The whole dc_val array is initialized (to 1024) immediately
after the allocation.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 84736f8b5b..e329771b38 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -340,7 +340,7 @@ av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
// MN: we need these for error resilience of intra-frames
// Allocating them unconditionally for decoders also means
// that we don't need to reinitialize when e.g. h263_aic changes.
- if (!FF_ALLOCZ_TYPED_ARRAY(s->dc_val_base, yc_size))
+ if (!FF_ALLOC_TYPED_ARRAY(s->dc_val_base, yc_size))
return AVERROR(ENOMEM);
s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 25/47] avcodec/mpegvideo: Defer init of enc slice ctxs in ff_mpv_common_init()
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (23 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 24/47] avcodec/mpegvideo: Don't zero unnecessarily Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 26/47] avcodec/mpegvideo_enc: Simplify allocating non-slice buffers Andreas Rheinhardt
` (21 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This will allow to perform initializations between ff_mpv_common_init()
and ff_mpv_init_duplicate_contexts() that will be automatically
copied to the slice contexts.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 8 +++++---
libavcodec/mpegvideo_enc.c | 9 ++++++---
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index e329771b38..f6e997193d 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -431,9 +431,11 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
s->slice_context_count = nb_slices;
// if (s->width && s->height) {
- ret = ff_mpv_init_duplicate_contexts(s);
- if (ret < 0)
- goto fail;
+ if (!s->encoding) {
+ ret = ff_mpv_init_duplicate_contexts(s);
+ if (ret < 0)
+ goto fail;
+ }
// }
return 0;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index af1e77cfec..1fae5fbeb0 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1023,9 +1023,9 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
m->lmin = m->lmax;
}
- /* ff_mpv_common_init() will copy (memdup) the contents of the main slice
- * to the slice contexts, so we initialize various fields of it
- * before calling ff_mpv_common_init(). */
+ /* ff_mpv_init_duplicate_contexts() will copy (memdup) the contents of the
+ * main slice to the slice contexts, so we initialize various fields of it
+ * before calling ff_mpv_init_duplicate_contexts(). */
s->parent = m;
ff_mpv_idct_init(&s->c);
init_unquantize(s, avctx);
@@ -1057,6 +1057,9 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->c.slice_ctx_size = sizeof(*s);
ret = ff_mpv_common_init(&s->c);
+ if (ret < 0)
+ return ret;
+ ret = ff_mpv_init_duplicate_contexts(&s->c);
if (ret < 0)
return ret;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 26/47] avcodec/mpegvideo_enc: Simplify allocating non-slice buffers
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (24 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 25/47] avcodec/mpegvideo: Defer init of enc slice ctxs in ff_mpv_common_init() Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 27/47] avcodec/ituh263dec: Simplify AIC handling Andreas Rheinhardt
` (20 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Allocate them before the slice contexts, so that they are automatically
copied to the slice contexts. This avoids having to set them in a loop.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 148 ++++++++++++++++++-------------------
1 file changed, 73 insertions(+), 75 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 1fae5fbeb0..60abe08d7a 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -444,50 +444,33 @@ static av_cold int init_matrices(MPVMainEncContext *const m, AVCodecContext *avc
return 0;
}
-static av_cold int init_buffers(MPVMainEncContext *const m, AVCodecContext *avctx)
+static av_cold int init_buffers(MPVMainEncContext *const m)
{
MPVEncContext *const s = &m->s;
- // Align the following per-thread buffers to avoid false sharing.
- enum {
-#ifndef _MSC_VER
- /// The number is supposed to match/exceed the cache-line size.
- ALIGN = FFMAX(128, _Alignof(max_align_t)),
-#else
- ALIGN = 128,
-#endif
- DCT_ERROR_SIZE = FFALIGN(2 * sizeof(*s->dct_error_sum), ALIGN),
- };
- static_assert(DCT_ERROR_SIZE * MAX_THREADS + ALIGN - 1 <= SIZE_MAX,
- "Need checks for potential overflow.");
- unsigned nb_slices = s->c.slice_context_count, mv_table_size, mb_array_size;
- char *dct_error = NULL;
- int has_b_frames = !!m->max_b_frames, nb_mv_tables = 1 + 5 * has_b_frames;
+ int has_b_frames = !!m->max_b_frames;
int16_t (*mv_table)[2];
- if (m->noise_reduction) {
- if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_offset, 2))
- return AVERROR(ENOMEM);
- dct_error = av_mallocz(ALIGN - 1 + nb_slices * DCT_ERROR_SIZE);
- if (!dct_error)
- return AVERROR(ENOMEM);
- m->dct_error_sum_base = dct_error;
- dct_error += FFALIGN((uintptr_t)dct_error, ALIGN) - (uintptr_t)dct_error;
- }
-
/* Allocate MB type table */
- mb_array_size = s->c.mb_stride * s->c.mb_height;
+ unsigned mb_array_size = s->c.mb_stride * s->c.mb_height;
s->mb_type = av_calloc(mb_array_size, 3 * sizeof(*s->mb_type) + sizeof(*s->mb_mean));
if (!s->mb_type)
return AVERROR(ENOMEM);
+ s->mc_mb_var = s->mb_type + mb_array_size;
+ s->mb_var = s->mc_mb_var + mb_array_size;
+ s->mb_mean = (uint8_t*)(s->mb_var + mb_array_size);
+
if (!FF_ALLOCZ_TYPED_ARRAY(s->lambda_table, mb_array_size))
return AVERROR(ENOMEM);
- mv_table_size = (s->c.mb_height + 2) * s->c.mb_stride + 1;
+ unsigned mv_table_size = (s->c.mb_height + 2) * s->c.mb_stride + 1;
+ unsigned nb_mv_tables = 1 + 5 * has_b_frames;
if (s->c.codec_id == AV_CODEC_ID_MPEG4 ||
(s->c.avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) {
nb_mv_tables += 8 * has_b_frames;
- if (!ALLOCZ_ARRAYS(s->p_field_select_table[0], 2 * (2 + 4 * has_b_frames), mv_table_size))
+ s->p_field_select_table[0] = av_calloc(mv_table_size, 2 * (2 + 4 * has_b_frames));
+ if (!s->p_field_select_table[0])
return AVERROR(ENOMEM);
+ s->p_field_select_table[1] = s->p_field_select_table[0] + 2 * mv_table_size;
}
mv_table = av_calloc(mv_table_size, nb_mv_tables * sizeof(*mv_table));
@@ -496,43 +479,21 @@ static av_cold int init_buffers(MPVMainEncContext *const m, AVCodecContext *avct
m->mv_table_base = mv_table;
mv_table += s->c.mb_stride + 1;
- for (unsigned i = 0; i < nb_slices; ++i) {
- MPVEncContext *const s2 = s->c.enc_contexts[i];
- int16_t (*tmp_mv_table)[2] = mv_table;
-
- if (dct_error) {
- s2->dct_offset = s->dct_offset;
- s2->dct_error_sum = (void*)dct_error;
- dct_error += DCT_ERROR_SIZE;
- }
-
- s2->mb_type = s->mb_type;
- s2->mc_mb_var = s2->mb_type + mb_array_size;
- s2->mb_var = s2->mc_mb_var + mb_array_size;
- s2->mb_mean = (uint8_t*)(s2->mb_var + mb_array_size);
- s2->lambda_table = s->lambda_table;
-
- s2->p_mv_table = tmp_mv_table;
- if (has_b_frames) {
- s2->b_forw_mv_table = tmp_mv_table += mv_table_size;
- s2->b_back_mv_table = tmp_mv_table += mv_table_size;
- s2->b_bidir_forw_mv_table = tmp_mv_table += mv_table_size;
- s2->b_bidir_back_mv_table = tmp_mv_table += mv_table_size;
- s2->b_direct_mv_table = tmp_mv_table += mv_table_size;
- }
-
- if (s->p_field_select_table[0]) { // MPEG-4 or INTERLACED_ME above
- uint8_t *field_select = s->p_field_select_table[0];
- s2->p_field_select_table[0] = field_select;
- s2->p_field_select_table[1] = field_select += 2 * mv_table_size;
-
- if (has_b_frames) {
- for (int j = 0; j < 2; j++) {
- for (int k = 0; k < 2; k++) {
- for (int l = 0; l < 2; l++)
- s2->b_field_mv_table[j][k][l] = tmp_mv_table += mv_table_size;
- s2->b_field_select_table[j][k] = field_select += 2 * mv_table_size;
- }
+ s->p_mv_table = mv_table;
+ if (has_b_frames) {
+ s->b_forw_mv_table = mv_table += mv_table_size;
+ s->b_back_mv_table = mv_table += mv_table_size;
+ s->b_bidir_forw_mv_table = mv_table += mv_table_size;
+ s->b_bidir_back_mv_table = mv_table += mv_table_size;
+ s->b_direct_mv_table = mv_table += mv_table_size;
+
+ if (s->p_field_select_table[1]) { // MPEG-4 or INTERLACED_ME above
+ uint8_t *field_select = s->p_field_select_table[1];
+ for (int j = 0; j < 2; j++) {
+ for (int k = 0; k < 2; k++) {
+ for (int l = 0; l < 2; l++)
+ s->b_field_mv_table[j][k][l] = mv_table += mv_table_size;
+ s->b_field_select_table[j][k] = field_select += 2 * mv_table_size;
}
}
}
@@ -541,6 +502,44 @@ static av_cold int init_buffers(MPVMainEncContext *const m, AVCodecContext *avct
return 0;
}
+static av_cold int init_slice_buffers(MPVMainEncContext *const m)
+{
+ MPVEncContext *const s = &m->s;
+ // Align the following per-thread buffers to avoid false sharing.
+ enum {
+#ifndef _MSC_VER
+ /// The number is supposed to match/exceed the cache-line size.
+ ALIGN = FFMAX(128, _Alignof(max_align_t)),
+#else
+ ALIGN = 128,
+#endif
+ DCT_ERROR_SIZE = FFALIGN(2 * sizeof(*s->dct_error_sum), ALIGN),
+ };
+ static_assert(DCT_ERROR_SIZE * MAX_THREADS + ALIGN - 1 <= SIZE_MAX,
+ "Need checks for potential overflow.");
+ unsigned nb_slices = s->c.slice_context_count;
+
+ if (!m->noise_reduction)
+ return 0;
+
+ if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_offset, 2))
+ return AVERROR(ENOMEM);
+ char *dct_error = av_mallocz(ALIGN - 1 + nb_slices * DCT_ERROR_SIZE);
+ if (!dct_error)
+ return AVERROR(ENOMEM);
+ m->dct_error_sum_base = dct_error;
+ dct_error += FFALIGN((uintptr_t)dct_error, ALIGN) - (uintptr_t)dct_error;
+
+ for (unsigned i = 0; i < nb_slices; ++i) {
+ MPVEncContext *const s2 = s->c.enc_contexts[i];
+
+ s2->dct_offset = s->dct_offset;
+ s2->dct_error_sum = (void*)dct_error;
+ dct_error += DCT_ERROR_SIZE;
+ }
+ return 0;
+}
+
/* init video encoder */
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
{
@@ -1059,20 +1058,19 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
ret = ff_mpv_common_init(&s->c);
if (ret < 0)
return ret;
- ret = ff_mpv_init_duplicate_contexts(&s->c);
+ ret = init_buffers(m);
if (ret < 0)
return ret;
-
if (s->c.slice_context_count > 1) {
- for (int i = 0; i < s->c.slice_context_count; ++i) {
- s->c.enc_contexts[i]->rtp_mode = 1;
-
- if (avctx->codec_id == AV_CODEC_ID_H263P)
- s->c.enc_contexts[i]->c.h263_slice_structured = 1;
- }
+ s->rtp_mode = 1;
+ if (avctx->codec_id == AV_CODEC_ID_H263P)
+ s->c.h263_slice_structured = 1;
}
+ ret = ff_mpv_init_duplicate_contexts(&s->c);
+ if (ret < 0)
+ return ret;
- ret = init_buffers(m, avctx);
+ ret = init_slice_buffers(m);
if (ret < 0)
return ret;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 27/47] avcodec/ituh263dec: Simplify AIC handling
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (25 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 26/47] avcodec/mpegvideo_enc: Simplify allocating non-slice buffers Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 28/47] avcodec/ituh263enc: " Andreas Rheinhardt
` (19 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Possible by using block_index.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263dec.c | 35 +++++++++++++----------------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 896556edfb..809bfcf564 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -448,34 +448,25 @@ static void h263_decode_dquant(MpegEncContext *s){
static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
{
- int x, y, wrap, a, c, pred_dc, scale;
- int16_t *dc_val, *ac_val, *ac_val1;
+ int wrap, a, c, pred_dc, scale;
+ const int xy = s->block_index[n];
+ int16_t *const dc_val = s->dc_val[0] + xy;
+ int16_t *const ac_val = (s->ac_val[0] + xy)[0];
/* find prediction */
if (n < 4) {
- x = 2 * s->mb_x + (n & 1);
- y = 2 * s->mb_y + (n>> 1);
wrap = s->b8_stride;
- dc_val = s->dc_val[0];
- ac_val = s->ac_val[0][0];
scale = s->y_dc_scale;
} else {
- x = s->mb_x;
- y = s->mb_y;
wrap = s->mb_stride;
- dc_val = s->dc_val[n - 4 + 1];
- ac_val = s->ac_val[n - 4 + 1][0];
scale = s->c_dc_scale;
}
- ac_val += ((y) * wrap + (x)) * 16;
- ac_val1 = ac_val;
-
/* B C
* A X
*/
- a = dc_val[(x - 1) + (y) * wrap];
- c = dc_val[(x) + (y - 1) * wrap];
+ a = dc_val[-1];
+ c = dc_val[-wrap];
/* No prediction outside GOB boundary */
if (s->first_slice_line && n != 3) {
@@ -488,18 +479,18 @@ static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
if (s->h263_aic_dir) {
/* left prediction */
if (a != 1024) {
- ac_val -= 16;
+ int16_t *const ac_val2 = ac_val - 16;
for (int i = 1; i < 8; i++) {
- block[s->idsp.idct_permutation[i << 3]] += ac_val[i];
+ block[s->idsp.idct_permutation[i << 3]] += ac_val2[i];
}
pred_dc = a;
}
} else {
/* top prediction */
if (c != 1024) {
- ac_val -= 16 * wrap;
+ int16_t *const ac_val2 = ac_val - 16 * wrap;
for (int i = 1; i < 8; i++) {
- block[s->idsp.idct_permutation[i]] += ac_val[i + 8];
+ block[s->idsp.idct_permutation[i]] += ac_val2[i + 8];
}
pred_dc = c;
}
@@ -523,14 +514,14 @@ static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
block[0] |= 1;
/* Update AC/DC tables */
- dc_val[(x) + (y) * wrap] = block[0];
+ *dc_val = block[0];
/* left copy */
for (int i = 1; i < 8; i++)
- ac_val1[i] = block[s->idsp.idct_permutation[i << 3]];
+ ac_val[i] = block[s->idsp.idct_permutation[i << 3]];
/* top copy */
for (int i = 1; i < 8; i++)
- ac_val1[8 + i] = block[s->idsp.idct_permutation[i]];
+ ac_val[8 + i] = block[s->idsp.idct_permutation[i]];
}
static int h263_decode_block(MpegEncContext * s, int16_t * block,
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 28/47] avcodec/ituh263enc: Simplify AIC handling
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (26 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 27/47] avcodec/ituh263dec: Simplify AIC handling Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 29/47] avcodec/flvenc: Combine writing bits Andreas Rheinhardt
` (18 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Namely with block_index and block_wrap.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263enc.c | 23 +++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index ae67907722..8126bf5c84 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -572,26 +572,17 @@ static void h263p_encode_umotion(PutBitContext *pb, int val)
static int h263_pred_dc(MPVEncContext *const s, int n, int16_t **dc_val_ptr)
{
- int x, y, wrap, a, c, pred_dc;
- int16_t *dc_val;
+ const int wrap = s->c.block_wrap[n];
+ const int xy = s->c.block_index[n];
+ int16_t *const dc_val = s->c.dc_val[0] + xy;
+ int pred_dc;
/* find prediction */
- if (n < 4) {
- x = 2 * s->c.mb_x + (n & 1);
- y = 2 * s->c.mb_y + ((n & 2) >> 1);
- wrap = s->c.b8_stride;
- dc_val = s->c.dc_val[0];
- } else {
- x = s->c.mb_x;
- y = s->c.mb_y;
- wrap = s->c.mb_stride;
- dc_val = s->c.dc_val[n - 4 + 1];
- }
/* B C
* A X
*/
- a = dc_val[(x - 1) + (y) * wrap];
- c = dc_val[(x) + (y - 1) * wrap];
+ int a = dc_val[-1];
+ int c = dc_val[-wrap];
/* No prediction outside GOB boundary */
if (s->c.first_slice_line && n != 3) {
@@ -607,7 +598,7 @@ static int h263_pred_dc(MPVEncContext *const s, int n, int16_t **dc_val_ptr)
pred_dc = c;
/* we assume pred is positive */
- *dc_val_ptr = &dc_val[x + y * wrap];
+ *dc_val_ptr = dc_val;
return pred_dc;
}
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 29/47] avcodec/flvenc: Combine writing bits
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (27 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 28/47] avcodec/ituh263enc: " Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 30/47] avcodec/flvenc: Move ff_flv2_encode_ac_esc() to ituh263enc.c Andreas Rheinhardt
` (17 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/flvenc.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index 8f07c3c778..184e688ebd 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -70,20 +70,23 @@ int ff_flv_encode_picture_header(MPVMainEncContext *const m)
void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level,
int run, int last)
{
+ unsigned code;
+ int bits;
if (level < 64) { // 7-bit level
- put_bits(pb, 1, 0);
- put_bits(pb, 1, last);
- put_bits(pb, 6, run);
-
- put_sbits(pb, 7, slevel);
+ bits = 1 + 1 + 6 + 7;
+ code = (0 << (1 + 6 + 7)) |
+ (last << (6 + 7)) |
+ (run << 7) |
+ (slevel & 0x7f);
} else {
/* 11-bit level */
- put_bits(pb, 1, 1);
- put_bits(pb, 1, last);
- put_bits(pb, 6, run);
-
- put_sbits(pb, 11, slevel);
+ bits = 1 + 1 + 6 + 11;
+ code = (1 << (1 + 6 + 11)) |
+ (last << (6 + 11)) |
+ (run << 11) |
+ (slevel & 0x7ff);
}
+ put_bits(pb, bits, code);
}
const FFCodec ff_flv_encoder = {
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 30/47] avcodec/flvenc: Move ff_flv2_encode_ac_esc() to ituh263enc.c
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (28 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 29/47] avcodec/flvenc: Combine writing bits Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 31/47] avcodec/mpegvideo: Redo resetting intra table entry Andreas Rheinhardt
` (16 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is the only place where it is used.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/flvenc.c | 22 ----------------------
libavcodec/flvenc.h | 4 ----
libavcodec/ituh263enc.c | 24 +++++++++++++++++++++++-
3 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index 184e688ebd..4143e7eecf 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -67,28 +67,6 @@ int ff_flv_encode_picture_header(MPVMainEncContext *const m)
return 0;
}
-void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level,
- int run, int last)
-{
- unsigned code;
- int bits;
- if (level < 64) { // 7-bit level
- bits = 1 + 1 + 6 + 7;
- code = (0 << (1 + 6 + 7)) |
- (last << (6 + 7)) |
- (run << 7) |
- (slevel & 0x7f);
- } else {
- /* 11-bit level */
- bits = 1 + 1 + 6 + 11;
- code = (1 << (1 + 6 + 11)) |
- (last << (6 + 11)) |
- (run << 11) |
- (slevel & 0x7ff);
- }
- put_bits(pb, bits, code);
-}
-
const FFCodec ff_flv_encoder = {
.p.name = "flv",
CODEC_LONG_NAME("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
diff --git a/libavcodec/flvenc.h b/libavcodec/flvenc.h
index 3dc7480376..a244145e42 100644
--- a/libavcodec/flvenc.h
+++ b/libavcodec/flvenc.h
@@ -21,12 +21,8 @@
#ifndef AVCODEC_FLVENC_H
#define AVCODEC_FLVENC_H
-#include "put_bits.h"
-
typedef struct MPVMainEncContext MPVMainEncContext;
int ff_flv_encode_picture_header(MPVMainEncContext *const m);
-void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run,
- int last);
#endif /* AVCODEC_FLV_H */
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 8126bf5c84..35d6aea9b5 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -417,6 +417,28 @@ void ff_clean_h263_qscales(MPVEncContext *const s)
static const int dquant_code[5]= {1,0,9,2,3};
+static void flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level,
+ int run, int last)
+{
+ unsigned code;
+ int bits;
+ if (level < 64) { // 7-bit level
+ bits = 1 + 1 + 6 + 7;
+ code = (0 << (1 + 6 + 7)) |
+ (last << (6 + 7)) |
+ (run << 7) |
+ (slevel & 0x7f);
+ } else {
+ /* 11-bit level */
+ bits = 1 + 1 + 6 + 11;
+ code = (1 << (1 + 6 + 11)) |
+ (last << (6 + 11)) |
+ (run << 11) |
+ (slevel & 0x7ff);
+ }
+ put_bits(pb, bits, code);
+}
+
/**
* Encode an 8x8 block.
* @param block the 8x8 block
@@ -522,7 +544,7 @@ static void h263_encode_block(MPVEncContext *const s, int16_t block[], int n)
put_sbits(&s->pb, 6, slevel>>5);
}
} else {
- ff_flv2_encode_ac_esc(&s->pb, slevel, level, run, last);
+ flv2_encode_ac_esc(&s->pb, slevel, level, run, last);
}
} else {
put_bits(&s->pb, 1, sign);
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 31/47] avcodec/mpegvideo: Redo resetting intra table entry
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (29 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 30/47] avcodec/flvenc: Move ff_flv2_encode_ac_esc() to ituh263enc.c Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 32/47] avcodec/mpegvideo: Avoid {a, d}c_val[{1, 2}] Andreas Rheinhardt
` (15 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
All callers check the corresponding entry of MpegEncContext.mbintra_table
and if set (indicating that the intra tables might have been written to
when decodeing a intra MB, so that they are "dirty"), call
ff_clean_intra_table_entries(), which resets them to default values
and resets the mbintra_table entry. Move resetting to the callers
(via an inline function that also performs the checks). This currently
has the advantage that the additional load of the mbintra_table ptr
can be avoided. It will also allow to simplify
ff_clean_intra_table_entries() (by using block_index[4] and [5]).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263.h | 8 ++++++++
libavcodec/h263dec.c | 3 +--
libavcodec/mpeg4videodec.c | 6 ++----
libavcodec/mpegvideo.c | 2 --
libavcodec/mpegvideo_enc.c | 7 +++++--
5 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/libavcodec/h263.h b/libavcodec/h263.h
index 59f937070e..2fee0df4cd 100644
--- a/libavcodec/h263.h
+++ b/libavcodec/h263.h
@@ -44,4 +44,12 @@ void ff_h263_init_rl_inter(void);
void ff_h263_update_motion_val(MpegEncContext * s);
void ff_h263_loop_filter(MpegEncContext * s);
+static inline void ff_h263_clean_intra_table_entries(MpegEncContext *s, int xy)
+{
+ if (s->mbintra_table[xy]) {
+ s->mbintra_table[xy] = 0;
+ ff_clean_intra_table_entries(s);
+ }
+}
+
#endif /* AVCODEC_H263_H */
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 37abf3382e..52b17663db 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -260,8 +260,7 @@ static int decode_slice(MpegEncContext *s)
if (s->h263_pred || s->h263_aic) {
int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
if (!s->mb_intra) {
- if (s->mbintra_table[mb_xy])
- ff_clean_intra_table_entries(s);
+ ff_h263_clean_intra_table_entries(s, mb_xy);
} else
s->mbintra_table[mb_xy] = 1;
}
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 32b2dec1d6..1294138d05 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1073,8 +1073,7 @@ try_again:
mot_val[1 + stride] =
mot_val[3 + stride] = my;
- if (s->mbintra_table[xy])
- ff_clean_intra_table_entries(s);
+ ff_h263_clean_intra_table_entries(s, xy);
continue;
}
@@ -1103,8 +1102,7 @@ try_again:
mot_val[1 + stride] =
mot_val[3 + stride] = 0;
} else {
- if (s->mbintra_table[xy])
- ff_clean_intra_table_entries(s);
+ ff_h263_clean_intra_table_entries(s, xy);
if (s->pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE &&
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index f6e997193d..b8f0957ec5 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -508,8 +508,6 @@ void ff_clean_intra_table_entries(MpegEncContext *s)
/* ac pred */
memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
-
- s->mbintra_table[xy]= 0;
}
void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 60abe08d7a..04cebee9c6 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3559,8 +3559,11 @@ static int encode_thread(AVCodecContext *c, void *arg){
if (s->c.mb_intra /* && I,P,S_TYPE */) {
s->p_mv_table[xy][0]=0;
s->p_mv_table[xy][1]=0;
- } else if ((s->c.h263_pred || s->c.h263_aic) && s->c.mbintra_table[xy])
- ff_clean_intra_table_entries(&s->c);
+#if CONFIG_H263_ENCODER
+ } else if (s->c.h263_pred || s->c.h263_aic) {
+ ff_h263_clean_intra_table_entries(&s->c, xy);
+#endif
+ }
if (s->c.avctx->flags & AV_CODEC_FLAG_PSNR) {
int w= 16;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 32/47] avcodec/mpegvideo: Avoid {a, d}c_val[{1, 2}]
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (30 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 31/47] avcodec/mpegvideo: Redo resetting intra table entry Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 33/47] avcodec/mpegvideo: Provide alignment hint to compiler Andreas Rheinhardt
` (14 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
These are already mostly unused; not using them here is in
preparation for removing them altogether. Use block_index[4..5]
instead for addressing.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index b8f0957ec5..109afbe858 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -492,22 +492,23 @@ void ff_clean_intra_table_entries(MpegEncContext *s)
{
int wrap = s->b8_stride;
int xy = s->block_index[0];
+ /* chroma */
+ unsigned uxy = s->block_index[4];
+ unsigned vxy = s->block_index[5];
+ int16_t *dc_val = s->dc_val[0];
s->dc_val[0][xy ] =
s->dc_val[0][xy + 1 ] =
s->dc_val[0][xy + wrap] =
s->dc_val[0][xy + 1 + wrap] = 1024;
+ dc_val[uxy] =
+ dc_val[vxy] = 1024;
/* ac pred */
memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t));
memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t));
- /* chroma */
- wrap = s->mb_stride;
- xy = s->mb_x + s->mb_y * wrap;
- s->dc_val[1][xy] =
- s->dc_val[2][xy] = 1024;
/* ac pred */
- memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
- memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
+ memset(s->ac_val[0][uxy], 0, 16 * sizeof(int16_t));
+ memset(s->ac_val[0][vxy], 0, 16 * sizeof(int16_t));
}
void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 33/47] avcodec/mpegvideo: Provide alignment hint to compiler
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (31 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 32/47] avcodec/mpegvideo: Avoid {a, d}c_val[{1, 2}] Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 34/47] avcodec/mpegvideo: Don't reset AC values of upper-left luma block Andreas Rheinhardt
` (13 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The underlying element type has always a size of 32B,
so that the pointer is always at least 16B aligned.
Clang uses this to upgrade the (inlined) memset to
aligned stores. GCC doesn't (it does it only when
the alignment hint is provided via __builtin_assume_aligned).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 109afbe858..a27efa8b89 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -504,11 +504,13 @@ void ff_clean_intra_table_entries(MpegEncContext *s)
dc_val[uxy] =
dc_val[vxy] = 1024;
/* ac pred */
- memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t));
- memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t));
+ int16_t (*ac_val)[16] = s->ac_val[0];
+ av_assume(!((uintptr_t)ac_val & 0xF));
+ memset(ac_val[xy ], 0, 2 * sizeof(*ac_val));
+ memset(ac_val[xy + wrap], 0, 2 * sizeof(*ac_val));
/* ac pred */
- memset(s->ac_val[0][uxy], 0, 16 * sizeof(int16_t));
- memset(s->ac_val[0][vxy], 0, 16 * sizeof(int16_t));
+ memset(ac_val[uxy], 0, sizeof(*ac_val));
+ memset(ac_val[vxy], 0, sizeof(*ac_val));
}
void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 34/47] avcodec/mpegvideo: Don't reset AC values of upper-left luma block
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (32 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 33/47] avcodec/mpegvideo: Provide alignment hint to compiler Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 35/47] avcodec/mpegvideo: Combine stores Andreas Rheinhardt
` (12 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Said block will only be referenced by blocks from the same macroblock,
which will read the new AC values instead of the reset values
from this function.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index a27efa8b89..b481d1eef4 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -506,7 +506,9 @@ void ff_clean_intra_table_entries(MpegEncContext *s)
/* ac pred */
int16_t (*ac_val)[16] = s->ac_val[0];
av_assume(!((uintptr_t)ac_val & 0xF));
- memset(ac_val[xy ], 0, 2 * sizeof(*ac_val));
+ // Don't reset the upper-left luma block, as it will only ever be
+ // referenced by blocks from the same macroblock.
+ memset(ac_val[xy + 1], 0, sizeof(*ac_val));
memset(ac_val[xy + wrap], 0, 2 * sizeof(*ac_val));
/* ac pred */
memset(ac_val[uxy], 0, sizeof(*ac_val));
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 35/47] avcodec/mpegvideo: Combine stores
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (33 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 34/47] avcodec/mpegvideo: Don't reset AC values of upper-left luma block Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 36/47] avcodec/mpeg4video: Don't use ac_val[1], ac_val[2] when cleaning buffers Andreas Rheinhardt
` (11 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index b481d1eef4..64563a509b 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -497,10 +497,8 @@ void ff_clean_intra_table_entries(MpegEncContext *s)
unsigned vxy = s->block_index[5];
int16_t *dc_val = s->dc_val[0];
- s->dc_val[0][xy ] =
- s->dc_val[0][xy + 1 ] =
- s->dc_val[0][xy + wrap] =
- s->dc_val[0][xy + 1 + wrap] = 1024;
+ AV_WN32A(dc_val + xy, 1024 << 16 | 1024);
+ AV_WN32 (dc_val + xy + wrap, 1024 << 16 | 1024);
dc_val[uxy] =
dc_val[vxy] = 1024;
/* ac pred */
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 36/47] avcodec/mpeg4video: Don't use ac_val[1], ac_val[2] when cleaning buffers
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (34 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 35/47] avcodec/mpegvideo: Combine stores Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 37/47] avcodec/mpegvideo: Only use a single ac_val pointer Andreas Rheinhardt
` (10 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is in preparation for removing removing ac_val[1]
and ac_val[2]. ff_mpeg4_clean_buffers() was the last user of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4video.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mpeg4video.c b/libavcodec/mpeg4video.c
index 3980a39305..a690077c58 100644
--- a/libavcodec/mpeg4video.c
+++ b/libavcodec/mpeg4video.c
@@ -43,17 +43,18 @@ int ff_mpeg4_get_video_packet_prefix_length(enum AVPictureType pict_type,
void ff_mpeg4_clean_buffers(MpegEncContext *s)
{
- int c_wrap, c_xy, l_wrap, l_xy;
+ const int mb_height = s->mb_height;
+ int c_wrap, l_wrap, l_xy;
l_wrap = s->b8_stride;
l_xy = (2 * s->mb_y - 1) * l_wrap + s->mb_x * 2 - 1;
c_wrap = s->mb_stride;
- c_xy = (s->mb_y - 1) * c_wrap + s->mb_x - 1;
+ int u_xy = 2 * mb_height * l_wrap + s->mb_y * c_wrap + s->mb_x - 1;
/* clean AC */
memset(s->ac_val[0] + l_xy, 0, (l_wrap * 2 + 1) * 16 * sizeof(int16_t));
- memset(s->ac_val[1] + c_xy, 0, (c_wrap + 1) * 16 * sizeof(int16_t));
- memset(s->ac_val[2] + c_xy, 0, (c_wrap + 1) * 16 * sizeof(int16_t));
+ memset(s->ac_val[0] + u_xy, 0, (c_wrap + 1) * 16 * sizeof(int16_t));
+ memset(s->ac_val[0] + u_xy + c_wrap * (mb_height + 1), 0, (c_wrap + 1) * 16 * sizeof(int16_t));
/* clean MV */
// we can't clear the MVs as they might be needed by a B-frame
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 37/47] avcodec/mpegvideo: Only use a single ac_val pointer
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (35 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 36/47] avcodec/mpeg4video: Don't use ac_val[1], ac_val[2] when cleaning buffers Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 38/47] avcodec/mpegvideo: Allocate ac_val jointly Andreas Rheinhardt
` (9 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The chroma pointers ac_val[1] and ac_val[2] are no longer used anywhere.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263dec.c | 2 +-
libavcodec/mpeg4video.c | 8 +++++---
libavcodec/mpeg4videodec.c | 6 ++----
libavcodec/mpeg4videoenc.c | 4 ++--
libavcodec/mpegvideo.c | 10 +++-------
libavcodec/mpegvideo.h | 2 +-
libavcodec/mpegvideo_enc.c | 4 ++--
libavcodec/vc1_block.c | 6 +++---
8 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 809bfcf564..49a87486cc 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -451,7 +451,7 @@ static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
int wrap, a, c, pred_dc, scale;
const int xy = s->block_index[n];
int16_t *const dc_val = s->dc_val[0] + xy;
- int16_t *const ac_val = (s->ac_val[0] + xy)[0];
+ int16_t *const ac_val = (s->ac_val + xy)[0];
/* find prediction */
if (n < 4) {
diff --git a/libavcodec/mpeg4video.c b/libavcodec/mpeg4video.c
index a690077c58..a53ce72dfd 100644
--- a/libavcodec/mpeg4video.c
+++ b/libavcodec/mpeg4video.c
@@ -50,11 +50,13 @@ void ff_mpeg4_clean_buffers(MpegEncContext *s)
l_xy = (2 * s->mb_y - 1) * l_wrap + s->mb_x * 2 - 1;
c_wrap = s->mb_stride;
int u_xy = 2 * mb_height * l_wrap + s->mb_y * c_wrap + s->mb_x - 1;
+ int v_xy = u_xy + c_wrap * (mb_height + 1);
+ int16_t (*ac_val)[16] = s->ac_val;
/* clean AC */
- memset(s->ac_val[0] + l_xy, 0, (l_wrap * 2 + 1) * 16 * sizeof(int16_t));
- memset(s->ac_val[0] + u_xy, 0, (c_wrap + 1) * 16 * sizeof(int16_t));
- memset(s->ac_val[0] + u_xy + c_wrap * (mb_height + 1), 0, (c_wrap + 1) * 16 * sizeof(int16_t));
+ memset(ac_val + l_xy, 0, (l_wrap * 2 + 1) * sizeof(*ac_val));
+ memset(ac_val + u_xy, 0, (c_wrap + 1) * sizeof(*ac_val));
+ memset(ac_val + v_xy, 0, (c_wrap + 1) * sizeof(*ac_val));
/* clean MV */
// we can't clear the MVs as they might be needed by a B-frame
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 1294138d05..d5d09e875d 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -326,7 +326,7 @@ void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
int8_t *const qscale_table = s->cur_pic.qscale_table;
/* find prediction */
- ac_val = &s->ac_val[0][0][0] + s->block_index[n] * 16;
+ ac_val = &s->ac_val[0][0] + s->block_index[n] * 16;
ac_val1 = ac_val;
if (s->ac_pred) {
if (dir == 0) {
@@ -3785,9 +3785,7 @@ static av_cold void clear_context(MpegEncContext *s)
s->block = NULL;
s->blocks = NULL;
s->ac_val_base = NULL;
- s->ac_val[0] =
- s->ac_val[1] =
- s->ac_val[2] =NULL;
+ s->ac_val = NULL;
memset(&s->sc, 0, sizeof(s->sc));
s->p_field_mv_table_base = NULL;
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 0fa8159f18..543fc9e649 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -130,7 +130,7 @@ static inline void restore_ac_coeffs(MPVEncContext *const s, int16_t block[6][64
memcpy(s->c.block_last_index, zigzag_last_index, sizeof(int) * 6);
for (n = 0; n < 6; n++) {
- int16_t *ac_val = &s->c.ac_val[0][0][0] + s->c.block_index[n] * 16;
+ int16_t *ac_val = &s->c.ac_val[0][0] + s->c.block_index[n] * 16;
st[n] = s->c.intra_scantable.permutated;
if (dir[n]) {
@@ -169,7 +169,7 @@ static inline int decide_ac_pred(MPVEncContext *const s, int16_t block[6][64],
score -= get_block_rate(s, block[n], s->c.block_last_index[n],
s->c.intra_scantable.permutated);
- ac_val = &s->c.ac_val[0][0][0] + s->c.block_index[n] * 16;
+ ac_val = &s->c.ac_val[0][0] + s->c.block_index[n] * 16;
ac_val1 = ac_val;
if (dir[n]) {
const int xy = s->c.mb_x + s->c.mb_y * s->c.mb_stride - s->c.mb_stride;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 64563a509b..e528935f68 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -129,9 +129,7 @@ static av_cold int init_duplicate_context(MpegEncContext *s)
/* ac values */
if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base, yc_size))
return AVERROR(ENOMEM);
- s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
- s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
- s->ac_val[2] = s->ac_val[1] + c_size;
+ s->ac_val = s->ac_val_base + s->b8_stride + 1;
}
return 0;
@@ -195,9 +193,7 @@ static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src)
COPY(start_mb_y);
COPY(end_mb_y);
COPY(ac_val_base);
- COPY(ac_val[0]);
- COPY(ac_val[1]);
- COPY(ac_val[2]);
+ COPY(ac_val);
#undef COPY
}
@@ -502,7 +498,7 @@ void ff_clean_intra_table_entries(MpegEncContext *s)
dc_val[uxy] =
dc_val[vxy] = 1024;
/* ac pred */
- int16_t (*ac_val)[16] = s->ac_val[0];
+ int16_t (*ac_val)[16] = s->ac_val;
av_assume(!((uintptr_t)ac_val & 0xF));
// Don't reset the upper-left luma block, as it will only ever be
// referenced by blocks from the same macroblock.
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 68d70cc0e3..72614d45f1 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -148,7 +148,7 @@ typedef struct MpegEncContext {
uint8_t *coded_block_base;
uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
int16_t (*ac_val_base)[16];
- int16_t (*ac_val[3])[16]; ///< used for MPEG-4 AC prediction, all 3 arrays must be continuous
+ int16_t (*ac_val)[16]; ///< used for H.263 AIC, MPEG-4 AC prediction
int mb_skipped; ///< MUST BE SET only during DECODING
uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
and used for B-frame encoding & decoding (contains skip table of next P-frame) */
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 04cebee9c6..870cf7f5a7 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3327,7 +3327,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
if(storecoefs){
for(i=0; i<6; i++){
dc[i] = s->c.dc_val[0][s->c.block_index[i]];
- memcpy(ac[i], s->c.ac_val[0][s->c.block_index[i]], sizeof(int16_t)*16);
+ memcpy(ac[i], s->c.ac_val[s->c.block_index[i]], sizeof(*s->c.ac_val));
}
}
@@ -3337,7 +3337,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
if(storecoefs){
for(i=0; i<6; i++){
s->c.dc_val[0][s->c.block_index[i]] = dc[i];
- memcpy(s->c.ac_val[0][s->c.block_index[i]], ac[i], sizeof(int16_t)*16);
+ memcpy(s->c.ac_val[s->c.block_index[i]], ac[i], sizeof(*s->c.ac_val));
}
}
}
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 1661fdd742..9427e96d1e 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -611,7 +611,7 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
/* Store the quantized DC coeff, used for prediction */
block[0] = dcdiff * s->y_dc_scale;
- ac_val = s->ac_val[0][s->block_index[n]];
+ ac_val = s->ac_val[s->block_index[n]];
ac_val2 = ac_val;
if (dc_pred_dir) // left
ac_val -= 16;
@@ -750,7 +750,7 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
scale = quant * 2 + ((mquant < 0) ? 0 : v->halfpq);
- ac_val = s->ac_val[0][s->block_index[n]];
+ ac_val = s->ac_val[s->block_index[n]];
ac_val2 = ac_val;
if (dc_pred_dir) // left
ac_val -= 16;
@@ -938,7 +938,7 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
if (!a_avail) dc_pred_dir = 1;
if (!c_avail) dc_pred_dir = 0;
if (!a_avail && !c_avail) use_pred = 0;
- ac_val = s->ac_val[0][s->block_index[n]];
+ ac_val = s->ac_val[s->block_index[n]];
ac_val2 = ac_val;
scale = quant * 2 + ((mquant < 0) ? 0 : v->halfpq);
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 38/47] avcodec/mpegvideo: Allocate ac_val jointly
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (36 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 37/47] avcodec/mpegvideo: Only use a single ac_val pointer Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 39/47] avcodec/mpegvideo: Zero-init mbintra_table Andreas Rheinhardt
` (8 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
They are currently allocated separately per slice; allocating them
jointly allows to avoid saving them in ff_update_duplicate_context().
The way it is done also avoids allocating ac_val for encoders that
don't need it (e.g. H.263 or H.263+ with AIC).
This entailed moving setting nb_slices to ff_mpv_init_context_frame()
which is called from ff_mpv_common_frame_size_change(). The resultant
nb_slices will always be one when called from a decoder using
ff_mpv_common_frame_size_change().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 60 ++++++++++++++++++--------------------
libavcodec/mpegvideo_enc.c | 36 +++++++++++++++--------
2 files changed, 52 insertions(+), 44 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index e528935f68..ae0c847aa4 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -120,18 +120,6 @@ static av_cold int init_duplicate_context(MpegEncContext *s)
return AVERROR(ENOMEM);
s->block = s->blocks[0];
- if (s->out_format == FMT_H263) {
- int mb_height = s->msmpeg4_version == MSMP4_VC1 ?
- FFALIGN(s->mb_height, 2) : s->mb_height;
- int y_size = s->b8_stride * (2 * mb_height + 1);
- int c_size = s->mb_stride * (mb_height + 1);
- int yc_size = y_size + 2 * c_size;
- /* ac values */
- if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base, yc_size))
- return AVERROR(ENOMEM);
- s->ac_val = s->ac_val_base + s->b8_stride + 1;
- }
-
return 0;
}
@@ -171,7 +159,6 @@ static av_cold void free_duplicate_context(MpegEncContext *s)
s->sc.linesize = 0;
av_freep(&s->blocks);
- av_freep(&s->ac_val_base);
s->block = NULL;
}
@@ -192,7 +179,6 @@ static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src)
COPY(block);
COPY(start_mb_y);
COPY(end_mb_y);
- COPY(ac_val_base);
COPY(ac_val);
#undef COPY
}
@@ -245,15 +231,34 @@ static av_cold void free_buffer_pools(BufferPoolContext *pools)
av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
{
+ int nb_slices = (HAVE_THREADS &&
+ s->avctx->active_thread_type & FF_THREAD_SLICE) ?
+ s->avctx->thread_count : 1;
BufferPoolContext *const pools = &s->buffer_pools;
int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
int mb_height;
+ if (s->encoding && s->avctx->slices)
+ nb_slices = s->avctx->slices;
+
if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
s->mb_height = (s->height + 31) / 32 * 2;
else
s->mb_height = (s->height + 15) / 16;
+ if (nb_slices > MAX_THREADS || (nb_slices > s->mb_height && s->mb_height)) {
+ int max_slices;
+ if (s->mb_height)
+ max_slices = FFMIN(MAX_THREADS, s->mb_height);
+ else
+ max_slices = MAX_THREADS;
+ av_log(s->avctx, AV_LOG_WARNING, "too many threads/slices (%d),"
+ " reducing to %d\n", nb_slices, max_slices);
+ nb_slices = max_slices;
+ }
+
+ s->slice_context_count = nb_slices;
+
/* VC-1 can change from being progressive to interlaced on a per-frame
* basis. We therefore allocate certain buffers so big that they work
* in both instances. */
@@ -332,6 +337,14 @@ av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
}
if (s->h263_pred || s->h263_aic || !s->encoding) {
+ size_t allslice_yc_size = yc_size * (s->encoding ? nb_slices : 1);
+ if (s->out_format == FMT_H263) {
+ /* ac values */
+ if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base, allslice_yc_size))
+ return AVERROR(ENOMEM);
+ s->ac_val = s->ac_val_base + s->b8_stride + 1;
+ }
+
/* dc values */
// MN: we need these for error resilience of intra-frames
// Allocating them unconditionally for decoders also means
@@ -381,14 +394,8 @@ av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
*/
av_cold int ff_mpv_common_init(MpegEncContext *s)
{
- int nb_slices = (HAVE_THREADS &&
- s->avctx->active_thread_type & FF_THREAD_SLICE) ?
- s->avctx->thread_count : 1;
int ret;
- if (s->encoding && s->avctx->slices)
- nb_slices = s->avctx->slices;
-
if (s->avctx->pix_fmt == AV_PIX_FMT_NONE) {
av_log(s->avctx, AV_LOG_ERROR,
"decoding to AV_PIX_FMT_NONE is not supported.\n");
@@ -411,20 +418,8 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
if ((ret = ff_mpv_init_context_frame(s)))
goto fail;
- if (nb_slices > MAX_THREADS || (nb_slices > s->mb_height && s->mb_height)) {
- int max_slices;
- if (s->mb_height)
- max_slices = FFMIN(MAX_THREADS, s->mb_height);
- else
- max_slices = MAX_THREADS;
- av_log(s->avctx, AV_LOG_WARNING, "too many threads/slices (%d),"
- " reducing to %d\n", nb_slices, max_slices);
- nb_slices = max_slices;
- }
-
s->context_initialized = 1;
s->thread_context[0] = s;
- s->slice_context_count = nb_slices;
// if (s->width && s->height) {
if (!s->encoding) {
@@ -450,6 +445,7 @@ av_cold void ff_mpv_free_context_frame(MpegEncContext *s)
for (int j = 0; j < 2; j++)
s->p_field_mv_table[i][j] = NULL;
+ av_freep(&s->ac_val_base);
av_freep(&s->dc_val_base);
av_freep(&s->coded_block_base);
av_freep(&s->mbintra_table);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 870cf7f5a7..3bec6b57cf 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -518,24 +518,36 @@ static av_cold int init_slice_buffers(MPVMainEncContext *const m)
static_assert(DCT_ERROR_SIZE * MAX_THREADS + ALIGN - 1 <= SIZE_MAX,
"Need checks for potential overflow.");
unsigned nb_slices = s->c.slice_context_count;
+ char *dct_error = NULL;
- if (!m->noise_reduction)
- return 0;
+ if (m->noise_reduction) {
+ if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_offset, 2))
+ return AVERROR(ENOMEM);
+ dct_error = av_mallocz(ALIGN - 1 + nb_slices * DCT_ERROR_SIZE);
+ if (!dct_error)
+ return AVERROR(ENOMEM);
+ m->dct_error_sum_base = dct_error;
+ dct_error += FFALIGN((uintptr_t)dct_error, ALIGN) - (uintptr_t)dct_error;
+ }
- if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_offset, 2))
- return AVERROR(ENOMEM);
- char *dct_error = av_mallocz(ALIGN - 1 + nb_slices * DCT_ERROR_SIZE);
- if (!dct_error)
- return AVERROR(ENOMEM);
- m->dct_error_sum_base = dct_error;
- dct_error += FFALIGN((uintptr_t)dct_error, ALIGN) - (uintptr_t)dct_error;
+ const int y_size = s->c.b8_stride * (2 * s->c.mb_height + 1);
+ const int c_size = s->c.mb_stride * (s->c.mb_height + 1);
+ const int yc_size = y_size + 2 * c_size;
+ ptrdiff_t offset = 0;
for (unsigned i = 0; i < nb_slices; ++i) {
MPVEncContext *const s2 = s->c.enc_contexts[i];
- s2->dct_offset = s->dct_offset;
- s2->dct_error_sum = (void*)dct_error;
- dct_error += DCT_ERROR_SIZE;
+ if (dct_error) {
+ s2->dct_offset = s->dct_offset;
+ s2->dct_error_sum = (void*)dct_error;
+ dct_error += DCT_ERROR_SIZE;
+ }
+
+ if (s2->c.ac_val) {
+ s2->c.ac_val += offset;
+ offset += yc_size;
+ }
}
return 0;
}
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 39/47] avcodec/mpegvideo: Zero-init mbintra_table
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (37 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 38/47] avcodec/mpegvideo: Allocate ac_val jointly Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 40/47] avcodec/mpegvideo: Only keep MpegEncContext.dc_val[0] Andreas Rheinhardt
` (7 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Up until now, they are marked as dirty (filled with 1), meaning that
the entries are in need of a reset via ff_clean_intra_table_entries();
but actually, the entries are initialized to the state that
ff_clean_intra_table_entries() produces, so they can be marked
as non-dirty (i.e. filled with 0).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index ae0c847aa4..df2c130a16 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -361,9 +361,8 @@ av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
// Note the + 1 is for a quicker MPEG-4 slice_end detection
if (!(s->mbskip_table = av_mallocz(mb_array_size + 2)) ||
/* which mb is an intra block, init macroblock skip table */
- !(s->mbintra_table = av_malloc(mb_array_size)))
+ !(s->mbintra_table = av_mallocz(mb_array_size)))
return AVERROR(ENOMEM);
- memset(s->mbintra_table, 1, mb_array_size);
ALLOC_POOL(qscale_table, mv_table_size, 0);
ALLOC_POOL(mb_type, mv_table_size * sizeof(uint32_t), 0);
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 40/47] avcodec/mpegvideo: Only keep MpegEncContext.dc_val[0]
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (38 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 39/47] avcodec/mpegvideo: Zero-init mbintra_table Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 41/47] avcodec/vc1: Only keep mb_type[0] Andreas Rheinhardt
` (6 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The chroma dc_val pointers are mostly unused (accesses use
dc_val[0] and block_index), so remove them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263dec.c | 2 +-
libavcodec/ituh263enc.c | 2 +-
libavcodec/mpeg4video.h | 3 +--
libavcodec/mpeg4videodec.c | 4 ++--
libavcodec/mpeg4videoenc.c | 2 +-
libavcodec/mpeg_er.c | 8 ++++----
libavcodec/mpegvideo.c | 6 ++----
libavcodec/mpegvideo.h | 2 +-
libavcodec/mpegvideo_enc.c | 6 +++---
libavcodec/msmpeg4.c | 3 +--
libavcodec/vc1_block.c | 36 ++++++++++++++++++------------------
11 files changed, 35 insertions(+), 39 deletions(-)
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 49a87486cc..f1f96010b2 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -450,7 +450,7 @@ static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
{
int wrap, a, c, pred_dc, scale;
const int xy = s->block_index[n];
- int16_t *const dc_val = s->dc_val[0] + xy;
+ int16_t *const dc_val = s->dc_val + xy;
int16_t *const ac_val = (s->ac_val + xy)[0];
/* find prediction */
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 35d6aea9b5..9a8671588c 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -596,7 +596,7 @@ static int h263_pred_dc(MPVEncContext *const s, int n, int16_t **dc_val_ptr)
{
const int wrap = s->c.block_wrap[n];
const int xy = s->c.block_index[n];
- int16_t *const dc_val = s->c.dc_val[0] + xy;
+ int16_t *const dc_val = s->c.dc_val + xy;
int pred_dc;
/* find prediction */
diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index dc0bf31922..059ea025e2 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -45,12 +45,11 @@ int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
static inline int ff_mpeg4_pred_dc(MpegEncContext *s, int n, int *dir_ptr)
{
int a, b, c, wrap, pred;
- const int16_t *dc_val;
+ const int16_t *const dc_val = s->dc_val + s->block_index[n];
/* find prediction */
wrap = s->block_wrap[n];
- dc_val = s->dc_val[0] + s->block_index[n];
/* B C
* A X
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index d5d09e875d..654e8eee3b 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -920,7 +920,7 @@ static inline int mpeg4_get_level_dc(MpegEncContext *s, int n, int pred, int lev
else if (!(s->workaround_bugs & FF_BUG_DC_CLIP))
level = 2047;
}
- s->dc_val[0][s->block_index[n]] = level;
+ s->dc_val[s->block_index[n]] = level;
return ret;
}
@@ -1347,7 +1347,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
if (use_intra_dc_vlc) {
/* DC coef */
if (s->partitioned_frame) {
- level = s->dc_val[0][s->block_index[n]];
+ level = s->dc_val[s->block_index[n]];
if (n < 4)
level = FASTDIV((level + (s->y_dc_scale >> 1)), s->y_dc_scale);
else
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 543fc9e649..27c0ee475f 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -742,7 +742,7 @@ static void mpeg4_encode_mb(MPVEncContext *const s, int16_t block[][64],
pred = FASTDIV((pred + (scale >> 1)), scale);
dc_diff[i] = block[i][0] - pred;
- s->c.dc_val[0][s->c.block_index[i]] = av_clip_uintp2(block[i][0] * scale, 11);
+ s->c.dc_val[s->c.block_index[i]] = av_clip_uintp2(block[i][0] * scale, 11);
}
if (s->c.avctx->flags & AV_CODEC_FLAG_AC_PRED) {
diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c
index 0b919f0ced..6ac3e7b3e7 100644
--- a/libavcodec/mpeg_er.c
+++ b/libavcodec/mpeg_er.c
@@ -100,7 +100,6 @@ av_cold int ff_mpeg_er_init(MpegEncContext *s)
{
ERContext *er = &s->er;
int mb_array_size = s->mb_height * s->mb_stride;
- int i;
er->avctx = s->avctx;
@@ -111,6 +110,10 @@ av_cold int ff_mpeg_er_init(MpegEncContext *s)
er->mb_stride = s->mb_stride;
er->b8_stride = s->b8_stride;
+ er->dc_val[0] = s->dc_val;
+ er->dc_val[1] = er->dc_val[0] + s->b8_stride * 2 * s->buffer_pools.alloc_mb_height + s->mb_stride;
+ er->dc_val[2] = er->dc_val[1] + s->mb_stride * (s->buffer_pools.alloc_mb_height + 1);
+
er->er_temp_buffer = av_malloc(s->mb_height * s->mb_stride * (4*sizeof(int) + 1));
er->error_status_table = av_mallocz(mb_array_size);
if (!er->er_temp_buffer || !er->error_status_table)
@@ -119,9 +122,6 @@ av_cold int ff_mpeg_er_init(MpegEncContext *s)
er->mbskip_table = s->mbskip_table;
er->mbintra_table = s->mbintra_table;
- for (i = 0; i < FF_ARRAY_ELEMS(s->dc_val); i++)
- er->dc_val[i] = s->dc_val[i];
-
er->decode_mb = mpeg_er_decode_mb;
er->opaque = s;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index df2c130a16..6c76a382cc 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -351,9 +351,7 @@ av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
// that we don't need to reinitialize when e.g. h263_aic changes.
if (!FF_ALLOC_TYPED_ARRAY(s->dc_val_base, yc_size))
return AVERROR(ENOMEM);
- s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
- s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
- s->dc_val[2] = s->dc_val[1] + c_size;
+ s->dc_val = s->dc_val_base + s->b8_stride + 1;
for (i = 0; i < yc_size; i++)
s->dc_val_base[i] = 1024;
}
@@ -486,7 +484,7 @@ void ff_clean_intra_table_entries(MpegEncContext *s)
/* chroma */
unsigned uxy = s->block_index[4];
unsigned vxy = s->block_index[5];
- int16_t *dc_val = s->dc_val[0];
+ int16_t *dc_val = s->dc_val;
AV_WN32A(dc_val + xy, 1024 << 16 | 1024);
AV_WN32 (dc_val + xy + wrap, 1024 << 16 | 1024);
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 72614d45f1..55a490adc7 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -141,13 +141,13 @@ typedef struct MpegEncContext {
int skipped_last_frame;
int last_dc[3]; ///< last DC values for MPEG-1
int16_t *dc_val_base;
- int16_t *dc_val[3]; ///< used for MPEG-4 DC prediction, all 3 arrays must be continuous
const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (H.263)
uint8_t *coded_block_base;
uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
int16_t (*ac_val_base)[16];
+ int16_t *dc_val; ///< used for H.263 AIC/MPEG-4 DC prediction and ER
int16_t (*ac_val)[16]; ///< used for H.263 AIC, MPEG-4 AC prediction
int mb_skipped; ///< MUST BE SET only during DECODING
uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 3bec6b57cf..b4e0099567 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3316,7 +3316,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
int16_t ac[6][16];
const int mvdir = (best_s.c.mv_dir & MV_DIR_BACKWARD) ? 1 : 0;
static const int dquant_tab[4]={-1,1,-2,2};
- int storecoefs = s->c.mb_intra && s->c.dc_val[0];
+ int storecoefs = s->c.mb_intra && s->c.dc_val;
av_assert2(backup_s.dquant == 0);
@@ -3338,7 +3338,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
backup_s.dquant= dquant;
if(storecoefs){
for(i=0; i<6; i++){
- dc[i] = s->c.dc_val[0][s->c.block_index[i]];
+ dc[i] = s->c.dc_val[s->c.block_index[i]];
memcpy(ac[i], s->c.ac_val[s->c.block_index[i]], sizeof(*s->c.ac_val));
}
}
@@ -3348,7 +3348,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
if (best_s.c.qscale != qp) {
if(storecoefs){
for(i=0; i<6; i++){
- s->c.dc_val[0][s->c.block_index[i]] = dc[i];
+ s->c.dc_val[s->c.block_index[i]] = dc[i];
memcpy(s->c.ac_val[s->c.block_index[i]], ac[i], sizeof(*s->c.ac_val));
}
}
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 872dc8db67..740dbdcba8 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -197,7 +197,7 @@ int ff_msmpeg4_pred_dc(MpegEncContext *s, int n,
int16_t **dc_val_ptr, int *dir_ptr)
{
int a, b, c, wrap, pred, scale;
- int16_t *dc_val;
+ int16_t *const dc_val = s->dc_val + s->block_index[n];
/* find prediction */
if (n < 4) {
@@ -207,7 +207,6 @@ int ff_msmpeg4_pred_dc(MpegEncContext *s, int n,
}
wrap = s->block_wrap[n];
- dc_val= s->dc_val[0] + s->block_index[n];
/* B C
* A X
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 9427e96d1e..9302c12c71 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -357,7 +357,7 @@ static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
scale = s->y_dc_scale;
wrap = s->block_wrap[n];
- dc_val = s->dc_val[0] + s->block_index[n];
+ dc_val = s->dc_val + s->block_index[n];
/* B A
* C X
@@ -422,7 +422,7 @@ static inline int ff_vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
return 0;
wrap = s->block_wrap[n];
- dc_val = s->dc_val[0] + s->block_index[n];
+ dc_val = s->dc_val + s->block_index[n];
/* B A
* C X
@@ -1314,7 +1314,7 @@ static int vc1_decode_p_mb(VC1Context *v)
if (!s->mb_intra) ff_vc1_mc_1mv(v, 0);
dst_idx = 0;
for (i = 0; i < 6; i++) {
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
@@ -1355,7 +1355,7 @@ static int vc1_decode_p_mb(VC1Context *v)
s->mb_intra = 0;
for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
}
s->cur_pic.mb_type[mb_pos] = MB_TYPE_SKIP;
s->cur_pic.qscale_table[mb_pos] = 0;
@@ -1370,7 +1370,7 @@ static int vc1_decode_p_mb(VC1Context *v)
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
val = ((cbp >> (5 - i)) & 1);
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
s->mb_intra = 0;
if (i < 4) {
dmv_x = dmv_y = 0;
@@ -1463,7 +1463,7 @@ static int vc1_decode_p_mb(VC1Context *v)
s->cur_pic.qscale_table[mb_pos] = 0;
for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
}
for (i = 0; i < 4; i++) {
ff_vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
@@ -1570,7 +1570,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
v->mb_type[0][s->block_index[i]] = 1;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (i == 2 || i == 3 || !s->first_slice_line)
@@ -1648,7 +1648,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
if (!v->ttmbf && cbp)
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index], VC1_TTMB_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (!fieldtx)
@@ -1673,7 +1673,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
s->mb_intra = v->is_intra[s->mb_x] = 0;
for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
}
s->cur_pic.mb_type[mb_pos] = MB_TYPE_SKIP;
s->cur_pic.qscale_table[mb_pos] = 0;
@@ -1736,7 +1736,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
v->mb_type[0][s->block_index[i]] = 1;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (i == 2 || i == 3 || !s->first_slice_line)
@@ -1789,7 +1789,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
}
dst_idx = 0;
for (i = 0; i < 6; i++) {
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
@@ -1854,7 +1854,7 @@ static int vc1_decode_b_mb(VC1Context *v)
dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
}
s->cur_pic.qscale_table[mb_pos] = 0;
@@ -1937,7 +1937,7 @@ static int vc1_decode_b_mb(VC1Context *v)
}
dst_idx = 0;
for (i = 0; i < 6; i++) {
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
@@ -2023,7 +2023,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
v->mb_type[0][s->block_index[i]] = 1;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (i == 2 || i == 3 || !s->first_slice_line)
@@ -2124,7 +2124,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
}
dst_idx = 0;
for (i = 0; i < 6; i++) {
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
@@ -2219,7 +2219,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
v->mb_type[0][s->block_index[i]] = 1;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (i == 2 || i == 3 || !s->first_slice_line)
@@ -2422,7 +2422,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
if (!v->ttmbf && cbp)
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index], VC1_TTMB_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (!fieldtx)
@@ -2447,7 +2447,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
dir = 0;
for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
- s->dc_val[0][s->block_index[i]] = 0;
+ s->dc_val[s->block_index[i]] = 0;
}
s->cur_pic.mb_type[mb_pos] = MB_TYPE_SKIP;
s->cur_pic.qscale_table[mb_pos] = 0;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 41/47] avcodec/vc1: Only keep mb_type[0]
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (39 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 40/47] avcodec/mpegvideo: Only keep MpegEncContext.dc_val[0] Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 42/47] avcodec/mpegvideo: Allocate dc_val for each encoder slice Andreas Rheinhardt
` (5 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The chroma mb_type[1] and mb_type[2] pointers are unused.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vc1.h | 2 +-
libavcodec/vc1_block.c | 96 ++++++++++++++++++-------------------
libavcodec/vc1_loopfilter.c | 10 ++--
libavcodec/vc1_mc.c | 8 ++--
libavcodec/vc1_pred.c | 14 +++---
libavcodec/vc1dec.c | 4 +-
6 files changed, 66 insertions(+), 68 deletions(-)
diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h
index da82124a5e..992c073cdc 100644
--- a/libavcodec/vc1.h
+++ b/libavcodec/vc1.h
@@ -263,7 +263,7 @@ typedef struct VC1Context{
int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding
int pqindex; ///< raw pqindex used in coding set selection
int a_avail, c_avail;
- uint8_t *mb_type_base, *mb_type[3];
+ uint8_t *mb_type_base, *mb_type;
/** Luma compensation parameters */
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 9302c12c71..f73a9a8898 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -90,8 +90,8 @@ static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
if (!s->first_slice_line && v->fcm != ILACE_FRAME) {
if (s->mb_x) {
for (i = 0; i < block_count; i++) {
- if (i > 3 ? v->mb_type[0][s->block_index[i] - s->block_wrap[i] - 1] :
- v->mb_type[0][s->block_index[i] - 2 * s->block_wrap[i] - 2]) {
+ if (i > 3 ? v->mb_type[s->block_index[i] - s->block_wrap[i] - 1] :
+ v->mb_type[s->block_index[i] - 2 * s->block_wrap[i] - 2]) {
dest = s->dest[0] + ((i & 2) - 4) * 4 * s->linesize + ((i & 1) - 2) * 8;
if (put_signed)
s->idsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][block_map[i]],
@@ -106,8 +106,8 @@ static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
}
if (s->mb_x == v->end_mb_x - 1) {
for (i = 0; i < block_count; i++) {
- if (i > 3 ? v->mb_type[0][s->block_index[i] - s->block_wrap[i]] :
- v->mb_type[0][s->block_index[i] - 2 * s->block_wrap[i]]) {
+ if (i > 3 ? v->mb_type[s->block_index[i] - s->block_wrap[i]] :
+ v->mb_type[s->block_index[i] - 2 * s->block_wrap[i]]) {
dest = s->dest[0] + ((i & 2) - 4) * 4 * s->linesize + (i & 1) * 8;
if (put_signed)
s->idsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][block_map[i]],
@@ -126,8 +126,8 @@ static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
if (v->fcm == ILACE_FRAME)
fieldtx = v->fieldtx_plane[s->mb_y * s->mb_stride + s->mb_x - 1];
for (i = 0; i < block_count; i++) {
- if (i > 3 ? v->mb_type[0][s->block_index[i] - 1] :
- v->mb_type[0][s->block_index[i] - 2]) {
+ if (i > 3 ? v->mb_type[s->block_index[i] - 1] :
+ v->mb_type[s->block_index[i] - 2]) {
if (fieldtx)
dest = s->dest[0] + ((i & 2) >> 1) * s->linesize + ((i & 1) - 2) * 8;
else
@@ -147,7 +147,7 @@ static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
if (v->fcm == ILACE_FRAME)
fieldtx = v->fieldtx_plane[s->mb_y * s->mb_stride + s->mb_x];
for (i = 0; i < block_count; i++) {
- if (v->mb_type[0][s->block_index[i]]) {
+ if (v->mb_type[s->block_index[i]]) {
if (fieldtx)
dest = s->dest[0] + ((i & 2) >> 1) * s->linesize + (i & 1) * 8;
else
@@ -1290,7 +1290,7 @@ static int vc1_decode_p_mb(VC1Context *v)
s->cur_pic.motion_val[1][s->block_index[0]][1] = 0;
}
s->cur_pic.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
- ff_vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
+ ff_vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type, 0, 0);
/* FIXME Set DC val for inter block ? */
if (s->mb_intra && !mb_has_coeffs) {
@@ -1318,14 +1318,14 @@ static int vc1_decode_p_mb(VC1Context *v)
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
- v->mb_type[0][s->block_index[i]] = s->mb_intra;
+ v->mb_type[s->block_index[i]] = s->mb_intra;
if (s->mb_intra) {
/* check if prediction blocks A and C are available */
v->a_avail = v->c_avail = 0;
if (i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ v->a_avail = v->mb_type[s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+ v->c_avail = v->mb_type[s->block_index[i] - 1];
ret = vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
@@ -1354,12 +1354,12 @@ static int vc1_decode_p_mb(VC1Context *v)
} else { // skipped
s->mb_intra = 0;
for (i = 0; i < 6; i++) {
- v->mb_type[0][s->block_index[i]] = 0;
+ v->mb_type[s->block_index[i]] = 0;
s->dc_val[s->block_index[i]] = 0;
}
s->cur_pic.mb_type[mb_pos] = MB_TYPE_SKIP;
s->cur_pic.qscale_table[mb_pos] = 0;
- ff_vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
+ ff_vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type, 0, 0);
ff_vc1_mc_1mv(v, 0);
}
} else { // 4MV mode
@@ -1379,7 +1379,7 @@ static int vc1_decode_p_mb(VC1Context *v)
if (val) {
GET_MVDATA(dmv_x, dmv_y);
}
- ff_vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
+ ff_vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type, 0, 0);
if (!s->mb_intra)
ff_vc1_mc_4mv_luma(v, i, 0, 0);
intra_count += s->mb_intra;
@@ -1392,7 +1392,7 @@ static int vc1_decode_p_mb(VC1Context *v)
}
if (i == 4)
ff_vc1_mc_4mv_chroma(v, 0);
- v->mb_type[0][s->block_index[i]] = is_intra[i];
+ v->mb_type[s->block_index[i]] = is_intra[i];
if (!coded_inter)
coded_inter = !is_intra[i] & is_coded[i];
}
@@ -1407,8 +1407,8 @@ static int vc1_decode_p_mb(VC1Context *v)
int intrapred = 0;
for (i = 0; i < 6; i++)
if (is_intra[i]) {
- if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
- || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) {
+ if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[s->block_index[i] - s->block_wrap[i]])
+ || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[s->block_index[i] - 1])) {
intrapred = 1;
break;
}
@@ -1428,9 +1428,9 @@ static int vc1_decode_p_mb(VC1Context *v)
/* check if prediction blocks A and C are available */
v->a_avail = v->c_avail = 0;
if (i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ v->a_avail = v->mb_type[s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+ v->c_avail = v->mb_type[s->block_index[i] - 1];
ret = vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, is_coded[i], mquant,
(i & 4) ? v->codingset2 : v->codingset);
@@ -1462,11 +1462,11 @@ static int vc1_decode_p_mb(VC1Context *v)
s->mb_intra = 0;
s->cur_pic.qscale_table[mb_pos] = 0;
for (i = 0; i < 6; i++) {
- v->mb_type[0][s->block_index[i]] = 0;
+ v->mb_type[s->block_index[i]] = 0;
s->dc_val[s->block_index[i]] = 0;
}
for (i = 0; i < 4; i++) {
- ff_vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
+ ff_vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type, 0, 0);
ff_vc1_mc_4mv_luma(v, i, 0, 0);
}
ff_vc1_mc_4mv_chroma(v, 0);
@@ -1569,14 +1569,14 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
dst_idx = 0;
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
- v->mb_type[0][s->block_index[i]] = 1;
+ v->mb_type[s->block_index[i]] = 1;
s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ v->a_avail = v->mb_type[s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+ v->c_avail = v->mb_type[s->block_index[i] - 1];
ret = vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
@@ -1602,7 +1602,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
}
s->mb_intra = v->is_intra[s->mb_x] = 0;
for (i = 0; i < 6; i++)
- v->mb_type[0][s->block_index[i]] = 0;
+ v->mb_type[s->block_index[i]] = 0;
fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][1];
/* for all motion vector read MVDATA and motion compensate each block */
dst_idx = 0;
@@ -1672,7 +1672,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
} else { // skipped
s->mb_intra = v->is_intra[s->mb_x] = 0;
for (i = 0; i < 6; i++) {
- v->mb_type[0][s->block_index[i]] = 0;
+ v->mb_type[s->block_index[i]] = 0;
s->dc_val[s->block_index[i]] = 0;
}
s->cur_pic.mb_type[mb_pos] = MB_TYPE_SKIP;
@@ -1735,14 +1735,14 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
dst_idx = 0;
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
- v->mb_type[0][s->block_index[i]] = 1;
+ v->mb_type[s->block_index[i]] = 1;
s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ v->a_avail = v->mb_type[s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+ v->c_avail = v->mb_type[s->block_index[i] - 1];
ret = vc1_decode_intra_block(v, v->block[v->cur_blk_idx][block_map[i]], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
@@ -1757,13 +1757,13 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
s->mb_intra = v->is_intra[s->mb_x] = 0;
s->cur_pic.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
for (i = 0; i < 6; i++)
- v->mb_type[0][s->block_index[i]] = 0;
+ v->mb_type[s->block_index[i]] = 0;
if (idx_mbmode <= 5) { // 1-MV
dmv_x = dmv_y = pred_flag = 0;
if (idx_mbmode & 1) {
get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
}
- ff_vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
+ ff_vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type, pred_flag, 0);
ff_vc1_mc_1mv(v, 0);
mb_has_coeffs = !(idx_mbmode & 2);
} else { // 4-MV
@@ -1772,7 +1772,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
dmv_x = dmv_y = pred_flag = 0;
if (v->fourmvbp & (8 >> i))
get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
- ff_vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
+ ff_vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type, pred_flag, 0);
ff_vc1_mc_4mv_luma(v, i, 0, 0);
}
ff_vc1_mc_4mv_chroma(v, 0);
@@ -1853,7 +1853,7 @@ static int vc1_decode_b_mb(VC1Context *v)
dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
for (i = 0; i < 6; i++) {
- v->mb_type[0][s->block_index[i]] = 0;
+ v->mb_type[s->block_index[i]] = 0;
s->dc_val[s->block_index[i]] = 0;
}
s->cur_pic.qscale_table[mb_pos] = 0;
@@ -1880,7 +1880,7 @@ static int vc1_decode_b_mb(VC1Context *v)
}
}
for (i = 0; i < 6; i++)
- v->mb_type[0][s->block_index[i]] = s->mb_intra;
+ v->mb_type[s->block_index[i]] = s->mb_intra;
if (skipped) {
if (direct)
@@ -1941,14 +1941,14 @@ static int vc1_decode_b_mb(VC1Context *v)
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
- v->mb_type[0][s->block_index[i]] = s->mb_intra;
+ v->mb_type[s->block_index[i]] = s->mb_intra;
if (s->mb_intra) {
/* check if prediction blocks A and C are available */
v->a_avail = v->c_avail = 0;
if (i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ v->a_avail = v->mb_type[s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+ v->c_avail = v->mb_type[s->block_index[i] - 1];
ret = vc1_decode_intra_block(v, s->block[i], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
@@ -2022,14 +2022,14 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
dst_idx = 0;
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
- v->mb_type[0][s->block_index[i]] = 1;
+ v->mb_type[s->block_index[i]] = 1;
s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ v->a_avail = v->mb_type[s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+ v->c_avail = v->mb_type[s->block_index[i] - 1];
ret = vc1_decode_intra_block(v, s->block[i], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
@@ -2051,7 +2051,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
s->mb_intra = v->is_intra[s->mb_x] = 0;
s->cur_pic.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
for (i = 0; i < 6; i++)
- v->mb_type[0][s->block_index[i]] = 0;
+ v->mb_type[s->block_index[i]] = 0;
if (v->fmb_is_raw)
fwd = v->forward_mb_plane[mb_pos] = get_bits1(gb);
else
@@ -2218,14 +2218,14 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
dst_idx = 0;
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
- v->mb_type[0][s->block_index[i]] = 1;
+ v->mb_type[s->block_index[i]] = 1;
s->dc_val[s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
if (i == 2 || i == 3 || !s->first_slice_line)
- v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
+ v->a_avail = v->mb_type[s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
- v->c_avail = v->mb_type[0][s->block_index[i] - 1];
+ v->c_avail = v->mb_type[s->block_index[i] - 1];
ret = vc1_decode_intra_block(v, s->block[i], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
@@ -2315,7 +2315,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
}
for (i = 0; i < 6; i++)
- v->mb_type[0][s->block_index[i]] = 0;
+ v->mb_type[s->block_index[i]] = 0;
fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[0][idx_mbmode][1];
/* for all motion vector read MVDATA and motion compensate each block */
dst_idx = 0;
@@ -2446,7 +2446,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
} else { // skipped
dir = 0;
for (i = 0; i < 6; i++) {
- v->mb_type[0][s->block_index[i]] = 0;
+ v->mb_type[s->block_index[i]] = 0;
s->dc_val[s->block_index[i]] = 0;
}
s->cur_pic.mb_type[mb_pos] = MB_TYPE_SKIP;
@@ -2562,7 +2562,7 @@ static void vc1_decode_i_blocks(VC1Context *v)
v->s.ac_pred = get_bits1(&v->s.gb);
for (k = 0; k < 6; k++) {
- v->mb_type[0][s->block_index[k]] = 1;
+ v->mb_type[s->block_index[k]] = 1;
val = ((cbp >> (5 - k)) & 1);
@@ -2708,7 +2708,7 @@ static int vc1_decode_i_blocks_adv(VC1Context *v)
s->y_dc_scale = ff_wmv3_dc_scale_table[FFABS(mquant)];
for (k = 0; k < 6; k++) {
- v->mb_type[0][s->block_index[k]] = 1;
+ v->mb_type[s->block_index[k]] = 1;
val = ((cbp >> (5 - k)) & 1);
diff --git a/libavcodec/vc1_loopfilter.c b/libavcodec/vc1_loopfilter.c
index e788d1890e..1d71d9d5ca 100644
--- a/libavcodec/vc1_loopfilter.c
+++ b/libavcodec/vc1_loopfilter.c
@@ -175,7 +175,7 @@ void ff_vc1_p_overlap_filter(VC1Context *v)
if (s->mb_x == 0 && (i & 5) != 1)
continue;
- if (v->mb_type[0][s->block_index[i]] && v->mb_type[0][s->block_index[i] - 1])
+ if (v->mb_type[s->block_index[i]] && v->mb_type[s->block_index[i] - 1])
vc1_h_overlap_filter(v,
s->mb_x ? left_blk : cur_blk, cur_blk,
v->fcm == ILACE_FRAME && s->mb_x && v->fieldtx_plane[mb_pos - 1],
@@ -188,12 +188,12 @@ void ff_vc1_p_overlap_filter(VC1Context *v)
if (s->first_slice_line && !(i & 2))
continue;
- if (s->mb_x && v->mb_type[0][s->block_index[i] - 2 + (i > 3)] &&
- v->mb_type[0][s->block_index[i] - s->block_wrap[i] - 2 + (i > 3)])
+ if (s->mb_x && v->mb_type[s->block_index[i] - 2 + (i > 3)] &&
+ v->mb_type[s->block_index[i] - s->block_wrap[i] - 2 + (i > 3)])
vc1_v_overlap_filter(v, s->first_slice_line ? left_blk : topleft_blk, left_blk, i);
if (s->mb_x == s->mb_width - 1)
- if (v->mb_type[0][s->block_index[i]] &&
- v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
+ if (v->mb_type[s->block_index[i]] &&
+ v->mb_type[s->block_index[i] - s->block_wrap[i]])
vc1_v_overlap_filter(v, s->first_slice_line ? cur_blk : top_blk, cur_blk, i);
}
}
diff --git a/libavcodec/vc1_mc.c b/libavcodec/vc1_mc.c
index 9adb71c7ad..db19d95ef9 100644
--- a/libavcodec/vc1_mc.c
+++ b/libavcodec/vc1_mc.c
@@ -140,10 +140,10 @@ static av_always_inline int get_luma_mv(VC1Context *v, int dir, int16_t *tx, int
static av_always_inline int get_chroma_mv(VC1Context *v, int dir, int16_t *tx, int16_t *ty)
{
MpegEncContext *s = &v->s;
- int idx = !v->mb_type[0][s->block_index[0]] |
- (!v->mb_type[0][s->block_index[1]] << 1) |
- (!v->mb_type[0][s->block_index[2]] << 2) |
- (!v->mb_type[0][s->block_index[3]] << 3);
+ int idx = !v->mb_type[s->block_index[0]] |
+ (!v->mb_type[s->block_index[1]] << 1) |
+ (!v->mb_type[s->block_index[2]] << 2) |
+ (!v->mb_type[s->block_index[3]] << 3);
static const uint8_t index2[16] = { 0, 0, 0, 0x01, 0, 0x02, 0x12, 0, 0, 0x03, 0x13, 0, 0x23, 0, 0, 0 };
int valid_count = popcount4[idx];
diff --git a/libavcodec/vc1_pred.c b/libavcodec/vc1_pred.c
index 87d9b6d6dc..202fa8cc3b 100644
--- a/libavcodec/vc1_pred.c
+++ b/libavcodec/vc1_pred.c
@@ -695,7 +695,7 @@ void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2],
int px, py;
int sum;
int r_x, r_y;
- const uint8_t *is_intra = v->mb_type[0];
+ const uint8_t *is_intra = v->mb_type;
av_assert0(!v->field_mode);
@@ -927,19 +927,19 @@ void ff_vc1_pred_b_mv_intfi(VC1Context *v, int n, int *dmv_x, int *dmv_y,
return;
}
if (v->bmvtype == BMV_TYPE_INTERPOLATED) {
- ff_vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0);
- ff_vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1);
+ ff_vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type, pred_flag[0], 0);
+ ff_vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type, pred_flag[1], 1);
return;
}
if (dir) { // backward
- ff_vc1_pred_mv(v, n, dmv_x[1], dmv_y[1], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1);
+ ff_vc1_pred_mv(v, n, dmv_x[1], dmv_y[1], mv1, v->range_x, v->range_y, v->mb_type, pred_flag[1], 1);
if (n == 3 || mv1) {
- ff_vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
+ ff_vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type, 0, 0);
}
} else { // forward
- ff_vc1_pred_mv(v, n, dmv_x[0], dmv_y[0], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0);
+ ff_vc1_pred_mv(v, n, dmv_x[0], dmv_y[0], mv1, v->range_x, v->range_y, v->mb_type, pred_flag[0], 0);
if (n == 3 || mv1) {
- ff_vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type[0], 0, 1);
+ ff_vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type, 0, 1);
}
}
}
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 7ee014d4b6..97174d10e3 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -396,9 +396,7 @@ static av_cold int vc1_decode_init_alloc_tables(VC1Context *v)
v->mb_type_base = av_mallocz(s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
if (!v->mb_type_base)
return AVERROR(ENOMEM);
- v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
- v->mb_type[1] = v->mb_type_base + s->b8_stride * (mb_height * 2 + 1) + s->mb_stride + 1;
- v->mb_type[2] = v->mb_type[1] + s->mb_stride * (mb_height + 1);
+ v->mb_type = v->mb_type_base + s->b8_stride + 1;
/* allocate memory to store block level MV info */
v->blk_mv_type_base = av_mallocz( s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 42/47] avcodec/mpegvideo: Allocate dc_val for each encoder slice
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (40 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 41/47] avcodec/vc1: Only keep mb_type[0] Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 43/47] avcodec/{ituh263, mpeg4video}enc: Simplify out-of-slice DC prediction Andreas Rheinhardt
` (4 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This fixes data races (which are UB) in the MPEG-4 and H.263+
encoder when predicting DC values; these encoders unconditionally
read values from the line above the current line and only check
lateron (via first_slice_line) whether said prediction can be used
at all. It will also allow to remove said checks (by setting the
entries to 1024 upon opening a new slice).
The vsynth{1,2,3,_lena}-mpeg4-thread FATE tests were affected by this:
https://fate.ffmpeg.org/report.cgi?slot=x86_64-archlinux-gcc-tsan-slices&time=20250613002615
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 15 ++++++++++++---
libavcodec/mpegvideo_enc.c | 1 +
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 6c76a382cc..4701267d81 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -179,6 +179,7 @@ static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src)
COPY(block);
COPY(start_mb_y);
COPY(end_mb_y);
+ COPY(dc_val);
COPY(ac_val);
#undef COPY
}
@@ -235,7 +236,7 @@ av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
s->avctx->active_thread_type & FF_THREAD_SLICE) ?
s->avctx->thread_count : 1;
BufferPoolContext *const pools = &s->buffer_pools;
- int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
+ int y_size, c_size, yc_size, mb_array_size, mv_table_size, x, y;
int mb_height;
if (s->encoding && s->avctx->slices)
@@ -337,6 +338,9 @@ av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
}
if (s->h263_pred || s->h263_aic || !s->encoding) {
+ // When encoding, each slice (and therefore each thread)
+ // gets its own ac_val and dc_val buffers in order to avoid
+ // races.
size_t allslice_yc_size = yc_size * (s->encoding ? nb_slices : 1);
if (s->out_format == FMT_H263) {
/* ac values */
@@ -349,10 +353,15 @@ av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
// MN: we need these for error resilience of intra-frames
// Allocating them unconditionally for decoders also means
// that we don't need to reinitialize when e.g. h263_aic changes.
- if (!FF_ALLOC_TYPED_ARRAY(s->dc_val_base, yc_size))
+
+ // y_size and therefore yc_size is always odd; allocate one element
+ // more for each encoder slice in order to be able to align each slice's
+ // dc_val to four in order to use aligned stores when cleaning dc_val.
+ allslice_yc_size += s->encoding * nb_slices;
+ if (!FF_ALLOC_TYPED_ARRAY(s->dc_val_base, allslice_yc_size))
return AVERROR(ENOMEM);
s->dc_val = s->dc_val_base + s->b8_stride + 1;
- for (i = 0; i < yc_size; i++)
+ for (size_t i = 0; i < allslice_yc_size; ++i)
s->dc_val_base[i] = 1024;
}
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index b4e0099567..1f581ec500 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -545,6 +545,7 @@ static av_cold int init_slice_buffers(MPVMainEncContext *const m)
}
if (s2->c.ac_val) {
+ s2->c.dc_val += offset + i;
s2->c.ac_val += offset;
offset += yc_size;
}
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 43/47] avcodec/{ituh263, mpeg4video}enc: Simplify out-of-slice DC prediction
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (41 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 42/47] avcodec/mpegvideo: Allocate dc_val for each encoder slice Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 44/47] avcodec/mpeg4video: Move ff_mpeg4_pred_dc() to decoder Andreas Rheinhardt
` (3 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Now that every slice (and therefore every thread) uses its own
DC array, one can simply set the out-of-slice DC values to its
expected values (this is not possible for the decoders due
to error resilience).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263enc.h | 1 +
libavcodec/ituh263enc.c | 21 ++++++++++++++++-----
libavcodec/mpeg4videoenc.c | 32 +++++++++++++++++++++++++++++++-
libavcodec/mpegvideo_enc.c | 8 +++++++-
4 files changed, 55 insertions(+), 7 deletions(-)
diff --git a/libavcodec/h263enc.h b/libavcodec/h263enc.h
index 63af3a576f..20e0c57326 100644
--- a/libavcodec/h263enc.h
+++ b/libavcodec/h263enc.h
@@ -27,6 +27,7 @@
const uint8_t (*ff_h263_get_mv_penalty(void))[MAX_DMV*2+1];
void ff_h263_encode_init(MPVMainEncContext *m);
+void ff_h263_mpeg4_reset_dc(MPVEncContext *s);
void ff_h263_encode_gob_header(MPVEncContext *s, int mb_line);
void ff_h263_encode_mba(MPVEncContext *s);
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 9a8671588c..d1d07bc5f8 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -361,6 +361,22 @@ static int h263_encode_picture_header(MPVMainEncContext *const m)
return 0;
}
+void ff_h263_mpeg4_reset_dc(MPVEncContext *s)
+{
+ int16_t *dc = s->c.dc_val;
+
+ // The "- 1" is for the top-left entry
+ const int l_xy = s->c.block_index[2];
+ for (int i = l_xy - 2 * s->c.b8_stride - 1; i < l_xy; i += 2)
+ AV_WN32A(dc + i, 1024 << 16 | 1024);
+
+ const int u_xy = s->c.block_index[4];
+ const int v_xy = s->c.block_index[5];
+ int16_t *dc2 = dc + v_xy - u_xy;
+ for (int i = u_xy - s->c.mb_stride - 1; i < u_xy; ++i)
+ dc[i] = dc2[i] = 1024;
+}
+
/**
* Encode a group of blocks header.
*/
@@ -606,11 +622,6 @@ static int h263_pred_dc(MPVEncContext *const s, int n, int16_t **dc_val_ptr)
int a = dc_val[-1];
int c = dc_val[-wrap];
- /* No prediction outside GOB boundary */
- if (s->c.first_slice_line && n != 3) {
- if (n != 2) c = 1024;
- if (n != 1 && s->c.mb_x == s->c.resync_mb_x) a = 1024;
- }
/* just DC prediction */
if (a != 1024 && c != 1024)
pred_dc = (a + c) >> 1;
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 27c0ee475f..1b8ccad380 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -145,6 +145,36 @@ static inline void restore_ac_coeffs(MPVEncContext *const s, int16_t block[6][64
}
}
+/**
+ * Predict the dc.
+ * @param n block index (0-3 are luma, 4-5 are chroma)
+ * @param dir_ptr pointer to an integer where the prediction direction will be stored
+ */
+static int mpeg4_pred_dc(MpegEncContext *s, int n, int *dir_ptr)
+{
+ const int16_t *const dc_val = s->dc_val + s->block_index[n];
+ const int wrap = s->block_wrap[n];
+
+ /* B C
+ * A X
+ */
+ const int a = dc_val[-1];
+ const int b = dc_val[-1 - wrap];
+ const int c = dc_val[-wrap];
+ int pred;
+
+ // There is no need for out-of-slice handling here, as all values are set
+ // appropriately when a new slice is opened.
+ if (abs(a - b) < abs(b - c)) {
+ pred = c;
+ *dir_ptr = 1; /* top */
+ } else {
+ pred = a;
+ *dir_ptr = 0; /* left */
+ }
+ return pred;
+}
+
/**
* Return the optimal value (0 or 1) for the ac_pred element for the given MB in MPEG-4.
* This function will also update s->c.block_last_index and s->c.ac_val.
@@ -737,7 +767,7 @@ static void mpeg4_encode_mb(MPVEncContext *const s, int16_t block[][64],
int i;
for (int i = 0; i < 6; i++) {
- int pred = ff_mpeg4_pred_dc(&s->c, i, &dir[i]);
+ int pred = mpeg4_pred_dc(&s->c, i, &dir[i]);
int scale = i < 4 ? s->c.y_dc_scale : s->c.c_dc_scale;
pred = FASTDIV((pred + (scale >> 1)), scale);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 1f581ec500..1f51f237fa 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3140,6 +3140,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
if (CONFIG_MPEG4_ENCODER) {
ff_mpeg4_encode_video_packet_header(s);
ff_mpeg4_clean_buffers(&s->c);
+ ff_h263_mpeg4_reset_dc(s);
}
break;
case AV_CODEC_ID_MPEG1VIDEO:
@@ -3149,8 +3150,13 @@ static int encode_thread(AVCodecContext *c, void *arg){
ff_mpeg1_clean_buffers(&s->c);
}
break;
- case AV_CODEC_ID_H263:
+#if CONFIG_H263P_ENCODER
case AV_CODEC_ID_H263P:
+ if (s->c.dc_val)
+ ff_h263_mpeg4_reset_dc(s);
+ // fallthrough
+#endif
+ case AV_CODEC_ID_H263:
if (CONFIG_H263_ENCODER) {
update_mb_info(s, 1);
ff_h263_encode_gob_header(s, mb_y);
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 44/47] avcodec/mpeg4video: Move ff_mpeg4_pred_dc() to decoder
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (42 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 43/47] avcodec/{ituh263, mpeg4video}enc: Simplify out-of-slice DC prediction Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 45/47] avcodec/ituh263enc: Simplify encoding umotion vectors Andreas Rheinhardt
` (2 subsequent siblings)
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Only used by the decoder now that the encoder solves
out-of-slice predictions by setting the out-of-slice
values appropriately.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4video.h | 44 -----------------------------------
libavcodec/mpeg4videodec.c | 47 ++++++++++++++++++++++++++++++++++++--
2 files changed, 45 insertions(+), 46 deletions(-)
diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index 059ea025e2..274b21a067 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -37,48 +37,4 @@ void ff_mpeg4_init_direct_mv(MpegEncContext *s);
*/
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
-/**
- * Predict the dc.
- * @param n block index (0-3 are luma, 4-5 are chroma)
- * @param dir_ptr pointer to an integer where the prediction direction will be stored
- */
-static inline int ff_mpeg4_pred_dc(MpegEncContext *s, int n, int *dir_ptr)
-{
- int a, b, c, wrap, pred;
- const int16_t *const dc_val = s->dc_val + s->block_index[n];
-
- /* find prediction */
-
- wrap = s->block_wrap[n];
-
- /* B C
- * A X
- */
- a = dc_val[-1];
- b = dc_val[-1 - wrap];
- c = dc_val[-wrap];
-
- /* outside slice handling (we can't do that by memset as we need the
- * dc for error resilience) */
- if (s->first_slice_line && n != 3) {
- if (n != 2)
- b = c = 1024;
- if (n != 1 && s->mb_x == s->resync_mb_x)
- b = a = 1024;
- }
- if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) {
- if (n == 0 || n == 4 || n == 5)
- b = 1024;
- }
-
- if (abs(a - b) < abs(b - c)) {
- pred = c;
- *dir_ptr = 1; /* top */
- } else {
- pred = a;
- *dir_ptr = 0; /* left */
- }
- return pred;
-}
-
#endif /* AVCODEC_MPEG4VIDEO_H */
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 654e8eee3b..522242de40 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -888,6 +888,49 @@ static inline int get_amv(Mpeg4DecContext *ctx, int n)
return sum;
}
+/**
+ * Predict the dc.
+ * @param n block index (0-3 are luma, 4-5 are chroma)
+ * @param dir_ptr pointer to an integer where the prediction direction will be stored
+ */
+static inline int mpeg4_pred_dc(MpegEncContext *s, int n, int *dir_ptr)
+{
+ const int16_t *const dc_val = s->dc_val + s->block_index[n];
+ const int wrap = s->block_wrap[n];
+ int pred;
+
+ /* find prediction */
+
+ /* B C
+ * A X
+ */
+ int a = dc_val[-1];
+ int b = dc_val[-1 - wrap];
+ int c = dc_val[-wrap];
+
+ /* outside slice handling (we can't do that by memset as we need the
+ * dc for error resilience) */
+ if (s->first_slice_line && n != 3) {
+ if (n != 2)
+ b = c = 1024;
+ if (n != 1 && s->mb_x == s->resync_mb_x)
+ b = a = 1024;
+ }
+ if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) {
+ if (n == 0 || n == 4 || n == 5)
+ b = 1024;
+ }
+
+ if (abs(a - b) < abs(b - c)) {
+ pred = c;
+ *dir_ptr = 1; /* top */
+ } else {
+ pred = a;
+ *dir_ptr = 0; /* left */
+ }
+ return pred;
+}
+
static inline int mpeg4_get_level_dc(MpegEncContext *s, int n, int pred, int level)
{
int scale = n < 4 ? s->y_dc_scale : s->c_dc_scale;
@@ -971,7 +1014,7 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
}
}
- pred = ff_mpeg4_pred_dc(s, n, dir_ptr);
+ pred = mpeg4_pred_dc(s, n, dir_ptr);
return mpeg4_get_level_dc(s, n, pred, level);
}
@@ -1362,7 +1405,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
i = 0;
} else {
i = -1;
- pred = ff_mpeg4_pred_dc(s, n, &dc_pred_dir);
+ pred = mpeg4_pred_dc(s, n, &dc_pred_dir);
}
if (!coded)
goto not_coded;
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 45/47] avcodec/ituh263enc: Simplify encoding umotion vectors
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (43 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 44/47] avcodec/mpeg4video: Move ff_mpeg4_pred_dc() to decoder Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 46/47] avcodec/mpegvideo: Reduce stack usage when copying MpegEncContext Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 47/47] avcodec/mpeg4videoenc: Fix data race when using AC prediction Andreas Rheinhardt
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
There is no need to use two loops.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263enc.c | 38 ++++++++++----------------------------
1 file changed, 10 insertions(+), 28 deletions(-)
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index d1d07bc5f8..903bb45fce 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -573,38 +573,20 @@ static void h263_encode_block(MPVEncContext *const s, int16_t block[], int n)
/* Encode MV differences on H.263+ with Unrestricted MV mode */
static void h263p_encode_umotion(PutBitContext *pb, int val)
{
- short sval = 0;
- short i = 0;
- short n_bits = 0;
- short temp_val;
- int code = 0;
- int tcode;
-
if ( val == 0)
put_bits(pb, 1, 1);
- else if (val == 1)
- put_bits(pb, 3, 0);
- else if (val == -1)
- put_bits(pb, 3, 2);
else {
-
- sval = ((val < 0) ? (short)(-val):(short)val);
- temp_val = sval;
-
- while (temp_val != 0) {
- temp_val = temp_val >> 1;
- n_bits++;
- }
-
- i = n_bits - 1;
- while (i > 0) {
- tcode = (sval & (1 << (i-1))) >> (i-1);
- tcode = (tcode << 1) | 1;
- code = (code << 2) | tcode;
- i--;
+ unsigned code = (val < 0) << 1;
+ unsigned aval = val < 0 ? -val : val;
+ unsigned n_bits = 2;
+
+ while (aval != 1) { // The leading digit is implicitly coded via length
+ unsigned tmp = (aval & 1) << 1 | 1;
+ aval >>= 1;
+ code |= tmp << n_bits;
+ n_bits += 2;
}
- code = ((code << 1) | (val < 0)) << 1;
- put_bits(pb, (2*n_bits)+1, code);
+ put_bits(pb, n_bits + 1, code);
}
}
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 46/47] avcodec/mpegvideo: Reduce stack usage when copying MpegEncContext
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (44 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 45/47] avcodec/ituh263enc: Simplify encoding umotion vectors Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 47/47] avcodec/mpeg4videoenc: Fix data race when using AC prediction Andreas Rheinhardt
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(GCC did not perform this on its own; Clang did.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 4701267d81..ff2703f487 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -171,27 +171,24 @@ static av_cold void free_duplicate_contexts(MpegEncContext *s)
free_duplicate_context(s);
}
-static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src)
-{
-#define COPY(a) bak->a = src->a
- COPY(sc);
- COPY(blocks);
- COPY(block);
- COPY(start_mb_y);
- COPY(end_mb_y);
- COPY(dc_val);
- COPY(ac_val);
-#undef COPY
-}
-
int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
{
- MpegEncContext bak;
+#define COPY(M) \
+ M(ScratchpadContext, sc) \
+ M(void*, blocks) \
+ M(void*, block) \
+ M(int, start_mb_y) \
+ M(int, end_mb_y) \
+ M(int16_t*, dc_val) \
+ M(void*, ac_val)
+
int ret;
// FIXME copy only needed parts
- backup_duplicate_context(&bak, dst);
+#define BACKUP(T, member) T member = dst->member;
+ COPY(BACKUP)
memcpy(dst, src, sizeof(MpegEncContext));
- backup_duplicate_context(dst, &bak);
+#define RESTORE(T, member) dst->member = member;
+ COPY(RESTORE)
ret = ff_mpv_framesize_alloc(dst->avctx, &dst->sc, dst->linesize);
if (ret < 0) {
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
* [FFmpeg-devel] [PATCH 47/47] avcodec/mpeg4videoenc: Fix data race when using AC prediction
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
` (45 preceding siblings ...)
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 46/47] avcodec/mpegvideo: Reduce stack usage when copying MpegEncContext Andreas Rheinhardt
@ 2025-06-15 16:54 ` Andreas Rheinhardt
46 siblings, 0 replies; 48+ messages in thread
From: Andreas Rheinhardt @ 2025-06-15 16:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The check for whether we can use the fast path to process
AC coefficients used the qscale value belonging to a different
slice; this worked in practice, because the predicted AC values
are zero in this case, so it does not matter whether we use
the fast or the slow path.
Fix this by checking for first_slice_line instead. This fixes all
the races in the encoding part of the vsynth*-mpeg4-thread tests
(and fixes them if no frame threading is in use for the decoding part).
(The left prediction check may use data from a different slice, too,
but said slice is always processed by the same thread, so that no race
can happen. Given that out-of-slice AC values are zero, it does not
matter whether we use the fast path or the slow path either.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videoenc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 1b8ccad380..a9d673707a 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -205,7 +205,7 @@ static inline int decide_ac_pred(MPVEncContext *const s, int16_t block[6][64],
const int xy = s->c.mb_x + s->c.mb_y * s->c.mb_stride - s->c.mb_stride;
/* top prediction */
ac_val -= s->c.block_wrap[n] * 16;
- if (s->c.mb_y == 0 || s->c.qscale == qscale_table[xy] || n == 2 || n == 3) {
+ if (s->c.first_slice_line || s->c.qscale == qscale_table[xy] || n == 2 || n == 3) {
/* same qscale */
for (i = 1; i < 8; i++) {
const int level = block[n][s->c.idsp.idct_permutation[i]];
--
ffmpeg-codebot
_______________________________________________
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".
^ permalink raw reply [flat|nested] 48+ messages in thread
end of thread, other threads:[~2025-06-15 17:04 UTC | newest]
Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-15 16:53 [FFmpeg-devel] [PATCH 00/47] avcodec/mpeg4videodec: Don't zero blocks twice ffmpegagent
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 01/47] " Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 02/47] avcodec/rv10: Perform RV20 initialization during init Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 03/47] avcodec/rv10: Perform RV20 check only for RV20 Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 04/47] avcodec/ituh263dec: Don't process unnecessarily many coefficients Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 05/47] avcodec/ituh263dec: Remove redundant store Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 06/47] avcodec/ituh263enc: Don't use array unnecessarily Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 07/47] avcodec/ituh263enc: Fix indentation Andreas Rheinhardt
2025-06-15 16:53 ` [FFmpeg-devel] [PATCH 08/47] avcodec/mpeg12dec: Don't store block_last_index unnecessarily Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 09/47] avcodec/rv10: Avoid indirection when reading VLC codes Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 10/47] avcodec/mpeg_er: Mark ff_mpeg_er_init() as av_cold Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 11/47] avcodec/mpegvideo_enc: Remove always-true branch Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 12/47] avcodec/motion_est: Fix indentation Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 13/47] avcodec/svq1enc: Don't free scratchbuf upon error Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 14/47] avcodec/svq1enc: Allocate motion_val{8, 16} during init Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 15/47] avcodec/svq1enc: Stop calling ff_mpv_common_init() Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 16/47] avcodec/svq1enc: Remove write-only c_block_{width, height} Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 17/47] avcodec/svq1enc: Set MpegEncContext.avctx only once Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 18/47] avcodec/svq1enc: Don't initialize unneeded block_index Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 19/47] configure: Factor mpegvideoencdsp out of mpegvideoenc Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 20/47] configure: Relax svq1enc->mpegvideoenc dependency Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 21/47] configure: Relax diracdec->mpegvideoenc dependency Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 22/47] configure: Relax snowenc->mpegvideoenc dependency Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 23/47] avcodec/mpegvideo: Don't reset thread_context ptrs unnecessarily Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 24/47] avcodec/mpegvideo: Don't zero unnecessarily Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 25/47] avcodec/mpegvideo: Defer init of enc slice ctxs in ff_mpv_common_init() Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 26/47] avcodec/mpegvideo_enc: Simplify allocating non-slice buffers Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 27/47] avcodec/ituh263dec: Simplify AIC handling Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 28/47] avcodec/ituh263enc: " Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 29/47] avcodec/flvenc: Combine writing bits Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 30/47] avcodec/flvenc: Move ff_flv2_encode_ac_esc() to ituh263enc.c Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 31/47] avcodec/mpegvideo: Redo resetting intra table entry Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 32/47] avcodec/mpegvideo: Avoid {a, d}c_val[{1, 2}] Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 33/47] avcodec/mpegvideo: Provide alignment hint to compiler Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 34/47] avcodec/mpegvideo: Don't reset AC values of upper-left luma block Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 35/47] avcodec/mpegvideo: Combine stores Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 36/47] avcodec/mpeg4video: Don't use ac_val[1], ac_val[2] when cleaning buffers Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 37/47] avcodec/mpegvideo: Only use a single ac_val pointer Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 38/47] avcodec/mpegvideo: Allocate ac_val jointly Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 39/47] avcodec/mpegvideo: Zero-init mbintra_table Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 40/47] avcodec/mpegvideo: Only keep MpegEncContext.dc_val[0] Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 41/47] avcodec/vc1: Only keep mb_type[0] Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 42/47] avcodec/mpegvideo: Allocate dc_val for each encoder slice Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 43/47] avcodec/{ituh263, mpeg4video}enc: Simplify out-of-slice DC prediction Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 44/47] avcodec/mpeg4video: Move ff_mpeg4_pred_dc() to decoder Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 45/47] avcodec/ituh263enc: Simplify encoding umotion vectors Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 46/47] avcodec/mpegvideo: Reduce stack usage when copying MpegEncContext Andreas Rheinhardt
2025-06-15 16:54 ` [FFmpeg-devel] [PATCH 47/47] avcodec/mpeg4videoenc: Fix data race when using AC prediction Andreas Rheinhardt
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