mirror of https://git.ffmpeg.org/ffmpeg.git
Make init_vlc* support proper static tables instead of this broken beyond
imagination alloc_static() trash. Originally committed as revision 13561 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
27f19ed501
commit
ccc54864fe
|
@ -110,6 +110,8 @@ static int alloc_table(VLC *vlc, int size, int use_static)
|
||||||
index = vlc->table_size;
|
index = vlc->table_size;
|
||||||
vlc->table_size += size;
|
vlc->table_size += size;
|
||||||
if (vlc->table_size > vlc->table_allocated) {
|
if (vlc->table_size > vlc->table_allocated) {
|
||||||
|
if(use_static>1)
|
||||||
|
abort(); //cant do anything, init_vlc() is used with too little memory
|
||||||
vlc->table_allocated += (1 << vlc->bits);
|
vlc->table_allocated += (1 << vlc->bits);
|
||||||
if(use_static)
|
if(use_static)
|
||||||
vlc->table = ff_realloc_static(vlc->table,
|
vlc->table = ff_realloc_static(vlc->table,
|
||||||
|
@ -135,7 +137,7 @@ static int build_table(VLC *vlc, int table_nb_bits,
|
||||||
VLC_TYPE (*table)[2];
|
VLC_TYPE (*table)[2];
|
||||||
|
|
||||||
table_size = 1 << table_nb_bits;
|
table_size = 1 << table_nb_bits;
|
||||||
table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_STATIC);
|
table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC));
|
||||||
#ifdef DEBUG_VLC
|
#ifdef DEBUG_VLC
|
||||||
av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n",
|
av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n",
|
||||||
table_index, table_size, code_prefix, n_prefix);
|
table_index, table_size, code_prefix, n_prefix);
|
||||||
|
@ -264,7 +266,13 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
|
||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
vlc->bits = nb_bits;
|
vlc->bits = nb_bits;
|
||||||
if(!(flags & INIT_VLC_USE_STATIC)) {
|
if(flags & INIT_VLC_USE_NEW_STATIC){
|
||||||
|
if(vlc->table_size && vlc->table_size == vlc->table_allocated){
|
||||||
|
return 0;
|
||||||
|
}else if(vlc->table_size){
|
||||||
|
abort(); // fatal error, we are called on a partially initialized table
|
||||||
|
}
|
||||||
|
}else if(!(flags & INIT_VLC_USE_STATIC)) {
|
||||||
vlc->table = NULL;
|
vlc->table = NULL;
|
||||||
vlc->table_allocated = 0;
|
vlc->table_allocated = 0;
|
||||||
vlc->table_size = 0;
|
vlc->table_size = 0;
|
||||||
|
@ -287,6 +295,8 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
|
||||||
av_freep(&vlc->table);
|
av_freep(&vlc->table);
|
||||||
return -1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -800,8 +800,9 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
|
||||||
const void *codes, int codes_wrap, int codes_size,
|
const void *codes, int codes_wrap, int codes_size,
|
||||||
const void *symbols, int symbols_wrap, int symbols_size,
|
const void *symbols, int symbols_wrap, int symbols_size,
|
||||||
int flags);
|
int flags);
|
||||||
#define INIT_VLC_USE_STATIC 1
|
#define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden
|
||||||
#define INIT_VLC_LE 2
|
#define INIT_VLC_LE 2
|
||||||
|
#define INIT_VLC_USE_NEW_STATIC 4
|
||||||
void free_vlc(VLC *vlc);
|
void free_vlc(VLC *vlc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue