Mercurial > libavcodec.hg
comparison h263.c @ 1089:7e79a58954b1 libavcodec
h263(+) clenaup & bugfixes
author | michaelni |
---|---|
date | Fri, 28 Feb 2003 13:07:07 +0000 |
parents | 6da5ae9ee199 |
children | 8216533dd959 |
comparison
equal
deleted
inserted
replaced
1088:bb27c685fc72 | 1089:7e79a58954b1 |
---|---|
197 put_bits(&s->pb,3,6); /* Custom Source Format */ | 197 put_bits(&s->pb,3,6); /* Custom Source Format */ |
198 else | 198 else |
199 put_bits(&s->pb, 3, format); | 199 put_bits(&s->pb, 3, format); |
200 | 200 |
201 put_bits(&s->pb,1,0); /* Custom PCF: off */ | 201 put_bits(&s->pb,1,0); /* Custom PCF: off */ |
202 s->umvplus = (s->pict_type == P_TYPE) && s->unrestricted_mv; | 202 s->umvplus = s->unrestricted_mv; |
203 put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */ | 203 put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */ |
204 put_bits(&s->pb,1,0); /* SAC: off */ | 204 put_bits(&s->pb,1,0); /* SAC: off */ |
205 put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */ | 205 put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */ |
206 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ | 206 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ |
207 put_bits(&s->pb,1,0); /* Deblocking Filter: off */ | 207 put_bits(&s->pb,1,0); /* Deblocking Filter: off */ |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | 242 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
243 if (s->umvplus) | 243 if (s->umvplus) |
244 put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ | 244 // put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ |
245 put_bits(&s->pb,2,1); /* unlimited */ | |
246 | |
245 put_bits(&s->pb, 5, s->qscale); | 247 put_bits(&s->pb, 5, s->qscale); |
246 } | 248 } |
247 | 249 |
248 put_bits(&s->pb, 1, 0); /* no PEI */ | 250 put_bits(&s->pb, 1, 0); /* no PEI */ |
249 | 251 |
1471 s->chroma_dc_vlc_length= uni_DCtab_chrom_len; | 1473 s->chroma_dc_vlc_length= uni_DCtab_chrom_len; |
1472 s->ac_esc_length= 7+2+1+6+1+12+1; | 1474 s->ac_esc_length= 7+2+1+6+1+12+1; |
1473 break; | 1475 break; |
1474 case CODEC_ID_H263P: | 1476 case CODEC_ID_H263P: |
1475 s->fcode_tab= umv_fcode_tab; | 1477 s->fcode_tab= umv_fcode_tab; |
1476 s->min_qcoeff= -128; | 1478 s->min_qcoeff= -127; |
1477 s->max_qcoeff= 127; | 1479 s->max_qcoeff= 127; |
1478 break; | 1480 break; |
1479 //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later | 1481 //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later |
1480 default: //nothing needed default table allready set in mpegvideo.c | 1482 default: //nothing needed default table allready set in mpegvideo.c |
1481 s->min_qcoeff= -128; | 1483 s->min_qcoeff= -127; |
1482 s->max_qcoeff= 127; | 1484 s->max_qcoeff= 127; |
1483 s->y_dc_scale_table= | 1485 s->y_dc_scale_table= |
1484 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | 1486 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; |
1485 } | 1487 } |
1486 | 1488 |
1504 RLTable *rl; | 1506 RLTable *rl; |
1505 | 1507 |
1506 rl = &rl_inter; | 1508 rl = &rl_inter; |
1507 if (s->mb_intra && !s->h263_aic) { | 1509 if (s->mb_intra && !s->h263_aic) { |
1508 /* DC coef */ | 1510 /* DC coef */ |
1509 level = block[0]; | 1511 level = block[0]; |
1510 /* 255 cannot be represented, so we clamp */ | 1512 /* 255 cannot be represented, so we clamp */ |
1511 if (level > 254) { | 1513 if (level > 254) { |
1512 level = 254; | 1514 level = 254; |
1513 block[0] = 254; | 1515 block[0] = 254; |
1514 } | 1516 } |
1515 /* 0 cannot be represented also */ | 1517 /* 0 cannot be represented also */ |
1516 else if (!level) { | 1518 else if (level < 1) { |
1517 level = 1; | 1519 level = 1; |
1518 block[0] = 1; | 1520 block[0] = 1; |
1519 } | 1521 } |
1520 if (level == 128) | 1522 if (level == 128) |
1521 put_bits(&s->pb, 8, 0xff); | 1523 put_bits(&s->pb, 8, 0xff); |
1522 else | 1524 else |
1523 put_bits(&s->pb, 8, level & 0xff); | 1525 put_bits(&s->pb, 8, level & 0xff); |
1524 i = 1; | 1526 i = 1; |
1525 } else { | 1527 } else { |
1526 i = 0; | 1528 i = 0; |
1527 if (s->h263_aic && s->mb_intra) | 1529 if (s->h263_aic && s->mb_intra) |
1528 rl = &rl_intra_aic; | 1530 rl = &rl_intra_aic; |
1529 } | 1531 } |
1530 | 1532 |
1531 /* AC coefs */ | 1533 /* AC coefs */ |
1532 last_index = s->block_last_index[n]; | 1534 last_index = s->block_last_index[n]; |
1533 last_non_zero = i - 1; | 1535 last_non_zero = i - 1; |
1546 code = get_rl_index(rl, last, run, level); | 1548 code = get_rl_index(rl, last, run, level); |
1547 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | 1549 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); |
1548 if (code == rl->n) { | 1550 if (code == rl->n) { |
1549 put_bits(&s->pb, 1, last); | 1551 put_bits(&s->pb, 1, last); |
1550 put_bits(&s->pb, 6, run); | 1552 put_bits(&s->pb, 6, run); |
1551 put_bits(&s->pb, 8, slevel & 0xff); | 1553 |
1554 assert(slevel != 0); | |
1555 | |
1556 if(slevel < 128 && slevel > -128) | |
1557 put_bits(&s->pb, 8, slevel & 0xff); | |
1558 else{ | |
1559 put_bits(&s->pb, 8, 128); | |
1560 put_bits(&s->pb, 5, slevel & 0x1f); | |
1561 put_bits(&s->pb, 6, (slevel>>5)&0x3f); | |
1562 } | |
1552 } else { | 1563 } else { |
1553 put_bits(&s->pb, 1, sign); | 1564 put_bits(&s->pb, 1, sign); |
1554 } | 1565 } |
1555 last_non_zero = i; | 1566 last_non_zero = i; |
1556 } | 1567 } |
3186 }else{ | 3197 }else{ |
3187 PRINT_MB_TYPE("P"); | 3198 PRINT_MB_TYPE("P"); |
3188 /* 16x16 motion prediction */ | 3199 /* 16x16 motion prediction */ |
3189 s->mv_type = MV_TYPE_16X16; | 3200 s->mv_type = MV_TYPE_16X16; |
3190 h263_pred_motion(s, 0, &pred_x, &pred_y); | 3201 h263_pred_motion(s, 0, &pred_x, &pred_y); |
3191 if (s->umvplus_dec) | 3202 if (s->umvplus) |
3192 mx = h263p_decode_umotion(s, pred_x); | 3203 mx = h263p_decode_umotion(s, pred_x); |
3193 else | 3204 else |
3194 mx = h263_decode_motion(s, pred_x, s->f_code); | 3205 mx = h263_decode_motion(s, pred_x, s->f_code); |
3195 | 3206 |
3196 if (mx >= 0xffff) | 3207 if (mx >= 0xffff) |
3197 return -1; | 3208 return -1; |
3198 | 3209 |
3199 if (s->umvplus_dec) | 3210 if (s->umvplus) |
3200 my = h263p_decode_umotion(s, pred_y); | 3211 my = h263p_decode_umotion(s, pred_y); |
3201 else | 3212 else |
3202 my = h263_decode_motion(s, pred_y, s->f_code); | 3213 my = h263_decode_motion(s, pred_y, s->f_code); |
3203 | 3214 |
3204 if (my >= 0xffff) | 3215 if (my >= 0xffff) |
3205 return -1; | 3216 return -1; |
3206 s->mv[0][0][0] = mx; | 3217 s->mv[0][0][0] = mx; |
3207 s->mv[0][0][1] = my; | 3218 s->mv[0][0][1] = my; |
3208 | 3219 |
3209 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) | 3220 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
3210 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 3221 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
3211 } | 3222 } |
3212 } else { | 3223 } else { |
3213 PRINT_MB_TYPE("4"); | 3224 PRINT_MB_TYPE("4"); |
3214 s->mv_type = MV_TYPE_8X8; | 3225 s->mv_type = MV_TYPE_8X8; |
3215 for(i=0;i<4;i++) { | 3226 for(i=0;i<4;i++) { |
3216 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); | 3227 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); |
3217 if (s->umvplus_dec) | 3228 if (s->umvplus) |
3218 mx = h263p_decode_umotion(s, pred_x); | 3229 mx = h263p_decode_umotion(s, pred_x); |
3219 else | 3230 else |
3220 mx = h263_decode_motion(s, pred_x, s->f_code); | 3231 mx = h263_decode_motion(s, pred_x, s->f_code); |
3221 if (mx >= 0xffff) | 3232 if (mx >= 0xffff) |
3222 return -1; | 3233 return -1; |
3223 | 3234 |
3224 if (s->umvplus_dec) | 3235 if (s->umvplus) |
3225 my = h263p_decode_umotion(s, pred_y); | 3236 my = h263p_decode_umotion(s, pred_y); |
3226 else | 3237 else |
3227 my = h263_decode_motion(s, pred_y, s->f_code); | 3238 my = h263_decode_motion(s, pred_y, s->f_code); |
3228 if (my >= 0xffff) | 3239 if (my >= 0xffff) |
3229 return -1; | 3240 return -1; |
3230 s->mv[0][i][0] = mx; | 3241 s->mv[0][i][0] = mx; |
3231 s->mv[0][i][1] = my; | 3242 s->mv[0][i][1] = my; |
3232 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) | 3243 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
3233 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | 3244 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
3234 mot_val[0] = mx; | 3245 mot_val[0] = mx; |
3235 mot_val[1] = my; | 3246 mot_val[1] = my; |
3236 } | 3247 } |
3237 } | 3248 } |
3551 } else { | 3562 } else { |
3552 s->rv10_first_dc_coded[component] = 1; | 3563 s->rv10_first_dc_coded[component] = 1; |
3553 } | 3564 } |
3554 } else { | 3565 } else { |
3555 level = get_bits(&s->gb, 8); | 3566 level = get_bits(&s->gb, 8); |
3567 if((level&0x7F) == 0){ | |
3568 fprintf("illegal dc at %d %d\n", s->mb_x, s->mb_y); | |
3569 return -1; | |
3570 } | |
3556 if (level == 255) | 3571 if (level == 255) |
3557 level = 128; | 3572 level = 128; |
3558 } | 3573 } |
3559 block[0] = level; | 3574 block[0] = level; |
3560 i = 1; | 3575 i = 1; |
3577 if (code == rl->n) { | 3592 if (code == rl->n) { |
3578 /* escape */ | 3593 /* escape */ |
3579 last = get_bits1(&s->gb); | 3594 last = get_bits1(&s->gb); |
3580 run = get_bits(&s->gb, 6); | 3595 run = get_bits(&s->gb, 6); |
3581 level = (int8_t)get_bits(&s->gb, 8); | 3596 level = (int8_t)get_bits(&s->gb, 8); |
3582 if (s->h263_rv10 && level == -128) { | 3597 if(level == -128){ |
3583 /* XXX: should patch encoder too */ | 3598 if (s->h263_rv10) { |
3584 level = get_bits(&s->gb, 12); | 3599 /* XXX: should patch encoder too */ |
3585 level= (level + ((-1)<<11)) ^ ((-1)<<11); //sign extension | 3600 level = get_bits(&s->gb, 12); |
3601 level= (level + ((-1)<<11)) ^ ((-1)<<11); //sign extension | |
3602 }else{ | |
3603 level = get_bits(&s->gb, 5); | |
3604 level += get_bits(&s->gb, 6)<<5; | |
3605 level= (level + ((-1)<<10)) ^ ((-1)<<10); //sign extension | |
3606 } | |
3586 } | 3607 } |
3587 } else { | 3608 } else { |
3588 run = rl->table_run[code]; | 3609 run = rl->table_run[code]; |
3589 level = rl->table_level[code]; | 3610 level = rl->table_level[code]; |
3590 last = code >= rl->last; | 3611 last = code >= rl->last; |
3929 if (ufep == 1) { | 3950 if (ufep == 1) { |
3930 /* OPPTYPE */ | 3951 /* OPPTYPE */ |
3931 format = get_bits(&s->gb, 3); | 3952 format = get_bits(&s->gb, 3); |
3932 dprintf("ufep=1, format: %d\n", format); | 3953 dprintf("ufep=1, format: %d\n", format); |
3933 skip_bits(&s->gb,1); /* Custom PCF */ | 3954 skip_bits(&s->gb,1); /* Custom PCF */ |
3934 s->umvplus_dec = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ | 3955 s->umvplus = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ |
3935 skip_bits1(&s->gb); /* Syntax-based Arithmetic Coding (SAC) */ | 3956 skip_bits1(&s->gb); /* Syntax-based Arithmetic Coding (SAC) */ |
3936 if (get_bits1(&s->gb) != 0) { | 3957 if (get_bits1(&s->gb) != 0) { |
3937 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | 3958 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ |
3938 } | 3959 } |
3939 if (get_bits1(&s->gb) != 0) { /* Advanced Intra Coding (AIC) */ | 3960 if (get_bits1(&s->gb) != 0) { /* Advanced Intra Coding (AIC) */ |
4000 } | 4021 } |
4001 if ((width == 0) || (height == 0)) | 4022 if ((width == 0) || (height == 0)) |
4002 return -1; | 4023 return -1; |
4003 s->width = width; | 4024 s->width = width; |
4004 s->height = height; | 4025 s->height = height; |
4005 if (s->umvplus_dec) { | 4026 if (s->umvplus) { |
4006 skip_bits1(&s->gb); /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | 4027 if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
4028 skip_bits1(&s->gb); | |
4007 } | 4029 } |
4008 } | 4030 } |
4009 | 4031 |
4010 s->qscale = get_bits(&s->gb, 5); | 4032 s->qscale = get_bits(&s->gb, 5); |
4011 } | 4033 } |