Mercurial > libavcodec.hg
comparison h264.c @ 3138:c12fc3d1c612 libavcodec
minor simplifications in cabac_mb_type
author | lorenm |
---|---|
date | Wed, 22 Feb 2006 05:59:44 +0000 |
parents | dd3f6be492bd |
children | 84406a59134c |
comparison
equal
deleted
inserted
replaced
3137:876d6280faf7 | 3138:c12fc3d1c612 |
---|---|
5245 | 5245 |
5246 if( get_cabac_terminate( &h->cabac ) ) | 5246 if( get_cabac_terminate( &h->cabac ) ) |
5247 return 25; /* PCM */ | 5247 return 25; /* PCM */ |
5248 | 5248 |
5249 mb_type = 1; /* I16x16 */ | 5249 mb_type = 1; /* I16x16 */ |
5250 if( get_cabac( &h->cabac, &state[1] ) ) | 5250 mb_type += 12 * get_cabac( &h->cabac, &state[1] ); /* cbp_luma != 0 */ |
5251 mb_type += 12; /* cbp_luma != 0 */ | 5251 if( get_cabac( &h->cabac, &state[2] ) ) /* cbp_chroma */ |
5252 | 5252 mb_type += 4 + 4 * get_cabac( &h->cabac, &state[2+intra_slice] ); |
5253 if( get_cabac( &h->cabac, &state[2] ) ) { | 5253 mb_type += 2 * get_cabac( &h->cabac, &state[3+intra_slice] ); |
5254 if( get_cabac( &h->cabac, &state[2+intra_slice] ) ) | 5254 mb_type += 1 * get_cabac( &h->cabac, &state[3+2*intra_slice] ); |
5255 mb_type += 4 * 2; /* cbp_chroma == 2 */ | |
5256 else | |
5257 mb_type += 4 * 1; /* cbp_chroma == 1 */ | |
5258 } | |
5259 if( get_cabac( &h->cabac, &state[3+intra_slice] ) ) | |
5260 mb_type += 2; | |
5261 if( get_cabac( &h->cabac, &state[3+2*intra_slice] ) ) | |
5262 mb_type += 1; | |
5263 return mb_type; | 5255 return mb_type; |
5264 } | 5256 } |
5265 | 5257 |
5266 static int decode_cabac_mb_type( H264Context *h ) { | 5258 static int decode_cabac_mb_type( H264Context *h ) { |
5267 MpegEncContext * const s = &h->s; | 5259 MpegEncContext * const s = &h->s; |
5270 return decode_cabac_intra_mb_type(h, 3, 1); | 5262 return decode_cabac_intra_mb_type(h, 3, 1); |
5271 } else if( h->slice_type == P_TYPE ) { | 5263 } else if( h->slice_type == P_TYPE ) { |
5272 if( get_cabac( &h->cabac, &h->cabac_state[14] ) == 0 ) { | 5264 if( get_cabac( &h->cabac, &h->cabac_state[14] ) == 0 ) { |
5273 /* P-type */ | 5265 /* P-type */ |
5274 if( get_cabac( &h->cabac, &h->cabac_state[15] ) == 0 ) { | 5266 if( get_cabac( &h->cabac, &h->cabac_state[15] ) == 0 ) { |
5275 if( get_cabac( &h->cabac, &h->cabac_state[16] ) == 0 ) | 5267 /* P_L0_D16x16, P_8x8 */ |
5276 return 0; /* P_L0_D16x16; */ | 5268 return 3 * get_cabac( &h->cabac, &h->cabac_state[16] ); |
5277 else | |
5278 return 3; /* P_8x8; */ | |
5279 } else { | 5269 } else { |
5280 if( get_cabac( &h->cabac, &h->cabac_state[17] ) == 0 ) | 5270 /* P_L0_D8x16, P_L0_D16x8 */ |
5281 return 2; /* P_L0_D8x16; */ | 5271 return 2 - get_cabac( &h->cabac, &h->cabac_state[17] ); |
5282 else | |
5283 return 1; /* P_L0_D16x8; */ | |
5284 } | 5272 } |
5285 } else { | 5273 } else { |
5286 return decode_cabac_intra_mb_type(h, 17, 0) + 5; | 5274 return decode_cabac_intra_mb_type(h, 17, 0) + 5; |
5287 } | 5275 } |
5288 } else if( h->slice_type == B_TYPE ) { | 5276 } else if( h->slice_type == B_TYPE ) { |
5289 const int mba_xy = h->left_mb_xy[0]; | 5277 const int mba_xy = h->left_mb_xy[0]; |
5290 const int mbb_xy = h->top_mb_xy; | 5278 const int mbb_xy = h->top_mb_xy; |
5291 int ctx = 0; | 5279 int ctx = 0; |
5292 int bits; | 5280 int bits; |
5293 | 5281 |
5294 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] ) | 5282 if( h->slice_table[mba_xy] == h->slice_num && !IS_DIRECT( s->current_picture.mb_type[mba_xy] ) ) |
5295 && !IS_DIRECT( s->current_picture.mb_type[mba_xy] ) ) | |
5296 ctx++; | 5283 ctx++; |
5297 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] ) | 5284 if( h->slice_table[mbb_xy] == h->slice_num && !IS_DIRECT( s->current_picture.mb_type[mbb_xy] ) ) |
5298 && !IS_DIRECT( s->current_picture.mb_type[mbb_xy] ) ) | |
5299 ctx++; | 5285 ctx++; |
5300 | 5286 |
5301 if( !get_cabac( &h->cabac, &h->cabac_state[27+ctx] ) ) | 5287 if( !get_cabac( &h->cabac, &h->cabac_state[27+ctx] ) ) |
5302 return 0; /* B_Direct_16x16 */ | 5288 return 0; /* B_Direct_16x16 */ |
5303 | 5289 |
5336 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] )) | 5322 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] )) |
5337 ctx++; | 5323 ctx++; |
5338 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] )) | 5324 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] )) |
5339 ctx++; | 5325 ctx++; |
5340 | 5326 |
5341 if( h->slice_type == P_TYPE || h->slice_type == SP_TYPE) | 5327 if( h->slice_type == B_TYPE ) |
5342 return get_cabac( &h->cabac, &h->cabac_state[11+ctx] ); | 5328 ctx += 13; |
5343 else /* B-frame */ | 5329 return get_cabac( &h->cabac, &h->cabac_state[11+ctx] ); |
5344 return get_cabac( &h->cabac, &h->cabac_state[24+ctx] ); | |
5345 } | 5330 } |
5346 | 5331 |
5347 static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) { | 5332 static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) { |
5348 int mode = 0; | 5333 int mode = 0; |
5349 | 5334 |
5399 | 5384 |
5400 static int decode_cabac_mb_cbp_luma( H264Context *h) { | 5385 static int decode_cabac_mb_cbp_luma( H264Context *h) { |
5401 MpegEncContext * const s = &h->s; | 5386 MpegEncContext * const s = &h->s; |
5402 | 5387 |
5403 int cbp = 0; | 5388 int cbp = 0; |
5389 int cbp_b = -1; | |
5404 int i8x8; | 5390 int i8x8; |
5391 | |
5392 if( h->slice_table[h->top_mb_xy] == h->slice_num ) { | |
5393 cbp_b = h->top_cbp; | |
5394 tprintf("cbp_b = top_cbp = %x\n", cbp_b); | |
5395 } | |
5405 | 5396 |
5406 for( i8x8 = 0; i8x8 < 4; i8x8++ ) { | 5397 for( i8x8 = 0; i8x8 < 4; i8x8++ ) { |
5407 int cbp_a = -1; | 5398 int cbp_a = -1; |
5408 int cbp_b = -1; | |
5409 int x, y; | 5399 int x, y; |
5410 int ctx = 0; | 5400 int ctx = 0; |
5411 | 5401 |
5412 x = block_idx_x[4*i8x8]; | 5402 x = block_idx_x[4*i8x8]; |
5413 y = block_idx_y[4*i8x8]; | 5403 y = block_idx_y[4*i8x8]; |
5414 | 5404 |
5415 if( x > 0 ) | 5405 if( x > 0 ) |
5416 cbp_a = cbp; | 5406 cbp_a = cbp; |
5417 else if( s->mb_x > 0 && (h->slice_table[h->left_mb_xy[0]] == h->slice_num)) { | 5407 else if( h->slice_table[h->left_mb_xy[0]] == h->slice_num ) { |
5418 cbp_a = h->left_cbp; | 5408 cbp_a = h->left_cbp; |
5419 tprintf("cbp_a = left_cbp = %x\n", cbp_a); | 5409 tprintf("cbp_a = left_cbp = %x\n", cbp_a); |
5420 } | 5410 } |
5421 | 5411 |
5422 if( y > 0 ) | 5412 if( y > 0 ) |
5423 cbp_b = cbp; | 5413 cbp_b = cbp; |
5424 else if( s->mb_y > 0 && (h->slice_table[h->top_mb_xy] == h->slice_num)) { | |
5425 cbp_b = h->top_cbp; | |
5426 tprintf("cbp_b = top_cbp = %x\n", cbp_b); | |
5427 } | |
5428 | 5414 |
5429 /* No need to test for skip as we put 0 for skip block */ | 5415 /* No need to test for skip as we put 0 for skip block */ |
5430 /* No need to test for IPCM as we put 1 for IPCM block */ | 5416 /* No need to test for IPCM as we put 1 for IPCM block */ |
5431 if( cbp_a >= 0 ) { | 5417 if( cbp_a >= 0 ) { |
5432 int i8x8a = block_idx_xy[(x-1)&0x03][y]/4; | 5418 int i8x8a = block_idx_xy[(x-1)&0x03][y]/4; |