Originally committed as revision 22761 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -7,32 +7,39 @@ Basic concepts |
| 7 | 7 |
|
| 8 | 8 |
A table generator consists of two files, *_tablegen.c and *_tablegen.h. |
| 9 | 9 |
The .h file will provide the variable declarations and initialization |
| 10 |
-code for the tables, the .c describes the tables so they can be printed |
|
| 11 |
-as a header file. |
|
| 10 |
+code for the tables, the .c calls the initialization code and then prints |
|
| 11 |
+the tables as a header file using the tableprint.h helpers. |
|
| 12 | 12 |
Both of these files will be compiled for the host system, so to avoid |
| 13 | 13 |
breakage with cross-compilation neither of them may include, directly |
| 14 | 14 |
or indirectly, config.h or avconfig.h. |
| 15 | 15 |
Due to this, the .c file or Makefile may have to provide additional defines |
| 16 | 16 |
or stubs, though if possible this should be avoided. |
| 17 |
+In particular, CONFIG_HARDCODED_TABLES should always be defined to 0. |
|
| 17 | 18 |
|
| 18 | 19 |
The .c file |
| 19 | 20 |
|
| 20 | 21 |
This file should include the *_tablegen.h and tableprint.h files and |
| 21 | 22 |
anything else it needs as long as it does not depend on config.h or |
| 22 | 23 |
avconfig.h. |
| 23 |
-In addition to that it must contain a void tableinit(void) function |
|
| 24 |
-which initializes all tables by calling the init functions from the .h |
|
| 25 |
-file. |
|
| 26 |
-It must also contain a "const struct tabledef tables[]" array describing |
|
| 27 |
-the tables to be generated. |
|
| 28 |
-Its entries consist of (in order): |
|
| 29 |
- - a string suitable for declaring the table, up to but not including the = |
|
| 30 |
- NULL terminates the table |
|
| 31 |
- - a function to print the table - tableprint.h defines some defaults, |
|
| 32 |
- e.g. write_uint8_array to print a uint8_t array. |
|
| 33 |
- - a pointer to the table |
|
| 34 |
- - the size of the first dimension of the array |
|
| 35 |
- - if applicable, the size of the second dimension of the array |
|
| 24 |
+In addition to that it must contain a main() function which initializes |
|
| 25 |
+all tables by calling the init functions from the .h file and then prints |
|
| 26 |
+them. |
|
| 27 |
+The printing code typically looks like this: |
|
| 28 |
+ write_fileheader(); |
|
| 29 |
+ printf("static const uint8_t my_array[100] = {\n");
|
|
| 30 |
+ write_uint8_array(my_array, 100); |
|
| 31 |
+ printf("};\n");
|
|
| 32 |
+ |
|
| 33 |
+write_fileheader() adds some minor things like a "this is a generated file" |
|
| 34 |
+comment and some standard includes. |
|
| 35 |
+tablegen.h defines some write functions for one- and two-dimensional arrays |
|
| 36 |
+for standard types - they print only the "core" parts so they are easier |
|
| 37 |
+to reuse for multi-dimensional arrays so the outermost {} must be printed
|
|
| 38 |
+separately. |
|
| 39 |
+If there's no standard function for printing the type you need, the |
|
| 40 |
+WRITE_1D_FUNC_ARGV macro is a very quick way to create one. |
|
| 41 |
+See libavcodec/dv_tablegen.c for an example. |
|
| 42 |
+ |
|
| 36 | 43 |
|
| 37 | 44 |
The .h file |
| 38 | 45 |
|
| ... | ... |
@@ -25,18 +25,15 @@ |
| 25 | 25 |
#include "cbrt_tablegen.h" |
| 26 | 26 |
#include "tableprint.h" |
| 27 | 27 |
|
| 28 |
-void tableinit(void) |
|
| 28 |
+int main(void) |
|
| 29 | 29 |
{
|
| 30 | 30 |
cbrt_tableinit(); |
| 31 |
-} |
|
| 32 | 31 |
|
| 33 |
-const struct tabledef tables[] = {
|
|
| 34 |
- {
|
|
| 35 |
- "static const uint32_t cbrt_tab[1<<13]", |
|
| 36 |
- write_uint32_array, |
|
| 37 |
- cbrt_tab, |
|
| 38 |
- 1 << 13, |
|
| 39 |
- 0 |
|
| 40 |
- }, |
|
| 41 |
- { NULL }
|
|
| 42 |
-}; |
|
| 32 |
+ write_fileheader(); |
|
| 33 |
+ |
|
| 34 |
+ printf("static const uint32_t cbrt_tab[1<<13] = {\n");
|
|
| 35 |
+ write_uint32_array(cbrt_tab, 1 << 13); |
|
| 36 |
+ printf("};\n");
|
|
| 37 |
+ |
|
| 38 |
+ return 0; |
|
| 39 |
+} |
| ... | ... |
@@ -33,18 +33,15 @@ WRITE_1D_FUNC_ARGV(vlc_pair, struct dv_vlc_pair, 7, |
| 33 | 33 |
"{0x%"PRIx32", %"PRId8"}", data[i].vlc, data[i].size)
|
| 34 | 34 |
WRITE_2D_FUNC(vlc_pair, struct dv_vlc_pair) |
| 35 | 35 |
|
| 36 |
-void tableinit(void) |
|
| 36 |
+int main(void) |
|
| 37 | 37 |
{
|
| 38 | 38 |
dv_vlc_map_tableinit(); |
| 39 |
-} |
|
| 40 | 39 |
|
| 41 |
-const struct tabledef tables[] = {
|
|
| 42 |
- {
|
|
| 43 |
- "static const struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]", |
|
| 44 |
- write_vlc_pair_2d_array, |
|
| 45 |
- dv_vlc_map, |
|
| 46 |
- DV_VLC_MAP_RUN_SIZE, |
|
| 47 |
- DV_VLC_MAP_LEV_SIZE |
|
| 48 |
- }, |
|
| 49 |
- { NULL }
|
|
| 50 |
-}; |
|
| 40 |
+ write_fileheader(); |
|
| 41 |
+ |
|
| 42 |
+ printf("static const struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE] = {\n");
|
|
| 43 |
+ write_vlc_pair_2d_array(dv_vlc_map, DV_VLC_MAP_RUN_SIZE, DV_VLC_MAP_LEV_SIZE); |
|
| 44 |
+ printf("};\n");
|
|
| 45 |
+ |
|
| 46 |
+ return 0; |
|
| 47 |
+} |
| ... | ... |
@@ -32,29 +32,18 @@ |
| 32 | 32 |
#include "mdct_tablegen.h" |
| 33 | 33 |
#include "tableprint.h" |
| 34 | 34 |
|
| 35 |
-void tableinit(void) |
|
| 35 |
+int main(void) |
|
| 36 | 36 |
{
|
| 37 | 37 |
int i; |
| 38 |
- for (i = 5; i <= 12; i++) |
|
| 39 |
- ff_init_ff_sine_windows(i); |
|
| 40 |
-} |
|
| 41 | 38 |
|
| 42 |
-#define SINE_TABLE_DEF(size) \ |
|
| 43 |
- { \
|
|
| 44 |
- "SINETABLE("#size")", \
|
|
| 45 |
- write_float_array, \ |
|
| 46 |
- ff_sine_##size, \ |
|
| 47 |
- size \ |
|
| 48 |
- }, |
|
| 39 |
+ write_fileheader(); |
|
| 49 | 40 |
|
| 50 |
-const struct tabledef tables[] = {
|
|
| 51 |
- SINE_TABLE_DEF( 32) |
|
| 52 |
- SINE_TABLE_DEF( 64) |
|
| 53 |
- SINE_TABLE_DEF( 128) |
|
| 54 |
- SINE_TABLE_DEF( 256) |
|
| 55 |
- SINE_TABLE_DEF( 512) |
|
| 56 |
- SINE_TABLE_DEF(1024) |
|
| 57 |
- SINE_TABLE_DEF(2048) |
|
| 58 |
- SINE_TABLE_DEF(4096) |
|
| 59 |
- { NULL }
|
|
| 60 |
-}; |
|
| 41 |
+ for (i = 5; i <= 12; i++) {
|
|
| 42 |
+ ff_init_ff_sine_windows(i); |
|
| 43 |
+ printf("SINETABLE(%4i) = {\n", 1 << i);
|
|
| 44 |
+ write_float_array(ff_sine_windows[i], 1 << i); |
|
| 45 |
+ printf("};\n");
|
|
| 46 |
+ } |
|
| 47 |
+ |
|
| 48 |
+ return 0; |
|
| 49 |
+} |
| ... | ... |
@@ -27,18 +27,15 @@ |
| 27 | 27 |
#include "motionpixels_tablegen.h" |
| 28 | 28 |
#include "tableprint.h" |
| 29 | 29 |
|
| 30 |
-void tableinit(void) |
|
| 30 |
+int main(void) |
|
| 31 | 31 |
{
|
| 32 | 32 |
motionpixels_tableinit(); |
| 33 |
-} |
|
| 34 | 33 |
|
| 35 |
-const struct tabledef tables[] = {
|
|
| 36 |
- {
|
|
| 37 |
- "static const YuvPixel mp_rgb_yuv_table[1 << 15]", |
|
| 38 |
- write_int8_2d_array, |
|
| 39 |
- mp_rgb_yuv_table, |
|
| 40 |
- 1 << 15, |
|
| 41 |
- 3 |
|
| 42 |
- }, |
|
| 43 |
- { NULL }
|
|
| 44 |
-}; |
|
| 34 |
+ write_fileheader(); |
|
| 35 |
+ |
|
| 36 |
+ printf("static const YuvPixel mp_rgb_yuv_table[1 << 15] = {\n");
|
|
| 37 |
+ write_int8_2d_array(mp_rgb_yuv_table, 1 << 15, 3); |
|
| 38 |
+ printf("};\n");
|
|
| 39 |
+ |
|
| 40 |
+ return 0; |
|
| 41 |
+} |
| ... | ... |
@@ -25,36 +25,27 @@ |
| 25 | 25 |
#include "mpegaudio_tablegen.h" |
| 26 | 26 |
#include "tableprint.h" |
| 27 | 27 |
|
| 28 |
-void tableinit(void) |
|
| 28 |
+int main(void) |
|
| 29 | 29 |
{
|
| 30 | 30 |
mpegaudio_tableinit(); |
| 31 |
-} |
|
| 32 | 31 |
|
| 33 |
-const struct tabledef tables[] = {
|
|
| 34 |
- {
|
|
| 35 |
- "static const int8_t table_4_3_exp[TABLE_4_3_SIZE]", |
|
| 36 |
- write_int8_array, |
|
| 37 |
- table_4_3_exp, |
|
| 38 |
- TABLE_4_3_SIZE |
|
| 39 |
- }, |
|
| 40 |
- {
|
|
| 41 |
- "static const uint32_t table_4_3_value[TABLE_4_3_SIZE]", |
|
| 42 |
- write_uint32_array, |
|
| 43 |
- table_4_3_value, |
|
| 44 |
- TABLE_4_3_SIZE |
|
| 45 |
- }, |
|
| 46 |
- {
|
|
| 47 |
- "static const uint32_t exp_table[512]", |
|
| 48 |
- write_uint32_array, |
|
| 49 |
- exp_table, |
|
| 50 |
- 512 |
|
| 51 |
- }, |
|
| 52 |
- {
|
|
| 53 |
- "static const uint32_t expval_table[512][16]", |
|
| 54 |
- write_uint32_2d_array, |
|
| 55 |
- expval_table, |
|
| 56 |
- 512, |
|
| 57 |
- 16 |
|
| 58 |
- }, |
|
| 59 |
- { NULL }
|
|
| 60 |
-}; |
|
| 32 |
+ write_fileheader(); |
|
| 33 |
+ |
|
| 34 |
+ printf("static const int8_t table_4_3_exp[TABLE_4_3_SIZE] = {\n");
|
|
| 35 |
+ write_int8_array(table_4_3_exp, TABLE_4_3_SIZE); |
|
| 36 |
+ printf("};\n");
|
|
| 37 |
+ |
|
| 38 |
+ printf("static const uint32_t table_4_3_value[TABLE_4_3_SIZE] = {\n");
|
|
| 39 |
+ write_uint32_array(table_4_3_value, TABLE_4_3_SIZE); |
|
| 40 |
+ printf("};\n");
|
|
| 41 |
+ |
|
| 42 |
+ printf("static const uint32_t exp_table[512] = {\n");
|
|
| 43 |
+ write_uint32_array(exp_table, 512); |
|
| 44 |
+ printf("};\n");
|
|
| 45 |
+ |
|
| 46 |
+ printf("static const uint32_t expval_table[512][16] = {\n");
|
|
| 47 |
+ write_uint32_2d_array(expval_table, 512, 16); |
|
| 48 |
+ printf("};\n");
|
|
| 49 |
+ |
|
| 50 |
+ return 0; |
|
| 51 |
+} |
| ... | ... |
@@ -25,48 +25,33 @@ |
| 25 | 25 |
#include "qdm2_tablegen.h" |
| 26 | 26 |
#include "tableprint.h" |
| 27 | 27 |
|
| 28 |
-void tableinit(void) |
|
| 28 |
+int main(void) |
|
| 29 | 29 |
{
|
| 30 | 30 |
softclip_table_init(); |
| 31 | 31 |
rnd_table_init(); |
| 32 | 32 |
init_noise_samples(); |
| 33 |
-} |
|
| 34 | 33 |
|
| 35 |
-const struct tabledef tables[] = {
|
|
| 36 |
- {
|
|
| 37 |
- "static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]", |
|
| 38 |
- write_uint16_array, |
|
| 39 |
- softclip_table, |
|
| 40 |
- HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1, |
|
| 41 |
- 0 |
|
| 42 |
- }, |
|
| 43 |
- {
|
|
| 44 |
- "static const float noise_table[4096]", |
|
| 45 |
- write_float_array, |
|
| 46 |
- noise_table, |
|
| 47 |
- 4096, |
|
| 48 |
- 0 |
|
| 49 |
- }, |
|
| 50 |
- {
|
|
| 51 |
- "static const uint8_t random_dequant_index[256][5]", |
|
| 52 |
- write_uint8_2d_array, |
|
| 53 |
- random_dequant_index, |
|
| 54 |
- 256, |
|
| 55 |
- 5 |
|
| 56 |
- }, |
|
| 57 |
- {
|
|
| 58 |
- "static const uint8_t random_dequant_type24[128][3]", |
|
| 59 |
- write_uint8_2d_array, |
|
| 60 |
- random_dequant_type24, |
|
| 61 |
- 128, |
|
| 62 |
- 3 |
|
| 63 |
- }, |
|
| 64 |
- {
|
|
| 65 |
- "static const float noise_samples[128]", |
|
| 66 |
- write_float_array, |
|
| 67 |
- noise_samples, |
|
| 68 |
- 128, |
|
| 69 |
- 0 |
|
| 70 |
- }, |
|
| 71 |
- { NULL }
|
|
| 72 |
-}; |
|
| 34 |
+ write_fileheader(); |
|
| 35 |
+ |
|
| 36 |
+ printf("static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1] = {\n");
|
|
| 37 |
+ write_uint16_array(softclip_table, HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1); |
|
| 38 |
+ printf("};\n");
|
|
| 39 |
+ |
|
| 40 |
+ printf("static const float noise_table[4096] = {\n");
|
|
| 41 |
+ write_float_array(noise_table, 4096); |
|
| 42 |
+ printf("};\n");
|
|
| 43 |
+ |
|
| 44 |
+ printf("static const uint8_t random_dequant_index[256][5] = {\n");
|
|
| 45 |
+ write_uint8_2d_array(random_dequant_index, 256, 5); |
|
| 46 |
+ printf("};\n");
|
|
| 47 |
+ |
|
| 48 |
+ printf("static const uint8_t random_dequant_type24[128][3] = {\n");
|
|
| 49 |
+ write_uint8_2d_array(random_dequant_type24, 128, 3); |
|
| 50 |
+ printf("};\n");
|
|
| 51 |
+ |
|
| 52 |
+ printf("static const float noise_samples[128] = {\n");
|
|
| 53 |
+ write_float_array(noise_samples, 128); |
|
| 54 |
+ printf("};\n");
|
|
| 55 |
+ |
|
| 56 |
+ return 0; |
|
| 57 |
+} |
| ... | ... |
@@ -34,18 +34,7 @@ WRITE_2D_FUNC(int8, int8_t) |
| 34 | 34 |
WRITE_2D_FUNC(uint8, uint8_t) |
| 35 | 35 |
WRITE_2D_FUNC(uint32, uint32_t) |
| 36 | 36 |
|
| 37 |
-int main(int argc, char *argv[]) |
|
| 38 |
-{
|
|
| 39 |
- int i; |
|
| 40 |
- |
|
| 37 |
+void write_fileheader(void) {
|
|
| 41 | 38 |
printf("/* This file was generated by libavcodec/tableprint */\n");
|
| 42 | 39 |
printf("#include <stdint.h>\n");
|
| 43 |
- tableinit(); |
|
| 44 |
- |
|
| 45 |
- for (i = 0; tables[i].declaration; i++) {
|
|
| 46 |
- printf("%s = {\n", tables[i].declaration);
|
|
| 47 |
- tables[i].printfunc(tables[i].data, tables[i].size, tables[i].size2); |
|
| 48 |
- printf("};\n");
|
|
| 49 |
- } |
|
| 50 |
- return 0; |
|
| 51 | 40 |
} |
| ... | ... |
@@ -27,9 +27,8 @@ |
| 27 | 27 |
#include <stdio.h> |
| 28 | 28 |
|
| 29 | 29 |
#define WRITE_1D_FUNC_ARGV(name, type, linebrk, fmtstr, ...)\ |
| 30 |
-void write_##name##_array(const void *arg, int len, int dummy)\ |
|
| 30 |
+void write_##name##_array(const type *data, int len)\ |
|
| 31 | 31 |
{\
|
| 32 |
- const type *data = arg;\ |
|
| 33 | 32 |
int i;\ |
| 34 | 33 |
printf(" ");\
|
| 35 | 34 |
for (i = 0; i < len - 1; i++) {\
|
| ... | ... |
@@ -49,7 +48,7 @@ void write_##name##_2d_array(const void *arg, int len, int len2)\ |
| 49 | 49 |
int i;\ |
| 50 | 50 |
printf(" {\n");\
|
| 51 | 51 |
for (i = 0; i < len; i++) {\
|
| 52 |
- write_##name##_array(data + i * len2, len2, 0);\ |
|
| 52 |
+ write_##name##_array(data + i * len2, len2);\ |
|
| 53 | 53 |
printf(i == len - 1 ? " }\n" : " }, {\n");\
|
| 54 | 54 |
}\ |
| 55 | 55 |
} |
| ... | ... |
@@ -59,34 +58,17 @@ void write_##name##_2d_array(const void *arg, int len, int len2)\ |
| 59 | 59 |
* |
| 60 | 60 |
* \{
|
| 61 | 61 |
*/ |
| 62 |
-void write_int8_array (const void *, int, int); |
|
| 63 |
-void write_uint8_array (const void *, int, int); |
|
| 64 |
-void write_uint16_array (const void *, int, int); |
|
| 65 |
-void write_uint32_array (const void *, int, int); |
|
| 66 |
-void write_float_array (const void *, int, int); |
|
| 62 |
+void write_int8_array (const int8_t *, int); |
|
| 63 |
+void write_uint8_array (const uint8_t *, int); |
|
| 64 |
+void write_uint16_array (const uint16_t *, int); |
|
| 65 |
+void write_uint32_array (const uint32_t *, int); |
|
| 66 |
+void write_float_array (const float *, int); |
|
| 67 | 67 |
void write_int8_2d_array (const void *, int, int); |
| 68 | 68 |
void write_uint8_2d_array (const void *, int, int); |
| 69 | 69 |
void write_uint32_2d_array(const void *, int, int); |
| 70 | 70 |
/** \} */ // end of printfuncs group |
| 71 | 71 |
|
| 72 |
-struct tabledef {
|
|
| 73 |
- /** String that declares the array. Adding " = { ..." after it should
|
|
| 74 |
- * make a valid initializer, adding "extern" before and ";" if possible |
|
| 75 |
- * should make a valid extern declaration. */ |
|
| 76 |
- const char *declaration; |
|
| 77 |
- /** Function used to print the table data (i.e. the part in {}).
|
|
| 78 |
- * Should be one of the predefined write_*_array functions. */ |
|
| 79 |
- void (*printfunc)(const void *, int, int); |
|
| 80 |
- /** Pointer passed to the printfunc, usually a pointer to the start |
|
| 81 |
- * of the array to be printed. */ |
|
| 82 |
- const void *data; |
|
| 83 |
- int size; ///< size of the first dimension of the array |
|
| 84 |
- int size2; ///< size of the second dimension of the array if any |
|
| 85 |
-}; |
|
| 86 |
- |
|
| 87 |
-/** Initializes all the tables described in the tables array */ |
|
| 88 |
-void tableinit(void); |
|
| 89 |
-/** Describes the tables that should be printed */ |
|
| 90 |
-extern const struct tabledef tables[]; |
|
| 72 |
+/** Write a standard file header */ |
|
| 73 |
+void write_fileheader(void); |
|
| 91 | 74 |
|
| 92 | 75 |
#endif /* AVCODEC_TABLEPRINT_H */ |