[FFmpeg-devel] [PATCH v1] lavc/qsvdec: Add VVC decoder

2024-06-12 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 Changelog  | 1 +
 configure  | 1 +
 doc/decoders.texi  | 2 +-
 libavcodec/allcodecs.c | 1 +
 libavcodec/qsv.c   | 4 
 libavcodec/qsvdec.c| 7 ++-
 libavcodec/version.h   | 2 +-
 7 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index 03d6b29ad8..a238a1c1f3 100644
--- a/Changelog
+++ b/Changelog
@@ -12,6 +12,7 @@ version :
 - qsv_params option added for QSV encoders
 - VVC decoder compatible with DVB test content
 - xHE-AAC decoder
+- Intel QSV-accelerated VVC decoding
 
 
 version 7.0:
diff --git a/configure b/configure
index 6c5b8aab9a..b4cf12658d 100755
--- a/configure
+++ b/configure
@@ -3423,6 +3423,7 @@ av1_qsv_encoder_deps="libvpl"
 av1_amf_encoder_deps="amf"
 av1_vaapi_encoder_deps="VAEncPictureParameterBufferAV1"
 av1_vaapi_encoder_select="cbs_av1 vaapi_encode"
+vvc_qsv_decoder_select="qsvdec"
 
 # parsers
 aac_parser_select="adts_header mpeg4audio"
diff --git a/doc/decoders.texi b/doc/decoders.texi
index 293c82c2ba..2fcc761d2f 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -157,7 +157,7 @@ Force to use a specific number of threads
 @section QSV Decoders
 
 The family of Intel QuickSync Video decoders (VC1, MPEG-2, H.264, HEVC,
-JPEG/MJPEG, VP8, VP9, AV1).
+JPEG/MJPEG, VP8, VP9, AV1, VVC).
 
 @subsection Common Options
 
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b102a8069e..a73b4e1673 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -885,6 +885,7 @@ extern const FFCodec ff_vp9_mediacodec_encoder;
 extern const FFCodec ff_vp9_qsv_decoder;
 extern const FFCodec ff_vp9_vaapi_encoder;
 extern const FFCodec ff_vp9_qsv_encoder;
+extern const FFCodec ff_vvc_qsv_decoder;
 
 // null codecs
 extern const FFCodec ff_vnull_decoder;
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 0c6fbd0dc0..221c1b24e5 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -73,6 +73,10 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 case AV_CODEC_ID_AV1:
 return MFX_CODEC_AV1;
 #endif
+#if QSV_VERSION_ATLEAST(2, 11)
+case AV_CODEC_ID_VVC:
+return MFX_CODEC_VVC;
+#endif
 
 default:
 break;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index f2cd6ae05c..9ad3439991 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -933,7 +933,8 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
 frame->pict_type = 
ff_qsv_map_pictype(aframe.frame->dec_info.FrameType);
 
 if (avctx->codec_id == AV_CODEC_ID_H264 ||
-avctx->codec_id == AV_CODEC_ID_HEVC) {
+avctx->codec_id == AV_CODEC_ID_HEVC ||
+avctx->codec_id == AV_CODEC_ID_VVC) {
 if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR)
 frame->flags |= AV_FRAME_FLAG_KEY;
 else
@@ -1300,3 +1301,7 @@ DEFINE_QSV_DECODER(vp9, VP9, NULL)
 #if CONFIG_AV1_QSV_DECODER
 DEFINE_QSV_DECODER(av1, AV1, NULL)
 #endif
+
+#if CONFIG_VVC_QSV_DECODER
+DEFINE_QSV_DECODER(vvc, VVC, NULL)
+#endif
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 7acb261bb3..37c4c39451 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR   7
+#define LIBAVCODEC_VERSION_MINOR   8
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v1] lavc/qsvdec: Add VVC decoder

2024-06-12 Thread Wang, Fei W
On Wed, 2024-06-12 at 14:59 +0800, fei.w.w...@intel.com wrote:
> From: Fei Wang 

Sorry for duplicate version. Please ignore this one.

Thanks

> 
> Signed-off-by: Fei Wang 
> ---
>  Changelog  | 1 +
>  configure  | 1 +
>  doc/decoders.texi  | 2 +-
>  libavcodec/allcodecs.c | 1 +
>  libavcodec/qsv.c   | 4 
>  libavcodec/qsvdec.c| 7 ++-
>  libavcodec/version.h   | 2 +-
>  7 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/Changelog b/Changelog
> index 03d6b29ad8..a238a1c1f3 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -12,6 +12,7 @@ version :
>  - qsv_params option added for QSV encoders
>  - VVC decoder compatible with DVB test content
>  - xHE-AAC decoder
> +- Intel QSV-accelerated VVC decoding
>  
>  
>  version 7.0:
> diff --git a/configure b/configure
> index 6c5b8aab9a..b4cf12658d 100755
> --- a/configure
> +++ b/configure
> @@ -3423,6 +3423,7 @@ av1_qsv_encoder_deps="libvpl"
>  av1_amf_encoder_deps="amf"
>  av1_vaapi_encoder_deps="VAEncPictureParameterBufferAV1"
>  av1_vaapi_encoder_select="cbs_av1 vaapi_encode"
> +vvc_qsv_decoder_select="qsvdec"
>  
>  # parsers
>  aac_parser_select="adts_header mpeg4audio"
> diff --git a/doc/decoders.texi b/doc/decoders.texi
> index 293c82c2ba..2fcc761d2f 100644
> --- a/doc/decoders.texi
> +++ b/doc/decoders.texi
> @@ -157,7 +157,7 @@ Force to use a specific number of threads
>  @section QSV Decoders
>  
>  The family of Intel QuickSync Video decoders (VC1, MPEG-2, H.264,
> HEVC,
> -JPEG/MJPEG, VP8, VP9, AV1).
> +JPEG/MJPEG, VP8, VP9, AV1, VVC).
>  
>  @subsection Common Options
>  
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index b102a8069e..a73b4e1673 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -885,6 +885,7 @@ extern const FFCodec ff_vp9_mediacodec_encoder;
>  extern const FFCodec ff_vp9_qsv_decoder;
>  extern const FFCodec ff_vp9_vaapi_encoder;
>  extern const FFCodec ff_vp9_qsv_encoder;
> +extern const FFCodec ff_vvc_qsv_decoder;
>  
>  // null codecs
>  extern const FFCodec ff_vnull_decoder;
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 0c6fbd0dc0..221c1b24e5 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -73,6 +73,10 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID
> codec_id)
>  case AV_CODEC_ID_AV1:
>  return MFX_CODEC_AV1;
>  #endif
> +#if QSV_VERSION_ATLEAST(2, 11)
> +case AV_CODEC_ID_VVC:
> +return MFX_CODEC_VVC;
> +#endif
>  
>  default:
>  break;
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index f2cd6ae05c..9ad3439991 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -933,7 +933,8 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext *q,
>  frame->pict_type = ff_qsv_map_pictype(aframe.frame-
> >dec_info.FrameType);
>  
>  if (avctx->codec_id == AV_CODEC_ID_H264 ||
> -avctx->codec_id == AV_CODEC_ID_HEVC) {
> +avctx->codec_id == AV_CODEC_ID_HEVC ||
> +avctx->codec_id == AV_CODEC_ID_VVC) {
>  if (aframe.frame->dec_info.FrameType &
> MFX_FRAMETYPE_IDR)
>  frame->flags |= AV_FRAME_FLAG_KEY;
>  else
> @@ -1300,3 +1301,7 @@ DEFINE_QSV_DECODER(vp9, VP9, NULL)
>  #if CONFIG_AV1_QSV_DECODER
>  DEFINE_QSV_DECODER(av1, AV1, NULL)
>  #endif
> +
> +#if CONFIG_VVC_QSV_DECODER
> +DEFINE_QSV_DECODER(vvc, VVC, NULL)
> +#endif
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 7acb261bb3..37c4c39451 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -29,7 +29,7 @@
>  
>  #include "version_major.h"
>  
> -#define LIBAVCODEC_VERSION_MINOR   7
> +#define LIBAVCODEC_VERSION_MINOR   8
>  #define LIBAVCODEC_VERSION_MICRO 100
>  
>  #define
> LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] lavc/hevcdec: always call hevc_frame_end() after successfully decoding an AU

2024-06-12 Thread Anton Khirnov
Currently it is only done if the final CTB address is at the end of the
frame, however that address is not known with hwaccel decoding. As we
only support exactly one AU per packet, and not partial/multiple AUs, we
can just as well call hevc_frame_end() unconditionally.

Fixes hwaccel decoding after d725c737fe2a19091b481d4d115fd939e0a674b2.

Reported-by: llyyr 
---
 libavcodec/hevc/hevcdec.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 88f2bcecad..4b95358b95 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3192,11 +3192,6 @@ static int decode_slice(HEVCContext *s, const H2645NAL 
*nal, GetBitContext *gb)
 ret = decode_slice_data(s, nal, gb);
 if (ret < 0)
 return ret;
-if (ret >= s->cur_frame->ctb_count) {
-ret = hevc_frame_end(s);
-if (ret < 0)
-return ret;
-}
 
 return 0;
 }
@@ -3370,8 +3365,13 @@ static int decode_nal_units(HEVCContext *s, const 
uint8_t *buf, int length)
 }
 
 fail:
-if (s->cur_frame && s->avctx->active_thread_type == FF_THREAD_FRAME)
-ff_progress_frame_report(&s->cur_frame->tf, INT_MAX);
+if (s->cur_frame) {
+if (ret >= 0)
+ret = hevc_frame_end(s);
+
+if (s->avctx->active_thread_type == FF_THREAD_FRAME)
+ff_progress_frame_report(&s->cur_frame->tf, INT_MAX);
+}
 
 return ret;
 }
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/4] avfilter/qsvvpp: Remove unreachable code

2024-06-12 Thread Xiang, Haihao
On Di, 2024-06-11 at 23:59 +0200, Michael Niedermayer wrote:
> Fixes: CID1598548 Logically dead code
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavfilter/qsvvpp.c | 5 -
>  1 file changed, 5 deletions(-)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 1c9773df099..6adf9f6e841 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -1099,11 +1099,6 @@ int ff_qsvvpp_create_mfx_session(void *ctx,
>  if (sts < 0)
>  return ff_qsvvpp_print_error(ctx, sts,
>   "Error creating a MFX session");
> -    else if (sts > 0) {
> -    ff_qsvvpp_print_warning(ctx, sts,
> -    "Warning in MFX session creation");
> -    return AVERROR_UNKNOWN;
> -    }
>  
>  *psession = session;
>  

LGTM, thx

-Haihao

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v13 06/15] avcodec/vaapi_encode: move the dpb logic from VAAPI to base layer

2024-06-12 Thread Wu, Tong1
>From: ffmpeg-devel  On Behalf Of Lynne
>via ffmpeg-devel
>Sent: Monday, June 10, 2024 10:01 AM
>To: FFmpeg development discussions and patches de...@ffmpeg.org>
>Cc: Lynne 
>Subject: Re: [FFmpeg-devel] [PATCH v13 06/15] avcodec/vaapi_encode: move
>the dpb logic from VAAPI to base layer
>
>On 07/06/2024 18:48, Lynne wrote:
>> On 07/06/2024 17:22, Wu, Tong1 wrote:
 From: ffmpeg-devel  On Behalf Of
>Lynne
 via ffmpeg-devel
 Sent: Friday, June 7, 2024 11:10 PM
 To: ffmpeg-devel@ffmpeg.org
 Cc: Lynne 
 Subject: Re: [FFmpeg-devel] [PATCH v13 06/15] avcodec/vaapi_encode:
>move
 the dpb logic from VAAPI to base layer

 On 03/06/2024 11:18, tong1.wu-at-intel@ffmpeg.org wrote:
> From: Tong Wu 
>
> Move receive_packet function to base. This requires adding *alloc,
> *issue, *output, *free as hardware callbacks. HWBaseEncodePicture is
> introduced as the base layer structure. The related parameters in
> VAAPIEncodeContext are also extracted to HWBaseEncodeContext. Then
>DPB
> management logic can be fully extracted to base layer as-is.
>
> Signed-off-by: Tong Wu 
> ---
>    libavcodec/Makefile |   2 +-
>    libavcodec/hw_base_encode.c | 594 
>    libavcodec/hw_base_encode.h | 124 +
>    libavcodec/vaapi_encode.c   | 793 +
> ---
>    libavcodec/vaapi_encode.h   | 102 +---
>    libavcodec/vaapi_encode_av1.c   |  35 +-
>    libavcodec/vaapi_encode_h264.c  |  84 ++--
>    libavcodec/vaapi_encode_h265.c  |  53 ++-
>    libavcodec/vaapi_encode_mjpeg.c |  13 +-
>    libavcodec/vaapi_encode_mpeg2.c |  33 +-
>    libavcodec/vaapi_encode_vp8.c   |  18 +-
>    libavcodec/vaapi_encode_vp9.c   |  24 +-
>    12 files changed, 985 insertions(+), 890 deletions(-)
>    create mode 100644 libavcodec/hw_base_encode.c

 This patch doesn't apply,

 error: sha1 information is lacking or useless (libavcodec/
 hw_base_encode.c).
 error: could not build fake ancestor

 Could you resent the patchset or link me a repo so I can work with it?
>>>
>>> https://github.com/intel-media-ci/ffmpeg/pull/689 This is the same as
>>> v13 please have a try.
>>
>> That worked, thanks.
>
>I don't think the behaviour is correct when the encoding length is less
>than the decode delay. In my old Vulkan code, I had this piece of code
>in the initialization function:
>
> > if (!src) {
> > ctx->end_of_stream = 1;
> > /* Fix timestamps if we hit end-of-stream before the initial
> >  * decode delay has elapsed. */
> > if (ctx->input_order < ctx->decode_delay)
> > ctx->dts_pts_diff = ctx->pic_end->pts - ctx->first_pts;
> > return AVERROR_EOF;
> > }
>
>I think a flush function should be added, to be called by each encoder,
>to make sure the timestamps remain correct.
>

For the current patch set, this piece is in hw_base_encode_send_frame and works 
well for vaapi and d3d12 except when the encoding length is equal to the decode 
delay, which I'll sent a fix later. Do you mean Vulkan cannot integrate into 
this part and we have to make a callback for it?

>Also, the D3D12VA structures need an FF prefix, e.g.
>D3D12VAEncodeContext -> FFD3D12VAEncodeContext.

The current VAAPIEncodeContext has existed for a long time. Does it have any 
difference for D3D12VAEncodeContext? I mean both VAAPIEncodeContext and 
D3D12VAEncodeContext are parallel and only referenced in vaapi_encode_*.c 
(d3d12va_encode_*.c).

Thanks,
Tong
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] lavc/vaapi_encode: correct the timestamp when input_order = decode_delay

2024-06-12 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Fixed the command line: ffmpeg -hwaccel vaapi -pix_fmt nv12 -s:v
widthxheight -i input.yuv -vf "hwupload" -c:v hevc_vaapi -bf 10 -b_depth 3
-vframes 3 -f null -

Signed-off-by: Tong Wu 
---
 libavcodec/vaapi_encode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index f54b2579ec..3c627b5ca8 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1383,7 +1383,7 @@ static int vaapi_encode_send_frame(AVCodecContext *avctx, 
AVFrame *frame)
 
 // Fix timestamps if we hit end-of-stream before the initial decode
 // delay has elapsed.
-if (ctx->input_order < ctx->decode_delay)
+if (ctx->input_order <= ctx->decode_delay)
 ctx->dts_pts_diff = ctx->pic_end->pts - ctx->first_pts;
 }
 
-- 
2.41.0.windows.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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/vp8dsp: R-V V put_bilin_h v unroll

2024-06-12 Thread flow gg
ping

 于2024年5月30日周四 23:27写道:

> From: sunyuechi 
>
> Since len < 64, the registers are sufficient, so it can be
> directly unrolled (a4 is even).
>
> Another benefit of unrolling is that it reduces one load operation
> vertically compared to horizontally.
>
>  old new
>  C908   X60  C908   X60
> vp8_put_bilin4_h_c :6.25.5 :6.25.5
> vp8_put_bilin4_h_rvv_i32   :2.22.0 :1.51.5
> vp8_put_bilin4_v_c :6.55.7 :6.25.7
> vp8_put_bilin4_v_rvv_i32   :2.22.0 :1.21.5
> vp8_put_bilin8_h_c :   24.2   21.5 :   24.2   21.5
> vp8_put_bilin8_h_rvv_i32   :5.24.7 :3.53.5
> vp8_put_bilin8_v_c :   24.5   21.7 :   24.5   21.7
> vp8_put_bilin8_v_rvv_i32   :5.24.7 :3.53.2
> vp8_put_bilin16_h_c:   48.0   42.7 :   48.0   42.7
> vp8_put_bilin16_h_rvv_i32  :5.75.0 :5.24.5
> vp8_put_bilin16_v_c:   48.2   43.0 :   48.2   42.7
> vp8_put_bilin16_v_rvv_i32  :5.75.2 :4.54.2
> ---
>  libavcodec/riscv/vp8dsp_rvv.S | 34 +-
>  1 file changed, 29 insertions(+), 5 deletions(-)
>
> diff --git a/libavcodec/riscv/vp8dsp_rvv.S b/libavcodec/riscv/vp8dsp_rvv.S
> index 3360a38cac..5bea6cba9c 100644
> --- a/libavcodec/riscv/vp8dsp_rvv.S
> +++ b/libavcodec/riscv/vp8dsp_rvv.S
> @@ -172,11 +172,35 @@ func ff_put_vp8_bilin4_\type\()_rvv, zve32x
>  li  t4, 4
>  sub t1, t1, \mn
>  1:
> -addia4, a4, -1
> -bilin_load  v0, \type, \mn
> -vse8.v  v0, (a0)
> -add a2, a2, a3
> -add a0, a0, a1
> +add t0, a2, a3
> +add t2, a0, a1
> +addia4, a4, -2
> +.ifc \type,v
> +add t3, t0, a3
> +.else
> +addit5, a2, 1
> +addit3, t0, 1
> +vle8.v  v2, (t5)
> +.endif
> +vle8.v  v0, (a2)
> +vle8.v  v4, (t0)
> +vle8.v  v6, (t3)
> +vwmulu.vx   v28, v0, t1
> +vwmulu.vx   v26, v4, t1
> +.ifc \type,v
> +vwmaccu.vx  v28, \mn, v4
> +.else
> +vwmaccu.vx  v28, \mn, v2
> +.endif
> +vwmaccu.vx  v26, \mn, v6
> +vwaddu.wx   v24, v28, t4
> +vwaddu.wx   v22, v26, t4
> +vnsra.wiv30, v24, 3
> +vnsra.wiv0, v22, 3
> +vse8.v  v30, (a0)
> +vse8.v  v0, (t2)
> +add a2, t0, a3
> +add a0, t2, a1
>  bneza4, 1b
>
>  ret
> --
> 2.45.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avfilter/af_amix: fix amix decreased sound output

2024-06-12 Thread Shiqi Zhu
fix he issue of decreased sound output when one or more input of the amix 
settings is set to EOF.

Signed-off-by: Shiqi Zhu 
---
 libavfilter/af_amix.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index ade4ef76a8..3ff85650a7 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -216,11 +216,11 @@ static void calculate_scales(MixContext *s, int 
nb_samples)
 int i;
 
 for (i = 0; i < s->nb_inputs; i++)
-if (s->input_state[i] & INPUT_ON)
+if ((s->input_state[i] & INPUT_ON) && av_audio_fifo_size(s->fifos[i]) 
> 0)
 weight_sum += FFABS(s->weights[i]);
 
 for (i = 0; i < s->nb_inputs; i++) {
-if (s->input_state[i] & INPUT_ON) {
+if ((s->input_state[i] & INPUT_ON) && av_audio_fifo_size(s->fifos[i]) 
> 0) {
 if (s->scale_norm[i] > weight_sum / FFABS(s->weights[i])) {
 s->scale_norm[i] -= ((s->weight_sum / FFABS(s->weights[i])) / 
s->nb_inputs) *
 nb_samples / (s->dropout_transition * 
s->sample_rate);
@@ -230,7 +230,7 @@ static void calculate_scales(MixContext *s, int nb_samples)
 }
 
 for (i = 0; i < s->nb_inputs; i++) {
-if (s->input_state[i] & INPUT_ON) {
+if ((s->input_state[i] & INPUT_ON) && av_audio_fifo_size(s->fifos[i]) 
> 0) {
 if (!s->normalize)
 s->input_scale[i] = FFABS(s->weights[i]);
 else
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] checkasm/lls: add missing random values to the test buffers

2024-06-12 Thread James Almer
Fixes valgrind warnings after 18adaf9fe558587cb1b707c647af83015b69da48.

Signed-off-by: James Almer 
---
 tests/checkasm/lls.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/checkasm/lls.c b/tests/checkasm/lls.c
index b1db21cd56..d2dbc53f41 100644
--- a/tests/checkasm/lls.c
+++ b/tests/checkasm/lls.c
@@ -24,7 +24,7 @@
 do {   \
 double bmg[2], stddev = 10.0;  \
\
-for (size_t i = 0; i < MAX_VARS; i += 2) { \
+for (size_t i = 0; i < MAX_VARS_ALIGN; i += 2) { \
 av_bmg_get(&checkasm_lfg, bmg);\
 buf[i] = bmg[0] * stddev;  \
 buf[i + 1] = bmg[1] * stddev;  \
-- 
2.45.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v1] lavc/qsvdec: Add VVC decoder

2024-06-12 Thread Nuo Mi
Hi Fei,
Thank you for the patch.
Which hardware supports this? Could you provide the link?

On Wed, Jun 12, 2024 at 9:03 AM  wrote:

> From: Fei Wang 
>
> Signed-off-by: Fei Wang 
> ---
>  Changelog  | 1 +
>  configure  | 1 +
>  doc/decoders.texi  | 2 +-
>  libavcodec/allcodecs.c | 1 +
>  libavcodec/qsv.c   | 4 
>  libavcodec/qsvdec.c| 7 ++-
>  libavcodec/version.h   | 2 +-
>  7 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/Changelog b/Changelog
> index 03d6b29ad8..a238a1c1f3 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -12,6 +12,7 @@ version :
>  - qsv_params option added for QSV encoders
>  - VVC decoder compatible with DVB test content
>  - xHE-AAC decoder
> +- Intel QSV-accelerated VVC decoding
>
>
>  version 7.0:
> diff --git a/configure b/configure
> index 6c5b8aab9a..b4cf12658d 100755
> --- a/configure
> +++ b/configure
> @@ -3423,6 +3423,7 @@ av1_qsv_encoder_deps="libvpl"
>  av1_amf_encoder_deps="amf"
>  av1_vaapi_encoder_deps="VAEncPictureParameterBufferAV1"
>  av1_vaapi_encoder_select="cbs_av1 vaapi_encode"
> +vvc_qsv_decoder_select="qsvdec"
>
It's better to follow the alphabetical order.
You can send another patch to fix av1

>
>  # parsers
>  aac_parser_select="adts_header mpeg4audio"
> diff --git a/doc/decoders.texi b/doc/decoders.texi
> index 293c82c2ba..2fcc761d2f 100644
> --- a/doc/decoders.texi
> +++ b/doc/decoders.texi
> @@ -157,7 +157,7 @@ Force to use a specific number of threads
>  @section QSV Decoders
>
>  The family of Intel QuickSync Video decoders (VC1, MPEG-2, H.264, HEVC,
> -JPEG/MJPEG, VP8, VP9, AV1).
> +JPEG/MJPEG, VP8, VP9, AV1, VVC).
>
>  @subsection Common Options
>
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index b102a8069e..a73b4e1673 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -885,6 +885,7 @@ extern const FFCodec ff_vp9_mediacodec_encoder;
>  extern const FFCodec ff_vp9_qsv_decoder;
>  extern const FFCodec ff_vp9_vaapi_encoder;
>  extern const FFCodec ff_vp9_qsv_encoder;
> +extern const FFCodec ff_vvc_qsv_decoder;
>
>  // null codecs
>  extern const FFCodec ff_vnull_decoder;
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 0c6fbd0dc0..221c1b24e5 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -73,6 +73,10 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
>  case AV_CODEC_ID_AV1:
>  return MFX_CODEC_AV1;
>  #endif
> +#if QSV_VERSION_ATLEAST(2, 11)
> +case AV_CODEC_ID_VVC:
> +return MFX_CODEC_VVC;
> +#endif
>
>  default:
>  break;
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index f2cd6ae05c..9ad3439991 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -933,7 +933,8 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext *q,
>  frame->pict_type =
> ff_qsv_map_pictype(aframe.frame->dec_info.FrameType);
>
>  if (avctx->codec_id == AV_CODEC_ID_H264 ||
> -avctx->codec_id == AV_CODEC_ID_HEVC) {
> +avctx->codec_id == AV_CODEC_ID_HEVC ||
> +avctx->codec_id == AV_CODEC_ID_VVC) {
>  if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR)
>  frame->flags |= AV_FRAME_FLAG_KEY;
>  else
> @@ -1300,3 +1301,7 @@ DEFINE_QSV_DECODER(vp9, VP9, NULL)
>  #if CONFIG_AV1_QSV_DECODER
>  DEFINE_QSV_DECODER(av1, AV1, NULL)
>  #endif
> +
> +#if CONFIG_VVC_QSV_DECODER
> +DEFINE_QSV_DECODER(vvc, VVC, NULL)
> +#endif
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 7acb261bb3..37c4c39451 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -29,7 +29,7 @@
>
>  #include "version_major.h"
>
> -#define LIBAVCODEC_VERSION_MINOR   7
> +#define LIBAVCODEC_VERSION_MINOR   8
>  #define LIBAVCODEC_VERSION_MICRO 100
>
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> --
> 2.25.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-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v4] lavc/vvc: Prevent overflow in chroma QP derivation

2024-06-12 Thread Nuo Mi
On Sun, Jun 9, 2024 at 7:18 PM Frank Plowman  wrote:

> On the top of p. 112 in VVC (09/2023):
>
> It is a requirement of bitstream conformance that the values of
> qpInVal[ i ][ j ] and qpOutVal[ i ][ j ] shall be in the range
> of −QpBdOffset to 63, inclusive for i in the range of 0 to
> numQpTables − 1, inclusive, and j in the range of 0 to
> sps_num_points_in_qp_table_minus1[ i ] + 1, inclusive.
>
> Additionally, don't discard the return code from sps_chroma_qp_table.
>
> Applied.
Thank you, Frank
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 01/57] avcodec/vc1: Combine identical checks

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vc1.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index 987e77fcc7..d263c70be7 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -583,21 +583,23 @@ int ff_vc1_decode_entry_point(AVCodecContext *avctx, 
VC1Context *v, GetBitContex
 
 static void rotate_luts(VC1Context *v)
 {
-#define ROTATE(DEF, L, N, C, A) do {  \
-if (v->s.pict_type == AV_PICTURE_TYPE_BI || v->s.pict_type == 
AV_PICTURE_TYPE_B) { \
-C = A;\
-} else {  \
+if (v->s.pict_type == AV_PICTURE_TYPE_BI || v->s.pict_type == 
AV_PICTURE_TYPE_B) {
+v->curr_use_ic = &v->aux_use_ic;
+v->curr_luty   = v->aux_luty;
+v->curr_lutuv  = v->aux_lutuv;
+} else {
+#define ROTATE(DEF, L, N, C) do { \
 DEF;  \
 memcpy(&tmp, L   , sizeof(tmp));  \
 memcpy(L   , N   , sizeof(tmp));  \
 memcpy(N   , &tmp, sizeof(tmp));  \
 C = N;\
-} \
 } while(0)
 
-ROTATE(int tmp, &v->last_use_ic, &v->next_use_ic, 
v->curr_use_ic, &v->aux_use_ic);
-ROTATE(uint8_t tmp[2][256], v->last_luty,   v->next_luty,   v->curr_luty,  
 v->aux_luty);
-ROTATE(uint8_t tmp[2][256], v->last_lutuv,  v->next_lutuv,  v->curr_lutuv, 
 v->aux_lutuv);
+ROTATE(int tmp, &v->last_use_ic, &v->next_use_ic, 
v->curr_use_ic);
+ROTATE(uint8_t tmp[2][256],  v->last_luty,v->next_luty,   
v->curr_luty);
+ROTATE(uint8_t tmp[2][256],  v->last_lutuv,   v->next_lutuv,  
v->curr_lutuv);
+}
 
 INIT_LUT(32, 0, v->curr_luty[0], v->curr_lutuv[0], 0);
 INIT_LUT(32, 0, v->curr_luty[1], v->curr_lutuv[1], 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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v5 1/1] avcodec: add external enc libvvenc for H266/VVC

2024-06-12 Thread Nuo Mi
Hi all,
If there are no objections, I will push it in 3 days.

Thank you,  Christian


On Thu, Jun 6, 2024 at 3:52 AM Christian Bartnik 
wrote:

> From: Thomas Siedel 
>
> Add external encoder VVenC for H266/VVC encoding.
> Register new encoder libvvenc.
> Add libvvenc to wrap the vvenc interface.
> libvvenc implements encoder option: preset,qp,qpa,period,
> passlogfile,stats,vvenc-params,level,tier.
> Enable encoder by adding --enable-libvvenc in configure step.
>
> Co-authored-by: Christian Bartnik chris1031...@gmail.com
> Signed-off-by: Thomas Siedel 
> ---
>  configure |   4 +
>  doc/encoders.texi |  64 +
>  fftools/ffmpeg_mux_init.c |   2 +-
>  libavcodec/Makefile   |   1 +
>  libavcodec/allcodecs.c|   1 +
>  libavcodec/libvvenc.c | 492 ++
>  6 files changed, 563 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/libvvenc.c
>
> diff --git a/configure b/configure
> index 6c5b8aab9a..37ece23376 100755
> --- a/configure
> +++ b/configure
> @@ -293,6 +293,7 @@ External library support:
>--enable-libvorbis   enable Vorbis en/decoding via libvorbis,
> native implementation exists [no]
>--enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
> +  --enable-libvvencenable H.266/VVC encoding via vvenc [no]
>--enable-libwebp enable WebP encoding via libwebp [no]
>--enable-libx264 enable H.264 encoding via x264 [no]
>--enable-libx265 enable HEVC encoding via x265 [no]
> @@ -1966,6 +1967,7 @@ EXTERNAL_LIBRARY_LIST="
>  libvmaf
>  libvorbis
>  libvpx
> +libvvenc
>  libwebp
>  libxevd
>  libxeve
> @@ -3560,6 +3562,7 @@ libvpx_vp8_decoder_deps="libvpx"
>  libvpx_vp8_encoder_deps="libvpx"
>  libvpx_vp9_decoder_deps="libvpx"
>  libvpx_vp9_encoder_deps="libvpx"
> +libvvenc_encoder_deps="libvvenc"
>  libwebp_encoder_deps="libwebp"
>  libwebp_anim_encoder_deps="libwebp"
>  libx262_encoder_deps="libx262"
> @@ -7030,6 +7033,7 @@ enabled libvpx&& {
>  fi
>  }
>
> +enabled libvvenc  && require_pkg_config libvvenc "libvvenc >=
> 1.6.1" "vvenc/vvenc.h" vvenc_get_version
>  enabled libwebp   && {
>  enabled libwebp_encoder  && require_pkg_config libwebp "libwebp
> >= 0.2.0" webp/encode.h WebPGetEncoderVersion
>  enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder
> "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index c82f316f94..496852faeb 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -2378,6 +2378,70 @@ Indicates frame duration
>  For more information about libvpx see:
>  @url{http://www.webmproject.org/}
>
> +@section libvvenc
> +
> +VVenC H.266/VVC encoder wrapper.
> +
> +This encoder requires the presence of the libvvenc headers and library
> +during configuration. You need to explicitly configure the build with
> +@option{--enable-libvvenc}.
> +
> +The VVenC project website is at
> +@url{https://github.com/fraunhoferhhi/vvenc}.
> +
> +@subsection Supported Pixel Formats
> +
> +VVenC supports only 10-bit color spaces as input. But the internal
> (encoded)
> +bit depth can be set to 8-bit or 10-bit at runtime.
> +
> +@subsection Options
> +
> +@table @option
> +@item b
> +Sets target video bitrate.
> +
> +@item g
> +Set the GOP size. Currently support for g=1 (Intra only) or default.
> +
> +@item preset
> +Set the VVenC preset.
> +
> +@item levelidc
> +Set level idc.
> +
> +@item tier
> +Set vvc tier.
> +
> +@item qp
> +Set constant quantization parameter.
> +
> +@item subopt @var{boolean}
> +Set subjective (perceptually motivated) optimization. Default is 1 (on).
> +
> +@item bitdepth8 @var{boolean}
> +Set 8bit coding mode instead of using 10bit. Default is 0 (off).
> +
> +@item period
> +set (intra) refresh period in seconds.
> +
> +@item vvenc-params
> +Set vvenc options using a list of @var{key}=@var{value} couples separated
> +by ":". See @command{vvencapp --fullhelp} or @command{vvencFFapp
> --fullhelp} for a list of options.
> +
> +For example, the options might be provided as:
> +
> +@example
> +intraperiod=64:decodingrefreshtype=idr:poc0idr=1:internalbitdepth=8
> +@end example
> +
> +For example the encoding options might be provided with
> @option{-vvenc-params}:
> +
> +@example
> +ffmpeg -i input -c:v libvvenc -b 1M -vvenc-params
> intraperiod=64:decodingrefreshtype=idr:poc0idr=1:internalbitdepth=8
> output.mp4
> +@end example
> +
> +@end table
> +
>  @section libwebp
>
>  libwebp WebP Image encoder wrapper
> diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
> index 8797265145..ef2922854a 100644
> --- a/fftools/ffmpeg_mux_init.c
> +++ b/fftools/ffmpeg_mux_init.c
> @@ -739,7 +739,7 @@ static int new_stream_video(Muxer *mux, const
> OptionsContext *o,
>   ost->logfile_prefix ? ost->logfile_prefix :
>
> DEFAULT_PASS_LOGFIL

[FFmpeg-devel] Add Mediacodec audio decoders support

2024-06-12 Thread Matthieu Bouron
Hello,

This patchset adds Mediacodec audio decoders support. Currently, only AAC, AMR,
MP3, FLAC, VORBIS and OPUS are supported.

This is mainly useful to avoid shipping Android builds of FFmpeg that are
subjects to licensing/patents (due to AAC and AMR).

Best regards,
Matthieu

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] avcodec/mediacodecdec_common: ensure input buffer timestamp is positive

2024-06-12 Thread Matthieu Bouron
Submitting a buffer with a negative timestamp seems to stall the Mediacodec 
audio
decoders.
---
 libavcodec/mediacodecdec_common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/mediacodecdec_common.c 
b/libavcodec/mediacodecdec_common.c
index d6f91e6e89..4d22db8ecf 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -658,6 +658,8 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, 
MediaCodecDecContext *s,
 if (pts && avctx->pkt_timebase.num && avctx->pkt_timebase.den) {
 pts = av_rescale_q(pts, avctx->pkt_timebase, AV_TIME_BASE_Q);
 }
+if (pts < 0)
+pts = 0;
 
 if (need_draining) {
 uint32_t flags = ff_AMediaCodec_getBufferFlagEndOfStream(codec);
-- 
2.45.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] avcodec: add Mediacodec audio decoders support

2024-06-12 Thread Matthieu Bouron
---
 configure |  14 ++
 libavcodec/Makefile   |   7 +
 libavcodec/allcodecs.c|   7 +
 libavcodec/mediacodecdec.c| 215 ++-
 libavcodec/mediacodecdec_common.c | 333 +++---
 5 files changed, 545 insertions(+), 31 deletions(-)

diff --git a/configure b/configure
index 83284427df..d7de3b73ed 100755
--- a/configure
+++ b/configure
@@ -3321,14 +3321,22 @@ amf_deps_any="libdl LoadLibrary"
 nvenc_deps="ffnvcodec"
 nvenc_deps_any="libdl LoadLibrary"
 
+aac_mediacodec_decoder_deps="mediacodec"
+aac_mediacodec_decoder_select="aac_adtstoasc_bsf aac_parser"
 aac_mf_encoder_deps="mediafoundation"
 ac3_mf_encoder_deps="mediafoundation"
+amrnb_mediacodec_decoder_deps="mediacodec"
+amrnb_mediacodec_decoder_select="amr_parser"
+amrwb_mediacodec_decoder_deps="mediacodec"
+amrwb_mediacodec_decoder_select="amr_parser"
 av1_cuvid_decoder_deps="cuvid CUVIDAV1PICPARAMS"
 av1_mediacodec_decoder_deps="mediacodec"
 av1_mediacodec_encoder_deps="mediacodec"
 av1_mediacodec_encoder_select="extract_extradata_bsf"
 av1_nvenc_encoder_deps="nvenc NV_ENC_PIC_PARAMS_AV1"
 av1_nvenc_encoder_select="atsc_a53"
+flac_mediacodec_decoder_deps="mediacodec"
+flac_mediacodec_decoder_select="flac_parser"
 h263_v4l2m2m_decoder_deps="v4l2_m2m h263_v4l2_m2m"
 h263_v4l2m2m_encoder_deps="v4l2_m2m h263_v4l2_m2m"
 h264_amf_encoder_deps="amf"
@@ -3377,6 +3385,8 @@ mjpeg_qsv_encoder_select="qsvenc"
 mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
 mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
 mp3_mf_encoder_deps="mediafoundation"
+mp3_mediacodec_decoder_deps="mediacodec"
+mp3_mediacodec_decoder_select="mpegaudioheader"
 mpeg1_cuvid_decoder_deps="cuvid"
 mpeg1_v4l2m2m_decoder_deps="v4l2_m2m mpeg1_v4l2_m2m"
 mpeg2_cuvid_decoder_deps="cuvid"
@@ -3394,10 +3404,14 @@ mpeg4_mmal_decoder_deps="mmal"
 mpeg4_omx_encoder_deps="omx"
 mpeg4_v4l2m2m_decoder_deps="v4l2_m2m mpeg4_v4l2_m2m"
 mpeg4_v4l2m2m_encoder_deps="v4l2_m2m mpeg4_v4l2_m2m"
+opus_mediacodec_decoder_deps="mediacodec"
+opus_mediacodec_decoder_select="opus_parser"
 vc1_cuvid_decoder_deps="cuvid"
 vc1_mmal_decoder_deps="mmal"
 vc1_qsv_decoder_select="qsvdec"
 vc1_v4l2m2m_decoder_deps="v4l2_m2m vc1_v4l2_m2m"
+vorbis_mediacodec_decoder_deps="mediacodec"
+vorbis_mediacodec_decoder_select="vorbis_parser"
 vp8_cuvid_decoder_deps="cuvid"
 vp8_mediacodec_decoder_deps="mediacodec"
 vp8_mediacodec_encoder_deps="mediacodec"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 1a44352906..64771b9944 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -196,6 +196,7 @@ OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o 
aaccoder.o aacenctab.o\
   aacenc_pred.o \
   psymodel.o kbdwin.o \
   mpeg4audio_sample_rates.o
+OBJS-$(CONFIG_AAC_MEDIACODEC_DECODER)  += mediacodecdec.o
 OBJS-$(CONFIG_AAC_MF_ENCODER)  += mfenc.o mf_utils.o
 OBJS-$(CONFIG_AASC_DECODER)+= aasc.o msrledec.o
 OBJS-$(CONFIG_AC3_DECODER) += ac3dec_float.o ac3dec_data.o ac3.o \
@@ -222,6 +223,8 @@ OBJS-$(CONFIG_AMRWB_DECODER)   += amrwbdec.o 
celp_filters.o   \
   celp_math.o acelp_filters.o \
   acelp_vectors.o \
   acelp_pitch_delay.o
+OBJS-$(CONFIG_AMRNB_MEDIACODEC_DECODER) += mediacodecdec.o
+OBJS-$(CONFIG_AMRWB_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_AMV_ENCODER) += mjpegenc.o mjpegenc_common.o
 OBJS-$(CONFIG_ANM_DECODER) += anm.o
 OBJS-$(CONFIG_ANULL_DECODER)   += null.o
@@ -367,6 +370,7 @@ OBJS-$(CONFIG_FIC_DECODER) += fic.o
 OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o fits.o
 OBJS-$(CONFIG_FITS_ENCODER)+= fitsenc.o
 OBJS-$(CONFIG_FLAC_DECODER)+= flacdec.o flacdata.o flacdsp.o flac.o
+OBJS-$(CONFIG_FLAC_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_FLAC_ENCODER)+= flacenc.o flacdata.o flacencdsp.o
 OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
 OBJS-$(CONFIG_FLASHSV_ENCODER) += flashsvenc.o
@@ -518,6 +522,7 @@ OBJS-$(CONFIG_MP2FIXED_ENCODER)+= 
mpegaudioenc_fixed.o mpegaudio.o \
   mpegaudiotabs.o
 OBJS-$(CONFIG_MP2FLOAT_DECODER)+= mpegaudiodec_float.o
 OBJS-$(CONFIG_MP3_DECODER) += mpegaudiodec_fixed.o
+OBJS-$(CONFIG_MP3_MEDIACODEC_DECODER)  += mediacodecdec.o
 OBJS-$(CONFIG_MP3_MF_ENCODER)  += mfenc.o mf_utils.o
 OBJS-$(CONFIG_MP3ADU_DECODER)  += mpegaudiodec_fixed.o
 OBJS-$(CONFIG_MP3ADUFLOAT_DECODER) += mpegaudiodec_float.o
@@ -578,6 +583,7 @@ OBJS-$(CONFIG_OPUS_DECODER)+= opusdec.o 
opusdec_celt.o opus_celt.o \
   opusdsp.o opus_parse.o opus_rc.o
 OBJS-$(CONFI

[FFmpeg-devel] [PATCH 02/57] avcodec/mpegvideo_enc: Avoid branches for flipping no_rounding

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 03/57] avcodec/mpegvideo: Don't pretend dct_init can fail

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 04/57] avcodec/mpegvideo: Set dct_unquantize earlier

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 05/57] avcodec/mpegvideo_dec: Set dct_unquantize ptrs only once when possible

2024-06-12 Thread Andreas Rheinhardt
Everything except dct_unquantize_intra for MPEG-4 need only
be set once.

Signed-off-by: Andreas Rheinhardt 
---
 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..75fcf1 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 06/57] configure: Remove obsolete mpeg4_decoder->mpeg4video_parser dependency

2024-06-12 Thread Andreas Rheinhardt
Obsolete since 3ceffe783965767e62d59e8e68ecd265c98460ec.

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 07/57] avcodec/mpegutils: Remap MB_TYPE_ACPRED, add codec-specific MB_TYPE

2024-06-12 Thread 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 
---
 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 0x0100
 
 // 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_INTRAMB_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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 08/57] avcodec/mpegutils: Remap MB_TYPE_{GMC, SKIP, CBP, QUANT}

2024-06-12 Thread 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 
---
 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_INTRAMB_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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 09/57] avcodec/h261dec: Use VLC symbol table

2024-06-12 Thread 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 
---
 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 0x80
+#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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 10/57] avcodec/h261dec: Remove nonsense information from error message

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 11/57] avcodec/mpegutils: Remove always-false check

2024-06-12 Thread Andreas Rheinhardt
SVQ3 does not call ff_print_debug_info2().

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 12/57] avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideo

2024-06-12 Thread 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 
---
 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

[FFmpeg-devel] [PATCH 13/57] avcodec/mpegutils: Move H.264-only macros to h264dec.h

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 14/57] avcodec/mpeg4videodec: Use VLC symbol table

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 15/57] avcodec/mpeg12dec: Use VLC symbol table

2024-06-12 Thread 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 
---
 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   0x2000
-
-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 

[FFmpeg-devel] [PATCH 16/57] avcodec/ituh263dec: Use VLC symbol table

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 17/57] avcodec/mpegvideo_enc: Avoid excessive inlining

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 18/57] avcodec/mpegvideo_enc: Check for existence of ildct cmp functions

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 19/57] avcodec/dvenc: Check for availability of interlaced dct cmp func

2024-06-12 Thread Andreas Rheinhardt
Not every type of comparison function implements every function.

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 20/57] avcodec/motion_est: Factor one-time initialization out of ff_init_me

2024-06-12 Thread 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 
---
 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, 1dia_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, 1pre_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

[FFmpeg-devel] [PATCH 21/57] avcodec/me_cmp: Constify ff_set_cmp()

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 22/57] avcodec/me_cmp, motion_est: Move me_(pre_)?_cmp etc. to MotionEstContext

2024-06-12 Thread 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 
---
 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, 1pre_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[

[FFmpeg-devel] [PATCH 23/57] avcodec/me_cmp, mpegvideo: Move frame_skip_cmp to MpegEncContext

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 24/57] avcodec/me_cmp, dvenc, mpegvideo: Move ildct_cmp to its users

2024-06-12 Thread 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 
---
 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(MpegE

[FFmpeg-devel] [PATCH 25/57] avcodec/me_cmp, motion_est: Sanitize permissible cmp_funcs

2024-06-12 Thread 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 
---
 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 
+
 #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(

[FFmpeg-devel] [PATCH 26/57] avcodec/motion_est: Store remaining required me_cmp_funcs

2024-06-12 Thread Andreas Rheinhardt
This avoids using MpegEncContext.mecc; it already allows
to avoid touching the latter for snowenc and svq1enc.

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 27/57] avcodec/me_cmp: Zero MECmpContext in ff_me_cmp_init()

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 28/57] avcodec/mpegvideo_enc: Avoid branch for sse vs nsse cmp

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 29/57] avcodec/mpegvideo_enc: Only keep what is used from MECmpContext

2024-06-12 Thread 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 
---
 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  =

[FFmpeg-devel] [PATCH 30/57] avcodec/mpegvideo_enc: Initialize qscale tab for all codecs

2024-06-12 Thread Andreas Rheinhardt
Calling it is the first thing ff_clean_h263_qscales() and
ff_clean_mpeg4_qscales() do anyway.

Signed-off-by: Andreas Rheinhardt 
---
 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; imb_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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 31/57] avcodec/mpegvideo_enc: Don't update qscale unnecessarily

2024-06-12 Thread Andreas Rheinhardt
The new value will be overwritten in ff_set_qscale() below.

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 32/57] avcodec/mpegutils: Fix ff_draw_horiz_band()

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 33/57] avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy data

2024-06-12 Thread 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 
---
 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-requ...@ffm

[FFmpeg-devel] [PATCH 34/57] avcodec/mpeg12dec: Disable allocating scratchpad buffers when possible

2024-06-12 Thread Andreas Rheinhardt
They are no longer used by the MPEG-1/2 decoders except when
using lowres.

Signed-off-by: Andreas Rheinhardt 
---
 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 
 #include 
 #include 
 
@@ -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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 35/57] avcodec/mpegvideo_dec: Don't alloc framesize-bufs in update_thread_ctx

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 36/57] avcodec/mpegvideo_dec: Don't keep droppable in sync in update_thread_ctx

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 37/57] avcodec/mpegutils: Don't output wrong mb skip values

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 38/57] avcodec/svq1enc: Stop copying PutBitContext unnecessarily

2024-06-12 Thread Andreas Rheinhardt
Possible since 404fe63e23433aa559cee5366cb26f78b425e7e5.

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 39/57] avcodec/ituh263enc: Inline constants

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 40/57] avcodec/h263enc: Remove no-output code

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 41/57] avcodec/mpeg4videodec: Inline constants

2024-06-12 Thread Andreas Rheinhardt
Partitioned macroblocks are always 8bit and not studio profile.

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 42/57] avcodec/mpeg4videodec: Don't initialize unused stuff

2024-06-12 Thread Andreas Rheinhardt
Only the intra scantable is used for studio profile.

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 43/57] avcodec/vc1_block: Remove unnecessary assignments

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 44/57] avcodec/vc1_block: Simplify resetting coded_block

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 45/57] avcodec/mpeg4videodec: Remove always-false check

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 46/57] avcodec/mpeg12enc: Use AVCodecContext, not priv ctx as logctx

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 47/57] avcodec/mpeg12enc: Pass AVCodecContext* directly

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 48/57] avcodec/msmpeg4enc: Combine writing bits

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 49/57] avcodec/h261dec: Don't reset gob_start_code_skipped in h261_decode_init()

2024-06-12 Thread Andreas Rheinhardt
It always gets reset at the start of h261_decode_frame().

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 50/57] avcodec/h261dec: Fix UB NULL + 0, remove broken resync code

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 51/57] avcodec/h261dec: Simplify decoding GOB header

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 52/57] avcodec/mpv_reconstruct_mb_template: Optimize always-true branch away

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 53/57] avcodec/mpegvideo_dec: Remove unnecessary FFMIN

2024-06-12 Thread Andreas Rheinhardt
No mpegvideo-based decoder supports lowres > 3,
so the FFMIN here are unnecessary.

Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 54/57] avcodec/mpegvideo: Join loops when initializing ScanTable

2024-06-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 55/57] avcodec/mpv_reconstruct_mb_template: Optimize WMV2 code away if possible

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 56/57] avcodec/mpeg4videodec: Don't initialize unused inter_scantable

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 57/57] avcodec/mpeg_er: Don't set block_index unnecessarily

2024-06-12 Thread 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 
---
 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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] Add Mediacodec audio decoders support

2024-06-12 Thread Paul B Mahol
FFmpeg RIP
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/vp8dsp: R-V V put_bilin_h v unroll

2024-06-12 Thread Rémi Denis-Courmont
Le torstaina 30. toukokuuta 2024, 18.26.53 EEST u...@foxmail.com a écrit :
> From: sunyuechi 
> 
> Since len < 64, the registers are sufficient, so it can be
> directly unrolled (a4 is even).
> 
> Another benefit of unrolling is that it reduces one load operation
> vertically compared to horizontally.
> 
>  old new
>  C908   X60  C908   X60
> vp8_put_bilin4_h_c :6.25.5 :6.25.5
> vp8_put_bilin4_h_rvv_i32   :2.22.0 :1.51.5
> vp8_put_bilin4_v_c :6.55.7 :6.25.7
> vp8_put_bilin4_v_rvv_i32   :2.22.0 :1.21.5
> vp8_put_bilin8_h_c :   24.2   21.5 :   24.2   21.5
> vp8_put_bilin8_h_rvv_i32   :5.24.7 :3.53.5
> vp8_put_bilin8_v_c :   24.5   21.7 :   24.5   21.7
> vp8_put_bilin8_v_rvv_i32   :5.24.7 :3.53.2
> vp8_put_bilin16_h_c:   48.0   42.7 :   48.0   42.7
> vp8_put_bilin16_h_rvv_i32  :5.75.0 :5.24.5
> vp8_put_bilin16_v_c:   48.2   43.0 :   48.2   42.7
> vp8_put_bilin16_v_rvv_i32  :5.75.2 :4.54.2
> ---
>  libavcodec/riscv/vp8dsp_rvv.S | 34 +-
>  1 file changed, 29 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/riscv/vp8dsp_rvv.S b/libavcodec/riscv/vp8dsp_rvv.S
> index 3360a38cac..5bea6cba9c 100644
> --- a/libavcodec/riscv/vp8dsp_rvv.S
> +++ b/libavcodec/riscv/vp8dsp_rvv.S
> @@ -172,11 +172,35 @@ func ff_put_vp8_bilin4_\type\()_rvv, zve32x
>  li  t4, 4
>  sub t1, t1, \mn
>  1:
> -addia4, a4, -1
> -bilin_load  v0, \type, \mn

Does this not render the type parameter of bilin_load useless (always h)?
(Not a blocker for this patch.)

> -vse8.v  v0, (a0)
> -add a2, a2, a3
> -add a0, a0, a1
> +add t0, a2, a3
> +add t2, a0, a1
> +addia4, a4, -2
> +.ifc \type,v
> +add t3, t0, a3
> +.else
> +addit5, a2, 1
> +addit3, t0, 1
> +vle8.v  v2, (t5)

Not sure if I already asked this but is this really faster than slide1? 
Normally we want to minimise the work of the memory bus.

> +.endif
> +vle8.v  v0, (a2)
> +vle8.v  v4, (t0)
> +vle8.v  v6, (t3)
> +vwmulu.vx   v28, v0, t1
> +vwmulu.vx   v26, v4, t1
> +.ifc \type,v
> +vwmaccu.vx  v28, \mn, v4
> +.else
> +vwmaccu.vx  v28, \mn, v2
> +.endif
> +vwmaccu.vx  v26, \mn, v6
> +vwaddu.wx   v24, v28, t4
> +vwaddu.wx   v22, v26, t4
> +vnsra.wiv30, v24, 3
> +vnsra.wiv0, v22, 3
> +vse8.v  v30, (a0)
> +vse8.v  v0, (t2)
> +add a2, t0, a3
> +add a0, t2, a1
>  bneza4, 1b
> 
>  ret

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 2/4] swscale/x86: add sse4 {lum, chr}ConvertRange

2024-06-12 Thread Ramiro Polla
Hi,

On Tue, Jun 11, 2024 at 8:42 PM James Almer  wrote:
>
> On 6/11/2024 3:26 PM, Michael Niedermayer wrote:
> > On Tue, Jun 11, 2024 at 02:28:56PM +0200, Ramiro Polla wrote:
> >> chrRangeFromJpeg_8_c: 28.7
> >> chrRangeFromJpeg_8_sse4: 16.2
> >> chrRangeFromJpeg_24_c: 152.7
> >> chrRangeFromJpeg_24_sse4: 29.7
> >> chrRangeFromJpeg_128_c: 366.5
> >> chrRangeFromJpeg_128_sse4: 233.0
> >> chrRangeFromJpeg_144_c: 408.0
> >> chrRangeFromJpeg_144_sse4: 182.5
> >> chrRangeFromJpeg_256_c: 698.7
> >> chrRangeFromJpeg_256_sse4: 325.5
> >> chrRangeFromJpeg_512_c: 1348.7
> >> chrRangeFromJpeg_512_sse4: 660.2
> >> chrRangeToJpeg_8_c: 37.7
> >> chrRangeToJpeg_8_sse4: 16.2
> >> chrRangeToJpeg_24_c: 115.7
> >> chrRangeToJpeg_24_sse4: 36.2
> >> chrRangeToJpeg_128_c: 631.2
> >> chrRangeToJpeg_128_sse4: 163.7
> >> chrRangeToJpeg_144_c: 710.7
> >> chrRangeToJpeg_144_sse4: 183.0
> >> chrRangeToJpeg_256_c: 1253.0
> >> chrRangeToJpeg_256_sse4: 343.5
> >> chrRangeToJpeg_512_c: 2491.2
> >> chrRangeToJpeg_512_sse4: 654.2
> >> lumRangeFromJpeg_8_c: 11.7
> >> lumRangeFromJpeg_8_sse4: 10.5
> >> lumRangeFromJpeg_24_c: 38.5
> >> lumRangeFromJpeg_24_sse4: 19.0
> >> lumRangeFromJpeg_128_c: 237.5
> >> lumRangeFromJpeg_128_sse4: 79.2
> >> lumRangeFromJpeg_144_c: 255.7
> >> lumRangeFromJpeg_144_sse4: 90.5
> >> lumRangeFromJpeg_256_c: 441.5
> >> lumRangeFromJpeg_256_sse4: 161.7
> >> lumRangeFromJpeg_512_c: 879.0
> >> lumRangeFromJpeg_512_sse4: 333.2
> >> lumRangeToJpeg_8_c: 20.0
> >> lumRangeToJpeg_8_sse4: 11.7
> >> lumRangeToJpeg_24_c: 61.5
> >> lumRangeToJpeg_24_sse4: 17.7
> >> lumRangeToJpeg_128_c: 357.5
> >> lumRangeToJpeg_128_sse4: 80.0
> >> lumRangeToJpeg_144_c: 371.5
> >> lumRangeToJpeg_144_sse4: 93.2
> >> lumRangeToJpeg_256_c: 651.5
> >> lumRangeToJpeg_256_sse4: 164.5
> >> lumRangeToJpeg_512_c: 1279.0
> >> lumRangeToJpeg_512_sse4: 333.7
> >> ---
> >>   libswscale/swscale_internal.h|   1 +
> >>   libswscale/utils.c   |   2 +
> >>   libswscale/x86/Makefile  |   1 +
> >>   libswscale/x86/range_convert.asm | 130 +++
> >>   libswscale/x86/swscale.c |  36 +
> >>   5 files changed, 170 insertions(+)
> >>   create mode 100644 libswscale/x86/range_convert.asm
> >
> > breaks x86-32 build
> >
> > LDffmpeg_g
> > /usr/lib/gcc-cross/i686-linux-gnu/7/../../../../i686-linux-gnu/bin/ld: 
> > libswscale/libswscale.a(utils.o): in function `sws_setColorspaceDetails':
> > ffmpeg/linux32/src/libswscale/utils.c:1086: undefined reference to 
> > `ff_sws_init_range_convert_x86'
> > collect2: error: ld returned 1 exit status
> > make: *** [Makefile:139: ffmpeg_g] Error 1
> >
> > thx
>
> The functions are wrapped in ARCH_X86_64 checks for seemingly no reason,
> so they should be removed in the next iteration.

Fixed.

James walked me through on IRC to optimize and improve the functions
in a way that they work both with sse2 and avx2. New patch attached.
From 9e49e72f6766e96cc06bec869fb776fff4c477bf Mon Sep 17 00:00:00 2001
From: Ramiro Polla 
Date: Thu, 6 Jun 2024 18:33:34 +0200
Subject: [PATCH] swscale/x86: add sse2 and avx2 {lum,chr}ConvertRange

chrRangeFromJpeg_8_c: 22.3
chrRangeFromJpeg_8_sse2: 13.3
chrRangeFromJpeg_8_avx2: 13.3
chrRangeFromJpeg_24_c: 72.8
chrRangeFromJpeg_24_sse2: 22.3
chrRangeFromJpeg_24_avx2: 17.5
chrRangeFromJpeg_128_c: 345.5
chrRangeFromJpeg_128_sse2: 106.0
chrRangeFromJpeg_128_avx2: 57.8
chrRangeFromJpeg_144_c: 380.5
chrRangeFromJpeg_144_sse2: 118.5
chrRangeFromJpeg_144_avx2: 62.3
chrRangeFromJpeg_256_c: 646.3
chrRangeFromJpeg_256_sse2: 218.8
chrRangeFromJpeg_256_avx2: 109.0
chrRangeFromJpeg_512_c: 1461.5
chrRangeFromJpeg_512_sse2: 426.5
chrRangeFromJpeg_512_avx2: 211.5
chrRangeToJpeg_8_c: 37.8
chrRangeToJpeg_8_sse2: 10.5
chrRangeToJpeg_8_avx2: 14.0
chrRangeToJpeg_24_c: 114.3
chrRangeToJpeg_24_sse2: 23.5
chrRangeToJpeg_24_avx2: 16.3
chrRangeToJpeg_128_c: 633.5
chrRangeToJpeg_128_sse2: 107.5
chrRangeToJpeg_128_avx2: 55.0
chrRangeToJpeg_144_c: 758.3
chrRangeToJpeg_144_sse2: 132.0
chrRangeToJpeg_144_avx2: 64.5
chrRangeToJpeg_256_c: 1345.0
chrRangeToJpeg_256_sse2: 218.0
chrRangeToJpeg_256_avx2: 105.3
chrRangeToJpeg_512_c: 2524.0
chrRangeToJpeg_512_sse2: 417.0
chrRangeToJpeg_512_avx2: 218.8
lumRangeFromJpeg_8_c: 11.8
lumRangeFromJpeg_8_sse2: 11.0
lumRangeFromJpeg_8_avx2: 10.3
lumRangeFromJpeg_24_c: 38.5
lumRangeFromJpeg_24_sse2: 15.5
lumRangeFromJpeg_24_avx2: 12.5
lumRangeFromJpeg_128_c: 232.3
lumRangeFromJpeg_128_sse2: 60.0
lumRangeFromJpeg_128_avx2: 26.8
lumRangeFromJpeg_144_c: 259.5
lumRangeFromJpeg_144_sse2: 65.3
lumRangeFromJpeg_144_avx2: 29.0
lumRangeFromJpeg_256_c: 464.5
lumRangeFromJpeg_256_sse2: 107.5
lumRangeFromJpeg_256_avx2: 54.0
lumRangeFromJpeg_512_c: 897.5
lumRangeFromJpeg_512_sse2: 224.5
lumRangeFromJpeg_512_avx2: 109.8
lumRangeToJpeg_8_c: 17.8
lumRangeToJpeg_8_sse2: 11.0
lumRangeToJpeg_8_avx2: 11.8
lumRangeToJpeg_24_c: 56.3
lumRangeToJpeg_24_sse2: 11.0
lumRangeToJpeg_24_avx2: 12.5
lumRangeToJpeg_128_c: 333.8
lumRangeToJpeg_128_sse2: 53.3
lumRangeToJ

[FFmpeg-devel] [PATCH] lavc/vp8dsp: R-V V bilin_load to bilin_load_h

2024-06-12 Thread uk7b
From: sunyuechi 

---
 libavcodec/riscv/vp8dsp_rvv.S | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/libavcodec/riscv/vp8dsp_rvv.S b/libavcodec/riscv/vp8dsp_rvv.S
index a5f2e34f44..6ad349741e 100644
--- a/libavcodec/riscv/vp8dsp_rvv.S
+++ b/libavcodec/riscv/vp8dsp_rvv.S
@@ -150,12 +150,8 @@ func ff_vp8_idct_dc_add4uv_rvv, zve32x
 ret
 endfunc
 
-.macro bilin_load dst type mn
-.ifc \type,v
-add t5, a2, a3
-.else
+.macro bilin_load_h dst mn
 addit5, a2, 1
-.endif
 vle8.v  \dst, (a2)
 vle8.v  v2, (t5)
 vwmulu.vx   v28, \dst, t1
@@ -217,12 +213,12 @@ func ff_put_vp8_bilin4_hv_rvv, zve32x
 sub t1, t3, a5
 sub t2, t3, a6
 li  t4, 4
-bilin_load  v4, h, a5
+bilin_load_hv4, a5
 add a2, a2, a3
 1:
 addia4, a4, -1
 vwmulu.vx   v20, v4, t2
-bilin_load  v4, h, a5
+bilin_load_hv4, a5
 vwmaccu.vx  v20, a6, v4
 vwaddu.wx   v24, v20, t4
 vnsra.wiv0, v24, 3
-- 
2.45.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/vp8dsp: R-V V put_bilin_h v unroll

2024-06-12 Thread flow gg
> Does this not render the type parameter of bilin_load useless (always h)?
> (Not a blocker for this patch.)

Yes, this was needed in the initial version, but it is no longer required.
I just sent a patch.

> Not sure if I already asked this but is this really faster than slide1?
> Normally we want to minimise the work of the memory bus.

Originally it was slide, but based on your review, it was changed to load,
which should be better.

review: "Can't we skip the slide and just load the vector at a2+1? Also
then, we can keep VL=len and halve the multipler."

Rémi Denis-Courmont  于2024年6月12日周三 22:41写道:

> Le torstaina 30. toukokuuta 2024, 18.26.53 EEST u...@foxmail.com a écrit :
> > From: sunyuechi 
> >
> > Since len < 64, the registers are sufficient, so it can be
> > directly unrolled (a4 is even).
> >
> > Another benefit of unrolling is that it reduces one load operation
> > vertically compared to horizontally.
> >
> >  old new
> >  C908   X60  C908   X60
> > vp8_put_bilin4_h_c :6.25.5 :6.25.5
> > vp8_put_bilin4_h_rvv_i32   :2.22.0 :1.51.5
> > vp8_put_bilin4_v_c :6.55.7 :6.25.7
> > vp8_put_bilin4_v_rvv_i32   :2.22.0 :1.21.5
> > vp8_put_bilin8_h_c :   24.2   21.5 :   24.2   21.5
> > vp8_put_bilin8_h_rvv_i32   :5.24.7 :3.53.5
> > vp8_put_bilin8_v_c :   24.5   21.7 :   24.5   21.7
> > vp8_put_bilin8_v_rvv_i32   :5.24.7 :3.53.2
> > vp8_put_bilin16_h_c:   48.0   42.7 :   48.0   42.7
> > vp8_put_bilin16_h_rvv_i32  :5.75.0 :5.24.5
> > vp8_put_bilin16_v_c:   48.2   43.0 :   48.2   42.7
> > vp8_put_bilin16_v_rvv_i32  :5.75.2 :4.54.2
> > ---
> >  libavcodec/riscv/vp8dsp_rvv.S | 34 +-
> >  1 file changed, 29 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavcodec/riscv/vp8dsp_rvv.S
> b/libavcodec/riscv/vp8dsp_rvv.S
> > index 3360a38cac..5bea6cba9c 100644
> > --- a/libavcodec/riscv/vp8dsp_rvv.S
> > +++ b/libavcodec/riscv/vp8dsp_rvv.S
> > @@ -172,11 +172,35 @@ func ff_put_vp8_bilin4_\type\()_rvv, zve32x
> >  li  t4, 4
> >  sub t1, t1, \mn
> >  1:
> > -addia4, a4, -1
> > -bilin_load  v0, \type, \mn
>
> Does this not render the type parameter of bilin_load useless (always h)?
> (Not a blocker for this patch.)
>
> > -vse8.v  v0, (a0)
> > -add a2, a2, a3
> > -add a0, a0, a1
> > +add t0, a2, a3
> > +add t2, a0, a1
> > +addia4, a4, -2
> > +.ifc \type,v
> > +add t3, t0, a3
> > +.else
> > +addit5, a2, 1
> > +addit3, t0, 1
> > +vle8.v  v2, (t5)
>
> Not sure if I already asked this but is this really faster than slide1?
> Normally we want to minimise the work of the memory bus.
>
> > +.endif
> > +vle8.v  v0, (a2)
> > +vle8.v  v4, (t0)
> > +vle8.v  v6, (t3)
> > +vwmulu.vx   v28, v0, t1
> > +vwmulu.vx   v26, v4, t1
> > +.ifc \type,v
> > +vwmaccu.vx  v28, \mn, v4
> > +.else
> > +vwmaccu.vx  v28, \mn, v2
> > +.endif
> > +vwmaccu.vx  v26, \mn, v6
> > +vwaddu.wx   v24, v28, t4
> > +vwaddu.wx   v22, v26, t4
> > +vnsra.wiv30, v24, 3
> > +vnsra.wiv0, v22, 3
> > +vse8.v  v30, (a0)
> > +vse8.v  v0, (t2)
> > +add a2, t0, a3
> > +add a0, t2, a1
> >  bneza4, 1b
> >
> >  ret
>
> --
> 雷米‧德尼-库尔蒙
> http://www.remlab.net/
>
>
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] avutil/macos_kperf: Fix assert which makes kperf failed to run

2024-06-12 Thread Zhao Zhili
From: Zhao Zhili 

On m1, kpc_get_counter_count(KPC_MASK) return 8. The exact value
doesn't matter in our case.
---
 libavutil/macos_kperf.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavutil/macos_kperf.c b/libavutil/macos_kperf.c
index a0bc845fd3..906b276a34 100644
--- a/libavutil/macos_kperf.c
+++ b/libavutil/macos_kperf.c
@@ -67,14 +67,15 @@ KPERF_LIST
 #define KPC_CLASS_POWER_MASK(1 << 2)
 #define KPC_CLASS_RAWPMU_MASK   (1 << 3)
 
-#define COUNTERS_COUNT 10
+#define KPC_MAX_COUNTERS 32
 #define CONFIG_COUNT 8
 #define KPC_MASK (KPC_CLASS_CONFIGURABLE_MASK | KPC_CLASS_FIXED_MASK)
 
 static void kperf_init(void)
 {
-uint64_t config[COUNTERS_COUNT] = {0};
+uint64_t config[CONFIG_COUNT] = {0};
 void *kperf = NULL;
+uint32_t n;
 
 av_assert0(kperf = 
dlopen("/System/Library/PrivateFrameworks/kperf.framework/Versions/A/kperf", 
RTLD_LAZY));
 
@@ -82,8 +83,10 @@ static void kperf_init(void)
 KPERF_LIST
 #undef F
 
-av_assert0(kpc_get_counter_count(KPC_MASK) == COUNTERS_COUNT);
-av_assert0(kpc_get_config_count(KPC_MASK) == CONFIG_COUNT);
+n = kpc_get_counter_count(KPC_MASK);
+av_assert0(n <= KPC_MAX_COUNTERS);
+n = kpc_get_config_count(KPC_MASK);
+av_assert0(n <= CONFIG_COUNT);
 
 config[0] = CPMU_CORE_CYCLE | CFGWORD_EL0A64EN_MASK;
 // config[3] = CPMU_INST_BRANCH | CFGWORD_EL0A64EN_MASK;
@@ -99,11 +102,11 @@ static void kperf_init(void)
 uint64_t ff_kperf_cycles(void)
 {
 static AVOnce init_static_once = AV_ONCE_INIT;
-uint64_t counters[COUNTERS_COUNT];
+uint64_t counters[KPC_MAX_COUNTERS];
 
 ff_thread_once(&init_static_once, kperf_init);
 
-if (kpc_get_thread_counters(0, COUNTERS_COUNT, counters)) {
+if (kpc_get_thread_counters(0, KPC_MAX_COUNTERS, counters)) {
 return -1;
 }
 
-- 
2.42.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] avutil/timer: define macos kperf as AV_READ_TIME

2024-06-12 Thread Zhao Zhili
From: Zhao Zhili 

Firstly, make ff_kperf_cycles as an implementation of AV_READ_TIME
avoids code duplication.

Secondly, fix compilation error since 6a18c0bc87e when macos-kperf
is enabled. mach_time.h is included only when CONFIG_MACOS_KPERF
is 0. The error happened due to define mach_absolute_time as
AV_READ_TIME but missing include mach_time.h. Define macos kperf
as AV_READ_TIME fixed the issue.
---
 libavutil/macos_kperf.c   |  8 +++-
 libavutil/macos_kperf.h   |  3 ++-
 libavutil/timer.h | 10 --
 tests/checkasm/checkasm.c |  8 
 4 files changed, 5 insertions(+), 24 deletions(-)

diff --git a/libavutil/macos_kperf.c b/libavutil/macos_kperf.c
index 9fb047..a0bc845fd3 100644
--- a/libavutil/macos_kperf.c
+++ b/libavutil/macos_kperf.c
@@ -96,15 +96,13 @@ static void kperf_init(void)
 av_assert0(kpc_set_thread_counting(KPC_MASK) == 0);
 }
 
-void ff_kperf_init(void)
+uint64_t ff_kperf_cycles(void)
 {
 static AVOnce init_static_once = AV_ONCE_INIT;
+uint64_t counters[COUNTERS_COUNT];
+
 ff_thread_once(&init_static_once, kperf_init);
-}
 
-uint64_t ff_kperf_cycles(void)
-{
-uint64_t counters[COUNTERS_COUNT];
 if (kpc_get_thread_counters(0, COUNTERS_COUNT, counters)) {
 return -1;
 }
diff --git a/libavutil/macos_kperf.h b/libavutil/macos_kperf.h
index d039691340..40bbc616df 100644
--- a/libavutil/macos_kperf.h
+++ b/libavutil/macos_kperf.h
@@ -21,7 +21,8 @@
 
 #include 
 
-void ff_kperf_init(void);
 uint64_t ff_kperf_cycles(void);
 
+#define AV_READ_TIME ff_kperf_cycles
+
 #endif /* AVUTIL_MACOS_KPERF_H */
diff --git a/libavutil/timer.h b/libavutil/timer.h
index 6bd6a0c645..16f2b1a96c 100644
--- a/libavutil/timer.h
+++ b/libavutil/timer.h
@@ -142,16 +142,6 @@
 read(linux_perf_fd, &tperf, sizeof(tperf)); \
 TIMER_REPORT(id, tperf)
 
-#elif CONFIG_MACOS_KPERF
-
-#define START_TIMER \
-uint64_t tperf; \
-ff_kperf_init();\
-tperf = ff_kperf_cycles();
-
-#define STOP_TIMER(id)  \
-TIMER_REPORT(id, ff_kperf_cycles() - tperf);
-
 #elif defined(AV_READ_TIME)
 #define START_TIMER \
 uint64_t tend;  \
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 2329e2e1bc..28237b4d25 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -775,12 +775,6 @@ static int bench_init_linux(void)
 }
 return 0;
 }
-#elif CONFIG_MACOS_KPERF
-static int bench_init_kperf(void)
-{
-ff_kperf_init();
-return 0;
-}
 #else
 static int bench_init_ffmpeg(void)
 {
@@ -806,8 +800,6 @@ static int bench_init(void)
 {
 #if CONFIG_LINUX_PERF
 int ret = bench_init_linux();
-#elif CONFIG_MACOS_KPERF
-int ret = bench_init_kperf();
 #else
 int ret = bench_init_ffmpeg();
 #endif
-- 
2.42.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCHv4 1/4] lavc/h263dsp: add DCT dequantisation functions

2024-06-12 Thread James Almer

On 6/10/2024 5:23 PM, Rémi Denis-Courmont wrote:

Note that optimised implementations of these functions will be taken
into actual use only if MpegEncContext.dct_unquantize_h263_{inter,intra}
are *not* overloaded by existing optimisations.
---
  libavcodec/h263dsp.c | 25 +
  libavcodec/h263dsp.h |  4 
  2 files changed, 29 insertions(+)

diff --git a/libavcodec/h263dsp.c b/libavcodec/h263dsp.c
index 6a13353499..755d7077bf 100644
--- a/libavcodec/h263dsp.c
+++ b/libavcodec/h263dsp.c
@@ -23,6 +23,29 @@
  #include "config.h"
  #include "h263dsp.h"
  
+static void h263_dct_unquantize_inter_c(int16_t *block, size_t nCoeffs,

+int qmul, int qadd)
+{
+for (size_t i = 0; i <= nCoeffs; i++) {
+int level = block[i];
+
+if (level) {
+if (level < 0)
+level = level * qmul - qadd;
+else
+level = level * qmul + qadd;
+block[i] = level;
+}
+}
+}
+
+static void h263_dct_unquantize_intra_c(int16_t *block, size_t nCoeffs,
+int qmul, int qadd)
+{
+if (nCoeffs > 0)
+h263_dct_unquantize_inter_c(block + 1, nCoeffs - 1, qmul, qadd);


I think you can avoid this branch by doing:

for (size_t i = 1; i <= nCoeffs; i++) {
int level = block[i];

if (level) {
if (level < 0)
level = level * qmul - qadd;
else
level = level * qmul + qadd;
block[i] = level;
}
}


+}
+
  const uint8_t ff_h263_loop_filter_strength[32] = {
  0, 1, 1, 2, 2, 3, 3,  4,  4,  4,  5,  5,  6,  6,  7, 7,
  7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12
@@ -116,6 +139,8 @@ static void h263_v_loop_filter_c(uint8_t *src, int stride, 
int qscale)
  
  av_cold void ff_h263dsp_init(H263DSPContext *ctx)

  {
+ctx->h263_dct_unquantize_intra = h263_dct_unquantize_intra_c;
+ctx->h263_dct_unquantize_inter = h263_dct_unquantize_inter_c;
  ctx->h263_h_loop_filter = h263_h_loop_filter_c;
  ctx->h263_v_loop_filter = h263_v_loop_filter_c;
  
diff --git a/libavcodec/h263dsp.h b/libavcodec/h263dsp.h

index 2dccd23392..0ecbe83314 100644
--- a/libavcodec/h263dsp.h
+++ b/libavcodec/h263dsp.h
@@ -24,6 +24,10 @@
  extern const uint8_t ff_h263_loop_filter_strength[32];
  
  typedef struct H263DSPContext {

+void (*h263_dct_unquantize_intra)(int16_t *block /* align 16 */,
+  size_t len, int mul, int add);
+void (*h263_dct_unquantize_inter)(int16_t *block /* align 16 */,
+  size_t len, int mul, int add);
  void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
  void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
  } H263DSPContext;

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCHv4 3/4] checkasm/h263dsp: test dct_unquantize_{intra, inter}

2024-06-12 Thread James Almer

On 6/10/2024 5:23 PM, Rémi Denis-Courmont wrote:

---
  tests/checkasm/h263dsp.c | 53 +++-
  1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/tests/checkasm/h263dsp.c b/tests/checkasm/h263dsp.c
index 2d0957a90b..a8530403ee 100644
--- a/tests/checkasm/h263dsp.c
+++ b/tests/checkasm/h263dsp.c
@@ -18,13 +18,61 @@
   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   */
  
+#include 

  #include 
  
  #include "checkasm.h"
  
-#include "libavcodec/h263dsp.h"

+#include "libavutil/avassert.h"
  #include "libavutil/mem.h"
  #include "libavutil/mem_internal.h"
+#include "libavcodec/h263dsp.h"
+#include "libavcodec/mpegvideodata.h"
+
+static uint_fast8_t mpeg_qscale_rnd(void)
+{
+int n = rnd(), q = (n >> 1) & 31;
+
+if (n & 1)
+return ff_mpeg2_non_linear_qscale[q];
+else
+return q << 1;
+}
+
+typedef void (*unquantizer)(int16_t *, size_t, int, int);
+
+static void check_dct_unquantize(unquantizer func, const char *name)
+{
+#define LEN 64
+LOCAL_ALIGNED_16(int16_t, block0, [LEN]);
+LOCAL_ALIGNED_16(int16_t, block1, [LEN]);
+size_t coeffs = rnd() % LEN;
+const int qscale = mpeg_qscale_rnd();
+const int qmul = qscale << 1;
+const int qadd = (rnd() & 1) ? (qscale - 1) | 1 : 0;
+
+declare_func(void, int16_t *, size_t, int, int);
+
+for (size_t i = 0; i < LEN; i++)
+block1[i] = block0[i] = (rnd() & 1) ? rnd() : 0;


Don't waste rng bits.

for (size_t i = 0; i < LEN; i++) {
int n = rnd();
block1[i] = block0[i] = (n & 1) ? n : 0;
}


+
+if (check_func(func, "h263dsp.dct_unquantize_%s", name)) {
+call_ref(block0, 0, qmul, qadd);
+call_new(block1, 0, qmul, qadd);
+
+if (block0[0] != block1[0])
+fail();
+
+av_assert0(coeffs < LEN);
+call_ref(block0, coeffs, qmul, qadd);
+call_new(block1, coeffs, qmul, qadd);
+
+if (memcmp(block0, block1, (coeffs + 1) * sizeof (int16_t)))
+fail();
+
+bench_new(block1, LEN - 1, qmul, qadd);
+}
+}
  
  typedef void (*filter)(uint8_t *src, int stride, int qscale);
  
@@ -56,6 +104,9 @@ void checkasm_check_h263dsp(void)

  H263DSPContext ctx;
  
  ff_h263dsp_init(&ctx);

+check_dct_unquantize(ctx.h263_dct_unquantize_intra, "intra");
+check_dct_unquantize(ctx.h263_dct_unquantize_inter, "inter");
+report("dct_unquantize");
  check_loop_filter('h', ctx.h263_h_loop_filter);
  check_loop_filter('v', ctx.h263_v_loop_filter);
  report("loop_filter");

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] tests/checkasm: Remove check on linux perf fd in uninit

2024-06-12 Thread Zhao Zhili
From: Zhao Zhili 

The check should be >= 0, not > 0. The check itself is redundant
since uninit only being called after init is success.
---
 tests/checkasm/checkasm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 28237b4d25..bbcc90f91f 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -814,8 +814,7 @@ static int bench_init(void)
 static void bench_uninit(void)
 {
 #if CONFIG_LINUX_PERF
-if (state.sysfd > 0)
-close(state.sysfd);
+close(state.sysfd);
 #endif
 }
 
-- 
2.42.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCHv5 1/4] lavc/h263dsp: add DCT dequantisation functions

2024-06-12 Thread James Almer

On 6/12/2024 1:47 AM, Rémi Denis-Courmont wrote:

Note that optimised implementations of these functions will be taken
into actual use only if MpegEncContext.dct_unquantize_h263_{inter,intra}
are *not* overloaded by existing optimisations.

---
This adds the plus ones back, saving two branch instructions in C and
one in assembler (at the cost of two unconditional adds).


See my reply in the previous version. Not sure if it will help with this.



---
  libavcodec/h263dsp.c | 26 ++
  libavcodec/h263dsp.h |  4 
  2 files changed, 30 insertions(+)

diff --git a/libavcodec/h263dsp.c b/libavcodec/h263dsp.c
index 6a13353499..f4523a68c1 100644
--- a/libavcodec/h263dsp.c
+++ b/libavcodec/h263dsp.c
@@ -19,10 +19,34 @@
  #include 
  
  #include "libavutil/attributes.h"

+#include "libavutil/avassert.h"
  #include "libavutil/common.h"
  #include "config.h"
  #include "h263dsp.h"
  
+static void h263_dct_unquantize_inter_c(int16_t *block, size_t len,

+int qmul, int qadd)
+{
+for (size_t i = 0; i < len; i++) {
+int level = block[i];
+
+if (level) {
+if (level < 0)
+level = level * qmul - qadd;
+else
+level = level * qmul + qadd;
+block[i] = level;
+}
+}
+}
+
+static void h263_dct_unquantize_intra_c(int16_t *block, size_t len,
+int qmul, int qadd)
+{
+av_assert1(len >= 1);
+h263_dct_unquantize_inter_c(block + 1, len - 1, qmul, qadd);
+}
+
  const uint8_t ff_h263_loop_filter_strength[32] = {
  0, 1, 1, 2, 2, 3, 3,  4,  4,  4,  5,  5,  6,  6,  7, 7,
  7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12
@@ -116,6 +140,8 @@ static void h263_v_loop_filter_c(uint8_t *src, int stride, 
int qscale)
  
  av_cold void ff_h263dsp_init(H263DSPContext *ctx)

  {
+ctx->h263_dct_unquantize_intra = h263_dct_unquantize_intra_c;
+ctx->h263_dct_unquantize_inter = h263_dct_unquantize_inter_c;
  ctx->h263_h_loop_filter = h263_h_loop_filter_c;
  ctx->h263_v_loop_filter = h263_v_loop_filter_c;
  
diff --git a/libavcodec/h263dsp.h b/libavcodec/h263dsp.h

index 2dccd23392..0ecbe83314 100644
--- a/libavcodec/h263dsp.h
+++ b/libavcodec/h263dsp.h
@@ -24,6 +24,10 @@
  extern const uint8_t ff_h263_loop_filter_strength[32];
  
  typedef struct H263DSPContext {

+void (*h263_dct_unquantize_intra)(int16_t *block /* align 16 */,
+  size_t len, int mul, int add);
+void (*h263_dct_unquantize_inter)(int16_t *block /* align 16 */,
+  size_t len, int mul, int add);
  void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
  void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale);
  } H263DSPContext;

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] doc/faq: Provide information about git send-email and gmail

2024-06-12 Thread Michael Niedermayer
The 2 links are the clearest i found.

Signed-off-by: Michael Niedermayer 
---
 doc/faq.texi | 5 +
 1 file changed, 5 insertions(+)

diff --git a/doc/faq.texi b/doc/faq.texi
index 477cc60533a..d07ed533dd7 100644
--- a/doc/faq.texi
+++ b/doc/faq.texi
@@ -683,4 +683,9 @@ Do you happen to have a @code{~} character in the samples 
path to indicate a
 home directory? The value is used in ways where the shell cannot expand it,
 causing FATE to not find files. Just replace @code{~} by the full path.
 
+@section How to setup git send-email?
+
+Please see @url{https://git-send-email.io/}.
+For gmail additionally see 
@url{https://shallowsky.com/blog/tech/email/gmail-app-passwds.html}.
+
 @bye
-- 
2.45.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCHv5 1/4] lavc/h263dsp: add DCT dequantisation functions

2024-06-12 Thread Rémi Denis-Courmont
Le keskiviikkona 12. kesäkuuta 2024, 20.40.37 EEST James Almer a écrit :
> On 6/12/2024 1:47 AM, Rémi Denis-Courmont wrote:
> > Note that optimised implementations of these functions will be taken
> > into actual use only if MpegEncContext.dct_unquantize_h263_{inter,intra}
> > are *not* overloaded by existing optimisations.
> > 
> > ---
> > This adds the plus ones back, saving two branch instructions in C and
> > one in assembler (at the cost of two unconditional adds).
> 
> See my reply in the previous version. Not sure if it will help with this.

We can of course avoid the branches - this version avoids the branches, as did 
the initial versions. In C (and in RVV), we can't avoid incrementing the 
pointer and a counter variable.

If you change the loop like yuo suggest:
 for (size_t i = 1; i <= nCoeffs; i++) { 
 int level = block[i];

 if (level) {
 if (level < 0)
 level = level * qmul - qadd;
 else
 level = level * qmul + qadd;
 block[i] = level;
 }
}

... at best, an optimising compiler will reinterpret it to:

 if (nCoeffs >= 1) {
 block++;
 end = block + nCoeffs;

  loop:
level = *block;
if (level) {
 tmp = level * qmul;
 if (level < 0)
 tmp -= qadd;
 else
 tmp += qadd;
 *(block++) = tmp;
 }
if (block <= end)
goto loop;
}

Or perhaps the compiler will keep an explicit counter, which is even worse. 
This does not save branches, nor increments. It just looks like it because of 
the syntactic sugar that is the for() loop. In reality, this only duplicates 
code (as we can no longer share between inter/intra).

-- 
レミ・デニ-クールモン
http://www.remlab.net/



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] doc/faq: Provide information about git send-email and gmail

2024-06-12 Thread epirat07



On 12 Jun 2024, at 19:46, Michael Niedermayer wrote:

> The 2 links are the clearest i found.
>
> Signed-off-by: Michael Niedermayer 
> ---
>  doc/faq.texi | 5 +
>  1 file changed, 5 insertions(+)
>
> diff --git a/doc/faq.texi b/doc/faq.texi
> index 477cc60533a..d07ed533dd7 100644
> --- a/doc/faq.texi
> +++ b/doc/faq.texi
> @@ -683,4 +683,9 @@ Do you happen to have a @code{~} character in the samples 
> path to indicate a
>  home directory? The value is used in ways where the shell cannot expand it,
>  causing FATE to not find files. Just replace @code{~} by the full path.
>
> +@section How to setup git send-email?
> +
> +Please see @url{https://git-send-email.io/}.
> +For gmail additionally see 
> @url{https://shallowsky.com/blog/tech/email/gmail-app-passwds.html}.
> +
>  @bye

Good idea, maybe we should link to https://sr.ht/~emersion/pyonji/ as well 
which IMHO
simplifies things a lot when someone is used to a feature-branch workflow.

> -- 
> 2.45.2
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/4] checkasm/h263dsp: test dct_unquantize_{intra, inter}

2024-06-12 Thread James Almer

On 6/12/2024 1:47 AM, Rémi Denis-Courmont wrote:

---
  tests/checkasm/h263dsp.c | 47 +++-
  1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/tests/checkasm/h263dsp.c b/tests/checkasm/h263dsp.c
index 2d0957a90b..8a2cdb34df 100644
--- a/tests/checkasm/h263dsp.c
+++ b/tests/checkasm/h263dsp.c
@@ -18,13 +18,55 @@
   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   */
  
+#include 

  #include 
  
  #include "checkasm.h"
  
-#include "libavcodec/h263dsp.h"

+#include "libavutil/avassert.h"
  #include "libavutil/mem.h"
  #include "libavutil/mem_internal.h"
+#include "libavcodec/h263dsp.h"
+#include "libavcodec/mpegvideodata.h"
+
+static uint_fast8_t mpeg_qscale_rnd(void)
+{
+int n = rnd(), q = (n >> 1) & 31;
+
+if (n & 1)
+return ff_mpeg2_non_linear_qscale[q];
+else
+return q << 1;
+}
+
+typedef void (*unquantizer)(int16_t *, size_t, int, int);
+
+static void check_dct_unquantize(unquantizer func, const char *name)
+{
+#define LEN 64
+LOCAL_ALIGNED_16(int16_t, block0, [LEN]);
+LOCAL_ALIGNED_16(int16_t, block1, [LEN]);


These are not padded, and unless I'm reading this wrong, an asm 
implementation loading say 16 bytes at a time will overread/write in 
dct_unquantize_intra (which offsets block by 1).



+size_t len = 1 + (rnd() & (LEN - 1));
+const int qscale = mpeg_qscale_rnd();
+const int qmul = qscale << 1;
+const int qadd = (rnd() & 1) ? (qscale - 1) | 1 : 0;
+
+declare_func(void, int16_t *, size_t, int, int);
+
+for (size_t i = 0; i < LEN; i++)
+block1[i] = block0[i] = (rnd() & 1) ? rnd() : 0;
+
+if (check_func(func, "h263dsp.dct_unquantize_%s", name)) {
+av_assert0(len <= LEN);
+call_ref(block0, len, qmul, qadd);
+call_new(block1, len, qmul, qadd);
+
+if (memcmp(block0, block1, len * sizeof (int16_t)))
+fail();
+
+bench_new(block1, LEN, qmul, qadd);
+}
+}
  
  typedef void (*filter)(uint8_t *src, int stride, int qscale);
  
@@ -56,6 +98,9 @@ void checkasm_check_h263dsp(void)

  H263DSPContext ctx;
  
  ff_h263dsp_init(&ctx);

+check_dct_unquantize(ctx.h263_dct_unquantize_intra, "intra");
+check_dct_unquantize(ctx.h263_dct_unquantize_inter, "inter");
+report("dct_unquantize");
  check_loop_filter('h', ctx.h263_h_loop_filter);
  check_loop_filter('v', ctx.h263_v_loop_filter);
  report("loop_filter");

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/4] checkasm/h263dsp: test dct_unquantize_{intra, inter}

2024-06-12 Thread Rémi Denis-Courmont
Le keskiviikkona 12. kesäkuuta 2024, 21.39.12 EEST James Almer a écrit :
> On 6/12/2024 1:47 AM, Rémi Denis-Courmont wrote:
> > ---
> > 
> >   tests/checkasm/h263dsp.c | 47 +++-
> >   1 file changed, 46 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tests/checkasm/h263dsp.c b/tests/checkasm/h263dsp.c
> > index 2d0957a90b..8a2cdb34df 100644
> > --- a/tests/checkasm/h263dsp.c
> > +++ b/tests/checkasm/h263dsp.c
> > @@ -18,13 +18,55 @@
> > 
> >* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> >*/
> > 
> > +#include 
> > 
> >   #include 
> >   
> >   #include "checkasm.h"
> > 
> > -#include "libavcodec/h263dsp.h"
> > +#include "libavutil/avassert.h"
> > 
> >   #include "libavutil/mem.h"
> >   #include "libavutil/mem_internal.h"
> > 
> > +#include "libavcodec/h263dsp.h"
> > +#include "libavcodec/mpegvideodata.h"
> > +
> > +static uint_fast8_t mpeg_qscale_rnd(void)
> > +{
> > +int n = rnd(), q = (n >> 1) & 31;
> > +
> > +if (n & 1)
> > +return ff_mpeg2_non_linear_qscale[q];
> > +else
> > +return q << 1;
> > +}
> > +
> > +typedef void (*unquantizer)(int16_t *, size_t, int, int);
> > +
> > +static void check_dct_unquantize(unquantizer func, const char *name)
> > +{
> > +#define LEN 64
> > +LOCAL_ALIGNED_16(int16_t, block0, [LEN]);
> > +LOCAL_ALIGNED_16(int16_t, block1, [LEN]);
> 
> These are not padded, and unless I'm reading this wrong, an asm
> implementation loading say 16 bytes at a time will overread/write in
> dct_unquantize_intra (which offsets block by 1).

AFAIU, there is no padding per se, but the block buffer size is always exactly 
64 elements, regardless of the number of coeffs, hence this code. The old NEON 
intrinsic code seems to assume the block is a multiple of 8 elements, and the 
tail can be overwritten safely (hence not checking in memcmp()).

I have a feeling that I am not grasping the implications of you comment here.

-- 
Rémi Denis-Courmont
http://www.remlab.net/



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] lavfi: add perlin noise generator

2024-06-12 Thread Stefano Sabatini
On date Monday 2024-06-03 11:41:59 +0200, Stefano Sabatini wrote:
> On date Tuesday 2024-05-28 18:58:28 +0200, Stefano Sabatini wrote:
> > On date Monday 2024-05-27 23:37:33 +0200, Stefano Sabatini wrote:
> > > Hi,
> > > 
> > > still missing documentation and might be optimized (and maybe extended
> > > to support gray16 - this should be simple), comments are welcome.
> > 
> > Updated with documentation.
> 
> > From 607459e7a184ab2d111b65f5017fb7f76e3bd58d Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini 
> > Date: Mon, 27 May 2024 11:19:08 +0200
> > Subject: [PATCH] lavfi: add perlin noise generator
> 
> Anyone interested with reviewing this?
> 
> Otherwise I'll probably push in a week or so, further improvements can
> be done on top of that.

Updated patch with minor doc fixes, will push it in a few days unless
I see comments.
>From 9932cfc19500acbd0685eb2cc8fd88e9af3f5dbd Mon Sep 17 00:00:00 2001
From: Stefano Sabatini 
Date: Mon, 27 May 2024 11:19:08 +0200
Subject: [PATCH] lavfi: add Perlin noise generator

---
 Changelog |   1 +
 doc/filters.texi  | 100 +
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/perlin.c  | 224 ++
 libavfilter/perlin.h  | 101 +
 libavfilter/vsrc_perlin.c | 169 
 7 files changed, 597 insertions(+)
 create mode 100644 libavfilter/perlin.c
 create mode 100644 libavfilter/perlin.h
 create mode 100644 libavfilter/vsrc_perlin.c

diff --git a/Changelog b/Changelog
index 03d6b29ad8..b8dcf452ac 100644
--- a/Changelog
+++ b/Changelog
@@ -12,6 +12,7 @@ version :
 - qsv_params option added for QSV encoders
 - VVC decoder compatible with DVB test content
 - xHE-AAC decoder
+- perlin source
 
 
 version 7.0:
diff --git a/doc/filters.texi b/doc/filters.texi
index 347103c04f..7af299b2a2 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -17290,6 +17290,9 @@ The command accepts the same syntax of the corresponding option.
 If the specified expression is not valid, it is kept at its current
 value.
 
+@anchor{lutrgb}
+@anchor{lutyuv}
+@anchor{lut}
 @section lut, lutrgb, lutyuv
 
 Compute a look-up table for binding each pixel component input value
@@ -29281,6 +29284,103 @@ ffplay -f lavfi life=s=300x200:mold=10:r=60:ratio=0.1:death_color=#C83232:life_c
 @end example
 @end itemize
 
+@section perlin
+Generate Perlin noise.
+
+Perlin noise is a kind of noise with local continuity in space. This
+can be used to generate patterns with continuity in space and time,
+e.g. to simulate smoke, fluids, or terrain.
+
+In case more than one octave is specified through the @option{octaves}
+option, Perlin noise is generated as a sum of components, each one
+with doubled frequency. In this case the @option{persistence} option
+specify the ratio of the amplitude with respect to the previous
+component. More octave components enable to specify more high
+frequency details in the generated noise (e.g. small size variations
+due to bolders in a generated terrain).
+
+@subsection Options
+@table @option
+
+@item size, s
+Specify the size (width and height) of the buffered video frames. For the
+syntax of this option, check the
+@ref{video size syntax,,"Video size" section in the ffmpeg-utils manual,ffmpeg-utils}.
+
+@item rate, r
+Specify the frame rate expected for the video stream, expressed as a
+number of frames per second.
+
+@item octaves
+Specify the total number of components making up the noise, each one
+with doubled frequency.
+
+@item persistence
+Set the ratio used to compute the amplitude of the next octave
+component with respect to the previous component amplitude.
+
+@item xscale
+@item yscale
+Define a scale factor used to multiple the x, y coordinates. This can
+be useful to define an effect with a pattern stretched along the x or
+y axis.
+
+@item tscale
+Define a scale factor used to multiple the time coordinate. This can
+be useful to change the time variation speed.
+
+@item random_mode
+Set random mode used to compute initial pattern.
+
+Supported values are:
+@table @option
+@item random
+Compute and use random seed.
+
+@item ken
+Use the predefined initial pattern defined by Ken Perlin in the
+original article, can be useful to compare the output with other
+sources.
+
+@item seed
+Use the value specified by @option{random_seed} option.
+@end table
+
+@item random_seed, seed
+Use this value to compute the initial pattern, it is only considered
+when @option{random_mode} is set to @var{random_seed}.
+@end table
+
+@subsection Examples
+@itemize
+@item
+Generate single component:
+@example
+perlin
+@end example
+
+@item
+Use Perlin noise with 7 components, each one with a halved contribute
+to total amplitude:
+@example
+perlin=octaves=7:persistence=0.5
+@end example
+
+@item
+Chain Perlin noise with the @ref{lutyuv} to generate a black&white
+effect:
+@example
+perlin:octaves=7:tscale=0.3,lutyuv=y='if(lt(val\,128)\,255\,0

Re: [FFmpeg-devel] [PATCH 3/4] checkasm/h263dsp: test dct_unquantize_{intra, inter}

2024-06-12 Thread James Almer

On 6/12/2024 4:15 PM, Rémi Denis-Courmont wrote:

Le keskiviikkona 12. kesäkuuta 2024, 21.39.12 EEST James Almer a écrit :

On 6/12/2024 1:47 AM, Rémi Denis-Courmont wrote:

---

   tests/checkasm/h263dsp.c | 47 +++-
   1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/tests/checkasm/h263dsp.c b/tests/checkasm/h263dsp.c
index 2d0957a90b..8a2cdb34df 100644
--- a/tests/checkasm/h263dsp.c
+++ b/tests/checkasm/h263dsp.c
@@ -18,13 +18,55 @@

* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

+#include 

   #include 
   
   #include "checkasm.h"


-#include "libavcodec/h263dsp.h"
+#include "libavutil/avassert.h"

   #include "libavutil/mem.h"
   #include "libavutil/mem_internal.h"

+#include "libavcodec/h263dsp.h"
+#include "libavcodec/mpegvideodata.h"
+
+static uint_fast8_t mpeg_qscale_rnd(void)
+{
+int n = rnd(), q = (n >> 1) & 31;
+
+if (n & 1)
+return ff_mpeg2_non_linear_qscale[q];
+else
+return q << 1;
+}
+
+typedef void (*unquantizer)(int16_t *, size_t, int, int);
+
+static void check_dct_unquantize(unquantizer func, const char *name)
+{
+#define LEN 64
+LOCAL_ALIGNED_16(int16_t, block0, [LEN]);
+LOCAL_ALIGNED_16(int16_t, block1, [LEN]);


These are not padded, and unless I'm reading this wrong, an asm
implementation loading say 16 bytes at a time will overread/write in
dct_unquantize_intra (which offsets block by 1).


AFAIU, there is no padding per se, but the block buffer size is always exactly
64 elements, regardless of the number of coeffs, hence this code. The old NEON
intrinsic code seems to assume the block is a multiple of 8 elements, and the
tail can be overwritten safely (hence not checking in memcmp()).

I have a feeling that I am not grasping the implications of you comment here.


An asm function loading 16 bytes at a time from block[1] onwards for 
intra may end up reading two bytes more than available at the end of the 
128 byte wide buffer.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3] area changed: scdet filter

2024-06-12 Thread radu.taraibuta
> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Michael Niedermayer
> Sent: marți, 11 iunie 2024 20:18
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v2] area changed: scdet filter
> 
> On Tue, Jun 11, 2024 at 10:07:32AM +0300, radu.taraib...@gmail.com wrote:
> >
> > > -Original Message-
> > > From: ffmpeg-devel  On Behalf Of
> > > Michael Niedermayer
> > > Sent: marți, 4 iunie 2024 01:42
> > > To: FFmpeg development discussions and patches
> > > 
> > > Subject: Re: [FFmpeg-devel] [PATCH] area changed: scdet filter
> > >
> > > On Sun, Jun 02, 2024 at 11:17:29PM +0300, radu.taraib...@gmail.com
> wrote:
> > > >
> > > >
> > > > > -Original Message-
> > > > > From: ffmpeg-devel  On Behalf
> > > > > Of Michael Niedermayer
> > > > > Sent: vineri, 31 mai 2024 00:32
> > > > > To: FFmpeg development discussions and patches
> > > > > 
> > > > > Subject: Re: [FFmpeg-devel] [PATCH] area changed: scdet filter
> > > > >
> > > > > On Mon, May 13, 2024 at 06:52:19PM +0300,
> > > > > radu.taraib...@gmail.com
> > > > > wrote:
> > > > > > Previous observations:
> > > > > >
> > > > > >  - Inconsistent code style with other filters. (Mostly using
> > > > > > AVFilterLink* link instead of AVFilterLink *link).
> > > > > > I hope it's fine now.
> > > > > >
> > > > > >  - Unrelated changes, please split trivial unrelated changes
> > > > > > into separate patches.
> > > > > > Removed trivial changes from this patch.
> > > > > >
> > > > > >  - Can't tables be generated at .init/.config_props time? No
> > > > > > point in storing them into binary.
> > > > > > Done.
> > > > > >
> > > > > >  - Adding extra delay is not backward compatible change, it
> > > > > > should be implemented properly by adding option for users to select
> mode:
> > > > > > next & prev frame or just next or prev frame.
> > > > > > Added legacy option to the mode parameter.
> > > > > >
> > > > > >  - Could split frame clone change into earlier separate patch.
> > > > > > Cannot be done. It's either frame clone or 1 frame delay.
> > > > > >
> > > > > >  - Where are results of improvements with accuracy so it can
> > > > > > be
> > > > confirmed?
> > > > > > Here are my test results with manual labeling of scene changes:
> > > > > > 2379Full length movie
> > > > > >
> > > > > > Method  Threshold   TP  FP  FN
>   Precision
> > > > > > Recall  F
> > > > > > Cubic   7   2357423 22  0.847841727
> > > > 0.990752417
> > > > > > 0.913742973
> > > > > > Cubic   10  2297200 82  0.919903885
> > > > 0.965531736
> > > > > > 0.94216571
> > > > > > Cubic   12  2217146 162 0.938214135
> > > > 0.931904161
> > > > > > 0.935048503
> > > > > > Cubic   15  2049101 330 0.953023256
> > > > 0.861286255
> > > > > > 0.904835505
> > > > > > Linear  2.8 2357106022  0.689786362
> > > > 0.990752417
> > > > > > 0.813319531
> > > > > > Linear  8   2099236 280 0.898929336
> > > > 0.882303489
> > > > > > 0.890538821
> > > > > > Linear  10  1886173 493 0.91597863
> > > > 0.792770071
> > > > > > 0.849932402
> > > > > > Legacy  5   22351260144 0.639484979
> > > > >   0.939470366
> > > > > > 0.760980592
> > > > > > Legacy  8   1998414 381 0.828358209
> > > > >   0.839848676
> > > > > > 0.83406387
> > > > > > Legacy  10  1743193 636 0.900309917
> > > > >   0.732660782
> > > > > > 0.80787949
> > > > > >
> > > > > > 15  HDR10Plus_PB_EAC3JOC
> > > > > > https://mega.nz/file/nehDka6Z#C5_OPbSZkONdOp1jRmc09C9-
> > > > > viDc3zMj8ZHruHcW
> > > > > > KyA
> > > > > >
> > > > > > Method  Threshold   TP  FP  FN
>   Precision
> > > > > > Recall  F
> > > > > > Cubic   10  15  0   0   1   1   
> > > > > > 1
> > > > > > Linear  5   13  1   2   0.928571429
> > > > 0.86667
> > > > > > 0.896551724
> > > > > > Legacy  5   12  2   3   0.857142857 
> > > > > > 0.8
> > > > > > 0.827586207
> > > > > >
> > > > > > 21  (HDR HEVC 10-bit BT.2020 24fps) Exodus Sample
> > > > > >
> > > > >
> > >
> https://mega.nz/file/Sfw1hDpK#ErxCOpQDVjcI1gq6ZbX3vIfdtXZompkFe0jq47
> > > > > E
> > > > > h
> > > > > > R2o
> > > > > >
> > > > > > Method  Threshold   TP  FP  FN
>   Precision
> > > > > > Recall  F
> > > > > > Cubic   10  21  0   0   1   1   
> > > > > > 1
> > > > > > Linear  4   20  0   1   1   
> > > > > > 0.952380952
> > > > > > 0.975609756
> > > > > > Legacy  4   19  0   2   1   
> > > > > > 0.904761905
> > > > >   0.95
> > > > > >
> > > > > > 94  Bieber Grammys
> > > > > > https://mega.nz/#!c9

Re: [FFmpeg-devel] [PATCH 3/4] checkasm/h263dsp: test dct_unquantize_{intra, inter}

2024-06-12 Thread Rémi Denis-Courmont
Le keskiviikkona 12. kesäkuuta 2024, 22.39.49 EEST James Almer a écrit :
> >> These are not padded, and unless I'm reading this wrong, an asm
> >> implementation loading say 16 bytes at a time will overread/write in
> >> dct_unquantize_intra (which offsets block by 1).
> > 
> > AFAIU, there is no padding per se, but the block buffer size is always
> > exactly 64 elements, regardless of the number of coeffs, hence this code.
> > The old NEON intrinsic code seems to assume the block is a multiple of 8
> > elements, and the tail can be overwritten safely (hence not checking in
> > memcmp()).
> > 
> > I have a feeling that I am not grasping the implications of you comment
> > here.
> An asm function loading 16 bytes at a time from block[1] onwards for
> intra may end up reading two bytes more than available at the end of the
> 128 byte wide buffer.

Wouldn't that be a bug in the assembler function? Do you mean that checkasm 
should add padding to check against overwrites?

The whole point of separating inter and intra was to preserve alignment for 
those instruction set extensions that want it (C and RVV couldn't care less).

-- 
レミ・デニ-クールモン
http://www.remlab.net/



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add sdlvsink for video display

2024-06-12 Thread Stefano Sabatini
On date Tuesday 2024-06-11 21:13:48 +0800, Shiqi Zhu wrote:
> On Fri, 7 Jun 2024 at 19:55, Rémi Denis-Courmont  wrote:
> > Le 7 juin 2024 12:53:51 GMT+03:00, Michael Niedermayer 
> >  a écrit :
> > >We can require anything from an API that we are able to change and extend
> > >Of course we can decide not to allow such requirment even if optional
> > >but we surely _could_ add such a feature if we choose to do so
> >
> > Sure. You can also require infinite memory or an oracle be provided. That's 
> > just not going to happen though. And having libraries depend on the main 
> > thread is a well-documented malpractice.
> >
> > I don't think we should add maintenance burden with code that can't be used 
> > safely.
> 
> Thank you all for your attention to this patch; I greatly appreciate it.
> 
> I'd like to provide a brief recap of the issue we've been discussing,
> with the following points:
> 
> 1. Addition of sink type in the filter:
> This enhancement is primarily based on the existing avfilter mechanism
> and serves as a strengthening module. Using SDL as the sink doesn't
> seem to be a good fit, as I'll attempt to rectify in the following
> patch.
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240611130310.1131755-1-hiccup...@gmail.com/
> 
> 2. Utilizing SDL as an implementation for the sink:
> Before submitting the patch, I hadn't considered many aspects. During
> the intense discussions, I retested the patch on different operating
> systems, with the following results, hoping it may assist those
> interested in this issue:
> 
> Command: ./ffmpeg -lavfi
> "testsrc2=size=300x200:rate=25:duration=500,format=yuv420p,sdlvsink"
> -f null /dev/null

In addition to this, I wonder if adding a vsink for each different
output device is the correct way.

We have a movie source which can be used to read from
libavformat/libavdevice, probablhy we should have a movie sink to be
used to write to libavformat/libavdevice, meaning that a single sink
would enable access to all the supported libavformat/libavdevice
outputs.

I started having a look in that direction a looot of time ago. This
was never finalized because I was not sure about ways to pass options
to encoders and muxers, and about dealing with a variable number of
outputs, I'm attaching this very old proof-of-concept patch for
reference.

This approach would be possibly much more complex, but should provide
a single bridge in place of having a different sink for every output
device or muxer.

>From dc88e3f19ad0e481e0adc5e192ad3e2b4b249f55 Mon Sep 17 00:00:00 2001
From: Stefano Sabatini 
Date: Wed, 11 Apr 2012 15:10:14 +0200
Subject: [PATCH] lavfi: add moviesink and amoviesink sinks

---
 configure|   2 +
 libavfilter/Makefile |   4 +
 libavfilter/allfilters.c |   2 +
 libavfilter/sink_moviesink.c | 365 +++
 4 files changed, 373 insertions(+)
 create mode 100644 libavfilter/sink_moviesink.c

diff --git a/configure b/configure
index 81c7cc18a2..5e08fbbf6c 100755
--- a/configure
+++ b/configure
@@ -1674,6 +1674,7 @@ udp_protocol_deps="network"
 # filters
 aconvert_filter_deps="swresample"
 amovie_filter_deps="avcodec avformat"
+amoviesink_filter_deps="avcodec avformat"
 aresample_filter_deps="swresample"
 ass_filter_deps="libass"
 asyncts_filter_deps="avresample"
@@ -1690,6 +1691,7 @@ frei0r_src_filter_deps="frei0r dlopen"
 frei0r_src_filter_extralibs='$ldl'
 hqdn3d_filter_deps="gpl"
 movie_filter_deps="avcodec avformat"
+moviesink_filter_deps="avcodec avformat"
 mp_filter_deps="gpl avcodec swscale postproc"
 mptestsrc_filter_deps="gpl"
 negate_filter_deps="lut_filter"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 29345fc15e..a2bd404304 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -7,8 +7,10 @@ FFLIBS-$(CONFIG_RESAMPLE_FILTER) += avresample
 
 FFLIBS-$(CONFIG_ACONVERT_FILTER) += swresample
 FFLIBS-$(CONFIG_AMOVIE_FILTER)   += avformat avcodec
+FFLIBS-$(CONFIG_AMOVIESINK_FILTER)   += avformat avcodec
 FFLIBS-$(CONFIG_ARESAMPLE_FILTER)+= swresample
 FFLIBS-$(CONFIG_MOVIE_FILTER)+= avformat avcodec
+FFLIBS-$(CONFIG_MOVIESINK_FILTER)+= avformat avcodec
 FFLIBS-$(CONFIG_PAN_FILTER)  += swresample
 FFLIBS-$(CONFIG_REMOVELOGO_FILTER)   += avformat avcodec
 FFLIBS-$(CONFIG_MP_FILTER)   += avcodec postproc
@@ -65,6 +67,7 @@ OBJS-$(CONFIG_AMOVIE_FILTER) += src_movie.o
 OBJS-$(CONFIG_ANULLSRC_FILTER)   += asrc_anullsrc.o
 
 OBJS-$(CONFIG_ABUFFERSINK_FILTER)+= sink_buffer.o
+OBJS-$(CONFIG_AMOVIESINK_FILTER) += sink_moviesink.o
 OBJS-$(CONFIG_ANULLSINK_FILTER)  += asink_anullsink.o
 
 OBJS-$(CONFIG_ASS_FILTER)+= vf_ass.o
@@ -133,6 +136,7 @@ OBJS-$(CONFIG_RGBTESTSRC_FILTER) += vsrc_testsrc.o
 OBJS-$(CONFIG_TESTSRC_FILTER)+= vsrc_testsrc.o
 
 OBJS-$(CO

Re: [FFmpeg-devel] [PATCH] doc/faq: Provide information about git send-email and gmail

2024-06-12 Thread Stefano Sabatini
On date Wednesday 2024-06-12 19:46:59 +0200, Michael Niedermayer wrote:
> The 2 links are the clearest i found.
> 
> Signed-off-by: Michael Niedermayer 
> ---
>  doc/faq.texi | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/doc/faq.texi b/doc/faq.texi
> index 477cc60533a..d07ed533dd7 100644
> --- a/doc/faq.texi
> +++ b/doc/faq.texi
> @@ -683,4 +683,9 @@ Do you happen to have a @code{~} character in the samples 
> path to indicate a
>  home directory? The value is used in ways where the shell cannot expand it,
>  causing FATE to not find files. Just replace @code{~} by the full path.
>  
> +@section How to setup git send-email?
> +
> +Please see @url{https://git-send-email.io/}.
> +For gmail additionally see 
> @url{https://shallowsky.com/blog/tech/email/gmail-app-passwds.html}.
> +

Should be good but I think it's more useful to put this close to
developers.texi - Submitting patches
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add sdlvsink for video display

2024-06-12 Thread Paul B Mahol
On Wed, Jun 12, 2024 at 9:52 PM Stefano Sabatini  wrote:

> On date Tuesday 2024-06-11 21:13:48 +0800, Shiqi Zhu wrote:
> > On Fri, 7 Jun 2024 at 19:55, Rémi Denis-Courmont 
> wrote:
> > > Le 7 juin 2024 12:53:51 GMT+03:00, Michael Niedermayer <
> mich...@niedermayer.cc> a écrit :
> > > >We can require anything from an API that we are able to change and
> extend
> > > >Of course we can decide not to allow such requirment even if optional
> > > >but we surely _could_ add such a feature if we choose to do so
> > >
> > > Sure. You can also require infinite memory or an oracle be provided.
> That's just not going to happen though. And having libraries depend on the
> main thread is a well-documented malpractice.
> > >
> > > I don't think we should add maintenance burden with code that can't be
> used safely.
> >
> > Thank you all for your attention to this patch; I greatly appreciate it.
> >
> > I'd like to provide a brief recap of the issue we've been discussing,
> > with the following points:
> >
> > 1. Addition of sink type in the filter:
> > This enhancement is primarily based on the existing avfilter mechanism
> > and serves as a strengthening module. Using SDL as the sink doesn't
> > seem to be a good fit, as I'll attempt to rectify in the following
> > patch.
> >
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240611130310.1131755-1-hiccup...@gmail.com/
> >
> > 2. Utilizing SDL as an implementation for the sink:
> > Before submitting the patch, I hadn't considered many aspects. During
> > the intense discussions, I retested the patch on different operating
> > systems, with the following results, hoping it may assist those
> > interested in this issue:
> >
> > Command: ./ffmpeg -lavfi
> > "testsrc2=size=300x200:rate=25:duration=500,format=yuv420p,sdlvsink"
> > -f null /dev/null
>
> In addition to this, I wonder if adding a vsink for each different
> output device is the correct way.
>
> We have a movie source which can be used to read from
> libavformat/libavdevice, probablhy we should have a movie sink to be
> used to write to libavformat/libavdevice, meaning that a single sink
> would enable access to all the supported libavformat/libavdevice
> outputs.
>
> I started having a look in that direction a looot of time ago. This
> was never finalized because I was not sure about ways to pass options
> to encoders and muxers, and about dealing with a variable number of
> outputs, I'm attaching this very old proof-of-concept patch for
> reference.
>
> This approach would be possibly much more complex, but should provide
> a single bridge in place of having a different sink for every output
> device or muxer.
>


Pointless as real plan is to get rid of immature libavdevice API.


>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v6 1/4] doc: Explain what "context" means

2024-06-12 Thread Stefano Sabatini
On date Tuesday 2024-06-04 15:47:21 +0100, Andrew Sayers wrote:
> Derived from explanations kindly provided by Stefano Sabatini and others:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2024-April/325903.html
> ---
>  doc/context.md | 430 +
>  1 file changed, 430 insertions(+)
>  create mode 100644 doc/context.md
> diff --git a/doc/context.md b/doc/context.md
> new file mode 100644
> index 00..bd8cb58696
> --- /dev/null
> +++ b/doc/context.md
> @@ -0,0 +1,430 @@
> +@page Context Introduction to contexts
> +
> +@tableofcontents
> +
> +FFmpeg uses the term “context” to refer to an idiom
> +you have probably used before:
> +
> +```c
> +// C structs often share context between functions:
> +
> +FILE *my_file; // my_file stores information about a filehandle
> +
> +printf(my_file, "hello "); // my_file provides context to this function,
> +printf(my_file, "world!"); // and also to this function
> +```
> +
> +```python
> +# Python classes provide context for the methods they contain:
> +
> +class MyClass:
> +def print(self,message):
> +if self.prev_message != message:
> +self.prev_message = message
> +print(message)
> +```
> +
> +
> +```c
> +// Many JavaScript callbacks accept an optional context argument:
> +
> +const my_object = {};
> +
> +my_array.forEach(function_1, my_object);
> +my_array.forEach(function_2, my_object);
> +```
> +
> +Be careful comparing FFmpeg contexts to things you're already familiar with -
> +FFmpeg may sometimes happen to reuse words you recognise, but mean something
> +completely different.  For example, the AVClass struct has nothing to do with
> +[object-oriented 
> classes](https://en.wikipedia.org/wiki/Class_(computer_programming)).
> +
> +If you've used contexts in other C projects, you may want to read
> +@ref Context_comparison before the rest of the document.

My impression is that this is growing out of scope for a
reference. The doxy is a reference, therefore it should be clean and
terse, and we should avoid adding too much information, enough
information should be right enough. In fact, a reference is different
from a tutorial, and much different from a C tutorial. Also this is
not a treatise comparing different languages and frameworks, as this
would confuse beginners and would annoy experienced developers.

I propose to cut this patch to provide the minimal information you can
expect in a reference, but not more than that. Addition can be added
later, but I think we should try to avoid any unnecessary content, in
the spirit of keeping this a reference. More extensive discussions
might be done in a separate place (the wiki, a blog post etc.), but in
the spirit of a keeping this a reference they should not be put here.

> +
> +@section Context_general “Context” as a general concept
> +
> +@par
> +A context is any data structure used by several functions
> +(or several instances of the same function) that all operate on the same 
> entity.
> +
> +In the broadest sense, “context” is just a way to think about code.

> +You can even use it to think about code written by people who have never
> +heard the term, or who would disagree with you about what it means.
> +Consider the following snippet:
> +
> +```c
> +struct DualWriter {
> +int fd1, fd2;
> +};
> +
> +ssize_t write_to_two_files(
> +struct DualWriter *my_writer,
> +uint8_t *buf,
> +int buf_size
> +) {
> +
> +ssize_t bytes_written_1 = write(my_writer->fd1, buf, buf_size);
> +ssize_t bytes_written_2 = write(my_writer->fd2, buf, buf_size);
> +
> +if ( bytes_written_1 != bytes_written_2 ) {
> +// ... handle this edge case ...
> +}
> +
> +return bytes_written_1;
> +
> +}
> +
> +int main() {
> +
> +struct DualWriter my_writer;
> +my_writer.fd1 = open("file1", 0644, "wb");
> +my_writer.fd2 = open("file2", 0644, "wb");
> +
> +write_to_two_files(&my_writer, "hello ", sizeof("hello "));
> +write_to_two_files(&my_writer, "world!", sizeof("world!"));
> +
> +close( my_writer.fd1 );
> +close( my_writer.fd2 );
> +
> +}
> +```
> +
> +The term “context” doesn't appear anywhere in the snippet.  But `DualWriter`
> +is passed to several instances of `write_to_two_files()` that operate on
> +the same entity, so it fits the definition of a context.
> +
> +When reading code that isn't explicitly described in terms of contexts,
> +remember that your interpretation may differ from other people's.
> +For example, FFmpeg's avio_alloc_context() accepts a set of callback 
> functions
> +and an `opaque` argument - even though this function guarantees to *return*
> +a context, it does not require `opaque` to *provide* context for the callback
> +functions.  So you could choose to pass a struct like `DualWriter` as the
> +`opaque` argument, or you could pass callbacks that use `stdin` and `stdout`
> +and just pass a `NULL` argument for `opaque`.

I'd skip all this part, as we assume the reader

[FFmpeg-devel] [PATCH 1/3] avfilter/vf_avgblur_opencl: Use AV_VIDEO_MAX_PLANES

2024-06-12 Thread Michael Niedermayer
Fixes: CID1437470 Out-of-bounds read (out of bounds read would only occur with 
a pixel format of more than 4 planes)

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavfilter/vf_avgblur_opencl.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_avgblur_opencl.c b/libavfilter/vf_avgblur_opencl.c
index c00d2f6363c..ad68b8be385 100644
--- a/libavfilter/vf_avgblur_opencl.c
+++ b/libavfilter/vf_avgblur_opencl.c
@@ -47,8 +47,8 @@ typedef struct AverageBlurOpenCLContext {
 FilterParam luma_param;
 FilterParam chroma_param;
 FilterParam alpha_param;
-int radius[4];
-int power[4];
+int radius[AV_VIDEO_MAX_PLANES];
+int power[AV_VIDEO_MAX_PLANES];
 
 } AverageBlurOpenCLContext;
 
@@ -101,7 +101,7 @@ static int avgblur_opencl_make_filter_params(AVFilterLink 
*inlink)
 s->radiusV = s->radiusH;
 }
 
-for (i = 0; i < 4; i++) {
+for (i = 0; i < AV_VIDEO_MAX_PLANES; i++) {
 s->power[i] = 1;
 }
 return 0;
@@ -133,7 +133,7 @@ static int boxblur_opencl_make_filter_params(AVFilterLink 
*inlink)
 s->power[U] = s->power[V] = s->chroma_param.power;
 s->power[A] = s->alpha_param.power;
 
-for (i = 0; i < 4; i++) {
+for (i = 0; i < AV_VIDEO_MAX_PLANES; i++) {
 if (s->power[i] == 0) {
 s->power[i] = 1;
 s->radius[i] = 0;
@@ -191,7 +191,7 @@ static int avgblur_opencl_filter_frame(AVFilterLink 
*inlink, AVFrame *input)
 goto fail;
 }
 
-for (p = 0; p < FF_ARRAY_ELEMS(output->data); p++) {
+for (p = 0; p < FFMIN(FF_ARRAY_ELEMS(output->data), AV_VIDEO_MAX_PLANES); 
p++) {
 src = (cl_mem) input->data[p];
 dst = (cl_mem) output->data[p];
 inter = (cl_mem)intermediate->data[p];
-- 
2.45.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/3] avfilter/vf_bm3d: Dont round MSE2SSE to an integer

2024-06-12 Thread Michael Niedermayer
Fixes: CID1439581 Result is not floating-point

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavfilter/vf_bm3d.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_bm3d.c b/libavfilter/vf_bm3d.c
index f53a206b518..eb7f6d34d99 100644
--- a/libavfilter/vf_bm3d.c
+++ b/libavfilter/vf_bm3d.c
@@ -274,7 +274,7 @@ static void do_block_matching_multi(BM3DContext *s, const 
uint8_t *src, int src_
 int r_y, int r_x, int plane, int jobnr)
 {
 SliceContext *sc = &s->slices[jobnr];
-double MSE2SSE = s->group_size * s->block_size * s->block_size * src_range 
* src_range / (s->max * s->max);
+double MSE2SSE = s->group_size * s->block_size * s->block_size * src_range 
* src_range / (double)(s->max * s->max);
 double distMul = 1. / MSE2SSE;
 double th_sse = th_mse * MSE2SSE;
 int index = sc->nb_match_blocks;
-- 
2.45.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 3/3] avfilter/vf_convolution_opencl: Assert that the filter name is one of the filters

2024-06-12 Thread Michael Niedermayer
Helps with: CID1439572 Uninitialized pointer read

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavfilter/vf_convolution_opencl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavfilter/vf_convolution_opencl.c 
b/libavfilter/vf_convolution_opencl.c
index 0eff9f40d3b..40938436f2b 100644
--- a/libavfilter/vf_convolution_opencl.c
+++ b/libavfilter/vf_convolution_opencl.c
@@ -20,6 +20,7 @@
 
 #include "config_components.h"
 
+#include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/mem.h"
@@ -80,6 +81,8 @@ static int convolution_opencl_init(AVFilterContext *avctx)
 kernel_name = "prewitt_global";
 } else if (!strcmp(avctx->filter->name, "roberts_opencl")){
 kernel_name = "roberts_global";
+} else {
+av_assert0(0);
 }
 ctx->kernel = clCreateKernel(ctx->ocf.program, kernel_name, &cle);
 CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to create "
-- 
2.45.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] doc/faq: Provide information about git send-email and gmail

2024-06-12 Thread Michael Niedermayer
On Wed, Jun 12, 2024 at 08:23:08PM +0200, epira...@gmail.com wrote:
> 
> 
> On 12 Jun 2024, at 19:46, Michael Niedermayer wrote:
> 
> > The 2 links are the clearest i found.
> >
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  doc/faq.texi | 5 +
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/doc/faq.texi b/doc/faq.texi
> > index 477cc60533a..d07ed533dd7 100644
> > --- a/doc/faq.texi
> > +++ b/doc/faq.texi
> > @@ -683,4 +683,9 @@ Do you happen to have a @code{~} character in the 
> > samples path to indicate a
> >  home directory? The value is used in ways where the shell cannot expand it,
> >  causing FATE to not find files. Just replace @code{~} by the full path.
> >
> > +@section How to setup git send-email?
> > +
> > +Please see @url{https://git-send-email.io/}.
> > +For gmail additionally see 
> > @url{https://shallowsky.com/blog/tech/email/gmail-app-passwds.html}.
> > +
> >  @bye
> 
> Good idea, maybe we should link to https://sr.ht/~emersion/pyonji/ as well 
> which IMHO
> simplifies things a lot when someone is used to a feature-branch workflow.

i dont know that tool, and iam having too many things todo ATM to look
(i need to backport many patches and make new releases for example which is
 more important)

so ill add the 2 links as it seems theres consensus on that step
and we can look at improving this later

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


  1   2   >