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] avcodec/cbrt_table: use dynamic buffer instead of static array (PR #20392)
@ 2025-09-02  1:29 yibofang via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: yibofang via ffmpeg-devel @ 2025-09-02  1:29 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: yibofang

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

The cbrt table generator previously used a 128 KiB static buffer in .bss.
Replace it with a temporary av_malloc()/av_free() buffer used only at init.
This saves ~128 KiB permanent bss, which is valuable on resource-constrained
platforms.


>From ae007d38ba0a8979339803e4db41a732de8d9238 Mon Sep 17 00:00:00 2001
From: YiboFang <blueybf777@outlook.com>
Date: Tue, 26 Aug 2025 16:51:58 +0800
Subject: [PATCH] avcodec/cbrt_table: use dynamic buffer instead of static
 array

The cbrt table generator previously used a 128 KiB static buffer in .bss.
Replace it with a temporary av_malloc()/av_free() buffer used only at init.
This saves ~128 KiB permanent bss, which is valuable 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=15446058 (+112 B), data=750736, bss=23364588 (-128 KiB)

overall image size reduced by ~128 KiB.

Signed-off-by: Yibo Fang <fangyibo@xiaomi.com>
Signed-off-by: YiboFang <fangyibo@xiaomi.com>
---
 libavcodec/cbrt_tablegen.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/libavcodec/cbrt_tablegen.h b/libavcodec/cbrt_tablegen.h
index 9af18d8ab5..70eccd8a73 100644
--- a/libavcodec/cbrt_tablegen.h
+++ b/libavcodec/cbrt_tablegen.h
@@ -25,6 +25,8 @@
 
 #include <stdint.h>
 #include <math.h>
+#include "libavutil/log.h"
+#include "libavutil/mem.h"
 #include "libavutil/attributes.h"
 #include "libavutil/intfloat.h"
 #include "libavcodec/aac_defines.h"
@@ -39,11 +41,18 @@ uint32_t AAC_RENAME(ff_cbrt_tab)[1 << 13];
 
 av_cold void AAC_RENAME(ff_cbrt_tableinit)(void)
 {
-    static double cbrt_tab_dbl[1 << 13];
     if (!AAC_RENAME(ff_cbrt_tab)[(1<<13) - 1]) {
+        double *cbrt_tab_dbl;
         int i, j, k;
         double cbrt_val;
 
+        cbrt_tab_dbl = av_malloc((1 << 13) * sizeof(double));
+        if (!cbrt_tab_dbl) {
+            av_log(NULL, AV_LOG_ERROR, "cbrt_tableinit malloc failed %zu\n",
+                   (1 << 13) * sizeof(double));
+            return;
+        }
+
         for (i = 1; i < 1<<13; i++)
             cbrt_tab_dbl[i] = 1;
 
@@ -67,6 +76,8 @@ av_cold void AAC_RENAME(ff_cbrt_tableinit)(void)
 
         for (i = 0; i < 1<<13; i++)
             AAC_RENAME(ff_cbrt_tab)[i] = CBRT(cbrt_tab_dbl[i]);
+
+        av_free(cbrt_tab_dbl);
     }
 }
 
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-09-02  1:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-02  1:29 [FFmpeg-devel] [PATCH] avcodec/cbrt_table: use dynamic buffer instead of static array (PR #20392) yibofang via ffmpeg-devel

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