Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable
@ 2022-01-05 21:53 Andreas Rheinhardt
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 02/10] avcodec/mpegvideo: Don't unnecessarily allocate buffers Andreas Rheinhardt
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:53 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

MpegEncContext.picture_number is write-only for MPEG-1/2 decoding.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpeg12dec.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 35dfc74fe7..6ad9fb245c 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1066,7 +1066,6 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx)
 
     s2->chroma_format              = 1;
     s->mpeg_enc_ctx_allocated      = 0;
-    s->mpeg_enc_ctx.picture_number = 0;
     s->repeat_field                = 0;
     avctx->color_range             = AVCOL_RANGE_MPEG;
     return 0;
@@ -1092,9 +1091,6 @@ static int mpeg_decode_update_thread_context(AVCodecContext *avctx,
     if (!ctx->mpeg_enc_ctx_allocated)
         memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext));
 
-    if (!(s->pict_type == AV_PICTURE_TYPE_B || s->low_delay))
-        s->picture_number++;
-
     return 0;
 }
 #endif
@@ -2072,10 +2068,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
             ff_print_debug_info(s, s->current_picture_ptr, pict);
             ff_mpv_export_qp_table(s, pict, s->current_picture_ptr, FF_QSCALE_TYPE_MPEG2);
         } else {
-            if (avctx->active_thread_type & FF_THREAD_FRAME)
-                s->picture_number++;
             /* latency of 1 frame for I- and P-frames */
-            /* XXX: use another variable than picture_number */
             if (s->last_picture_ptr) {
                 int ret = av_frame_ref(pict, s->last_picture_ptr->f);
                 if (ret < 0)
-- 
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 02/10] avcodec/mpegvideo: Don't unnecessarily allocate buffers
  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 ` Andreas Rheinhardt
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 03/10] avcodec/mpegvideo: Avoid macro/av_calloc for ordinary allocations Andreas Rheinhardt
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

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

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 1c2b28f450..af433153f2 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -371,17 +371,17 @@ static int init_duplicate_context(MpegEncContext *s)
         s->pblocks[i] = &s->block[i];
     }
 
-    if (!(s->block32         = av_mallocz(sizeof(*s->block32))) ||
-        !(s->dpcm_macroblock = av_mallocz(sizeof(*s->dpcm_macroblock))))
-        return AVERROR(ENOMEM);
-    s->dpcm_direction = 0;
-
     if (s->avctx->codec_tag == AV_RL32("VCR2")) {
         // exchange uv
         FFSWAP(void *, s->pblocks[4], s->pblocks[5]);
     }
 
     if (s->out_format == FMT_H263) {
+        if (!(s->block32         = av_mallocz(sizeof(*s->block32))) ||
+            !(s->dpcm_macroblock = av_mallocz(sizeof(*s->dpcm_macroblock))))
+            return AVERROR(ENOMEM);
+        s->dpcm_direction = 0;
+
         /* ac values */
         if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base,  yc_size))
             return AVERROR(ENOMEM);
-- 
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 03/10] avcodec/mpegvideo: Avoid macro/av_calloc for ordinary allocations
  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 ` Andreas Rheinhardt
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 04/10] avcodec/h263: Move functions only used once to their caller Andreas Rheinhardt
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

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

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index af433153f2..e9f2fb212a 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -632,9 +632,9 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
 
     if (s->out_format == FMT_H263) {
         /* cbp values, cbp, ac_pred, pred_dir */
-        if (!FF_ALLOCZ_TYPED_ARRAY(s->coded_block_base, y_size + (s->mb_height&1)*2*s->b8_stride) ||
-            !FF_ALLOCZ_TYPED_ARRAY(s->cbp_table,        mb_array_size)                            ||
-            !FF_ALLOCZ_TYPED_ARRAY(s->pred_dir_table,   mb_array_size))
+        if (!(s->coded_block_base = av_mallocz(y_size + (s->mb_height&1)*2*s->b8_stride)) ||
+            !(s->cbp_table        = av_mallocz(mb_array_size)) ||
+            !(s->pred_dir_table   = av_mallocz(mb_array_size)))
             return AVERROR(ENOMEM);
         s->coded_block = s->coded_block_base + s->b8_stride + 1;
     }
@@ -652,9 +652,9 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
     }
 
     /* which mb is an intra block,  init macroblock skip table */
-    if (!FF_ALLOC_TYPED_ARRAY(s->mbintra_table, mb_array_size) ||
+    if (!(s->mbintra_table = av_mallocz(mb_array_size)) ||
         // Note the + 1 is for a quicker MPEG-4 slice_end detection
-        !FF_ALLOCZ_TYPED_ARRAY(s->mbskip_table,  mb_array_size + 2))
+        !(s->mbskip_table  = av_mallocz(mb_array_size + 2)))
         return AVERROR(ENOMEM);
     memset(s->mbintra_table, 1, mb_array_size);
 
-- 
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 04/10] avcodec/h263: Move functions only used once to their caller
  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 ` Andreas Rheinhardt
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 05/10] avcodec/mpeg4video: Skip unneeded element when parsing picture header Andreas Rheinhardt
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

In this case it means moving ff_h263_pred_dc() resp. ff_h263_pred_acdc()
to ituh263enc.c resp. ituh263dec.c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h263.c       | 128 ----------------------------------------
 libavcodec/h263.h       |   2 -
 libavcodec/ituh263dec.c |  89 +++++++++++++++++++++++++++-
 libavcodec/ituh263enc.c |  43 +++++++++++++-
 4 files changed, 130 insertions(+), 132 deletions(-)

diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index f8fba3c9f4..b30ffaf878 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -102,47 +102,6 @@ void ff_h263_update_motion_val(MpegEncContext * s){
     }
 }
 
-int ff_h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr)
-{
-    int x, y, wrap, a, c, pred_dc;
-    int16_t *dc_val;
-
-    /* find prediction */
-    if (n < 4) {
-        x = 2 * s->mb_x + (n & 1);
-        y = 2 * s->mb_y + ((n & 2) >> 1);
-        wrap = s->b8_stride;
-        dc_val = s->dc_val[0];
-    } else {
-        x = s->mb_x;
-        y = s->mb_y;
-        wrap = s->mb_stride;
-        dc_val = s->dc_val[n - 4 + 1];
-    }
-    /* B C
-     * A X
-     */
-    a = dc_val[(x - 1) + (y) * wrap];
-    c = dc_val[(x) + (y - 1) * wrap];
-
-    /* No prediction outside GOB boundary */
-    if(s->first_slice_line && n!=3){
-        if(n!=2) c= 1024;
-        if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024;
-    }
-    /* just DC prediction */
-    if (a != 1024 && c != 1024)
-        pred_dc = (a + c) >> 1;
-    else if (a != 1024)
-        pred_dc = a;
-    else
-        pred_dc = c;
-
-    /* we assume pred is positive */
-    *dc_val_ptr = &dc_val[x + y * wrap];
-    return pred_dc;
-}
-
 void ff_h263_loop_filter(MpegEncContext * s){
     int qp_c;
     const int linesize  = s->linesize;
@@ -228,93 +187,6 @@ void ff_h263_loop_filter(MpegEncContext * s){
     }
 }
 
-void ff_h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
-{
-    int x, y, wrap, a, c, pred_dc, scale, i;
-    int16_t *dc_val, *ac_val, *ac_val1;
-
-    /* find prediction */
-    if (n < 4) {
-        x = 2 * s->mb_x + (n & 1);
-        y = 2 * s->mb_y + (n>> 1);
-        wrap = s->b8_stride;
-        dc_val = s->dc_val[0];
-        ac_val = s->ac_val[0][0];
-        scale = s->y_dc_scale;
-    } else {
-        x = s->mb_x;
-        y = s->mb_y;
-        wrap = s->mb_stride;
-        dc_val = s->dc_val[n - 4 + 1];
-        ac_val = s->ac_val[n - 4 + 1][0];
-        scale = s->c_dc_scale;
-    }
-
-    ac_val += ((y) * wrap + (x)) * 16;
-    ac_val1 = ac_val;
-
-    /* B C
-     * A X
-     */
-    a = dc_val[(x - 1) + (y) * wrap];
-    c = dc_val[(x) + (y - 1) * wrap];
-
-    /* No prediction outside GOB boundary */
-    if(s->first_slice_line && n!=3){
-        if(n!=2) c= 1024;
-        if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024;
-    }
-
-    if (s->ac_pred) {
-        pred_dc = 1024;
-        if (s->h263_aic_dir) {
-            /* left prediction */
-            if (a != 1024) {
-                ac_val -= 16;
-                for(i=1;i<8;i++) {
-                    block[s->idsp.idct_permutation[i << 3]] += ac_val[i];
-                }
-                pred_dc = a;
-            }
-        } else {
-            /* top prediction */
-            if (c != 1024) {
-                ac_val -= 16 * wrap;
-                for(i=1;i<8;i++) {
-                    block[s->idsp.idct_permutation[i]] += ac_val[i + 8];
-                }
-                pred_dc = c;
-            }
-        }
-    } else {
-        /* just DC prediction */
-        if (a != 1024 && c != 1024)
-            pred_dc = (a + c) >> 1;
-        else if (a != 1024)
-            pred_dc = a;
-        else
-            pred_dc = c;
-    }
-
-    /* we assume pred is positive */
-    block[0]=block[0]*scale + pred_dc;
-
-    if (block[0] < 0)
-        block[0] = 0;
-    else
-        block[0] |= 1;
-
-    /* Update AC/DC tables */
-    dc_val[(x) + (y) * wrap] = block[0];
-
-    /* left copy */
-    for(i=1;i<8;i++)
-        ac_val1[i]     = block[s->idsp.idct_permutation[i << 3]];
-    /* top copy */
-    for(i=1;i<8;i++)
-        ac_val1[8 + i] = block[s->idsp.idct_permutation[i]];
-}
-
 int16_t *ff_h263_pred_motion(MpegEncContext * s, int block, int dir,
                              int *px, int *py)
 {
diff --git a/libavcodec/h263.h b/libavcodec/h263.h
index 84a3a19517..982e545491 100644
--- a/libavcodec/h263.h
+++ b/libavcodec/h263.h
@@ -74,8 +74,6 @@ void ff_h263_loop_filter(MpegEncContext * s);
 int ff_h263_decode_mba(MpegEncContext *s);
 void ff_h263_encode_mba(MpegEncContext *s);
 void ff_init_qscale_tab(MpegEncContext *s);
-int ff_h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr);
-void ff_h263_pred_acdc(MpegEncContext * s, int16_t *block, int n);
 
 
 /**
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 3f982f414f..17af5d7f89 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -439,6 +439,93 @@ static void h263_decode_dquant(MpegEncContext *s){
     ff_set_qscale(s, s->qscale);
 }
 
+static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
+{
+    int x, y, wrap, a, c, pred_dc, scale;
+    int16_t *dc_val, *ac_val, *ac_val1;
+
+    /* find prediction */
+    if (n < 4) {
+        x = 2 * s->mb_x + (n & 1);
+        y = 2 * s->mb_y + (n>> 1);
+        wrap = s->b8_stride;
+        dc_val = s->dc_val[0];
+        ac_val = s->ac_val[0][0];
+        scale = s->y_dc_scale;
+    } else {
+        x = s->mb_x;
+        y = s->mb_y;
+        wrap = s->mb_stride;
+        dc_val = s->dc_val[n - 4 + 1];
+        ac_val = s->ac_val[n - 4 + 1][0];
+        scale = s->c_dc_scale;
+    }
+
+    ac_val += ((y) * wrap + (x)) * 16;
+    ac_val1 = ac_val;
+
+    /* B C
+     * A X
+     */
+    a = dc_val[(x - 1) + (y) * wrap];
+    c = dc_val[(x) + (y - 1) * wrap];
+
+    /* No prediction outside GOB boundary */
+    if (s->first_slice_line && n != 3) {
+        if (n != 2) c= 1024;
+        if (n != 1 && s->mb_x == s->resync_mb_x) a= 1024;
+    }
+
+    if (s->ac_pred) {
+        pred_dc = 1024;
+        if (s->h263_aic_dir) {
+            /* left prediction */
+            if (a != 1024) {
+                ac_val -= 16;
+                for (int i = 1; i < 8; i++) {
+                    block[s->idsp.idct_permutation[i << 3]] += ac_val[i];
+                }
+                pred_dc = a;
+            }
+        } else {
+            /* top prediction */
+            if (c != 1024) {
+                ac_val -= 16 * wrap;
+                for (int i = 1; i < 8; i++) {
+                    block[s->idsp.idct_permutation[i]] += ac_val[i + 8];
+                }
+                pred_dc = c;
+            }
+        }
+    } else {
+        /* just DC prediction */
+        if (a != 1024 && c != 1024)
+            pred_dc = (a + c) >> 1;
+        else if (a != 1024)
+            pred_dc = a;
+        else
+            pred_dc = c;
+    }
+
+    /* we assume pred is positive */
+    block[0] = block[0] * scale + pred_dc;
+
+    if (block[0] < 0)
+        block[0] = 0;
+    else
+        block[0] |= 1;
+
+    /* Update AC/DC tables */
+    dc_val[(x) + (y) * wrap] = block[0];
+
+    /* left copy */
+    for (int i = 1; i < 8; i++)
+        ac_val1[i]     = block[s->idsp.idct_permutation[i << 3]];
+    /* top copy */
+    for (int i = 1; i < 8; i++)
+        ac_val1[8 + i] = block[s->idsp.idct_permutation[i]];
+}
+
 static int h263_decode_block(MpegEncContext * s, int16_t * block,
                              int n, int coded)
 {
@@ -579,7 +666,7 @@ retry:
     }
 not_coded:
     if (s->mb_intra && s->h263_aic) {
-        ff_h263_pred_acdc(s, block, n);
+        h263_pred_acdc(s, block, n);
         i = 63;
     }
     s->block_last_index[n] = i;
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 79c8c9999e..d944c4879f 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -445,6 +445,47 @@ static void h263p_encode_umotion(PutBitContext *pb, int val)
     }
 }
 
+static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr)
+{
+    int x, y, wrap, a, c, pred_dc;
+    int16_t *dc_val;
+
+    /* find prediction */
+    if (n < 4) {
+        x = 2 * s->mb_x + (n & 1);
+        y = 2 * s->mb_y + ((n & 2) >> 1);
+        wrap = s->b8_stride;
+        dc_val = s->dc_val[0];
+    } else {
+        x = s->mb_x;
+        y = s->mb_y;
+        wrap = s->mb_stride;
+        dc_val = s->dc_val[n - 4 + 1];
+    }
+    /* B C
+     * A X
+     */
+    a = dc_val[(x - 1) + (y) * wrap];
+    c = dc_val[(x) + (y - 1) * wrap];
+
+    /* No prediction outside GOB boundary */
+    if (s->first_slice_line && n != 3) {
+        if (n != 2) c = 1024;
+        if (n != 1 && s->mb_x == s->resync_mb_x) a = 1024;
+    }
+    /* just DC prediction */
+    if (a != 1024 && c != 1024)
+        pred_dc = (a + c) >> 1;
+    else if (a != 1024)
+        pred_dc = a;
+    else
+        pred_dc = c;
+
+    /* we assume pred is positive */
+    *dc_val_ptr = &dc_val[x + y * wrap];
+    return pred_dc;
+}
+
 void ff_h263_encode_mb(MpegEncContext * s,
                        int16_t block[6][64],
                        int motion_x, int motion_y)
@@ -552,7 +593,7 @@ void ff_h263_encode_mb(MpegEncContext * s,
                 if(i<4) scale= s->y_dc_scale;
                 else    scale= s->c_dc_scale;
 
-                pred_dc = ff_h263_pred_dc(s, i, &dc_ptr[i]);
+                pred_dc = h263_pred_dc(s, i, &dc_ptr[i]);
                 level -= pred_dc;
                 /* Quant */
                 if (level >= 0)
-- 
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 05/10] avcodec/mpeg4video: Skip unneeded element when parsing picture header
  2022-01-05 21:53 [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
                   ` (2 preceding siblings ...)
  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 ` Andreas Rheinhardt
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 06/10] avcodec/mpeg4videodec: Fix data race when initializing VLCs Andreas Rheinhardt
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Namely, skip some elements that are only useful for a decoder
when calling ff_mpeg4_decode_picture_header() from the MPEG-4 parser.

In particular, this ensures that the VLCs need no longer be
initialized by the parser.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h263dec.c           |  4 ++--
 libavcodec/mpeg4video.h        |  3 ++-
 libavcodec/mpeg4video_parser.c |  4 ++--
 libavcodec/mpeg4videodec.c     | 18 +++++++++++++++---
 4 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 2682a7f43a..11e80cb9e9 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -507,9 +507,9 @@ retry:
             GetBitContext gb;
 
             if (init_get_bits8(&gb, s->avctx->extradata, s->avctx->extradata_size) >= 0 )
-                ff_mpeg4_decode_picture_header(avctx->priv_data, &gb, 1);
+                ff_mpeg4_decode_picture_header(avctx->priv_data, &gb, 1, 0);
         }
-        ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb, 0);
+        ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb, 0, 0);
     } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {
         ret = ff_intel_h263_decode_picture_header(s);
     } else if (CONFIG_FLV_DECODER && s->h263_flv) {
diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index 3db6f85153..ee8eea7121 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -160,7 +160,8 @@ void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n,
 void ff_set_mpeg4_time(MpegEncContext *s);
 int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
 
-int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header);
+int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
+                                   int header, int parse_only);
 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
 void ff_mpeg4_clean_buffers(MpegEncContext *s);
 void ff_mpeg4_stuffing(PutBitContext *pbc);
diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c
index c68c966259..9e96619a12 100644
--- a/libavcodec/mpeg4video_parser.c
+++ b/libavcodec/mpeg4video_parser.c
@@ -100,13 +100,13 @@ static int mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx,
 
     if (avctx->extradata_size && pc->first_picture) {
         init_get_bits(gb, avctx->extradata, avctx->extradata_size * 8);
-        ret = ff_mpeg4_decode_picture_header(dec_ctx, gb, 1);
+        ret = ff_mpeg4_decode_picture_header(dec_ctx, gb, 1, 1);
         if (ret < 0)
             av_log(avctx, AV_LOG_WARNING, "Failed to parse extradata\n");
     }
 
     init_get_bits(gb, buf, 8 * buf_size);
-    ret = ff_mpeg4_decode_picture_header(dec_ctx, gb, 0);
+    ret = ff_mpeg4_decode_picture_header(dec_ctx, gb, 0, 1);
     if (s->width && (!avctx->width || !avctx->height ||
                      !avctx->coded_width || !avctx->coded_height)) {
         ret = ff_set_dimensions(avctx, s->width, s->height);
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 34b050db28..ab8d2e8236 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -2844,7 +2844,8 @@ int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
     return 0;
 }
 
-static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
+static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
+                             int parse_only)
 {
     MpegEncContext *s = &ctx->m;
     int time_incr, time_increment;
@@ -3018,6 +3019,12 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
         ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
     }
 
+    /* Skip at this point when only parsing since the remaining
+     * data is not useful for a parser and requires the
+     * sprite_trajectory VLC to be initialized. */
+    if (parse_only)
+        goto end;
+
     if (s->pict_type == AV_PICTURE_TYPE_S) {
         if((ctx->vol_sprite_usage == STATIC_SPRITE ||
             ctx->vol_sprite_usage == GMC_SPRITE)) {
@@ -3095,6 +3102,8 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
             skip_bits(gb, 2);  // ref_select_code
         }
     }
+
+end:
     /* detect buggy encoders which don't set the low_delay flag
      * (divx4/xvid/opendivx). Note we cannot detect divx5 without B-frames
      * easily (although it's buggy too) */
@@ -3214,11 +3223,14 @@ static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb)
  * Decode MPEG-4 headers.
  *
  * @param  header If set the absence of a VOP is not treated as error; otherwise, it is treated as such.
+ * @param  parse_only If set, things only relevant to a decoder may be skipped;
+ *                    furthermore, the VLC tables may be uninitialized.
  * @return <0 if an error occurred
  *         FRAME_SKIPPED if a not coded VOP is found
  *         0 else
  */
-int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header)
+int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
+                                   int header, int parse_only)
 {
     MpegEncContext *s = &ctx->m;
     unsigned startcode, v;
@@ -3371,7 +3383,7 @@ end:
         }
         return decode_studio_vop_header(ctx, gb);
     } else
-        return decode_vop_header(ctx, gb);
+        return decode_vop_header(ctx, gb, parse_only);
 }
 
 av_cold void ff_mpeg4videodec_static_init(void) {
-- 
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 06/10] avcodec/mpeg4videodec: Fix data race when initializing VLCs
  2022-01-05 21:53 [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
                   ` (3 preceding siblings ...)
  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 ` 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
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Both the MPEG-4 parser as well as the decoder initialized
several VLCs. There is a "static int done = 0;" in order to
guard against initializing these multiple times, but this does
not work when several threads try to initialize these VLCs
concurrently, which can happen when initializing several parsers
at the same time (they don't use the global lock that is used
for codecs without the FF_CODEC_CAP_INIT_THREADSAFE cap; actually,
they don't use any lock at all).

Since ff_mpeg4_decode_picture_header() now aborts early when called
from the parser, it no longer needs to have these VLCs initialized
at all. This commit therefore does exactly this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpeg4video.h        |  1 -
 libavcodec/mpeg4video_parser.c |  2 --
 libavcodec/mpeg4videodec.c     | 50 ++++++++++++++--------------------
 3 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index ee8eea7121..cec8b30c32 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -173,7 +173,6 @@ int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
 int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx);
 int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx);
 void ff_mpeg4_init_direct_mv(MpegEncContext *s);
-void ff_mpeg4videodec_static_init(void);
 int ff_mpeg4_workaround_bugs(AVCodecContext *avctx);
 int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
 
diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c
index 9e96619a12..1f89bae490 100644
--- a/libavcodec/mpeg4video_parser.c
+++ b/libavcodec/mpeg4video_parser.c
@@ -129,8 +129,6 @@ static av_cold int mpeg4video_parse_init(AVCodecParserContext *s)
 {
     struct Mp4vParseContext *pc = s->priv_data;
 
-    ff_mpeg4videodec_static_init();
-
     pc->first_picture           = 1;
     pc->dec_ctx.m.quant_precision     = 5;
     pc->dec_ctx.m.slice_context_count = 1;
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index ab8d2e8236..325593a795 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3386,34 +3386,6 @@ end:
         return decode_vop_header(ctx, gb, parse_only);
 }
 
-av_cold void ff_mpeg4videodec_static_init(void) {
-    static int done = 0;
-
-    if (!done) {
-        static uint8_t mpeg4_rvlc_rl_tables[2][2][2 * MAX_RUN + MAX_LEVEL + 3];
-
-        ff_mpeg4_init_rl_intra();
-        ff_rl_init(&ff_rvlc_rl_inter, mpeg4_rvlc_rl_tables[0]);
-        ff_rl_init(&ff_rvlc_rl_intra, mpeg4_rvlc_rl_tables[1]);
-        INIT_FIRST_VLC_RL(ff_mpeg4_rl_intra, 554);
-        INIT_VLC_RL(ff_rvlc_rl_inter, 1072);
-        INIT_FIRST_VLC_RL(ff_rvlc_rl_intra, 1072);
-        INIT_VLC_STATIC(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
-                        &ff_mpeg4_DCtab_lum[0][1], 2, 1,
-                        &ff_mpeg4_DCtab_lum[0][0], 2, 1, 512);
-        INIT_VLC_STATIC(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
-                        &ff_mpeg4_DCtab_chrom[0][1], 2, 1,
-                        &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 512);
-        INIT_VLC_STATIC_FROM_LENGTHS(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
-                                     ff_sprite_trajectory_lens, 1,
-                                     NULL, 0, 0, 0, 0, 128);
-        INIT_VLC_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
-                        &ff_mb_type_b_tab[0][1], 2, 1,
-                        &ff_mb_type_b_tab[0][0], 2, 1, 16);
-        done = 1;
-    }
-}
-
 int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
 {
     Mpeg4DecContext *ctx = avctx->priv_data;
@@ -3525,6 +3497,8 @@ static int mpeg4_update_thread_context_for_user(AVCodecContext *dst,
 
 static av_cold void mpeg4_init_static(void)
 {
+    static uint8_t mpeg4_rvlc_rl_tables[2][2][2 * MAX_RUN + MAX_LEVEL + 3];
+
     INIT_VLC_STATIC_FROM_LENGTHS(&studio_luma_dc, STUDIO_INTRA_BITS, 19,
                                  &ff_mpeg4_studio_dc_luma[0][1], 2,
                                  &ff_mpeg4_studio_dc_luma[0][0], 2, 1,
@@ -3547,7 +3521,25 @@ static av_cold void mpeg4_init_static(void)
                                  0, INIT_VLC_STATIC_OVERLONG, NULL);
         offset += studio_intra_tab[i].table_size;
     }
-    ff_mpeg4videodec_static_init();
+
+    ff_mpeg4_init_rl_intra();
+    ff_rl_init(&ff_rvlc_rl_inter, mpeg4_rvlc_rl_tables[0]);
+    ff_rl_init(&ff_rvlc_rl_intra, mpeg4_rvlc_rl_tables[1]);
+    INIT_FIRST_VLC_RL(ff_mpeg4_rl_intra, 554);
+    INIT_VLC_RL(ff_rvlc_rl_inter, 1072);
+    INIT_FIRST_VLC_RL(ff_rvlc_rl_intra, 1072);
+    INIT_VLC_STATIC(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
+                    &ff_mpeg4_DCtab_lum[0][1], 2, 1,
+                    &ff_mpeg4_DCtab_lum[0][0], 2, 1, 512);
+    INIT_VLC_STATIC(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
+                    &ff_mpeg4_DCtab_chrom[0][1], 2, 1,
+                    &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 512);
+    INIT_VLC_STATIC_FROM_LENGTHS(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
+                                 ff_sprite_trajectory_lens, 1,
+                                 NULL, 0, 0, 0, 0, 128);
+    INIT_VLC_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
+                    &ff_mb_type_b_tab[0][1], 2, 1,
+                    &ff_mb_type_b_tab[0][0], 2, 1, 16);
 }
 
 static av_cold int decode_init(AVCodecContext *avctx)
-- 
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 07/10] avcodec/rl: Don't pretend ff_rl_init() initializes a RLTable twice
  2022-01-05 21:53 [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
                   ` (4 preceding siblings ...)
  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 ` Andreas Rheinhardt
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 08/10] avcodec/bitstream: Don't pretend VLCs to be initialized concurrently Andreas Rheinhardt
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

It can't any longer, because all users of ff_rl_init() are now
behind ff_thread_once() or the global codec lock. Therefore
the check for whether the RLTable is already initialized can be removed;
as can the stack buffers that existed to make sure that nothing is ever
set to a value different from its final value.
Similarly, it is not necessary to check whether the VLCs associated
with the RLTable are already initialized (they aren't).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/rl.c | 20 ++++++--------------
 libavcodec/rl.h |  9 +++------
 2 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/libavcodec/rl.c b/libavcodec/rl.c
index fab96d63a1..4ce003ccf4 100644
--- a/libavcodec/rl.c
+++ b/libavcodec/rl.c
@@ -27,16 +27,13 @@
 av_cold void ff_rl_init(RLTable *rl,
                         uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3])
 {
-    int8_t  max_level[MAX_RUN + 1], max_run[MAX_LEVEL + 1];
-    uint8_t index_run[MAX_RUN + 1];
     int last, run, level, start, end, i;
 
-    /* If rl->max_level[0] is set, this RLTable has already been initialized */
-    if (rl->max_level[0])
-        return;
-
     /* compute max_level[], max_run[] and index_run[] */
     for (last = 0; last < 2; last++) {
+        int8_t *max_level  = static_store[last];
+        int8_t *max_run    = static_store[last] + MAX_RUN + 1;
+        uint8_t *index_run = static_store[last] + MAX_RUN + 1 + MAX_LEVEL + 1;
         if (last == 0) {
             start = 0;
             end = rl->last;
@@ -45,8 +42,6 @@ av_cold void ff_rl_init(RLTable *rl,
             end = rl->n;
         }
 
-        memset(max_level, 0, MAX_RUN + 1);
-        memset(max_run, 0, MAX_LEVEL + 1);
         memset(index_run, rl->n, MAX_RUN + 1);
         for (i = start; i < end; i++) {
             run   = rl->table_run[i];
@@ -58,12 +53,9 @@ av_cold void ff_rl_init(RLTable *rl,
             if (run > max_run[level])
                 max_run[level] = run;
         }
-        rl->max_level[last] = static_store[last];
-        memcpy(rl->max_level[last], max_level, MAX_RUN + 1);
-        rl->max_run[last]   = static_store[last] + MAX_RUN + 1;
-        memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);
-        rl->index_run[last] = static_store[last] + MAX_RUN + MAX_LEVEL + 2;
-        memcpy(rl->index_run[last], index_run, MAX_RUN + 1);
+        rl->max_level[last] = max_level;
+        rl->max_run[last]   = max_run;
+        rl->index_run[last] = index_run;
     }
 }
 
diff --git a/libavcodec/rl.h b/libavcodec/rl.h
index 5aae698e31..07e3da5003 100644
--- a/libavcodec/rl.h
+++ b/libavcodec/rl.h
@@ -72,15 +72,12 @@ void ff_rl_init_vlc(RLTable *rl, unsigned static_size);
 
 #define INIT_VLC_RL(rl, static_size)\
 {\
-    int q;\
     static RL_VLC_ELEM rl_vlc_table[32][static_size];\
 \
-    if(!rl.rl_vlc[0]){\
-        for(q=0; q<32; q++)\
-            rl.rl_vlc[q]= rl_vlc_table[q];\
+    for (int q = 0; q < 32; q++) \
+        rl.rl_vlc[q] = rl_vlc_table[q]; \
 \
-        ff_rl_init_vlc(&rl, static_size);\
-    }\
+    ff_rl_init_vlc(&rl, static_size); \
 }
 
 #define INIT_FIRST_VLC_RL(rl, static_size)              \
-- 
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 08/10] avcodec/bitstream: Don't pretend VLCs to be initialized concurrently
  2022-01-05 21:53 [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
                   ` (5 preceding siblings ...)
  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
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 09/10] avcodec: Remove unnecessary h263.h inclusions Andreas Rheinhardt
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 09/10] avcodec: Remove unnecessary h263.h inclusions
  2022-01-05 21:53 [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
                   ` (6 preceding siblings ...)
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 08/10] avcodec/bitstream: Don't pretend VLCs to be initialized concurrently Andreas Rheinhardt
@ 2022-01-05 21:56 ` Andreas Rheinhardt
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 10/10] avcodec/avcodec: Remove outdated comment Andreas Rheinhardt
  2022-01-08 13:08 ` [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
  9 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/flvenc.c      | 1 -
 libavcodec/h261dec.c     | 1 -
 libavcodec/h261enc.c     | 1 -
 libavcodec/msmpeg4.c     | 1 -
 libavcodec/msmpeg4data.c | 2 +-
 libavcodec/snow.c        | 1 -
 libavcodec/snowdec.c     | 2 --
 libavcodec/svq1dec.c     | 2 +-
 8 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index 614ef20243..158b399c40 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -19,7 +19,6 @@
  */
 
 #include "flv.h"
-#include "h263.h"
 #include "h263data.h"
 #include "mpegvideo.h"
 #include "mpegvideodata.h"
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 80ec1c8814..2fd8d94df1 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -31,7 +31,6 @@
 #include "mpeg_er.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
-#include "h263.h"
 #include "h261.h"
 #include "internal.h"
 
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 79f680f81d..af65c1f3b1 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -31,7 +31,6 @@
 #include "avcodec.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
-#include "h263.h"
 #include "h261.h"
 #include "mpegvideodata.h"
 
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 16b6f18950..e76aec6dfc 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -34,7 +34,6 @@
 #include "mpegvideo.h"
 #include "msmpeg4.h"
 #include "libavutil/x86/asm.h"
-#include "h263.h"
 #include "mpeg4video.h"
 #include "msmpeg4data.h"
 #include "mpegvideodata.h"
diff --git a/libavcodec/msmpeg4data.c b/libavcodec/msmpeg4data.c
index 890aeb5670..a3a8144664 100644
--- a/libavcodec/msmpeg4data.c
+++ b/libavcodec/msmpeg4data.c
@@ -27,7 +27,7 @@
  * MSMPEG4 data tables.
  */
 
-#include "h263.h"
+#include "h263data.h"
 #include "mpeg4video.h"
 #include "msmpeg4data.h"
 
diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index e0fb58042c..0a500695ce 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -31,7 +31,6 @@
 
 #include "rangecoder.h"
 #include "mathops.h"
-#include "h263.h"
 
 
 void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h,
diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index cd2265aba1..d54036e02b 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -29,8 +29,6 @@
 #include "rangecoder.h"
 #include "mathops.h"
 
-#include "h263.h"
-
 static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, IDWTELEM * old_buffer, int plane_index, int add, int mb_y){
     Plane *p= &s->plane[plane_index];
     const int mb_w= s->b_width  << s->block_max_depth;
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index a67d1866b6..a2b3f71c07 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -37,7 +37,7 @@
 
 #include "avcodec.h"
 #include "get_bits.h"
-#include "h263.h"
+#include "h263data.h"
 #include "hpeldsp.h"
 #include "internal.h"
 #include "mathops.h"
-- 
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 10/10] avcodec/avcodec: Remove outdated comment
  2022-01-05 21:53 [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
                   ` (7 preceding siblings ...)
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 09/10] avcodec: Remove unnecessary h263.h inclusions Andreas Rheinhardt
@ 2022-01-05 21:56 ` Andreas Rheinhardt
  2022-01-05 22:21   ` Marvin Scholz
  2022-01-08 13:08 ` [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
  9 siblings, 1 reply; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-05 21:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

avcodec_open2() is supposed to be thread-safe (those codecs
whose init functions are not thread-safe are guarded
by a global lock).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/avcodec.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7ee8bc2b7c..ec1a0566a4 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2384,8 +2384,6 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
  * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  * retrieving a codec.
  *
- * @warning This function is not thread safe!
- *
  * @note Always call this function before using decoding routines (such as
  * @ref avcodec_receive_frame()).
  *
-- 
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 10/10] avcodec/avcodec: Remove outdated comment
  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
  0 siblings, 1 reply; 13+ messages in thread
From: Marvin Scholz @ 2022-01-05 22:21 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On 5 Jan 2022, at 22:56, Andreas Rheinhardt wrote:

> avcodec_open2() is supposed to be thread-safe (those codecs
> whose init functions are not thread-safe are guarded
> by a global lock).
>

Maybe it would be better to note since which version this is
the case, or at least mention it in the api changelog?

> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/avcodec.h | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 7ee8bc2b7c..ec1a0566a4 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -2384,8 +2384,6 @@ int avcodec_parameters_to_context(AVCodecContext 
> *codec,
>   * avcodec_find_decoder() and avcodec_find_encoder() provide an easy 
> way for
>   * retrieving a codec.
>   *
> - * @warning This function is not thread safe!
> - *
>   * @note Always call this function before using decoding routines 
> (such as
>   * @ref avcodec_receive_frame()).
>   *
> -- 
> 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".
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 10/10] avcodec/avcodec: Remove outdated comment
  2022-01-05 22:21   ` Marvin Scholz
@ 2022-01-06  7:08     ` Andreas Rheinhardt
  0 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-06  7:08 UTC (permalink / raw)
  To: ffmpeg-devel

Marvin Scholz:
> 
> 
> On 5 Jan 2022, at 22:56, Andreas Rheinhardt wrote:
> 
>> avcodec_open2() is supposed to be thread-safe (those codecs
>> whose init functions are not thread-safe are guarded
>> by a global lock).
>>
> 
> Maybe it would be better to note since which version this is
> the case, or at least mention it in the api changelog?
> 

There can be a data race with current git master if an mpeg4 decoder is
opened concurrently with an mpeg4-parser. This is fixed in patch #6 of
this patchset.
(Actually, avcodec_open2() is supposed to be thread-safe since the
introduction of the global lock, yet in practice there were several
issues with this; one of this is fixed in #6. Other issues were that the
AAC codecs claimed to be init-threadsafe, yet weren't for a long time
(see 195d8ce85eb73ff283f85dcee63383ec4081e3e7).)

>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/avcodec.h | 2 --
>>  1 file changed, 2 deletions(-)
>>
>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>> index 7ee8bc2b7c..ec1a0566a4 100644
>> --- a/libavcodec/avcodec.h
>> +++ b/libavcodec/avcodec.h
>> @@ -2384,8 +2384,6 @@ int avcodec_parameters_to_context(AVCodecContext
>> *codec,
>>   * avcodec_find_decoder() and avcodec_find_encoder() provide an easy
>> way for
>>   * retrieving a codec.
>>   *
>> - * @warning This function is not thread safe!
>> - *
>>   * @note Always call this function before using decoding routines
>> (such as
>>   * @ref avcodec_receive_frame()).
>>   *
>> -- 
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable
  2022-01-05 21:53 [FFmpeg-devel] [PATCH 01/10] avcodec/mpeg12dec: Don't set write-only variable Andreas Rheinhardt
                   ` (8 preceding siblings ...)
  2022-01-05 21:56 ` [FFmpeg-devel] [PATCH 10/10] avcodec/avcodec: Remove outdated comment Andreas Rheinhardt
@ 2022-01-08 13:08 ` Andreas Rheinhardt
  9 siblings, 0 replies; 13+ messages in thread
From: Andreas Rheinhardt @ 2022-01-08 13:08 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> MpegEncContext.picture_number is write-only for MPEG-1/2 decoding.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/mpeg12dec.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
> index 35dfc74fe7..6ad9fb245c 100644
> --- a/libavcodec/mpeg12dec.c
> +++ b/libavcodec/mpeg12dec.c
> @@ -1066,7 +1066,6 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx)
>  
>      s2->chroma_format              = 1;
>      s->mpeg_enc_ctx_allocated      = 0;
> -    s->mpeg_enc_ctx.picture_number = 0;
>      s->repeat_field                = 0;
>      avctx->color_range             = AVCOL_RANGE_MPEG;
>      return 0;
> @@ -1092,9 +1091,6 @@ static int mpeg_decode_update_thread_context(AVCodecContext *avctx,
>      if (!ctx->mpeg_enc_ctx_allocated)
>          memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext));
>  
> -    if (!(s->pict_type == AV_PICTURE_TYPE_B || s->low_delay))
> -        s->picture_number++;
> -
>      return 0;
>  }
>  #endif
> @@ -2072,10 +2068,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
>              ff_print_debug_info(s, s->current_picture_ptr, pict);
>              ff_mpv_export_qp_table(s, pict, s->current_picture_ptr, FF_QSCALE_TYPE_MPEG2);
>          } else {
> -            if (avctx->active_thread_type & FF_THREAD_FRAME)
> -                s->picture_number++;
>              /* latency of 1 frame for I- and P-frames */
> -            /* XXX: use another variable than picture_number */
>              if (s->last_picture_ptr) {
>                  int ret = av_frame_ref(pict, s->last_picture_ptr->f);
>                  if (ret < 0)
> 

Will apply this patchset tomorrow unless there are objections.

- Andreas
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-01-08 13:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [FFmpeg-devel] [PATCH 08/10] avcodec/bitstream: Don't pretend VLCs to be initialized concurrently Andreas Rheinhardt
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

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