* [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing code size
@ 2025-05-19 11:41 chenyu202107
2025-05-19 11:54 ` Andreas Rheinhardt
0 siblings, 1 reply; 5+ messages in thread
From: chenyu202107 @ 2025-05-19 11:41 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] [ffmpeg-deve] avcodec/mpegaudiodec optimizing code size
2025-05-19 11:41 [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing code size chenyu202107
@ 2025-05-19 11:54 ` Andreas Rheinhardt
0 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2025-05-19 11:54 UTC (permalink / raw)
To: ffmpeg-devel
chenyu202107@gmail.com:
> 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;
This does not improve "code size" at all; after all you are actually
adding code (and an indirection) with your allocation. If one interprets
"code size" as "size of the binary" (instead of just .text), then this
patch still doesn't make sense, because the tables are currently in .bss
which does not increase the size of the binaries (that's at least the
case for common systems, is it different for you?).
And of course you are missing the error check (in fact, you have no way
to return an error from init functions like this).
- Andreas
_______________________________________________
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
* 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
* [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 " chenyu202107
@ 2025-05-19 12:15 ` chenyu202107
2025-05-21 0:46 ` Michael Niedermayer
0 siblings, 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
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 11:41 [FFmpeg-devel] [PATCH 1/1] [ffmpeg-deve] avcodec/mpegaudiodec optimizing code size chenyu202107
2025-05-19 11:54 ` Andreas Rheinhardt
2025-05-19 12:15 [FFmpeg-devel] [PATCH 1/1] avcodec/pcm: reduce " 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
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