diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-12-07 00:45:26 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-12-07 00:46:42 +0400 |
commit | 4b6869d6e0120c92253d525921f0e04361888e10 (patch) | |
tree | 85b47094bf7c30193b4642a1e5063f75084f4cc1 | |
parent | bbd44f6ca4bacbc2319b7dfa9db96eeff6f0a33c (diff) |
bitstream: make vlc init of static tables thread safe.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/bitstream.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index ce83ee01f9..bf131e9a0b 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -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; } |