One step in untangling the mpegvideo code and fixing some problems in
the order that initialization is being done in h263dec and h261dec.
---
 libavcodec/dnxhdenc.c      |  2 +-
 libavcodec/h261dec.c       |  4 +++-
 libavcodec/h263dec.c       |  8 ++++++--
 libavcodec/mpeg12dec.c     |  5 +++++
 libavcodec/mpeg4videodec.c |  7 +++++--
 libavcodec/mpegvideo.c     | 10 +++++++---
 libavcodec/mpegvideo.h     |  1 +
 libavcodec/mpegvideo_enc.c |  1 +
 libavcodec/rv10.c          |  1 +
 libavcodec/rv34.c          |  5 +++++
 libavcodec/svq1enc.c       |  1 +
 11 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index e656b6e..16d3260 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -309,7 +309,7 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
 
     ff_blockdsp_init(&ctx->bdsp, avctx);
     ff_fdctdsp_init(&ctx->m.fdsp, avctx);
-    ff_idctdsp_init(&ctx->m.idsp, avctx);
+    ff_idct_common_init(&ctx->m, avctx);
     ff_mpegvideoencdsp_init(&ctx->m.mpvencdsp, avctx);
     ff_pixblockdsp_init(&ctx->m.pdsp, avctx);
     ff_dct_common_init(&ctx->m);
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index d83fb31..dcd7c54 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -581,10 +581,12 @@ static int h261_decode_frame(AVCodecContext *avctx, void 
*data,
 retry:
     init_get_bits(&s->gb, buf, buf_size * 8);
 
-    if (!s->context_initialized)
+    if (!s->context_initialized) {
         // we need the IDCT permutaton for reading a custom matrix
+        ff_idct_common_init(s, s->avctx);
         if (ff_MPV_common_init(s) < 0)
             return -1;
+    }
 
     ret = h261_decode_picture_header(h);
 
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index cdd5544..f0b275b 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -113,9 +113,11 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
 
     /* for h263, we allocate the images after having read the header */
     if (avctx->codec->id != AV_CODEC_ID_H263 &&
-        avctx->codec->id != AV_CODEC_ID_MPEG4)
+        avctx->codec->id != AV_CODEC_ID_MPEG4) {
+        ff_idct_common_init(s, s->avctx);
         if ((ret = ff_MPV_common_init(s)) < 0)
             return ret;
+    }
 
     ff_h263dsp_init(&s->h263dsp);
     ff_qpeldsp_init(&s->qdsp);
@@ -414,10 +416,12 @@ int ff_h263_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
     if (ret < 0)
         return ret;
 
-    if (!s->context_initialized)
+    if (!s->context_initialized) {
         // we need the idct permutaton for reading a custom matrix
+        ff_idct_common_init(s, s->avctx);
         if ((ret = ff_MPV_common_init(s)) < 0)
             return ret;
+    }
 
     /* We need to set current_picture_ptr before reading the header,
      * otherwise we cannot store anyting in there */
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index a181fcc..4291890 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1136,6 +1136,9 @@ static int 
mpeg_decode_update_thread_context(AVCodecContext *avctx,
         !s1->context_initialized)
         return 0;
 
+    if (!s->context_initialized)
+        ff_idct_common_init(s, avctx);
+
     err = ff_mpeg_update_thread_context(avctx, avctx_from);
     if (err)
         return err;
@@ -1313,6 +1316,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
          * if DCT permutation is changed. */
         memcpy(old_permutation, s->idsp.idct_permutation, 64 * 
sizeof(uint8_t));
 
+        ff_idct_common_init(s, s->avctx);
         if (ff_MPV_common_init(s) < 0)
             return -2;
 
@@ -2151,6 +2155,7 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
 #endif /* FF_API_XVMC */
         avctx->idct_algo = FF_IDCT_SIMPLE;
 
+    ff_idct_common_init(s, s->avctx);
     if (ff_MPV_common_init(s) < 0)
         return -1;
     s1->mpeg_enc_ctx_allocated = 1;
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 863dd29..c7bbd3e 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -2546,8 +2546,11 @@ static int mpeg4_update_thread_context(AVCodecContext 
*dst,
     if (ret < 0)
         return ret;
 
-    if (CONFIG_MPEG4_DECODER && !init && s1->xvid_build >= 0)
-        ff_xvididct_init(&s->m.idsp, dst);
+    if (!init)
+        if (CONFIG_MPEG4_DECODER && s1->xvid_build >= 0)
+            ff_xvididct_init(&s->m.idsp, dst);
+        else
+            ff_idct_common_init(&s->m, dst);
 
     s->shape               = s1->shape;
     s->time_increment_bits = s1->time_increment_bits;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index da42541..1b3cbbb 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -379,7 +379,6 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
 {
     ff_blockdsp_init(&s->bdsp, s->avctx);
     ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
-    ff_idctdsp_init(&s->idsp, s->avctx);
     ff_me_cmp_init(&s->mecc, s->avctx);
     ff_mpegvideodsp_init(&s->mdsp);
     ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
@@ -403,6 +402,13 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
     if (ARCH_X86)
         ff_MPV_common_init_x86(s);
 
+    return 0;
+}
+
+av_cold void ff_idct_common_init(MpegEncContext *s, AVCodecContext *avctx)
+{
+    ff_idctdsp_init(&s->idsp, avctx);
+
     /* load & permutate scantables
      * note: only wmv uses different ones
      */
@@ -415,8 +421,6 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
     }
     ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, 
ff_alternate_horizontal_scan);
     ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, 
ff_alternate_vertical_scan);
-
-    return 0;
 }
 
 static int frame_size_alloc(MpegEncContext *s, int linesize)
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 1333d44..a4c7a3f 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -721,6 +721,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src
 void ff_set_qscale(MpegEncContext * s, int qscale);
 
 int ff_dct_common_init(MpegEncContext *s);
+void ff_idct_common_init(MpegEncContext *s, AVCodecContext *avctx);
 void ff_convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t 
(*qmat16)[2][64],
                        const uint16_t *quant_matrix, int bias, int qmin, int 
qmax, int intra);
 int ff_dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, 
int *overflow);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 2d0cd83..17c184f 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -700,6 +700,7 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
                                 s->alternate_scan);
 
     /* init */
+    ff_idct_common_init(s, s->avctx);
     if (ff_MPV_common_init(s) < 0)
         return -1;
 
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 835a1aa..71ecffe 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -498,6 +498,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
 
     avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 
+    ff_idct_common_init(s, s->avctx);
     if ((ret = ff_MPV_common_init(s)) < 0)
         return ret;
 
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 0c36348..1218c06 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1488,6 +1488,7 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx)
     avctx->has_b_frames = 1;
     s->low_delay = 0;
 
+    ff_idct_common_init(s, s->avctx);
     if ((ret = ff_MPV_common_init(s)) < 0)
         return ret;
 
@@ -1524,6 +1525,7 @@ int ff_rv34_decode_init_thread_copy(AVCodecContext *avctx)
 
     if (avctx->internal->is_copy) {
         r->tmp_b_block_base = NULL;
+        ff_idct_common_init(&r->s, avctx);
         if ((err = ff_MPV_common_init(&r->s)) < 0)
             return err;
         if ((err = rv34_decoder_alloc(r)) < 0) {
@@ -1553,6 +1555,9 @@ int ff_rv34_decode_update_thread_context(AVCodecContext 
*dst, const AVCodecConte
             return err;
     }
 
+    if (!s->context_initialized)
+        ff_idct_common_init(s, dst);
+
     if ((err = ff_mpeg_update_thread_context(dst, src)))
         return err;
 
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 506ee9b..952f923 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -533,6 +533,7 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
     s->avctx               = avctx;
     s->m.avctx             = avctx;
 
+    ff_idct_common_init(&s->m, avctx);
     if ((ret = ff_MPV_common_init(&s->m)) < 0) {
         svq1_encode_end(avctx);
         return ret;
-- 
1.9.3

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to