Commit 03dbad35 authored by michaelni's avatar michaelni

optimizing mpeg2 decode block stuff


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@989 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 8c5653f8
...@@ -58,10 +58,10 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, ...@@ -58,10 +58,10 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s,
static inline int mpeg1_decode_block_intra(MpegEncContext *s, static inline int mpeg1_decode_block_intra(MpegEncContext *s,
DCTELEM *block, DCTELEM *block,
int n); int n);
static int mpeg2_decode_block_non_intra(MpegEncContext *s, static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
DCTELEM *block, DCTELEM *block,
int n); int n);
static int mpeg2_decode_block_intra(MpegEncContext *s, static inline int mpeg2_decode_block_intra(MpegEncContext *s,
DCTELEM *block, DCTELEM *block,
int n); int n);
static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
...@@ -1117,18 +1117,15 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, ...@@ -1117,18 +1117,15 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s,
UPDATE_CACHE(re, &s->gb); UPDATE_CACHE(re, &s->gb);
v= SHOW_UBITS(re, &s->gb, 2); v= SHOW_UBITS(re, &s->gb, 2);
if (v & 2) { if (v & 2) {
SKIP_BITS(re, &s->gb, 2); LAST_SKIP_BITS(re, &s->gb, 2);
level= (3*qscale*quant_matrix[0])>>4; level= (3*qscale*quant_matrix[0])>>4;
level= (level-1)|1; level= (level-1)|1;
if(v&1) if(v&1)
level= -level; level= -level;
block[ scantable[0] ] = level; block[0] = level;
i++; i++;
} }
CLOSE_READER(re, &s->gb);
}
{
OPEN_READER(re, &s->gb);
/* now quantify & encode AC coefs */ /* now quantify & encode AC coefs */
for(;;) { for(;;) {
UPDATE_CACHE(re, &s->gb); UPDATE_CACHE(re, &s->gb);
...@@ -1180,110 +1177,114 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, ...@@ -1180,110 +1177,114 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s,
/* Also does unquantization here, since I will never support mpeg2 /* Also does unquantization here, since I will never support mpeg2
encoding */ encoding */
static int mpeg2_decode_block_non_intra(MpegEncContext *s, static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
DCTELEM *block, DCTELEM *block,
int n) int n)
{ {
int level, i, j, run; int level, i, j, run;
int code;
RLTable *rl = &rl_mpeg1; RLTable *rl = &rl_mpeg1;
const UINT8 *scan_table; UINT8 * scantable;
const UINT16 *matrix; const UINT16 *quant_matrix;
const int qscale= s->qscale;
int mismatch; int mismatch;
if (s->alternate_scan) if (s->alternate_scan)
scan_table = s->intra_v_scantable.permutated; scantable = s->intra_v_scantable.permutated;
else else
scan_table = s->intra_scantable.permutated; scantable = s->intra_scantable.permutated;
mismatch = 1; mismatch = 1;
{ {
int v; int v;
OPEN_READER(re, &s->gb); OPEN_READER(re, &s->gb);
i = 0; i = -1;
if (n < 4) if (n < 4)
matrix = s->inter_matrix; quant_matrix = s->inter_matrix;
else else
matrix = s->chroma_inter_matrix; quant_matrix = s->chroma_inter_matrix;
/* special case for the first coef. no need to add a second vlc table */ /* special case for the first coef. no need to add a second vlc table */
UPDATE_CACHE(re, &s->gb); UPDATE_CACHE(re, &s->gb);
v= SHOW_UBITS(re, &s->gb, 2); v= SHOW_UBITS(re, &s->gb, 2);
if (v & 2) { if (v & 2) {
run = 0; LAST_SKIP_BITS(re, &s->gb, 2);
level = 5 - (v << 1); level= (3*qscale*quant_matrix[0])>>5;
SKIP_BITS(re, &s->gb, 2); if(v&1)
CLOSE_READER(re, &s->gb); level= -level;
goto add_coef; block[0] = level;
} mismatch ^= level;
CLOSE_READER(re, &s->gb); i++;
} }
/* now quantify & encode AC coefs */ /* now quantify & encode AC coefs */
for(;;) { for(;;) {
code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); UPDATE_CACHE(re, &s->gb);
if (code < 0){ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2);
fprintf(stderr, "invalid ac code at %d %d\n", s->mb_x, s->mb_y);
return -1; if(level == 127){
}
if (code == 112) {
break; break;
} else if (code == 111) { } else if(level != 0) {
/* escape */ i += run;
run = get_bits(&s->gb, 6); j = scantable[i];
level = get_bits(&s->gb, 12); level= ((level*2+1)*qscale*quant_matrix[j])>>5;
level= (level + ((-1)<<11)) ^ ((-1)<<11); //sign extension level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
LAST_SKIP_BITS(re, &s->gb, 1);
} else { } else {
run = rl->table_run[code]; /* escape */
level = rl->table_level[code]; run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
if (get_bits1(&s->gb)) UPDATE_CACHE(re, &s->gb);
level = -level; level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
}
i += run; i += run;
if (i >= 64){ j = scantable[i];
fprintf(stderr, "run too long at %d %d\n", s->mb_x, s->mb_y); if(level<0){
return -1; level= ((-level*2+1)*qscale*quant_matrix[j])>>5;
level= -level;
}else{
level= ((level*2+1)*qscale*quant_matrix[j])>>5;
} }
add_coef:
j = scan_table[i];
dprintf("%d: run=%d level=%d\n", n, run, level);
/* XXX: optimize */
if (level > 0) {
level = ((level * 2 + 1) * s->qscale * matrix[j]) >> 5;
} else {
level = ((-level * 2 + 1) * s->qscale * matrix[j]) >> 5;
level = -level;
} }
/* XXX: is it really necessary to saturate since the encoder if (i > 63){
knows whats going on ? */ fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
mismatch ^= level; mismatch ^= level;
block[j] = level; block[j] = level;
i++; }
CLOSE_READER(re, &s->gb);
} }
block[63] ^= (mismatch & 1); block[63] ^= (mismatch & 1);
s->block_last_index[n] = i;
s->block_last_index[n] = i;
return 0; return 0;
} }
static int mpeg2_decode_block_intra(MpegEncContext *s, static inline int mpeg2_decode_block_intra(MpegEncContext *s,
DCTELEM *block, DCTELEM *block,
int n) int n)
{ {
int level, dc, diff, i, j, run; int level, dc, diff, i, j, run;
int code, component; int component;
RLTable *rl; RLTable *rl;
const UINT8 *scan_table; UINT8 * scantable;
const UINT16 *matrix; const UINT16 *quant_matrix;
const int qscale= s->qscale;
int mismatch; int mismatch;
if (s->alternate_scan) if (s->alternate_scan)
scan_table = s->intra_v_scantable.permutated; scantable = s->intra_v_scantable.permutated;
else else
scan_table = s->intra_scantable.permutated; scantable = s->intra_scantable.permutated;
/* DC coef */ /* DC coef */
component = (n <= 3 ? 0 : n - 4 + 1); if (n < 4){
quant_matrix = s->intra_matrix;
component = 0;
}else{
quant_matrix = s->chroma_intra_matrix;
component = n - 3;
}
diff = decode_dc(s, component); diff = decode_dc(s, component);
if (diff >= 0xffff) if (diff >= 0xffff)
return -1; return -1;
...@@ -1293,51 +1294,53 @@ static int mpeg2_decode_block_intra(MpegEncContext *s, ...@@ -1293,51 +1294,53 @@ static int mpeg2_decode_block_intra(MpegEncContext *s,
block[0] = dc << (3 - s->intra_dc_precision); block[0] = dc << (3 - s->intra_dc_precision);
dprintf("dc=%d\n", block[0]); dprintf("dc=%d\n", block[0]);
mismatch = block[0] ^ 1; mismatch = block[0] ^ 1;
i = 1; i = 0;
if (s->intra_vlc_format) if (s->intra_vlc_format)
rl = &rl_mpeg2; rl = &rl_mpeg2;
else else
rl = &rl_mpeg1; rl = &rl_mpeg1;
if (n < 4)
matrix = s->intra_matrix;
else
matrix = s->chroma_intra_matrix;
{
OPEN_READER(re, &s->gb);
/* now quantify & encode AC coefs */ /* now quantify & encode AC coefs */
for(;;) { for(;;) {
code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); UPDATE_CACHE(re, &s->gb);
if (code < 0){ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2);
fprintf(stderr, "invalid ac code at %d %d\n", s->mb_x, s->mb_y);
return -1; if(level == 127){
}
if (code == 112) {
break; break;
} else if (code == 111) { } else if(level != 0) {
/* escape */ i += run;
run = get_bits(&s->gb, 6); j = scantable[i];
level = get_bits(&s->gb, 12); level= (level*qscale*quant_matrix[j])>>4;
level= (level + ((-1)<<11)) ^ ((-1)<<11); //sign extension level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
LAST_SKIP_BITS(re, &s->gb, 1);
} else { } else {
run = rl->table_run[code]; /* escape */
level = rl->table_level[code]; run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
if (get_bits1(&s->gb)) UPDATE_CACHE(re, &s->gb);
level = -level; level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
}
i += run; i += run;
if (i >= 64){ j = scantable[i];
fprintf(stderr, "run too long at %d %d\n", s->mb_x, s->mb_y); if(level<0){
level= (-level*qscale*quant_matrix[j])>>4;
level= -level;
}else{
level= (level*qscale*quant_matrix[j])>>4;
}
}
if (i > 63){
fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -1; return -1;
} }
j = scan_table[i];
dprintf("%d: run=%d level=%d\n", n, run, level); mismatch^= level;
level = (level * s->qscale * matrix[j]) / 16;
/* XXX: is it really necessary to saturate since the encoder
knows whats going on ? */
mismatch ^= level;
block[j] = level; block[j] = level;
i++;
} }
block[63] ^= (mismatch & 1); CLOSE_READER(re, &s->gb);
}
block[63]^= mismatch&1;
s->block_last_index[n] = i; s->block_last_index[n] = i;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment