[FFmpeg-devel] [PATCH 004/114] avcodec/bitstream: Allow static VLC tables to be bigger than needed

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Tue Nov 10 13:26:31 EET 2020


Paul B Mahol:
> I do not think this is a good direction.
> 

Why?

> On Tue, Nov 10, 2020 at 11:50 AM Andreas Rheinhardt <
> andreas.rheinhardt at gmail.com> wrote:
> 
>> Right now the allocated size of the VLC table of a static VLC has to
>> exactly match the size actually used for the VLC: If it is not enough,
>> abort is called; if it is more than enough, an error message is
>> emitted. This is no problem when one wants to initialize an individual
>> VLC via one of the INIT_VLC macros as one just hardcodes the needed
>> size. Yet it is an obstacle when one wants to initialize several VLCs
>> in a loop as one then needs to add an array for the sizes/offsets of
>> the VLC tables (unless max_depth of all arrays is one in which case
>> the sizes are derivable from the number of bits used).
>>
>> Yet said size array is not necessary if one removes the warning for too
>> big buffers. The reason is that the amount of entries needed for the
>> table is of course generated as a byproduct of initializing the VLC.
>> So one can proceed as follows:
>>
>> static VLC vlcs[NUM];
>> static VLC_TYPE vlc_table[BUF_SIZE][2];
>>
>> for (int i = 0, offset = 0; i < NUM; i++) {
>>     vlcs[i].table           = &vlc_table[offset];
>>     vlcs[i].table_allocated = BUF_SIZE - offset;
>>     init_vlc();
>>     offset += vlcs[i].table_size;
>> }
>>
>> Of course, BUF_SIZE should be equal to the number of entries actually
>> needed.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
>> ---
>>  libavcodec/bitstream.c | 3 ---
>>  1 file changed, 3 deletions(-)
>>
>> diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
>> index 03d39ad88c..4ffec7e17a 100644
>> --- a/libavcodec/bitstream.c
>> +++ b/libavcodec/bitstream.c
>> @@ -281,9 +281,6 @@ static int vlc_common_end(VLC *vlc, int nb_bits, int
>> nb_codes, VLCcode *codes,
>>      int ret = build_table(vlc, nb_bits, nb_codes, codes, flags);
>>
>>      if (flags & INIT_VLC_USE_NEW_STATIC) {
>> -        if(vlc->table_size != vlc->table_allocated)
>> -            av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n",
>> vlc->table_size, vlc->table_allocated);
>> -
>>          av_assert0(ret >= 0);
>>          *vlc_arg = *vlc;
>>      } else {
>> --
>> 2.25.1
>>



More information about the ffmpeg-devel mailing list