Mercurial > libavcodec.hg
comparison h264.c @ 2498:4d6d056a00c6 libavcodec
H.264 multiple slice support in CABAC patch by (Loic (lll+ffmpeg m4x org)
3 more streams of the conformance suite decode to the
end instead of failing on an assert (CABACI3_Sony_B.jsv,
CABAST3_Sony_E.jsv and CABASTBR3_Sony_B.jsv), they are still false since
the first B slice probably because of deblocking in B slices not yet
implemented.
author | michael |
---|---|
date | Fri, 04 Feb 2005 02:47:45 +0000 |
parents | 2844b8cf4e11 |
children | f12657081093 |
comparison
equal
deleted
inserted
replaced
2497:69adfbbdcdeb | 2498:4d6d056a00c6 |
---|---|
3475 static int decode_slice_header(H264Context *h){ | 3475 static int decode_slice_header(H264Context *h){ |
3476 MpegEncContext * const s = &h->s; | 3476 MpegEncContext * const s = &h->s; |
3477 int first_mb_in_slice, pps_id; | 3477 int first_mb_in_slice, pps_id; |
3478 int num_ref_idx_active_override_flag; | 3478 int num_ref_idx_active_override_flag; |
3479 static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE}; | 3479 static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE}; |
3480 int slice_type; | |
3481 int default_ref_list_done = 0; | |
3480 | 3482 |
3481 s->current_picture.reference= h->nal_ref_idc != 0; | 3483 s->current_picture.reference= h->nal_ref_idc != 0; |
3482 | 3484 |
3483 first_mb_in_slice= get_ue_golomb(&s->gb); | 3485 first_mb_in_slice= get_ue_golomb(&s->gb); |
3484 | 3486 |
3485 h->slice_type= get_ue_golomb(&s->gb); | 3487 slice_type= get_ue_golomb(&s->gb); |
3486 if(h->slice_type > 9){ | 3488 if(slice_type > 9){ |
3487 av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y); | 3489 av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y); |
3488 return -1; | 3490 return -1; |
3489 } | 3491 } |
3490 if(h->slice_type > 4){ | 3492 if(slice_type > 4){ |
3491 h->slice_type -= 5; | 3493 slice_type -= 5; |
3492 h->slice_type_fixed=1; | 3494 h->slice_type_fixed=1; |
3493 }else | 3495 }else |
3494 h->slice_type_fixed=0; | 3496 h->slice_type_fixed=0; |
3495 | 3497 |
3496 h->slice_type= slice_type_map[ h->slice_type ]; | 3498 slice_type= slice_type_map[ slice_type ]; |
3497 | 3499 if (slice_type == I_TYPE |
3500 || (h->slice_num != 0 && slice_type == h->slice_type) ) { | |
3501 default_ref_list_done = 1; | |
3502 } | |
3503 h->slice_type= slice_type; | |
3504 | |
3498 s->pict_type= h->slice_type; // to make a few old func happy, its wrong though | 3505 s->pict_type= h->slice_type; // to make a few old func happy, its wrong though |
3499 | 3506 |
3500 pps_id= get_ue_golomb(&s->gb); | 3507 pps_id= get_ue_golomb(&s->gb); |
3501 if(pps_id>255){ | 3508 if(pps_id>255){ |
3502 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); | 3509 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); |
3621 return -1; | 3628 return -1; |
3622 } | 3629 } |
3623 } | 3630 } |
3624 } | 3631 } |
3625 | 3632 |
3626 if(h->slice_num == 0){ | 3633 if(!default_ref_list_done){ |
3627 fill_default_ref_list(h); | 3634 fill_default_ref_list(h); |
3628 } | 3635 } |
3629 | 3636 |
3630 decode_ref_pic_list_reordering(h); | 3637 decode_ref_pic_list_reordering(h); |
3631 | 3638 |
4340 int mb_type; | 4347 int mb_type; |
4341 | 4348 |
4342 if(intra_slice){ | 4349 if(intra_slice){ |
4343 MpegEncContext * const s = &h->s; | 4350 MpegEncContext * const s = &h->s; |
4344 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; | 4351 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
4352 const int mba_xy = mb_xy - 1; | |
4353 const int mbb_xy = mb_xy - s->mb_stride; | |
4345 int ctx=0; | 4354 int ctx=0; |
4346 if( s->mb_x > 0 && !IS_INTRA4x4( s->current_picture.mb_type[mb_xy-1] ) ) | 4355 if( h->slice_table[mba_xy] == h->slice_num && !IS_INTRA4x4( s->current_picture.mb_type[mba_xy] ) ) |
4347 ctx++; | 4356 ctx++; |
4348 if( s->mb_y > 0 && !IS_INTRA4x4( s->current_picture.mb_type[mb_xy-s->mb_stride] ) ) | 4357 if( h->slice_table[mbb_xy] == h->slice_num && !IS_INTRA4x4( s->current_picture.mb_type[mbb_xy] ) ) |
4349 ctx++; | 4358 ctx++; |
4350 if( get_cabac( &h->cabac, &state[ctx] ) == 0 ) | 4359 if( get_cabac( &h->cabac, &state[ctx] ) == 0 ) |
4351 return 0; /* I4x4 */ | 4360 return 0; /* I4x4 */ |
4352 state += 2; | 4361 state += 2; |
4353 }else{ | 4362 }else{ |
4397 } else { | 4406 } else { |
4398 return decode_cabac_intra_mb_type(h, 17, 0) + 5; | 4407 return decode_cabac_intra_mb_type(h, 17, 0) + 5; |
4399 } | 4408 } |
4400 } else if( h->slice_type == B_TYPE ) { | 4409 } else if( h->slice_type == B_TYPE ) { |
4401 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; | 4410 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
4411 const int mba_xy = mb_xy - 1; | |
4412 const int mbb_xy = mb_xy - s->mb_stride; | |
4402 int ctx = 0; | 4413 int ctx = 0; |
4403 int bits; | 4414 int bits; |
4404 | 4415 |
4405 if( s->mb_x > 0 && !IS_SKIP( s->current_picture.mb_type[mb_xy-1] ) | 4416 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] ) |
4406 && !IS_DIRECT( s->current_picture.mb_type[mb_xy-1] ) ) | 4417 && !IS_DIRECT( s->current_picture.mb_type[mba_xy] ) ) |
4407 ctx++; | 4418 ctx++; |
4408 if( s->mb_y > 0 && !IS_SKIP( s->current_picture.mb_type[mb_xy-s->mb_stride] ) | 4419 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] ) |
4409 && !IS_DIRECT( s->current_picture.mb_type[mb_xy-s->mb_stride] ) ) | 4420 && !IS_DIRECT( s->current_picture.mb_type[mbb_xy] ) ) |
4410 ctx++; | 4421 ctx++; |
4411 | 4422 |
4412 if( !get_cabac( &h->cabac, &h->cabac_state[27+ctx] ) ) | 4423 if( !get_cabac( &h->cabac, &h->cabac_state[27+ctx] ) ) |
4413 return 0; /* B_Direct_16x16 */ | 4424 return 0; /* B_Direct_16x16 */ |
4414 | 4425 |
4442 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; | 4453 const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; |
4443 const int mba_xy = mb_xy - 1; | 4454 const int mba_xy = mb_xy - 1; |
4444 const int mbb_xy = mb_xy - s->mb_stride; | 4455 const int mbb_xy = mb_xy - s->mb_stride; |
4445 int ctx = 0; | 4456 int ctx = 0; |
4446 | 4457 |
4447 if( s->mb_x > 0 && !IS_SKIP( s->current_picture.mb_type[mba_xy] ) ) | 4458 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] )) |
4448 ctx++; | 4459 ctx++; |
4449 if( s->mb_y > 0 && !IS_SKIP( s->current_picture.mb_type[mbb_xy] ) ) | 4460 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] )) |
4450 ctx++; | 4461 ctx++; |
4451 | 4462 |
4452 if( h->slice_type == P_TYPE || h->slice_type == SP_TYPE) | 4463 if( h->slice_type == P_TYPE || h->slice_type == SP_TYPE) |
4453 return get_cabac( &h->cabac, &h->cabac_state[11+ctx] ); | 4464 return get_cabac( &h->cabac, &h->cabac_state[11+ctx] ); |
4454 else /* B-frame */ | 4465 else /* B-frame */ |
4480 const int mbb_xy = mb_xy - s->mb_stride; | 4491 const int mbb_xy = mb_xy - s->mb_stride; |
4481 | 4492 |
4482 int ctx = 0; | 4493 int ctx = 0; |
4483 | 4494 |
4484 /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */ | 4495 /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */ |
4485 if( s->mb_x > 0 && h->chroma_pred_mode_table[mba_xy] != 0 ) | 4496 if( h->slice_table[mba_xy] == h->slice_num && h->chroma_pred_mode_table[mba_xy] != 0 ) |
4486 ctx++; | 4497 ctx++; |
4487 | 4498 |
4488 if( s->mb_y > 0 && h->chroma_pred_mode_table[mbb_xy] != 0 ) | 4499 if( h->slice_table[mbb_xy] == h->slice_num && h->chroma_pred_mode_table[mbb_xy] != 0 ) |
4489 ctx++; | 4500 ctx++; |
4490 | 4501 |
4491 if( get_cabac( &h->cabac, &h->cabac_state[64+ctx] ) == 0 ) | 4502 if( get_cabac( &h->cabac, &h->cabac_state[64+ctx] ) == 0 ) |
4492 return 0; | 4503 return 0; |
4493 | 4504 |
4530 x = block_idx_x[4*i8x8]; | 4541 x = block_idx_x[4*i8x8]; |
4531 y = block_idx_y[4*i8x8]; | 4542 y = block_idx_y[4*i8x8]; |
4532 | 4543 |
4533 if( x > 0 ) | 4544 if( x > 0 ) |
4534 mba_xy = mb_xy; | 4545 mba_xy = mb_xy; |
4535 else if( s->mb_x > 0 ) | 4546 else if( s->mb_x > 0 ) { |
4536 mba_xy = mb_xy - 1; | 4547 mba_xy = mb_xy - 1; |
4548 if (h->slice_table[mba_xy] != h->slice_num) { | |
4549 mba_xy = -1; | |
4550 } | |
4551 } | |
4537 | 4552 |
4538 if( y > 0 ) | 4553 if( y > 0 ) |
4539 mbb_xy = mb_xy; | 4554 mbb_xy = mb_xy; |
4540 else if( s->mb_y > 0 ) | 4555 else if( s->mb_y > 0 ) { |
4541 mbb_xy = mb_xy - s->mb_stride; | 4556 mbb_xy = mb_xy - s->mb_stride; |
4557 if (h->slice_table[mbb_xy] != h->slice_num) { | |
4558 mbb_xy = -1; | |
4559 } | |
4560 } | |
4542 | 4561 |
4543 /* No need to test for skip as we put 0 for skip block */ | 4562 /* No need to test for skip as we put 0 for skip block */ |
4544 if( mba_xy >= 0 ) { | 4563 if( mba_xy >= 0 ) { |
4545 int i8x8a = block_idx_xy[(x-1)&0x03][y]/4; | 4564 int i8x8a = block_idx_xy[(x-1)&0x03][y]/4; |
4546 if( ((h->cbp_table[mba_xy] >> i8x8a)&0x01) == 0 ) | 4565 if( ((h->cbp_table[mba_xy] >> i8x8a)&0x01) == 0 ) |
4587 if( s->mb_x > 0 ) | 4606 if( s->mb_x > 0 ) |
4588 mbn_xy = s->mb_x + s->mb_y*s->mb_stride - 1; | 4607 mbn_xy = s->mb_x + s->mb_y*s->mb_stride - 1; |
4589 else | 4608 else |
4590 mbn_xy = s->mb_width - 1 + (s->mb_y-1)*s->mb_stride; | 4609 mbn_xy = s->mb_width - 1 + (s->mb_y-1)*s->mb_stride; |
4591 | 4610 |
4592 if( mbn_xy >= 0 && h->last_qscale_diff != 0 && ( IS_INTRA16x16(s->current_picture.mb_type[mbn_xy] ) || (h->cbp_table[mbn_xy]&0x3f) ) ) | 4611 if( h->last_qscale_diff != 0 && ( IS_INTRA16x16(s->current_picture.mb_type[mbn_xy] ) || (h->cbp_table[mbn_xy]&0x3f) ) ) |
4593 ctx++; | 4612 ctx++; |
4594 | 4613 |
4595 while( get_cabac( &h->cabac, &h->cabac_state[60 + ctx] ) ) { | 4614 while( get_cabac( &h->cabac, &h->cabac_state[60 + ctx] ) ) { |
4596 if( ctx < 2 ) | 4615 if( ctx < 2 ) |
4597 ctx = 2; | 4616 ctx = 2; |