* [FFmpeg-devel] [PATCH 2/4] lavc/mpegvideo: use H263DSP dequant function
2024-06-09 9:27 [FFmpeg-devel] [PATCHv2 1/4] lavc/h263dsp: add DCT dequantisation function Rémi Denis-Courmont
@ 2024-06-09 9:27 ` Rémi Denis-Courmont
2024-06-09 16:13 ` Andreas Rheinhardt
2024-06-09 9:27 ` [FFmpeg-devel] [PATCHv2 3/4] checkasm/h263dsp: test dct_unquantize Rémi Denis-Courmont
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Rémi Denis-Courmont @ 2024-06-09 9:27 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/mpegvideo.c | 30 +++++-------------------------
1 file changed, 5 insertions(+), 25 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 7af823b8bd..fa25d14970 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -201,7 +201,7 @@ static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s,
static void dct_unquantize_h263_intra_c(MpegEncContext *s,
int16_t *block, int n, int qscale)
{
- int i, level, qmul, qadd;
+ int qmul, qadd;
int nCoeffs;
av_assert2(s->block_last_index[n]>=0 || s->h263_aic);
@@ -219,23 +219,13 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s,
else
nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
- for(i=1; i<=nCoeffs; i++) {
- level = block[i];
- if (level) {
- if (level < 0) {
- level = level * qmul - qadd;
- } else {
- level = level * qmul + qadd;
- }
- block[i] = level;
- }
- }
+ s->h263dsp.h263_dct_unquantize(block, 1, nCoeffs, qmul, qadd);
}
static void dct_unquantize_h263_inter_c(MpegEncContext *s,
int16_t *block, int n, int qscale)
{
- int i, level, qmul, qadd;
+ int qmul, qadd;
int nCoeffs;
av_assert2(s->block_last_index[n]>=0);
@@ -244,18 +234,7 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s,
qmul = qscale << 1;
nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
-
- for(i=0; i<=nCoeffs; i++) {
- level = block[i];
- if (level) {
- if (level < 0) {
- level = level * qmul - qadd;
- } else {
- level = level * qmul + qadd;
- }
- block[i] = level;
- }
- }
+ s->h263dsp.h263_dct_unquantize(block, 0, nCoeffs, qmul, qadd);
}
@@ -275,6 +254,7 @@ static void gray8(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
static av_cold int dct_init(MpegEncContext *s)
{
ff_blockdsp_init(&s->bdsp);
+ ff_h263dsp_init(&s->h263dsp);
ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
--
2.45.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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/4] lavc/mpegvideo: use H263DSP dequant function
2024-06-09 9:27 ` [FFmpeg-devel] [PATCH 2/4] lavc/mpegvideo: use H263DSP dequant function Rémi Denis-Courmont
@ 2024-06-09 16:13 ` Andreas Rheinhardt
2024-06-09 16:39 ` Rémi Denis-Courmont
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Rheinhardt @ 2024-06-09 16:13 UTC (permalink / raw)
To: ffmpeg-devel
Rémi Denis-Courmont:
> ---
> libavcodec/mpegvideo.c | 30 +++++-------------------------
> 1 file changed, 5 insertions(+), 25 deletions(-)
>
> diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
> index 7af823b8bd..fa25d14970 100644
> --- a/libavcodec/mpegvideo.c
> +++ b/libavcodec/mpegvideo.c
> @@ -201,7 +201,7 @@ static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s,
> static void dct_unquantize_h263_intra_c(MpegEncContext *s,
> int16_t *block, int n, int qscale)
> {
> - int i, level, qmul, qadd;
> + int qmul, qadd;
> int nCoeffs;
>
> av_assert2(s->block_last_index[n]>=0 || s->h263_aic);
> @@ -219,23 +219,13 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s,
> else
> nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
>
> - for(i=1; i<=nCoeffs; i++) {
> - level = block[i];
> - if (level) {
> - if (level < 0) {
> - level = level * qmul - qadd;
> - } else {
> - level = level * qmul + qadd;
> - }
> - block[i] = level;
> - }
> - }
> + s->h263dsp.h263_dct_unquantize(block, 1, nCoeffs, qmul, qadd);
> }
>
> static void dct_unquantize_h263_inter_c(MpegEncContext *s,
> int16_t *block, int n, int qscale)
> {
> - int i, level, qmul, qadd;
> + int qmul, qadd;
> int nCoeffs;
>
> av_assert2(s->block_last_index[n]>=0);
> @@ -244,18 +234,7 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s,
> qmul = qscale << 1;
>
> nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
> -
> - for(i=0; i<=nCoeffs; i++) {
> - level = block[i];
> - if (level) {
> - if (level < 0) {
> - level = level * qmul - qadd;
> - } else {
> - level = level * qmul + qadd;
> - }
> - block[i] = level;
> - }
> - }
> + s->h263dsp.h263_dct_unquantize(block, 0, nCoeffs, qmul, qadd);
> }
>
>
> @@ -275,6 +254,7 @@ static void gray8(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
> static av_cold int dct_init(MpegEncContext *s)
> {
> ff_blockdsp_init(&s->bdsp);
> + ff_h263dsp_init(&s->h263dsp);
> ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
> ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
>
This approach will make H.261 use a h263dsp function which is a misnomer
and will lead to undefined references if no H.263 decoder or encoder is
enabled.
- Andreas
_______________________________________________
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] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/4] lavc/mpegvideo: use H263DSP dequant function
2024-06-09 16:13 ` Andreas Rheinhardt
@ 2024-06-09 16:39 ` Rémi Denis-Courmont
0 siblings, 0 replies; 7+ messages in thread
From: Rémi Denis-Courmont @ 2024-06-09 16:39 UTC (permalink / raw)
To: ffmpeg-devel
Le sunnuntaina 9. kesäkuuta 2024, 19.13.54 EEST Andreas Rheinhardt a écrit :
> Rémi Denis-Courmont:
> > ---
> >
> > libavcodec/mpegvideo.c | 30 +++++-------------------------
> > 1 file changed, 5 insertions(+), 25 deletions(-)
> >
> > diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
> > index 7af823b8bd..fa25d14970 100644
> > --- a/libavcodec/mpegvideo.c
> > +++ b/libavcodec/mpegvideo.c
> > @@ -201,7 +201,7 @@ static void
> > dct_unquantize_mpeg2_inter_c(MpegEncContext *s,>
> > static void dct_unquantize_h263_intra_c(MpegEncContext *s,
> >
> > int16_t *block, int n, int qscale)
> >
> > {
> >
> > - int i, level, qmul, qadd;
> > + int qmul, qadd;
> >
> > int nCoeffs;
> >
> > av_assert2(s->block_last_index[n]>=0 || s->h263_aic);
> >
> > @@ -219,23 +219,13 @@ static void
> > dct_unquantize_h263_intra_c(MpegEncContext *s,>
> > else
> >
> > nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
> >
> > - for(i=1; i<=nCoeffs; i++) {
> > - level = block[i];
> > - if (level) {
> > - if (level < 0) {
> > - level = level * qmul - qadd;
> > - } else {
> > - level = level * qmul + qadd;
> > - }
> > - block[i] = level;
> > - }
> > - }
> > + s->h263dsp.h263_dct_unquantize(block, 1, nCoeffs, qmul, qadd);
> >
> > }
> >
> > static void dct_unquantize_h263_inter_c(MpegEncContext *s,
> >
> > int16_t *block, int n, int qscale)
> >
> > {
> >
> > - int i, level, qmul, qadd;
> > + int qmul, qadd;
> >
> > int nCoeffs;
> >
> > av_assert2(s->block_last_index[n]>=0);
> >
> > @@ -244,18 +234,7 @@ static void
> > dct_unquantize_h263_inter_c(MpegEncContext *s,>
> > qmul = qscale << 1;
> >
> > nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
> >
> > -
> > - for(i=0; i<=nCoeffs; i++) {
> > - level = block[i];
> > - if (level) {
> > - if (level < 0) {
> > - level = level * qmul - qadd;
> > - } else {
> > - level = level * qmul + qadd;
> > - }
> > - block[i] = level;
> > - }
> > - }
> > + s->h263dsp.h263_dct_unquantize(block, 0, nCoeffs, qmul, qadd);
> >
> > }
> >
> > @@ -275,6 +254,7 @@ static void gray8(uint8_t *dst, const uint8_t *src,
> > ptrdiff_t linesize, int h)>
> > static av_cold int dct_init(MpegEncContext *s)
> > {
> >
> > ff_blockdsp_init(&s->bdsp);
> >
> > + ff_h263dsp_init(&s->h263dsp);
> >
> > ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
> > ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
>
> This approach will make H.261 use a h263dsp function which is a misnomer
In reality, that is an existing problem: the *existing* pair of DCT functions
for H.263 is provisioned regardless of the codec. Fixing the god object and
spaghetti anti-patterns in MpegEncContext is way outside the scope of this MR.
> and will lead to undefined references if no H.263 decoder or encoder is
> enabled.
Fair enough, *that* is easy to fix.
--
Rémi Denis-Courmont
http://www.remlab.net/
_______________________________________________
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] 7+ messages in thread
* [FFmpeg-devel] [PATCHv2 3/4] checkasm/h263dsp: test dct_unquantize
2024-06-09 9:27 [FFmpeg-devel] [PATCHv2 1/4] lavc/h263dsp: add DCT dequantisation function Rémi Denis-Courmont
2024-06-09 9:27 ` [FFmpeg-devel] [PATCH 2/4] lavc/mpegvideo: use H263DSP dequant function Rémi Denis-Courmont
@ 2024-06-09 9:27 ` Rémi Denis-Courmont
2024-06-09 9:27 ` [FFmpeg-devel] [PATCH 4/4] lavc/h263dsp: R-V V dct_unquantize Rémi Denis-Courmont
2024-06-09 15:47 ` [FFmpeg-devel] [PATCHv2 1/4] lavc/h263dsp: add DCT dequantisation function Rémi Denis-Courmont
3 siblings, 0 replies; 7+ messages in thread
From: Rémi Denis-Courmont @ 2024-06-09 9:27 UTC (permalink / raw)
To: ffmpeg-devel
---
tests/checkasm/h263dsp.c | 46 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/tests/checkasm/h263dsp.c b/tests/checkasm/h263dsp.c
index 2d0957a90b..546204cb28 100644
--- a/tests/checkasm/h263dsp.c
+++ b/tests/checkasm/h263dsp.c
@@ -18,13 +18,54 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <stdbool.h>
#include <string.h>
#include "checkasm.h"
-#include "libavcodec/h263dsp.h"
+#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
+#include "libavcodec/h263dsp.h"
+#include "libavcodec/mpegvideodata.h"
+
+static uint_fast8_t mpeg_qscale_rnd(void)
+{
+ int n = rnd(), q = (n >> 1) & 31;
+
+ if (n & 1)
+ return ff_mpeg2_non_linear_qscale[q];
+ else
+ return q << 1;
+}
+
+static void check_dct_unquantize(H263DSPContext *ctx, bool intra)
+{
+#define LEN 64
+ LOCAL_ALIGNED_16(int16_t, block0, [LEN]);
+ LOCAL_ALIGNED_16(int16_t, block1, [LEN]);
+ size_t end = rnd() % LEN;
+ const int qscale = mpeg_qscale_rnd();
+ const int qmul = qscale << 1;
+ const int qadd = (rnd() & 1) ? (qscale - 1) | 1 : 0;
+
+ declare_func(void, int16_t *, size_t, size_t, int, int);
+
+ for (size_t i = 0; i < LEN; i++)
+ block1[i] = block0[i] = (rnd() & 1) ? rnd() : 0;
+
+ if (check_func(ctx->h263_dct_unquantize, "h263dsp.dct_unquantize_int%s",
+ intra ? "ra" : "er")) {
+ av_assert0(end < LEN);
+ call_ref(block0, intra, end, qmul, qadd);
+ call_new(block1, intra, end, qmul, qadd);
+
+ if (memcmp(block0, block1, (end + 1) * sizeof (int16_t)))
+ fail();
+
+ bench_new(block1, intra, LEN, qmul, qadd);
+ }
+}
typedef void (*filter)(uint8_t *src, int stride, int qscale);
@@ -56,6 +97,9 @@ void checkasm_check_h263dsp(void)
H263DSPContext ctx;
ff_h263dsp_init(&ctx);
+ check_dct_unquantize(&ctx, false);
+ check_dct_unquantize(&ctx, true);
+ report("dct_unquantize");
check_loop_filter('h', ctx.h263_h_loop_filter);
check_loop_filter('v', ctx.h263_v_loop_filter);
report("loop_filter");
--
2.45.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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH 4/4] lavc/h263dsp: R-V V dct_unquantize
2024-06-09 9:27 [FFmpeg-devel] [PATCHv2 1/4] lavc/h263dsp: add DCT dequantisation function Rémi Denis-Courmont
2024-06-09 9:27 ` [FFmpeg-devel] [PATCH 2/4] lavc/mpegvideo: use H263DSP dequant function Rémi Denis-Courmont
2024-06-09 9:27 ` [FFmpeg-devel] [PATCHv2 3/4] checkasm/h263dsp: test dct_unquantize Rémi Denis-Courmont
@ 2024-06-09 9:27 ` Rémi Denis-Courmont
2024-06-09 15:47 ` [FFmpeg-devel] [PATCHv2 1/4] lavc/h263dsp: add DCT dequantisation function Rémi Denis-Courmont
3 siblings, 0 replies; 7+ messages in thread
From: Rémi Denis-Courmont @ 2024-06-09 9:27 UTC (permalink / raw)
To: ffmpeg-devel
T-Head C908:
h263dsp.dct_unquantize_inter_c: 5.7
h263dsp.dct_unquantize_inter_rvv_i32: 2.7
h263dsp.dct_unquantize_intra_c: 5.7
h263dsp.dct_unquantize_intra_rvv_i32: 3.0
SpacemiT X60:
h263dsp.dct_unquantize_inter_c: 5.0
h263dsp.dct_unquantize_inter_rvv_i32: 1.2
h263dsp.dct_unquantize_intra_c: 5.0
h263dsp.dct_unquantize_intra_rvv_i32: 1.5
---
libavcodec/riscv/h263dsp_init.c | 12 +++++++++---
libavcodec/riscv/h263dsp_rvv.S | 22 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/libavcodec/riscv/h263dsp_init.c b/libavcodec/riscv/h263dsp_init.c
index 21b536366c..5d73fde865 100644
--- a/libavcodec/riscv/h263dsp_init.c
+++ b/libavcodec/riscv/h263dsp_init.c
@@ -25,6 +25,7 @@
#include "libavutil/riscv/cpu.h"
#include "libavcodec/h263dsp.h"
+void ff_h263_dct_unquantize_rvv(int16_t *, size_t start, size_t end, int, int);
void ff_h263_h_loop_filter_rvv(uint8_t *src, int stride, int q);
void ff_h263_v_loop_filter_rvv(uint8_t *src, int stride, int q);
@@ -33,9 +34,14 @@ av_cold void ff_h263dsp_init_riscv(H263DSPContext *c)
#if HAVE_RVV
int flags = av_get_cpu_flags();
- if ((flags & AV_CPU_FLAG_RVV_I32) && ff_rv_vlen_least(128)) {
- c->h263_h_loop_filter = ff_h263_h_loop_filter_rvv;
- c->h263_v_loop_filter = ff_h263_v_loop_filter_rvv;
+ if (flags & AV_CPU_FLAG_RVV_I32) {
+ if (flags & AV_CPU_FLAG_RVB_ADDR)
+ c->h263_dct_unquantize = ff_h263_dct_unquantize_rvv;
+
+ if (ff_rv_vlen_least(128)) {
+ c->h263_h_loop_filter = ff_h263_h_loop_filter_rvv;
+ c->h263_v_loop_filter = ff_h263_v_loop_filter_rvv;
+ }
}
#endif
}
diff --git a/libavcodec/riscv/h263dsp_rvv.S b/libavcodec/riscv/h263dsp_rvv.S
index 97503d527c..319c51a0bb 100644
--- a/libavcodec/riscv/h263dsp_rvv.S
+++ b/libavcodec/riscv/h263dsp_rvv.S
@@ -20,6 +20,28 @@
#include "libavutil/riscv/asm.S"
+func ff_h263_dct_unquantize_rvv, zve32x
+ sub a2, a2, a1
+ sh1add a0, a1, a0
+ addi a2, a2, 1
+1:
+ vsetvli t0, a2, e16, m4, ta, mu
+ vle16.v v8, (a0)
+ sub a2, a2, t0
+ vmv.v.x v24, a4
+ vmslt.vi v0, v8, 0
+ vneg.v v24, v24, v0.t
+ vmsne.vi v0, v8, 0
+ vwmul.vx v16, v8, a3
+ vwadd.wv v16, v16, v24, v0.t
+ vncvt.x.x.w v8, v16
+ vse16.v v8, (a0)
+ sh1add a0, t0, a0
+ bnez a2, 1b
+
+ ret
+endfunc
+
.option push
.option norelax
func ff_h263_h_loop_filter_rvv, zve32x
--
2.45.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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCHv2 1/4] lavc/h263dsp: add DCT dequantisation function
2024-06-09 9:27 [FFmpeg-devel] [PATCHv2 1/4] lavc/h263dsp: add DCT dequantisation function Rémi Denis-Courmont
` (2 preceding siblings ...)
2024-06-09 9:27 ` [FFmpeg-devel] [PATCH 4/4] lavc/h263dsp: R-V V dct_unquantize Rémi Denis-Courmont
@ 2024-06-09 15:47 ` Rémi Denis-Courmont
3 siblings, 0 replies; 7+ messages in thread
From: Rémi Denis-Courmont @ 2024-06-09 15:47 UTC (permalink / raw)
To: ffmpeg-devel
Le sunnuntaina 9. kesäkuuta 2024, 12.27.06 EEST Rémi Denis-Courmont a écrit :
> To preserve the alignment promise of the block base address, we pass
> the start offset separately (it is either 0 or 1).
>
> Note that optimised implementations of this function will be taken into
> actual use if MpegEncContext.dct_unquantize_h263_{inter,intra} are *not*
> overloaded by existing optimisations.
> ---
> libavcodec/h263dsp.c | 17 +++++++++++++++++
> libavcodec/h263dsp.h | 2 ++
> 2 files changed, 19 insertions(+)
>
> diff --git a/libavcodec/h263dsp.c b/libavcodec/h263dsp.c
> index 6a13353499..eb990f27bd 100644
> --- a/libavcodec/h263dsp.c
> +++ b/libavcodec/h263dsp.c
> @@ -23,6 +23,22 @@
> #include "config.h"
> #include "h263dsp.h"
>
> +static void h263_dct_unquantize_c(int16_t *block, size_t start, size_t end,
> + int qmul, int qadd)
> +{
> + for (size_t i = start; i <= end; i++) {
C and R-V V don't care, but for the sake of more constrained SIMD extensions,
it should be easier to keep intra and inter DCT functions separate.
--
Rémi Denis-Courmont
http://www.remlab.net/
_______________________________________________
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] 7+ messages in thread