Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce code size
@ 2025-05-19 12:15 chenyu202107
  2025-05-19 12:15 ` [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing " chenyu202107
  2025-05-19 13:03 ` [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce " Andreas Rheinhardt
  0 siblings, 2 replies; 5+ messages in thread
From: chenyu202107 @ 2025-05-19 12:15 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: chenyu

From: chenyu <chenyu202107@gmail.com>

add depends to pcm.c for reducing size when ALAW/MULAW/VIDC not defined

Signed-off-by: chenyu <chenyu202107@gmail.com>
---
 libavcodec/pcm.c          | 36 +++++++++++++++++++++++++++++++-----
 libavcodec/pcm_tablegen.h | 22 ++++++++++++++++++++++
 2 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index bff61f2195..60a2c544a8 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -44,15 +44,20 @@ static av_cold int pcm_encode_init(AVCodecContext *avctx)
 #if !CONFIG_HARDCODED_TABLES
     switch (avctx->codec->id) {
 #define INIT_ONCE(id, name)                                                 \
-    case AV_CODEC_ID_PCM_ ## id:                                            \
-        if (CONFIG_PCM_ ## id ## _ENCODER) {                                \
+    case AV_CODEC_ID_PCM_ ## id: {                                          \
             static AVOnce init_static_once = AV_ONCE_INIT;                  \
             ff_thread_once(&init_static_once, pcm_ ## name ## _tableinit);  \
-        }                                                                   \
-        break
+            break;                                                          \
+        }
+#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
         INIT_ONCE(ALAW,  alaw);
+#endif
+#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
         INIT_ONCE(MULAW, ulaw);
+#endif
+#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
         INIT_ONCE(VIDC,  vidc);
+#endif
     default:
         break;
     }
@@ -216,24 +221,30 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
             bytestream_put_buffer(&dst, src, n * sample_size);
         }
         break;
+#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
     case AV_CODEC_ID_PCM_ALAW:
         for (; n > 0; n--) {
             v      = *samples++;
             *dst++ = linear_to_alaw[(v + 32768) >> 2];
         }
         break;
+#endif
+#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
     case AV_CODEC_ID_PCM_MULAW:
         for (; n > 0; n--) {
             v      = *samples++;
             *dst++ = linear_to_ulaw[(v + 32768) >> 2];
         }
         break;
+#endif
+#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
     case AV_CODEC_ID_PCM_VIDC:
         for (; n > 0; n--) {
             v      = *samples++;
             *dst++ = linear_to_vidc[(v + 32768) >> 2];
         }
         break;
+#endif
     default:
         return -1;
     }
@@ -327,20 +338,25 @@ static av_cold av_unused int pcm_lut_decode_init(AVCodecContext *avctx)
     PCMLUTDecode *s = avctx->priv_data;
 
     switch (avctx->codec_id) {
+#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
     case AV_CODEC_ID_PCM_ALAW:
         for (int i = 0; i < 256; i++)
             s->table[i] = alaw2linear(i);
         break;
+#endif
+#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
     case AV_CODEC_ID_PCM_MULAW:
         for (int i = 0; i < 256; i++)
             s->table[i] = ulaw2linear(i);
         break;
+#endif
+#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
     case AV_CODEC_ID_PCM_VIDC:
         for (int i = 0; i < 256; i++)
             s->table[i] = vidc2linear(i);
         break;
     }
-
+#endif
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
     s->base.sample_size = 1;
 
@@ -545,6 +561,9 @@ static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
             bytestream_get_buffer(&src, samples, n * sample_size);
         }
         break;
+#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER || \
+    CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER || \
+    CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
     case AV_CODEC_ID_PCM_ALAW:
     case AV_CODEC_ID_PCM_MULAW:
     case AV_CODEC_ID_PCM_VIDC: {
@@ -555,6 +574,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
             *samples_16++ = lut[*src++];
         break;
     }
+#endif
     case AV_CODEC_ID_PCM_LXF:
     {
         int i;
@@ -655,7 +675,9 @@ const FFCodec ff_ ## name_ ## _decoder = {                                  \
  *       to the table in pcm_decode_init() as well. */
 //            AV_CODEC_ID_*      pcm_* name
 //                          AV_SAMPLE_FMT_*    long name                                DecodeContext   decode init func
+#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
 PCM_CODEC_EXT(ALAW,         S16, alaw,         "PCM A-law / G.711 A-law",               PCMLUTDecode,   pcm_lut_decode_init);
+#endif
 PCM_DEC_EXT  (F16LE,        FLT, f16le,        "PCM 16.8 floating point little-endian", PCMScaleDecode, pcm_scale_decode_init);
 PCM_DEC_EXT  (F24LE,        FLT, f24le,        "PCM 24.0 floating point little-endian", PCMScaleDecode, pcm_scale_decode_init);
 PCM_CODEC    (F32BE,        FLT, f32be,        "PCM 32-bit floating point big-endian");
@@ -663,7 +685,9 @@ PCM_CODEC    (F32LE,        FLT, f32le,        "PCM 32-bit floating point little
 PCM_CODEC    (F64BE,        DBL, f64be,        "PCM 64-bit floating point big-endian");
 PCM_CODEC    (F64LE,        DBL, f64le,        "PCM 64-bit floating point little-endian");
 PCM_DECODER  (LXF,          S32P,lxf,          "PCM signed 20-bit little-endian planar");
+#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
 PCM_CODEC_EXT(MULAW,        S16, mulaw,        "PCM mu-law / G.711 mu-law",             PCMLUTDecode,   pcm_lut_decode_init);
+#endif
 PCM_CODEC    (S8,           U8,  s8,           "PCM signed 8-bit");
 PCM_CODEC    (S8_PLANAR,    U8P, s8_planar,    "PCM signed 8-bit planar");
 PCM_CODEC    (S16BE,        S16, s16be,        "PCM signed 16-bit big-endian");
@@ -686,5 +710,7 @@ PCM_CODEC    (U32BE,        S32, u32be,        "PCM unsigned 32-bit big-endian")
 PCM_CODEC    (U32LE,        S32, u32le,        "PCM unsigned 32-bit little-endian");
 PCM_CODEC    (S64BE,        S64, s64be,        "PCM signed 64-bit big-endian");
 PCM_CODEC    (S64LE,        S64, s64le,        "PCM signed 64-bit little-endian");
+#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
 PCM_CODEC_EXT(VIDC,         S16, vidc,         "PCM Archimedes VIDC",                   PCMLUTDecode,   pcm_lut_decode_init);
+#endif
 PCM_DECODER  (SGA,          U8,  sga,          "PCM SGA");
diff --git a/libavcodec/pcm_tablegen.h b/libavcodec/pcm_tablegen.h
index 7274c3cd17..590ba59814 100644
--- a/libavcodec/pcm_tablegen.h
+++ b/libavcodec/pcm_tablegen.h
@@ -42,6 +42,7 @@
 #define         VIDC_SEG_SHIFT   (5)
 #define         VIDC_SEG_MASK    (0xE0)
 
+#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
 /* alaw2linear() - Convert an A-law value to 16-bit linear PCM */
 static av_cold int alaw2linear(unsigned char a_val)
 {
@@ -57,7 +58,9 @@ static av_cold int alaw2linear(unsigned char a_val)
 
     return (a_val & SIGN_BIT) ? t : -t;
 }
+#endif
 
+#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
 static av_cold int ulaw2linear(unsigned char u_val)
 {
     int t;
@@ -74,7 +77,9 @@ static av_cold int ulaw2linear(unsigned char u_val)
 
     return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS);
 }
+#endif
 
+#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
 static av_cold int vidc2linear(unsigned char u_val)
 {
     int t;
@@ -88,6 +93,7 @@ static av_cold int vidc2linear(unsigned char u_val)
 
     return (u_val & VIDC_SIGN_BIT) ? (BIAS - t) : (t - BIAS);
 }
+#endif
 
 #if CONFIG_HARDCODED_TABLES
 #define pcm_alaw_tableinit()
@@ -96,10 +102,19 @@ static av_cold int vidc2linear(unsigned char u_val)
 #include "libavcodec/pcm_tables.h"
 #else
 /* 16384 entries per table */
+#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
 static uint8_t linear_to_alaw[16384];
+#endif
+#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
 static uint8_t linear_to_ulaw[16384];
+#endif
+#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
 static uint8_t linear_to_vidc[16384];
+#endif
 
+#if CONFIG_PCM_ALAW_DECODER  || CONFIG_PCM_ALAW_ENCODER  || \
+    CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER || \
+    CONFIG_PCM_VIDC_DECODER  || CONFIG_PCM_VIDC_ENCODER
 static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
                              int (*xlaw2linear)(unsigned char),
                              int mask)
@@ -123,21 +138,28 @@ static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
     }
     linear_to_xlaw[0] = linear_to_xlaw[1];
 }
+#endif
 
+#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
 static void pcm_alaw_tableinit(void)
 {
     build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5);
 }
+#endif
 
+#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
 static void pcm_ulaw_tableinit(void)
 {
     build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
 }
+#endif
 
+#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
 static void pcm_vidc_tableinit(void)
 {
     build_xlaw_table(linear_to_vidc, vidc2linear, 0xff);
 }
+#endif
 #endif /* CONFIG_HARDCODED_TABLES */
 
 #endif /* AVCODEC_PCM_TABLEGEN_H */
-- 
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-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing code size
  2025-05-19 12:15 [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce code size chenyu202107
@ 2025-05-19 12:15 ` chenyu202107
  2025-05-21  0:46   ` Michael Niedermayer
  2025-05-19 13:03 ` [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce " Andreas Rheinhardt
  1 sibling, 1 reply; 5+ messages in thread
From: chenyu202107 @ 2025-05-19 12:15 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: chenyu

From: chenyu <chenyu202107@gmail.com>

Optimizing 160k code size by converting static array to dynamic malloc memory.

Signed-off-by: chenyu <chenyu202107@gmail.com>
---
 libavcodec/mpegaudiodata.h                |  4 ++--
 libavcodec/mpegaudiodec_common_tablegen.h | 10 ++++++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpegaudiodata.h b/libavcodec/mpegaudiodata.h
index 720c4bee64..6dfb74cd01 100644
--- a/libavcodec/mpegaudiodata.h
+++ b/libavcodec/mpegaudiodata.h
@@ -50,8 +50,8 @@ extern const unsigned char * const ff_mpa_alloc_tables[5];
 extern const int8_t   ff_table_4_3_exp  [TABLE_4_3_SIZE];
 extern const uint32_t ff_table_4_3_value[TABLE_4_3_SIZE];
 #else
-extern int8_t   ff_table_4_3_exp  [TABLE_4_3_SIZE];
-extern uint32_t ff_table_4_3_value[TABLE_4_3_SIZE];
+extern int8_t   *ff_table_4_3_exp;
+extern uint32_t *ff_table_4_3_value;
 #endif
 
 /* VLCs for decoding layer 3 huffman tables */
diff --git a/libavcodec/mpegaudiodec_common_tablegen.h b/libavcodec/mpegaudiodec_common_tablegen.h
index bf402c9d84..66e93df27f 100644
--- a/libavcodec/mpegaudiodec_common_tablegen.h
+++ b/libavcodec/mpegaudiodec_common_tablegen.h
@@ -34,9 +34,10 @@
 #else
 #include <math.h>
 #include "libavutil/attributes.h"
+#include "libavutil/mem.h"
 
-int8_t   ff_table_4_3_exp  [TABLE_4_3_SIZE];
-uint32_t ff_table_4_3_value[TABLE_4_3_SIZE];
+int8_t   *ff_table_4_3_exp;
+uint32_t *ff_table_4_3_value;
 
 #define FRAC_BITS 23
 #define IMDCT_SCALAR 1.759
@@ -51,6 +52,11 @@ static av_cold void mpegaudiodec_common_tableinit(void)
     };
     double pow43_val = 0;
 
+#if !CONFIG_HARDCODED_TABLES
+    ff_table_4_3_exp = (int8_t *)av_calloc(TABLE_4_3_SIZE, sizeof(int8_t));
+    ff_table_4_3_value = (uint32_t *)av_calloc(TABLE_4_3_SIZE, sizeof(uint32_t));
+#endif
+
     for (int i = 1; i < TABLE_4_3_SIZE; i++) {
         double f, fm;
         int e, m;
-- 
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-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce code size
  2025-05-19 12:15 [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce code size chenyu202107
  2025-05-19 12:15 ` [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing " chenyu202107
@ 2025-05-19 13:03 ` Andreas Rheinhardt
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2025-05-19 13:03 UTC (permalink / raw)
  To: ffmpeg-devel

chenyu202107@gmail.com:
> From: chenyu <chenyu202107@gmail.com>
> 
> add depends to pcm.c for reducing size when ALAW/MULAW/VIDC not defined
> 
> Signed-off-by: chenyu <chenyu202107@gmail.com>
> ---
>  libavcodec/pcm.c          | 36 +++++++++++++++++++++++++++++++-----
>  libavcodec/pcm_tablegen.h | 22 ++++++++++++++++++++++
>  2 files changed, 53 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
> index bff61f2195..60a2c544a8 100644
> --- a/libavcodec/pcm.c
> +++ b/libavcodec/pcm.c
> @@ -44,15 +44,20 @@ static av_cold int pcm_encode_init(AVCodecContext *avctx)
>  #if !CONFIG_HARDCODED_TABLES
>      switch (avctx->codec->id) {
>  #define INIT_ONCE(id, name)                                                 \
> -    case AV_CODEC_ID_PCM_ ## id:                                            \
> -        if (CONFIG_PCM_ ## id ## _ENCODER) {                                \
> +    case AV_CODEC_ID_PCM_ ## id: {                                          \
>              static AVOnce init_static_once = AV_ONCE_INIT;                  \
>              ff_thread_once(&init_static_once, pcm_ ## name ## _tableinit);  \
> -        }                                                                   \
> -        break
> +            break;                                                          \
> +        }
> +#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
>          INIT_ONCE(ALAW,  alaw);
> +#endif
> +#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
>          INIT_ONCE(MULAW, ulaw);
> +#endif
> +#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
>          INIT_ONCE(VIDC,  vidc);
> +#endif

The macro already checks whether the relevant encoder is enabled; your
code meanwhile enables the code when the encoder or the decoder is
enabled, although only the encoders will ever use this.

>      default:
>          break;
>      }
> @@ -216,24 +221,30 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>              bytestream_put_buffer(&dst, src, n * sample_size);
>          }
>          break;
> +#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
>      case AV_CODEC_ID_PCM_ALAW:
>          for (; n > 0; n--) {
>              v      = *samples++;
>              *dst++ = linear_to_alaw[(v + 32768) >> 2];
>          }
>          break;
> +#endif
> +#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
>      case AV_CODEC_ID_PCM_MULAW:
>          for (; n > 0; n--) {
>              v      = *samples++;
>              *dst++ = linear_to_ulaw[(v + 32768) >> 2];
>          }
>          break;
> +#endif
> +#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
>      case AV_CODEC_ID_PCM_VIDC:
>          for (; n > 0; n--) {
>              v      = *samples++;
>              *dst++ = linear_to_vidc[(v + 32768) >> 2];
>          }
>          break;
> +#endif
>      default:
>          return -1;
>      }
> @@ -327,20 +338,25 @@ static av_cold av_unused int pcm_lut_decode_init(AVCodecContext *avctx)
>      PCMLUTDecode *s = avctx->priv_data;
>  
>      switch (avctx->codec_id) {
> +#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
>      case AV_CODEC_ID_PCM_ALAW:
>          for (int i = 0; i < 256; i++)
>              s->table[i] = alaw2linear(i);
>          break;
> +#endif
> +#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
>      case AV_CODEC_ID_PCM_MULAW:
>          for (int i = 0; i < 256; i++)
>              s->table[i] = ulaw2linear(i);
>          break;
> +#endif
> +#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
>      case AV_CODEC_ID_PCM_VIDC:
>          for (int i = 0; i < 256; i++)
>              s->table[i] = vidc2linear(i);
>          break;
>      }
> -
> +#endif

The encoder checks here are wrong; and the placement of the last endif
is wrong, too.

>      avctx->sample_fmt = AV_SAMPLE_FMT_S16;
>      s->base.sample_size = 1;
>  
> @@ -545,6 +561,9 @@ static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
>              bytestream_get_buffer(&src, samples, n * sample_size);
>          }
>          break;
> +#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER || \
> +    CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER || \
> +    CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER

This should not check for the encoders at all, because this is in the
decoder.

>      case AV_CODEC_ID_PCM_ALAW:
>      case AV_CODEC_ID_PCM_MULAW:
>      case AV_CODEC_ID_PCM_VIDC: {
> @@ -555,6 +574,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
>              *samples_16++ = lut[*src++];
>          break;
>      }
> +#endif
>      case AV_CODEC_ID_PCM_LXF:
>      {
>          int i;
> @@ -655,7 +675,9 @@ const FFCodec ff_ ## name_ ## _decoder = {                                  \
>   *       to the table in pcm_decode_init() as well. */
>  //            AV_CODEC_ID_*      pcm_* name
>  //                          AV_SAMPLE_FMT_*    long name                                DecodeContext   decode init func
> +#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
>  PCM_CODEC_EXT(ALAW,         S16, alaw,         "PCM A-law / G.711 A-law",               PCMLUTDecode,   pcm_lut_decode_init);
> +#endif

These macros already contain implicit checks to ensure that only the
FFCodecs for actually enabled codecs are included in the binary.

>  PCM_DEC_EXT  (F16LE,        FLT, f16le,        "PCM 16.8 floating point little-endian", PCMScaleDecode, pcm_scale_decode_init);
>  PCM_DEC_EXT  (F24LE,        FLT, f24le,        "PCM 24.0 floating point little-endian", PCMScaleDecode, pcm_scale_decode_init);
>  PCM_CODEC    (F32BE,        FLT, f32be,        "PCM 32-bit floating point big-endian");
> @@ -663,7 +685,9 @@ PCM_CODEC    (F32LE,        FLT, f32le,        "PCM 32-bit floating point little
>  PCM_CODEC    (F64BE,        DBL, f64be,        "PCM 64-bit floating point big-endian");
>  PCM_CODEC    (F64LE,        DBL, f64le,        "PCM 64-bit floating point little-endian");
>  PCM_DECODER  (LXF,          S32P,lxf,          "PCM signed 20-bit little-endian planar");
> +#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
>  PCM_CODEC_EXT(MULAW,        S16, mulaw,        "PCM mu-law / G.711 mu-law",             PCMLUTDecode,   pcm_lut_decode_init);
> +#endif
>  PCM_CODEC    (S8,           U8,  s8,           "PCM signed 8-bit");
>  PCM_CODEC    (S8_PLANAR,    U8P, s8_planar,    "PCM signed 8-bit planar");
>  PCM_CODEC    (S16BE,        S16, s16be,        "PCM signed 16-bit big-endian");
> @@ -686,5 +710,7 @@ PCM_CODEC    (U32BE,        S32, u32be,        "PCM unsigned 32-bit big-endian")
>  PCM_CODEC    (U32LE,        S32, u32le,        "PCM unsigned 32-bit little-endian");
>  PCM_CODEC    (S64BE,        S64, s64be,        "PCM signed 64-bit big-endian");
>  PCM_CODEC    (S64LE,        S64, s64le,        "PCM signed 64-bit little-endian");
> +#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
>  PCM_CODEC_EXT(VIDC,         S16, vidc,         "PCM Archimedes VIDC",                   PCMLUTDecode,   pcm_lut_decode_init);
> +#endif
>  PCM_DECODER  (SGA,          U8,  sga,          "PCM SGA");
> diff --git a/libavcodec/pcm_tablegen.h b/libavcodec/pcm_tablegen.h
> index 7274c3cd17..590ba59814 100644
> --- a/libavcodec/pcm_tablegen.h
> +++ b/libavcodec/pcm_tablegen.h
> @@ -42,6 +42,7 @@
>  #define         VIDC_SEG_SHIFT   (5)
>  #define         VIDC_SEG_MASK    (0xE0)
>  
> +#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
>  /* alaw2linear() - Convert an A-law value to 16-bit linear PCM */
>  static av_cold int alaw2linear(unsigned char a_val)
>  {
> @@ -57,7 +58,9 @@ static av_cold int alaw2linear(unsigned char a_val)
>  
>      return (a_val & SIGN_BIT) ? t : -t;
>  }
> +#endif
>  
> +#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
>  static av_cold int ulaw2linear(unsigned char u_val)
>  {
>      int t;
> @@ -74,7 +77,9 @@ static av_cold int ulaw2linear(unsigned char u_val)
>  
>      return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS);
>  }
> +#endif
>  
> +#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
>  static av_cold int vidc2linear(unsigned char u_val)
>  {
>      int t;
> @@ -88,6 +93,7 @@ static av_cold int vidc2linear(unsigned char u_val)
>  
>      return (u_val & VIDC_SIGN_BIT) ? (BIAS - t) : (t - BIAS);
>  }
> +#endif
>  
>  #if CONFIG_HARDCODED_TABLES
>  #define pcm_alaw_tableinit()
> @@ -96,10 +102,19 @@ static av_cold int vidc2linear(unsigned char u_val)
>  #include "libavcodec/pcm_tables.h"
>  #else
>  /* 16384 entries per table */
> +#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
>  static uint8_t linear_to_alaw[16384];
> +#endif
> +#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
>  static uint8_t linear_to_ulaw[16384];
> +#endif
> +#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
>  static uint8_t linear_to_vidc[16384];
> +#endif
>  
> +#if CONFIG_PCM_ALAW_DECODER  || CONFIG_PCM_ALAW_ENCODER  || \
> +    CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER || \
> +    CONFIG_PCM_VIDC_DECODER  || CONFIG_PCM_VIDC_ENCODER
>  static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
>                               int (*xlaw2linear)(unsigned char),
>                               int mask)
> @@ -123,21 +138,28 @@ static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw,
>      }
>      linear_to_xlaw[0] = linear_to_xlaw[1];
>  }
> +#endif
>  
> +#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
>  static void pcm_alaw_tableinit(void)
>  {
>      build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5);
>  }
> +#endif
>  
> +#if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
>  static void pcm_ulaw_tableinit(void)
>  {
>      build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
>  }
> +#endif
>  
> +#if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
>  static void pcm_vidc_tableinit(void)
>  {
>      build_xlaw_table(linear_to_vidc, vidc2linear, 0xff);
>  }
> +#endif
>  #endif /* CONFIG_HARDCODED_TABLES */

This is static stuff; the compiler can already optimize it away when it
sees that it is not referenced by anything that is kept.

>  
>  #endif /* AVCODEC_PCM_TABLEGEN_H */

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

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing code size
  2025-05-19 12:15 ` [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing " chenyu202107
@ 2025-05-21  0:46   ` Michael Niedermayer
  2025-05-21  7:40     ` Michael Niedermayer
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Niedermayer @ 2025-05-21  0:46 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 837 bytes --]

On Mon, May 19, 2025 at 08:15:37PM +0800, chenyu202107@gmail.com wrote:
> From: chenyu <chenyu202107@gmail.com>
> 
> Optimizing 160k code size by converting static array to dynamic malloc memory.
> 
> Signed-off-by: chenyu <chenyu202107@gmail.com>
> ---
>  libavcodec/mpegaudiodata.h                |  4 ++--
>  libavcodec/mpegaudiodec_common_tablegen.h | 10 ++++++++--
>  2 files changed, 10 insertions(+), 4 deletions(-)

This segfaults:

./ffmpeg_g -max_error_rate 2 -max_alloc 100000 -i ~/tickets/2950/mpeg2_fuzz.mpg -max_muxing_queue_size 8000 -f null -


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

Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

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

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing code size
  2025-05-21  0:46   ` Michael Niedermayer
@ 2025-05-21  7:40     ` Michael Niedermayer
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Niedermayer @ 2025-05-21  7:40 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1846 bytes --]

On Wed, May 21, 2025 at 02:46:42AM +0200, Michael Niedermayer wrote:
> On Mon, May 19, 2025 at 08:15:37PM +0800, chenyu202107@gmail.com wrote:
> > From: chenyu <chenyu202107@gmail.com>
> > 
> > Optimizing 160k code size by converting static array to dynamic malloc memory.
> > 
> > Signed-off-by: chenyu <chenyu202107@gmail.com>
> > ---
> >  libavcodec/mpegaudiodata.h                |  4 ++--
> >  libavcodec/mpegaudiodec_common_tablegen.h | 10 ++++++++--
> >  2 files changed, 10 insertions(+), 4 deletions(-)
> 
> This segfaults:
> 
> ./ffmpeg_g -max_error_rate 2 -max_alloc 100000 -i ~/tickets/2950/mpeg2_fuzz.mpg -max_muxing_queue_size 8000 -f null -

==3638361== Invalid write of size 4
==3638361==    at 0x2DFB01: mpegaudiodec_common_init_static (in ffmpeg/ffmpeg_g)
==3638361==    by 0x4A114DE: __pthread_once_slow (pthread_once.c:116)
==3638361==    by 0x2DFBB1: ff_mpegaudiodec_common_init_static (in ffmpeg/ffmpeg_g)
==3638361==    by 0x4A114DE: __pthread_once_slow (pthread_once.c:116)
==3638361==    by 0x2A6FFD: decode_init (in ffmpeg/ffmpeg_g)
==3638361==    by 0x7E4BF1: avcodec_open2 (in ffmpeg/ffmpeg_g)
==3638361==    by 0x62C444: try_decode_frame (in ffmpeg/ffmpeg_g)
==3638361==    by 0x631575: avformat_find_stream_info (in ffmpeg/ffmpeg_g)
==3638361==    by 0x306596: ifile_open (in ffmpeg/ffmpeg_g)
==3638361==    by 0x31CA17: open_files.isra.0 (in ffmpeg/ffmpeg_g)
==3638361==    by 0x31E9F5: ffmpeg_parse_options (in ffmpeg/ffmpeg_g)
==3638361==    by 0x2FD297: main (in ffmpeg/ffmpeg_g)
==3638361==  Address 0x4 is not stack'd, malloc'd or (recently) free'd

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

For a strong democracy, genuine criticism is necessary, allegations benefit
noone, they just cause unnecessary conflicts. - Narendra Modi

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

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

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-21  7:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-19 12:15 [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce code size chenyu202107
2025-05-19 12:15 ` [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing " chenyu202107
2025-05-21  0:46   ` Michael Niedermayer
2025-05-21  7:40     ` Michael Niedermayer
2025-05-19 13:03 ` [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce " Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git