# HG changeset patch # User kabi # Date 1038944435 0 # Node ID 6acc8394960d19890ec631d6a177b02d5d2678da # Parent 07a677389920aff3dcbf466cadca7d832aac1e20 * two functions to handle allocation of static data more simple av_mallocz_static - called for every static data table av_free_static - called when ffmpeg is no longer needed and should free all static resources * simple usage shown in mpegaudiodec.c diff -r 07a677389920 -r 6acc8394960d avcodec.h --- a/avcodec.h Tue Dec 03 15:42:17 2002 +0000 +++ b/avcodec.h Tue Dec 03 19:40:35 2002 +0000 @@ -1061,5 +1061,10 @@ void av_free(void *ptr); void __av_freep(void **ptr); #define av_freep(p) __av_freep((void **)(p)) +/* for static data only */ +/* call av_free_static to release all staticaly allocated tables */ +void av_free_static(); +void *__av_mallocz_static(void** location, unsigned int size); +#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s) #endif /* AVCODEC_H */ diff -r 07a677389920 -r 6acc8394960d mpegaudiodec.c --- a/mpegaudiodec.c Tue Dec 03 15:42:17 2002 +0000 +++ b/mpegaudiodec.c Tue Dec 03 19:40:35 2002 +0000 @@ -379,17 +379,13 @@ band_index_long[i][22] = k; } - /* compute n ^ (4/3) and store it in mantissa/exp format */ - table_4_3_exp = av_mallocz(TABLE_4_3_SIZE * - sizeof(table_4_3_exp[0])); - if (!table_4_3_exp) + /* compute n ^ (4/3) and store it in mantissa/exp format */ + if (!av_mallocz_static(&table_4_3_exp, + TABLE_4_3_SIZE * sizeof(table_4_3_exp[0]))) + return -1; + if (!av_mallocz_static(&table_4_3_value, + TABLE_4_3_SIZE * sizeof(table_4_3_value[0]))) return -1; - table_4_3_value = av_mallocz(TABLE_4_3_SIZE * - sizeof(table_4_3_value[0])); - if (!table_4_3_value) { - av_free(table_4_3_exp); - return -1; - } int_pow_init(); for(i=1;i last_static) + array_static = realloc(array_static, l); + array_static[last_static++] = (char**) location; + *location = ptr; + } + return ptr; +} +/* free all static arrays and reset pointers to 0 */ +void av_free_static() +{ + if (array_static) + { + unsigned i; + for (i = 0; i < last_static; i++) + { + free(*array_static[i]); + *array_static[i] = NULL; + } + free(array_static); + array_static = 0; + } + last_static = 0; +} + /* cannot call it directly because of 'void **' casting is not automatic */ void __av_freep(void **ptr) {