* [FFmpeg-devel] [PATCH 02/57] avcodec/mpegvideo_enc: Avoid branches for flipping no_rounding
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
@ 2024-06-12 13:47 ` Andreas Rheinhardt
2024-06-12 13:47 ` [FFmpeg-devel] [PATCH 03/57] avcodec/mpegvideo: Don't pretend dct_init can fail Andreas Rheinhardt
` (70 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:47 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index eda2305630..6ad5b0eb39 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -713,6 +713,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->modified_quant = s->h263_aic;
s->loop_filter = (avctx->flags & AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
s->unrestricted_mv = s->obmc || s->loop_filter || s->umvplus;
+ s->flipflop_rounding = 1;
/* /Fx */
/* These are just to be sure */
@@ -746,6 +747,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->out_format = FMT_H263;
s->h263_pred = 1;
s->unrestricted_mv = 1;
+ s->flipflop_rounding = 1;
s->low_delay = s->max_b_frames ? 0 : 1;
avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1);
break;
@@ -1829,10 +1831,7 @@ vbv_retry:
s->mb_skipped = 0; // done in frame_start()
// done in encode_picture() so we must undo it
if (s->pict_type == AV_PICTURE_TYPE_P) {
- if (s->flipflop_rounding ||
- s->codec_id == AV_CODEC_ID_H263P ||
- s->codec_id == AV_CODEC_ID_MPEG4)
- s->no_rounding ^= 1;
+ s->no_rounding ^= s->flipflop_rounding;
}
if (s->pict_type != AV_PICTURE_TYPE_B) {
s->time_base = s->last_time_base;
@@ -3576,8 +3575,7 @@ static int encode_picture(MpegEncContext *s, const AVPacket *pkt)
if(s->pict_type==AV_PICTURE_TYPE_I){
s->no_rounding = s->msmpeg4_version >= MSMP4_V3;
}else if(s->pict_type!=AV_PICTURE_TYPE_B){
- if(s->flipflop_rounding || s->codec_id == AV_CODEC_ID_H263P || s->codec_id == AV_CODEC_ID_MPEG4)
- s->no_rounding ^= 1;
+ s->no_rounding ^= s->flipflop_rounding;
}
if (s->avctx->flags & AV_CODEC_FLAG_PASS2) {
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 03/57] avcodec/mpegvideo: Don't pretend dct_init can fail
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
2024-06-12 13:47 ` [FFmpeg-devel] [PATCH 02/57] avcodec/mpegvideo_enc: Avoid branches for flipping no_rounding Andreas Rheinhardt
@ 2024-06-12 13:47 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 04/57] avcodec/mpegvideo: Set dct_unquantize earlier Andreas Rheinhardt
` (69 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:47 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 4fe9350c40..bbee9a5f61 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -273,7 +273,7 @@ static void gray8(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
}
/* init common dct for both encoder and decoder */
-static av_cold int dct_init(MpegEncContext *s)
+static av_cold void dct_init(MpegEncContext *s)
{
ff_blockdsp_init(&s->bdsp);
ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
@@ -316,8 +316,6 @@ static av_cold int dct_init(MpegEncContext *s)
#elif ARCH_MIPS
ff_mpv_common_init_mips(s);
#endif
-
- return 0;
}
av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 04/57] avcodec/mpegvideo: Set dct_unquantize earlier
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
2024-06-12 13:47 ` [FFmpeg-devel] [PATCH 02/57] avcodec/mpegvideo_enc: Avoid branches for flipping no_rounding Andreas Rheinhardt
2024-06-12 13:47 ` [FFmpeg-devel] [PATCH 03/57] avcodec/mpegvideo: Don't pretend dct_init can fail Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 05/57] avcodec/mpegvideo_dec: Set dct_unquantize ptrs only once when possible Andreas Rheinhardt
` (68 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Set them in ff_mpv_idct_init() so that they are already set
in ff_mpv_decode_init(). This is in preparation for avoiding
to set dct_unquantize in every ff_mpv_frame_start().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 54 +++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index bbee9a5f61..27f7ebf933 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -273,7 +273,7 @@ static void gray8(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
}
/* init common dct for both encoder and decoder */
-static av_cold void dct_init(MpegEncContext *s)
+static av_cold void dsp_init(MpegEncContext *s)
{
ff_blockdsp_init(&s->bdsp);
ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
@@ -291,31 +291,6 @@ static av_cold void dct_init(MpegEncContext *s)
s->hdsp.put_no_rnd_pixels_tab[1][i] = gray8;
}
}
-
- s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
- s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
- 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
- ff_mpv_common_init_neon(s);
-#endif
-
-#if ARCH_ALPHA
- ff_mpv_common_init_axp(s);
-#elif ARCH_ARM
- ff_mpv_common_init_arm(s);
-#elif ARCH_PPC
- ff_mpv_common_init_ppc(s);
-#elif ARCH_X86
- ff_mpv_common_init_x86(s);
-#elif ARCH_MIPS
- ff_mpv_common_init_mips(s);
-#endif
}
av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
@@ -359,6 +334,31 @@ av_cold void ff_mpv_idct_init(MpegEncContext *s)
s->idsp.idct_permutation);
ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan,
s->idsp.idct_permutation);
+
+ s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
+ s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
+ 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
+ ff_mpv_common_init_neon(s);
+#endif
+
+#if ARCH_ALPHA
+ ff_mpv_common_init_axp(s);
+#elif ARCH_ARM
+ ff_mpv_common_init_arm(s);
+#elif ARCH_PPC
+ ff_mpv_common_init_ppc(s);
+#elif ARCH_X86
+ ff_mpv_common_init_x86(s);
+#elif ARCH_MIPS
+ ff_mpv_common_init_mips(s);
+#endif
}
static int init_duplicate_context(MpegEncContext *s)
@@ -718,7 +718,7 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
av_image_check_size(s->width, s->height, 0, s->avctx))
return AVERROR(EINVAL);
- dct_init(s);
+ dsp_init(s);
/* set chroma shifts */
ret = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 05/57] avcodec/mpegvideo_dec: Set dct_unquantize ptrs only once when possible
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (2 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 04/57] avcodec/mpegvideo: Set dct_unquantize earlier Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 06/57] configure: Remove obsolete mpeg4_decoder->mpeg4video_parser dependency Andreas Rheinhardt
` (67 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything except dct_unquantize_intra for MPEG-4 need only
be set once.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 8 ++++++++
libavcodec/mpegvideo_dec.c | 21 +++++++--------------
2 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index eee7978452..666675fcf1 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -110,6 +110,9 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
break;
case AV_CODEC_ID_MPEG4:
+ // dct_unquantize_inter is only used with MPEG-2 quantizers,
+ // so we can already set dct_unquantize_inter here once and for all.
+ s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
break;
case AV_CODEC_ID_MSMPEG4V1:
s->h263_pred = 1;
@@ -523,6 +526,11 @@ retry:
goto retry;
if (s->studio_profile != (s->idsp.idct == NULL))
ff_mpv_idct_init(s);
+ if (s->mpeg_quant) {
+ s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
+ } else {
+ s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
+ }
}
/* After H.263 & MPEG-4 header decode we have the height, width,
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 0a50cfac5b..ad35505819 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -59,6 +59,13 @@ int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
s->codec_tag = ff_toupper4(avctx->codec_tag);
ff_mpv_idct_init(s);
+
+ // dct_unquantize defaults for H.261 and H.263;
+ // they might change on a per-frame basis for MPEG-4.
+ // Unused by the MPEG-1/2 decoders.
+ s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
+ s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
+
ff_h264chroma_init(&s->h264chroma, 8); //for lowres
if (s->picture_pool) // VC-1 can call this multiple times
@@ -393,20 +400,6 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
if (ret < 0)
return ret;
- /* set dequantizer, we can't do it during init as
- * it might change for MPEG-4 and we can't do it in the header
- * decode as init is not called for MPEG-4 there yet */
- if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
- s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
- s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
- } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
- s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
- s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
- } else {
- s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
- s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
- }
-
if (s->avctx->debug & FF_DEBUG_NOMC)
color_frame(s->cur_pic.ptr->f, 0x80);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 06/57] configure: Remove obsolete mpeg4_decoder->mpeg4video_parser dependency
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (3 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 05/57] avcodec/mpegvideo_dec: Set dct_unquantize ptrs only once when possible Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 07/57] avcodec/mpegutils: Remap MB_TYPE_ACPRED, add codec-specific MB_TYPE Andreas Rheinhardt
` (66 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Obsolete since 3ceffe783965767e62d59e8e68ecd265c98460ec.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
configure | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure b/configure
index 83284427df..3525d9991c 100755
--- a/configure
+++ b/configure
@@ -3019,7 +3019,7 @@ mpeg1video_decoder_select="mpegvideodec"
mpeg1video_encoder_select="mpegvideoenc"
mpeg2video_decoder_select="mpegvideodec"
mpeg2video_encoder_select="mpegvideoenc"
-mpeg4_decoder_select="h263_decoder mpeg4video_parser"
+mpeg4_decoder_select="h263_decoder"
mpeg4_encoder_select="h263_encoder qpeldsp"
msa1_decoder_select="mss34dsp"
mscc_decoder_select="inflate_wrapper"
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 07/57] avcodec/mpegutils: Remap MB_TYPE_ACPRED, add codec-specific MB_TYPE
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (4 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 06/57] configure: Remove obsolete mpeg4_decoder->mpeg4video_parser dependency Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 08/57] avcodec/mpegutils: Remap MB_TYPE_{GMC, SKIP, CBP, QUANT} Andreas Rheinhardt
` (65 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
MB_TYPE_ACPRED is currently reused for MB_TYPE_REF0 by H.264,
so that the value fits into an uint16_t. Given that MB_TYPE_ACPRED
is not subject to any such restriction (apart from fitting into
32bits), it can be remapped to a hithereto unused bit.
The then available bit will be declared to be codec-specific
(i.e. unused by generic code), so that H.264 can use it
for MB_TYPE_REF0 and so that it can be reused later for
e.g. MB_TYPE_H261_FIL.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h264_parse.h | 2 +-
libavcodec/mpegutils.c | 2 +-
libavcodec/mpegutils.h | 5 ++++-
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
index 4ee863df66..3481451c10 100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@ -33,7 +33,7 @@
#include "get_bits.h"
#include "h264_ps.h"
-#define MB_TYPE_REF0 MB_TYPE_ACPRED // dirty but it fits in 16 bit
+#define MB_TYPE_REF0 MB_TYPE_CODEC_SPECIFIC
#define MB_TYPE_8x8DCT 0x01000000
// This table must be here because scan8[constant] must be known at compiletime
diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c
index 92ebdd3a98..4b1bcaa995 100644
--- a/libavcodec/mpegutils.c
+++ b/libavcodec/mpegutils.c
@@ -109,7 +109,7 @@ static char get_type_mv_char(int mb_type)
// Type & MV direction
if (IS_PCM(mb_type))
return 'P';
- else if (IS_INTRA(mb_type) && IS_ACPRED(mb_type))
+ else if (IS_ACPRED(mb_type))
return 'A';
else if (IS_INTRA4x4(mb_type))
return 'i';
diff --git a/libavcodec/mpegutils.h b/libavcodec/mpegutils.h
index 3da1e7ed38..0cca4f0a2f 100644
--- a/libavcodec/mpegutils.h
+++ b/libavcodec/mpegutils.h
@@ -45,7 +45,6 @@
#define MB_TYPE_8x8 (1 << 6)
#define MB_TYPE_INTERLACED (1 << 7)
#define MB_TYPE_DIRECT2 (1 << 8) // FIXME
-#define MB_TYPE_ACPRED (1 << 9)
#define MB_TYPE_GMC (1 << 10)
#define MB_TYPE_SKIP (1 << 11)
#define MB_TYPE_P0L0 (1 << 12)
@@ -57,9 +56,13 @@
#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
#define MB_TYPE_QUANT (1 << 16)
#define MB_TYPE_CBP (1 << 17)
+#define MB_TYPE_ACPRED (1 << 18)
#define MB_TYPE_INTRA MB_TYPE_INTRA4x4 // default mb_type if there is just one type
+// The following MB-type can be used by each codec as it sees fit.
+#define MB_TYPE_CODEC_SPECIFIC (1 << 9)
+
#define IS_INTRA4x4(a) ((a) & MB_TYPE_INTRA4x4)
#define IS_INTRA16x16(a) ((a) & MB_TYPE_INTRA16x16)
#define IS_PCM(a) ((a) & MB_TYPE_INTRA_PCM)
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 08/57] avcodec/mpegutils: Remap MB_TYPE_{GMC, SKIP, CBP, QUANT}
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (5 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 07/57] avcodec/mpegutils: Remap MB_TYPE_ACPRED, add codec-specific MB_TYPE Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 09/57] avcodec/h261dec: Use VLC symbol table Andreas Rheinhardt
` (64 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Do this to make MB_TYPE_{CBP,QUANT} fit into an int16_t,
so that can be used in a VLC symbol table.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegutils.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mpegutils.h b/libavcodec/mpegutils.h
index 0cca4f0a2f..8597ca18b8 100644
--- a/libavcodec/mpegutils.h
+++ b/libavcodec/mpegutils.h
@@ -45,8 +45,8 @@
#define MB_TYPE_8x8 (1 << 6)
#define MB_TYPE_INTERLACED (1 << 7)
#define MB_TYPE_DIRECT2 (1 << 8) // FIXME
-#define MB_TYPE_GMC (1 << 10)
-#define MB_TYPE_SKIP (1 << 11)
+#define MB_TYPE_CBP (1 << 10)
+#define MB_TYPE_QUANT (1 << 11)
#define MB_TYPE_P0L0 (1 << 12)
#define MB_TYPE_P1L0 (1 << 13)
#define MB_TYPE_P0L1 (1 << 14)
@@ -54,8 +54,8 @@
#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
-#define MB_TYPE_QUANT (1 << 16)
-#define MB_TYPE_CBP (1 << 17)
+#define MB_TYPE_GMC (1 << 16)
+#define MB_TYPE_SKIP (1 << 17)
#define MB_TYPE_ACPRED (1 << 18)
#define MB_TYPE_INTRA MB_TYPE_INTRA4x4 // default mb_type if there is just one type
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 09/57] avcodec/h261dec: Use VLC symbol table
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (6 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 08/57] avcodec/mpegutils: Remap MB_TYPE_{GMC, SKIP, CBP, QUANT} Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 10/57] avcodec/h261dec: Remove nonsense information from error message Andreas Rheinhardt
` (63 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible now that MB_TYPE_CBP and MB_TYPE_QUANT
fit into an int16_t; only MB_TYPE_H261_FIL needs to
be remapped to MB_TYPE_CODEC_SPECIFIC.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261.h | 5 +++--
libavcodec/h261data.c | 2 +-
libavcodec/h261dec.c | 9 ++++-----
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/libavcodec/h261.h b/libavcodec/h261.h
index 67c362be93..11a8a8685a 100644
--- a/libavcodec/h261.h
+++ b/libavcodec/h261.h
@@ -28,6 +28,7 @@
#ifndef AVCODEC_H261_H
#define AVCODEC_H261_H
+#include "mpegutils.h"
#include "mpegvideo.h"
#include "rl.h"
@@ -38,13 +39,13 @@ typedef struct H261Context {
int mtype;
} H261Context;
-#define MB_TYPE_H261_FIL 0x800000
+#define MB_TYPE_H261_FIL MB_TYPE_CODEC_SPECIFIC
extern const uint8_t ff_h261_mba_code[35];
extern const uint8_t ff_h261_mba_bits[35];
extern const uint8_t ff_h261_mtype_code[10];
extern const uint8_t ff_h261_mtype_bits[10];
-extern const int ff_h261_mtype_map[10];
+extern const uint16_t ff_h261_mtype_map[10];
extern const uint8_t ff_h261_mv_tab[17][2];
extern const uint8_t ff_h261_cbp_tab[63][2];
extern RLTable ff_h261_rl_tcoeff;
diff --git a/libavcodec/h261data.c b/libavcodec/h261data.c
index a9891edd0a..bccd9e5f56 100644
--- a/libavcodec/h261data.c
+++ b/libavcodec/h261data.c
@@ -72,7 +72,7 @@ const uint8_t ff_h261_mtype_bits[10] = {
2, 6
};
-const int ff_h261_mtype_map[10] = {
+const uint16_t ff_h261_mtype_map[10] = {
MB_TYPE_INTRA4x4,
MB_TYPE_INTRA4x4 | MB_TYPE_QUANT,
MB_TYPE_CBP,
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 392f1aef1d..05279b9ec5 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -67,9 +67,10 @@ static av_cold void h261_decode_init_static(void)
VLC_INIT_STATIC_TABLE(h261_mba_vlc, H261_MBA_VLC_BITS, 35,
ff_h261_mba_bits, 1, 1,
ff_h261_mba_code, 1, 1, 0);
- VLC_INIT_STATIC_TABLE(h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
- ff_h261_mtype_bits, 1, 1,
- ff_h261_mtype_code, 1, 1, 0);
+ VLC_INIT_STATIC_SPARSE_TABLE(h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
+ ff_h261_mtype_bits, 1, 1,
+ ff_h261_mtype_code, 1, 1,
+ ff_h261_mtype_map, 2, 2, 0);
VLC_INIT_STATIC_TABLE(h261_mv_vlc, H261_MV_VLC_BITS, 17,
&ff_h261_mv_tab[0][1], 2, 1,
&ff_h261_mv_tab[0][0], 2, 1, 0);
@@ -418,8 +419,6 @@ static int h261_decode_mb(H261DecContext *h)
com->mtype);
return SLICE_ERROR;
}
- av_assert0(com->mtype < FF_ARRAY_ELEMS(ff_h261_mtype_map));
- com->mtype = ff_h261_mtype_map[com->mtype];
// Read mquant
if (IS_QUANT(com->mtype))
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 10/57] avcodec/h261dec: Remove nonsense information from error message
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (7 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 09/57] avcodec/h261dec: Use VLC symbol table Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 11/57] avcodec/mpegutils: Remove always-false check Andreas Rheinhardt
` (62 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The "invalid mtype index" here is always -1, because that is
the value the VLC api uses for not existent leafs in an incomplete tree.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 05279b9ec5..b62575b7b3 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -415,8 +415,7 @@ static int h261_decode_mb(H261DecContext *h)
// Read mtype
com->mtype = get_vlc2(&s->gb, h261_mtype_vlc, H261_MTYPE_VLC_BITS, 2);
if (com->mtype < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
- com->mtype);
+ av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index\n");
return SLICE_ERROR;
}
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 11/57] avcodec/mpegutils: Remove always-false check
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (8 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 10/57] avcodec/h261dec: Remove nonsense information from error message Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 12/57] avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideo Andreas Rheinhardt
` (61 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
SVQ3 does not call ff_print_debug_info2().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegutils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c
index 4b1bcaa995..acc4989aba 100644
--- a/libavcodec/mpegutils.c
+++ b/libavcodec/mpegutils.c
@@ -165,7 +165,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
if ((avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) && mbtype_table && motion_val[0]) {
const int shift = 1 + quarter_sample;
const int scale = 1 << shift;
- const int mv_sample_log2 = avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_SVQ3 ? 2 : 1;
+ const int mv_sample_log2 = avctx->codec_id == AV_CODEC_ID_H264 ? 2 : 1;
const int mv_stride = (mb_width << mv_sample_log2) +
(avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1);
int mb_x, mb_y, mbcount = 0;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 12/57] avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideo
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (9 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 11/57] avcodec/mpegutils: Remove always-false check Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-13 8:23 ` Michael Niedermayer
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 13/57] avcodec/mpegutils: Move H.264-only macros to h264dec.h Andreas Rheinhardt
` (60 subsequent siblings)
71 siblings, 1 reply; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
MB_TYPE_L[01] is based upon H.264 terminology (it stands for
list); yet the mpegvideo based decoders don't have lists
of reference frames, they have at most one forward and one
backward reference. So use terminology based upon this.
This also has a second advantage: MB_TYPE_L[01] is actually
an OR of two flags (which are set independently for H.264,
but aren't for mpegvideo). Switching to different flags
makes the flags fit into an int16_t, which will be useful
in future commits.
The only downside to this is a very small amount of code
in error_resilience.c and mpegutils.c (the only code shared
between the H.264 decoder and mpegvideo).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/error_resilience.c | 8 +++---
libavcodec/h261dec.c | 4 +--
libavcodec/ituh263dec.c | 44 ++++++++++++++---------------
libavcodec/ituh263enc.c | 4 +--
libavcodec/mpeg12dec.c | 44 ++++++++++++++---------------
libavcodec/mpeg4video.c | 6 ++--
libavcodec/mpeg4videodec.c | 53 +++++++++++++++++------------------
libavcodec/mpegutils.c | 23 +++++++++------
libavcodec/mpegutils.h | 10 +++++++
libavcodec/msmpeg4dec.c | 8 +++---
libavcodec/rv34.c | 18 ++++++------
libavcodec/wmv2dec.c | 12 ++++----
12 files changed, 123 insertions(+), 111 deletions(-)
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index 56844d5084..6edc2dc15f 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -902,6 +902,7 @@ void ff_er_frame_end(ERContext *s, int *decode_error_flags)
int threshold = 50;
int is_intra_likely;
int size = s->b8_stride * 2 * s->mb_height;
+ int guessed_mb_type;
/* We do not support ER of field pictures yet,
* though it should not crash if enabled. */
@@ -1117,16 +1118,15 @@ void ff_er_frame_end(ERContext *s, int *decode_error_flags)
is_intra_likely = is_intra_more_likely(s);
/* set unknown mb-type to most likely */
+ guessed_mb_type = is_intra_likely ? MB_TYPE_INTRA4x4 :
+ (MB_TYPE_16x16 | (s->avctx->codec_id == AV_CODEC_ID_H264 ? MB_TYPE_L0 : MB_TYPE_FORWARD_MV));
for (i = 0; i < s->mb_num; i++) {
const int mb_xy = s->mb_index2xy[i];
int error = s->error_status_table[mb_xy];
if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR)))
continue;
- if (is_intra_likely)
- s->cur_pic.mb_type[mb_xy] = MB_TYPE_INTRA4x4;
- else
- s->cur_pic.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0;
+ s->cur_pic.mb_type[mb_xy] = guessed_mb_type;
}
// change inter to intra blocks if no reference frames are available
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index b62575b7b3..be285ce5e9 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -232,7 +232,7 @@ static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2)
s->mv_dir = MV_DIR_FORWARD;
s->mv_type = MV_TYPE_16X16;
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
s->mb_skipped = 1;
@@ -460,7 +460,7 @@ static int h261_decode_mb(H261DecContext *h)
//set motion vectors
s->mv_dir = MV_DIR_FORWARD;
s->mv_type = MV_TYPE_16X16;
- s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
s->mv[0][0][0] = h->current_mv_x * 2; // gets divided by 2 in motion compensation
s->mv[0][0][1] = h->current_mv_y * 2;
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 0809048362..47ad891391 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -60,18 +60,18 @@
#define CBPC_B_VLC_BITS 3
static const int h263_mb_type_b_map[15]= {
- MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
- MB_TYPE_DIRECT2 | MB_TYPE_L0L1 | MB_TYPE_CBP,
- MB_TYPE_DIRECT2 | MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_QUANT,
- MB_TYPE_L0 | MB_TYPE_16x16,
- MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_16x16,
- MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
- MB_TYPE_L1 | MB_TYPE_16x16,
- MB_TYPE_L1 | MB_TYPE_CBP | MB_TYPE_16x16,
- MB_TYPE_L1 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
- MB_TYPE_L0L1 | MB_TYPE_16x16,
- MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_16x16,
- MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
+ MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV,
+ MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV | MB_TYPE_CBP,
+ MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV | MB_TYPE_CBP | MB_TYPE_QUANT,
+ MB_TYPE_FORWARD_MV | MB_TYPE_16x16,
+ MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_16x16,
+ MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
+ MB_TYPE_BACKWARD_MV | MB_TYPE_16x16,
+ MB_TYPE_BACKWARD_MV | MB_TYPE_CBP | MB_TYPE_16x16,
+ MB_TYPE_BACKWARD_MV | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
+ MB_TYPE_BIDIR_MV | MB_TYPE_16x16,
+ MB_TYPE_BIDIR_MV | MB_TYPE_CBP | MB_TYPE_16x16,
+ MB_TYPE_BIDIR_MV | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
0, //stuffing
MB_TYPE_INTRA4x4 | MB_TYPE_CBP,
MB_TYPE_INTRA4x4 | MB_TYPE_CBP | MB_TYPE_QUANT,
@@ -363,7 +363,7 @@ static void preview_obmc(MpegEncContext *s){
mot_val[1 ]= mot_val[3 ]=
mot_val[1+stride]= mot_val[3+stride]= 0;
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
goto end;
}
cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
@@ -382,7 +382,7 @@ static void preview_obmc(MpegEncContext *s){
}
if ((cbpc & 16) == 0) {
- s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
/* 16x16 motion prediction */
mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
if (s->umvplus)
@@ -400,7 +400,7 @@ static void preview_obmc(MpegEncContext *s){
mot_val[1 ]= mot_val[3 ]=
mot_val[1+stride]= mot_val[3+stride]= my;
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
for(i=0;i<4;i++) {
mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
if (s->umvplus)
@@ -763,7 +763,7 @@ static int set_direct_mv(MpegEncContext *s)
s->mv_type = MV_TYPE_8X8;
for (i = 0; i < 4; i++)
set_one_direct_mv(s, p, i);
- return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1;
+ return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_BIDIR_MV;
} else {
set_one_direct_mv(s, p, 0);
s->mv[0][1][0] =
@@ -780,7 +780,7 @@ static int set_direct_mv(MpegEncContext *s)
s->mv[1][3][1] = s->mv[1][0][1];
s->mv_type = MV_TYPE_8X8;
// Note see prev line
- return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1;
+ return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_BIDIR_MV;
}
}
@@ -803,7 +803,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->block_last_index[i] = -1;
s->mv_dir = MV_DIR_FORWARD;
s->mv_type = MV_TYPE_16X16;
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
s->mb_skipped = !(s->obmc | s->loop_filter);
@@ -841,7 +841,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->mv_dir = MV_DIR_FORWARD;
if ((cbpc & 16) == 0) {
- s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
/* 16x16 motion prediction */
s->mv_type = MV_TYPE_16X16;
ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
@@ -866,7 +866,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
s->mv_type = MV_TYPE_8X8;
for(i=0;i<4;i++) {
mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
@@ -952,7 +952,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->mv_type= MV_TYPE_16X16;
//FIXME UMV
- if(USES_LIST(mb_type, 0)){
+ if (HAS_FORWARD_MV(mb_type)) {
int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
s->mv_dir = MV_DIR_FORWARD;
@@ -979,7 +979,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
}
- if(USES_LIST(mb_type, 1)){
+ if (HAS_BACKWARD_MV(mb_type)) {
int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &pred_x, &pred_y);
s->mv_dir |= MV_DIR_BACKWARD;
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index db8003c242..8d0c4147bf 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -697,11 +697,11 @@ void ff_h263_update_mb(MpegEncContext *s)
s->cur_pic.mbskip_table[mb_xy] = s->mb_skipped;
if (s->mv_type == MV_TYPE_8X8)
- s->cur_pic.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_8x8;
+ s->cur_pic.mb_type[mb_xy] = MB_TYPE_FORWARD_MV | MB_TYPE_8x8;
else if(s->mb_intra)
s->cur_pic.mb_type[mb_xy] = MB_TYPE_INTRA;
else
- s->cur_pic.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_16x16;
+ s->cur_pic.mb_type[mb_xy] = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
ff_h263_update_motion_val(s);
}
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 8bb0932a13..601106138e 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -97,26 +97,26 @@ typedef struct Mpeg1Context {
static const uint32_t ptype2mb_type[7] = {
MB_TYPE_INTRA,
- MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
- MB_TYPE_L0,
- MB_TYPE_L0 | MB_TYPE_CBP,
+ MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+ MB_TYPE_FORWARD_MV,
+ MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_INTRA,
- MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
- MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+ MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
};
static const uint32_t btype2mb_type[11] = {
MB_TYPE_INTRA,
- MB_TYPE_L1,
- MB_TYPE_L1 | MB_TYPE_CBP,
- MB_TYPE_L0,
- MB_TYPE_L0 | MB_TYPE_CBP,
- MB_TYPE_L0L1,
- MB_TYPE_L0L1 | MB_TYPE_CBP,
+ MB_TYPE_BACKWARD_MV,
+ MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
+ MB_TYPE_FORWARD_MV,
+ MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
+ MB_TYPE_BIDIR_MV,
+ MB_TYPE_BIDIR_MV | MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_INTRA,
- MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_BIDIR_MV | MB_TYPE_CBP,
};
/* as H.263, but only 17 codes */
@@ -438,7 +438,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
if (s->pict_type == AV_PICTURE_TYPE_P) {
s->mb_skipped = 1;
s->cur_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride] =
- MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
+ MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
} else {
int mb_type;
@@ -579,7 +579,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
} else {
- av_assert2(mb_type & MB_TYPE_L0L1);
+ av_assert2(mb_type & MB_TYPE_BIDIR_MV);
// FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED
/* get additional motion vector type */
if (s->picture_structure == PICT_FRAME && s->frame_pred_frame_dct) {
@@ -594,7 +594,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
s->qscale = mpeg_get_qscale(s);
/* motion vectors */
- s->mv_dir = (mb_type >> 13) & 3;
+ s->mv_dir = MB_TYPE_MV_2_MV_DIR(mb_type);
ff_tlog(s->avctx, "motion_type=%d\n", motion_type);
switch (motion_type) {
case MT_FRAME: /* or MT_16X8 */
@@ -602,7 +602,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
mb_type |= MB_TYPE_16x16;
s->mv_type = MV_TYPE_16X16;
for (i = 0; i < 2; i++) {
- if (USES_LIST(mb_type, i)) {
+ if (HAS_MV(mb_type, i)) {
/* MT_FRAME */
s->mv[i][0][0] =
s->last_mv[i][0][0] =
@@ -625,7 +625,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
s->mv_type = MV_TYPE_16X8;
for (i = 0; i < 2; i++) {
- if (USES_LIST(mb_type, i)) {
+ if (HAS_MV(mb_type, i)) {
/* MT_16X8 */
for (j = 0; j < 2; j++) {
s->field_select[i][j] = get_bits1(&s->gb);
@@ -645,7 +645,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
if (s->picture_structure == PICT_FRAME) {
mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
for (i = 0; i < 2; i++) {
- if (USES_LIST(mb_type, i)) {
+ if (HAS_MV(mb_type, i)) {
for (j = 0; j < 2; j++) {
s->field_select[i][j] = get_bits1(&s->gb);
val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
@@ -665,7 +665,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
av_assert0(!s->progressive_sequence);
mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
for (i = 0; i < 2; i++) {
- if (USES_LIST(mb_type, i)) {
+ if (HAS_MV(mb_type, i)) {
s->field_select[i][0] = get_bits1(&s->gb);
for (k = 0; k < 2; k++) {
val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
@@ -685,7 +685,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
}
s->mv_type = MV_TYPE_DMV;
for (i = 0; i < 2; i++) {
- if (USES_LIST(mb_type, i)) {
+ if (HAS_MV(mb_type, i)) {
int dmx, dmy, mx, my, m;
const int my_shift = s->picture_structure == PICT_FRAME;
diff --git a/libavcodec/mpeg4video.c b/libavcodec/mpeg4video.c
index 7bbd412aa8..3133cc22c4 100644
--- a/libavcodec/mpeg4video.c
+++ b/libavcodec/mpeg4video.c
@@ -141,7 +141,7 @@ int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
s->mv_type = MV_TYPE_8X8;
for (i = 0; i < 4; i++)
ff_mpeg4_set_one_direct_mv(s, mx, my, i);
- return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1;
+ return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_BIDIR_MV;
} else if (IS_INTERLACED(colocated_mb_type)) {
s->mv_type = MV_TYPE_FIELD;
for (i = 0; i < 2; i++) {
@@ -169,7 +169,7 @@ int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
(time_pb - time_pp) / time_pp;
}
return MB_TYPE_DIRECT2 | MB_TYPE_16x8 |
- MB_TYPE_L0L1 | MB_TYPE_INTERLACED;
+ MB_TYPE_BIDIR_MV | MB_TYPE_INTERLACED;
} else {
ff_mpeg4_set_one_direct_mv(s, mx, my, 0);
s->mv[0][1][0] =
@@ -190,6 +190,6 @@ int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my)
else
s->mv_type = MV_TYPE_8X8;
// Note see prev line
- return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1;
+ return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_BIDIR_MV;
}
}
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 81f05bbb28..ebbd845129 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -68,10 +68,10 @@ static VLCElem studio_chroma_dc[528];
static const uint8_t mpeg4_block_count[4] = { 0, 6, 8, 12 };
static const int mb_type_b_map[4] = {
- MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
- MB_TYPE_L0L1 | MB_TYPE_16x16,
- MB_TYPE_L1 | MB_TYPE_16x16,
- MB_TYPE_L0 | MB_TYPE_16x16,
+ MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV,
+ MB_TYPE_BIDIR_MV | MB_TYPE_16x16,
+ MB_TYPE_BACKWARD_MV | MB_TYPE_16x16,
+ MB_TYPE_FORWARD_MV | MB_TYPE_16x16,
};
static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
@@ -1010,13 +1010,13 @@ try_again:
s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
MB_TYPE_16x16 |
MB_TYPE_GMC |
- MB_TYPE_L0;
+ MB_TYPE_FORWARD_MV;
mx = get_amv(ctx, 0);
my = get_amv(ctx, 1);
} else {
s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
MB_TYPE_16x16 |
- MB_TYPE_L0;
+ MB_TYPE_FORWARD_MV;
mx = my = 0;
}
mot_val[0] =
@@ -1081,13 +1081,13 @@ try_again:
if (my >= 0xffff)
return AVERROR_INVALIDDATA;
s->cur_pic.mb_type[xy] = MB_TYPE_16x16 |
- MB_TYPE_L0;
+ MB_TYPE_FORWARD_MV;
} else {
mx = get_amv(ctx, 0);
my = get_amv(ctx, 1);
s->cur_pic.mb_type[xy] = MB_TYPE_16x16 |
MB_TYPE_GMC |
- MB_TYPE_L0;
+ MB_TYPE_FORWARD_MV;
}
mot_val[0] =
@@ -1101,7 +1101,7 @@ try_again:
} else {
int i;
s->cur_pic.mb_type[xy] = MB_TYPE_8x8 |
- MB_TYPE_L0;
+ MB_TYPE_FORWARD_MV;
for (i = 0; i < 4; i++) {
int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
mx = ff_h263_decode_motion(s, pred_x, s->f_code);
@@ -1675,16 +1675,15 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
MB_TYPE_GMC |
MB_TYPE_16x16 |
- MB_TYPE_L0;
+ MB_TYPE_FORWARD_MV;
s->mcsel = 1;
s->mv[0][0][0] = get_amv(ctx, 0);
s->mv[0][0][1] = get_amv(ctx, 1);
s->cur_pic.mbskip_table[xy] = 0;
s->mb_skipped = 0;
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
- MB_TYPE_16x16 |
- MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 |
+ MB_TYPE_FORWARD_MV;
s->mcsel = 0;
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
@@ -1729,9 +1728,8 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv_dir = MV_DIR_FORWARD;
if ((cbpc & 16) == 0) {
if (s->mcsel) {
- s->cur_pic.mb_type[xy] = MB_TYPE_GMC |
- MB_TYPE_16x16 |
- MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 |
+ MB_TYPE_FORWARD_MV;
/* 16x16 global motion prediction */
s->mv_type = MV_TYPE_16X16;
mx = get_amv(ctx, 0);
@@ -1739,8 +1737,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv[0][0][0] = mx;
s->mv[0][0][1] = my;
} else if ((!s->progressive_sequence) && get_bits1(&s->gb)) {
- s->cur_pic.mb_type[xy] = MB_TYPE_16x8 |
- MB_TYPE_L0 |
+ s->cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV |
MB_TYPE_INTERLACED;
/* 16x8 field motion prediction */
s->mv_type = MV_TYPE_FIELD;
@@ -1763,7 +1760,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv[0][i][1] = my;
}
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
/* 16x16 motion prediction */
s->mv_type = MV_TYPE_16X16;
ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
@@ -1780,7 +1777,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv[0][0][1] = my;
}
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
+ s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
s->mv_type = MV_TYPE_8X8;
for (i = 0; i < 4; i++) {
int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
@@ -1832,14 +1829,14 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv[1][0][1] = 0;
s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
MB_TYPE_16x16 |
- MB_TYPE_L0;
+ MB_TYPE_FORWARD_MV;
goto end;
}
modb1 = get_bits1(&s->gb);
if (modb1) {
// like MB_TYPE_B_DIRECT but no vectors coded
- mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1;
+ mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV;
cbp = 0;
} else {
modb2 = get_bits1(&s->gb);
@@ -1869,11 +1866,11 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
mb_type &= ~MB_TYPE_16x16;
- if (USES_LIST(mb_type, 0)) {
+ if (HAS_FORWARD_MV(mb_type)) {
s->field_select[0][0] = get_bits1(&s->gb);
s->field_select[0][1] = get_bits1(&s->gb);
}
- if (USES_LIST(mb_type, 1)) {
+ if (HAS_BACKWARD_MV(mb_type)) {
s->field_select[1][0] = get_bits1(&s->gb);
s->field_select[1][1] = get_bits1(&s->gb);
}
@@ -1884,7 +1881,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) {
s->mv_type = MV_TYPE_16X16;
- if (USES_LIST(mb_type, 0)) {
+ if (HAS_FORWARD_MV(mb_type)) {
s->mv_dir = MV_DIR_FORWARD;
mx = ff_h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);
@@ -1897,7 +1894,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv[0][0][1] = my;
}
- if (USES_LIST(mb_type, 1)) {
+ if (HAS_BACKWARD_MV(mb_type)) {
s->mv_dir |= MV_DIR_BACKWARD;
mx = ff_h263_decode_motion(s, s->last_mv[1][0][0], s->b_code);
@@ -1912,7 +1909,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
} else if (!IS_DIRECT(mb_type)) {
s->mv_type = MV_TYPE_FIELD;
- if (USES_LIST(mb_type, 0)) {
+ if (HAS_FORWARD_MV(mb_type)) {
s->mv_dir = MV_DIR_FORWARD;
for (i = 0; i < 2; i++) {
@@ -1924,7 +1921,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
}
}
- if (USES_LIST(mb_type, 1)) {
+ if (HAS_BACKWARD_MV(mb_type)) {
s->mv_dir |= MV_DIR_BACKWARD;
for (i = 0; i < 2; i++) {
diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c
index acc4989aba..a567165fd9 100644
--- a/libavcodec/mpegutils.c
+++ b/libavcodec/mpegutils.c
@@ -104,7 +104,9 @@ void ff_draw_horiz_band(AVCodecContext *avctx,
y, picture_structure, h);
}
-static char get_type_mv_char(int mb_type)
+#define HAS_MV_EXT(mb_type, flags, dir) ((mb_type) & flags[(dir)])
+
+static char get_type_mv_char(int mb_type, const int mb_type_mv_flags[2])
{
// Type & MV direction
if (IS_PCM(mb_type))
@@ -125,12 +127,12 @@ static char get_type_mv_char(int mb_type)
return 'G';
else if (IS_SKIP(mb_type))
return 'S';
- else if (!USES_LIST(mb_type, 1))
+ else if (!HAS_MV_EXT(mb_type, 1, mb_type_mv_flags))
return '>';
- else if (!USES_LIST(mb_type, 0))
+ else if (!HAS_MV_EXT(mb_type, 0, mb_type_mv_flags))
return '<';
else {
- av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
+ av_assert2(HAS_MV_EXT(mb_type, 0, mb_type_mv_flags) && HAS_MV_EXT(mb_type, 1, mb_type_mv_flags));
return 'X';
}
}
@@ -162,12 +164,15 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
const int8_t *qscale_table, int16_t (*const motion_val[2])[2],
int mb_width, int mb_height, int mb_stride, int quarter_sample)
{
+ const int is_h264 = avctx->codec_id == AV_CODEC_ID_H264;
+ const int mb_type_mv_flags[2] = { is_h264 ? MB_TYPE_L0 : MB_TYPE_FORWARD_MV,
+ is_h264 ? MB_TYPE_L1 : MB_TYPE_BACKWARD_MV };
+
if ((avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) && mbtype_table && motion_val[0]) {
const int shift = 1 + quarter_sample;
const int scale = 1 << shift;
- const int mv_sample_log2 = avctx->codec_id == AV_CODEC_ID_H264 ? 2 : 1;
- const int mv_stride = (mb_width << mv_sample_log2) +
- (avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1);
+ const int mv_sample_log2 = is_h264 ? 2 : 1;
+ const int mv_stride = (mb_width << mv_sample_log2) + !is_h264;
int mb_x, mb_y, mbcount = 0;
/* size is width * height * 2 * 4 where 2 is for directions and 4 is
@@ -180,7 +185,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
for (mb_x = 0; mb_x < mb_width; mb_x++) {
int i, direction, mb_type = mbtype_table[mb_x + mb_y * mb_stride];
for (direction = 0; direction < 2; direction++) {
- if (!USES_LIST(mb_type, direction))
+ if (!HAS_MV_EXT(mb_type, direction, mb_type_mv_flags))
continue;
if (IS_8X8(mb_type)) {
for (i = 0; i < 4; i++) {
@@ -299,7 +304,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
int mb_type = mbtype_table[x + y * mb_stride];
av_bprintf(&buf, "%c%c%c",
- get_type_mv_char(mb_type),
+ get_type_mv_char(mb_type, mb_type_mv_flags),
get_segmentation_char(mb_type),
get_interlacement_char(mb_type));
}
diff --git a/libavcodec/mpegutils.h b/libavcodec/mpegutils.h
index 8597ca18b8..c58a14d497 100644
--- a/libavcodec/mpegutils.h
+++ b/libavcodec/mpegutils.h
@@ -47,6 +47,10 @@
#define MB_TYPE_DIRECT2 (1 << 8) // FIXME
#define MB_TYPE_CBP (1 << 10)
#define MB_TYPE_QUANT (1 << 11)
+#define MB_TYPE_FORWARD_MV (1 << 12)
+#define MB_TYPE_BACKWARD_MV (1 << 13)
+#define MB_TYPE_BIDIR_MV (MB_TYPE_FORWARD_MV | MB_TYPE_BACKWARD_MV)
+// MB_TYPE_P[01]L[01], MB_TYPE_L[01] and MB_TYPE_L0L1 are H.264 only.
#define MB_TYPE_P0L0 (1 << 12)
#define MB_TYPE_P1L0 (1 << 13)
#define MB_TYPE_P0L1 (1 << 14)
@@ -90,6 +94,12 @@
#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0 | MB_TYPE_P1L0) << (2 * (list))))
#define HAS_CBP(a) ((a) & MB_TYPE_CBP)
+#define HAS_FORWARD_MV(a) ((a) & MB_TYPE_FORWARD_MV)
+#define HAS_BACKWARD_MV(a) ((a) & MB_TYPE_BACKWARD_MV)
+// dir == 0 means forward, dir == 1 is backward
+#define HAS_MV(a, dir) ((a) & (MB_TYPE_FORWARD_MV << (dir)))
+
+#define MB_TYPE_MV_2_MV_DIR(a) (((a) >> 12) & 3)
/**
* Draw a horizontal band if supported.
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 209e1fe1b2..31b17c2839 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -120,7 +120,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
s->mb_skipped = 1;
- *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
+ *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
return 0;
}
}
@@ -170,7 +170,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv_type = MV_TYPE_16X16;
s->mv[0][0][0] = mx;
s->mv[0][0][1] = my;
- *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
+ *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
} else {
int v;
if (s->msmpeg4_version == MSMP4_V2) {
@@ -226,7 +226,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
s->mb_skipped = 1;
- *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
+ *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
return 0;
}
@@ -265,7 +265,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mv_type = MV_TYPE_16X16;
s->mv[0][0][0] = mx;
s->mv[0][0][1] = my;
- *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
+ *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
} else {
ff_dlog(s, "I at %d %d %d %06X\n", s->mb_x, s->mb_y,
((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 728e117df4..d94285431e 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -59,16 +59,16 @@ static inline void ZERO8x2(void* dst, int stride)
static const int rv34_mb_type_to_lavc[12] = {
MB_TYPE_INTRA,
MB_TYPE_INTRA16x16 | MB_TYPE_SEPARATE_DC,
- MB_TYPE_16x16 | MB_TYPE_L0,
- MB_TYPE_8x8 | MB_TYPE_L0,
- MB_TYPE_16x16 | MB_TYPE_L0,
- MB_TYPE_16x16 | MB_TYPE_L1,
+ MB_TYPE_16x16 | MB_TYPE_FORWARD_MV,
+ MB_TYPE_8x8 | MB_TYPE_FORWARD_MV,
+ MB_TYPE_16x16 | MB_TYPE_FORWARD_MV,
+ MB_TYPE_16x16 | MB_TYPE_BACKWARD_MV,
MB_TYPE_SKIP,
MB_TYPE_DIRECT2 | MB_TYPE_16x16,
- MB_TYPE_16x8 | MB_TYPE_L0,
- MB_TYPE_8x16 | MB_TYPE_L0,
- MB_TYPE_16x16 | MB_TYPE_L0L1,
- MB_TYPE_16x16 | MB_TYPE_L0 | MB_TYPE_SEPARATE_DC
+ MB_TYPE_16x8 | MB_TYPE_FORWARD_MV,
+ MB_TYPE_8x16 | MB_TYPE_FORWARD_MV,
+ MB_TYPE_16x16 | MB_TYPE_BIDIR_MV,
+ MB_TYPE_16x16 | MB_TYPE_FORWARD_MV | MB_TYPE_SEPARATE_DC
};
@@ -568,7 +568,7 @@ static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir)
int mx, my;
int i, j;
MPVWorkPicture *cur_pic = &s->cur_pic;
- const int mask = dir ? MB_TYPE_L1 : MB_TYPE_L0;
+ const int mask = dir ? MB_TYPE_BACKWARD_MV : MB_TYPE_FORWARD_MV;
int type = cur_pic->mb_type[mb_pos];
if((r->avail_cache[6-1] & type) & mask){
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 5c91006169..677467ccc2 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -112,7 +112,7 @@ static int parse_mb_skip(WMV2DecContext *w)
for (mb_y = 0; mb_y < s->mb_height; mb_y++)
for (mb_x = 0; mb_x < s->mb_width; mb_x++)
mb_type[mb_y * s->mb_stride + mb_x] =
- MB_TYPE_16x16 | MB_TYPE_L0;
+ MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
break;
case SKIP_TYPE_MPEG:
if (get_bits_left(&s->gb) < s->mb_height * s->mb_width)
@@ -120,7 +120,7 @@ static int parse_mb_skip(WMV2DecContext *w)
for (mb_y = 0; mb_y < s->mb_height; mb_y++)
for (mb_x = 0; mb_x < s->mb_width; mb_x++)
mb_type[mb_y * s->mb_stride + mb_x] =
- (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
+ (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
break;
case SKIP_TYPE_ROW:
for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
@@ -129,11 +129,11 @@ static int parse_mb_skip(WMV2DecContext *w)
if (get_bits1(&s->gb)) {
for (mb_x = 0; mb_x < s->mb_width; mb_x++)
mb_type[mb_y * s->mb_stride + mb_x] =
- MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
} else {
for (mb_x = 0; mb_x < s->mb_width; mb_x++)
mb_type[mb_y * s->mb_stride + mb_x] =
- (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
+ (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
}
}
break;
@@ -144,11 +144,11 @@ static int parse_mb_skip(WMV2DecContext *w)
if (get_bits1(&s->gb)) {
for (mb_y = 0; mb_y < s->mb_height; mb_y++)
mb_type[mb_y * s->mb_stride + mb_x] =
- MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
+ MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
} else {
for (mb_y = 0; mb_y < s->mb_height; mb_y++)
mb_type[mb_y * s->mb_stride + mb_x] =
- (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
+ (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
}
}
break;
--
2.40.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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 12/57] avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideo
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 12/57] avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideo Andreas Rheinhardt
@ 2024-06-13 8:23 ` Michael Niedermayer
2024-06-13 8:49 ` Andreas Rheinhardt
0 siblings, 1 reply; 87+ messages in thread
From: Michael Niedermayer @ 2024-06-13 8:23 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1348 bytes --]
On Wed, Jun 12, 2024 at 03:48:08PM +0200, Andreas Rheinhardt wrote:
> MB_TYPE_L[01] is based upon H.264 terminology (it stands for
> list); yet the mpegvideo based decoders don't have lists
> of reference frames, they have at most one forward and one
> backward reference. So use terminology based upon this.
>
> This also has a second advantage: MB_TYPE_L[01] is actually
> an OR of two flags (which are set independently for H.264,
> but aren't for mpegvideo). Switching to different flags
> makes the flags fit into an int16_t, which will be useful
> in future commits.
>
> The only downside to this is a very small amount of code
> in error_resilience.c and mpegutils.c (the only code shared
> between the H.264 decoder and mpegvideo).
Cant you just call the flags differently but leave them nummerically
the same, if you dont like L0L1 terminology ?
Having each codec be different does not seem to me to be a good thing
It adds burden to every bit of common code. It may be thats error_resilience
ATM, but there are other things people may want to add, like an universal
encoder for all the block based transform + MC formats
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 12/57] avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideo
2024-06-13 8:23 ` Michael Niedermayer
@ 2024-06-13 8:49 ` Andreas Rheinhardt
2024-06-13 9:56 ` Michael Niedermayer
0 siblings, 1 reply; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-13 8:49 UTC (permalink / raw)
To: ffmpeg-devel
Michael Niedermayer:
> On Wed, Jun 12, 2024 at 03:48:08PM +0200, Andreas Rheinhardt wrote:
>> MB_TYPE_L[01] is based upon H.264 terminology (it stands for
>> list); yet the mpegvideo based decoders don't have lists
>> of reference frames, they have at most one forward and one
>> backward reference. So use terminology based upon this.
>>
>> This also has a second advantage: MB_TYPE_L[01] is actually
>> an OR of two flags (which are set independently for H.264,
>> but aren't for mpegvideo). Switching to different flags
>> makes the flags fit into an int16_t, which will be useful
>> in future commits.
>>
>> The only downside to this is a very small amount of code
>> in error_resilience.c and mpegutils.c (the only code shared
>> between the H.264 decoder and mpegvideo).
>
> Cant you just call the flags differently but leave them nummerically
> the same, if you dont like L0L1 terminology ?
>
> Having each codec be different does not seem to me to be a good thing
> It adds burden to every bit of common code. It may be thats error_resilience
> ATM, but there are other things people may want to add, like an universal
> encoder for all the block based transform + MC formats
1. The terminology is only one part of this: Using the same flags
currently adds a burden to the mpegvideo-decoders, because their
mb_types don't fit into an int16_t, so that they can't use symbols
tables. See the following patches for this.
2. Furthermore, it is not "each codec" that has its own system of
defines; it is only H.264 vs. the rest. And even these two systems are
mostly the same.
3. If you create a universal encoder, then you'd be better off to use
your own MB_TYPE_ defines for it and not to reuse this system here. In
fact, mpegvideoenc does not really use it (it uses its
CANDIDATE_MB_TYPE_* system).
4. And I don't think that a "universal" encoder is even a desirable
idea. An in-tree H.264 encoder would be very complex and all encoders
would benefit if it were not tied to the other encoders. Apart from
that, x264 is a thing.
- 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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 12/57] avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideo
2024-06-13 8:49 ` Andreas Rheinhardt
@ 2024-06-13 9:56 ` Michael Niedermayer
0 siblings, 0 replies; 87+ messages in thread
From: Michael Niedermayer @ 2024-06-13 9:56 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2829 bytes --]
On Thu, Jun 13, 2024 at 10:49:15AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Wed, Jun 12, 2024 at 03:48:08PM +0200, Andreas Rheinhardt wrote:
> >> MB_TYPE_L[01] is based upon H.264 terminology (it stands for
> >> list); yet the mpegvideo based decoders don't have lists
> >> of reference frames, they have at most one forward and one
> >> backward reference. So use terminology based upon this.
> >>
> >> This also has a second advantage: MB_TYPE_L[01] is actually
> >> an OR of two flags (which are set independently for H.264,
> >> but aren't for mpegvideo). Switching to different flags
> >> makes the flags fit into an int16_t, which will be useful
> >> in future commits.
> >>
> >> The only downside to this is a very small amount of code
> >> in error_resilience.c and mpegutils.c (the only code shared
> >> between the H.264 decoder and mpegvideo).
> >
> > Cant you just call the flags differently but leave them nummerically
> > the same, if you dont like L0L1 terminology ?
> >
> > Having each codec be different does not seem to me to be a good thing
> > It adds burden to every bit of common code. It may be thats error_resilience
> > ATM, but there are other things people may want to add, like an universal
> > encoder for all the block based transform + MC formats
>
> 1. The terminology is only one part of this: Using the same flags
> currently adds a burden to the mpegvideo-decoders, because their
> mb_types don't fit into an int16_t, so that they can't use symbols
> tables. See the following patches for this.
> 2. Furthermore, it is not "each codec" that has its own system of
> defines; it is only H.264 vs. the rest. And even these two systems are
> mostly the same.
> 3. If you create a universal encoder, then you'd be better off to use
> your own MB_TYPE_ defines for it and not to reuse this system here. In
> fact, mpegvideoenc does not really use it (it uses its
> CANDIDATE_MB_TYPE_* system).
> 4. And I don't think that a "universal" encoder is even a desirable
> idea. An in-tree H.264 encoder would be very complex and all encoders
> would benefit if it were not tied to the other encoders. Apart from
> that, x264 is a thing.
iam not talking about h.264, I do think though that extending the concept
of our mpegvideo encoder which happily encodes from mjpeg, h.261, RV10, RV20
mpeg-1, mpeg-2, mpeg-4, h.263 to WMV1 and WMV2
to some more generic universal encoder that covers the more modern formats
does make sense and is desirable
That said, i guess it doesnt matter if you change the flags, you are probably
correct that they wont be too usefull as they are either ...
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
You can kill me, but you cannot change the truth.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 13/57] avcodec/mpegutils: Move H.264-only macros to h264dec.h
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (10 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 12/57] avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideo Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 14/57] avcodec/mpeg4videodec: Use VLC symbol table Andreas Rheinhardt
` (59 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h264dec.h | 8 ++++++++
libavcodec/mpegutils.h | 8 --------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index fc50df90f2..ccd7583bf4 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -93,6 +93,14 @@
#define IS_REF0(a) ((a) & MB_TYPE_REF0)
#define IS_8x8DCT(a) ((a) & MB_TYPE_8x8DCT)
+#define IS_SUB_8X8(a) ((a) & MB_TYPE_16x16) // note reused
+#define IS_SUB_8X4(a) ((a) & MB_TYPE_16x8) // note reused
+#define IS_SUB_4X8(a) ((a) & MB_TYPE_8x16) // note reused
+#define IS_SUB_4X4(a) ((a) & MB_TYPE_8x8) // note reused
+#define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0 << ((part) + 2 * (list))))
+
+// does this mb use listX, note does not work if subMBs
+#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0 | MB_TYPE_P1L0) << (2 * (list))))
/**
* Memory management control operation.
diff --git a/libavcodec/mpegutils.h b/libavcodec/mpegutils.h
index c58a14d497..43075191c6 100644
--- a/libavcodec/mpegutils.h
+++ b/libavcodec/mpegutils.h
@@ -82,16 +82,8 @@
#define IS_16X8(a) ((a) & MB_TYPE_16x8)
#define IS_8X16(a) ((a) & MB_TYPE_8x16)
#define IS_8X8(a) ((a) & MB_TYPE_8x8)
-#define IS_SUB_8X8(a) ((a) & MB_TYPE_16x16) // note reused
-#define IS_SUB_8X4(a) ((a) & MB_TYPE_16x8) // note reused
-#define IS_SUB_4X8(a) ((a) & MB_TYPE_8x16) // note reused
-#define IS_SUB_4X4(a) ((a) & MB_TYPE_8x8) // note reused
#define IS_ACPRED(a) ((a) & MB_TYPE_ACPRED)
#define IS_QUANT(a) ((a) & MB_TYPE_QUANT)
-#define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0 << ((part) + 2 * (list))))
-
-// does this mb use listX, note does not work if subMBs
-#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0 | MB_TYPE_P1L0) << (2 * (list))))
#define HAS_CBP(a) ((a) & MB_TYPE_CBP)
#define HAS_FORWARD_MV(a) ((a) & MB_TYPE_FORWARD_MV)
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 14/57] avcodec/mpeg4videodec: Use VLC symbol table
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (11 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 13/57] avcodec/mpegutils: Move H.264-only macros to h264dec.h Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 15/57] avcodec/mpeg12dec: " Andreas Rheinhardt
` (58 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Possible now that MB_TYPE_L1 (which does not fit into
an int16_t) is no longer used).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videodec.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index ebbd845129..116dc1507e 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -67,7 +67,7 @@ static VLCElem studio_chroma_dc[528];
static const uint8_t mpeg4_block_count[4] = { 0, 6, 8, 12 };
-static const int mb_type_b_map[4] = {
+static const int16_t mb_type_b_map[4] = {
MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV,
MB_TYPE_BIDIR_MV | MB_TYPE_16x16,
MB_TYPE_BACKWARD_MV | MB_TYPE_16x16,
@@ -1845,7 +1845,6 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n");
return AVERROR_INVALIDDATA;
}
- mb_type = mb_type_b_map[mb_type];
if (modb2) {
cbp = 0;
} else {
@@ -3794,9 +3793,10 @@ static av_cold void mpeg4_init_static(void)
VLC_INIT_STATIC_TABLE_FROM_LENGTHS(sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
ff_sprite_trajectory_lens, 1,
NULL, 0, 0, 0, 0);
- VLC_INIT_STATIC_TABLE(mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
- &ff_mb_type_b_tab[0][1], 2, 1,
- &ff_mb_type_b_tab[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_SPARSE_TABLE(mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
+ &ff_mb_type_b_tab[0][1], 2, 1,
+ &ff_mb_type_b_tab[0][0], 2, 1,
+ mb_type_b_map, 2, 2, 0);
}
static av_cold int decode_init(AVCodecContext *avctx)
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 15/57] avcodec/mpeg12dec: Use VLC symbol table
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (12 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 14/57] avcodec/mpeg4videodec: Use VLC symbol table Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 16/57] avcodec/ituh263dec: " Andreas Rheinhardt
` (57 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Possible by using MB_TYPE_CODEC_SPECIFIC for MB_TYPE_ZERO_MV
and due to the MB_TYPE_*_MV flags fitting into an int16_t.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12.c | 42 +++++++++++++++++++++++++++++++++---------
libavcodec/mpeg12dec.c | 28 ----------------------------
libavcodec/mpeg12dec.h | 2 ++
3 files changed, 35 insertions(+), 37 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 62d7fd1814..444ea83f3c 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -31,14 +31,12 @@
#include "libavutil/avassert.h"
#include "libavutil/thread.h"
-#include "avcodec.h"
#include "mpegvideo.h"
-#include "mpeg12.h"
#include "mpeg12codecs.h"
#include "mpeg12data.h"
#include "mpeg12dec.h"
+#include "mpegutils.h"
#include "rl.h"
-#include "startcode.h"
static const uint8_t table_mb_ptype[7][2] = {
{ 3, 5 }, // 0x01 MB_INTRA
@@ -64,6 +62,30 @@ static const uint8_t table_mb_btype[11][2] = {
{ 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT
};
+static const int16_t ptype2mb_type[7] = {
+ MB_TYPE_INTRA,
+ MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+ MB_TYPE_FORWARD_MV,
+ MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_INTRA,
+ MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+ MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
+};
+
+static const int16_t btype2mb_type[11] = {
+ MB_TYPE_INTRA,
+ MB_TYPE_BACKWARD_MV,
+ MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
+ MB_TYPE_FORWARD_MV,
+ MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
+ MB_TYPE_BIDIR_MV,
+ MB_TYPE_BIDIR_MV | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_INTRA,
+ MB_TYPE_QUANT | MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_BIDIR_MV | MB_TYPE_CBP,
+};
+
av_cold void ff_init_2d_vlc_rl(const uint16_t table_vlc[][2], RL_VLC_ELEM rl_vlc[],
const int8_t table_run[], const uint8_t table_level[],
int n, unsigned static_size, int flags)
@@ -146,12 +168,14 @@ static av_cold void mpeg12_init_vlcs(void)
&ff_mpeg12_mbPatTable[0][1], 2, 1,
&ff_mpeg12_mbPatTable[0][0], 2, 1, 0);
- VLC_INIT_STATIC_TABLE(ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
- &table_mb_ptype[0][1], 2, 1,
- &table_mb_ptype[0][0], 2, 1, 0);
- VLC_INIT_STATIC_TABLE(ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
- &table_mb_btype[0][1], 2, 1,
- &table_mb_btype[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_SPARSE_TABLE(ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
+ &table_mb_ptype[0][1], 2, 1,
+ &table_mb_ptype[0][0], 2, 1,
+ ptype2mb_type, 2, 2, 0);
+ VLC_INIT_STATIC_SPARSE_TABLE(ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
+ &table_mb_btype[0][1], 2, 1,
+ &table_mb_btype[0][0], 2, 1,
+ btype2mb_type, 2, 2, 0);
ff_init_2d_vlc_rl(ff_mpeg1_vlc_table, ff_mpeg1_rl_vlc, ff_mpeg12_run,
ff_mpeg12_level, MPEG12_RL_NB_ELEMS,
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 601106138e..e0e9a8fb1e 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -93,32 +93,6 @@ typedef struct Mpeg1Context {
int64_t timecode_frame_start; /*< GOP timecode frame start number, in non drop frame format */
} Mpeg1Context;
-#define MB_TYPE_ZERO_MV 0x20000000
-
-static const uint32_t ptype2mb_type[7] = {
- MB_TYPE_INTRA,
- MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
- MB_TYPE_FORWARD_MV,
- MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_INTRA,
- MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
- MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
-};
-
-static const uint32_t btype2mb_type[11] = {
- MB_TYPE_INTRA,
- MB_TYPE_BACKWARD_MV,
- MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
- MB_TYPE_FORWARD_MV,
- MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
- MB_TYPE_BIDIR_MV,
- MB_TYPE_BIDIR_MV | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_INTRA,
- MB_TYPE_QUANT | MB_TYPE_BACKWARD_MV | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_FORWARD_MV | MB_TYPE_CBP,
- MB_TYPE_QUANT | MB_TYPE_BIDIR_MV | MB_TYPE_CBP,
-};
-
/* as H.263, but only 17 codes */
static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
{
@@ -483,7 +457,6 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
"Invalid mb type in P-frame at %d %d\n", s->mb_x, s->mb_y);
return AVERROR_INVALIDDATA;
}
- mb_type = ptype2mb_type[mb_type];
break;
case AV_PICTURE_TYPE_B:
mb_type = get_vlc2(&s->gb, ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 1);
@@ -492,7 +465,6 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
"Invalid mb type in B-frame at %d %d\n", s->mb_x, s->mb_y);
return AVERROR_INVALIDDATA;
}
- mb_type = btype2mb_type[mb_type];
break;
}
ff_tlog(s->avctx, "mb_type=%x\n", mb_type);
diff --git a/libavcodec/mpeg12dec.h b/libavcodec/mpeg12dec.h
index 4641179149..79809b7c3e 100644
--- a/libavcodec/mpeg12dec.h
+++ b/libavcodec/mpeg12dec.h
@@ -25,6 +25,8 @@
#include "get_bits.h"
#include "mpeg12vlc.h"
+#define MB_TYPE_ZERO_MV MB_TYPE_CODEC_SPECIFIC
+
static inline int decode_dc(GetBitContext *gb, int component)
{
int code, diff;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 16/57] avcodec/ituh263dec: Use VLC symbol table
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (13 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 15/57] avcodec/mpeg12dec: " Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 17/57] avcodec/mpegvideo_enc: Avoid excessive inlining Andreas Rheinhardt
` (56 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263dec.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 47ad891391..e0f3034e57 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -59,7 +59,7 @@
#define H263_MBTYPE_B_VLC_BITS 6
#define CBPC_B_VLC_BITS 3
-static const int h263_mb_type_b_map[15]= {
+static const int16_t h263_mb_type_b_map[15]= {
MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV,
MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV | MB_TYPE_CBP,
MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV | MB_TYPE_CBP | MB_TYPE_QUANT,
@@ -125,9 +125,10 @@ static av_cold void h263_decode_init_vlc(void)
ff_h263_init_rl_inter();
VLC_INIT_RL(ff_h263_rl_inter, 554);
INIT_FIRST_VLC_RL(ff_rl_intra_aic, 554);
- VLC_INIT_STATIC_TABLE(h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
- &ff_h263_mbtype_b_tab[0][1], 2, 1,
- &ff_h263_mbtype_b_tab[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_SPARSE_TABLE(h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
+ &ff_h263_mbtype_b_tab[0][1], 2, 1,
+ &ff_h263_mbtype_b_tab[0][0], 2, 1,
+ h263_mb_type_b_map, 2, 2, 0);
VLC_INIT_STATIC_TABLE(cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
&ff_cbpc_b_tab[0][1], 2, 1,
&ff_cbpc_b_tab[0][0], 2, 1, 0);
@@ -911,8 +912,6 @@ int ff_h263_decode_mb(MpegEncContext *s,
av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
return SLICE_ERROR;
}
-
- mb_type= h263_mb_type_b_map[ mb_type ];
}while(!mb_type);
s->mb_intra = IS_INTRA(mb_type);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 17/57] avcodec/mpegvideo_enc: Avoid excessive inlining
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (14 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 16/57] avcodec/ituh263dec: " Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 18/57] avcodec/mpegvideo_enc: Check for existence of ildct cmp functions Andreas Rheinhardt
` (55 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6ad5b0eb39..11f2a72804 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2484,7 +2484,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
}
}
-static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
+static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
{
if (s->chroma_format == CHROMA_420)
encode_mb_internal(s, motion_x, motion_y, 8, 8, 6, 1, 1, CHROMA_420);
@@ -2559,9 +2559,9 @@ static inline void copy_context_after_encode(MpegEncContext *d,
d->esc3_level_length= s->esc3_level_length;
}
-static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best,
- PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2],
- int *dmin, int *next_block, int motion_x, int motion_y)
+static void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best,
+ PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2],
+ int *dmin, int *next_block, int motion_x, int motion_y)
{
int score;
uint8_t *dest_backup[3];
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 18/57] avcodec/mpegvideo_enc: Check for existence of ildct cmp functions
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (15 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 17/57] avcodec/mpegvideo_enc: Avoid excessive inlining Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 19/57] avcodec/dvenc: Check for availability of interlaced dct cmp func Andreas Rheinhardt
` (54 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Not all compare functions are implemented for all compare function
types. Therefore check for the existence of the used functions.
Fixes issue #10245.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 11f2a72804..c97120de21 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -910,8 +910,14 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->quant_precision = 5;
- ret = ff_set_cmp(&s->mecc, s->mecc.ildct_cmp, avctx->ildct_cmp);
- ret |= ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, s->frame_skip_cmp);
+ if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
+ ret = ff_set_cmp(&s->mecc, s->mecc.ildct_cmp, avctx->ildct_cmp);
+ if (ret < 0)
+ return ret;
+ if (!s->mecc.ildct_cmp[0] || !s->mecc.ildct_cmp[4])
+ return AVERROR(EINVAL);
+ }
+ ret = ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, s->frame_skip_cmp);
if (ret < 0)
return AVERROR(EINVAL);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 19/57] avcodec/dvenc: Check for availability of interlaced dct cmp func
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (16 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 18/57] avcodec/mpegvideo_enc: Check for existence of ildct cmp functions Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 20/57] avcodec/motion_est: Factor one-time initialization out of ff_init_me Andreas Rheinhardt
` (53 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Not every type of comparison function implements every function.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/dvenc.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 3afeedbb87..08ed53d823 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -70,7 +70,6 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
{
DVEncContext *s = avctx->priv_data;
FDCTDSPContext fdsp;
- MECmpContext mecc;
PixblockDSPContext pdsp;
int ret;
@@ -95,19 +94,24 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
ff_dv_init_dynamic_tables(s->work_chunks, s->sys);
+ if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
+ MECmpContext mecc;
+
+ memset(&mecc,0, sizeof(mecc));
+ ff_me_cmp_init(&mecc, avctx);
+ ret = ff_set_cmp(&mecc, mecc.ildct_cmp, avctx->ildct_cmp);
+ if (ret < 0)
+ return ret;
+ if (!mecc.ildct_cmp[5])
+ return AVERROR(EINVAL);
+ s->ildct_cmp = mecc.ildct_cmp[5];
+ }
+
memset(&fdsp,0, sizeof(fdsp));
- memset(&mecc,0, sizeof(mecc));
memset(&pdsp,0, sizeof(pdsp));
ff_fdctdsp_init(&fdsp, avctx);
- ff_me_cmp_init(&mecc, avctx);
ff_pixblockdsp_init(&pdsp, avctx);
- ret = ff_set_cmp(&mecc, mecc.ildct_cmp, avctx->ildct_cmp);
- if (ret < 0)
- return AVERROR(EINVAL);
-
s->get_pixels = pdsp.get_pixels;
- s->ildct_cmp = mecc.ildct_cmp[5];
-
s->fdct[0] = fdsp.fdct;
s->fdct[1] = fdsp.fdct248;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 20/57] avcodec/motion_est: Factor one-time initialization out of ff_init_me
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (17 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 19/57] avcodec/dvenc: Check for availability of interlaced dct cmp func Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 21/57] avcodec/me_cmp: Constify ff_set_cmp() Andreas Rheinhardt
` (52 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The majority of the stuff performed in it needs to be done only
once; so factor it out into a function of its own to be called
in the user's init function.
Also avoid using MpegEncContext in it, to separate the two
a bit more.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/motion_est.c | 89 ++++++++++++++++++++------------------
libavcodec/motion_est.h | 9 +++-
libavcodec/mpegvideo_enc.c | 19 ++++++--
libavcodec/snowenc.c | 11 ++---
libavcodec/svq1enc.c | 5 ++-
5 files changed, 80 insertions(+), 53 deletions(-)
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index 162472d693..ee28a4a445 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -305,45 +305,40 @@ static int zero_cmp(MpegEncContext *s, const uint8_t *a, const uint8_t *b,
static void zero_hpel(uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h){
}
-int ff_init_me(MpegEncContext *s){
- MotionEstContext * const c= &s->me;
- int cache_size= FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT);
- int dia_size= FFMAX(FFABS(s->avctx->dia_size)&255, FFABS(s->avctx->pre_dia_size)&255);
+av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, MECmpContext *mecc)
+{
+ int cache_size = FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT);
+ int dia_size = FFMAX(FFABS(avctx->dia_size) & 255, FFABS(avctx->pre_dia_size) & 255);
int ret;
- if(FFMIN(s->avctx->dia_size, s->avctx->pre_dia_size) < -FFMIN(ME_MAP_SIZE, MAX_SAB_SIZE)){
- av_log(s->avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n");
- return -1;
+ if (FFMIN(avctx->dia_size, avctx->pre_dia_size) < -FFMIN(ME_MAP_SIZE, MAX_SAB_SIZE)) {
+ av_log(avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n");
+ return AVERROR(EINVAL);
}
- c->avctx= s->avctx;
+ c->avctx = avctx;
- if(s->codec_id == AV_CODEC_ID_H261)
- c->avctx->me_sub_cmp = c->avctx->me_cmp;
+ if (avctx->codec_id == AV_CODEC_ID_H261)
+ avctx->me_sub_cmp = avctx->me_cmp;
- if(cache_size < 2*dia_size && !c->stride){
- av_log(s->avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n");
- }
+ if (cache_size < 2 * dia_size)
+ av_log(avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n");
- ret = ff_set_cmp(&s->mecc, s->mecc.me_pre_cmp, c->avctx->me_pre_cmp);
- ret |= ff_set_cmp(&s->mecc, s->mecc.me_cmp, c->avctx->me_cmp);
- ret |= ff_set_cmp(&s->mecc, s->mecc.me_sub_cmp, c->avctx->me_sub_cmp);
- ret |= ff_set_cmp(&s->mecc, s->mecc.mb_cmp, c->avctx->mb_cmp);
+ ret = ff_set_cmp(mecc, mecc->me_pre_cmp, avctx->me_pre_cmp);
+ ret |= ff_set_cmp(mecc, mecc->me_cmp, avctx->me_cmp);
+ ret |= ff_set_cmp(mecc, mecc->me_sub_cmp, avctx->me_sub_cmp);
+ ret |= ff_set_cmp(mecc, mecc->mb_cmp, avctx->mb_cmp);
if (ret < 0)
return ret;
- c->flags = get_flags(c, 0, c->avctx->me_cmp &FF_CMP_CHROMA);
- c->sub_flags= get_flags(c, 0, c->avctx->me_sub_cmp&FF_CMP_CHROMA);
- c->mb_flags = get_flags(c, 0, c->avctx->mb_cmp &FF_CMP_CHROMA);
+ c->flags = get_flags(c, 0, avctx->me_cmp & FF_CMP_CHROMA);
+ c->sub_flags = get_flags(c, 0, avctx->me_sub_cmp & FF_CMP_CHROMA);
+ c->mb_flags = get_flags(c, 0, avctx->mb_cmp & FF_CMP_CHROMA);
-/*FIXME s->no_rounding b_type*/
- if (s->avctx->flags & AV_CODEC_FLAG_QPEL) {
+ if (avctx->codec_id == AV_CODEC_ID_H261) {
+ c->sub_motion_search = no_sub_motion_search;
+ } else if (avctx->flags & AV_CODEC_FLAG_QPEL) {
c->sub_motion_search= qpel_motion_search;
- c->qpel_avg = s->qdsp.avg_qpel_pixels_tab;
- if (s->no_rounding)
- c->qpel_put = s->qdsp.put_no_rnd_qpel_pixels_tab;
- else
- c->qpel_put = s->qdsp.put_qpel_pixels_tab;
}else{
if(c->avctx->me_sub_cmp&FF_CMP_CHROMA)
c->sub_motion_search= hpel_motion_search;
@@ -354,6 +349,32 @@ int ff_init_me(MpegEncContext *s){
else
c->sub_motion_search= hpel_motion_search;
}
+
+ /* 8x8 fullpel search would need a 4x4 chroma compare, which we do
+ * not have yet, and even if we had, the motion estimation code
+ * does not expect it. */
+ if (avctx->codec_id != AV_CODEC_ID_SNOW) {
+ if ((avctx->me_cmp & FF_CMP_CHROMA) /* && !s->mecc.me_cmp[2] */)
+ mecc->me_cmp[2] = zero_cmp;
+ if ((avctx->me_sub_cmp & FF_CMP_CHROMA) && !mecc->me_sub_cmp[2])
+ mecc->me_sub_cmp[2] = zero_cmp;
+ }
+
+ return 0;
+}
+
+void ff_me_init_pic(MpegEncContext *s)
+{
+ MotionEstContext * const c= &s->me;
+
+/*FIXME s->no_rounding b_type*/
+ if (s->avctx->flags & AV_CODEC_FLAG_QPEL) {
+ c->qpel_avg = s->qdsp.avg_qpel_pixels_tab;
+ if (s->no_rounding)
+ c->qpel_put = s->qdsp.put_no_rnd_qpel_pixels_tab;
+ else
+ c->qpel_put = s->qdsp.put_qpel_pixels_tab;
+ }
c->hpel_avg = s->hdsp.avg_pixels_tab;
if (s->no_rounding)
c->hpel_put = s->hdsp.put_no_rnd_pixels_tab;
@@ -367,24 +388,10 @@ int ff_init_me(MpegEncContext *s){
c->stride = 16*s->mb_width + 32;
c->uvstride= 8*s->mb_width + 16;
}
-
- /* 8x8 fullpel search would need a 4x4 chroma compare, which we do
- * not have yet, and even if we had, the motion estimation code
- * does not expect it. */
if (s->codec_id != AV_CODEC_ID_SNOW) {
- if ((c->avctx->me_cmp & FF_CMP_CHROMA) /* && !s->mecc.me_cmp[2] */)
- s->mecc.me_cmp[2] = zero_cmp;
- if ((c->avctx->me_sub_cmp & FF_CMP_CHROMA) && !s->mecc.me_sub_cmp[2])
- s->mecc.me_sub_cmp[2] = zero_cmp;
c->hpel_put[2][0]= c->hpel_put[2][1]=
c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel;
}
-
- if(s->codec_id == AV_CODEC_ID_H261){
- c->sub_motion_search= no_sub_motion_search;
- }
-
- return 0;
}
#define CHECK_SAD_HALF_MV(suffix, x, y) \
diff --git a/libavcodec/motion_est.h b/libavcodec/motion_est.h
index f6a563b08c..feea9a473b 100644
--- a/libavcodec/motion_est.h
+++ b/libavcodec/motion_est.h
@@ -25,6 +25,7 @@
#include "avcodec.h"
#include "hpeldsp.h"
+#include "me_cmp.h"
#include "qpeldsp.h"
struct MpegEncContext;
@@ -105,7 +106,13 @@ static inline int ff_h263_round_chroma(int x)
return h263_chroma_roundtab[x & 0xf] + (x >> 3);
}
-int ff_init_me(struct MpegEncContext *s);
+/**
+ * Performs one-time initialization of the MotionEstContext.
+ */
+int ff_me_init(MotionEstContext *c, struct AVCodecContext *avctx,
+ struct MECmpContext *mecc);
+
+void ff_me_init_pic(struct MpegEncContext *s);
void ff_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
void ff_estimate_b_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index c97120de21..5b8d877935 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -306,6 +306,18 @@ av_cold void ff_dct_encode_init(MpegEncContext *s)
s->dct_quantize = dct_quantize_trellis_c;
}
+static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
+{
+ int ret;
+
+ ff_me_cmp_init(&s->mecc, avctx);
+ ret = ff_me_init(&s->me, avctx, &s->mecc);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
/* init video encoder */
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
{
@@ -810,9 +822,11 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
return ret;
ff_fdctdsp_init(&s->fdsp, avctx);
- ff_me_cmp_init(&s->mecc, avctx);
ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
ff_pixblockdsp_init(&s->pdsp, avctx);
+ ret = me_cmp_init(s, avctx);
+ if (ret < 0)
+ return ret;
if (!(avctx->stats_out = av_mallocz(256)) ||
!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix, 32) ||
@@ -3603,8 +3617,7 @@ static int encode_picture(MpegEncContext *s, const AVPacket *pkt)
s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
}
- if(ff_init_me(s)<0)
- return -1;
+ ff_me_init_pic(s);
s->mb_intra=0; //for the rate distortion & bit compare functions
for (int i = 0; i < context_count; i++) {
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 8d6dabae65..f3c78cfb21 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -217,6 +217,9 @@ static av_cold int encode_init(AVCodecContext *avctx)
mcf(12,12)
ff_me_cmp_init(&enc->mecc, avctx);
+ ret = ff_me_init(&enc->m.me, avctx, &enc->mecc);
+ if (ret < 0)
+ return ret;
ff_mpegvideoencdsp_init(&enc->mpvencdsp, avctx);
ff_snow_alloc_blocks(s);
@@ -278,11 +281,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
if (ret)
return ret;
- ret = ff_set_cmp(&enc->mecc, enc->mecc.me_cmp, s->avctx->me_cmp);
- ret |= ff_set_cmp(&enc->mecc, enc->mecc.me_sub_cmp, s->avctx->me_sub_cmp);
- if (ret < 0)
- return AVERROR(EINVAL);
-
s->input_picture = av_frame_alloc();
if (!s->input_picture)
return AVERROR(ENOMEM);
@@ -1874,9 +1872,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
mpv->mecc = enc->mecc; //move
mpv->qdsp = enc->qdsp; //move
mpv->hdsp = s->hdsp;
- ff_init_me(&enc->m);
+ ff_me_init_pic(&enc->m);
s->hdsp = mpv->hdsp;
- enc->mecc = mpv->mecc;
}
if (enc->pass1_rc) {
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 35413b8afd..ceb8bf83c2 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -374,7 +374,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
s->m.p_mv_table = s->motion_val16[plane] +
s->m.mb_stride + 1;
s->m.mecc = s->mecc; // move
- ff_init_me(&s->m);
+ ff_me_init_pic(&s->m);
s->m.me.dia_size = s->avctx->dia_size;
s->m.first_slice_line = 1;
@@ -589,6 +589,9 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
ff_hpeldsp_init(&s->hdsp, avctx->flags);
ff_me_cmp_init(&s->mecc, avctx);
+ ret = ff_me_init(&s->m.me, avctx, &s->mecc);
+ if (ret < 0)
+ return ret;
ff_mpegvideoencdsp_init(&s->m.mpvencdsp, avctx);
s->current_picture = av_frame_alloc();
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 21/57] avcodec/me_cmp: Constify ff_set_cmp()
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (18 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 20/57] avcodec/motion_est: Factor one-time initialization out of ff_init_me Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 22/57] avcodec/me_cmp, motion_est: Move me_(pre_)?_cmp etc. to MotionEstContext Andreas Rheinhardt
` (51 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/me_cmp.c | 2 +-
libavcodec/me_cmp.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/me_cmp.c b/libavcodec/me_cmp.c
index 670103cc05..cff8936e44 100644
--- a/libavcodec/me_cmp.c
+++ b/libavcodec/me_cmp.c
@@ -473,7 +473,7 @@ static int zero_cmp(MpegEncContext *s, const uint8_t *a, const uint8_t *b,
return 0;
}
-int ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
+int ff_set_cmp(const MECmpContext *c, me_cmp_func *cmp, int type)
{
int ret = 0;
int i;
diff --git a/libavcodec/me_cmp.h b/libavcodec/me_cmp.h
index fee0ecb28e..14d19bd142 100644
--- a/libavcodec/me_cmp.h
+++ b/libavcodec/me_cmp.h
@@ -90,7 +90,7 @@ void ff_me_cmp_init_riscv(MECmpContext *c, AVCodecContext *avctx);
void ff_me_cmp_init_x86(MECmpContext *c, AVCodecContext *avctx);
void ff_me_cmp_init_mips(MECmpContext *c, AVCodecContext *avctx);
-int ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type);
+int ff_set_cmp(const MECmpContext *c, me_cmp_func *cmp, int type);
void ff_dsputil_init_dwt(MECmpContext *c);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 22/57] avcodec/me_cmp, motion_est: Move me_(pre_)?_cmp etc. to MotionEstContext
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (19 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 21/57] avcodec/me_cmp: Constify ff_set_cmp() Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 23/57] avcodec/me_cmp, mpegvideo: Move frame_skip_cmp to MpegEncContext Andreas Rheinhardt
` (50 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
MECmpContext has several arrays of function pointers that
are not set by ff_me_cmp_init(), but that are set by users
to one of the other arrays via ff_set_cmp().
One of these other users is the motion estimation API.
It uses MECmpContext.(me_pre|me|me_sub|mb)_cmp. It is
basically the only user of these arrays.
This commit therefore moves these arrays to MotionEstContext;
this has the additional advantage of making motion_est.c
more independent from MpegEncContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/me_cmp.h | 4 ---
libavcodec/motion_est.c | 42 +++++++++++-----------
libavcodec/motion_est.h | 7 +++-
libavcodec/motion_est_template.c | 60 ++++++++++++++++----------------
libavcodec/snowenc.c | 6 ++--
tests/checkasm/motion.c | 4 ---
6 files changed, 60 insertions(+), 63 deletions(-)
diff --git a/libavcodec/me_cmp.h b/libavcodec/me_cmp.h
index 14d19bd142..67e3816829 100644
--- a/libavcodec/me_cmp.h
+++ b/libavcodec/me_cmp.h
@@ -70,10 +70,6 @@ typedef struct MECmpContext {
me_cmp_func dct_max[6];
me_cmp_func dct264_sad[6];
- me_cmp_func me_pre_cmp[6];
- me_cmp_func me_cmp[6];
- me_cmp_func me_sub_cmp[6];
- me_cmp_func mb_cmp[6];
me_cmp_func ildct_cmp[6]; // only width 16 used
me_cmp_func frame_skip_cmp[6]; // only width 8 used
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index ee28a4a445..b29d0c6d96 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -305,7 +305,7 @@ static int zero_cmp(MpegEncContext *s, const uint8_t *a, const uint8_t *b,
static void zero_hpel(uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h){
}
-av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, MECmpContext *mecc)
+av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, const MECmpContext *mecc)
{
int cache_size = FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT);
int dia_size = FFMAX(FFABS(avctx->dia_size) & 255, FFABS(avctx->pre_dia_size) & 255);
@@ -324,10 +324,10 @@ av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, MECmpContext
if (cache_size < 2 * dia_size)
av_log(avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n");
- ret = ff_set_cmp(mecc, mecc->me_pre_cmp, avctx->me_pre_cmp);
- ret |= ff_set_cmp(mecc, mecc->me_cmp, avctx->me_cmp);
- ret |= ff_set_cmp(mecc, mecc->me_sub_cmp, avctx->me_sub_cmp);
- ret |= ff_set_cmp(mecc, mecc->mb_cmp, avctx->mb_cmp);
+ ret = ff_set_cmp(mecc, c->me_pre_cmp, avctx->me_pre_cmp);
+ ret |= ff_set_cmp(mecc, c->me_cmp, avctx->me_cmp);
+ ret |= ff_set_cmp(mecc, c->me_sub_cmp, avctx->me_sub_cmp);
+ ret |= ff_set_cmp(mecc, c->mb_cmp, avctx->mb_cmp);
if (ret < 0)
return ret;
@@ -354,10 +354,10 @@ av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, MECmpContext
* not have yet, and even if we had, the motion estimation code
* does not expect it. */
if (avctx->codec_id != AV_CODEC_ID_SNOW) {
- if ((avctx->me_cmp & FF_CMP_CHROMA) /* && !s->mecc.me_cmp[2] */)
- mecc->me_cmp[2] = zero_cmp;
- if ((avctx->me_sub_cmp & FF_CMP_CHROMA) && !mecc->me_sub_cmp[2])
- mecc->me_sub_cmp[2] = zero_cmp;
+ if ((avctx->me_cmp & FF_CMP_CHROMA) /* && !c->me_cmp[2] */)
+ c->me_cmp[2] = zero_cmp;
+ if ((avctx->me_sub_cmp & FF_CMP_CHROMA) && !c->me_sub_cmp[2])
+ c->me_sub_cmp[2] = zero_cmp;
}
return 0;
@@ -649,7 +649,7 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
dmin4= c->sub_motion_search(s, &mx4, &my4, dmin4, block, block, size, h);
- if (s->mecc.me_sub_cmp[0] != s->mecc.mb_cmp[0]) {
+ if (c->me_sub_cmp[0] != c->mb_cmp[0]) {
int dxy;
const int offset= ((block&1) + (block>>1)*stride)*8;
uint8_t *dest_y = c->scratchpad + offset;
@@ -691,11 +691,11 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
if(same)
return INT_MAX;
- if (s->mecc.me_sub_cmp[0] != s->mecc.mb_cmp[0]) {
- dmin_sum += s->mecc.mb_cmp[0](s,
- s->new_pic->data[0] +
- s->mb_x * 16 + s->mb_y * 16 * stride,
- c->scratchpad, stride, 16);
+ if (c->me_sub_cmp[0] != c->mb_cmp[0]) {
+ dmin_sum += c->mb_cmp[0](s,
+ s->new_pic->data[0] +
+ s->mb_x * 16 + s->mb_y * 16 * stride,
+ c->scratchpad, stride, 16);
}
if(c->avctx->mb_cmp&FF_CMP_CHROMA){
@@ -717,8 +717,8 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
s->hdsp.put_pixels_tab [1][dxy](c->scratchpad + 8, s->last_pic.data[2] + offset, s->uvlinesize, 8);
}
- dmin_sum += s->mecc.mb_cmp[1](s, s->new_pic->data[1] + s->mb_x * 8 + s->mb_y * 8 * s->uvlinesize, c->scratchpad, s->uvlinesize, 8);
- dmin_sum += s->mecc.mb_cmp[1](s, s->new_pic->data[2] + s->mb_x * 8 + s->mb_y * 8 * s->uvlinesize, c->scratchpad + 8, s->uvlinesize, 8);
+ dmin_sum += c->mb_cmp[1](s, s->new_pic->data[1] + s->mb_x * 8 + s->mb_y * 8 * s->uvlinesize, c->scratchpad, s->uvlinesize, 8);
+ dmin_sum += c->mb_cmp[1](s, s->new_pic->data[2] + s->mb_x * 8 + s->mb_y * 8 * s->uvlinesize, c->scratchpad + 8, s->uvlinesize, 8);
}
c->pred_x= mx;
@@ -814,7 +814,7 @@ static int interlaced_search(MpegEncContext *s, int ref_index,
mv_table[xy][0]= mx_i;
mv_table[xy][1]= my_i;
- if (s->mecc.me_sub_cmp[0] != s->mecc.mb_cmp[0]) {
+ if (c->me_sub_cmp[0] != c->mb_cmp[0]) {
int dxy;
//FIXME chroma ME
@@ -826,7 +826,7 @@ static int interlaced_search(MpegEncContext *s, int ref_index,
}else{
s->hdsp.put_pixels_tab [size][dxy](c->scratchpad, ref , stride, h);
}
- dmin = s->mecc.mb_cmp[size](s, c->src[block][0], c->scratchpad, stride, h);
+ dmin = c->mb_cmp[size](s, c->src[block][0], c->scratchpad, stride, h);
dmin+= (mv_penalty[mx_i-c->pred_x] + mv_penalty[my_i-c->pred_y] + 1)*c->mb_penalty_factor;
}else
dmin+= c->mb_penalty_factor; //field_select bits
@@ -1049,7 +1049,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
*(uint32_t*)(&c->scratchpad[i*s->linesize+12]) = mean;
}
- intra_score= s->mecc.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
+ intra_score= c->mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
}
intra_score += c->mb_penalty_factor*16 + s->intra_penalty;
@@ -1236,7 +1236,7 @@ static inline int check_bidir_mv(MpegEncContext * s,
fbmin = (mv_penalty_f[motion_fx-pred_fx] + mv_penalty_f[motion_fy-pred_fy])*c->mb_penalty_factor
+(mv_penalty_b[motion_bx-pred_bx] + mv_penalty_b[motion_by-pred_by])*c->mb_penalty_factor
- + s->mecc.mb_cmp[size](s, src_data[0], dest_y, stride, h); // FIXME new_pic
+ + c->mb_cmp[size](s, src_data[0], dest_y, stride, h); // FIXME new_pic
if(c->avctx->mb_cmp&FF_CMP_CHROMA){
}
diff --git a/libavcodec/motion_est.h b/libavcodec/motion_est.h
index feea9a473b..5547aeb8bc 100644
--- a/libavcodec/motion_est.h
+++ b/libavcodec/motion_est.h
@@ -84,6 +84,11 @@ typedef struct MotionEstContext {
int64_t mb_var_sum_temp;
int scene_change_score;
+ me_cmp_func me_pre_cmp[6];
+ me_cmp_func me_cmp[6];
+ me_cmp_func me_sub_cmp[6];
+ me_cmp_func mb_cmp[6];
+
op_pixels_func(*hpel_put)[4];
op_pixels_func(*hpel_avg)[4];
qpel_mc_func(*qpel_put)[16];
@@ -110,7 +115,7 @@ static inline int ff_h263_round_chroma(int x)
* Performs one-time initialization of the MotionEstContext.
*/
int ff_me_init(MotionEstContext *c, struct AVCodecContext *avctx,
- struct MECmpContext *mecc);
+ const struct MECmpContext *mecc);
void ff_me_init_pic(struct MpegEncContext *s);
diff --git a/libavcodec/motion_est_template.c b/libavcodec/motion_est_template.c
index 1888697db7..b2701aa32e 100644
--- a/libavcodec/motion_est_template.c
+++ b/libavcodec/motion_est_template.c
@@ -64,8 +64,8 @@ static int hpel_motion_search(MpegEncContext * s,
//FIXME factorize
- cmp_sub = s->mecc.me_sub_cmp[size];
- chroma_cmp_sub = s->mecc.me_sub_cmp[size + 1];
+ cmp_sub = c->me_sub_cmp[size];
+ chroma_cmp_sub = c->me_sub_cmp[size + 1];
if(c->skip){ //FIXME move out of hpel?
*mx_ptr = 0;
@@ -178,8 +178,8 @@ static inline int get_mb_score(MpegEncContext *s, int mx, int my,
//FIXME factorize
- cmp_sub = s->mecc.mb_cmp[size];
- chroma_cmp_sub = s->mecc.mb_cmp[size + 1];
+ cmp_sub = c->mb_cmp[size];
+ chroma_cmp_sub = c->mb_cmp[size + 1];
d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
//FIXME check cbp before adding penalty for (0,0) vector
@@ -222,12 +222,12 @@ static int qpel_motion_search(MpegEncContext * s,
LOAD_COMMON
int flags= c->sub_flags;
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1]; // FIXME: factorize
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1]; // FIXME: factorize
//FIXME factorize
- cmp_sub = s->mecc.me_sub_cmp[size];
- chroma_cmp_sub = s->mecc.me_sub_cmp[size + 1];
+ cmp_sub = c->me_sub_cmp[size];
+ chroma_cmp_sub = c->me_sub_cmp[size + 1];
if(c->skip){ //FIXME somehow move up (benchmark)
*mx_ptr = 0;
@@ -424,8 +424,8 @@ static av_always_inline int small_diamond_search(MpegEncContext * s, int *best,
LOAD_COMMON2
unsigned map_generation = c->map_generation;
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
{ /* ensure that the best point is in the MAP as h/qpel refinement needs it */
const unsigned key = ((unsigned)best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
@@ -465,8 +465,8 @@ static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
LOAD_COMMON2
unsigned map_generation = c->map_generation;
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
for(dia_size=1; dia_size<=4; dia_size++){
int dir;
@@ -508,8 +508,8 @@ static int hex_search(MpegEncContext * s, int *best, int dmin,
int x,y,d;
const int dec= dia_size & (dia_size-1);
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
do{
@@ -545,8 +545,8 @@ static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1},
{ 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}};
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
do{
@@ -584,8 +584,8 @@ static int umh_search(MpegEncContext * s, int *best, int dmin,
{-2, 3}, { 0, 4}, { 2, 3},
{-2,-3}, { 0,-4}, { 2,-3},};
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
x= best[0];
y= best[1];
@@ -627,8 +627,8 @@ static int full_search(MpegEncContext * s, int *best, int dmin,
int x,y, d;
const int dia_size= c->dia_size&0xFF;
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
for(y=FFMAX(-dia_size, ymin); y<=FFMIN(dia_size,ymax); y++){
for(x=FFMAX(-dia_size, xmin); x<=FFMIN(dia_size,xmax); x++){
@@ -693,8 +693,8 @@ static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
av_assert1(minima_count <= MAX_SAB_SIZE);
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
/*Note j<MAX_SAB_SIZE is needed if MAX_SAB_SIZE < ME_MAP_SIZE as j can
become larger due to MVs overflowing their ME_MAP_MV_BITS bits space in map
@@ -779,8 +779,8 @@ static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
LOAD_COMMON2
unsigned map_generation = c->map_generation;
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
for(dia_size=1; dia_size<=c->dia_size; dia_size++){
int dir, start, end;
@@ -880,12 +880,12 @@ static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int
if(c->pre_pass){
penalty_factor= c->pre_penalty_factor;
- cmpf = s->mecc.me_pre_cmp[size];
- chroma_cmpf = s->mecc.me_pre_cmp[size + 1];
+ cmpf = c->me_pre_cmp[size];
+ chroma_cmpf = c->me_pre_cmp[size + 1];
}else{
penalty_factor= c->penalty_factor;
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
}
map_generation= update_map_generation(c);
@@ -1008,8 +1008,8 @@ static int epzs_motion_search2(MpegEncContext * s,
int flags= c->flags;
LOAD_COMMON2
- cmpf = s->mecc.me_cmp[size];
- chroma_cmpf = s->mecc.me_cmp[size + 1];
+ cmpf = c->me_cmp[size];
+ chroma_cmpf = c->me_cmp[size + 1];
map_generation= update_map_generation(c);
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index f3c78cfb21..9d64b1efe2 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -832,12 +832,12 @@ static int get_block_rd(SnowEncContext *enc, int mb_x, int mb_y,
distortion = 0;
for(i=0; i<4; i++){
int off = sx+16*(i&1) + (sy+16*(i>>1))*ref_stride;
- distortion += enc->mecc.me_cmp[0](&enc->m, src + off, dst + off, ref_stride, 16);
+ distortion += enc->m.me.me_cmp[0](&enc->m, src + off, dst + off, ref_stride, 16);
}
}
}else{
av_assert2(block_w==8);
- distortion = enc->mecc.me_cmp[0](&enc->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2);
+ distortion = enc->m.me.me_cmp[0](&enc->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2);
}
if(plane_index==0){
@@ -903,7 +903,7 @@ static int get_4block_rd(SnowEncContext *enc, int mb_x, int mb_y, int plane_inde
}
av_assert1(block_w== 8 || block_w==16);
- distortion += enc->mecc.me_cmp[block_w==8](&enc->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_h);
+ distortion += enc->m.me.me_cmp[block_w==8](&enc->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_h);
}
if(plane_index==0){
diff --git a/tests/checkasm/motion.c b/tests/checkasm/motion.c
index e7a36bbbda..2bf49afc77 100644
--- a/tests/checkasm/motion.c
+++ b/tests/checkasm/motion.c
@@ -94,10 +94,6 @@ static void test_motion(const char *name, me_cmp_func test_func)
XX(vsad) \
XX(vsse) \
XX(nsse) \
- XX(me_pre_cmp) \
- XX(me_cmp) \
- XX(me_sub_cmp) \
- XX(mb_cmp) \
XX(ildct_cmp) \
XX(frame_skip_cmp) \
XX(median_sad)
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 23/57] avcodec/me_cmp, mpegvideo: Move frame_skip_cmp to MpegEncContext
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (20 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 22/57] avcodec/me_cmp, motion_est: Move me_(pre_)?_cmp etc. to MotionEstContext Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 24/57] avcodec/me_cmp, dvenc, mpegvideo: Move ildct_cmp to its users Andreas Rheinhardt
` (49 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
MECmpContext has several arrays of function pointers that
are not set by ff_me_cmp_init(), but that are set by users
to one of the other arrays via ff_set_cmp().
One of these other users is mpegvideo_enc; it is the only user
of MECmpContext.frame_skip_cmp and it only uses one of these
function pointers at all.
This commit therefore moves this function pointer to MpegEncContext;
and removes the array from MECmpContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/me_cmp.h | 1 -
libavcodec/mpegvideo.h | 1 +
libavcodec/mpegvideo_enc.c | 10 ++++++----
tests/checkasm/motion.c | 1 -
4 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/libavcodec/me_cmp.h b/libavcodec/me_cmp.h
index 67e3816829..4f964ca188 100644
--- a/libavcodec/me_cmp.h
+++ b/libavcodec/me_cmp.h
@@ -71,7 +71,6 @@ typedef struct MECmpContext {
me_cmp_func dct264_sad[6];
me_cmp_func ildct_cmp[6]; // only width 16 used
- me_cmp_func frame_skip_cmp[6]; // only width 8 used
me_cmp_func pix_abs[2][4];
me_cmp_func median_sad[6];
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 60dcf65288..df46433a82 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -542,6 +542,7 @@ typedef struct MpegEncContext {
int frame_skip_factor;
int frame_skip_exp;
int frame_skip_cmp;
+ me_cmp_func frame_skip_cmp_fn;
int scenechange_threshold;
int noise_reduction;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 5b8d877935..6ec8fa2e0b 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -308,12 +308,17 @@ av_cold void ff_dct_encode_init(MpegEncContext *s)
static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
{
+ me_cmp_func me_cmp[6];
int ret;
ff_me_cmp_init(&s->mecc, avctx);
ret = ff_me_init(&s->me, avctx, &s->mecc);
if (ret < 0)
return ret;
+ ret = ff_set_cmp(&s->mecc, me_cmp, s->frame_skip_cmp);
+ if (ret < 0)
+ return ret;
+ s->frame_skip_cmp_fn = me_cmp[1];
return 0;
}
@@ -931,9 +936,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
if (!s->mecc.ildct_cmp[0] || !s->mecc.ildct_cmp[4])
return AVERROR(EINVAL);
}
- ret = ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, s->frame_skip_cmp);
- if (ret < 0)
- return AVERROR(EINVAL);
if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) {
ff_h263_encode_init(s);
@@ -1311,7 +1313,7 @@ static int skip_check(MpegEncContext *s, const MPVPicture *p, const MPVPicture *
int off = p->shared ? 0 : 16;
const uint8_t *dptr = p->f->data[plane] + 8 * (x + y * stride) + off;
const uint8_t *rptr = ref->f->data[plane] + 8 * (x + y * stride);
- int v = s->mecc.frame_skip_cmp[1](s, dptr, rptr, stride, 8);
+ int v = s->frame_skip_cmp_fn(s, dptr, rptr, stride, 8);
switch (FFABS(s->frame_skip_exp)) {
case 0: score = FFMAX(score, v); break;
diff --git a/tests/checkasm/motion.c b/tests/checkasm/motion.c
index 2bf49afc77..8f9915c63a 100644
--- a/tests/checkasm/motion.c
+++ b/tests/checkasm/motion.c
@@ -95,7 +95,6 @@ static void test_motion(const char *name, me_cmp_func test_func)
XX(vsse) \
XX(nsse) \
XX(ildct_cmp) \
- XX(frame_skip_cmp) \
XX(median_sad)
// tests for functions not yet implemented
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 24/57] avcodec/me_cmp, dvenc, mpegvideo: Move ildct_cmp to its users
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (21 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 23/57] avcodec/me_cmp, mpegvideo: Move frame_skip_cmp to MpegEncContext Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 25/57] avcodec/me_cmp, motion_est: Sanitize permissible cmp_funcs Andreas Rheinhardt
` (48 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
MECmpContext.ildct_cmp is an array of function pointers that
are not set by ff_me_cmp_init(), but that are set by users
to one of the other arrays via ff_set_cmp().
Remove these pointers from MECmpContext and add pointers
for the actually used functions to its users. (The DV encoder
already did so.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/dvenc.c | 7 +++---
libavcodec/me_cmp.h | 2 --
libavcodec/mpegvideo.h | 2 ++
libavcodec/mpegvideo_enc.c | 49 +++++++++++++++++++-------------------
tests/checkasm/motion.c | 1 -
5 files changed, 31 insertions(+), 30 deletions(-)
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 08ed53d823..784340744e 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -96,15 +96,16 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
MECmpContext mecc;
+ me_cmp_func ildct_cmp[6];
memset(&mecc,0, sizeof(mecc));
ff_me_cmp_init(&mecc, avctx);
- ret = ff_set_cmp(&mecc, mecc.ildct_cmp, avctx->ildct_cmp);
+ ret = ff_set_cmp(&mecc, ildct_cmp, avctx->ildct_cmp);
if (ret < 0)
return ret;
- if (!mecc.ildct_cmp[5])
+ if (!ildct_cmp[5])
return AVERROR(EINVAL);
- s->ildct_cmp = mecc.ildct_cmp[5];
+ s->ildct_cmp = ildct_cmp[5];
}
memset(&fdsp,0, sizeof(fdsp));
diff --git a/libavcodec/me_cmp.h b/libavcodec/me_cmp.h
index 4f964ca188..b9abc7fb8e 100644
--- a/libavcodec/me_cmp.h
+++ b/libavcodec/me_cmp.h
@@ -70,8 +70,6 @@ typedef struct MECmpContext {
me_cmp_func dct_max[6];
me_cmp_func dct264_sad[6];
- me_cmp_func ildct_cmp[6]; // only width 16 used
-
me_cmp_func pix_abs[2][4];
me_cmp_func median_sad[6];
} MECmpContext;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index df46433a82..44695776ad 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -506,6 +506,8 @@ typedef struct MpegEncContext {
int mpv_flags; ///< flags set by private options
int quantizer_noise_shaping;
+ me_cmp_func ildct_cmp[2]; ///< 0 = intra, 1 = non-intra
+
/**
* ratecontrol qmin qmax limiting method
* 0-> clipping, 1-> use a nice continuous function to limit qscale within qmin/qmax.
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6ec8fa2e0b..6059bdee11 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -319,6 +319,15 @@ static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
if (ret < 0)
return ret;
s->frame_skip_cmp_fn = me_cmp[1];
+ if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
+ ret = ff_set_cmp(&s->mecc, me_cmp, avctx->ildct_cmp);
+ if (ret < 0)
+ return ret;
+ if (!me_cmp[0] || !me_cmp[4])
+ return AVERROR(EINVAL);
+ s->ildct_cmp[0] = me_cmp[0];
+ s->ildct_cmp[1] = me_cmp[4];
+ }
return 0;
}
@@ -929,14 +938,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->quant_precision = 5;
- if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
- ret = ff_set_cmp(&s->mecc, s->mecc.ildct_cmp, avctx->ildct_cmp);
- if (ret < 0)
- return ret;
- if (!s->mecc.ildct_cmp[0] || !s->mecc.ildct_cmp[4])
- return AVERROR(EINVAL);
- }
-
if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) {
ff_h263_encode_init(s);
#if CONFIG_MSMPEG4ENC
@@ -2209,15 +2210,15 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
int progressive_score, interlaced_score;
s->interlaced_dct = 0;
- progressive_score = s->mecc.ildct_cmp[4](s, ptr_y, NULL, wrap_y, 8) +
- s->mecc.ildct_cmp[4](s, ptr_y + wrap_y * 8,
- NULL, wrap_y, 8) - 400;
+ progressive_score = s->ildct_cmp[1](s, ptr_y, NULL, wrap_y, 8) +
+ s->ildct_cmp[1](s, ptr_y + wrap_y * 8,
+ NULL, wrap_y, 8) - 400;
if (progressive_score > 0) {
- interlaced_score = s->mecc.ildct_cmp[4](s, ptr_y,
- NULL, wrap_y * 2, 8) +
- s->mecc.ildct_cmp[4](s, ptr_y + wrap_y,
- NULL, wrap_y * 2, 8);
+ interlaced_score = s->ildct_cmp[1](s, ptr_y,
+ NULL, wrap_y * 2, 8) +
+ s->ildct_cmp[1](s, ptr_y + wrap_y,
+ NULL, wrap_y * 2, 8);
if (progressive_score > interlaced_score) {
s->interlaced_dct = 1;
@@ -2288,20 +2289,20 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
int progressive_score, interlaced_score;
s->interlaced_dct = 0;
- progressive_score = s->mecc.ildct_cmp[0](s, dest_y, ptr_y, wrap_y, 8) +
- s->mecc.ildct_cmp[0](s, dest_y + wrap_y * 8,
- ptr_y + wrap_y * 8,
- wrap_y, 8) - 400;
+ progressive_score = s->ildct_cmp[0](s, dest_y, ptr_y, wrap_y, 8) +
+ s->ildct_cmp[0](s, dest_y + wrap_y * 8,
+ ptr_y + wrap_y * 8,
+ wrap_y, 8) - 400;
if (s->avctx->ildct_cmp == FF_CMP_VSSE)
progressive_score -= 400;
if (progressive_score > 0) {
- interlaced_score = s->mecc.ildct_cmp[0](s, dest_y, ptr_y,
- wrap_y * 2, 8) +
- s->mecc.ildct_cmp[0](s, dest_y + wrap_y,
- ptr_y + wrap_y,
- wrap_y * 2, 8);
+ interlaced_score = s->ildct_cmp[0](s, dest_y, ptr_y,
+ wrap_y * 2, 8) +
+ s->ildct_cmp[0](s, dest_y + wrap_y,
+ ptr_y + wrap_y,
+ wrap_y * 2, 8);
if (progressive_score > interlaced_score) {
s->interlaced_dct = 1;
diff --git a/tests/checkasm/motion.c b/tests/checkasm/motion.c
index 8f9915c63a..bfd1a3c17b 100644
--- a/tests/checkasm/motion.c
+++ b/tests/checkasm/motion.c
@@ -94,7 +94,6 @@ static void test_motion(const char *name, me_cmp_func test_func)
XX(vsad) \
XX(vsse) \
XX(nsse) \
- XX(ildct_cmp) \
XX(median_sad)
// tests for functions not yet implemented
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 25/57] avcodec/me_cmp, motion_est: Sanitize permissible cmp_funcs
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (22 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 24/57] avcodec/me_cmp, dvenc, mpegvideo: Move ildct_cmp to its users Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-13 7:49 ` Michael Niedermayer
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 26/57] avcodec/motion_est: Store remaining required me_cmp_funcs Andreas Rheinhardt
` (47 subsequent siblings)
71 siblings, 1 reply; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Several of the potential choices of comparison functions
need an initialized MpegEncContext (initialized for encoding,
not only ff_mpv_common_init()) or they crash when called.
Modify ff_set_cmp() to check for this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/dvenc.c | 2 +-
libavcodec/me_cmp.c | 116 +++++++++++++++++--------------------
libavcodec/me_cmp.h | 9 ++-
libavcodec/motion_est.c | 11 ++--
libavcodec/motion_est.h | 2 +-
libavcodec/mpegvideo_enc.c | 6 +-
libavcodec/snowenc.c | 2 +-
libavcodec/svq1enc.c | 2 +-
8 files changed, 73 insertions(+), 77 deletions(-)
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 784340744e..f2221d0b94 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -100,7 +100,7 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
memset(&mecc,0, sizeof(mecc));
ff_me_cmp_init(&mecc, avctx);
- ret = ff_set_cmp(&mecc, ildct_cmp, avctx->ildct_cmp);
+ ret = ff_set_cmp(&mecc, ildct_cmp, avctx->ildct_cmp, 0);
if (ret < 0)
return ret;
if (!ildct_cmp[5])
diff --git a/libavcodec/me_cmp.c b/libavcodec/me_cmp.c
index cff8936e44..dfc351d7ae 100644
--- a/libavcodec/me_cmp.c
+++ b/libavcodec/me_cmp.c
@@ -20,6 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stddef.h>
+
#include "libavutil/attributes.h"
#include "libavutil/internal.h"
#include "libavutil/mem_internal.h"
@@ -473,74 +475,60 @@ static int zero_cmp(MpegEncContext *s, const uint8_t *a, const uint8_t *b,
return 0;
}
-int ff_set_cmp(const MECmpContext *c, me_cmp_func *cmp, int type)
+av_cold int ff_set_cmp(const MECmpContext *c, me_cmp_func *cmp, int type, int mpvenc)
{
- int ret = 0;
- int i;
-
- memset(cmp, 0, sizeof(void *) * 6);
-
- for (i = 0; i < 6; i++) {
- switch (type & 0xFF) {
- case FF_CMP_SAD:
- cmp[i] = c->sad[i];
- break;
- case FF_CMP_MEDIAN_SAD:
- cmp[i] = c->median_sad[i];
- break;
- case FF_CMP_SATD:
- cmp[i] = c->hadamard8_diff[i];
- break;
- case FF_CMP_SSE:
- cmp[i] = c->sse[i];
- break;
- case FF_CMP_DCT:
- cmp[i] = c->dct_sad[i];
- break;
- case FF_CMP_DCT264:
- cmp[i] = c->dct264_sad[i];
- break;
- case FF_CMP_DCTMAX:
- cmp[i] = c->dct_max[i];
- break;
- case FF_CMP_PSNR:
- cmp[i] = c->quant_psnr[i];
- break;
- case FF_CMP_BIT:
- cmp[i] = c->bit[i];
- break;
- case FF_CMP_RD:
- cmp[i] = c->rd[i];
- break;
- case FF_CMP_VSAD:
- cmp[i] = c->vsad[i];
- break;
- case FF_CMP_VSSE:
- cmp[i] = c->vsse[i];
- break;
- case FF_CMP_ZERO:
- cmp[i] = zero_cmp;
- break;
- case FF_CMP_NSSE:
- cmp[i] = c->nsse[i];
- break;
-#if CONFIG_DWT
- case FF_CMP_W53:
- cmp[i]= c->w53[i];
- break;
- case FF_CMP_W97:
- cmp[i]= c->w97[i];
- break;
+#define ENTRY(CMP_FLAG, ARRAY, MPVENC_ONLY) \
+ [FF_CMP_ ## CMP_FLAG] = { \
+ .offset = offsetof(MECmpContext, ARRAY), \
+ .mpv_only = MPVENC_ONLY, \
+ .available = 1, \
+ }
+ static const struct {
+ char available;
+ char mpv_only;
+ uint16_t offset;
+ } cmp_func_list[] = {
+ ENTRY(SAD, sad, 0),
+ ENTRY(SSE, sse, 0),
+ ENTRY(SATD, hadamard8_diff, 0),
+ ENTRY(DCT, dct_sad, 1),
+ ENTRY(PSNR, quant_psnr, 1),
+ ENTRY(BIT, bit, 1),
+ ENTRY(RD, rd, 1),
+ ENTRY(VSAD, vsad, 0),
+ ENTRY(VSSE, vsse, 0),
+ ENTRY(NSSE, nsse, 0),
+#if CONFIG_SNOW_DECODER || CONFIG_SNOW_ENCODER
+ ENTRY(W53, w53, 0),
+ ENTRY(W97, w97, 0),
#endif
- default:
- av_log(NULL, AV_LOG_ERROR,
- "invalid cmp function selection\n");
- ret = -1;
- break;
- }
+ ENTRY(DCTMAX, dct_max, 1),
+#if CONFIG_GPL
+ ENTRY(DCT264, dct264_sad, 1),
+#endif
+ ENTRY(MEDIAN_SAD, median_sad, 0),
+ };
+ const me_cmp_func *me_cmp_func_array;
+
+ type &= 0xFF;
+
+ if (type == FF_CMP_ZERO) {
+ for (int i = 0; i < 6; i++)
+ cmp[i] = zero_cmp;
+ return 0;
+ }
+ if (type > FF_ARRAY_ELEMS(cmp_func_list) ||
+ !cmp_func_list[type].available ||
+ !mpvenc && cmp_func_list[type].mpv_only) {
+ av_log(NULL, AV_LOG_ERROR,
+ "invalid cmp function selection\n");
+ return AVERROR(EINVAL);
}
+ me_cmp_func_array = (const me_cmp_func*)(((const char*)c) + cmp_func_list[type].offset);
+ for (int i = 0; i < 6; i++)
+ cmp[i] = me_cmp_func_array[i];
- return ret;
+ return 0;
}
#define BUTTERFLY2(o1, o2, i1, i2) \
diff --git a/libavcodec/me_cmp.h b/libavcodec/me_cmp.h
index b9abc7fb8e..9053327c4c 100644
--- a/libavcodec/me_cmp.h
+++ b/libavcodec/me_cmp.h
@@ -83,7 +83,14 @@ void ff_me_cmp_init_riscv(MECmpContext *c, AVCodecContext *avctx);
void ff_me_cmp_init_x86(MECmpContext *c, AVCodecContext *avctx);
void ff_me_cmp_init_mips(MECmpContext *c, AVCodecContext *avctx);
-int ff_set_cmp(const MECmpContext *c, me_cmp_func *cmp, int type);
+/**
+ * Fill the function pointer array cmp[6] with me_cmp_funcs from
+ * c based upon type. If mpvenc is not set, an error is returned
+ * if the type of comparison functions requires an initialized
+ * MpegEncContext.
+ */
+int ff_set_cmp(const MECmpContext *c, me_cmp_func *cmp,
+ int type, int mpvenc);
void ff_dsputil_init_dwt(MECmpContext *c);
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index b29d0c6d96..13f3d8040e 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -305,7 +305,8 @@ static int zero_cmp(MpegEncContext *s, const uint8_t *a, const uint8_t *b,
static void zero_hpel(uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h){
}
-av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, const MECmpContext *mecc)
+av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx,
+ const MECmpContext *mecc, int mpvenc)
{
int cache_size = FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT);
int dia_size = FFMAX(FFABS(avctx->dia_size) & 255, FFABS(avctx->pre_dia_size) & 255);
@@ -324,10 +325,10 @@ av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx, const MECmpCo
if (cache_size < 2 * dia_size)
av_log(avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n");
- ret = ff_set_cmp(mecc, c->me_pre_cmp, avctx->me_pre_cmp);
- ret |= ff_set_cmp(mecc, c->me_cmp, avctx->me_cmp);
- ret |= ff_set_cmp(mecc, c->me_sub_cmp, avctx->me_sub_cmp);
- ret |= ff_set_cmp(mecc, c->mb_cmp, avctx->mb_cmp);
+ ret = ff_set_cmp(mecc, c->me_pre_cmp, avctx->me_pre_cmp, mpvenc);
+ ret |= ff_set_cmp(mecc, c->me_cmp, avctx->me_cmp, mpvenc);
+ ret |= ff_set_cmp(mecc, c->me_sub_cmp, avctx->me_sub_cmp, mpvenc);
+ ret |= ff_set_cmp(mecc, c->mb_cmp, avctx->mb_cmp, mpvenc);
if (ret < 0)
return ret;
diff --git a/libavcodec/motion_est.h b/libavcodec/motion_est.h
index 5547aeb8bc..243b73ff4e 100644
--- a/libavcodec/motion_est.h
+++ b/libavcodec/motion_est.h
@@ -115,7 +115,7 @@ static inline int ff_h263_round_chroma(int x)
* Performs one-time initialization of the MotionEstContext.
*/
int ff_me_init(MotionEstContext *c, struct AVCodecContext *avctx,
- const struct MECmpContext *mecc);
+ const struct MECmpContext *mecc, int mpvenc);
void ff_me_init_pic(struct MpegEncContext *s);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6059bdee11..8022fe474a 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -312,15 +312,15 @@ static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
int ret;
ff_me_cmp_init(&s->mecc, avctx);
- ret = ff_me_init(&s->me, avctx, &s->mecc);
+ ret = ff_me_init(&s->me, avctx, &s->mecc, 1);
if (ret < 0)
return ret;
- ret = ff_set_cmp(&s->mecc, me_cmp, s->frame_skip_cmp);
+ ret = ff_set_cmp(&s->mecc, me_cmp, s->frame_skip_cmp, 1);
if (ret < 0)
return ret;
s->frame_skip_cmp_fn = me_cmp[1];
if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
- ret = ff_set_cmp(&s->mecc, me_cmp, avctx->ildct_cmp);
+ ret = ff_set_cmp(&s->mecc, me_cmp, avctx->ildct_cmp, 1);
if (ret < 0)
return ret;
if (!me_cmp[0] || !me_cmp[4])
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 9d64b1efe2..819a7933fe 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -217,7 +217,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
mcf(12,12)
ff_me_cmp_init(&enc->mecc, avctx);
- ret = ff_me_init(&enc->m.me, avctx, &enc->mecc);
+ ret = ff_me_init(&enc->m.me, avctx, &enc->mecc, 0);
if (ret < 0)
return ret;
ff_mpegvideoencdsp_init(&enc->mpvencdsp, avctx);
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index ceb8bf83c2..5413508217 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -589,7 +589,7 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
ff_hpeldsp_init(&s->hdsp, avctx->flags);
ff_me_cmp_init(&s->mecc, avctx);
- ret = ff_me_init(&s->m.me, avctx, &s->mecc);
+ ret = ff_me_init(&s->m.me, avctx, &s->mecc, 0);
if (ret < 0)
return ret;
ff_mpegvideoencdsp_init(&s->m.mpvencdsp, avctx);
--
2.40.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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 25/57] avcodec/me_cmp, motion_est: Sanitize permissible cmp_funcs
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 25/57] avcodec/me_cmp, motion_est: Sanitize permissible cmp_funcs Andreas Rheinhardt
@ 2024-06-13 7:49 ` Michael Niedermayer
2024-06-13 9:37 ` Andreas Rheinhardt
0 siblings, 1 reply; 87+ messages in thread
From: Michael Niedermayer @ 2024-06-13 7:49 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 735 bytes --]
On Wed, Jun 12, 2024 at 03:48:21PM +0200, Andreas Rheinhardt wrote:
> Several of the potential choices of comparison functions
> need an initialized MpegEncContext (initialized for encoding,
> not only ff_mpv_common_init()) or they crash when called.
> Modify ff_set_cmp() to check for this.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
I dont think they always crashed, so to me marking these as
unsupported now feels a bit strange. But it shows we where lacking
testing
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 25/57] avcodec/me_cmp, motion_est: Sanitize permissible cmp_funcs
2024-06-13 7:49 ` Michael Niedermayer
@ 2024-06-13 9:37 ` Andreas Rheinhardt
2024-06-13 21:11 ` Michael Niedermayer
0 siblings, 1 reply; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-13 9:37 UTC (permalink / raw)
To: ffmpeg-devel
Michael Niedermayer:
> On Wed, Jun 12, 2024 at 03:48:21PM +0200, Andreas Rheinhardt wrote:
>> Several of the potential choices of comparison functions
>> need an initialized MpegEncContext (initialized for encoding,
>> not only ff_mpv_common_init()) or they crash when called.
>> Modify ff_set_cmp() to check for this.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>
> I dont think they always crashed, so to me marking these as
> unsupported now feels a bit strange. But it shows we where lacking
> testing
Why don't you just try:
for codec in svq1 snow; do for cmp in dct psnr bit rd dctmax 14; do
./ffmpeg_g -hide_banner -filter_complex nullsrc -c:v "$codec" -cmp
"$cmp" -f null -; done; done
yourself?
- 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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 25/57] avcodec/me_cmp, motion_est: Sanitize permissible cmp_funcs
2024-06-13 9:37 ` Andreas Rheinhardt
@ 2024-06-13 21:11 ` Michael Niedermayer
0 siblings, 0 replies; 87+ messages in thread
From: Michael Niedermayer @ 2024-06-13 21:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1263 bytes --]
On Thu, Jun 13, 2024 at 11:37:13AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Wed, Jun 12, 2024 at 03:48:21PM +0200, Andreas Rheinhardt wrote:
> >> Several of the potential choices of comparison functions
> >> need an initialized MpegEncContext (initialized for encoding,
> >> not only ff_mpv_common_init()) or they crash when called.
> >> Modify ff_set_cmp() to check for this.
> >>
> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> >> ---
> >
> > I dont think they always crashed, so to me marking these as
> > unsupported now feels a bit strange. But it shows we where lacking
> > testing
>
> Why don't you just try:
> for codec in svq1 snow; do for cmp in dct psnr bit rd dctmax 14; do
> ./ffmpeg_g -hide_banner -filter_complex nullsrc -c:v "$codec" -cmp
> "$cmp" -f null -; done; done
> yourself?
I did misread your patch, i thought you where disabling them for all
cases. Yes svq1 & snow probably didnt work with them
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 26/57] avcodec/motion_est: Store remaining required me_cmp_funcs
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (23 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 25/57] avcodec/me_cmp, motion_est: Sanitize permissible cmp_funcs Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 27/57] avcodec/me_cmp: Zero MECmpContext in ff_me_cmp_init() Andreas Rheinhardt
` (46 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This avoids using MpegEncContext.mecc; it already allows
to avoid touching the latter for snowenc and svq1enc.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/motion_est.c | 7 +++++--
libavcodec/motion_est.h | 3 +++
libavcodec/snowenc.c | 1 -
libavcodec/svq1enc.c | 1 -
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index 13f3d8040e..e783e79a94 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -332,6 +332,9 @@ av_cold int ff_me_init(MotionEstContext *c, AVCodecContext *avctx,
if (ret < 0)
return ret;
+ c->sse = mecc->sse[0];
+ memcpy(c->pix_abs, mecc->pix_abs, sizeof(c->pix_abs));
+
c->flags = get_flags(c, 0, avctx->me_cmp & FF_CMP_CHROMA);
c->sub_flags = get_flags(c, 0, avctx->me_sub_cmp & FF_CMP_CHROMA);
c->mb_flags = get_flags(c, 0, avctx->mb_cmp & FF_CMP_CHROMA);
@@ -397,7 +400,7 @@ void ff_me_init_pic(MpegEncContext *s)
#define CHECK_SAD_HALF_MV(suffix, x, y) \
{\
- d = s->mecc.pix_abs[size][(x ? 1 : 0) + (y ? 2 : 0)](NULL, pix, ptr + ((x) >> 1), stride, h); \
+ d = c->pix_abs[size][(x ? 1 : 0) + (y ? 2 : 0)](NULL, pix, ptr + ((x) >> 1), stride, h); \
d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\
COPY3_IF_LT(dminh, d, dx, x, dy, y)\
}
@@ -973,7 +976,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
/* At this point (mx,my) are full-pell and the relative displacement */
ppix = c->ref[0][0] + (my * s->linesize) + mx;
- vard = s->mecc.sse[0](NULL, pix, ppix, s->linesize, 16);
+ vard = c->sse(NULL, pix, ppix, s->linesize, 16);
s->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;
c->mc_mb_var_sum_temp += (vard+128)>>8;
diff --git a/libavcodec/motion_est.h b/libavcodec/motion_est.h
index 243b73ff4e..12f7cd43ab 100644
--- a/libavcodec/motion_est.h
+++ b/libavcodec/motion_est.h
@@ -89,6 +89,9 @@ typedef struct MotionEstContext {
me_cmp_func me_sub_cmp[6];
me_cmp_func mb_cmp[6];
+ me_cmp_func pix_abs[2][4];
+ me_cmp_func sse;
+
op_pixels_func(*hpel_put)[4];
op_pixels_func(*hpel_avg)[4];
qpel_mc_func(*qpel_put)[16];
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 819a7933fe..9db4314efb 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -1869,7 +1869,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
mpv->qscale = (mpv->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
enc->lambda2 = mpv->lambda2 = (mpv->lambda*mpv->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
- mpv->mecc = enc->mecc; //move
mpv->qdsp = enc->qdsp; //move
mpv->hdsp = s->hdsp;
ff_me_init_pic(&enc->m);
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 5413508217..6e687166b8 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -373,7 +373,6 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
s->m.cur_pic.motion_val[0] = s->motion_val8[plane] + 2;
s->m.p_mv_table = s->motion_val16[plane] +
s->m.mb_stride + 1;
- s->m.mecc = s->mecc; // move
ff_me_init_pic(&s->m);
s->m.me.dia_size = s->avctx->dia_size;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 27/57] avcodec/me_cmp: Zero MECmpContext in ff_me_cmp_init()
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (24 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 26/57] avcodec/motion_est: Store remaining required me_cmp_funcs Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 28/57] avcodec/mpegvideo_enc: Avoid branch for sse vs nsse cmp Andreas Rheinhardt
` (45 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Not every function will be set, so zero the context
to initialize everything.
This also allows to remove an initialization in dvenc.c.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/dvenc.c | 1 -
libavcodec/me_cmp.c | 2 ++
libavcodec/tests/motion.c | 2 --
tests/checkasm/motion.c | 3 ---
4 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index f2221d0b94..c42ab8931e 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -98,7 +98,6 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
MECmpContext mecc;
me_cmp_func ildct_cmp[6];
- memset(&mecc,0, sizeof(mecc));
ff_me_cmp_init(&mecc, avctx);
ret = ff_set_cmp(&mecc, ildct_cmp, avctx->ildct_cmp, 0);
if (ret < 0)
diff --git a/libavcodec/me_cmp.c b/libavcodec/me_cmp.c
index dfc351d7ae..27da787c71 100644
--- a/libavcodec/me_cmp.c
+++ b/libavcodec/me_cmp.c
@@ -995,6 +995,8 @@ WRAPPER8_16_SQ(bit8x8_c, bit16_c)
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
{
+ memset(c, 0, sizeof(*c));
+
c->sum_abs_dctelem = sum_abs_dctelem_c;
/* TODO [0] 16 [1] 8 */
diff --git a/libavcodec/tests/motion.c b/libavcodec/tests/motion.c
index caa8ecb8be..c37fc551c3 100644
--- a/libavcodec/tests/motion.c
+++ b/libavcodec/tests/motion.c
@@ -131,12 +131,10 @@ int main(int argc, char **argv)
ctx = avcodec_alloc_context3(NULL);
ctx->flags |= AV_CODEC_FLAG_BITEXACT;
av_force_cpu_flags(0);
- memset(&cctx, 0, sizeof(cctx));
ff_me_cmp_init(&cctx, ctx);
for (c = 0; c < flags_size; c++) {
int x;
av_force_cpu_flags(flags[c]);
- memset(&mmxctx, 0, sizeof(mmxctx));
ff_me_cmp_init(&mmxctx, ctx);
for (x = 0; x < 2; x++) {
diff --git a/tests/checkasm/motion.c b/tests/checkasm/motion.c
index bfd1a3c17b..7e322da0d5 100644
--- a/tests/checkasm/motion.c
+++ b/tests/checkasm/motion.c
@@ -116,9 +116,6 @@ static void check_motion(void)
AVCodecContext av_ctx = { .codec_id = AV_CODEC_ID_NONE, .flags = AV_CODEC_FLAG_BITEXACT };
MECmpContext me_ctx;
- memset(&me_ctx, 0, sizeof(me_ctx));
-
-
ff_me_cmp_init(&me_ctx, &av_ctx);
for (int i = 0; i < FF_ARRAY_ELEMS(me_ctx.pix_abs); i++) {
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 28/57] avcodec/mpegvideo_enc: Avoid branch for sse vs nsse cmp
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (25 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 27/57] avcodec/me_cmp: Zero MECmpContext in ff_me_cmp_init() Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 29/57] avcodec/mpegvideo_enc: Only keep what is used from MECmpContext Andreas Rheinhardt
` (44 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.h | 1 +
libavcodec/mpegvideo_enc.c | 23 +++++++++++------------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 44695776ad..79c5561793 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -507,6 +507,7 @@ typedef struct MpegEncContext {
int quantizer_noise_shaping;
me_cmp_func ildct_cmp[2]; ///< 0 = intra, 1 = non-intra
+ me_cmp_func n_sse_cmp[2]; ///< either SSE or NSSE cmp func
/**
* ratecontrol qmin qmax limiting method
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 8022fe474a..3d659fa290 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -329,6 +329,14 @@ static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
s->ildct_cmp[1] = me_cmp[4];
}
+ if (avctx->mb_cmp == FF_CMP_NSSE) {
+ s->n_sse_cmp[0] = s->mecc.nsse[0];
+ s->n_sse_cmp[1] = s->mecc.nsse[1];
+ } else {
+ s->n_sse_cmp[0] = s->mecc.sse[0];
+ s->n_sse_cmp[1] = s->mecc.sse[1];
+ }
+
return 0;
}
@@ -2664,21 +2672,12 @@ static int sse_mb(MpegEncContext *s){
if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16;
if(w==16 && h==16)
- if(s->avctx->mb_cmp == FF_CMP_NSSE){
- return s->mecc.nsse[0](s, s->new_pic->data[0] + s->mb_x * 16 + s->mb_y * s->linesize * 16,
+ return s->n_sse_cmp[0](s, s->new_pic->data[0] + s->mb_x * 16 + s->mb_y * s->linesize * 16,
s->dest[0], s->linesize, 16) +
- s->mecc.nsse[1](s, s->new_pic->data[1] + s->mb_x * chroma_mb_w + s->mb_y * s->uvlinesize * chroma_mb_h,
+ s->n_sse_cmp[1](s, s->new_pic->data[1] + s->mb_x * chroma_mb_w + s->mb_y * s->uvlinesize * chroma_mb_h,
s->dest[1], s->uvlinesize, chroma_mb_h) +
- s->mecc.nsse[1](s, s->new_pic->data[2] + s->mb_x * chroma_mb_w + s->mb_y * s->uvlinesize * chroma_mb_h,
+ s->n_sse_cmp[1](s, s->new_pic->data[2] + s->mb_x * chroma_mb_w + s->mb_y * s->uvlinesize * chroma_mb_h,
s->dest[2], s->uvlinesize, chroma_mb_h);
- }else{
- return s->mecc.sse[0](NULL, s->new_pic->data[0] + s->mb_x * 16 + s->mb_y * s->linesize * 16,
- s->dest[0], s->linesize, 16) +
- s->mecc.sse[1](NULL, s->new_pic->data[1] + s->mb_x * chroma_mb_w + s->mb_y * s->uvlinesize * chroma_mb_h,
- s->dest[1], s->uvlinesize, chroma_mb_h) +
- s->mecc.sse[1](NULL, s->new_pic->data[2] + s->mb_x * chroma_mb_w + s->mb_y * s->uvlinesize * chroma_mb_h,
- s->dest[2], s->uvlinesize, chroma_mb_h);
- }
else
return sse(s, s->new_pic->data[0] + s->mb_x * 16 + s->mb_y * s->linesize * 16,
s->dest[0], w, h, s->linesize) +
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 29/57] avcodec/mpegvideo_enc: Only keep what is used from MECmpContext
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (26 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 28/57] avcodec/mpegvideo_enc: Avoid branch for sse vs nsse cmp Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 30/57] avcodec/mpegvideo_enc: Initialize qscale tab for all codecs Andreas Rheinhardt
` (43 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
A MECmpContext is quite big (792B here) and given
how ff_update_duplicate_context() works, it is (unfortunately)
copied quite frequently when using slice threading.
Therefore keep only what is needed from MECmpContext
and remove MECmpContext from MpegEncContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/me_cmp.c | 4 +--
libavcodec/mpeg4videoenc.c | 2 +-
libavcodec/mpegvideo.h | 4 ++-
libavcodec/mpegvideo_enc.c | 59 ++++++++++++++++++++----------------
libavcodec/x86/me_cmp_init.c | 2 +-
5 files changed, 40 insertions(+), 31 deletions(-)
diff --git a/libavcodec/me_cmp.c b/libavcodec/me_cmp.c
index 27da787c71..478bfc207d 100644
--- a/libavcodec/me_cmp.c
+++ b/libavcodec/me_cmp.c
@@ -653,7 +653,7 @@ static int dct_sad8x8_c(MpegEncContext *s, const uint8_t *src1,
s->pdsp.diff_pixels_unaligned(temp, src1, src2, stride);
s->fdsp.fdct(temp);
- return s->mecc.sum_abs_dctelem(temp);
+ return s->sum_abs_dctelem(temp);
}
#if CONFIG_GPL
@@ -819,7 +819,7 @@ static int rd8x8_c(MpegEncContext *s, const uint8_t *src1, const uint8_t *src2,
s->idsp.idct_add(lsrc2, 8, temp);
- distortion = s->mecc.sse[1](NULL, lsrc2, lsrc1, 8, 8);
+ distortion = s->sse_cmp[1](NULL, lsrc2, lsrc1, 8, 8);
return distortion + ((bits * s->qscale * s->qscale * 109 + 64) >> 7);
}
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 583ea9de6f..84b603f312 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -673,7 +673,7 @@ void ff_mpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64],
}
diff = diff * 256 / (xe * ye);
} else {
- diff = s->mecc.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
+ diff = s->sad_cmp[0](NULL, p_pic, b_pic, s->linesize, 16);
}
if (diff > s->qscale * 70) { // FIXME check that 70 is optimal
s->mb_skipped = 0;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 79c5561793..844da6881f 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -220,7 +220,6 @@ typedef struct MpegEncContext {
H264ChromaContext h264chroma;
HpelDSPContext hdsp;
IDCTDSPContext idsp;
- MECmpContext mecc;
MpegvideoEncDSPContext mpvencdsp;
PixblockDSPContext pdsp;
QpelDSPContext qdsp;
@@ -508,6 +507,9 @@ typedef struct MpegEncContext {
me_cmp_func ildct_cmp[2]; ///< 0 = intra, 1 = non-intra
me_cmp_func n_sse_cmp[2]; ///< either SSE or NSSE cmp func
+ me_cmp_func sad_cmp[2];
+ me_cmp_func sse_cmp[2];
+ int (*sum_abs_dctelem)(const int16_t *block);
/**
* ratecontrol qmin qmax limiting method
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 3d659fa290..73e1a69490 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -308,19 +308,20 @@ av_cold void ff_dct_encode_init(MpegEncContext *s)
static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
{
+ MECmpContext mecc;
me_cmp_func me_cmp[6];
int ret;
- ff_me_cmp_init(&s->mecc, avctx);
- ret = ff_me_init(&s->me, avctx, &s->mecc, 1);
+ ff_me_cmp_init(&mecc, avctx);
+ ret = ff_me_init(&s->me, avctx, &mecc, 1);
if (ret < 0)
return ret;
- ret = ff_set_cmp(&s->mecc, me_cmp, s->frame_skip_cmp, 1);
+ ret = ff_set_cmp(&mecc, me_cmp, s->frame_skip_cmp, 1);
if (ret < 0)
return ret;
s->frame_skip_cmp_fn = me_cmp[1];
if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
- ret = ff_set_cmp(&s->mecc, me_cmp, avctx->ildct_cmp, 1);
+ ret = ff_set_cmp(&mecc, me_cmp, avctx->ildct_cmp, 1);
if (ret < 0)
return ret;
if (!me_cmp[0] || !me_cmp[4])
@@ -329,12 +330,18 @@ static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
s->ildct_cmp[1] = me_cmp[4];
}
+ s->sum_abs_dctelem = mecc.sum_abs_dctelem;
+
+ s->sse_cmp[0] = mecc.sse[0];
+ s->sse_cmp[1] = mecc.sse[1];
+ s->sad_cmp[0] = mecc.sad[0];
+ s->sad_cmp[1] = mecc.sad[1];
if (avctx->mb_cmp == FF_CMP_NSSE) {
- s->n_sse_cmp[0] = s->mecc.nsse[0];
- s->n_sse_cmp[1] = s->mecc.nsse[1];
+ s->n_sse_cmp[0] = mecc.nsse[0];
+ s->n_sse_cmp[1] = mecc.nsse[1];
} else {
- s->n_sse_cmp[0] = s->mecc.sse[0];
- s->n_sse_cmp[1] = s->mecc.sse[1];
+ s->n_sse_cmp[0] = mecc.sse[0];
+ s->n_sse_cmp[1] = mecc.sse[1];
}
return 0;
@@ -1123,8 +1130,8 @@ static int get_intra_count(MpegEncContext *s, const uint8_t *src,
for (y = 0; y < h; y += 16) {
for (x = 0; x < w; x += 16) {
int offset = x + y * stride;
- int sad = s->mecc.sad[0](NULL, src + offset, ref + offset,
- stride, 16);
+ int sad = s->sad_cmp[0](NULL, src + offset, ref + offset,
+ stride, 16);
int mean = (s->mpvencdsp.pix_sum(src + offset, stride) + 128) >> 8;
int sae = get_sae(src + offset, mean, stride);
@@ -2347,28 +2354,28 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
/* pre quantization */
if (s->mc_mb_var[s->mb_stride * mb_y + mb_x] < 2 * s->qscale * s->qscale) {
// FIXME optimize
- if (s->mecc.sad[1](NULL, ptr_y, dest_y, wrap_y, 8) < 20 * s->qscale)
+ if (s->sad_cmp[1](NULL, ptr_y, dest_y, wrap_y, 8) < 20 * s->qscale)
skip_dct[0] = 1;
- if (s->mecc.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20 * s->qscale)
+ if (s->sad_cmp[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20 * s->qscale)
skip_dct[1] = 1;
- if (s->mecc.sad[1](NULL, ptr_y + dct_offset, dest_y + dct_offset,
- wrap_y, 8) < 20 * s->qscale)
+ if (s->sad_cmp[1](NULL, ptr_y + dct_offset, dest_y + dct_offset,
+ wrap_y, 8) < 20 * s->qscale)
skip_dct[2] = 1;
- if (s->mecc.sad[1](NULL, ptr_y + dct_offset + 8, dest_y + dct_offset + 8,
- wrap_y, 8) < 20 * s->qscale)
+ if (s->sad_cmp[1](NULL, ptr_y + dct_offset + 8, dest_y + dct_offset + 8,
+ wrap_y, 8) < 20 * s->qscale)
skip_dct[3] = 1;
- if (s->mecc.sad[1](NULL, ptr_cb, dest_cb, wrap_c, 8) < 20 * s->qscale)
+ if (s->sad_cmp[1](NULL, ptr_cb, dest_cb, wrap_c, 8) < 20 * s->qscale)
skip_dct[4] = 1;
- if (s->mecc.sad[1](NULL, ptr_cr, dest_cr, wrap_c, 8) < 20 * s->qscale)
+ if (s->sad_cmp[1](NULL, ptr_cr, dest_cr, wrap_c, 8) < 20 * s->qscale)
skip_dct[5] = 1;
if (!chroma_y_shift) { /* 422 */
- if (s->mecc.sad[1](NULL, ptr_cb + uv_dct_offset,
- dest_cb + uv_dct_offset,
- wrap_c, 8) < 20 * s->qscale)
+ if (s->sad_cmp[1](NULL, ptr_cb + uv_dct_offset,
+ dest_cb + uv_dct_offset,
+ wrap_c, 8) < 20 * s->qscale)
skip_dct[6] = 1;
- if (s->mecc.sad[1](NULL, ptr_cr + uv_dct_offset,
- dest_cr + uv_dct_offset,
- wrap_c, 8) < 20 * s->qscale)
+ if (s->sad_cmp[1](NULL, ptr_cr + uv_dct_offset,
+ dest_cr + uv_dct_offset,
+ wrap_c, 8) < 20 * s->qscale)
skip_dct[7] = 1;
}
}
@@ -2647,9 +2654,9 @@ static int sse(MpegEncContext *s, const uint8_t *src1, const uint8_t *src2, int
int x,y;
if(w==16 && h==16)
- return s->mecc.sse[0](NULL, src1, src2, stride, 16);
+ return s->sse_cmp[0](NULL, src1, src2, stride, 16);
else if(w==8 && h==8)
- return s->mecc.sse[1](NULL, src1, src2, stride, 8);
+ return s->sse_cmp[1](NULL, src1, src2, stride, 8);
for(y=0; y<h; y++){
for(x=0; x<w; x++){
diff --git a/libavcodec/x86/me_cmp_init.c b/libavcodec/x86/me_cmp_init.c
index bc1051c27e..98b71b1894 100644
--- a/libavcodec/x86/me_cmp_init.c
+++ b/libavcodec/x86/me_cmp_init.c
@@ -94,7 +94,7 @@ static int nsse16_mmx(MpegEncContext *c, const uint8_t *pix1, const uint8_t *pix
int score1, score2;
if (c)
- score1 = c->mecc.sse[0](c, pix1, pix2, stride, h);
+ score1 = c->sse_cmp[0](c, pix1, pix2, stride, h);
else
score1 = ff_sse16_mmx(c, pix1, pix2, stride, h);
score2 = ff_hf_noise16_mmx(pix1, stride, h) + ff_hf_noise8_mmx(pix1+8, stride, h)
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 30/57] avcodec/mpegvideo_enc: Initialize qscale tab for all codecs
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (27 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 29/57] avcodec/mpegvideo_enc: Only keep what is used from MECmpContext Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 31/57] avcodec/mpegvideo_enc: Don't update qscale unnecessarily Andreas Rheinhardt
` (42 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Calling it is the first thing ff_clean_h263_qscales() and
ff_clean_mpeg4_qscales() do anyway.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263enc.h | 1 -
libavcodec/ituh263enc.c | 2 --
libavcodec/mpegvideo_enc.c | 6 +++---
3 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/libavcodec/h263enc.h b/libavcodec/h263enc.h
index cd5ded1593..6e07440b30 100644
--- a/libavcodec/h263enc.h
+++ b/libavcodec/h263enc.h
@@ -32,7 +32,6 @@ void ff_h263_encode_mb(MpegEncContext *s,
int motion_x, int motion_y);
void ff_h263_encode_mba(MpegEncContext *s);
-void ff_init_qscale_tab(MpegEncContext *s);
void ff_clean_h263_qscales(MpegEncContext *s);
void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code);
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 8d0c4147bf..b1fe4e241e 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -274,8 +274,6 @@ void ff_clean_h263_qscales(MpegEncContext *s){
int i;
int8_t * const qscale_table = s->cur_pic.qscale_table;
- ff_init_qscale_tab(s);
-
for(i=1; i<s->mb_num; i++){
if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i-1] ] >2)
qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i-1] ]+2;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 73e1a69490..6d26b2d619 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -237,7 +237,7 @@ void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
/**
* init s->cur_pic.qscale_table from s->lambda_table
*/
-void ff_init_qscale_tab(MpegEncContext *s)
+static void init_qscale_tab(MpegEncContext *s)
{
int8_t * const qscale_table = s->cur_pic.qscale_table;
int i;
@@ -3542,6 +3542,8 @@ static int estimate_qp(MpegEncContext *s, int dry_run){
}
if(s->adaptive_quant){
+ init_qscale_tab(s);
+
switch(s->codec_id){
case AV_CODEC_ID_MPEG4:
if (CONFIG_MPEG4_ENCODER)
@@ -3553,8 +3555,6 @@ static int estimate_qp(MpegEncContext *s, int dry_run){
if (CONFIG_H263_ENCODER)
ff_clean_h263_qscales(s);
break;
- default:
- ff_init_qscale_tab(s);
}
s->lambda= s->lambda_table[0];
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 31/57] avcodec/mpegvideo_enc: Don't update qscale unnecessarily
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (28 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 30/57] avcodec/mpegvideo_enc: Initialize qscale tab for all codecs Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 32/57] avcodec/mpegutils: Fix ff_draw_horiz_band() Andreas Rheinhardt
` (41 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The new value will be overwritten in ff_set_qscale() below.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6d26b2d619..125d16e694 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2163,11 +2163,11 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
const int mb_xy = mb_x + mb_y * s->mb_stride;
s->lambda = s->lambda_table[mb_xy];
- update_qscale(s);
+ s->lambda2 = (s->lambda * s->lambda + FF_LAMBDA_SCALE / 2) >>
+ FF_LAMBDA_SHIFT;
if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) {
- s->qscale = s->cur_pic.qscale_table[mb_xy];
- s->dquant = s->qscale - last_qp;
+ s->dquant = s->cur_pic.qscale_table[mb_xy] - last_qp;
if (s->out_format == FMT_H263) {
s->dquant = av_clip(s->dquant, -2, 2);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 32/57] avcodec/mpegutils: Fix ff_draw_horiz_band()
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (29 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 31/57] avcodec/mpegvideo_enc: Don't update qscale unnecessarily Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 33/57] avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy data Andreas Rheinhardt
` (40 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Broken in 5ecf5b93dda9d0c69875b80d28929f0d97dd7d06.
More precisely, 3994623df2efd2749631c3492184dd8d4ffa9d1b changed
the precursor of ff_mpv_reconstruct_mb() to always decode
to the first row of macroblocks for B pictures when
a draw_horiz_band callback is set and to (they are exported to
the caller via said callback and each row overwrites the previously
decoded row; this was probably intended as a cache-optimization).
This first macroblock row was used as source for the draw_horiz_band
callback.
This of course means that the ordinary output B-frame was not
decoded correctly at all. Therefore the first aforementioned commit
removed this special handling of draw_horiz_band; yet it did not
remove the special handling for B-frames in ff_draw_horiz_band(),
which broke draw_horiz_band for B-frames. This commit fixes this.
(Actually, draw_horiz_band was already broken before
5ecf5b93dda9d0c69875b80d28929f0d97dd7d06 when using slice-threading:
All slice-threads would write to the first row of macroblocks
for B-frames, leading to data races. It seems no one has ever complained
about this, just as no one has ever complained about the breakage
caused by 5ecf5b93dda9d0c69875b80d28929f0d97dd7d06. Probably no one
uses draw_horiz_band.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegutils.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c
index a567165fd9..a53996852f 100644
--- a/libavcodec/mpegutils.c
+++ b/libavcodec/mpegutils.c
@@ -57,6 +57,7 @@ void ff_draw_horiz_band(AVCodecContext *avctx,
int first_field, int low_delay)
{
const int field_pic = picture_structure != PICT_FRAME;
+ const AVPixFmtDescriptor *desc;
const AVFrame *src;
int offset[AV_NUM_DATA_POINTERS];
@@ -82,21 +83,13 @@ void ff_draw_horiz_band(AVCodecContext *avctx,
else
return;
- if (cur->pict_type == AV_PICTURE_TYPE_B &&
- picture_structure == PICT_FRAME &&
- avctx->codec_id != AV_CODEC_ID_SVQ3) {
- for (int i = 0; i < AV_NUM_DATA_POINTERS; i++)
- offset[i] = 0;
- } else {
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
- int vshift = desc->log2_chroma_h;
-
- offset[0] = y * src->linesize[0];
- offset[1] =
- offset[2] = (y >> vshift) * src->linesize[1];
- for (int i = 3; i < AV_NUM_DATA_POINTERS; i++)
- offset[i] = 0;
- }
+ desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+
+ offset[0] = y * src->linesize[0];
+ offset[1] =
+ offset[2] = (y >> desc->log2_chroma_h) * src->linesize[1];
+ for (int i = 3; i < AV_NUM_DATA_POINTERS; i++)
+ offset[i] = 0;
emms_c();
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 33/57] avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy data
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (30 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 32/57] avcodec/mpegutils: Fix ff_draw_horiz_band() Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-13 7:36 ` Michael Niedermayer
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 34/57] avcodec/mpeg12dec: Disable allocating scratchpad buffers when possible Andreas Rheinhardt
` (39 subsequent siblings)
71 siblings, 1 reply; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
There is no reason to use a temporary buffer as destination
for the new macroblock before copying it into its proper place.
(History: 3994623df2efd2749631c3492184dd8d4ffa9d1b changed
the precursor of ff_mpv_reconstruct_mb() to always decode
to the first row of macroblocks for B pictures when
a draw_horiz_band callback is set (they are exported to the caller
via said callback and each row overwrites the previously decoded
row; this was probably intended as a cache-optimization).
Later b68ab2609c67d07b6f12ed65125d76bf9a054479 changed this
to the current form in which a scratchpad buffer is used when
decoding B-pictures without draw_horiz_band callback, followed
by copying the block from the scratchpad buffer to the actual
destination. I do not know what the aim of this was. When thinking
of it as a cache optimization, it makes sense to not use it
when the aforementioned draw_horiz_band optimization is in effect,
because then the destination row can be presumed to be hot
already. But then it makes no sense to restrict this optimization
to B-frames.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegpicture.h | 1 -
libavcodec/mpv_reconstruct_mb_template.c | 23 ++---------------------
2 files changed, 2 insertions(+), 22 deletions(-)
diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h
index 86504fe8ca..d3f39bbae6 100644
--- a/libavcodec/mpegpicture.h
+++ b/libavcodec/mpegpicture.h
@@ -35,7 +35,6 @@ typedef struct ScratchpadContext {
uint8_t *obmc_scratchpad;
union {
uint8_t *scratchpad_buf; ///< the other *_scratchpad point into this buffer
- uint8_t *b_scratchpad; ///< scratchpad used for writing into write only buffers
uint8_t *rd_scratchpad; ///< scratchpad for rate distortion mb decision
};
int linesize; ///< linesize that the buffers in this context have been allocated for
diff --git a/libavcodec/mpv_reconstruct_mb_template.c b/libavcodec/mpv_reconstruct_mb_template.c
index 6ad353ddfd..e39b3d0e73 100644
--- a/libavcodec/mpv_reconstruct_mb_template.c
+++ b/libavcodec/mpv_reconstruct_mb_template.c
@@ -80,11 +80,10 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
s->avctx->mb_decision != FF_MB_DECISION_RD)) // FIXME precalc
#endif /* IS_ENCODER */
{
- uint8_t *dest_y, *dest_cb, *dest_cr;
+ uint8_t *dest_y = s->dest[0], *dest_cb = s->dest[1], *dest_cr = s->dest[2];
int dct_linesize, dct_offset;
const int linesize = s->cur_pic.linesize[0]; //not s->linesize as this would be wrong for field pics
const int uvlinesize = s->cur_pic.linesize[1];
- const int readable = IS_ENCODER || lowres_flag || s->pict_type != AV_PICTURE_TYPE_B;
const int block_size = lowres_flag ? 8 >> s->avctx->lowres : 8;
/* avoid copy if macroblock skipped in last frame too */
@@ -106,16 +105,6 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
dct_linesize = linesize << s->interlaced_dct;
dct_offset = s->interlaced_dct ? linesize : linesize * block_size;
- if (readable) {
- dest_y = s->dest[0];
- dest_cb = s->dest[1];
- dest_cr = s->dest[2];
- } else {
- dest_y = s->sc.b_scratchpad;
- dest_cb = s->sc.b_scratchpad + 16 * linesize;
- dest_cr = s->sc.b_scratchpad + 32 * linesize;
- }
-
if (!s->mb_intra) {
/* motion handling */
/* decoding or more than one mb_type (MC was already done otherwise) */
@@ -169,7 +158,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B)
||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I)
|| s->avctx->skip_idct >= AVDISCARD_ALL)
- goto skip_idct;
+ return;
}
/* add dct residue */
@@ -288,14 +277,6 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
} //gray
}
- }
-skip_idct:
- if (!readable) {
- s->hdsp.put_pixels_tab[0][0](s->dest[0], dest_y, linesize, 16);
- if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
- s->hdsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[1], dest_cb, uvlinesize, 16 >> s->chroma_y_shift);
- s->hdsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[2], dest_cr, uvlinesize, 16 >> s->chroma_y_shift);
- }
#endif /* !IS_ENCODER */
}
}
--
2.40.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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 33/57] avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy data
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 33/57] avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy data Andreas Rheinhardt
@ 2024-06-13 7:36 ` Michael Niedermayer
2024-06-13 8:50 ` Andreas Rheinhardt
0 siblings, 1 reply; 87+ messages in thread
From: Michael Niedermayer @ 2024-06-13 7:36 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1645 bytes --]
On Wed, Jun 12, 2024 at 03:48:29PM +0200, Andreas Rheinhardt wrote:
> There is no reason to use a temporary buffer as destination
> for the new macroblock before copying it into its proper place.
>
> (History: 3994623df2efd2749631c3492184dd8d4ffa9d1b changed
> the precursor of ff_mpv_reconstruct_mb() to always decode
> to the first row of macroblocks for B pictures when
> a draw_horiz_band callback is set (they are exported to the caller
> via said callback and each row overwrites the previously decoded
> row; this was probably intended as a cache-optimization).
> Later b68ab2609c67d07b6f12ed65125d76bf9a054479 changed this
> to the current form in which a scratchpad buffer is used when
> decoding B-pictures without draw_horiz_band callback, followed
> by copying the block from the scratchpad buffer to the actual
> destination. I do not know what the aim of this was. When thinking
> of it as a cache optimization, it makes sense to not use it
> when the aforementioned draw_horiz_band optimization is in effect,
> because then the destination row can be presumed to be hot
> already. But then it makes no sense to restrict this optimization
> to B-frames.)
IIRC
The B frames where directly placed in GPU memory, which is slow to read
from, so building up MC + IDCT (which could read depending on caches)
was avoided by a a scratchpad but its really long ago so i might remember
this only partly
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 33/57] avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy data
2024-06-13 7:36 ` Michael Niedermayer
@ 2024-06-13 8:50 ` Andreas Rheinhardt
2024-06-13 21:19 ` Michael Niedermayer
0 siblings, 1 reply; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-13 8:50 UTC (permalink / raw)
To: ffmpeg-devel
Michael Niedermayer:
> On Wed, Jun 12, 2024 at 03:48:29PM +0200, Andreas Rheinhardt wrote:
>> There is no reason to use a temporary buffer as destination
>> for the new macroblock before copying it into its proper place.
>>
>> (History: 3994623df2efd2749631c3492184dd8d4ffa9d1b changed
>> the precursor of ff_mpv_reconstruct_mb() to always decode
>> to the first row of macroblocks for B pictures when
>> a draw_horiz_band callback is set (they are exported to the caller
>> via said callback and each row overwrites the previously decoded
>> row; this was probably intended as a cache-optimization).
>> Later b68ab2609c67d07b6f12ed65125d76bf9a054479 changed this
>> to the current form in which a scratchpad buffer is used when
>> decoding B-pictures without draw_horiz_band callback, followed
>> by copying the block from the scratchpad buffer to the actual
>> destination. I do not know what the aim of this was. When thinking
>> of it as a cache optimization, it makes sense to not use it
>> when the aforementioned draw_horiz_band optimization is in effect,
>> because then the destination row can be presumed to be hot
>> already. But then it makes no sense to restrict this optimization
>> to B-frames.)
>
> IIRC
> The B frames where directly placed in GPU memory, which is slow to read
> from, so building up MC + IDCT (which could read depending on caches)
> was avoided by a a scratchpad but its really long ago so i might remember
> this only partly
>
The code here is not executed for hardware acceleration at all. For the
ordinary case, this copy incurs overhead; furthermore it increases
complexity (and for these reasons no other codec has similar code). So
I'd like to remove it (with an amended commit message that says that
this was done due to concerns about reading from GPU memory). Do you
object to this?
- 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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 33/57] avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy data
2024-06-13 8:50 ` Andreas Rheinhardt
@ 2024-06-13 21:19 ` Michael Niedermayer
0 siblings, 0 replies; 87+ messages in thread
From: Michael Niedermayer @ 2024-06-13 21:19 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2792 bytes --]
On Thu, Jun 13, 2024 at 10:50:36AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Wed, Jun 12, 2024 at 03:48:29PM +0200, Andreas Rheinhardt wrote:
> >> There is no reason to use a temporary buffer as destination
> >> for the new macroblock before copying it into its proper place.
> >>
> >> (History: 3994623df2efd2749631c3492184dd8d4ffa9d1b changed
> >> the precursor of ff_mpv_reconstruct_mb() to always decode
> >> to the first row of macroblocks for B pictures when
> >> a draw_horiz_band callback is set (they are exported to the caller
> >> via said callback and each row overwrites the previously decoded
> >> row; this was probably intended as a cache-optimization).
> >> Later b68ab2609c67d07b6f12ed65125d76bf9a054479 changed this
> >> to the current form in which a scratchpad buffer is used when
> >> decoding B-pictures without draw_horiz_band callback, followed
> >> by copying the block from the scratchpad buffer to the actual
> >> destination. I do not know what the aim of this was. When thinking
> >> of it as a cache optimization, it makes sense to not use it
> >> when the aforementioned draw_horiz_band optimization is in effect,
> >> because then the destination row can be presumed to be hot
> >> already. But then it makes no sense to restrict this optimization
> >> to B-frames.)
> >
> > IIRC
> > The B frames where directly placed in GPU memory, which is slow to read
> > from, so building up MC + IDCT (which could read depending on caches)
> > was avoided by a a scratchpad but its really long ago so i might remember
> > this only partly
> >
>
> The code here is not executed for hardware acceleration at all. For the
> ordinary case, this copy incurs overhead; furthermore it increases
> complexity (and for these reasons no other codec has similar code). So
> I'd like to remove it (with an amended commit message that says that
> this was done due to concerns about reading from GPU memory). Do you
> object to this?
i dont object, i was trying to explain why this was there. This predates
modern hw acceleration. The memory in AVFrame.data[] for a normal
pixel format can be mapped to GPU memory. FFmpeg itself probably did not
set it up this way but some applications did do this with get_buffer()
callbacks VERY long ago IIRC to avoid having to copy the image later
when the application belived the image would not be read from. (like a B frame
in MPEG-2 times)
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The day soldiers stop bringing you their problems is the day you have stopped
leading them. They have either lost confidence that you can help or concluded
you do not care. Either case is a failure of leadership. - Colin Powell
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 34/57] avcodec/mpeg12dec: Disable allocating scratchpad buffers when possible
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (31 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 33/57] avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy data Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 35/57] avcodec/mpegvideo_dec: Don't alloc framesize-bufs in update_thread_ctx Andreas Rheinhardt
` (38 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
They are no longer used by the MPEG-1/2 decoders except when
using lowres.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 4 ++++
libavcodec/mpegpicture.h | 10 ++++++++++
2 files changed, 14 insertions(+)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index e0e9a8fb1e..7485b7c65f 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1000,6 +1000,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
if ((ret = ff_mpv_common_init(s)) < 0)
return ret;
+ if (!s->avctx->lowres)
+ ff_mpv_framesize_disable(&s->sc);
}
return 0;
}
@@ -1874,6 +1876,8 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
if ((ret = ff_mpv_common_init(s)) < 0)
return ret;
+ if (!s->avctx->lowres)
+ ff_mpv_framesize_disable(&s->sc);
for (i = 0; i < 64; i++) {
int j = s->idsp.idct_permutation[i];
diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h
index d3f39bbae6..196aa9b744 100644
--- a/libavcodec/mpegpicture.h
+++ b/libavcodec/mpegpicture.h
@@ -21,6 +21,7 @@
#ifndef AVCODEC_MPEGPICTURE_H
#define AVCODEC_MPEGPICTURE_H
+#include <limits.h>
#include <stddef.h>
#include <stdint.h>
@@ -135,6 +136,15 @@ int ff_mpv_pic_check_linesize(void *logctx, const struct AVFrame *f,
int ff_mpv_framesize_alloc(AVCodecContext *avctx,
ScratchpadContext *sc, int linesize);
+/**
+ * Disable allocating the ScratchpadContext's buffers in future calls
+ * to ff_mpv_framesize_alloc().
+ */
+static inline void ff_mpv_framesize_disable(ScratchpadContext *sc)
+{
+ sc->linesize = INT_MAX;
+}
+
void ff_mpv_unref_picture(MPVWorkPicture *pic);
void ff_mpv_workpic_from_pic(MPVWorkPicture *wpic, MPVPicture *pic);
void ff_mpv_replace_picture(MPVWorkPicture *dst, const MPVWorkPicture *src);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 35/57] avcodec/mpegvideo_dec: Don't alloc framesize-bufs in update_thread_ctx
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (32 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 34/57] avcodec/mpeg12dec: Disable allocating scratchpad buffers when possible Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 36/57] avcodec/mpegvideo_dec: Don't keep droppable in sync " Andreas Rheinhardt
` (37 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is always allocated in ff_mpv_frame_start(), so the only
reason to put it into ff_mpeg_update_thread_context()
would be for the case that a frame-threaded decoder
that supports coded fields implements frame-threading.
The only mpegvideo-decoders supporting coded fields
are MPEG-1/2 and VC-1. The latter's bitstream requires
both coded fields to be part of the same access unit/packet,
so that every frame thread will always call ff_mpv_frame_start()
itself. The former only "need" the framesize buffers when
using lowres. If MPEG-1/2 gains frame-threading, one could either
perform framesize allocation in its update_thread_context
or when starting a field.
(Given that the next packet may trigger a reinitialization
due to a frame size change, it was possible for the buffers
that were allocated here to be thrown away unused.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_dec.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index ad35505819..b3753b6ad2 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -160,14 +160,6 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
s1->bitstream_buffer_size);
}
- // linesize-dependent scratch buffer allocation
- ret = ff_mpv_framesize_alloc(s->avctx, &s->sc, s1->linesize);
- if (ret < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate context "
- "scratch buffers.\n");
- return ret;
- }
-
// MPEG-2/interlacing info
memcpy(&s->progressive_sequence, &s1->progressive_sequence,
(char *) &s1->rtp_mode - (char *) &s1->progressive_sequence);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 36/57] avcodec/mpegvideo_dec: Don't keep droppable in sync in update_thread_ctx
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (33 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 35/57] avcodec/mpegvideo_dec: Don't alloc framesize-bufs in update_thread_ctx Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 37/57] avcodec/mpegutils: Don't output wrong mb skip values Andreas Rheinhardt
` (36 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is not a stream property, but a property of an individual picture
(in fact, it is only set by the FLV decoder that does not even support
frame threading).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_dec.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index b3753b6ad2..e95b5a0940 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -142,7 +142,6 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
// B-frame info
s->max_b_frames = s1->max_b_frames;
s->low_delay = s1->low_delay;
- s->droppable = s1->droppable;
// DivX handling (doesn't work)
s->divx_packed = s1->divx_packed;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 37/57] avcodec/mpegutils: Don't output wrong mb skip values
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (34 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 36/57] avcodec/mpegvideo_dec: Don't keep droppable in sync " Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-13 7:27 ` Michael Niedermayer
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 38/57] avcodec/svq1enc: Stop copying PutBitContext unnecessarily Andreas Rheinhardt
` (35 subsequent siblings)
71 siblings, 1 reply; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The earlier code had two problems:
1. For reference frames that are not directly output (happens unless
low_delay is set), the mb skip values referred to the next reference
frame to be decoded.
2. For non-reference frames, every macroblock was always considered
skipped.
This makes the output (worse than) useless; that no one ever
complained about this shows that this feature is not really used.
It is therefore removed.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h264dec.c | 2 +-
libavcodec/mpegutils.c | 12 ++----------
libavcodec/mpegutils.h | 2 +-
libavcodec/mpegvideo_dec.c | 2 +-
4 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index fd23e367b4..c77d8f42db 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -979,7 +979,7 @@ static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *g
*got_frame = 1;
if (CONFIG_MPEGVIDEODEC) {
- ff_print_debug_info2(h->avctx, dst, NULL,
+ ff_print_debug_info2(h->avctx, dst,
out->mb_type,
out->qscale_table,
out->motion_val,
diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c
index a53996852f..73b6650b70 100644
--- a/libavcodec/mpegutils.c
+++ b/libavcodec/mpegutils.c
@@ -153,7 +153,7 @@ static char get_interlacement_char(int mb_type)
}
void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
- const uint8_t *mbskip_table, const uint32_t *mbtype_table,
+ const uint32_t *mbtype_table,
const int8_t *qscale_table, int16_t (*const motion_val[2])[2],
int mb_width, int mb_height, int mb_stride, int quarter_sample)
{
@@ -248,7 +248,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
return;
- if (avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) {
+ if (avctx->debug & (FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) {
int x,y;
AVBPrint buf;
int n;
@@ -267,8 +267,6 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
av_bprint_chars(&buf, ' ', margin_left);
n = 0;
- if (avctx->debug & FF_DEBUG_SKIP)
- n++;
if (avctx->debug & FF_DEBUG_QP)
n += 2;
if (avctx->debug & FF_DEBUG_MB_TYPE)
@@ -284,12 +282,6 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
for (x = 0; x < mb_width; x++) {
if (x == 0)
av_bprintf(&buf, "%*d ", margin_left - 1, y << 4);
- if (avctx->debug & FF_DEBUG_SKIP) {
- int count = mbskip_table ? mbskip_table[x + y * mb_stride] : 0;
- if (count > 9)
- count = 9;
- av_bprintf(&buf, "%1d", count);
- }
if (avctx->debug & FF_DEBUG_QP) {
av_bprintf(&buf, "%2d", qscale_table[x + y * mb_stride]);
}
diff --git a/libavcodec/mpegutils.h b/libavcodec/mpegutils.h
index 43075191c6..64e69c7746 100644
--- a/libavcodec/mpegutils.h
+++ b/libavcodec/mpegutils.h
@@ -106,7 +106,7 @@ void ff_draw_horiz_band(AVCodecContext *avctx, const AVFrame *cur, const AVFrame
* Print debugging info for the given picture.
*/
void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict,
- const uint8_t *mbskip_table, const uint32_t *mbtype_table,
+ const uint32_t *mbtype_table,
const int8_t *qscale_table, int16_t (*const motion_val[2])[2],
int mb_width, int mb_height, int mb_stride, int quarter_sample);
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index e95b5a0940..4e279d9fa8 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -408,7 +408,7 @@ void ff_mpv_frame_end(MpegEncContext *s)
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
{
- ff_print_debug_info2(s->avctx, pict, s->mbskip_table, p->mb_type,
+ ff_print_debug_info2(s->avctx, pict, p->mb_type,
p->qscale_table, p->motion_val,
s->mb_width, s->mb_height, s->mb_stride, s->quarter_sample);
}
--
2.40.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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 37/57] avcodec/mpegutils: Don't output wrong mb skip values
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 37/57] avcodec/mpegutils: Don't output wrong mb skip values Andreas Rheinhardt
@ 2024-06-13 7:27 ` Michael Niedermayer
2024-06-17 11:08 ` Andreas Rheinhardt
0 siblings, 1 reply; 87+ messages in thread
From: Michael Niedermayer @ 2024-06-13 7:27 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1013 bytes --]
On Wed, Jun 12, 2024 at 03:48:33PM +0200, Andreas Rheinhardt wrote:
> The earlier code had two problems:
> 1. For reference frames that are not directly output (happens unless
> low_delay is set), the mb skip values referred to the next reference
> frame to be decoded.
> 2. For non-reference frames, every macroblock was always considered
> skipped.
> This makes the output (worse than) useless; that no one ever
> complained about this shows that this feature is not really used.
> It is therefore removed.
I used it for statistical purposes long ago, seeing how much blocks where
skiped and for that a +-1 frame difference is inconsequantal. Also
i understood that B frame are handled differently, its an internal
bitstream related number after all
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Some people wanted to paint the bikeshed green, some blue and some pink.
People argued and fought, when they finally agreed, only rust was left.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 37/57] avcodec/mpegutils: Don't output wrong mb skip values
2024-06-13 7:27 ` Michael Niedermayer
@ 2024-06-17 11:08 ` Andreas Rheinhardt
2024-06-18 22:08 ` Michael Niedermayer
0 siblings, 1 reply; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-17 11:08 UTC (permalink / raw)
To: ffmpeg-devel
Michael Niedermayer:
> On Wed, Jun 12, 2024 at 03:48:33PM +0200, Andreas Rheinhardt wrote:
>> The earlier code had two problems:
>> 1. For reference frames that are not directly output (happens unless
>> low_delay is set), the mb skip values referred to the next reference
>> frame to be decoded.
>> 2. For non-reference frames, every macroblock was always considered
>> skipped.
>> This makes the output (worse than) useless; that no one ever
>> complained about this shows that this feature is not really used.
>> It is therefore removed.
>
> I used it for statistical purposes long ago, seeing how much blocks where
> skiped and for that a +-1 frame difference is inconsequantal. Also
> i understood that B frame are handled differently, its an internal
> bitstream related number after all
Does "long ago" mean that you agree that it is unused and can be removed?
- 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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 37/57] avcodec/mpegutils: Don't output wrong mb skip values
2024-06-17 11:08 ` Andreas Rheinhardt
@ 2024-06-18 22:08 ` Michael Niedermayer
2024-06-19 13:54 ` Andreas Rheinhardt
0 siblings, 1 reply; 87+ messages in thread
From: Michael Niedermayer @ 2024-06-18 22:08 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1452 bytes --]
On Mon, Jun 17, 2024 at 01:08:56PM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Wed, Jun 12, 2024 at 03:48:33PM +0200, Andreas Rheinhardt wrote:
> >> The earlier code had two problems:
> >> 1. For reference frames that are not directly output (happens unless
> >> low_delay is set), the mb skip values referred to the next reference
> >> frame to be decoded.
> >> 2. For non-reference frames, every macroblock was always considered
> >> skipped.
> >> This makes the output (worse than) useless; that no one ever
> >> complained about this shows that this feature is not really used.
> >> It is therefore removed.
> >
> > I used it for statistical purposes long ago, seeing how much blocks where
> > skiped and for that a +-1 frame difference is inconsequantal. Also
> > i understood that B frame are handled differently, its an internal
> > bitstream related number after all
>
> Does "long ago" mean that you agree that it is unused and can be removed?
It simply means that it was usefull and a number similar could be usefull
again. I dont care much about it, judging from the past i might use this once
in 10 years, if its available. If its not available its not.
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 37/57] avcodec/mpegutils: Don't output wrong mb skip values
2024-06-18 22:08 ` Michael Niedermayer
@ 2024-06-19 13:54 ` Andreas Rheinhardt
0 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-19 13:54 UTC (permalink / raw)
To: ffmpeg-devel
Michael Niedermayer:
> On Mon, Jun 17, 2024 at 01:08:56PM +0200, Andreas Rheinhardt wrote:
>> Michael Niedermayer:
>>> On Wed, Jun 12, 2024 at 03:48:33PM +0200, Andreas Rheinhardt wrote:
>>>> The earlier code had two problems:
>>>> 1. For reference frames that are not directly output (happens unless
>>>> low_delay is set), the mb skip values referred to the next reference
>>>> frame to be decoded.
>>>> 2. For non-reference frames, every macroblock was always considered
>>>> skipped.
>>>> This makes the output (worse than) useless; that no one ever
>>>> complained about this shows that this feature is not really used.
>>>> It is therefore removed.
>>>
>>> I used it for statistical purposes long ago, seeing how much blocks where
>>> skiped and for that a +-1 frame difference is inconsequantal. Also
>>> i understood that B frame are handled differently, its an internal
>>> bitstream related number after all
>>
>> Does "long ago" mean that you agree that it is unused and can be removed?
>
> It simply means that it was usefull and a number similar could be usefull
> again. I dont care much about it, judging from the past i might use this once
> in 10 years, if its available. If its not available its not.
>
Ok, then I'll apply this patchset tomorrow (unless there are any
objections by anyone or unless you (or anyone) wants more time to look
at it).
- 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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 38/57] avcodec/svq1enc: Stop copying PutBitContext unnecessarily
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (35 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 37/57] avcodec/mpegutils: Don't output wrong mb skip values Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 39/57] avcodec/ituh263enc: Inline constants Andreas Rheinhardt
` (34 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Possible since 404fe63e23433aa559cee5366cb26f78b425e7e5.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1enc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 6e687166b8..4065c9b21a 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -468,16 +468,14 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
put_bits(&s->reorder_pb[5], SVQ1_BLOCK_INTER_LEN, SVQ1_BLOCK_INTER_CODE);
- s->m.pb = s->reorder_pb[5];
mx = motion_ptr[0];
my = motion_ptr[1];
av_assert1(mx >= -32 && mx <= 31);
av_assert1(my >= -32 && my <= 31);
av_assert1(pred_x >= -32 && pred_x <= 31);
av_assert1(pred_y >= -32 && pred_y <= 31);
- ff_h263_encode_motion(&s->m.pb, mx - pred_x, 1);
- ff_h263_encode_motion(&s->m.pb, my - pred_y, 1);
- s->reorder_pb[5] = s->m.pb;
+ ff_h263_encode_motion(&s->reorder_pb[5], mx - pred_x, 1);
+ ff_h263_encode_motion(&s->reorder_pb[5], my - pred_y, 1);
score[1] += lambda * put_bits_count(&s->reorder_pb[5]);
dxy = (mx & 1) + 2 * (my & 1);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 39/57] avcodec/ituh263enc: Inline constants
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (36 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 38/57] avcodec/svq1enc: Stop copying PutBitContext unnecessarily Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 40/57] avcodec/h263enc: Remove no-output code Andreas Rheinhardt
` (33 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263enc.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index b1fe4e241e..3982b1e675 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -709,9 +709,8 @@ void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code)
int range, bit_size, sign, code, bits;
if (val == 0) {
- /* zero vector */
- code = 0;
- put_bits(pb, ff_mvtab[code][1], ff_mvtab[code][0]);
+ /* zero vector -- corresponds to ff_mvtab[0] */
+ put_bits(pb, 1, 1);
} else {
bit_size = f_code - 1;
range = 1 << bit_size;
@@ -741,7 +740,7 @@ static av_cold void init_mv_penalty_and_fcode(void)
for(mv=-MAX_DMV; mv<=MAX_DMV; mv++){
int len;
- if(mv==0) len= ff_mvtab[0][1];
+ if (mv==0) len = 1; // ff_mvtab[0][1]
else{
int val, bit_size, code;
@@ -755,7 +754,7 @@ static av_cold void init_mv_penalty_and_fcode(void)
if(code<33){
len= ff_mvtab[code][1] + 1 + bit_size;
}else{
- len= ff_mvtab[32][1] + av_log2(code>>5) + 2 + bit_size;
+ len = 12 /* ff_mvtab[32][1] */ + av_log2(code>>5) + 2 + bit_size;
}
}
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 40/57] avcodec/h263enc: Remove no-output code
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (37 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 39/57] avcodec/ituh263enc: Inline constants Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 41/57] avcodec/mpeg4videodec: Inline constants Andreas Rheinhardt
` (32 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The no-output mode (guarded by AV_CODEC_FLAG2_NO_OUTPUT)
does not provide a noteworthy speedup; in fact, it even
turned out to be slower than the code with the no-output
code removed (ordinary encode: 153259721 decicycles,
noout encode: 153259721; encode with this patch applied:
152451581 decicycles; timings are for encode_frame callbacks
when encoding a 1080p sample to MPEG-4).
(Furthermore, this code was broken for most of its existence
(since 9207dc3b0db368bb9cf5eb295cbc1129c2975e31) and no one
noticed, so the no-output mode is probably not used at all.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263enc.h | 29 ++---------------------------
1 file changed, 2 insertions(+), 27 deletions(-)
diff --git a/libavcodec/h263enc.h b/libavcodec/h263enc.h
index 6e07440b30..784500ca7a 100644
--- a/libavcodec/h263enc.h
+++ b/libavcodec/h263enc.h
@@ -37,36 +37,11 @@ void ff_clean_h263_qscales(MpegEncContext *s);
void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code);
void ff_h263_update_mb(MpegEncContext *s);
-static inline int h263_get_motion_length(int val, int f_code)
-{
- int bit_size, code, sign;
-
- if (val == 0) {
- return 1; /* ff_mvtab[0][1] */
- } else {
- bit_size = f_code - 1;
- /* modulo encoding */
- val = sign_extend(val, 6 + bit_size);
- sign = val >> 31;
- val = (val ^ sign) - sign; /* val = FFABS(val) */
- val--;
- code = (val >> bit_size) + 1;
-
- return ff_mvtab[code][1] + 1 + bit_size;
- }
-}
-
static inline void ff_h263_encode_motion_vector(MpegEncContext * s,
int x, int y, int f_code)
{
- if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) {
- skip_put_bits(&s->pb,
- h263_get_motion_length(x, f_code) +
- h263_get_motion_length(y, f_code));
- } else {
- ff_h263_encode_motion(&s->pb, x, f_code);
- ff_h263_encode_motion(&s->pb, y, f_code);
- }
+ ff_h263_encode_motion(&s->pb, x, f_code);
+ ff_h263_encode_motion(&s->pb, y, f_code);
}
static inline int get_p_cbp(MpegEncContext * s,
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 41/57] avcodec/mpeg4videodec: Inline constants
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (38 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 40/57] avcodec/h263enc: Remove no-output code Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-13 7:16 ` Michael Niedermayer
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 42/57] avcodec/mpeg4videodec: Don't initialize unused stuff Andreas Rheinhardt
` (31 subsequent siblings)
71 siblings, 1 reply; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Partitioned macroblocks are always 8bit and not studio profile.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videodec.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 116dc1507e..f1b542cebf 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -949,8 +949,7 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
int dir = 0;
mb_num++;
- ff_update_block_index(s, s->avctx->bits_per_raw_sample,
- s->avctx->lowres, s->chroma_x_shift);
+ ff_update_block_index(s, 8, s->avctx->lowres, 1);
if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1)
s->first_slice_line = 0;
@@ -1141,8 +1140,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
const int xy = s->mb_x + s->mb_y * s->mb_stride;
mb_num++;
- ff_update_block_index(s, s->avctx->bits_per_raw_sample,
- s->avctx->lowres, s->chroma_x_shift);
+ ff_update_block_index(s, 8, s->avctx->lowres, 1);
if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1)
s->first_slice_line = 0;
--
2.40.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] 87+ messages in thread
* Re: [FFmpeg-devel] [PATCH 41/57] avcodec/mpeg4videodec: Inline constants
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 41/57] avcodec/mpeg4videodec: Inline constants Andreas Rheinhardt
@ 2024-06-13 7:16 ` Michael Niedermayer
0 siblings, 0 replies; 87+ messages in thread
From: Michael Niedermayer @ 2024-06-13 7:16 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 675 bytes --]
On Wed, Jun 12, 2024 at 03:48:37PM +0200, Andreas Rheinhardt wrote:
> Partitioned macroblocks are always 8bit and not studio profile.
This is not true
Table 9-1 -- Tools for Version 1 Visual Object Types
data partitioning allows N-Bit object Type, theres a "x" there
Thing is we dont fully support N-bit so it may look like that but
studio profile != N-bit
some other of your patches also look like they remove N-bit related code
[...]
thx
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 42/57] avcodec/mpeg4videodec: Don't initialize unused stuff
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (39 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 41/57] avcodec/mpeg4videodec: Inline constants Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 43/57] avcodec/vc1_block: Remove unnecessary assignments Andreas Rheinhardt
` (30 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Only the intra scantable is used for studio profile.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videodec.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index f1b542cebf..18329132aa 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3430,21 +3430,8 @@ static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
s->q_scale_type = get_bits1(gb);
}
- if (s->alternate_scan) {
- ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan);
- ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);
- ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_vertical_scan,
- s->idsp.idct_permutation);
- ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan,
- s->idsp.idct_permutation);
- } else {
- ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct);
- ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);
- ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_horizontal_scan,
- s->idsp.idct_permutation);
- ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan,
- s->idsp.idct_permutation);
- }
+ ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable,
+ s->alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct);
mpeg4_load_default_matrices(s);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 43/57] avcodec/vc1_block: Remove unnecessary assignments
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (40 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 42/57] avcodec/mpeg4videodec: Don't initialize unused stuff Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 44/57] avcodec/vc1_block: Simplify resetting coded_block Andreas Rheinhardt
` (29 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vc1_block.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 640f7329ca..384979caf5 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -2675,12 +2675,11 @@ static int vc1_decode_i_blocks_adv(VC1Context *v)
}
// do frame decode
- s->mb_x = s->mb_y = 0;
s->mb_intra = 1;
s->first_slice_line = 1;
+ s->mb_x = 0;
s->mb_y = s->start_mb_y;
if (s->start_mb_y) {
- s->mb_x = 0;
init_block_index(v);
memset(&s->coded_block[s->block_index[0] - s->b8_stride], 0,
(1 + s->b8_stride) * sizeof(*s->coded_block));
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 44/57] avcodec/vc1_block: Simplify resetting coded_block
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (41 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 43/57] avcodec/vc1_block: Remove unnecessary assignments Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 45/57] avcodec/mpeg4videodec: Remove always-false check Andreas Rheinhardt
` (28 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything that init_block_index() sets will be overwritten
a few lines below again, so don't call it and simply calculate
the only thing that is used (namely block_index[0]) manually.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vc1_block.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 384979caf5..1d622b1a67 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -2680,8 +2680,7 @@ static int vc1_decode_i_blocks_adv(VC1Context *v)
s->mb_x = 0;
s->mb_y = s->start_mb_y;
if (s->start_mb_y) {
- init_block_index(v);
- memset(&s->coded_block[s->block_index[0] - s->b8_stride], 0,
+ memset(&s->coded_block[(2 * s->mb_y - 1) * s->b8_stride - 2], 0,
(1 + s->b8_stride) * sizeof(*s->coded_block));
}
for (; s->mb_y < s->end_mb_y; s->mb_y++) {
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 45/57] avcodec/mpeg4videodec: Remove always-false check
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (42 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 44/57] avcodec/vc1_block: Simplify resetting coded_block Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 46/57] avcodec/mpeg12enc: Use AVCodecContext, not priv ctx as logctx Andreas Rheinhardt
` (27 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
All valid values of dc_lum and dc_chrom are in the range 0..9,
because they are initialized via tables with 10 elements.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videodec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 18329132aa..130cde7a9d 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -895,7 +895,7 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
else
code = get_vlc2(&s->gb, dc_chrom, DC_VLC_BITS, 1);
- if (code < 0 || code > 9 /* && s->nbit < 9 */) {
+ if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
return AVERROR_INVALIDDATA;
}
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 46/57] avcodec/mpeg12enc: Use AVCodecContext, not priv ctx as logctx
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (43 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 45/57] avcodec/mpeg4videodec: Remove always-false check Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 47/57] avcodec/mpeg12enc: Pass AVCodecContext* directly Andreas Rheinhardt
` (26 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12enc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index ba56f0c37a..3948dbe599 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -180,7 +180,6 @@ static int find_frame_rate_index(MPEG12EncContext *mpeg12)
static av_cold int encode_init(AVCodecContext *avctx)
{
MPEG12EncContext *const mpeg12 = avctx->priv_data;
- MpegEncContext *const s = &mpeg12->mpeg;
int ret;
int max_size = avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 16383 : 4095;
@@ -259,7 +258,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
if (mpeg12->tc_opt_str) {
AVRational rate = ff_mpeg12_frame_rate_tab[mpeg12->frame_rate_index];
- int ret = av_timecode_init_from_string(&mpeg12->tc, rate, mpeg12->tc_opt_str, s);
+ int ret = av_timecode_init_from_string(&mpeg12->tc, rate, mpeg12->tc_opt_str, avctx);
if (ret < 0)
return ret;
mpeg12->drop_frame_timecode = !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 47/57] avcodec/mpeg12enc: Pass AVCodecContext* directly
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (44 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 46/57] avcodec/mpeg12enc: Use AVCodecContext, not priv ctx as logctx Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 48/57] avcodec/msmpeg4enc: Combine writing bits Andreas Rheinhardt
` (25 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12enc.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 3948dbe599..b840fe887d 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -137,16 +137,15 @@ av_cold void ff_mpeg1_init_uni_ac_vlc(const int8_t max_level[],
}
#if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER
-static int find_frame_rate_index(MPEG12EncContext *mpeg12)
+static int find_frame_rate_index(AVCodecContext *avctx, MPEG12EncContext *mpeg12)
{
- MpegEncContext *const s = &mpeg12->mpeg;
int i;
AVRational bestq = (AVRational) {0, 0};
AVRational ext;
- AVRational target = av_inv_q(s->avctx->time_base);
+ AVRational target = av_inv_q(avctx->time_base);
for (i = 1; i < 14; i++) {
- if (s->avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL &&
+ if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL &&
i >= 9)
break;
@@ -154,7 +153,7 @@ static int find_frame_rate_index(MPEG12EncContext *mpeg12)
for (ext.den=1; ext.den <= 32; ext.den++) {
AVRational q = av_mul_q(ext, ff_mpeg12_frame_rate_tab[i]);
- if (s->codec_id != AV_CODEC_ID_MPEG2VIDEO && (ext.den!=1 || ext.num!=1))
+ if (avctx->codec_id != AV_CODEC_ID_MPEG2VIDEO && (ext.den!=1 || ext.num!=1))
continue;
if (av_gcd(ext.den, ext.num) != 1)
continue;
@@ -236,7 +235,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
if ((ret = ff_mpv_encode_init(avctx)) < 0)
return ret;
- if (find_frame_rate_index(mpeg12) < 0) {
+ if (find_frame_rate_index(avctx, mpeg12) < 0) {
if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
av_log(avctx, AV_LOG_ERROR, "MPEG-1/2 does not support %d/%d fps\n",
avctx->time_base.den, avctx->time_base.num);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 48/57] avcodec/msmpeg4enc: Combine writing bits
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (45 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 47/57] avcodec/mpeg12enc: Pass AVCodecContext* directly Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 49/57] avcodec/h261dec: Don't reset gob_start_code_skipped in h261_decode_init() Andreas Rheinhardt
` (24 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/msmpeg4enc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 642a0ff100..3103a73663 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -71,8 +71,7 @@ void ff_msmpeg4_code012(PutBitContext *pb, int n)
if (n == 0) {
put_bits(pb, 1, 0);
} else {
- put_bits(pb, 1, 1);
- put_bits(pb, 1, (n >= 2));
+ put_bits(pb, 2, 2 | (n >= 2));
}
}
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 49/57] avcodec/h261dec: Don't reset gob_start_code_skipped in h261_decode_init()
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (46 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 48/57] avcodec/msmpeg4enc: Combine writing bits Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 50/57] avcodec/h261dec: Fix UB NULL + 0, remove broken resync code Andreas Rheinhardt
` (23 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It always gets reset at the start of h261_decode_frame().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index be285ce5e9..8671800c3e 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -97,8 +97,6 @@ static av_cold int h261_decode_init(AVCodecContext *avctx)
s->low_delay = 1;
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
- h->gob_start_code_skipped = 0;
-
ff_thread_once(&init_static_once, h261_decode_init_static);
return 0;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 50/57] avcodec/h261dec: Fix UB NULL + 0, remove broken resync code
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (47 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 49/57] avcodec/h261dec: Don't reset gob_start_code_skipped in h261_decode_init() Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 51/57] avcodec/h261dec: Simplify decoding GOB header Andreas Rheinhardt
` (22 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
last_resync_gb is never initialized, causing NULL + 0
in align_get_bits(). In addition to that, the loop is never
entered.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 18 +-----------------
1 file changed, 1 insertion(+), 17 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 8671800c3e..2038afc591 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -172,7 +172,7 @@ static int h261_decode_gob_header(H261DecContext *h)
static int h261_resync(H261DecContext *h)
{
MpegEncContext *const s = &h->s;
- int left, ret;
+ int ret;
if (h->gob_start_code_skipped) {
ret = h261_decode_gob_header(h);
@@ -185,22 +185,6 @@ static int h261_resync(H261DecContext *h)
return 0;
}
// OK, it is not where it is supposed to be ...
- s->gb = s->last_resync_gb;
- align_get_bits(&s->gb);
- left = get_bits_left(&s->gb);
-
- for (; left > 15 + 1 + 4 + 5; left -= 8) {
- if (show_bits(&s->gb, 15) == 0) {
- GetBitContext bak = s->gb;
-
- ret = h261_decode_gob_header(h);
- if (ret >= 0)
- return 0;
-
- s->gb = bak;
- }
- skip_bits(&s->gb, 8);
- }
}
return -1;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 51/57] avcodec/h261dec: Simplify decoding GOB header
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (48 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 50/57] avcodec/h261dec: Fix UB NULL + 0, remove broken resync code Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 52/57] avcodec/mpv_reconstruct_mb_template: Optimize always-true branch away Andreas Rheinhardt
` (21 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
h261_resync() can be completely removed, because
h261_decode_gob_header() checks for a GOB header itself if
gob_start_code_skipped is zero.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 27 +--------------------------
1 file changed, 1 insertion(+), 26 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 2038afc591..f1c1e1a48a 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -165,31 +165,6 @@ static int h261_decode_gob_header(H261DecContext *h)
return 0;
}
-/**
- * Decode the group of blocks / video packet header.
- * @return <0 if no resync found
- */
-static int h261_resync(H261DecContext *h)
-{
- MpegEncContext *const s = &h->s;
- int ret;
-
- if (h->gob_start_code_skipped) {
- ret = h261_decode_gob_header(h);
- if (ret >= 0)
- return 0;
- } else {
- if (show_bits(&s->gb, 15) == 0) {
- ret = h261_decode_gob_header(h);
- if (ret >= 0)
- return 0;
- }
- // OK, it is not where it is supposed to be ...
- }
-
- return -1;
-}
-
/**
* Decode skipped macroblocks.
* @return 0
@@ -626,7 +601,7 @@ static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict,
s->mb_y = 0;
while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {
- if (h261_resync(h) < 0)
+ if (h261_decode_gob_header(h) < 0)
break;
h261_decode_gob(h);
}
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 52/57] avcodec/mpv_reconstruct_mb_template: Optimize always-true branch away
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (49 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 51/57] avcodec/h261dec: Simplify decoding GOB header Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 53/57] avcodec/mpegvideo_dec: Remove unnecessary FFMIN Andreas Rheinhardt
` (20 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
There are only two mpegvideo decoders that use another
(software) pixel format than YUV420: MPEG-1/2 and
the MPEG-4 studio profile. Neither of these use this part
of the code, so one can optimize the 422 code away when
this code is compiled for the decoder.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpv_reconstruct_mb_template.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/mpv_reconstruct_mb_template.c b/libavcodec/mpv_reconstruct_mb_template.c
index e39b3d0e73..257767e80b 100644
--- a/libavcodec/mpv_reconstruct_mb_template.c
+++ b/libavcodec/mpv_reconstruct_mb_template.c
@@ -172,7 +172,8 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
- if (s->chroma_y_shift) {
+ av_assert2(IS_ENCODER || s->chroma_y_shift);
+ if (!IS_ENCODER || s->chroma_y_shift) {
add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
} else {
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 53/57] avcodec/mpegvideo_dec: Remove unnecessary FFMIN
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (50 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 52/57] avcodec/mpv_reconstruct_mb_template: Optimize always-true branch away Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 54/57] avcodec/mpegvideo: Join loops when initializing ScanTable Andreas Rheinhardt
` (19 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
No mpegvideo-based decoder supports lowres > 3,
so the FFMIN here are unnecessary.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_dec.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 4e279d9fa8..684f31947c 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -483,11 +483,13 @@ static inline int hpel_motion_lowres(MpegEncContext *s,
int motion_x, int motion_y)
{
const int lowres = s->avctx->lowres;
- const int op_index = FFMIN(lowres, 3);
+ const int op_index = lowres;
const int s_mask = (2 << lowres) - 1;
int emu = 0;
int sx, sy;
+ av_assert2(op_index <= 3);
+
if (s->quarter_sample) {
motion_x /= 2;
motion_y /= 2;
@@ -536,12 +538,15 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, sx, sy, uvsx, uvsy;
ptrdiff_t uvlinesize, linesize;
const int lowres = s->avctx->lowres;
- const int op_index = FFMIN(lowres - 1 + s->chroma_x_shift, 3);
+ const int op_index = lowres - 1 + s->chroma_x_shift;
const int block_s = 8 >> lowres;
const int s_mask = (2 << lowres) - 1;
const int h_edge_pos = s->h_edge_pos >> lowres;
const int v_edge_pos = s->v_edge_pos >> lowres;
int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h;
+
+ av_assert2(op_index <= 3);
+
linesize = s->cur_pic.linesize[0] << field_based;
uvlinesize = s->cur_pic.linesize[1] << field_based;
@@ -666,7 +671,7 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s,
int mx, int my)
{
const int lowres = s->avctx->lowres;
- const int op_index = FFMIN(lowres, 3);
+ const int op_index = lowres;
const int block_s = 8 >> lowres;
const int s_mask = (2 << lowres) - 1;
const int h_edge_pos = s->h_edge_pos >> lowres + 1;
@@ -675,6 +680,8 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s,
ptrdiff_t offset;
const uint8_t *ptr;
+ av_assert2(op_index <= 3);
+
if (s->quarter_sample) {
mx /= 2;
my /= 2;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 54/57] avcodec/mpegvideo: Join loops when initializing ScanTable
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (51 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 53/57] avcodec/mpegvideo_dec: Remove unnecessary FFMIN Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 55/57] avcodec/mpv_reconstruct_mb_template: Optimize WMV2 code away if possible Andreas Rheinhardt
` (18 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 27f7ebf933..4b5b864b83 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -296,20 +296,13 @@ static av_cold void dsp_init(MpegEncContext *s)
av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
const uint8_t *src_scantable)
{
- int end;
-
st->scantable = src_scantable;
- for (int i = 0; i < 64; i++) {
+ for (int i = 0, end = -1; i < 64; i++) {
int j = src_scantable[i];
st->permutated[i] = permutation[j];
- }
-
- end = -1;
- for (int i = 0; i < 64; i++) {
- int j = st->permutated[i];
- if (j > end)
- end = j;
+ if (permutation[j] > end)
+ end = permutation[j];
st->raster_end[i] = end;
}
}
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 55/57] avcodec/mpv_reconstruct_mb_template: Optimize WMV2 code away if possible
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (52 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 54/57] avcodec/mpegvideo: Join loops when initializing ScanTable Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 56/57] avcodec/mpeg4videodec: Don't initialize unused inter_scantable Andreas Rheinhardt
` (17 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The WMV2 decoder does not support lowres, so one can optimize
the WMV2 specific code away in the lowres version of this function.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpv_reconstruct_mb_template.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpv_reconstruct_mb_template.c b/libavcodec/mpv_reconstruct_mb_template.c
index 257767e80b..4b16974827 100644
--- a/libavcodec/mpv_reconstruct_mb_template.c
+++ b/libavcodec/mpv_reconstruct_mb_template.c
@@ -187,7 +187,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
}
#if !IS_ENCODER
- else if (is_mpeg12 == DEFINITELY_MPEG12 || (s->codec_id != AV_CODEC_ID_WMV2)) {
+ else if (is_mpeg12 == DEFINITELY_MPEG12 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) {
add_dct(s, block[0], 0, dest_y , dct_linesize);
add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 56/57] avcodec/mpeg4videodec: Don't initialize unused inter_scantable
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (53 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 55/57] avcodec/mpv_reconstruct_mb_template: Optimize WMV2 code away if possible Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 57/57] avcodec/mpeg_er: Don't set block_index unnecessarily Andreas Rheinhardt
` (16 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
inter_scantable is only used by the dct_unquantize_h263_inter
functions, yet this is not used by the MPEG-4 decoder at all
(in case H.263 quantization is used, the unquantization already
happens in mpeg4_decode_block()).
Also move the common initialization of ff_permute_scantable()
out of the if.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videodec.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 130cde7a9d..77bd3e9947 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3251,22 +3251,17 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
} else
s->alternate_scan = 0;
}
-
if (s->alternate_scan) {
- ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan);
ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);
ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_vertical_scan,
s->idsp.idct_permutation);
- ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan,
- s->idsp.idct_permutation);
} else {
- ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct);
ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);
ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_horizontal_scan,
s->idsp.idct_permutation);
- ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan,
- s->idsp.idct_permutation);
}
+ ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan,
+ s->idsp.idct_permutation);
/* Skip at this point when only parsing since the remaining
* data is not useful for a parser and requires the
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 57/57] avcodec/mpeg_er: Don't set block_index unnecessarily
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (54 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 56/57] avcodec/mpeg4videodec: Don't initialize unused inter_scantable Andreas Rheinhardt
@ 2024-06-12 13:48 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 58/67] avcodec/h261enc, msmpeg4: Avoid setting dc_scale_tables unnecessarily Andreas Rheinhardt
` (15 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-12 13:48 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
ff_init_block_index() sets MpegEncContext.dest and
MpegEncContext.block_index. The latter is unused by
ff_mpv_reconstruct_mb() (which is what this code is
preparatory for) and dest is overwritten a few lines below.
So don't initialize block_index at all.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg_er.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c
index e7b3197bb1..fe7dcd7efb 100644
--- a/libavcodec/mpeg_er.c
+++ b/libavcodec/mpeg_er.c
@@ -76,10 +76,6 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
s->mcsel = 0;
memcpy(s->mv, mv, sizeof(*mv));
- ff_init_block_index(s);
- ff_update_block_index(s, s->avctx->bits_per_raw_sample,
- s->avctx->lowres, s->chroma_x_shift);
-
s->bdsp.clear_blocks(s->block[0]);
if (!s->chroma_y_shift)
s->bdsp.clear_blocks(s->block[6]);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 58/67] avcodec/h261enc, msmpeg4: Avoid setting dc_scale_tables unnecessarily
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (55 preceding siblings ...)
2024-06-12 13:48 ` [FFmpeg-devel] [PATCH 57/57] avcodec/mpeg_er: Don't set block_index unnecessarily Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 59/67] avcodec/h261dec: Unquantize coefficients while parsing them Andreas Rheinhardt
` (14 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is unnecessary because ff_mpeg1_dc_scale_table is the default
for both dc_scale_tables.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261enc.c | 3 ---
libavcodec/msmpeg4.c | 4 +---
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 01bce533a0..dd4419ec8c 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -34,7 +34,6 @@
#include "mpegvideo.h"
#include "h261.h"
#include "h261enc.h"
-#include "mpegvideodata.h"
#include "mpegvideoenc.h"
static uint8_t uni_h261_rl_len [64*64*2*2];
@@ -388,8 +387,6 @@ av_cold int ff_h261_encode_init(MpegEncContext *s)
s->min_qcoeff = -127;
s->max_qcoeff = 127;
- s->y_dc_scale_table =
- s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
s->ac_esc_length = 6+6+8;
s->intra_ac_vlc_length = s->inter_ac_vlc_length = uni_h261_rl_len;
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 50fd581a83..872dc8db67 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -41,7 +41,6 @@
#include "mpeg4videodata.h"
#include "msmpeg4data.h"
#include "msmpeg4_vc1_data.h"
-#include "mpegvideodata.h"
/*
* You can also call this codec: MPEG-4 with a twist!
@@ -122,8 +121,7 @@ av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
switch(s->msmpeg4_version){
case MSMP4_V1:
case MSMP4_V2:
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
+ // Correct *_dc_scale_tables (ff_mpeg1_dc_scale_table) is the default
break;
case MSMP4_V3:
if(s->workaround_bugs){
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 59/67] avcodec/h261dec: Unquantize coefficients while parsing them
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (56 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 58/67] avcodec/h261enc, msmpeg4: Avoid setting dc_scale_tables unnecessarily Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 60/67] avcodec/h261dec: Simplify decoding motion vectors Andreas Rheinhardt
` (13 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is beneficial for performance: When concatenating
the file from the vsynth1-h261 fate-test 100 times,
performance (measured by timing the codec's decode callback)
improved by 9.6%.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 11 +++++++++--
libavcodec/mpegvideo_dec.c | 11 ++++++-----
libavcodec/mpegvideo_enc.c | 2 +-
libavcodec/mpv_reconstruct_mb_template.c | 24 ++++++++++++------------
4 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index f1c1e1a48a..6df8588bb6 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -244,6 +244,7 @@ static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded
int level, i, j, run;
const RLTable *rl = &ff_h261_rl_tcoeff;
const uint8_t *scan_table;
+ const int qmul = s->qscale << 1, qadd = (s->qscale - 1) | 1;
/* For the variable length encoding there are two code tables, one being
* used for the first transmitted LEVEL in INTER, INTER + MC and
@@ -265,7 +266,7 @@ static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded
* being coded as 1111 1111. */
if (level == 255)
level = 128;
- block[0] = level;
+ block[0] = level * s->y_dc_scale;
i = 1;
} else if (coded) {
// Run Level Code
@@ -276,7 +277,8 @@ static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded
i = 0;
if (check & 0x2) {
skip_bits(&s->gb, 2);
- block[0] = (check & 0x1) ? -1 : 1;
+ block[0] = qmul + qadd;
+ block[0] *= (check & 0x1) ? -1 : 1;
i = 1;
}
} else {
@@ -306,10 +308,15 @@ static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded
run = SHOW_UBITS(re, &s->gb, 6) + 1;
SKIP_CACHE(re, &s->gb, 6);
level = SHOW_SBITS(re, &s->gb, 8);
+ if (level > 0)
+ level = level * qmul + qadd;
+ else if (level < 0)
+ level = level * qmul - qadd;
SKIP_COUNTER(re, &s->gb, 6 + 8);
} else if (level == 0) {
break;
} else {
+ level = level * qmul + qadd;
if (SHOW_UBITS(re, &s->gb, 1))
level = -level;
SKIP_COUNTER(re, &s->gb, 1);
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 684f31947c..da88a35120 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -927,15 +927,16 @@ void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
}
}
+ av_assert2((s->out_format <= FMT_H261) == (s->out_format == FMT_H261 || s->out_format == FMT_MPEG1));
if (!s->avctx->lowres) {
#if !CONFIG_SMALL
- if (s->out_format == FMT_MPEG1)
- mpv_reconstruct_mb_internal(s, block, 0, DEFINITELY_MPEG12);
+ if (s->out_format <= FMT_H261)
+ mpv_reconstruct_mb_internal(s, block, 0, DEFINITELY_MPEG12_H261);
else
- mpv_reconstruct_mb_internal(s, block, 0, NOT_MPEG12);
+ mpv_reconstruct_mb_internal(s, block, 0, NOT_MPEG12_H261);
#else
- mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12);
+ mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12_H261);
#endif
} else
- mpv_reconstruct_mb_internal(s, block, 1, MAY_BE_MPEG12);
+ mpv_reconstruct_mb_internal(s, block, 1, MAY_BE_MPEG12_H261);
}
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 125d16e694..d05a93d249 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1101,7 +1101,7 @@ static void mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
}
}
- mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12);
+ mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12_H261);
}
static int get_sae(const uint8_t *src, int ref, int stride)
diff --git a/libavcodec/mpv_reconstruct_mb_template.c b/libavcodec/mpv_reconstruct_mb_template.c
index 4b16974827..dca982ae0f 100644
--- a/libavcodec/mpv_reconstruct_mb_template.c
+++ b/libavcodec/mpv_reconstruct_mb_template.c
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#define NOT_MPEG12 0
-#define MAY_BE_MPEG12 1
-#define DEFINITELY_MPEG12 2
+#define NOT_MPEG12_H261 0
+#define MAY_BE_MPEG12_H261 1
+#define DEFINITELY_MPEG12_H261 2
/* put block[] to dest[] */
static inline void put_dct(MpegEncContext *s,
@@ -56,14 +56,14 @@ static av_always_inline
void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
int lowres_flag, int is_mpeg12)
{
-#define IS_MPEG12(s) (is_mpeg12 == MAY_BE_MPEG12 ? ((s)->out_format == FMT_MPEG1) : is_mpeg12)
+#define IS_MPEG12_H261(s) (is_mpeg12 == MAY_BE_MPEG12_H261 ? ((s)->out_format <= FMT_H261) : is_mpeg12)
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
s->cur_pic.qscale_table[mb_xy] = s->qscale;
/* update DC predictors for P macroblocks */
if (!s->mb_intra) {
- if (is_mpeg12 != DEFINITELY_MPEG12 && (s->h263_pred || s->h263_aic)) {
+ if (is_mpeg12 != DEFINITELY_MPEG12_H261 && (s->h263_pred || s->h263_aic)) {
if (s->mbintra_table[mb_xy])
ff_clean_intra_table_entries(s);
} else {
@@ -71,7 +71,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
s->last_dc[1] =
s->last_dc[2] = 128 << s->intra_dc_precision;
}
- } else if (is_mpeg12 != DEFINITELY_MPEG12 && (s->h263_pred || s->h263_aic))
+ } else if (is_mpeg12 != DEFINITELY_MPEG12_H261 && (s->h263_pred || s->h263_aic))
s->mbintra_table[mb_xy] = 1;
#if IS_ENCODER
@@ -110,7 +110,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
/* decoding or more than one mb_type (MC was already done otherwise) */
#if !IS_ENCODER
- if (HAVE_THREADS && is_mpeg12 != DEFINITELY_MPEG12 &&
+ if (HAVE_THREADS && is_mpeg12 != DEFINITELY_MPEG12_H261 &&
s->avctx->active_thread_type & FF_THREAD_FRAME) {
if (s->mv_dir & MV_DIR_FORWARD) {
ff_thread_progress_await(&s->last_pic.ptr->progress,
@@ -136,7 +136,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
const op_pixels_func (*op_pix)[4];
const qpel_mc_func (*op_qpix)[16];
- if ((is_mpeg12 == DEFINITELY_MPEG12 || !s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
+ if ((is_mpeg12 == DEFINITELY_MPEG12_H261 || !s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
op_pix = s->hdsp.put_pixels_tab;
op_qpix = s->qdsp.put_qpel_pixels_tab;
} else {
@@ -162,7 +162,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
/* add dct residue */
- if (!(IS_MPEG12(s) || s->msmpeg4_version != MSMP4_UNUSED ||
+ if (!(IS_MPEG12_H261(s) || s->msmpeg4_version != MSMP4_UNUSED ||
(s->codec_id == AV_CODEC_ID_MPEG4 && !s->mpeg_quant)))
#endif /* !IS_ENCODER */
{
@@ -187,7 +187,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
}
#if !IS_ENCODER
- else if (is_mpeg12 == DEFINITELY_MPEG12 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) {
+ else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) {
add_dct(s, block[0], 0, dest_y , dct_linesize);
add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
@@ -222,12 +222,12 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
#if !IS_ENCODER
/* Only MPEG-4 Simple Studio Profile is supported in > 8-bit mode.
TODO: Integrate 10-bit properly into mpegvideo.c so that ER works properly */
- if (is_mpeg12 != DEFINITELY_MPEG12 && CONFIG_MPEG4_DECODER &&
+ if (is_mpeg12 != DEFINITELY_MPEG12_H261 && CONFIG_MPEG4_DECODER &&
/* s->codec_id == AV_CODEC_ID_MPEG4 && */
s->avctx->bits_per_raw_sample > 8) {
ff_mpeg4_decode_studio(s, dest_y, dest_cb, dest_cr, block_size,
uvlinesize, dct_linesize, dct_offset);
- } else if (!IS_MPEG12(s))
+ } else if (!IS_MPEG12_H261(s))
#endif /* !IS_ENCODER */
{
/* dct only in intra block */
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 60/67] avcodec/h261dec: Simplify decoding motion vectors
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (57 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 59/67] avcodec/h261dec: Unquantize coefficients while parsing them Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 61/67] avcodec/h261dec: Don't set framerate multiple times Andreas Rheinhardt
` (12 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Don't use a LUT to negate followed by a conditional ordinary
negation immediately thereafter. Instead fold the two.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 6df8588bb6..852de8d535 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -208,10 +208,6 @@ static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2)
return 0;
}
-static const int mvmap[17] = {
- 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
-};
-
static int decode_mv_component(GetBitContext *gb, int v)
{
int mv_diff = get_vlc2(gb, h261_mv_vlc, H261_MV_VLC_BITS, 2);
@@ -220,9 +216,7 @@ static int decode_mv_component(GetBitContext *gb, int v)
if (mv_diff < 0)
return v;
- mv_diff = mvmap[mv_diff];
-
- if (mv_diff && !get_bits1(gb))
+ if (mv_diff && get_bits1(gb))
mv_diff = -mv_diff;
v += mv_diff;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 61/67] avcodec/h261dec: Don't set framerate multiple times
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (58 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 60/67] avcodec/h261dec: Simplify decoding motion vectors Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 62/67] avcodec/rv10: Remove write-only assignments Andreas Rheinhardt
` (11 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Just do it one during init.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 852de8d535..cabca33c8d 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -87,6 +87,8 @@ static av_cold int h261_decode_init(AVCodecContext *avctx)
MpegEncContext *const s = &h->s;
int ret;
+ avctx->framerate = (AVRational) { 30000, 1001 };
+
s->private_ctx = &h->common;
// set defaults
ret = ff_mpv_decode_init(s, avctx);
@@ -473,8 +475,6 @@ static int h261_decode_picture_header(H261DecContext *h)
/* temporal reference */
skip_bits(&s->gb, 5); /* picture timestamp */
- s->avctx->framerate = (AVRational) { 30000, 1001 };
-
/* PTYPE starts here */
skip_bits1(&s->gb); /* split screen off */
skip_bits1(&s->gb); /* camera off */
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 62/67] avcodec/rv10: Remove write-only assignments
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (59 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 61/67] avcodec/h261dec: Don't set framerate multiple times Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 63/67] avcodec/mpeg_er: Simplify disabling IDCT Andreas Rheinhardt
` (10 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv10.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 3dcee0a065..c6baaa0269 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -498,12 +498,6 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
s->rv10_first_dc_coded[0] = 0;
s->rv10_first_dc_coded[1] = 0;
s->rv10_first_dc_coded[2] = 0;
- s->block_wrap[0] =
- s->block_wrap[1] =
- s->block_wrap[2] =
- s->block_wrap[3] = s->b8_stride;
- s->block_wrap[4] =
- s->block_wrap[5] = s->mb_stride;
ff_init_block_index(s);
/* decode each macroblock */
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 63/67] avcodec/mpeg_er: Simplify disabling IDCT
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (60 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 62/67] avcodec/rv10: Remove write-only assignments Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 64/67] avcodec/rv10: Use ff_h263_decode_init() Andreas Rheinhardt
` (9 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The error resilience code does not make up block coefficients
and therefore zeroes them in order to disable the IDCT.
But this can be done in a simpler manner, namely by setting
block_last_index to a negative value. Doing so also has
the advantage that the dct_unquantize functions are never even
called for those codecs that do not use ff_mpv_reconstruct_mb()
for ordinary decoding (namely RV-30/40 and the VC-1 family).
This approach would not work for intra macroblocks (there is always
at least one coefficient for them and therefore there is no check
for block_last_index for them), but this does not happen at all.
Add an assert for this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg_er.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c
index fe7dcd7efb..3cbdeeebec 100644
--- a/libavcodec/mpeg_er.c
+++ b/libavcodec/mpeg_er.c
@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#include "error_resilience.h"
#include "mpegvideo.h"
@@ -67,6 +68,8 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
{
MpegEncContext *s = opaque;
+ av_assert1(!mb_intra);
+
s->mv_dir = mv_dir;
s->mv_type = mv_type;
s->mb_intra = mb_intra;
@@ -76,9 +79,9 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
s->mcsel = 0;
memcpy(s->mv, mv, sizeof(*mv));
- s->bdsp.clear_blocks(s->block[0]);
- if (!s->chroma_y_shift)
- s->bdsp.clear_blocks(s->block[6]);
+ // The following disables the IDCT.
+ for (size_t i = 0; i < FF_ARRAY_ELEMS(s->block_last_index); i++)
+ s->block_last_index[i] = -1;
s->dest[0] = s->cur_pic.data[0] +
s->mb_y * 16 * s->linesize +
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 64/67] avcodec/rv10: Use ff_h263_decode_init()
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (61 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 63/67] avcodec/mpeg_er: Simplify disabling IDCT Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 65/67] avcodec/mpegvideo: Move quant_precision to Mpeg4DecContext Andreas Rheinhardt
` (8 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The RV10 and RV20 decoders use ff_h263_decode_mb() and also the
H.263 DSP and VLCs. Despite not calling ff_h263_decode_frame(),
it is nevertheless beneficial to call ff_h263_decode_init()
to reduce code duplication.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 2 ++
libavcodec/rv10.c | 19 +++----------------
2 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 666675fcf1..19a57582ad 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -135,6 +135,8 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
s->msmpeg4_version = MSMP4_WMV2;
break;
case AV_CODEC_ID_H263I:
+ case AV_CODEC_ID_RV10:
+ case AV_CODEC_ID_RV20:
break;
case AV_CODEC_ID_FLV1:
s->h263_flv = 1;
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index c6baaa0269..65060d4ece 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -346,7 +346,6 @@ static av_cold void rv10_init_static(void)
rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i].sym = 255;
rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i].len = 18;
}
- ff_h263_decode_init_vlc();
}
static av_cold int rv10_decode_init(AVCodecContext *avctx)
@@ -364,16 +363,12 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
avctx->coded_height, 0, avctx)) < 0)
return ret;
- ret = ff_mpv_decode_init(s, avctx);
+ ret = ff_h263_decode_init(avctx);
if (ret < 0)
return ret;
- s->out_format = FMT_H263;
-
- rv->orig_width =
- s->width = avctx->coded_width;
- rv->orig_height =
- s->height = avctx->coded_height;
+ rv->orig_width = avctx->coded_width;
+ rv->orig_height = avctx->coded_height;
s->h263_long_vectors = ((uint8_t *) avctx->extradata)[3] & 1;
rv->sub_id = AV_RB32((uint8_t *) avctx->extradata + 4);
@@ -382,7 +377,6 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
minor_ver = RV_GET_MINOR_VER(rv->sub_id);
micro_ver = RV_GET_MICRO_VER(rv->sub_id);
- s->low_delay = 1;
switch (major_ver) {
case 1:
s->rv10_version = micro_ver ? 3 : 1;
@@ -405,13 +399,6 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
((uint32_t *) avctx->extradata)[0]);
}
- avctx->pix_fmt = AV_PIX_FMT_YUV420P;
-
- if ((ret = ff_mpv_common_init(s)) < 0)
- return ret;
-
- ff_h263dsp_init(&s->h263dsp);
-
/* init static VLCs */
ff_thread_once(&init_static_once, rv10_init_static);
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 65/67] avcodec/mpegvideo: Move quant_precision to Mpeg4DecContext
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (62 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 64/67] avcodec/rv10: Use ff_h263_decode_init() Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 66/67] avcodec/rv10: Avoid indirection Andreas Rheinhardt
` (7 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is an MPEG-4-only value; it is always five for the MPEG-4
encoder, so just hardcode this value and move the MpegEncContext
field to Mpeg4DecContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 1 -
libavcodec/mpeg4video_parser.c | 2 +-
libavcodec/mpeg4videodec.c | 20 ++++++++++----------
libavcodec/mpeg4videodec.h | 2 ++
libavcodec/mpeg4videoenc.c | 2 +-
libavcodec/mpegvideo.h | 1 -
libavcodec/mpegvideo_enc.c | 2 --
libavcodec/vaapi_mpeg4.c | 2 +-
8 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 19a57582ad..a81786479d 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -99,7 +99,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
if (ret < 0)
return ret;
- s->quant_precision = 5;
s->decode_mb = ff_h263_decode_mb;
s->low_delay = 1;
diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c
index 402594e01d..b00b523bde 100644
--- a/libavcodec/mpeg4video_parser.c
+++ b/libavcodec/mpeg4video_parser.c
@@ -122,7 +122,7 @@ static av_cold int mpeg4video_parse_init(AVCodecParserContext *s)
struct Mp4vParseContext *pc = s->priv_data;
pc->first_picture = 1;
- pc->dec_ctx.m.quant_precision = 5;
+ pc->dec_ctx.quant_precision = 5;
pc->dec_ctx.m.slice_context_count = 1;
pc->dec_ctx.showed_packed_warning = 1;
return 0;
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 77bd3e9947..debcafc4c0 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -728,7 +728,7 @@ int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx)
s->mb_y = mb_num / s->mb_width;
if (ctx->shape != BIN_ONLY_SHAPE) {
- int qscale = get_bits(&s->gb, s->quant_precision);
+ int qscale = get_bits(&s->gb, ctx->quant_precision);
if (qscale)
s->chroma_qscale = s->qscale = qscale;
}
@@ -2706,17 +2706,16 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
// FIXME sadct disable bit if verid!=1 && shape not rect
if (get_bits1(gb) == 1) { /* not_8_bit */
- s->quant_precision = get_bits(gb, 4); /* quant_precision */
+ ctx->quant_precision = get_bits(gb, 4); /* quant_precision */
if (get_bits(gb, 4) != 8) /* bits_per_pixel */
av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n");
- if (s->quant_precision != 5)
+ if (ctx->quant_precision != 5)
av_log(s->avctx, AV_LOG_ERROR,
- "quant precision %d\n", s->quant_precision);
- if (s->quant_precision<3 || s->quant_precision>9) {
- s->quant_precision = 5;
- }
+ "quant precision %d\n", ctx->quant_precision);
+ if (ctx->quant_precision < 3 || ctx->quant_precision > 9)
+ ctx->quant_precision = 5;
} else {
- s->quant_precision = 5;
+ ctx->quant_precision = 5;
}
// FIXME a bunch of grayscale shape things
@@ -2904,7 +2903,7 @@ no_cplx_est:
av_log(s->avctx, AV_LOG_DEBUG, "tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d %s%s%s%s\n",
s->avctx->framerate.den, s->avctx->framerate.num,
ctx->time_increment_bits,
- s->quant_precision,
+ ctx->quant_precision,
s->progressive_sequence,
s->low_delay,
ctx->scalability ? "scalability " :"" , s->quarter_sample ? "qpel " : "",
@@ -3286,7 +3285,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
}
if (ctx->shape != BIN_ONLY_SHAPE) {
- s->chroma_qscale = s->qscale = get_bits(gb, s->quant_precision);
+ s->chroma_qscale = s->qscale = get_bits(gb, ctx->quant_precision);
if (s->qscale == 0) {
av_log(s->avctx, AV_LOG_ERROR,
"Error, header damaged or not MPEG-4 header (qscale=0)\n");
@@ -3798,6 +3797,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
s->low_delay = 0; /* default, might be overridden in the vol header during header parsing */
s->decode_mb = mpeg4_decode_mb;
ctx->time_increment_bits = 4; /* default value for broken headers */
+ ctx->quant_precision = 5;
avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index 4a26d18987..734237b16f 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -60,6 +60,8 @@ typedef struct Mpeg4DecContext {
int enhancement_type;
int scalability;
+ int quant_precision;
+
/// QP above which the ac VLC should be used for intra dc
int intra_dc_threshold;
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 84b603f312..0b18776497 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -1358,7 +1358,7 @@ void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
put_bits(&s->pb, 1, 1);
put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y * s->mb_width);
- put_bits(&s->pb, s->quant_precision, s->qscale);
+ put_bits(&s->pb, 5 /* quant_precision */, s->qscale);
put_bits(&s->pb, 1, 0); /* no HEC */
}
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 844da6881f..8083299b66 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -384,7 +384,6 @@ typedef struct MpegEncContext {
uint16_t pp_field_time;
uint16_t pb_field_time; ///< like above, just for interlaced
int mcsel;
- int quant_precision;
int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
int data_partitioning; ///< data partitioning flag from header
int partitioned_frame; ///< is current frame partitioned
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index d05a93d249..abeb235277 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -951,8 +951,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->h263_slice_structured = 1;
}
- s->quant_precision = 5;
-
if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) {
ff_h263_encode_init(s);
#if CONFIG_MSMPEG4ENC
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index d182f879cb..2c9dfbe42f 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -74,7 +74,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_
.resync_marker_disable = !ctx->resync_marker,
},
.no_of_sprite_warping_points = ctx->num_sprite_warping_points,
- .quant_precision = s->quant_precision,
+ .quant_precision = ctx->quant_precision,
.vop_fields.bits = {
.vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I,
.backward_reference_vop_coding_type =
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 66/67] avcodec/rv10: Avoid indirection
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (63 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 65/67] avcodec/mpegvideo: Move quant_precision to Mpeg4DecContext Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 67/67] avcodec/mpegvideo_dec: Move setting dct_unquant funcs to h263dec.c Andreas Rheinhardt
` (6 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv10.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 65060d4ece..753c6c6cb3 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -385,11 +385,11 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
case 2:
if (minor_ver >= 2) {
s->low_delay = 0;
- s->avctx->has_b_frames = 1;
+ avctx->has_b_frames = 1;
}
break;
default:
- av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", rv->sub_id);
+ av_log(avctx, AV_LOG_ERROR, "unknown header %X\n", rv->sub_id);
avpriv_request_sample(avctx, "RV1/2 version");
return AVERROR_PATCHWELCOME;
}
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 67/67] avcodec/mpegvideo_dec: Move setting dct_unquant funcs to h263dec.c
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (64 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 66/67] avcodec/rv10: Avoid indirection Andreas Rheinhardt
@ 2024-06-14 18:25 ` Andreas Rheinhardt
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 68/73] avcodec/h261enc: Inline constants Andreas Rheinhardt
` (5 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-14 18:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is a better place for it; no non-h263-based decoder needs
these functions any more (both H.261 and the error resilience
code recently stopped doing so).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 5 +++++
libavcodec/mpegvideo_dec.c | 6 ------
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index a81786479d..0c23012584 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -102,6 +102,11 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
s->decode_mb = ff_h263_decode_mb;
s->low_delay = 1;
+ // dct_unquantize defaults for H.263;
+ // they might change on a per-frame basis for MPEG-4.
+ s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
+ s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
+
/* select sub codec */
switch (avctx->codec->id) {
case AV_CODEC_ID_H263:
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index da88a35120..1cab108935 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -60,12 +60,6 @@ int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
ff_mpv_idct_init(s);
- // dct_unquantize defaults for H.261 and H.263;
- // they might change on a per-frame basis for MPEG-4.
- // Unused by the MPEG-1/2 decoders.
- s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
- s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
-
ff_h264chroma_init(&s->h264chroma, 8); //for lowres
if (s->picture_pool) // VC-1 can call this multiple times
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 68/73] avcodec/h261enc: Inline constants
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (65 preceding siblings ...)
2024-06-14 18:25 ` [FFmpeg-devel] [PATCH 67/67] avcodec/mpegvideo_dec: Move setting dct_unquant funcs to h263dec.c Andreas Rheinhardt
@ 2024-06-15 17:16 ` Andreas Rheinhardt
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 69/73] avcodec/motion_est: Optimize dead code away Andreas Rheinhardt
` (4 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-15 17:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261enc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index dd4419ec8c..8e08c749d1 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -133,8 +133,8 @@ static void h261_encode_motion(PutBitContext *pb, int val)
{
int sign, code;
if (val == 0) {
- code = 0;
- put_bits(pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]);
+ // Corresponds to ff_h261_mv_tab[0]
+ put_bits(pb, 1, 1);
} else {
if (val > 15)
val -= 32;
@@ -227,7 +227,7 @@ static void h261_encode_block(H261EncContext *h, int16_t *block, int n)
}
}
if (last_index > -1)
- put_bits(&s->pb, rl->table_vlc[0][1], rl->table_vlc[0][0]); // EOB
+ put_bits(&s->pb, 2, 0x2); // EOB
}
void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64],
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 69/73] avcodec/motion_est: Optimize dead code away
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (66 preceding siblings ...)
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 68/73] avcodec/h261enc: Inline constants Andreas Rheinhardt
@ 2024-06-15 17:16 ` Andreas Rheinhardt
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 70/73] avcodec/mpegvideo_enc: Constify pointers to static storage Andreas Rheinhardt
` (3 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-15 17:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
H.261 does not have B-frames.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/motion_est.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index e783e79a94..554fc9780e 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -537,7 +537,7 @@ static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4)
/**
* get fullpel ME search limits.
*/
-static inline void get_limits(MpegEncContext *s, int x, int y)
+static inline void get_limits(MpegEncContext *s, int x, int y, int bframe)
{
MotionEstContext * const c= &s->me;
int range= c->avctx->me_range >> (1 + !!(c->flags&FLAG_QPEL));
@@ -551,7 +551,7 @@ static inline void get_limits(MpegEncContext *s, int x, int y)
c->ymin = - y - 16;
c->xmax = - x + s->width;
c->ymax = - y + s->height;
- } else if (s->out_format == FMT_H261){
+ } else if (!(av_builtin_constant_p(bframe) && bframe) && s->out_format == FMT_H261){
// Search range of H.261 is different from other codec standards
c->xmin = (x > 15) ? - 15 : 0;
c->ymin = (y > 15) ? - 15 : 0;
@@ -921,7 +921,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp);
c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_DMV;
- get_limits(s, 16*mb_x, 16*mb_y);
+ get_limits(s, 16*mb_x, 16*mb_y, 0);
c->skip=0;
/* intra / predictive decision */
@@ -1088,7 +1088,7 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
c->pre_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp);
c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_DMV;
- get_limits(s, 16*mb_x, 16*mb_y);
+ get_limits(s, 16*mb_x, 16*mb_y, 0);
c->skip=0;
P_LEFT[0] = s->p_mv_table[xy + 1][0];
@@ -1140,7 +1140,7 @@ static int estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y,
c->current_mv_penalty= mv_penalty;
- get_limits(s, 16*mb_x, 16*mb_y);
+ get_limits(s, 16*mb_x, 16*mb_y, 1);
if (s->motion_est != FF_ME_ZERO) {
P_LEFT[0] = mv_table[mot_xy - 1][0];
@@ -1489,7 +1489,7 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1);
- get_limits(s, 16*mb_x, 16*mb_y); //restore c->?min/max, maybe not needed
+ get_limits(s, 16*mb_x, 16*mb_y, 1); //restore c->?min/max, maybe not needed
mv_table[mot_xy][0]= mx;
mv_table[mot_xy][1]= my;
@@ -1509,7 +1509,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
init_ref(c, s->new_pic->data, s->last_pic.data,
s->next_pic.data, 16 * mb_x, 16 * mb_y, 2);
- get_limits(s, 16*mb_x, 16*mb_y);
+ get_limits(s, 16*mb_x, 16*mb_y, 1);
c->skip=0;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 70/73] avcodec/mpegvideo_enc: Constify pointers to static storage
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (67 preceding siblings ...)
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 69/73] avcodec/motion_est: Optimize dead code away Andreas Rheinhardt
@ 2024-06-15 17:16 ` Andreas Rheinhardt
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 71/73] avcodec/h261data: Make some tables non-static Andreas Rheinhardt
` (2 subsequent siblings)
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-15 17:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
These must not be modified (even when they are initialized at runtime
and therefore modifiable).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index abeb235277..620ca08869 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3914,8 +3914,7 @@ static int dct_quantize_trellis_c(MpegEncContext *s,
int coeff_count[64];
int qmul, qadd, start_i, last_non_zero, i, dc;
const int esc_length= s->ac_esc_length;
- uint8_t * length;
- uint8_t * last_length;
+ const uint8_t *length, *last_length;
const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
int mpeg2_qscale;
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 71/73] avcodec/h261data: Make some tables non-static
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (68 preceding siblings ...)
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 70/73] avcodec/mpegvideo_enc: Constify pointers to static storage Andreas Rheinhardt
@ 2024-06-15 17:16 ` Andreas Rheinhardt
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 72/73] avcodec/h261enc: Avoid RLTable when writing macroblock Andreas Rheinhardt
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 73/73] avcodec/h261enc: Fix ac_vlc_length tables Andreas Rheinhardt
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-15 17:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This will allow to avoid the indirection via ff_h261_rl_tcoeff
in future commits.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261.h | 4 ++++
libavcodec/h261data.c | 12 ++++++------
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/libavcodec/h261.h b/libavcodec/h261.h
index 11a8a8685a..4279a12677 100644
--- a/libavcodec/h261.h
+++ b/libavcodec/h261.h
@@ -50,6 +50,10 @@ extern const uint8_t ff_h261_mv_tab[17][2];
extern const uint8_t ff_h261_cbp_tab[63][2];
extern RLTable ff_h261_rl_tcoeff;
+extern const uint16_t ff_h261_tcoeff_vlc[65][2];
+extern const int8_t ff_h261_tcoeff_level[64];
+extern const int8_t ff_h261_tcoeff_run[64];
+
void ff_h261_loop_filter(MpegEncContext *s);
#endif /* AVCODEC_H261_H */
diff --git a/libavcodec/h261data.c b/libavcodec/h261data.c
index bccd9e5f56..3ee750f98c 100644
--- a/libavcodec/h261data.c
+++ b/libavcodec/h261data.c
@@ -104,7 +104,7 @@ const uint8_t ff_h261_cbp_tab[63][2] = {
};
// H.261 VLC table for transform coefficients
-static const uint16_t h261_tcoeff_vlc[65][2] = {
+const uint16_t ff_h261_tcoeff_vlc[65][2] = {
{ 0x2, 2 }, { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 },
{ 0x6, 7 }, { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 },
{ 0x1d, 12 }, { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 },
@@ -124,7 +124,7 @@ static const uint16_t h261_tcoeff_vlc[65][2] = {
{ 0x1, 6 } // escape
};
-static const int8_t h261_tcoeff_level[64] = {
+const int8_t ff_h261_tcoeff_level[64] = {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
1, 2, 3, 4, 5, 6, 7, 1,
@@ -135,7 +135,7 @@ static const int8_t h261_tcoeff_level[64] = {
1, 1, 1, 1, 1, 1, 1, 1
};
-static const int8_t h261_tcoeff_run[64] = {
+const int8_t ff_h261_tcoeff_run[64] = {
0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1,
@@ -150,7 +150,7 @@ static const int8_t h261_tcoeff_run[64] = {
RLTable ff_h261_rl_tcoeff = {
64,
64,
- h261_tcoeff_vlc,
- h261_tcoeff_run,
- h261_tcoeff_level,
+ ff_h261_tcoeff_vlc,
+ ff_h261_tcoeff_run,
+ ff_h261_tcoeff_level,
};
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 72/73] avcodec/h261enc: Avoid RLTable when writing macroblock
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (69 preceding siblings ...)
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 71/73] avcodec/h261data: Make some tables non-static Andreas Rheinhardt
@ 2024-06-15 17:16 ` Andreas Rheinhardt
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 73/73] avcodec/h261enc: Fix ac_vlc_length tables Andreas Rheinhardt
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-15 17:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The RLTable API in rl.c is not well designed for codecs with
an explicit end-of-block code. ff_h261_rl_tcoeff's vlc has
the EOB code as first element (presumably so that the decoder
can check for it via "if (level == 0)") and this implies
that the indices returned by get_rl_index() are off by one
for run == 0 which is therefore explicitly checked.
This commit changes this by adding a simple LUT for the
values not requiring escaping. It is easy to directly
include the sign bit into this, so this has also been done.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261enc.c | 51 +++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 20 deletions(-)
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 8e08c749d1..b19830d578 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -36,6 +36,14 @@
#include "h261enc.h"
#include "mpegvideoenc.h"
+#define H261_MAX_RUN 26
+#define H261_MAX_LEVEL 15
+
+static struct VLCLUT {
+ uint8_t len;
+ uint16_t code;
+} vlc_lut[H261_MAX_RUN + 1][32 /* 0..2 * H261_MAX_LEN are used */];
+
static uint8_t uni_h261_rl_len [64*64*2*2];
#define UNI_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
@@ -165,10 +173,8 @@ static inline int get_cbp(MpegEncContext *s, int16_t block[6][64])
static void h261_encode_block(H261EncContext *h, int16_t *block, int n)
{
MpegEncContext *const s = &h->s;
- int level, run, i, j, last_index, last_non_zero, sign, slevel, code;
- const RLTable *rl;
+ int level, run, i, j, last_index, last_non_zero;
- rl = &ff_h261_rl_tcoeff;
if (s->mb_intra) {
/* DC coef */
level = block[0];
@@ -204,24 +210,18 @@ static void h261_encode_block(H261EncContext *h, int16_t *block, int n)
level = block[j];
if (level) {
run = i - last_non_zero - 1;
- sign = 0;
- slevel = level;
- if (level < 0) {
- sign = 1;
- level = -level;
- }
- code = get_rl_index(rl, 0 /*no last in H.261, EOB is used*/,
- run, level);
- if (run == 0 && level < 16)
- code += 1;
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- if (code == rl->n) {
- put_bits(&s->pb, 6, run);
- av_assert1(slevel != 0);
- av_assert1(level <= 127);
- put_sbits(&s->pb, 8, slevel);
+
+ if (run <= H261_MAX_RUN &&
+ (unsigned)(level + H261_MAX_LEVEL) <= 2 * H261_MAX_LEVEL &&
+ vlc_lut[run][level + H261_MAX_LEVEL].len) {
+ put_bits(&s->pb, vlc_lut[run][level + H261_MAX_LEVEL].len,
+ vlc_lut[run][level + H261_MAX_LEVEL].code);
} else {
- put_bits(&s->pb, 1, sign);
+ /* Escape */
+ put_bits(&s->pb, 6 + 6, (1 << 6) | run);
+ av_assert1(level != 0);
+ av_assert1(FFABS(level) <= 127);
+ put_sbits(&s->pb, 8, level);
}
last_non_zero = i;
}
@@ -365,6 +365,17 @@ static av_cold void h261_encode_init_static(void)
ff_rl_init(&ff_h261_rl_tcoeff, h261_rl_table_store);
init_uni_h261_rl_tab(&ff_h261_rl_tcoeff, uni_h261_rl_len);
+
+ // The following loop is over the ordinary elements, not EOB or escape.
+ for (size_t i = 1; i < FF_ARRAY_ELEMS(ff_h261_tcoeff_vlc) - 1; i++) {
+ unsigned run = ff_h261_tcoeff_run[i];
+ unsigned level = ff_h261_tcoeff_level[i];
+ unsigned len = ff_h261_tcoeff_vlc[i][1] + 1 /* sign */;
+ unsigned code = ff_h261_tcoeff_vlc[i][0];
+
+ vlc_lut[run][H261_MAX_LEVEL + level] = (struct VLCLUT){ len, code << 1 };
+ vlc_lut[run][H261_MAX_LEVEL - level] = (struct VLCLUT){ len, (code << 1) | 1 };
+ }
}
av_cold int ff_h261_encode_init(MpegEncContext *s)
--
2.40.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] 87+ messages in thread
* [FFmpeg-devel] [PATCH 73/73] avcodec/h261enc: Fix ac_vlc_length tables
2024-06-12 13:16 [FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks Andreas Rheinhardt
` (70 preceding siblings ...)
2024-06-15 17:16 ` [FFmpeg-devel] [PATCH 72/73] avcodec/h261enc: Avoid RLTable when writing macroblock Andreas Rheinhardt
@ 2024-06-15 17:16 ` Andreas Rheinhardt
71 siblings, 0 replies; 87+ messages in thread
From: Andreas Rheinhardt @ 2024-06-15 17:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
These tables are supposed to contain the number of bits needed
to encode a given (run, level) pair. Yet the number of bits
for pairs needing the escape code was wrong (it only contained
the escape code and not the bits needed for run and level).
Furthermore, H.261 (a format with explicit end-of-block codes)
does not work well together with the RLTable API from rl.c:
The EOB code is the first one in ff_h261_rl_tcoeff's VLC table
and has a run value of zero. Therefore the result of get_rl_index()
is off by one for run == 0 and level values with explicit
(run, level) pair.
Fixing this necessitated changing the ref files of the
vsynth*-h261-trellis tests. Both filesizes as well as PSNR
decreased. If one used a qscale value of 11 for this test,
one would have received files with about the same size as
before this patch (with qscale 12), but with better PSNR.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261enc.c | 59 +++++------------------
tests/ref/vsynth/vsynth1-h261-trellis | 8 +--
tests/ref/vsynth/vsynth2-h261-trellis | 8 +--
tests/ref/vsynth/vsynth_lena-h261-trellis | 8 +--
4 files changed, 24 insertions(+), 59 deletions(-)
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index b19830d578..a901c32e42 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -38,14 +38,15 @@
#define H261_MAX_RUN 26
#define H261_MAX_LEVEL 15
+#define H261_ESC_LEN (6 + 6 + 8)
static struct VLCLUT {
uint8_t len;
uint16_t code;
} vlc_lut[H261_MAX_RUN + 1][32 /* 0..2 * H261_MAX_LEN are used */];
-static uint8_t uni_h261_rl_len [64*64*2*2];
-#define UNI_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
+static uint8_t uni_h261_rl_len [64 * 128];
+static uint8_t uni_h261_rl_len_last[64 * 128];
typedef struct H261EncContext {
MpegEncContext s;
@@ -320,51 +321,10 @@ void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64],
}
}
-static av_cold void init_uni_h261_rl_tab(const RLTable *rl, uint8_t *len_tab)
-{
- int slevel, run, last;
-
- av_assert0(MAX_LEVEL >= 64);
- av_assert0(MAX_RUN >= 63);
-
- for(slevel=-64; slevel<64; slevel++){
- if(slevel==0) continue;
- for(run=0; run<64; run++){
- for(last=0; last<=1; last++){
- const int index= UNI_ENC_INDEX(last, run, slevel+64);
- int level= slevel < 0 ? -slevel : slevel;
- int len, code;
-
- len_tab[index]= 100;
-
- /* ESC0 */
- code= get_rl_index(rl, 0, run, level);
- len= rl->table_vlc[code][1] + 1;
- if(last)
- len += 2;
-
- if(code!=rl->n && len < len_tab[index]){
- len_tab [index]= len;
- }
- /* ESC */
- len = rl->table_vlc[rl->n][1];
- if(last)
- len += 2;
-
- if(len < len_tab[index]){
- len_tab [index]= len;
- }
- }
- }
- }
-}
-
static av_cold void h261_encode_init_static(void)
{
- static uint8_t h261_rl_table_store[2][2 * MAX_RUN + MAX_LEVEL + 3];
-
- ff_rl_init(&ff_h261_rl_tcoeff, h261_rl_table_store);
- init_uni_h261_rl_tab(&ff_h261_rl_tcoeff, uni_h261_rl_len);
+ memset(uni_h261_rl_len, H261_ESC_LEN, sizeof(uni_h261_rl_len));
+ memset(uni_h261_rl_len_last, H261_ESC_LEN + 2 /* EOB */, sizeof(uni_h261_rl_len_last));
// The following loop is over the ordinary elements, not EOB or escape.
for (size_t i = 1; i < FF_ARRAY_ELEMS(ff_h261_tcoeff_vlc) - 1; i++) {
@@ -375,6 +335,11 @@ static av_cold void h261_encode_init_static(void)
vlc_lut[run][H261_MAX_LEVEL + level] = (struct VLCLUT){ len, code << 1 };
vlc_lut[run][H261_MAX_LEVEL - level] = (struct VLCLUT){ len, (code << 1) | 1 };
+
+ uni_h261_rl_len [UNI_AC_ENC_INDEX(run, 64 + level)] = len;
+ uni_h261_rl_len [UNI_AC_ENC_INDEX(run, 64 - level)] = len;
+ uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 + level)] = len + 2;
+ uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 - level)] = len + 2;
}
}
@@ -398,10 +363,10 @@ av_cold int ff_h261_encode_init(MpegEncContext *s)
s->min_qcoeff = -127;
s->max_qcoeff = 127;
- s->ac_esc_length = 6+6+8;
+ s->ac_esc_length = H261_ESC_LEN;
s->intra_ac_vlc_length = s->inter_ac_vlc_length = uni_h261_rl_len;
- s->intra_ac_vlc_last_length = s->inter_ac_vlc_last_length = uni_h261_rl_len + 128*64;
+ s->intra_ac_vlc_last_length = s->inter_ac_vlc_last_length = uni_h261_rl_len_last;
ff_thread_once(&init_static_once, h261_encode_init_static);
return 0;
diff --git a/tests/ref/vsynth/vsynth1-h261-trellis b/tests/ref/vsynth/vsynth1-h261-trellis
index 87b078b0d5..0cbb9b0e18 100644
--- a/tests/ref/vsynth/vsynth1-h261-trellis
+++ b/tests/ref/vsynth/vsynth1-h261-trellis
@@ -1,4 +1,4 @@
-02b4109ce5343b7ef24fb11c2635498a *tests/data/fate/vsynth1-h261-trellis.avi
-655416 tests/data/fate/vsynth1-h261-trellis.avi
-70ceba944548ba680b1101c91707ea25 *tests/data/fate/vsynth1-h261-trellis.out.rawvideo
-stddev: 8.75 PSNR: 29.28 MAXDIFF: 90 bytes: 7603200/ 7603200
+9980463214cb744a7780737a16408540 *tests/data/fate/vsynth1-h261-trellis.avi
+590384 tests/data/fate/vsynth1-h261-trellis.avi
+7bbb0520a5ca26cdcea148f9997eae27 *tests/data/fate/vsynth1-h261-trellis.out.rawvideo
+stddev: 9.09 PSNR: 28.96 MAXDIFF: 93 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth2-h261-trellis b/tests/ref/vsynth/vsynth2-h261-trellis
index b9c694f016..03d17e194d 100644
--- a/tests/ref/vsynth/vsynth2-h261-trellis
+++ b/tests/ref/vsynth/vsynth2-h261-trellis
@@ -1,4 +1,4 @@
-f5e0cfc70bbe4f4048c15be88dea4378 *tests/data/fate/vsynth2-h261-trellis.avi
-249856 tests/data/fate/vsynth2-h261-trellis.avi
-15452237f6c333690d3e05f354f63196 *tests/data/fate/vsynth2-h261-trellis.out.rawvideo
-stddev: 7.10 PSNR: 31.10 MAXDIFF: 96 bytes: 7603200/ 7603200
+cdf6013013b8de3fe56476178b5adc89 *tests/data/fate/vsynth2-h261-trellis.avi
+227156 tests/data/fate/vsynth2-h261-trellis.avi
+d1107f161a7d923e0ffb6aeb9c713633 *tests/data/fate/vsynth2-h261-trellis.out.rawvideo
+stddev: 7.24 PSNR: 30.93 MAXDIFF: 87 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth_lena-h261-trellis b/tests/ref/vsynth/vsynth_lena-h261-trellis
index a306508032..75558679ec 100644
--- a/tests/ref/vsynth/vsynth_lena-h261-trellis
+++ b/tests/ref/vsynth/vsynth_lena-h261-trellis
@@ -1,4 +1,4 @@
-41522be50f14b7fff6b1fb8d10b1ff00 *tests/data/fate/vsynth_lena-h261-trellis.avi
-184586 tests/data/fate/vsynth_lena-h261-trellis.avi
-f9df8cd110a2f3d9706dd2f29a1d0a89 *tests/data/fate/vsynth_lena-h261-trellis.out.rawvideo
-stddev: 6.32 PSNR: 32.11 MAXDIFF: 89 bytes: 7603200/ 7603200
+aa3e00ffeb48a23452bb1c5b0dde9e77 *tests/data/fate/vsynth_lena-h261-trellis.avi
+167808 tests/data/fate/vsynth_lena-h261-trellis.avi
+055f8805df2bb21ef6752dc944e7828d *tests/data/fate/vsynth_lena-h261-trellis.out.rawvideo
+stddev: 6.43 PSNR: 31.96 MAXDIFF: 87 bytes: 7603200/ 7603200
--
2.40.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] 87+ messages in thread