comparison bitstream.c @ 6935:24e01f7cc819 libavcodec

Make init_vlc* support proper static tables instead of this broken beyond imagination alloc_static() trash.
author michael
date Fri, 30 May 2008 19:48:02 +0000
parents f57fee2decd6
children da73a98945ea
comparison
equal deleted inserted replaced
6934:ac6f00bed029 6935:24e01f7cc819
108 { 108 {
109 int index; 109 int index;
110 index = vlc->table_size; 110 index = vlc->table_size;
111 vlc->table_size += size; 111 vlc->table_size += size;
112 if (vlc->table_size > vlc->table_allocated) { 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 vlc->table_allocated += (1 << vlc->bits); 115 vlc->table_allocated += (1 << vlc->bits);
114 if(use_static) 116 if(use_static)
115 vlc->table = ff_realloc_static(vlc->table, 117 vlc->table = ff_realloc_static(vlc->table,
116 sizeof(VLC_TYPE) * 2 * vlc->table_allocated); 118 sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
117 else 119 else
133 int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol; 135 int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol;
134 uint32_t code; 136 uint32_t code;
135 VLC_TYPE (*table)[2]; 137 VLC_TYPE (*table)[2];
136 138
137 table_size = 1 << table_nb_bits; 139 table_size = 1 << table_nb_bits;
138 table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_STATIC); 140 table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC));
139 #ifdef DEBUG_VLC 141 #ifdef DEBUG_VLC
140 av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n", 142 av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n",
141 table_index, table_size, code_prefix, n_prefix); 143 table_index, table_size, code_prefix, n_prefix);
142 #endif 144 #endif
143 if (table_index < 0) 145 if (table_index < 0)
262 const void *codes, int codes_wrap, int codes_size, 264 const void *codes, int codes_wrap, int codes_size,
263 const void *symbols, int symbols_wrap, int symbols_size, 265 const void *symbols, int symbols_wrap, int symbols_size,
264 int flags) 266 int flags)
265 { 267 {
266 vlc->bits = nb_bits; 268 vlc->bits = nb_bits;
267 if(!(flags & INIT_VLC_USE_STATIC)) { 269 if(flags & INIT_VLC_USE_NEW_STATIC){
270 if(vlc->table_size && vlc->table_size == vlc->table_allocated){
271 return 0;
272 }else if(vlc->table_size){
273 abort(); // fatal error, we are called on a partially initialized table
274 }
275 }else if(!(flags & INIT_VLC_USE_STATIC)) {
268 vlc->table = NULL; 276 vlc->table = NULL;
269 vlc->table_allocated = 0; 277 vlc->table_allocated = 0;
270 vlc->table_size = 0; 278 vlc->table_size = 0;
271 } else { 279 } else {
272 /* Static tables are initially always NULL, return 280 /* Static tables are initially always NULL, return
285 symbols, symbols_wrap, symbols_size, 293 symbols, symbols_wrap, symbols_size,
286 0, 0, flags) < 0) { 294 0, 0, flags) < 0) {
287 av_freep(&vlc->table); 295 av_freep(&vlc->table);
288 return -1; 296 return -1;
289 } 297 }
298 if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated)
299 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated);
290 return 0; 300 return 0;
291 } 301 }
292 302
293 303
294 void free_vlc(VLC *vlc) 304 void free_vlc(VLC *vlc)