diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2005-04-20 20:31:04 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2005-04-20 20:31:04 +0000 |
commit | dff0f0354605102ac06e419ddd437ca7aa558c30 (patch) | |
tree | 651ebedc4212e78618d15a062395250bec0814ee /libavcodec | |
parent | bfaad39f8c5de4d4bf2847a709ec9d180295ed57 (diff) | |
download | ffmpeg-dff0f0354605102ac06e419ddd437ca7aa558c30.tar.gz |
mpeg2_fast_decode_block_intra()
Originally committed as revision 4146 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/mpeg12.c | 83 |
1 files changed, 80 insertions, 3 deletions
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index c912c45040..fe0ccd1b42 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -72,6 +72,7 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n); static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n); +static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n); static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); static void exchange_uv(MpegEncContext *s); @@ -1173,9 +1174,15 @@ static int mpeg_decode_mb(MpegEncContext *s, #endif if (s->codec_id == CODEC_ID_MPEG2VIDEO) { - for(i=0;i<mb_block_count;i++) { - if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0) - return -1; + if(s->flags2 & 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 (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0) + return -1; + } } } else { for(i=0;i<6;i++) { @@ -1928,6 +1935,76 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, return 0; } +static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, + DCTELEM *block, + int n) +{ + int level, dc, diff, j, run; + int component; + RLTable *rl; + uint8_t * scantable= s->intra_scantable.permutated; + const uint16_t *quant_matrix; + const int qscale= s->qscale; + + /* DC coef */ + 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); + if (diff >= 0xffff) + return -1; + dc = s->last_dc[component]; + dc += diff; + s->last_dc[component] = dc; + block[0] = dc << (3 - s->intra_dc_precision); + if (s->intra_vlc_format) + rl = &rl_mpeg2; + else + rl = &rl_mpeg1; + + { + OPEN_READER(re, &s->gb); + /* now quantify & encode AC coefs */ + for(;;) { + UPDATE_CACHE(re, &s->gb); + GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); + + if(level == 127){ + break; + } else if(level != 0) { + scantable += run; + j = *scantable; + 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; 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); + scantable += run; + j = *scantable; + 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); + } + + s->block_last_index[n] = scantable - s->intra_scantable.permutated; + return 0; +} + typedef struct Mpeg1Context { MpegEncContext mpeg_enc_ctx; int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ |