Commit 3e6a20a0 authored by Michael Niedermayer's avatar Michael Niedermayer

minor optimizations

fixing numbers.avi
 fixing ac prediction between MBs with different QP

Originally committed as revision 782 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 4afeaec9
...@@ -57,7 +57,7 @@ static int h263_decode_block(MpegEncContext * s, DCTELEM * block, ...@@ -57,7 +57,7 @@ static int h263_decode_block(MpegEncContext * s, DCTELEM * block,
int n, int coded); int n, int coded);
static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr); static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
int n, int coded); int n, int coded, int intra);
static int h263_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr); static int h263_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr);
static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n, static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n,
int dir); int dir);
...@@ -1414,17 +1414,37 @@ void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, ...@@ -1414,17 +1414,37 @@ void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n,
ac_val1 = ac_val; ac_val1 = ac_val;
if (s->ac_pred) { if (s->ac_pred) {
if (dir == 0) { if (dir == 0) {
const int xy= s->mb_x-1 + s->mb_y*s->mb_width;
/* left prediction */ /* left prediction */
ac_val -= 16; ac_val -= 16;
if(s->mb_x==0 || s->qscale == s->qscale_table[xy] || n==1 || n==3){
/* same qscale */
for(i=1;i<8;i++) { for(i=1;i<8;i++) {
block[block_permute_op(i*8)] += ac_val[i]; block[block_permute_op(i*8)] += ac_val[i];
} }
}else{
/* different qscale, we must rescale */
for(i=1;i<8;i++) {
block[block_permute_op(i*8)] += ROUNDED_DIV(ac_val[i]*s->qscale_table[xy], s->qscale);
}
}
} else { } else {
const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width;
/* top prediction */ /* top prediction */
ac_val -= 16 * s->block_wrap[n]; ac_val -= 16 * s->block_wrap[n];
if(s->mb_y==0 || s->qscale == s->qscale_table[xy] || n==2 || n==3){
/* same qscale */
for(i=1;i<8;i++) { for(i=1;i<8;i++) {
block[block_permute_op(i)] += ac_val[i + 8]; block[block_permute_op(i)] += ac_val[i + 8];
} }
}else{
/* different qscale, we must rescale */
for(i=1;i<8;i++) {
block[block_permute_op(i)] += ROUNDED_DIV(ac_val[i + 8]*s->qscale_table[xy], s->qscale);
}
}
} }
} }
/* left copy */ /* left copy */
...@@ -2344,7 +2364,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, ...@@ -2344,7 +2364,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s,
/* decode each block */ /* decode each block */
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1); int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1);
if(ret==DECODING_AC_LOST){ if(ret==DECODING_AC_LOST){
fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y); fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y);
s->decoding_error=DECODING_AC_LOST; s->decoding_error=DECODING_AC_LOST;
...@@ -2367,7 +2387,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, ...@@ -2367,7 +2387,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s,
if(s->decoding_error==0 && cbp){ if(s->decoding_error==0 && cbp){
/* decode each block */ /* decode each block */
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1); int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 0);
if(ret==DECODING_AC_LOST){ if(ret==DECODING_AC_LOST){
fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y); fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y);
s->decoding_error=DECODING_AC_LOST; s->decoding_error=DECODING_AC_LOST;
...@@ -2383,7 +2403,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, ...@@ -2383,7 +2403,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s,
/* decode each block */ /* decode each block */
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1); int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1);
if(ret==DECODING_AC_LOST){ if(ret==DECODING_AC_LOST){
fprintf(stderr, "texture corrupted at %d %d (trying to continue with dc only)\n", s->mb_x, s->mb_y); fprintf(stderr, "texture corrupted at %d %d (trying to continue with dc only)\n", s->mb_x, s->mb_y);
s->decoding_error=DECODING_AC_LOST; s->decoding_error=DECODING_AC_LOST;
...@@ -2697,12 +2717,26 @@ intra: ...@@ -2697,12 +2717,26 @@ intra:
s->qscale = 31; s->qscale = 31;
h263_dc_scale(s); h263_dc_scale(s);
} }
/* decode each block */
if (s->h263_pred) {
for (i = 0; i < 6; i++) {
if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1) < 0)
return -1;
}
} else {
for (i = 0; i < 6; i++) {
if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0)
return -1;
}
}
return 0;
} }
/* decode each block */ /* decode each block */
if (s->h263_pred) { if (s->h263_pred) {
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 0) < 0)
return -1; return -1;
} }
} else { } else {
...@@ -2915,16 +2949,16 @@ static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) ...@@ -2915,16 +2949,16 @@ static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
* returns DECODING_ACDC_LOST if an error was detected during DC decoding * returns DECODING_ACDC_LOST if an error was detected during DC decoding
*/ */
static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
int n, int coded) int n, int coded, int intra)
{ {
int level, i, last, run; int level, i, last, run;
int dc_pred_dir; int dc_pred_dir;
RLTable *rl; RLTable * rl;
RL_VLC_ELEM *rl_vlc; RL_VLC_ELEM * rl_vlc;
const UINT8 *scan_table; const UINT8 * scan_table;
int qmul, qadd; int qmul, qadd;
if (s->mb_intra) { if(intra) {
/* DC coef */ /* DC coef */
if(s->data_partitioning && s->pict_type!=B_TYPE){ if(s->data_partitioning && s->pict_type!=B_TYPE){
level = s->dc_val[0][ s->block_index[n] ]; level = s->dc_val[0][ s->block_index[n] ];
...@@ -3661,7 +3695,17 @@ int mpeg4_decode_picture_header(MpegEncContext * s) ...@@ -3661,7 +3695,17 @@ int mpeg4_decode_picture_header(MpegEncContext * s)
} }
s->scalability= get_bits1(&s->gb); s->scalability= get_bits1(&s->gb);
if(s->workaround_bugs==1) s->scalability=0;
if (s->scalability) { if (s->scalability) {
int dummy= s->hierachy_type= get_bits1(&s->gb);
int ref_layer_id= get_bits(&s->gb, 4);
int ref_layer_sampling_dir= get_bits1(&s->gb);
int h_sampling_factor_n= get_bits(&s->gb, 5);
int h_sampling_factor_m= get_bits(&s->gb, 5);
int v_sampling_factor_n= get_bits(&s->gb, 5);
int v_sampling_factor_m= get_bits(&s->gb, 5);
s->enhancement_type= get_bits1(&s->gb);
// bin shape stuff FIXME
printf("scalability not supported\n"); printf("scalability not supported\n");
} }
} }
...@@ -3817,6 +3861,14 @@ int mpeg4_decode_picture_header(MpegEncContext * s) ...@@ -3817,6 +3861,14 @@ int mpeg4_decode_picture_header(MpegEncContext * s)
if (s->shape!=RECT_SHAPE && s->pict_type!=I_TYPE) { if (s->shape!=RECT_SHAPE && s->pict_type!=I_TYPE) {
skip_bits1(&s->gb); // vop shape coding type skip_bits1(&s->gb); // vop shape coding type
} }
}else{
if(s->enhancement_type){
int load_backward_shape= get_bits1(&s->gb);
if(load_backward_shape){
printf("load backward shape isnt supported\n");
}
}
skip_bits(&s->gb, 2); //ref_select_code
} }
} }
/* detect buggy encoders which dont set the low_delay flag (divx4/xvid/opendivx)*/ /* detect buggy encoders which dont set the low_delay flag (divx4/xvid/opendivx)*/
......
...@@ -270,9 +270,9 @@ int MPV_common_init(MpegEncContext *s) ...@@ -270,9 +270,9 @@ int MPV_common_init(MpegEncContext *s)
/* cbp, ac_pred, pred_dir */ /* cbp, ac_pred, pred_dir */
CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(UINT8)) CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(UINT8))
CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(UINT8)) CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(UINT8))
CHECKED_ALLOCZ(s->qscale_table , s->mb_num * sizeof(UINT8))
} }
CHECKED_ALLOCZ(s->qscale_table , s->mb_num * sizeof(UINT8))
/* default structure is frame */ /* default structure is frame */
s->picture_structure = PICT_FRAME; s->picture_structure = PICT_FRAME;
...@@ -1414,8 +1414,10 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) ...@@ -1414,8 +1414,10 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
quant_store[mb_y][mb_x]=s->qscale; quant_store[mb_y][mb_x]=s->qscale;
//printf("[%02d][%02d] %d\n",mb_x,mb_y,s->qscale); //printf("[%02d][%02d] %d\n",mb_x,mb_y,s->qscale);
#else #else
/* even more obsolete, exists for mplayer xp only */
if(s->avctx->quant_store) s->avctx->quant_store[mb_y*s->avctx->qstride+mb_x] = s->qscale; if(s->avctx->quant_store) s->avctx->quant_store[mb_y*s->avctx->qstride+mb_x] = s->qscale;
#endif #endif
s->qscale_table[mb_xy]= s->qscale;
/* update DC predictors for P macroblocks */ /* update DC predictors for P macroblocks */
if (!s->mb_intra) { if (!s->mb_intra) {
......
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