Originally committed as revision 13561 to svn://svn.ffmpeg.org/ffmpeg/trunk
Michael Niedermayer authored on 2008/05/31 04:48:02... | ... |
@@ -110,6 +110,8 @@ static int alloc_table(VLC *vlc, int size, int use_static) |
110 | 110 |
index = vlc->table_size; |
111 | 111 |
vlc->table_size += size; |
112 | 112 |
if (vlc->table_size > vlc->table_allocated) { |
113 |
+ if(use_static>1) |
|
114 |
+ abort(); //cant do anything, init_vlc() is used with too little memory |
|
113 | 115 |
vlc->table_allocated += (1 << vlc->bits); |
114 | 116 |
if(use_static) |
115 | 117 |
vlc->table = ff_realloc_static(vlc->table, |
... | ... |
@@ -135,7 +137,7 @@ static int build_table(VLC *vlc, int table_nb_bits, |
135 | 135 |
VLC_TYPE (*table)[2]; |
136 | 136 |
|
137 | 137 |
table_size = 1 << table_nb_bits; |
138 |
- table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_STATIC); |
|
138 |
+ table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); |
|
139 | 139 |
#ifdef DEBUG_VLC |
140 | 140 |
av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n", |
141 | 141 |
table_index, table_size, code_prefix, n_prefix); |
... | ... |
@@ -264,7 +266,13 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, |
264 | 264 |
int flags) |
265 | 265 |
{ |
266 | 266 |
vlc->bits = nb_bits; |
267 |
- if(!(flags & INIT_VLC_USE_STATIC)) { |
|
267 |
+ if(flags & INIT_VLC_USE_NEW_STATIC){ |
|
268 |
+ if(vlc->table_size && vlc->table_size == vlc->table_allocated){ |
|
269 |
+ return 0; |
|
270 |
+ }else if(vlc->table_size){ |
|
271 |
+ abort(); // fatal error, we are called on a partially initialized table |
|
272 |
+ } |
|
273 |
+ }else if(!(flags & INIT_VLC_USE_STATIC)) { |
|
268 | 274 |
vlc->table = NULL; |
269 | 275 |
vlc->table_allocated = 0; |
270 | 276 |
vlc->table_size = 0; |
... | ... |
@@ -287,6 +295,8 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, |
287 | 287 |
av_freep(&vlc->table); |
288 | 288 |
return -1; |
289 | 289 |
} |
290 |
+ if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated) |
|
291 |
+ av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated); |
|
290 | 292 |
return 0; |
291 | 293 |
} |
292 | 294 |
|
... | ... |
@@ -800,8 +800,9 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, |
800 | 800 |
const void *codes, int codes_wrap, int codes_size, |
801 | 801 |
const void *symbols, int symbols_wrap, int symbols_size, |
802 | 802 |
int flags); |
803 |
-#define INIT_VLC_USE_STATIC 1 |
|
803 |
+#define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden |
|
804 | 804 |
#define INIT_VLC_LE 2 |
805 |
+#define INIT_VLC_USE_NEW_STATIC 4 |
|
805 | 806 |
void free_vlc(VLC *vlc); |
806 | 807 |
|
807 | 808 |
/** |