Mercurial > libavcodec.hg
comparison h264.c @ 2449:6f719184e2b9 libavcodec
simplify deblock
author | michael |
---|---|
date | Sun, 23 Jan 2005 14:03:13 +0000 |
parents | 0237bb5ca0f0 |
children | f67b63ed036d |
comparison
equal
deleted
inserted
replaced
2448:bfa9192a22ce | 2449:6f719184e2b9 |
---|---|
406 *(uint64_t*)(p + 8+3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; | 406 *(uint64_t*)(p + 8+3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL; |
407 }else | 407 }else |
408 assert(0); | 408 assert(0); |
409 } | 409 } |
410 | 410 |
411 static inline void fill_caches(H264Context *h, int mb_type){ | 411 static inline void fill_caches(H264Context *h, int mb_type, int for_deblock){ |
412 MpegEncContext * const s = &h->s; | 412 MpegEncContext * const s = &h->s; |
413 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; | 413 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; |
414 int topleft_xy, top_xy, topright_xy, left_xy[2]; | 414 int topleft_xy, top_xy, topright_xy, left_xy[2]; |
415 int topleft_type, top_type, topright_type, left_type[2]; | 415 int topleft_type, top_type, topright_type, left_type[2]; |
416 int left_block[4]; | 416 int left_block[4]; |
433 left_block[1]= 1; | 433 left_block[1]= 1; |
434 left_block[2]= 2; | 434 left_block[2]= 2; |
435 left_block[3]= 3; | 435 left_block[3]= 3; |
436 } | 436 } |
437 | 437 |
438 topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0; | 438 if(for_deblock){ |
439 top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0; | 439 topleft_type = h->slice_table[topleft_xy ] < 255 ? s->current_picture.mb_type[topleft_xy] : 0; |
440 topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0; | 440 top_type = h->slice_table[top_xy ] < 255 ? s->current_picture.mb_type[top_xy] : 0; |
441 left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0; | 441 topright_type= h->slice_table[topright_xy] < 255 ? s->current_picture.mb_type[topright_xy]: 0; |
442 left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0; | 442 left_type[0] = h->slice_table[left_xy[0] ] < 255 ? s->current_picture.mb_type[left_xy[0]] : 0; |
443 left_type[1] = h->slice_table[left_xy[1] ] < 255 ? s->current_picture.mb_type[left_xy[1]] : 0; | |
444 }else{ | |
445 topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0; | |
446 top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0; | |
447 topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0; | |
448 left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0; | |
449 left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0; | |
450 } | |
443 | 451 |
444 if(IS_INTRA(mb_type)){ | 452 if(IS_INTRA(mb_type)){ |
445 h->topleft_samples_available= | 453 h->topleft_samples_available= |
446 h->top_samples_available= | 454 h->top_samples_available= |
447 h->left_samples_available= 0xFFFF; | 455 h->left_samples_available= 0xFFFF; |
648 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 2*8]= | 656 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 2*8]= |
649 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 3*8]= 0; | 657 *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 3*8]= 0; |
650 h->ref_cache[list][scan8[0] - 1 + 2*8]= | 658 h->ref_cache[list][scan8[0] - 1 + 2*8]= |
651 h->ref_cache[list][scan8[0] - 1 + 3*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; | 659 h->ref_cache[list][scan8[0] - 1 + 3*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; |
652 } | 660 } |
661 | |
662 if(for_deblock) | |
663 continue; | |
653 | 664 |
654 h->ref_cache[list][scan8[5 ]+1] = | 665 h->ref_cache[list][scan8[5 ]+1] = |
655 h->ref_cache[list][scan8[7 ]+1] = | 666 h->ref_cache[list][scan8[7 ]+1] = |
656 h->ref_cache[list][scan8[13]+1] = //FIXME remove past 3 (init somewher else) | 667 h->ref_cache[list][scan8[13]+1] = //FIXME remove past 3 (init somewher else) |
657 h->ref_cache[list][scan8[4 ]] = | 668 h->ref_cache[list][scan8[4 ]] = |
2833 } | 2844 } |
2834 } | 2845 } |
2835 } | 2846 } |
2836 if(h->deblocking_filter) { | 2847 if(h->deblocking_filter) { |
2837 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize); | 2848 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize); |
2849 fill_caches(h, mb_type, 1); //FIXME dont fill stuff which isnt used by filter_mb | |
2838 filter_mb(h, mb_x, mb_y, dest_y, dest_cb, dest_cr); | 2850 filter_mb(h, mb_x, mb_y, dest_y, dest_cb, dest_cr); |
2839 } | 2851 } |
2840 } | 2852 } |
2841 | 2853 |
2842 /** | 2854 /** |
3855 { | 3867 { |
3856 // just for fill_caches. pred_direct_motion will set the real mb_type | 3868 // just for fill_caches. pred_direct_motion will set the real mb_type |
3857 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP; | 3869 mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP; |
3858 //FIXME mbaff | 3870 //FIXME mbaff |
3859 | 3871 |
3860 fill_caches(h, mb_type); //FIXME check what is needed and what not ... | 3872 fill_caches(h, mb_type, 0); //FIXME check what is needed and what not ... |
3861 pred_direct_motion(h, &mb_type); | 3873 pred_direct_motion(h, &mb_type); |
3862 if(h->pps.cabac){ | 3874 if(h->pps.cabac){ |
3863 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | 3875 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); |
3864 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); | 3876 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); |
3865 } | 3877 } |
3873 h->mb_field_decoding_flag= get_bits1(&s->gb); | 3885 h->mb_field_decoding_flag= get_bits1(&s->gb); |
3874 } | 3886 } |
3875 if(h->mb_field_decoding_flag) | 3887 if(h->mb_field_decoding_flag) |
3876 mb_type|= MB_TYPE_INTERLACED; | 3888 mb_type|= MB_TYPE_INTERLACED; |
3877 | 3889 |
3878 fill_caches(h, mb_type); //FIXME check what is needed and what not ... | 3890 fill_caches(h, mb_type, 0); //FIXME check what is needed and what not ... |
3879 pred_pskip_motion(h, &mx, &my); | 3891 pred_pskip_motion(h, &mx, &my); |
3880 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); | 3892 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); |
3881 fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); | 3893 fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); |
3882 if(h->pps.cabac) | 3894 if(h->pps.cabac) |
3883 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); | 3895 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); |
3992 s->current_picture.qscale_table[mb_xy]= s->qscale; | 4004 s->current_picture.qscale_table[mb_xy]= s->qscale; |
3993 | 4005 |
3994 return 0; | 4006 return 0; |
3995 } | 4007 } |
3996 | 4008 |
3997 fill_caches(h, mb_type); | 4009 fill_caches(h, mb_type, 0); |
3998 | 4010 |
3999 //mb_pred | 4011 //mb_pred |
4000 if(IS_INTRA(mb_type)){ | 4012 if(IS_INTRA(mb_type)){ |
4001 // init_top_left_availability(h); | 4013 // init_top_left_availability(h); |
4002 if(IS_INTRA4x4(mb_type)){ | 4014 if(IS_INTRA4x4(mb_type)){ |
4888 h->chroma_pred_mode_table[mb_xy] = 0; | 4900 h->chroma_pred_mode_table[mb_xy] = 0; |
4889 s->current_picture.qscale_table[mb_xy]= s->qscale; | 4901 s->current_picture.qscale_table[mb_xy]= s->qscale; |
4890 return -1; | 4902 return -1; |
4891 } | 4903 } |
4892 | 4904 |
4893 fill_caches(h, mb_type); | 4905 fill_caches(h, mb_type, 0); |
4894 | 4906 |
4895 if( IS_INTRA( mb_type ) ) { | 4907 if( IS_INTRA( mb_type ) ) { |
4896 if( IS_INTRA4x4( mb_type ) ) { | 4908 if( IS_INTRA4x4( mb_type ) ) { |
4897 int i; | 4909 int i; |
4898 for( i = 0; i < 16; i++ ) { | 4910 for( i = 0; i < 16; i++ ) { |
5544 if( IS_INTRA( s->current_picture.mb_type[mb_xy] ) || | 5556 if( IS_INTRA( s->current_picture.mb_type[mb_xy] ) || |
5545 IS_INTRA( s->current_picture.mb_type[mbn_xy] ) ) { | 5557 IS_INTRA( s->current_picture.mb_type[mbn_xy] ) ) { |
5546 bS[0] = bS[1] = bS[2] = bS[3] = ( edge == 0 ? 4 : 3 ); | 5558 bS[0] = bS[1] = bS[2] = bS[3] = ( edge == 0 ? 4 : 3 ); |
5547 } else { | 5559 } else { |
5548 int i; | 5560 int i; |
5549 const int slice_boundary = (h->slice_table[mbn_xy] != h->slice_table[mb_xy]); | |
5550 for( i = 0; i < 4; i++ ) { | 5561 for( i = 0; i < 4; i++ ) { |
5551 int x = dir == 0 ? edge : i; | 5562 int x = dir == 0 ? edge : i; |
5552 int y = dir == 0 ? i : edge; | 5563 int y = dir == 0 ? i : edge; |
5553 int b_idx= 8 + 4 + x + 8*y; | 5564 int b_idx= 8 + 4 + x + 8*y; |
5554 int bn_idx= b_idx - (dir ? 8:1); | 5565 int bn_idx= b_idx - (dir ? 8:1); |
5555 uint8_t left_non_zero_count; | |
5556 if (slice_boundary) { | |
5557 // must not use non_zero_count_cache, it is not valid | |
5558 // across slice boundaries | |
5559 if (0 == dir) { | |
5560 left_non_zero_count = h->non_zero_count[mbn_xy][6-i]; | |
5561 } else { | |
5562 left_non_zero_count = h->non_zero_count[mbn_xy][i]; | |
5563 } | |
5564 } else { | |
5565 left_non_zero_count = h->non_zero_count_cache[bn_idx]; | |
5566 } | |
5567 | 5566 |
5568 if( h->non_zero_count_cache[b_idx] != 0 || | 5567 if( h->non_zero_count_cache[b_idx] != 0 || |
5569 left_non_zero_count != 0 ) { | 5568 h->non_zero_count_cache[bn_idx] != 0 ) { |
5570 bS[i] = 2; | 5569 bS[i] = 2; |
5571 } | 5570 } |
5572 else if( h->slice_type == P_TYPE ) { | 5571 else if( h->slice_type == P_TYPE ) { |
5573 int16_t left_mv[2]; | 5572 if( h->ref_cache[0][b_idx] != h->ref_cache[0][bn_idx] || |
5574 int8_t left_ref; | 5573 ABS( h->mv_cache[0][b_idx][0] - h->mv_cache[0][bn_idx][0] ) >= 4 || |
5575 if (slice_boundary) { | 5574 ABS( h->mv_cache[0][b_idx][1] - h->mv_cache[0][bn_idx][1] ) >= 4 ) |
5576 // must not use ref_cache and mv_cache, they are not | |
5577 // valid across slice boundaries | |
5578 if (dir == 0) { | |
5579 left_ref = s->current_picture.ref_index[0][h->mb2b8_xy[mbn_xy] + (i>>1) * h->b8_stride + 1]; | |
5580 *(uint32_t*)left_mv = *(uint32_t*)s->current_picture.motion_val[0][h->mb2b_xy[mbn_xy]+i*h->b_stride+3]; | |
5581 } else { | |
5582 left_ref = s->current_picture.ref_index[0][h->mb2b8_xy[mbn_xy] + (i>>1) + h->b8_stride]; | |
5583 *(uint32_t*)left_mv = *(uint32_t*)s->current_picture.motion_val[0][h->mb2b_xy[mbn_xy]+3*h->b_stride+i]; | |
5584 } | |
5585 } else { | |
5586 left_ref = h->ref_cache[0][bn_idx]; | |
5587 *(uint32_t*)left_mv = *(uint32_t*)h->mv_cache[0][bn_idx]; | |
5588 } | |
5589 if( h->ref_cache[0][b_idx] != left_ref || | |
5590 ABS( h->mv_cache[0][b_idx][0] - left_mv[0] ) >= 4 || | |
5591 ABS( h->mv_cache[0][b_idx][1] - left_mv[1] ) >= 4 ) | |
5592 bS[i] = 1; | 5575 bS[i] = 1; |
5593 else | 5576 else |
5594 bS[i] = 0; | 5577 bS[i] = 0; |
5595 } else { | 5578 } else { |
5596 /* FIXME Add support for B frame */ | 5579 /* FIXME Add support for B frame */ |