X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fbitstream.c;h=6bcdadb9c4d2578ceba203ebd26dbac60709b70a;hb=d27edc038a5d59f25b28964b38d9f8d7ce4a6e64;hp=ce83ee01f90d15b90b7e56a2a6b23456dc4eb7b7;hpb=264441715b132344e15f27f6a5740645d5146f56;p=ffmpeg diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index ce83ee01f90..6bcdadb9c4d 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -172,7 +172,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, table[i][0] = -1; //codes } - /* first pass: map codes and compute auxillary table sizes */ + /* first pass: map codes and compute auxiliary table sizes */ for (i = 0; i < nb_codes; i++) { n = codes[i].bits; code = codes[i].code; @@ -270,11 +270,24 @@ int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, vlc->bits = nb_bits; if(flags & INIT_VLC_USE_NEW_STATIC){ - if(vlc->table_size && vlc->table_size == vlc->table_allocated){ + VLC dyn_vlc = *vlc; + + if (vlc->table_size) return 0; - }else if(vlc->table_size){ - abort(); // fatal error, we are called on a partially initialized table - } + + ret = ff_init_vlc_sparse(&dyn_vlc, nb_bits, nb_codes, + bits, bits_wrap, bits_size, + codes, codes_wrap, codes_size, + symbols, symbols_wrap, symbols_size, + flags & ~INIT_VLC_USE_NEW_STATIC); + av_assert0(ret >= 0); + av_assert0(dyn_vlc.table_size <= vlc->table_allocated); + if(dyn_vlc.table_size < vlc->table_allocated) + av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", dyn_vlc.table_size, vlc->table_allocated); + memcpy(vlc->table, dyn_vlc.table, dyn_vlc.table_size * sizeof(*vlc->table)); + vlc->table_size = dyn_vlc.table_size; + ff_free_vlc(&dyn_vlc); + return 0; }else { vlc->table = NULL; vlc->table_allocated = 0; @@ -316,8 +329,6 @@ int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, av_freep(&vlc->table); return -1; } - if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated) - av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated); return 0; }