avcodec/vc1: cleanup and simplification

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
zhaoxiu.zeng 2015-02-14 22:45:49 +08:00 committed by Michael Niedermayer
parent e4a6486c17
commit 38c619c1ed
1 changed files with 97 additions and 112 deletions

View File

@ -234,37 +234,34 @@ static int vop_dquant_decoding(VC1Context *v)
int pqdiff; int pqdiff;
//variable size //variable size
if (v->dquant == 2) { if (v->dquant != 2) {
pqdiff = get_bits(gb, 3);
if (pqdiff == 7)
v->altpq = get_bits(gb, 5);
else
v->altpq = v->pq + pqdiff + 1;
} else {
v->dquantfrm = get_bits1(gb); v->dquantfrm = get_bits1(gb);
if (v->dquantfrm) { if (!v->dquantfrm)
v->dqprofile = get_bits(gb, 2); return 0;
switch (v->dqprofile) {
case DQPROFILE_SINGLE_EDGE: v->dqprofile = get_bits(gb, 2);
case DQPROFILE_DOUBLE_EDGES: switch (v->dqprofile) {
v->dqsbedge = get_bits(gb, 2); case DQPROFILE_SINGLE_EDGE:
break; case DQPROFILE_DOUBLE_EDGES:
case DQPROFILE_ALL_MBS: v->dqsbedge = get_bits(gb, 2);
v->dqbilevel = get_bits1(gb); break;
if (!v->dqbilevel) case DQPROFILE_ALL_MBS:
v->halfpq = 0; v->dqbilevel = get_bits1(gb);
default: if (!v->dqbilevel) {
break; //Forbidden ? v->halfpq = 0;
} return 0;
if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS) {
pqdiff = get_bits(gb, 3);
if (pqdiff == 7)
v->altpq = get_bits(gb, 5);
else
v->altpq = v->pq + pqdiff + 1;
} }
default:
break; //Forbidden ?
} }
} }
pqdiff = get_bits(gb, 3);
if (pqdiff == 7)
v->altpq = get_bits(gb, 5);
else
v->altpq = v->pq + pqdiff + 1;
return 0; return 0;
} }
@ -335,8 +332,7 @@ int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitCo
return -1; return -1;
} }
v->extended_mv = get_bits1(gb); //common v->extended_mv = get_bits1(gb); //common
if (!v->profile && v->extended_mv) if (!v->profile && v->extended_mv) {
{
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"Extended MVs unavailable in Simple Profile\n"); "Extended MVs unavailable in Simple Profile\n");
return -1; return -1;
@ -345,8 +341,7 @@ int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitCo
v->vstransform = get_bits1(gb); //common v->vstransform = get_bits1(gb); //common
v->res_transtab = get_bits1(gb); v->res_transtab = get_bits1(gb);
if (v->res_transtab) if (v->res_transtab) {
{
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"1 for reserved RES_TRANSTAB is forbidden\n"); "1 for reserved RES_TRANSTAB is forbidden\n");
return -1; return -1;
@ -649,17 +644,14 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
v->rangeredfrm = 0; v->rangeredfrm = 0;
if (v->rangered) if (v->rangered)
v->rangeredfrm = get_bits1(gb); v->rangeredfrm = get_bits1(gb);
v->s.pict_type = get_bits1(gb); if (get_bits1(gb)) {
if (v->s.avctx->max_b_frames) { v->s.pict_type = AV_PICTURE_TYPE_P;
if (!v->s.pict_type) { } else {
if (get_bits1(gb)) if (v->s.avctx->max_b_frames && !get_bits1(gb)) {
v->s.pict_type = AV_PICTURE_TYPE_I; v->s.pict_type = AV_PICTURE_TYPE_B;
else
v->s.pict_type = AV_PICTURE_TYPE_B;
} else } else
v->s.pict_type = AV_PICTURE_TYPE_P; v->s.pict_type = AV_PICTURE_TYPE_I;
} else }
v->s.pict_type = v->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
v->bi_type = 0; v->bi_type = 0;
if (v->s.pict_type == AV_PICTURE_TYPE_B) { if (v->s.pict_type == AV_PICTURE_TYPE_B) {
@ -689,19 +681,25 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
v->pq = ff_vc1_pquant_table[0][pqindex]; v->pq = ff_vc1_pquant_table[0][pqindex];
else else
v->pq = ff_vc1_pquant_table[1][pqindex]; v->pq = ff_vc1_pquant_table[1][pqindex];
v->pquantizer = 1;
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pquantizer = pqindex < 9;
if (v->quantizer_mode == QUANT_NON_UNIFORM)
v->pquantizer = 0;
v->pqindex = pqindex; v->pqindex = pqindex;
if (pqindex < 9) if (pqindex < 9)
v->halfpq = get_bits1(gb); v->halfpq = get_bits1(gb);
else else
v->halfpq = 0; v->halfpq = 0;
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) switch (v->quantizer_mode) {
case QUANT_FRAME_IMPLICIT:
v->pquantizer = pqindex < 9;
break;
case QUANT_NON_UNIFORM:
v->pquantizer = 0;
break;
case QUANT_FRAME_EXPLICIT:
v->pquantizer = get_bits1(gb); v->pquantizer = get_bits1(gb);
break;
default:
v->pquantizer = 1;
break;
}
v->dquantfrm = 0; v->dquantfrm = 0;
if (v->extended_mv == 1) if (v->extended_mv == 1)
v->mvrange = get_unary(gb, 0, 3); v->mvrange = get_unary(gb, 0, 3);
@ -725,9 +723,7 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
switch (v->s.pict_type) { switch (v->s.pict_type) {
case AV_PICTURE_TYPE_P: case AV_PICTURE_TYPE_P:
if (v->pq < 5) v->tt_index = 0; v->tt_index = (v->pq > 4) + (v->pq > 12);
else if (v->pq < 13) v->tt_index = 1;
else v->tt_index = 2;
lowquant = (v->pq > 12) ? 0 : 1; lowquant = (v->pq > 12) ? 0 : 1;
v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)]; v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
@ -741,16 +737,15 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1); INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);
} }
v->qs_last = v->s.quarter_sample; v->qs_last = v->s.quarter_sample;
if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
v->s.quarter_sample = 0; v->s.quarter_sample = (v->mv_mode2 != MV_PMODE_1MV_HPEL &&
else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN) v->s.mspel = (v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
v->s.quarter_sample = 0; } else {
else v->s.quarter_sample = (v->mv_mode != MV_PMODE_1MV_HPEL &&
v->s.quarter_sample = 1; v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
} else v->s.mspel = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
v->s.quarter_sample = 1; }
v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode2 == MV_PMODE_MIXED_MV) ||
@ -779,21 +774,19 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
vop_dquant_decoding(v); vop_dquant_decoding(v);
} }
v->ttfrm = 0; //FIXME Is that so ?
if (v->vstransform) { if (v->vstransform) {
v->ttmbf = get_bits1(gb); v->ttmbf = get_bits1(gb);
if (v->ttmbf) { if (v->ttmbf) {
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
} } else
v->ttfrm = 0; //FIXME Is that so ?
} else { } else {
v->ttmbf = 1; v->ttmbf = 1;
v->ttfrm = TT_8X8; v->ttfrm = TT_8X8;
} }
break; break;
case AV_PICTURE_TYPE_B: case AV_PICTURE_TYPE_B:
if (v->pq < 5) v->tt_index = 0; v->tt_index = (v->pq > 4) + (v->pq > 12);
else if (v->pq < 13) v->tt_index = 1;
else v->tt_index = 2;
v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN; v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
v->qs_last = v->s.quarter_sample; v->qs_last = v->s.quarter_sample;
@ -819,12 +812,12 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
vop_dquant_decoding(v); vop_dquant_decoding(v);
} }
v->ttfrm = 0;
if (v->vstransform) { if (v->vstransform) {
v->ttmbf = get_bits1(gb); v->ttmbf = get_bits1(gb);
if (v->ttmbf) { if (v->ttmbf) {
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
} } else
v->ttfrm = 0;
} else { } else {
v->ttmbf = 1; v->ttmbf = 1;
v->ttfrm = TT_8X8; v->ttfrm = TT_8X8;
@ -859,11 +852,12 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
v->numref = 0; v->numref = 0;
v->p_frame_skipped = 0; v->p_frame_skipped = 0;
if (v->second_field) { if (v->second_field) {
if(v->fcm!=2 || v->field_mode!=1) if (v->fcm != ILACE_FIELD || v->field_mode!=1)
return -1; return -1;
v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
if (v->fptype & 4) if (v->fptype & 4)
v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B; v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
else
v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
v->s.current_picture_ptr->f->pict_type = v->s.pict_type; v->s.current_picture_ptr->f->pict_type = v->s.pict_type;
if (!v->pic_header_flag) if (!v->pic_header_flag)
goto parse_common_info; goto parse_common_info;
@ -889,10 +883,10 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
if (v->field_mode) { if (v->field_mode) {
v->s.mb_height = FFALIGN(v->s.height + 15 >> 4, 2); v->s.mb_height = FFALIGN(v->s.height + 15 >> 4, 2);
v->fptype = get_bits(gb, 3); v->fptype = get_bits(gb, 3);
v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
if (v->fptype & 4) // B-picture if (v->fptype & 4) // B-picture
v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B; v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
else
v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
} else { } else {
v->s.mb_height = v->s.height + 15 >> 4; v->s.mb_height = v->s.height + 15 >> 4;
switch (get_unary(gb, 0, 4)) { switch (get_unary(gb, 0, 4)) {
@ -974,24 +968,29 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
pqindex = get_bits(gb, 5); pqindex = get_bits(gb, 5);
if (!pqindex) if (!pqindex)
return -1; return -1;
v->pqindex = pqindex;
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pq = ff_vc1_pquant_table[0][pqindex]; v->pq = ff_vc1_pquant_table[0][pqindex];
else else
v->pq = ff_vc1_pquant_table[1][pqindex]; v->pq = ff_vc1_pquant_table[1][pqindex];
v->pquantizer = 1;
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pquantizer = pqindex < 9;
if (v->quantizer_mode == QUANT_NON_UNIFORM)
v->pquantizer = 0;
v->pqindex = pqindex; v->pqindex = pqindex;
if (pqindex < 9) if (pqindex < 9)
v->halfpq = get_bits1(gb); v->halfpq = get_bits1(gb);
else else
v->halfpq = 0; v->halfpq = 0;
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) switch (v->quantizer_mode) {
case QUANT_FRAME_IMPLICIT:
v->pquantizer = pqindex < 9;
break;
case QUANT_NON_UNIFORM:
v->pquantizer = 0;
break;
case QUANT_FRAME_EXPLICIT:
v->pquantizer = get_bits1(gb); v->pquantizer = get_bits1(gb);
break;
default:
v->pquantizer = 1;
break;
}
if (v->postprocflag) if (v->postprocflag)
v->postproc = get_bits(gb, 2); v->postproc = get_bits(gb, 2);
@ -1081,12 +1080,7 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
v->range_x = 1 << (v->k_x - 1); v->range_x = 1 << (v->k_x - 1);
v->range_y = 1 << (v->k_y - 1); v->range_y = 1 << (v->k_y - 1);
if (v->pq < 5) v->tt_index = (v->pq > 4) + (v->pq > 12);
v->tt_index = 0;
else if (v->pq < 13)
v->tt_index = 1;
else
v->tt_index = 2;
if (v->fcm != ILACE_FRAME) { if (v->fcm != ILACE_FRAME) {
int mvmode; int mvmode;
mvmode = get_unary(gb, 1, 4); mvmode = get_unary(gb, 1, 4);
@ -1130,18 +1124,15 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
v->last_use_ic = 1; v->last_use_ic = 1;
} }
v->qs_last = v->s.quarter_sample; v->qs_last = v->s.quarter_sample;
if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
v->s.quarter_sample = 0; v->s.quarter_sample = (v->mv_mode2 != MV_PMODE_1MV_HPEL &&
else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN) v->s.mspel = (v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
v->s.quarter_sample = 0; } else {
else v->s.quarter_sample = (v->mv_mode != MV_PMODE_1MV_HPEL &&
v->s.quarter_sample = 1; v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
} else v->s.mspel = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
v->s.quarter_sample = 1; }
v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN
|| (v->mv_mode == MV_PMODE_INTENSITY_COMP
&& v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
} }
if (v->fcm == PROGRESSIVE) { // progressive if (v->fcm == PROGRESSIVE) { // progressive
if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
@ -1192,12 +1183,12 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
vop_dquant_decoding(v); vop_dquant_decoding(v);
} }
v->ttfrm = 0; //FIXME Is that so ?
if (v->vstransform) { if (v->vstransform) {
v->ttmbf = get_bits1(gb); v->ttmbf = get_bits1(gb);
if (v->ttmbf) { if (v->ttmbf) {
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
} } else
v->ttfrm = 0; //FIXME Is that so ?
} else { } else {
v->ttmbf = 1; v->ttmbf = 1;
v->ttfrm = TT_8X8; v->ttfrm = TT_8X8;
@ -1220,12 +1211,7 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
v->range_x = 1 << (v->k_x - 1); v->range_x = 1 << (v->k_x - 1);
v->range_y = 1 << (v->k_y - 1); v->range_y = 1 << (v->k_y - 1);
if (v->pq < 5) v->tt_index = (v->pq > 4) + (v->pq > 12);
v->tt_index = 0;
else if (v->pq < 13)
v->tt_index = 1;
else
v->tt_index = 2;
if (v->field_mode) { if (v->field_mode) {
int mvmode; int mvmode;
@ -1313,12 +1299,12 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
vop_dquant_decoding(v); vop_dquant_decoding(v);
} }
v->ttfrm = 0;
if (v->vstransform) { if (v->vstransform) {
v->ttmbf = get_bits1(gb); v->ttmbf = get_bits1(gb);
if (v->ttmbf) { if (v->ttmbf) {
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
} } else
v->ttfrm = 0;
} else { } else {
v->ttmbf = 1; v->ttmbf = 1;
v->ttfrm = TT_8X8; v->ttfrm = TT_8X8;
@ -1344,11 +1330,10 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
vop_dquant_decoding(v); vop_dquant_decoding(v);
} }
v->bi_type = 0; v->bi_type = (v->s.pict_type == AV_PICTURE_TYPE_BI);
if (v->s.pict_type == AV_PICTURE_TYPE_BI) { if (v->bi_type)
v->s.pict_type = AV_PICTURE_TYPE_B; v->s.pict_type = AV_PICTURE_TYPE_B;
v->bi_type = 1;
}
return 0; return 0;
} }