Re: [FFmpeg-devel] [PATCH V2 2/3] libavcodec/vaapi_encode: Change the way to call async to increase performance

2022-02-06 Thread Chen, Wenbin
> On Wed, 2022-01-05 at 10:48 +0800, Wenbin Chen wrote:
> > Fix: #7706. After commit 5fdcf85bbffe7451c2, vaapi encoder's performance
> > decrease. The reason is that vaRenderPicture() and vaSyncBuffer() are
> > called at the same time (vaRenderPicture() always followed by a
> > vaSyncBuffer()). When we encode stream with B frames, we need buffer to
> > reorder frames, so we can send serveral frames to HW at once to increase
> > performance. Now I changed them to be called in a asynchronous way,
> which
> > will make better use of hardware. 1080p transcoding increases about 17%
> > fps on my environment.
> >
> > This change fits vaSyncBuffer(), so if driver does not support
> > vaSyncBuffer, it will keep previous operation.
> >
> > Signed-off-by: Wenbin Chen 
> > ---
> >  libavcodec/vaapi_encode.c | 64 -
> --
> >  libavcodec/vaapi_encode.h |  5 +++
> >  2 files changed, 58 insertions(+), 11 deletions(-)
> >
> > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> > index b87b58a42b..9a3b3ba4ad 100644
> > --- a/libavcodec/vaapi_encode.c
> > +++ b/libavcodec/vaapi_encode.c
> > @@ -984,8 +984,10 @@ static int
> vaapi_encode_pick_next(AVCodecContext *avctx,
> >  if (!pic && ctx->end_of_stream) {
> >  --b_counter;
> >  pic = ctx->pic_end;
> > -if (pic->encode_issued)
> > +if (pic->encode_complete)
> >  return AVERROR_EOF;
> > +else if (pic->encode_issued)
> > +return AVERROR(EAGAIN);
> >  }
> >
> >  if (!pic) {
> > @@ -1210,18 +1212,45 @@ int
> ff_vaapi_encode_receive_packet(AVCodecContext
> > *avctx, AVPacket *pkt)
> >  return AVERROR(EAGAIN);
> >  }
> >
> > -pic = NULL;
> > -err = vaapi_encode_pick_next(avctx, );
> > -if (err < 0)
> > -return err;
> > -av_assert0(pic);
> > +#if VA_CHECK_VERSION(1, 9, 0)
> > +if (ctx->has_sync_buffer_func) {
> > +while (av_fifo_size(ctx->encode_fifo) <=
> > +   MAX_PICTURE_REFERENCES * sizeof(VAAPIEncodePicture *)) {
> > +pic = NULL;
> > +err = vaapi_encode_pick_next(avctx, );
> > +if (err < 0)
> > +break;
> > +
> > +av_assert0(pic);
> > +pic->encode_order = ctx->encode_order +
> > +(av_fifo_size(ctx->encode_fifo) / sizeof(VAAPIEncodePicture
> > *));
> > +err = vaapi_encode_issue(avctx, pic);
> > +if (err < 0) {
> > +av_log(avctx, AV_LOG_ERROR, "Encode failed: %d.\n", err);
> > +return err;
> > +}
> > +av_fifo_generic_write(ctx->encode_fifo, , sizeof(pic), 
> > NULL);
> > +}
> > +if (!av_fifo_size(ctx->encode_fifo))
> > +return err;
> > +av_fifo_generic_read(ctx->encode_fifo, , sizeof(pic), NULL);
> > +ctx->encode_order = pic->encode_order + 1;
> > +} else
> > +#endif
> > +{
> > +pic = NULL;
> > +err = vaapi_encode_pick_next(avctx, );
> > +if (err < 0)
> > +return err;
> > +av_assert0(pic);
> >
> > -pic->encode_order = ctx->encode_order++;
> > +pic->encode_order = ctx->encode_order++;
> >
> > -err = vaapi_encode_issue(avctx, pic);
> > -if (err < 0) {
> > -av_log(avctx, AV_LOG_ERROR, "Encode failed: %d.\n", err);
> > -return err;
> > +err = vaapi_encode_issue(avctx, pic);
> > +if (err < 0) {
> > +av_log(avctx, AV_LOG_ERROR, "Encode failed: %d.\n", err);
> > +return err;
> > +}
> >  }
> >
> >  err = vaapi_encode_output(avctx, pic, pkt);
> > @@ -2555,6 +2584,18 @@ av_cold int
> ff_vaapi_encode_init(AVCodecContext *avctx)
> >  }
> >  }
> >
> > +#if VA_CHECK_VERSION(1, 9, 0)
> > +//check vaSyncBuffer function
> > +vas = vaSyncBuffer(ctx->hwctx->display, 0, 0);
> > +if (vas != VA_STATUS_ERROR_UNIMPLEMENTED) {
> > +ctx->has_sync_buffer_func = 1;
> > +ctx->encode_fifo = av_fifo_alloc((MAX_PICTURE_REFERENCES + 1) *
> > +sizeof(VAAPIEncodePicture *));
> > +if (!ctx->encode_fifo)
> > +return AVERROR(ENOMEM);
> > +}
> > +#endif
> > +
> >  return 0;
> >
> >  fail:
> > @@ -2592,6 +2633,7 @@ av_cold int
> ff_vaapi_encode_close(AVCodecContext *avctx)
> >
> >  av_freep(>codec_sequence_params);
> >  av_freep(>codec_picture_params);
> > +av_fifo_freep(>encode_fifo);
> >
> >  av_buffer_unref(>recon_frames_ref);
> >  av_buffer_unref(>input_frames_ref);
> > diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
> > index b41604a883..560a1c42a9 100644
> > --- a/libavcodec/vaapi_encode.h
> > +++ b/libavcodec/vaapi_encode.h
> > @@ -29,6 +29,7 @@
> >
> >  #include "libavutil/hwcontext.h"
> >  #include "libavutil/hwcontext_vaapi.h"
> > +#include "libavutil/fifo.h"
> >
> >  #include "avcodec.h"
> >  #include "hwconfig.h"
> > 

Re: [FFmpeg-devel] [PATCH V2 2/3] libavcodec/vaapi_encode: Change the way to call async to increase performance

2022-02-06 Thread Xiang, Haihao
On Wed, 2022-01-05 at 10:48 +0800, Wenbin Chen wrote:
> Fix: #7706. After commit 5fdcf85bbffe7451c2, vaapi encoder's performance
> decrease. The reason is that vaRenderPicture() and vaSyncBuffer() are
> called at the same time (vaRenderPicture() always followed by a
> vaSyncBuffer()). When we encode stream with B frames, we need buffer to
> reorder frames, so we can send serveral frames to HW at once to increase
> performance. Now I changed them to be called in a asynchronous way, which
> will make better use of hardware. 1080p transcoding increases about 17%
> fps on my environment.
> 
> This change fits vaSyncBuffer(), so if driver does not support
> vaSyncBuffer, it will keep previous operation.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  libavcodec/vaapi_encode.c | 64 ---
>  libavcodec/vaapi_encode.h |  5 +++
>  2 files changed, 58 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index b87b58a42b..9a3b3ba4ad 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -984,8 +984,10 @@ static int vaapi_encode_pick_next(AVCodecContext *avctx,
>  if (!pic && ctx->end_of_stream) {
>  --b_counter;
>  pic = ctx->pic_end;
> -if (pic->encode_issued)
> +if (pic->encode_complete)
>  return AVERROR_EOF;
> +else if (pic->encode_issued)
> +return AVERROR(EAGAIN);
>  }
>  
>  if (!pic) {
> @@ -1210,18 +1212,45 @@ int ff_vaapi_encode_receive_packet(AVCodecContext
> *avctx, AVPacket *pkt)
>  return AVERROR(EAGAIN);
>  }
>  
> -pic = NULL;
> -err = vaapi_encode_pick_next(avctx, );
> -if (err < 0)
> -return err;
> -av_assert0(pic);
> +#if VA_CHECK_VERSION(1, 9, 0)
> +if (ctx->has_sync_buffer_func) {
> +while (av_fifo_size(ctx->encode_fifo) <=
> +   MAX_PICTURE_REFERENCES * sizeof(VAAPIEncodePicture *)) {
> +pic = NULL;
> +err = vaapi_encode_pick_next(avctx, );
> +if (err < 0)
> +break;
> +
> +av_assert0(pic);
> +pic->encode_order = ctx->encode_order +
> +(av_fifo_size(ctx->encode_fifo) / sizeof(VAAPIEncodePicture
> *));
> +err = vaapi_encode_issue(avctx, pic);
> +if (err < 0) {
> +av_log(avctx, AV_LOG_ERROR, "Encode failed: %d.\n", err);
> +return err;
> +}
> +av_fifo_generic_write(ctx->encode_fifo, , sizeof(pic), NULL);
> +}
> +if (!av_fifo_size(ctx->encode_fifo))
> +return err;
> +av_fifo_generic_read(ctx->encode_fifo, , sizeof(pic), NULL);
> +ctx->encode_order = pic->encode_order + 1;
> +} else
> +#endif
> +{
> +pic = NULL;
> +err = vaapi_encode_pick_next(avctx, );
> +if (err < 0)
> +return err;
> +av_assert0(pic);
>  
> -pic->encode_order = ctx->encode_order++;
> +pic->encode_order = ctx->encode_order++;
>  
> -err = vaapi_encode_issue(avctx, pic);
> -if (err < 0) {
> -av_log(avctx, AV_LOG_ERROR, "Encode failed: %d.\n", err);
> -return err;
> +err = vaapi_encode_issue(avctx, pic);
> +if (err < 0) {
> +av_log(avctx, AV_LOG_ERROR, "Encode failed: %d.\n", err);
> +return err;
> +}
>  }
>  
>  err = vaapi_encode_output(avctx, pic, pkt);
> @@ -2555,6 +2584,18 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
>  }
>  }
>  
> +#if VA_CHECK_VERSION(1, 9, 0)
> +//check vaSyncBuffer function
> +vas = vaSyncBuffer(ctx->hwctx->display, 0, 0);
> +if (vas != VA_STATUS_ERROR_UNIMPLEMENTED) {
> +ctx->has_sync_buffer_func = 1;
> +ctx->encode_fifo = av_fifo_alloc((MAX_PICTURE_REFERENCES + 1) *
> +sizeof(VAAPIEncodePicture *));
> +if (!ctx->encode_fifo)
> +return AVERROR(ENOMEM);
> +}
> +#endif
> +
>  return 0;
>  
>  fail:
> @@ -2592,6 +2633,7 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
>  
>  av_freep(>codec_sequence_params);
>  av_freep(>codec_picture_params);
> +av_fifo_freep(>encode_fifo);
>  
>  av_buffer_unref(>recon_frames_ref);
>  av_buffer_unref(>input_frames_ref);
> diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
> index b41604a883..560a1c42a9 100644
> --- a/libavcodec/vaapi_encode.h
> +++ b/libavcodec/vaapi_encode.h
> @@ -29,6 +29,7 @@
>  
>  #include "libavutil/hwcontext.h"
>  #include "libavutil/hwcontext_vaapi.h"
> +#include "libavutil/fifo.h"
>  
>  #include "avcodec.h"
>  #include "hwconfig.h"
> @@ -345,6 +346,10 @@ typedef struct VAAPIEncodeContext {
>  int roi_warned;
>  
>  AVFrame *frame;
> +//Store buffered pic
> +AVFifoBuffer *encode_fifo;
> +//Whether the driver support vaSyncBuffer

Could you update 

Re: [FFmpeg-devel] [PATCH] avformat/mpegts: initialize max_packet_size when sub-demuxer

2022-02-06 Thread Gyan Doshi




On 2022-02-07 03:59 am, Marton Balint wrote:



On Sat, 5 Feb 2022, Gyan Doshi wrote:


bca30570d2 added a user option to set max_packet_size replacing
a hardcoded value. This had a side-effect of leaving the field
set to 0 when packet demuxing is carried out from another demuxer
using avpriv functions, which could lead to demux failure.

Hardcoded max_packet_size inside avpriv_mpegts_parse_open to
2048000 to avoid this. Value chosen to be 10x that of default value
to accommodate large payloads.


I don't understand why the default is different from the normal mpegts 
case. Large payloads can happen there as well, and previously it was 
assumed that splitting is OK, because it will be parsed anyway.
The option was added because MPEG-TS allows any codec to be carried as a 
private stream and when demuxing that, the parser isn't inserted, even 
when forcing a decoder, hence the need to not have split packets. In 
this case, the user can't tune the value, so I went with an expansive one.


Regards,
Gyan
___
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] avcodec/vp6: return value check for av_mallocz

2022-02-06 Thread Jiasheng Jiang
As the potential failure of the av_mallocz(), the 's->alpha_context'
could be NULL and be dereferenced later.
Therefore, it should be better to check it and deal with it if fails
in order to prevent memory leak, same as the av_frame_alloc() in
ff_vp56_init().

Fixes: 39a3894ad5 ("lavc/vp6: Implement "slice" threading for VP6A decode")
Signed-off-by: Jiasheng Jiang 
---
 libavcodec/vp6.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/vp6.c b/libavcodec/vp6.c
index d024370793..d75e717082 100644
--- a/libavcodec/vp6.c
+++ b/libavcodec/vp6.c
@@ -653,6 +653,10 @@ static av_cold int vp6_decode_init(AVCodecContext *avctx)
 
 if (s->has_alpha) {
 s->alpha_context = av_mallocz(sizeof(VP56Context));
+if (!s->alpha_context) {
+ff_vp56_free(avctx);
+return AVERROR(ENOMEM);
+}
 ff_vp56_init_context(avctx, s->alpha_context,
  s->flip == -1, s->has_alpha);
 ff_vp6dsp_init(>alpha_context->vp56dsp);
-- 
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 1/4] lavc/mpeg*: drop the XvMC hwaccel code

2022-02-06 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> James Almer
> Sent: Monday, February 7, 2022 2:53 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC
> hwaccel code
> 
> On 2/6/2022 10:46 PM, Andreas Rheinhardt wrote:
> > Anton Khirnov:
> >> XvMC was last relevant over 10 years ago, if ever. There is no
> reason to
> >> use it today.
> >> ---
> >>   MAINTAINERS|   1 -
> >>   configure  |   9 -
> >>   libavcodec/Makefile|   2 -
> >>   libavcodec/avcodec.h   |  12 --
> >>   libavcodec/error_resilience.c  |   9 -
> >>   libavcodec/hwaccels.h  |   2 -
> >>   libavcodec/hwconfig.h  |   2 -
> >>   libavcodec/mpeg12dec.c |  43 
> >>   libavcodec/mpegvideo.c |   6 -
> >>   libavcodec/mpegvideo.h |   2 -
> >>   libavcodec/mpegvideo_xvmc.c| 376 
> -
> >>   libavcodec/x86/blockdsp_init.c |   4 -
> >>   libavcodec/xvmc_internal.h |  31 ---
> >>   13 files changed, 499 deletions(-)
> >>   delete mode 100644 libavcodec/mpegvideo_xvmc.c
> >>   delete mode 100644 libavcodec/xvmc_internal.h
> >>
> >> diff --git a/MAINTAINERS b/MAINTAINERS
> >> index c065e94498..f33ccbd1d9 100644
> >> --- a/MAINTAINERS
> >> +++ b/MAINTAINERS
> >> @@ -266,7 +266,6 @@ Codecs:
> >> xan.c Mike Melanson
> >> xbm*  Paul B Mahol
> >> xface Stefano Sabatini
> >> -  xvmc.cIvan Kalvachev
> >> xwd*  Paul B Mahol
> >>
> >>   Hardware acceleration:
> >> diff --git a/configure b/configure
> >> index 5b19a35f59..6dbe108284 100755
> >> --- a/configure
> >> +++ b/configure
> >> @@ -1900,7 +1900,6 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
> >>   videotoolbox
> >>   vulkan
> >>   v4l2_m2m
> >> -xvmc
> >>   "
> >>
> >>   # catchall list of things that require external libs to link
> >> @@ -3006,7 +3005,6 @@ vaapi_x11_deps="xlib_x11"
> >>   videotoolbox_hwaccel_deps="videotoolbox pthreads"
> >>   videotoolbox_hwaccel_extralibs="-framework QuartzCore"
> >>   vulkan_deps_any="libdl LoadLibrary"
> >> -xvmc_deps="X11_extensions_XvMClib_h"
> >>
> >>   av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
> >>   av1_d3d11va_hwaccel_select="av1_decoder"
> >> @@ -3054,16 +3052,12 @@ mjpeg_nvdec_hwaccel_deps="nvdec"
> >>   mjpeg_nvdec_hwaccel_select="mjpeg_decoder"
> >>   mjpeg_vaapi_hwaccel_deps="vaapi"
> >>   mjpeg_vaapi_hwaccel_select="mjpeg_decoder"
> >> -mpeg_xvmc_hwaccel_deps="xvmc"
> >> -mpeg_xvmc_hwaccel_select="mpeg2video_decoder"
> >>   mpeg1_nvdec_hwaccel_deps="nvdec"
> >>   mpeg1_nvdec_hwaccel_select="mpeg1video_decoder"
> >>   mpeg1_vdpau_hwaccel_deps="vdpau"
> >>   mpeg1_vdpau_hwaccel_select="mpeg1video_decoder"
> >>   mpeg1_videotoolbox_hwaccel_deps="videotoolbox"
> >>   mpeg1_videotoolbox_hwaccel_select="mpeg1video_decoder"
> >> -mpeg1_xvmc_hwaccel_deps="xvmc"
> >> -mpeg1_xvmc_hwaccel_select="mpeg1video_decoder"
> >>   mpeg2_d3d11va_hwaccel_deps="d3d11va"
> >>   mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
> >>   mpeg2_d3d11va2_hwaccel_deps="d3d11va"
> >> @@ -3078,8 +3072,6 @@ mpeg2_vdpau_hwaccel_deps="vdpau"
> >>   mpeg2_vdpau_hwaccel_select="mpeg2video_decoder"
> >>   mpeg2_videotoolbox_hwaccel_deps="videotoolbox"
> >>   mpeg2_videotoolbox_hwaccel_select="mpeg2video_decoder"
> >> -mpeg2_xvmc_hwaccel_deps="xvmc"
> >> -mpeg2_xvmc_hwaccel_select="mpeg2video_decoder"
> >>   mpeg4_nvdec_hwaccel_deps="nvdec"
> >>   mpeg4_nvdec_hwaccel_select="mpeg4_decoder"
> >>   mpeg4_vaapi_hwaccel_deps="vaapi"
> >> @@ -6320,7 +6312,6 @@ check_headers unistd.h
> >>   check_headers valgrind/valgrind.h
> >>   check_func_headers VideoToolbox/VTCompressionSession.h
> VTCompressionSessionPrepareToEncodeFrames -framework VideoToolbox
> >>   check_headers windows.h
> >> -check_headers X11/extensions/XvMClib.h
> >>   check_headers asm/types.h
> >>
> >>   # it seems there are versions of clang in some distros that try
> to use the
> >> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> >> index cfc70a3eaf..6076b4ad80 100644
> >> --- a/libavcodec/Makefile
> >> +++ b/libavcodec/Makefile
> >> @@ -963,7 +963,6 @@ OBJS-$(CONFIG_MJPEG_VAAPI_HWACCEL)+=
> vaapi_mjpeg.o
> >>   OBJS-$(CONFIG_MPEG1_NVDEC_HWACCEL)+= nvdec_mpeg12.o
> >>   OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= vdpau_mpeg12.o
> >>   OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
> >> -OBJS-$(CONFIG_MPEG1_XVMC_HWACCEL) += mpegvideo_xvmc.o
> >>   OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
> >>   OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
> >>   OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
> >> @@ -971,7 +970,6 @@ OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  +=
> qsvdec.o
> >>   OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
> >> 

Re: [FFmpeg-devel] [PATCH 1/7] avcodec/cbs_mpeg2: Remove redundant counter

2022-02-06 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Use -1 as the position in ff_cbs_insert_unit_data()
> which implicitly reuses frag->nb_units as the counter.
> 
> Also switch to a do-while-loop, as it is more natural
> than a for-loop now that the counter is gone.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/cbs_mpeg2.c | 12 +---
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
> index 26400f279f..4395bbf047 100644
> --- a/libavcodec/cbs_mpeg2.c
> +++ b/libavcodec/cbs_mpeg2.c
> @@ -148,7 +148,8 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext 
> *ctx,
>  CodedBitstreamUnitType unit_type;
>  uint32_t start_code = -1;
>  size_t unit_size;
> -int err, i, final = 0;
> +int err;
> +int final = 0;
>  
>  start = avpriv_find_start_code(frag->data, frag->data + frag->data_size,
> _code);
> @@ -157,7 +158,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext 
> *ctx,
>  return AVERROR_INVALIDDATA;
>  }
>  
> -for (i = 0;; i++) {
> +do {
>  unit_type = start_code & 0xff;
>  
>  if (start == frag->data + frag->data_size) {
> @@ -185,16 +186,13 @@ static int 
> cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
> final = 1;
>  }
>  
> -err = ff_cbs_insert_unit_data(frag, i, unit_type, (uint8_t*)start,
> +err = ff_cbs_insert_unit_data(frag, -1, unit_type, (uint8_t*)start,
>unit_size, frag->data_ref);
>  if (err < 0)
>  return err;
>  
> -if (final)
> -break;
> -
>  start = end;
> -}
> +} while (!final);
>  
>  return 0;
>  }

Will apply this patchset tomorrow unless there are objections.

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

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


Re: [FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC hwaccel code

2022-02-06 Thread James Almer

On 2/6/2022 10:46 PM, Andreas Rheinhardt wrote:

Anton Khirnov:

XvMC was last relevant over 10 years ago, if ever. There is no reason to
use it today.
---
  MAINTAINERS|   1 -
  configure  |   9 -
  libavcodec/Makefile|   2 -
  libavcodec/avcodec.h   |  12 --
  libavcodec/error_resilience.c  |   9 -
  libavcodec/hwaccels.h  |   2 -
  libavcodec/hwconfig.h  |   2 -
  libavcodec/mpeg12dec.c |  43 
  libavcodec/mpegvideo.c |   6 -
  libavcodec/mpegvideo.h |   2 -
  libavcodec/mpegvideo_xvmc.c| 376 -
  libavcodec/x86/blockdsp_init.c |   4 -
  libavcodec/xvmc_internal.h |  31 ---
  13 files changed, 499 deletions(-)
  delete mode 100644 libavcodec/mpegvideo_xvmc.c
  delete mode 100644 libavcodec/xvmc_internal.h

diff --git a/MAINTAINERS b/MAINTAINERS
index c065e94498..f33ccbd1d9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -266,7 +266,6 @@ Codecs:
xan.c Mike Melanson
xbm*  Paul B Mahol
xface Stefano Sabatini
-  xvmc.cIvan Kalvachev
xwd*  Paul B Mahol
  
  Hardware acceleration:

diff --git a/configure b/configure
index 5b19a35f59..6dbe108284 100755
--- a/configure
+++ b/configure
@@ -1900,7 +1900,6 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
  videotoolbox
  vulkan
  v4l2_m2m
-xvmc
  "
  
  # catchall list of things that require external libs to link

@@ -3006,7 +3005,6 @@ vaapi_x11_deps="xlib_x11"
  videotoolbox_hwaccel_deps="videotoolbox pthreads"
  videotoolbox_hwaccel_extralibs="-framework QuartzCore"
  vulkan_deps_any="libdl LoadLibrary"
-xvmc_deps="X11_extensions_XvMClib_h"
  
  av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"

  av1_d3d11va_hwaccel_select="av1_decoder"
@@ -3054,16 +3052,12 @@ mjpeg_nvdec_hwaccel_deps="nvdec"
  mjpeg_nvdec_hwaccel_select="mjpeg_decoder"
  mjpeg_vaapi_hwaccel_deps="vaapi"
  mjpeg_vaapi_hwaccel_select="mjpeg_decoder"
-mpeg_xvmc_hwaccel_deps="xvmc"
-mpeg_xvmc_hwaccel_select="mpeg2video_decoder"
  mpeg1_nvdec_hwaccel_deps="nvdec"
  mpeg1_nvdec_hwaccel_select="mpeg1video_decoder"
  mpeg1_vdpau_hwaccel_deps="vdpau"
  mpeg1_vdpau_hwaccel_select="mpeg1video_decoder"
  mpeg1_videotoolbox_hwaccel_deps="videotoolbox"
  mpeg1_videotoolbox_hwaccel_select="mpeg1video_decoder"
-mpeg1_xvmc_hwaccel_deps="xvmc"
-mpeg1_xvmc_hwaccel_select="mpeg1video_decoder"
  mpeg2_d3d11va_hwaccel_deps="d3d11va"
  mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
  mpeg2_d3d11va2_hwaccel_deps="d3d11va"
@@ -3078,8 +3072,6 @@ mpeg2_vdpau_hwaccel_deps="vdpau"
  mpeg2_vdpau_hwaccel_select="mpeg2video_decoder"
  mpeg2_videotoolbox_hwaccel_deps="videotoolbox"
  mpeg2_videotoolbox_hwaccel_select="mpeg2video_decoder"
-mpeg2_xvmc_hwaccel_deps="xvmc"
-mpeg2_xvmc_hwaccel_select="mpeg2video_decoder"
  mpeg4_nvdec_hwaccel_deps="nvdec"
  mpeg4_nvdec_hwaccel_select="mpeg4_decoder"
  mpeg4_vaapi_hwaccel_deps="vaapi"
@@ -6320,7 +6312,6 @@ check_headers unistd.h
  check_headers valgrind/valgrind.h
  check_func_headers VideoToolbox/VTCompressionSession.h 
VTCompressionSessionPrepareToEncodeFrames -framework VideoToolbox
  check_headers windows.h
-check_headers X11/extensions/XvMClib.h
  check_headers asm/types.h
  
  # it seems there are versions of clang in some distros that try to use the

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cfc70a3eaf..6076b4ad80 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -963,7 +963,6 @@ OBJS-$(CONFIG_MJPEG_VAAPI_HWACCEL)+= vaapi_mjpeg.o
  OBJS-$(CONFIG_MPEG1_NVDEC_HWACCEL)+= nvdec_mpeg12.o
  OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= vdpau_mpeg12.o
  OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
-OBJS-$(CONFIG_MPEG1_XVMC_HWACCEL) += mpegvideo_xvmc.o
  OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
  OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
  OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
@@ -971,7 +970,6 @@ OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
  OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
  OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL)+= vdpau_mpeg12.o
  OBJS-$(CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
-OBJS-$(CONFIG_MPEG2_XVMC_HWACCEL) += mpegvideo_xvmc.o
  OBJS-$(CONFIG_MPEG4_NVDEC_HWACCEL)+= nvdec_mpeg4.o
  OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)+= vaapi_mpeg4.o
  OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ec1a0566a4..acb7ae0e14 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2119,7 +2119,6 @@ typedef struct AVHWAccel {
   *
   * Meaningful slice information (codec specific) is guaranteed to
   * be parsed at this point. This function is mandatory.
- * The only exception is 

Re: [FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC hwaccel code

2022-02-06 Thread Andreas Rheinhardt
Anton Khirnov:
> XvMC was last relevant over 10 years ago, if ever. There is no reason to
> use it today.
> ---
>  MAINTAINERS|   1 -
>  configure  |   9 -
>  libavcodec/Makefile|   2 -
>  libavcodec/avcodec.h   |  12 --
>  libavcodec/error_resilience.c  |   9 -
>  libavcodec/hwaccels.h  |   2 -
>  libavcodec/hwconfig.h  |   2 -
>  libavcodec/mpeg12dec.c |  43 
>  libavcodec/mpegvideo.c |   6 -
>  libavcodec/mpegvideo.h |   2 -
>  libavcodec/mpegvideo_xvmc.c| 376 -
>  libavcodec/x86/blockdsp_init.c |   4 -
>  libavcodec/xvmc_internal.h |  31 ---
>  13 files changed, 499 deletions(-)
>  delete mode 100644 libavcodec/mpegvideo_xvmc.c
>  delete mode 100644 libavcodec/xvmc_internal.h
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index c065e94498..f33ccbd1d9 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -266,7 +266,6 @@ Codecs:
>xan.c Mike Melanson
>xbm*  Paul B Mahol
>xface Stefano Sabatini
> -  xvmc.cIvan Kalvachev
>xwd*  Paul B Mahol
>  
>  Hardware acceleration:
> diff --git a/configure b/configure
> index 5b19a35f59..6dbe108284 100755
> --- a/configure
> +++ b/configure
> @@ -1900,7 +1900,6 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
>  videotoolbox
>  vulkan
>  v4l2_m2m
> -xvmc
>  "
>  
>  # catchall list of things that require external libs to link
> @@ -3006,7 +3005,6 @@ vaapi_x11_deps="xlib_x11"
>  videotoolbox_hwaccel_deps="videotoolbox pthreads"
>  videotoolbox_hwaccel_extralibs="-framework QuartzCore"
>  vulkan_deps_any="libdl LoadLibrary"
> -xvmc_deps="X11_extensions_XvMClib_h"
>  
>  av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1"
>  av1_d3d11va_hwaccel_select="av1_decoder"
> @@ -3054,16 +3052,12 @@ mjpeg_nvdec_hwaccel_deps="nvdec"
>  mjpeg_nvdec_hwaccel_select="mjpeg_decoder"
>  mjpeg_vaapi_hwaccel_deps="vaapi"
>  mjpeg_vaapi_hwaccel_select="mjpeg_decoder"
> -mpeg_xvmc_hwaccel_deps="xvmc"
> -mpeg_xvmc_hwaccel_select="mpeg2video_decoder"
>  mpeg1_nvdec_hwaccel_deps="nvdec"
>  mpeg1_nvdec_hwaccel_select="mpeg1video_decoder"
>  mpeg1_vdpau_hwaccel_deps="vdpau"
>  mpeg1_vdpau_hwaccel_select="mpeg1video_decoder"
>  mpeg1_videotoolbox_hwaccel_deps="videotoolbox"
>  mpeg1_videotoolbox_hwaccel_select="mpeg1video_decoder"
> -mpeg1_xvmc_hwaccel_deps="xvmc"
> -mpeg1_xvmc_hwaccel_select="mpeg1video_decoder"
>  mpeg2_d3d11va_hwaccel_deps="d3d11va"
>  mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
>  mpeg2_d3d11va2_hwaccel_deps="d3d11va"
> @@ -3078,8 +3072,6 @@ mpeg2_vdpau_hwaccel_deps="vdpau"
>  mpeg2_vdpau_hwaccel_select="mpeg2video_decoder"
>  mpeg2_videotoolbox_hwaccel_deps="videotoolbox"
>  mpeg2_videotoolbox_hwaccel_select="mpeg2video_decoder"
> -mpeg2_xvmc_hwaccel_deps="xvmc"
> -mpeg2_xvmc_hwaccel_select="mpeg2video_decoder"
>  mpeg4_nvdec_hwaccel_deps="nvdec"
>  mpeg4_nvdec_hwaccel_select="mpeg4_decoder"
>  mpeg4_vaapi_hwaccel_deps="vaapi"
> @@ -6320,7 +6312,6 @@ check_headers unistd.h
>  check_headers valgrind/valgrind.h
>  check_func_headers VideoToolbox/VTCompressionSession.h 
> VTCompressionSessionPrepareToEncodeFrames -framework VideoToolbox
>  check_headers windows.h
> -check_headers X11/extensions/XvMClib.h
>  check_headers asm/types.h
>  
>  # it seems there are versions of clang in some distros that try to use the
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index cfc70a3eaf..6076b4ad80 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -963,7 +963,6 @@ OBJS-$(CONFIG_MJPEG_VAAPI_HWACCEL)+= vaapi_mjpeg.o
>  OBJS-$(CONFIG_MPEG1_NVDEC_HWACCEL)+= nvdec_mpeg12.o
>  OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= vdpau_mpeg12.o
>  OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
> -OBJS-$(CONFIG_MPEG1_XVMC_HWACCEL) += mpegvideo_xvmc.o
>  OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL)  += dxva2_mpeg2.o
>  OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o
>  OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o
> @@ -971,7 +970,6 @@ OBJS-$(CONFIG_MPEG2_QSV_HWACCEL)  += qsvdec.o
>  OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o
>  OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL)+= vdpau_mpeg12.o
>  OBJS-$(CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
> -OBJS-$(CONFIG_MPEG2_XVMC_HWACCEL) += mpegvideo_xvmc.o
>  OBJS-$(CONFIG_MPEG4_NVDEC_HWACCEL)+= nvdec_mpeg4.o
>  OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)+= vaapi_mpeg4.o
>  OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index ec1a0566a4..acb7ae0e14 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -2119,7 +2119,6 @@ typedef struct AVHWAccel {
>   *
>   * Meaningful slice information (codec specific) is 

[FFmpeg-devel] [PATCH 5/6] avcodec/thread: Don't use ThreadFrame when unnecessary

2022-02-06 Thread Andreas Rheinhardt
The majority of frame-threaded decoders (mainly the intra-only)
need exactly one part of ThreadFrame: The AVFrame. They don't
need the owners nor the progress, yet they had to use it because
ff_thread_(get|release)_buffer() requires it.

This commit changes this and makes these functions work with ordinary
AVFrames; the decoders that need the extra fields for progress
use ff_thread_(get|release)_ext_buffer() which work exactly
as ff_thread_(get|release)_buffer() used to do.

This also avoids some unnecessary allocations of progress AVBuffers,
namely for H.264 and HEVC film grain frames: These frames are not
used for synchronization and therefore don't need a ThreadFrame.

Also move the ThreadFrame structure as well as ff_thread_ref_frame()
to threadframe.h, the header for frame-threaded decoders with
inter-frame dependencies.

Signed-off-by: Andreas Rheinhardt 
---
In case anyone is wondering why ff_thread_get_ext_buffer() still
checks for FF_CODEC_CAP_ALLOCATE_PROGRESS:
It is due to weirdness in the WebP decoder. The WebP decoder 
(which has the AV_CODEC_CAP_FRAME_THREADS set, but not
FF_CODEC_CAP_ALLOCATE_PROGRESS) directly uses the VP8 decoder's
init, decode_frame and close function. According to the spec [1],
this is only to be used with VP8 key frames, yet I don't see a check
that enforces this. If the data would contain non-keyframes,
it would probably (haven't tested it) lead to very broken results
when using frame threading, because there is no synchronisation
whatsoever between the underlying VP8 decode contexts.
Always flushing the VP8 decoder after every frame should be enough
to make it consistent (and error out in case there are non-keyframes).

[1]: https://developers.google.com/speed/webp/docs/riff_container

 libavcodec/aic.c  |  3 +-
 libavcodec/alac.c |  3 +-
 libavcodec/av1dec.c   | 35 
 libavcodec/av1dec.h   |  4 +-
 libavcodec/bitpacked_dec.c|  3 +-
 libavcodec/cfhd.c | 13 +++---
 libavcodec/cllc.c |  7 ++--
 libavcodec/cri.c  |  3 +-
 libavcodec/dnxhddec.c |  3 +-
 libavcodec/dvdec.c| 22 +-
 libavcodec/dxtory.c   | 15 +++
 libavcodec/dxv.c  | 11 +++--
 libavcodec/dxva2_av1.c|  8 ++--
 libavcodec/error_resilience.h |  2 +-
 libavcodec/exr.c  |  3 +-
 libavcodec/ffv1.h |  2 +-
 libavcodec/ffv1dec.c  |  1 +
 libavcodec/flacdec.c  |  3 +-
 libavcodec/fraps.c|  3 +-
 libavcodec/h264_picture.c | 15 +++
 libavcodec/h264_slice.c   |  4 +-
 libavcodec/h264dec.c  |  1 +
 libavcodec/h264dec.h  |  1 -
 libavcodec/hapdec.c   | 14 +++
 libavcodec/hevc_refs.c|  2 +-
 libavcodec/hevcdec.c  |  6 +--
 libavcodec/hevcdec.h  |  3 +-
 libavcodec/hqx.c  |  4 +-
 libavcodec/huffyuvdec.c   |  3 +-
 libavcodec/jpeg2000dec.c  |  3 +-
 libavcodec/lagarith.c | 11 +++--
 libavcodec/lcldec.c   |  3 +-
 libavcodec/libopenjpegdec.c   |  3 +-
 libavcodec/magicyuv.c |  3 +-
 libavcodec/mdec.c | 11 +++--
 libavcodec/mpegpicture.h  |  2 +-
 libavcodec/notchlc.c  |  7 ++--
 libavcodec/nvdec_av1.c|  6 +--
 libavcodec/photocd.c  |  3 +-
 libavcodec/pixlet.c   |  9 ++--
 libavcodec/proresdec2.c   |  3 +-
 libavcodec/pthread_frame.c| 79 +++
 libavcodec/rv34.c |  1 +
 libavcodec/sheervideo.c   |  3 +-
 libavcodec/takdec.c   |  3 +-
 libavcodec/thread.h   | 14 +--
 libavcodec/threadframe.h  | 12 +-
 libavcodec/tiff.c |  9 ++--
 libavcodec/tta.c  |  3 +-
 libavcodec/utils.c| 11 +++--
 libavcodec/utvideodec.c   | 76 -
 libavcodec/v210dec.c  |  3 +-
 libavcodec/v410dec.c  |  3 +-
 libavcodec/vaapi_av1.c| 44 +--
 libavcodec/vble.c |  3 +-
 libavcodec/vp8.h  |  2 +-
 libavcodec/vp9shared.h|  2 +-
 libavcodec/webp.c |  3 +-
 libavcodec/ylc.c  |  3 +-
 59 files changed, 252 insertions(+), 283 deletions(-)

diff --git a/libavcodec/aic.c b/libavcodec/aic.c
index c95bdae1ed..552e7e9c10 100644
--- a/libavcodec/aic.c
+++ b/libavcodec/aic.c
@@ -391,7 +391,6 @@ static int aic_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 uint32_t off;
 int x, y, ret;
 int slice_size;
-ThreadFrame frame = { .f = data };
 
 ctx->frame= data;
 ctx->frame->pict_type = AV_PICTURE_TYPE_I;
@@ -410,7 +409,7 @@ static int aic_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 return ret;
 }
 
-if ((ret = ff_thread_get_buffer(avctx, , 0)) < 0)
+if ((ret = ff_thread_get_buffer(avctx, ctx->frame, 0)) < 0)
 return ret;
 
 bytestream2_init(, buf + AIC_HDR_SIZE,

[FFmpeg-devel] [PATCH 6/6] avcodec/pthread_frame: Properly unref frame in case of decoding failure

2022-02-06 Thread Andreas Rheinhardt
Use ff_thread_release_buffer() instead of av_frame_unref(),
as the former handles the case of non-thread-safe callbacks
properly. (This is possible now that ff_thread_release_buffer()
no longer requires a ThreadFrame.)

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/pthread_frame.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 75b70a17ec..27ed0b2cc4 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -223,7 +223,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 if (avctx->codec->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS)
 av_log(avctx, AV_LOG_ERROR, "A frame threaded decoder did not "
"free the frame on failure. This is a bug, please 
report it.\n");
-av_frame_unref(p->frame);
+ff_thread_release_buffer(avctx, p->frame);
 }
 
 if (atomic_load(>state) == STATE_SETTING_UP)
-- 
2.32.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 4/6] avcodec/threadframe: Add ff_thread_(get|release)_ext_buffer()

2022-02-06 Thread Andreas Rheinhardt
These will be used by the codecs that need allocated progress
and is in preparation for no longer using ThreadFrame by the codecs
that don't.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ffv1.c  |  5 +++--
 libavcodec/ffv1dec.c   |  9 +
 libavcodec/h264_picture.c  |  4 ++--
 libavcodec/h264_slice.c|  6 +++---
 libavcodec/hevc_refs.c |  6 +++---
 libavcodec/mimic.c | 12 ++--
 libavcodec/mpegpicture.c   |  7 ---
 libavcodec/pngdec.c| 17 +
 libavcodec/pthread_frame.c | 10 ++
 libavcodec/threadframe.h   | 24 
 libavcodec/utils.c | 15 ++-
 libavcodec/vp3.c   | 23 ---
 libavcodec/vp8.c   |  8 
 libavcodec/vp9.c   | 18 +-
 libavcodec/wavpack.c   | 18 ++
 15 files changed, 118 insertions(+), 64 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index d8a0c39254..6bde984815 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -37,6 +37,7 @@
 #include "rangecoder.h"
 #include "mathops.h"
 #include "ffv1.h"
+#include "threadframe.h"
 
 av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
 {
@@ -204,11 +205,11 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 int i, j;
 
 if (s->picture.f)
-ff_thread_release_buffer(avctx, >picture);
+ff_thread_release_ext_buffer(avctx, >picture);
 av_frame_free(>picture.f);
 
 if (s->last_picture.f)
-ff_thread_release_buffer(avctx, >last_picture);
+ff_thread_release_ext_buffer(avctx, >last_picture);
 av_frame_free(>last_picture.f);
 
 for (j = 0; j < s->max_slice_count; j++) {
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 3f90a8fb55..45ecf3152e 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -842,7 +842,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame, AVPac
 AVFrame *p;
 
 if (f->last_picture.f)
-ff_thread_release_buffer(avctx, >last_picture);
+ff_thread_release_ext_buffer(avctx, >last_picture);
 FFSWAP(ThreadFrame, f->picture, f->last_picture);
 
 f->cur = p = f->picture.f;
@@ -874,7 +874,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame, AVPac
 p->key_frame = 0;
 }
 
-if ((ret = ff_thread_get_buffer(avctx, >picture, 
AV_GET_BUFFER_FLAG_REF)) < 0)
+ret = ff_thread_get_ext_buffer(avctx, >picture, AV_GET_BUFFER_FLAG_REF);
+if (ret < 0)
 return ret;
 
 if (avctx->debug & FF_DEBUG_PICT_INFO)
@@ -966,7 +967,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame, AVPac
 ff_thread_report_progress(>picture, INT_MAX, 0);
 
 if (f->last_picture.f)
-ff_thread_release_buffer(avctx, >last_picture);
+ff_thread_release_ext_buffer(avctx, >last_picture);
 if ((ret = av_frame_ref(data, f->picture.f)) < 0)
 return ret;
 
@@ -1037,7 +1038,7 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
 av_assert1(fdst->max_slice_count == fsrc->max_slice_count);
 
 
-ff_thread_release_buffer(dst, >picture);
+ff_thread_release_ext_buffer(dst, >picture);
 if (fsrc->picture.f->data[0]) {
 if ((ret = ff_thread_ref_frame(>picture, >picture)) < 0)
 return ret;
diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index 50a21c260f..c7f5b64b99 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -40,7 +40,7 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
 if (!pic->f || !pic->f->buf[0])
 return;
 
-ff_thread_release_buffer(h->avctx, >tf);
+ff_thread_release_ext_buffer(h->avctx, >tf);
 ff_thread_release_buffer(h->avctx, >tf_grain);
 av_buffer_unref(>hwaccel_priv_buf);
 
@@ -155,7 +155,7 @@ int ff_h264_replace_picture(H264Context *h, H264Picture 
*dst, const H264Picture
 av_assert0(src->tf.f == src->f);
 
 dst->tf.f = dst->f;
-ff_thread_release_buffer(h->avctx, >tf);
+ff_thread_release_ext_buffer(h->avctx, >tf);
 ret = ff_thread_ref_frame(>tf, >tf);
 if (ret < 0)
 goto fail;
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 600a109889..32d2e090d5 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -191,8 +191,8 @@ static int alloc_picture(H264Context *h, H264Picture *pic)
 av_assert0(!pic->f->data[0]);
 
 pic->tf.f = pic->f;
-ret = ff_thread_get_buffer(h->avctx, >tf, pic->reference ?
-   AV_GET_BUFFER_FLAG_REF : 0);
+ret = ff_thread_get_ext_buffer(h->avctx, >tf,
+   pic->reference ? AV_GET_BUFFER_FLAG_REF : 
0);
 if (ret < 0)
 goto fail;
 
@@ -1699,7 +1699,7 @@ static int h264_field_start(H264Context *h, const 
H264SliceContext *sl,
 ff_thread_await_progress(>tf, INT_MAX, 0);
 

[FFmpeg-devel] [PATCH 3/6] avcodec/thread: Move ff_thread_(await|report)_progress to new header

2022-02-06 Thread Andreas Rheinhardt
This is in preparation for further commits that will stop
using ThreadFrame for frame-threaded codecs that don't use
ff_thread_(await|report)_progress(); the API for those codecs
having inter-frame dependencies will live in threadframe.h.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/error_resilience.c |  2 +-
 libavcodec/ffv1dec.c  |  1 +
 libavcodec/h264_direct.c  |  2 +-
 libavcodec/h264_mb.c  |  2 +-
 libavcodec/h264_picture.c |  2 +-
 libavcodec/h264_slice.c   |  2 +-
 libavcodec/h264dec.c  |  2 +-
 libavcodec/hevc_filter.c  |  1 +
 libavcodec/hevc_mvs.c |  1 +
 libavcodec/hevc_refs.c|  1 +
 libavcodec/hevcdec.c  |  1 +
 libavcodec/mimic.c|  1 +
 libavcodec/mpeg4videodec.c|  2 +-
 libavcodec/mpegvideo.c|  2 +-
 libavcodec/mpegvideo_dec.c|  2 +-
 libavcodec/pngdec.c   |  1 +
 libavcodec/pthread_frame.c|  1 +
 libavcodec/rv34.c |  2 +-
 libavcodec/thread.h   | 26 -
 libavcodec/threadframe.h  | 53 +++
 libavcodec/utils.c|  1 +
 libavcodec/vp3.c  |  1 +
 libavcodec/vp8.c  |  1 +
 libavcodec/vp9.c  |  1 +
 libavcodec/vp9block.c |  1 +
 libavcodec/vp9mvs.c   |  1 +
 libavcodec/vp9recon.c |  1 +
 libavcodec/wavpack.c  |  1 +
 28 files changed, 79 insertions(+), 36 deletions(-)
 create mode 100644 libavcodec/threadframe.h

diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index 91cd8a..551ef914ce 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -34,7 +34,7 @@
 #include "mpegutils.h"
 #include "mpegvideo.h"
 #include "rectangle.h"
-#include "thread.h"
+#include "threadframe.h"
 
 /**
  * @param stride the number of MVs to get to the next row
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 810b2e18f0..3f90a8fb55 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -37,6 +37,7 @@
 #include "golomb.h"
 #include "mathops.h"
 #include "ffv1.h"
+#include "threadframe.h"
 
 static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state,
int is_signed)
diff --git a/libavcodec/h264_direct.c b/libavcodec/h264_direct.c
index 93c2e1e438..014491e29b 100644
--- a/libavcodec/h264_direct.c
+++ b/libavcodec/h264_direct.c
@@ -30,7 +30,7 @@
 #include "h264_ps.h"
 #include "mpegutils.h"
 #include "rectangle.h"
-#include "thread.h"
+#include "threadframe.h"
 
 #include 
 
diff --git a/libavcodec/h264_mb.c b/libavcodec/h264_mb.c
index 3cd17b7e4b..0b31774556 100644
--- a/libavcodec/h264_mb.c
+++ b/libavcodec/h264_mb.c
@@ -34,7 +34,7 @@
 #include "h264dec.h"
 #include "h264_ps.h"
 #include "qpeldsp.h"
-#include "thread.h"
+#include "threadframe.h"
 
 static inline int get_lowest_part_list_y(H264SliceContext *sl,
  int n, int height, int y_offset, int 
list)
diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index dcd5874c2e..50a21c260f 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -30,7 +30,7 @@
 #include "avcodec.h"
 #include "h264dec.h"
 #include "mpegutils.h"
-#include "thread.h"
+#include "threadframe.h"
 
 void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
 {
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index dc636c5e78..600a109889 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -45,7 +45,7 @@
 #include "mathops.h"
 #include "mpegutils.h"
 #include "rectangle.h"
-#include "thread.h"
+#include "threadframe.h"
 
 static const uint8_t field_scan[16+1] = {
 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index a47caa95e8..1d648f04b7 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -46,7 +46,7 @@
 #include "mpegutils.h"
 #include "profiles.h"
 #include "rectangle.h"
-#include "thread.h"
+#include "threadframe.h"
 
 const uint16_t ff_h264_mb_sizes[4] = { 256, 384, 512, 768 };
 
diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c
index 3c45b5a39e..1ef214b0ff 100644
--- a/libavcodec/hevc_filter.c
+++ b/libavcodec/hevc_filter.c
@@ -26,6 +26,7 @@
 #include "libavutil/internal.h"
 
 #include "hevcdec.h"
+#include "threadframe.h"
 
 #define LUMA 0
 #define CB 1
diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c
index 1f6ca5a314..7477efcf52 100644
--- a/libavcodec/hevc_mvs.c
+++ b/libavcodec/hevc_mvs.c
@@ -23,6 +23,7 @@
 
 #include "hevc.h"
 #include "hevcdec.h"
+#include "threadframe.h"
 
 static const uint8_t l0_l1_cand_idx[12][2] = {
 { 0, 1, },
diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 06e42d9c53..d0a7888e21 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -28,6 +28,7 @@
 #include "thread.h"
 #include "hevc.h"
 #include "hevcdec.h"
+#include "threadframe.h"
 
 

[FFmpeg-devel] [PATCH 2/6] avcodec/hapdec: Remove always-false check

2022-02-06 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/hapdec.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index 2c8c5c36ba..45c44ad78d 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -352,9 +352,6 @@ static int hap_decode(AVCodecContext *avctx, void *data,
 
 start_texture_section += ctx->texture_section_size + 4;
 
-if (avctx->codec->update_thread_context)
-ff_thread_finish_setup(avctx);
-
 /* Unpack the DXT texture */
 if (hap_can_use_tex_in_place(ctx)) {
 int tex_size;
-- 
2.32.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/6] avcodec/pthread_frame: Don't prematurily presume frame-threading

2022-02-06 Thread Andreas Rheinhardt
Several of our decoders support both frame- as well as slice-threading;
in case of the latter avctx->internal->thread_ctx points to
a SliceThreadContext, not to a frame-thread PerThreadContext.
So only treat avctx->internal->thread_ctx as the latter after
having checked that frame-threading is active.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/pthread_frame.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 85a6bc98c1..43e097ff06 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -949,7 +949,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, 
int flags)
 {
-PerThreadContext *p = avctx->internal->thread_ctx;
+PerThreadContext *p;
 int err;
 
 f->owner[0] = f->owner[1] = avctx;
@@ -957,6 +957,7 @@ static int thread_get_buffer_internal(AVCodecContext 
*avctx, ThreadFrame *f, int
 if (!(avctx->active_thread_type & FF_THREAD_FRAME))
 return ff_get_buffer(avctx, f->f, flags);
 
+p = avctx->internal->thread_ctx;
 FF_DISABLE_DEPRECATION_WARNINGS
 if (atomic_load(>state) != STATE_SETTING_UP &&
 (avctx->codec->update_thread_context
@@ -1020,10 +1021,12 @@ FF_DISABLE_DEPRECATION_WARNINGS
 enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)
 {
 enum AVPixelFormat res;
-PerThreadContext *p = avctx->internal->thread_ctx;
+PerThreadContext *p;
 if (!(avctx->active_thread_type & FF_THREAD_FRAME) || 
avctx->thread_safe_callbacks ||
 avctx->get_format == avcodec_default_get_format)
 return ff_get_format(avctx, fmt);
+
+p = avctx->internal->thread_ctx;
 if (atomic_load(>state) != STATE_SETTING_UP) {
 av_log(avctx, AV_LOG_ERROR, "get_format() cannot be called after 
ff_thread_finish_setup()\n");
 return -1;
@@ -1057,7 +1060,7 @@ void ff_thread_release_buffer(AVCodecContext *avctx, 
ThreadFrame *f)
 {
 #if FF_API_THREAD_SAFE_CALLBACKS
 FF_DISABLE_DEPRECATION_WARNINGS
-PerThreadContext *p = avctx->internal->thread_ctx;
+PerThreadContext *p;
 FrameThreadContext *fctx;
 AVFrame *dst;
 int ret = 0;
@@ -1084,6 +1087,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 return;
 }
 
+p= avctx->internal->thread_ctx;
 fctx = p->parent;
 pthread_mutex_lock(>buffer_mutex);
 
-- 
2.32.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 v2 2/3] avformat/udp: Fix IP_MULTICAST_TTL for BSD compatibility

2022-02-06 Thread lance . lmwang
On Sun, Feb 06, 2022 at 02:27:09PM -0800, Chad Fraleigh wrote:
> 
> On 2/5/2022 6:09 PM, lance.lmw...@gmail.com wrote:
> > On Sat, Feb 05, 2022 at 01:26:18PM -0800, Chad Fraleigh wrote:
> >> Since any [valid] value over 255 is impossible in the IPv4 protocol (the 
> >> TTL field is only 8-bits), it should always be capped at 255 (for 
> >> consistency) or return an invalid value error (the one I would suggest).
> >>
> > 
> > zhilizhao have submit a patch to limit the range of ttl from option. Do you 
> > want
> > to return an invalid error here still?
> 
> If it can never be called with an invalid value, not even programmatically if 
> someone links against the ffmpeg libs, then checking it is unneeded. But also 
> checking it to limit the unsigned char value would be redundant, so only the 
> value cast would be needed, i.e.:
> 
>ttl = (unsigned char) mcastTTL;

Yes, checking is unneeded anymore, I'll remove it locally.

> 
> 
> If however, it could be called without being first limited, then returning an 
> error would be best to avoid silently having unexpected results. Also, 
> checking that it isn't negative should be done in that case. Not counting 
> pending patches, I only see udp_open() calls it, so if it's already bound in 
> there, no extra checks are needed.

Sure, the patch will be applied after the pending patches for limit anyway if
nobody have other comments.

> 
> Of course, these are only suggestions, since I'm a nobody. =)
> 
> 
> >> Despite VLC's reversed comment, using an int seems to be the exception to 
> >> the rule (i.e. only linux and windows seem to use it [as-documented]), 
> >> perhaps doing the unsigned char first and using the int as the fallback 
> >> would be better? It's not really just a BSD thing, unless you also count 
> >> LWIP and Solaris as BSD. Unless VLC's code history shows them doing it 
> >> this way at one time and swapping it (but forgetting the comment) to fix a 
> >> known bug?
> >>
> > 
> > I have blamed vlc code and sure the code doing it this way at one 
> > time(104938796a3). 
> > For the mismatch of code and comments, I prefer to code always as code were 
> > build 
> > and used by all kinds of system which vlc is supported already. 
> > 
> > As for use BSD, I prefer to count LWIP and Solaris into BSD category which 
> > using
> > rule of byte. If you still prefer to add them into comments, I'm OK also. 
> > 
> >>
> >> On 2/4/2022 9:28 PM, lance.lmw...@gmail.com wrote:
> >>> From: Limin Wang 
> >>>
> >>> Suggested by zhilizhao, vlc project has solved the compatibility by
> >>> the same way, so I borrowed the comments from vlc project.
> >>>
> >>> Fix #ticket9449
> >>>
> >>> Signed-off-by: Limin Wang 
> >>> ---
> >>>  libavformat/udp.c | 15 +--
> >>>  1 file changed, 13 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/libavformat/udp.c b/libavformat/udp.c
> >>> index 3dc79eb..34488d6 100644
> >>> --- a/libavformat/udp.c
> >>> +++ b/libavformat/udp.c
> >>> @@ -164,6 +164,10 @@ static int udp_set_multicast_ttl(int sockfd, int 
> >>> mcastTTL,
> >>>  {
> >>>  int protocol, cmd;
> >>>  
> >>> +/* There is some confusion in the world whether IP_MULTICAST_TTL
> >>> + * takes a byte or an int as an argument.
> >>> + * BSD seems to indicate byte so we are going with that and use
> >>> + * int as a fallback to be safe */
> >>>  switch (addr->sa_family) {
> >>>  #ifdef IP_MULTICAST_TTL
> >>>  case AF_INET:
> >>> @@ -183,8 +187,15 @@ static int udp_set_multicast_ttl(int sockfd, int 
> >>> mcastTTL,
> >>>  }
> >>>  
> >>>  if (setsockopt(sockfd, protocol, cmd, , sizeof(mcastTTL)) < 
> >>> 0) {
> >>> -ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt");
> >>> -return ff_neterrno();
> >>> +/* BSD compatibility */
> >>> +unsigned char ttl;
> >>> +
> >>> +ff_log_net_error(logctx, AV_LOG_DEBUG, "setsockopt");
> >>> +ttl = (unsigned char)(( mcastTTL > 255 ) ? 255 : mcastTTL);
> >>> +if (setsockopt(sockfd, protocol, cmd, , sizeof(ttl)) < 0) {
> >>> +ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt");
> >>> +return ff_neterrno();
> >>> +}
> >>>  }
> >>>  
> >>>  return 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 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".

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

To unsubscribe, visit link 

Re: [FFmpeg-devel] [PATCH] avformat/mpegts: initialize max_packet_size when sub-demuxer

2022-02-06 Thread Marton Balint




On Sat, 5 Feb 2022, Gyan Doshi wrote:


bca30570d2 added a user option to set max_packet_size replacing
a hardcoded value. This had a side-effect of leaving the field
set to 0 when packet demuxing is carried out from another demuxer
using avpriv functions, which could lead to demux failure.

Hardcoded max_packet_size inside avpriv_mpegts_parse_open to
2048000 to avoid this. Value chosen to be 10x that of default value
to accommodate large payloads.


I don't understand why the default is different from the normal mpegts 
case. Large payloads can happen there as well, and previously it was 
assumed that splitting is OK, because it will be parsed anyway.


Regards,
Marton



---
libavformat/mpegts.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index da15223b8a..e23f596490 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -3377,6 +3377,7 @@ MpegTSContext *avpriv_mpegts_parse_open(AVFormatContext 
*s)
return NULL;
/* no stream case, currently used by RTP */
ts->raw_packet_size = TS_PACKET_SIZE;
+ts->max_packet_size = 2048000;
ts->stream = s;
ts->auto_guess = 1;

--
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 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/3] avformat/udp: Fix IP_MULTICAST_TTL for BSD compatibility

2022-02-06 Thread Chad Fraleigh


On 2/5/2022 6:09 PM, lance.lmw...@gmail.com wrote:
> On Sat, Feb 05, 2022 at 01:26:18PM -0800, Chad Fraleigh wrote:
>> Since any [valid] value over 255 is impossible in the IPv4 protocol (the TTL 
>> field is only 8-bits), it should always be capped at 255 (for consistency) 
>> or return an invalid value error (the one I would suggest).
>>
> 
> zhilizhao have submit a patch to limit the range of ttl from option. Do you 
> want
> to return an invalid error here still?

If it can never be called with an invalid value, not even programmatically if 
someone links against the ffmpeg libs, then checking it is unneeded. But also 
checking it to limit the unsigned char value would be redundant, so only the 
value cast would be needed, i.e.:

   ttl = (unsigned char) mcastTTL;


If however, it could be called without being first limited, then returning an 
error would be best to avoid silently having unexpected results. Also, checking 
that it isn't negative should be done in that case. Not counting pending 
patches, I only see udp_open() calls it, so if it's already bound in there, no 
extra checks are needed.

Of course, these are only suggestions, since I'm a nobody. =)


>> Despite VLC's reversed comment, using an int seems to be the exception to 
>> the rule (i.e. only linux and windows seem to use it [as-documented]), 
>> perhaps doing the unsigned char first and using the int as the fallback 
>> would be better? It's not really just a BSD thing, unless you also count 
>> LWIP and Solaris as BSD. Unless VLC's code history shows them doing it this 
>> way at one time and swapping it (but forgetting the comment) to fix a known 
>> bug?
>>
> 
> I have blamed vlc code and sure the code doing it this way at one 
> time(104938796a3). 
> For the mismatch of code and comments, I prefer to code always as code were 
> build 
> and used by all kinds of system which vlc is supported already. 
> 
> As for use BSD, I prefer to count LWIP and Solaris into BSD category which 
> using
> rule of byte. If you still prefer to add them into comments, I'm OK also. 
> 
>>
>> On 2/4/2022 9:28 PM, lance.lmw...@gmail.com wrote:
>>> From: Limin Wang 
>>>
>>> Suggested by zhilizhao, vlc project has solved the compatibility by
>>> the same way, so I borrowed the comments from vlc project.
>>>
>>> Fix #ticket9449
>>>
>>> Signed-off-by: Limin Wang 
>>> ---
>>>  libavformat/udp.c | 15 +--
>>>  1 file changed, 13 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/libavformat/udp.c b/libavformat/udp.c
>>> index 3dc79eb..34488d6 100644
>>> --- a/libavformat/udp.c
>>> +++ b/libavformat/udp.c
>>> @@ -164,6 +164,10 @@ static int udp_set_multicast_ttl(int sockfd, int 
>>> mcastTTL,
>>>  {
>>>  int protocol, cmd;
>>>  
>>> +/* There is some confusion in the world whether IP_MULTICAST_TTL
>>> + * takes a byte or an int as an argument.
>>> + * BSD seems to indicate byte so we are going with that and use
>>> + * int as a fallback to be safe */
>>>  switch (addr->sa_family) {
>>>  #ifdef IP_MULTICAST_TTL
>>>  case AF_INET:
>>> @@ -183,8 +187,15 @@ static int udp_set_multicast_ttl(int sockfd, int 
>>> mcastTTL,
>>>  }
>>>  
>>>  if (setsockopt(sockfd, protocol, cmd, , sizeof(mcastTTL)) < 
>>> 0) {
>>> -ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt");
>>> -return ff_neterrno();
>>> +/* BSD compatibility */
>>> +unsigned char ttl;
>>> +
>>> +ff_log_net_error(logctx, AV_LOG_DEBUG, "setsockopt");
>>> +ttl = (unsigned char)(( mcastTTL > 255 ) ? 255 : mcastTTL);
>>> +if (setsockopt(sockfd, protocol, cmd, , sizeof(ttl)) < 0) {
>>> +ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt");
>>> +return ff_neterrno();
>>> +}
>>>  }
>>>  
>>>  return 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 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/3] avformat/udp: Fix IP_MULTICAST_TTL for BSD compatibility

2022-02-06 Thread Marton Balint




On Sun, 6 Feb 2022, lance.lmw...@gmail.com wrote:


On Sat, Feb 05, 2022 at 01:26:18PM -0800, Chad Fraleigh wrote:

Since any [valid] value over 255 is impossible in the IPv4 protocol (the TTL 
field is only 8-bits), it should always be capped at 255 (for consistency) or 
return an invalid value error (the one I would suggest).



zhilizhao have submit a patch to limit the range of ttl from option. Do you want
to return an invalid error here still?


I have applied the patch, so capping is no longer needed.




Despite VLC's reversed comment, using an int seems to be the exception 
to the rule (i.e. only linux and windows seem to use it 
[as-documented]), perhaps doing the unsigned char first and using the 
int as the fallback would be better? It's not really just a BSD thing, 
unless you also count LWIP and Solaris as BSD. Unless VLC's code 
history shows them doing it this way at one time and swapping it (but 
forgetting the comment) to fix a known bug?




I have blamed vlc code and sure the code doing it this way at one 
time(104938796a3).
For the mismatch of code and comments, I prefer to code always as code were 
build
and used by all kinds of system which vlc is supported already.



Yeah, I agree, if we are copying VLC approach then probably it makes more 
sense to use the same order as they do in their code.


Thanks,
Marton
___
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 1/2] lavf/udp: set ttl upper bound to 255

2022-02-06 Thread Marton Balint



On Thu, 27 Jan 2022, myp...@gmail.com wrote:


On Thu, Jan 27, 2022 at 1:09 PM "zhilizhao(赵志立)"  wrote:




> On Jan 27, 2022, at 12:22 AM, Zhao Zhili  wrote:
>
> ---
> libavformat/udp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index 83c042d079..b441d2ea0d 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -134,7 +134,7 @@ static const AVOption options[] = {
> { "reuse",  "explicitly allow reusing UDP sockets",
OFFSET(reuse_socket),   AV_OPT_TYPE_BOOL,   { .i64 = -1 },-1, 1,   D|E },
> { "reuse_socket",   "explicitly allow reusing UDP sockets",
OFFSET(reuse_socket),   AV_OPT_TYPE_BOOL,   { .i64 = -1 },-1, 1,   .flags = D|E },
> { "broadcast", "explicitly allow or disallow broadcast destination",   
OFFSET(is_broadcast),   AV_OPT_TYPE_BOOL,   { .i64 = 0  }, 0, 1,   E },
> -{ "ttl","Time to live (multicast only)",   
OFFSET(ttl),AV_OPT_TYPE_INT,{ .i64 = 16 }, 0, INT_MAX, E },
> +{ "ttl","Time to live (multicast only)",   
OFFSET(ttl),AV_OPT_TYPE_INT,{ .i64 = 16 }, 0, 255, E },
> { "connect","set if connect() should be called on socket", 
OFFSET(is_connected),   AV_OPT_TYPE_BOOL,   { .i64 =  0 }, 0, 1,   .flags = D|E },
> { "fifo_size",  "set the UDP receiving circular buffer size, expressed as 
a number of packets with size of 188 bytes", OFFSET(circular_buffer_size), AV_OPT_TYPE_INT, {.i64 
= 7*4096}, 0, INT_MAX, D },
> { "overrun_nonfatal", "survive in case of UDP receiving circular buffer 
overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,D },
> --
> 2.29.2
>

This patchset is related to 'Fix setsockopt IP_MULTICAST_TTL on OpenBSD’.

https://patchwork.ffmpeg.org/project/ffmpeg/patch/yd5jaxbcd6gp7...@humpty.home.comstyle.com/

Looks like it’s impossible to avoid casting int to unsigned char, so integer
overflow/truncation must be handled. Since the maximum value of TTL is 255
limited by IPv4/IPv6, set the upper bound of AVOption to fail early for
invalid value.

Patchset LGTM, limited the TTL(Time to live) in IPv4  <= 255 in option
is better than coding in the function


Will apply.

Thanks,
Marton
___
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 dialogue enhance audio filter

2022-02-06 Thread Pierre-Anthony Lemieux
On Sun, Feb 6, 2022 at 11:52 AM Paul B Mahol  wrote:
>
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi|  28 +++
>  libavfilter/Makefile|   1 +
>  libavfilter/af_dialoguenhance.c | 407 
>  libavfilter/allfilters.c|   1 +
>  4 files changed, 437 insertions(+)
>  create mode 100644 libavfilter/af_dialoguenhance.c
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 04c34cb1fb..10c11c1f55 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -4178,6 +4178,34 @@ Default value is @var{o}.
>
>  @end table
>
> +@section dialoguenhance
> +Enhance dialogue in stereo audio.

I suggest adding a link to an explainer/article and/or including an
overview description of the algorithm.

> +
> +This filter accepts stereo input and produce surround (3.0) channels output.
> +The newly produced front center channel have enhanced speech dialogue 
> originally
> +available in both stereo channels.
> +This filter outputs front left and front right channels same as available in 
> stereo input.
> +
> +The filter accepts the following options:
> +
> +@table @option
> +@item original
> +Set the original center factor to keep in front center channel output.
> +Allowed range is from 0 to 1. Default value is 1.
> +
> +@item enhance
> +Set the dialogue enhance factor to put in front center channel output.
> +Allowed range is from 0 to 3. Default value is 1.
> +
> +@item voice
> +Set the voice detection factor.
> +Allowed range is from 2 to 32. Default value is 2.
> +@end table
> +
> +@subsection Commands
> +
> +This filter supports the all above options as @ref{commands}.
> +
>  @section drmeter
>  Measure audio dynamic range.
>
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 282967144b..56d33e6480 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -124,6 +124,7 @@ OBJS-$(CONFIG_CROSSFEED_FILTER)  += 
> af_crossfeed.o
>  OBJS-$(CONFIG_CRYSTALIZER_FILTER)+= af_crystalizer.o
>  OBJS-$(CONFIG_DCSHIFT_FILTER)+= af_dcshift.o
>  OBJS-$(CONFIG_DEESSER_FILTER)+= af_deesser.o
> +OBJS-$(CONFIG_DIALOGUENHANCE_FILTER) += af_dialoguenhance.o
>  OBJS-$(CONFIG_DRMETER_FILTER)+= af_drmeter.o
>  OBJS-$(CONFIG_DYNAUDNORM_FILTER) += af_dynaudnorm.o
>  OBJS-$(CONFIG_EARWAX_FILTER) += af_earwax.o
> diff --git a/libavfilter/af_dialoguenhance.c b/libavfilter/af_dialoguenhance.c
> new file mode 100644
> index 00..87cf131320
> --- /dev/null
> +++ b/libavfilter/af_dialoguenhance.c
> @@ -0,0 +1,407 @@
> +/*
> + * Copyright (c) 2022 Paul B Mahol
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public License
> + * as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public License
> + * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavutil/channel_layout.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/tx.h"
> +#include "audio.h"
> +#include "avfilter.h"
> +#include "filters.h"
> +#include "internal.h"
> +#include "window_func.h"
> +
> +#include 
> +
> +typedef struct AudioDialogueEnhancementContext {
> +const AVClass *class;
> +
> +double original, enhance, voice;
> +
> +int fft_size;
> +int overlap;
> +
> +float *window;
> +float prev_vad;
> +
> +AVFrame *in;
> +AVFrame *in_frame;
> +AVFrame *out_dist_frame;
> +AVFrame *windowed_frame;
> +AVFrame *windowed_out;
> +AVFrame *windowed_prev;
> +AVFrame *center_frame;
> +
> +AVTXContext *tx_ctx[2], *itx_ctx;
> +av_tx_fn tx_fn, itx_fn;
> +} AudioDialogueEnhanceContext;
> +
> +#define OFFSET(x) offsetof(AudioDialogueEnhanceContext, x)
> +#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | 
> AV_OPT_FLAG_RUNTIME_PARAM
> +
> +static const AVOption dialoguenhance_options[] = {
> +{ "original", "set original center factor", OFFSET(original), 
> AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
> +{ "enhance",  "set dialog enhance factor",  OFFSET(enhance),  
> AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 3, FLAGS },
> +{ "voice","set voice detection factor", OFFSET(voice),
> AV_OPT_TYPE_DOUBLE, {.dbl=2}, 2,32, FLAGS },
> +{NULL}
> +};
> +
> +AVFILTER_DEFINE_CLASS(dialoguenhance);
> +
> +static int query_formats(AVFilterContext *ctx)
> +{
> +

[FFmpeg-devel] [PATCH] avfilter: add dialogue enhance audio filter

2022-02-06 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi|  28 +++
 libavfilter/Makefile|   1 +
 libavfilter/af_dialoguenhance.c | 407 
 libavfilter/allfilters.c|   1 +
 4 files changed, 437 insertions(+)
 create mode 100644 libavfilter/af_dialoguenhance.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 04c34cb1fb..10c11c1f55 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4178,6 +4178,34 @@ Default value is @var{o}.
 
 @end table
 
+@section dialoguenhance
+Enhance dialogue in stereo audio.
+
+This filter accepts stereo input and produce surround (3.0) channels output.
+The newly produced front center channel have enhanced speech dialogue 
originally
+available in both stereo channels.
+This filter outputs front left and front right channels same as available in 
stereo input.
+
+The filter accepts the following options:
+
+@table @option
+@item original
+Set the original center factor to keep in front center channel output.
+Allowed range is from 0 to 1. Default value is 1.
+
+@item enhance
+Set the dialogue enhance factor to put in front center channel output.
+Allowed range is from 0 to 3. Default value is 1.
+
+@item voice
+Set the voice detection factor.
+Allowed range is from 2 to 32. Default value is 2.
+@end table
+
+@subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @section drmeter
 Measure audio dynamic range.
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 282967144b..56d33e6480 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -124,6 +124,7 @@ OBJS-$(CONFIG_CROSSFEED_FILTER)  += 
af_crossfeed.o
 OBJS-$(CONFIG_CRYSTALIZER_FILTER)+= af_crystalizer.o
 OBJS-$(CONFIG_DCSHIFT_FILTER)+= af_dcshift.o
 OBJS-$(CONFIG_DEESSER_FILTER)+= af_deesser.o
+OBJS-$(CONFIG_DIALOGUENHANCE_FILTER) += af_dialoguenhance.o
 OBJS-$(CONFIG_DRMETER_FILTER)+= af_drmeter.o
 OBJS-$(CONFIG_DYNAUDNORM_FILTER) += af_dynaudnorm.o
 OBJS-$(CONFIG_EARWAX_FILTER) += af_earwax.o
diff --git a/libavfilter/af_dialoguenhance.c b/libavfilter/af_dialoguenhance.c
new file mode 100644
index 00..87cf131320
--- /dev/null
+++ b/libavfilter/af_dialoguenhance.c
@@ -0,0 +1,407 @@
+/*
+ * Copyright (c) 2022 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/channel_layout.h"
+#include "libavutil/opt.h"
+#include "libavutil/tx.h"
+#include "audio.h"
+#include "avfilter.h"
+#include "filters.h"
+#include "internal.h"
+#include "window_func.h"
+
+#include 
+
+typedef struct AudioDialogueEnhancementContext {
+const AVClass *class;
+
+double original, enhance, voice;
+
+int fft_size;
+int overlap;
+
+float *window;
+float prev_vad;
+
+AVFrame *in;
+AVFrame *in_frame;
+AVFrame *out_dist_frame;
+AVFrame *windowed_frame;
+AVFrame *windowed_out;
+AVFrame *windowed_prev;
+AVFrame *center_frame;
+
+AVTXContext *tx_ctx[2], *itx_ctx;
+av_tx_fn tx_fn, itx_fn;
+} AudioDialogueEnhanceContext;
+
+#define OFFSET(x) offsetof(AudioDialogueEnhanceContext, x)
+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | 
AV_OPT_FLAG_RUNTIME_PARAM
+
+static const AVOption dialoguenhance_options[] = {
+{ "original", "set original center factor", OFFSET(original), 
AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
+{ "enhance",  "set dialog enhance factor",  OFFSET(enhance),  
AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 3, FLAGS },
+{ "voice","set voice detection factor", OFFSET(voice),
AV_OPT_TYPE_DOUBLE, {.dbl=2}, 2,32, FLAGS },
+{NULL}
+};
+
+AVFILTER_DEFINE_CLASS(dialoguenhance);
+
+static int query_formats(AVFilterContext *ctx)
+{
+AVFilterFormats *formats = NULL;
+AVFilterChannelLayouts *in_layout = NULL, *out_layout = NULL;
+int ret;
+
+if ((ret = ff_add_format (, AV_SAMPLE_FMT_FLTP )) 
< 0 ||
+(ret = ff_set_common_formats (ctx , formats)) 
< 0 ||
+(ret = ff_add_channel_layout (_layout , 
AV_CH_LAYOUT_STEREO)) < 0 ||
+(ret = ff_channel_layouts_ref(in_layout, 

Re: [FFmpeg-devel] [PATCH] avfilter/af_atempo: switch to rdft from lavu/tx

2022-02-06 Thread Lynne
6 Feb 2022, 19:04 by pkoshe...@gmail.com:

> On Sun, Feb 6, 2022 at 10:24 AM Paul B Mahol  wrote:
>
>> On Sun, Feb 6, 2022 at 6:16 PM Pavel Koshevoy  wrote:
>>
>> > On Sun, Feb 6, 2022 at 4:24 AM Paul B Mahol  wrote:
>>
>> > >
>> > >
>> > Is the old API being removed or deprecated?
>> > Just wondering why this change is necessary.
>> >
>>
>> New api is faster.
>>

Old API will get deprecated soon, but we have to replace its use
in our code first.
New API is faster, and supports non-power-of-two lengths.
___
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/af_atempo: switch to rdft from lavu/tx

2022-02-06 Thread Pavel Koshevoy
On Sun, Feb 6, 2022 at 10:24 AM Paul B Mahol  wrote:

> On Sun, Feb 6, 2022 at 6:16 PM Pavel Koshevoy  wrote:
>
> > On Sun, Feb 6, 2022 at 4:24 AM Paul B Mahol  wrote:
> >
> > > Signed-off-by: Paul B Mahol 
> > > ---
> > >  configure   |   3 -
> > >  libavfilter/af_atempo.c | 126 
> > >  2 files changed, 64 insertions(+), 65 deletions(-)
> > >
> > > diff --git a/configure b/configure
> > > index 5a8b52c77d..6ec25dd622 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -3610,8 +3610,6 @@ amovie_filter_deps="avcodec avformat"
> > >  aresample_filter_deps="swresample"
> > >  asr_filter_deps="pocketsphinx"
> > >  ass_filter_deps="libass"
> > > -atempo_filter_deps="avcodec"
> > > -atempo_filter_select="rdft"
> > >  avgblur_opencl_filter_deps="opencl"
> > >  avgblur_vulkan_filter_deps="vulkan spirv_compiler"
> > >  azmq_filter_deps="libzmq"
> > > @@ -7387,7 +7385,6 @@ enabled zlib && add_cppflags -DZLIB_CONST
> > >  # conditional library dependencies, in any order
> > >  enabled amovie_filter   && prepend avfilter_deps "avformat
> avcodec"
> > >  enabled aresample_filter&& prepend avfilter_deps "swresample"
> > > -enabled atempo_filter   && prepend avfilter_deps "avcodec"
> > >  enabled bm3d_filter && prepend avfilter_deps "avcodec"
> > >  enabled cover_rect_filter   && prepend avfilter_deps "avformat
> avcodec"
> > >  enabled ebur128_filter && enabled swresample && prepend avfilter_deps
> > > "swresample"
> > > diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
> > > index e9a6da7970..27f2f6daa0 100644
> > > --- a/libavfilter/af_atempo.c
> > > +++ b/libavfilter/af_atempo.c
> > > @@ -39,13 +39,13 @@
> > >   */
> > >
> > >  #include 
> > > -#include "libavcodec/avfft.h"
> > >  #include "libavutil/avassert.h"
> > >  #include "libavutil/avstring.h"
> > >  #include "libavutil/channel_layout.h"
> > >  #include "libavutil/eval.h"
> > >  #include "libavutil/opt.h"
> > >  #include "libavutil/samplefmt.h"
> > > +#include "libavutil/tx.h"
> > >  #include "avfilter.h"
> > >  #include "audio.h"
> > >  #include "internal.h"
> > > @@ -67,7 +67,8 @@ typedef struct AudioFragment {
> > >
> > >  // rDFT transform of the down-mixed mono fragment, used for
> > >  // fast waveform alignment via correlation in frequency domain:
> > > -FFTSample *xdat;
> > > +float *xdat_in;
> > > +float *xdat;
> > >  } AudioFragment;
> > >
> > >
> > Is the old API being removed or deprecated?
> > Just wondering why this change is necessary.
> >
>
> New api is faster.
>
> >
> >
> >
> >
> > >  /**
> > > @@ -140,9 +141,11 @@ typedef struct ATempoContext {
> > >  FilterState state;
> > >
> > >  // for fast correlation calculation in frequency domain:
> > > -RDFTContext *real_to_complex;
> > > -RDFTContext *complex_to_real;
> > > -FFTSample *correlation;
> > > +AVTXContext *real_to_complex;
> > > +AVTXContext *complex_to_real;
> > > +av_tx_fn r2c_fn, c2r_fn;
> > > +float *correlation_in;
> > > +float *correlation;
> > >
> > >  // for managing AVFilterPad.request_frame and
> > AVFilterPad.filter_frame
> > >  AVFrame *dst_buffer;
> > > @@ -228,18 +231,18 @@ static void yae_release_buffers(ATempoContext
> > > *atempo)
> > >
> > >  av_freep(>frag[0].data);
> > >  av_freep(>frag[1].data);
> > > +av_freep(>frag[0].xdat_in);
> > > +av_freep(>frag[1].xdat_in);
> > >  av_freep(>frag[0].xdat);
> > >  av_freep(>frag[1].xdat);
> > >
> > >  av_freep(>buffer);
> > >  av_freep(>hann);
> > > +av_freep(>correlation_in);
> > >  av_freep(>correlation);
> > >
> > > -av_rdft_end(atempo->real_to_complex);
> > > -atempo->real_to_complex = NULL;
> > > -
> > > -av_rdft_end(atempo->complex_to_real);
> > > -atempo->complex_to_real = NULL;
> > > +av_tx_uninit(>real_to_complex);
> > > +av_tx_uninit(>complex_to_real);
> > >  }
> > >
> > >  /* av_realloc is not aligned enough; fortunately, the data does not
> need
> > > to
> > > @@ -247,7 +250,7 @@ static void yae_release_buffers(ATempoContext
> > *atempo)
> > >  #define RE_MALLOC_OR_FAIL(field, field_size)\
> > >  do {\
> > >  av_freep();   \
> > > -field = av_malloc(field_size);  \
> > > +field = av_calloc(field_size, 1);   \
> > >  if (!field) {   \
> > >  yae_release_buffers(atempo);\
> > >  return AVERROR(ENOMEM); \
> > > @@ -265,6 +268,7 @@ static int yae_reset(ATempoContext *atempo,
> > >  {
> > >  const int sample_size = av_get_bytes_per_sample(format);
> > >  uint32_t nlevels  = 0;
> > > +float scale = 1.f, iscale = 1.f;
> > >  uint32_t pot;
> > >  int i;
> > >
> > > @@ -288,29 

Re: [FFmpeg-devel] [PATCH] avcodec/h264dec: add option to ignore in band parameter set

2022-02-06 Thread zhilizhao(赵志立)


> On Feb 6, 2022, at 11:31 PM, Hendrik Leppkes  wrote:
> 
> On Sun, Feb 6, 2022 at 3:58 PM Zhao Zhili  wrote:
>> 
>> It works in three mode:
>> 0: don't ignore in-band ps
>> 1: ignore in-band ps
>> -1: if corrupted data is detected, then ignore in-band ps afterwards
>> 
>> h264dec working hard to do error resilience, it doesn't drop a
>> whole packet when error is detected in a nalu. Then there is a
>> higher chance for fake sps/pps be found and used. This happened
>> in a mp4 file. h264dec failed to recovery after broken data due
>> to the fake pps, while other H.264 decoders have no such problem.
> 
> This seems extremely hacky. I think you need to elaborate on the
> problem you are trying to fix, so that any approach to a solution can
> be judged properly.

There are two problems here:

Firstly, after split a packet into multiple NALUs, if part of these NALUs
have broken data, drop the whole packet or not. For H.264 with avcc
bitstream, the split itself is questionable if part of these NALUs are
invalid. Keep going after broken H264_NAL_SLICE has no serious effect,
but updating SPS/PPS in this case can be dangerous.

Secondly, for some containers like mp4, updating SPS/PPS are supported by
spec but don’t get widely support among implementations. FFmpeg can
generate mp4 with SPS/PPS updating in-band, but demux and decoding only
works without seek. On the whole, it make sense to have an option do
ignore in-band parameter set for those container.

> 
> - Hendrik
> ___
> 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] avfilter/af_atempo: switch to rdft from lavu/tx

2022-02-06 Thread Paul B Mahol
On Sun, Feb 6, 2022 at 6:16 PM Pavel Koshevoy  wrote:

> On Sun, Feb 6, 2022 at 4:24 AM Paul B Mahol  wrote:
>
> > Signed-off-by: Paul B Mahol 
> > ---
> >  configure   |   3 -
> >  libavfilter/af_atempo.c | 126 
> >  2 files changed, 64 insertions(+), 65 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 5a8b52c77d..6ec25dd622 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3610,8 +3610,6 @@ amovie_filter_deps="avcodec avformat"
> >  aresample_filter_deps="swresample"
> >  asr_filter_deps="pocketsphinx"
> >  ass_filter_deps="libass"
> > -atempo_filter_deps="avcodec"
> > -atempo_filter_select="rdft"
> >  avgblur_opencl_filter_deps="opencl"
> >  avgblur_vulkan_filter_deps="vulkan spirv_compiler"
> >  azmq_filter_deps="libzmq"
> > @@ -7387,7 +7385,6 @@ enabled zlib && add_cppflags -DZLIB_CONST
> >  # conditional library dependencies, in any order
> >  enabled amovie_filter   && prepend avfilter_deps "avformat avcodec"
> >  enabled aresample_filter&& prepend avfilter_deps "swresample"
> > -enabled atempo_filter   && prepend avfilter_deps "avcodec"
> >  enabled bm3d_filter && prepend avfilter_deps "avcodec"
> >  enabled cover_rect_filter   && prepend avfilter_deps "avformat avcodec"
> >  enabled ebur128_filter && enabled swresample && prepend avfilter_deps
> > "swresample"
> > diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
> > index e9a6da7970..27f2f6daa0 100644
> > --- a/libavfilter/af_atempo.c
> > +++ b/libavfilter/af_atempo.c
> > @@ -39,13 +39,13 @@
> >   */
> >
> >  #include 
> > -#include "libavcodec/avfft.h"
> >  #include "libavutil/avassert.h"
> >  #include "libavutil/avstring.h"
> >  #include "libavutil/channel_layout.h"
> >  #include "libavutil/eval.h"
> >  #include "libavutil/opt.h"
> >  #include "libavutil/samplefmt.h"
> > +#include "libavutil/tx.h"
> >  #include "avfilter.h"
> >  #include "audio.h"
> >  #include "internal.h"
> > @@ -67,7 +67,8 @@ typedef struct AudioFragment {
> >
> >  // rDFT transform of the down-mixed mono fragment, used for
> >  // fast waveform alignment via correlation in frequency domain:
> > -FFTSample *xdat;
> > +float *xdat_in;
> > +float *xdat;
> >  } AudioFragment;
> >
> >
> Is the old API being removed or deprecated?
> Just wondering why this change is necessary.
>

New api is faster.

>
>
>
>
> >  /**
> > @@ -140,9 +141,11 @@ typedef struct ATempoContext {
> >  FilterState state;
> >
> >  // for fast correlation calculation in frequency domain:
> > -RDFTContext *real_to_complex;
> > -RDFTContext *complex_to_real;
> > -FFTSample *correlation;
> > +AVTXContext *real_to_complex;
> > +AVTXContext *complex_to_real;
> > +av_tx_fn r2c_fn, c2r_fn;
> > +float *correlation_in;
> > +float *correlation;
> >
> >  // for managing AVFilterPad.request_frame and
> AVFilterPad.filter_frame
> >  AVFrame *dst_buffer;
> > @@ -228,18 +231,18 @@ static void yae_release_buffers(ATempoContext
> > *atempo)
> >
> >  av_freep(>frag[0].data);
> >  av_freep(>frag[1].data);
> > +av_freep(>frag[0].xdat_in);
> > +av_freep(>frag[1].xdat_in);
> >  av_freep(>frag[0].xdat);
> >  av_freep(>frag[1].xdat);
> >
> >  av_freep(>buffer);
> >  av_freep(>hann);
> > +av_freep(>correlation_in);
> >  av_freep(>correlation);
> >
> > -av_rdft_end(atempo->real_to_complex);
> > -atempo->real_to_complex = NULL;
> > -
> > -av_rdft_end(atempo->complex_to_real);
> > -atempo->complex_to_real = NULL;
> > +av_tx_uninit(>real_to_complex);
> > +av_tx_uninit(>complex_to_real);
> >  }
> >
> >  /* av_realloc is not aligned enough; fortunately, the data does not need
> > to
> > @@ -247,7 +250,7 @@ static void yae_release_buffers(ATempoContext
> *atempo)
> >  #define RE_MALLOC_OR_FAIL(field, field_size)\
> >  do {\
> >  av_freep();   \
> > -field = av_malloc(field_size);  \
> > +field = av_calloc(field_size, 1);   \
> >  if (!field) {   \
> >  yae_release_buffers(atempo);\
> >  return AVERROR(ENOMEM); \
> > @@ -265,6 +268,7 @@ static int yae_reset(ATempoContext *atempo,
> >  {
> >  const int sample_size = av_get_bytes_per_sample(format);
> >  uint32_t nlevels  = 0;
> > +float scale = 1.f, iscale = 1.f;
> >  uint32_t pot;
> >  int i;
> >
> > @@ -288,29 +292,29 @@ static int yae_reset(ATempoContext *atempo,
> >  // initialize audio fragment buffers:
> >  RE_MALLOC_OR_FAIL(atempo->frag[0].data, atempo->window *
> > atempo->stride);
> >  RE_MALLOC_OR_FAIL(atempo->frag[1].data, atempo->window *
> > atempo->stride);
> > -RE_MALLOC_OR_FAIL(atempo->frag[0].xdat, 

Re: [FFmpeg-devel] [PATCH] avfilter/af_atempo: switch to rdft from lavu/tx

2022-02-06 Thread Pavel Koshevoy
On Sun, Feb 6, 2022 at 4:24 AM Paul B Mahol  wrote:

> Signed-off-by: Paul B Mahol 
> ---
>  configure   |   3 -
>  libavfilter/af_atempo.c | 126 
>  2 files changed, 64 insertions(+), 65 deletions(-)
>
> diff --git a/configure b/configure
> index 5a8b52c77d..6ec25dd622 100755
> --- a/configure
> +++ b/configure
> @@ -3610,8 +3610,6 @@ amovie_filter_deps="avcodec avformat"
>  aresample_filter_deps="swresample"
>  asr_filter_deps="pocketsphinx"
>  ass_filter_deps="libass"
> -atempo_filter_deps="avcodec"
> -atempo_filter_select="rdft"
>  avgblur_opencl_filter_deps="opencl"
>  avgblur_vulkan_filter_deps="vulkan spirv_compiler"
>  azmq_filter_deps="libzmq"
> @@ -7387,7 +7385,6 @@ enabled zlib && add_cppflags -DZLIB_CONST
>  # conditional library dependencies, in any order
>  enabled amovie_filter   && prepend avfilter_deps "avformat avcodec"
>  enabled aresample_filter&& prepend avfilter_deps "swresample"
> -enabled atempo_filter   && prepend avfilter_deps "avcodec"
>  enabled bm3d_filter && prepend avfilter_deps "avcodec"
>  enabled cover_rect_filter   && prepend avfilter_deps "avformat avcodec"
>  enabled ebur128_filter && enabled swresample && prepend avfilter_deps
> "swresample"
> diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
> index e9a6da7970..27f2f6daa0 100644
> --- a/libavfilter/af_atempo.c
> +++ b/libavfilter/af_atempo.c
> @@ -39,13 +39,13 @@
>   */
>
>  #include 
> -#include "libavcodec/avfft.h"
>  #include "libavutil/avassert.h"
>  #include "libavutil/avstring.h"
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/eval.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/samplefmt.h"
> +#include "libavutil/tx.h"
>  #include "avfilter.h"
>  #include "audio.h"
>  #include "internal.h"
> @@ -67,7 +67,8 @@ typedef struct AudioFragment {
>
>  // rDFT transform of the down-mixed mono fragment, used for
>  // fast waveform alignment via correlation in frequency domain:
> -FFTSample *xdat;
> +float *xdat_in;
> +float *xdat;
>  } AudioFragment;
>
>
Is the old API being removed or deprecated?
Just wondering why this change is necessary.




>  /**
> @@ -140,9 +141,11 @@ typedef struct ATempoContext {
>  FilterState state;
>
>  // for fast correlation calculation in frequency domain:
> -RDFTContext *real_to_complex;
> -RDFTContext *complex_to_real;
> -FFTSample *correlation;
> +AVTXContext *real_to_complex;
> +AVTXContext *complex_to_real;
> +av_tx_fn r2c_fn, c2r_fn;
> +float *correlation_in;
> +float *correlation;
>
>  // for managing AVFilterPad.request_frame and AVFilterPad.filter_frame
>  AVFrame *dst_buffer;
> @@ -228,18 +231,18 @@ static void yae_release_buffers(ATempoContext
> *atempo)
>
>  av_freep(>frag[0].data);
>  av_freep(>frag[1].data);
> +av_freep(>frag[0].xdat_in);
> +av_freep(>frag[1].xdat_in);
>  av_freep(>frag[0].xdat);
>  av_freep(>frag[1].xdat);
>
>  av_freep(>buffer);
>  av_freep(>hann);
> +av_freep(>correlation_in);
>  av_freep(>correlation);
>
> -av_rdft_end(atempo->real_to_complex);
> -atempo->real_to_complex = NULL;
> -
> -av_rdft_end(atempo->complex_to_real);
> -atempo->complex_to_real = NULL;
> +av_tx_uninit(>real_to_complex);
> +av_tx_uninit(>complex_to_real);
>  }
>
>  /* av_realloc is not aligned enough; fortunately, the data does not need
> to
> @@ -247,7 +250,7 @@ static void yae_release_buffers(ATempoContext *atempo)
>  #define RE_MALLOC_OR_FAIL(field, field_size)\
>  do {\
>  av_freep();   \
> -field = av_malloc(field_size);  \
> +field = av_calloc(field_size, 1);   \
>  if (!field) {   \
>  yae_release_buffers(atempo);\
>  return AVERROR(ENOMEM); \
> @@ -265,6 +268,7 @@ static int yae_reset(ATempoContext *atempo,
>  {
>  const int sample_size = av_get_bytes_per_sample(format);
>  uint32_t nlevels  = 0;
> +float scale = 1.f, iscale = 1.f;
>  uint32_t pot;
>  int i;
>
> @@ -288,29 +292,29 @@ static int yae_reset(ATempoContext *atempo,
>  // initialize audio fragment buffers:
>  RE_MALLOC_OR_FAIL(atempo->frag[0].data, atempo->window *
> atempo->stride);
>  RE_MALLOC_OR_FAIL(atempo->frag[1].data, atempo->window *
> atempo->stride);
> -RE_MALLOC_OR_FAIL(atempo->frag[0].xdat, atempo->window *
> sizeof(FFTComplex));
> -RE_MALLOC_OR_FAIL(atempo->frag[1].xdat, atempo->window *
> sizeof(FFTComplex));
> +RE_MALLOC_OR_FAIL(atempo->frag[0].xdat_in, (atempo->window + 1) *
> sizeof(AVComplexFloat));
> +RE_MALLOC_OR_FAIL(atempo->frag[1].xdat_in, (atempo->window + 1) *
> sizeof(AVComplexFloat));
> +

Re: [FFmpeg-devel] [PATCH] avcodec/h264dec: add option to ignore in band parameter set

2022-02-06 Thread Hendrik Leppkes
On Sun, Feb 6, 2022 at 3:58 PM Zhao Zhili  wrote:
>
> It works in three mode:
> 0: don't ignore in-band ps
> 1: ignore in-band ps
> -1: if corrupted data is detected, then ignore in-band ps afterwards
>
> h264dec working hard to do error resilience, it doesn't drop a
> whole packet when error is detected in a nalu. Then there is a
> higher chance for fake sps/pps be found and used. This happened
> in a mp4 file. h264dec failed to recovery after broken data due
> to the fake pps, while other H.264 decoders have no such problem.

This seems extremely hacky. I think you need to elaborate on the
problem you are trying to fix, so that any approach to a solution can
be judged properly.

- Hendrik
___
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] zscale video filter performance optimization 4x

2022-02-06 Thread Victoria Zhislina
Paul, thanks a lot for reviewing. The answer is - yes, the move saves up to
30% of performance for a single thread execution, so it is necessary.
I wasn't aware of the cases where width/height can change between frames -
never seen them in real life, but right you are,  iI will change my code
accordingly - to make re-init if some change happened.
Thanks again!

On Fri, Feb 4, 2022 at 8:17 PM Paul B Mahol  wrote:

> Is moving all this code really needed?
>
> Note that width/height can change between frames so that is supported
> by scale filter.
> With your change that is not more possible?
> ___
> 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] avcodec/h264dec: add option to ignore in band parameter set

2022-02-06 Thread Zhao Zhili
It works in three mode:
0: don't ignore in-band ps
1: ignore in-band ps
-1: if corrupted data is detected, then ignore in-band ps afterwards

h264dec working hard to do error resilience, it doesn't drop a
whole packet when error is detected in a nalu. Then there is a
higher chance for fake sps/pps be found and used. This happened
in a mp4 file. h264dec failed to recovery after broken data due
to the fake pps, while other H.264 decoders have no such problem.
---
 libavcodec/h264dec.c | 17 -
 libavcodec/h264dec.h |  1 +
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index a47caa95e8..1ee2b68459 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -681,6 +681,10 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size)
 break;
 case H264_NAL_SPS: {
 GetBitContext tmp_gb = nal->gb;
+if (h->ps.sps && h->ignore_in_band_ps == 1) {
+av_log(h, AV_LOG_WARNING, "ignore in-band sps\n");
+break;
+}
 if (avctx->hwaccel && avctx->hwaccel->decode_params) {
 ret = avctx->hwaccel->decode_params(avctx,
 nal->type,
@@ -700,6 +704,10 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size)
 break;
 }
 case H264_NAL_PPS:
+if (h->ps.pps && h->ignore_in_band_ps == 1) {
+av_log(h, AV_LOG_WARNING, "ignore in-band pps\n");
+break;
+}
 if (avctx->hwaccel && avctx->hwaccel->decode_params) {
 ret = avctx->hwaccel->decode_params(avctx,
 nal->type,
@@ -726,6 +734,8 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size)
 }
 
 if (err < 0) {
+if (h->ignore_in_band_ps == -1)
+h->ignore_in_band_ps = 1;
 av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\n");
 }
 }
@@ -1011,8 +1021,12 @@ static int h264_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 
 buf_index = decode_nal_units(h, buf, buf_size);
-if (buf_index < 0)
+if (buf_index < 0) {
+/* If there is corrupted data, then don't trust the in-band ps. */
+if (h->ignore_in_band_ps == -1)
+h->ignore_in_band_ps = 1;
 return AVERROR_INVALIDDATA;
+}
 
 if (!h->cur_pic_ptr && h->nal_unit_type == H264_NAL_END_SEQUENCE) {
 av_assert0(buf_index <= buf_size);
@@ -1055,6 +1069,7 @@ static const AVOption h264_options[] = {
 { "nal_length_size", "nal_length_size", OFFSET(nal_length_size), 
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, VDX },
 { "enable_er", "Enable error resilience on damaged frames (unsafe)", 
OFFSET(enable_er), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD },
 { "x264_build", "Assume this x264 version if no x264 version found in any 
SEI", OFFSET(x264_build), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VD },
+{ "ignore_in_band_ps", "ignore in-band parameter set", 
OFFSET(ignore_in_band_ps), AV_OPT_TYPE_INT, {.i64 = 0}, -1, 1, VD },
 { NULL },
 };
 
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 8168c8e97b..760540bc9d 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -448,6 +448,7 @@ typedef struct H264Context {
 int bit_depth_luma; ///< luma bit depth from sps to detect changes
 int chroma_format_idc;  ///< chroma format from sps to detect changes
 
+int ignore_in_band_ps;
 H264ParamSets ps;
 
 uint16_t *slice_table_base;
-- 
2.31.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] avfilter: add dialog enhance audio filter

2022-02-06 Thread Paul B Mahol
On Sun, Feb 6, 2022 at 12:45 PM Gyan Doshi  wrote:

>
>
> On 2022-02-06 04:54 pm, Paul B Mahol wrote:
> > That will make two e.
>
> enhancedialogue
>
> I very dislike that approach.

I will use dialoguenhance


> Gyan
> ___
> 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] avfilter: add dialog enhance audio filter

2022-02-06 Thread Gyan Doshi




On 2022-02-06 04:54 pm, Paul B Mahol wrote:

That will make two e.


enhancedialogue

Gyan
___
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_atempo: switch to rdft from lavu/tx

2022-02-06 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 configure   |   3 -
 libavfilter/af_atempo.c | 126 
 2 files changed, 64 insertions(+), 65 deletions(-)

diff --git a/configure b/configure
index 5a8b52c77d..6ec25dd622 100755
--- a/configure
+++ b/configure
@@ -3610,8 +3610,6 @@ amovie_filter_deps="avcodec avformat"
 aresample_filter_deps="swresample"
 asr_filter_deps="pocketsphinx"
 ass_filter_deps="libass"
-atempo_filter_deps="avcodec"
-atempo_filter_select="rdft"
 avgblur_opencl_filter_deps="opencl"
 avgblur_vulkan_filter_deps="vulkan spirv_compiler"
 azmq_filter_deps="libzmq"
@@ -7387,7 +7385,6 @@ enabled zlib && add_cppflags -DZLIB_CONST
 # conditional library dependencies, in any order
 enabled amovie_filter   && prepend avfilter_deps "avformat avcodec"
 enabled aresample_filter&& prepend avfilter_deps "swresample"
-enabled atempo_filter   && prepend avfilter_deps "avcodec"
 enabled bm3d_filter && prepend avfilter_deps "avcodec"
 enabled cover_rect_filter   && prepend avfilter_deps "avformat avcodec"
 enabled ebur128_filter && enabled swresample && prepend avfilter_deps 
"swresample"
diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
index e9a6da7970..27f2f6daa0 100644
--- a/libavfilter/af_atempo.c
+++ b/libavfilter/af_atempo.c
@@ -39,13 +39,13 @@
  */
 
 #include 
-#include "libavcodec/avfft.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/eval.h"
 #include "libavutil/opt.h"
 #include "libavutil/samplefmt.h"
+#include "libavutil/tx.h"
 #include "avfilter.h"
 #include "audio.h"
 #include "internal.h"
@@ -67,7 +67,8 @@ typedef struct AudioFragment {
 
 // rDFT transform of the down-mixed mono fragment, used for
 // fast waveform alignment via correlation in frequency domain:
-FFTSample *xdat;
+float *xdat_in;
+float *xdat;
 } AudioFragment;
 
 /**
@@ -140,9 +141,11 @@ typedef struct ATempoContext {
 FilterState state;
 
 // for fast correlation calculation in frequency domain:
-RDFTContext *real_to_complex;
-RDFTContext *complex_to_real;
-FFTSample *correlation;
+AVTXContext *real_to_complex;
+AVTXContext *complex_to_real;
+av_tx_fn r2c_fn, c2r_fn;
+float *correlation_in;
+float *correlation;
 
 // for managing AVFilterPad.request_frame and AVFilterPad.filter_frame
 AVFrame *dst_buffer;
@@ -228,18 +231,18 @@ static void yae_release_buffers(ATempoContext *atempo)
 
 av_freep(>frag[0].data);
 av_freep(>frag[1].data);
+av_freep(>frag[0].xdat_in);
+av_freep(>frag[1].xdat_in);
 av_freep(>frag[0].xdat);
 av_freep(>frag[1].xdat);
 
 av_freep(>buffer);
 av_freep(>hann);
+av_freep(>correlation_in);
 av_freep(>correlation);
 
-av_rdft_end(atempo->real_to_complex);
-atempo->real_to_complex = NULL;
-
-av_rdft_end(atempo->complex_to_real);
-atempo->complex_to_real = NULL;
+av_tx_uninit(>real_to_complex);
+av_tx_uninit(>complex_to_real);
 }
 
 /* av_realloc is not aligned enough; fortunately, the data does not need to
@@ -247,7 +250,7 @@ static void yae_release_buffers(ATempoContext *atempo)
 #define RE_MALLOC_OR_FAIL(field, field_size)\
 do {\
 av_freep();   \
-field = av_malloc(field_size);  \
+field = av_calloc(field_size, 1);   \
 if (!field) {   \
 yae_release_buffers(atempo);\
 return AVERROR(ENOMEM); \
@@ -265,6 +268,7 @@ static int yae_reset(ATempoContext *atempo,
 {
 const int sample_size = av_get_bytes_per_sample(format);
 uint32_t nlevels  = 0;
+float scale = 1.f, iscale = 1.f;
 uint32_t pot;
 int i;
 
@@ -288,29 +292,29 @@ static int yae_reset(ATempoContext *atempo,
 // initialize audio fragment buffers:
 RE_MALLOC_OR_FAIL(atempo->frag[0].data, atempo->window * atempo->stride);
 RE_MALLOC_OR_FAIL(atempo->frag[1].data, atempo->window * atempo->stride);
-RE_MALLOC_OR_FAIL(atempo->frag[0].xdat, atempo->window * 
sizeof(FFTComplex));
-RE_MALLOC_OR_FAIL(atempo->frag[1].xdat, atempo->window * 
sizeof(FFTComplex));
+RE_MALLOC_OR_FAIL(atempo->frag[0].xdat_in, (atempo->window + 1) * 
sizeof(AVComplexFloat));
+RE_MALLOC_OR_FAIL(atempo->frag[1].xdat_in, (atempo->window + 1) * 
sizeof(AVComplexFloat));
+RE_MALLOC_OR_FAIL(atempo->frag[0].xdat, (atempo->window + 1) * 
sizeof(AVComplexFloat));
+RE_MALLOC_OR_FAIL(atempo->frag[1].xdat, (atempo->window + 1) * 
sizeof(AVComplexFloat));
 
 // initialize rDFT contexts:
-av_rdft_end(atempo->real_to_complex);
-atempo->real_to_complex = NULL;
-
-av_rdft_end(atempo->complex_to_real);
-atempo->complex_to_real = NULL;
+

Re: [FFmpeg-devel] [PATCH] avfilter: add dialog enhance audio filter

2022-02-06 Thread Paul B Mahol
That will make two e.
___
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 dialog enhance audio filter

2022-02-06 Thread Gyan Doshi




On 2022-02-06 03:55 pm, Paul B Mahol wrote:

Signed-off-by: Paul B Mahol 
---
  doc/filters.texi   |  24 ++
  libavfilter/Makefile   |   1 +
  libavfilter/af_dialogenhance.c | 409 +
  libavfilter/allfilters.c   |   1 +
  4 files changed, 435 insertions(+)
  create mode 100644 libavfilter/af_dialogenhance.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 04c34cb1fb..5ba9a35673 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4178,6 +4178,30 @@ Default value is @var{o}.
  
  @end table
  
+@section dialogenhance

s/dialog/dialogue

dialog is archaic for conversation, even in American English.

https://books.google.com/ngrams/graph?content=dialog+with%2C+dialogue+with_start=1800_end=2000=5=3_url=t1%3B%2Cdialog%20with%3B%2Cc0%3B.t1%3B%2Cdialogue%20with%3B%2Cc0#t1%3B%2Cdialog%20with%3B%2Cc0%3B.t1%3B%2Cdialogue%20with%3B%2Cc0

Regards,
Gyan
___
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: add dialog enhance audio filter

2022-02-06 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi   |  24 ++
 libavfilter/Makefile   |   1 +
 libavfilter/af_dialogenhance.c | 409 +
 libavfilter/allfilters.c   |   1 +
 4 files changed, 435 insertions(+)
 create mode 100644 libavfilter/af_dialogenhance.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 04c34cb1fb..5ba9a35673 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4178,6 +4178,30 @@ Default value is @var{o}.
 
 @end table
 
+@section dialogenhance
+Enhance dialog in stereo audio.
+
+This filter accepts stereo input and produce surround (3.0) channels output.
+The newly produced front center channel have enhanced speech dialog originally
+available in both stereo channels.
+This filter outputs front left and front right channels same as available in 
stereo input.
+
+The filter accepts the following options:
+
+@table @option
+@item original
+Set the original center factor to keep in front center channel output.
+Allowed range is from 0 to 1. Default value is 1.
+
+@item enhance
+Set the dialog enhance factor to put in front center channel output.
+Allowed range is from 0 to 3. Default value is 1.
+@end table
+
+@subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @section drmeter
 Measure audio dynamic range.
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 282967144b..c4dfb9a41b 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -124,6 +124,7 @@ OBJS-$(CONFIG_CROSSFEED_FILTER)  += 
af_crossfeed.o
 OBJS-$(CONFIG_CRYSTALIZER_FILTER)+= af_crystalizer.o
 OBJS-$(CONFIG_DCSHIFT_FILTER)+= af_dcshift.o
 OBJS-$(CONFIG_DEESSER_FILTER)+= af_deesser.o
+OBJS-$(CONFIG_DIALOGENHANCE_FILTER)  += af_dialogenhance.o
 OBJS-$(CONFIG_DRMETER_FILTER)+= af_drmeter.o
 OBJS-$(CONFIG_DYNAUDNORM_FILTER) += af_dynaudnorm.o
 OBJS-$(CONFIG_EARWAX_FILTER) += af_earwax.o
diff --git a/libavfilter/af_dialogenhance.c b/libavfilter/af_dialogenhance.c
new file mode 100644
index 00..2f259fcd1d
--- /dev/null
+++ b/libavfilter/af_dialogenhance.c
@@ -0,0 +1,409 @@
+/*
+ * Copyright (c) 2022 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/channel_layout.h"
+#include "libavutil/opt.h"
+#include "libavutil/tx.h"
+#include "audio.h"
+#include "avfilter.h"
+#include "filters.h"
+#include "internal.h"
+#include "window_func.h"
+
+#include 
+
+typedef struct AudioDialogEnhanceContext {
+const AVClass *class;
+
+double original, enhance;
+
+int fft_size;
+int overlap;
+
+float *window;
+float prev_vad;
+
+AVFrame *in;
+AVFrame *in_frame;
+AVFrame *out_dist_frame;
+AVFrame *windowed_frame;
+AVFrame *windowed_out;
+AVFrame *windowed_prev;
+AVFrame *center_frame;
+
+AVTXContext *tx_ctx[2], *itx_ctx;
+av_tx_fn tx_fn, itx_fn;
+} AudioDialogEnhanceContext;
+
+#define OFFSET(x) offsetof(AudioDialogEnhanceContext, x)
+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | 
AV_OPT_FLAG_RUNTIME_PARAM
+
+static const AVOption dialogenhance_options[] = {
+{ "original", "set original center factor", OFFSET(original), 
AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
+{ "enhance",  "set dialog enhance factor",  OFFSET(enhance),  
AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 3, FLAGS },
+{NULL}
+};
+
+AVFILTER_DEFINE_CLASS(dialogenhance);
+
+static int query_formats(AVFilterContext *ctx)
+{
+AVFilterFormats *formats = NULL;
+AVFilterChannelLayouts *in_layout = NULL, *out_layout = NULL;
+int ret;
+
+if ((ret = ff_add_format (, AV_SAMPLE_FMT_FLTP )) 
< 0 ||
+(ret = ff_set_common_formats (ctx , formats)) 
< 0 ||
+(ret = ff_add_channel_layout (_layout , 
AV_CH_LAYOUT_STEREO)) < 0 ||
+(ret = ff_channel_layouts_ref(in_layout, 
>inputs[0]->outcfg.channel_layouts)) < 0 ||
+(ret = ff_add_channel_layout (_layout , 
AV_CH_LAYOUT_SURROUND)) < 0 ||
+(ret = ff_channel_layouts_ref(out_layout, 
>outputs[0]->incfg.channel_layouts)) < 0)
+return ret;
+
+return 

[FFmpeg-devel] [PATCH v3] mpegvideo_parser: check picture_structure for field order

2022-02-06 Thread Tom Yan
the top_field_first bit is only used to indicate the field order
when the picture is a frame picture (which consists of two fields)
but not when it is a field picture (which consists of one single
top or bottom field).

Signed-off-by: Tom Yan 
---
 libavcodec/mpegvideo_parser.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index c5dc867d24..26f3aac9da 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -181,6 +181,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext 
*s,
 break;
 case 0x8: /* picture coding extension */
 if (bytes_left >= 5) {
+s->picture_structure = buf[2] & 0x3;
 top_field_first = buf[3] & (1 << 7);
 repeat_first_field = buf[3] & (1 << 1);
 progressive_frame = buf[4] & (1 << 7);
@@ -198,13 +199,15 @@ static void 
mpegvideo_extract_headers(AVCodecParserContext *s,
 }
 }
 
-if (!pc->progressive_sequence && !progressive_frame) {
-if (top_field_first)
-s->field_order = AV_FIELD_TT;
-else
-s->field_order = AV_FIELD_BB;
-} else
+/* picture_structure > progressive bits > 
top_field_first */
+if (s->picture_structure == 
AV_PICTURE_STRUCTURE_TOP_FIELD)
+s->field_order = AV_FIELD_TT;
+else if (s->picture_structure == 
AV_PICTURE_STRUCTURE_BOTTOM_FIELD)
+s->field_order = AV_FIELD_BB;
+else if (pc->progressive_sequence || progressive_frame)
 s->field_order = AV_FIELD_PROGRESSIVE;
+else
+s->field_order = top_field_first ? AV_FIELD_TT : 
AV_FIELD_BB;
 }
 break;
 }
-- 
2.35.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] Libera.chat irc logs

2022-02-06 Thread Andreas Rheinhardt
Gyan Doshi:
> 
> In our documentation, we state
> 
> 'Our IRC channels are publically logged and archives of both channels
> can be viewed at ffmpeg-devel-irc.'
> 
> However, the archives in the link end with June 2020 i.e. at the time of
> the Libera switchover. The topic for #ffmpeg-devel at Libera does
> include "This channel is publicly logged".
> 
> Where do we host logs for chats on Libera?
> 
> Regards,
> Gyan

The logs stopped way before the libera switchover (which was only in
2021, not June 2020). There were issues even before then.

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

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


[FFmpeg-devel] Libera.chat irc logs

2022-02-06 Thread Gyan Doshi



In our documentation, we state

'Our IRC channels are publically logged and archives of both channels 
can be viewed at ffmpeg-devel-irc.'


However, the archives in the link end with June 2020 i.e. at the time of 
the Libera switchover. The topic for #ffmpeg-devel at Libera does 
include "This channel is publicly logged".


Where do we host logs for chats on Libera?

Regards,
Gyan
___
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] mpegvideo_parser: check picture_structure for field order

2022-02-06 Thread Tom Yan
This is really just a matter of choice. If you don't care about
spec-conformance in this particular case, top_field_first *could* be 1
and/or picture_structure *could* be not 3 even when
progressive_sequence is 1, so which one do you choose to believe? The
truth is, it doesn't even matter.

If you insist on making it more clumsy and silly, I can resend.

On Sun, 6 Feb 2022 at 13:46, Andreas Rheinhardt
 wrote:
>
> Tom Yan:
> > the top_field_first bit is only used to indicate the field order
> > when the picture is a frame picture (which consists of two fields)
> > but not when it is a field picture (which consists of one single
> > top or bottom field).
> >
> > also removing the unnecessary progressive_sequence check (the bit
> > is mandated to be 0 if progressive_frame is 0 on any picture in the
> > sequence).
> >
>
> Just because something is mandated does not mean that it is so;
> spec-incompliant files exist.
>
> > Signed-off-by: Tom Yan 
> > ---
> >  libavcodec/mpegvideo_parser.c | 15 +--
> >  1 file changed, 9 insertions(+), 6 deletions(-)
> >
> > diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
> > index c5dc867d24..004ff602f6 100644
> > --- a/libavcodec/mpegvideo_parser.c
> > +++ b/libavcodec/mpegvideo_parser.c
> > @@ -181,6 +181,7 @@ static void 
> > mpegvideo_extract_headers(AVCodecParserContext *s,
> >  break;
> >  case 0x8: /* picture coding extension */
> >  if (bytes_left >= 5) {
> > +s->picture_structure = buf[2] & 0x3;
> >  top_field_first = buf[3] & (1 << 7);
> >  repeat_first_field = buf[3] & (1 << 1);
> >  progressive_frame = buf[4] & (1 << 7);
> > @@ -198,13 +199,15 @@ static void 
> > mpegvideo_extract_headers(AVCodecParserContext *s,
> >  }
> >  }
> >
> > -if (!pc->progressive_sequence && 
> > !progressive_frame) {
> > -if (top_field_first)
> > -s->field_order = AV_FIELD_TT;
> > -else
> > -s->field_order = AV_FIELD_BB;
> > -} else
> > +if (progressive_frame)
> >  s->field_order = AV_FIELD_PROGRESSIVE;
> > +else if (top_field_first ||
> > + /* top_field_first is mandated to be 0 
> > when
> > +the picture is not a frame picture) */
> > + s->picture_structure == 
> > AV_PICTURE_STRUCTURE_TOP_FIELD)
> > +s->field_order = AV_FIELD_TT;
> > +else
> > +s->field_order = AV_FIELD_BB;
> >  }
> >  break;
> >  }
>
> ___
> 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".