# HG changeset patch # User bellard # Date 1043362989 0 # Node ID 19de1445beb2919fd217e8f87a065a35a1047f75 # Parent 801f2739264a03f5c8930123fadefc8a9209ba50 use av_malloc() functions - added av_strdup and av_realloc() diff -r 801f2739264a -r 19de1445beb2 avcodec.h --- a/avcodec.h Thu Jan 23 22:59:06 2003 +0000 +++ b/avcodec.h Thu Jan 23 23:03:09 2003 +0000 @@ -1233,7 +1233,9 @@ /* memory */ void *av_malloc(unsigned int size); void *av_mallocz(unsigned int size); +void *av_realloc(void *ptr, unsigned int size); void av_free(void *ptr); +char *av_strdup(const char *s); void __av_freep(void **ptr); #define av_freep(p) __av_freep((void **)(p)) void *av_fast_realloc(void *ptr, int *size, int min_size); diff -r 801f2739264a -r 19de1445beb2 common.c --- a/common.c Thu Jan 23 22:59:06 2003 +0000 +++ b/common.c Thu Jan 23 23:03:09 2003 +0000 @@ -171,8 +171,8 @@ vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { vlc->table_allocated += (1 << vlc->bits); - vlc->table = realloc(vlc->table, - sizeof(VLC_TYPE) * 2 * vlc->table_allocated); + vlc->table = av_realloc(vlc->table, + sizeof(VLC_TYPE) * 2 * vlc->table_allocated); if (!vlc->table) return -1; } diff -r 801f2739264a -r 19de1445beb2 common.h --- a/common.h Thu Jan 23 22:59:06 2003 +0000 +++ b/common.h Thu Jan 23 23:03:09 2003 +0000 @@ -931,6 +931,11 @@ #define CLAMP_TO_8BIT(d) ((d > 0xff) ? 0xff : (d < 0) ? 0 : d) +/* avoid usage of various functions */ +#define malloc please_use_av_malloc +#define free please_use_av_free +#define realloc please_use_av_realloc + #endif /* HAVE_AV_CONFIG_H */ #endif /* COMMON_H */ diff -r 801f2739264a -r 19de1445beb2 imgconvert.c --- a/imgconvert.c Thu Jan 23 22:59:06 2003 +0000 +++ b/imgconvert.c Thu Jan 23 23:03:09 2003 +0000 @@ -1071,7 +1071,7 @@ static void avpicture_free(AVPicture *picture) { - free(picture->data[0]); + av_free(picture->data[0]); } /* XXX: always use linesize. Return -1 if not supported */ diff -r 801f2739264a -r 19de1445beb2 mem.c --- a/mem.c Thu Jan 23 22:59:06 2003 +0000 +++ b/mem.c Thu Jan 23 23:03:09 2003 +0000 @@ -17,6 +17,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avcodec.h" + +/* here we can use OS dependant allocation functions */ +#undef malloc +#undef free +#undef realloc + #ifdef HAVE_MALLOC_H #include #endif @@ -25,13 +31,15 @@ memory allocator. You do not need to suppress this file because the linker will do it automatically */ -/* memory alloc */ +/** + * Memory allocation of size byte with alignment suitable for all + * memory accesses (including vectors if available on the + * CPU). av_malloc(0) must return a non NULL pointer. + */ void *av_malloc(unsigned int size) { void *ptr; -// if(size==0) return NULL; - #if defined (HAVE_MEMALIGN) ptr = memalign(16,size); /* Why 64? @@ -63,23 +71,17 @@ #else ptr = malloc(size); #endif - if (!ptr) - return NULL; -//fprintf(stderr, "%X %d\n", (int)ptr, size); - /* NOTE: this memset should not be present */ - memset(ptr, 0, size); return ptr; } /** - * realloc which does nothing if the block is large enogh + * av_realloc semantics (same as glibc): if ptr is NULL and size > 0, + * identical to malloc(size). If size is zero, it is identical to + * free(ptr) and NULL is returned. */ -void *av_fast_realloc(void *ptr, int *size, int min_size){ - if(min_size < *size) return ptr; - - *size= min_size + 10*1024; - - return realloc(ptr, *size); +void *av_realloc(void *ptr, unsigned int size) +{ + return realloc(ptr, size); } /* NOTE: ptr = NULL is explicetly allowed */ diff -r 801f2739264a -r 19de1445beb2 mpegaudio.c --- a/mpegaudio.c Thu Jan 23 22:59:06 2003 +0000 +++ b/mpegaudio.c Thu Jan 23 23:03:09 2003 +0000 @@ -770,6 +770,7 @@ static int MPA_encode_close(AVCodecContext *avctx) { av_freep(&avctx->coded_frame); + return 0; } AVCodec mp2_encoder = { diff -r 801f2739264a -r 19de1445beb2 ratecontrol.c --- a/ratecontrol.c Thu Jan 23 22:59:06 2003 +0000 +++ b/ratecontrol.c Thu Jan 23 23:03:09 2003 +0000 @@ -751,8 +751,8 @@ } //printf("%lld %lld %lld %lld\n", available_bits[I_TYPE], available_bits[P_TYPE], available_bits[B_TYPE], all_available_bits); - qscale= malloc(sizeof(double)*rcc->num_entries); - blured_qscale= malloc(sizeof(double)*rcc->num_entries); + qscale= av_malloc(sizeof(double)*rcc->num_entries); + blured_qscale= av_malloc(sizeof(double)*rcc->num_entries); for(step=256*256; step>0.0000001; step*=0.5){ expected_bits=0; @@ -809,8 +809,8 @@ // printf("%f %d %f\n", expected_bits, (int)all_available_bits, rate_factor); if(expected_bits > all_available_bits) rate_factor-= step; } - free(qscale); - free(blured_qscale); + av_free(qscale); + av_free(blured_qscale); if(abs(expected_bits/all_available_bits - 1.0) > 0.01 ){ fprintf(stderr, "Error: 2pass curve failed to converge\n"); diff -r 801f2739264a -r 19de1445beb2 utils.c --- a/utils.c Thu Jan 23 22:59:06 2003 +0000 +++ b/utils.c Thu Jan 23 23:03:09 2003 +0000 @@ -33,6 +33,32 @@ return ptr; } +char *av_strdup(const char *s) +{ + char *ptr; + int len; + len = strlen(s) + 1; + ptr = av_malloc(len); + if (!ptr) + return NULL; + memcpy(ptr, s, len); + return ptr; +} + +/** + * realloc which does nothing if the block is large enough + */ +void *av_fast_realloc(void *ptr, int *size, int min_size) +{ + if(min_size < *size) + return ptr; + + *size= min_size + 10*1024; + + return av_realloc(ptr, *size); +} + + /* allocation of static arrays - do not use for normal allocation */ static unsigned int last_static = 0; static char*** array_static = NULL; @@ -47,7 +73,7 @@ if (location) { if (l > last_static) - array_static = realloc(array_static, l); + array_static = av_realloc(array_static, l); array_static[last_static++] = (char**) location; *location = ptr; } @@ -61,10 +87,10 @@ unsigned i; for (i = 0; i < last_static; i++) { - free(*array_static[i]); + av_free(*array_static[i]); *array_static[i] = NULL; } - free(array_static); + av_free(array_static); array_static = 0; } last_static = 0; diff -r 801f2739264a -r 19de1445beb2 wmadec.c --- a/wmadec.c Thu Jan 23 22:59:06 2003 +0000 +++ b/wmadec.c Thu Jan 23 23:03:09 2003 +0000 @@ -92,7 +92,7 @@ int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]; float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE] __attribute__((aligned(16))); MDCTContext mdct_ctx[BLOCK_NB_SIZES]; - float *windows[BLOCK_NB_SIZES] __attribute__((aligned(16))); + float *windows[BLOCK_NB_SIZES]; FFTSample mdct_tmp[BLOCK_MAX_SIZE] __attribute__((aligned(16))); /* temporary storage for imdct */ /* output buffer for one frame and the last for IMDCT windowing */ float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2] __attribute__((aligned(16))); @@ -212,8 +212,8 @@ init_vlc(vlc, 9, n, table_bits, 1, 1, table_codes, 4, 4); - run_table = malloc(n * sizeof(uint16_t)); - level_table = malloc(n * sizeof(uint16_t)); + run_table = av_malloc(n * sizeof(uint16_t)); + level_table = av_malloc(n * sizeof(uint16_t)); p = levels_table; i = 2; level = 1;