Mercurial > libavcodec.hg
comparison utils.c @ 6941:da73a98945ea libavcodec
Move *_static to bitstream.c which is the only file left which needs
them.
| author | michael |
|---|---|
| date | Fri, 30 May 2008 21:12:33 +0000 |
| parents | f7cbb7733146 |
| children | 92c74bbdf4fb |
comparison
equal
deleted
inserted
replaced
| 6940:778ecab25dd8 | 6941:da73a98945ea |
|---|---|
| 70 if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now | 70 if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now |
| 71 *size= 0; | 71 *size= 0; |
| 72 | 72 |
| 73 return ptr; | 73 return ptr; |
| 74 } | 74 } |
| 75 | |
| 76 static unsigned int last_static = 0; | |
| 77 static unsigned int allocated_static = 0; | |
| 78 static void** array_static = NULL; | |
| 79 | |
| 80 void *av_mallocz_static(unsigned int size) | |
| 81 { | |
| 82 void *ptr = av_mallocz(size); | |
| 83 | |
| 84 if(ptr){ | |
| 85 array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1)); | |
| 86 if(!array_static) | |
| 87 return NULL; | |
| 88 array_static[last_static++] = ptr; | |
| 89 } | |
| 90 | |
| 91 return ptr; | |
| 92 } | |
| 93 | |
| 94 void *ff_realloc_static(void *ptr, unsigned int size) | |
| 95 { | |
| 96 int i; | |
| 97 if(!ptr) | |
| 98 return av_mallocz_static(size); | |
| 99 /* Look for the old ptr */ | |
| 100 for(i = 0; i < last_static; i++) { | |
| 101 if(array_static[i] == ptr) { | |
| 102 array_static[i] = av_realloc(array_static[i], size); | |
| 103 return array_static[i]; | |
| 104 } | |
| 105 } | |
| 106 return NULL; | |
| 107 | |
| 108 } | |
| 109 | |
| 110 void av_free_static(void) | |
| 111 { | |
| 112 while(last_static){ | |
| 113 av_freep(&array_static[--last_static]); | |
| 114 } | |
| 115 av_freep(&array_static); | |
| 116 } | |
| 117 | |
| 118 /** | |
| 119 * Call av_free_static automatically before it's too late | |
| 120 */ | |
| 121 | |
| 122 static void do_free(void) __attribute__ ((destructor)); | |
| 123 | |
| 124 static void do_free(void) | |
| 125 { | |
| 126 av_free_static(); | |
| 127 } | |
| 128 | |
| 129 | 75 |
| 130 /* encoder management */ | 76 /* encoder management */ |
| 131 AVCodec *first_avcodec = NULL; | 77 AVCodec *first_avcodec = NULL; |
| 132 | 78 |
| 133 AVCodec *av_codec_next(AVCodec *c){ | 79 AVCodec *av_codec_next(AVCodec *c){ |
