[FFmpeg-cvslog] libavcodec/mpeg12: Remove "fast" mode

Kieran Kunhya git at videolan.org
Mon Oct 30 00:49:36 EET 2023


ffmpeg | branch: master | Kieran Kunhya <kierank at obe.tv> | Sun Oct 29 15:32:49 2023 +0000| [7d497a1119b1525c32fa0a342329898e7c3f5373] | committer: Kieran Kunhya

libavcodec/mpeg12: Remove "fast" mode

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7d497a1119b1525c32fa0a342329898e7c3f5373
---

 libavcodec/mpeg12dec.c | 265 -------------------------------------------------
 1 file changed, 265 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 5dac83ebcd..d266dfcef3 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -233,94 +233,6 @@ end:
     return 0;
 }
 
-/**
- * Changing this would eat up any speed benefits it has.
- * Do not use "fast" flag if you need the code to be robust.
- */
-static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s,
-                                                int16_t *block, int n)
-{
-    int level, i, j, run;
-    uint8_t *const scantable = s->intra_scantable.permutated;
-    const int qscale         = s->qscale;
-
-    {
-        OPEN_READER(re, &s->gb);
-        i = -1;
-        // Special case for first coefficient, no need to add second VLC table.
-        UPDATE_CACHE(re, &s->gb);
-        if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {
-            level = (3 * qscale) >> 1;
-            level = (level - 1) | 1;
-            if (GET_CACHE(re, &s->gb) & 0x40000000)
-                level = -level;
-            block[0] = level;
-            i++;
-            SKIP_BITS(re, &s->gb, 2);
-            if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
-                goto end;
-        }
-
-        /* now quantify & encode AC coefficients */
-        for (;;) {
-            GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc,
-                       TEX_VLC_BITS, 2, 0);
-
-            if (level != 0) {
-                i += run;
-                if (i > MAX_INDEX)
-                    break;
-                j = scantable[i];
-                level = ((level * 2 + 1) * qscale) >> 1;
-                level = (level - 1) | 1;
-                level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
-                        SHOW_SBITS(re, &s->gb, 1);
-                SKIP_BITS(re, &s->gb, 1);
-            } else {
-                /* escape */
-                run = SHOW_UBITS(re, &s->gb, 6) + 1;
-                LAST_SKIP_BITS(re, &s->gb, 6);
-                UPDATE_CACHE(re, &s->gb);
-                level = SHOW_SBITS(re, &s->gb, 8);
-                SKIP_BITS(re, &s->gb, 8);
-                if (level == -128) {
-                    level = SHOW_UBITS(re, &s->gb, 8) - 256;
-                    SKIP_BITS(re, &s->gb, 8);
-                } else if (level == 0) {
-                    level = SHOW_UBITS(re, &s->gb, 8);
-                    SKIP_BITS(re, &s->gb, 8);
-                }
-                i += run;
-                if (i > MAX_INDEX)
-                    break;
-                j = scantable[i];
-                if (level < 0) {
-                    level = -level;
-                    level = ((level * 2 + 1) * qscale) >> 1;
-                    level = (level - 1) | 1;
-                    level = -level;
-                } else {
-                    level = ((level * 2 + 1) * qscale) >> 1;
-                    level = (level - 1) | 1;
-                }
-            }
-
-            block[j] = level;
-            if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
-                break;
-            UPDATE_CACHE(re, &s->gb);
-        }
-end:
-        LAST_SKIP_BITS(re, &s->gb, 2);
-        CLOSE_READER(re, &s->gb);
-    }
-
-    check_scantable_index(s, i);
-
-    s->block_last_index[n] = i;
-    return 0;
-}
-
 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
                                                int16_t *block, int n)
 {
@@ -406,81 +318,6 @@ end:
     return 0;
 }
 
-/**
- * Changing this would eat up any speed benefits it has.
- * Do not use "fast" flag if you need the code to be robust.
- */
-static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s,
-                                                    int16_t *block, int n)
-{
-    int level, i, j, run;
-    uint8_t *const scantable = s->intra_scantable.permutated;
-    const int qscale         = s->qscale;
-    OPEN_READER(re, &s->gb);
-    i = -1;
-
-    // special case for first coefficient, no need to add second VLC table
-    UPDATE_CACHE(re, &s->gb);
-    if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {
-        level = (3 * qscale) >> 1;
-        if (GET_CACHE(re, &s->gb) & 0x40000000)
-            level = -level;
-        block[0] = level;
-        i++;
-        SKIP_BITS(re, &s->gb, 2);
-        if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
-            goto end;
-    }
-
-    /* now quantify & encode AC coefficients */
-    for (;;) {
-        GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc, TEX_VLC_BITS, 2, 0);
-
-        if (level != 0) {
-            i += run;
-            if (i > MAX_INDEX)
-                break;
-            j = scantable[i];
-            level = ((level * 2 + 1) * qscale) >> 1;
-            level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
-                    SHOW_SBITS(re, &s->gb, 1);
-            SKIP_BITS(re, &s->gb, 1);
-        } else {
-            /* escape */
-            run = SHOW_UBITS(re, &s->gb, 6) + 1;
-            LAST_SKIP_BITS(re, &s->gb, 6);
-            UPDATE_CACHE(re, &s->gb);
-            level = SHOW_SBITS(re, &s->gb, 12);
-            SKIP_BITS(re, &s->gb, 12);
-
-            i += run;
-            if (i > MAX_INDEX)
-                break;
-            j = scantable[i];
-            if (level < 0) {
-                level = ((-level * 2 + 1) * qscale) >> 1;
-                level = -level;
-            } else {
-                level = ((level * 2 + 1) * qscale) >> 1;
-            }
-        }
-
-        block[j] = level;
-        if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF || i > 63)
-            break;
-
-        UPDATE_CACHE(re, &s->gb);
-    }
-end:
-    LAST_SKIP_BITS(re, &s->gb, 2);
-    CLOSE_READER(re, &s->gb);
-
-    check_scantable_index(s, i);
-
-    s->block_last_index[n] = i;
-    return 0;
-}
-
 static inline int mpeg2_decode_block_intra(MpegEncContext *s,
                                            int16_t *block, int n)
 {
@@ -563,83 +400,6 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s,
     return 0;
 }
 
-/**
- * Changing this would eat up any speed benefits it has.
- * Do not use "fast" flag if you need the code to be robust.
- */
-static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s,
-                                                int16_t *block, int n)
-{
-    int level, dc, diff, i, j, run;
-    int component;
-    const RL_VLC_ELEM *rl_vlc;
-    uint8_t *const scantable = s->intra_scantable.permutated;
-    const uint16_t *quant_matrix;
-    const int qscale = s->qscale;
-
-    /* DC coefficient */
-    if (n < 4) {
-        quant_matrix = s->intra_matrix;
-        component    = 0;
-    } else {
-        quant_matrix = s->chroma_intra_matrix;
-        component    = (n & 1) + 1;
-    }
-    diff = decode_dc(&s->gb, component);
-    dc = s->last_dc[component];
-    dc += diff;
-    s->last_dc[component] = dc;
-    block[0] = dc * (1 << (3 - s->intra_dc_precision));
-    i = 0;
-    if (s->intra_vlc_format)
-        rl_vlc = ff_mpeg2_rl_vlc;
-    else
-        rl_vlc = ff_mpeg1_rl_vlc;
-
-    {
-        OPEN_READER(re, &s->gb);
-        /* now quantify & encode AC coefficients */
-        for (;;) {
-            UPDATE_CACHE(re, &s->gb);
-            GET_RL_VLC(level, run, re, &s->gb, rl_vlc,
-                       TEX_VLC_BITS, 2, 0);
-
-            if (level >= 64 || i > 63) {
-                break;
-            } else if (level != 0) {
-                i += run;
-                j = scantable[i];
-                level = (level * qscale * quant_matrix[j]) >> 4;
-                level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
-                        SHOW_SBITS(re, &s->gb, 1);
-                LAST_SKIP_BITS(re, &s->gb, 1);
-            } else {
-                /* escape */
-                run = SHOW_UBITS(re, &s->gb, 6) + 1;
-                SKIP_BITS(re, &s->gb, 6);
-                level = SHOW_SBITS(re, &s->gb, 12);
-                LAST_SKIP_BITS(re, &s->gb, 12);
-                i += run;
-                j = scantable[i];
-                if (level < 0) {
-                    level = (-level * qscale * quant_matrix[j]) >> 4;
-                    level = -level;
-                } else {
-                    level = (level * qscale * quant_matrix[j]) >> 4;
-                }
-            }
-
-            block[j] = level;
-        }
-        CLOSE_READER(re, &s->gb);
-    }
-
-    check_scantable_index(s, i);
-
-    s->block_last_index[n] = i;
-    return 0;
-}
-
 /******************************************/
 /* decoding */
 
@@ -767,14 +527,9 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
         s->mb_intra = 1;
 
         if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
-            if (s->avctx->flags2 & AV_CODEC_FLAG2_FAST) {
-                for (i = 0; i < 6; i++)
-                    mpeg2_fast_decode_block_intra(s, *s->pblocks[i], i);
-            } else {
                 for (i = 0; i < mb_block_count; i++)
                     if ((ret = mpeg2_decode_block_intra(s, *s->pblocks[i], i)) < 0)
                         return ret;
-            }
         } else {
             for (i = 0; i < 6; i++) {
                 ret = ff_mpeg1_decode_block_intra(&s->gb,
@@ -994,15 +749,6 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
             }
 
             if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
-                if (s->avctx->flags2 & AV_CODEC_FLAG2_FAST) {
-                    for (i = 0; i < 6; i++) {
-                        if (cbp & 32)
-                            mpeg2_fast_decode_block_non_intra(s, *s->pblocks[i], i);
-                        else
-                            s->block_last_index[i] = -1;
-                        cbp += cbp;
-                    }
-                } else {
                     cbp <<= 12 - mb_block_count;
 
                     for (i = 0; i < mb_block_count; i++) {
@@ -1014,17 +760,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
                         }
                         cbp += cbp;
                     }
-                }
             } else {
-                if (s->avctx->flags2 & AV_CODEC_FLAG2_FAST) {
-                    for (i = 0; i < 6; i++) {
-                        if (cbp & 32)
-                            mpeg1_fast_decode_block_inter(s, *s->pblocks[i], i);
-                        else
-                            s->block_last_index[i] = -1;
-                        cbp += cbp;
-                    }
-                } else {
                     for (i = 0; i < 6; i++) {
                         if (cbp & 32) {
                             if ((ret = mpeg1_decode_block_inter(s, *s->pblocks[i], i)) < 0)
@@ -1034,7 +770,6 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
                         }
                         cbp += cbp;
                     }
-                }
             }
         } else {
             for (i = 0; i < 12; i++)



More information about the ffmpeg-cvslog mailing list