[FFmpeg-devel] [PATCH v2 60/69] avcodec/mpegvideo: Move slice_context_count to MPVMainContext

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Feb 1 15:06:57 EET 2022


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/mjpegenc.c          |  6 +++---
 libavcodec/mpeg12dec.c         |  4 ++--
 libavcodec/mpeg4video_parser.c |  2 +-
 libavcodec/mpegvideo.c         | 13 ++++++-------
 libavcodec/mpegvideo.h         |  3 ++-
 libavcodec/mpegvideo_enc.c     |  8 ++++----
 libavcodec/vc1_parser.c        |  2 +-
 7 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 70636ffc91..bf6371768a 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -82,10 +82,10 @@ static void mjpeg_encode_picture_header(MPVMainEncContext *m)
     ff_mjpeg_encode_picture_header(s->avctx, &s->pb, s->mjpeg_ctx,
                                    &s->intra_scantable, 0,
                                    s->intra_matrix, s->chroma_intra_matrix,
-                                   s->slice_context_count > 1);
+                                   m2->slice_context_count > 1);
 
     s->esc_pos = put_bytes_count(&s->pb, 0);
-    for (int i = 1; i < s->slice_context_count; i++)
+    for (int i = 1; i < m2->slice_context_count; i++)
         m2->thread_context[i]->esc_pos = 0;
 }
 
@@ -255,7 +255,7 @@ int ff_mjpeg_encode_stuffing(MPVEncContext *s)
 
     ff_mjpeg_escape_FF(pbc, s->esc_pos);
 
-    if (s->slice_context_count > 1 && mb_y < s->mb_height - 1)
+    if (s->parent_ctx->slice_context_count > 1 && mb_y < s->mb_height - 1)
         put_marker(pbc, RST0 + (mb_y&7));
     s->esc_pos = put_bytes_count(pbc, 0);
 
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 925c72e8ff..69d0bb809b 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -2770,8 +2770,8 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
                     (avctx->active_thread_type & FF_THREAD_SLICE) &&
                     !avctx->hwaccel) {
                     int threshold = (s2->mb_height * s->slice_count +
-                                     s2->slice_context_count / 2) /
-                                    s2->slice_context_count;
+                                     m2->slice_context_count / 2) /
+                                    m2->slice_context_count;
                     av_assert0(avctx->thread_count > 1);
                     if (threshold <= mb_y) {
                         MPVDecContext *const thread_context = m2->thread_context[s->slice_count];
diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c
index adc2409953..a7909d92ec 100644
--- a/libavcodec/mpeg4video_parser.c
+++ b/libavcodec/mpeg4video_parser.c
@@ -132,7 +132,7 @@ static av_cold int mpeg4video_parse_init(AVCodecParserContext *s)
 
     pc->first_picture           = 1;
     pc->dec_ctx.m.s.quant_precision     = 5;
-    pc->dec_ctx.m.s.slice_context_count = 1;
+    pc->dec_ctx.m.slice_context_count = 1;
     pc->dec_ctx.showed_packed_warning = 1;
     return 0;
 }
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 4b22eb746a..0e98680056 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -394,7 +394,7 @@ static int init_duplicate_context(MPVContext *s)
 int ff_mpv_init_duplicate_contexts(MPVMainContext *m)
 {
     MPVContext *const s = &m->s;
-    int nb_slices = s->slice_context_count, ret;
+    int nb_slices = m->slice_context_count, ret;
 
     s->parent_ctx = m;
 
@@ -443,7 +443,7 @@ static void free_duplicate_contexts(MPVMainContext *m)
 {
     MPVContext *const s = &m->s;
 
-    for (int i = 1; i < s->slice_context_count; i++) {
+    for (int i = 1; i < m->slice_context_count; i++) {
         free_duplicate_context(m->thread_context[i]);
         av_freep(&m->thread_context[i]);
     }
@@ -525,7 +525,7 @@ void ff_mpv_common_defaults(MPVMainContext *m)
     s->f_code                = 1;
     s->b_code                = 1;
 
-    s->slice_context_count   = 1;
+    m->slice_context_count   = 1;
     s->parent_ctx            = m;
 }
 
@@ -625,7 +625,6 @@ static void clear_context(MPVMainContext *m)
     memset(&s->current_picture, 0, sizeof(s->current_picture));
     memset(&s->new_picture, 0, sizeof(s->new_picture));
 
-    s->slice_context_count = 1;
     s->me.map = NULL;
     s->me.score_map = NULL;
     s->dct_error_sum = NULL;
@@ -740,7 +739,7 @@ av_cold int ff_mpv_common_init(MPVMainContext *m)
 
     s->context_initialized = 1;
     m->thread_context[0]   = s;
-    s->slice_context_count = nb_slices;
+    m->slice_context_count = nb_slices;
 
 //     if (s->width && s->height) {
     ret = ff_mpv_init_duplicate_contexts(m);
@@ -791,8 +790,8 @@ void ff_mpv_common_end(MPVMainContext *m)
     s = &m->s;
 
     ff_mpv_free_context_frame(m);
-    if (s->slice_context_count > 1)
-        s->slice_context_count = 1;
+    if (m->slice_context_count > 1)
+        m->slice_context_count = 1;
 
 #if FF_API_FLAG_TRUNCATED
     av_freep(&s->parse_context.buffer);
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 1c44e9be2f..4a03cde7fe 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -122,7 +122,6 @@ typedef struct MPVContext {
 
     int start_mb_y;            ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
     int end_mb_y;              ///< end   mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
-    int slice_context_count;   ///< number of used thread_contexts
 
     /**
      * copy of the previous picture structure.
@@ -507,6 +506,8 @@ typedef struct MPVContext {
  */
 typedef struct MPVMainContext {
     MPVContext s;
+
+    int slice_context_count;   ///< number of used thread_contexts
     /* The first entry of this array points to the above MPVContext. */
     MPVContext *thread_context[MAX_THREADS];
 } MPVMainContext;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 735c9d322f..aef4de0fe6 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -885,7 +885,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
     if ((CONFIG_H263P_ENCODER || CONFIG_RV20_ENCODER) && s->modified_quant)
         s->chroma_qscale_table = ff_h263_chroma_qscale_table;
 
-    if (s->slice_context_count > 1) {
+    if (m2->slice_context_count > 1) {
         s->rtp_mode = 1;
 
         if (avctx->codec_id == AV_CODEC_ID_H263P)
@@ -1749,7 +1749,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
     MPVMainContext *const m2 = &m->common;
     MPVEncContext *const s = &m2->s;
     int i, stuffing_count, ret;
-    int context_count = s->slice_context_count;
+    int context_count = m2->slice_context_count;
 
     s->vbv_ignore_qmax = 0;
 
@@ -2795,7 +2795,7 @@ static void update_mb_info(MPVEncContext *s, int startcode)
 int ff_mpv_reallocate_putbitbuffer(MPVEncContext *s, size_t threshold, size_t size_increase)
 {
     if (put_bytes_left(&s->pb, 0) < threshold
-        && s->slice_context_count == 1
+        && s->parent_ctx->slice_context_count == 1
         && s->pb.buf == s->avctx->internal->byte_buffer) {
         int lastgob_pos = s->ptr_lastgob - s->pb.buf;
 
@@ -3561,7 +3561,7 @@ static int encode_picture(MPVMainEncContext *m, int picture_number)
     MPVEncContext *const s = &m2->s;
     int i, ret;
     int bits;
-    int context_count = s->slice_context_count;
+    int context_count = m2->slice_context_count;
 
     s->picture_number = picture_number;
 
diff --git a/libavcodec/vc1_parser.c b/libavcodec/vc1_parser.c
index b320826e5b..af5ff5028a 100644
--- a/libavcodec/vc1_parser.c
+++ b/libavcodec/vc1_parser.c
@@ -259,7 +259,7 @@ static int vc1_parse(AVCodecParserContext *s,
 static av_cold int vc1_parse_init(AVCodecParserContext *s)
 {
     VC1ParseContext *vpc = s->priv_data;
-    vpc->v.s.s.slice_context_count = 1;
+    vpc->v.s.slice_context_count = 1;
     vpc->v.first_pic_header_flag = 1;
     vpc->prev_start_code = 0;
     vpc->bytes_to_skip = 0;
-- 
2.32.0



More information about the ffmpeg-devel mailing list