Commit e51d6d27 authored by Michael Niedermayer's avatar Michael Niedermayer
Browse files

h263(+) clenaup & bugfixes

Originally committed as revision 1614 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent d671e2fe
......@@ -199,7 +199,7 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number)
put_bits(&s->pb, 3, format);
put_bits(&s->pb,1,0); /* Custom PCF: off */
s->umvplus = (s->pict_type == P_TYPE) && s->unrestricted_mv;
s->umvplus = s->unrestricted_mv;
put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */
put_bits(&s->pb,1,0); /* SAC: off */
put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */
......@@ -241,7 +241,9 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number)
/* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
if (s->umvplus)
put_bits(&s->pb,1,1); /* Limited according tables of Annex D */
// put_bits(&s->pb,1,1); /* Limited according tables of Annex D */
put_bits(&s->pb,2,1); /* unlimited */
put_bits(&s->pb, 5, s->qscale);
}
......@@ -1473,12 +1475,12 @@ void h263_encode_init(MpegEncContext *s)
break;
case CODEC_ID_H263P:
s->fcode_tab= umv_fcode_tab;
s->min_qcoeff= -128;
s->min_qcoeff= -127;
s->max_qcoeff= 127;
break;
//Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later
default: //nothing needed default table allready set in mpegvideo.c
s->min_qcoeff= -128;
s->min_qcoeff= -127;
s->max_qcoeff= 127;
s->y_dc_scale_table=
s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
......@@ -1506,26 +1508,26 @@ static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
rl = &rl_inter;
if (s->mb_intra && !s->h263_aic) {
/* DC coef */
level = block[0];
level = block[0];
/* 255 cannot be represented, so we clamp */
if (level > 254) {
level = 254;
block[0] = 254;
}
/* 0 cannot be represented also */
else if (!level) {
else if (level < 1) {
level = 1;
block[0] = 1;
}
if (level == 128)
put_bits(&s->pb, 8, 0xff);
else
put_bits(&s->pb, 8, level & 0xff);
i = 1;
if (level == 128)
put_bits(&s->pb, 8, 0xff);
else
put_bits(&s->pb, 8, level & 0xff);
i = 1;
} else {
i = 0;
if (s->h263_aic && s->mb_intra)
rl = &rl_intra_aic;
i = 0;
if (s->h263_aic && s->mb_intra)
rl = &rl_intra_aic;
}
/* AC coefs */
......@@ -1548,7 +1550,16 @@ static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
if (code == rl->n) {
put_bits(&s->pb, 1, last);
put_bits(&s->pb, 6, run);
put_bits(&s->pb, 8, slevel & 0xff);
assert(slevel != 0);
if(slevel < 128 && slevel > -128)
put_bits(&s->pb, 8, slevel & 0xff);
else{
put_bits(&s->pb, 8, 128);
put_bits(&s->pb, 5, slevel & 0x1f);
put_bits(&s->pb, 6, (slevel>>5)&0x3f);
}
} else {
put_bits(&s->pb, 1, sign);
}
......@@ -3188,7 +3199,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
/* 16x16 motion prediction */
s->mv_type = MV_TYPE_16X16;
h263_pred_motion(s, 0, &pred_x, &pred_y);
if (s->umvplus_dec)
if (s->umvplus)
mx = h263p_decode_umotion(s, pred_x);
else
mx = h263_decode_motion(s, pred_x, s->f_code);
......@@ -3196,7 +3207,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
if (mx >= 0xffff)
return -1;
if (s->umvplus_dec)
if (s->umvplus)
my = h263p_decode_umotion(s, pred_y);
else
my = h263_decode_motion(s, pred_y, s->f_code);
......@@ -3206,7 +3217,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->mv[0][0][0] = mx;
s->mv[0][0][1] = my;
if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1)
if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
}
} else {
......@@ -3214,14 +3225,14 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->mv_type = MV_TYPE_8X8;
for(i=0;i<4;i++) {
mot_val = h263_pred_motion(s, i, &pred_x, &pred_y);
if (s->umvplus_dec)
if (s->umvplus)
mx = h263p_decode_umotion(s, pred_x);
else
mx = h263_decode_motion(s, pred_x, s->f_code);
if (mx >= 0xffff)
return -1;
if (s->umvplus_dec)
if (s->umvplus)
my = h263p_decode_umotion(s, pred_y);
else
my = h263_decode_motion(s, pred_y, s->f_code);
......@@ -3229,7 +3240,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
return -1;
s->mv[0][i][0] = mx;
s->mv[0][i][1] = my;
if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1)
if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
mot_val[0] = mx;
mot_val[1] = my;
......@@ -3553,6 +3564,10 @@ static int h263_decode_block(MpegEncContext * s, DCTELEM * block,
}
} else {
level = get_bits(&s->gb, 8);
if((level&0x7F) == 0){
fprintf("illegal dc at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
if (level == 255)
level = 128;
}
......@@ -3579,10 +3594,16 @@ static int h263_decode_block(MpegEncContext * s, DCTELEM * block,
last = get_bits1(&s->gb);
run = get_bits(&s->gb, 6);
level = (int8_t)get_bits(&s->gb, 8);
if (s->h263_rv10 && level == -128) {
/* XXX: should patch encoder too */
level = get_bits(&s->gb, 12);
level= (level + ((-1)<<11)) ^ ((-1)<<11); //sign extension
if(level == -128){
if (s->h263_rv10) {
/* XXX: should patch encoder too */
level = get_bits(&s->gb, 12);
level= (level + ((-1)<<11)) ^ ((-1)<<11); //sign extension
}else{
level = get_bits(&s->gb, 5);
level += get_bits(&s->gb, 6)<<5;
level= (level + ((-1)<<10)) ^ ((-1)<<10); //sign extension
}
}
} else {
run = rl->table_run[code];
......@@ -3931,7 +3952,7 @@ int h263_decode_picture_header(MpegEncContext *s)
format = get_bits(&s->gb, 3);
dprintf("ufep=1, format: %d\n", format);
skip_bits(&s->gb,1); /* Custom PCF */
s->umvplus_dec = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */
s->umvplus = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */
skip_bits1(&s->gb); /* Syntax-based Arithmetic Coding (SAC) */
if (get_bits1(&s->gb) != 0) {
s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */
......@@ -4002,8 +4023,9 @@ int h263_decode_picture_header(MpegEncContext *s)
return -1;
s->width = width;
s->height = height;
if (s->umvplus_dec) {
skip_bits1(&s->gb); /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
if (s->umvplus) {
if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
skip_bits1(&s->gb);
}
}
......
......@@ -656,8 +656,7 @@ int MPV_encode_init(AVCodecContext *avctx)
s->h263_aic = 1;
/* These are just to be sure */
s->umvplus = 0;
s->umvplus_dec = 0;
s->umvplus = 1;
avctx->delay=0;
s->low_delay=1;
break;
......@@ -2908,17 +2907,14 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->qscale= (int)(s->frame_qscale + 0.5); //FIXME qscale / ... stuff for ME ratedistoration
if(s->msmpeg4_version){
if(s->pict_type==I_TYPE)
s->no_rounding=1;
else if(s->flipflop_rounding)
s->no_rounding ^= 1;
}else if(s->out_format == FMT_H263){
if(s->pict_type==I_TYPE)
s->no_rounding=0;
else if(s->pict_type!=B_TYPE)
if(s->pict_type==I_TYPE){
if(s->msmpeg4_version) s->no_rounding=1;
else s->no_rounding=0;
}else if(s->pict_type!=B_TYPE){
if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4)
s->no_rounding ^= 1;
}
/* Estimate motion for every MB */
s->mb_intra=0; //for the rate distoration & bit compare functions
if(s->pict_type != I_TYPE){
......@@ -2993,7 +2989,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
//printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum);
}
if(s->codec_id != CODEC_ID_H263P){ //FIXME use umvplus or something
if(!s->umvplus){
if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) {
s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER);
......
......@@ -251,7 +251,7 @@ typedef struct MpegEncContext {
int last_non_b_pict_type; /* used for mpeg4 gmc b-frames & ratecontrol */
int frame_rate_index;
/* motion compensation */
int unrestricted_mv;
int unrestricted_mv; /* mv can point outside of the coded picture */
int h263_long_vectors; /* use horrible h263v1 long vector mode */
DSPContext dsp; /* pointers for accelerated dsp fucntions */
......@@ -399,8 +399,7 @@ typedef struct MpegEncContext {
int gob_index;
/* H.263+ specific */
int umvplus;
int umvplus_dec;
int umvplus; /* == H263+ && unrestricted_mv */
int h263_aic; /* Advanded INTRA Coding (AIC) */
int h263_aic_dir; /* AIC direction: 0 = left, 1 = top */
......
......@@ -7,9 +7,9 @@ e573c2022c1a84ad56c131296de3eed3 *./data/a-msmpeg4.avi
8786aa956838234fe3e48d0ef8cbd46c *./data/out.yuv
3f3771cacabde5393aa6788e10352407 *./data/a-wmv1.avi
7261e23fd8ad1de6efee022051b936be *./data/out.yuv
5620fba72a9bbe771b21ce918fa77d10 *./data/a-h263.avi
658ffd4e5489ede8ac9ca7e00975b31c *./data/out.yuv
05a8cbec70adaaf2582467aaa1baf6e3 *./data/a-h263p.avi
8596e23c3f300cd42eb66750ac9d37af *./data/a-h263.avi
545df74e0aa443499600faedd10a7065 *./data/out.yuv
d7b1b397a978e7e66fb48ca784d0b1f7 *./data/a-h263p.avi
76dea7e8f5a4c7e77b80ce1ff4f632b5 *./data/out.yuv
cbb3e7118b48671c686d046e7c1ae4b0 *./data/a-odivx.avi
98bb113f0fa0d61fd3b0b1699ac6c69a *./data/out.yuv
......@@ -21,8 +21,8 @@ cbb3e7118b48671c686d046e7c1ae4b0 *./data/a-odivx.avi
da8e21c7b78b7a25558dc319524b91d8 *./data/out.yuv
5bcc6fd4b7dde27c74c633c761f0e5b1 *./data/a-mjpeg.avi
f23a9e50a559e174766ee808c48fea22 *./data/out.yuv
137d3ce0f14ab7bb48cb2de0f2c45818 *./data/a-rv10.rm
658ffd4e5489ede8ac9ca7e00975b31c *./data/out.yuv
4b37703d3dc03873f99603165c0fe11e *./data/a-rv10.rm
545df74e0aa443499600faedd10a7065 *./data/out.yuv
21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
116d1290ba1b4eb98fdee52e423417b1 *./data/out.wav
048b9c3444c788bac6ce5cc3a8f4db00 *./data/a-ac3.rm
......
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