Procházet zdrojové kódy

avcodec/mpegvideo: Move last_dc to {H263Dec,Mpeg12Slice,MPVEnc}Context

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Andreas Rheinhardt před 4 dny
rodič
revize
43abd1ced9

+ 10 - 10
libavcodec/dnxhdenc.c

@@ -575,8 +575,8 @@ void dnxhd_encode_block(PutBitContext *pb, DNXHDEncContext *ctx,
     int last_non_zero = 0;
     int slevel, i, j;
 
-    dnxhd_encode_dc(pb, ctx, block[0] - ctx->m.c.last_dc[n]);
-    ctx->m.c.last_dc[n] = block[0];
+    dnxhd_encode_dc(pb, ctx, block[0] - ctx->m.last_dc[n]);
+    ctx->m.last_dc[n] = block[0];
 
     for (i = 1; i <= last_index; i++) {
         j = ctx->m.c.intra_scantable.permutated[i];
@@ -822,9 +822,9 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg,
     LOCAL_ALIGNED_16(int16_t, block, [64]);
     ctx = ctx->thread[threadnr];
 
-    ctx->m.c.last_dc[0] =
-    ctx->m.c.last_dc[1] =
-    ctx->m.c.last_dc[2] = 1 << (ctx->bit_depth + 2);
+    ctx->m.last_dc[0] =
+    ctx->m.last_dc[1] =
+    ctx->m.last_dc[2] = 1 << (ctx->bit_depth + 2);
 
     for (int mb_x = 0; mb_x < ctx->m.c.mb_width; mb_x++) {
         unsigned mb = mb_y * ctx->m.c.mb_width + mb_x;
@@ -846,7 +846,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg,
                                              qscale, &overflow);
             ac_bits   += dnxhd_calc_ac_bits(ctx, block, last_index);
 
-            diff = block[0] - ctx->m.c.last_dc[n];
+            diff = block[0] - ctx->m.last_dc[n];
             if (diff < 0)
                 nbits = av_log2_16bit(-2 * diff);
             else
@@ -855,7 +855,7 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg,
             av_assert1(nbits < ctx->bit_depth + 4);
             dc_bits += ctx->cid_table->dc_bits[nbits] + nbits;
 
-            ctx->m.c.last_dc[n] = block[0];
+            ctx->m.last_dc[n] = block[0];
 
             if (avctx->mb_decision == FF_MB_DECISION_RD || !RC_VARIANCE) {
                 dnxhd_unquantize_c(ctx, block, i, qscale, last_index);
@@ -880,9 +880,9 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg,
     init_put_bits(pb, (uint8_t *)arg + ctx->data_offset + ctx->slice_offs[jobnr],
                   ctx->slice_size[jobnr]);
 
-    ctx->m.c.last_dc[0] =
-    ctx->m.c.last_dc[1] =
-    ctx->m.c.last_dc[2] = 1 << (ctx->bit_depth + 2);
+    ctx->m.last_dc[0] =
+    ctx->m.last_dc[1] =
+    ctx->m.last_dc[2] = 1 << (ctx->bit_depth + 2);
     for (int mb_x = 0; mb_x < ctx->m.c.mb_width; mb_x++) {
         unsigned mb = mb_y * ctx->m.c.mb_width + mb_x;
         int qscale = ctx->mb_qscale[mb];

+ 3 - 3
libavcodec/h263dec.c

@@ -247,9 +247,9 @@ static int decode_slice(H263DecContext *const h)
         }
 
         if (h->c.msmpeg4_version == MSMP4_V1) {
-            h->c.last_dc[0] =
-            h->c.last_dc[1] =
-            h->c.last_dc[2] = 128;
+            h->last_dc[0] =
+            h->last_dc[1] =
+            h->last_dc[2] = 128;
         }
 
         ff_init_block_index(&h->c);

+ 3 - 0
libavcodec/h263dec.h

@@ -79,6 +79,9 @@ typedef struct H263DecContext {
     /* MSMPEG4 specific */
     int slice_height;           ///< in macroblocks
 
+    /* MPEG-4 (Studio Profile), MSMPEG4 and RV10 specific */
+    int last_dc[3];             ///< last DC values, used by MPEG4, MSMPEG4V1, RV10
+
     /* RV10 specific */
     int rv10_version; ///< RV10 version: 0 or 3
     int rv10_first_dc_coded[3];

+ 2 - 2
libavcodec/ituh263dec.c

@@ -551,14 +551,14 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64],
         if (CONFIG_RV10_DECODER && h->c.codec_id == AV_CODEC_ID_RV10) {
             if (h->rv10_version == 3 && h->c.pict_type == AV_PICTURE_TYPE_I) {
                 int component = (n <= 3 ? 0 : n - 4 + 1);
-                level = h->c.last_dc[component];
+                level = h->last_dc[component];
                 if (h->rv10_first_dc_coded[component]) {
                     int diff = ff_rv_decode_dc(h, n);
                     if (diff < 0)
                         return -1;
                     level += diff;
                     level = level & 0xff; /* handle wrap round */
-                    h->c.last_dc[component] = level;
+                    h->last_dc[component] = level;
                 } else {
                     h->rv10_first_dc_coded[component] = 1;
                 }

+ 5 - 5
libavcodec/mjpegenc.c

@@ -279,7 +279,7 @@ int ff_mjpeg_encode_stuffing(MPVEncContext *const s)
 
 fail:
     for (int i = 0; i < 3; i++)
-        s->c.last_dc[i] = 128 << s->c.intra_dc_precision;
+        s->last_dc[i] = 128 << s->c.intra_dc_precision;
 
     return ret;
 }
@@ -371,11 +371,11 @@ static void record_block(MPVEncContext *const s, int16_t block[], int n)
     component = (n <= 3 ? 0 : (n&1) + 1);
     table_id = (n <= 3 ? 0 : 1);
     dc = block[0]; /* overflow is impossible */
-    val = dc - s->c.last_dc[component];
+    val = dc - s->last_dc[component];
 
     mjpeg_encode_coef(m, table_id, val, 0);
 
-    s->c.last_dc[component] = dc;
+    s->last_dc[component] = dc;
 
     /* AC coefs */
 
@@ -415,7 +415,7 @@ static void encode_block(MPVEncContext *const s, int16_t block[], int n)
     /* DC coef */
     component = (n <= 3 ? 0 : (n&1) + 1);
     dc = block[0]; /* overflow is impossible */
-    val = dc - s->c.last_dc[component];
+    val = dc - s->last_dc[component];
     if (n < 4) {
         ff_mjpeg_encode_dc(&s->pb, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance);
         huff_size_ac = m->huff_size_ac_luminance;
@@ -425,7 +425,7 @@ static void encode_block(MPVEncContext *const s, int16_t block[], int n)
         huff_size_ac = m->huff_size_ac_chrominance;
         huff_code_ac = m->huff_code_ac_chrominance;
     }
-    s->c.last_dc[component] = dc;
+    s->last_dc[component] = dc;
 
     /* AC coefs */
 

+ 12 - 10
libavcodec/mpeg12dec.c

@@ -73,6 +73,8 @@ typedef struct Mpeg12SliceContext {
     MPVContext c;
     GetBitContext gb;
 
+    int last_dc[3];                ///< last DC values
+
     DECLARE_ALIGNED_32(int16_t, block)[12][64];
 } Mpeg12SliceContext;
 
@@ -326,9 +328,9 @@ static inline int mpeg2_decode_block_intra(Mpeg12SliceContext *const s,
         component    = (n & 1) + 1;
     }
     diff = decode_dc(&s->gb, component);
-    dc  = s->c.last_dc[component];
+    dc  = s->last_dc[component];
     dc += diff;
-    s->c.last_dc[component] = dc;
+    s->last_dc[component] = dc;
     block[0] = dc * (1 << (3 - s->c.intra_dc_precision));
     ff_tlog(s->c.avctx, "dc=%d\n", block[0]);
     mismatch = block[0] ^ 1;
@@ -517,7 +519,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s, int *mb_skip_run)
                 ret = ff_mpeg1_decode_block_intra(&s->gb,
                                                   s->c.intra_matrix,
                                                   s->c.intra_scantable.permutated,
-                                                  s->c.last_dc, s->block[i],
+                                                  s->last_dc, s->block[i],
                                                   i, s->c.qscale);
                 if (ret < 0) {
                     av_log(s->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
@@ -713,7 +715,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s, int *mb_skip_run)
         }
 
         s->c.mb_intra = 0;
-        s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
+        s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->c.intra_dc_precision;
         if (HAS_CBP(mb_type)) {
             s->c.bdsp.clear_blocks(s->block[0]);
 
@@ -1453,9 +1455,9 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
         }
     }
 
-    s->c.last_dc[0] = 128 << s->c.intra_dc_precision;
-    s->c.last_dc[1] = s->c.last_dc[0];
-    s->c.last_dc[2] = s->c.last_dc[0];
+    s->last_dc[0] = 128 << s->c.intra_dc_precision;
+    s->last_dc[1] = s->last_dc[0];
+    s->last_dc[2] = s->last_dc[0];
     memset(s->c.last_mv, 0, sizeof(s->c.last_mv));
 
     for (int mb_skip_run = 0;;) {
@@ -1600,7 +1602,7 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
                 s->c.mb_intra = 0;
                 for (i = 0; i < 12; i++)
                     s->c.block_last_index[i] = -1;
-                s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
+                s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->c.intra_dc_precision;
                 if (s->c.picture_structure == PICT_FRAME)
                     s->c.mv_type = MV_TYPE_16X16;
                 else
@@ -2793,7 +2795,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                          s->flags & 0x10 ? ff_alternate_vertical_scan : ff_zigzag_direct,
                          m->idsp.idct_permutation);
 
-    m->last_dc[0] = m->last_dc[1] = m->last_dc[2] = 1 << (7 + (s->flags & 3));
+    s->m.last_dc[0] = s->m.last_dc[1] = s->m.last_dc[2] = 128 << (s->flags & 3);
     m->qscale = 1;
 
     for (int y = 0; y < avctx->height; y += 16) {
@@ -2825,7 +2827,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                     ret = ff_mpeg1_decode_block_intra(gb,
                                                       m->intra_matrix,
                                                       m->intra_scantable.permutated,
-                                                      m->last_dc, block[n],
+                                                      s->m.last_dc, block[n],
                                                       n, m->qscale);
                 } else {
                     ret = mpeg2_decode_block_intra(&s->m, block[n], n);

+ 3 - 3
libavcodec/mpeg12enc.c

@@ -589,9 +589,9 @@ static void mpeg1_encode_block(MPVEncContext *const s, const int16_t block[], in
     if (s->c.mb_intra) {
         component = (n <= 3 ? 0 : (n & 1) + 1);
         dc        = block[0];                   /* overflow is impossible */
-        diff      = dc - s->c.last_dc[component];
+        diff      = dc - s->last_dc[component];
         encode_dc(s, diff, component);
-        s->c.last_dc[component] = dc;
+        s->last_dc[component] = dc;
         i = 1;
         if (s->c.intra_vlc_format)
             table_vlc = ff_mpeg2_vlc_table;
@@ -936,7 +936,7 @@ static void mpeg12_encode_mb(MPVEncContext *const s, int16_t block[][64],
                              int motion_x, int motion_y)
 {
     if (!s->c.mb_intra)
-        s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
+        s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->c.intra_dc_precision;
     if (s->c.chroma_format == CHROMA_420)
         mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6, 1);
     else

+ 3 - 3
libavcodec/mpeg12enc.h

@@ -38,9 +38,9 @@ static inline void ff_mpeg1_encode_init(MPVEncContext *s)
 
 static inline void ff_mpeg1_clean_buffers(MPVEncContext *s)
 {
-    s->c.last_dc[0] = 128 << s->c.intra_dc_precision;
-    s->c.last_dc[1] = s->c.last_dc[0];
-    s->c.last_dc[2] = s->c.last_dc[0];
+    s->last_dc[0] = 128 << s->c.intra_dc_precision;
+    s->last_dc[1] = s->last_dc[0];
+    s->last_dc[2] = s->last_dc[0];
     memset(s->c.last_mv, 0, sizeof(s->c.last_mv));
 }
 

+ 8 - 8
libavcodec/mpeg4videodec.c

@@ -794,11 +794,11 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
 
 static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
 {
-    MPVContext *const s = &ctx->h.c;
+    H263DecContext *const h = &ctx->h;
     /* Reset DC Predictors */
-    s->last_dc[0] =
-    s->last_dc[1] =
-    s->last_dc[2] = 1 << (s->avctx->bits_per_raw_sample + ctx->dct_precision + s->intra_dc_precision - 1);
+    h->last_dc[0] =
+    h->last_dc[1] =
+    h->last_dc[2] = 1 << (h->c.avctx->bits_per_raw_sample + ctx->dct_precision + h->c.intra_dc_precision - 1);
 }
 
 /**
@@ -2196,12 +2196,12 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6
 
     }
 
-    h->c.last_dc[cc] += dct_diff;
+    h->last_dc[cc] += dct_diff;
 
     if (ctx->mpeg_quant)
-        block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision);
+        block[0] = h->last_dc[cc] * (8 >> h->c.intra_dc_precision);
     else
-        block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision) * (8 >> ctx->dct_precision);
+        block[0] = h->last_dc[cc] * (8 >> h->c.intra_dc_precision) * (8 >> ctx->dct_precision);
     /* TODO: support mpeg_quant for AC coefficients */
 
     block[0] = av_clip(block[0], min, max);
@@ -2283,7 +2283,7 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
         av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
         return AVERROR_INVALIDDATA;
     }
-    h->c.last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));
+    h->last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));
 
     rice_parameter = get_bits(&h->gb, 4);
     if (rice_parameter == 0) {

+ 0 - 1
libavcodec/mpegvideo.h

@@ -133,7 +133,6 @@ typedef struct MpegEncContext {
      */
     MPVWorkPicture cur_pic;
 
-    int last_dc[3];                ///< last DC values for MPEG-1
     int16_t *dc_val_base;
     const uint8_t *y_dc_scale_table;     ///< qscale -> y_dc_scale table
     const uint8_t *c_dc_scale_table;     ///< qscale -> c_dc_scale table

+ 8 - 8
libavcodec/mpegvideo_enc.c

@@ -2639,13 +2639,13 @@ typedef struct MBBackup {
         int mv[2][4][2];
         int last_mv[2][2][2];
         int mv_type, mv_dir;
-        int last_dc[3];
         int mb_intra, mb_skipped;
         int qscale;
         int block_last_index[8];
         int interlaced_dct;
     } c;
     int mb_skip_run;
+    int last_dc[3];
     int mv_bits, i_tex_bits, p_tex_bits, i_count, misc_bits, last_bits;
     int dquant;
     int esc3_level_length;
@@ -2663,7 +2663,7 @@ static inline void BEFORE ##_context_before_encode(DST_TYPE *const d,       \
     /* MPEG-1 */                                                            \
     d->mb_skip_run = s->mb_skip_run;                                        \
     for (int i = 0; i < 3; i++)                                             \
-        d->c.last_dc[i] = s->c.last_dc[i];                                  \
+        d->last_dc[i] = s->last_dc[i];                                      \
                                                                             \
     /* statistics */                                                        \
     d->mv_bits    = s->mv_bits;                                             \
@@ -2691,7 +2691,7 @@ static inline void AFTER ## _context_after_encode(DST_TYPE *const d,        \
     /* MPEG-1 */                                                            \
     d->mb_skip_run = s->mb_skip_run;                                        \
     for (int i = 0; i < 3; i++)                                             \
-        d->c.last_dc[i] = s->c.last_dc[i];                                  \
+        d->last_dc[i] = s->last_dc[i];                                      \
                                                                             \
     /* statistics */                                                        \
     d->mv_bits    = s->mv_bits;                                             \
@@ -3009,14 +3009,14 @@ static int encode_thread(AVCodecContext *c, void *arg){
     for(i=0; i<3; i++){
         /* init last dc values */
         /* note: quant matrix value (8) is implied here */
-        s->c.last_dc[i] = 128 << s->c.intra_dc_precision;
+        s->last_dc[i] = 128 << s->c.intra_dc_precision;
 
         s->encoding_error[i] = 0;
     }
     if (s->c.codec_id == AV_CODEC_ID_AMV) {
-        s->c.last_dc[0] = 128 * 8 / 13;
-        s->c.last_dc[1] = 128 * 8 / 14;
-        s->c.last_dc[2] = 128 * 8 / 14;
+        s->last_dc[0] = 128 * 8 / 13;
+        s->last_dc[1] = 128 * 8 / 14;
+        s->last_dc[2] = 128 * 8 / 14;
 #if CONFIG_MPEG4_ENCODER
     } else if (s->partitioned_frame) {
         av_assert1(s->c.codec_id == AV_CODEC_ID_MPEG4);
@@ -3039,7 +3039,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
             mb_y = ff_speedhq_mb_y_order_to_mb(mb_y_order, s->c.mb_height, &first_in_slice);
             if (first_in_slice && mb_y_order != s->c.start_mb_y)
                 ff_speedhq_end_slice(s);
-            s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 1024 << s->c.intra_dc_precision;
+            s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 1024 << s->c.intra_dc_precision;
         } else {
             mb_y = mb_y_order;
         }

+ 1 - 0
libavcodec/mpegvideoenc.h

@@ -138,6 +138,7 @@ typedef struct MPVEncContext {
     int last_bits; ///< temp var used for calculating the above vars
 
     int mb_skip_run;
+    int last_dc[3];                ///< last DC values
 
     /* H.263 specific */
     int gob_index;

+ 4 - 4
libavcodec/msmpeg4dec.c

@@ -48,7 +48,7 @@
 
 static const VLCElem *mv_tables[2];
 
-static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
+static inline int msmpeg4v1_pred_dc(H263DecContext *const h, int n,
                                     int32_t **dc_val_ptr)
 {
     int i;
@@ -59,8 +59,8 @@ static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
         i= n-3;
     }
 
-    *dc_val_ptr= &s->last_dc[i];
-    return s->last_dc[i];
+    *dc_val_ptr= &h->last_dc[i];
+    return h->last_dc[i];
 }
 
 /****************************************/
@@ -588,7 +588,7 @@ static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
 
     if (h->c.msmpeg4_version == MSMP4_V1) {
         int32_t *dc_val;
-        pred = msmpeg4v1_pred_dc(&h->c, n, &dc_val);
+        pred = msmpeg4v1_pred_dc(h, n, &dc_val);
         level += pred;
 
         /* update predictor */

+ 5 - 5
libavcodec/rv10.c

@@ -129,11 +129,11 @@ static int rv10_decode_picture_header(H263DecContext *const h)
     if (h->c.pict_type == AV_PICTURE_TYPE_I) {
         if (h->rv10_version == 3) {
             /* specific MPEG like DC coding not used */
-            h->c.last_dc[0] = get_bits(&h->gb, 8);
-            h->c.last_dc[1] = get_bits(&h->gb, 8);
-            h->c.last_dc[2] = get_bits(&h->gb, 8);
-            ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->c.last_dc[0],
-                    h->c.last_dc[1], h->c.last_dc[2]);
+            h->last_dc[0] = get_bits(&h->gb, 8);
+            h->last_dc[1] = get_bits(&h->gb, 8);
+            h->last_dc[2] = get_bits(&h->gb, 8);
+            ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->last_dc[0],
+                    h->last_dc[1], h->last_dc[2]);
         }
     }
     /* if multiple packets per frame are sent, the position at which

+ 2 - 2
libavcodec/speedhqenc.c

@@ -172,9 +172,9 @@ static void encode_block(MPVEncContext *const s, const int16_t block[], int n)
     /* DC coef */
     component = (n <= 3 ? 0 : (n&1) + 1);
     dc = block[0]; /* overflow is impossible */
-    val = s->c.last_dc[component] - dc;  /* opposite of most codecs */
+    val = s->last_dc[component] - dc;  /* opposite of most codecs */
     encode_dc(&s->pb, val, component);
-    s->c.last_dc[component] = dc;
+    s->last_dc[component] = dc;
 
     /* now quantify & encode AC coefs */
     last_non_zero = 0;