Re: [FFmpeg-devel] [PATCH v2 1/3] avfilter/avfilter: Don't use AVFrame.channel_layout

2022-09-13 Thread Nicolas George
Andreas Rheinhardt (12022-09-12):
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/avfilter.c | 12 ++--
>  1 file changed, 10 insertions(+), 2 deletions(-)

Series should be ok.

Regards,

-- 
  Nicolas George
___
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/x86/audiodsp: add scalarproduct avx2

2022-09-13 Thread Paul B Mahol
On 9/12/22, Paul B Mahol  wrote:
> Patch attached.
>
> How to get more speed?
>

Thanks for review, updated patch attached.
From 2a5bab90b863c7cc9dbbb4d3d3021bec8ab09843 Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Mon, 12 Sep 2022 18:53:31 +0200
Subject: [PATCH] avcodec/x86/audiodsp: add scalarproduct avx2

Signed-off-by: Paul B Mahol 
---
 libavcodec/x86/audiodsp.asm| 16 
 libavcodec/x86/audiodsp_init.c |  6 ++
 2 files changed, 22 insertions(+)

diff --git a/libavcodec/x86/audiodsp.asm b/libavcodec/x86/audiodsp.asm
index b604b0443c..88e3fefef2 100644
--- a/libavcodec/x86/audiodsp.asm
+++ b/libavcodec/x86/audiodsp.asm
@@ -44,6 +44,22 @@ cglobal scalarproduct_int16, 3,3,3, v1, v2, order
 movd   eax, m2
 RET
 
+INIT_YMM avx2
+cglobal scalarproduct_int16, 3,3,2, v1, v2, order
+add orderd, orderd
+add v1q, orderq
+add v2q, orderq
+neg orderq
+pxorm1, m1
+.loop:
+movum0, [v1q + orderq]
+pmaddwd m0, [v2q + orderq]
+paddd   m1, m0
+add orderq, mmsize
+jl .loop
+HADDD   m1, m0
+movd   eax, xm1
+RET
 
 ;-
 ; void ff_vector_clip_int32(int32_t *dst, const int32_t *src, int32_t min,
diff --git a/libavcodec/x86/audiodsp_init.c b/libavcodec/x86/audiodsp_init.c
index aa5e43e570..77d5948442 100644
--- a/libavcodec/x86/audiodsp_init.c
+++ b/libavcodec/x86/audiodsp_init.c
@@ -24,6 +24,9 @@
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/audiodsp.h"
 
+int32_t ff_scalarproduct_int16_avx2(const int16_t *v1, const int16_t *v2,
+int order);
+
 int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
 int order);
 
@@ -53,4 +56,7 @@ av_cold void ff_audiodsp_init_x86(AudioDSPContext *c)
 
 if (EXTERNAL_SSE4(cpu_flags))
 c->vector_clip_int32 = ff_vector_clip_int32_sse4;
+
+if (EXTERNAL_AVX2(cpu_flags))
+c->scalarproduct_int16 = ff_scalarproduct_int16_avx2;
 }
-- 
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".


Re: [FFmpeg-devel] [PATCH] avcodec/x86/audiodsp: add scalarproduct avx2

2022-09-13 Thread Andreas Rheinhardt
Paul B Mahol:
>  
> +INIT_YMM avx2
> +cglobal scalarproduct_int16, 3,3,2, v1, v2, order
> +add orderd, orderd
> +add v1q, orderq
> +add v2q, orderq
> +neg orderq
> +pxorm1, m1
> +.loop:
> +movum0, [v1q + orderq]
> +pmaddwd m0, [v2q + orderq]
> +paddd   m1, m0
> +add orderq, mmsize
> +jl .loop
> +HADDD   m1, m0
> +movd   eax, xm1
> +RET
>  

avx2 asm functions are guarded by %if HAVE_AVX2_EXTERNAL (presumably not
all assemblers can handle them?).

- 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] avcodec/flac_parser: fix triggered assert

2022-09-13 Thread Paul B Mahol
On 9/8/22, Paul B Mahol  wrote:
> Patch attached.
>

Will apply soon.
___
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] RTP: get the buffer information of the RTP extension header.

2022-09-13 Thread Andreas Rheinhardt
Wujian(Chin):
> Signed-off-by: wujian_nanjing 
> ---
>  libavcodec/avpacket.c | 44 
>  libavcodec/packet.h   | 17 +
>  libavformat/demux.c   |  7 +++
>  libavformat/rtpdec.c  | 37 -
>  4 files changed, 96 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index bcbc416..45c131a 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -46,6 +46,8 @@ void av_init_packet(AVPacket *pkt)
>  pkt->opaque   = NULL;
>  pkt->opaque_ref   = NULL;
>  pkt->time_base= av_make_q(0, 1);
> +pkt->ext  = NULL;
> +pkt->extlen   = 0;
>  }
>  #endif
>  
> @@ -109,6 +111,46 @@ int av_new_packet(AVPacket *pkt, int size)
>  return 0;
>  }
>  
> +static void av_packet_free_ext(AVPacket *pkt)
> +{
> +if (!pkt)
> +return;
> +
> +if (pkt->ext) {
> +av_free(pkt->ext);
> +pkt->ext = NULL;
> +}
> +
> +pkt->extlen = 0;
> +}
> +
> +int av_set_packet_ext(AVPacket *pkt, uint8_t *buf, int len)
> +{
> +if (!buf || (len <= 0))
> +return 0;
> +
> +if (pkt->ext == buf) {
> +pkt->extlen = len;
> +return 0;
> +}
> +
> +pkt->ext = av_malloc(len);
> +pkt->extlen = len;
> +(void)memcpy(pkt->ext, buf, len);
> +
> +return 0;
> +}
> +
> +static int av_copy_packet_ext(AVPacket *pkt, const AVPacket *src)
> +{
> +pkt->ext = NULL;
> +pkt->extlen = 0;
> +
> +av_set_packet_ext(pkt, src->ext, src->extlen);
> +
> +return 0;
> +}
> +
>  void av_shrink_packet(AVPacket *pkt, int size)
>  {
>  if (pkt->size <= size)
> @@ -422,6 +464,7 @@ int av_packet_copy_props(AVPacket *dst, const AVPacket 
> *src)
>  void av_packet_unref(AVPacket *pkt)
>  {
>  av_packet_free_side_data(pkt);
> +av_packet_free_ext(pkt);
>  av_buffer_unref(&pkt->opaque_ref);
>  av_buffer_unref(&pkt->buf);
>  get_packet_defaults(pkt);
> @@ -456,6 +499,7 @@ int av_packet_ref(AVPacket *dst, const AVPacket *src)
>  }
>  
>  dst->size = src->size;
> +av_copy_packet_ext(dst, src);
>  
>  return 0;
>  fail:
> diff --git a/libavcodec/packet.h b/libavcodec/packet.h
> index 404d520..137d1fa 100644
> --- a/libavcodec/packet.h
> +++ b/libavcodec/packet.h
> @@ -374,6 +374,13 @@ typedef struct AVPacket {
>  uint8_t *data;
>  int   size;
>  int   stream_index;
> +
> +/**
> + * Extension header data and size
> + */
> +uint8_t *ext;
> +uint32_t extlen;
> +
>  /**
>   * A combination of AV_PKT_FLAG values
>   */
> @@ -523,6 +530,16 @@ void av_init_packet(AVPacket *pkt);
>  int av_new_packet(AVPacket *pkt, int size);
>  
>  /**
> + * Allocate the ext data from buf with len lenght.
> + * Make sure pkt->ext is null, otherwise cause memory leak.
> + *
> + * @param pkt packet
> + * @param buf buffer with ext data
> + * @param len buffer size
> + */
> +int av_set_packet_ext(AVPacket *pkt, uint8_t *buf, int len);
> +
> +/**
>   * Reduce packet size, correctly zeroing padding
>   *
>   * @param pkt packet
> diff --git a/libavformat/demux.c b/libavformat/demux.c
> index 1620716..2a8b201 100644
> --- a/libavformat/demux.c
> +++ b/libavformat/demux.c
> @@ -1175,6 +1175,13 @@ static int parse_packet(AVFormatContext *s, AVPacket 
> *pkt,
>  pkt->side_data_elems= 0;
>  }
>  
> +if (pkt->extlen > 0) {
> +out_pkt->extlen = pkt->extlen;
> +out_pkt->ext = pkt->ext;
> +pkt->extlen = 0;
> +pkt->ext = NULL;
> +}
> +
>  /* set the duration */
>  out_pkt->duration = (sti->parser->flags & 
> PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0;
>  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
> diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
> index fa7544c..2a539e0 100644
> --- a/libavformat/rtpdec.c
> +++ b/libavformat/rtpdec.c
> @@ -699,13 +699,14 @@ static int rtp_parse_packet_internal(RTPDemuxContext 
> *s, AVPacket *pkt,
>  {
>  unsigned int ssrc;
>  int payload_type, seq, flags = 0;
> -int ext, csrc;
> +int has_ext, csrc, extlen;
> +uint8_t *extbuf;
>  AVStream *st;
>  uint32_t timestamp;
>  int rv = 0;
>  
>  csrc = buf[0] & 0x0f;
> -ext  = buf[0] & 0x10;
> +has_ext  = buf[0] & 0x10;
>  payload_type = buf[1] & 0x7f;
>  if (buf[1] & 0x80)
>  flags |= RTP_FLAG_MARKER;
> @@ -744,18 +745,25 @@ static int rtp_parse_packet_internal(RTPDemuxContext 
> *s, AVPacket *pkt,
>  return AVERROR_INVALIDDATA;
>  
>  /* RFC 3550 Section 5.3.1 RTP Header Extension handling */
> -if (ext) {
> +if (has_ext) {
>  if (len < 4)
>  return -1;
>  /* calculate the header extension length (stored as number
>   * of 32-bit words) */
> -ext = (AV_RB16(buf + 2) + 1) << 2

Re: [FFmpeg-devel] [PATCH] avcodec/x86/audiodsp: add scalarproduct avx2

2022-09-13 Thread Paul B Mahol
On 9/13/22, Paul B Mahol  wrote:
> On 9/12/22, Paul B Mahol  wrote:
>> Patch attached.
>>
>> How to get more speed?
>>
>
> Thanks for review, updated patch attached.
>

Fixed patch from Andreas review attached.
From aa3cbb9d792d18c1756d00138925382eab924804 Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Mon, 12 Sep 2022 18:53:31 +0200
Subject: [PATCH] avcodec/x86/audiodsp: add scalarproduct avx2

Signed-off-by: Paul B Mahol 
---
 libavcodec/x86/audiodsp.asm| 18 ++
 libavcodec/x86/audiodsp_init.c |  6 ++
 2 files changed, 24 insertions(+)

diff --git a/libavcodec/x86/audiodsp.asm b/libavcodec/x86/audiodsp.asm
index b604b0443c..f64077cb13 100644
--- a/libavcodec/x86/audiodsp.asm
+++ b/libavcodec/x86/audiodsp.asm
@@ -44,6 +44,24 @@ cglobal scalarproduct_int16, 3,3,3, v1, v2, order
 movd   eax, m2
 RET
 
+%if HAVE_AVX2_EXTERNAL
+INIT_YMM avx2
+cglobal scalarproduct_int16, 3,3,2, v1, v2, order
+add orderd, orderd
+add v1q, orderq
+add v2q, orderq
+neg orderq
+pxorm1, m1
+.loop:
+movum0, [v1q + orderq]
+pmaddwd m0, [v2q + orderq]
+paddd   m1, m0
+add orderq, mmsize
+jl .loop
+HADDD   m1, m0
+movd   eax, xm1
+RET
+%endif
 
 ;-
 ; void ff_vector_clip_int32(int32_t *dst, const int32_t *src, int32_t min,
diff --git a/libavcodec/x86/audiodsp_init.c b/libavcodec/x86/audiodsp_init.c
index aa5e43e570..68aa3b2129 100644
--- a/libavcodec/x86/audiodsp_init.c
+++ b/libavcodec/x86/audiodsp_init.c
@@ -24,6 +24,9 @@
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/audiodsp.h"
 
+int32_t ff_scalarproduct_int16_avx2(const int16_t *v1, const int16_t *v2,
+int order);
+
 int32_t ff_scalarproduct_int16_sse2(const int16_t *v1, const int16_t *v2,
 int order);
 
@@ -53,4 +56,7 @@ av_cold void ff_audiodsp_init_x86(AudioDSPContext *c)
 
 if (EXTERNAL_SSE4(cpu_flags))
 c->vector_clip_int32 = ff_vector_clip_int32_sse4;
+
+if (EXTERNAL_AVX2_FAST(cpu_flags))
+c->scalarproduct_int16 = ff_scalarproduct_int16_avx2;
 }
-- 
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 01/13] avcodec/dolby_e_parser: Remove unnecessary headers

2022-09-13 Thread Andreas Rheinhardt
Possible since 81d070dd09ce154d635414fd07d80a591266b421.

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

diff --git a/libavcodec/dolby_e_parser.c b/libavcodec/dolby_e_parser.c
index 9f54627356..d2566e5446 100644
--- a/libavcodec/dolby_e_parser.c
+++ b/libavcodec/dolby_e_parser.c
@@ -21,8 +21,6 @@
 #include "libavutil/channel_layout.h"
 #include "avcodec.h"
 #include "dolby_e.h"
-#include "get_bits.h"
-#include "put_bits.h"
 
 typedef struct DBEParseContext {
 DBEContext dectx;
-- 
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 02/13] avcodec/dcahuff: Remove unused define

2022-09-13 Thread Andreas Rheinhardt
In reality, the bit allocation VLCs do not use the same number
of bits at all.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dcahuff.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index 8d5541f9d0..d1b64798ab 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -44,7 +44,6 @@ static const uint8_t tmode_bits[TMODE_COUNT][4] = {
 { 2, 2, 2, 2 }
 };
 
-#define BITALLOC_12_VLC_BITS 9
 static const uint8_t bitalloc_12_vlc_bits[DCA_BITALLOC_12_COUNT] = {
 9, 7, 7, 9, 9
 };
-- 
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 03/13] avcodec/dcahuff: Avoid redundant offset table

2022-09-13 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dcahuff.c | 30 ++
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index d1b64798ab..9b809cc415 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -1232,17 +1232,6 @@ static const uint8_t rsd_bitvals[18] = {
  6,  4,
 };
 
-static const uint16_t vlc_offs[80] = {
-0,   512,   640,   768,  1282,  1794,  2436,  3080,  3770,  4454,  
5364,
- 5372,  5380,  5388,  5392,  5396,  5412,  5420,  5428,  5460,  5492,  
5508,
- 5572,  5604,  5668,  5796,  5860,  5892,  6412,  6668,  6796,  7308,  
7564,
- 7820,  8076,  8620,  9132,  9388,  9910, 10166, 10680, 11196, 11726, 
12240,
-12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 
18264,
-18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622, 24200, 24748, 
25276,
-25792, 26306, 26826, 26890, 26954, 27468, 27500, 28038, 28554, 29086, 
29630,
-30150, 30214
-};
-
 DCAVLC  ff_dca_vlc_bit_allocation;
 DCAVLC  ff_dca_vlc_transition_mode;
 DCAVLC  ff_dca_vlc_scale_factor;
@@ -1264,14 +1253,15 @@ VLC ff_dca_vlc_rsd;
 av_cold void ff_dca_init_vlcs(void)
 {
 static VLCElem dca_table[30214];
-int i, j, k = 0;
+unsigned offset = 0;
+int i, j;
 
 #define DCA_INIT_VLC(vlc, a, b, c, d)   \
 do {\
-vlc.table   = &dca_table[vlc_offs[k]];  \
-vlc.table_allocated = vlc_offs[k + 1] - vlc_offs[k];\
-init_vlc(&vlc, a, b, c, 1, 1, d, 2, 2, INIT_VLC_USE_NEW_STATIC);\
-k++;\
+vlc.table   = &dca_table[offset];   \
+vlc.table_allocated = FF_ARRAY_ELEMS(dca_table) - offset;   \
+init_vlc(&vlc, a, b, c, 1, 1, d, 2, 2, INIT_VLC_STATIC_OVERLONG);   \
+offset += vlc.table_size;   \
 } while (0)
 
 ff_dca_vlc_bit_allocation.offset= 1;
@@ -1302,14 +1292,14 @@ av_cold void ff_dca_init_vlcs(void)
 
 #define LBR_INIT_VLC(vlc, tab, nb_bits) \
 do {\
-vlc.table   = &dca_table[vlc_offs[k]];  \
-vlc.table_allocated = vlc_offs[k + 1] - vlc_offs[k];\
+vlc.table   = &dca_table[offset];   \
+vlc.table_allocated = FF_ARRAY_ELEMS(dca_table) - offset;   \
 ff_init_vlc_sparse(&vlc, nb_bits, FF_ARRAY_ELEMS(tab##_codes),  \
&tab##_bitvals[0], 2, 1, \
tab##_codes, 2, 2,   \
&tab##_bitvals[1], 2, 1, \
-   INIT_VLC_LE | INIT_VLC_USE_NEW_STATIC);  \
-k++;\
+   INIT_VLC_LE | INIT_VLC_STATIC_OVERLONG); \
+offset += vlc.table_size;   \
 } while (0)
 
 LBR_INIT_VLC(ff_dca_vlc_tnl_grp[0],  tnl_grp_0,   9);
-- 
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 04/13] avcodec/dca_core, dcahuff: Don't use DCAVLC unnecessarily

2022-09-13 Thread Andreas Rheinhardt
The ff_dca_vlc_transition_mode VLCs don't use an offset at all,
so just use ordinary VLCs for them.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dca_core.c | 3 ++-
 libavcodec/dcahuff.c  | 8 +++-
 libavcodec/dcahuff.h  | 2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index bbf36ea678..499afc8204 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -456,7 +456,8 @@ static int parse_subframe_header(DCACoreDecoder *s, int sf,
 int sel = s->transition_mode_sel[ch];
 for (band = 0; band < s->subband_vq_start[ch]; band++)
 if (s->bit_allocation[ch][band])
-s->transition_mode[sf][ch][band] = dca_get_vlc(&s->gb, 
&ff_dca_vlc_transition_mode, sel);
+s->transition_mode[sf][ch][band] = get_vlc2(&s->gb, 
ff_dca_vlc_transition_mode[sel].table,
+
ff_dca_vlc_transition_mode[sel].bits,1);
 }
 }
 
diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index 9b809cc415..49fb06eeb4 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -1233,7 +1233,7 @@ static const uint8_t rsd_bitvals[18] = {
 };
 
 DCAVLC  ff_dca_vlc_bit_allocation;
-DCAVLC  ff_dca_vlc_transition_mode;
+VLC ff_dca_vlc_transition_mode[4];
 DCAVLC  ff_dca_vlc_scale_factor;
 DCAVLC  ff_dca_vlc_quant_index[DCA_CODE_BOOKS];
 
@@ -1276,10 +1276,8 @@ av_cold void ff_dca_init_vlcs(void)
 DCA_INIT_VLC(ff_dca_vlc_scale_factor.vlc[i], SCALES_VLC_BITS, 129,
  scales_bits[i], scales_codes[i]);
 
-ff_dca_vlc_transition_mode.offset= 0;
-ff_dca_vlc_transition_mode.max_depth = 1;
-for (i = 0; i < 4; i++)
-DCA_INIT_VLC(ff_dca_vlc_transition_mode.vlc[i], tmode_vlc_bits[i], 4,
+for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_transition_mode); i++)
+DCA_INIT_VLC(ff_dca_vlc_transition_mode[i], tmode_vlc_bits[i], 4,
  tmode_bits[i], tmode_codes[i]);
 
 for (i = 0; i < DCA_CODE_BOOKS; i++) {
diff --git a/libavcodec/dcahuff.h b/libavcodec/dcahuff.h
index c0e04b725a..87e1fd1cea 100644
--- a/libavcodec/dcahuff.h
+++ b/libavcodec/dcahuff.h
@@ -40,7 +40,7 @@ typedef struct DCAVLC {
 } DCAVLC;
 
 extern DCAVLC   ff_dca_vlc_bit_allocation;
-extern DCAVLC   ff_dca_vlc_transition_mode;
+extern VLC  ff_dca_vlc_transition_mode[4];
 extern DCAVLC   ff_dca_vlc_scale_factor;
 extern DCAVLC   ff_dca_vlc_quant_index[DCA_CODE_BOOKS];
 
-- 
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 05/13] avcodec/dcahuff: Always use three bits for transition mode VLCs

2022-09-13 Thread Andreas Rheinhardt
It increases the size of one VLC from two to three bits, thereby
requiring four more VLCEntries (16 bytes .bss), but it allows to
inline the number of bits used when reading them.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dca_core.c | 2 +-
 libavcodec/dcahuff.c  | 5 ++---
 libavcodec/dcahuff.h  | 1 +
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 499afc8204..069d428fff 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -457,7 +457,7 @@ static int parse_subframe_header(DCACoreDecoder *s, int sf,
 for (band = 0; band < s->subband_vq_start[ch]; band++)
 if (s->bit_allocation[ch][band])
 s->transition_mode[sf][ch][band] = get_vlc2(&s->gb, 
ff_dca_vlc_transition_mode[sel].table,
-
ff_dca_vlc_transition_mode[sel].bits,1);
+
DCA_TMODE_VLC_BITS, 1);
 }
 }
 
diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index 49fb06eeb4..842b1401dd 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -29,7 +29,6 @@
 #include "put_bits.h"
 
 #define TMODE_COUNT 4
-static const uint8_t tmode_vlc_bits[TMODE_COUNT] = { 3, 3, 3, 2 };
 static const uint16_t tmode_codes[TMODE_COUNT][4] = {
 { 0x, 0x0002, 0x0006, 0x0007 },
 { 0x0002, 0x0006, 0x0007, 0x },
@@ -1252,7 +1251,7 @@ VLC ff_dca_vlc_rsd;
 
 av_cold void ff_dca_init_vlcs(void)
 {
-static VLCElem dca_table[30214];
+static VLCElem dca_table[30218];
 unsigned offset = 0;
 int i, j;
 
@@ -1277,7 +1276,7 @@ av_cold void ff_dca_init_vlcs(void)
  scales_bits[i], scales_codes[i]);
 
 for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_transition_mode); i++)
-DCA_INIT_VLC(ff_dca_vlc_transition_mode[i], tmode_vlc_bits[i], 4,
+DCA_INIT_VLC(ff_dca_vlc_transition_mode[i], DCA_TMODE_VLC_BITS, 4,
  tmode_bits[i], tmode_codes[i]);
 
 for (i = 0; i < DCA_CODE_BOOKS; i++) {
diff --git a/libavcodec/dcahuff.h b/libavcodec/dcahuff.h
index 87e1fd1cea..1f13b6f443 100644
--- a/libavcodec/dcahuff.h
+++ b/libavcodec/dcahuff.h
@@ -40,6 +40,7 @@ typedef struct DCAVLC {
 } DCAVLC;
 
 extern DCAVLC   ff_dca_vlc_bit_allocation;
+#define DCA_TMODE_VLC_BITS 3
 extern VLC  ff_dca_vlc_transition_mode[4];
 extern DCAVLC   ff_dca_vlc_scale_factor;
 extern DCAVLC   ff_dca_vlc_quant_index[DCA_CODE_BOOKS];
-- 
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 08/13] avcodec/dcahuff, dca_core, dca_lbr: Apply offset during VLC creation

2022-09-13 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dca_core.c |  2 +-
 libavcodec/dca_lbr.c  |  4 ++--
 libavcodec/dcahuff.c  | 45 ---
 libavcodec/dcahuff.h  |  1 -
 4 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 069d428fff..96787fe95d 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -69,7 +69,7 @@ static const uint8_t block_code_nbits[7] = {
 
 static int dca_get_vlc(GetBitContext *s, DCAVLC *v, int i)
 {
-return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, v->max_depth) + 
v->offset;
+return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, v->max_depth);
 }
 
 static void get_array(GetBitContext *s, int32_t *array, int size, int n)
diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index 5343bcde8a..579bd9c469 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -263,8 +263,8 @@ static int parse_lfe_chunk(DCALbrDecoder *s, LBRChunk 
*chunk)
 static inline int parse_vlc(GetBitContext *s, VLC *vlc, int max_depth)
 {
 int v = get_vlc2(s, vlc->table, vlc->bits, max_depth);
-if (v > 0)
-return v - 1;
+if (v >= 0)
+return v;
 // Rare value
 return get_bits(s, get_bits(s, 3) + 1);
 }
diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index ee4d4bcd6d..7a5b054dd5 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -793,44 +793,41 @@ av_cold void ff_dca_init_vlcs(void)
 unsigned offset = 0;
 int i;
 
-#define DCA_INIT_VLC(vlc, nb_bits, nb_codes)\
+#define DCA_INIT_VLC(vlc, nb_bits, nb_codes, entry_offset)  \
 do {\
 vlc.table   = &dca_table[offset];   \
 vlc.table_allocated = FF_ARRAY_ELEMS(dca_table) - offset;   \
 ff_init_vlc_from_lengths(&vlc, nb_bits, nb_codes, &src_table[0][1], 2, 
\
- &src_table[0][0], 2, 1,\
- 0, INIT_VLC_STATIC_OVERLONG, NULL);\
+ &src_table[0][0], 2, 1, entry_offset,  \
+ INIT_VLC_STATIC_OVERLONG, NULL);   \
 offset += vlc.table_size;   \
 src_table += nb_codes;  \
 } while (0)
 
 for (unsigned i = 0; i < DCA_CODE_BOOKS; i++) {
-ff_dca_vlc_quant_index[i].offset= ff_dca_bitalloc_offsets[i];
 ff_dca_vlc_quant_index[i].max_depth = 1 + (i > 4);
 for (unsigned j = 0; j < ff_dca_quant_index_group_size[i]; j++)
 DCA_INIT_VLC(ff_dca_vlc_quant_index[i].vlc[j], 
bitalloc_maxbits[i][j],
- ff_dca_bitalloc_sizes[i]);
+ ff_dca_bitalloc_sizes[i], ff_dca_bitalloc_offsets[i]);
 }
 
-ff_dca_vlc_bit_allocation.offset= 1;
 ff_dca_vlc_bit_allocation.max_depth = 2;
 for (i = 0; i < 5; i++)
-DCA_INIT_VLC(ff_dca_vlc_bit_allocation.vlc[i], 
bitalloc_12_vlc_bits[i], 12);
+DCA_INIT_VLC(ff_dca_vlc_bit_allocation.vlc[i], 
bitalloc_12_vlc_bits[i], 12, 1);
 
-ff_dca_vlc_scale_factor.offset= -64;
 ff_dca_vlc_scale_factor.max_depth = 2;
 for (i = 0; i < 5; i++)
-DCA_INIT_VLC(ff_dca_vlc_scale_factor.vlc[i], SCALES_VLC_BITS, 129);
+DCA_INIT_VLC(ff_dca_vlc_scale_factor.vlc[i], SCALES_VLC_BITS, 129, 
-64);
 
 for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_transition_mode); i++)
-DCA_INIT_VLC(ff_dca_vlc_transition_mode[i], DCA_TMODE_VLC_BITS, 4);
+DCA_INIT_VLC(ff_dca_vlc_transition_mode[i], DCA_TMODE_VLC_BITS, 4, 0);
 
-#define LBR_INIT_VLC(vlc, nb_bits, nb_codes)\
+#define LBR_INIT_VLC(vlc, nb_bits, nb_codes, entry_offset)  \
 do {\
 vlc.table   = &dca_table[offset];   \
 vlc.table_allocated = FF_ARRAY_ELEMS(dca_table) - offset;   \
 ff_init_vlc_from_lengths(&vlc, nb_bits, nb_codes, &src_table[0][1], 2, 
\
- &src_table[0][0], 2, 1, 0, \
+ &src_table[0][0], 2, 1, entry_offset,  \
  INIT_VLC_STATIC_OVERLONG | INIT_VLC_LE,\
  NULL); \
 offset += vlc.table_size;   \
@@ -838,16 +835,16 @@ av_cold void ff_dca_init_vlcs(void)
 } while (0)
 
 for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_tnl_grp); i++)
-LBR_INIT_VLC(ff_dca_vlc_tnl_grp[i], 9, tnl_grp_sizes[i]);
-LBR_INIT_VLC(ff_dca_vlc_tnl_scf, 9,  20);
-LBR_INIT_VLC(ff_dca_vlc_damp,6,   7);
-LBR_INIT_VLC(ff_dca_vlc_dph, 6, 

[FFmpeg-devel] [PATCH 07/13] avcodec/dcahuff: Combine tables, use ff_init_vlc_from_lengths()

2022-09-13 Thread Andreas Rheinhardt
Up until now, initializing the dca VLC tables uses ff_init_vlc_sparse()
with length tables of type uint8_t and code tables of type uint16_t
(except for the LBR tables, which uses length and symbols of type
uint8_t; these tables are interleaved). In case of the quant index
codebooks these arrays were accessed via tables of pointers to the
individual tables.

This commit changes this: First, we switch to ff_init_vlc_from_lengths()
to replace the uint16_t code tables by uint8_t symbol tables
(this necessitates ordering the tables from left-to-right in the tree
first). These symbol tables are interleaved with the length tables.

Furthermore, these tables are combined in order to remove the table of
pointers to individual tables, thereby avoiding relocations (for x64
elf systems this amounts to 96*24B = 2304B saved in .rela.dyn) and
saving 1280B from .data.rel.ro (for 64bit systems). Meanwhile the
savings in .rodata amount to 2709 + 2 * 334 = 3377B. Due to padding
the actual savings are higher: The ELF x64 ABI requires objects >= 16B
to be padded to 16B and lots of the tables have 2^n + 1 elements
of these were from replacing uint16_t codes with uint8_t symbols;
the rest was due to the fact that combining the tables eliminated
padding (the ELF x64 ABI requires objects >= 16B to be padded to 16B
and lots of the tables have 2^n + 1 elements)). Taking this into
account gives savings of 4548B. (GCC by default uses an even higher
alignment (controlled by -malign-data); for it the savings are 5748B.)

These changes also necessitated to modify the init code for
the encoder tables.

Signed-off-by: Andreas Rheinhardt 
---
A part of me wants to move the whole LBR tables (including its init
code) to dca_lbr.c.

 libavcodec/dcaenc.c  |   22 +-
 libavcodec/dcahuff.c | 1963 --
 libavcodec/dcahuff.h |6 +-
 3 files changed, 766 insertions(+), 1225 deletions(-)

diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index 4a02aa9d46..d0de6d3eee 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -166,30 +166,38 @@ static uint16_t bitalloc_table[DCA_NUM_BITALLOC_CODES][2];
 static const uint16_t (*bitalloc_tables[DCA_CODE_BOOKS][8])[2];
 
 static av_cold void create_enc_table(uint16_t dst[][2], unsigned count,
- const uint8_t len[], const uint16_t 
codes[])
+ const uint8_t (**src_tablep)[2])
 {
+const uint8_t (*src_table)[2] = *src_tablep;
+uint16_t code = 0;
+
 for (unsigned i = 0; i < count; i++) {
-dst[i][0] = codes[i];
-dst[i][1] = len[i];
+unsigned dst_idx = src_table[i][0];
+
+dst[dst_idx][0] = code >> (16 - src_table[i][1]);
+dst[dst_idx][1] = src_table[i][1];
+
+code += 1 << (16 - src_table[i][1]);
 }
+*src_tablep += count;
 }
 
 static av_cold void dcaenc_init_static_tables(void)
 {
 uint16_t (*bitalloc_dst)[2] = bitalloc_table;
+const uint8_t (*src_table)[2] = ff_dca_vlc_src_tables;
 
 for (unsigned i = 0; i < DCA_CODE_BOOKS; i++) {
-for (unsigned j = 0; ff_dca_bitalloc_codes[i][j]; j++) {
+for (unsigned j = 0; j < ff_dca_quant_index_group_size[i]; j++) {
 create_enc_table(bitalloc_dst, ff_dca_bitalloc_sizes[i],
- ff_dca_bitalloc_bits[i][j], 
ff_dca_bitalloc_codes[i][j]);
+ &src_table);
 bitalloc_tables[i][j] = bitalloc_dst - ff_dca_bitalloc_offsets[i];
 bitalloc_dst += ff_dca_bitalloc_sizes[i];
 }
 }
 
 for (unsigned i = 0; i < DCA_BITALLOC_12_COUNT; i++)
-create_enc_table(&bitalloc_12_table[i][1], 12,
- ff_dca_bitalloc_12_bits[i], 
ff_dca_bitalloc_12_codes[i]);
+create_enc_table(&bitalloc_12_table[i][1], 12, &src_table);
 }
 
 static int encode_init(AVCodecContext *avctx)
diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index d17b49a089..ee4d4bcd6d 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -24,959 +24,15 @@
 
 #include "libavutil/macros.h"
 
+#include "dcadata.h"
 #include "dcahuff.h"
 
-#define TMODE_COUNT 4
-static const uint16_t tmode_codes[TMODE_COUNT][4] = {
-{ 0x, 0x0002, 0x0006, 0x0007 },
-{ 0x0002, 0x0006, 0x0007, 0x },
-{ 0x0006, 0x0007, 0x, 0x0002 },
-{ 0x, 0x0001, 0x0002, 0x0003 }
-};
-
-static const uint8_t tmode_bits[TMODE_COUNT][4] = {
-{ 1, 2, 3, 3 },
-{ 2, 3, 3, 1 },
-{ 3, 3, 1, 2 },
-{ 2, 2, 2, 2 }
-};
-
 static const uint8_t bitalloc_12_vlc_bits[DCA_BITALLOC_12_COUNT] = {
 9, 7, 7, 9, 9
 };
 
-const uint16_t ff_dca_bitalloc_12_codes[DCA_BITALLOC_12_COUNT][12] = {
-{ 0x, 0x0002, 0x0006, 0x000E, 0x001E, 0x003E, 0x00FF, 0x00FE,
-  0x01FB, 0x01FA, 0x01F9, 0x01F8, },
-{ 0x0001, 0x, 0x0002, 0x000F, 0x000C, 0x001D, 0x0039, 0x0038,
-  0x0037, 0x0036, 0x0035, 0x0034, },
-{ 0x, 0x0007, 0x0005, 0x0004, 0x0002, 0x000D, 0x000C, 0x0006,
-

[FFmpeg-devel] [PATCH 09/13] avcodec/dca_core: Inline number of bits of scale factor VLCs

2022-09-13 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dca_core.c | 6 --
 libavcodec/dcahuff.c  | 7 +++
 libavcodec/dcahuff.h  | 3 ++-
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 96787fe95d..7dff6633df 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -362,7 +362,8 @@ static inline int parse_scale(DCACoreDecoder *s, int 
*scale_index, int sel)
 
 // If Huffman code was used, the difference of scales was encoded
 if (sel < 5)
-*scale_index += dca_get_vlc(&s->gb, &ff_dca_vlc_scale_factor, sel);
+*scale_index += get_vlc2(&s->gb, ff_dca_vlc_scale_factor[sel].table,
+ DCA_SCALES_VLC_BITS, 2);
 else
 *scale_index = get_bits(&s->gb, sel + 1);
 
@@ -381,7 +382,8 @@ static inline int parse_joint_scale(DCACoreDecoder *s, int 
sel)
 
 // Absolute value was encoded even when Huffman code was used
 if (sel < 5)
-scale_index = dca_get_vlc(&s->gb, &ff_dca_vlc_scale_factor, sel);
+scale_index = get_vlc2(&s->gb, ff_dca_vlc_scale_factor[sel].table,
+   DCA_SCALES_VLC_BITS, 2);
 else
 scale_index = get_bits(&s->gb, sel + 1);
 
diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index 7a5b054dd5..a7518aded8 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -770,7 +770,7 @@ const uint8_t ff_dca_vlc_src_tables[][2] = {
 
 DCAVLC  ff_dca_vlc_bit_allocation;
 VLC ff_dca_vlc_transition_mode[4];
-DCAVLC  ff_dca_vlc_scale_factor;
+VLC ff_dca_vlc_scale_factor[5];
 DCAVLC  ff_dca_vlc_quant_index[DCA_CODE_BOOKS];
 
 VLC ff_dca_vlc_tnl_grp[5];
@@ -815,9 +815,8 @@ av_cold void ff_dca_init_vlcs(void)
 for (i = 0; i < 5; i++)
 DCA_INIT_VLC(ff_dca_vlc_bit_allocation.vlc[i], 
bitalloc_12_vlc_bits[i], 12, 1);
 
-ff_dca_vlc_scale_factor.max_depth = 2;
-for (i = 0; i < 5; i++)
-DCA_INIT_VLC(ff_dca_vlc_scale_factor.vlc[i], SCALES_VLC_BITS, 129, 
-64);
+for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_scale_factor); i++)
+DCA_INIT_VLC(ff_dca_vlc_scale_factor[i], DCA_SCALES_VLC_BITS, 129, 
-64);
 
 for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_transition_mode); i++)
 DCA_INIT_VLC(ff_dca_vlc_transition_mode[i], DCA_TMODE_VLC_BITS, 4, 0);
diff --git a/libavcodec/dcahuff.h b/libavcodec/dcahuff.h
index a50d49d6dd..8663f8ba12 100644
--- a/libavcodec/dcahuff.h
+++ b/libavcodec/dcahuff.h
@@ -43,7 +43,8 @@ typedef struct DCAVLC {
 extern DCAVLC   ff_dca_vlc_bit_allocation;
 #define DCA_TMODE_VLC_BITS 3
 extern VLC  ff_dca_vlc_transition_mode[4];
-extern DCAVLC   ff_dca_vlc_scale_factor;
+#define DCA_SCALES_VLC_BITS 9
+extern VLC  ff_dca_vlc_scale_factor[5];
 extern DCAVLC   ff_dca_vlc_quant_index[DCA_CODE_BOOKS];
 
 extern VLC  ff_dca_vlc_tnl_grp[5];
-- 
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 10/13] avcodec/dca_core: Don't use too big max_depth in get_vlc2()

2022-09-13 Thread Andreas Rheinhardt
Most of the VLCs used here have a max_depth of two;
some have a max_depth of one. Therefore one can just use two
and avoid the runtime check for whether one should
perform another round of LUT lookup in case the first read
did not read a complete codeword.

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

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 7dff6633df..7b23a40df4 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -69,7 +69,7 @@ static const uint8_t block_code_nbits[7] = {
 
 static int dca_get_vlc(GetBitContext *s, DCAVLC *v, int i)
 {
-return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, v->max_depth);
+return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, 2);
 }
 
 static void get_array(GetBitContext *s, int32_t *array, int size, int n)
-- 
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 11/13] avcodec/dcahuff: Replace DCAVLC by ordinary VLCs

2022-09-13 Thread Andreas Rheinhardt
This is possible now that the offsets are already applied
when creating the VLC.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dca_core.c | 10 +-
 libavcodec/dcahuff.c  | 13 +
 libavcodec/dcahuff.h  |  9 ++---
 3 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 7b23a40df4..c204e41cb7 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -67,9 +67,9 @@ static const uint8_t block_code_nbits[7] = {
 7, 10, 12, 13, 15, 17, 19
 };
 
-static int dca_get_vlc(GetBitContext *s, DCAVLC *v, int i)
+static int dca_get_vlc(GetBitContext *s, const VLC *vlc)
 {
-return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, 2);
+return get_vlc2(s, vlc->table, vlc->bits, 2);
 }
 
 static void get_array(GetBitContext *s, int32_t *array, int size, int n)
@@ -435,7 +435,7 @@ static int parse_subframe_header(DCACoreDecoder *s, int sf,
 int abits;
 
 if (sel < 5)
-abits = dca_get_vlc(&s->gb, &ff_dca_vlc_bit_allocation, sel);
+abits = dca_get_vlc(&s->gb, &ff_dca_vlc_bit_allocation[sel]);
 else
 abits = get_bits(&s->gb, sel - 1);
 
@@ -570,7 +570,7 @@ static inline int parse_huffman_codes(DCACoreDecoder *s, 
int32_t *audio, int abi
 
 // Extract Huffman codes from the bit stream
 for (i = 0; i < DCA_SUBBAND_SAMPLES; i++)
-audio[i] = dca_get_vlc(&s->gb, &ff_dca_vlc_quant_index[abits - 1], 
sel);
+audio[i] = dca_get_vlc(&s->gb, &ff_dca_vlc_quant_index[abits - 
1][sel]);
 
 return 1;
 }
@@ -1340,7 +1340,7 @@ static int parse_x96_subframe_header(DCACoreDecoder *s, 
int xch_base)
 for (band = s->x96_subband_start; band < s->nsubbands[ch]; band++) {
 // If Huffman code was used, the difference of abits was encoded
 if (sel < 7)
-abits += dca_get_vlc(&s->gb, &ff_dca_vlc_quant_index[5 + 2 * 
s->x96_high_res], sel);
+abits += dca_get_vlc(&s->gb, &ff_dca_vlc_quant_index[5 + 2 * 
s->x96_high_res][sel]);
 else
 abits = get_bits(&s->gb, 3 + s->x96_high_res);
 
diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index a7518aded8..937a87ee05 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -768,10 +768,10 @@ const uint8_t ff_dca_vlc_src_tables[][2] = {
 {   4,   3 }, {   0,   3 }, {   2,   2 }, {   3,   2 },
 };
 
-DCAVLC  ff_dca_vlc_bit_allocation;
+VLC ff_dca_vlc_bit_allocation[5];
 VLC ff_dca_vlc_transition_mode[4];
 VLC ff_dca_vlc_scale_factor[5];
-DCAVLC  ff_dca_vlc_quant_index[DCA_CODE_BOOKS];
+VLC ff_dca_vlc_quant_index[DCA_CODE_BOOKS][7];
 
 VLC ff_dca_vlc_tnl_grp[5];
 VLC ff_dca_vlc_tnl_scf;
@@ -791,7 +791,6 @@ av_cold void ff_dca_init_vlcs(void)
 static VLCElem dca_table[30218];
 const uint8_t (*src_table)[2] = ff_dca_vlc_src_tables;
 unsigned offset = 0;
-int i;
 
 #define DCA_INIT_VLC(vlc, nb_bits, nb_codes, entry_offset)  \
 do {\
@@ -805,15 +804,13 @@ av_cold void ff_dca_init_vlcs(void)
 } while (0)
 
 for (unsigned i = 0; i < DCA_CODE_BOOKS; i++) {
-ff_dca_vlc_quant_index[i].max_depth = 1 + (i > 4);
 for (unsigned j = 0; j < ff_dca_quant_index_group_size[i]; j++)
-DCA_INIT_VLC(ff_dca_vlc_quant_index[i].vlc[j], 
bitalloc_maxbits[i][j],
+DCA_INIT_VLC(ff_dca_vlc_quant_index[i][j], bitalloc_maxbits[i][j],
  ff_dca_bitalloc_sizes[i], ff_dca_bitalloc_offsets[i]);
 }
 
-ff_dca_vlc_bit_allocation.max_depth = 2;
-for (i = 0; i < 5; i++)
-DCA_INIT_VLC(ff_dca_vlc_bit_allocation.vlc[i], 
bitalloc_12_vlc_bits[i], 12, 1);
+for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_bit_allocation); i++)
+DCA_INIT_VLC(ff_dca_vlc_bit_allocation[i], bitalloc_12_vlc_bits[i], 
12, 1);
 
 for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_scale_factor); i++)
 DCA_INIT_VLC(ff_dca_vlc_scale_factor[i], DCA_SCALES_VLC_BITS, 129, 
-64);
diff --git a/libavcodec/dcahuff.h b/libavcodec/dcahuff.h
index 8663f8ba12..eaae234479 100644
--- a/libavcodec/dcahuff.h
+++ b/libavcodec/dcahuff.h
@@ -35,17 +35,12 @@
 3 * (5 + 7 + 9 + 13) \
 + 7 * (17 + 25 + 33 + 65 + 129))
 
-typedef struct DCAVLC {
-int max_depth;  ///< Parameter for get_vlc2()
-VLC vlc[7]; ///< Actual codes
-} DCAVLC;
-
-extern DCAVLC   ff_dca_vlc_bit_allocation;
+extern VLC  ff_dca_vlc_bit_allocation[5];
 #define DCA_TMODE_VLC_BITS 3
 extern VLC  ff_dca_vlc_transition_mode[4];
 #define DCA_SCALES_VLC_BITS 9
 extern VLC  ff_dca_vlc_scale_factor[5];
-extern DCAVLC   ff_dca_vlc_quant_index[DCA_CODE_BOOKS];
+extern VLC  ff_dca_vlc_quant_index[DCA_CODE_BOOKS][7];
 
 extern VLC  ff_dca_vlc_tnl_grp[5];
 extern VLC  ff_dca_vlc_tnl_scf;
-- 
2.34.1


[FFmpeg-devel] [PATCH 12/13] avcodec/dca_lbr: Hardcode lpc table to save space

2022-09-13 Thread Andreas Rheinhardt
The code to initialize it takes more space (in .text) than
the table to be initialized (namely 86B vs 64B for GCC 11.2
with -O3 in an av_cold function), so hardcode the table.

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

diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index 579bd9c469..9a0eb62f06 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -119,7 +119,17 @@ static const uint16_t channel_layouts[7] = {
 };
 
 static floatcos_tab[256];
-static floatlpc_tab[16];
+static const float lpc_tab[16] = {
+/* lpc_tab[i] = sin((i - 8) * (M_PI / ((i < 8) ? 17 : 15))) */
+-0.995734176295034521871191178905, -0.961825643172819070408796290732,
+-0.895163291355062322067016499754, -0.798017227280239503332805112796,
+-0.673695643646557211712691912426, -0.526432162877355800244607799141,
+-0.361241666187152948744714596184, -0.183749517816570331574408839621,
+ 0.0,   0.207911690817759337101742284405,
+ 0.406736643075800207753985990341,  0.587785252292473129168705954639,
+ 0.743144825477394235014697048974,  0.866025403784438646763723170753,
+ 0.95105651629515357211643979,  0.994521895368273336922691944981
+};
 
 av_cold void ff_dca_lbr_init_tables(void)
 {
@@ -127,9 +137,6 @@ av_cold void ff_dca_lbr_init_tables(void)
 
 for (i = 0; i < 256; i++)
 cos_tab[i] = cos(M_PI * i / 128);
-
-for (i = 0; i < 16; i++)
-lpc_tab[i] = sin((i - 8) * (M_PI / ((i < 8) ? 17 : 15)));
 }
 
 static int parse_lfe_24(DCALbrDecoder *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 13/13] avcodec/dca_lbr: Inline nb_bits for VLCs

2022-09-13 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dca_lbr.c | 31 ---
 libavcodec/dcahuff.c | 24 
 libavcodec/dcahuff.h | 11 +++
 3 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index 9a0eb62f06..73bc16d275 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -267,9 +267,10 @@ static int parse_lfe_chunk(DCALbrDecoder *s, LBRChunk 
*chunk)
 return AVERROR_INVALIDDATA;
 }
 
-static inline int parse_vlc(GetBitContext *s, VLC *vlc, int max_depth)
+static inline int parse_vlc(GetBitContext *s, const VLC *vlc,
+int nb_bits, int max_depth)
 {
-int v = get_vlc2(s, vlc->table, vlc->bits, max_depth);
+int v = get_vlc2(s, vlc->table, nb_bits, max_depth);
 if (v >= 0)
 return v;
 // Rare value
@@ -296,7 +297,7 @@ static int parse_tonal(DCALbrDecoder *s, int group)
 return AVERROR_INVALIDDATA;
 }
 
-diff = parse_vlc(&s->gb, &ff_dca_vlc_tnl_grp[group], 2);
+diff = parse_vlc(&s->gb, &ff_dca_vlc_tnl_grp[group], 
DCA_TNL_GRP_VLC_BITS, 2);
 if (diff >= FF_ARRAY_ELEMS(ff_dca_fst_amp)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid tonal frequency 
diff\n");
 return AVERROR_INVALIDDATA;
@@ -314,7 +315,7 @@ static int parse_tonal(DCALbrDecoder *s, int group)
 
 // Main channel
 main_ch = get_bitsz(&s->gb, ch_nbits);
-main_amp = parse_vlc(&s->gb, &ff_dca_vlc_tnl_scf, 2)
+main_amp = parse_vlc(&s->gb, &ff_dca_vlc_tnl_scf, 
DCA_TNL_SCF_VLC_BITS, 2)
 + s->tonal_scf[ff_dca_freq_to_sb[freq >> (7 - group)]]
 + s->limited_range - 2;
 amp[main_ch] = main_amp < AMP_MAX ? main_amp : 0;
@@ -325,8 +326,8 @@ static int parse_tonal(DCALbrDecoder *s, int group)
 if (ch == main_ch)
 continue;
 if (get_bits1(&s->gb)) {
-amp[ch] = amp[main_ch] - parse_vlc(&s->gb, 
&ff_dca_vlc_damp, 1);
-phs[ch] = phs[main_ch] - parse_vlc(&s->gb, 
&ff_dca_vlc_dph,  1);
+amp[ch] = amp[main_ch] - parse_vlc(&s->gb, 
&ff_dca_vlc_damp, DCA_DAMP_VLC_BITS, 1);
+phs[ch] = phs[main_ch] - parse_vlc(&s->gb, 
&ff_dca_vlc_dph,  DCA_DPH_VLC_BITS,  1);
 } else {
 amp[ch] = 0;
 phs[ch] = 0;
@@ -430,7 +431,7 @@ static int parse_scale_factors(DCALbrDecoder *s, uint8_t 
*scf)
 return 0;
 
 // Initial scale factor
-prev = parse_vlc(&s->gb, &ff_dca_vlc_fst_rsd_amp, 2);
+prev = parse_vlc(&s->gb, &ff_dca_vlc_fst_rsd_amp, DCA_FST_RSD_VLC_BITS, 2);
 
 for (sf = 0; sf < 7; sf += dist) {
 scf[sf] = prev; // Store previous value
@@ -439,7 +440,7 @@ static int parse_scale_factors(DCALbrDecoder *s, uint8_t 
*scf)
 return 0;
 
 // Interpolation distance
-dist = parse_vlc(&s->gb, &ff_dca_vlc_rsd_apprx, 1) + 1;
+dist = parse_vlc(&s->gb, &ff_dca_vlc_rsd_apprx, 
DCA_RSD_APPRX_VLC_BITS, 1) + 1;
 if (dist > 7 - sf) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid scale factor distance\n");
 return AVERROR_INVALIDDATA;
@@ -449,7 +450,7 @@ static int parse_scale_factors(DCALbrDecoder *s, uint8_t 
*scf)
 return 0;
 
 // Final interpolation point
-next = parse_vlc(&s->gb, &ff_dca_vlc_rsd_amp, 2);
+next = parse_vlc(&s->gb, &ff_dca_vlc_rsd_amp, DCA_RSD_AMP_VLC_BITS, 2);
 
 if (next & 1)
 next = prev + ((next + 1) >> 1);
@@ -493,7 +494,7 @@ static int parse_scale_factors(DCALbrDecoder *s, uint8_t 
*scf)
 
 static int parse_st_code(GetBitContext *s, int min_v)
 {
-unsigned int v = parse_vlc(s, &ff_dca_vlc_st_grid, 2) + min_v;
+unsigned int v = parse_vlc(s, &ff_dca_vlc_st_grid, DCA_ST_GRID_VLC_BITS, 
2) + min_v;
 
 if (v & 1)
 v = 16 + (v >> 1);
@@ -534,10 +535,10 @@ static int parse_grid_1_chunk(DCALbrDecoder *s, LBRChunk 
*chunk, int ch1, int ch
 
 // Average values for third grid
 for (sb = 0; sb < s->nsubbands - 4; sb++) {
-s->grid_3_avg[ch1][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, 2) - 16;
+s->grid_3_avg[ch1][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, 
DCA_AVG_G3_VLC_BITS, 2) - 16;
 if (ch1 != ch2) {
 if (sb + 4 < s->min_mono_subband)
-s->grid_3_avg[ch2][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, 
2) - 16;
+s->grid_3_avg[ch2][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, 
DCA_AVG_G3_VLC_BITS, 2) - 16;
 else
 s->grid_3_avg[ch2][sb] = s->grid_3_avg[ch1][sb];
 }
@@ -592,7 +593,7 @@ static int parse_grid_1_sec_ch(DCALbrDecoder *s, int ch2)
 if (sb + 4 >= s->min_mono_subband) {
 if (ensure_bits(&s->gb, 20))
 return 0;
-s->grid_3_avg

[FFmpeg-devel] [PATCH 06/13] avcodec/dcaenc: Create encoder-adapted tables

2022-09-13 Thread Andreas Rheinhardt
Up until now, the encoder used the same tables that the decoder
uses to create its VLCs. These have the downside of requiring
the encoder to offset the tables at runtime as well as having
to read from separate tables for the length as well as the code
of the symbol to encode. The former are uint8_t, the latter uint16_t,
so using a joint table would require padding, but this doesn't
matter when these tables are generated at runtime, because they
live in the .bss segment.

Also move these init functions as well as the functions that
actually use them to dcaenc.c, because they are encoder-specific.
This also allows to remove an inclusion of PutBitContext from
dcahuff.h (and indirectly from all dca-decoder files).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dcaenc.c  | 82 
 libavcodec/dcahuff.c | 64 ++
 libavcodec/dcahuff.h | 16 ++---
 3 files changed, 96 insertions(+), 66 deletions(-)

diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index d02602761b..4a02aa9d46 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -29,6 +29,7 @@
 #include "libavutil/ffmath.h"
 #include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
+#include "libavutil/thread.h"
 #include "avcodec.h"
 #include "codec_internal.h"
 #include "dca.h"
@@ -159,8 +160,41 @@ static void subband_bufer_free(DCAEncContext *c)
 }
 }
 
+static uint16_t bitalloc_12_table[DCA_BITALLOC_12_COUNT][12 + 1][2];
+
+static uint16_t bitalloc_table[DCA_NUM_BITALLOC_CODES][2];
+static const uint16_t (*bitalloc_tables[DCA_CODE_BOOKS][8])[2];
+
+static av_cold void create_enc_table(uint16_t dst[][2], unsigned count,
+ const uint8_t len[], const uint16_t 
codes[])
+{
+for (unsigned i = 0; i < count; i++) {
+dst[i][0] = codes[i];
+dst[i][1] = len[i];
+}
+}
+
+static av_cold void dcaenc_init_static_tables(void)
+{
+uint16_t (*bitalloc_dst)[2] = bitalloc_table;
+
+for (unsigned i = 0; i < DCA_CODE_BOOKS; i++) {
+for (unsigned j = 0; ff_dca_bitalloc_codes[i][j]; j++) {
+create_enc_table(bitalloc_dst, ff_dca_bitalloc_sizes[i],
+ ff_dca_bitalloc_bits[i][j], 
ff_dca_bitalloc_codes[i][j]);
+bitalloc_tables[i][j] = bitalloc_dst - ff_dca_bitalloc_offsets[i];
+bitalloc_dst += ff_dca_bitalloc_sizes[i];
+}
+}
+
+for (unsigned i = 0; i < DCA_BITALLOC_12_COUNT; i++)
+create_enc_table(&bitalloc_12_table[i][1], 12,
+ ff_dca_bitalloc_12_bits[i], 
ff_dca_bitalloc_12_codes[i]);
+}
+
 static int encode_init(AVCodecContext *avctx)
 {
+static AVOnce init_static_once = AV_ONCE_INIT;
 DCAEncContext *c = avctx->priv_data;
 AVChannelLayout layout = avctx->ch_layout;
 int i, j, k, min_frame_bits;
@@ -307,6 +341,7 @@ static int encode_init(AVCodecContext *avctx)
 c->band_spectrum_tab[1][j] = (int32_t)(200 * log10(accum));
 }
 
+ff_thread_once(&init_static_once, dcaenc_init_static_tables);
 return 0;
 }
 
@@ -400,6 +435,39 @@ static void lfe_downsample(DCAEncContext *c, const int32_t 
*input)
 }
 }
 
+static uint32_t dca_vlc_calc_alloc_bits(const int values[], uint8_t n, uint8_t 
sel)
+{
+uint32_t sum = 0;
+for (unsigned i = 0; i < n; i++)
+sum += bitalloc_12_table[sel][values[i]][1];
+return sum;
+}
+
+static void dca_vlc_enc_alloc(PutBitContext *pb, const int values[],
+  uint8_t n, uint8_t sel)
+{
+for (unsigned i = 0; i < n; i++)
+put_bits(pb, bitalloc_12_table[sel][values[i]][1],
+ bitalloc_12_table[sel][values[i]][0]);
+}
+
+static uint32_t dca_vlc_calc_quant_bits(const int values[], uint8_t n,
+uint8_t sel, uint8_t table)
+{
+uint32_t sum = 0;
+for (unsigned i = 0; i < n; i++)
+sum += bitalloc_tables[table][sel][values[i]][1];
+return sum;
+}
+
+static void dca_vlc_enc_quant(PutBitContext *pb, const int values[],
+  uint8_t n, uint8_t sel, uint8_t table)
+{
+for (unsigned i = 0; i < n; i++)
+put_bits(pb, bitalloc_tables[table][sel][values[i]][1],
+ bitalloc_tables[table][sel][values[i]][0]);
+}
+
 static int32_t get_cb(DCAEncContext *c, int32_t in)
 {
 int i, res = 0;
@@ -695,8 +763,8 @@ static void accumulate_huff_bit_consumption(int abits, 
int32_t *quantized,
 {
 uint8_t sel, id = abits - 1;
 for (sel = 0; sel < ff_dca_quant_index_group_size[id]; sel++)
-result[sel] += ff_dca_vlc_calc_quant_bits(quantized, SUBBAND_SAMPLES,
-  sel, id);
+result[sel] += dca_vlc_calc_quant_bits(quantized, SUBBAND_SAMPLES,
+   sel, id);
 }
 
 static uint32_t set_best_code(uint32_t vlc_bits[DCA_CODE_BOOKS][7],
@@ -757,7 +825,7 @@ static uint32_t set_best_abits_

Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg: Fix EOF pts for libavfilter in send_filter_eof()

2022-09-13 Thread Paul B Mahol
On 9/11/22, Li-Heng Chen  wrote:
> When input is video bitstream (e.g. *.264) with framerate set by -r,
> ist->pts could be a nonsense value.
>
> In libavfilter/vf_fps, the pts value of EOF from above is compared to pts
> derived from inlink. The wrong EOF pts may trigger a bug, where ffmpeg keeps
> writting the last video frame to the output. This bug can be easily
> reproduced by the ffmpeg cmd below (h264 bitstreams in fate-suite can
> reproduce this issue):
>
> ffmpeg -r num_in/den_in -i bitstream -vf fps=num_out/den_out -f rawvideo
> out.yuv
>
> Example: ffmpeg -r 24/1 -i fate-suite/h264/bbc2.sample.h264 -vf fps=24/1 -f
> rawvideo out.yuv
> Signed-off-by: Li-Heng Chen 
> ---
> fftools/ffmpeg.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 0e1477299d..e9a986c95b 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -2383,6 +2383,9 @@ static int send_filter_eof(InputStream *ist)
> int64_t pts = av_rescale_q_rnd(ist->pts, AV_TIME_BASE_Q,
> ist->st->time_base,
>AV_ROUND_NEAR_INF |
> AV_ROUND_PASS_MINMAX);
>
> +if(ist->framerate.num)
> +pts = ist->cfr_next_pts;
> +

Style is wrong

> for (i = 0; i < ist->nb_filters; i++) {
> ret = ifilter_send_eof(ist->filters[i], pts);
> if (ret < 0)
> --
> 2.32.1 (Apple Git-133)
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH] avcodec/tak*: use cached bitstream reader on !x86_32

2022-09-13 Thread Paul B Mahol
Patch attached
From fce08a8582169c44dc3a08a956897ccb36731822 Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Tue, 13 Sep 2022 14:38:18 +0200
Subject: [PATCH] avcodec/tak*: use cached bitstream reader on !x86_32

Increases single thread decoding speed in one example from 85x to 90x

Signed-off-by: Paul B Mahol 
---
 libavcodec/tak.c| 1 +
 libavcodec/tak_parser.c | 1 +
 libavcodec/takdec.c | 1 +
 3 files changed, 3 insertions(+)

diff --git a/libavcodec/tak.c b/libavcodec/tak.c
index 7221a80094..f26574c968 100644
--- a/libavcodec/tak.c
+++ b/libavcodec/tak.c
@@ -23,6 +23,7 @@
 #include "libavutil/crc.h"
 #include "libavutil/intreadwrite.h"
 
+#define CACHED_BITSTREAM_READER !ARCH_X86_32
 #define BITSTREAM_READER_LE
 #include "tak.h"
 
diff --git a/libavcodec/tak_parser.c b/libavcodec/tak_parser.c
index b9f47db8ac..7f5f5314af 100644
--- a/libavcodec/tak_parser.c
+++ b/libavcodec/tak_parser.c
@@ -24,6 +24,7 @@
  * TAK parser
  **/
 
+#define CACHED_BITSTREAM_READER !ARCH_X86_32
 #define BITSTREAM_READER_LE
 #include "parser.h"
 #include "tak.h"
diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index 68ad1e9ed7..5cbc2de6bd 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -29,6 +29,7 @@
 #include "libavutil/mem_internal.h"
 #include "libavutil/samplefmt.h"
 
+#define CACHED_BITSTREAM_READER !ARCH_X86_32
 #define BITSTREAM_READER_LE
 #include "audiodsp.h"
 #include "thread.h"
-- 
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] lavc: avoid rounding errors in float constants

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

INT_MAX is (typically) a value with 31 significant bits but float can
only represent 23 significant bits, leading to a rounding error.

This substitutes the actual rounded value to avoid a clang warning:

 warning: implicit conversion from 'int' to 'float' changes value from
  2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
---
 libavcodec/aaccoder.c | 2 +-
 libavcodec/imc.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index e3b6b2f02c..877558c91c 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -531,7 +531,7 @@ static void search_for_quantizers_anmr(AVCodecContext 
*avctx, AACEncContext *s,
 int nz = 0;
 
 bandaddr[idx] = w * 16 + g;
-qmin = INT_MAX;
+qmin = -INT_MIN;
 qmax = 0.0f;
 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
 FFPsyBand *band = 
&s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 92f9980ded..d4dfe3222c 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -917,7 +917,7 @@ static int imc_decode_block(AVCodecContext *avctx, 
IMCContext *q, int ch)
chctx->flcoeffs1, chctx->flcoeffs2);
 
 for(i=0; iflcoeffs1[i] > INT_MAX) {
+if(chctx->flcoeffs1[i] > -INT_MIN) {
 av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
 return AVERROR_INVALIDDATA;
 }
-- 
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".


Re: [FFmpeg-devel] [PATCH] lavc: avoid rounding errors in float constants

2022-09-13 Thread Andreas Rheinhardt
r...@remlab.net:
> From: Rémi Denis-Courmont 
> 
> INT_MAX is (typically) a value with 31 significant bits but float can
> only represent 23 significant bits, leading to a rounding error.
> 
> This substitutes the actual rounded value to avoid a clang warning:
> 
>  warning: implicit conversion from 'int' to 'float' changes value from
>   2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
> ---
>  libavcodec/aaccoder.c | 2 +-
>  libavcodec/imc.c  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
> index e3b6b2f02c..877558c91c 100644
> --- a/libavcodec/aaccoder.c
> +++ b/libavcodec/aaccoder.c
> @@ -531,7 +531,7 @@ static void search_for_quantizers_anmr(AVCodecContext 
> *avctx, AACEncContext *s,
>  int nz = 0;
>  
>  bandaddr[idx] = w * 16 + g;
> -qmin = INT_MAX;
> +qmin = -INT_MIN;
>  qmax = 0.0f;
>  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
>  FFPsyBand *band = 
> &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
> diff --git a/libavcodec/imc.c b/libavcodec/imc.c
> index 92f9980ded..d4dfe3222c 100644
> --- a/libavcodec/imc.c
> +++ b/libavcodec/imc.c
> @@ -917,7 +917,7 @@ static int imc_decode_block(AVCodecContext *avctx, 
> IMCContext *q, int ch)
> chctx->flcoeffs1, chctx->flcoeffs2);
>  
>  for(i=0; i -if(chctx->flcoeffs1[i] > INT_MAX) {
> +if(chctx->flcoeffs1[i] > -INT_MIN) {
>  av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
>  return AVERROR_INVALIDDATA;
>  }

-INT_MIN can't be represented in an int and therefore -INT_MIN on the
right is UB by C11 6.5 (5).

- 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] lavc: avoid rounding errors in float constants

2022-09-13 Thread Rémi Denis-Courmont
Le tiistaina 13. syyskuuta 2022, 18.11.35 EEST Andreas Rheinhardt a écrit :
> r...@remlab.net:
> > From: Rémi Denis-Courmont 
> > 
> > INT_MAX is (typically) a value with 31 significant bits but float can
> > only represent 23 significant bits, leading to a rounding error.
> > 
> > This substitutes the actual rounded value to avoid a clang warning:
> >  warning: implicit conversion from 'int' to 'float' changes value from
> >  
> >   2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
> > 
> > ---
> > 
> >  libavcodec/aaccoder.c | 2 +-
> >  libavcodec/imc.c  | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
> > index e3b6b2f02c..877558c91c 100644
> > --- a/libavcodec/aaccoder.c
> > +++ b/libavcodec/aaccoder.c
> > @@ -531,7 +531,7 @@ static void search_for_quantizers_anmr(AVCodecContext
> > *avctx, AACEncContext *s,> 
> >  int nz = 0;
> >  
> >  bandaddr[idx] = w * 16 + g;
> > 
> > -qmin = INT_MAX;
> > +qmin = -INT_MIN;
> > 
> >  qmax = 0.0f;
> >  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
> >  
> >  FFPsyBand *band =
> >  &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
> > 
> > diff --git a/libavcodec/imc.c b/libavcodec/imc.c
> > index 92f9980ded..d4dfe3222c 100644
> > --- a/libavcodec/imc.c
> > +++ b/libavcodec/imc.c
> > @@ -917,7 +917,7 @@ static int imc_decode_block(AVCodecContext *avctx,
> > IMCContext *q, int ch)> 
> > chctx->flcoeffs1,
> > chctx->flcoeffs2);
> >  
> >  for(i=0; i > 
> > -if(chctx->flcoeffs1[i] > INT_MAX) {
> > +if(chctx->flcoeffs1[i] > -INT_MIN) {
> > 
> >  av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
> >  return AVERROR_INVALIDDATA;
> >  
> >  }
> 
> -INT_MIN can't be represented in an int

Sure, but that's irrelevant.

> and therefore -INT_MIN on the right is UB by C11 6.5 (5).

Of course not. The type of an integer constant is always large enough to fit 
the value. In this case, it will either be long int or long long int, the 
later being large enough on any platform.

See C11 §6.4.4.1.

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



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

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


Re: [FFmpeg-devel] [PATCH] lavc: avoid rounding errors in float constants

2022-09-13 Thread Andreas Rheinhardt
Rémi Denis-Courmont:
> Le tiistaina 13. syyskuuta 2022, 18.11.35 EEST Andreas Rheinhardt a écrit :
>> r...@remlab.net:
>>> From: Rémi Denis-Courmont 
>>>
>>> INT_MAX is (typically) a value with 31 significant bits but float can
>>> only represent 23 significant bits, leading to a rounding error.
>>>
>>> This substitutes the actual rounded value to avoid a clang warning:
>>>  warning: implicit conversion from 'int' to 'float' changes value from
>>>  
>>>   2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
>>>
>>> ---
>>>
>>>  libavcodec/aaccoder.c | 2 +-
>>>  libavcodec/imc.c  | 2 +-
>>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
>>> index e3b6b2f02c..877558c91c 100644
>>> --- a/libavcodec/aaccoder.c
>>> +++ b/libavcodec/aaccoder.c
>>> @@ -531,7 +531,7 @@ static void search_for_quantizers_anmr(AVCodecContext
>>> *avctx, AACEncContext *s,> 
>>>  int nz = 0;
>>>  
>>>  bandaddr[idx] = w * 16 + g;
>>>
>>> -qmin = INT_MAX;
>>> +qmin = -INT_MIN;
>>>
>>>  qmax = 0.0f;
>>>  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
>>>  
>>>  FFPsyBand *band =
>>>  &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
>>>
>>> diff --git a/libavcodec/imc.c b/libavcodec/imc.c
>>> index 92f9980ded..d4dfe3222c 100644
>>> --- a/libavcodec/imc.c
>>> +++ b/libavcodec/imc.c
>>> @@ -917,7 +917,7 @@ static int imc_decode_block(AVCodecContext *avctx,
>>> IMCContext *q, int ch)> 
>>> chctx->flcoeffs1,
>>> chctx->flcoeffs2);
>>>  
>>>  for(i=0; i>>
>>> -if(chctx->flcoeffs1[i] > INT_MAX) {
>>> +if(chctx->flcoeffs1[i] > -INT_MIN) {
>>>
>>>  av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
>>>  return AVERROR_INVALIDDATA;
>>>  
>>>  }
>>
>> -INT_MIN can't be represented in an int
> 
> Sure, but that's irrelevant.
> 
>> and therefore -INT_MIN on the right is UB by C11 6.5 (5).
> 
> Of course not. The type of an integer constant is always large enough to fit 
> the value. In this case, it will either be long int or long long int, the 
> later being large enough on any platform.
> 
> See C11 §6.4.4.1.
> 

Incorrect. -INT_MIN is the unary minus operator applied to INT_MIN.
Regardless of how INT_MIN is defined, it is not an integer constant,
because they just don't start with '-'. See the syntax in 6.4.4.1.
Anyway, my limits.h here defines INT_MIN as follows: "#define INT_MIN
(-__INT_MAX__  -1)". As you can see, this is definitely not even close
to an integer constant as defined in 6.4.4.1.

- 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] [PATCHv2] lavc: avoid rounding errors in float constants

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

INT_MAX is (typically) a value with 31 significant bits but float can
only represent 23 significant bits, leading to a rounding error.

This substitutes the actual rounded value as an unsigned int,
to avoid a clang warning while not overflowing signed int:

 warning: implicit conversion from 'int' to 'float' changes value from
  2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
---
 libavcodec/aaccoder.c | 2 +-
 libavcodec/imc.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index e3b6b2f02c..4eab81c43f 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -531,7 +531,7 @@ static void search_for_quantizers_anmr(AVCodecContext 
*avctx, AACEncContext *s,
 int nz = 0;
 
 bandaddr[idx] = w * 16 + g;
-qmin = INT_MAX;
+qmin = 1U << 31;
 qmax = 0.0f;
 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
 FFPsyBand *band = 
&s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 92f9980ded..afdb93636a 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -917,7 +917,7 @@ static int imc_decode_block(AVCodecContext *avctx, 
IMCContext *q, int ch)
chctx->flcoeffs1, chctx->flcoeffs2);
 
 for(i=0; iflcoeffs1[i] > INT_MAX) {
+if(chctx->flcoeffs1[i] > (1U << 31)) {
 av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
 return AVERROR_INVALIDDATA;
 }
-- 
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] lavc/audiodsp: fix aliasing violation

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

Even though they have the same size, and typically the same alignment,
uint32_t and float are under no circumstances compatible types in C.

The casts from float * to uint32_t * are invalid here. Insofar as the
resulting pointers are dereferenced, this is undefined behaviour.

This patch replaces the invalid cast with explicit type aliasing via
union. Fortunately, compilers are able to optimise the "conversion"
away and skip floating pointer registers here.
---
 libavcodec/audiodsp.c | 34 ++
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/libavcodec/audiodsp.c b/libavcodec/audiodsp.c
index ff43e87dce..1781ad8bc4 100644
--- a/libavcodec/audiodsp.c
+++ b/libavcodec/audiodsp.c
@@ -22,6 +22,18 @@
 #include "libavutil/common.h"
 #include "audiodsp.h"
 
+static inline uint32_t pf2u(const float *f)
+{
+union { uint32_t u; float f; } u = { .f = *f };
+return u.u;
+}
+
+static inline float u2f(uint_fast32_t x)
+{
+union { uint32_t u; float f; } u = { .u = x };
+return u.f;
+}
+
 static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
uint32_t maxi, uint32_t maxisign)
 {
@@ -37,21 +49,19 @@ static void vector_clipf_c_opposite_sign(float *dst, const 
float *src,
  float *min, float *max, int len)
 {
 int i;
-uint32_t mini= *(uint32_t *) min;
-uint32_t maxi= *(uint32_t *) max;
+uint32_t mini= pf2u(min);
+uint32_t maxi= pf2u(max);
 uint32_t maxisign= maxi ^ (1U << 31);
-uint32_t *dsti   = (uint32_t *) dst;
-const uint32_t *srci = (const uint32_t *) src;
 
 for (i = 0; i < len; i += 8) {
-dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
-dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
-dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
-dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
-dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
-dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
-dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
-dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
+dst[i + 0] = u2f(clipf_c_one(pf2u(src + i + 0), mini, maxi, maxisign));
+dst[i + 1] = u2f(clipf_c_one(pf2u(src + i + 1), mini, maxi, maxisign));
+dst[i + 2] = u2f(clipf_c_one(pf2u(src + i + 2), mini, maxi, maxisign));
+dst[i + 3] = u2f(clipf_c_one(pf2u(src + i + 3), mini, maxi, maxisign));
+dst[i + 4] = u2f(clipf_c_one(pf2u(src + i + 4), mini, maxi, maxisign));
+dst[i + 5] = u2f(clipf_c_one(pf2u(src + i + 5), mini, maxi, maxisign));
+dst[i + 6] = u2f(clipf_c_one(pf2u(src + i + 6), mini, maxi, maxisign));
+dst[i + 7] = u2f(clipf_c_one(pf2u(src + i + 7), mini, maxi, maxisign));
 }
 }
 
-- 
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".


Re: [FFmpeg-devel] [PATCH] lavc/audiodsp: fix aliasing violation

2022-09-13 Thread Andreas Rheinhardt
r...@remlab.net:
> From: Rémi Denis-Courmont 
> 
> Even though they have the same size, and typically the same alignment,
> uint32_t and float are under no circumstances compatible types in C.
> 
> The casts from float * to uint32_t * are invalid here. Insofar as the
> resulting pointers are dereferenced, this is undefined behaviour.
> 
> This patch replaces the invalid cast with explicit type aliasing via
> union. Fortunately, compilers are able to optimise the "conversion"
> away and skip floating pointer registers here.
> ---
>  libavcodec/audiodsp.c | 34 ++
>  1 file changed, 22 insertions(+), 12 deletions(-)
> 
> diff --git a/libavcodec/audiodsp.c b/libavcodec/audiodsp.c
> index ff43e87dce..1781ad8bc4 100644
> --- a/libavcodec/audiodsp.c
> +++ b/libavcodec/audiodsp.c
> @@ -22,6 +22,18 @@
>  #include "libavutil/common.h"
>  #include "audiodsp.h"
>  
> +static inline uint32_t pf2u(const float *f)
> +{
> +union { uint32_t u; float f; } u = { .f = *f };
> +return u.u;
> +}
> +
> +static inline float u2f(uint_fast32_t x)
> +{
> +union { uint32_t u; float f; } u = { .u = x };
> +return u.f;
> +}
> +
>  static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
> uint32_t maxi, uint32_t maxisign)
>  {
> @@ -37,21 +49,19 @@ static void vector_clipf_c_opposite_sign(float *dst, 
> const float *src,
>   float *min, float *max, int len)
>  {
>  int i;
> -uint32_t mini= *(uint32_t *) min;
> -uint32_t maxi= *(uint32_t *) max;
> +uint32_t mini= pf2u(min);
> +uint32_t maxi= pf2u(max);
>  uint32_t maxisign= maxi ^ (1U << 31);
> -uint32_t *dsti   = (uint32_t *) dst;
> -const uint32_t *srci = (const uint32_t *) src;
>  
>  for (i = 0; i < len; i += 8) {
> -dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
> -dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
> -dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
> -dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
> -dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
> -dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
> -dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
> -dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
> +dst[i + 0] = u2f(clipf_c_one(pf2u(src + i + 0), mini, maxi, 
> maxisign));
> +dst[i + 1] = u2f(clipf_c_one(pf2u(src + i + 1), mini, maxi, 
> maxisign));
> +dst[i + 2] = u2f(clipf_c_one(pf2u(src + i + 2), mini, maxi, 
> maxisign));
> +dst[i + 3] = u2f(clipf_c_one(pf2u(src + i + 3), mini, maxi, 
> maxisign));
> +dst[i + 4] = u2f(clipf_c_one(pf2u(src + i + 4), mini, maxi, 
> maxisign));
> +dst[i + 5] = u2f(clipf_c_one(pf2u(src + i + 5), mini, maxi, 
> maxisign));
> +dst[i + 6] = u2f(clipf_c_one(pf2u(src + i + 6), mini, maxi, 
> maxisign));
> +dst[i + 7] = u2f(clipf_c_one(pf2u(src + i + 7), mini, maxi, 
> maxisign));
>  }
>  }
>  

We already have av_float2int() in libavutil/intfloat.h.

- 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] [PATCHv2] lavc/audiodsp: fix aliasing violation

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

Even though they have the same size, and typically the same alignment,
uint32_t and float are under no circumstances compatible types in C.

The casts from float * to uint32_t * are invalid here. Insofar as the
resulting pointers are dereferenced, this is undefined behaviour.
This patch uses av_float2int() / av_int2float() instead.
---
 libavcodec/audiodsp.c | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/libavcodec/audiodsp.c b/libavcodec/audiodsp.c
index ff43e87dce..8c0847f53f 100644
--- a/libavcodec/audiodsp.c
+++ b/libavcodec/audiodsp.c
@@ -22,36 +22,36 @@
 #include "libavutil/common.h"
 #include "audiodsp.h"
 
-static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
-   uint32_t maxi, uint32_t maxisign)
+static inline float clipf_c_one(float a, uint32_t mini,
+uint32_t maxi, uint32_t maxisign)
 {
-if (a > mini)
-return mini;
-else if ((a ^ (1U << 31)) > maxisign)
-return maxi;
+uint32_t ai = av_float2int(a);
+
+if (ai > mini)
+return av_int2float(mini);
+else if ((ai ^ (1U << 31)) > maxisign)
+return av_int2float(maxi);
 else
 return a;
 }
 
 static void vector_clipf_c_opposite_sign(float *dst, const float *src,
- float *min, float *max, int len)
+ float min, float max, int len)
 {
 int i;
-uint32_t mini= *(uint32_t *) min;
-uint32_t maxi= *(uint32_t *) max;
+uint32_t mini= av_float2int(min);
+uint32_t maxi= av_float2int(max);
 uint32_t maxisign= maxi ^ (1U << 31);
-uint32_t *dsti   = (uint32_t *) dst;
-const uint32_t *srci = (const uint32_t *) src;
 
 for (i = 0; i < len; i += 8) {
-dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
-dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
-dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
-dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
-dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
-dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
-dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
-dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
+dst[i + 0] = clipf_c_one(src[i + 0], mini, maxi, maxisign);
+dst[i + 1] = clipf_c_one(src[i + 1], mini, maxi, maxisign);
+dst[i + 2] = clipf_c_one(src[i + 2], mini, maxi, maxisign);
+dst[i + 3] = clipf_c_one(src[i + 3], mini, maxi, maxisign);
+dst[i + 4] = clipf_c_one(src[i + 4], mini, maxi, maxisign);
+dst[i + 5] = clipf_c_one(src[i + 5], mini, maxi, maxisign);
+dst[i + 6] = clipf_c_one(src[i + 6], mini, maxi, maxisign);
+dst[i + 7] = clipf_c_one(src[i + 7], mini, maxi, maxisign);
 }
 }
 
@@ -61,7 +61,7 @@ static void vector_clipf_c(float *dst, const float *src, int 
len,
 int i;
 
 if (min < 0 && max > 0) {
-vector_clipf_c_opposite_sign(dst, src, &min, &max, len);
+vector_clipf_c_opposite_sign(dst, src, min, max, len);
 } else {
 for (i = 0; i < len; i += 8) {
 dst[i] = av_clipf(src[i], min, max);
-- 
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".


Re: [FFmpeg-devel] [PATCH] avcodec/flac_parser: fix triggered assert

2022-09-13 Thread Mattias Wadman
On Tue, Sep 13, 2022 at 11:28 AM Paul B Mahol  wrote:

> On 9/8/22, Paul B Mahol  wrote:
> > Patch attached.
> >
>
> Will apply soon.


Curious where the 1 << 28 constant come from?
___
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] avutil/dict: Fix memleak when using AV_DICT_APPEND

2022-09-13 Thread Andreas Rheinhardt
If a key already exists in an AVDictionary and the AV_DICT_APPEND flag
is set, the old entry is at first discarded from the dictionary, but
a pointer to the value is kept. Lateron enough memory to store the
appended string is allocated; should this allocation fail, the old string
is not freed and hence leaks. This commit changes this by moving
creating the combined value to an earlier point in the function,
which also ensures that the AVDictionaty is unchanged in case of errors.

Signed-off-by: Andreas Rheinhardt 
---
This is an improved version of 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/2019011259.27313-1-andreas.rheinha...@gmail.com/

 libavutil/dict.c | 28 
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index a4f638a1fc..c01165634e 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -73,7 +73,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 {
 AVDictionary *m = *pm;
 AVDictionaryEntry *tag = NULL;
-char *oldval = NULL, *copy_key = NULL, *copy_value = NULL;
+char *copy_key = NULL, *copy_value = NULL;
 
 if (!(flags & AV_DICT_MULTIKEY)) {
 tag = av_dict_get(m, key, NULL, flags);
@@ -97,10 +97,17 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 av_free(copy_value);
 return 0;
 }
-if (flags & AV_DICT_APPEND)
-oldval = tag->value;
-else
-av_free(tag->value);
+if (copy_value && flags & AV_DICT_APPEND) {
+size_t len = strlen(tag->value) + strlen(copy_value) + 1;
+char *newval = av_mallocz(len);
+if (!newval)
+goto err_out;
+av_strlcat(newval, tag->value, len);
+av_strlcat(newval, copy_value, len);
+av_freep(©_value);
+copy_value = newval;
+}
+av_free(tag->value);
 av_free(tag->key);
 *tag = m->elems[--m->count];
 } else if (copy_value) {
@@ -113,17 +120,6 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 if (copy_value) {
 m->elems[m->count].key = copy_key;
 m->elems[m->count].value = copy_value;
-if (oldval && flags & AV_DICT_APPEND) {
-size_t len = strlen(oldval) + strlen(copy_value) + 1;
-char *newval = av_mallocz(len);
-if (!newval)
-goto err_out;
-av_strlcat(newval, oldval, len);
-av_freep(&oldval);
-av_strlcat(newval, copy_value, len);
-m->elems[m->count].value = newval;
-av_freep(©_value);
-}
 m->count++;
 } else {
 av_freep(©_key);
-- 
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] avutil/dict: Improve appending values

2022-09-13 Thread Andreas Rheinhardt
When appending two values (due to AV_DICT_APPEND), the earlier code
would first zero-allocate a buffer of the required size and then
copy both parts into it via av_strlcat(). This is problematic,
as it leads to quadratic performance in case of frequent enlargements.
Fix this by using av_realloc() (which is hopefully designed to handle
such cases in a better way than simply throwing the buffer we already
have away) and by copying the string via memcpy() (after all, we already
calculated the strlen of both strings).

Signed-off-by: Andreas Rheinhardt 
---
 libavutil/dict.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index c01165634e..1968063b0b 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -98,16 +98,17 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 return 0;
 }
 if (copy_value && flags & AV_DICT_APPEND) {
-size_t len = strlen(tag->value) + strlen(copy_value) + 1;
-char *newval = av_mallocz(len);
+size_t oldlen = strlen(tag->value);
+size_t new_part_len = strlen(copy_value);
+size_t len = oldlen + new_part_len + 1;
+char *newval = av_realloc(tag->value, len);
 if (!newval)
 goto err_out;
-av_strlcat(newval, tag->value, len);
-av_strlcat(newval, copy_value, len);
+memcpy(newval + oldlen, copy_value, new_part_len + 1);
 av_freep(©_value);
 copy_value = newval;
-}
-av_free(tag->value);
+} else
+av_free(tag->value);
 av_free(tag->key);
 *tag = m->elems[--m->count];
 } else if (copy_value) {
-- 
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] avutil/dict: Avoid check whose result is known in advance

2022-09-13 Thread Andreas Rheinhardt
We know that an AVDictionary is not empty if we have just added
an entry to it, so only check for it being empty on the branch
that does not do so.

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

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 1968063b0b..4bba041d0a 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -123,12 +123,12 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 m->elems[m->count].value = copy_value;
 m->count++;
 } else {
+if (!m->count) {
+av_freep(&m->elems);
+av_freep(pm);
+}
 av_freep(©_key);
 }
-if (!m->count) {
-av_freep(&m->elems);
-av_freep(pm);
-}
 
 return 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".


Re: [FFmpeg-devel] [PATCH 3/3] avutil/dict: Avoid check whose result is known in advance

2022-09-13 Thread Paul B Mahol
On 9/13/22, Andreas Rheinhardt  wrote:
> We know that an AVDictionary is not empty if we have just added
> an entry to it, so only check for it being empty on the branch
> that does not do so.
>
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavutil/dict.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>

LGTM

> diff --git a/libavutil/dict.c b/libavutil/dict.c
> index 1968063b0b..4bba041d0a 100644
> --- a/libavutil/dict.c
> +++ b/libavutil/dict.c
> @@ -123,12 +123,12 @@ int av_dict_set(AVDictionary **pm, const char *key,
> const char *value,
>  m->elems[m->count].value = copy_value;
>  m->count++;
>  } else {
> +if (!m->count) {
> +av_freep(&m->elems);
> +av_freep(pm);
> +}
>  av_freep(©_key);
>  }
> -if (!m->count) {
> -av_freep(&m->elems);
> -av_freep(pm);
> -}
>
>  return 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 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] libavfilter/vf_colorrange_cuda: CUDA-accelerated video filter for MPEG and JPEG color range conversions

2022-09-13 Thread Timo Rothenpieler

On 11.09.2022 09:28, Roman Arzumanyan wrote:

Thanks for the detailed review, Timo.

Please find fixed patch in attachement.


I've renamed the filter to colorspace_cuda, did some super minor 
stylistic fixes and applied the patch.


Works as I would expect. Obviously it's super limited in what it can do, 
as is the intent for now. But that's fine, features the software version 
offers can be added as people need/want them.



___
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/dolby_e: Add error recovery when parse_mantissas run out of bits

2022-09-13 Thread Nicolas Gaullier
Mantissas are the last data in the channel subsegment and it appears it is
sometimes missing a very few bits for the parsing to complete.
This should not be confused with data corruption.
For 5.1+2@25fps, the occurence of this issue is pretty steady and about once 
every 2 hours.
The truncation is at about 950 out of the 1024 values (never seen below 923 so 
far).
The current code raises a severe 'Read past end' error and all data is lost 
resulting in
20ms(@25fps) of silence for the affected channel.
This patch introduces a tolerance: if 800 out of the 1024 mantissas have been 
parsed,
a simple warning is raised and the data is preserved.

Signed-off-by: Nicolas Gaullier 
---
 libavcodec/dolby_e.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 06f4fdd44f..0ec7b5e318 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -844,6 +844,7 @@ static int parse_indices(DBEContext *s, DBEChannel *c)
 return 0;
 }
 
+#define MIN_MANTISSAS 800
 static int parse_mantissas(DBEContext *s, DBEChannel *c)
 {
 DBEGroup *g;
@@ -884,6 +885,13 @@ static int parse_mantissas(DBEContext *s, DBEChannel *c)
 }
 }
 } else {
+if (i == c->nb_groups - 1
+&& count * size1 > get_bits_left(&s->gb)
+&& get_bits_left(&s->gb) >= 0
+&& (int)(mnt - c->mantissas) >= MIN_MANTISSAS) {
+av_log(s->avctx, AV_LOG_WARNING, "Truncated mantissas @%d, 
highest frequencies not recoverable\n", (int)(mnt - c->mantissas));
+break;
+}
 for (k = 0; k < count; k++)
 mnt[k] = get_sbits(&s->gb, size1) * scale;
 }
-- 
2.11.0

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

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


[FFmpeg-devel] [PATCH] avcodec/libvpxenc: add -min-gf-interval

2022-09-13 Thread James Zern
this maps to the vpxenc argument with the same name and the
VP9E_SET_MIN_GF_INTERVAL codec control

Signed-off-by: James Zern 
---
 doc/encoders.texi  |  2 ++
 libavcodec/libvpxenc.c | 11 +++
 libavcodec/version.h   |  2 +-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index ac71f50ad2..5a5579d5e5 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2176,6 +2176,8 @@ Set altref noise reduction filter type: backward, 
forward, centered.
 Set altref noise reduction filter strength.
 @item rc-lookahead, lag-in-frames (@emph{lag-in-frames})
 Set number of frames to look ahead for frametype and ratecontrol.
+@item min-gf-interval
+Set minimum golden/alternate reference frame interval (VP9 only).
 @end table
 
 @item error-resilient
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 09b56aae2a..667cffc200 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -131,6 +131,7 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
+int min_gf_interval;
 AVFifo *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
@@ -186,6 +187,9 @@ static const char *const ctlidstr[] = {
 #ifdef VPX_CTRL_VP9E_SET_TPL
 [VP9E_SET_TPL] = "VP9E_SET_TPL",
 #endif
+#ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
+[VP9E_SET_MIN_GF_INTERVAL] = "VP9E_SET_MIN_GF_INTERVAL",
+#endif
 #endif
 };
 
@@ -1173,6 +1177,10 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 #ifdef VPX_CTRL_VP9E_SET_TPL
 if (ctx->tpl_model >= 0)
 codecctl_int(avctx, VP9E_SET_TPL, ctx->tpl_model);
+#endif
+#ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
+if (ctx->min_gf_interval >= 0)
+codecctl_int(avctx, VP9E_SET_MIN_GF_INTERVAL, 
ctx->min_gf_interval);
 #endif
 }
 #endif
@@ -1911,6 +1919,9 @@ static const AVOption vp9_options[] = {
 #endif
 #ifdef VPX_CTRL_VP9E_SET_TPL
 { "enable-tpl",  "Enable temporal dependency model", 
OFFSET(tpl_model), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },
+#endif
+#ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
+{ "min-gf-interval", "Minimum golden/alternate reference frame interval", 
OFFSET(min_gf_interval), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE },
 #endif
 LEGACY_OPTIONS
 { NULL }
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 2328be4b26..7e89daf017 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  43
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.37.2.789.g6183377224-goog

___
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] avformat/dump: Avoid unnecessary implicit calculation of strlen

2022-09-13 Thread Andreas Rheinhardt
av_strlcpy() returns the length of the src string to enable
the caller to check for truncation. It is currently used in
the following way in dump_metadata(): Every metadata value
is searched for \b, \n, \v, \f, \r and then the data up to
the first of these characters found is copied to a small
temporary buffer via av_strlcpy() (but of course not more
than fits into said buffer) and then printed; all characters up
to the character found earlier are then treated as consumed.

But this is bad performance-wise if the while string is big
and contains many of these characters, because av_strlcpy()
will unnecessarily calculate the length of the whole remaining string.
(dump_metadata() actually ignored the return value of av_strlcpy().)

Fix this by just not copying the data in a temporary buffer at all.
Instead just use the %.*s to bound the number of characters output.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/dump.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavformat/dump.c b/libavformat/dump.c
index e3f0056c20..cafcef36c6 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -145,10 +145,8 @@ static void dump_metadata(void *ctx, const AVDictionary 
*m, const char *indent)
 av_log(ctx, AV_LOG_INFO,
"%s  %-16s: ", indent, tag->key);
 while (*p) {
-char tmp[256];
 size_t len = strcspn(p, "\x8\xa\xb\xc\xd");
-av_strlcpy(tmp, p, FFMIN(sizeof(tmp), len+1));
-av_log(ctx, AV_LOG_INFO, "%s", tmp);
+av_log(ctx, AV_LOG_INFO, "%.*s", (int)(FFMIN(255, len)), 
p);
 p += len;
 if (*p == 0xd) av_log(ctx, AV_LOG_INFO, " ");
 if (*p == 0xa) av_log(ctx, AV_LOG_INFO, "\n%s  %-16s: ", 
indent, "");
-- 
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".