ffmpeg-devel
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
November 2025
- 64 participants
- 306 discussions
[PATCH] avcodec/aacenc: add bitrate threshold for PNS and improve attack detection (PR #20815)
by Agent45 01 Nov '25
by Agent45 01 Nov '25
01 Nov '25
PR #20815 opened by Agent45
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20815
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20815.patch
- Fixes indexing errors in attack detection logic and introduces a state flag (next_attack0_zero) to stabilize attack[0] prediction across frames. This reduces vertical line artifacts in periodic signals such as trumpet.
- Changes PSY_LAME_NUM_SUBBLOCKS from 3 to 2 to ensure full coverage of all 1024 MDCT samples, with each subblock containing exactly 64 samples—matching LAME’s empirical design. And adjust attack threshold presets. This improves the handling of periodic signals, especially under low bitrate conditions.
- Disables PNS when the per-channel bitrate exceeds 64 kbps. This avoids unnecessary noise substitution in high-bitrate scenarios where it may degrade quality.
This resolves issue #20200.
From 458a942481151ede27478e6ac6d9d2866d438b84 Mon Sep 17 00:00:00 2001
From: Agent45 <agent45(a)noreply.code.ffmpeg.org>
Date: Sat, 1 Nov 2025 19:49:05 +0000
Subject: [PATCH 1/2] avcodec/aacenc: add bitrate threshold for PNS
---
libavcodec/aaccoder.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 7f1c4cdcc1..ddebdfd53d 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -58,6 +58,9 @@
* replace low energy non zero bands */
#define NOISE_LAMBDA_REPLACE 1.948f
+/* Bitrate threshold (in bits/sec/channel) above which PNS is disabled. */
+#define PNS_BITRATE_LIMIT 64000.0f
+
#include "libavcodec/aaccoder_trellis.h"
typedef float (*quantize_and_encode_band_func)(struct AACEncContext *s, PutBitContext *pb,
@@ -513,6 +516,7 @@ static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChanne
? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024)
: (avctx->bit_rate / avctx->ch_layout.nb_channels);
+ int pns_at_low_bitrate = frame_bit_rate < PNS_BITRATE_LIMIT;
frame_bit_rate *= 1.15f;
if (avctx->cutoff > 0) {
@@ -536,7 +540,7 @@ static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChanne
const int start = wstart+sce->ics.swb_offset[g];
const float freq = (start-wstart)*freq_mult;
const float freq_boost = FFMAX(0.88f*freq/NOISE_LOW_LIMIT, 1.0f);
- if (freq < NOISE_LOW_LIMIT || (start-wstart) >= cutoff) {
+ if (!pns_at_low_bitrate || freq < NOISE_LOW_LIMIT || (start-wstart) >= cutoff) {
if (!sce->zeroes[w*16+g])
prev_sf = sce->sf_idx[w*16+g];
continue;
@@ -649,6 +653,7 @@ static void mark_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelEleme
? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024)
: (avctx->bit_rate / avctx->ch_layout.nb_channels);
+ int pns_at_low_bitrate = frame_bit_rate < PNS_BITRATE_LIMIT;
frame_bit_rate *= 1.15f;
if (avctx->cutoff > 0) {
@@ -667,7 +672,7 @@ static void mark_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelEleme
const int start = sce->ics.swb_offset[g];
const float freq = start*freq_mult;
const float freq_boost = FFMAX(0.88f*freq/NOISE_LOW_LIMIT, 1.0f);
- if (freq < NOISE_LOW_LIMIT || start >= cutoff) {
+ if (!pns_at_low_bitrate || freq < NOISE_LOW_LIMIT || start >= cutoff) {
sce->can_pns[w*16+g] = 0;
continue;
}
--
2.49.1
From 81a985d6a92eb411ba495fb05a3a962d181649ea Mon Sep 17 00:00:00 2001
From: Agent45 <agent45(a)noreply.code.ffmpeg.org>
Date: Sat, 1 Nov 2025 20:41:24 +0000
Subject: [PATCH 2/2] avcodec/aacpsy: fix attack detection logic and subblock
indexing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fix several indexing errors in attack detection logic and refine transient handling in the AAC psychoacoustic model.
- Change PSY_LAME_NUM_SUBBLOCKS from 3 to 2 to ensure full coverage of all 1024 MDCT samples, with each subblock containing exactly 1024 / (8 * 2) = 64 samples—matching LAME’s empirical design.
- Introduce next_attack0_zero state flag to stabilize attack[0] prediction across frames.
- Adjust attack threshold presets.
These changes improve the handling of periodic signals such as trumpet, especially under low bitrate conditions.
---
libavcodec/aacpsy.c | 64 +++++++++++++++++++++++----------------------
1 file changed, 33 insertions(+), 31 deletions(-)
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index ed03cb68ac..f91ba45a52 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -97,7 +97,7 @@ enum {
#define AAC_BLOCK_SIZE_LONG 1024 ///< long block size
#define AAC_BLOCK_SIZE_SHORT 128 ///< short block size
#define AAC_NUM_BLOCKS_SHORT 8 ///< number of blocks in a short sequence
-#define PSY_LAME_NUM_SUBBLOCKS 3 ///< Number of sub-blocks in each short block
+#define PSY_LAME_NUM_SUBBLOCKS 2 ///< Number of sub-blocks in each short block
/**
* @}
@@ -133,6 +133,7 @@ typedef struct AacPsyChannel{
float attack_threshold; ///< attack threshold for this channel
float prev_energy_subshort[AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS];
int prev_attack; ///< attack value for the last short block in the previous sequence
+ int next_attack0_zero; ///< whether attack[0] of the next frame is zero
}AacPsyChannel;
/**
@@ -181,19 +182,19 @@ typedef struct PsyLamePreset {
static const PsyLamePreset psy_abr_map[] = {
/* TODO: Tuning. These were taken from LAME. */
/* kbps/ch st_lrm */
- { 8, 6.60},
- { 16, 6.60},
- { 24, 6.60},
- { 32, 6.60},
- { 40, 6.60},
- { 48, 6.60},
- { 56, 6.60},
- { 64, 6.40},
- { 80, 6.00},
- { 96, 5.60},
- {112, 5.20},
- {128, 5.20},
- {160, 5.20}
+ { 8, 7.60},
+ { 16, 7.60},
+ { 24, 7.60},
+ { 32, 7.60},
+ { 40, 7.60},
+ { 48, 7.60},
+ { 56, 7.60},
+ { 64, 7.40},
+ { 80, 7.00},
+ { 96, 6.60},
+ {112, 6.20},
+ {128, 6.20},
+ {160, 6.20}
};
/**
@@ -900,8 +901,8 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
/* Calculate the energies of each sub-shortblock */
for (i = 0; i < PSY_LAME_NUM_SUBBLOCKS; i++) {
energy_subshort[i] = pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 1) * PSY_LAME_NUM_SUBBLOCKS)];
- assert(pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 2) * PSY_LAME_NUM_SUBBLOCKS + 1)] > 0);
- attack_intensity[i] = energy_subshort[i] / pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 2) * PSY_LAME_NUM_SUBBLOCKS + 1)];
+ assert(pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 1) * PSY_LAME_NUM_SUBBLOCKS - 2)] > 0);
+ attack_intensity[i] = energy_subshort[i] / pch->prev_energy_subshort[i + ((AAC_NUM_BLOCKS_SHORT - 1) * PSY_LAME_NUM_SUBBLOCKS - 2)];
energy_short[0] += energy_subshort[i];
}
@@ -912,17 +913,12 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
p = FFMAX(p, fabsf(*pf));
pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p;
energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p;
- /* NOTE: The indexes below are [i + 3 - 2] in the LAME source.
- * Obviously the 3 and 2 have some significance, or this would be just [i + 1]
- * (which is what we use here). What the 3 stands for is ambiguous, as it is both
- * number of short blocks, and the number of sub-short blocks.
- * It seems that LAME is comparing each sub-block to sub-block + 1 in the
- * previous block.
- */
- if (p > energy_subshort[i + 1])
- p = p / energy_subshort[i + 1];
- else if (energy_subshort[i + 1] > p * 10.0f)
- p = energy_subshort[i + 1] / (p * 10.0f);
+
+ /* NOTE: The indexes below are [i + 3 - 2] in the LAME source. Compare each sub-block to sub-block - 2 */
+ if (p > energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS - 2])
+ p = p / energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS - 2];
+ else if (energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS - 2] > p * 10.0f)
+ p = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS - 2] / (p * 10.0f);
else
p = 0.0;
attack_intensity[i + PSY_LAME_NUM_SUBBLOCKS] = p;
@@ -943,7 +939,7 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
const float v = energy_short[i];
const float m = FFMAX(u, v);
if (m < 40000) { /* (2) */
- if (u < 1.7f * v && v < 1.7f * u) { /* (1) */
+ if (u < 2.3f * v && v < 2.3f * u) { /* (1) */
if (i == 1 && attacks[0] < attacks[i])
attacks[0] = 0;
attacks[i] = 0;
@@ -951,13 +947,19 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
}
att_sum += attacks[i];
}
+ if (pch->next_attack0_zero)
+ attacks[0] = 0;
+ if (attacks[AAC_NUM_BLOCKS_SHORT] == 0)
+ pch->next_attack0_zero = 1;
+ else
+ pch->next_attack0_zero = 0;
if (attacks[0] <= pch->prev_attack)
attacks[0] = 0;
att_sum += attacks[0];
- /* 3 below indicates the previous attack happened in the last sub-block of the previous sequence */
- if (pch->prev_attack == 3 || att_sum) {
+ /* If the previous attack happened in the last sub-block of the previous sequence, or if there's a new attack, use short window */
+ if (pch->prev_attack == PSY_LAME_NUM_SUBBLOCKS || att_sum) {
uselongblock = 0;
for (i = 1; i < AAC_NUM_BLOCKS_SHORT + 1; i++)
@@ -1007,7 +1009,7 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
}
pch->next_grouping = window_grouping[grouping];
- pch->prev_attack = attacks[8];
+ pch->prev_attack = attacks[AAC_NUM_BLOCKS_SHORT - 1];
return wi;
}
--
2.49.1
1
0
[PATCH] Fix build failure, deprecation warnings due to parser changes (PR #20814)
by mkver 01 Nov '25
by mkver 01 Nov '25
01 Nov '25
PR #20814 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20814
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20814.patch
I intend to apply this soon.
From 25968dbb056a1066296a005e2d24545c28a4fa8c Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
Date: Sat, 1 Nov 2025 18:41:27 +0100
Subject: [PATCH 1/2] avcodec/parser_internal: Rename PASSTHROUGH macro to
avoid name conflict
wingdi.h defines its own PASSTHROUGH and it is included implicitly
by the VC-1 parser (which is mpegvideo-based and therefore includes
a lot of stuff).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
---
libavcodec/parser_internal.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/parser_internal.h b/libavcodec/parser_internal.h
index e366b5576a..fa9af971c1 100644
--- a/libavcodec/parser_internal.h
+++ b/libavcodec/parser_internal.h
@@ -67,9 +67,9 @@ static inline const FFCodecParser *ffcodecparser(const AVCodecParser *parser)
#define CHECK_FOR_TOO_MANY_IDS(...) AV_JOIN(EIGTH_ARG(__VA_ARGS__, NO, NO, NO, NO, NO, NO, NO, NO), _FAIL)
// For compatibility with MSVC's old, spec-incompliant preprocessor.
-#define PASSTHROUGH(...) __VA_ARGS__
+#define FF_MSVC_EXPAND(...) __VA_ARGS__
#define FIRST_SEVEN2(a,b,c,d,e,f,g,...) a,b,c,d,e,f,g
-#define FIRST_SEVEN(...) PASSTHROUGH(FIRST_SEVEN2(__VA_ARGS__))
+#define FIRST_SEVEN(...) FF_MSVC_EXPAND(FIRST_SEVEN2(__VA_ARGS__))
#define TIMES_SEVEN(a) a,a,a,a,a,a,a
#if FF_API_PARSER_PRIVATE
--
2.49.1
From fa959bb135bf95edc0f4bcc7ab8c327532f64694 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
Date: Sat, 1 Nov 2025 18:48:17 +0100
Subject: [PATCH 2/2] avcodec/parsers: Silence deprecation warnings
Slipped through because Clang (in contrast to GCC) does not warn about
this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
---
libavcodec/parsers.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c
index c3460a3b86..cae1f7213e 100644
--- a/libavcodec/parsers.c
+++ b/libavcodec/parsers.c
@@ -22,8 +22,11 @@
#include "parser_internal.h"
#if FF_API_PARSER_PRIVATE
+#include "libavutil/internal.h"
#include <assert.h>
#include <stddef.h>
+
+FF_DISABLE_DEPRECATION_WARNINGS
#define CHECK_OFFSET(field, public_prefix) static_assert(offsetof(FFCodecParser, field) == offsetof(FFCodecParser, p.public_prefix ## field), "Wrong offsets")
CHECK_OFFSET(codec_ids,);
CHECK_OFFSET(priv_data_size,);
@@ -31,6 +34,7 @@ CHECK_OFFSET(init, parser_);
CHECK_OFFSET(parse, parser_);
CHECK_OFFSET(close, parser_);
CHECK_OFFSET(split,);
+FF_ENABLE_DEPRECATION_WARNINGS
#endif
extern const FFCodecParser ff_aac_parser;
--
2.49.1
1
0
Hi all
I think ive finally found a way to fix the ffmpeg-devel-owners from
being unsubscribed/disabled due to spam bounces
Let me first explain what the problem is, then how we solved it.
The problem:
1. spam hits ffmpeg-devel-owners
2. our spam filters remove alot but not all spam
3. spam to ffmpeg-devel-owners is processed my mailman3
4. mailman3 forwards the spam to all the people on ffmpeg-devel-owners
5. some of this spam bounces because it is spam
6. the bounce is now indistingishable from a ffmpeg-devel subscriber
7. the bounce hits our server and is routed to mailman
8. mailman3 increases the bouce score for the address that bounced the spam (if theres a matching subscriber)
9. once the bouce score reaches the threshold the person has his subscription disabled
10. If you followed along, you will realize that mailman now disabled an account
but that account was never involved in the bounce
mailman2 did not have this issue
What we tried:
1. Improve spam filtering, we did not run *-owner through all our
spam filters, now we do, but its not enough.
future plan here is to install rspamd
2. verp_probes = yes & probe_add_dsn: no
This should prevent primary bounces from disabling accounts by
having a final test message send (which should ideally not bounce
as spam) sadly these seem to be able to bounce too
3. postfix
we simply handle the ffmpeg-devel-owner in postfix now
and now as mailman doesnt forward it, the return
address is distinct from mailing list subscriber mail and thus any
bounces from owners dont get counted as subscriber bounces.
ATM this is used only for ffmpeg-devel-owner,
i intend to enable the same thing for other mailing lists
what this also means, you can now again subscribe with the same mail
address to the list as used in ffmpeg-devel-owner without being
unsubscribed/disabled due to ffmpeg-devel-owner bounces.
Of course bounces from normal mailing list mail still can get your
account disabled.
thx
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If you fake or manipulate statistics in a paper in physics you will never
get a job again.
If you fake or manipulate statistics in a paper in medicin you will get
a job for life at the pharma industry.
2
3
PR #20813 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20813
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20813.patch
From f3d54991d9243bd5065d22c4424628ff8972f1c4 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
Date: Thu, 30 Oct 2025 15:40:02 +0100
Subject: [PATCH 1/4] avcodec/h264chroma: Move mc1 function to mpegvideo_dec.c
It is only used by mpegvideo decoders (for lowres). It is also only used
for bitdepth == 8, so don't build the bitdepth == 16 function at all any
more.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
---
libavcodec/h264chroma.c | 2 --
libavcodec/h264chroma_template.c | 34 --------------------------
libavcodec/mpegvideo_dec.c | 41 ++++++++++++++++++++++++++++++++
tests/checkasm/h264chroma.c | 2 +-
4 files changed, 42 insertions(+), 37 deletions(-)
diff --git a/libavcodec/h264chroma.c b/libavcodec/h264chroma.c
index 1eeab7bc40..5000c89aa7 100644
--- a/libavcodec/h264chroma.c
+++ b/libavcodec/h264chroma.c
@@ -32,11 +32,9 @@
c->put_h264_chroma_pixels_tab[0] = put_h264_chroma_mc8_ ## depth ## _c; \
c->put_h264_chroma_pixels_tab[1] = put_h264_chroma_mc4_ ## depth ## _c; \
c->put_h264_chroma_pixels_tab[2] = put_h264_chroma_mc2_ ## depth ## _c; \
- c->put_h264_chroma_pixels_tab[3] = put_h264_chroma_mc1_ ## depth ## _c; \
c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_ ## depth ## _c; \
c->avg_h264_chroma_pixels_tab[1] = avg_h264_chroma_mc4_ ## depth ## _c; \
c->avg_h264_chroma_pixels_tab[2] = avg_h264_chroma_mc2_ ## depth ## _c; \
- c->avg_h264_chroma_pixels_tab[3] = avg_h264_chroma_mc1_ ## depth ## _c; \
av_cold void ff_h264chroma_init(H264ChromaContext *c, int bit_depth)
{
diff --git a/libavcodec/h264chroma_template.c b/libavcodec/h264chroma_template.c
index b9d24f5a0c..b58be192cd 100644
--- a/libavcodec/h264chroma_template.c
+++ b/libavcodec/h264chroma_template.c
@@ -26,40 +26,6 @@
#include "bit_depth_template.c"
#define H264_CHROMA_MC(OPNAME, OP)\
-static void FUNCC(OPNAME ## h264_chroma_mc1)(uint8_t *_dst /*align 8*/, const uint8_t *_src /*align 1*/, ptrdiff_t stride, int h, int x, int y){\
- pixel *dst = (pixel*)_dst;\
- const pixel *src = (const pixel*)_src;\
- const int A=(8-x)*(8-y);\
- const int B=( x)*(8-y);\
- const int C=(8-x)*( y);\
- const int D=( x)*( y);\
- int i;\
- stride >>= sizeof(pixel)-1;\
- \
- av_assert2(x<8 && y<8 && x>=0 && y>=0);\
-\
- if(D){\
- for(i=0; i<h; i++){\
- OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
- dst+= stride;\
- src+= stride;\
- }\
- } else if (B + C) {\
- const int E= B+C;\
- const int step= C ? stride : 1;\
- for(i=0; i<h; i++){\
- OP(dst[0], (A*src[0] + E*src[step+0]));\
- dst+= stride;\
- src+= stride;\
- }\
- } else {\
- for(i=0; i<h; i++){\
- OP(dst[0], (A*src[0]));\
- dst+= stride;\
- src+= stride;\
- }\
- }\
-}\
static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *_dst /*align 8*/, const uint8_t *_src /*align 1*/, ptrdiff_t stride, int h, int x, int y)\
{\
pixel *dst = (pixel*)_dst;\
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 85e24c667e..ad27180efd 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -44,6 +44,45 @@
#include "threadprogress.h"
#include "wmv2dec.h"
+#define H264_CHROMA_MC(OPNAME, OP)\
+static void OPNAME ## h264_chroma_mc1(uint8_t *dst /*align 8*/, const uint8_t *src /*align 1*/, ptrdiff_t stride, int h, int x, int y)\
+{\
+ const int A = (8-x) * (8-y);\
+ const int B = ( x) * (8-y);\
+ const int C = (8-x) * ( y);\
+ const int D = ( x) * ( y);\
+ \
+ av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);\
+\
+ if (D) {\
+ for (int i = 0; i < h; ++i) {\
+ OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
+ dst += stride;\
+ src += stride;\
+ }\
+ } else if (B + C) {\
+ const int E = B + C;\
+ const int step = C ? stride : 1;\
+ for (int i = 0; i < h; ++i) {\
+ OP(dst[0], (A*src[0] + E*src[step+0]));\
+ dst += stride;\
+ src += stride;\
+ }\
+ } else {\
+ for (int i = 0; i < h; ++i) {\
+ OP(dst[0], (A*src[0]));\
+ dst += stride;\
+ src += stride;\
+ }\
+ }\
+}\
+
+#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
+#define op_put(a, b) a = (((b) + 32)>>6)
+
+H264_CHROMA_MC(put_, op_put)
+H264_CHROMA_MC(avg_, op_avg)
+
av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
{
enum ThreadingStatus thread_status;
@@ -62,6 +101,8 @@ av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
ff_mpv_idct_init(s);
ff_h264chroma_init(&s->h264chroma, 8); //for lowres
+ s->h264chroma.avg_h264_chroma_pixels_tab[3] = avg_h264_chroma_mc1;
+ s->h264chroma.put_h264_chroma_pixels_tab[3] = put_h264_chroma_mc1;
if (s->picture_pool) // VC-1 can call this multiple times
return 0;
diff --git a/tests/checkasm/h264chroma.c b/tests/checkasm/h264chroma.c
index 9579fceab7..52aa220152 100644
--- a/tests/checkasm/h264chroma.c
+++ b/tests/checkasm/h264chroma.c
@@ -51,7 +51,7 @@ static void check_chroma_mc(void)
for (int bit_depth = 8; bit_depth <= 10; bit_depth++) {
ff_h264chroma_init(&h, bit_depth);
randomize_buffers(bit_depth);
- for (int size = 0; size < 4; size++) {
+ for (int size = 0; size < 3; size++) {
#define CHECK_CHROMA_MC(name) \
do { \
--
2.49.1
From 392026641d525d8df0b5fff01102de98d9e4097b Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
Date: Sat, 1 Nov 2025 11:27:22 +0100
Subject: [PATCH 2/4] configure: Add config_components.asm
This is in preparation for the next commit.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
---
configure | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
index 3b132d07c9..17f72b735e 100755
--- a/configure
+++ b/configure
@@ -8524,8 +8524,10 @@ echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH
cp_if_changed $TMPH config.h
touch ffbuild/.config
-# Copy config.asm before printing ALL_COMPONENTS; that's not needed in assembly.
-enabled x86asm && cp_if_changed $TMPASM config.asm
+# Copy config.asm and reopen a new TMPASM for config_components.asm
+enabled x86asm && cp_if_changed $TMPASM config.asm && cat > $TMPASM <<EOF
+; Automatically generated by configure - do not modify!
+EOF
# Reopen a new TMPH for config_components.h.
cat > $TMPH <<EOF
@@ -8540,6 +8542,7 @@ echo "#endif /* FFMPEG_CONFIG_COMPONENTS_H */" >> $TMPH
echo "endif # FFMPEG_CONFIG_MAK" >> ffbuild/config.mak
cp_if_changed $TMPH config_components.h
+enabled x86asm && cp_if_changed $TMPASM config_components.asm
cat > $TMPH <<EOF
/* Generated by ffmpeg configure */
--
2.49.1
From ec488bbdbec83c23ac74e34f2a5b9d19379b7de4 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
Date: Sat, 1 Nov 2025 10:37:25 +0100
Subject: [PATCH 3/4] avcodec/x86/h264_chromamc: Add SSSE3 RV40 chroma motion
compensation functions
The only difference between it and the H.264/VC-1 versions is the
bias constant which depends on the shift parameters for RV40.
This value ends up in a register and therefore one can reuse
the H.264 code by setting the registers for RV40 and then jumping
into the relevant H.264 function, making the four new functions
cheap (just 256 bytes in total). This approach uses one jump more
for the no-filter case and one jump less in the one-dimensional
case than an approach using separate functions.
avg_chroma_mc4_c: 167.5 ( 1.00x)
avg_chroma_mc4_mmxext: 48.1 ( 3.48x)
avg_chroma_mc4_ssse3: 31.1 ( 5.39x)
avg_chroma_mc8_c: 325.5 ( 1.00x)
avg_chroma_mc8_mmxext: 103.2 ( 3.15x)
avg_chroma_mc8_ssse3: 33.5 ( 9.71x)
put_chroma_mc4_c: 137.4 ( 1.00x)
put_chroma_mc4_mmx: 44.5 ( 3.09x)
put_chroma_mc4_ssse3: 28.4 ( 4.83x)
put_chroma_mc8_c: 271.4 ( 1.00x)
put_chroma_mc8_mmx: 99.9 ( 2.72x)
put_chroma_mc8_ssse3: 30.6 ( 8.86x)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
---
libavcodec/rv40dsp.c | 7 +--
libavcodec/x86/h264_chromamc.asm | 83 +++++++++++++++++++++++++++++---
libavcodec/x86/rv40dsp_init.c | 10 ++++
3 files changed, 91 insertions(+), 9 deletions(-)
diff --git a/libavcodec/rv40dsp.c b/libavcodec/rv40dsp.c
index 970faec5de..dd73737bd6 100644
--- a/libavcodec/rv40dsp.c
+++ b/libavcodec/rv40dsp.c
@@ -24,6 +24,7 @@
* RV40 decoder motion compensation functions
*/
+#include "libavutil/attributes_internal.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "h264qpel.h"
@@ -283,7 +284,7 @@ static void avg_rv40_qpel8_mc33_c(uint8_t *dst, const uint8_t *src, ptrdiff_t st
avg_pixels8_xy2_8_c(dst, src, stride, 8);
}
-static const int rv40_bias[4][4] = {
+attribute_visibility_hidden const int ff_rv40_bias[4][4] = {
{ 0, 16, 32, 16 },
{ 32, 28, 32, 28 },
{ 0, 32, 16, 32 },
@@ -300,7 +301,7 @@ static void OPNAME ## rv40_chroma_mc4_c(uint8_t *dst /*align 8*/,\
const int C = (8-x) * ( y);\
const int D = ( x) * ( y);\
int i;\
- int bias = rv40_bias[y>>1][x>>1];\
+ int bias = ff_rv40_bias[y>>1][x>>1];\
\
av_assert2(x<8 && y<8 && x>=0 && y>=0);\
\
@@ -336,7 +337,7 @@ static void OPNAME ## rv40_chroma_mc8_c(uint8_t *dst/*align 8*/,\
const int C = (8-x) * ( y);\
const int D = ( x) * ( y);\
int i;\
- int bias = rv40_bias[y>>1][x>>1];\
+ int bias = ff_rv40_bias[y>>1][x>>1];\
\
av_assert2(x<8 && y<8 && x>=0 && y>=0);\
\
diff --git a/libavcodec/x86/h264_chromamc.asm b/libavcodec/x86/h264_chromamc.asm
index ec6288d48e..8cdc0fe5a1 100644
--- a/libavcodec/x86/h264_chromamc.asm
+++ b/libavcodec/x86/h264_chromamc.asm
@@ -20,6 +20,7 @@
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
+%include "config_components.asm"
%include "libavutil/x86/x86util.asm"
SECTION_RODATA
@@ -64,6 +65,8 @@ pw_28: times 8 dw 28
cextern pw_32
cextern pw_64
+cextern rv40_bias
+
SECTION .text
%macro mv0_pixels_mc8 0
@@ -447,11 +450,12 @@ chroma_mc4_mmx_func avg, rv40
chroma_mc2_mmx_func avg, h264
%macro chroma_mc8_ssse3_func 2-3
-cglobal %1_%2_chroma_mc8%3, 6, 7, 8
+cglobal %1_%2_chroma_mc8%3, 6, 7+UNIX64, 8
mov r6d, r5d
or r6d, r4d
jne .at_least_one_non_zero
; mx == 0 AND my == 0 - no filter needed
+..@%1_%2_chroma_mc8_no_filter_ %+ cpuname:
mv0_pixels_mc8
RET
@@ -462,6 +466,8 @@ cglobal %1_%2_chroma_mc8%3, 6, 7, 8
je .mx_is_zero
; general case, bilinear
+ movdqa m5, [rnd_2d_%2]
+..@%1_%2_chroma_mc8_both_nonzero_ %+ cpuname:
mov r6d, r4d
shl r4d, 8
sub r4, r6
@@ -473,7 +479,6 @@ cglobal %1_%2_chroma_mc8%3, 6, 7, 8
movd m7, r6d
movd m6, r4d
- movdqa m5, [rnd_2d_%2]
movq m0, [r1 ]
movq m1, [r1+1]
pshuflw m7, m7, 0
@@ -517,12 +522,13 @@ cglobal %1_%2_chroma_mc8%3, 6, 7, 8
RET
.my_is_zero:
+ movdqa m6, [rnd_1d_%2]
+..@%1_%2_chroma_mc8_my_zero_ %+ cpuname:
mov r5d, r4d
shl r4d, 8
add r4, 8
sub r4, r5 ; 255*x+8 = x<<8 | (8-x)
movd m7, r4d
- movdqa m6, [rnd_1d_%2]
pshuflw m7, m7, 0
movlhps m7, m7
@@ -554,12 +560,13 @@ cglobal %1_%2_chroma_mc8%3, 6, 7, 8
RET
.mx_is_zero:
+ movdqa m6, [rnd_1d_%2]
+..@%1_%2_chroma_mc8_mx_zero_ %+ cpuname:
mov r4d, r5d
shl r5d, 8
add r5, 8
sub r5, r4 ; 255*y+8 = y<<8 | (8-y)
movd m7, r5d
- movdqa m6, [rnd_1d_%2]
pshuflw m7, m7, 0
movlhps m7, m7
@@ -592,7 +599,9 @@ cglobal %1_%2_chroma_mc8%3, 6, 7, 8
%endmacro
%macro chroma_mc4_ssse3_func 2
-cglobal %1_%2_chroma_mc4, 6, 7, 0
+cglobal %1_%2_chroma_mc4, 6, 7+UNIX64, 0
+ movq m5, [pw_32]
+..@%1_%2_chroma_mc4_after_init_ %+ cpuname:
mov r6, r4
shl r4d, 8
sub r4d, r6d
@@ -604,7 +613,6 @@ cglobal %1_%2_chroma_mc4, 6, 7, 0
movd m7, r6d
movd m6, r4d
- movq m5, [pw_32]
movd m0, [r1 ]
pshufw m7, m7, 0
punpcklbw m0, [r1+1]
@@ -641,16 +649,79 @@ cglobal %1_%2_chroma_mc4, 6, 7, 0
RET
%endmacro
+%macro rv40_get_bias 1 ; dst reg
+%if !PIC || UNIX64
+ ; on UNIX64 we have enough volatile registers
+%if PIC && UNIX64
+ lea r7, [rv40_bias]
+%endif
+ mov r6d, r5d
+ and r6d, 6 ; &~1 for mx/my=[0,7]
+ lea r6d, [r6d*4+r4d]
+ sar r6d, 1
+%if PIC && UNIX64
+ movd %1, [r7+4*r6]
+%else
+ movd %1, [rv40_bias+4*r6]
+%endif
+%else ; PIC && !UNIX64, de facto WIN64
+ lea r6, [rv40_bias]
+%ifidn r5d, r5m ; always false for currently supported calling conventions
+ push r5
+%endif
+ and r5d, 6 ; &~1 for mx/my=[0,7]
+ lea r5d, [r5d*4+r4d]
+ sar r5d, 1
+ movd %1, [r6+4*r5]
+%ifidn r5d, r5m
+ pop r5
+%else
+ mov r5d, r5m
+%endif
+%endif
+ SPLATW %1, %1
+%endmacro
+
+%macro rv40_chroma_mc8_func 1 ; put vs avg
+%if CONFIG_RV40_DECODER
+ cglobal rv40_%1_chroma_mc8, 6, 7+UNIX64, 8
+ mov r6d, r5d
+ or r6d, r4d
+ jz ..@%1_h264_chroma_mc8_no_filter_ %+ cpuname
+ rv40_get_bias m5
+ ; the bilinear code expects bias in m5, the one-dimensional code in m6
+ mova m6, m5
+ psraw m6, 3
+ test r5d, r5d
+ je ..@%1_h264_chroma_mc8_my_zero_ %+ cpuname
+ test r4d, r4d
+ je ..@%1_h264_chroma_mc8_mx_zero_ %+ cpuname
+ jmp ..@%1_h264_chroma_mc8_both_nonzero_ %+ cpuname
+%endif
+%endmacro
+
+%macro rv40_chroma_mc4_func 1 ; put vs avg
+%if CONFIG_RV40_DECODER
+ cglobal rv40_%1_chroma_mc4, 6, 7+UNIX64, 0
+ rv40_get_bias m5
+ jmp ..@%1_h264_chroma_mc4_after_init_ %+ cpuname
+%endif
+%endmacro
+
%define CHROMAMC_AVG NOTHING
INIT_XMM ssse3
chroma_mc8_ssse3_func put, h264, _rnd
chroma_mc8_ssse3_func put, vc1, _nornd
+rv40_chroma_mc8_func put
INIT_MMX ssse3
chroma_mc4_ssse3_func put, h264
+rv40_chroma_mc4_func put
%define CHROMAMC_AVG DIRECT_AVG
INIT_XMM ssse3
chroma_mc8_ssse3_func avg, h264, _rnd
chroma_mc8_ssse3_func avg, vc1, _nornd
+rv40_chroma_mc8_func avg
INIT_MMX ssse3
chroma_mc4_ssse3_func avg, h264
+rv40_chroma_mc4_func avg
diff --git a/libavcodec/x86/rv40dsp_init.c b/libavcodec/x86/rv40dsp_init.c
index 780358abc2..ce2c955cb1 100644
--- a/libavcodec/x86/rv40dsp_init.c
+++ b/libavcodec/x86/rv40dsp_init.c
@@ -178,6 +178,12 @@ DEFINE_FN(avg, 8, ssse3)
DEFINE_FN(avg, 16, sse2)
DEFINE_FN(avg, 16, ssse3)
+
+#define CHROMA_MC_FUNC(OP, SIZE, XMM) \
+void ff_rv40_ ## OP ## _chroma_mc ## SIZE ## _ ## XMM(uint8_t *dst, const uint8_t *src, \
+ ptrdiff_t stride, int h, int x, int y);\
+ c->OP ## _chroma_pixels_tab[SIZE == 4] = ff_rv40_ ## OP ## _chroma_mc ## SIZE ## _ ## XMM
+
#endif /* HAVE_X86ASM */
av_cold void ff_rv40dsp_init_x86(RV34DSPContext *c)
@@ -204,6 +210,10 @@ av_cold void ff_rv40dsp_init_x86(RV34DSPContext *c)
QPEL_MC_SET(avg_, _sse2)
}
if (EXTERNAL_SSSE3(cpu_flags)) {
+ CHROMA_MC_FUNC(put, 8, ssse3);
+ CHROMA_MC_FUNC(put, 4, ssse3);
+ CHROMA_MC_FUNC(avg, 8, ssse3);
+ CHROMA_MC_FUNC(avg, 4, ssse3);
c->put_pixels_tab[0][15] = put_rv40_qpel16_mc33_ssse3;
c->put_pixels_tab[1][15] = put_rv40_qpel8_mc33_ssse3;
c->avg_pixels_tab[0][15] = avg_rv40_qpel16_mc33_ssse3;
--
2.49.1
From 30371f23dfbdf100204e98079aaad8fffec904fb Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
Date: Thu, 30 Oct 2025 15:59:21 +0100
Subject: [PATCH 4/4] avcodec/x86/h264_chromamc: Remove MMX(EXT) funcs
overridden by SSSE3
SSSE3 is already quite old (introduced 2006 for Intel, 2011 for AMD),
so that the overwhelming majority of our users (particularly those
that actually update their FFmpeg) will be using the SSSE3 versions.
This commit therefore removes the MMX(EXT) functions overridden
by them (which don't abide by the ABI) to get closer to a removal
of emms_c.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt(a)outlook.com>
---
libavcodec/x86/h264_chromamc.asm | 327 +------------------------------
libavcodec/x86/h264chroma_init.c | 17 --
libavcodec/x86/rv40dsp_init.c | 18 --
libavcodec/x86/vc1dsp_init.c | 9 -
4 files changed, 2 insertions(+), 369 deletions(-)
diff --git a/libavcodec/x86/h264_chromamc.asm b/libavcodec/x86/h264_chromamc.asm
index 8cdc0fe5a1..6a65d5cabd 100644
--- a/libavcodec/x86/h264_chromamc.asm
+++ b/libavcodec/x86/h264_chromamc.asm
@@ -25,39 +25,6 @@
SECTION_RODATA
-rnd_rv40_2d_tbl: times 4 dw 0
- times 4 dw 16
- times 4 dw 32
- times 4 dw 16
- times 4 dw 32
- times 4 dw 28
- times 4 dw 32
- times 4 dw 28
- times 4 dw 0
- times 4 dw 32
- times 4 dw 16
- times 4 dw 32
- times 4 dw 32
- times 4 dw 28
- times 4 dw 32
- times 4 dw 28
-rnd_rv40_1d_tbl: times 4 dw 0
- times 4 dw 2
- times 4 dw 4
- times 4 dw 2
- times 4 dw 4
- times 4 dw 3
- times 4 dw 4
- times 4 dw 3
- times 4 dw 0
- times 4 dw 4
- times 4 dw 2
- times 4 dw 4
- times 4 dw 4
- times 4 dw 3
- times 4 dw 4
- times 4 dw 3
-
cextern pw_3
cextern pw_4
cextern pw_8
@@ -92,285 +59,6 @@ SECTION .text
jne .next4rows
%endmacro
-%macro chroma_mc8_mmx_func 2-3
-%ifidn %2, rv40
-%if PIC
-%define rnd_1d_rv40 r8
-%define rnd_2d_rv40 r8
-%define extra_regs 2
-%else ; no-PIC
-%define rnd_1d_rv40 rnd_rv40_1d_tbl
-%define rnd_2d_rv40 rnd_rv40_2d_tbl
-%define extra_regs 1
-%endif ; PIC
-%else
-%define extra_regs 0
-%endif ; rv40
-; void ff_put/avg_h264_chroma_mc8_*(uint8_t *dst /* align 8 */,
-; const uint8_t *src /* align 1 */,
-; ptrdiff_t stride, int h, int mx, int my)
-cglobal %1_%2_chroma_mc8%3, 6, 7 + extra_regs, 0
- mov r6d, r5d
- or r6d, r4d
- jne .at_least_one_non_zero
- ; mx == 0 AND my == 0 - no filter needed
- mv0_pixels_mc8
- RET
-
-.at_least_one_non_zero:
-%ifidn %2, rv40
-%if ARCH_X86_64
- mov r7, r5
- and r7, 6 ; &~1 for mx/my=[0,7]
- lea r7, [r7*4+r4]
- sar r7d, 1
-%define rnd_bias r7
-%define dest_reg r0
-%else ; x86-32
- mov r0, r5
- and r0, 6 ; &~1 for mx/my=[0,7]
- lea r0, [r0*4+r4]
- sar r0d, 1
-%define rnd_bias r0
-%define dest_reg r5
-%endif
-%else ; vc1, h264
-%define rnd_bias 0
-%define dest_reg r0
-%endif
-
- test r5d, r5d
- mov r6, 1
- je .my_is_zero
- test r4d, r4d
- mov r6, r2 ; dxy = x ? 1 : stride
- jne .both_non_zero
-.my_is_zero:
- ; mx == 0 XOR my == 0 - 1 dimensional filter only
- or r4d, r5d ; x + y
-
-%ifidn %2, rv40
-%if PIC
- lea r8, [rnd_rv40_1d_tbl]
-%endif
-%if ARCH_X86_64 == 0
- mov r5, r0m
-%endif
-%endif
-
- movd m5, r4d
- movq m4, [pw_8]
- movq m6, [rnd_1d_%2+rnd_bias*8] ; mm6 = rnd >> 3
- punpcklwd m5, m5
- punpckldq m5, m5 ; mm5 = B = x
- pxor m7, m7
- psubw m4, m5 ; mm4 = A = 8-x
-
-.next1drow:
- movq m0, [r1 ] ; mm0 = src[0..7]
- movq m2, [r1+r6] ; mm1 = src[1..8]
-
- movq m1, m0
- movq m3, m2
- punpcklbw m0, m7
- punpckhbw m1, m7
- punpcklbw m2, m7
- punpckhbw m3, m7
- pmullw m0, m4 ; [mm0,mm1] = A * src[0..7]
- pmullw m1, m4
- pmullw m2, m5 ; [mm2,mm3] = B * src[1..8]
- pmullw m3, m5
-
- paddw m0, m6
- paddw m1, m6
- paddw m0, m2
- paddw m1, m3
- psrlw m0, 3
- psrlw m1, 3
- packuswb m0, m1
- CHROMAMC_AVG m0, [dest_reg]
- movq [dest_reg], m0 ; dst[0..7] = (A * src[0..7] + B * src[1..8] + (rnd >> 3)) >> 3
-
- add dest_reg, r2
- add r1, r2
- dec r3d
- jne .next1drow
- RET
-
-.both_non_zero: ; general case, bilinear
- movd m4, r4d ; x
- movd m6, r5d ; y
-%ifidn %2, rv40
-%if PIC
- lea r8, [rnd_rv40_2d_tbl]
-%endif
-%if ARCH_X86_64 == 0
- mov r5, r0m
-%endif
-%endif
- mov r6, rsp ; backup stack pointer
- and rsp, ~(mmsize-1) ; align stack
- sub rsp, 16 ; AA and DD
-
- punpcklwd m4, m4
- punpcklwd m6, m6
- punpckldq m4, m4 ; mm4 = x words
- punpckldq m6, m6 ; mm6 = y words
- movq m5, m4
- pmullw m4, m6 ; mm4 = x * y
- psllw m5, 3
- psllw m6, 3
- movq m7, m5
- paddw m7, m6
- movq [rsp+8], m4 ; DD = x * y
- psubw m5, m4 ; mm5 = B = 8x - xy
- psubw m6, m4 ; mm6 = C = 8y - xy
- paddw m4, [pw_64]
- psubw m4, m7 ; mm4 = A = xy - (8x+8y) + 64
- pxor m7, m7
- movq [rsp ], m4
-
- movq m0, [r1 ] ; mm0 = src[0..7]
- movq m1, [r1+1] ; mm1 = src[1..8]
-.next2drow:
- add r1, r2
-
- movq m2, m0
- movq m3, m1
- punpckhbw m0, m7
- punpcklbw m1, m7
- punpcklbw m2, m7
- punpckhbw m3, m7
- pmullw m0, [rsp]
- pmullw m2, [rsp]
- pmullw m1, m5
- pmullw m3, m5
- paddw m2, m1 ; mm2 = A * src[0..3] + B * src[1..4]
- paddw m3, m0 ; mm3 = A * src[4..7] + B * src[5..8]
-
- movq m0, [r1]
- movq m1, m0
- punpcklbw m0, m7
- punpckhbw m1, m7
- pmullw m0, m6
- pmullw m1, m6
- paddw m2, m0
- paddw m3, m1 ; [mm2,mm3] += C * src[0..7]
-
- movq m1, [r1+1]
- movq m0, m1
- movq m4, m1
- punpcklbw m0, m7
- punpckhbw m4, m7
- pmullw m0, [rsp+8]
- pmullw m4, [rsp+8]
- paddw m2, m0
- paddw m3, m4 ; [mm2,mm3] += D * src[1..8]
- movq m0, [r1]
-
- paddw m2, [rnd_2d_%2+rnd_bias*8]
- paddw m3, [rnd_2d_%2+rnd_bias*8]
- psrlw m2, 6
- psrlw m3, 6
- packuswb m2, m3
- CHROMAMC_AVG m2, [dest_reg]
- movq [dest_reg], m2 ; dst[0..7] = ([mm2,mm3] + rnd) >> 6
-
- add dest_reg, r2
- dec r3d
- jne .next2drow
- mov rsp, r6 ; restore stack pointer
- RET
-%endmacro
-
-%macro chroma_mc4_mmx_func 2
-%define extra_regs 0
-%ifidn %2, rv40
-%if PIC
-%define extra_regs 1
-%endif ; PIC
-%endif ; rv40
-cglobal %1_%2_chroma_mc4, 6, 6 + extra_regs, 0
- pxor m7, m7
- movd m2, r4d ; x
- movd m3, r5d ; y
- movq m4, [pw_8]
- movq m5, [pw_8]
- punpcklwd m2, m2
- punpcklwd m3, m3
- punpcklwd m2, m2
- punpcklwd m3, m3
- psubw m4, m2
- psubw m5, m3
-
-%ifidn %2, rv40
-%if PIC
- lea r6, [rnd_rv40_2d_tbl]
-%define rnd_2d_rv40 r6
-%else
-%define rnd_2d_rv40 rnd_rv40_2d_tbl
-%endif
- and r5, 6 ; &~1 for mx/my=[0,7]
- lea r5, [r5*4+r4]
- sar r5d, 1
-%define rnd_bias r5
-%else ; vc1, h264
-%define rnd_bias 0
-%endif
-
- movd m0, [r1 ]
- movd m6, [r1+1]
- add r1, r2
- punpcklbw m0, m7
- punpcklbw m6, m7
- pmullw m0, m4
- pmullw m6, m2
- paddw m6, m0
-
-.next2rows:
- movd m0, [r1 ]
- movd m1, [r1+1]
- add r1, r2
- punpcklbw m0, m7
- punpcklbw m1, m7
- pmullw m0, m4
- pmullw m1, m2
- paddw m1, m0
- movq m0, m1
-
- pmullw m6, m5
- pmullw m1, m3
- paddw m6, [rnd_2d_%2+rnd_bias*8]
- paddw m1, m6
- psrlw m1, 6
- packuswb m1, m1
- CHROMAMC_AVG4 m1, m6, [r0]
- movd [r0], m1
- add r0, r2
-
- movd m6, [r1 ]
- movd m1, [r1+1]
- add r1, r2
- punpcklbw m6, m7
- punpcklbw m1, m7
- pmullw m6, m4
- pmullw m1, m2
- paddw m1, m6
- movq m6, m1
- pmullw m0, m5
- pmullw m1, m3
- paddw m0, [rnd_2d_%2+rnd_bias*8]
- paddw m1, m0
- psrlw m1, 6
- packuswb m1, m1
- CHROMAMC_AVG4 m1, m0, [r0]
- movd [r0], m1
- add r0, r2
- sub r3d, 2
- jnz .next2rows
- RET
-%endmacro
-
%macro chroma_mc2_mmx_func 2
cglobal %1_%2_chroma_mc2, 6, 7, 0
mov r6d, r4d
@@ -428,25 +116,14 @@ cglobal %1_%2_chroma_mc2, 6, 7, 0
PAVGB %1, %2
%endmacro
-INIT_MMX mmx
-%define CHROMAMC_AVG NOTHING
-%define CHROMAMC_AVG4 NOTHING
-chroma_mc8_mmx_func put, h264, _rnd
-chroma_mc8_mmx_func put, vc1, _nornd
-chroma_mc8_mmx_func put, rv40
-chroma_mc4_mmx_func put, h264
-chroma_mc4_mmx_func put, rv40
INIT_MMX mmxext
+%define CHROMAMC_AVG NOTHING
+%define CHROMAMC_AVG4 NOTHING
chroma_mc2_mmx_func put, h264
%define CHROMAMC_AVG DIRECT_AVG
%define CHROMAMC_AVG4 COPY_AVG
-chroma_mc8_mmx_func avg, h264, _rnd
-chroma_mc8_mmx_func avg, vc1, _nornd
-chroma_mc8_mmx_func avg, rv40
-chroma_mc4_mmx_func avg, h264
-chroma_mc4_mmx_func avg, rv40
chroma_mc2_mmx_func avg, h264
%macro chroma_mc8_ssse3_func 2-3
diff --git a/libavcodec/x86/h264chroma_init.c b/libavcodec/x86/h264chroma_init.c
index 34934b6ad0..6eb52746ad 100644
--- a/libavcodec/x86/h264chroma_init.c
+++ b/libavcodec/x86/h264chroma_init.c
@@ -24,16 +24,6 @@
#include "libavutil/x86/cpu.h"
#include "libavcodec/h264chroma.h"
-void ff_put_h264_chroma_mc8_rnd_mmx (uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
-void ff_avg_h264_chroma_mc8_rnd_mmxext(uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
-
-void ff_put_h264_chroma_mc4_mmx (uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
-void ff_avg_h264_chroma_mc4_mmxext (uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
-
void ff_put_h264_chroma_mc2_mmxext (uint8_t *dst, const uint8_t *src,
ptrdiff_t stride, int h, int x, int y);
void ff_avg_h264_chroma_mc2_mmxext (uint8_t *dst, const uint8_t *src,
@@ -68,14 +58,7 @@ av_cold void ff_h264chroma_init_x86(H264ChromaContext *c, int bit_depth)
int high_bit_depth = bit_depth > 8;
int cpu_flags = av_get_cpu_flags();
- if (EXTERNAL_MMX(cpu_flags) && !high_bit_depth) {
- c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_rnd_mmx;
- c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_mmx;
- }
-
if (EXTERNAL_MMXEXT(cpu_flags) && !high_bit_depth) {
- c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_rnd_mmxext;
- c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmxext;
c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_mmxext;
c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_mmxext;
}
diff --git a/libavcodec/x86/rv40dsp_init.c b/libavcodec/x86/rv40dsp_init.c
index ce2c955cb1..a07acae6bc 100644
--- a/libavcodec/x86/rv40dsp_init.c
+++ b/libavcodec/x86/rv40dsp_init.c
@@ -40,16 +40,6 @@ static void op##_rv40_qpel##size##_mc33_##insn(uint8_t *dst, const uint8_t *src,
}
#if HAVE_X86ASM
-void ff_put_rv40_chroma_mc8_mmx (uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
-void ff_avg_rv40_chroma_mc8_mmxext(uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
-
-void ff_put_rv40_chroma_mc4_mmx (uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
-void ff_avg_rv40_chroma_mc4_mmxext(uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
-
#define DECLARE_WEIGHT(opt) \
void ff_rv40_weight_func_rnd_16_##opt(uint8_t *dst, uint8_t *src1, uint8_t *src2, \
int w1, int w2, ptrdiff_t stride); \
@@ -191,14 +181,6 @@ av_cold void ff_rv40dsp_init_x86(RV34DSPContext *c)
av_unused int cpu_flags = av_get_cpu_flags();
#if HAVE_X86ASM
- if (EXTERNAL_MMX(cpu_flags)) {
- c->put_chroma_pixels_tab[0] = ff_put_rv40_chroma_mc8_mmx;
- c->put_chroma_pixels_tab[1] = ff_put_rv40_chroma_mc4_mmx;
- }
- if (EXTERNAL_MMXEXT(cpu_flags)) {
- c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_mmxext;
- c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_mmxext;
- }
if (EXTERNAL_SSE2(cpu_flags)) {
c->put_pixels_tab[0][15] = put_rv40_qpel16_mc33_sse2;
c->avg_pixels_tab[0][15] = avg_rv40_qpel16_mc33_sse2;
diff --git a/libavcodec/x86/vc1dsp_init.c b/libavcodec/x86/vc1dsp_init.c
index e7874d2a5a..5cebc1f6f2 100644
--- a/libavcodec/x86/vc1dsp_init.c
+++ b/libavcodec/x86/vc1dsp_init.c
@@ -80,10 +80,6 @@ DECLARE_FUNCTION(avg_, 16, _sse2)
#endif /* HAVE_X86ASM */
-void ff_put_vc1_chroma_mc8_nornd_mmx (uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
-void ff_avg_vc1_chroma_mc8_nornd_mmxext(uint8_t *dst, const uint8_t *src,
- ptrdiff_t stride, int h, int x, int y);
void ff_put_vc1_chroma_mc8_nornd_ssse3(uint8_t *dst, const uint8_t *src,
ptrdiff_t stride, int h, int x, int y);
void ff_avg_vc1_chroma_mc8_nornd_ssse3(uint8_t *dst, const uint8_t *src,
@@ -122,13 +118,8 @@ av_cold void ff_vc1dsp_init_x86(VC1DSPContext *dsp)
dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_ ## EXT
#if HAVE_X86ASM
- if (EXTERNAL_MMX(cpu_flags)) {
- dsp->put_no_rnd_vc1_chroma_pixels_tab[0] = ff_put_vc1_chroma_mc8_nornd_mmx;
-
- }
if (EXTERNAL_MMXEXT(cpu_flags)) {
ASSIGN_LF4(mmxext);
- dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = ff_avg_vc1_chroma_mc8_nornd_mmxext;
dsp->avg_vc1_mspel_pixels_tab[1][0] = avg_vc1_mspel_mc00_8_mmxext;
--
2.49.1
1
0
PR #20812 opened by michaelni
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20812
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20812.patch
Fixes: out of array access
no testcase
Found-by: Joshua Rogers <joshua(a)joshua.hu> with ZeroPath
Signed-off-by: Michael Niedermayer <michael(a)niedermayer.cc>
From c772162c87dab3db5910db5e33dcc6f6dc34c2ba Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michael(a)niedermayer.cc>
Date: Sat, 1 Nov 2025 02:02:44 +0100
Subject: [PATCH] avformat/rtpdec_qdm2: Check block_size
Fixes: out of array access
no testcase
Found-by: Joshua Rogers <joshua(a)joshua.hu> with ZeroPath
Signed-off-by: Michael Niedermayer <michael(a)niedermayer.cc>
---
libavformat/rtpdec_qdm2.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/libavformat/rtpdec_qdm2.c b/libavformat/rtpdec_qdm2.c
index dce3c48bcc..9d71fe67dd 100644
--- a/libavformat/rtpdec_qdm2.c
+++ b/libavformat/rtpdec_qdm2.c
@@ -186,8 +186,9 @@ static int qdm2_parse_subpacket(PayloadContext *qdm, AVStream *st,
*/
static int qdm2_restore_block(PayloadContext *qdm, AVStream *st, AVPacket *pkt)
{
- int to_copy, n, res, include_csum;
+ int to_copy, n, res;
uint8_t *p, *csum_pos = NULL;
+ int include_csum = qdm->block_type == 2 || qdm->block_type == 4;
/* create packet to hold subpkts into a superblock */
av_assert0(qdm->cache > 0);
@@ -196,6 +197,11 @@ static int qdm2_restore_block(PayloadContext *qdm, AVStream *st, AVPacket *pkt)
break;
av_assert0(n < 0x80);
+ int min_size = 2 + (qdm->len[n] > 0xff) + 2*include_csum;
+
+ if (qdm->block_size < min_size)
+ return AVERROR_INVALIDDATA;
+
if ((res = av_new_packet(pkt, qdm->block_size)) < 0)
return res;
memset(pkt->data, 0, pkt->size);
@@ -211,7 +217,7 @@ static int qdm2_restore_block(PayloadContext *qdm, AVStream *st, AVPacket *pkt)
*p++ = qdm->block_type;
*p++ = qdm->len[n];
}
- if ((include_csum = (qdm->block_type == 2 || qdm->block_type == 4))) {
+ if (include_csum) {
csum_pos = p;
p += 2;
}
--
2.49.1
1
0
01 Nov '25
PR #20811 opened by michaelni
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20811
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20811.patch
Fixes: out of array access
no test case
Found-by: Joshua Rogers <joshua(a)joshua.hu> with ZeroPath
Signed-off-by: Michael Niedermayer <michael(a)niedermayer.cc>
From bb465160a15208fc663086ec2f0a0e6d6b676702 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michael(a)niedermayer.cc>
Date: Sat, 1 Nov 2025 01:29:32 +0100
Subject: [PATCH] avfilter/vf_drawtext: Account for bbox text seperator
Fixes: out of array access
no test case
Found-by: Joshua Rogers <joshua(a)joshua.hu> with ZeroPath
Signed-off-by: Michael Niedermayer <michael(a)niedermayer.cc>
---
libavfilter/vf_drawtext.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 867536aa61..1d23805b54 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -1011,7 +1011,7 @@ static av_cold int init(AVFilterContext *ctx)
av_log(ctx, AV_LOG_WARNING, "Multiple texts provided, will use text_source only\n");
av_free(s->text);
}
- s->text = av_mallocz(AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE *
+ s->text = av_mallocz((AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE + 1) *
(AV_NUM_DETECTION_BBOX_CLASSIFY + 1));
if (!s->text)
return AVERROR(ENOMEM);
--
2.49.1
1
0