History

avcodec/pixblockdsp: Improve 8 vs 16 bit check

Before this commit, the input in get_pixels and get_pixels_unaligned has been treated inconsistenly: - The generic code treated 9, 10, 12 and 14 bits as 16bit input (these bits correspond to what FFmpeg's dsputils supported), everything with <= 8 bits as 8 bit and everything else as 8 bit when used via AVDCT (which exposes these functions and purports to support up to 14 bits). - AARCH64, ARM, PPC and RISC-V, x86 ignore this AVDCT special case. - RISC-V also ignored the restriction to 9, 10, 12 and 14 for its 16bit check and treated everything > 8 bits as 16bit. - The mmi MIPS code treats everything as 8 bit when used via AVDCT (this is certainly broken); otherwise it checks for <= 8 bits. The msa MIPS code behaves like the generic code. This commit changes this to treat 9..16 bits as 16 bit input, everything else as 8 bit (the former because it makes sense, the latter to preserve the behaviour for external users*). *: The only internal user of AVDCT (the spp filter) always uses 8, 9 or 10 bits.

Andreas Rheinhardt committed 1 year ago

Commit 20ddada1 parent 61a70e88 files · +22 −52Browse files

Unified · Split

8 files
  1. libavcodec/aarch64/pixblockdsp_init_aarch64.c +0 −2
  2. libavcodec/arm/pixblockdsp_init_arm.c +0 −2
  3. libavcodec/mips/pixblockdsp_init_mips.c +3 −17
  4. libavcodec/pixblockdsp.c +13 −20
  5. libavcodec/pixblockdsp.h +6 −6
  6. libavcodec/ppc/pixblockdsp.c +0 −2
  7. libavcodec/riscv/pixblockdsp_init.c +0 −2
  8. libavcodec/x86/pixblockdsp_init.c +0 −1
libavcodec/aarch64/pixblockdsp_init_aarch64.c+0−2
@@ -21,7 +21,6 @@ · 20 unmodified lines
2121 #include "libavutil/attributes.h"
2222 #include "libavutil/cpu.h"
2323 #include "libavutil/aarch64/cpu.h"
24−#include "libavcodec/avcodec.h"
2524 #include "libavcodec/pixblockdsp.h"
2625
2726 void ff_get_pixels_neon(int16_t *block, const uint8_t *pixels,
@@ -30,7 +29,6 @@ void ff_diff_pixels_neon(int16_t *block, const uint8_t *s1, · 2 unmodified lines
3029 const uint8_t *s2, ptrdiff_t stride);
3130
3231 av_cold void ff_pixblockdsp_init_aarch64(PixblockDSPContext *c,
33− AVCodecContext *avctx,
3432 unsigned high_bit_depth)
3533 {
3634 int cpu_flags = av_get_cpu_flags();
libavcodec/arm/pixblockdsp_init_arm.c+0−2
@@ -21,7 +21,6 @@ · 20 unmodified lines
2121 #include "libavutil/attributes.h"
2222 #include "libavutil/cpu.h"
2323 #include "libavutil/arm/cpu.h"
24−#include "libavcodec/avcodec.h"
2524 #include "libavcodec/pixblockdsp.h"
2625
2726 void ff_get_pixels_armv6(int16_t *block, const uint8_t *pixels,
@@ -39,7 +38,6 @@ void ff_diff_pixels_unaligned_neon(int16_t *block, const uint8_t *s1, · 11 unmodified lines
3938 const uint8_t *s2, ptrdiff_t stride);
4039
4140 av_cold void ff_pixblockdsp_init_arm(PixblockDSPContext *c,
42− AVCodecContext *avctx,
4341 unsigned high_bit_depth)
4442 {
4543 int cpu_flags = av_get_cpu_flags();
libavcodec/mips/pixblockdsp_init_mips.c+3−17
@@ -23,7 +23,7 @@ · 22 unmodified lines
2323 #include "libavcodec/pixblockdsp.h"
2424 #include "pixblockdsp_mips.h"
2525
26−void ff_pixblockdsp_init_mips(PixblockDSPContext *c, AVCodecContext *avctx,
26+void ff_pixblockdsp_init_mips(PixblockDSPContext *c,
2727 unsigned high_bit_depth)
2828 {
2929 int cpu_flags = av_get_cpu_flags();
@@ -31,27 +31,13 @@ void ff_pixblockdsp_init_mips(PixblockDSPContext *c, AVCodecContext *avctx, · 1 unmodified line
3131 if (have_mmi(cpu_flags)) {
3232 c->diff_pixels = ff_diff_pixels_mmi;
3333
34− if (!high_bit_depth || avctx->codec_type != AVMEDIA_TYPE_VIDEO) {
34+ if (!high_bit_depth)
3535 c->get_pixels = ff_get_pixels_8_mmi;
36− }
3736 }
3837
3938 if (have_msa(cpu_flags)) {
4039 c->diff_pixels = ff_diff_pixels_msa;
4140
42− switch (avctx->bits_per_raw_sample) {
43− case 9:
44− case 10:
45− case 12:
46− case 14:
47− c->get_pixels = ff_get_pixels_16_msa;
48− break;
49− default:
50− if (avctx->bits_per_raw_sample <= 8 || avctx->codec_type !=
51− AVMEDIA_TYPE_VIDEO) {
52− c->get_pixels = ff_get_pixels_8_msa;
53− }
54− break;
55− }
41+ c->get_pixels = high_bit_depth ? ff_get_pixels_16_msa : ff_get_pixels_8_msa;
5642 }
5743 }
libavcodec/pixblockdsp.c+13−20
@@ -87,38 +87,31 @@ static void diff_pixels_c(int16_t *restrict block, const uint8_t *s1, · 86 unmodified lines
8787
8888 av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx)
8989 {
90− av_unused const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
90+ const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8 &&
91+ avctx->bits_per_raw_sample <= 16;
9192
9293 c->diff_pixels_unaligned =
9394 c->diff_pixels = diff_pixels_c;
9495
95− switch (avctx->bits_per_raw_sample) {
96− case 9:
97− case 10:
98− case 12:
99− case 14:
96+ if (high_bit_depth) {
10097 c->get_pixels_unaligned = get_pixels_unaligned_16_c;
101− c->get_pixels = get_pixels_16_c;
102− break;
103− default:
104− if (avctx->bits_per_raw_sample<=8 || avctx->codec_type != AVMEDIA_TYPE_VIDEO) {
105− c->get_pixels_unaligned =
106− c->get_pixels = get_pixels_8_c;
107− }
108− break;
98+ c->get_pixels = get_pixels_16_c;
99+ } else {
100+ c->get_pixels_unaligned =
101+ c->get_pixels = get_pixels_8_c;
109102 }
110103
111104 #if ARCH_AARCH64
112− ff_pixblockdsp_init_aarch64(c, avctx, high_bit_depth);
105+ ff_pixblockdsp_init_aarch64(c, high_bit_depth);
113106 #elif ARCH_ARM
114− ff_pixblockdsp_init_arm(c, avctx, high_bit_depth);
107+ ff_pixblockdsp_init_arm(c, high_bit_depth);
115108 #elif ARCH_PPC
116− ff_pixblockdsp_init_ppc(c, avctx, high_bit_depth);
109+ ff_pixblockdsp_init_ppc(c, high_bit_depth);
117110 #elif ARCH_RISCV
118− ff_pixblockdsp_init_riscv(c, avctx, high_bit_depth);
111+ ff_pixblockdsp_init_riscv(c, high_bit_depth);
119112 #elif ARCH_X86
120− ff_pixblockdsp_init_x86(c, avctx, high_bit_depth);
113+ ff_pixblockdsp_init_x86(c, high_bit_depth);
121114 #elif ARCH_MIPS
122− ff_pixblockdsp_init_mips(c, avctx, high_bit_depth);
115+ ff_pixblockdsp_init_mips(c, high_bit_depth);
123116 #endif
124117 }
libavcodec/pixblockdsp.h+6−6
@@ -42,17 +42,17 @@ typedef struct PixblockDSPContext { · 41 unmodified lines
4242 } PixblockDSPContext;
4343
4444 void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx);
45−void ff_pixblockdsp_init_aarch64(PixblockDSPContext *c, AVCodecContext *avctx,
45+void ff_pixblockdsp_init_aarch64(PixblockDSPContext *c,
4646 unsigned high_bit_depth);
47−void ff_pixblockdsp_init_arm(PixblockDSPContext *c, AVCodecContext *avctx,
47+void ff_pixblockdsp_init_arm(PixblockDSPContext *c,
4848 unsigned high_bit_depth);
49−void ff_pixblockdsp_init_ppc(PixblockDSPContext *c, AVCodecContext *avctx,
49+void ff_pixblockdsp_init_ppc(PixblockDSPContext *c,
5050 unsigned high_bit_depth);
51−void ff_pixblockdsp_init_riscv(PixblockDSPContext *c, AVCodecContext *avctx,
51+void ff_pixblockdsp_init_riscv(PixblockDSPContext *c,
5252 unsigned high_bit_depth);
53−void ff_pixblockdsp_init_x86(PixblockDSPContext *c, AVCodecContext *avctx,
53+void ff_pixblockdsp_init_x86(PixblockDSPContext *c,
5454 unsigned high_bit_depth);
55−void ff_pixblockdsp_init_mips(PixblockDSPContext *c, AVCodecContext *avctx,
55+void ff_pixblockdsp_init_mips(PixblockDSPContext *c,
5656 unsigned high_bit_depth);
5757
5858 #endif /* AVCODEC_PIXBLOCKDSP_H */
libavcodec/ppc/pixblockdsp.c+0−2
@@ -27,7 +27,6 @@ · 26 unmodified lines
2727 #include "libavutil/ppc/cpu.h"
2828 #include "libavutil/ppc/util_altivec.h"
2929
30−#include "libavcodec/avcodec.h"
3130 #include "libavcodec/pixblockdsp.h"
3231
3332 #if HAVE_ALTIVEC
@@ -263,7 +262,6 @@ static void diff_pixels_vsx(int16_t *restrict block, const uint8_t *s1, · 229 unmodified lines
263262 #endif /* HAVE_VSX */
264263
265264 av_cold void ff_pixblockdsp_init_ppc(PixblockDSPContext *c,
266− AVCodecContext *avctx,
267265 unsigned high_bit_depth)
268266 {
269267 #if HAVE_ALTIVEC
libavcodec/riscv/pixblockdsp_init.c+0−2
@@ -24,7 +24,6 @@ · 23 unmodified lines
2424 #include "libavutil/attributes.h"
2525 #include "libavutil/cpu.h"
2626 #include "libavutil/riscv/cpu.h"
27−#include "libavcodec/avcodec.h"
2827 #include "libavcodec/pixblockdsp.h"
2928
3029 void ff_get_pixels_8_rvi(int16_t *block, const uint8_t *pixels,
@@ -42,7 +41,6 @@ void ff_diff_pixels_unaligned_rvv(int16_t *block, const uint8_t *s1, · 11 unmodified lines
4241 const uint8_t *s2, ptrdiff_t stride);
4342
4443 av_cold void ff_pixblockdsp_init_riscv(PixblockDSPContext *c,
45− AVCodecContext *avctx,
4644 unsigned high_bit_depth)
4745 {
4846 #if HAVE_RV
libavcodec/x86/pixblockdsp_init.c+0−1
@@ -28,7 +28,6 @@ void ff_diff_pixels_sse2(int16_t *block, const uint8_t *s1, const uint8_t *s2, · 27 unmodified lines
2828 ptrdiff_t stride);
2929
3030 av_cold void ff_pixblockdsp_init_x86(PixblockDSPContext *c,
31− AVCodecContext *avctx,
3231 unsigned high_bit_depth)
3332 {
3433 int cpu_flags = av_get_cpu_flags();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t