Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 08/10] avcodec/bitstream: Don't pretend VLCs to be initialized concurrently
Date: Wed,  5 Jan 2022 22:56:08 +0100
Message-ID: <AM7PR03MB6660E1AC6A3AEF53206AF01E8F4B9@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <AM7PR03MB6660E16D4E4345D825454C178F4B9@AM7PR03MB6660.eurprd03.prod.outlook.com>

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.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/bitstream.c | 43 ++++++++++++++++--------------------------
 1 file changed, 16 insertions(+), 27 deletions(-)

diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
index 1f77cafae6..2dd0226614 100644
--- a/libavcodec/bitstream.c
+++ b/libavcodec/bitstream.c
@@ -142,21 +142,16 @@ typedef struct VLCcode {
     uint32_t code;
 } VLCcode;
 
-static int vlc_common_init(VLC *vlc_arg, int nb_bits, int nb_codes,
-                           VLC **vlc, VLC *localvlc, VLCcode **buf,
-                           int flags)
+static int vlc_common_init(VLC *vlc, int nb_bits, int nb_codes,
+                           VLCcode **buf, int flags)
 {
-    *vlc = vlc_arg;
-    (*vlc)->bits = nb_bits;
+    vlc->bits = nb_bits;
+    vlc->table_size = 0;
     if (flags & INIT_VLC_USE_NEW_STATIC) {
         av_assert0(nb_codes <= LOCALBUF_ELEMS);
-        *localvlc = *vlc_arg;
-        *vlc = localvlc;
-        (*vlc)->table_size = 0;
     } else {
-        (*vlc)->table           = NULL;
-        (*vlc)->table_allocated = 0;
-        (*vlc)->table_size      = 0;
+        vlc->table           = NULL;
+        vlc->table_allocated = 0;
     }
     if (nb_codes > LOCALBUF_ELEMS) {
         *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,
 {
     int table_size, table_index, index, code_prefix, symbol, subtable_bits;
     int i, j, k, n, nb, inc;
+    VLC_TYPE (*table)[2];
     uint32_t code;
-    volatile VLC_TYPE (* volatile table)[2]; // the double volatile is needed to prevent an internal compiler error in gcc 4.2
 
     if (table_nb_bits > 30)
        return AVERROR(EINVAL);
@@ -201,7 +196,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
     ff_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);
     if (table_index < 0)
         return table_index;
-    table = (volatile VLC_TYPE (*)[2])&vlc->table[table_index];
+    table = &vlc->table[table_index];
 
     /* first pass: map codes and compute auxiliary table sizes */
     for (i = 0; i < nb_codes; i++) {
@@ -257,7 +252,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
             if (index < 0)
                 return index;
             /* note: realloc has been done, so reload tables */
-            table = (volatile VLC_TYPE (*)[2])&vlc->table[table_index];
+            table = &vlc->table[table_index];
             table[j][0] = index; //code
             if (table[j][0] != index) {
                 avpriv_request_sample(NULL, "strange codes");
@@ -276,7 +271,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
 }
 
 static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes,
-                          int flags, VLC *vlc_arg, VLCcode localbuf[LOCALBUF_ELEMS])
+                          int flags, VLCcode localbuf[LOCALBUF_ELEMS])
 {
     int ret = build_table(vlc, nb_bits, nb_codes, codes, flags);
 
@@ -285,7 +280,6 @@ static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes,
             !(flags & (INIT_VLC_STATIC_OVERLONG & ~INIT_VLC_USE_NEW_STATIC)))
             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 {
         if (codes != localbuf)
             av_free(codes);
@@ -320,7 +314,7 @@ static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes,
    'wrap' and 'size' make it possible to use any memory configuration and types
    (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
 */
-int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes,
+int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
                        const void *bits, int bits_wrap, int bits_size,
                        const void *codes, int codes_wrap, int codes_size,
                        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,
 {
     VLCcode localbuf[LOCALBUF_ELEMS], *buf = localbuf;
     int i, j, ret;
-    VLC localvlc, *vlc;
 
-    ret = vlc_common_init(vlc_arg, nb_bits, nb_codes, &vlc, &localvlc,
-                          &buf, flags);
+    ret = vlc_common_init(vlc, nb_bits, nb_codes, &buf, flags);
     if (ret < 0)
         return ret;
 
@@ -375,21 +367,19 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes,
     nb_codes = j;
 
     return vlc_common_end(vlc, nb_bits, nb_codes, buf,
-                          flags, vlc_arg, localbuf);
+                          flags, localbuf);
 }
 
-int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes,
+int ff_init_vlc_from_lengths(VLC *vlc, int nb_bits, int nb_codes,
                              const int8_t *lens, int lens_wrap,
                              const void *symbols, int symbols_wrap, int symbols_size,
                              int offset, int flags, void *logctx)
 {
     VLCcode localbuf[LOCALBUF_ELEMS], *buf = localbuf;
-    VLC localvlc, *vlc;
     uint64_t code;
     int ret, j, len_max = FFMIN(32, 3 * nb_bits);
 
-    ret = vlc_common_init(vlc_arg, nb_bits, nb_codes, &vlc, &localvlc,
-                          &buf, flags);
+    ret = vlc_common_init(vlc, nb_bits, nb_codes, &buf, flags);
     if (ret < 0)
         return ret;
 
@@ -420,8 +410,7 @@ int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes,
             goto fail;
         }
     }
-    return vlc_common_end(vlc, nb_bits, j, buf,
-                          flags, vlc_arg, localbuf);
+    return vlc_common_end(vlc, nb_bits, j, buf, flags, localbuf);
 fail:
     if (buf != localbuf)
         av_free(buf);
-- 
2.32.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-01-05 21:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05 21:53 [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 02/10] avcodec/mpegvideo: Don't unnecessarily allocate buffers Andreas Rheinhardt
2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 03/10] avcodec/mpegvideo: Avoid macro/av_calloc for ordinary allocations Andreas Rheinhardt
2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 04/10] avcodec/h263: Move functions only used once to their caller Andreas Rheinhardt
2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 05/10] avcodec/mpeg4video: Skip unneeded element when parsing picture header Andreas Rheinhardt
2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 06/10] avcodec/mpeg4videodec: Fix data race when initializing VLCs Andreas Rheinhardt
2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 07/10] avcodec/rl: Don't pretend ff_rl_init() initializes a RLTable twice Andreas Rheinhardt
2022-01-05 21:56 ` Andreas Rheinhardt [this message]
2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 09/10] avcodec: Remove unnecessary h263.h inclusions Andreas Rheinhardt
2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 10/10] avcodec/avcodec: Remove outdated comment Andreas Rheinhardt
2022-01-05 22:21   ` Marvin Scholz
2022-01-06  7:08     ` Andreas Rheinhardt
2022-01-08 13:08 ` [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM7PR03MB6660E1AC6A3AEF53206AF01E8F4B9@AM7PR03MB6660.eurprd03.prod.outlook.com \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git