Mercurial > libavcodec.hg
comparison h264.c @ 4533:dca590e16c43 libavcodec
replace list<2 checks by list<list_count
remove silly ref_count<0 and ref_count==0 checks its impossible for this variable to have such a value
author | michael |
---|---|
date | Fri, 16 Feb 2007 21:42:01 +0000 |
parents | c296efb7575e |
children | a856fe4b80f0 |
comparison
equal
deleted
inserted
replaced
4532:c296efb7575e | 4533:dca590e16c43 |
---|---|
612 if(FRAME_MBAFF && !IS_INTRA(mb_type)){ | 612 if(FRAME_MBAFF && !IS_INTRA(mb_type)){ |
613 int list; | 613 int list; |
614 int v = *(uint16_t*)&h->non_zero_count[mb_xy][14]; | 614 int v = *(uint16_t*)&h->non_zero_count[mb_xy][14]; |
615 for(i=0; i<16; i++) | 615 for(i=0; i<16; i++) |
616 h->non_zero_count_cache[scan8[i]] = (v>>i)&1; | 616 h->non_zero_count_cache[scan8[i]] = (v>>i)&1; |
617 for(list=0; list<1+(h->slice_type==B_TYPE); list++){ | 617 for(list=0; list<h->list_count; list++){ |
618 if(USES_LIST(mb_type,list)){ | 618 if(USES_LIST(mb_type,list)){ |
619 uint32_t *src = (uint32_t*)s->current_picture.motion_val[list][h->mb2b_xy[mb_xy]]; | 619 uint32_t *src = (uint32_t*)s->current_picture.motion_val[list][h->mb2b_xy[mb_xy]]; |
620 uint32_t *dst = (uint32_t*)h->mv_cache[list][scan8[0]]; | 620 uint32_t *dst = (uint32_t*)h->mv_cache[list][scan8[0]]; |
621 int8_t *ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]]; | 621 int8_t *ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]]; |
622 for(i=0; i<4; i++, dst+=8, src+=h->b_stride){ | 622 for(i=0; i<4; i++, dst+=8, src+=h->b_stride){ |
780 } | 780 } |
781 | 781 |
782 #if 1 | 782 #if 1 |
783 if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){ | 783 if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){ |
784 int list; | 784 int list; |
785 for(list=0; list<1+(h->slice_type==B_TYPE); list++){ | 785 for(list=0; list<h->list_count; list++){ |
786 if(!USES_LIST(mb_type, list) && !IS_DIRECT(mb_type) && !h->deblocking_filter){ | 786 if(!USES_LIST(mb_type, list) && !IS_DIRECT(mb_type) && !h->deblocking_filter){ |
787 /*if(!h->mv_cache_clean[list]){ | 787 /*if(!h->mv_cache_clean[list]){ |
788 memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? | 788 memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? |
789 memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); | 789 memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); |
790 h->mv_cache_clean[list]= 1; | 790 h->mv_cache_clean[list]= 1; |
1701 int list; | 1701 int list; |
1702 | 1702 |
1703 if(!USES_LIST(mb_type, 0)) | 1703 if(!USES_LIST(mb_type, 0)) |
1704 fill_rectangle(&s->current_picture.ref_index[0][b8_xy], 2, 2, h->b8_stride, (uint8_t)LIST_NOT_USED, 1); | 1704 fill_rectangle(&s->current_picture.ref_index[0][b8_xy], 2, 2, h->b8_stride, (uint8_t)LIST_NOT_USED, 1); |
1705 | 1705 |
1706 for(list=0; list<2; list++){ | 1706 for(list=0; list<h->list_count; list++){ |
1707 int y; | 1707 int y; |
1708 if(!USES_LIST(mb_type, list)) | 1708 if(!USES_LIST(mb_type, list)) |
1709 continue; | 1709 continue; |
1710 | 1710 |
1711 for(y=0; y<4; y++){ | 1711 for(y=0; y<4; y++){ |
3541 dest_cb-= s->uvlinesize*7; | 3541 dest_cb-= s->uvlinesize*7; |
3542 dest_cr-= s->uvlinesize*7; | 3542 dest_cr-= s->uvlinesize*7; |
3543 } | 3543 } |
3544 if(FRAME_MBAFF) { | 3544 if(FRAME_MBAFF) { |
3545 int list; | 3545 int list; |
3546 for(list=0; list<2; list++){ | 3546 for(list=0; list<h->list_count; list++){ |
3547 if(!USES_LIST(mb_type, list)) | 3547 if(!USES_LIST(mb_type, list)) |
3548 continue; | 3548 continue; |
3549 if(IS_16X16(mb_type)){ | 3549 if(IS_16X16(mb_type)){ |
3550 int8_t *ref = &h->ref_cache[list][scan8[0]]; | 3550 int8_t *ref = &h->ref_cache[list][scan8[0]]; |
3551 fill_rectangle(ref, 4, 4, 8, 16+*ref^(s->mb_y&1), 1); | 3551 fill_rectangle(ref, 4, 4, 8, 16+*ref^(s->mb_y&1), 1); |
3909 | 3909 |
3910 print_short_term(h); | 3910 print_short_term(h); |
3911 print_long_term(h); | 3911 print_long_term(h); |
3912 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func | 3912 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func |
3913 | 3913 |
3914 for(list=0; list<2; list++){ | 3914 for(list=0; list<h->list_count; list++){ |
3915 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); | 3915 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); |
3916 | 3916 |
3917 if(get_bits1(&s->gb)){ | 3917 if(get_bits1(&s->gb)){ |
3918 int pred= h->curr_pic_num; | 3918 int pred= h->curr_pic_num; |
3919 | 3919 |
3987 av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); | 3987 av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); |
3988 return -1; | 3988 return -1; |
3989 } | 3989 } |
3990 } | 3990 } |
3991 } | 3991 } |
3992 | 3992 } |
3993 if(h->slice_type!=B_TYPE) break; | 3993 for(list=0; list<h->list_count; list++){ |
3994 } | |
3995 for(list=0; list<2; list++){ | |
3996 for(index= 0; index < h->ref_count[list]; index++){ | 3994 for(index= 0; index < h->ref_count[list]; index++){ |
3997 if(!h->ref_list[list][index].data[0]) | 3995 if(!h->ref_list[list][index].data[0]) |
3998 h->ref_list[list][index]= s->current_picture; | 3996 h->ref_list[list][index]= s->current_picture; |
3999 } | 3997 } |
4000 if(h->slice_type!=B_TYPE) break; | |
4001 } | 3998 } |
4002 | 3999 |
4003 if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred) | 4000 if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred) |
4004 direct_dist_scale_factor(h); | 4001 direct_dist_scale_factor(h); |
4005 direct_ref_list_init(h); | 4002 direct_ref_list_init(h); |
4006 return 0; | 4003 return 0; |
4007 } | 4004 } |
4008 | 4005 |
4009 static void fill_mbaff_ref_list(H264Context *h){ | 4006 static void fill_mbaff_ref_list(H264Context *h){ |
4010 int list, i, j; | 4007 int list, i, j; |
4011 for(list=0; list<2; list++){ | 4008 for(list=0; list<2; list++){ //FIXME try list_count |
4012 for(i=0; i<h->ref_count[list]; i++){ | 4009 for(i=0; i<h->ref_count[list]; i++){ |
4013 Picture *frame = &h->ref_list[list][i]; | 4010 Picture *frame = &h->ref_list[list][i]; |
4014 Picture *field = &h->ref_list[list][16+2*i]; | 4011 Picture *field = &h->ref_list[list][16+2*i]; |
4015 field[0] = *frame; | 4012 field[0] = *frame; |
4016 for(j=0; j<3; j++) | 4013 for(j=0; j<3; j++) |
5256 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | 5253 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; |
5257 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; | 5254 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; |
5258 } | 5255 } |
5259 } | 5256 } |
5260 | 5257 |
5261 for(list=0; list<2; list++){ | 5258 for(list=0; list<h->list_count; list++){ |
5262 int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | 5259 int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; |
5263 if(ref_count == 0) continue; | |
5264 for(i=0; i<4; i++){ | 5260 for(i=0; i<4; i++){ |
5265 if(IS_DIRECT(h->sub_mb_type[i])) continue; | 5261 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
5266 if(IS_DIR(h->sub_mb_type[i], 0, list)){ | 5262 if(IS_DIR(h->sub_mb_type[i], 0, list)){ |
5267 unsigned int tmp = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip? | 5263 unsigned int tmp = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip? |
5268 if(tmp>=ref_count){ | 5264 if(tmp>=ref_count){ |
5278 } | 5274 } |
5279 | 5275 |
5280 if(dct8x8_allowed) | 5276 if(dct8x8_allowed) |
5281 dct8x8_allowed = get_dct8x8_allowed(h); | 5277 dct8x8_allowed = get_dct8x8_allowed(h); |
5282 | 5278 |
5283 for(list=0; list<2; list++){ | 5279 for(list=0; list<h->list_count; list++){ |
5284 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; | 5280 const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; |
5285 if(ref_count == 0) continue; | |
5286 | 5281 |
5287 for(i=0; i<4; i++){ | 5282 for(i=0; i<4; i++){ |
5288 if(IS_DIRECT(h->sub_mb_type[i])) { | 5283 if(IS_DIRECT(h->sub_mb_type[i])) { |
5289 h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ]; | 5284 h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ]; |
5290 continue; | 5285 continue; |
6391 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | 6386 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; |
6392 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; | 6387 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; |
6393 } | 6388 } |
6394 } | 6389 } |
6395 | 6390 |
6396 for( list = 0; list < 2; list++ ) { | 6391 for( list = 0; list < h->list_count; list++ ) { |
6397 if( h->ref_count[list] > 0 ) { | |
6398 for( i = 0; i < 4; i++ ) { | 6392 for( i = 0; i < 4; i++ ) { |
6399 if(IS_DIRECT(h->sub_mb_type[i])) continue; | 6393 if(IS_DIRECT(h->sub_mb_type[i])) continue; |
6400 if(IS_DIR(h->sub_mb_type[i], 0, list)){ | 6394 if(IS_DIR(h->sub_mb_type[i], 0, list)){ |
6401 if( h->ref_count[list] > 1 ) | 6395 if( h->ref_count[list] > 1 ) |
6402 ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); | 6396 ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); |
6406 ref[list][i] = -1; | 6400 ref[list][i] = -1; |
6407 } | 6401 } |
6408 h->ref_cache[list][ scan8[4*i]+1 ]= | 6402 h->ref_cache[list][ scan8[4*i]+1 ]= |
6409 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; | 6403 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; |
6410 } | 6404 } |
6411 } | |
6412 } | 6405 } |
6413 | 6406 |
6414 if(dct8x8_allowed) | 6407 if(dct8x8_allowed) |
6415 dct8x8_allowed = get_dct8x8_allowed(h); | 6408 dct8x8_allowed = get_dct8x8_allowed(h); |
6416 | 6409 |
6417 for(list=0; list<2; list++){ | 6410 for(list=0; list<h->list_count; list++){ |
6418 for(i=0; i<4; i++){ | 6411 for(i=0; i<4; i++){ |
6419 if(IS_DIRECT(h->sub_mb_type[i])){ | 6412 if(IS_DIRECT(h->sub_mb_type[i])){ |
6420 fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4); | 6413 fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4); |
6421 continue; | 6414 continue; |
6422 } | 6415 } |
6504 }else | 6497 }else |
6505 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4); | 6498 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4); |
6506 } | 6499 } |
6507 } | 6500 } |
6508 else if(IS_16X8(mb_type)){ | 6501 else if(IS_16X8(mb_type)){ |
6509 for(list=0; list<2; list++){ | 6502 for(list=0; list<h->list_count; list++){ |
6510 if(h->ref_count[list]>0){ | |
6511 for(i=0; i<2; i++){ | 6503 for(i=0; i<2; i++){ |
6512 if(IS_DIR(mb_type, i, list)){ | 6504 if(IS_DIR(mb_type, i, list)){ |
6513 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 8*i ) : 0; | 6505 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 8*i ) : 0; |
6514 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1); | 6506 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1); |
6515 }else | 6507 }else |
6516 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); | 6508 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); |
6517 } | 6509 } |
6518 } | 6510 } |
6519 } | 6511 for(list=0; list<h->list_count; list++){ |
6520 for(list=0; list<2; list++){ | |
6521 for(i=0; i<2; i++){ | 6512 for(i=0; i<2; i++){ |
6522 if(IS_DIR(mb_type, i, list)){ | 6513 if(IS_DIR(mb_type, i, list)){ |
6523 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy); | 6514 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy); |
6524 mx = mpx + decode_cabac_mb_mvd( h, list, 8*i, 0 ); | 6515 mx = mpx + decode_cabac_mb_mvd( h, list, 8*i, 0 ); |
6525 my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 ); | 6516 my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 ); |
6533 } | 6524 } |
6534 } | 6525 } |
6535 } | 6526 } |
6536 }else{ | 6527 }else{ |
6537 assert(IS_8X16(mb_type)); | 6528 assert(IS_8X16(mb_type)); |
6538 for(list=0; list<2; list++){ | 6529 for(list=0; list<h->list_count; list++){ |
6539 if(h->ref_count[list]>0){ | |
6540 for(i=0; i<2; i++){ | 6530 for(i=0; i<2; i++){ |
6541 if(IS_DIR(mb_type, i, list)){ //FIXME optimize | 6531 if(IS_DIR(mb_type, i, list)){ //FIXME optimize |
6542 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 4*i ) : 0; | 6532 const int ref= h->ref_count[list] > 1 ? decode_cabac_mb_ref( h, list, 4*i ) : 0; |
6543 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1); | 6533 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1); |
6544 }else | 6534 }else |
6545 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); | 6535 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); |
6546 } | 6536 } |
6547 } | 6537 } |
6548 } | 6538 for(list=0; list<h->list_count; list++){ |
6549 for(list=0; list<2; list++){ | |
6550 for(i=0; i<2; i++){ | 6539 for(i=0; i<2; i++){ |
6551 if(IS_DIR(mb_type, i, list)){ | 6540 if(IS_DIR(mb_type, i, list)){ |
6552 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy); | 6541 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy); |
6553 mx = mpx + decode_cabac_mb_mvd( h, list, 4*i, 0 ); | 6542 mx = mpx + decode_cabac_mb_mvd( h, list, 4*i, 0 ); |
6554 my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 ); | 6543 my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 ); |