comparison h264.c @ 1170:4710976004a5 libavcodec

#ifdef TRACE printf() -> tprintf()
author michaelni
date Sat, 05 Apr 2003 10:08:48 +0000
parents 4e891257d3e2
children 2de2a847af67
comparison
equal deleted inserted replaced
1169:4e891257d3e2 1170:4710976004a5
683 const int index8= scan8[n]; 683 const int index8= scan8[n];
684 const int left= h->intra4x4_pred_mode_cache[index8 - 1]; 684 const int left= h->intra4x4_pred_mode_cache[index8 - 1];
685 const int top = h->intra4x4_pred_mode_cache[index8 - 8]; 685 const int top = h->intra4x4_pred_mode_cache[index8 - 8];
686 const int min= FFMIN(left, top); 686 const int min= FFMIN(left, top);
687 687
688 #ifdef TRACE 688 tprintf("mode:%d %d min:%d\n", left ,top, min);
689 printf("mode:%d %d min:%d\n", left ,top, min);
690 #endif
691 689
692 if(min<0) return DC_PRED; 690 if(min<0) return DC_PRED;
693 else return min; 691 else return min;
694 } 692 }
695 693
724 const int top = h->non_zero_count_cache[index8 - 8]; 722 const int top = h->non_zero_count_cache[index8 - 8];
725 int i= left + top; 723 int i= left + top;
726 724
727 if(i<64) i= (i+1)>>1; 725 if(i<64) i= (i+1)>>1;
728 726
729 #ifdef TRACE 727 tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
730 printf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
731 #endif
732 728
733 return i&31; 729 return i&31;
734 } 730 }
735 731
736 static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ 732 static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){
738 734
739 if(topright_ref != PART_NOT_AVAILABLE){ 735 if(topright_ref != PART_NOT_AVAILABLE){
740 *C= h->mv_cache[list][ i - 8 + part_width ]; 736 *C= h->mv_cache[list][ i - 8 + part_width ];
741 return topright_ref; 737 return topright_ref;
742 }else{ 738 }else{
743 #ifdef TRACE 739 tprintf("topright MV not available\n");
744 printf("topright MV not available\n"); 740
745 #endif
746 *C= h->mv_cache[list][ i - 8 - 1 ]; 741 *C= h->mv_cache[list][ i - 8 - 1 ];
747 return h->ref_cache[list][ i - 8 - 1 ]; 742 return h->ref_cache[list][ i - 8 - 1 ];
748 } 743 }
749 } 744 }
750 745
800 *mx= mid_pred(A[0], B[0], C[0]); 795 *mx= mid_pred(A[0], B[0], C[0]);
801 *my= mid_pred(A[1], B[1], C[1]); 796 *my= mid_pred(A[1], B[1], C[1]);
802 } 797 }
803 } 798 }
804 799
805 #ifdef TRACE 800 tprintf("pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, s->mb_x, s->mb_y, n, list);
806 printf("pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, s->mb_x, s->mb_y, n, list);
807 #endif
808 } 801 }
809 802
810 /** 803 /**
811 * gets the directionally predicted 16x8 MV. 804 * gets the directionally predicted 16x8 MV.
812 * @param n the block index 805 * @param n the block index
817 MpegEncContext * const s = &h->s; 810 MpegEncContext * const s = &h->s;
818 if(n==0){ 811 if(n==0){
819 const int top_ref= h->ref_cache[list][ scan8[0] - 8 ]; 812 const int top_ref= h->ref_cache[list][ scan8[0] - 8 ];
820 const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; 813 const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];
821 814
822 #ifdef TRACE 815 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d", top_ref, B[0], B[1], s->mb_x, s->mb_y, n, list);
823 printf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d", top_ref, B[0], B[1], s->mb_x, s->mb_y, n, list);
824 #endif
825 816
826 if(top_ref == ref){ 817 if(top_ref == ref){
827 *mx= B[0]; 818 *mx= B[0];
828 *my= B[1]; 819 *my= B[1];
829 return; 820 return;
830 } 821 }
831 }else{ 822 }else{
832 const int left_ref= h->ref_cache[list][ scan8[8] - 1 ]; 823 const int left_ref= h->ref_cache[list][ scan8[8] - 1 ];
833 const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ]; 824 const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ];
834 825
835 #ifdef TRACE 826 tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d", left_ref, A[0], A[1], s->mb_x, s->mb_y, n, list);
836 printf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d", left_ref, A[0], A[1], s->mb_x, s->mb_y, n, list);
837 #endif
838 827
839 if(left_ref == ref){ 828 if(left_ref == ref){
840 *mx= A[0]; 829 *mx= A[0];
841 *my= A[1]; 830 *my= A[1];
842 return; 831 return;
857 MpegEncContext * const s = &h->s; 846 MpegEncContext * const s = &h->s;
858 if(n==0){ 847 if(n==0){
859 const int left_ref= h->ref_cache[list][ scan8[0] - 1 ]; 848 const int left_ref= h->ref_cache[list][ scan8[0] - 1 ];
860 const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; 849 const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ];
861 850
862 #ifdef TRACE 851 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", left_ref, A[0], A[1], s->mb_x, s->mb_y, n, list);
863 printf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", left_ref, A[0], A[1], s->mb_x, s->mb_y, n, list);
864 #endif
865 852
866 if(left_ref == ref){ 853 if(left_ref == ref){
867 *mx= A[0]; 854 *mx= A[0];
868 *my= A[1]; 855 *my= A[1];
869 return; 856 return;
872 const int16_t * C; 859 const int16_t * C;
873 int diagonal_ref; 860 int diagonal_ref;
874 861
875 diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); 862 diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2);
876 863
877 #ifdef TRACE 864 tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", diagonal_ref, C[0], C[1], s->mb_x, s->mb_y, n, list);
878 printf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", diagonal_ref, C[0], C[1], s->mb_x, s->mb_y, n, list);
879 #endif
880 865
881 if(diagonal_ref == ref){ 866 if(diagonal_ref == ref){
882 *mx= C[0]; 867 *mx= C[0];
883 *my= C[1]; 868 *my= C[1];
884 return; 869 return;
892 static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){ 877 static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){
893 MpegEncContext * const s = &h->s; 878 MpegEncContext * const s = &h->s;
894 const int top_ref = h->ref_cache[0][ scan8[0] - 8 ]; 879 const int top_ref = h->ref_cache[0][ scan8[0] - 8 ];
895 const int left_ref= h->ref_cache[0][ scan8[0] - 1 ]; 880 const int left_ref= h->ref_cache[0][ scan8[0] - 1 ];
896 881
897 #ifdef TRACE 882 tprintf("pred_pskip: (%d) (%d) at %2d %2d", top_ref, left_ref, s->mb_x, s->mb_y);
898 printf("pred_pskip: (%d) (%d) at %2d %2d", top_ref, left_ref, s->mb_x, s->mb_y);
899 #endif
900 883
901 if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE 884 if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE
902 || (top_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0) 885 || (top_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0)
903 || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){ 886 || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){
904 887
1086 */ 1069 */
1087 static int decode_rbsp_trailing(uint8_t *src){ 1070 static int decode_rbsp_trailing(uint8_t *src){
1088 int v= *src; 1071 int v= *src;
1089 int r; 1072 int r;
1090 1073
1091 #ifdef TRACE 1074 tprintf("rbsp trailing %X\n", v);
1092 printf("rbsp trailing %X\n", v);
1093 #endif
1094 1075
1095 for(r=1; r<9; r++){ 1076 for(r=1; r<9; r++){
1096 if(v&1) return r; 1077 if(v&1) return r;
1097 v>>=1; 1078 v>>=1;
1098 } 1079 }
3071 3052
3072 if(total_coeff==0) 3053 if(total_coeff==0)
3073 return 0; 3054 return 0;
3074 3055
3075 trailing_ones= coeff_token&3; 3056 trailing_ones= coeff_token&3;
3076 #ifdef TRACE 3057 tprintf("trailing:%d, total:%d\n", trailing_ones, total_coeff);
3077 printf("trailing:%d, total:%d\n", trailing_ones, total_coeff);
3078 #endif
3079 assert(total_coeff<=16); 3058 assert(total_coeff<=16);
3080 3059
3081 for(i=0; i<trailing_ones; i++){ 3060 for(i=0; i<trailing_ones; i++){
3082 level[i]= 1 - 2*get_bits1(gb); 3061 level[i]= 1 - 2*get_bits1(gb);
3083 } 3062 }
3117 if(ABS(level[i]) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++; 3096 if(ABS(level[i]) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++;
3118 #else 3097 #else
3119 if((2+level_code)>>1) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++; 3098 if((2+level_code)>>1) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++;
3120 ? == prefix > 2 or sth 3099 ? == prefix > 2 or sth
3121 #endif 3100 #endif
3122 #ifdef TRACE 3101 tprintf("level: %d suffix_length:%d\n", level[i], suffix_length);
3123 printf("level: %d suffix_length:%d\n", level[i], suffix_length);
3124 #endif
3125 } 3102 }
3126 3103
3127 if(total_coeff == max_coeff) 3104 if(total_coeff == max_coeff)
3128 zeros_left=0; 3105 zeros_left=0;
3129 else{ 3106 else{
3188 const int mb_xy= s->mb_x + s->mb_y*h->mb_stride; 3165 const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
3189 int mb_type, partition_count, cbp; 3166 int mb_type, partition_count, cbp;
3190 3167
3191 memset(h->mb, 0, sizeof(int16_t)*24*16); //FIXME avoid if allready clear (move after skip handlong? 3168 memset(h->mb, 0, sizeof(int16_t)*24*16); //FIXME avoid if allready clear (move after skip handlong?
3192 3169
3193 #ifdef TRACE 3170 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
3194 printf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
3195 #endif
3196 3171
3197 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){ 3172 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){
3198 if(s->mb_skip_run==-1) 3173 if(s->mb_skip_run==-1)
3199 s->mb_skip_run= get_ue_golomb(&s->gb); 3174 s->mb_skip_run= get_ue_golomb(&s->gb);
3200 3175
3408 const int index= 4*i + block_width*j; 3383 const int index= 4*i + block_width*j;
3409 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; 3384 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];
3410 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); 3385 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);
3411 mx += get_se_golomb(&s->gb); 3386 mx += get_se_golomb(&s->gb);
3412 my += get_se_golomb(&s->gb); 3387 my += get_se_golomb(&s->gb);
3413 #ifdef TRACE 3388 tprintf("final mv:%d %d\n", mx, my);
3414 printf("final mv:%d %d\n", mx, my); 3389
3415 #endif
3416 if(IS_SUB_8X8(sub_mb_type)){ 3390 if(IS_SUB_8X8(sub_mb_type)){
3417 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= 3391 mv_cache[ 0 ][0]= mv_cache[ 1 ][0]=
3418 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; 3392 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
3419 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= 3393 mv_cache[ 0 ][1]= mv_cache[ 1 ][1]=
3420 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; 3394 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
3452 for(list=0; list<2; list++){ 3426 for(list=0; list<2; list++){
3453 if(IS_DIR(mb_type, 0, list)){ 3427 if(IS_DIR(mb_type, 0, list)){
3454 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); 3428 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);
3455 mx += get_se_golomb(&s->gb); 3429 mx += get_se_golomb(&s->gb);
3456 my += get_se_golomb(&s->gb); 3430 my += get_se_golomb(&s->gb);
3457 #ifdef TRACE 3431 tprintf("final mv:%d %d\n", mx, my);
3458 printf("final mv:%d %d\n", mx, my); 3432
3459 #endif
3460 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, (mx&0xFFFF) + (my<<16), 4); 3433 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, (mx&0xFFFF) + (my<<16), 4);
3461 } 3434 }
3462 } 3435 }
3463 } 3436 }
3464 else if(IS_16X8(mb_type)){ 3437 else if(IS_16X8(mb_type)){
3476 for(i=0; i<2; i++){ 3449 for(i=0; i<2; i++){
3477 if(IS_DIR(mb_type, i, list)){ 3450 if(IS_DIR(mb_type, i, list)){
3478 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); 3451 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);
3479 mx += get_se_golomb(&s->gb); 3452 mx += get_se_golomb(&s->gb);
3480 my += get_se_golomb(&s->gb); 3453 my += get_se_golomb(&s->gb);
3481 #ifdef TRACE 3454 tprintf("final mv:%d %d\n", mx, my);
3482 printf("final mv:%d %d\n", mx, my); 3455
3483 #endif
3484 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (mx&0xFFFF) + (my<<16), 4); 3456 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (mx&0xFFFF) + (my<<16), 4);
3485 } 3457 }
3486 } 3458 }
3487 } 3459 }
3488 }else{ 3460 }else{
3501 for(i=0; i<2; i++){ 3473 for(i=0; i<2; i++){
3502 if(IS_DIR(mb_type, i, list)){ 3474 if(IS_DIR(mb_type, i, list)){
3503 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); 3475 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
3504 mx += get_se_golomb(&s->gb); 3476 mx += get_se_golomb(&s->gb);
3505 my += get_se_golomb(&s->gb); 3477 my += get_se_golomb(&s->gb);
3506 #ifdef TRACE 3478 tprintf("final mv:%d %d\n", mx, my);
3507 printf("final mv:%d %d\n", mx, my); 3479
3508 #endif
3509 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (mx&0xFFFF) + (my<<16), 4); 3480 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (mx&0xFFFF) + (my<<16), 4);
3510 } 3481 }
3511 } 3482 }
3512 } 3483 }
3513 } 3484 }
3653 3624
3654 if(++s->mb_x >= s->mb_width){ 3625 if(++s->mb_x >= s->mb_width){
3655 s->mb_x=0; 3626 s->mb_x=0;
3656 ff_draw_horiz_band(s, 16*s->mb_y, 16); 3627 ff_draw_horiz_band(s, 16*s->mb_y, 16);
3657 if(++s->mb_y >= s->mb_height){ 3628 if(++s->mb_y >= s->mb_height){
3658 #ifdef TRACE 3629 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
3659 printf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); 3630
3660 #endif
3661 if(get_bits_count(&s->gb) == s->gb.size_in_bits){ 3631 if(get_bits_count(&s->gb) == s->gb.size_in_bits){
3662 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); 3632 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
3663 3633
3664 return 0; 3634 return 0;
3665 }else{ 3635 }else{