The branch, master has been updated
       via  ae448e00afb43d7f72dfa9c82a4c45994e4fea6a (commit)
      from  f317b6c052f1108fcf2ce07b28efa2484c21cabe (commit)


- Log -----------------------------------------------------------------
commit ae448e00afb43d7f72dfa9c82a4c45994e4fea6a
Author:     YiboFang <blueybf...@outlook.com>
AuthorDate: Tue Aug 26 15:54:33 2025 +0800
Commit:     Zhao Zhili <quinkbl...@foxmail.com>
CommitDate: Sun Aug 31 21:40:29 2025 +0800

    avcodec/pcm: use compile-time guards for PCM table init
    
    Change the PCM table init to use compile-time #if instead of a runtime
    `if (CONFIG_...)`. This makes sure code for disabled encoders never gets
    built, without depending on compiler dead-code elimination.
    
    Signed-off-by: YiboFang <fangy...@xiaomi.com>
    Signed-off-by: Zhao Zhili <zhiliz...@tencent.com>

diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 68b1945194..7132eeb8de 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -43,16 +43,27 @@ static av_cold int pcm_encode_init(AVCodecContext *avctx)
     avctx->frame_size = 0;
 #if !CONFIG_HARDCODED_TABLES
     switch (avctx->codec->id) {
-#define INIT_ONCE(id, name)                                                 \
-    case AV_CODEC_ID_PCM_ ## id:                                            \
-        if (CONFIG_PCM_ ## id ## _ENCODER) {                                \
-            static AVOnce init_static_once = AV_ONCE_INIT;                  \
-            ff_thread_once(&init_static_once, pcm_ ## name ## _tableinit);  \
-        }                                                                   \
-        break
-        INIT_ONCE(ALAW,  alaw);
-        INIT_ONCE(MULAW, ulaw);
-        INIT_ONCE(VIDC,  vidc);
+#if CONFIG_PCM_ALAW_ENCODER
+    case AV_CODEC_ID_PCM_ALAW: {
+        static AVOnce once_alaw = AV_ONCE_INIT;
+        ff_thread_once(&once_alaw, pcm_alaw_tableinit);
+        break;
+    }
+#endif
+#if CONFIG_PCM_MULAW_ENCODER
+    case AV_CODEC_ID_PCM_MULAW: {
+        static AVOnce once_mulaw = AV_ONCE_INIT;
+        ff_thread_once(&once_mulaw, pcm_ulaw_tableinit);
+        break;
+    }
+#endif
+#if CONFIG_PCM_VIDC_ENCODER
+    case AV_CODEC_ID_PCM_VIDC: {
+        static AVOnce once_vidc = AV_ONCE_INIT;
+        ff_thread_once(&once_vidc, pcm_vidc_tableinit);
+        break;
+    }
+#endif
     default:
         break;
     }
@@ -216,24 +227,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;
     }
@@ -329,18 +346,24 @@ static av_cold av_unused int 
pcm_lut_decode_init(AVCodecContext *avctx)
     switch (avctx->codec_id) {
     default:
         av_unreachable("pcm_lut_decode_init() only used with alaw, mulaw and 
vidc");
+#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;
@@ -547,6 +570,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: {
@@ -557,6 +583,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
             *samples_16++ = lut[*src++];
         break;
     }
+#endif
     case AV_CODEC_ID_PCM_LXF:
     {
         int i;
@@ -657,7 +684,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");
@@ -665,7 +694,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");
@@ -688,5 +719,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 */

-----------------------------------------------------------------------

Summary of changes:
 libavcodec/pcm.c          | 53 ++++++++++++++++++++++++++++++++++++++---------
 libavcodec/pcm_tablegen.h | 22 ++++++++++++++++++++
 2 files changed, 65 insertions(+), 10 deletions(-)


hooks/post-receive
-- 

_______________________________________________
ffmpeg-cvslog mailing list -- ffmpeg-cvslog@ffmpeg.org
To unsubscribe send an email to ffmpeg-cvslog-le...@ffmpeg.org

Reply via email to