PR #22468 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22468 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22468.patch
>From b7aa044b639b4e5d9d70638044acf110deb21d53 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Mon, 2 Mar 2026 02:49:28 +0100 Subject: [PATCH 1/7] avcodec/apv_decode: Fix pixel format selection The current code just happens to work for 10 and 12. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/apv_decode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/apv_decode.c b/libavcodec/apv_decode.c index dbe354a793..3d774d3378 100644 --- a/libavcodec/apv_decode.c +++ b/libavcodec/apv_decode.c @@ -87,7 +87,7 @@ static int apv_decode_check_format(AVCodecContext *avctx, return AVERROR_PATCHWELCOME; } avctx->pix_fmt = - apv_format_table[header->frame_info.chroma_format_idc][bit_depth - 4 >> 2]; + apv_format_table[header->frame_info.chroma_format_idc][(bit_depth - 8) >> 1]; if (!avctx->pix_fmt) { avpriv_request_sample(avctx, "YUVA444P14"); -- 2.52.0 >From 94584bc9acb065d8fc8e7ecee07b7fd3320919ef Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 10 Mar 2026 21:42:58 +0100 Subject: [PATCH 2/7] avcodec/apv_decode: Remove always-false branches Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/apv_decode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/apv_decode.c b/libavcodec/apv_decode.c index 3d774d3378..ab5a6b098a 100644 --- a/libavcodec/apv_decode.c +++ b/libavcodec/apv_decode.c @@ -19,6 +19,7 @@ #include <stdatomic.h> #include "libavutil/attributes.h" +#include "libavutil/avassert.h" #include "libavutil/mastering_display_metadata.h" #include "libavutil/mem_internal.h" #include "libavutil/pixdesc.h" @@ -82,7 +83,8 @@ static int apv_decode_check_format(AVCodecContext *avctx, avctx->level = header->frame_info.level_idc; bit_depth = header->frame_info.bit_depth_minus8 + 8; - if (bit_depth < 8 || bit_depth > 16 || bit_depth % 2) { + av_assert1(bit_depth >= 10 && bit_depth <= 16); // checked by CBS + if (bit_depth % 2) { avpriv_request_sample(avctx, "Bit depth %d", bit_depth); return AVERROR_PATCHWELCOME; } -- 2.52.0 >From e367c64fa7fe18591a85fe77e9ccf6068f355fa1 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 10 Mar 2026 21:53:33 +0100 Subject: [PATCH 3/7] avcodec/apv_decode: Remove unused array entries Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/apv_decode.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/apv_decode.c b/libavcodec/apv_decode.c index ab5a6b098a..a40b45dec0 100644 --- a/libavcodec/apv_decode.c +++ b/libavcodec/apv_decode.c @@ -64,12 +64,12 @@ typedef struct APVDecodeContext { uint8_t warned_unknown_pbu_types; } APVDecodeContext; -static const enum AVPixelFormat apv_format_table[5][5] = { - { AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16 }, +static const enum AVPixelFormat apv_format_table[5][4] = { + { AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16 }, { 0 }, // 4:2:0 is not valid. - { AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV422P16 }, - { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV444P16 }, - { AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, 0 ,AV_PIX_FMT_YUVA444P16 }, + { AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV422P16 }, + { AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV444P16 }, + { AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, 0 , AV_PIX_FMT_YUVA444P16 }, }; static APVVLCLUT decode_lut; @@ -89,7 +89,7 @@ static int apv_decode_check_format(AVCodecContext *avctx, return AVERROR_PATCHWELCOME; } avctx->pix_fmt = - apv_format_table[header->frame_info.chroma_format_idc][(bit_depth - 8) >> 1]; + apv_format_table[header->frame_info.chroma_format_idc][(bit_depth - 10) >> 1]; if (!avctx->pix_fmt) { avpriv_request_sample(avctx, "YUVA444P14"); -- 2.52.0 >From 722c3bb6a080fb0416e22a164ae9f9bf515bda4f Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 10 Mar 2026 21:56:17 +0100 Subject: [PATCH 4/7] avcodec/apv_decode: Don't rely on AV_PIX_FMT_YUV420 == 0 Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/apv_decode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/apv_decode.c b/libavcodec/apv_decode.c index a40b45dec0..4c0fd78cb0 100644 --- a/libavcodec/apv_decode.c +++ b/libavcodec/apv_decode.c @@ -66,10 +66,10 @@ typedef struct APVDecodeContext { static const enum AVPixelFormat apv_format_table[5][4] = { { AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16 }, - { 0 }, // 4:2:0 is not valid. + { AV_PIX_FMT_NONE, AV_PIX_FMT_NONE, AV_PIX_FMT_NONE, AV_PIX_FMT_NONE }, // 4:2:0 is not valid. { AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV422P16 }, { AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV444P16 }, - { AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, 0 , AV_PIX_FMT_YUVA444P16 }, + { AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_NONE, AV_PIX_FMT_YUVA444P16 }, }; static APVVLCLUT decode_lut; @@ -91,7 +91,7 @@ static int apv_decode_check_format(AVCodecContext *avctx, avctx->pix_fmt = apv_format_table[header->frame_info.chroma_format_idc][(bit_depth - 10) >> 1]; - if (!avctx->pix_fmt) { + if (avctx->pix_fmt == AV_PIX_FMT_NONE) { avpriv_request_sample(avctx, "YUVA444P14"); return AVERROR_PATCHWELCOME; } -- 2.52.0 >From 42000e19ec53a0dee6e7101c5092fe684d30e1ec Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 10 Mar 2026 22:07:17 +0100 Subject: [PATCH 5/7] avcodec/apv_dsp: Remove dead 8 bit code Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/apv_dsp.c | 17 ++------------ libavcodec/x86/apv_dsp.asm | 46 -------------------------------------- tests/checkasm/apv_dsp.c | 38 ------------------------------- 3 files changed, 2 insertions(+), 99 deletions(-) diff --git a/libavcodec/apv_dsp.c b/libavcodec/apv_dsp.c index 982ec36910..3513f04cd4 100644 --- a/libavcodec/apv_dsp.c +++ b/libavcodec/apv_dsp.c @@ -20,6 +20,7 @@ #include "config.h" #include "libavutil/attributes.h" +#include "libavutil/avassert.h" #include "libavutil/common.h" #include "apv.h" @@ -100,20 +101,7 @@ static void apv_decode_transquant_c(void *output, } // Output. - if (bit_depth == 8) { - uint8_t *ptr = output; - int bd_shift = 20 - bit_depth; - - for (int y = 0; y < 8; y++) { - for (int x = 0; x < 8; x++) { - int sample = ((recon_sample[y][x] + - (1 << (bd_shift - 1))) >> bd_shift) + - (1 << (bit_depth - 1)); - ptr[x] = av_clip_uintp2(sample, bit_depth); - } - ptr += pitch; - } - } else { + av_assert2(bit_depth > 8 && bit_depth <= 16); uint16_t *ptr = output; int bd_shift = 20 - bit_depth; pitch /= 2; // Pitch was in bytes, 2 bytes per sample. @@ -127,7 +115,6 @@ static void apv_decode_transquant_c(void *output, } ptr += pitch; } - } } av_cold void ff_apv_dsp_init(APVDSPContext *dsp) diff --git a/libavcodec/x86/apv_dsp.asm b/libavcodec/x86/apv_dsp.asm index e2f30fff13..2196759379 100644 --- a/libavcodec/x86/apv_dsp.asm +++ b/libavcodec/x86/apv_dsp.asm @@ -230,52 +230,6 @@ cglobal apv_decode_transquant, 5, 7, 16, output, pitch, input, qmatrix, bit_dept ; m11 = zero ; m12 = vector (1 << bit_depth) - 1 - cmp bit_depthd, 8 - jne store_10 - - lea tmpq, [pitchq + 2*pitchq] -%macro NORMALISE_AND_STORE_8 4 - vpaddd m%1, m%1, m8 - vpaddd m%2, m%2, m8 - vpaddd m%3, m%3, m8 - vpaddd m%4, m%4, m8 - vpsrad m%1, m%1, xm9 - vpsrad m%2, m%2, xm9 - vpsrad m%3, m%3, xm9 - vpsrad m%4, m%4, xm9 - vpaddd m%1, m%1, m10 - vpaddd m%2, m%2, m10 - vpaddd m%3, m%3, m10 - vpaddd m%4, m%4, m10 - ; m%1 = A0-3 A4-7 - ; m%2 = B0-3 B4-7 - ; m%3 = C0-3 C4-7 - ; m%4 = D0-3 D4-7 - vpackusdw m%1, m%1, m%2 - vpackusdw m%3, m%3, m%4 - ; m%1 = A0-3 B0-3 A4-7 B4-7 - ; m%2 = C0-3 D0-3 C4-7 D4-7 - vpermq m%1, m%1, q3120 - vpermq m%2, m%3, q3120 - ; m%1 = A0-3 A4-7 B0-3 B4-7 - ; m%2 = C0-3 C4-7 D0-3 D4-7 - vpackuswb m%1, m%1, m%2 - ; m%1 = A0-3 A4-7 C0-3 C4-7 B0-3 B4-7 D0-3 D4-7 - vextracti128 xm%2, m%1, 1 - vmovq [outputq], xm%1 - vmovq [outputq + pitchq], xm%2 - vpextrq [outputq + 2*pitchq], xm%1, 1 - vpextrq [outputq + tmpq], xm%2, 1 - lea outputq, [outputq + 4*pitchq] -%endmacro - - NORMALISE_AND_STORE_8 0, 1, 2, 3 - NORMALISE_AND_STORE_8 4, 5, 6, 7 - - RET - -store_10: - %macro NORMALISE_AND_STORE_10 2 vpaddd m%1, m%1, m8 vpaddd m%2, m%2, m8 diff --git a/tests/checkasm/apv_dsp.c b/tests/checkasm/apv_dsp.c index 6d3a356838..68c0f0313c 100644 --- a/tests/checkasm/apv_dsp.c +++ b/tests/checkasm/apv_dsp.c @@ -24,41 +24,6 @@ #include "libavutil/mem_internal.h" #include "libavcodec/apv_dsp.h" - -static void check_decode_transquant_8(void) -{ - LOCAL_ALIGNED_16(int16_t, input, [64]); - LOCAL_ALIGNED_16(int16_t, qmatrix, [64]); - LOCAL_ALIGNED_16(uint8_t, new_output, [64]); - LOCAL_ALIGNED_16(uint8_t, ref_output, [64]); - - declare_func(void, - void *output, - ptrdiff_t pitch, - const int16_t *input, - const int16_t *qmatrix, - int bit_depth, - int qp_shift); - - for (int i = 0; i < 64; i++) { - // Any signed 12-bit integer. - input[i] = rnd() % 2048 - 1024; - - // qmatrix input is premultiplied by level_scale, so - // range is 1 to 255 * 71. Interesting values are all - // at the low end of that, though. - qmatrix[i] = rnd() % 16 + 16; - } - - call_ref(ref_output, 8, input, qmatrix, 8, 4); - call_new(new_output, 8, input, qmatrix, 8, 4); - - if (memcmp(new_output, ref_output, 64 * sizeof(*ref_output))) - fail(); - - bench_new(new_output, 8, input, qmatrix, 8, 4); -} - static void check_decode_transquant_10(void) { LOCAL_ALIGNED_16( int16_t, input, [64]); @@ -99,9 +64,6 @@ void checkasm_check_apv_dsp(void) ff_apv_dsp_init(&dsp); - if (check_func(dsp.decode_transquant, "decode_transquant_8")) - check_decode_transquant_8(); - if (check_func(dsp.decode_transquant, "decode_transquant_10")) check_decode_transquant_10(); -- 2.52.0 >From 1cbf631fcf770eda5fd3693968041c4958d983bc Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Tue, 10 Mar 2026 22:09:29 +0100 Subject: [PATCH 6/7] avcodec/apv_dsp: Reindent after previous commit Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/apv_dsp.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libavcodec/apv_dsp.c b/libavcodec/apv_dsp.c index 3513f04cd4..22446d25a4 100644 --- a/libavcodec/apv_dsp.c +++ b/libavcodec/apv_dsp.c @@ -102,19 +102,19 @@ static void apv_decode_transquant_c(void *output, // Output. av_assert2(bit_depth > 8 && bit_depth <= 16); - uint16_t *ptr = output; - int bd_shift = 20 - bit_depth; - pitch /= 2; // Pitch was in bytes, 2 bytes per sample. + uint16_t *ptr = output; + int bd_shift = 20 - bit_depth; + pitch /= 2; // Pitch was in bytes, 2 bytes per sample. - for (int y = 0; y < 8; y++) { - for (int x = 0; x < 8; x++) { - int sample = ((recon_sample[y][x] + - (1 << (bd_shift - 1))) >> bd_shift) + - (1 << (bit_depth - 1)); - ptr[x] = av_clip_uintp2(sample, bit_depth); - } - ptr += pitch; + for (int y = 0; y < 8; y++) { + for (int x = 0; x < 8; x++) { + int sample = ((recon_sample[y][x] + + (1 << (bd_shift - 1))) >> bd_shift) + + (1 << (bit_depth - 1)); + ptr[x] = av_clip_uintp2(sample, bit_depth); } + ptr += pitch; + } } av_cold void ff_apv_dsp_init(APVDSPContext *dsp) -- 2.52.0 >From 1d1077306c3b8c1e5f8783ab4bae5bf31256052b Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Mon, 2 Mar 2026 02:13:55 +0100 Subject: [PATCH 7/7] avcodec/x86/apv_dsp: Don't clip unnecessarily It is redundant due to packusdw. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/x86/apv_dsp.asm | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libavcodec/x86/apv_dsp.asm b/libavcodec/x86/apv_dsp.asm index 2196759379..3ea28f62fd 100644 --- a/libavcodec/x86/apv_dsp.asm +++ b/libavcodec/x86/apv_dsp.asm @@ -222,12 +222,10 @@ cglobal apv_decode_transquant, 5, 7, 16, output, pitch, input, qmatrix, bit_dept vpslld m12, m14, xm15 vpsrld m10, m12, 1 vpsubd m12, m12, m14 - vpxor m11, m11, m11 ; m8 = vector 1 << (bd_shift - 1) ; m9 = scalar bd_shift ; m10 = vector 1 << (bit_depth - 1) - ; m11 = zero ; m12 = vector (1 << bit_depth) - 1 %macro NORMALISE_AND_STORE_10 2 @@ -237,8 +235,6 @@ cglobal apv_decode_transquant, 5, 7, 16, output, pitch, input, qmatrix, bit_dept vpsrad m%2, m%2, xm9 vpaddd m%1, m%1, m10 vpaddd m%2, m%2, m10 - vpmaxsd m%1, m%1, m11 - vpmaxsd m%2, m%2, m11 vpminsd m%1, m%1, m12 vpminsd m%2, m%2, m12 ; m%1 = A0-3 A4-7 -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
