PR #20393 opened by yibofang
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20393
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20393.patch

The tables ff_table_4_3_exp and ff_table_4_3_value were previously
large static arrays (~160 KiB) in .bss. Change them into pointers and
allocate memory via av_calloc() during mpegaudiodec_common_tableinit().

This reduces permanent bss usage by ~160 KiB, which helps on
resource-constrained platforms.


>From 97ff4b44b14546f93b70a80cc77420775e8903a8 Mon Sep 17 00:00:00 2001
From: YiboFang <[email protected]>
Date: Tue, 26 Aug 2025 17:17:28 +0800
Subject: [PATCH] avcodec/mpegaudiodec: allocate tables dynamically to reduce
 .bss

The tables ff_table_4_3_exp and ff_table_4_3_value were previously
large static arrays (~160 KiB) in .bss. Change them into pointers and
allocate memory via av_calloc() during mpegaudiodec_common_tableinit().

This reduces permanent bss usage by ~160 KiB, which helps on
resource-constrained platforms.

Build cmd:
  ./configure --arch=arm --target-os=linux \
              --enable-cross-compile \
              --cross-prefix=arm-linux-gnueabihf- \
              --extra-cflags='-march=armv7-a -mfpu=neon-vfpv3 -mfloat-abi=hard 
-fPIC'

On ARM cross build (armv7-a, NEON):

  before: text=15445946, data=750736, bss=23495660
  after : text=15446072 (+126 B), data=750736, bss=23331516 (-164144 B)

overall image size reduced by ~160 KiB.

Signed-off-by: Yibo Fang <[email protected]>
---
 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..e18c02d716 100644
--- a/libavcodec/mpegaudiodec_common_tablegen.h
+++ b/libavcodec/mpegaudiodec_common_tablegen.h
@@ -33,10 +33,11 @@
 #include "libavcodec/mpegaudiodec_common_tables.h"
 #else
 #include <math.h>
+#include "libavutil/mem.h"
 #include "libavutil/attributes.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.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to