|
|
|
@ -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);
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|