[FFmpeg-devel] [PATCH] riscv: Fix linking without RVV; change #ifdef into #if

2022-09-28 Thread Martin Storsjö
---
This should hopefully fix the current build failures at
http://fate.ffmpeg.org/history.cgi?slot=riscv64-linux-gnu-clang-14.
---
 libavcodec/riscv/fmtconvert_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/riscv/fmtconvert_init.c 
b/libavcodec/riscv/fmtconvert_init.c
index fd1a8e0ca1..2ded9d3615 100644
--- a/libavcodec/riscv/fmtconvert_init.c
+++ b/libavcodec/riscv/fmtconvert_init.c
@@ -33,7 +33,7 @@ void ff_int32_to_float_fmul_array8_rvv(FmtConvertContext *c, 
float *dst,
 
 av_cold void ff_fmt_convert_init_riscv(FmtConvertContext *c)
 {
-#ifdef HAVE_RVV
+#if HAVE_RVV
 int flags = av_get_cpu_flags();
 
 if (flags & AV_CPU_FLAG_RVV_F32) {
-- 
2.37.0 (Apple Git-136)

___
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 0/3] RISC-V V swscale pixel format conversions

2022-09-28 Thread Lynne
Sep 28, 2022, 17:29 by r...@remlab.net:

> Hello,
>
> This adds the pixel format conversions that appear to covered by checkasm
> (plus YUYV to I422 for which a patch was sent already).
>
> RVV has no register-register interleaving/deinterleaving instructions, so this
> uses strided loads or stores instead. Another option would be full register 
> move then segmented store, but that is presumably slower.
>
> The following changes since commit d31013166ac3727ae7c7ebbb756e1e5800bc2b40:
>
>  lavc/pixblockdsp: RISC-V diff_pixels & diff_pixels_unaligned (2022-09-28 
> 11:46:11 +0200)
>
> are available in the Git repository at:
>
>  git.remlab.net:git/ffmpeg.git rvv-swscale
>
> for you to fetch changes up to 18edd2c3108b126fc478635ac1048db60b9d7fc4:
>
>  sws/rgb2rgb: RISC-V 64-bit V packed YUYV/UYVY to planar 4:2:2 (2022-09-28 
> 18:23:53 +0300)
>
> 
> Rémi Denis-Courmont (3):
>  sws/rgb2rgb: RISC-V V shuffle_bytes_ functions
>  sws/rgb2rgb: RISC-V V interleaveBytes
>  sws/rgb2rgb: RISC-V 64-bit V packed YUYV/UYVY to planar 4:2:2
>
>  libswscale/rgb2rgb.c   |   2 +
>  libswscale/rgb2rgb.h   |   1 +
>  libswscale/riscv/Makefile  |   2 +
>  libswscale/riscv/rgb2rgb.c |  61 
>  libswscale/riscv/rgb2rgb_rvv.S | 157 
> +
>  5 files changed, 223 insertions(+)
>  create mode 100644 libswscale/riscv/Makefile
>  create mode 100644 libswscale/riscv/rgb2rgb.c
>  create mode 100644 libswscale/riscv/rgb2rgb_rvv.S
>

Patchset looks good. Will apply in a couple of hours.

___
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/pngdec: Don't use unsigned for width, height

2022-09-28 Thread Andreas Rheinhardt
Otherwise p->linesize[0] * y will be evaluated as an unsigned
which leads to segfaults in case linesize is negative.
This happens in the apng-dispose-previous FATE-test in case
one makes get_buffer return pictures with negative linesizes.

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

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 582953d17b..3c3eca601e 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1387,7 +1387,7 @@ exit_loop:
 if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE) {
 size_t byte_depth = s->bit_depth > 8 ? 2 : 1;
 size_t raw_bpp = s->bpp - byte_depth;
-unsigned x, y;
+ptrdiff_t x, y;
 
 av_assert0(s->bit_depth > 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".


Re: [FFmpeg-devel] [PATCH 1/2] avformat/vividas: Check packet size

2022-09-28 Thread Michael Niedermayer
On Wed, Sep 28, 2022 at 05:16:05PM +0200, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2022-09-22 20:08:51)
> > Fixes: signed integer overflow: 119760682 - -2084600173 cannot be 
> > represented in type 'int'
> > Fixes: 
> > 50993/clusterfuzz-testcase-minimized-ffmpeg_dem_VIVIDAS_fuzzer-6745781167587328
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/vividas.c | 13 +++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavformat/vividas.c b/libavformat/vividas.c
> > index e9954f73ed0..e8efe49a5c0 100644
> > --- a/libavformat/vividas.c
> > +++ b/libavformat/vividas.c
> > @@ -683,6 +683,7 @@ static int viv_read_packet(AVFormatContext *s,
> >  
> >  if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
> >  uint64_t v_size = ffio_read_varlen(pb);
> > +int last, last_start;
> >  
> >  if (!viv->num_audio)
> >  return AVERROR_INVALIDDATA;
> > @@ -704,14 +705,22 @@ static int viv_read_packet(AVFormatContext *s,
> >  start = ffio_read_varlen(pb);
> >  pcm_bytes = ffio_read_varlen(pb);
> >  
> > -if (i > 0 && start == 0)
> > -break;
> > +if (i > 0) {
> > +if (start == 0)
> > +break;
> > +if (start < last || start - (unsigned)last > INT_MAX)
> 
> What is the second condition for?

start is signed int so are "copyies" of it
"start < last" would allow a negative last with a large start
the 2nd check handles that.
the difference of consequtive values are stored as int later

The patch tried to leave the storage types and check for it.
The types could be changed or some other checks could be used
I was undecided on this patch a bit too. I picked this mainly
to keep changes more minimal but maybe this was not the best
choice

Thx


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

No great genius has ever existed without some touch of madness. -- Aristotle


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

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


Re: [FFmpeg-devel] [PATCH] avcodec/ac3dsp: Remove unused parameter

2022-09-28 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Forgotten in fd98594a8831ce037a495b6d7e090bd8f81e83a1.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/ac3dec.c  | 2 +-
>  libavcodec/ac3dsp.c  | 8 
>  libavcodec/ac3dsp.h  | 8 
>  libavcodec/ac3enc.c  | 2 +-
>  libavcodec/arm/ac3dsp_init_arm.c | 2 +-
>  libavcodec/mips/ac3dsp_mips.c| 3 ++-
>  libavcodec/x86/ac3dsp_init.c | 2 +-
>  7 files changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
> index aba8e0fb7f..340f6e1e37 100644
> --- a/libavcodec/ac3dec.c
> +++ b/libavcodec/ac3dec.c
> @@ -236,7 +236,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
>  if (!s->fdsp)
>  return AVERROR(ENOMEM);
>  
> -ff_ac3dsp_init(&s->ac3dsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
> +ff_ac3dsp_init(&s->ac3dsp);
>  av_lfg_init(&s->dith_state, 0);
>  
>  if (USE_FIXED)
> diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c
> index afd6b557bf..22cb5f242e 100644
> --- a/libavcodec/ac3dsp.c
> +++ b/libavcodec/ac3dsp.c
> @@ -374,7 +374,7 @@ void ff_ac3dsp_downmix(AC3DSPContext *c, float **samples, 
> float **matrix,
>  ac3_downmix_c(samples, matrix, out_ch, in_ch, len);
>  }
>  
> -av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
> +av_cold void ff_ac3dsp_init(AC3DSPContext *c)
>  {
>  c->ac3_exponent_min = ac3_exponent_min_c;
>  c->float_to_fixed24 = float_to_fixed24_c;
> @@ -390,10 +390,10 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int 
> bit_exact)
>  c->downmix_fixed = NULL;
>  
>  #if ARCH_ARM
> -ff_ac3dsp_init_arm(c, bit_exact);
> +ff_ac3dsp_init_arm(c);
>  #elif ARCH_X86
> -ff_ac3dsp_init_x86(c, bit_exact);
> +ff_ac3dsp_init_x86(c);
>  #elif ARCH_MIPS
> -ff_ac3dsp_init_mips(c, bit_exact);
> +ff_ac3dsp_init_mips(c);
>  #endif
>  }
> diff --git a/libavcodec/ac3dsp.h b/libavcodec/ac3dsp.h
> index a23b11526e..33e51e202e 100644
> --- a/libavcodec/ac3dsp.h
> +++ b/libavcodec/ac3dsp.h
> @@ -105,10 +105,10 @@ typedef struct AC3DSPContext {
>  void (*downmix_fixed)(int32_t **samples, int16_t **matrix, int len);
>  } AC3DSPContext;
>  
> -void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact);
> -void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact);
> -void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact);
> -void ff_ac3dsp_init_mips(AC3DSPContext *c, int bit_exact);
> +void ff_ac3dsp_init(AC3DSPContext *c);
> +void ff_ac3dsp_init_arm(AC3DSPContext *c);
> +void ff_ac3dsp_init_x86(AC3DSPContext *c);
> +void ff_ac3dsp_init_mips(AC3DSPContext *c);
>  
>  void ff_ac3dsp_downmix(AC3DSPContext *c, float **samples, float **matrix,
> int out_ch, int in_ch, int len);
> diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
> index a090576823..279dd5c20e 100644
> --- a/libavcodec/ac3enc.c
> +++ b/libavcodec/ac3enc.c
> @@ -2613,7 +2613,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
>  
>  ff_audiodsp_init(&s->adsp);
>  ff_me_cmp_init(&s->mecc, avctx);
> -ff_ac3dsp_init(&s->ac3dsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
> +ff_ac3dsp_init(&s->ac3dsp);
>  
>  dprint_options(s);
>  
> diff --git a/libavcodec/arm/ac3dsp_init_arm.c 
> b/libavcodec/arm/ac3dsp_init_arm.c
> index 9217a7d0c2..a64aa6ae82 100644
> --- a/libavcodec/arm/ac3dsp_init_arm.c
> +++ b/libavcodec/arm/ac3dsp_init_arm.c
> @@ -44,7 +44,7 @@ void ff_ac3_bit_alloc_calc_bap_armv6(int16_t *mask, int16_t 
> *psd,
>  
>  void ff_ac3_update_bap_counts_arm(uint16_t mant_cnt[16], uint8_t *bap, int 
> len);
>  
> -av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact)
> +av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c)
>  {
>  int cpu_flags = av_get_cpu_flags();
>  
> diff --git a/libavcodec/mips/ac3dsp_mips.c b/libavcodec/mips/ac3dsp_mips.c
> index 8f62c03aaf..a5eaaf8eb2 100644
> --- a/libavcodec/mips/ac3dsp_mips.c
> +++ b/libavcodec/mips/ac3dsp_mips.c
> @@ -401,7 +401,8 @@ static void ac3_downmix_mips(float **samples, float 
> (*matrix)[2],
>  #endif /* HAVE_MIPSFPU */
>  #endif /* HAVE_INLINE_ASM */
>  
> -void ff_ac3dsp_init_mips(AC3DSPContext *c, int bit_exact) {
> +void ff_ac3dsp_init_mips(AC3DSPContext *c)
> +{
>  #if HAVE_INLINE_ASM
>  #if HAVE_MIPSDSP
>  c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_mips;
> diff --git a/libavcodec/x86/ac3dsp_init.c b/libavcodec/x86/ac3dsp_init.c
> index 75a341bc95..43b3b4ac85 100644
> --- a/libavcodec/x86/ac3dsp_init.c
> +++ b/libavcodec/x86/ac3dsp_init.c
> @@ -33,7 +33,7 @@ int ff_ac3_compute_mantissa_size_sse2(uint16_t 
> mant_cnt[6][16]);
>  void ff_ac3_extract_exponents_sse2 (uint8_t *exp, int32_t *coef, int 
> nb_coefs);
>  void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int 
> nb_coefs);
>  
> -av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
> +av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c)
>  {
>  int cpu_flags = av_get_cpu_flags();
>  

Will app

Re: [FFmpeg-devel] [PATCH 3/6] avformat/aviobuf: Don't use NULL as src for memcpy

2022-09-28 Thread Andreas Rheinhardt
James Almer:
> On 9/28/2022 3:58 PM, Andreas Rheinhardt wrote:
>> This might happen in avio_write() if size == 0
>> when the direct codepath is taken. It is undefined behaviour
>> according to the spec although it happens to work in practice.
>> Fixes the webm-webvtt-remux FATE-test under UBSan.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>   libavformat/aviobuf.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
>> index b20b1a611a..5b6a42d7f4 100644
>> --- a/libavformat/aviobuf.c
>> +++ b/libavformat/aviobuf.c
>> @@ -231,6 +231,8 @@ void ffio_fill(AVIOContext *s, int b, int64_t count)
>>     void avio_write(AVIOContext *s, const unsigned char *buf, int size)
>>   {
>> +    if (size <= 0)
>> +    return;
>>   if (s->direct && !s->update_checksum) {
>>   avio_flush(s);
>>   writeout(s, buf, size);
>> @@ -246,7 +248,7 @@ void avio_write(AVIOContext *s, const unsigned
>> char *buf, int size)
>>     buf += len;
>>   size -= len;
>> -    }
>> +    } while (size > 0);
> 
> Why are you adding this at the end of a similar while statement? Did you
> mean to replace the previous one with do()?
> 

Yes, exactly. Somehow I didn't. fate passed locally (apart from the
tdsc). Crazy that I forgot this. Thanks for spotting.

- 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 3/6] avformat/aviobuf: Don't use NULL as src for memcpy

2022-09-28 Thread James Almer

On 9/28/2022 3:58 PM, Andreas Rheinhardt wrote:

This might happen in avio_write() if size == 0
when the direct codepath is taken. It is undefined behaviour
according to the spec although it happens to work in practice.
Fixes the webm-webvtt-remux FATE-test under UBSan.

Signed-off-by: Andreas Rheinhardt 
---
  libavformat/aviobuf.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index b20b1a611a..5b6a42d7f4 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -231,6 +231,8 @@ void ffio_fill(AVIOContext *s, int b, int64_t count)
  
  void avio_write(AVIOContext *s, const unsigned char *buf, int size)

  {
+if (size <= 0)
+return;
  if (s->direct && !s->update_checksum) {
  avio_flush(s);
  writeout(s, buf, size);
@@ -246,7 +248,7 @@ void avio_write(AVIOContext *s, const unsigned char *buf, 
int size)
  
  buf += len;

  size -= len;
-}
+} while (size > 0);


Why are you adding this at the end of a similar while statement? Did you 
mean to replace the previous one with do()?



  }
  
  void avio_flush(AVIOContext *s)

___
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] swscale/swscale_unscaled: Fix undefined NULL + 0

2022-09-28 Thread Michael Niedermayer
On Wed, Sep 28, 2022 at 09:43:56PM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Wed, Sep 28, 2022 at 08:39:09PM +0200, Andreas Rheinhardt wrote:
> >> Affected the fitsdec-gbrp16 FATE-test.
> >>
> >> Signed-off-by: Andreas Rheinhardt 
> >> ---
> >>  libswscale/swscale_unscaled.c | 6 +++---
> >>  1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
> >> index 8838cc8b53..0b97377934 100644
> >> --- a/libswscale/swscale_unscaled.c
> >> +++ b/libswscale/swscale_unscaled.c
> >> @@ -695,7 +695,7 @@ static void packed16togbra16(const uint8_t *src, int 
> >> srcStride,
> >>  }
> >>  }
> >>  for (i = 0; i < 4; i++)
> >> -dst[i] += dstStride[i] >> 1;
> >> +dst[i] = FF_PTR_ADD(dst[i], dstStride[i] >> 1);
> >>  }
> >>  }
> >>  
> >> @@ -729,8 +729,8 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsContext *c, 
> >> const uint8_t *src[],
> >>  }
> >>  
> >>  for(i=0; i<4; i++) {
> >> -dst2013[i] += stride2013[i] * srcSliceY / 2;
> >> -dst1023[i] += stride1023[i] * srcSliceY / 2;
> >> +dst2013[i] = FF_PTR_ADD(dst2013[i], stride2013[i] * srcSliceY / 
> >> 2);
> >> +dst1023[i] = FF_PTR_ADD(dst1023[i], stride1023[i] * srcSliceY / 
> >> 2);
> >>  }
> > 
> > is there a reason not to check the pointer in the loop ?
> > as in
> > for (i = 0; i < 4 && dst[i]; i++)
> > 
> 
> I consider NULL + 0 to be sane and would be happy to see it being
> defined in a future version of the spec. 

i agree but that will not help our code for a long time


> So I don't like adding checks
> to workaround the insanities of the spec. 

Ive seen this less as a workaround and more as a "only work on
the active/used pointers"
a dst[i] check is more used elsewhere in sws too
but i really dont have much of an oppinon

libswscale/slice.c:for (i = 0; i < 4 && src[i] != NULL; ++i) {
libswscale/swscale.c:for (i = 0; i < 4 && src2[i]; i++) {
libswscale/swscale.c:for (i = 0; i < 4 && dst2[i]; i++) {
libswscale/swscale_unscaled.c:for (plane = 0; plane < 4 && dst[plane] != 
NULL; plane++) {
libswscale/tests/swscale.c:for (i = 0; i < 4 && dstStride[i]; i++)
libswscale/swscale.c:for (int i = 0; i < FF_ARRAY_ELEMS(dst) && 
parent->frame_dst->data[i]; i++) {

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Observe your enemies, for they first find out your faults. -- Antisthenes


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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavc/encode: make sure frame timebase matches encoder, when set

2022-09-28 Thread Marton Balint




On Wed, 28 Sep 2022, Anton Khirnov wrote:


AVFrame.time_base has been added recently, but is currently not used for
anything. Prepare for its use in encoders by rejecting frames where
time_base is set, but differs from the AVCodecContext one.


How is that not an API break? Users can encode AVFrames with anything in 
the AVFrame->time_base right now, if you change that behaviour, that will 
surely break some code. That is why it was explicitly documented that 
it will be ignored by encoders by default.


It is the second time people make this mistake, and it is exactly this 
confusion why I was hesitant to accept adding the time base to AVFrame.


Regards,
Marton


---
libavcodec/avcodec.h | 4 
libavcodec/encode.c  | 8 
libavutil/frame.h| 5 +++--
3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7365eb5cc0..4030675d4f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2645,6 +2645,10 @@ int avcodec_receive_frame(AVCodecContext *avctx, AVFrame 
*frame);
 *  packets are ignored, and sending frames will return
 *  AVERROR_EOF.
 *
+ *  frame->time_base should be set to the same value as
+ *  avctx->time_base. This is not required yet, but may be in
+ *  the future.
+ *
 *  For audio:
 *  If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
 *  can have any number of samples.
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index b275344bd1..0f78012747 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -386,6 +386,14 @@ static int encode_send_frame_internal(AVCodecContext 
*avctx, const AVFrame *src)
AVFrame *dst = avci->buffer_frame;
int ret;

+/* make sure the frame's timebase (if set) matches the encoder one */
+if (src->time_base.num &&
+(src->time_base.num != avctx->time_base.num ||
+ src->time_base.den != avctx->time_base.den)) {
+av_log(avctx, AV_LOG_ERROR, "Mismatching frame/encoder time base\n");
+return AVERROR(EINVAL);
+}
+
if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
/* extract audio service type metadata */
AVFrameSideData *sd = av_frame_get_side_data(src, 
AV_FRAME_DATA_AUDIO_SERVICE_TYPE);
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 6d9563bc5d..c5e2de85b3 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -441,8 +441,9 @@ typedef struct AVFrame {
/**
 * Time base for the timestamps in this frame.
 * In the future, this field may be set on frames output by decoders or
- * filters, but its value will be by default ignored on input to encoders
- * or filters.
+ * filters; its value will be by default ignored on input to filters.
+ * For frames sent to encoders, it should be set by the user to the same
+ * value as AVCodecContext.time_base.
 */
AVRational time_base;

--
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".


___
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] swscale/swscale_unscaled: Fix undefined NULL + 0

2022-09-28 Thread Andreas Rheinhardt
Michael Niedermayer:
> On Wed, Sep 28, 2022 at 08:39:09PM +0200, Andreas Rheinhardt wrote:
>> Affected the fitsdec-gbrp16 FATE-test.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>  libswscale/swscale_unscaled.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
>> index 8838cc8b53..0b97377934 100644
>> --- a/libswscale/swscale_unscaled.c
>> +++ b/libswscale/swscale_unscaled.c
>> @@ -695,7 +695,7 @@ static void packed16togbra16(const uint8_t *src, int 
>> srcStride,
>>  }
>>  }
>>  for (i = 0; i < 4; i++)
>> -dst[i] += dstStride[i] >> 1;
>> +dst[i] = FF_PTR_ADD(dst[i], dstStride[i] >> 1);
>>  }
>>  }
>>  
>> @@ -729,8 +729,8 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsContext *c, 
>> const uint8_t *src[],
>>  }
>>  
>>  for(i=0; i<4; i++) {
>> -dst2013[i] += stride2013[i] * srcSliceY / 2;
>> -dst1023[i] += stride1023[i] * srcSliceY / 2;
>> +dst2013[i] = FF_PTR_ADD(dst2013[i], stride2013[i] * srcSliceY / 2);
>> +dst1023[i] = FF_PTR_ADD(dst1023[i], stride1023[i] * srcSliceY / 2);
>>  }
> 
> is there a reason not to check the pointer in the loop ?
> as in
> for (i = 0; i < 4 && dst[i]; i++)
> 

I consider NULL + 0 to be sane and would be happy to see it being
defined in a future version of the spec. So I don't like adding checks
to workaround the insanities of the spec. Notice that FF_PTR_ADD() is
designed to allow the compiler to optimize the check away.

- 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] avformat/mpegtsenc: add pcr_at_keyframe flag

2022-09-28 Thread Marton Balint




On Wed, 28 Sep 2022, Zhao Zhili wrote:


From: Zhao Zhili 

Add PCR at keyframe can be undesirable when -pcr_period is
specified. Add an flag to disable this behavior.


Actually you are disabling the writing of random access indicators, not 
only PCRs. PCR's are just there because it is mandatory when RAI is set 
for PCR pids. In the help text you can mention that it affects writing of 
PCR as well, but in principle you disable RAI, so the option name should 
reflect that instead. Also I kind of prefer not to change the default of 
mpegts_flags from zero, use a negative option instead, like "omit_rai".


Thanks,
Marton




Signed-off-by: Zhao Zhili 
---
doc/muxers.texi | 2 ++
libavformat/mpegtsenc.c | 8 ++--
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index b2f4326aae..0f576d8096 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1915,6 +1915,8 @@ Conform to System B (DVB) instead of System A (ATSC).
Mark the initial packet of each stream as discontinuity.
@item nit
Emit NIT table.
+@item pcr_at_keyframe
+Write PCR at key frame.
@end table

@item mpegts_copyts @var{boolean}
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 5148a6aecd..808d2c04a2 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -112,6 +112,7 @@ typedef struct MpegTSWrite {
#define MPEGTS_FLAG_SYSTEM_B0x08
#define MPEGTS_FLAG_DISCONT 0x10
#define MPEGTS_FLAG_NIT 0x20
+#define MPEGTS_FLAG_PCR_AT_KEYFRAME 0x40
int flags;
int copyts;
int tables_version;
@@ -1566,7 +1567,8 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream 
*st,
q = get_ts_payload_start(buf);
ts_st->discontinuity = 0;
}
-if (key && is_start && pts != AV_NOPTS_VALUE &&
+if ((ts->flags & MPEGTS_FLAG_PCR_AT_KEYFRAME) &&
+key && is_start && pts != AV_NOPTS_VALUE &&
!is_dvb_teletext /* adaptation+payload forbidden for teletext (ETSI 
EN 300 472 V1.3.1 4.1) */) {
// set Random Access for key frames
if (ts_st->pcr_period)
@@ -2269,7 +2271,7 @@ static const AVOption options[] = {
{ "muxrate", NULL, OFFSET(mux_rate), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 
INT_MAX, ENC },
{ "pes_payload_size", "Minimum PES packet payload in bytes",
  OFFSET(pes_payload_size), AV_OPT_TYPE_INT, { .i64 = 
DEFAULT_PES_PAYLOAD_SIZE }, 0, INT_MAX, ENC },
-{ "mpegts_flags", "MPEG-TS muxing flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 
0 }, 0, INT_MAX, ENC, "mpegts_flags" },
+{ "mpegts_flags", "MPEG-TS muxing flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 
MPEGTS_FLAG_PCR_AT_KEYFRAME }, 0, INT_MAX, ENC, "mpegts_flags" },
{ "resend_headers", "Reemit PAT/PMT before writing the next packet",
  0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_FLAG_REEMIT_PAT_PMT }, 0, INT_MAX, ENC, 
"mpegts_flags" },
{ "latm", "Use LATM packetization for AAC",
@@ -2282,6 +2284,8 @@ static const AVOption options[] = {
  0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_FLAG_DISCONT }, 0, INT_MAX, ENC, 
"mpegts_flags" },
{ "nit", "Enable NIT transmission",
  0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_FLAG_NIT}, 0, INT_MAX, ENC, 
"mpegts_flags" },
+{ "pcr_at_keyframe", "Write PCR at key frame",
+  0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_FLAG_PCR_AT_KEYFRAME }, 0, INT_MAX, ENC, 
"mpegts_flags" },
{ "mpegts_copyts", "don't offset dts/pts", OFFSET(copyts), 
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, ENC },
{ "tables_version", "set PAT, PMT, SDT and NIT version", 
OFFSET(tables_version), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 31, ENC },
{ "omit_video_pes_length", "Omit the PES packet length for video packets",
--
2.25.1

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

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


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

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


Re: [FFmpeg-devel] [PATCH] swscale/swscale_unscaled: Fix undefined NULL + 0

2022-09-28 Thread Michael Niedermayer
On Wed, Sep 28, 2022 at 08:39:09PM +0200, Andreas Rheinhardt wrote:
> Affected the fitsdec-gbrp16 FATE-test.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libswscale/swscale_unscaled.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
> index 8838cc8b53..0b97377934 100644
> --- a/libswscale/swscale_unscaled.c
> +++ b/libswscale/swscale_unscaled.c
> @@ -695,7 +695,7 @@ static void packed16togbra16(const uint8_t *src, int 
> srcStride,
>  }
>  }
>  for (i = 0; i < 4; i++)
> -dst[i] += dstStride[i] >> 1;
> +dst[i] = FF_PTR_ADD(dst[i], dstStride[i] >> 1);
>  }
>  }
>  
> @@ -729,8 +729,8 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsContext *c, const 
> uint8_t *src[],
>  }
>  
>  for(i=0; i<4; i++) {
> -dst2013[i] += stride2013[i] * srcSliceY / 2;
> -dst1023[i] += stride1023[i] * srcSliceY / 2;
> +dst2013[i] = FF_PTR_ADD(dst2013[i], stride2013[i] * srcSliceY / 2);
> +dst1023[i] = FF_PTR_ADD(dst1023[i], stride1023[i] * srcSliceY / 2);
>  }

is there a reason not to check the pointer in the loop ?
as in
for (i = 0; i < 4 && dst[i]; i++)

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott



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

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


[FFmpeg-devel] [PATCH 6/6] avcodec/mpegvideo_dec: Fix UB NULL + 0

2022-09-28 Thread Andreas Rheinhardt
Affected the mpeg2-field-enc FATE-test.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_dec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 5b37e79e36..6d1edc027a 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -446,8 +446,8 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 if (s->picture_structure != PICT_FRAME) {
 for (int i = 0; i < 4; i++) {
 if (s->picture_structure == PICT_BOTTOM_FIELD) {
-s->current_picture.f->data[i] +=
-s->current_picture.f->linesize[i];
+s->current_picture.f->data[i] = 
FF_PTR_ADD(s->current_picture.f->data[i],
+   
s->current_picture.f->linesize[i]);
 }
 s->current_picture.f->linesize[i] *= 2;
 s->last_picture.f->linesize[i]*= 2;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 5/6] avcodec/mpegvideo: Fix undefined left shift of negative numbers

2022-09-28 Thread Andreas Rheinhardt
Fixes the rv20-1239 FATE-test.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index d8c7bc687d..5095149eaa 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -843,7 +843,7 @@ static inline int hpel_motion_lowres(MpegEncContext *s,
 s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src,
  s->linesize, s->linesize,
  w + 1, (h + 1) << field_based,
- src_x, src_y   << field_based,
+ src_x, src_y * (1 << field_based),
  h_edge_pos, v_edge_pos);
 src = s->sc.edge_emu_buffer;
 emu = 1;
@@ -945,7 +945,7 @@ static av_always_inline void 
mpeg_motion_lowres(MpegEncContext *s,
 s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr_y,
  linesize >> field_based, linesize >> 
field_based,
  17, 17 + field_based,
-src_x, src_y << field_based, h_edge_pos,
+src_x, src_y * (1 << field_based), h_edge_pos,
 v_edge_pos);
 ptr_y = s->sc.edge_emu_buffer;
 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
@@ -956,12 +956,12 @@ static av_always_inline void 
mpeg_motion_lowres(MpegEncContext *s,
 s->vdsp.emulated_edge_mc(ubuf,  ptr_cb,
  uvlinesize >> field_based, uvlinesize >> 
field_based,
  9, 9 + field_based,
-uvsrc_x, uvsrc_y << field_based,
+uvsrc_x, uvsrc_y * (1 << field_based),
 h_edge_pos >> 1, v_edge_pos >> 1);
 s->vdsp.emulated_edge_mc(vbuf,  ptr_cr,
  uvlinesize >> field_based,uvlinesize >> 
field_based,
  9, 9 + field_based,
-uvsrc_x, uvsrc_y << field_based,
+uvsrc_x, uvsrc_y * (1 << field_based),
 h_edge_pos >> 1, v_edge_pos >> 1);
 ptr_cb = ubuf;
 ptr_cr = vbuf;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 4/6] avcodec/jrevdct: Fix UB left shifts of negative numbers

2022-09-28 Thread Andreas Rheinhardt
Affected the rv20-1239 FATE test.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/jrevdct.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavcodec/jrevdct.c b/libavcodec/jrevdct.c
index 36160cb663..7f1863515f 100644
--- a/libavcodec/jrevdct.c
+++ b/libavcodec/jrevdct.c
@@ -255,7 +255,7 @@ void ff_j_rev_dct(DCTBLOCK data)
   if (d0) {
   /* Compute a 32 bit value to assign. */
   int16_t dcval = (int16_t) (d0 * (1 << PASS1_BITS));
-  register int v = (dcval & 0x) | ((dcval * (1 << 16)) & 
0x);
+  register unsigned v = (dcval & 0x) | ((uint32_t)dcval << 16);
 
   AV_WN32A(&idataptr[ 0], v);
   AV_WN32A(&idataptr[ 4], v);
@@ -988,8 +988,8 @@ void ff_j_rev_dct4(DCTBLOCK data)
   /* AC terms all zero */
   if (d0) {
   /* Compute a 32 bit value to assign. */
-  int16_t dcval = (int16_t) (d0 << PASS1_BITS);
-  register int v = (dcval & 0x) | ((dcval << 16) & 0x);
+  int16_t dcval = (int16_t) (d0 * (1 << PASS1_BITS));
+  register unsigned v = (dcval & 0x) | ((uint32_t)dcval << 16);
 
   AV_WN32A(&idataptr[0], v);
   AV_WN32A(&idataptr[4], v);
@@ -1008,8 +1008,8 @@ void ff_j_rev_dct4(DCTBLOCK data)
 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
 
-tmp0 = (d0 + d4) << CONST_BITS;
-tmp1 = (d0 - d4) << CONST_BITS;
+tmp0 = (d0 + d4) * (1 << CONST_BITS);
+tmp1 = (d0 - d4) * (1 << CONST_BITS);
 
 tmp10 = tmp0 + tmp3;
 tmp13 = tmp0 - tmp3;
@@ -1020,8 +1020,8 @@ void ff_j_rev_dct4(DCTBLOCK data)
 tmp2 = MULTIPLY(-d6, FIX_1_306562965);
 tmp3 = MULTIPLY(d6, FIX_0_541196100);
 
-tmp0 = (d0 + d4) << CONST_BITS;
-tmp1 = (d0 - d4) << CONST_BITS;
+tmp0 = (d0 + d4) * (1 << CONST_BITS);
+tmp1 = (d0 - d4) * (1 << CONST_BITS);
 
 tmp10 = tmp0 + tmp3;
 tmp13 = tmp0 - tmp3;
@@ -1034,8 +1034,8 @@ void ff_j_rev_dct4(DCTBLOCK data)
 tmp2 = MULTIPLY(d2, FIX_0_541196100);
 tmp3 = MULTIPLY(d2, FIX_1_306562965);
 
-tmp0 = (d0 + d4) << CONST_BITS;
-tmp1 = (d0 - d4) << CONST_BITS;
+tmp0 = (d0 + d4) * (1 << CONST_BITS);
+tmp1 = (d0 - d4) * (1 << CONST_BITS);
 
 tmp10 = tmp0 + tmp3;
 tmp13 = tmp0 - tmp3;
@@ -1043,8 +1043,8 @@ void ff_j_rev_dct4(DCTBLOCK data)
 tmp12 = tmp1 - tmp2;
 } else {
 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
-tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
-tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
+tmp10 = tmp13 = (d0 + d4) * (1 << CONST_BITS);
+tmp11 = tmp12 = (d0 - d4) * (1 << CONST_BITS);
 }
   }
 
@@ -1086,8 +1086,8 @@ void ff_j_rev_dct4(DCTBLOCK data)
 tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
 tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
 
-tmp0 = (d0 + d4) << CONST_BITS;
-tmp1 = (d0 - d4) << CONST_BITS;
+tmp0 = (d0 + d4) * (1 << CONST_BITS);
+tmp1 = (d0 - d4) * (1 << CONST_BITS);
 
 tmp10 = tmp0 + tmp3;
 tmp13 = tmp0 - tmp3;
@@ -1098,8 +1098,8 @@ void ff_j_rev_dct4(DCTBLOCK data)
 tmp2 = MULTIPLY(-d6, FIX_1_306562965);
 tmp3 = MULTIPLY(d6, FIX_0_541196100);
 
-tmp0 = (d0 + d4) << CONST_BITS;
-tmp1 = (d0 - d4) << CONST_BITS;
+tmp0 = (d0 + d4) * (1 << CONST_BITS);
+tmp1 = (d0 - d4) * (1 << CONST_BITS);
 
 tmp10 = tmp0 + tmp3;
 tmp13 = tmp0 - tmp3;
@@ -1112,8 +1112,8 @@ void ff_j_rev_dct4(DCTBLOCK data)
 tmp2 = MULTIPLY(d2, FIX_0_541196100);
 tmp3 = MULTIPLY(d2, FIX_1_306562965);
 
-tmp0 = (d0 + d4) << CONST_BITS;
-tmp1 = (d0 - d4) << CONST_BITS;
+tmp0 = (d0 + d4) * (1 << CONST_BITS);
+tmp1 = (d0 - d4) * (1 << CONST_BITS);
 
 tmp10 = tmp0 + tmp3;
 tmp13 = tmp0 - tmp3;
@@ -1121,8 +1121,8 @@ void ff_j_rev_dct4(DCTBLOCK data)
 tmp12 = tmp1 - tmp2;
 } else {
 /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
-tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
-tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
+   

[FFmpeg-devel] [PATCH 3/6] avformat/aviobuf: Don't use NULL as src for memcpy

2022-09-28 Thread Andreas Rheinhardt
This might happen in avio_write() if size == 0
when the direct codepath is taken. It is undefined behaviour
according to the spec although it happens to work in practice.
Fixes the webm-webvtt-remux FATE-test under UBSan.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/aviobuf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index b20b1a611a..5b6a42d7f4 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -231,6 +231,8 @@ void ffio_fill(AVIOContext *s, int b, int64_t count)
 
 void avio_write(AVIOContext *s, const unsigned char *buf, int size)
 {
+if (size <= 0)
+return;
 if (s->direct && !s->update_checksum) {
 avio_flush(s);
 writeout(s, buf, size);
@@ -246,7 +248,7 @@ void avio_write(AVIOContext *s, const unsigned char *buf, 
int size)
 
 buf += len;
 size -= len;
-}
+} while (size > 0);
 }
 
 void avio_flush(AVIOContext *s)
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 2/6] avcodec/g723_1enc: Fix undefined left-shifts of negative numbers

2022-09-28 Thread Andreas Rheinhardt
Affected the acodec-g723_1 FATE-test.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/g723_1enc.c | 71 +-
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c
index a22985ca44..8466067185 100644
--- a/libavcodec/g723_1enc.c
+++ b/libavcodec/g723_1enc.c
@@ -126,7 +126,7 @@ static void highpass_filter(int16_t *buf, int16_t *fir, int 
*iir)
 {
 int i;
 for (i = 0; i < FRAME_LEN; i++) {
-*iir   = (buf[i] << 15) + ((-*fir) << 15) + MULL2(*iir, 0x7f00);
+*iir   = (buf[i] - *fir) * (1 << 15) + MULL2(*iir, 0x7f00);
 *fir   = buf[i];
 buf[i] = av_clipl_int32((int64_t)*iir + (1 << 15)) >> 16;
 }
@@ -166,7 +166,7 @@ static void comp_autocorr(int16_t *buf, int16_t *autocorr)
 } else {
 for (i = 1; i <= LPC_ORDER; i++) {
 temp= ff_dot_product(vector, vector + i, LPC_FRAME - i);
-temp= MULL2((temp << scale), binomial_window[i - 1]);
+temp= MULL2(temp * (1 << scale), binomial_window[i - 1]);
 autocorr[i] = av_clipl_int32((int64_t) temp + (1 << 15)) >> 16;
 }
 }
@@ -193,7 +193,7 @@ static void levinson_durbin(int16_t *lpc, int16_t 
*autocorr, int16_t error)
 temp = 0;
 for (j = 0; j < i; j++)
 temp -= lpc[j] * autocorr[i - j - 1];
-temp = ((autocorr[i] << 13) + temp) << 3;
+temp = (autocorr[i] * (1 << 13) + temp) * (1 << 3);
 
 if (FFABS(temp) >= (error << 16))
 break;
@@ -209,8 +209,8 @@ static void levinson_durbin(int16_t *lpc, int16_t 
*autocorr, int16_t error)
 
 memcpy(vector, lpc, i * sizeof(int16_t));
 for (j = 0; j < i; j++) {
-temp   = partial_corr * vector[i - j - 1] << 1;
-lpc[j] = av_clipl_int32((int64_t) (lpc[j] << 16) - temp +
+temp   = partial_corr * vector[i - j - 1] * 2;
+lpc[j] = av_clipl_int32((int64_t) (lpc[j] * (1 << 16)) - temp +
 (1 << 15)) >> 16;
 }
 }
@@ -259,9 +259,9 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, 
int16_t *lsp)
 /* Compute the remaining coefficients */
 for (i = 0; i < LPC_ORDER / 2; i++) {
 /* f1 */
-f[2 * i + 2] = -f[2 * i] - ((lsp[i] + lsp[LPC_ORDER - 1 - i]) << 12);
+f[2 * i + 2] = -f[2 * i]- (lsp[i] + lsp[LPC_ORDER - 1 - i]) * (1 
<< 12);
 /* f2 */
-f[2 * i + 3] = f[2 * i + 1] - ((lsp[i] - lsp[LPC_ORDER - 1 - i]) << 
12);
+f[2 * i + 3] = f[2 * i + 1] - (lsp[i] - lsp[LPC_ORDER - 1 - i]) * (1 
<< 12);
 }
 
 /* Divide f1[5] and f2[5] by 2 for use in polynomial evaluation */
@@ -276,7 +276,7 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, 
int16_t *lsp)
 shift = ff_g723_1_normalize_bits(max, 31);
 
 for (i = 0; i < LPC_ORDER + 2; i++)
-f[i] = av_clipl_int32((int64_t) (f[i] << shift) + (1 << 15)) >> 16;
+f[i] = av_clipl_int32((int64_t) (f[i] * (1 << shift)) + (1 << 15)) >> 
16;
 
 /**
  * Evaluate F1 and F2 at uniform intervals of pi/256 along the
@@ -293,7 +293,7 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, 
int16_t *lsp)
 temp = 0;
 for (j = 0; j <= LPC_ORDER / 2; j++)
 temp += f[LPC_ORDER - 2 * j + p] * ff_g723_1_cos_tab[i * j % 
COS_TBL_SIZE];
-cur_val = av_clipl_int32(temp << 1);
+cur_val = av_clipl_int32(temp * 2);
 
 /* Check for sign change, indicating a zero crossing */
 if ((cur_val ^ prev_val) < 0) {
@@ -317,7 +317,7 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, 
int16_t *lsp)
 for (j = 0; j <= LPC_ORDER / 2; j++)
 temp += f[LPC_ORDER - 2 * j + p] *
 ff_g723_1_cos_tab[i * j % COS_TBL_SIZE];
-cur_val = av_clipl_int32(temp << 1);
+cur_val = av_clipl_int32(temp * 2);
 }
 prev_val = cur_val;
 }
@@ -344,7 +344,7 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, 
int16_t *lsp)
 temp[j] = (weight[j + (offset)] * ff_g723_1_lsp_band##num[i][j] + \
   (1 << 14)) >> 15;   \
 } \
-error  = ff_g723_1_dot_product(lsp + (offset), temp, size) << 1;  \
+error  = ff_g723_1_dot_product(lsp + (offset), temp, size) * 2;   \
 error -= ff_g723_1_dot_product(ff_g723_1_lsp_band##num[i], temp, 
size); \
 if (error > max) {\
 max = error;  \
@@ -419,7 +419,7 @@ static void iir_filter(int16_t *fir_coef, int16_t *iir_coef,
   iir_coef[n - 1] * dest[m - n];
 }
 
-dest[m] = av_clipl_int32((src[m] << 16) + (filter << 3) +
+dest[m] = av_clipl_int32(src[m] * 

[FFmpeg-devel] [PATCH 1/6] avcodec/g723_1enc: Remove unnecessary av_clipl_int32()

2022-09-28 Thread Andreas Rheinhardt
partial_corr is an int16_t and so the av_clipl_int32()
never clips and can be removed. This also avoids
undefined left-shifts of negative numbers.

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

diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c
index f3baf7b4ec..a22985ca44 100644
--- a/libavcodec/g723_1enc.c
+++ b/libavcodec/g723_1enc.c
@@ -200,8 +200,7 @@ static void levinson_durbin(int16_t *lpc, int16_t 
*autocorr, int16_t error)
 
 partial_corr = temp / (error << 1);
 
-lpc[i] = av_clipl_int32((int64_t) (partial_corr << 14) +
-(1 << 15)) >> 16;
+lpc[i] = (partial_corr + (1 << 1)) >> 2;
 
 /* Update the prediction error */
 temp  = MULL2(temp, partial_corr);
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 3/3] avcodec/wmalosslessdec: Simplify flushing, avoid NULL + 0

2022-09-28 Thread Andreas Rheinhardt
Return immediately if not enough leftover bits are available
when flushing. This is simpler and also avoids an
init_get_bits(gb, NULL, 0) (which currently leads to NULL + 0,
which is UB; this affects the lossless-wma(|-1|-2|-rawtile)
FATE tests).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/wmalosslessdec.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index 5112b763fa..d545d848e2 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -1192,16 +1192,15 @@ static int decode_packet(AVCodecContext *avctx, AVFrame 
*rframe,
 
 s->frame->nb_samples = 0;
 
-if (!buf_size && s->num_saved_bits > get_bits_count(&s->gb)) {
+if (!buf_size) {
 s->packet_done = 0;
+if (s->num_saved_bits <= get_bits_count(&s->gb))
+return 0;
 if (!decode_frame(s))
 s->num_saved_bits = 0;
 } else if (s->packet_done || s->packet_loss) {
 s->packet_done = 0;
 
-if (!buf_size)
-return 0;
-
 s->next_packet_start = buf_size - FFMIN(avctx->block_align, buf_size);
 buf_size = FFMIN(avctx->block_align, buf_size);
 s->buf_bit_size  = buf_size << 3;
@@ -1299,7 +1298,7 @@ static int decode_packet(AVCodecContext *avctx, AVFrame 
*rframe,
 
 s->packet_offset = get_bits_count(gb) & 7;
 
-return (s->packet_loss) ? AVERROR_INVALIDDATA : buf_size ? 
get_bits_count(gb) >> 3 : 0;
+return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
 }
 
 static void flush(AVCodecContext *avctx)
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 2/3] avcodec/wmavoice: Check init_get_bits8()

2022-09-28 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/wmavoice.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index 26744719e6..bb98f841a5 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -1911,7 +1911,9 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, 
AVFrame *frame,
  * capping the packet size at ctx->block_align. */
 for (size = avpkt->size; size > ctx->block_align; size -= 
ctx->block_align);
 buf = size ? buf : dummy;
-init_get_bits8(&s->gb, buf, size);
+res = init_get_bits8(&s->gb, buf, size);
+if (res < 0)
+return res;
 
 /* size == ctx->block_align is used to indicate whether we are dealing with
  * a new packet or a packet of which we already read the packet header
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 1/3] avcodec/wmavoice: Don't initialize GetBitContext with buf == NULL

2022-09-28 Thread Andreas Rheinhardt
Happens when flushing. This triggers NULL + 0 (which is UB) in
init_get_bits_xe (which previously errored out, but the return value
has not been checked) and in copy_bits().

This fixes the wmavoice-(7|11|19)k FATE-tests with UBSan.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/wmavoice.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index 4438089e51..26744719e6 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -1900,6 +1900,8 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, 
AVFrame *frame,
 {
 WMAVoiceContext *s = ctx->priv_data;
 GetBitContext *gb = &s->gb;
+const uint8_t *buf = avpkt->data;
+uint8_t dummy[1];
 int size, res, pos;
 
 /* Packets are sometimes a multiple of ctx->block_align, with a packet
@@ -1908,7 +1910,8 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, 
AVFrame *frame,
  * in a single "muxer" packet, so we artificially emulate that by
  * capping the packet size at ctx->block_align. */
 for (size = avpkt->size; size > ctx->block_align; size -= 
ctx->block_align);
-init_get_bits8(&s->gb, avpkt->data, size);
+buf = size ? buf : dummy;
+init_get_bits8(&s->gb, buf, size);
 
 /* size == ctx->block_align is used to indicate whether we are dealing with
  * a new packet or a packet of which we already read the packet header
@@ -1931,7 +1934,7 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, 
AVFrame *frame,
 if (cnt + s->spillover_nbits > avpkt->size * 8) {
 s->spillover_nbits = avpkt->size * 8 - cnt;
 }
-copy_bits(&s->pb, avpkt->data, size, gb, s->spillover_nbits);
+copy_bits(&s->pb, buf, size, gb, s->spillover_nbits);
 flush_put_bits(&s->pb);
 s->sframe_cache_size += s->spillover_nbits;
 if ((res = synth_superframe(ctx, frame, got_frame_ptr)) == 0 &&
@@ -1968,7 +1971,7 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, 
AVFrame *frame,
 } else if ((s->sframe_cache_size = pos) > 0) {
 /* ... cache it for spillover in next packet */
 init_put_bits(&s->pb, s->sframe_cache, SFRAME_CACHE_MAXSIZE);
-copy_bits(&s->pb, avpkt->data, size, gb, s->sframe_cache_size);
+copy_bits(&s->pb, buf, size, gb, s->sframe_cache_size);
 // FIXME bad - just copy bytes as whole and add use the
 // skip_bits_next field
 }
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH] avcodec/zerocodec: Avoid undefined NULL - 0

2022-09-28 Thread Andreas Rheinhardt
Fixes the zerocodec FATE-test.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/zerocodec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/zerocodec.c b/libavcodec/zerocodec.c
index 93fc2834e4..42fb24ff6c 100644
--- a/libavcodec/zerocodec.c
+++ b/libavcodec/zerocodec.c
@@ -84,11 +84,12 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, 
AVFrame *pic,
 return AVERROR_INVALIDDATA;
 }
 
-if (!(avpkt->flags & AV_PKT_FLAG_KEY))
+if (!(avpkt->flags & AV_PKT_FLAG_KEY)) {
 for (j = 0; j < avctx->width << 1; j++)
 dst[j] += prev[j] & -!dst[j];
+prev -= prev_pic->linesize[0];
+}
 
-prev -= prev_pic->linesize[0];
 dst  -= pic->linesize[0];
 }
 
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH] swscale/swscale_unscaled: Fix undefined NULL + 0

2022-09-28 Thread Andreas Rheinhardt
Affected the fitsdec-gbrp16 FATE-test.

Signed-off-by: Andreas Rheinhardt 
---
 libswscale/swscale_unscaled.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 8838cc8b53..0b97377934 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -695,7 +695,7 @@ static void packed16togbra16(const uint8_t *src, int 
srcStride,
 }
 }
 for (i = 0; i < 4; i++)
-dst[i] += dstStride[i] >> 1;
+dst[i] = FF_PTR_ADD(dst[i], dstStride[i] >> 1);
 }
 }
 
@@ -729,8 +729,8 @@ static int Rgb16ToPlanarRgb16Wrapper(SwsContext *c, const 
uint8_t *src[],
 }
 
 for(i=0; i<4; i++) {
-dst2013[i] += stride2013[i] * srcSliceY / 2;
-dst1023[i] += stride1023[i] * srcSliceY / 2;
+dst2013[i] = FF_PTR_ADD(dst2013[i], stride2013[i] * srcSliceY / 2);
+dst1023[i] = FF_PTR_ADD(dst1023[i], stride1023[i] * srcSliceY / 2);
 }
 
 switch (c->srcFormat) {
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 4/5] avcodec/rl2: Fix undefined pointer arithmetic

2022-09-28 Thread Andreas Rheinhardt
Don't increment back_frame if it does not correspond
to a real buffer. To do this, handle copying from
the back frame separately from the "use coded value"
codepath; also use memcpy for the former, as the
chunks here are typically worth it.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/rl2.c | 35 ---
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/libavcodec/rl2.c b/libavcodec/rl2.c
index 76982f0426..7938ef1d92 100644
--- a/libavcodec/rl2.c
+++ b/libavcodec/rl2.c
@@ -69,13 +69,16 @@ static void rl2_rle_decode(Rl2Context *s, const uint8_t 
*in, int size,
 uint8_t *line_end;
 
 /** copy start of the background frame */
+if (s->back_frame) {
 for (i = 0; i <= base_y; i++) {
-if (s->back_frame)
 memcpy(out, back_frame, s->avctx->width);
 out+= stride;
 back_frame += s->avctx->width;
 }
 back_frame += base_x - s->avctx->width;
+} else {
+out += stride * (base_y + 1);
+}
 line_end= out - stride_adj;
 out+= base_x - stride;
 
@@ -89,16 +92,32 @@ static void rl2_rle_decode(Rl2Context *s, const uint8_t 
*in, int size,
 len = *in++;
 if (!len)
 break;
+val &= 0x7F;
 }
 
-if (s->back_frame)
+if (back_frame) {
+if (!val) {
+do {
+size_t copy = FFMIN(line_end - out, len);
+memcpy(out, back_frame, copy);
+out+= copy;
+back_frame += copy;
+len-= copy;
+if (out == line_end) {
+if (out == out_end)
+return;
+out  += stride_adj;
+line_end += stride;
+}
+} while (len > 0);
+continue;
+}
+back_frame += len;
 val |= 0x80;
-else
-val &= ~0x80;
+}
 
 while (len--) {
-*out++ = (val == 0x80) ? *back_frame : val;
-back_frame++;
+*out++ = val;
 if (out == line_end) {
 if (out == out_end)
 return;
@@ -164,7 +183,9 @@ static av_cold int rl2_decode_init(AVCodecContext *avctx)
 back_size = avctx->extradata_size - EXTRADATA1_SIZE;
 
 if (back_size > 0) {
-uint8_t *back_frame = av_mallocz(avctx->width*avctx->height);
+/* The 254 are padding to ensure that pointer arithmetic stays within
+ * the buffer. */
+uint8_t *back_frame = av_mallocz(avctx->width * avctx->height + 254);
 if (!back_frame)
 return AVERROR(ENOMEM);
 rl2_rle_decode(s, avctx->extradata + EXTRADATA1_SIZE, back_size,
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 5/5] avcodec/rl2: Fix indentation

2022-09-28 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/rl2.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavcodec/rl2.c b/libavcodec/rl2.c
index 7938ef1d92..e427a27dce 100644
--- a/libavcodec/rl2.c
+++ b/libavcodec/rl2.c
@@ -62,7 +62,6 @@ static void rl2_rle_decode(Rl2Context *s, const uint8_t *in, 
int size,
 int base_x = video_base % s->avctx->width;
 int base_y = video_base / s->avctx->width;
 ptrdiff_t stride_adj = stride - s->avctx->width;
-int i;
 const uint8_t *back_frame = s->back_frame;
 const uint8_t *in_end = in + size;
 const uint8_t *out_end= out + stride * s->avctx->height - stride_adj;
@@ -70,12 +69,12 @@ static void rl2_rle_decode(Rl2Context *s, const uint8_t 
*in, int size,
 
 /** copy start of the background frame */
 if (s->back_frame) {
-for (i = 0; i <= base_y; i++) {
+for (int i = 0; i <= base_y; i++) {
 memcpy(out, back_frame, s->avctx->width);
-out+= stride;
-back_frame += s->avctx->width;
-}
-back_frame += base_x - s->avctx->width;
+out+= stride;
+back_frame += s->avctx->width;
+}
+back_frame += base_x - s->avctx->width;
 } else {
 out += stride * (base_y + 1);
 }
@@ -121,8 +120,8 @@ static void rl2_rle_decode(Rl2Context *s, const uint8_t 
*in, int size,
 if (out == line_end) {
 if (out == out_end)
 return;
- out  += stride_adj;
- line_end += stride;
+out  += stride_adj;
+line_end += stride;
 }
 }
 }
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 3/5] avcodec/rl2: Use ptrdiff_t for stride

2022-09-28 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/rl2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/rl2.c b/libavcodec/rl2.c
index 467c4913a4..76982f0426 100644
--- a/libavcodec/rl2.c
+++ b/libavcodec/rl2.c
@@ -57,11 +57,11 @@ typedef struct Rl2Context {
  * @param video_base offset of the rle data inside the frame
  */
 static void rl2_rle_decode(Rl2Context *s, const uint8_t *in, int size,
-   uint8_t *out, int stride, int video_base)
+   uint8_t *out, ptrdiff_t stride, int video_base)
 {
 int base_x = video_base % s->avctx->width;
 int base_y = video_base / s->avctx->width;
-int stride_adj = stride - s->avctx->width;
+ptrdiff_t stride_adj = stride - s->avctx->width;
 int i;
 const uint8_t *back_frame = s->back_frame;
 const uint8_t *in_end = in + size;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 2/5] avcodec/rl2: Don't presume stride to be > 0

2022-09-28 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
Lots of fate tests fail if this assumption is not fulfilled.

 libavcodec/rl2.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/rl2.c b/libavcodec/rl2.c
index 2464ad59ac..467c4913a4 100644
--- a/libavcodec/rl2.c
+++ b/libavcodec/rl2.c
@@ -65,7 +65,7 @@ static void rl2_rle_decode(Rl2Context *s, const uint8_t *in, 
int size,
 int i;
 const uint8_t *back_frame = s->back_frame;
 const uint8_t *in_end = in + size;
-const uint8_t *out_end= out + stride * s->avctx->height;
+const uint8_t *out_end= out + stride * s->avctx->height - stride_adj;
 uint8_t *line_end;
 
 /** copy start of the background frame */
@@ -100,18 +100,20 @@ static void rl2_rle_decode(Rl2Context *s, const uint8_t 
*in, int size,
 *out++ = (val == 0x80) ? *back_frame : val;
 back_frame++;
 if (out == line_end) {
+if (out == out_end)
+return;
  out  += stride_adj;
  line_end += stride;
- if (len >= out_end - out)
-return;
 }
 }
 }
 
 /** copy the rest from the background frame */
 if (s->back_frame) {
-while (out < out_end) {
+while (1) {
 memcpy(out, back_frame, line_end - out);
+if (line_end == out_end)
+break;
 back_frame += line_end - out;
 out = line_end + stride_adj;
 line_end   += stride;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 1/5] avcodec/rl2: Remove wrong check

2022-09-28 Thread Andreas Rheinhardt
This check is intended to be avoid buffer overflows,
yet there are four problems with it:
1. It has an in-built off-by-one error: len == out_end - out
is perfectly fine and nothing to worry about.
This off-by-one error led to the pixel in the lower-right corner
not being set properly for the back frame of the sample from
the rl2 FATE-test. This pixel is copied to every frame which
is the reason for the update to the reference file of said test.
With this patch, the output of the decoder matches the output
as captured from the reference decoder* (apart from the fact
that said reference somehow lacks the top part of the frame
(copied over from the background frame)).
2. Given that the stride of the buffer may be different
from the width of the video (despite one pixel taking one byte),
there is a second check lateron making the first check redundant
(if one returns immediately; a simple break at the second check
is not sufficient, because it only exits the inner loop).
3. The check is based around the assumption of the stride being
positive (it has this in common with the other check which
will be fixed in a future commit).
4. Even after fixing the off-by-one error, the check in
question is still triggered by all the non-background frames
in the FATE sample as well as by A1100100.RL2. In all these
cases, they use len == 255 and val == 128. For videos with
background frame this just means "copy from the background
frame", which would be done anyway lateron.* Yet for videos
without it copying it is necessary to avoid leaving
uninitialized parts in the video.

*: Available in https://samples.mplayerhq.hu/game-formats/voyeur-rl2/
**: Due to this, the code that copies the rest from the
back frame is no longer executed for any of the samples
available on the sample server. Given that these are only
the files from the demo version of this game, I don't know
whether this code is executed for any file in existence or not.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/rl2.c   |   5 +-
 tests/ref/fate/rl2 | 216 ++---
 2 files changed, 109 insertions(+), 112 deletions(-)

diff --git a/libavcodec/rl2.c b/libavcodec/rl2.c
index 5dedb96266..2464ad59ac 100644
--- a/libavcodec/rl2.c
+++ b/libavcodec/rl2.c
@@ -91,9 +91,6 @@ static void rl2_rle_decode(Rl2Context *s, const uint8_t *in, 
int size,
 break;
 }
 
-if (len >= out_end - out)
-break;
-
 if (s->back_frame)
 val |= 0x80;
 else
@@ -106,7 +103,7 @@ static void rl2_rle_decode(Rl2Context *s, const uint8_t 
*in, int size,
  out  += stride_adj;
  line_end += stride;
  if (len >= out_end - out)
- break;
+return;
 }
 }
 }
diff --git a/tests/ref/fate/rl2 b/tests/ref/fate/rl2
index 9189822503..a3c6a75d05 100644
--- a/tests/ref/fate/rl2
+++ b/tests/ref/fate/rl2
@@ -3,111 +3,111 @@
 #codec_id 0: rawvideo
 #dimensions 0: 320x200
 #sar 0: 0/1
-0,  0,  0,1,   192000, 0x7112a667
-0,  1,  1,1,   192000, 0x6936abf3
-0,  2,  2,1,   192000, 0xb1f08981
-0,  3,  3,1,   192000, 0x4ce7fece
-0,  4,  4,1,   192000, 0xf04decde
-0,  5,  5,1,   192000, 0x47fef74b
-0,  6,  6,1,   192000, 0x99b42ac2
-0,  7,  7,1,   192000, 0x3c4c419d
-0,  8,  8,1,   192000, 0x66bf5588
-0,  9,  9,1,   192000, 0xe1de4725
-0, 10, 10,1,   192000, 0x348b2af9
-0, 11, 11,1,   192000, 0x1ce73e83
-0, 12, 12,1,   192000, 0xcdaa6e02
-0, 13, 13,1,   192000, 0x370dc2ce
-0, 14, 14,1,   192000, 0x1e1e40fe
-0, 15, 15,1,   192000, 0x491470a4
-0, 16, 16,1,   192000, 0x88c43e9a
-0, 17, 17,1,   192000, 0x036f3f44
-0, 18, 18,1,   192000, 0xc8be7e25
-0, 19, 19,1,   192000, 0xbedb397d
-0, 20, 20,1,   192000, 0x97c410f4
-0, 21, 21,1,   192000, 0xc2c8225d
-0, 22, 22,1,   192000, 0xe396bccb
-0, 23, 23,1,   192000, 0x7e89c24c
-0, 24, 24,1,   192000, 0xb044954c
-0, 25, 25,1,   192000, 0x335890dd
-0, 26, 26,1,   192000, 0x58a457c0
-0, 27, 27,1,   192000, 0xeb0f4798
-0, 28, 28,1,   192000, 0x0bfc39a1
-0, 29, 29,1,   192000, 0x06a6905a
-0, 30, 30,1,   192000, 0x5300c99b
-0, 31, 31,1,   192000, 0x38f3f845
-0, 32, 32,1,   192000, 0x6afa3543
-0

Re: [FFmpeg-devel] [PATCH 1/1] libswscale: force a minimum size of the slide for bayer sources

2022-09-28 Thread Chema Gonzalez
Hi,

On Wed, Sep 28, 2022 at 8:09 AM Anton Khirnov  wrote:
> >  if (isBayer(srcFormat)) {
> > +c->dst_slice_align = 2;
>
> IMO it's better to put this next to the line that sets dst_slice_align
> for non-bayer cases, makes it clearer what the final value is.
Are you suggesting setting `dst_slice_align` in a different function?

The way I read `ff_get_unscaled_swscale()` is that it goes through the
quirks of all the different conversions (per source and destination
type). In all cases, it sets the `convert_unscaled` function pointer.
In the cases where there is the need to align (yuv2bgr and
yuv410p_to_yuv[a]420p), it also adds `dst_slice_align`. In the same
fashion, the conversions that affect Bayer sources are set in line
2097.

Thanks,
-Chema
___
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] avcodec: add a bsf to reorder DTS into PTS

2022-09-28 Thread Anton Khirnov
Quoting James Almer (2022-09-23 16:27:32)
> On 9/23/2022 10:06 AM, Anton Khirnov wrote:
> >> +static int dts2pts_filter(AVBSFContext *ctx, AVPacket *out)
> >> +{
> >> +DTS2PTSContext *s = ctx->priv_data;
> >> +DTS2PTSNode *poc_node = NULL, *next[2] = { NULL, NULL };
> >> +DTS2PTSFrame frame;
> >> +int ret;
> >> +
> >> +// Fill up the FIFO and POC tree
> >> +if (!s->eof && av_fifo_can_write(s->fifo)) {
> > 
> > More than one packet can be available, so this should probably be a
> > loop.
> 
> What do you mean? AVBSFContext can contain at most one buffered packet.

I'd prefer if filters didn't make any such assumptions.

-- 
Anton Khirnov
___
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/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()

2022-09-28 Thread Andreas Rheinhardt
Tomas Härdin:
> ons 2022-09-28 klockan 12:48 +0200 skrev Anton Khirnov:
>>
>> +/**
>> + * Reallocate a data buffer, reusing the existing one if it is large
>> enough.
>> + *
>> + * This function is similar to av_realloc(), but optimized for cases
>> where the
>> + * buffer may grow significantly and is not expected to shrink.
>> + *
>> + * @param[in] ptr Previously allocated buffer, or `NULL`. If `ptr`
>> is `NULL`, a
>> + * new uninitialized buffer is allocated. `ptr` is invalidated when
>> this
>> + * function returns non-`NULL` and must be replaced with its return
>> value.
>> + *
>> + * @param[in,out] size Pointer to the allocated size of buffer
>> `ptr`. This
>> + * function updates `*size` to the new allocated size (which may be
>> larger than
>> + * `min_size`). `*size` is set to 0 on failure.
>> + *
>> + * @param[in] min_size Minimum size in bytes of the returned buffer.
>> + *
>> + * @return
>> + * - An allocated buffer (to be freed with `av_free()`) that is
>> large enough to
>> + *   hold at least `min_size` bytes. The first `*size` (value on
>> entry to this
>> + *   function) bytes of the buffer remain the same as the data in
>> `ptr`, the
>> + *   rest is uninitialized.
>> + * - `NULL` on failure, then `*size` is set to 0 and ptr remains
>> untouched.
>> + *
>> + * @see av_realloc()
>> + * @see av_fast_malloc()
>> + */
>> +void *av_realloc_reuse(void *ptr, size_t *size, size_t min_size);
> 
> Isn't it better to return int like av_realloc_array_reuse() and leave
> *ptr and *size untouched on error just as it does? If we're in the
> business of straightening this all out then having all functions work
> the same is less mental load down the line.
> 

IMO size should be unchanged on error, but returning an int is IMO
overblown. I only did it for my version because there is the possibility
of the multiplication overflowing, but that is not the case here.

- 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] [PATCH 3/3] sws/rgb2rgb: RISC-V 64-bit V packed YUYV/UYVY to planar 4:2:2

2022-09-28 Thread remi
From: Rémi Denis-Courmont 

This is currently 64-bit only because the stack spilling code would not
assemble on RV32I (and it would corrupt s0 and s1 on RV128I, in theory).

This could be added later in the unlikely that someone wants it.
---
 libswscale/riscv/rgb2rgb.c | 10 +++
 libswscale/riscv/rgb2rgb_rvv.S | 53 ++
 2 files changed, 63 insertions(+)

diff --git a/libswscale/riscv/rgb2rgb.c b/libswscale/riscv/rgb2rgb.c
index 32c1546827..93bc6b6245 100644
--- a/libswscale/riscv/rgb2rgb.c
+++ b/libswscale/riscv/rgb2rgb.c
@@ -33,6 +33,12 @@ void ff_shuffle_bytes_3210_rvv(const uint8_t *src, uint8_t 
*dst, int src_len);
 void ff_interleave_bytes_rvv(const uint8_t *src1, const uint8_t *src2,
  uint8_t *dst, int width, int height, int s1stride,
  int s2stride, int dstride);
+void ff_uyvytoyuv422_rvv(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ const uint8_t *src, int width, int height,
+ int ystride, int uvstride, int src_stride);
+void ff_yuyvtoyuv422_rvv(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
+ const uint8_t *src, int width, int height,
+ int ystride, int uvstride, int src_stride);
 
 av_cold void rgb2rgb_init_riscv(void)
 {
@@ -46,6 +52,10 @@ av_cold void rgb2rgb_init_riscv(void)
 shuffle_bytes_3012 = ff_shuffle_bytes_3012_rvv;
 shuffle_bytes_3210 = ff_shuffle_bytes_3210_rvv;
 interleaveBytes = ff_interleave_bytes_rvv;
+# if (__riscv_xlen == 64)
+uyvytoyuv422 = ff_uyvytoyuv422_rvv;
+yuyvtoyuv422 = ff_yuyvtoyuv422_rvv;
+# endif
 }
 #endif
 }
diff --git a/libswscale/riscv/rgb2rgb_rvv.S b/libswscale/riscv/rgb2rgb_rvv.S
index 7f8c2efd80..5626d906eb 100644
--- a/libswscale/riscv/rgb2rgb_rvv.S
+++ b/libswscale/riscv/rgb2rgb_rvv.S
@@ -102,3 +102,56 @@ func ff_interleave_bytes_rvv, zve32x
 
 ret
 endfunc
+
+#if (__riscv_xlen == 64)
+.macro yuy2_to_i422p v_y0, v_y1, v_u, v_v
+addisp, sp, -16
+sd  s0,   (sp)
+sd  s1,  8(sp)
+addia4, a4, 1
+lw  s0, 16(sp)
+sraia4, a4, 1 // pixel width -> chroma width
+li  s1, 2
+1:
+mv  t4, a4
+mv  t3, a3
+mv  t0, a0
+addit6, a0, 1
+mv  t1, a1
+mv  t2, a2
+addia5, a5, -1
+2:
+vsetvlit5, t4, e8, m1, ta, ma
+subt4, t4, t5
+vlseg4e8.v v8, (t3)
+sh2add t3, t5, t3
+vsse8.v\v_y0, (t0), s1
+sh1add t0, t5, t0
+vsse8.v\v_y1, (t6), s1
+sh1add t6, t5, t6
+vse8.v \v_u, (t1)
+addt1, t5, t1
+vse8.v \v_v, (t2)
+addt2, t5, t2
+bnez   t4, 2b
+
+add a3, a3, s0
+add a0, a0, a6
+add a1, a1, a7
+add a2, a2, a7
+bneza5, 1b
+
+ld  s1,  8(sp)
+ld  s0,   (sp)
+addisp, sp, 16
+ret
+.endm
+
+func ff_uyvytoyuv422_rvv, zve32x
+yuy2_to_i422p v9, v11, v8, v10
+endfunc
+
+func ff_yuyvtoyuv422_rvv, zve32x
+yuy2_to_i422p v8, v10, v9, v11
+endfunc
+#endif
-- 
2.37.2

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

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


[FFmpeg-devel] [PATCH 2/3] sws/rgb2rgb: RISC-V V interleaveBytes

2022-09-28 Thread remi
From: Rémi Denis-Courmont 

---
 libswscale/riscv/rgb2rgb.c |  4 
 libswscale/riscv/rgb2rgb_rvv.S | 26 ++
 2 files changed, 30 insertions(+)

diff --git a/libswscale/riscv/rgb2rgb.c b/libswscale/riscv/rgb2rgb.c
index 5654154494..32c1546827 100644
--- a/libswscale/riscv/rgb2rgb.c
+++ b/libswscale/riscv/rgb2rgb.c
@@ -30,6 +30,9 @@ void ff_shuffle_bytes_2103_rvv(const uint8_t *src, uint8_t 
*dst, int src_len);
 void ff_shuffle_bytes_1230_rvv(const uint8_t *src, uint8_t *dst, int src_len);
 void ff_shuffle_bytes_3012_rvv(const uint8_t *src, uint8_t *dst, int src_len);
 void ff_shuffle_bytes_3210_rvv(const uint8_t *src, uint8_t *dst, int src_len);
+void ff_interleave_bytes_rvv(const uint8_t *src1, const uint8_t *src2,
+ uint8_t *dst, int width, int height, int s1stride,
+ int s2stride, int dstride);
 
 av_cold void rgb2rgb_init_riscv(void)
 {
@@ -42,6 +45,7 @@ av_cold void rgb2rgb_init_riscv(void)
 shuffle_bytes_1230 = ff_shuffle_bytes_1230_rvv;
 shuffle_bytes_3012 = ff_shuffle_bytes_3012_rvv;
 shuffle_bytes_3210 = ff_shuffle_bytes_3210_rvv;
+interleaveBytes = ff_interleave_bytes_rvv;
 }
 #endif
 }
diff --git a/libswscale/riscv/rgb2rgb_rvv.S b/libswscale/riscv/rgb2rgb_rvv.S
index 3eb11262c0..7f8c2efd80 100644
--- a/libswscale/riscv/rgb2rgb_rvv.S
+++ b/libswscale/riscv/rgb2rgb_rvv.S
@@ -76,3 +76,29 @@ func ff_shuffle_bytes_3210_rvv, zve32x
 addia0, a0, 3
 j   1b
 endfunc
+
+func ff_interleave_bytes_rvv, zve32x
+1:
+mv  t0, a0
+mv  t1, a1
+mv  t2, a2
+mv  t3, a3
+addia4, a4, -1
+2:
+vsetvlit4, t3, e8, ta, ma
+subt3, t3, t4
+vle8.v v8, (t0)
+addt0, t4, t0
+vle8.v v9, (t1)
+addt1, t4, t1
+vsseg2e8.v v8, (t2)
+sh1add t2, t4, t2
+bnez   t4, 2b
+
+add a0, a0, a5
+add a1, a1, a6
+add a2, a2, a7
+bneza4, 1b
+
+ret
+endfunc
-- 
2.37.2

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

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


[FFmpeg-devel] [PATCH 1/3] sws/rgb2rgb: RISC-V V shuffle_bytes_xxxx functions

2022-09-28 Thread remi
From: Rémi Denis-Courmont 

---
 libswscale/rgb2rgb.c   |  2 +
 libswscale/rgb2rgb.h   |  1 +
 libswscale/riscv/Makefile  |  2 +
 libswscale/riscv/rgb2rgb.c | 47 
 libswscale/riscv/rgb2rgb_rvv.S | 78 ++
 5 files changed, 130 insertions(+)
 create mode 100644 libswscale/riscv/Makefile
 create mode 100644 libswscale/riscv/rgb2rgb.c
 create mode 100644 libswscale/riscv/rgb2rgb_rvv.S

diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c
index 3af775b389..e98fdac8ea 100644
--- a/libswscale/rgb2rgb.c
+++ b/libswscale/rgb2rgb.c
@@ -139,6 +139,8 @@ av_cold void ff_sws_rgb2rgb_init(void)
 rgb2rgb_init_c();
 #if ARCH_AARCH64
 rgb2rgb_init_aarch64();
+#elif ARCH_RISCV
+rgb2rgb_init_riscv();
 #elif ARCH_X86
 rgb2rgb_init_x86();
 #elif ARCH_LOONGARCH64
diff --git a/libswscale/rgb2rgb.h b/libswscale/rgb2rgb.h
index db85bfc42f..f3951d523e 100644
--- a/libswscale/rgb2rgb.h
+++ b/libswscale/rgb2rgb.h
@@ -167,6 +167,7 @@ extern void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, 
uint8_t *vdst, const u
 void ff_sws_rgb2rgb_init(void);
 
 void rgb2rgb_init_aarch64(void);
+void rgb2rgb_init_riscv(void);
 void rgb2rgb_init_x86(void);
 void rgb2rgb_init_loongarch(void);
 
diff --git a/libswscale/riscv/Makefile b/libswscale/riscv/Makefile
new file mode 100644
index 00..214d877b62
--- /dev/null
+++ b/libswscale/riscv/Makefile
@@ -0,0 +1,2 @@
+OBJS += riscv/rgb2rgb.o
+RVV-OBJS += riscv/rgb2rgb_rvv.o
diff --git a/libswscale/riscv/rgb2rgb.c b/libswscale/riscv/rgb2rgb.c
new file mode 100644
index 00..5654154494
--- /dev/null
+++ b/libswscale/riscv/rgb2rgb.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2022 Rémi Denis-Courmont.
+ *
+ * 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 
+
+#include "config.h"
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libswscale/rgb2rgb.h"
+
+void ff_shuffle_bytes_0321_rvv(const uint8_t *src, uint8_t *dst, int src_len);
+void ff_shuffle_bytes_2103_rvv(const uint8_t *src, uint8_t *dst, int src_len);
+void ff_shuffle_bytes_1230_rvv(const uint8_t *src, uint8_t *dst, int src_len);
+void ff_shuffle_bytes_3012_rvv(const uint8_t *src, uint8_t *dst, int src_len);
+void ff_shuffle_bytes_3210_rvv(const uint8_t *src, uint8_t *dst, int src_len);
+
+av_cold void rgb2rgb_init_riscv(void)
+{
+#if HAVE_RVV
+int flags = av_get_cpu_flags();
+
+if (flags & AV_CPU_FLAG_RVV_I32) {
+shuffle_bytes_0321 = ff_shuffle_bytes_0321_rvv;
+shuffle_bytes_2103 = ff_shuffle_bytes_2103_rvv;
+shuffle_bytes_1230 = ff_shuffle_bytes_1230_rvv;
+shuffle_bytes_3012 = ff_shuffle_bytes_3012_rvv;
+shuffle_bytes_3210 = ff_shuffle_bytes_3210_rvv;
+}
+#endif
+}
diff --git a/libswscale/riscv/rgb2rgb_rvv.S b/libswscale/riscv/rgb2rgb_rvv.S
new file mode 100644
index 00..3eb11262c0
--- /dev/null
+++ b/libswscale/riscv/rgb2rgb_rvv.S
@@ -0,0 +1,78 @@
+/*
+ * Copyright © 2022 Rémi Denis-Courmont.
+ *
+ * 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/riscv/asm.S"
+
+func ff_shuffle_bytes_0321_rvv, zve32x
+addit1, a0, 3
+addit2, a0, 2
+addit3, a0, 1
+1:
+sraia2, a2, 2
+li  t4, 4
+2:
+vsetvlit0, a2, e8, m1, ta, ma
+suba2, a2, t0
+vlse8.vv8, (a0), t4
+sh2add a0, t0, a0
+vlse8.vv9, (t1), t4
+sh2add t1, t0, t1
+vlse8.vv10, (t2), t4
+sh2add t2, t0, t2
+v

[FFmpeg-devel] [PATCH 0/3] RISC-V V swscale pixel format conversions

2022-09-28 Thread Rémi Denis-Courmont
Hello,

This adds the pixel format conversions that appear to covered by checkasm
(plus YUYV to I422 for which a patch was sent already).

RVV has no register-register interleaving/deinterleaving instructions, so this
uses strided loads or stores instead. Another option would be full register 
move then segmented store, but that is presumably slower.

The following changes since commit d31013166ac3727ae7c7ebbb756e1e5800bc2b40:

  lavc/pixblockdsp: RISC-V diff_pixels & diff_pixels_unaligned (2022-09-28 
11:46:11 +0200)

are available in the Git repository at:

  git.remlab.net:git/ffmpeg.git rvv-swscale

for you to fetch changes up to 18edd2c3108b126fc478635ac1048db60b9d7fc4:

  sws/rgb2rgb: RISC-V 64-bit V packed YUYV/UYVY to planar 4:2:2 (2022-09-28 
18:23:53 +0300)


Rémi Denis-Courmont (3):
  sws/rgb2rgb: RISC-V V shuffle_bytes_ functions
  sws/rgb2rgb: RISC-V V interleaveBytes
  sws/rgb2rgb: RISC-V 64-bit V packed YUYV/UYVY to planar 4:2:2

 libswscale/rgb2rgb.c   |   2 +
 libswscale/rgb2rgb.h   |   1 +
 libswscale/riscv/Makefile  |   2 +
 libswscale/riscv/rgb2rgb.c |  61 
 libswscale/riscv/rgb2rgb_rvv.S | 157 +
 5 files changed, 223 insertions(+)
 create mode 100644 libswscale/riscv/Makefile
 create mode 100644 libswscale/riscv/rgb2rgb.c
 create mode 100644 libswscale/riscv/rgb2rgb_rvv.S

-- 
Реми Дёни-Курмон
http://www.remlab.net/



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

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


Re: [FFmpeg-devel] [PATCH 2/2] avformat/westwood_vqa: Check chunk size

2022-09-28 Thread Anton Khirnov
Quoting Michael Niedermayer (2022-09-22 20:08:52)
> the type is also changed to int as it is interpreted as int in av_get_packet()
> 
> Fixes: signed integer overflow: 2147483647 + 1 cannot be represented in type 
> 'int'
> Fixes: 
> 50993/clusterfuzz-testcase-minimized-ffmpeg_dem_WSVQA_fuzzer-6593408795279360
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/westwood_vqa.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)

Looks good, thank you.

-- 
Anton Khirnov
___
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] avformat/vividas: Check packet size

2022-09-28 Thread Anton Khirnov
Quoting Michael Niedermayer (2022-09-22 20:08:51)
> Fixes: signed integer overflow: 119760682 - -2084600173 cannot be represented 
> in type 'int'
> Fixes: 
> 50993/clusterfuzz-testcase-minimized-ffmpeg_dem_VIVIDAS_fuzzer-6745781167587328
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/vividas.c | 13 +++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/vividas.c b/libavformat/vividas.c
> index e9954f73ed0..e8efe49a5c0 100644
> --- a/libavformat/vividas.c
> +++ b/libavformat/vividas.c
> @@ -683,6 +683,7 @@ static int viv_read_packet(AVFormatContext *s,
>  
>  if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
>  uint64_t v_size = ffio_read_varlen(pb);
> +int last, last_start;
>  
>  if (!viv->num_audio)
>  return AVERROR_INVALIDDATA;
> @@ -704,14 +705,22 @@ static int viv_read_packet(AVFormatContext *s,
>  start = ffio_read_varlen(pb);
>  pcm_bytes = ffio_read_varlen(pb);
>  
> -if (i > 0 && start == 0)
> -break;
> +if (i > 0) {
> +if (start == 0)
> +break;
> +if (start < last || start - (unsigned)last > INT_MAX)

What is the second condition for?

-- 
Anton Khirnov
___
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] configure: Remove dcbzl check for e500v1 and e500v2 architectures

2022-09-28 Thread Peter Krefting

Rémi Denis-Courmont:


Our compiler (powerpc-btech-linux-gnuspe-gcc (crosstool-NG 1.24.0) 8.3.0)
recognizes the instruction, so the configure test succeeds, but the CPU
(e500v2) crashes if it tries to execute it.

Yes?


Indeed.


I previously had a patch (d5733936d857ce5c7d28c0bc9e89a2e2548f8895) to
suppress the instruction, but it broke at some point, this patch tries to fix
it in a slightly better way.

AFAICT, this old changeset had the exact same problem as this patch. If
somebody just compiles FFmpeg with default flags as one does, it remains
broken.


Before d5733936, ffmpeg would crash on startup on e500v2 when the 
binary tried to use the unsupported instruction (when built with 
default configuration). At d5733936 it works as the instruction is 
disabled.


At some point between d5733936 and HEAD, a default "configure" run for 
this CPU re-enabled the instruction, causing it again to crash on 
startup. Since the configure script was changed to set "disable" in 
the CPU selection header:


  e500v2)
cpuflags="-mcpu=8548 -mhard-float -mfloat-gprs=double"
disable altivec
disable dcbzl  <--- here

(which I believe came in from the avconf fork merge), my patch fixes 
the ppc-specific branch to check if it was disabled in the above 
stanza.


Normally, you would expect that the default flags result in something 
that works, if perhaps not optimally, no?


Exactly, this is what I am trying to (re-)fix.

(And yes, I know that the CPU I am running on is end-of-life, but the 
joy of working with embedded hardware is that you have to support it 
anyway.)


--
\\// Peter - http://www.softwolves.pp.se/
___
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/1] libswscale: force a minimum size of the slide for bayer sources

2022-09-28 Thread Anton Khirnov
Quoting Chema Gonzalez (2022-09-26 18:11:22)
> diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
> index 8838cc8b53..9af2e7ecc3 100644
> --- a/libswscale/swscale_unscaled.c
> +++ b/libswscale/swscale_unscaled.c
> @@ -2095,6 +2095,7 @@ void ff_get_unscaled_swscale(SwsContext *c)
>  c->convert_unscaled = rgbToPlanarRgbWrapper;
>  
>  if (isBayer(srcFormat)) {
> +c->dst_slice_align = 2;

IMO it's better to put this next to the line that sets dst_slice_align
for non-bayer cases, makes it clearer what the final value is.

-- 
Anton Khirnov
___
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/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()

2022-09-28 Thread Anton Khirnov
Quoting Tomas Härdin (2022-09-28 13:48:01)
> ons 2022-09-28 klockan 12:48 +0200 skrev Anton Khirnov:
> > 
> > +/**
> > + * Reallocate a data buffer, reusing the existing one if it is large
> > enough.
> > + *
> > + * This function is similar to av_realloc(), but optimized for cases
> > where the
> > + * buffer may grow significantly and is not expected to shrink.
> > + *
> > + * @param[in] ptr Previously allocated buffer, or `NULL`. If `ptr`
> > is `NULL`, a
> > + * new uninitialized buffer is allocated. `ptr` is invalidated when
> > this
> > + * function returns non-`NULL` and must be replaced with its return
> > value.
> > + *
> > + * @param[in,out] size Pointer to the allocated size of buffer
> > `ptr`. This
> > + * function updates `*size` to the new allocated size (which may be
> > larger than
> > + * `min_size`). `*size` is set to 0 on failure.
> > + *
> > + * @param[in] min_size Minimum size in bytes of the returned buffer.
> > + *
> > + * @return
> > + * - An allocated buffer (to be freed with `av_free()`) that is
> > large enough to
> > + *   hold at least `min_size` bytes. The first `*size` (value on
> > entry to this
> > + *   function) bytes of the buffer remain the same as the data in
> > `ptr`, the
> > + *   rest is uninitialized.
> > + * - `NULL` on failure, then `*size` is set to 0 and ptr remains
> > untouched.
> > + *
> > + * @see av_realloc()
> > + * @see av_fast_malloc()
> > + */
> > +void *av_realloc_reuse(void *ptr, size_t *size, size_t min_size);
> 
> Isn't it better to return int like av_realloc_array_reuse() and leave
> *ptr and *size untouched on error just as it does? If we're in the
> business of straightening this all out then having all functions work
> the same is less mental load down the line.

I suppose you're right, it's just more work to convert all the callers.
Will do and resend.

-- 
Anton Khirnov
___
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] avcodec/mjpegdec: fix -Wparentheses warning

2022-09-28 Thread Anton Khirnov
Quoting Zhao Zhili (2022-09-23 19:46:24)
> 
> 
> > -Original Message-
> > From: ffmpeg-devel-boun...@ffmpeg.org  On 
> > Behalf Of Rémi Denis-Courmont
> > Sent: 2022年9月23日 22:35
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: Re: [FFmpeg-devel] [PATCH] avcodec/mjpegdec: fix -Wparentheses 
> > warning
> > 
> > Le perjantaina 23. syyskuuta 2022, 20.40.30 EEST Zhao Zhili a écrit :
> > > From: Zhao Zhili 
> > >
> > > Signed-off-by: Zhao Zhili 
> > > ---
> > >  libavcodec/mjpegdec.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> > > index c594950500..d77c644d3b 100644
> > > --- a/libavcodec/mjpegdec.c
> > > +++ b/libavcodec/mjpegdec.c
> > > @@ -2866,7 +2866,7 @@ the_end:
> > >  }
> > >  }
> > >
> > > -if (e = av_dict_get(s->exif_metadata, "Orientation", e,
> > > AV_DICT_IGNORE_SUFFIX)) { +if ((e = av_dict_get(s->exif_metadata,
> > > "Orientation", e, AV_DICT_IGNORE_SUFFIX))) { char *value = e->value +
> > > strspn(e->value, " \n\t\r"), *endptr; int orientation = strtol(value,
> > > &endptr, 0);
> > 
> > Isn't it easier to read if you break the assignment out, and use the result 
> > as
> > predicate??
> 
> I prefer the coding style of splitting into two lines personally, but current 
> coding
> Style is used everywhere in the code base, so I'm not sure.

Not everywhere, it depends on the author.
I try to avoid assignments in conditions wherever possible, because they
are hard to read IMO.

-- 
Anton Khirnov
___
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] lavu: bump minor version for the RISC-V flags

2022-09-28 Thread Anton Khirnov
Forgotten in 0c0a3deb18.

Also add an APIchanges entry.
---
 doc/APIchanges  | 5 +
 libavutil/version.h | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index a6df7a231a..f32a3954a0 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,11 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-09-27 - 0c0a3deb18 - lavu 57.38.100 - cpu.h
+  Add CPU flags for RISC-V vector extensions:
+  AV_CPU_FLAG_RVV_I32, AV_CPU_FLAG_RVV_F32, AV_CPU_FLAG_RVV_I64,
+  AV_CPU_FLAG_RVV_F64
+
 2022-09-26 - xx - lavc 59.48.100 - avcodec.h
   Deprecate avcodec_enum_to_chroma_pos() and avcodec_chroma_pos_to_enum().
   Use av_chroma_location_enum_to_pos() or av_chroma_location_pos_to_enum()
diff --git a/libavutil/version.h b/libavutil/version.h
index 9c44cef6aa..5aca550f45 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  37
+#define LIBAVUTIL_VERSION_MINOR  38
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
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] [PATCH 1/2] fftools/ffmpeg: Remove unused do_deinterlace variable

2022-09-28 Thread Anton Khirnov
patches LGTM, will push

-- 
Anton Khirnov
___
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] configure: Remove dcbzl check for e500v1 and e500v2 architectures

2022-09-28 Thread Rémi Denis-Courmont
Le 28 septembre 2022 15:52:46 GMT+03:00, Peter Krefting 
 a écrit :
>Hi!
>
>>> The DCBZL instruction is not available for the e500v1 and e500v2
>>> architectures, but may still be recognized by the toolchain, so we need to
>>> remove the test for it explicitly for these architectures.
>> Isn't this the sort of thing that's supposed ti be guarded by run-time CPU
>> flags rather than in the configure script?
>
>Our compiler (powerpc-btech-linux-gnuspe-gcc (crosstool-NG 1.24.0) 8.3.0)
>recognizes the instruction, so the configure test succeeds, but the CPU
>(e500v2) crashes if it tries to execute it.

Yes?

>I previously had a patch (d5733936d857ce5c7d28c0bc9e89a2e2548f8895) to
>suppress the instruction, but it broke at some point, this patch tries to fix
>it in a slightly better way.

AFAICT, this old changeset had the exact same problem as this patch. If 
somebody just compiles FFmpeg with default flags as one does, it remains 
broken. Normally, you would expect that the default flags result in something 
that works, if perhaps not optimally, no?

I mean, the patch is basically correct in that it keeps DCBZL disabled if the 
selected CPU is known not to support it. Altivec already works the exact same 
way for that matter. But Altivec is also guarded at run-time, so it won't 
cause a crash if the target CPU is unspecified/unknown.

Br,



___
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] libavformat/flac_picture: Don't return AVERROR_INVALIDDATA for errors with flac picture mimetype

2022-09-28 Thread Anton Khirnov
Quoting James Almer (2022-09-10 03:16:32)
> On 9/9/2022 7:44 PM, Will Cassella wrote:
> > In the case where the FLAC picture MIME type is not understood, fail to
> > parse the picture silently rather than return AVERROR_INVALIDDATA.
> > 
> > This originated from a bug reported in Chromium: https://crbug.com/1052821
> > 
> > Signed-off-by: Will Cassella 
> > ---
> >   libavformat/flac_picture.c | 4 
> >   1 file changed, 4 deletions(-)
> > 
> > diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
> > index b33fee75b4..1acad9b251 100644
> > --- a/libavformat/flac_picture.c
> > +++ b/libavformat/flac_picture.c
> > @@ -68,8 +68,6 @@ int ff_flac_parse_picture(AVFormatContext *s,
> > uint8_t **bufp, int buf_size,
> >   if (len <= 0 || len >= sizeof(mimetype)) {
> >   av_log(s, AV_LOG_ERROR, "Could not read mimetype from an attached 
> > "
> >  "picture.\n");
> > -if (s->error_recognition & AV_EF_EXPLODE)
> > -return AVERROR_INVALIDDATA;
> 
> If you don't want to error out, then don't enable explode mode, which is 
> meant to abort on the slightest issue?

IMO failing to recognize the MIME type is a lavf error rather than a
file error and so should not fail, much less with AVERROR_INVALIDDATA
(should be ENOSYS if anything).

THe other error should stay though - then the file actually is broken.

-- 
Anton Khirnov
___
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 04/11] lavc/jpeg2000dec: Thread init_tile()

2022-09-28 Thread Tomas Härdin
ons 2022-09-28 klockan 12:06 +0200 skrev Tomas Härdin:
> This is the one that needs the new execute2()

A data race snuck into this one, updated patch attached.

/Tomas
From 6fc3920731950a1820f88e3ae0cf1258ae17b75d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Mon, 13 Jun 2022 15:09:17 +0200
Subject: [PATCH 04/11] lavc/jpeg2000dec: Thread init_tile()

---
 libavcodec/jpeg2000dec.c | 33 ++---
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 273346538f..a680eaa1bd 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1019,26 +1019,29 @@ static int get_ppt(Jpeg2000DecoderContext *s, int n)
 return 0;
 }
 
-static int init_tile(Jpeg2000DecoderContext *s, int tileno)
+static int init_tile(AVCodecContext *avctx, void *td,
+ int jobnr, int threadnr)
 {
-int compno;
-int tilex = tileno % s->numXtiles;
-int tiley = tileno / s->numXtiles;
-Jpeg2000Tile *tile = s->tile + tileno;
+const Jpeg2000DecoderContext *s = avctx->priv_data;
+int tileno  = jobnr / s->ncomponents;
+int tilex   = tileno % s->numXtiles;
+int tiley   = tileno / s->numXtiles;
+int compno  = jobnr % s->ncomponents;
+Jpeg2000Tile *tile  = s->tile + tileno;
+Jpeg2000Component *comp = tile->comp + compno;
+Jpeg2000CodingStyle *codsty = tile->codsty + compno;
+Jpeg2000QuantStyle  *qntsty = tile->qntsty + compno;
+int ret; // global bandno
 
 if (!tile->comp)
 return AVERROR(ENOMEM);
 
+if (compno == 0) {
 tile->coord[0][0] = av_clip(tilex   * (int64_t)s->tile_width  + s->tile_offset_x, s->image_offset_x, s->width);
 tile->coord[0][1] = av_clip((tilex + 1) * (int64_t)s->tile_width  + s->tile_offset_x, s->image_offset_x, s->width);
 tile->coord[1][0] = av_clip(tiley   * (int64_t)s->tile_height + s->tile_offset_y, s->image_offset_y, s->height);
 tile->coord[1][1] = av_clip((tiley + 1) * (int64_t)s->tile_height + s->tile_offset_y, s->image_offset_y, s->height);
-
-for (compno = 0; compno < s->ncomponents; compno++) {
-Jpeg2000Component *comp = tile->comp + compno;
-Jpeg2000CodingStyle *codsty = tile->codsty + compno;
-Jpeg2000QuantStyle  *qntsty = tile->qntsty + compno;
-int ret; // global bandno
+}
 
 comp->coord_o[0][0] = tile->coord[0][0];
 comp->coord_o[0][1] = tile->coord[0][1];
@@ -1063,7 +1066,7 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
  s->cbps[compno], s->cdx[compno],
  s->cdy[compno], s->avctx, s->slices))
 return ret;
-}
+
 return 0;
 }
 
@@ -2371,9 +2374,6 @@ static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s)
 for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) {
 Jpeg2000Tile *tile = s->tile + tileno;
 
-if ((ret = init_tile(s, tileno)) < 0)
-return ret;
-
 if ((ret = jpeg2000_decode_packets(s, tile)) < 0)
 return ret;
 }
@@ -2668,6 +2668,9 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
 picture->key_frame = 1;
 s->slices = avctx->active_thread_type == FF_THREAD_SLICE ? avctx->thread_count : 1;
 
+if ((ret = avctx->execute2(avctx, init_tile, NULL, NULL, s->numXtiles * s->numYtiles * s->ncomponents)) < 0)
+goto end;
+
 if (ret = jpeg2000_read_bitstream_packets(s))
 goto end;
 
-- 
2.30.2

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

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


Re: [FFmpeg-devel] [PATCH] lavf/async: Fix wrapped_url_read return value

2022-09-28 Thread Anton Khirnov
Quoting Guangyu Sun (2022-09-19 07:22:39)
> This fixes a regression from commit 36117968ad.
> 
> wrapped_url_read() used to be able to return positive number from
> ffurl_read(). It relies on the result to check if EOF is reached in
> async_buffer_task().
> 
> Test case:
>   ffmpeg -f lavfi -i testsrc -t 1 test.mp4
>   ffmpeg -i async:test.mp4
> 
> Signed-off-by: Guangyu Sun 
> ---
>  libavformat/async.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/async.c b/libavformat/async.c
> index 547417aa1e..a929f4d16e 100644
> --- a/libavformat/async.c
> +++ b/libavformat/async.c
> @@ -139,7 +139,7 @@ static int wrapped_url_read(void *src, void *dst, size_t 
> *size)
>  *size = ret > 0 ? ret : 0;
>  c->inner_io_error = ret < 0 ? ret : 0;
>  
> -return c->inner_io_error;
> +return ret;

This is wrong, FIFO callbacks must return 0 on success. This should be
handled in ring_write() instead.

-- 
Anton Khirnov
___
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 2/5] avutil/pixdesc: Avoid direct access to pix fmt desc array

2022-09-28 Thread Andreas Rheinhardt
Anton Khirnov:
> Quoting Andreas Rheinhardt (2022-09-26 21:58:55)
>> Instead use av_pix_fmt_desc_next(). It is still possible
>> to check its return values by comparing it with the
>> (currently) expected values and the code does so.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>  libavutil/pixdesc.c | 17 -
>>  1 file changed, 12 insertions(+), 5 deletions(-)
>>
>> diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
>> index c42a0242c5..f6755f41df 100644
>> --- a/libavutil/pixdesc.c
>> +++ b/libavutil/pixdesc.c
>> @@ -2913,10 +2913,10 @@ int av_pix_fmt_count_planes(enum AVPixelFormat 
>> pix_fmt)
>>  }
>>  
>>  void ff_check_pixfmt_descriptors(void){
>> -int i, j;
>> +const AVPixFmtDescriptor *d, *last = NULL;
>> +int i;
>>  
>> -for (i=0; i> -const AVPixFmtDescriptor *d = &av_pix_fmt_descriptors[i];
>> +for (i = AV_PIX_FMT_NONE, d = NULL; i++, d = av_pix_fmt_desc_next(d);) {
>>  uint8_t fill[4][8+6+3] = {{0}};
>>  uint8_t *data[4] = {fill[0], fill[1], fill[2], fill[3]};
>>  int linesize[4] = {0,0,0,0};
>> @@ -2927,9 +2927,15 @@ void ff_check_pixfmt_descriptors(void){
>>  av_assert0(d->log2_chroma_w <= 3);
>>  av_assert0(d->log2_chroma_h <= 3);
>>  av_assert0(d->nb_components <= 4);
>> -av_assert2(av_get_pix_fmt(d->name) == i);
>> +av_assert2(av_get_pix_fmt(d->name) == av_pix_fmt_desc_get_id(d));
>> +
>> +/* The following two checks as well as the one after the loop
>> + * would need to be changed if we changed the way the descriptors
>> + * are stored. */
>> +av_assert0(i == av_pix_fmt_desc_get_id(d));
>> +av_assert0(!last || last + 1 == d);
> 
> Don't see last being set.
> 

Correct. Will fix.

- 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 2/5] avutil/pixdesc: Avoid direct access to pix fmt desc array

2022-09-28 Thread Anton Khirnov
Quoting Andreas Rheinhardt (2022-09-26 21:58:55)
> Instead use av_pix_fmt_desc_next(). It is still possible
> to check its return values by comparing it with the
> (currently) expected values and the code does so.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavutil/pixdesc.c | 17 -
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
> index c42a0242c5..f6755f41df 100644
> --- a/libavutil/pixdesc.c
> +++ b/libavutil/pixdesc.c
> @@ -2913,10 +2913,10 @@ int av_pix_fmt_count_planes(enum AVPixelFormat 
> pix_fmt)
>  }
>  
>  void ff_check_pixfmt_descriptors(void){
> -int i, j;
> +const AVPixFmtDescriptor *d, *last = NULL;
> +int i;
>  
> -for (i=0; i -const AVPixFmtDescriptor *d = &av_pix_fmt_descriptors[i];
> +for (i = AV_PIX_FMT_NONE, d = NULL; i++, d = av_pix_fmt_desc_next(d);) {
>  uint8_t fill[4][8+6+3] = {{0}};
>  uint8_t *data[4] = {fill[0], fill[1], fill[2], fill[3]};
>  int linesize[4] = {0,0,0,0};
> @@ -2927,9 +2927,15 @@ void ff_check_pixfmt_descriptors(void){
>  av_assert0(d->log2_chroma_w <= 3);
>  av_assert0(d->log2_chroma_h <= 3);
>  av_assert0(d->nb_components <= 4);
> -av_assert2(av_get_pix_fmt(d->name) == i);
> +av_assert2(av_get_pix_fmt(d->name) == av_pix_fmt_desc_get_id(d));
> +
> +/* The following two checks as well as the one after the loop
> + * would need to be changed if we changed the way the descriptors
> + * are stored. */
> +av_assert0(i == av_pix_fmt_desc_get_id(d));
> +av_assert0(!last || last + 1 == d);

Don't see last being set.

-- 
Anton Khirnov
___
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] configure: Remove dcbzl check for e500v1 and e500v2 architectures

2022-09-28 Thread Peter Krefting

Hi!


The DCBZL instruction is not available for the e500v1 and e500v2
architectures, but may still be recognized by the toolchain, so we need to
remove the test for it explicitly for these architectures.

Isn't this the sort of thing that's supposed ti be guarded by run-time CPU 
flags rather than in the configure script?


Our compiler (powerpc-btech-linux-gnuspe-gcc (crosstool-NG 1.24.0) 
8.3.0) recognizes the instruction, so the configure test succeeds, but 
the CPU (e500v2) crashes if it tries to execute it.


I previously had a patch (d5733936d857ce5c7d28c0bc9e89a2e2548f8895) to 
suppress the instruction, but it broke at some point, this patch tries 
to fix it in a slightly better way.


Having said that, the test is there due to the fix in 
a4adb60858f1fa0b35b08576ea34e531f0f83459 (from 2003), and disabling the 
instruction does not bring back the old optimizations as it just expects 
it not to work at all. But for our purposes this is not as important as h

aving a working library.

--
\\// Peter - http://www.softwolves.pp.se/
___
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/aarch64: Add neon implementation for pix_abs8 functions.

2022-09-28 Thread Grzegorz Bernacki
Hi Martin,

I resent the patchset, because the first try did not reach ffmpeg-devel
maillist. I apologize, I should have mentioned about that in cover letter.
Thanks a lot for your review, I will apply the changes and send v2 soon.

thanks,
grzegorz

śr., 28 wrz 2022 o 11:07 Martin Storsjö  napisał(a):

> On Mon, 26 Sep 2022, Grzegorz Bernacki wrote:
>
> > Provide optimized implementation of pix_abs8 function for arm64.
> >
> > Performance comparison tests are shown below:
> > pix_abs_1_1_c: 162.5
> > pix_abs_1_1_neon: 27.0
> > pix_abs_1_2_c: 174.0
> > pix_abs_1_2_neon: 23.5
> > pix_abs_1_3_c: 203.2
> > pix_abs_1_3_neon: 34.7
> >
> > Benchmarks and tests are run with checkasm tool on AWS Graviton 3.
> >
> > Signed-off-by: Grzegorz Bernacki 
> > ---
> > libavcodec/aarch64/me_cmp_init_aarch64.c |   9 ++
> > libavcodec/aarch64/me_cmp_neon.S | 193 +++
> > 2 files changed, 202 insertions(+)
>
> I don't see any changes compared to the version you sent last week? If
> reposting a patchset, please do mention what has changed - or ping the old
> one. (I had it on my radar to review, but reviews of larger amounts of
> code doesn't happen immediately, unfortunately.)
>
> Overall, you seem to have mixed in tabs among regular spaces. Please do
> fix that. (I would have kinda expected us to have a fate test that checks
> this, but apparently we don't.)
>
> > diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c
> b/libavcodec/aarch64/me_cmp_init_aarch64.c
> > index e143f0816e..3459403ee5 100644
> > --- a/libavcodec/aarch64/me_cmp_init_aarch64.c
> > +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c
> > @@ -59,6 +59,12 @@ int pix_median_abs16_neon(MpegEncContext *v, const
> uint8_t *pix1, const uint8_t
> >   ptrdiff_t stride, int h);
> > int pix_median_abs8_neon(MpegEncContext *v, const uint8_t *pix1, const
> uint8_t *pix2,
> >  ptrdiff_t stride, int h);
> > +int ff_pix_abs8_x2_neon(MpegEncContext *v, const uint8_t *pix1, const
> uint8_t *pix2,
> > +ptrdiff_t stride, int h);
> > +int ff_pix_abs8_y2_neon(MpegEncContext *v, const uint8_t *pix1, const
> uint8_t *pix2,
> > +ptrdiff_t stride, int h);
> > +int ff_pix_abs8_xy2_neon(MpegEncContext *v, const uint8_t *pix1, const
> uint8_t *pix2,
> > + ptrdiff_t stride, int h);
> >
> > av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext
> *avctx)
> > {
> > @@ -70,6 +76,9 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c,
> AVCodecContext *avctx)
> > c->pix_abs[0][2] = ff_pix_abs16_y2_neon;
> > c->pix_abs[0][3] = ff_pix_abs16_xy2_neon;
> > c->pix_abs[1][0] = ff_pix_abs8_neon;
> > + c->pix_abs[1][1] = ff_pix_abs8_x2_neon;
> > + c->pix_abs[1][2] = ff_pix_abs8_y2_neon;
> > + c->pix_abs[1][3] = ff_pix_abs8_xy2_neon;
>
> In most mediums, the diff here shows that there's something off - tabs.
>
> >
> > c->sad[0] = ff_pix_abs16_neon;
> > c->sad[1] = ff_pix_abs8_neon;
> > diff --git a/libavcodec/aarch64/me_cmp_neon.S
> b/libavcodec/aarch64/me_cmp_neon.S
> > index 11af4849f9..e03c0c26cd 100644
> > --- a/libavcodec/aarch64/me_cmp_neon.S
> > +++ b/libavcodec/aarch64/me_cmp_neon.S
> > @@ -119,6 +119,199 @@ function ff_pix_abs8_neon, export=1
> > ret
> > endfunc
> >
> > +function ff_pix_abs8_x2_neon, export=1
> > +// x0   unused
> > +// x1   uint8_t *pix1
> > +// x2   uint8_t *pix2
> > +// x3   ptrdiff_t stride
> > +// w4   int h
> > +
> > +cmp w4, #4
> > +moviv26.8h, #0
> > +add x5, x2, #1 // pix2 + 1
> > +b.lt2f
> > +
> > +// make 4 iterations at once
> > +1:
> > +ld1 {v1.8b}, [x2], x3
> > +ld1 {v2.8b}, [x5], x3
> > +ld1 {v0.8b}, [x1], x3
> > +ld1 {v4.8b}, [x2], x3
> > + urhadd  v30.8b, v1.8b, v2.8b
> > +ld1 {v5.8b}, [x5], x3
> > +uabal   v26.8h, v0.8b, v30.8b
> > +ld1 {v6.8b}, [x1], x3
> > + urhadd  v29.8b, v4.8b, v5.8b
> > +ld1 {v7.8b}, [x2], x3
> > +ld1 {v20.8b}, [x5], x3
> > +uabal   v26.8h, v6.8b, v29.8b
> > +ld1 {v21.8b}, [x1], x3
> > + urhadd  v28.8b, v7.8b, v20.8b
> > +ld1 {v22.8b}, [x2], x3
> > +ld1 {v23.8b}, [x5], x3
> > +uabal   v26.8h, v21.8b, v28.8b
> > +sub w4, w4, #4
> > +ld1 {v24.8b}, [x1], x3
> > + urhadd  v27.8b, v22.8b, v23.8b
> > +cmp w4, #4
> > +uabal   v26.8h, v24.8b, v27.8b
> > +
> > +b.ge1b
> > +cbz w4, 3f
> > +
> > +// iterate by one
> > +2:
> > +

Re: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()

2022-09-28 Thread Tomas Härdin
ons 2022-09-28 klockan 12:48 +0200 skrev Anton Khirnov:
> 
> +/**
> + * Reallocate a data buffer, reusing the existing one if it is large
> enough.
> + *
> + * This function is similar to av_realloc(), but optimized for cases
> where the
> + * buffer may grow significantly and is not expected to shrink.
> + *
> + * @param[in] ptr Previously allocated buffer, or `NULL`. If `ptr`
> is `NULL`, a
> + * new uninitialized buffer is allocated. `ptr` is invalidated when
> this
> + * function returns non-`NULL` and must be replaced with its return
> value.
> + *
> + * @param[in,out] size Pointer to the allocated size of buffer
> `ptr`. This
> + * function updates `*size` to the new allocated size (which may be
> larger than
> + * `min_size`). `*size` is set to 0 on failure.
> + *
> + * @param[in] min_size Minimum size in bytes of the returned buffer.
> + *
> + * @return
> + * - An allocated buffer (to be freed with `av_free()`) that is
> large enough to
> + *   hold at least `min_size` bytes. The first `*size` (value on
> entry to this
> + *   function) bytes of the buffer remain the same as the data in
> `ptr`, the
> + *   rest is uninitialized.
> + * - `NULL` on failure, then `*size` is set to 0 and ptr remains
> untouched.
> + *
> + * @see av_realloc()
> + * @see av_fast_malloc()
> + */
> +void *av_realloc_reuse(void *ptr, size_t *size, size_t min_size);

Isn't it better to return int like av_realloc_array_reuse() and leave
*ptr and *size untouched on error just as it does? If we're in the
business of straightening this all out then having all functions work
the same is less mental load down the line.

/Tomas

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

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


Re: [FFmpeg-devel] [PATCH 3/8] avutil/mem: Add av_fast_realloc_array()

2022-09-28 Thread Tomas Härdin
ons 2022-09-28 klockan 13:06 +0200 skrev Andreas Rheinhardt:
> Tomas Härdin:
> > tis 2022-09-27 klockan 17:23 +0200 skrev Tomas Härdin:
> > > mån 2022-09-26 klockan 16:24 +0200 skrev Tomas Härdin:
> > > > mån 2022-09-26 klockan 14:25 +0200 skrev Andreas Rheinhardt:
> > > > > Anton Khirnov:
> > > > > > Quoting Andreas Rheinhardt (2022-07-14 14:51:07)
> > > > > > > Anton Khirnov:
> > > > > > > > Quoting Andreas Rheinhardt (2022-07-12 16:12:16)
> > > > > > > > > Anton really dislikes the av_fast_* naming and
> > > > > > > > > instead
> > > > > > > > > wants
> > > > > > > > > this to be
> > > > > > > > > called av_realloc_array_reuse(). I don't care either
> > > > > > > > > way.
> > > > > > > > > Any
> > > > > > > > > more
> > > > > > > > > opinions on this (or on the patch itself)?
> > > > > > > > 
> > > > > > > > If people dislike _reuse(), I am open to other
> > > > > > > > reasonable
> > > > > > > > suggestions.
> > > > > > > > This 'fast' naming sucks because
> > > > > > > > - it tells you nothing about how this function is
> > > > > > > > "fast"
> > > > > > > > - it is added at the beginning rather than the end,
> > > > > > > > which
> > > > > > > > is
> > > > > > > >   against standard namespacing conventions
> > > > > > > > 
> > > > > > > 
> > > > > > > Isn't reusing the basic modus operandi for a reallocation
> > > > > > > function? So
> > > > > > > your suggested name doesn't seem to fit either.
> > > > > > 
> > > > > > Ordinary realloc just keeps the data, I wouldn't call that
> > > > > > "reuse"
> > > > > > since
> > > > > > it will often be a copy. This "fast" realloc OTOH reuses
> > > > > > the
> > > > > > actual
> > > > > > buffer, same as all the other "fast" mem.h functions.
> > > > > > 
> > > > > > But feel free to suggest another naming pattern if you can
> > > > > > think
> > > > > > of
> > > > > > one.
> > > > > > 
> > > > > 
> > > > > I see two differences between this function and ordinary
> > > > > realloc:
> > > > > It
> > > > > never shrinks the buffer and it overallocates. These two
> > > > > properties
> > > > > make
> > > > > it more likely that these functions can avoid copies more
> > > > > often
> > > > > than
> > > > > plain realloc (but in contrast to realloc, we can not grow
> > > > > the
> > > > > buffer
> > > > > in
> > > > > case there is free space after it), but it is nevertheless
> > > > > the
> > > > > same
> > > > > as
> > > > > realloc.
> > > > > 
> > > > > But I don't really care that much about the name and will
> > > > > therefore
> > > > > use
> > > > > your name as I can't come up with anything better.
> > > > > (Of course, I am still open to alternative suggestions.)
> > > > > 
> > > > > - Andreas
> > > > 
> > > > So this means av_realloc_array_reuse()? Eh, it works. I will
> > > > add a
> > > > function that also zeroes the newly allocated space, what
> > > > should we
> > > > call that? av_realloc_array_reusez()?
> > > > av_realloc_array_reuse_zerofill()?
> > > 
> > > Here's a draft patch that calls it av_reallocz_array_reuse().
> > > Needs a
> > > minor version bump of course
> > 
> > This makes me realize something: av_realloc_array_reuse() requires
> > that
> > *nb_allocated == 0 initially but this isn't specified in the
> > documentation. Patch attached relaxes this.
> > 
> 
> * @param[in,out] nb_allocated  Pointer to the number of elements of
> the
> array
> *  `*ptr`. `*nb_allocated` is updated to
> the new
> *  number of allocated elements.
> 
> If *ptr == NULL, then the number of elements of said array is (of
> course) zero, so *nb_allocated has to be set to that.

Keep in mind av_malloc(0) and av_realloc(ptr, 0) are both legal and
will allocate one byte. Seems it's not a problem in this case luckily

> (But if you think
> that this needs to be said explicitly, I can document it.)

It's best to be explicit IMO, so that callers know they can't just use
an uninitialized size_t on the stack or something.

/Tomas

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

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


Re: [FFmpeg-devel] [PATCH 3/8] avutil/mem: Add av_fast_realloc_array()

2022-09-28 Thread Andreas Rheinhardt
Tomas Härdin:
> tis 2022-09-27 klockan 17:23 +0200 skrev Tomas Härdin:
>> mån 2022-09-26 klockan 16:24 +0200 skrev Tomas Härdin:
>>> mån 2022-09-26 klockan 14:25 +0200 skrev Andreas Rheinhardt:
 Anton Khirnov:
> Quoting Andreas Rheinhardt (2022-07-14 14:51:07)
>> Anton Khirnov:
>>> Quoting Andreas Rheinhardt (2022-07-12 16:12:16)
 Anton really dislikes the av_fast_* naming and instead
 wants
 this to be
 called av_realloc_array_reuse(). I don't care either way.
 Any
 more
 opinions on this (or on the patch itself)?
>>>
>>> If people dislike _reuse(), I am open to other reasonable
>>> suggestions.
>>> This 'fast' naming sucks because
>>> - it tells you nothing about how this function is "fast"
>>> - it is added at the beginning rather than the end, which
>>> is
>>>   against standard namespacing conventions
>>>
>>
>> Isn't reusing the basic modus operandi for a reallocation
>> function? So
>> your suggested name doesn't seem to fit either.
>
> Ordinary realloc just keeps the data, I wouldn't call that
> "reuse"
> since
> it will often be a copy. This "fast" realloc OTOH reuses the
> actual
> buffer, same as all the other "fast" mem.h functions.
>
> But feel free to suggest another naming pattern if you can
> think
> of
> one.
>

 I see two differences between this function and ordinary realloc:
 It
 never shrinks the buffer and it overallocates. These two
 properties
 make
 it more likely that these functions can avoid copies more often
 than
 plain realloc (but in contrast to realloc, we can not grow the
 buffer
 in
 case there is free space after it), but it is nevertheless the
 same
 as
 realloc.

 But I don't really care that much about the name and will
 therefore
 use
 your name as I can't come up with anything better.
 (Of course, I am still open to alternative suggestions.)

 - Andreas
>>>
>>> So this means av_realloc_array_reuse()? Eh, it works. I will add a
>>> function that also zeroes the newly allocated space, what should we
>>> call that? av_realloc_array_reusez()?
>>> av_realloc_array_reuse_zerofill()?
>>
>> Here's a draft patch that calls it av_reallocz_array_reuse(). Needs a
>> minor version bump of course
> 
> This makes me realize something: av_realloc_array_reuse() requires that
> *nb_allocated == 0 initially but this isn't specified in the
> documentation. Patch attached relaxes this.
> 

* @param[in,out] nb_allocated  Pointer to the number of elements of the
array
*  `*ptr`. `*nb_allocated` is updated to the new
*  number of allocated elements.

If *ptr == NULL, then the number of elements of said array is (of
course) zero, so *nb_allocated has to be set to that. (But if you think
that this needs to be said explicitly, I can document it.)

- Andreas

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

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


Re: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()

2022-09-28 Thread Rémi Denis-Courmont
Le 28 septembre 2022 13:51:43 GMT+03:00, "Rémi Denis-Courmont" 
 a écrit :
>Le 28 septembre 2022 13:48:49 GMT+03:00, Anton Khirnov  a 
>écrit :
>>It uses size_t rather than unsigned for the size and conforms to our
>>standard naming scheme.
>>---
>> configure   |  5 -
>> doc/APIchanges  |  3 +++
>> libavutil/mem.c | 30 ++
>> libavutil/mem.h | 37 +++--
>> libavutil/version.h |  3 ++-
>> 5 files changed, 74 insertions(+), 4 deletions(-)
>>
>>diff --git a/configure b/configure
>>index 6712d045d9..fd0e6ae032 100755
>>--- a/configure
>>+++ b/configure
>>@@ -4360,7 +4360,10 @@ case "$toolchain" in
>> target_exec_default="valgrind"
>> case "$toolchain" in
>> valgrind-massif)
>>-target_exec_args="--tool=massif --alloc-fn=av_malloc 
>>--alloc-fn=av_mallocz --alloc-fn=av_calloc --alloc-fn=av_fast_padded_malloc 
>>--alloc-fn=av_fast_malloc --alloc-fn=av_realloc_f --alloc-fn=av_fast_realloc 
>>--alloc-fn=av_realloc"
>>+target_exec_args="--tool=massif"
>>+for func in av_malloc av_mallocz av_calloc 
>>av_fast_padded_malloc av_fast_malloc av_realloc_f av_fast_realloc av_realloc 
>>av_realloc_reuse; do
>>+target_exec_args="$target_exec_args --alloc-fn=$func"
>>+done
>> ;;
>> valgrind-memcheck)
>> target_exec_args="--error-exitcode=1 --malloc-fill=0x2a 
>> --track-origins=yes --leak-check=full --gen-suppressions=all 
>> --suppressions=$source_path/tests/fate-valgrind.supp"
>>diff --git a/doc/APIchanges b/doc/APIchanges
>>index b0a41c9e37..9a735c27e7 100644
>>--- a/doc/APIchanges
>>+++ b/doc/APIchanges
>>@@ -14,6 +14,9 @@ libavutil: 2021-04-27
>> 
>> API changes, most recent first:
>> 
>>+2022-xx-xx - xx - lavu 57.38.100 - mem.h
>>+  Add av_realloc_reuse(), deprecate av_fast_realloc().
>>+
>> 2022-09-26 - xx - lavc 59.48.100 - avcodec.h
>>   Deprecate avcodec_enum_to_chroma_pos() and avcodec_chroma_pos_to_enum().
>>   Use av_chroma_location_enum_to_pos() or av_chroma_location_pos_to_enum()
>>diff --git a/libavutil/mem.c b/libavutil/mem.c
>>index 18aff5291f..51fdc9155f 100644
>>--- a/libavutil/mem.c
>>+++ b/libavutil/mem.c
>>@@ -502,6 +502,35 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
>> }
>> }
>> 
>>+void *av_realloc_reuse(void *ptr, size_t *size, size_t min_size)
>>+{
>>+size_t max_size;
>>+
>>+if (min_size <= *size)
>>+return ptr;
>>+
>>+max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
>>+
>>+if (min_size > max_size) {
>>+*size = 0;
>>+return NULL;
>
>Isn't this leaking the existing allocation?
>
>>+}
>>+
>>+min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, 
>>min_size));
>>+
>>+ptr = av_realloc(ptr, min_size);
>>+/* we could set this to the unmodified min_size but this is safer
>>+ * if the user lost the ptr and uses NULL now
>>+ */
>>+if (!ptr)
>>+min_size = 0;
>>+
>>+*size = min_size;
>>+
>>+return ptr;
>>+}
>>+
>>+#if FF_API_FAST_ALLOC
>> void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
>> {
>> size_t max_size;
>>@@ -531,6 +560,7 @@ void *av_fast_realloc(void *ptr, unsigned int *size, 
>>size_t min_size)
>> 
>> return ptr;
>> }
>>+#endif
>> 
>> static inline void fast_malloc(void *ptr, unsigned int *size, size_t 
>> min_size, int zero_realloc)
>> {
>>diff --git a/libavutil/mem.h b/libavutil/mem.h
>>index d91174196c..deb440ca1a 100644
>>--- a/libavutil/mem.h
>>+++ b/libavutil/mem.h
>>@@ -264,7 +264,7 @@ void *av_mallocz_array(size_t nmemb, size_t size) 
>>av_malloc_attrib av_alloc_size
>>  * @warning Unlike av_malloc(), the returned pointer is not guaranteed to be
>>  *  correctly aligned. The returned pointer must be freed after even
>>  *  if size is zero.
>>- * @see av_fast_realloc()
>>+ * @see av_realloc_reuse()
>>  * @see av_reallocp()
>>  */
>> void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
>>@@ -346,6 +346,35 @@ av_alloc_size(2, 3) void *av_realloc_array(void *ptr, 
>>size_t nmemb, size_t size)
>>  */
>> int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
>> 
>>+/**
>>+ * Reallocate a data buffer, reusing the existing one if it is large enough.
>>+ *
>>+ * This function is similar to av_realloc(), but optimized for cases where 
>>the
>>+ * buffer may grow significantly and is not expected to shrink.
>>+ *
>>+ * @param[in] ptr Previously allocated buffer, or `NULL`. If `ptr` is 
>>`NULL`, a
>>+ * new uninitialized buffer is allocated. `ptr` is invalidated when this
>>+ * function returns non-`NULL` and must be replaced with its return value.
>>+ *
>>+ * @param[in,out] size Pointer to the allocated size of buffer `ptr`. This
>>+ * function updates `*size` to the new allocated size (which may be larger 
>>than
>>+ * `min_size`). `*size` is set to 0 on failu

Re: [FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()

2022-09-28 Thread Rémi Denis-Courmont
Le 28 septembre 2022 13:48:49 GMT+03:00, Anton Khirnov  a 
écrit :
>It uses size_t rather than unsigned for the size and conforms to our
>standard naming scheme.
>---
> configure   |  5 -
> doc/APIchanges  |  3 +++
> libavutil/mem.c | 30 ++
> libavutil/mem.h | 37 +++--
> libavutil/version.h |  3 ++-
> 5 files changed, 74 insertions(+), 4 deletions(-)
>
>diff --git a/configure b/configure
>index 6712d045d9..fd0e6ae032 100755
>--- a/configure
>+++ b/configure
>@@ -4360,7 +4360,10 @@ case "$toolchain" in
> target_exec_default="valgrind"
> case "$toolchain" in
> valgrind-massif)
>-target_exec_args="--tool=massif --alloc-fn=av_malloc 
>--alloc-fn=av_mallocz --alloc-fn=av_calloc --alloc-fn=av_fast_padded_malloc 
>--alloc-fn=av_fast_malloc --alloc-fn=av_realloc_f --alloc-fn=av_fast_realloc 
>--alloc-fn=av_realloc"
>+target_exec_args="--tool=massif"
>+for func in av_malloc av_mallocz av_calloc 
>av_fast_padded_malloc av_fast_malloc av_realloc_f av_fast_realloc av_realloc 
>av_realloc_reuse; do
>+target_exec_args="$target_exec_args --alloc-fn=$func"
>+done
> ;;
> valgrind-memcheck)
> target_exec_args="--error-exitcode=1 --malloc-fill=0x2a 
> --track-origins=yes --leak-check=full --gen-suppressions=all 
> --suppressions=$source_path/tests/fate-valgrind.supp"
>diff --git a/doc/APIchanges b/doc/APIchanges
>index b0a41c9e37..9a735c27e7 100644
>--- a/doc/APIchanges
>+++ b/doc/APIchanges
>@@ -14,6 +14,9 @@ libavutil: 2021-04-27
> 
> API changes, most recent first:
> 
>+2022-xx-xx - xx - lavu 57.38.100 - mem.h
>+  Add av_realloc_reuse(), deprecate av_fast_realloc().
>+
> 2022-09-26 - xx - lavc 59.48.100 - avcodec.h
>   Deprecate avcodec_enum_to_chroma_pos() and avcodec_chroma_pos_to_enum().
>   Use av_chroma_location_enum_to_pos() or av_chroma_location_pos_to_enum()
>diff --git a/libavutil/mem.c b/libavutil/mem.c
>index 18aff5291f..51fdc9155f 100644
>--- a/libavutil/mem.c
>+++ b/libavutil/mem.c
>@@ -502,6 +502,35 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
> }
> }
> 
>+void *av_realloc_reuse(void *ptr, size_t *size, size_t min_size)
>+{
>+size_t max_size;
>+
>+if (min_size <= *size)
>+return ptr;
>+
>+max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
>+
>+if (min_size > max_size) {
>+*size = 0;
>+return NULL;

Isn't this leaking the existing allocation?

>+}
>+
>+min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, 
>min_size));
>+
>+ptr = av_realloc(ptr, min_size);
>+/* we could set this to the unmodified min_size but this is safer
>+ * if the user lost the ptr and uses NULL now
>+ */
>+if (!ptr)
>+min_size = 0;
>+
>+*size = min_size;
>+
>+return ptr;
>+}
>+
>+#if FF_API_FAST_ALLOC
> void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
> {
> size_t max_size;
>@@ -531,6 +560,7 @@ void *av_fast_realloc(void *ptr, unsigned int *size, 
>size_t min_size)
> 
> return ptr;
> }
>+#endif
> 
> static inline void fast_malloc(void *ptr, unsigned int *size, size_t 
> min_size, int zero_realloc)
> {
>diff --git a/libavutil/mem.h b/libavutil/mem.h
>index d91174196c..deb440ca1a 100644
>--- a/libavutil/mem.h
>+++ b/libavutil/mem.h
>@@ -264,7 +264,7 @@ void *av_mallocz_array(size_t nmemb, size_t size) 
>av_malloc_attrib av_alloc_size
>  * @warning Unlike av_malloc(), the returned pointer is not guaranteed to be
>  *  correctly aligned. The returned pointer must be freed after even
>  *  if size is zero.
>- * @see av_fast_realloc()
>+ * @see av_realloc_reuse()
>  * @see av_reallocp()
>  */
> void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
>@@ -346,6 +346,35 @@ av_alloc_size(2, 3) void *av_realloc_array(void *ptr, 
>size_t nmemb, size_t size)
>  */
> int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
> 
>+/**
>+ * Reallocate a data buffer, reusing the existing one if it is large enough.
>+ *
>+ * This function is similar to av_realloc(), but optimized for cases where the
>+ * buffer may grow significantly and is not expected to shrink.
>+ *
>+ * @param[in] ptr Previously allocated buffer, or `NULL`. If `ptr` is `NULL`, 
>a
>+ * new uninitialized buffer is allocated. `ptr` is invalidated when this
>+ * function returns non-`NULL` and must be replaced with its return value.
>+ *
>+ * @param[in,out] size Pointer to the allocated size of buffer `ptr`. This
>+ * function updates `*size` to the new allocated size (which may be larger 
>than
>+ * `min_size`). `*size` is set to 0 on failure.
>+ *
>+ * @param[in] min_size Minimum size in bytes of the returned buffer.
>+ *
>+ * @return
>+ * - An allocated buffer (to be freed with `av_free()`) that is large enough 
>to
>+ *   hold at least `min_size` b

[FFmpeg-devel] [PATCH 2/6] lavu: replace av_fast_realloc() with av_realloc_reuse()

2022-09-28 Thread Anton Khirnov
---
 libavutil/hwcontext_vulkan.c |  6 +++---
 libavutil/tx.c   |  6 +++---
 libavutil/vulkan.c   | 40 ++--
 libavutil/vulkan.h   | 18 
 4 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index f1db1c7291..907f3ecc77 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -65,7 +65,7 @@ typedef struct VulkanQueueCtx {
 /* Buffer dependencies */
 AVBufferRef **buf_deps;
 int nb_buf_deps;
-int buf_deps_alloc_size;
+size_t buf_deps_alloc_size;
 } VulkanQueueCtx;
 
 typedef struct VulkanExecCtx {
@@ -1226,8 +1226,8 @@ static int add_buf_dep_exec_ctx(AVHWFramesContext *hwfc, 
VulkanExecCtx *cmd,
 if (!deps || !nb_deps)
 return 0;
 
-dst = av_fast_realloc(q->buf_deps, &q->buf_deps_alloc_size,
-  (q->nb_buf_deps + nb_deps) * sizeof(*dst));
+dst = av_realloc_reuse(q->buf_deps, &q->buf_deps_alloc_size,
+   (q->nb_buf_deps + nb_deps) * sizeof(*dst));
 if (!dst)
 goto err;
 
diff --git a/libavutil/tx.c b/libavutil/tx.c
index 0c16ecffc3..2ea56a732b 100644
--- a/libavutil/tx.c
+++ b/libavutil/tx.c
@@ -443,7 +443,7 @@ av_cold int ff_tx_init_subtx(AVTXContext *s, enum AVTXType 
type,
 int ret = 0;
 AVTXContext *sub = NULL;
 TXCodeletMatch *cd_tmp, *cd_matches = NULL;
-unsigned int cd_matches_size = 0;
+size_t cd_matches_size = 0;
 int nb_cd_matches = 0;
 #if !CONFIG_SMALL
 AVBPrint bp = { 0 };
@@ -533,8 +533,8 @@ av_cold int ff_tx_init_subtx(AVTXContext *s, enum AVTXType 
type,
 continue;
 
 /* Realloc array and append */
-cd_tmp = av_fast_realloc(cd_matches, &cd_matches_size,
- sizeof(*cd_tmp) * (nb_cd_matches + 1));
+cd_tmp = av_realloc_reuse(cd_matches, &cd_matches_size,
+  sizeof(*cd_tmp) * (nb_cd_matches + 1));
 if (!cd_tmp) {
 av_free(cd_matches);
 return AVERROR(ENOMEM);
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 403f0b1f27..d70bc2e2af 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -284,8 +284,8 @@ int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer *buf, 
uint8_t *mem[],
 };
 if (buf[i].flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
 continue;
-inval_list = av_fast_realloc(s->scratch, &s->scratch_size,
- (++inval_count)*sizeof(*inval_list));
+inval_list = av_realloc_reuse(s->scratch, &s->scratch_size,
+  (++inval_count)*sizeof(*inval_list));
 if (!inval_list)
 return AVERROR(ENOMEM);
 inval_list[inval_count - 1] = ival_buf;
@@ -322,8 +322,8 @@ int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer 
*buf, int nb_buffers,
 };
 if (buf[i].flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
 continue;
-flush_list = av_fast_realloc(s->scratch, &s->scratch_size,
- (++flush_count)*sizeof(*flush_list));
+flush_list = av_realloc_reuse(s->scratch, &s->scratch_size,
+  (++flush_count)*sizeof(*flush_list));
 if (!flush_list)
 return AVERROR(ENOMEM);
 flush_list[flush_count - 1] = flush_buf;
@@ -516,43 +516,43 @@ int ff_vk_add_exec_dep(FFVulkanContext *s, 
FFVkExecContext *e, AVFrame *frame,
 int planes = av_pix_fmt_count_planes(fc->sw_format);
 
 for (int i = 0; i < planes; i++) {
-e->sem_wait = av_fast_realloc(e->sem_wait, &e->sem_wait_alloc,
-  (e->sem_wait_cnt + 
1)*sizeof(*e->sem_wait));
+e->sem_wait = av_realloc_reuse(e->sem_wait, &e->sem_wait_alloc,
+   (e->sem_wait_cnt + 
1)*sizeof(*e->sem_wait));
 if (!e->sem_wait) {
 ff_vk_discard_exec_deps(e);
 return AVERROR(ENOMEM);
 }
 
-e->sem_wait_dst = av_fast_realloc(e->sem_wait_dst, 
&e->sem_wait_dst_alloc,
-  (e->sem_wait_cnt + 
1)*sizeof(*e->sem_wait_dst));
+e->sem_wait_dst = av_realloc_reuse(e->sem_wait_dst, 
&e->sem_wait_dst_alloc,
+   (e->sem_wait_cnt + 
1)*sizeof(*e->sem_wait_dst));
 if (!e->sem_wait_dst) {
 ff_vk_discard_exec_deps(e);
 return AVERROR(ENOMEM);
 }
 
-e->sem_wait_val = av_fast_realloc(e->sem_wait_val, 
&e->sem_wait_val_alloc,
-  (e->sem_wait_cnt + 
1)*sizeof(*e->sem_wait_val));
+e->sem_wait_val = av_realloc_reuse(e->sem_wait_val, 
&e->sem_wait_val_alloc,
+   (e->sem_wait_cnt + 
1)*sizeof

[FFmpeg-devel] [PATCH 4/6] lavfi: replace av_fast_realloc() with av_realloc_reuse()

2022-09-28 Thread Anton Khirnov
---
 libavfilter/af_adelay.c|  4 ++--
 libavfilter/asrc_afirsrc.c | 12 ++--
 libavfilter/avf_showspectrum.c |  8 
 libavfilter/f_drawgraph.c  | 18 +-
 libavfilter/f_graphmonitor.c   |  8 
 libavfilter/f_reverse.c| 16 
 6 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/libavfilter/af_adelay.c b/libavfilter/af_adelay.c
index 9e63e2d618..6eb2aa400c 100644
--- a/libavfilter/af_adelay.c
+++ b/libavfilter/af_adelay.c
@@ -31,7 +31,7 @@ typedef struct ChanDelay {
 int64_t delay;
 size_t delay_index;
 size_t index;
-unsigned int samples_size;
+size_t samples_size;
 uint8_t *samples;
 } ChanDelay;
 
@@ -116,7 +116,7 @@ static int resize_samples_## name ##p(ChanDelay *d, int64_t 
new_delay)
 return 0;  
 \
 }  
 \

 \
-samples = (type *) av_fast_realloc(d->samples, &d->samples_size, new_delay 
* sizeof(type)); \
+samples = (type *) av_realloc_reuse(d->samples, &d->samples_size, 
new_delay * sizeof(type));\
 if (!samples) {
 \
 return AVERROR(ENOMEM);
 \
 }  
 \
diff --git a/libavfilter/asrc_afirsrc.c b/libavfilter/asrc_afirsrc.c
index 615242e0f5..ad65b7498b 100644
--- a/libavfilter/asrc_afirsrc.c
+++ b/libavfilter/asrc_afirsrc.c
@@ -43,9 +43,9 @@ typedef struct AudioFIRSourceContext {
 float *freq;
 float *magnitude;
 float *phase;
-int freq_size;
-int magnitude_size;
-int phase_size;
+size_t freq_size;
+size_t magnitude_size;
+size_t phase_size;
 int nb_freq;
 int nb_magnitude;
 int nb_phase;
@@ -126,12 +126,12 @@ static av_cold int query_formats(AVFilterContext *ctx)
 return ff_set_common_samplerates_from_list(ctx, sample_rates);
 }
 
-static int parse_string(char *str, float **items, int *nb_items, int 
*items_size)
+static int parse_string(char *str, float **items, int *nb_items, size_t 
*items_size)
 {
 float *new_items;
 char *tail;
 
-new_items = av_fast_realloc(NULL, items_size, 1 * sizeof(float));
+new_items = av_realloc_reuse(NULL, items_size, 1 * sizeof(float));
 if (!new_items)
 return AVERROR(ENOMEM);
 *items = new_items;
@@ -142,7 +142,7 @@ static int parse_string(char *str, float **items, int 
*nb_items, int *items_size
 
 do {
 (*items)[(*nb_items)++] = av_strtod(tail, &tail);
-new_items = av_fast_realloc(*items, items_size, (*nb_items + 1) * 
sizeof(float));
+new_items = av_realloc_reuse(*items, items_size, (*nb_items + 1) * 
sizeof(float));
 if (!new_items)
 return AVERROR(ENOMEM);
 *items = new_items;
diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index b111471116..a9ee8458f3 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -114,7 +114,7 @@ typedef struct ShowSpectrumContext {
 
 AVFrame **frames;
 unsigned int nb_frames;
-unsigned int frames_size;
+size_t frames_size;
 } ShowSpectrumContext;
 
 #define OFFSET(x) offsetof(ShowSpectrumContext, x)
@@ -1300,8 +1300,8 @@ static int config_output(AVFilterLink *outlink)
 if (!s->in_frame)
 return AVERROR(ENOMEM);
 
-s->frames = av_fast_realloc(NULL, &s->frames_size,
-DEFAULT_LENGTH * sizeof(*(s->frames)));
+s->frames = av_realloc_reuse(NULL, &s->frames_size,
+ DEFAULT_LENGTH * sizeof(*(s->frames)));
 if (!s->frames)
 return AVERROR(ENOMEM);
 
@@ -1840,7 +1840,7 @@ static int showspectrumpic_filter_frame(AVFilterLink 
*inlink, AVFrame *insamples
 void *ptr;
 
 if (s->nb_frames + 1ULL > s->frames_size / sizeof(*(s->frames))) {
-ptr = av_fast_realloc(s->frames, &s->frames_size, s->frames_size * 2);
+ptr = av_realloc_reuse(s->frames, &s->frames_size, s->frames_size * 2);
 if (!ptr)
 return AVERROR(ENOMEM);
 s->frames = ptr;
diff --git a/libavfilter/f_drawgraph.c b/libavfilter/f_drawgraph.c
index 000255fc52..f616bd2c04 100644
--- a/libavfilter/f_drawgraph.c
+++ b/libavfilter/f_drawgraph.c
@@ -49,7 +49,7 @@ typedef struct DrawGraphContext {
 int   prev_y[4];
 int   first[4];
 float *values[4];
-int   values_size[4];
+size_tvalues_size[4];
 int   nb_values;
 int64_t   prev_pts;
 } DrawGraphContext;
@@ -114,10 +114,10 @@ static 

[FFmpeg-devel] [PATCH 1/6] lavu/mem: add av_realloc_reuse() as a replacement for av_fast_realloc()

2022-09-28 Thread Anton Khirnov
It uses size_t rather than unsigned for the size and conforms to our
standard naming scheme.
---
 configure   |  5 -
 doc/APIchanges  |  3 +++
 libavutil/mem.c | 30 ++
 libavutil/mem.h | 37 +++--
 libavutil/version.h |  3 ++-
 5 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 6712d045d9..fd0e6ae032 100755
--- a/configure
+++ b/configure
@@ -4360,7 +4360,10 @@ case "$toolchain" in
 target_exec_default="valgrind"
 case "$toolchain" in
 valgrind-massif)
-target_exec_args="--tool=massif --alloc-fn=av_malloc 
--alloc-fn=av_mallocz --alloc-fn=av_calloc --alloc-fn=av_fast_padded_malloc 
--alloc-fn=av_fast_malloc --alloc-fn=av_realloc_f --alloc-fn=av_fast_realloc 
--alloc-fn=av_realloc"
+target_exec_args="--tool=massif"
+for func in av_malloc av_mallocz av_calloc 
av_fast_padded_malloc av_fast_malloc av_realloc_f av_fast_realloc av_realloc 
av_realloc_reuse; do
+target_exec_args="$target_exec_args --alloc-fn=$func"
+done
 ;;
 valgrind-memcheck)
 target_exec_args="--error-exitcode=1 --malloc-fill=0x2a 
--track-origins=yes --leak-check=full --gen-suppressions=all 
--suppressions=$source_path/tests/fate-valgrind.supp"
diff --git a/doc/APIchanges b/doc/APIchanges
index b0a41c9e37..9a735c27e7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-xx-xx - xx - lavu 57.38.100 - mem.h
+  Add av_realloc_reuse(), deprecate av_fast_realloc().
+
 2022-09-26 - xx - lavc 59.48.100 - avcodec.h
   Deprecate avcodec_enum_to_chroma_pos() and avcodec_chroma_pos_to_enum().
   Use av_chroma_location_enum_to_pos() or av_chroma_location_pos_to_enum()
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 18aff5291f..51fdc9155f 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -502,6 +502,35 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
 }
 }
 
+void *av_realloc_reuse(void *ptr, size_t *size, size_t min_size)
+{
+size_t max_size;
+
+if (min_size <= *size)
+return ptr;
+
+max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
+
+if (min_size > max_size) {
+*size = 0;
+return NULL;
+}
+
+min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size));
+
+ptr = av_realloc(ptr, min_size);
+/* we could set this to the unmodified min_size but this is safer
+ * if the user lost the ptr and uses NULL now
+ */
+if (!ptr)
+min_size = 0;
+
+*size = min_size;
+
+return ptr;
+}
+
+#if FF_API_FAST_ALLOC
 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
 {
 size_t max_size;
@@ -531,6 +560,7 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t 
min_size)
 
 return ptr;
 }
+#endif
 
 static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, 
int zero_realloc)
 {
diff --git a/libavutil/mem.h b/libavutil/mem.h
index d91174196c..deb440ca1a 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -264,7 +264,7 @@ void *av_mallocz_array(size_t nmemb, size_t size) 
av_malloc_attrib av_alloc_size
  * @warning Unlike av_malloc(), the returned pointer is not guaranteed to be
  *  correctly aligned. The returned pointer must be freed after even
  *  if size is zero.
- * @see av_fast_realloc()
+ * @see av_realloc_reuse()
  * @see av_reallocp()
  */
 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
@@ -346,6 +346,35 @@ av_alloc_size(2, 3) void *av_realloc_array(void *ptr, 
size_t nmemb, size_t size)
  */
 int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
 
+/**
+ * Reallocate a data buffer, reusing the existing one if it is large enough.
+ *
+ * This function is similar to av_realloc(), but optimized for cases where the
+ * buffer may grow significantly and is not expected to shrink.
+ *
+ * @param[in] ptr Previously allocated buffer, or `NULL`. If `ptr` is `NULL`, a
+ * new uninitialized buffer is allocated. `ptr` is invalidated when this
+ * function returns non-`NULL` and must be replaced with its return value.
+ *
+ * @param[in,out] size Pointer to the allocated size of buffer `ptr`. This
+ * function updates `*size` to the new allocated size (which may be larger than
+ * `min_size`). `*size` is set to 0 on failure.
+ *
+ * @param[in] min_size Minimum size in bytes of the returned buffer.
+ *
+ * @return
+ * - An allocated buffer (to be freed with `av_free()`) that is large enough to
+ *   hold at least `min_size` bytes. The first `*size` (value on entry to this
+ *   function) bytes of the buffer remain the same as the data in `ptr`, the
+ *   rest is uninitialized.
+ * - `NULL` on failure, then `*size` is set to 0 and ptr remains untouched.
+ *
+ * @see av_realloc()
+

[FFmpeg-devel] [PATCH 6/6] sws: replace av_fast_realloc() with av_realloc_reuse()

2022-09-28 Thread Anton Khirnov
---
 libswscale/swscale_internal.h | 2 +-
 libswscale/utils.c| 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index abeebbb002..1566bb50fe 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -91,7 +91,7 @@ typedef struct Range {
 typedef struct RangeList {
 Range  *ranges;
 unsigned int nb_ranges;
-int ranges_allocated;
+size_t  ranges_allocated;
 } RangeList;
 
 int ff_range_add(RangeList *r, unsigned int start, unsigned int len);
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 45baa22b23..67d1cd9fd5 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -2570,8 +2570,8 @@ int ff_range_add(RangeList *rl, unsigned int start, 
unsigned int len)
 return AVERROR(EINVAL);
 }
 
-tmp = av_fast_realloc(rl->ranges, &rl->ranges_allocated,
-  (rl->nb_ranges + 1) * sizeof(*rl->ranges));
+tmp = av_realloc_reuse(rl->ranges, &rl->ranges_allocated,
+   (rl->nb_ranges + 1) * sizeof(*rl->ranges));
 if (!tmp)
 return AVERROR(ENOMEM);
 rl->ranges = tmp;
-- 
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".


[FFmpeg-devel] [PATCH 5/6] lavf: replace av_fast_realloc() with av_realloc_reuse()

2022-09-28 Thread Anton Khirnov
---
 libavformat/avc.c |  4 +--
 libavformat/avc.h |  2 +-
 libavformat/bethsoftvid.c |  6 ++--
 libavformat/cafenc.c  |  8 ++---
 libavformat/concat.c  |  4 +--
 libavformat/demux.h   |  2 +-
 libavformat/hls.c |  4 +--
 libavformat/imf.h |  2 +-
 libavformat/imf_cpl.c | 16 -
 libavformat/imfdec.c  | 10 +++---
 libavformat/internal.h|  2 +-
 libavformat/isom.h|  4 +--
 libavformat/matroskadec.c |  8 ++---
 libavformat/mms.c |  6 ++--
 libavformat/mms.h |  2 +-
 libavformat/mov.c | 68 +--
 libavformat/mxg.c |  8 ++---
 libavformat/seek.c| 10 +++---
 libavformat/spdifenc.c|  5 +--
 libavformat/subtitles.c   |  4 +--
 libavformat/subtitles.h   |  2 +-
 libavformat/wavenc.c  |  4 +--
 libavformat/wtvdec.c  |  2 +-
 23 files changed, 94 insertions(+), 89 deletions(-)

diff --git a/libavformat/avc.c b/libavformat/avc.c
index b0ceb1d2d8..cb5357fa4a 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -92,8 +92,8 @@ static int avc_parse_nal_units(AVIOContext *pb, NALUList 
*list,
 } else if (list->nb_nalus >= nalu_limit) {
 return AVERROR(ERANGE);
 } else {
-NALU *tmp = av_fast_realloc(list->nalus, &list->nalus_array_size,
-(list->nb_nalus + 1) * 
sizeof(*list->nalus));
+NALU *tmp = av_realloc_reuse(list->nalus, &list->nalus_array_size,
+ (list->nb_nalus + 1) * 
sizeof(*list->nalus));
 if (!tmp)
 return AVERROR(ENOMEM);
 list->nalus = tmp;
diff --git a/libavformat/avc.h b/libavformat/avc.h
index 0ce95c194e..121155e0ba 100644
--- a/libavformat/avc.h
+++ b/libavformat/avc.h
@@ -33,7 +33,7 @@ typedef struct NALU {
 
 typedef struct NALUList {
 NALU *nalus;
-unsigned nalus_array_size;
+size_t   nalus_array_size;
 unsigned nb_nalus;  ///< valid entries in nalus
 } NALUList;
 
diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c
index cfb7d57332..1620fb5eaf 100644
--- a/libavformat/bethsoftvid.c
+++ b/libavformat/bethsoftvid.c
@@ -108,7 +108,7 @@ static int read_frame(BVID_DemuxContext *vid, AVIOContext 
*pb, AVPacket *pkt,
 int code;
 int bytes_copied = 0;
 int position, duration, npixels;
-unsigned int vidbuf_capacity;
+size_t vidbuf_capacity;
 int ret = 0;
 AVStream *st;
 
@@ -153,8 +153,8 @@ static int read_frame(BVID_DemuxContext *vid, AVIOContext 
*pb, AVPacket *pkt,
 }
 
 do{
-uint8_t *tmp = av_fast_realloc(vidbuf_start, &vidbuf_capacity,
-   vidbuf_nbytes + BUFFER_PADDING_SIZE);
+uint8_t *tmp = av_realloc_reuse(vidbuf_start, &vidbuf_capacity,
+vidbuf_nbytes + BUFFER_PADDING_SIZE);
 if (!tmp) {
 ret = AVERROR(ENOMEM);
 goto fail;
diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c
index b90811d46f..d8d98fc5aa 100644
--- a/libavformat/cafenc.c
+++ b/libavformat/cafenc.c
@@ -31,7 +31,7 @@
 
 typedef struct {
 int64_t data;
-int size_buffer_size;
+size_t size_buffer_size;
 int size_entries_used;
 int packets;
 } CAFContext;
@@ -226,9 +226,9 @@ static int caf_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (alloc_size < 0)
 return AVERROR(ERANGE);
 
-pkt_sizes = av_fast_realloc(st->priv_data,
-&caf->size_buffer_size,
-alloc_size);
+pkt_sizes = av_realloc_reuse(st->priv_data,
+ &caf->size_buffer_size,
+ alloc_size);
 if (!pkt_sizes)
 return AVERROR(ENOMEM);
 st->priv_data = pkt_sizes;
diff --git a/libavformat/concat.c b/libavformat/concat.c
index dc0985e40c..60c0ae158c 100644
--- a/libavformat/concat.c
+++ b/libavformat/concat.c
@@ -214,7 +214,7 @@ static av_cold int concatf_open(URLContext *h, const char 
*uri, int flags)
 AVIOContext *in = NULL;
 const char *cursor;
 int64_t total_size = 0;
-unsigned int nodes_size = 0;
+size_t nodes_size = 0;
 size_t i = 0;
 int err;
 
@@ -280,7 +280,7 @@ static av_cold int concatf_open(URLContext *h, const char 
*uri, int flags)
 break;
 }
 
-nodes = av_fast_realloc(data->nodes, &nodes_size, sizeof(*nodes) * 
len);
+nodes = av_realloc_reuse(data->nodes, &nodes_size, sizeof(*nodes) * 
len);
 if (!nodes) {
 ffurl_close(uc);
 err = AVERROR(ENOMEM);
diff --git a/libavformat/demux.h b/libavformat/demux.h
index 1f57e062f6..af461e5ebd 100644
--- a/libavformat/demux.h
+++ b/libavformat/demux.h
@@ -135,7 +135,7 @@ int ff_index_search_timestamp(const AVIndexEntry *entries, 
int nb_entries,
  */
 int ff_add_index_entry(AVIndexEntry **inde

[FFmpeg-devel] [PATCH 3/6] lavc: replace av_fast_realloc() with av_realloc_reuse()

2022-09-28 Thread Anton Khirnov
---
 libavcodec/4xm.c   |  6 +++---
 libavcodec/audio_frame_queue.c |  3 ++-
 libavcodec/audio_frame_queue.h |  2 +-
 libavcodec/av1_parse.c |  2 +-
 libavcodec/av1_parse.h |  2 +-
 libavcodec/dirac_parser.c  | 10 +-
 libavcodec/dxva2_av1.c |  6 +++---
 libavcodec/flac_parser.c   |  6 +++---
 libavcodec/h2645_parse.c   |  2 +-
 libavcodec/h2645_parse.h   |  2 +-
 libavcodec/libaomenc.c | 10 +-
 libavcodec/librav1e.c  |  5 +++--
 libavcodec/libtheoraenc.c  |  5 +++--
 libavcodec/libvpxenc.c | 10 +-
 libavcodec/libx264.c   |  5 +++--
 libavcodec/libx265.c   |  8 
 libavcodec/movtextenc.c|  8 
 libavcodec/nvdec.c |  4 ++--
 libavcodec/nvdec.h |  4 ++--
 libavcodec/nvdec_av1.c |  8 
 libavcodec/nvdec_h264.c|  8 
 libavcodec/nvdec_hevc.c|  8 
 libavcodec/nvenc.c | 18 +-
 libavcodec/nvenc.h |  2 +-
 libavcodec/parser.c| 12 ++--
 libavcodec/parser.h|  2 +-
 libavcodec/shorten.c   | 10 +-
 libavcodec/vdpau.c |  4 ++--
 libavcodec/vdpau_internal.h|  2 +-
 libavcodec/videotoolbox.c  | 12 ++--
 libavcodec/vt_internal.h   |  2 +-
 31 files changed, 96 insertions(+), 92 deletions(-)

diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index 5636fdef2d..e523a6ea96 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -129,7 +129,7 @@ static VLC block_type_vlc[2][4];
 
 
 typedef struct CFrameBuffer {
-unsigned int allocated_size;
+size_t allocated_size;
 unsigned int size;
 int id;
 uint8_t *data;
@@ -895,8 +895,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*picture,
 if (data_size > UINT_MAX -  cfrm->size - AV_INPUT_BUFFER_PADDING_SIZE)
 return AVERROR_INVALIDDATA;
 
-cfrm->data = av_fast_realloc(cfrm->data, &cfrm->allocated_size,
- cfrm->size + data_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
+cfrm->data = av_realloc_reuse(cfrm->data, &cfrm->allocated_size,
+  cfrm->size + data_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
 // explicit check needed as memcpy below might not catch a NULL
 if (!cfrm->data) {
 av_log(f->avctx, AV_LOG_ERROR, "realloc failure\n");
diff --git a/libavcodec/audio_frame_queue.c b/libavcodec/audio_frame_queue.c
index 08b4b368c7..bd92fe23c0 100644
--- a/libavcodec/audio_frame_queue.c
+++ b/libavcodec/audio_frame_queue.c
@@ -43,7 +43,8 @@ void ff_af_queue_close(AudioFrameQueue *afq)
 
 int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
 {
-AudioFrame *new = av_fast_realloc(afq->frames, &afq->frame_alloc, 
sizeof(*afq->frames)*(afq->frame_count+1));
+AudioFrame *new = av_realloc_reuse(afq->frames, &afq->frame_alloc,
+   
sizeof(*afq->frames)*(afq->frame_count+1));
 if(!new)
 return AVERROR(ENOMEM);
 afq->frames = new;
diff --git a/libavcodec/audio_frame_queue.h b/libavcodec/audio_frame_queue.h
index d8076eae54..8aa82ba5cf 100644
--- a/libavcodec/audio_frame_queue.h
+++ b/libavcodec/audio_frame_queue.h
@@ -35,7 +35,7 @@ typedef struct AudioFrameQueue {
 int remaining_samples;
 AudioFrame *frames;
 unsigned frame_count;
-unsigned frame_alloc;
+size_t frame_alloc;
 } AudioFrameQueue;
 
 /**
diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
index 59ea0bc6e7..baab46016b 100644
--- a/libavcodec/av1_parse.c
+++ b/libavcodec/av1_parse.c
@@ -70,7 +70,7 @@ int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, 
int length, void *lo
 
 if (new_size >= INT_MAX / sizeof(*tmp))
 return AVERROR(ENOMEM);
-tmp = av_fast_realloc(pkt->obus, &pkt->obus_allocated_size, 
new_size * sizeof(*tmp));
+tmp = av_realloc_reuse(pkt->obus, &pkt->obus_allocated_size, 
new_size * sizeof(*tmp));
 if (!tmp)
 return AVERROR(ENOMEM);
 
diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index f4a5d2830e..20ce94105d 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -63,7 +63,7 @@ typedef struct AV1Packet {
 AV1OBU *obus;
 int nb_obus;
 int obus_allocated;
-unsigned obus_allocated_size;
+size_t obus_allocated_size;
 } AV1Packet;
 
 /**
diff --git a/libavcodec/dirac_parser.c b/libavcodec/dirac_parser.c
index 912f594243..1de08e43db 100644
--- a/libavcodec/dirac_parser.c
+++ b/libavcodec/dirac_parser.c
@@ -46,7 +46,7 @@ typedef struct DiracParseContext {
 int sync_offset;
 int header_bytes_needed;
 int overread_index;
-int buffer_size;
+size_t buffer_size;
 int index;
 uint8_t *buffer;
 int dirac_unit_size;
@@ -156,8 +156,8 @@ static int dirac_combine_frame(AVCodecParserContext *s, 
AVCodecConte

[FFmpeg-devel] [PATCH 2/2] fftools/ffmpeg: Remove unused frame_bits_per_raw_sample variable

2022-09-28 Thread Marvin Scholz
Unused since the bits_per_raw_sample was made a per-output-stream
option in 425889396137451ae30288c84122e28532b71596
---
 fftools/ffmpeg.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b7a7062378..a4c25e0f32 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -673,7 +673,6 @@ extern int print_stats;
 extern int64_t stats_period;
 extern int qp_hist;
 extern int stdin_interaction;
-extern int frame_bits_per_raw_sample;
 extern AVIOContext *progress_avio;
 extern float max_error_rate;
 
-- 
2.37.0 (Apple Git-136)

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

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


[FFmpeg-devel] [PATCH 1/2] fftools/ffmpeg: Remove unused do_deinterlace variable

2022-09-28 Thread Marvin Scholz
Unused since removal of the -deinterlace option in
d013453caafcc44c74d4bdbaa99ee4e8f32414cb
---
 fftools/ffmpeg.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index ede0b2bd96..b7a7062378 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -661,7 +661,6 @@ extern enum VideoSyncMethod video_sync_method;
 extern float frame_drop_threshold;
 extern int do_benchmark;
 extern int do_benchmark_all;
-extern int do_deinterlace;
 extern int do_hex_dump;
 extern int do_pkt_dump;
 extern int copy_ts;
-- 
2.37.0 (Apple Git-136)

___
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] ffmpeg: Make find_stream_info behave like a normal per-file option

2022-09-28 Thread Marvin Scholz
Currently it would essentially change the find_stream_info setting for
the file it was specified for and all following files, which is unusual
and somewhat unexpected behaviour for a per-file option and not even
documented to behave like this.
---
 fftools/ffmpeg.h | 1 +
 fftools/ffmpeg_opt.c | 7 ---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index ede0b2bd96..3389ce5edc 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -126,6 +126,7 @@ typedef struct OptionsContext {
 int accurate_seek;
 int thread_queue_size;
 int input_sync_ref;
+int find_stream_info;
 
 SpecifierOpt *ts_scale;
 intnb_ts_scale;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 5febe319e4..df1c8df454 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -190,7 +190,6 @@ static int input_stream_potentially_available = 0;
 static int ignore_unknown_streams = 0;
 static int copy_unknown_streams = 0;
 static int recast_media = 0;
-static int find_stream_info = 1;
 
 static void uninit_options(OptionsContext *o)
 {
@@ -240,6 +239,7 @@ static void init_options(OptionsContext *o)
 o->accurate_seek  = 1;
 o->thread_queue_size = -1;
 o->input_sync_ref = -1;
+o->find_stream_info = 1;
 o->shortest_buf_duration = 10.f;
 }
 
@@ -1307,7 +1307,7 @@ static int open_input_file(OptionsContext *o, const char 
*filename)
 for (i = 0; i < ic->nb_streams; i++)
 choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, 
AV_HWDEVICE_TYPE_NONE);
 
-if (find_stream_info) {
+if (o->find_stream_info) {
 AVDictionary **opts = setup_find_stream_info_opts(ic, 
o->g->codec_opts);
 int orig_nb_streams = ic->nb_streams;
 
@@ -4000,7 +4000,8 @@ const OptionDef options[] = {
 { "thread_queue_size", HAS_ARG | OPT_INT | OPT_OFFSET | OPT_EXPERT | 
OPT_INPUT | OPT_OUTPUT,
  { .off = 
OFFSET(thread_queue_size) },
 "set the maximum number of queued packets from the demuxer" },
-{ "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT, { 
&find_stream_info },
+{ "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT | 
OPT_OFFSET, 
+ { .off = 
OFFSET(find_stream_info) },
 "read and decode the streams to fill missing information with 
heuristics" },
 { "bits_per_raw_sample", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | 
OPT_OUTPUT,
 { .off = OFFSET(bits_per_raw_sample) },
-- 
2.37.0 (Apple Git-136)

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

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


[FFmpeg-devel] [PATCH 11/11] lavc/jpeg2000dec: Component-level threading of write_frame()

2022-09-28 Thread Tomas Härdin
Ideally the clipping done by write_frame() and the MCT stuff would be
done at the final IDWT stage
From 34f055bb0732085d6f97d8f27890b47afb8ca868 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Tue, 14 Jun 2022 15:45:32 +0200
Subject: [PATCH 11/11] lavc/jpeg2000dec: Component-level threading of
 write_frame()

Split off MCT and don't bother with it unless the picture actually uses MCT.
---
 libavcodec/jpeg2000dec.c | 37 ++---
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 71176d944d..8b984cfc27 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -156,6 +156,7 @@ typedef struct Jpeg2000DecoderContext {
 // used for idwt slicing
 int reslevel, dir, slices;
 int have_dwt97_int; // 1 if any coding style is FF_DWT97_INT
+int have_mct;
 } Jpeg2000DecoderContext;
 
 /* get_bits functions for JPEG2000 packet bitstream
@@ -604,6 +605,9 @@ static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c,
 return AVERROR_INVALIDDATA;
 }
 
+if (tmp.mct)
+s->have_mct = 1;
+
 if ((ret = get_cox(s, &tmp)) < 0)
 return ret;
 tmp.init = 1;
@@ -2074,16 +2078,14 @@ static int jpeg2000_dwt97_int_postshift(AVCodecContext *avctx, void *td,
 
 #define WRITE_FRAME(D, PIXEL) \
 static inline void write_frame_ ## D(const Jpeg2000DecoderContext * s, Jpeg2000Tile * tile,   \
- AVFrame * picture, int precision)\
+ AVFrame * picture, int precision, int compno)\
 { \
 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(s->avctx->pix_fmt);   \
 int planar= !!(pixdesc->flags & AV_PIX_FMT_FLAG_PLANAR);  \
 int pixelsize = planar ? 1 : pixdesc->nb_components;  \
   \
-int compno;   \
 int x, y; \
   \
-for (compno = 0; compno < s->ncomponents; compno++) { \
 Jpeg2000Component *comp = tile->comp + compno;\
 Jpeg2000CodingStyle *codsty = tile->codsty + compno;  \
 PIXEL *line;  \
@@ -2130,8 +2132,6 @@ static int jpeg2000_dwt97_int_postshift(AVCodecContext *avctx, void *td,
 } \
 line += picture->linesize[plane] / sizeof(PIXEL); \
 } \
-} \
-  \
 }
 
 WRITE_FRAME(8, uint8_t)
@@ -2139,26 +2139,36 @@ WRITE_FRAME(16, uint16_t)
 
 #undef WRITE_FRAME
 
-static int jpeg2000_mct_write_frame(AVCodecContext *avctx, void *td,
-int jobnr, int threadnr)
+static int jpeg2000_mct(AVCodecContext *avctx, void *td,
+int jobnr, int threadnr)
 {
 const Jpeg2000DecoderContext *s = avctx->priv_data;
-AVFrame *picture = td;
 Jpeg2000Tile *tile = s->tile + jobnr;
 
 /* inverse MCT transformation */
 if (tile->codsty[0].mct)
 mct_decode(s, tile);
 
+return 0;
+}
+
+static int jpeg2000_write_frame(AVCodecContext *avctx, void *td,
+int jobnr, int threadnr)
+{
+Jpeg2000DecoderContext *s = avctx->priv_data;
+AVFrame *picture = td;
+Jpeg2000Tile *tile = s->tile + jobnr / s->ncomponents;
+int compno = jobnr % s->ncomponents;
+
 if (s->precision <= 8) {
-write_frame_8(s, tile, picture, 8);
+write_frame_8(s, tile, picture, 8, compno);
 } else {
 int precision = picture->format == AV_PIX_FMT_XYZ12 ||
 picture->format == AV_PIX_FMT_RGB48 ||
 picture->format == AV_PIX_FMT_RGBA64 ||
 picture->format == AV_PIX_FMT_GRAY16 ? 16 : s->precision;
 
-write_frame_16(s, tile, picture, precision);
+write_frame_16(s, tile, picture, precision

[FFmpeg-devel] [PATCH 10/11] lavc/jpeg2000dec: Use coarser slicing for initial reslevels

2022-09-28 Thread Tomas Härdin
This patch is more informal, there's probably a better way to bump
performance up above 50 fps. This is for the smoke_sauna sample on
SVT's FTP by the way.
From 103c38adabae39a607049ef517de43f4d2f9d406 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Tue, 14 Jun 2022 11:19:06 +0200
Subject: [PATCH 10/11] lavc/jpeg2000dec: Use coarser slicing for initial
 reslevels

This brings -lowres 2 lossless 4K J2K on an AMD EPYC 7R32 to 52 fps (2080% CPU).
---
 libavcodec/jpeg2000dec.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 46f7d841b5..71176d944d 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -2673,9 +2673,19 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
 
 for (s->reslevel = 0; s->reslevel < maxreslevels; s->reslevel++) {
 for (s->dir = 0; s->dir < 2; s->dir++) {
+int before = s->slices;
+int div = s->slices >= 96 ? 7 : 5;
+
+if (s->reslevel < div) {
+int halve = 1<<(div - s->reslevel + (s->slices >= 96 ? 0 : 1 - s->dir));
+s->slices = (s->slices + halve-1)/halve;
+}
+
 if ((ret = avctx->execute2(avctx, jpeg2000_idwt, NULL, NULL,
 s->numXtiles * s->numYtiles * s->ncomponents * s->slices)) < 0)
 goto end;
+
+s->slices = before;
 }
 }
 
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 09/11] lavc/jpeg2000: Minimize calls to av_codec_is_encoder()

2022-09-28 Thread Tomas Härdin

From ecb1d9ff671b83bddb0d1c7d31d60ade4b5cdead Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Tue, 14 Jun 2022 10:57:45 +0200
Subject: [PATCH 09/11] lavc/jpeg2000: Minimize calls to av_codec_is_encoder()

---
 libavcodec/jpeg2000.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 2574c2b97e..bb6efab72e 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -248,7 +248,7 @@ static void init_band_stepsize(AVCodecContext *avctx,
Jpeg2000CodingStyle *codsty,
Jpeg2000QuantStyle *qntsty,
int bandno, int gbandno, int reslevelno,
-   int cbps)
+   int cbps, int is_enc)
 {
 /* TODO: Implementation of quantization step not finished,
  * see ISO/IEC 15444-1:2002 E.1 and A.6.4. */
@@ -306,7 +306,7 @@ static void init_band_stepsize(AVCodecContext *avctx,
 
 /* FIXME: In OpenJPEG code stepsize = stepsize * 0.5. Why?
  * If not set output of entropic decoder is not correct. */
-if (!av_codec_is_encoder(avctx->codec))
+if (!is_enc)
 band->f_stepsize *= 0.5;
 }
 
@@ -317,7 +317,8 @@ static int init_prec(AVCodecContext *avctx,
  Jpeg2000CodingStyle *codsty,
  int precno, int bandno, int reslevelno,
  int log2_band_prec_width,
- int log2_band_prec_height)
+ int log2_band_prec_height,
+ int is_enc)
 {
 Jpeg2000Prec *prec = band->prec + precno;
 int nb_codeblocks, cblkno, ret;
@@ -414,7 +415,7 @@ static int init_prec(AVCodecContext *avctx,
 cblk->lblock= 3;
 cblk->length= 0;
 cblk->npasses   = 0;
-if (av_codec_is_encoder(avctx->codec)) {
+if (is_enc) {
 av_freep(&cblk->layers);
 cblk->layers = av_calloc(codsty->nlayers, sizeof(*cblk->layers));
 if (!cblk->layers)
@@ -431,7 +432,7 @@ static int init_band(AVCodecContext *avctx,
  Jpeg2000CodingStyle *codsty,
  Jpeg2000QuantStyle *qntsty,
  int bandno, int gbandno, int reslevelno,
- int cbps, int dx, int dy)
+ int cbps, int dx, int dy, int is_enc)
 {
 Jpeg2000Band *band = reslevel->band + bandno;
 uint8_t log2_band_prec_width, log2_band_prec_height;
@@ -440,7 +441,7 @@ static int init_band(AVCodecContext *avctx,
 int nb_precincts;
 int i, j, ret;
 
-init_band_stepsize(avctx, band, codsty, qntsty, bandno, gbandno, reslevelno, cbps);
+init_band_stepsize(avctx, band, codsty, qntsty, bandno, gbandno, reslevelno, cbps, is_enc);
 
 /* computation of tbx_0, tbx_1, tby_0, tby_1
  * see ISO/IEC 15444-1:2002 B.5 eq. B-15 and tbl B.1
@@ -494,7 +495,8 @@ static int init_band(AVCodecContext *avctx,
 for (precno = 0; precno < nb_precincts; precno++) {
 ret = init_prec(avctx, band, reslevel, comp, codsty,
 precno, bandno, reslevelno,
-log2_band_prec_width, log2_band_prec_height);
+log2_band_prec_width, log2_band_prec_height,
+is_enc);
 if (ret < 0)
 return ret;
 }
@@ -511,6 +513,7 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
 int reslevelno, bandno, gbandno = 0, ret, i, j;
 uint32_t csize;
 size_t prod;
+int is_enc = av_codec_is_encoder(avctx->codec);
 
 if (codsty->nreslevels2decode <= 0) {
 av_log(avctx, AV_LOG_ERROR, "nreslevels2decode %d invalid or uninitialized\n", codsty->nreslevels2decode);
@@ -608,7 +611,7 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
 ret = init_band(avctx, reslevel,
 comp, codsty, qntsty,
 bandno, gbandno, reslevelno,
-cbps, dx, dy);
+cbps, dx, dy, is_enc);
 if (ret < 0)
 return ret;
 }
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 08/11] lavc/jpeg2000: Reindent

2022-09-28 Thread Tomas Härdin

From 2e915fbbd481c1d202c0ec058842cfc9f9593871 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Tue, 14 Jun 2022 11:23:08 +0200
Subject: [PATCH 08/11] lavc/jpeg2000: Reindent

---
 libavcodec/jpeg2000.c | 44 +--
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 203782502c..2574c2b97e 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -94,34 +94,34 @@ static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size,
 } else
 return AVERROR(ENOMEM);
 } else {
-tt_size = tag_tree_size(w, h);
+tt_size = tag_tree_size(w, h);
 
-if (av_size_mult(tt_size, sizeof(*t), &prod))
-return AVERROR(ENOMEM);
+if (av_size_mult(tt_size, sizeof(*t), &prod))
+return AVERROR(ENOMEM);
 
-av_fast_malloc(old, size, prod);
-if (!*old)
-return AVERROR(ENOMEM);
-t = *old;
-memset(*old, 0, prod);
+av_fast_malloc(old, size, prod);
+if (!*old)
+return AVERROR(ENOMEM);
+t = *old;
+memset(*old, 0, prod);
 
-while (w > 1 || h > 1) {
-int i, j;
-pw = w;
-ph = h;
+while (w > 1 || h > 1) {
+int i, j;
+pw = w;
+ph = h;
 
-w  = (w + 1) >> 1;
-h  = (h + 1) >> 1;
-ofs += pw * ph;
+w  = (w + 1) >> 1;
+h  = (h + 1) >> 1;
+ofs += pw * ph;
 
-for (i = 0; i < ph; i++)
-for (j = 0; j < pw; j++)
-t[i * pw + j].parent = (i >> 1) * w + (j >> 1) + ofs;
+for (i = 0; i < ph; i++)
+for (j = 0; j < pw; j++)
+t[i * pw + j].parent = (i >> 1) * w + (j >> 1) + ofs;
 
-t += pw * ph;
-}
-t[0].parent = -1;
-return 0;
+t += pw * ph;
+}
+t[0].parent = -1;
+return 0;
 }
 }
 
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 07/11] lavc/jpeg2000: Speed up ff_jpeg2000_tag_tree_init() using stereotypes for sizes <= 4x4

2022-09-28 Thread Tomas Härdin

From a31a6d82b257f51618389a67af18d49cc78ac240 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Wed, 8 Jun 2022 10:08:15 +0200
Subject: [PATCH 07/11] lavc/jpeg2000: Speed up ff_jpeg2000_tag_tree_init()
 using stereotypes for sizes <= 4x4

---
 libavcodec/jpeg2000.c | 36 
 1 file changed, 36 insertions(+)

diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 4ddb45bf33..203782502c 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -51,6 +51,31 @@ static int32_t tag_tree_size(int w, int h)
 return (int32_t)(res + 1);
 }
 
+#define T(x) (x*sizeof(Jpeg2000TgtNode))
+
+static const size_t tt_sizes[16] = {
+T(1),T(3),T(6),T(7),T(3),T(5),T(9),T(11),T(6),T(9),T(14),T(17),T(7),T(11),T(17),T(21),
+};
+
+static const Jpeg2000TgtNode tt_stereotypes[16][21] = {
+{{-1},},
+{{2},{2},{-1},},
+{{3},{3},{4},{5},{5},{-1},},
+{{4},{4},{5},{5},{6},{6},{-1},},
+{{2},{2},{-1},},
+{{4},{4},{4},{4},{-1},},
+{{6},{6},{7},{6},{6},{7},{8},{8},{-1},},
+{{8},{8},{9},{9},{8},{8},{9},{9},{10},{10},{-1},},
+{{3},{3},{4},{5},{5},{-1},},
+{{6},{6},{6},{6},{7},{7},{8},{8},{-1},},
+{{9},{9},{10},{9},{9},{10},{11},{11},{12},{13},{13},{13},{13},{-1},},
+{{12},{12},{13},{13},{12},{12},{13},{13},{14},{14},{15},{15},{16},{16},{16},{16},{-1},},
+{{4},{4},{5},{5},{6},{6},{-1},},
+{{8},{8},{8},{8},{9},{9},{9},{9},{10},{10},{-1},},
+{{12},{12},{13},{12},{12},{13},{14},{14},{15},{14},{14},{15},{16},{16},{16},{16},{-1},},
+{{16},{16},{17},{17},{16},{16},{17},{17},{18},{18},{19},{19},{18},{18},{19},{19},{20},{20},{20},{20},{-1},},
+};
+
 /* allocate the memory for tag tree */
 static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size, int w, int h)
 {
@@ -59,6 +84,16 @@ static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size,
 int32_t tt_size, ofs = 0;
 size_t prod;
 
+if (w <= 4 && h <= 4) {
+int idx = w-1 + (h-1)*4;
+size_t sz = tt_sizes[idx];
+av_fast_malloc(old, size, sz);
+if (*old) {
+memcpy(*old, tt_stereotypes[idx], sz);
+return 0;
+} else
+return AVERROR(ENOMEM);
+} else {
 tt_size = tag_tree_size(w, h);
 
 if (av_size_mult(tt_size, sizeof(*t), &prod))
@@ -87,6 +122,7 @@ static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size,
 }
 t[0].parent = -1;
 return 0;
+}
 }
 
 void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h, int val)
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 06/11] lavc/jpeg2000: Switch Jpeg2000TgtNode to int32_t parent

2022-09-28 Thread Tomas Härdin

From 807d7d315269126e7eccd0c36d7c29615cb98676 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Tue, 7 Jun 2022 16:43:40 +0200
Subject: [PATCH 06/11] lavc/jpeg2000: Switch Jpeg2000TgtNode to int32_t parent

---
 libavcodec/j2kenc.c  | 44 
 libavcodec/jpeg2000.c| 20 +-
 libavcodec/jpeg2000.h|  2 +-
 libavcodec/jpeg2000dec.c | 18 
 4 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index cd325e94e0..8f23ddbcf6 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -249,36 +249,36 @@ static void j2k_flush(Jpeg2000EncoderContext *s)
 /* tag tree routines */
 
 /** code the value stored in node */
-static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int threshold)
+static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *nodes, int32_t node, int threshold)
 {
-Jpeg2000TgtNode *stack[30];
+int32_t stack[30];
 int sp = -1, curval = 0;
 
-while(node->parent){
+while(nodes[node].parent >= 0){
 stack[++sp] = node;
-node = node->parent;
+node = nodes[node].parent;
 }
 
 while (1) {
-if (curval > node->temp_val)
-node->temp_val = curval;
+if (curval > nodes[node].temp_val)
+nodes[node].temp_val = curval;
 else {
-curval = node->temp_val;
+curval = nodes[node].temp_val;
 }
 
-if (node->val >= threshold) {
+if (nodes[node].val >= threshold) {
 put_bits(s, 0, threshold - curval);
 curval = threshold;
 } else {
-put_bits(s, 0, node->val - curval);
-curval = node->val;
-if (!node->vis) {
+put_bits(s, 0, nodes[node].val - curval);
+curval = nodes[node].val;
+if (!nodes[node].vis) {
 put_bits(s, 1, 1);
-node->vis = 1;
+nodes[node].vis = 1;
 }
 }
 
-node->temp_val = curval;
+nodes[node].temp_val = curval;
 if (sp < 0)
 break;
 node = stack[sp--];
@@ -286,13 +286,13 @@ static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int
 }
 
 /** update the value in node */
-static void tag_tree_update(Jpeg2000TgtNode *node)
+static void tag_tree_update(Jpeg2000TgtNode *nodes, int node)
 {
-while (node->parent){
-if (node->parent->val <= node->val)
+while (nodes[node].parent >= 0){
+if (nodes[nodes[node].parent].val <= nodes[node].val)
 break;
-node->parent->val = node->val;
-node = node->parent;
+nodes[nodes[node].parent].val = nodes[node].val;
+node = nodes[node].parent;
 }
 }
 
@@ -812,7 +812,7 @@ static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, in
 prec->zerobits[pos].val = expn[bandno] + numgbits - 1 - cblk->nonzerobits;
 cblk->incl = 0;
 cblk->lblock = 3;
-tag_tree_update(prec->zerobits + pos);
+tag_tree_update(prec->zerobits, pos);
 for (i = 0; i < nlayers; i++) {
 if (cblk->layers[i].npasses > 0) {
 prec->cblkincl[pos].val = i;
@@ -821,7 +821,7 @@ static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, in
 }
 if (i == nlayers)
 prec->cblkincl[pos].val = i;
-tag_tree_update(prec->cblkincl + pos);
+tag_tree_update(prec->cblkincl, pos);
 }
 }
 }
@@ -875,7 +875,7 @@ static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, in
 
 // inclusion information
 if (!cblk->incl)
-tag_tree_code(s, prec->cblkincl + pos, layno + 1);
+tag_tree_code(s, prec->cblkincl, pos, layno + 1);
 else {
 put_bits(s, cblk->layers[layno].npasses > 0, 1);
 }
@@ -885,7 +885,7 @@ static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, in
 
 // zerobits information
 if (!cblk->incl) {
-tag_tree_code(s, prec->zerobits + pos, 100);
+tag_tree_code(s, prec->zerobits, pos, 100);
 cblk->incl = 1;
 }
 
diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index afff9809e4..4ddb45bf33 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -55,8 +55,8 @@ static int32_t tag_tree_size(int w, int h)
 static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size, int w, int h)
 {
 int pw = w, ph = h;
-Jpeg2000TgtNode *t, *t2;
-int32_t tt_size;
+Jpeg2000

[FFmpeg-devel] [PATCH 05/11] lavc/jpeg2000*: Use av_realloc_array_reuse() and av_reallocz_array_reuse() to eliminate lots of allocations

2022-09-28 Thread Tomas Härdin

From 5a5986c29d62933f3f2cd2259becb763f3719eaa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Mon, 13 Jun 2022 17:04:10 +0200
Subject: [PATCH 05/11] lavc/jpeg2000*: Use av_realloc_array_reuse() and
 av_reallocz_array_reuse() to eliminate lots of allocations

---
 libavcodec/jpeg2000.c| 79 +---
 libavcodec/jpeg2000.h| 10 +
 libavcodec/jpeg2000dec.c | 48 ++--
 libavcodec/jpeg2000dwt.c |  9 -
 libavcodec/jpeg2000dwt.h |  2 +
 5 files changed, 80 insertions(+), 68 deletions(-)

diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 945b787565..afff9809e4 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -52,17 +52,23 @@ static int32_t tag_tree_size(int w, int h)
 }
 
 /* allocate the memory for tag tree */
-static Jpeg2000TgtNode *ff_jpeg2000_tag_tree_init(int w, int h)
+static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size, int w, int h)
 {
 int pw = w, ph = h;
-Jpeg2000TgtNode *res, *t, *t2;
+Jpeg2000TgtNode *t, *t2;
 int32_t tt_size;
+size_t prod;
 
 tt_size = tag_tree_size(w, h);
 
-t = res = av_calloc(tt_size, sizeof(*t));
-if (!res)
-return NULL;
+if (av_size_mult(tt_size, sizeof(*t), &prod))
+return AVERROR(ENOMEM);
+
+av_fast_malloc(old, size, prod);
+if (!*old)
+return AVERROR(ENOMEM);
+t = *old;
+memset(*old, 0, prod);
 
 while (w > 1 || h > 1) {
 int i, j;
@@ -80,7 +86,7 @@ static Jpeg2000TgtNode *ff_jpeg2000_tag_tree_init(int w, int h)
 t = t2;
 }
 t[0].parent = NULL;
-return res;
+return 0;
 }
 
 void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h, int val)
@@ -278,7 +284,7 @@ static int init_prec(AVCodecContext *avctx,
  int log2_band_prec_height)
 {
 Jpeg2000Prec *prec = band->prec + precno;
-int nb_codeblocks, cblkno;
+int nb_codeblocks, cblkno, ret;
 
 prec->decoded_layers = 0;
 
@@ -316,25 +322,22 @@ static int init_prec(AVCodecContext *avctx,
 
 
 /* Tag trees initialization */
-prec->cblkincl =
-ff_jpeg2000_tag_tree_init(prec->nb_codeblocks_width,
-  prec->nb_codeblocks_height);
-if (!prec->cblkincl)
-return AVERROR(ENOMEM);
-
-prec->zerobits =
-ff_jpeg2000_tag_tree_init(prec->nb_codeblocks_width,
-  prec->nb_codeblocks_height);
-if (!prec->zerobits)
-return AVERROR(ENOMEM);
+if ((ret = ff_jpeg2000_tag_tree_init(&prec->cblkincl,
+ &prec->cblkincl_size,
+ prec->nb_codeblocks_width,
+ prec->nb_codeblocks_height)) < 0 ||
+(ret = ff_jpeg2000_tag_tree_init(&prec->zerobits,
+ &prec->zerobits_size,
+ prec->nb_codeblocks_width,
+ prec->nb_codeblocks_height)) < 0)
+return ret;
 
 if (prec->nb_codeblocks_width * (uint64_t)prec->nb_codeblocks_height > INT_MAX) {
 prec->cblk = NULL;
 return AVERROR(ENOMEM);
 }
 nb_codeblocks = prec->nb_codeblocks_width * prec->nb_codeblocks_height;
-prec->cblk = av_calloc(nb_codeblocks, sizeof(*prec->cblk));
-if (!prec->cblk)
+if (av_reallocz_array_reuse(&prec->cblk, &prec->cblk_allocated, nb_codeblocks, INT_MAX, sizeof(*prec->cblk)))
 return AVERROR(ENOMEM);
 for (cblkno = 0; cblkno < nb_codeblocks; cblkno++) {
 Jpeg2000Cblk *cblk = prec->cblk + cblkno;
@@ -376,6 +379,7 @@ static int init_prec(AVCodecContext *avctx,
 cblk->length= 0;
 cblk->npasses   = 0;
 if (av_codec_is_encoder(avctx->codec)) {
+av_freep(&cblk->layers);
 cblk->layers = av_calloc(codsty->nlayers, sizeof(*cblk->layers));
 if (!cblk->layers)
 return AVERROR(ENOMEM);
@@ -448,8 +452,7 @@ static int init_band(AVCodecContext *avctx,
 return AVERROR(ENOMEM);
 }
 nb_precincts = reslevel->num_precincts_x * reslevel->num_precincts_y;
-band->prec = av_calloc(nb_precincts, sizeof(*band->prec));
-if (!band->prec)
+if (av_reallocz_array_reuse(&band->prec, &band->prec_allocated, nb_precincts, INT_MAX, sizeof(*band->prec)))
 return AVERROR(ENOMEM);
 
 for (precno = 0; precno < nb_precincts; precno++) {
@@ -471,6 +474,7 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
 {
 int reslevelno, bandno, gbandno = 0, ret, i, j;
 uint32_t csize;
+size_t prod;
 
 if (codsty->nreslevels2decode <= 0) {
 av_log(avctx, AV_LOG_ERROR, "nreslevels2decode %d invalid or uninitialized\n", codsty->nreslevels2decode);
@@ -496,19 +500,22 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
 
 if (codsty->transform == FF_DWT97) {
 csize += AV_INPUT_BUFFE

[FFmpeg-devel] [PATCH 04/11] lavc/jpeg2000dec: Thread init_tile()

2022-09-28 Thread Tomas Härdin
This is the one that needs the new execute2()
From 4e7c65a7a3e049396ce5e3c01db335a532889115 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Mon, 13 Jun 2022 15:09:17 +0200
Subject: [PATCH 04/11] lavc/jpeg2000dec: Thread init_tile()

---
 libavcodec/jpeg2000dec.c | 31 ---
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 273346538f..00aa73e261 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1019,12 +1019,19 @@ static int get_ppt(Jpeg2000DecoderContext *s, int n)
 return 0;
 }
 
-static int init_tile(Jpeg2000DecoderContext *s, int tileno)
+static int init_tile(AVCodecContext *avctx, void *td,
+ int jobnr, int threadnr)
 {
-int compno;
-int tilex = tileno % s->numXtiles;
-int tiley = tileno / s->numXtiles;
-Jpeg2000Tile *tile = s->tile + tileno;
+const Jpeg2000DecoderContext *s = avctx->priv_data;
+int tileno  = jobnr / s->ncomponents;
+int tilex   = tileno % s->numXtiles;
+int tiley   = tileno / s->numXtiles;
+int compno  = jobnr % s->ncomponents;
+Jpeg2000Tile *tile  = s->tile + tileno;
+Jpeg2000Component *comp = tile->comp + compno;
+Jpeg2000CodingStyle *codsty = tile->codsty + compno;
+Jpeg2000QuantStyle  *qntsty = tile->qntsty + compno;
+int ret; // global bandno
 
 if (!tile->comp)
 return AVERROR(ENOMEM);
@@ -1034,12 +1041,6 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
 tile->coord[1][0] = av_clip(tiley   * (int64_t)s->tile_height + s->tile_offset_y, s->image_offset_y, s->height);
 tile->coord[1][1] = av_clip((tiley + 1) * (int64_t)s->tile_height + s->tile_offset_y, s->image_offset_y, s->height);
 
-for (compno = 0; compno < s->ncomponents; compno++) {
-Jpeg2000Component *comp = tile->comp + compno;
-Jpeg2000CodingStyle *codsty = tile->codsty + compno;
-Jpeg2000QuantStyle  *qntsty = tile->qntsty + compno;
-int ret; // global bandno
-
 comp->coord_o[0][0] = tile->coord[0][0];
 comp->coord_o[0][1] = tile->coord[0][1];
 comp->coord_o[1][0] = tile->coord[1][0];
@@ -1063,7 +1064,7 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
  s->cbps[compno], s->cdx[compno],
  s->cdy[compno], s->avctx, s->slices))
 return ret;
-}
+
 return 0;
 }
 
@@ -2371,9 +2372,6 @@ static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s)
 for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) {
 Jpeg2000Tile *tile = s->tile + tileno;
 
-if ((ret = init_tile(s, tileno)) < 0)
-return ret;
-
 if ((ret = jpeg2000_decode_packets(s, tile)) < 0)
 return ret;
 }
@@ -2668,6 +2666,9 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
 picture->key_frame = 1;
 s->slices = avctx->active_thread_type == FF_THREAD_SLICE ? avctx->thread_count : 1;
 
+if ((ret = avctx->execute2(avctx, init_tile, NULL, NULL, s->numXtiles * s->numYtiles * s->ncomponents)) < 0)
+goto end;
+
 if (ret = jpeg2000_read_bitstream_packets(s))
 goto end;
 
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 03/11] lavc/jpeg2000dwt: Implement sliced transforms

2022-09-28 Thread Tomas Härdin

From 159d744f09f39e3350ac39ac5d05feaca22103af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Fri, 10 Jun 2022 17:18:14 +0200
Subject: [PATCH 03/11] lavc/jpeg2000dwt: Implement sliced transforms

lavc/tests/jpeg2000dwt tests this.
---
 libavcodec/j2kenc.c|   3 +-
 libavcodec/jpeg2000.c  |   5 +-
 libavcodec/jpeg2000.h  |   2 +-
 libavcodec/jpeg2000dec.c   | 109 +++
 libavcodec/jpeg2000dwt.c   | 132 +++--
 libavcodec/jpeg2000dwt.h   |   6 +-
 libavcodec/tests/jpeg2000dwt.c |  15 ++--
 7 files changed, 189 insertions(+), 83 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index e883d5deb7..cd325e94e0 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -494,7 +494,8 @@ static int init_tiles(Jpeg2000EncoderContext *s)
 s->cbps[compno],
 compno?1avctx
+s->avctx,
+1
)) < 0)
 return ret;
 }
diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c
index 0aa984bc53..945b787565 100644
--- a/libavcodec/jpeg2000.c
+++ b/libavcodec/jpeg2000.c
@@ -467,7 +467,7 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
Jpeg2000CodingStyle *codsty,
Jpeg2000QuantStyle *qntsty,
int cbps, int dx, int dy,
-   AVCodecContext *avctx)
+   AVCodecContext *avctx, int max_slices)
 {
 int reslevelno, bandno, gbandno = 0, ret, i, j;
 uint32_t csize;
@@ -479,7 +479,8 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
 
 if (ret = ff_jpeg2000_dwt_init(&comp->dwt, comp->coord,
codsty->nreslevels2decode - 1,
-   codsty->transform))
+   codsty->transform,
+   max_slices))
 return ret;
 
 if (av_image_check_size(comp->coord[0][1] - comp->coord[0][0],
diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h
index e5ecb4cbf9..389813a9b9 100644
--- a/libavcodec/jpeg2000.h
+++ b/libavcodec/jpeg2000.h
@@ -280,7 +280,7 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp,
Jpeg2000CodingStyle *codsty,
Jpeg2000QuantStyle *qntsty,
int cbps, int dx, int dy,
-   AVCodecContext *ctx);
+   AVCodecContext *ctx, int max_slices);
 
 void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty);
 
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 92bd76d90f..273346538f 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -150,6 +150,10 @@ typedef struct Jpeg2000DecoderContext {
 size_t idwt_allocated;
 Jpeg2000CodeblockThread *cb;
 size_t cb_allocated;
+
+// used for idwt slicing
+int reslevel, dir, slices;
+int have_dwt97_int; // 1 if any coding style is FF_DWT97_INT
 } Jpeg2000DecoderContext;
 
 /* get_bits functions for JPEG2000 packet bitstream
@@ -545,9 +549,10 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
 }
 c->transform = bytestream2_get_byteu(&s->g); // DWT transformation type
 /* set integer 9/7 DWT in case of BITEXACT flag */
-if ((s->avctx->flags & AV_CODEC_FLAG_BITEXACT) && (c->transform == FF_DWT97))
+if ((s->avctx->flags & AV_CODEC_FLAG_BITEXACT) && (c->transform == FF_DWT97)) {
 c->transform = FF_DWT97_INT;
-else if (c->transform == FF_DWT53) {
+s->have_dwt97_int = 1;
+} else if (c->transform == FF_DWT53) {
 s->avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
 }
 
@@ -1056,7 +1061,7 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
 return AVERROR_INVALIDDATA;
 if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty,
  s->cbps[compno], s->cdx[compno],
- s->cdy[compno], s->avctx))
+ s->cdy[compno], s->avctx, s->slices))
 return ret;
 }
 return 0;
@@ -1997,19 +2002,74 @@ static int jpeg2000_decode_cb(AVCodecContext *avctx, void *td,
 return 0;
 }
 
+static int jpeg2000_dwt97_int_preshift(AVCodecContext *avctx, void *td,
+   int jobnr, int threadnr)
+{
+const Jpeg2000DecoderContext *s = avctx->priv_data;
+Jpeg2000IdwtThread *idwt 

[FFmpeg-devel] [PATCH 02/11] lavc/jpeg2000dec: Reindent

2022-09-28 Thread Tomas Härdin

From 99e9b6cf421538dee6e0280daf3d1ffc71c1acda Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Fri, 10 Jun 2022 14:12:11 +0200
Subject: [PATCH 02/11] lavc/jpeg2000dec: Reindent

---
 libavcodec/jpeg2000dec.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index e823ae58ec..92bd76d90f 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1973,26 +1973,26 @@ static int jpeg2000_decode_cb(AVCodecContext *avctx, void *td,
 t1.stride = (1coded = 0;
 
-ret = decode_cblk(s, codsty, &t1, cblk,
-cblk->coord[0][1] - cblk->coord[0][0],
-cblk->coord[1][1] - cblk->coord[1][0],
-bandpos, comp->roi_shift);
-if (ret)
-cb->coded = 1;
-else
-return 0;
+ret = decode_cblk(s, codsty, &t1, cblk,
+cblk->coord[0][1] - cblk->coord[0][0],
+cblk->coord[1][1] - cblk->coord[1][0],
+bandpos, comp->roi_shift);
+if (ret)
+cb->coded = 1;
+else
+return 0;
 
-x = cblk->coord[0][0] - band->coord[0][0];
-y = cblk->coord[1][0] - band->coord[1][0];
+x = cblk->coord[0][0] - band->coord[0][0];
+y = cblk->coord[1][0] - band->coord[1][0];
 
-if (comp->roi_shift)
-roi_scale_cblk(cblk, comp, &t1);
-if (codsty->transform == FF_DWT97)
-dequantization_float(x, y, cblk, comp, &t1, band);
-else if (codsty->transform == FF_DWT97_INT)
-dequantization_int_97(x, y, cblk, comp, &t1, band);
-else
-dequantization_int(x, y, cblk, comp, &t1, band);
+if (comp->roi_shift)
+roi_scale_cblk(cblk, comp, &t1);
+if (codsty->transform == FF_DWT97)
+dequantization_float(x, y, cblk, comp, &t1, band);
+else if (codsty->transform == FF_DWT97_INT)
+dequantization_int_97(x, y, cblk, comp, &t1, band);
+else
+dequantization_int(x, y, cblk, comp, &t1, band);
 
 return 0;
 }
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 01/11] lavc/jpeg2000dec: Finer granularity threading

2022-09-28 Thread Tomas Härdin
Hi

This patchset depends both on my execute2() patchset and on
av_realloc*_array_reuse(). The performance numbers aren't fully up to
date, but I expect they won't have changed much.

/Tomas
From 9f70f673b2977e969c2c6df51d7a2b7d73302f08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Fri, 10 Jun 2022 14:10:02 +0200
Subject: [PATCH 01/11] lavc/jpeg2000dec: Finer granularity threading

Decoding and dequant is now threaded on codeblock level.
IDWT is threaded on component level.
MCT and write_frame() remain threaded on tile level.

This brings lossless 4K J2K with -lowres 2 -thread_type slice -threads 96 on an AMD EPYC 7R32 from 4.8 fps (177% CPU) to 31 fps (1284% CPU).
---
 libavcodec/jpeg2000dec.c | 195 ---
 1 file changed, 141 insertions(+), 54 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index c2b81ec103..e823ae58ec 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -92,6 +92,15 @@ typedef struct Jpeg2000Tile {
 int coord[2][2];// border coordinates {{x0, x1}, {y0, y1}}
 } Jpeg2000Tile;
 
+typedef struct Jpeg2000IdwtThread {
+int cb_start, cb_end;
+} Jpeg2000IdwtThread;
+
+typedef struct Jpeg2000CodeblockThread {
+int tileno, compno, reslevelno, bandno, precno, cblkno;
+int coded;
+} Jpeg2000CodeblockThread;
+
 typedef struct Jpeg2000DecoderContext {
 AVClass *class;
 AVCodecContext  *avctx;
@@ -136,6 +145,11 @@ typedef struct Jpeg2000DecoderContext {
 
 /*options parameters*/
 int reduction_factor;
+
+Jpeg2000IdwtThread *idwt;
+size_t idwt_allocated;
+Jpeg2000CodeblockThread *cb;
+size_t cb_allocated;
 } Jpeg2000DecoderContext;
 
 /* get_bits functions for JPEG2000 packet bitstream
@@ -1941,54 +1955,33 @@ static inline void roi_scale_cblk(Jpeg2000Cblk *cblk,
 }
 }
 
-static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
+static int jpeg2000_decode_cb(AVCodecContext *avctx, void *td,
+  int jobnr, int threadnr)
 {
 Jpeg2000T1Context t1;
-
-int compno, reslevelno, bandno;
-
-/* Loop on tile components */
-for (compno = 0; compno < s->ncomponents; compno++) {
-Jpeg2000Component *comp = tile->comp + compno;
-Jpeg2000CodingStyle *codsty = tile->codsty + compno;
-int coded = 0;
-
-t1.stride = (1nreslevels2decode; reslevelno++) {
-Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
-/* Loop on bands */
-for (bandno = 0; bandno < rlevel->nbands; bandno++) {
-int nb_precincts, precno;
-Jpeg2000Band *band = rlevel->band + bandno;
-int cblkno = 0, bandpos;
-
-bandpos = bandno + (reslevelno > 0);
-
-if (band->coord[0][0] == band->coord[0][1] ||
-band->coord[1][0] == band->coord[1][1])
-continue;
-
-nb_precincts = rlevel->num_precincts_x * rlevel->num_precincts_y;
-/* Loop on precincts */
-for (precno = 0; precno < nb_precincts; precno++) {
-Jpeg2000Prec *prec = band->prec + precno;
-
-/* Loop on codeblocks */
-for (cblkno = 0;
- cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height;
- cblkno++) {
-int x, y;
-Jpeg2000Cblk *cblk = prec->cblk + cblkno;
-int ret = decode_cblk(s, codsty, &t1, cblk,
+const Jpeg2000DecoderContext *s = avctx->priv_data;
+Jpeg2000CodeblockThread *cb = s->cb + jobnr;
+Jpeg2000Tile *tile  = s->tile + cb->tileno;
+Jpeg2000Component *comp = tile->comp + cb->compno;
+Jpeg2000CodingStyle *codsty = tile->codsty + cb->compno;
+Jpeg2000ResLevel *rlevel= comp->reslevel + cb->reslevelno;
+Jpeg2000Band *band  = rlevel->band + cb->bandno;
+Jpeg2000Prec *prec  = band->prec + cb->precno;
+Jpeg2000Cblk *cblk  = prec->cblk + cb->cblkno;
+int ret, x, y, bandpos  = cb->bandno + (cb->reslevelno > 0);
+
+t1.stride = (1coded = 0;
+
+ret = decode_cblk(s, codsty, &t1, cblk,
 cblk->coord[0][1] - cblk->coord[0][0],
 cblk->coord[1][1] - cblk->coord[1][0],
 bandpos, comp->roi_shift);
 if (ret)
-coded = 1;
+cb->coded = 1;
 else
-continue;
+return 0;
+
   

[FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg: move some code from init_output_stream() to init_output_stream_encode()

2022-09-28 Thread Anton Khirnov
The code is subtitle-encoding-specific, so this is a more appropriate
place for it.
---
 fftools/ffmpeg.c | 58 
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 6deca8bfbf..754172e568 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3129,6 +3129,34 @@ static int init_output_stream_encode(OutputStream *ost, 
AVFrame *frame)
 enc_ctx->width = input_streams[ost->source_index]->par->width;
 enc_ctx->height= input_streams[ost->source_index]->par->height;
 }
+if (dec_ctx && dec_ctx->subtitle_header) {
+/* ASS code assumes this buffer is null terminated so add extra 
byte. */
+ost->enc_ctx->subtitle_header = 
av_mallocz(dec_ctx->subtitle_header_size + 1);
+if (!ost->enc_ctx->subtitle_header)
+return AVERROR(ENOMEM);
+memcpy(ost->enc_ctx->subtitle_header, dec_ctx->subtitle_header,
+   dec_ctx->subtitle_header_size);
+ost->enc_ctx->subtitle_header_size = dec_ctx->subtitle_header_size;
+}
+if (ist && ist->dec->type == AVMEDIA_TYPE_SUBTITLE &&
+enc_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+int input_props = 0, output_props = 0;
+AVCodecDescriptor const *input_descriptor =
+avcodec_descriptor_get(ist->dec->id);
+AVCodecDescriptor const *output_descriptor =
+avcodec_descriptor_get(ost->enc_ctx->codec_id);
+if (input_descriptor)
+input_props = input_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
+if (output_descriptor)
+output_props = output_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
+if (input_props && output_props && input_props != output_props) {
+av_log(NULL, AV_LOG_ERROR,
+   "Subtitle encoding currently only possible from text to 
text "
+   "or bitmap to bitmap");
+return AVERROR_INVALIDDATA;
+}
+}
+
 break;
 case AVMEDIA_TYPE_DATA:
 break;
@@ -3156,23 +3184,13 @@ static int init_output_stream(OutputStream *ost, 
AVFrame *frame,
 
 if (ost->enc_ctx) {
 const AVCodec *codec = ost->enc_ctx->codec;
-AVCodecContext *dec = NULL;
 InputStream *ist;
 
 ret = init_output_stream_encode(ost, frame);
 if (ret < 0)
 return ret;
 
-if ((ist = get_input_stream(ost)))
-dec = ist->dec_ctx;
-if (dec && dec->subtitle_header) {
-/* ASS code assumes this buffer is null terminated so add extra 
byte. */
-ost->enc_ctx->subtitle_header = 
av_mallocz(dec->subtitle_header_size + 1);
-if (!ost->enc_ctx->subtitle_header)
-return AVERROR(ENOMEM);
-memcpy(ost->enc_ctx->subtitle_header, dec->subtitle_header, 
dec->subtitle_header_size);
-ost->enc_ctx->subtitle_header_size = dec->subtitle_header_size;
-}
+ist = get_input_stream(ost);
 if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
 av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
 
@@ -3184,24 +3202,6 @@ static int init_output_stream(OutputStream *ost, AVFrame 
*frame,
 return ret;
 }
 
-if (ist && ist->dec->type == AVMEDIA_TYPE_SUBTITLE && codec->type == 
AVMEDIA_TYPE_SUBTITLE) {
-int input_props = 0, output_props = 0;
-AVCodecDescriptor const *input_descriptor =
-avcodec_descriptor_get(dec->codec_id);
-AVCodecDescriptor const *output_descriptor =
-avcodec_descriptor_get(ost->enc_ctx->codec_id);
-if (input_descriptor)
-input_props = input_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
-if (output_descriptor)
-output_props = output_descriptor->props & 
(AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
-if (input_props && output_props && input_props != output_props) {
-snprintf(error, error_len,
- "Subtitle encoding currently only possible from text 
to text "
- "or bitmap to bitmap");
-return AVERROR_INVALIDDATA;
-}
-}
-
 if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 
0) {
 if (ret == AVERROR_EXPERIMENTAL)
 abort_codec_experimental(codec, 1);
-- 
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".


[FFmpeg-devel] [PATCH 8/9] fftools/ffmpeg: rename OutputStream.sync_opts to next_pts

2022-09-28 Thread Anton Khirnov
The current name is confusing.
---
 fftools/ffmpeg.c | 22 --
 fftools/ffmpeg.h |  6 +++---
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 40c01b1c65..6deca8bfbf 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1044,12 +1044,12 @@ static void do_audio_out(OutputFile *of, OutputStream 
*ost,
 
 adjust_frame_pts_to_encoder_tb(of, ost, frame);
 
-if (!check_recording_time(ost, ost->sync_opts, ost->enc_ctx->time_base))
+if (!check_recording_time(ost, ost->next_pts, ost->enc_ctx->time_base))
 return;
 
 if (frame->pts == AV_NOPTS_VALUE)
-frame->pts = ost->sync_opts;
-ost->sync_opts = frame->pts + frame->nb_samples;
+frame->pts = ost->next_pts;
+ost->next_pts = frame->pts + frame->nb_samples;
 
 ret = submit_encode_frame(of, ost, frame);
 if (ret < 0 && ret != AVERROR_EOF)
@@ -1230,7 +1230,9 @@ static void do_video_out(OutputFile *of,
   ost->last_nb0_frames[1],
   ost->last_nb0_frames[2]);
 } else {
-delta0 = sync_ipts - ost->sync_opts; // delta0 is the "drift" between 
the input frame (next_picture) and where it would fall in the output.
+/* delta0 is the "drift" between the input frame (next_picture) and
+ * where it would fall in the output. */
+delta0 = sync_ipts - ost->next_pts;
 delta  = delta0 + duration;
 
 /* by default, we output a single frame */
@@ -1245,7 +1247,7 @@ static void do_video_out(OutputFile *of,
 av_log(NULL, AV_LOG_VERBOSE, "Past duration %f too large\n", 
-delta0);
 } else
 av_log(NULL, AV_LOG_DEBUG, "Clipping frame in rate conversion 
by %f\n", -delta0);
-sync_ipts = ost->sync_opts;
+sync_ipts = ost->next_pts;
 duration += delta0;
 delta0 = 0;
 }
@@ -1256,7 +1258,7 @@ static void do_video_out(OutputFile *of,
 av_log(NULL, AV_LOG_DEBUG, "Not duplicating %d initial 
frames\n", (int)lrintf(delta0));
 delta = duration;
 delta0 = 0;
-ost->sync_opts = llrint(sync_ipts);
+ost->next_pts = llrint(sync_ipts);
 }
 case VSYNC_CFR:
 // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
@@ -1275,13 +1277,13 @@ static void do_video_out(OutputFile *of,
 if (delta <= -0.6)
 nb_frames = 0;
 else if (delta > 0.6)
-ost->sync_opts = llrint(sync_ipts);
+ost->next_pts = llrint(sync_ipts);
 next_picture->duration = duration;
 break;
 case VSYNC_DROP:
 case VSYNC_PASSTHROUGH:
 next_picture->duration = duration;
-ost->sync_opts = llrint(sync_ipts);
+ost->next_pts = llrint(sync_ipts);
 break;
 default:
 av_assert0(0);
@@ -1335,7 +1337,7 @@ static void do_video_out(OutputFile *of,
 if (!in_picture)
 return;
 
-in_picture->pts = ost->sync_opts;
+in_picture->pts = ost->next_pts;
 
 if (!check_recording_time(ost, in_picture->pts, 
ost->enc_ctx->time_base))
 return;
@@ -1347,7 +1349,7 @@ static void do_video_out(OutputFile *of,
 if (ret < 0 && ret != AVERROR_EOF)
 exit_program(1);
 
-ost->sync_opts++;
+ost->next_pts++;
 ost->vsync_frame_number++;
 }
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index a9883c0442..d466a1ff9f 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -492,9 +492,9 @@ typedef struct OutputStream {
 AVStream *st;/* stream in the output file */
 /* number of frames emitted by the video-encoding sync code */
 int64_t vsync_frame_number;
-/* input pts and corresponding output pts
-   for A/V sync */
-int64_t sync_opts;   /* output frame counter, could be changed to some 
true timestamp */ // FIXME look at frame_number
+/* predicted pts of the next frame to be encoded
+ * audio/video encoding only */
+int64_t next_pts;
 /* dts of the last packet sent to the muxing queue, in AV_TIME_BASE_Q */
 int64_t last_mux_dts;
 /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */
-- 
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".


[FFmpeg-devel] [PATCH 5/9] fftools/ffmpeg: drop never-set OutputStream.first_pts

2022-09-28 Thread Anton Khirnov
---
 fftools/ffmpeg.c | 2 +-
 fftools/ffmpeg.h | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 697971167c..971c146fea 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -763,7 +763,7 @@ static int check_recording_time(OutputStream *ost)
 OutputFile *of = output_files[ost->file_index];
 
 if (of->recording_time != INT64_MAX &&
-av_compare_ts(ost->sync_opts - ost->first_pts, 
ost->enc_ctx->time_base, of->recording_time,
+av_compare_ts(ost->sync_opts, ost->enc_ctx->time_base, 
of->recording_time,
   AV_TIME_BASE_Q) >= 0) {
 close_output_stream(ost);
 return 0;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 8acc83e92a..a9883c0442 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -495,9 +495,6 @@ typedef struct OutputStream {
 /* input pts and corresponding output pts
for A/V sync */
 int64_t sync_opts;   /* output frame counter, could be changed to some 
true timestamp */ // FIXME look at frame_number
-/* pts of the first frame encoded for this stream, used for limiting
- * recording time */
-int64_t first_pts;
 /* dts of the last packet sent to the muxing queue, in AV_TIME_BASE_Q */
 int64_t last_mux_dts;
 /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */
-- 
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".


[FFmpeg-devel] [PATCH 3/9] fftools/ffmpeg: move forced keyframe processing into its own function

2022-09-28 Thread Anton Khirnov
---
 fftools/ffmpeg.c | 108 +--
 1 file changed, 58 insertions(+), 50 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 2054271c82..833df0b167 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1133,6 +1133,63 @@ static void do_subtitle_out(OutputFile *of,
 }
 }
 
+static enum AVPictureType forced_kf_apply(OutputStream *ost,
+  const AVFrame *in_picture, int 
dup_idx)
+{
+AVCodecContext *enc = ost->enc_ctx;
+double pts_time;
+
+if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE)
+ost->forced_kf_ref_pts = in_picture->pts;
+
+pts_time = (in_picture->pts - ost->forced_kf_ref_pts) * 
av_q2d(enc->time_base);
+if (ost->forced_kf_index < ost->forced_kf_count &&
+in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
+ost->forced_kf_index++;
+goto force_keyframe;
+} else if (ost->forced_keyframes_pexpr) {
+double res;
+ost->forced_keyframes_expr_const_values[FKF_T] = pts_time;
+res = av_expr_eval(ost->forced_keyframes_pexpr,
+   ost->forced_keyframes_expr_const_values, NULL);
+ff_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f 
t:%f prev_forced_t:%f -> res:%f\n",
+ost->forced_keyframes_expr_const_values[FKF_N],
+ost->forced_keyframes_expr_const_values[FKF_N_FORCED],
+ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N],
+ost->forced_keyframes_expr_const_values[FKF_T],
+ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T],
+res);
+
+ost->forced_keyframes_expr_const_values[FKF_N] += 1;
+
+if (res) {
+ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] =
+ost->forced_keyframes_expr_const_values[FKF_N] - 1;
+ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] =
+ost->forced_keyframes_expr_const_values[FKF_T];
+ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1;
+goto force_keyframe;
+}
+} else if (   ost->forced_keyframes
+   && !strncmp(ost->forced_keyframes, "source", 6)
+   && in_picture->key_frame==1
+   && !dup_idx) {
+goto force_keyframe;
+} else if (   ost->forced_keyframes
+   && !strncmp(ost->forced_keyframes, "source_no_drop", 14)
+   && !dup_idx) {
+ost->dropped_keyframe = 0;
+if ((in_picture->key_frame == 1) || ost->dropped_keyframe)
+goto force_keyframe;
+}
+
+return AV_PICTURE_TYPE_NONE;
+
+force_keyframe:
+av_log(NULL, AV_LOG_DEBUG, "Forced keyframe at time %f\n", pts_time);
+return AV_PICTURE_TYPE_I;
+}
+
 /* May modify/reset next_picture */
 static void do_video_out(OutputFile *of,
  OutputStream *ost,
@@ -1272,8 +1329,6 @@ static void do_video_out(OutputFile *of,
 /* duplicates frame if needed */
 for (i = 0; i < nb_frames; i++) {
 AVFrame *in_picture;
-int forced_keyframe = 0;
-double pts_time;
 
 if (i < nb0_frames && ost->last_frame->buf[0]) {
 in_picture = ost->last_frame;
@@ -1289,54 +1344,7 @@ static void do_video_out(OutputFile *of,
 return;
 
 in_picture->quality = enc->global_quality;
-in_picture->pict_type = 0;
-
-if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE)
-ost->forced_kf_ref_pts = in_picture->pts;
-
-pts_time = (in_picture->pts - ost->forced_kf_ref_pts) * 
av_q2d(enc->time_base);
-if (ost->forced_kf_index < ost->forced_kf_count &&
-in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
-ost->forced_kf_index++;
-forced_keyframe = 1;
-} else if (ost->forced_keyframes_pexpr) {
-double res;
-ost->forced_keyframes_expr_const_values[FKF_T] = pts_time;
-res = av_expr_eval(ost->forced_keyframes_pexpr,
-   ost->forced_keyframes_expr_const_values, NULL);
-ff_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f 
t:%f prev_forced_t:%f -> res:%f\n",
-ost->forced_keyframes_expr_const_values[FKF_N],
-ost->forced_keyframes_expr_const_values[FKF_N_FORCED],
-ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N],
-ost->forced_keyframes_expr_const_values[FKF_T],
-ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T],
-res);
-if (res) {
-forced_keyframe = 1;
-ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] =

[FFmpeg-devel] [PATCH 4/9] fftools/ffmpeg: cosmetics

2022-09-28 Thread Anton Khirnov
Reindent after previous commit, apply some style fixes.
---
 fftools/ffmpeg.c | 85 
 1 file changed, 42 insertions(+), 43 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 833df0b167..697971167c 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1137,51 +1137,50 @@ static enum AVPictureType forced_kf_apply(OutputStream 
*ost,
   const AVFrame *in_picture, int 
dup_idx)
 {
 AVCodecContext *enc = ost->enc_ctx;
-double pts_time;
-
-if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE)
-ost->forced_kf_ref_pts = in_picture->pts;
-
-pts_time = (in_picture->pts - ost->forced_kf_ref_pts) * 
av_q2d(enc->time_base);
-if (ost->forced_kf_index < ost->forced_kf_count &&
-in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
-ost->forced_kf_index++;
-goto force_keyframe;
-} else if (ost->forced_keyframes_pexpr) {
-double res;
-ost->forced_keyframes_expr_const_values[FKF_T] = pts_time;
-res = av_expr_eval(ost->forced_keyframes_pexpr,
-   ost->forced_keyframes_expr_const_values, NULL);
-ff_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f 
t:%f prev_forced_t:%f -> res:%f\n",
-ost->forced_keyframes_expr_const_values[FKF_N],
-ost->forced_keyframes_expr_const_values[FKF_N_FORCED],
-ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N],
-ost->forced_keyframes_expr_const_values[FKF_T],
-ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T],
-res);
-
-ost->forced_keyframes_expr_const_values[FKF_N] += 1;
-
-if (res) {
-ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] =
-ost->forced_keyframes_expr_const_values[FKF_N] - 1;
-ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] =
-ost->forced_keyframes_expr_const_values[FKF_T];
-ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1;
-goto force_keyframe;
-}
-} else if (   ost->forced_keyframes
-   && !strncmp(ost->forced_keyframes, "source", 6)
-   && in_picture->key_frame==1
-   && !dup_idx) {
+double pts_time;
+
+if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE)
+ost->forced_kf_ref_pts = in_picture->pts;
+
+pts_time = (in_picture->pts - ost->forced_kf_ref_pts) * 
av_q2d(enc->time_base);
+if (ost->forced_kf_index < ost->forced_kf_count &&
+in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
+ost->forced_kf_index++;
+goto force_keyframe;
+} else if (ost->forced_keyframes_pexpr) {
+double res;
+ost->forced_keyframes_expr_const_values[FKF_T] = pts_time;
+res = av_expr_eval(ost->forced_keyframes_pexpr,
+   ost->forced_keyframes_expr_const_values, NULL);
+ff_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f 
prev_forced_t:%f -> res:%f\n",
+ost->forced_keyframes_expr_const_values[FKF_N],
+ost->forced_keyframes_expr_const_values[FKF_N_FORCED],
+ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N],
+ost->forced_keyframes_expr_const_values[FKF_T],
+ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T],
+res);
+
+ost->forced_keyframes_expr_const_values[FKF_N] += 1;
+
+if (res) {
+ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] =
+ost->forced_keyframes_expr_const_values[FKF_N] - 1;
+ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] =
+ost->forced_keyframes_expr_const_values[FKF_T];
+ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1;
 goto force_keyframe;
-} else if (   ost->forced_keyframes
-   && !strncmp(ost->forced_keyframes, "source_no_drop", 14)
-   && !dup_idx) {
-ost->dropped_keyframe = 0;
-if ((in_picture->key_frame == 1) || ost->dropped_keyframe)
-goto force_keyframe;
 }
+} else if (ost->forced_keyframes&&
+   !strncmp(ost->forced_keyframes, "source", 6) &&
+   in_picture->key_frame == 1 && !dup_idx) {
+goto force_keyframe;
+} else if (ost->forced_keyframes &&
+   !strncmp(ost->forced_keyframes, "source_no_drop", 14) &&
+   !dup_idx) {
+ost->dropped_keyframe = 0;
+if ((in_picture->key_frame == 1) || ost->dropped_keyframe)
+goto force_keyframe;
+}
 
 ret

[FFmpeg-devel] [PATCH 7/9] fftools/ffmpeg: pass the timestamp to check_recording_time()

2022-09-28 Thread Anton Khirnov
Stop setting OutputStream.sync_opts for subtitle encoding, as it is now
unused.
---
 fftools/ffmpeg.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1a6768f6c2..40c01b1c65 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -758,13 +758,12 @@ fail:
 
 }
 
-static int check_recording_time(OutputStream *ost)
+static int check_recording_time(OutputStream *ost, int64_t ts, AVRational tb)
 {
 OutputFile *of = output_files[ost->file_index];
 
 if (of->recording_time != INT64_MAX &&
-av_compare_ts(ost->sync_opts, ost->enc_ctx->time_base, 
of->recording_time,
-  AV_TIME_BASE_Q) >= 0) {
+av_compare_ts(ts, tb, of->recording_time, AV_TIME_BASE_Q) >= 0) {
 close_output_stream(ost);
 return 0;
 }
@@ -1045,7 +1044,7 @@ static void do_audio_out(OutputFile *of, OutputStream 
*ost,
 
 adjust_frame_pts_to_encoder_tb(of, ost, frame);
 
-if (!check_recording_time(ost))
+if (!check_recording_time(ost, ost->sync_opts, ost->enc_ctx->time_base))
 return;
 
 if (frame->pts == AV_NOPTS_VALUE)
@@ -1091,8 +1090,7 @@ static void do_subtitle_out(OutputFile *of,
 for (i = 0; i < nb; i++) {
 unsigned save_num_rects = sub->num_rects;
 
-ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base);
-if (!check_recording_time(ost))
+if (!check_recording_time(ost, pts, AV_TIME_BASE_Q))
 return;
 
 ret = av_new_packet(pkt, subtitle_out_max_size);
@@ -1339,7 +1337,7 @@ static void do_video_out(OutputFile *of,
 
 in_picture->pts = ost->sync_opts;
 
-if (!check_recording_time(ost))
+if (!check_recording_time(ost, in_picture->pts, 
ost->enc_ctx->time_base))
 return;
 
 in_picture->quality = enc->global_quality;
-- 
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".


[FFmpeg-devel] [PATCH 6/9] fftools/ffmpeg: stop setting OutputStream.sync_opts for streamcopy

2022-09-28 Thread Anton Khirnov
It is not used for anything.
---
 fftools/ffmpeg.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 971c146fea..1a6768f6c2 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1934,8 +1934,6 @@ static void do_streamcopy(InputStream *ist, OutputStream 
*ost, const AVPacket *p
 
 opkt->duration = av_rescale_q(pkt->duration, ist->st->time_base, 
ost->mux_timebase);
 
-ost->sync_opts += opkt->duration;
-
 output_packet(of, opkt, ost, 0);
 
 ost->streamcopy_started = 1;
-- 
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".


[FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg: drop the -async option

2022-09-28 Thread Anton Khirnov
It has been deprecated in favor of the aresample filter for almost 10
years.

Another thing this option can do is drop audio timestamps and have them
generated by the encoding code or the muxer, but
- for encoding, this can already be done with the setpts filter
- for muxing this should almost never be done as timestamp generation by
  the muxer is deprecated, but people who really want to do this can use
  the setts bitstream filter
---
 doc/ffmpeg.texi | 12 
 fftools/ffmpeg.c|  2 +-
 fftools/ffmpeg.h|  1 -
 fftools/ffmpeg_filter.c | 10 --
 fftools/ffmpeg_mux.c|  3 +--
 fftools/ffmpeg_opt.c|  3 ---
 6 files changed, 2 insertions(+), 29 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 42440d93b4..e9020b30d5 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1697,18 +1697,6 @@ The default is -1.1. One possible usecase is to avoid 
framedrops in case
 of noisy timestamps or to increase frame drop precision in case of exact
 timestamps.
 
-@item -async @var{samples_per_second}
-Audio sync method. "Stretches/squeezes" the audio stream to match the 
timestamps,
-the parameter is the maximum samples per second by which the audio is changed.
--async 1 is a special case where only the start of the audio stream is 
corrected
-without any later correction.
-
-Note that the timestamps may be further modified by the muxer, after this.
-For example, in the case that the format option @option{avoid_negative_ts}
-is enabled.
-
-This option has been deprecated. Use the @code{aresample} audio filter instead.
-
 @item -adrift_threshold @var{time}
 Set the minimum difference between timestamps and audio data (in seconds) to 
trigger
 adding/dropping samples to make it match the timestamps. This option 
effectively is
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 69716de6b6..f84701ec75 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1048,7 +1048,7 @@ static void do_audio_out(OutputFile *of, OutputStream 
*ost,
 if (!check_recording_time(ost))
 return;
 
-if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0)
+if (frame->pts == AV_NOPTS_VALUE)
 frame->pts = ost->sync_opts;
 ost->sync_opts = frame->pts + frame->nb_samples;
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index ede0b2bd96..8acc83e92a 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -656,7 +656,6 @@ extern float audio_drift_threshold;
 extern float dts_delta_threshold;
 extern float dts_error_threshold;
 
-extern int audio_sync_method;
 extern enum VideoSyncMethod video_sync_method;
 extern float frame_drop_threshold;
 extern int do_benchmark;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 17928cea2c..82abb38a93 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -892,16 +892,6 @@ static int configure_input_audio_filter(FilterGraph *fg, 
InputFilter *ifilter,
 last_filter = filt_ctx; \
 } while (0)
 
-if (audio_sync_method > 0) {
-char args[256] = {0};
-
-av_strlcatf(args, sizeof(args), "async=%d", audio_sync_method);
-av_strlcatf(args, sizeof(args), ":min_hard_comp=%f", 
audio_drift_threshold);
-if (!fg->reconfiguration)
-av_strlcatf(args, sizeof(args), ":first_pts=0");
-AUTO_INSERT_FILTER_INPUT("-async", "aresample", args);
-}
-
 snprintf(name, sizeof(name), "trim for input stream %d:%d",
  ist->file_index, ist->st->index);
 if (copy_ts) {
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index b781e1f5a6..395f7cc89f 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -102,8 +102,7 @@ static int write_packet(OutputFile *of, OutputStream *ost, 
AVPacket *pkt)
 goto fail;
 }
 
-if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->vsync_method 
== VSYNC_DROP) ||
-(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 
0))
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == 
VSYNC_DROP)
 pkt->pts = pkt->dts = AV_NOPTS_VALUE;
 
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 5febe319e4..8f57b699f1 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -157,7 +157,6 @@ float audio_drift_threshold = 0.1;
 float dts_delta_threshold   = 10;
 float dts_error_threshold   = 3600*30;
 
-int audio_sync_method = 0;
 enum VideoSyncMethod video_sync_method = VSYNC_AUTO;
 float frame_drop_threshold = 0;
 int do_benchmark  = 0;
@@ -3910,8 +3909,6 @@ const OptionDef options[] = {
 "set video sync method globally; deprecated, use -fps_mode", "" },
 { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT,  { 
&frame_drop_threshold },
 "frame drop threshold", "" },
-{ "async",  HAS_ARG | OPT_INT | OPT_EXPERT,  { 
&audio_sync_method },
-"

[FFmpeg-devel] [PATCH 2/9] fftools/ffmpeg: drop always-true conditions

2022-09-28 Thread Anton Khirnov
in_picture->pts cannot be AV_NOPTS_VALUE, as it is set to ost->sync_opts
a few lines above. ost->sync_opts is never AV_NOPTS_VALUE.
---
 fftools/ffmpeg.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index f84701ec75..2054271c82 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1291,12 +1291,10 @@ static void do_video_out(OutputFile *of,
 in_picture->quality = enc->global_quality;
 in_picture->pict_type = 0;
 
-if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE &&
-in_picture->pts != AV_NOPTS_VALUE)
+if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE)
 ost->forced_kf_ref_pts = in_picture->pts;
 
-pts_time = in_picture->pts != AV_NOPTS_VALUE ?
-(in_picture->pts - ost->forced_kf_ref_pts) * 
av_q2d(enc->time_base) : NAN;
+pts_time = (in_picture->pts - ost->forced_kf_ref_pts) * 
av_q2d(enc->time_base);
 if (ost->forced_kf_index < ost->forced_kf_count &&
 in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
 ost->forced_kf_index++;
-- 
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] [PATCH 2/7] lavc/idctdsp: RISC-V V put_pixels_clamped function

2022-09-28 Thread Lynne
Sep 28, 2022, 10:06 by r...@remlab.net:

> Le 27 septembre 2022 23:04:22 GMT+03:00, r...@remlab.net a écrit :
> >From: Rémi Denis-Courmont 
>
>>
>>
> >---
>
>> libavcodec/idctdsp.c|  2 ++
>> libavcodec/idctdsp.h|  2 ++
>> libavcodec/riscv/Makefile   |  2 ++
>> libavcodec/riscv/idctdsp_init.c | 41 +++
>> libavcodec/riscv/idctdsp_rvv.S  | 43 +
>> 5 files changed, 90 insertions(+)
>> create mode 100644 libavcodec/riscv/idctdsp_init.c
>> create mode 100644 libavcodec/riscv/idctdsp_rvv.S
>>
> >diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c
> >index 9035003b72..4ee9c3aa74 100644
> >--- a/libavcodec/idctdsp.c
> >+++ b/libavcodec/idctdsp.c
> >@@ -312,6 +312,8 @@ av_cold void ff_idctdsp_init(IDCTDSPContext *c, 
> >AVCodecContext *avctx)
>
>> ff_idctdsp_init_arm(c, avctx, high_bit_depth);
>> #elif ARCH_PPC
>>  ff_idctdsp_init_ppc(c, avctx, high_bit_depth);
>>
> >+#elif ARCH_RISCV
> >+ff_idctdsp_init_riscv(c, avctx, high_bit_depth);
>
>> #elif ARCH_X86
>>  ff_idctdsp_init_x86(c, avctx, high_bit_depth);
>> #elif ARCH_MIPS
>>
> >diff --git a/libavcodec/idctdsp.h b/libavcodec/idctdsp.h
> >index e8f20acaf2..2bd9820f72 100644
> >--- a/libavcodec/idctdsp.h
> >+++ b/libavcodec/idctdsp.h
> >@@ -114,6 +114,8 @@ void ff_idctdsp_init_arm(IDCTDSPContext *c, 
> >AVCodecContext *avctx,
>
>> unsigned high_bit_depth);
>> void ff_idctdsp_init_ppc(IDCTDSPContext *c, AVCodecContext *avctx,
>>  unsigned high_bit_depth);
>>
> >+void ff_idctdsp_init_riscv(IDCTDSPContext *c, AVCodecContext *avctx,
> >+   unsigned high_bit_depth);
>
>> void ff_idctdsp_init_x86(IDCTDSPContext *c, AVCodecContext *avctx,
>>  unsigned high_bit_depth);
>> void ff_idctdsp_init_mips(IDCTDSPContext *c, AVCodecContext *avctx,
>>
> >diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
> >index 829a1823d2..96925afdab 100644
> >--- a/libavcodec/riscv/Makefile
> >+++ b/libavcodec/riscv/Makefile
> >@@ -5,6 +5,8 @@ OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_init.o \
>
>> RVV-OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_rvv.o
>> OBJS-$(CONFIG_FMTCONVERT) += riscv/fmtconvert_init.o
>> RVV-OBJS-$(CONFIG_FMTCONVERT) += riscv/fmtconvert_rvv.o
>>
> >+OBJS-$(CONFIG_IDCTDSP) += riscv/idctdsp_init.o
> >+RVV-OBJS-$(CONFIG_IDCTDSP) += riscv/idctdsp_rvv.o
>
>> OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_init.o \
>>  riscv/pixblockdsp_rvi.o
>> OBJS-$(CONFIG_VORBIS_DECODER) += riscv/vorbisdsp_init.o
>>
> >diff --git a/libavcodec/riscv/idctdsp_init.c 
> >b/libavcodec/riscv/idctdsp_init.c
> >new file mode 100644
> >index 00..1a6add80da
> >--- /dev/null
> >+++ b/libavcodec/riscv/idctdsp_init.c
> >@@ -0,0 +1,41 @@
> >+/*
> >+ * Copyright © 2022 Rémi Denis-Courmont.
> >+ *
> >+ * 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 
> >+
> >+#include "libavutil/attributes.h"
> >+#include "libavutil/cpu.h"
> >+#include "libavutil/riscv/cpu.h"
> >+#include "libavcodec/avcodec.h"
> >+#include "libavcodec/idctdsp.h"
> >+
> >+void ff_put_pixels_clamped_rvv(const int16_t *block, uint8_t *pixels,
> >+   ptrdiff_t stride);
> >+
> >+av_cold void ff_idctdsp_init_riscv(IDCTDSPContext *c, AVCodecContext *avctx,
> >+   unsigned high_bit_depth)
> >+{
> >+#if HAVE_RVV
> >+int flags = av_get_cpu_flags();
> >+
> >+if ((flags & AV_CPU_FLAG_RVV_I32) && ff_get_rv_vlenb() >= 16)
> >+c->put_pixels_clamped = ff_put_pixels_clamped_rvv;
> >+#endif
> >+}
> >diff --git a/libavcodec/riscv/idctdsp_rvv.S b/libavcodec/riscv/idctdsp_rvv.S
> >new file mode 100644
> >index 00..a59edd0a83
> >--- /dev/null
> >+++ b/libavcodec/riscv/idctdsp_rvv.S
> >@@ -0,0 +1,43 @@
> >+/*
> >+ * Copyright © 2022 Rémi Denis-Courmont.
> >+ *
> >+ * 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 WAR

Re: [FFmpeg-devel] [PATCH] mediacodecdec_common: enable refcounting of buffers unconditionally

2022-09-28 Thread Matthieu Bouron
On Wed, Sep 28, 2022 at 10:27:49AM +0200, Anton Khirnov wrote:
> Quoting sfan5 (2022-09-18 20:26:48)
> > This allows av_mediacodec_release_buffer to be called safely after
> > the decoder is closed, this was already the case with delay_flush=1.
> > Note that this causes holding onto frames to keep the decoding context
> > alive which is generally considered to be the intended behavior
> > 
> > 
> > (resending as my patch got mangled somehow)
> 
> The patch looks like it makes sense, but I have no experience with this
> code. CCing the maintainer, will push in a few days if nobody objects.

Sorry for the wait, the patch looks good to me.

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

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


Re: [FFmpeg-devel] [PATCH 3/8] avutil/mem: Add av_fast_realloc_array()

2022-09-28 Thread Tomas Härdin
tis 2022-09-27 klockan 17:23 +0200 skrev Tomas Härdin:
> mån 2022-09-26 klockan 16:24 +0200 skrev Tomas Härdin:
> > mån 2022-09-26 klockan 14:25 +0200 skrev Andreas Rheinhardt:
> > > Anton Khirnov:
> > > > Quoting Andreas Rheinhardt (2022-07-14 14:51:07)
> > > > > Anton Khirnov:
> > > > > > Quoting Andreas Rheinhardt (2022-07-12 16:12:16)
> > > > > > > Anton really dislikes the av_fast_* naming and instead
> > > > > > > wants
> > > > > > > this to be
> > > > > > > called av_realloc_array_reuse(). I don't care either way.
> > > > > > > Any
> > > > > > > more
> > > > > > > opinions on this (or on the patch itself)?
> > > > > > 
> > > > > > If people dislike _reuse(), I am open to other reasonable
> > > > > > suggestions.
> > > > > > This 'fast' naming sucks because
> > > > > > - it tells you nothing about how this function is "fast"
> > > > > > - it is added at the beginning rather than the end, which
> > > > > > is
> > > > > >   against standard namespacing conventions
> > > > > > 
> > > > > 
> > > > > Isn't reusing the basic modus operandi for a reallocation
> > > > > function? So
> > > > > your suggested name doesn't seem to fit either.
> > > > 
> > > > Ordinary realloc just keeps the data, I wouldn't call that
> > > > "reuse"
> > > > since
> > > > it will often be a copy. This "fast" realloc OTOH reuses the
> > > > actual
> > > > buffer, same as all the other "fast" mem.h functions.
> > > > 
> > > > But feel free to suggest another naming pattern if you can
> > > > think
> > > > of
> > > > one.
> > > > 
> > > 
> > > I see two differences between this function and ordinary realloc:
> > > It
> > > never shrinks the buffer and it overallocates. These two
> > > properties
> > > make
> > > it more likely that these functions can avoid copies more often
> > > than
> > > plain realloc (but in contrast to realloc, we can not grow the
> > > buffer
> > > in
> > > case there is free space after it), but it is nevertheless the
> > > same
> > > as
> > > realloc.
> > > 
> > > But I don't really care that much about the name and will
> > > therefore
> > > use
> > > your name as I can't come up with anything better.
> > > (Of course, I am still open to alternative suggestions.)
> > > 
> > > - Andreas
> > 
> > So this means av_realloc_array_reuse()? Eh, it works. I will add a
> > function that also zeroes the newly allocated space, what should we
> > call that? av_realloc_array_reusez()?
> > av_realloc_array_reuse_zerofill()?
> 
> Here's a draft patch that calls it av_reallocz_array_reuse(). Needs a
> minor version bump of course

This makes me realize something: av_realloc_array_reuse() requires that
*nb_allocated == 0 initially but this isn't specified in the
documentation. Patch attached relaxes this.

/Tomas
From df72691f514e2437b1917d808b6fcd153c393c20 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Wed, 28 Sep 2022 11:34:45 +0200
Subject: [PATCH] lavu/mem: Do not require *nb_allocated == 0 when *ptr == NULL

---
 libavutil/mem.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavutil/mem.c b/libavutil/mem.c
index 781dcbaded..bd2ee342fe 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -561,7 +561,10 @@ int av_realloc_array_reuse(void *ptr, size_t *nb_allocated,
 void *array;
 size_t nb, max_alloc_size_bytes;
 
-if (min_nb <= *nb_allocated)
+memcpy(&array, ptr, sizeof(array));
+
+// make no demands on *nb_allocated if *ptr == NULL
+if (array && min_nb <= *nb_allocated)
 return 0;
 
 max_alloc_size_bytes = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
@@ -571,7 +574,6 @@ int av_realloc_array_reuse(void *ptr, size_t *nb_allocated,
 return AVERROR(ERANGE);
 
 nb = compute_nb(min_nb, max_nb);
-memcpy(&array, ptr, sizeof(array));
 
 array = av_realloc(array, nb * elsize);
 if (!array)
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 1/3] lavc/encode: make sure frame timebase matches encoder, when set

2022-09-28 Thread Anton Khirnov
AVFrame.time_base has been added recently, but is currently not used for
anything. Prepare for its use in encoders by rejecting frames where
time_base is set, but differs from the AVCodecContext one.
---
 libavcodec/avcodec.h | 4 
 libavcodec/encode.c  | 8 
 libavutil/frame.h| 5 +++--
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7365eb5cc0..4030675d4f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2645,6 +2645,10 @@ int avcodec_receive_frame(AVCodecContext *avctx, AVFrame 
*frame);
  *  packets are ignored, and sending frames will return
  *  AVERROR_EOF.
  *
+ *  frame->time_base should be set to the same value as
+ *  avctx->time_base. This is not required yet, but may be in
+ *  the future.
+ *
  *  For audio:
  *  If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  *  can have any number of samples.
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index b275344bd1..0f78012747 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -386,6 +386,14 @@ static int encode_send_frame_internal(AVCodecContext 
*avctx, const AVFrame *src)
 AVFrame *dst = avci->buffer_frame;
 int ret;
 
+/* make sure the frame's timebase (if set) matches the encoder one */
+if (src->time_base.num &&
+(src->time_base.num != avctx->time_base.num ||
+ src->time_base.den != avctx->time_base.den)) {
+av_log(avctx, AV_LOG_ERROR, "Mismatching frame/encoder time base\n");
+return AVERROR(EINVAL);
+}
+
 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
 /* extract audio service type metadata */
 AVFrameSideData *sd = av_frame_get_side_data(src, 
AV_FRAME_DATA_AUDIO_SERVICE_TYPE);
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 6d9563bc5d..c5e2de85b3 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -441,8 +441,9 @@ typedef struct AVFrame {
 /**
  * Time base for the timestamps in this frame.
  * In the future, this field may be set on frames output by decoders or
- * filters, but its value will be by default ignored on input to encoders
- * or filters.
+ * filters; its value will be by default ignored on input to filters.
+ * For frames sent to encoders, it should be set by the user to the same
+ * value as AVCodecContext.time_base.
  */
 AVRational time_base;
 
-- 
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".


[FFmpeg-devel] [PATCH 3/3] lavc/encode: combine setting no-delay pts for video/audio

2022-09-28 Thread Anton Khirnov
---
 libavcodec/encode.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index fb3ab0db3c..a1bc10fa3a 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -209,13 +209,13 @@ int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket 
*avpkt,
 av_assert0(avpkt->buf);
 }
 
-if (avctx->codec->type == AVMEDIA_TYPE_VIDEO &&
-!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
-avpkt->pts = frame->pts;
+// set the timestamps for the simple no-delay case
+// encoders with delay have to set the timestamps themselves
 if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
+if (avpkt->pts == AV_NOPTS_VALUE)
+avpkt->pts = frame->pts;
+
 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
-if (avpkt->pts == AV_NOPTS_VALUE)
-avpkt->pts = frame->pts;
 if (!avpkt->duration)
 avpkt->duration = ff_samples_to_time_base(avctx,
   
frame->nb_samples);
-- 
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".


[FFmpeg-devel] [PATCH 2/3] lavc/encode: generalize a check for setting dts=pts

2022-09-28 Thread Anton Khirnov
DTS may be different from PTS only if both of these are true:
- the codec supports reordering
- the encoder has delay
---
 libavcodec/encode.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 0f78012747..fb3ab0db3c 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -211,7 +211,7 @@ int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket 
*avpkt,
 
 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO &&
 !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
-avpkt->pts = avpkt->dts = frame->pts;
+avpkt->pts = frame->pts;
 if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
 if (avpkt->pts == AV_NOPTS_VALUE)
@@ -221,9 +221,12 @@ int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket 
*avpkt,
   
frame->nb_samples);
 }
 }
-if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
+
+// dts equals pts unless there is reordering
+// there can be no reordering if there is no encoder delay
+if (!(avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) ||
+!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
 avpkt->dts = avpkt->pts;
-}
 } else {
 unref:
 av_packet_unref(avpkt);
-- 
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".


[FFmpeg-devel] [PATCH 8/8] lavfi/avf_showspatial: add framerate option

2022-09-28 Thread Anton Khirnov
Apparently this option was intended (the context contains a
currently-unused frame_rate field), but was never added. This results in
the output timebase being unset after config_output(), so the input
audio timebase ends up being used for video output, which is clearly
wrong.

Add an option for setting output video framerate. Also set output frame
durations.
---
 doc/filters.texi  | 3 +++
 libavfilter/avf_showspatial.c | 4 
 libavfilter/version.h | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index d0f718678c..7e516a43ba 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -29337,6 +29337,9 @@ Default value is @code{hann}.
 Set ratio of overlap window. Default value is @code{0.5}.
 When value is @code{1} overlap is set to recommended size for specific
 window function currently used.
+
+@item rate, r
+Set output framerate.
 @end table
 
 @anchor{showspectrum}
diff --git a/libavfilter/avf_showspatial.c b/libavfilter/avf_showspatial.c
index 7807628540..3db4db9af0 100644
--- a/libavfilter/avf_showspatial.c
+++ b/libavfilter/avf_showspatial.c
@@ -62,6 +62,8 @@ static const AVOption showspatial_options[] = {
 { "win_size", "set window size", OFFSET(win_size), AV_OPT_TYPE_INT, {.i64 
= 4096}, 1024, 65536, FLAGS },
 WIN_FUNC_OPTION("win_func", OFFSET(win_func), FLAGS, WFUNC_HANNING),
 { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, 
{.dbl=0.5}, 0, 1, FLAGS },
+{ "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, 
{.str="25"}, 0, INT_MAX, FLAGS },
+{ "r","set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, 
{.str="25"}, 0, INT_MAX, FLAGS },
 { NULL }
 };
 
@@ -187,6 +189,7 @@ static int config_output(AVFilterLink *outlink)
 }
 }
 
+outlink->frame_rate = s->frame_rate;
 outlink->time_base = av_inv_q(outlink->frame_rate);
 
 av_audio_fifo_free(s->fifo);
@@ -253,6 +256,7 @@ static int draw_spatial(AVFilterLink *inlink, AVFrame 
*insamples)
 }
 
 outpicref->pts = av_rescale_q(insamples->pts, inlink->time_base, 
outlink->time_base);
+outpicref->duration = 1;
 
 return ff_filter_frame(outlink, outpicref);
 }
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 5aac9c513a..4ccbf5641c 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"
 
 #define LIBAVFILTER_VERSION_MINOR  49
-#define LIBAVFILTER_VERSION_MICRO 100
+#define LIBAVFILTER_VERSION_MICRO 101
 
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
-- 
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".


[FFmpeg-devel] [PATCH 7/8] lavfi/avf_showfreqs: set frame durations

2022-09-28 Thread Anton Khirnov
The filter is supposed to produce CFR output.
---
 libavfilter/avf_showfreqs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/avf_showfreqs.c b/libavfilter/avf_showfreqs.c
index 86a67c7328..cc7d6204b4 100644
--- a/libavfilter/avf_showfreqs.c
+++ b/libavfilter/avf_showfreqs.c
@@ -469,6 +469,7 @@ static int plot_freqs(AVFilterLink *inlink, int64_t pts)
 
 av_free(colors);
 out->pts = s->pts;
+out->duration = 1;
 out->sample_aspect_ratio = (AVRational){1,1};
 return ff_filter_frame(outlink, out);
 }
-- 
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".


[FFmpeg-devel] [PATCH 3/8] lavfi/avf_ahistogram: set frame durations

2022-09-28 Thread Anton Khirnov
The filter is supposed to produce CFR output.
---
 libavfilter/avf_ahistogram.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/avf_ahistogram.c b/libavfilter/avf_ahistogram.c
index d14e0bcfac..c45493730d 100644
--- a/libavfilter/avf_ahistogram.c
+++ b/libavfilter/avf_ahistogram.c
@@ -245,6 +245,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 memset(s->out->data[3] + n * s->out->linesize[0], 0, w);
 }
 s->out->pts = av_rescale_q(in->pts, inlink->time_base, outlink->time_base);
+s->out->duration = 1;
 
 s->first = s->frame_count;
 
-- 
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".


[FFmpeg-devel] [PATCH 5/8] lavfi/avf_avectorscope: set frame durations

2022-09-28 Thread Anton Khirnov
The filter is supposed to produce CFR output.
---
 libavfilter/avf_avectorscope.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/avf_avectorscope.c b/libavfilter/avf_avectorscope.c
index fe381a631d..2ed85f56e5 100644
--- a/libavfilter/avf_avectorscope.c
+++ b/libavfilter/avf_avectorscope.c
@@ -275,6 +275,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*insamples)
 memset(s->outpicref->data[0] + i * s->outpicref->linesize[0], 0, 
outlink->w * 4);
 }
 s->outpicref->pts = av_rescale_q(insamples->pts, inlink->time_base, 
outlink->time_base);
+s->outpicref->duration = 1;
 
 av_frame_make_writable(s->outpicref);
 ff_filter_execute(ctx, fade, NULL, NULL, FFMIN(outlink->h, 
ff_filter_get_nb_threads(ctx)));
-- 
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".


[FFmpeg-devel] [PATCH 4/8] lavfi/avf_aphasemeter: set frame durations

2022-09-28 Thread Anton Khirnov
The filter is supposed to produce CFR output.
---
 libavfilter/avf_aphasemeter.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavfilter/avf_aphasemeter.c b/libavfilter/avf_aphasemeter.c
index 3501e62825..0f7692982c 100644
--- a/libavfilter/avf_aphasemeter.c
+++ b/libavfilter/avf_aphasemeter.c
@@ -327,6 +327,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 AVFrame *clone;
 
 s->out->pts = in->pts;
+s->out->duration = av_rescale_q(1, av_inv_q(outlink->frame_rate), 
outlink->time_base);
+
 clone = av_frame_clone(s->out);
 if (!clone)
 return AVERROR(ENOMEM);
-- 
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".


[FFmpeg-devel] [PATCH 2/8] lavfi/setpts: unset frame durations

2022-09-28 Thread Anton Khirnov
This filter cannot know frame durations.
---
 libavfilter/setpts.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
index 171fae88c0..ba653df4ae 100644
--- a/libavfilter/setpts.c
+++ b/libavfilter/setpts.c
@@ -185,6 +185,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 
 d = eval_pts(setpts, inlink, frame, frame->pts);
 frame->pts = D2TS(d);
+frame->duration = 0;
 
 av_log(inlink->dst, AV_LOG_TRACE,
 "N:%"PRId64" PTS:%s T:%f POS:%s",
-- 
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".


[FFmpeg-devel] [PATCH 6/8] lavfi/avf_showcqt: set frame durations

2022-09-28 Thread Anton Khirnov
The filter is supposed to produce CFR output.
---
 libavfilter/avf_showcqt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c
index 33c482bd42..c019dc2564 100644
--- a/libavfilter/avf_showcqt.c
+++ b/libavfilter/avf_showcqt.c
@@ -1187,6 +1187,7 @@ static int plot_cqt(AVFilterContext *ctx, AVFrame 
**frameout)
 UPDATE_TIME(s->sono_time);
 }
 out->pts = s->next_pts;
+out->duration = PTS_STEP;
 s->next_pts += PTS_STEP;
 }
 s->sono_count = (s->sono_count + 1) % s->count;
-- 
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".


[FFmpeg-devel] [PATCH 1/8] lavfi/vf_fps: set frame duration

2022-09-28 Thread Anton Khirnov
---
 libavfilter/vf_fps.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
index 0e5a1fec35..051d278f54 100644
--- a/libavfilter/vf_fps.c
+++ b/libavfilter/vf_fps.c
@@ -291,6 +291,7 @@ static int write_frame(AVFilterContext *ctx, FPSContext *s, 
AVFilterLink *outlin
 // Make sure Closed Captions will not be duplicated
 av_frame_remove_side_data(s->frames[0], AV_FRAME_DATA_A53_CC);
 frame->pts = s->next_pts++;
+frame->duration = 1;
 
 av_log(ctx, AV_LOG_DEBUG, "Writing frame with pts %"PRId64" to pts 
%"PRId64"\n",
s->frames[0]->pts, frame->pts);
-- 
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] [PATCH 2/2] aarch64: me_cmp: Avoid using the non-unrolled codepath for the minimum unroll size

2022-09-28 Thread Hubert Mazur
LGTM.

On Wed, Sep 28, 2022 at 11:13 AM Martin Storsjö  wrote:

> Signed-off-by: Martin Storsjö 
> ---
>  libavcodec/aarch64/me_cmp_neon.S | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/aarch64/me_cmp_neon.S
> b/libavcodec/aarch64/me_cmp_neon.S
> index 832a7cb22d..c710358ab7 100644
> --- a/libavcodec/aarch64/me_cmp_neon.S
> +++ b/libavcodec/aarch64/me_cmp_neon.S
> @@ -471,7 +471,7 @@ function sse8_neon, export=1
>  moviv21.4s, #0
>  moviv20.4s, #0
>  cmp w4, #4
> -b.le2f
> +b.lt2f
>
>  // make 4 iterations at once
>  1:
> @@ -534,7 +534,7 @@ function sse4_neon, export=1
>
>  moviv16.4s, #0  // clear the
> result accumulator
>  cmp w4, #4
> -b.le2f
> +b.lt2f
>
>  // make 4 iterations at once
>  1:
> @@ -663,7 +663,7 @@ function vsse16_neon, export=1
>  cmp w4, #3  // check if we
> can make 3 iterations at once
>  usubl   v31.8h, v0.8b, v1.8b// Signed
> difference of pix1[0] - pix2[0], first iteration
>  usubl2  v30.8h, v0.16b, v1.16b  // Signed
> difference of pix1[0] - pix2[0], first iteration
> -b.le2f
> +b.lt2f
>
>
>  1:
> --
> 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".


  1   2   >