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
142142 uint32_t code;
143143 } VLCcode;
144144
145−static int vlc_common_init(VLC *vlc_arg, int nb_bits, int nb_codes,
146− VLC **vlc, VLC *localvlc, VLCcode **buf,
147− int flags)
145+static int vlc_common_init(VLC *vlc, int nb_bits, int nb_codes,
146+ VLCcode **buf, int flags)
148147 {
149− *vlc = vlc_arg;
150− (*vlc)->bits = nb_bits;
148+ vlc->bits = nb_bits;
149+ vlc->table_size = 0;
151150 if (flags & INIT_VLC_USE_NEW_STATIC) {
152151 av_assert0(nb_codes <= LOCALBUF_ELEMS);
153− *localvlc = *vlc_arg;
154− *vlc = localvlc;
155− (*vlc)->table_size = 0;
156152 } else {
157− (*vlc)->table = NULL;
158− (*vlc)->table_allocated = 0;
159− (*vlc)->table_size = 0;
153+ vlc->table = NULL;
154+ vlc->table_allocated = 0;
160155 }
161156 if (nb_codes > LOCALBUF_ELEMS) {
162157 *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
191186 {
192187 int table_size, table_index, index, code_prefix, symbol, subtable_bits;
193188 int i, j, k, n, nb, inc;
189+ VLC_TYPE (*table)[2];
194190 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
196191
197192 if (table_nb_bits > 30)
198193 return AVERROR(EINVAL);
@@ -201,7 +196,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, · 2 unmodified lines
201196 ff_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);
202197 if (table_index < 0)
203198 return table_index;
204− table = (volatile VLC_TYPE (*)[2])&vlc->table[table_index];
199+ table = &vlc->table[table_index];
205200
206201 /* first pass: map codes and compute auxiliary table sizes */
207202 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
257252 if (index < 0)
258253 return index;
259254 /* note: realloc has been done, so reload tables */
260− table = (volatile VLC_TYPE (*)[2])&vlc->table[table_index];
255+ table = &vlc->table[table_index];
261256 table[j][0] = index; //code
262257 if (table[j][0] != index) {
263258 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
276271 }
277272
278273 static 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])
280275 {
281276 int ret = build_table(vlc, nb_bits, nb_codes, codes, flags);
282277
@@ -285,7 +280,6 @@ static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes, · 2 unmodified lines
285280 !(flags & (INIT_VLC_STATIC_OVERLONG & ~INIT_VLC_USE_NEW_STATIC)))
286281 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated);
287282 av_assert0(ret >= 0);
288− *vlc_arg = *vlc;
289283 } else {
290284 if (codes != localbuf)
291285 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
320314 'wrap' and 'size' make it possible to use any memory configuration and types
321315 (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
322316 */
323−int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes,
317+int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
324318 const void *bits, int bits_wrap, int bits_size,
325319 const void *codes, int codes_wrap, int codes_size,
326320 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
328322 {
329323 VLCcode localbuf[LOCALBUF_ELEMS], *buf = localbuf;
330324 int i, j, ret;
331− VLC localvlc, *vlc;
332325
333− ret = vlc_common_init(vlc_arg, nb_bits, nb_codes, &vlc, &localvlc,
334− &buf, flags);
326+ ret = vlc_common_init(vlc, nb_bits, nb_codes, &buf, flags);
335327 if (ret < 0)
336328 return ret;
337329
@@ -375,21 +367,19 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, · 37 unmodified lines
375367 nb_codes = j;
376368
377369 return vlc_common_end(vlc, nb_bits, nb_codes, buf,
378− flags, vlc_arg, localbuf);
370+ flags, localbuf);
379371 }
380372
381−int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes,
373+int ff_init_vlc_from_lengths(VLC *vlc, int nb_bits, int nb_codes,
382374 const int8_t *lens, int lens_wrap,
383375 const void *symbols, int symbols_wrap, int symbols_size,
384376 int offset, int flags, void *logctx)
385377 {
386378 VLCcode localbuf[LOCALBUF_ELEMS], *buf = localbuf;
387− VLC localvlc, *vlc;
388379 uint64_t code;
389380 int ret, j, len_max = FFMIN(32, 3 * nb_bits);
390381
391− ret = vlc_common_init(vlc_arg, nb_bits, nb_codes, &vlc, &localvlc,
392− &buf, flags);
382+ ret = vlc_common_init(vlc, nb_bits, nb_codes, &buf, flags);
393383 if (ret < 0)
394384 return ret;
395385
@@ -420,8 +410,7 @@ int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes, · 24 unmodified lines
420410 goto fail;
421411 }
422412 }
423− return vlc_common_end(vlc, nb_bits, j, buf,
424− flags, vlc_arg, localbuf);
413+ return vlc_common_end(vlc, nb_bits, j, buf, flags, localbuf);
425414 fail:
426415 if (buf != localbuf)
427416 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