From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH] avcodec/mpegvideo: Remove spec-incompliant inverse quantisation
Date: Mon, 30 Oct 2023 14:11:27 +0100
Message-ID: <AS8P250MB07442A1CD0C5A69943DF4DA78FA1A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
Section 7.4.4 of the MPEG-2 specifications requires that the
last bit of the last coefficient be toggled so that the sum
of all coefficients is odd; both our decoder and encoder
did this only if the bitexact flag has been set (although
stuff like this should be behind AV_CODEC_FLAG2_FAST).
This patch changes this by removing the spec-incompliant
functions.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mips/mpegvideo_init_mips.c | 4 --
libavcodec/mips/mpegvideo_mips.h | 2 -
libavcodec/mips/mpegvideo_mmi.c | 93 ---------------------------
libavcodec/mpegvideo.c | 32 ---------
libavcodec/x86/mpegvideo.c | 72 ---------------------
5 files changed, 203 deletions(-)
diff --git a/libavcodec/mips/mpegvideo_init_mips.c b/libavcodec/mips/mpegvideo_init_mips.c
index f687ad18f1..1b383ee3f5 100644
--- a/libavcodec/mips/mpegvideo_init_mips.c
+++ b/libavcodec/mips/mpegvideo_init_mips.c
@@ -33,10 +33,6 @@ av_cold void ff_mpv_common_init_mips(MpegEncContext *s)
s->dct_unquantize_mpeg1_intra = ff_dct_unquantize_mpeg1_intra_mmi;
s->dct_unquantize_mpeg1_inter = ff_dct_unquantize_mpeg1_inter_mmi;
- if (!(s->avctx->flags & AV_CODEC_FLAG_BITEXACT))
- if (!s->q_scale_type)
- s->dct_unquantize_mpeg2_intra = ff_dct_unquantize_mpeg2_intra_mmi;
-
s->denoise_dct= ff_denoise_dct_mmi;
}
diff --git a/libavcodec/mips/mpegvideo_mips.h b/libavcodec/mips/mpegvideo_mips.h
index 760d7b3295..0bc0e375bd 100644
--- a/libavcodec/mips/mpegvideo_mips.h
+++ b/libavcodec/mips/mpegvideo_mips.h
@@ -31,8 +31,6 @@ void ff_dct_unquantize_mpeg1_intra_mmi(MpegEncContext *s, int16_t *block,
int n, int qscale);
void ff_dct_unquantize_mpeg1_inter_mmi(MpegEncContext *s, int16_t *block,
int n, int qscale);
-void ff_dct_unquantize_mpeg2_intra_mmi(MpegEncContext *s, int16_t *block,
- int n, int qscale);
void ff_denoise_dct_mmi(MpegEncContext *s, int16_t *block);
#endif /* AVCODEC_MIPS_MPEGVIDEO_MIPS_H */
diff --git a/libavcodec/mips/mpegvideo_mmi.c b/libavcodec/mips/mpegvideo_mmi.c
index 3d5b5e20ab..d0bf1a3c10 100644
--- a/libavcodec/mips/mpegvideo_mmi.c
+++ b/libavcodec/mips/mpegvideo_mmi.c
@@ -342,99 +342,6 @@ void ff_dct_unquantize_mpeg1_inter_mmi(MpegEncContext *s, int16_t *block,
);
}
-void ff_dct_unquantize_mpeg2_intra_mmi(MpegEncContext *s, int16_t *block,
- int n, int qscale)
-{
- uint64_t nCoeffs;
- const uint16_t *quant_matrix;
- int block0;
- double ftmp[10];
- uint64_t tmp[1];
- mips_reg addr[1];
- DECLARE_VAR_ALL64;
- DECLARE_VAR_ADDRT;
-
- assert(s->block_last_index[n]>=0);
-
- if (s->alternate_scan)
- nCoeffs = 63;
- else
- nCoeffs = s->intra_scantable.raster_end[s->block_last_index[n]];
-
- if (n < 4)
- block0 = block[0] * s->y_dc_scale;
- else
- block0 = block[0] * s->c_dc_scale;
-
- quant_matrix = s->intra_matrix;
-
- __asm__ volatile (
- "dli %[tmp0], 0x0f \n\t"
- "pcmpeqh %[ftmp0], %[ftmp0], %[ftmp0] \n\t"
- "mtc1 %[tmp0], %[ftmp3] \n\t"
- "mtc1 %[qscale], %[ftmp9] \n\t"
- "psrlh %[ftmp0], %[ftmp0], %[ftmp3] \n\t"
- "packsswh %[ftmp9], %[ftmp9], %[ftmp9] \n\t"
- "packsswh %[ftmp9], %[ftmp9], %[ftmp9] \n\t"
- "or %[addr0], %[nCoeffs], $0 \n\t"
- ".p2align 4 \n\t"
-
- "1: \n\t"
- MMI_LDXC1(%[ftmp1], %[addr0], %[block], 0x00)
- MMI_LDXC1(%[ftmp2], %[addr0], %[block], 0x08)
- "mov.d %[ftmp3], %[ftmp1] \n\t"
- "mov.d %[ftmp4], %[ftmp2] \n\t"
- MMI_LDXC1(%[ftmp5], %[addr0], %[quant], 0x00)
- MMI_LDXC1(%[ftmp6], %[addr0], %[quant], 0x08)
- "pmullh %[ftmp5], %[ftmp5], %[ftmp9] \n\t"
- "pmullh %[ftmp6], %[ftmp6], %[ftmp9] \n\t"
- "pxor %[ftmp7], %[ftmp7], %[ftmp7] \n\t"
- "pxor %[ftmp8], %[ftmp8], %[ftmp8] \n\t"
- "pcmpgth %[ftmp7], %[ftmp7], %[ftmp1] \n\t"
- "pcmpgth %[ftmp8], %[ftmp8], %[ftmp2] \n\t"
- "pxor %[ftmp1], %[ftmp1], %[ftmp7] \n\t"
- "pxor %[ftmp2], %[ftmp2], %[ftmp8] \n\t"
- "psubh %[ftmp1], %[ftmp1], %[ftmp7] \n\t"
- "psubh %[ftmp2], %[ftmp2], %[ftmp8] \n\t"
- "pmullh %[ftmp1], %[ftmp1], %[ftmp5] \n\t"
- "pmullh %[ftmp2], %[ftmp2], %[ftmp6] \n\t"
- "pxor %[ftmp5], %[ftmp5], %[ftmp5] \n\t"
- "pxor %[ftmp6], %[ftmp6], %[ftmp6] \n\t"
- "pcmpeqh %[ftmp5], %[ftmp5], %[ftmp3] \n\t"
- "dli %[tmp0], 0x03 \n\t"
- "pcmpeqh %[ftmp6] , %[ftmp6], %[ftmp4] \n\t"
- "mtc1 %[tmp0], %[ftmp3] \n\t"
- "psrah %[ftmp1], %[ftmp1], %[ftmp3] \n\t"
- "psrah %[ftmp2], %[ftmp2], %[ftmp3] \n\t"
- "pxor %[ftmp1], %[ftmp1], %[ftmp7] \n\t"
- "pxor %[ftmp2], %[ftmp2], %[ftmp8] \n\t"
- "psubh %[ftmp1], %[ftmp1], %[ftmp7] \n\t"
- "psubh %[ftmp2], %[ftmp2], %[ftmp8] \n\t"
- "pandn %[ftmp5], %[ftmp5], %[ftmp1] \n\t"
- "pandn %[ftmp6], %[ftmp6], %[ftmp2] \n\t"
- MMI_SDXC1(%[ftmp5], %[addr0], %[block], 0x00)
- MMI_SDXC1(%[ftmp6], %[addr0], %[block], 0x08)
- PTR_ADDIU "%[addr0], %[addr0], 0x10 \n\t"
- "blez %[addr0], 1b \n\t"
- : [ftmp0]"=&f"(ftmp[0]), [ftmp1]"=&f"(ftmp[1]),
- [ftmp2]"=&f"(ftmp[2]), [ftmp3]"=&f"(ftmp[3]),
- [ftmp4]"=&f"(ftmp[4]), [ftmp5]"=&f"(ftmp[5]),
- [ftmp6]"=&f"(ftmp[6]), [ftmp7]"=&f"(ftmp[7]),
- [ftmp8]"=&f"(ftmp[8]), [ftmp9]"=&f"(ftmp[9]),
- [tmp0]"=&r"(tmp[0]),
- RESTRICT_ASM_ALL64
- RESTRICT_ASM_ADDRT
- [addr0]"=&r"(addr[0])
- : [block]"r"((mips_reg)(block+nCoeffs)),
- [quant]"r"((mips_reg)(quant_matrix+nCoeffs)),
- [nCoeffs]"r"((mips_reg)(2*(-nCoeffs))),
- [qscale]"r"(qscale)
- : "memory"
- );
-
- block[0]= block0;
-}
-
void ff_denoise_dct_mmi(MpegEncContext *s, int16_t *block)
{
const int intra = s->mb_intra;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 81796e42bb..dadb8462e1 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -104,36 +104,6 @@ static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s,
{
int i, level, nCoeffs;
const uint16_t *quant_matrix;
-
- if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale];
- else qscale <<= 1;
-
- if(s->alternate_scan) nCoeffs= 63;
- else nCoeffs= s->block_last_index[n];
-
- block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale;
- quant_matrix = s->intra_matrix;
- for(i=1;i<=nCoeffs;i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (int)(level * qscale * quant_matrix[j]) >> 4;
- level = -level;
- } else {
- level = (int)(level * qscale * quant_matrix[j]) >> 4;
- }
- block[j] = level;
- }
- }
-}
-
-static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s,
- int16_t *block, int n, int qscale)
-{
- int i, level, nCoeffs;
- const uint16_t *quant_matrix;
int sum=-1;
if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale];
@@ -295,8 +265,6 @@ static av_cold int dct_init(MpegEncContext *s)
s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;
s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;
- if (s->avctx->flags & AV_CODEC_FLAG_BITEXACT)
- s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;
s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
#if HAVE_INTRINSICS_NEON
diff --git a/libavcodec/x86/mpegvideo.c b/libavcodec/x86/mpegvideo.c
index 73967cafda..f3384dfaa5 100644
--- a/libavcodec/x86/mpegvideo.c
+++ b/libavcodec/x86/mpegvideo.c
@@ -23,7 +23,6 @@
#include "libavutil/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
-#include "libavcodec/avcodec.h"
#include "libavcodec/mpegvideo.h"
#include "libavcodec/mpegvideodata.h"
@@ -300,75 +299,6 @@ __asm__ volatile(
);
}
-static void dct_unquantize_mpeg2_intra_mmx(MpegEncContext *s,
- int16_t *block, int n, int qscale)
-{
- x86_reg nCoeffs;
- const uint16_t *quant_matrix;
- int block0;
-
- av_assert2(s->block_last_index[n]>=0);
-
- if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale];
- else qscale <<= 1;
-
- if(s->alternate_scan) nCoeffs= 63; //FIXME
- else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
-
- if (n < 4)
- block0 = block[0] * s->y_dc_scale;
- else
- block0 = block[0] * s->c_dc_scale;
- quant_matrix = s->intra_matrix;
-__asm__ volatile(
- "pcmpeqw %%mm7, %%mm7 \n\t"
- "psrlw $15, %%mm7 \n\t"
- "movd %2, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "mov %3, %%"FF_REG_a" \n\t"
- ".p2align 4 \n\t"
- "1: \n\t"
- "movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
- "movq 8(%0, %%"FF_REG_a"), %%mm1\n\t"
- "movq (%1, %%"FF_REG_a"), %%mm4 \n\t"
- "movq 8(%1, %%"FF_REG_a"), %%mm5\n\t"
- "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
- "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
- "pxor %%mm2, %%mm2 \n\t"
- "pxor %%mm3, %%mm3 \n\t"
- "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
- "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
- "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
- "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
- "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
- "pxor %%mm4, %%mm4 \n\t"
- "pxor %%mm5, %%mm5 \n\t" // FIXME slow
- "pcmpeqw (%0, %%"FF_REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
- "pcmpeqw 8(%0, %%"FF_REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
- "psraw $4, %%mm0 \n\t"
- "psraw $4, %%mm1 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t"
- "psubw %%mm3, %%mm1 \n\t"
- "pandn %%mm0, %%mm4 \n\t"
- "pandn %%mm1, %%mm5 \n\t"
- "movq %%mm4, (%0, %%"FF_REG_a") \n\t"
- "movq %%mm5, 8(%0, %%"FF_REG_a")\n\t"
-
- "add $16, %%"FF_REG_a" \n\t"
- "jng 1b \n\t"
- ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
- : "%"FF_REG_a, "memory"
- );
- block[0]= block0;
- //Note, we do not do mismatch control for intra as errors cannot accumulate
-}
-
static void dct_unquantize_mpeg2_inter_mmx(MpegEncContext *s,
int16_t *block, int n, int qscale)
{
@@ -461,8 +391,6 @@ av_cold void ff_mpv_common_init_x86(MpegEncContext *s)
s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_mmx;
s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_mmx;
s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_mmx;
- if (!(s->avctx->flags & AV_CODEC_FLAG_BITEXACT))
- s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_mmx;
s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_mmx;
}
#endif /* HAVE_MMX_INLINE */
--
2.34.1
_______________________________________________
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".
next reply other threads:[~2023-10-30 13:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-30 13:11 Andreas Rheinhardt [this message]
2023-10-30 18:40 ` Kieran Kunhya
2023-10-31 8:40 ` Michael Niedermayer
2023-11-08 11:40 ` Anton Khirnov
2023-11-08 20:55 ` Alexander Strasser
2023-11-08 22:58 ` Vittorio Giovara
2023-11-09 20:55 ` Alexander Strasser
2023-11-09 10:13 ` Anton Khirnov
2023-11-09 20:45 ` Alexander Strasser
2023-11-09 20:52 ` Rémi Denis-Courmont
2023-11-09 22:16 ` Michael Niedermayer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS8P250MB07442A1CD0C5A69943DF4DA78FA1A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git