annotate ffmpeg/doc/tablegen.txt @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 Writing a table generator
yading@10 2
yading@10 3 This documentation is preliminary.
yading@10 4 Parts of the API are not good and should be changed.
yading@10 5
yading@10 6 Basic concepts
yading@10 7
yading@10 8 A table generator consists of two files, *_tablegen.c and *_tablegen.h.
yading@10 9 The .h file will provide the variable declarations and initialization
yading@10 10 code for the tables, the .c calls the initialization code and then prints
yading@10 11 the tables as a header file using the tableprint.h helpers.
yading@10 12 Both of these files will be compiled for the host system, so to avoid
yading@10 13 breakage with cross-compilation neither of them may include, directly
yading@10 14 or indirectly, config.h or avconfig.h.
yading@10 15 This means that e.g. libavutil/mathematics.h is ok but libavutil/libm.h is not.
yading@10 16 Due to this, the .c file or Makefile may have to provide additional defines
yading@10 17 or stubs, though if possible this should be avoided.
yading@10 18 In particular, CONFIG_HARDCODED_TABLES should always be defined to 0.
yading@10 19
yading@10 20 The .c file
yading@10 21
yading@10 22 This file should include the *_tablegen.h and tableprint.h files and
yading@10 23 anything else it needs as long as it does not depend on config.h or
yading@10 24 avconfig.h.
yading@10 25 In addition to that it must contain a main() function which initializes
yading@10 26 all tables by calling the init functions from the .h file and then prints
yading@10 27 them.
yading@10 28 The printing code typically looks like this:
yading@10 29 write_fileheader();
yading@10 30 printf("static const uint8_t my_array[100] = {\n");
yading@10 31 write_uint8_t_array(my_array, 100);
yading@10 32 printf("};\n");
yading@10 33
yading@10 34 This is the more generic form, in case you need to do something special.
yading@10 35 Usually you should instead use the short form:
yading@10 36 write_fileheader();
yading@10 37 WRITE_ARRAY("static const", uint8_t, my_array);
yading@10 38
yading@10 39 write_fileheader() adds some minor things like a "this is a generated file"
yading@10 40 comment and some standard includes.
yading@10 41 tablegen.h defines some write functions for one- and two-dimensional arrays
yading@10 42 for standard types - they print only the "core" parts so they are easier
yading@10 43 to reuse for multi-dimensional arrays so the outermost {} must be printed
yading@10 44 separately.
yading@10 45 If there's no standard function for printing the type you need, the
yading@10 46 WRITE_1D_FUNC_ARGV macro is a very quick way to create one.
yading@10 47 See libavcodec/dv_tablegen.c for an example.
yading@10 48
yading@10 49
yading@10 50 The .h file
yading@10 51
yading@10 52 This file should contain:
yading@10 53 - one or more initialization functions
yading@10 54 - the table variable declarations
yading@10 55 If CONFIG_HARDCODED_TABLES is set, the initialization functions should
yading@10 56 not do anything, and instead of the variable declarations the
yading@10 57 generated *_tables.h file should be included.
yading@10 58 Since that will be generated in the build directory, the path must be
yading@10 59 included, i.e.
yading@10 60 #include "libavcodec/example_tables.h"
yading@10 61 not
yading@10 62 #include "example_tables.h"
yading@10 63
yading@10 64 Makefile changes
yading@10 65
yading@10 66 To make the automatic table creation work, you must manually declare the
yading@10 67 new dependency.
yading@10 68 For this add a line similar to this:
yading@10 69 $(SUBDIR)example.o: $(SUBDIR)example_tables.h
yading@10 70 under the "ifdef CONFIG_HARDCODED_TABLES" section in the Makefile.