Mercurial > libavcodec.hg
comparison bitstream.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 | 24e01f7cc819 |
| children | 29ebf511fb22 |
comparison
equal
deleted
inserted
replaced
| 6940:778ecab25dd8 | 6941:da73a98945ea |
|---|---|
| 38 * @return Block of memory of requested size. | 38 * @return Block of memory of requested size. |
| 39 * @deprecated. Code which uses ff_realloc_static is broken/misdesigned | 39 * @deprecated. Code which uses ff_realloc_static is broken/misdesigned |
| 40 * and should correctly use static arrays | 40 * and should correctly use static arrays |
| 41 */ | 41 */ |
| 42 attribute_deprecated av_alloc_size(2) | 42 attribute_deprecated av_alloc_size(2) |
| 43 void *ff_realloc_static(void *ptr, unsigned int size); | 43 static void *ff_realloc_static(void *ptr, unsigned int size); |
| 44 | |
| 45 static unsigned int last_static = 0; | |
| 46 static unsigned int allocated_static = 0; | |
| 47 static void** array_static = NULL; | |
| 48 | |
| 49 static void *av_mallocz_static(unsigned int size) | |
| 50 { | |
| 51 void *ptr = av_mallocz(size); | |
| 52 | |
| 53 if(ptr){ | |
| 54 array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1)); | |
| 55 if(!array_static) | |
| 56 return NULL; | |
| 57 array_static[last_static++] = ptr; | |
| 58 } | |
| 59 | |
| 60 return ptr; | |
| 61 } | |
| 62 | |
| 63 static void *ff_realloc_static(void *ptr, unsigned int size) | |
| 64 { | |
| 65 int i; | |
| 66 if(!ptr) | |
| 67 return av_mallocz_static(size); | |
| 68 /* Look for the old ptr */ | |
| 69 for(i = 0; i < last_static; i++) { | |
| 70 if(array_static[i] == ptr) { | |
| 71 array_static[i] = av_realloc(array_static[i], size); | |
| 72 return array_static[i]; | |
| 73 } | |
| 74 } | |
| 75 return NULL; | |
| 76 | |
| 77 } | |
| 78 | |
| 79 static void av_free_static(void) | |
| 80 { | |
| 81 while(last_static){ | |
| 82 av_freep(&array_static[--last_static]); | |
| 83 } | |
| 84 av_freep(&array_static); | |
| 85 } | |
| 86 | |
| 87 /** | |
| 88 * Call av_free_static automatically before it's too late | |
| 89 */ | |
| 90 | |
| 91 static void do_free(void) __attribute__ ((destructor)); | |
| 92 | |
| 93 static void do_free(void) | |
| 94 { | |
| 95 av_free_static(); | |
| 96 } | |
| 97 | |
| 44 | 98 |
| 45 void align_put_bits(PutBitContext *s) | 99 void align_put_bits(PutBitContext *s) |
| 46 { | 100 { |
| 47 #ifdef ALT_BITSTREAM_WRITER | 101 #ifdef ALT_BITSTREAM_WRITER |
| 48 put_bits(s,( - s->index) & 7,0); | 102 put_bits(s,( - s->index) & 7,0); |
