History

avcodec/bitstream: Don't pretend VLCs to be initialized concurrently

Since the MPEG-4 parser no longer initializes some MPEG-4 VLCs, no VLC is initialized concurrently by multiple threads (initializing static VLCs is guarded by locks and nonstatic VLCs never posed an issue in this regard). So remove the code in bitstream.c that only exists because of this possibility.

Andreas Rheinhardt committed 4 years ago

Commit e60debb1 parent 938251c1 file · +16 −27Browse files

Showing the changes to libavcodec/bitstream.c (1 of 1 file). Show all

Unified · Split

libavcodec/bitstream.c+16−27
@@ -142,21 +142,16 @@ typedef struct VLCcode { · 141 unmodified lines
142 uint32_t code;142 uint32_t code;
143} VLCcode;143} VLCcode;
144 144
145static int vlc_common_init(VLC *vlc_arg, int nb_bits, int nb_codes,145static int vlc_common_init(VLC *vlc, int nb_bits, int nb_codes,
146 VLC **vlc, VLC *localvlc, VLCcode **buf,146 VLCcode **buf, int flags)
147 int flags)
148{147{
149 *vlc = vlc_arg;148 vlc->bits = nb_bits;
150 (*vlc)->bits = nb_bits;149 vlc->table_size = 0;
151 if (flags & INIT_VLC_USE_NEW_STATIC) {150 if (flags & INIT_VLC_USE_NEW_STATIC) {
152 av_assert0(nb_codes <= LOCALBUF_ELEMS);151 av_assert0(nb_codes <= LOCALBUF_ELEMS);
153 *localvlc = *vlc_arg;
154 *vlc = localvlc;
155 (*vlc)->table_size = 0;
156 } else {152 } else {
157 (*vlc)->table = NULL;153 vlc->table = NULL;
158 (*vlc)->table_allocated = 0;154 vlc->table_allocated = 0;
159 (*vlc)->table_size = 0;
160 }155 }
161 if (nb_codes > LOCALBUF_ELEMS) {156 if (nb_codes > LOCALBUF_ELEMS) {
162 *buf = av_malloc_array(nb_codes, sizeof(VLCcode));157 *buf = av_malloc_array(nb_codes, sizeof(VLCcode));
@@ -191,8 +186,8 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, · 28 unmodified lines
191{186{
192 int table_size, table_index, index, code_prefix, symbol, subtable_bits;187 int table_size, table_index, index, code_prefix, symbol, subtable_bits;
193 int i, j, k, n, nb, inc;188 int i, j, k, n, nb, inc;
189 VLC_TYPE (*table)[2];
194 uint32_t code;190 uint32_t code;
195 volatile VLC_TYPE (* volatile table)[2]; // the double volatile is needed to prevent an internal compiler error in gcc 4.2
196 191
197 if (table_nb_bits > 30)192 if (table_nb_bits > 30)
198 return AVERROR(EINVAL);193 return AVERROR(EINVAL);
@@ -201,7 +196,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, · 2 unmodified lines
201 ff_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);196 ff_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);
202 if (table_index < 0)197 if (table_index < 0)
203 return table_index;198 return table_index;
204 table = (volatile VLC_TYPE (*)[2])&vlc->table[table_index];199 table = &vlc->table[table_index];
205 200
206 /* first pass: map codes and compute auxiliary table sizes */201 /* first pass: map codes and compute auxiliary table sizes */
207 for (i = 0; i < nb_codes; i++) {202 for (i = 0; i < nb_codes; i++) {
@@ -257,7 +252,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, · 49 unmodified lines
257 if (index < 0)252 if (index < 0)
258 return index;253 return index;
259 /* note: realloc has been done, so reload tables */254 /* note: realloc has been done, so reload tables */
260 table = (volatile VLC_TYPE (*)[2])&vlc->table[table_index];255 table = &vlc->table[table_index];
261 table[j][0] = index; //code256 table[j][0] = index; //code
262 if (table[j][0] != index) {257 if (table[j][0] != index) {
263 avpriv_request_sample(NULL, "strange codes");258 avpriv_request_sample(NULL, "strange codes");
@@ -276,7 +271,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, · 12 unmodified lines
276}271}
277 272
278static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes,273static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes,
279 int flags, VLC *vlc_arg, VLCcode localbuf[LOCALBUF_ELEMS])274 int flags, VLCcode localbuf[LOCALBUF_ELEMS])
280{275{
281 int ret = build_table(vlc, nb_bits, nb_codes, codes, flags);276 int ret = build_table(vlc, nb_bits, nb_codes, codes, flags);
282 277
@@ -285,7 +280,6 @@ static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes, · 2 unmodified lines
285 !(flags & (INIT_VLC_STATIC_OVERLONG & ~INIT_VLC_USE_NEW_STATIC)))280 !(flags & (INIT_VLC_STATIC_OVERLONG & ~INIT_VLC_USE_NEW_STATIC)))
286 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated);281 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated);
287 av_assert0(ret >= 0);282 av_assert0(ret >= 0);
288 *vlc_arg = *vlc;
289 } else {283 } else {
290 if (codes != localbuf)284 if (codes != localbuf)
291 av_free(codes);285 av_free(codes);
@@ -320,7 +314,7 @@ static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes, · 28 unmodified lines
320 'wrap' and 'size' make it possible to use any memory configuration and types314 'wrap' and 'size' make it possible to use any memory configuration and types
321 (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.315 (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
322*/316*/
323int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes,317int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
324 const void *bits, int bits_wrap, int bits_size,318 const void *bits, int bits_wrap, int bits_size,
325 const void *codes, int codes_wrap, int codes_size,319 const void *codes, int codes_wrap, int codes_size,
326 const void *symbols, int symbols_wrap, int symbols_size,320 const void *symbols, int symbols_wrap, int symbols_size,
@@ -328,10 +322,8 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, · 1 unmodified line
328{322{
329 VLCcode localbuf[LOCALBUF_ELEMS], *buf = localbuf;323 VLCcode localbuf[LOCALBUF_ELEMS], *buf = localbuf;
330 int i, j, ret;324 int i, j, ret;
331 VLC localvlc, *vlc;
332 325
333 ret = vlc_common_init(vlc_arg, nb_bits, nb_codes, &vlc, &localvlc,326 ret = vlc_common_init(vlc, nb_bits, nb_codes, &buf, flags);
334 &buf, flags);
335 if (ret < 0)327 if (ret < 0)
336 return ret;328 return ret;
337 329
@@ -375,21 +367,19 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, · 37 unmodified lines
375 nb_codes = j;367 nb_codes = j;
376 368
377 return vlc_common_end(vlc, nb_bits, nb_codes, buf,369 return vlc_common_end(vlc, nb_bits, nb_codes, buf,
378 flags, vlc_arg, localbuf);370 flags, localbuf);
379}371}
380 372
381int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes,373int ff_init_vlc_from_lengths(VLC *vlc, int nb_bits, int nb_codes,
382 const int8_t *lens, int lens_wrap,374 const int8_t *lens, int lens_wrap,
383 const void *symbols, int symbols_wrap, int symbols_size,375 const void *symbols, int symbols_wrap, int symbols_size,
384 int offset, int flags, void *logctx)376 int offset, int flags, void *logctx)
385{377{
386 VLCcode localbuf[LOCALBUF_ELEMS], *buf = localbuf;378 VLCcode localbuf[LOCALBUF_ELEMS], *buf = localbuf;
387 VLC localvlc, *vlc;
388 uint64_t code;379 uint64_t code;
389 int ret, j, len_max = FFMIN(32, 3 * nb_bits);380 int ret, j, len_max = FFMIN(32, 3 * nb_bits);
390 381
391 ret = vlc_common_init(vlc_arg, nb_bits, nb_codes, &vlc, &localvlc,382 ret = vlc_common_init(vlc, nb_bits, nb_codes, &buf, flags);
392 &buf, flags);
393 if (ret < 0)383 if (ret < 0)
394 return ret;384 return ret;
395 385
@@ -420,8 +410,7 @@ int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes, · 24 unmodified lines
420 goto fail;410 goto fail;
421 }411 }
422 }412 }
423 return vlc_common_end(vlc, nb_bits, j, buf,413 return vlc_common_end(vlc, nb_bits, j, buf, flags, localbuf);
424 flags, vlc_arg, localbuf);
425fail:414fail:
426 if (buf != localbuf)415 if (buf != localbuf)
427 av_free(buf);416 av_free(buf);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t