summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2010-04-01 17:11:47 +0000
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2010-04-01 17:11:47 +0000
commit8eaa6e0e04c3c340d7c44a97613ebc6dbcc0a51d (patch)
tree6b40a6af3963c4f53e90e1e9a6dbbd05eb98ca3e
parent27eecec3598b0c35b7aeb10c08f2c5e42b1fdd4f (diff)
Change/simplify the tableprint/tablegen API.
Originally committed as revision 22761 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--doc/tablegen.txt37
-rw-r--r--libavcodec/cbrt_tablegen.c21
-rw-r--r--libavcodec/dv_tablegen.c21
-rw-r--r--libavcodec/mdct_tablegen.c33
-rw-r--r--libavcodec/motionpixels_tablegen.c21
-rw-r--r--libavcodec/mpegaudio_tablegen.c51
-rw-r--r--libavcodec/qdm2_tablegen.c65
-rw-r--r--libavcodec/tableprint.c13
-rw-r--r--libavcodec/tableprint.h36
9 files changed, 116 insertions, 182 deletions
diff --git a/doc/tablegen.txt b/doc/tablegen.txt
index 203f4477b9..8dfcd7d354 100644
--- a/doc/tablegen.txt
+++ b/doc/tablegen.txt
@@ -7,32 +7,39 @@ Basic concepts
A table generator consists of two files, *_tablegen.c and *_tablegen.h.
The .h file will provide the variable declarations and initialization
-code for the tables, the .c describes the tables so they can be printed
-as a header file.
+code for the tables, the .c calls the initialization code and then prints
+the tables as a header file using the tableprint.h helpers.
Both of these files will be compiled for the host system, so to avoid
breakage with cross-compilation neither of them may include, directly
or indirectly, config.h or avconfig.h.
Due to this, the .c file or Makefile may have to provide additional defines
or stubs, though if possible this should be avoided.
+In particular, CONFIG_HARDCODED_TABLES should always be defined to 0.
The .c file
This file should include the *_tablegen.h and tableprint.h files and
anything else it needs as long as it does not depend on config.h or
avconfig.h.
-In addition to that it must contain a void tableinit(void) function
-which initializes all tables by calling the init functions from the .h
-file.
-It must also contain a "const struct tabledef tables[]" array describing
-the tables to be generated.
-Its entries consist of (in order):
- - a string suitable for declaring the table, up to but not including the =
- NULL terminates the table
- - a function to print the table - tableprint.h defines some defaults,
- e.g. write_uint8_array to print a uint8_t array.
- - a pointer to the table
- - the size of the first dimension of the array
- - if applicable, the size of the second dimension of the array
+In addition to that it must contain a main() function which initializes
+all tables by calling the init functions from the .h file and then prints
+them.
+The printing code typically looks like this:
+ write_fileheader();
+ printf("static const uint8_t my_array[100] = {\n");
+ write_uint8_array(my_array, 100);
+ printf("};\n");
+
+write_fileheader() adds some minor things like a "this is a generated file"
+comment and some standard includes.
+tablegen.h defines some write functions for one- and two-dimensional arrays
+for standard types - they print only the "core" parts so they are easier
+to reuse for multi-dimensional arrays so the outermost {} must be printed
+separately.
+If there's no standard function for printing the type you need, the
+WRITE_1D_FUNC_ARGV macro is a very quick way to create one.
+See libavcodec/dv_tablegen.c for an example.
+
The .h file
diff --git a/libavcodec/cbrt_tablegen.c b/libavcodec/cbrt_tablegen.c
index 9a0ffcfa1a..dbbd632693 100644
--- a/libavcodec/cbrt_tablegen.c
+++ b/libavcodec/cbrt_tablegen.c
@@ -25,18 +25,15 @@
#include "cbrt_tablegen.h"
#include "tableprint.h"
-void tableinit(void)
+int main(void)
{
cbrt_tableinit();
-}
-const struct tabledef tables[] = {
- {
- "static const uint32_t cbrt_tab[1<<13]",
- write_uint32_array,
- cbrt_tab,
- 1 << 13,
- 0
- },
- { NULL }
-};
+ write_fileheader();
+
+ printf("static const uint32_t cbrt_tab[1<<13] = {\n");
+ write_uint32_array(cbrt_tab, 1 << 13);
+ printf("};\n");
+
+ return 0;
+}
diff --git a/libavcodec/dv_tablegen.c b/libavcodec/dv_tablegen.c
index 4294132cf2..0e2b39dfb2 100644
--- a/libavcodec/dv_tablegen.c
+++ b/libavcodec/dv_tablegen.c
@@ -33,18 +33,15 @@ WRITE_1D_FUNC_ARGV(vlc_pair, struct dv_vlc_pair, 7,
"{0x%"PRIx32", %"PRId8"}", data[i].vlc, data[i].size)
WRITE_2D_FUNC(vlc_pair, struct dv_vlc_pair)
-void tableinit(void)
+int main(void)
{
dv_vlc_map_tableinit();
-}
-const struct tabledef tables[] = {
- {
- "static const struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]",
- write_vlc_pair_2d_array,
- dv_vlc_map,
- DV_VLC_MAP_RUN_SIZE,
- DV_VLC_MAP_LEV_SIZE
- },
- { NULL }
-};
+ write_fileheader();
+
+ printf("static const struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE] = {\n");
+ write_vlc_pair_2d_array(dv_vlc_map, DV_VLC_MAP_RUN_SIZE, DV_VLC_MAP_LEV_SIZE);
+ printf("};\n");
+
+ return 0;
+}
diff --git a/libavcodec/mdct_tablegen.c b/libavcodec/mdct_tablegen.c
index a6b13c345b..6205f06e3c 100644
--- a/libavcodec/mdct_tablegen.c
+++ b/libavcodec/mdct_tablegen.c
@@ -32,29 +32,18 @@
#include "mdct_tablegen.h"
#include "tableprint.h"
-void tableinit(void)
+int main(void)
{
int i;
- for (i = 5; i <= 12; i++)
- ff_init_ff_sine_windows(i);
-}
-#define SINE_TABLE_DEF(size) \
- { \
- "SINETABLE("#size")", \
- write_float_array, \
- ff_sine_##size, \
- size \
- },
+ write_fileheader();
-const struct tabledef tables[] = {
- SINE_TABLE_DEF( 32)
- SINE_TABLE_DEF( 64)
- SINE_TABLE_DEF( 128)
- SINE_TABLE_DEF( 256)
- SINE_TABLE_DEF( 512)
- SINE_TABLE_DEF(1024)
- SINE_TABLE_DEF(2048)
- SINE_TABLE_DEF(4096)
- { NULL }
-};
+ for (i = 5; i <= 12; i++) {
+ ff_init_ff_sine_windows(i);
+ printf("SINETABLE(%4i) = {\n", 1 << i);
+ write_float_array(ff_sine_windows[i], 1 << i);
+ printf("};\n");
+ }
+
+ return 0;
+}
diff --git a/libavcodec/motionpixels_tablegen.c b/libavcodec/motionpixels_tablegen.c
index 188384b5a3..5f1220aff5 100644
--- a/libavcodec/motionpixels_tablegen.c
+++ b/libavcodec/motionpixels_tablegen.c
@@ -27,18 +27,15 @@
#include "motionpixels_tablegen.h"
#include "tableprint.h"
-void tableinit(void)
+int main(void)
{
motionpixels_tableinit();
-}
-const struct tabledef tables[] = {
- {
- "static const YuvPixel mp_rgb_yuv_table[1 << 15]",
- write_int8_2d_array,
- mp_rgb_yuv_table,
- 1 << 15,
- 3
- },
- { NULL }
-};
+ write_fileheader();
+
+ printf("static const YuvPixel mp_rgb_yuv_table[1 << 15] = {\n");
+ write_int8_2d_array(mp_rgb_yuv_table, 1 << 15, 3);
+ printf("};\n");
+
+ return 0;
+}
diff --git a/libavcodec/mpegaudio_tablegen.c b/libavcodec/mpegaudio_tablegen.c
index 9f832a3b0e..70d145b205 100644
--- a/libavcodec/mpegaudio_tablegen.c
+++ b/libavcodec/mpegaudio_tablegen.c
@@ -25,36 +25,27 @@
#include "mpegaudio_tablegen.h"
#include "tableprint.h"
-void tableinit(void)
+int main(void)
{
mpegaudio_tableinit();
-}
-const struct tabledef tables[] = {
- {
- "static const int8_t table_4_3_exp[TABLE_4_3_SIZE]",
- write_int8_array,
- table_4_3_exp,
- TABLE_4_3_SIZE
- },
- {
- "static const uint32_t table_4_3_value[TABLE_4_3_SIZE]",
- write_uint32_array,
- table_4_3_value,
- TABLE_4_3_SIZE
- },
- {
- "static const uint32_t exp_table[512]",
- write_uint32_array,
- exp_table,
- 512
- },
- {
- "static const uint32_t expval_table[512][16]",
- write_uint32_2d_array,
- expval_table,
- 512,
- 16
- },
- { NULL }
-};
+ write_fileheader();
+
+ printf("static const int8_t table_4_3_exp[TABLE_4_3_SIZE] = {\n");
+ write_int8_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_array(table_4_3_value, TABLE_4_3_SIZE);
+ printf("};\n");
+
+ printf("static const uint32_t exp_table[512] = {\n");
+ write_uint32_array(exp_table, 512);
+ printf("};\n");
+
+ printf("static const uint32_t expval_table[512][16] = {\n");
+ write_uint32_2d_array(expval_table, 512, 16);
+ printf("};\n");
+
+ return 0;
+}
diff --git a/libavcodec/qdm2_tablegen.c b/libavcodec/qdm2_tablegen.c
index d23493c741..c225bc4391 100644
--- a/libavcodec/qdm2_tablegen.c
+++ b/libavcodec/qdm2_tablegen.c
@@ -25,48 +25,33 @@
#include "qdm2_tablegen.h"
#include "tableprint.h"
-void tableinit(void)
+int main(void)
{
softclip_table_init();
rnd_table_init();
init_noise_samples();
-}
-const struct tabledef tables[] = {
- {
- "static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]",
- write_uint16_array,
- softclip_table,
- HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1,
- 0
- },
- {
- "static const float noise_table[4096]",
- write_float_array,
- noise_table,
- 4096,
- 0
- },
- {
- "static const uint8_t random_dequant_index[256][5]",
- write_uint8_2d_array,
- random_dequant_index,
- 256,
- 5
- },
- {
- "static const uint8_t random_dequant_type24[128][3]",
- write_uint8_2d_array,
- random_dequant_type24,
- 128,
- 3
- },
- {
- "static const float noise_samples[128]",
- write_float_array,
- noise_samples,
- 128,
- 0
- },
- { NULL }
-};
+ write_fileheader();
+
+ printf("static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1] = {\n");
+ write_uint16_array(softclip_table, HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1);
+ printf("};\n");
+
+ 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_2d_array(random_dequant_index, 256, 5);
+ printf("};\n");
+
+ printf("static const uint8_t random_dequant_type24[128][3] = {\n");
+ write_uint8_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");
+
+ return 0;
+}
diff --git a/libavcodec/tableprint.c b/libavcodec/tableprint.c
index 2d8cc419e4..e39606bb15 100644
--- a/libavcodec/tableprint.c
+++ b/libavcodec/tableprint.c
@@ -34,18 +34,7 @@ WRITE_2D_FUNC(int8, int8_t)
WRITE_2D_FUNC(uint8, uint8_t)
WRITE_2D_FUNC(uint32, uint32_t)
-int main(int argc, char *argv[])
-{
- int i;
-
+void write_fileheader(void) {
printf("/* This file was generated by libavcodec/tableprint */\n");
printf("#include <stdint.h>\n");
- tableinit();
-
- for (i = 0; tables[i].declaration; i++) {
- printf("%s = {\n", tables[i].declaration);
- tables[i].printfunc(tables[i].data, tables[i].size, tables[i].size2);
- printf("};\n");
- }
- return 0;
}
diff --git a/libavcodec/tableprint.h b/libavcodec/tableprint.h
index e91ba1ec32..d81af97e95 100644
--- a/libavcodec/tableprint.h
+++ b/libavcodec/tableprint.h
@@ -27,9 +27,8 @@
#include <stdio.h>
#define WRITE_1D_FUNC_ARGV(name, type, linebrk, fmtstr, ...)\
-void write_##name##_array(const void *arg, int len, int dummy)\
+void write_##name##_array(const type *data, int len)\
{\
- const type *data = arg;\
int i;\
printf(" ");\
for (i = 0; i < len - 1; i++) {\
@@ -49,7 +48,7 @@ void write_##name##_2d_array(const void *arg, int len, int len2)\
int i;\
printf(" {\n");\
for (i = 0; i < len; i++) {\
- write_##name##_array(data + i * len2, len2, 0);\
+ write_##name##_array(data + i * len2, len2);\
printf(i == len - 1 ? " }\n" : " }, {\n");\
}\
}
@@ -59,34 +58,17 @@ void write_##name##_2d_array(const void *arg, int len, int len2)\
*
* \{
*/
-void write_int8_array (const void *, int, int);
-void write_uint8_array (const void *, int, int);
-void write_uint16_array (const void *, int, int);
-void write_uint32_array (const void *, int, int);
-void write_float_array (const void *, int, int);
+void write_int8_array (const int8_t *, int);
+void write_uint8_array (const uint8_t *, int);
+void write_uint16_array (const uint16_t *, int);
+void write_uint32_array (const uint32_t *, int);
+void write_float_array (const float *, int);
void write_int8_2d_array (const void *, int, int);
void write_uint8_2d_array (const void *, int, int);
void write_uint32_2d_array(const void *, int, int);
/** \} */ // end of printfuncs group
-struct tabledef {
- /** String that declares the array. Adding " = { ..." after it should
- * make a valid initializer, adding "extern" before and ";" if possible
- * should make a valid extern declaration. */
- const char *declaration;
- /** Function used to print the table data (i.e. the part in {}).
- * Should be one of the predefined write_*_array functions. */
- void (*printfunc)(const void *, int, int);
- /** Pointer passed to the printfunc, usually a pointer to the start
- * of the array to be printed. */
- const void *data;
- int size; ///< size of the first dimension of the array
- int size2; ///< size of the second dimension of the array if any
-};
-
-/** Initializes all the tables described in the tables array */
-void tableinit(void);
-/** Describes the tables that should be printed */
-extern const struct tabledef tables[];
+/** Write a standard file header */
+void write_fileheader(void);
#endif /* AVCODEC_TABLEPRINT_H */