Mercurial > libavcodec.hg
comparison h264.c @ 2314:9db5a4aab7e4 libavcodec
cbp_table cleanup
author | michael |
---|---|
date | Sat, 23 Oct 2004 19:12:21 +0000 |
parents | b5376aef1fe0 |
children | 29b67549d0cc |
comparison
equal
deleted
inserted
replaced
2313:b5376aef1fe0 | 2314:9db5a4aab7e4 |
---|---|
305 uint8_t cabac_state[399]; | 305 uint8_t cabac_state[399]; |
306 int cabac_init_idc; | 306 int cabac_init_idc; |
307 | 307 |
308 /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */ | 308 /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */ |
309 uint16_t *cbp_table; | 309 uint16_t *cbp_table; |
310 int top_cbp; | |
311 int left_cbp; | |
310 /* chroma_pred_mode for i4x4 or i16x16, else 0 */ | 312 /* chroma_pred_mode for i4x4 or i16x16, else 0 */ |
311 uint8_t *chroma_pred_mode_table; | 313 uint8_t *chroma_pred_mode_table; |
312 int last_qscale_diff; | 314 int last_qscale_diff; |
313 int16_t (*mvd_table[2])[2]; | 315 int16_t (*mvd_table[2])[2]; |
314 int16_t mvd_cache[2][5*8][2]; | 316 int16_t mvd_cache[2][5*8][2]; |
511 h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][7]; | 513 h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][7]; |
512 h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8]; | 514 h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8]; |
513 | 515 |
514 h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][10]; | 516 h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][10]; |
515 h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11]; | 517 h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11]; |
518 | |
519 h->top_cbp= h->cbp_table[top_xy]; | |
516 }else{ | 520 }else{ |
517 h->non_zero_count_cache[4+8*0]= | 521 h->non_zero_count_cache[4+8*0]= |
518 h->non_zero_count_cache[5+8*0]= | 522 h->non_zero_count_cache[5+8*0]= |
519 h->non_zero_count_cache[6+8*0]= | 523 h->non_zero_count_cache[6+8*0]= |
520 h->non_zero_count_cache[7+8*0]= | 524 h->non_zero_count_cache[7+8*0]= |
521 | 525 |
522 h->non_zero_count_cache[1+8*0]= | 526 h->non_zero_count_cache[1+8*0]= |
523 h->non_zero_count_cache[2+8*0]= | 527 h->non_zero_count_cache[2+8*0]= |
524 | 528 |
525 h->non_zero_count_cache[1+8*3]= | 529 h->non_zero_count_cache[1+8*3]= |
526 h->non_zero_count_cache[2+8*3]= 64; | 530 h->non_zero_count_cache[2+8*3]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
531 | |
532 if(IS_INTRA(mb_type)) h->top_cbp= 0x1C0; | |
533 else h->top_cbp= 0; | |
527 } | 534 } |
528 | 535 |
529 if(left_type[0]){ | 536 if(left_type[0]){ |
530 h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][6]; | 537 h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][6]; |
531 h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][5]; | 538 h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][5]; |
532 h->non_zero_count_cache[0+8*1]= h->non_zero_count[left_xy[0]][9]; //FIXME left_block | 539 h->non_zero_count_cache[0+8*1]= h->non_zero_count[left_xy[0]][9]; //FIXME left_block |
533 h->non_zero_count_cache[0+8*4]= h->non_zero_count[left_xy[0]][12]; | 540 h->non_zero_count_cache[0+8*4]= h->non_zero_count[left_xy[0]][12]; |
541 h->left_cbp= h->cbp_table[left_xy[0]]; //FIXME interlacing | |
534 }else{ | 542 }else{ |
535 h->non_zero_count_cache[3+8*1]= | 543 h->non_zero_count_cache[3+8*1]= |
536 h->non_zero_count_cache[3+8*2]= | 544 h->non_zero_count_cache[3+8*2]= |
537 h->non_zero_count_cache[0+8*1]= | 545 h->non_zero_count_cache[0+8*1]= |
538 h->non_zero_count_cache[0+8*4]= 64; | 546 h->non_zero_count_cache[0+8*4]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
547 | |
548 if(IS_INTRA(mb_type)) h->left_cbp= 0x1C0;//FIXME interlacing | |
549 else h->left_cbp= 0; | |
539 } | 550 } |
540 | 551 |
541 if(left_type[1]){ | 552 if(left_type[1]){ |
542 h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[1]][4]; | 553 h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[1]][4]; |
543 h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[1]][3]; | 554 h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[1]][3]; |
545 h->non_zero_count_cache[0+8*5]= h->non_zero_count[left_xy[1]][11]; | 556 h->non_zero_count_cache[0+8*5]= h->non_zero_count[left_xy[1]][11]; |
546 }else{ | 557 }else{ |
547 h->non_zero_count_cache[3+8*3]= | 558 h->non_zero_count_cache[3+8*3]= |
548 h->non_zero_count_cache[3+8*4]= | 559 h->non_zero_count_cache[3+8*4]= |
549 h->non_zero_count_cache[0+8*2]= | 560 h->non_zero_count_cache[0+8*2]= |
550 h->non_zero_count_cache[0+8*5]= 64; | 561 h->non_zero_count_cache[0+8*5]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; |
551 } | 562 } |
552 | 563 |
553 #if 1 | 564 #if 1 |
554 if(IS_INTER(mb_type)){ | 565 if(IS_INTER(mb_type)){ |
555 int list; | 566 int list; |
4010 } | 4021 } |
4011 } | 4022 } |
4012 return cbp; | 4023 return cbp; |
4013 } | 4024 } |
4014 static int decode_cabac_mb_cbp_chroma( H264Context *h) { | 4025 static int decode_cabac_mb_cbp_chroma( H264Context *h) { |
4015 MpegEncContext * const s = &h->s; | |
4016 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; | |
4017 int ctx; | 4026 int ctx; |
4018 int cbp_a, cbp_b; | 4027 int cbp_a, cbp_b; |
4019 | 4028 |
4020 /* No need to test for skip */ | 4029 cbp_a = (h->left_cbp>>4)&0x03; |
4021 if( s->mb_x > 0 ) | 4030 cbp_b = (h-> top_cbp>>4)&0x03; |
4022 cbp_a = (h->cbp_table[mb_xy-1]>>4)&0x03; | |
4023 else | |
4024 cbp_a = -1; | |
4025 | |
4026 if( s->mb_y > 0 ) | |
4027 cbp_b = (h->cbp_table[mb_xy-s->mb_stride]>>4)&0x03; | |
4028 else | |
4029 cbp_b = -1; | |
4030 | 4031 |
4031 ctx = 0; | 4032 ctx = 0; |
4032 if( cbp_a > 0 ) ctx++; | 4033 if( cbp_a > 0 ) ctx++; |
4033 if( cbp_b > 0 ) ctx += 2; | 4034 if( cbp_b > 0 ) ctx += 2; |
4034 if( get_cabac( &h->cabac, &h->cabac_state[77 + ctx] ) == 0 ) | 4035 if( get_cabac( &h->cabac, &h->cabac_state[77 + ctx] ) == 0 ) |
4035 return 0; | 4036 return 0; |
4036 | 4037 |
4037 ctx = 4; | 4038 ctx = 4; |
4038 if( cbp_a == 2 ) ctx++; | 4039 if( cbp_a == 2 ) ctx++; |
4039 if( cbp_b == 2 ) ctx += 2; | 4040 if( cbp_b == 2 ) ctx += 2; |
4040 if( get_cabac( &h->cabac, &h->cabac_state[77 + ctx] ) ) | 4041 return 1 + get_cabac( &h->cabac, &h->cabac_state[77 + ctx] ); |
4041 return 2; | |
4042 else | |
4043 return 1; | |
4044 } | 4042 } |
4045 static int decode_cabac_mb_dqp( H264Context *h) { | 4043 static int decode_cabac_mb_dqp( H264Context *h) { |
4046 MpegEncContext * const s = &h->s; | 4044 MpegEncContext * const s = &h->s; |
4047 int mbn_xy; | 4045 int mbn_xy; |
4048 int ctx = 0; | 4046 int ctx = 0; |
4154 return mvd; | 4152 return mvd; |
4155 } | 4153 } |
4156 | 4154 |
4157 | 4155 |
4158 static int get_cabac_cbf_ctx( H264Context *h, int cat, int idx ) { | 4156 static int get_cabac_cbf_ctx( H264Context *h, int cat, int idx ) { |
4159 MpegEncContext * const s = &h->s; | 4157 int nza, nzb; |
4160 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; | |
4161 int mba_xy = -1; | |
4162 int mbb_xy = -1; | |
4163 | |
4164 int nza = -1; | |
4165 int nzb = -1; | |
4166 int ctx = 0; | 4158 int ctx = 0; |
4167 | 4159 |
4168 if( cat == 0 ) { | 4160 if( cat == 0 ) { |
4169 if( s->mb_x > 0 ) { | 4161 nza = h->left_cbp&0x100; |
4170 mba_xy = mb_xy - 1; | 4162 nzb = h-> top_cbp&0x100; |
4171 if( IS_INTRA16x16(s->current_picture.mb_type[mba_xy] ) ) | |
4172 nza = h->cbp_table[mba_xy]&0x100; | |
4173 } | |
4174 if( s->mb_y > 0 ) { | |
4175 mbb_xy = mb_xy - s->mb_stride; | |
4176 if( IS_INTRA16x16(s->current_picture.mb_type[mbb_xy] ) ) | |
4177 nzb = h->cbp_table[mbb_xy]&0x100; | |
4178 } | |
4179 } else if( cat == 1 || cat == 2 ) { | 4163 } else if( cat == 1 || cat == 2 ) { |
4180 int i8x8a, i8x8b; | 4164 nza = h->non_zero_count_cache[scan8[idx] - 1]; |
4181 int x, y; | 4165 nzb = h->non_zero_count_cache[scan8[idx] - 8]; |
4182 | |
4183 x = block_idx_x[idx]; | |
4184 y = block_idx_y[idx]; | |
4185 | |
4186 if( x > 0 ) | |
4187 mba_xy = mb_xy; | |
4188 else if( s->mb_x > 0 ) | |
4189 mba_xy = mb_xy - 1; | |
4190 | |
4191 if( y > 0 ) | |
4192 mbb_xy = mb_xy; | |
4193 else if( s->mb_y > 0 ) | |
4194 mbb_xy = mb_xy - s->mb_stride; | |
4195 | |
4196 /* No need to test for skip */ | |
4197 if( mba_xy >= 0 ) { | |
4198 i8x8a = block_idx_xy[(x-1)&0x03][y]/4; | |
4199 | |
4200 if( !IS_INTRA_PCM(s->current_picture.mb_type[mba_xy] ) && | |
4201 ((h->cbp_table[mba_xy]&0x0f)>>i8x8a)) | |
4202 nza = h->non_zero_count_cache[scan8[idx] - 1]; | |
4203 } | |
4204 | |
4205 if( mbb_xy >= 0 ) { | |
4206 i8x8b = block_idx_xy[x][(y-1)&0x03]/4; | |
4207 | |
4208 if( !IS_INTRA_PCM(s->current_picture.mb_type[mbb_xy] ) && | |
4209 ((h->cbp_table[mbb_xy]&0x0f)>>i8x8b)) | |
4210 nzb = h->non_zero_count_cache[scan8[idx] - 8]; | |
4211 } | |
4212 } else if( cat == 3 ) { | 4166 } else if( cat == 3 ) { |
4213 if( s->mb_x > 0 ) { | 4167 nza = (h->left_cbp>>(6+idx))&0x01; |
4214 mba_xy = mb_xy - 1; | 4168 nzb = (h-> top_cbp>>(6+idx))&0x01; |
4215 | 4169 } else { |
4216 if( !IS_INTRA_PCM(s->current_picture.mb_type[mba_xy] ) && | 4170 assert(cat == 4); |
4217 (h->cbp_table[mba_xy]&0x30) ) | 4171 nza = h->non_zero_count_cache[scan8[16+idx] - 1]; |
4218 nza = (h->cbp_table[mba_xy]>>(6+idx))&0x01; | 4172 nzb = h->non_zero_count_cache[scan8[16+idx] - 8]; |
4219 } | 4173 } |
4220 if( s->mb_y > 0 ) { | 4174 |
4221 mbb_xy = mb_xy - s->mb_stride; | 4175 if( nza > 0 ) |
4222 | |
4223 if( !IS_INTRA_PCM(s->current_picture.mb_type[mbb_xy] ) && | |
4224 (h->cbp_table[mbb_xy]&0x30) ) | |
4225 nzb = (h->cbp_table[mbb_xy]>>(6+idx))&0x01; | |
4226 } | |
4227 } else if( cat == 4 ) { | |
4228 int idxc = idx % 4 ; | |
4229 if( idxc == 1 || idxc == 3 ) | |
4230 mba_xy = mb_xy; | |
4231 else if( s->mb_x > 0 ) | |
4232 mba_xy = mb_xy -1; | |
4233 | |
4234 if( idxc == 2 || idxc == 3 ) | |
4235 mbb_xy = mb_xy; | |
4236 else if( s->mb_y > 0 ) | |
4237 mbb_xy = mb_xy - s->mb_stride; | |
4238 | |
4239 if( mba_xy >= 0 && | |
4240 !IS_INTRA_PCM(s->current_picture.mb_type[mba_xy] ) && | |
4241 (h->cbp_table[mba_xy]&0x30) == 0x20 ) | |
4242 nza = h->non_zero_count_cache[scan8[16+idx] - 1]; | |
4243 | |
4244 if( mbb_xy >= 0 && | |
4245 !IS_INTRA_PCM(s->current_picture.mb_type[mbb_xy] ) && | |
4246 (h->cbp_table[mbb_xy]&0x30) == 0x20 ) | |
4247 nzb = h->non_zero_count_cache[scan8[16+idx] - 8]; | |
4248 } | |
4249 | |
4250 if( ( mba_xy < 0 && IS_INTRA( s->current_picture.mb_type[mb_xy] ) ) || | |
4251 ( mba_xy >= 0 && IS_INTRA_PCM(s->current_picture.mb_type[mba_xy] ) ) || | |
4252 nza > 0 ) | |
4253 ctx++; | 4176 ctx++; |
4254 | 4177 |
4255 if( ( mbb_xy < 0 && IS_INTRA( s->current_picture.mb_type[mb_xy] ) ) || | 4178 if( nzb > 0 ) |
4256 ( mbb_xy >= 0 && IS_INTRA_PCM(s->current_picture.mb_type[mbb_xy] ) ) || | |
4257 nzb > 0 ) | |
4258 ctx += 2; | 4179 ctx += 2; |
4259 | 4180 |
4260 return ctx + 4 * cat; | 4181 return ctx + 4 * cat; |
4261 } | 4182 } |
4262 | 4183 |
4461 s->current_picture.mb_type[mb_xy]= mb_type; | 4382 s->current_picture.mb_type[mb_xy]= mb_type; |
4462 h->slice_table[ mb_xy ]= h->slice_num; | 4383 h->slice_table[ mb_xy ]= h->slice_num; |
4463 | 4384 |
4464 if(IS_INTRA_PCM(mb_type)) { | 4385 if(IS_INTRA_PCM(mb_type)) { |
4465 /* TODO */ | 4386 /* TODO */ |
4466 h->cbp_table[mb_xy] = 0xf +4*2; | 4387 assert(0); |
4388 h->cbp_table[mb_xy] = 0xf +4*2; //FIXME ?! | |
4389 h->cbp_table[mb_xy] |= 0x1C0; | |
4467 h->chroma_pred_mode_table[mb_xy] = 0; | 4390 h->chroma_pred_mode_table[mb_xy] = 0; |
4468 s->current_picture.qscale_table[mb_xy]= s->qscale; | 4391 s->current_picture.qscale_table[mb_xy]= s->qscale; |
4469 return -1; | 4392 return -1; |
4470 } | 4393 } |
4471 | 4394 |