Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: yibofang via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: yibofang <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/mpegaudiodec: allocate tables dynamically to reduce .bss (PR #20393)
Message-ID: <175677659859.25.15869937322765000068@463a07221176> (raw)

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 <blueybf777@outlook.com>
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 <fangyibo@xiaomi.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..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 -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-09-02  1:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=175677659859.25.15869937322765000068@463a07221176 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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