[FFmpeg-devel] [PATCH] tablegen: implement and use WRITE_ARRAY macros

Diego Elio 'Flameeyes' Pettenò flameeyes
Sun Jun 27 12:20:17 CEST 2010


Two macros (WRITE_ARRAY and WRITE_ARRAY_2D) take the prefix (modifiers)
(not all tables are static, and they might not be constant either), the
type, and the name of the array. It'll be copied with same name and type,
and with the correct size of the currently-defined object.
---
 libavcodec/aac_tablegen.c       |    4 +---
 libavcodec/cbrt_tablegen.c      |    4 +---
 libavcodec/mpegaudio_tablegen.c |   29 ++++++-----------------------
 libavcodec/pcm_tablegen.c       |    9 ++-------
 libavcodec/qdm2_tablegen.c      |   23 +++++------------------
 libavcodec/tableprint.h         |   20 ++++++++++++++++++++
 6 files changed, 35 insertions(+), 54 deletions(-)

diff --git a/libavcodec/aac_tablegen.c b/libavcodec/aac_tablegen.c
index de1c957..33a179f 100644
--- a/libavcodec/aac_tablegen.c
+++ b/libavcodec/aac_tablegen.c
@@ -31,9 +31,7 @@ int main(void)
 
     write_fileheader();
 
-    printf("const float ff_aac_pow2sf_tab[428] = {\n");
-    write_float_array(ff_aac_pow2sf_tab, 428);
-    printf("};\n");
+    WRITE_ARRAY("const", float, ff_aac_pow2sf_tab);
 
     return 0;
 }
diff --git a/libavcodec/cbrt_tablegen.c b/libavcodec/cbrt_tablegen.c
index 5cbceb2..e0a8e63 100644
--- a/libavcodec/cbrt_tablegen.c
+++ b/libavcodec/cbrt_tablegen.c
@@ -31,9 +31,7 @@ int main(void)
 
     write_fileheader();
 
-    printf("static const uint32_t cbrt_tab[1<<13] = {\n");
-    write_uint32_t_array(cbrt_tab, 1 << 13);
-    printf("};\n");
+    WRITE_ARRAY("static const", uint32_t, cbrt_tab);
 
     return 0;
 }
diff --git a/libavcodec/mpegaudio_tablegen.c b/libavcodec/mpegaudio_tablegen.c
index 57e239c..0888e78 100644
--- a/libavcodec/mpegaudio_tablegen.c
+++ b/libavcodec/mpegaudio_tablegen.c
@@ -31,29 +31,12 @@ int main(void)
 
     write_fileheader();
 
-    printf("static const int8_t table_4_3_exp[TABLE_4_3_SIZE] = {\n");
-    write_int8_t_array(table_4_3_exp, TABLE_4_3_SIZE);
-    printf("};\n");
-
-    printf("static const uint32_t table_4_3_value[TABLE_4_3_SIZE] = {\n");
-    write_uint32_t_array(table_4_3_value, TABLE_4_3_SIZE);
-    printf("};\n");
-
-    printf("static const uint32_t exp_table[512] = {\n");
-    write_uint32_t_array(exp_table, 512);
-    printf("};\n");
-
-    printf("static const float exp_table_float[512] = {\n");
-    write_float_array(exp_table_float, 512);
-    printf("};\n");
-
-    printf("static const uint32_t expval_table[512][16] = {\n");
-    write_uint32_t_2d_array(expval_table, 512, 16);
-    printf("};\n");
-
-    printf("static const float expval_table_float[512][16] = {\n");
-    write_float_2d_array(expval_table_float, 512, 16);
-    printf("};\n");
+    WRITE_ARRAY("static const", int8_t, table_4_3_exp);
+    WRITE_ARRAY("static const", uint32_t, table_4_3_value);
+    WRITE_ARRAY("static const", uint32_t, exp_table);
+    WRITE_ARRAY("static const", float, exp_table_float);
+    WRITE_2D_ARRAY("static const", uint32_t, expval_table);
+    WRITE_2D_ARRAY("static const", float, expval_table_float);
 
     return 0;
 }
diff --git a/libavcodec/pcm_tablegen.c b/libavcodec/pcm_tablegen.c
index 13b33dd..b0fde93 100644
--- a/libavcodec/pcm_tablegen.c
+++ b/libavcodec/pcm_tablegen.c
@@ -32,13 +32,8 @@ int main(void)
 
     write_fileheader();
 
-    printf("static const uint8_t linear_to_alaw[1 << 14] = {\n");
-    write_uint8_t_array(linear_to_alaw, 1 << 14);
-    printf("};\n");
-
-    printf("static const uint8_t linear_to_ulaw[1 << 14] = {\n");
-    write_uint8_t_array(linear_to_ulaw, 1 << 14);
-    printf("};\n");
+    WRITE_ARRAY("static const", uint8_t, linear_to_alaw);
+    WRITE_ARRAY("static const", uint8_t, linear_to_ulaw);
 
     return 0;
 }
diff --git a/libavcodec/qdm2_tablegen.c b/libavcodec/qdm2_tablegen.c
index d11599b..a7a9fb6 100644
--- a/libavcodec/qdm2_tablegen.c
+++ b/libavcodec/qdm2_tablegen.c
@@ -33,25 +33,12 @@ int main(void)
 
     write_fileheader();
 
-    printf("static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1] = {\n");
-    write_uint16_t_array(softclip_table, HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1);
-    printf("};\n");
+    WRITE_ARRAY("static const", uint16_t, softclip_table);
+    WRITE_ARRAY("static const", float, noise_table);
+    WRITE_ARRAY("static const", float, noise_samples);
 
-    printf("static const float noise_table[4096] = {\n");
-    write_float_array(noise_table, 4096);
-    printf("};\n");
-
-    printf("static const uint8_t random_dequant_index[256][5] = {\n");
-    write_uint8_t_2d_array(random_dequant_index, 256, 5);
-    printf("};\n");
-
-    printf("static const uint8_t random_dequant_type24[128][3] = {\n");
-    write_uint8_t_2d_array(random_dequant_type24, 128, 3);
-    printf("};\n");
-
-    printf("static const float noise_samples[128] = {\n");
-    write_float_array(noise_samples, 128);
-    printf("};\n");
+    WRITE_2D_ARRAY("static const", uint8_t, random_dequant_index);
+    WRITE_2D_ARRAY("static const", uint8_t, random_dequant_type24);
 
     return 0;
 }
diff --git a/libavcodec/tableprint.h b/libavcodec/tableprint.h
index 849bccf..7e4b009 100644
--- a/libavcodec/tableprint.h
+++ b/libavcodec/tableprint.h
@@ -25,6 +25,7 @@
 
 #include <stdint.h>
 #include <stdio.h>
+#include "libavutil/common.h"
 
 #define WRITE_1D_FUNC_ARGV(type, linebrk, fmtstr, ...)\
 void write_##type##_array(const type *data, int len)\
@@ -72,4 +73,23 @@ void write_float_2d_array   (const void *, int, int);
 /** Write a standard file header */
 void write_fileheader(void);
 
+#define WRITE_ARRAY(prefix, type, name)				\
+    do {							\
+        const size_t array_size = FF_ARRAY_ELEMS(name);		\
+        printf(prefix" "#type" "#name"[%zu] = {\n",		\
+               array_size);					\
+        write_##type##_array(name, array_size);			\
+        printf("};\n");						\
+    } while(0)
+
+#define WRITE_2D_ARRAY(prefix, type, name)				\
+    do {								\
+        const size_t array_size1 = FF_ARRAY_ELEMS(name);		\
+        const size_t array_size2 = FF_ARRAY_ELEMS(name[0]);		\
+	printf(prefix" "#type" "#name"[%zu][%zu] = {\n",		\
+               array_size1, array_size2 );				\
+	write_##type##_2d_array(name, array_size1, array_size2);	\
+        printf("};\n");							\
+    } while(0)
+
 #endif /* AVCODEC_TABLEPRINT_H */
-- 
1.7.1




More information about the ffmpeg-devel mailing list