comparison error_resilience.c @ 1938:e2501e6e7ff7 libavcodec

unify table indexing (motion_val,dc_val,ac_val,coded_block changed) minor +-1 bugfix
author michael
date Fri, 16 Apr 2004 01:01:45 +0000
parents fcbf31baa1af
children 2ede7cc1fe4e
comparison
equal deleted inserted replaced
1937:4d91a9342d95 1938:e2501e6e7ff7
43 */ 43 */
44 static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y) 44 static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y)
45 { 45 {
46 int dc, dcu, dcv, y, i; 46 int dc, dcu, dcv, y, i;
47 for(i=0; i<4; i++){ 47 for(i=0; i<4; i++){
48 dc= s->dc_val[0][mb_x*2+1 + (i&1) + (mb_y*2+1 + (i>>1))*(s->mb_width*2+2)]; 48 dc= s->dc_val[0][mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride];
49 if(dc<0) dc=0; 49 if(dc<0) dc=0;
50 else if(dc>2040) dc=2040; 50 else if(dc>2040) dc=2040;
51 for(y=0; y<8; y++){ 51 for(y=0; y<8; y++){
52 int x; 52 int x;
53 for(x=0; x<8; x++){ 53 for(x=0; x<8; x++){
54 dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8; 54 dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8;
55 } 55 }
56 } 56 }
57 } 57 }
58 dcu = s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)]; 58 dcu = s->dc_val[1][mb_x + mb_y*s->mb_stride];
59 dcv = s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)]; 59 dcv = s->dc_val[2][mb_x + mb_y*s->mb_stride];
60 if (dcu<0 ) dcu=0; 60 if (dcu<0 ) dcu=0;
61 else if(dcu>2040) dcu=2040; 61 else if(dcu>2040) dcu=2040;
62 if (dcv<0 ) dcv=0; 62 if (dcv<0 ) dcv=0;
63 else if(dcv>2040) dcv=2040; 63 else if(dcv>2040) dcv=2040;
64 for(y=0; y<8; y++){ 64 for(y=0; y<8; y++){
207 int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]); 207 int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
208 int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]); 208 int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
209 int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR); 209 int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
210 int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR); 210 int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
211 int offset= b_x*8 + b_y*stride*8; 211 int offset= b_x*8 + b_y*stride*8;
212 int16_t *left_mv= s->current_picture.motion_val[0][s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ( b_x <<(1-is_luma))]; 212 int16_t *left_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ( b_x <<(1-is_luma))];
213 int16_t *right_mv= s->current_picture.motion_val[0][s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ((b_x+1)<<(1-is_luma))]; 213 int16_t *right_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ((b_x+1)<<(1-is_luma))];
214 214
215 if(!(left_damage||right_damage)) continue; // both undamaged 215 if(!(left_damage||right_damage)) continue; // both undamaged
216 216
217 if( (!left_intra) && (!right_intra) 217 if( (!left_intra) && (!right_intra)
218 && ABS(left_mv[0]-right_mv[0]) + ABS(left_mv[1]+right_mv[1]) < 2) continue; 218 && ABS(left_mv[0]-right_mv[0]) + ABS(left_mv[1]+right_mv[1]) < 2) continue;
267 int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]); 267 int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]);
268 int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]); 268 int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
269 int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR); 269 int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
270 int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR); 270 int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
271 int offset= b_x*8 + b_y*stride*8; 271 int offset= b_x*8 + b_y*stride*8;
272 int16_t *top_mv= s->current_picture.motion_val[0][s->block_wrap[0]*(( b_y <<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; 272 int16_t *top_mv= s->current_picture.motion_val[0][s->b8_stride*( b_y <<(1-is_luma)) + (b_x<<(1-is_luma))];
273 int16_t *bottom_mv= s->current_picture.motion_val[0][s->block_wrap[0]*(((b_y+1)<<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; 273 int16_t *bottom_mv= s->current_picture.motion_val[0][s->b8_stride*((b_y+1)<<(1-is_luma)) + (b_x<<(1-is_luma))];
274 274
275 if(!(top_damage||bottom_damage)) continue; // both undamaged 275 if(!(top_damage||bottom_damage)) continue; // both undamaged
276 276
277 if( (!top_intra) && (!bottom_intra) 277 if( (!top_intra) && (!bottom_intra)
278 && ABS(top_mv[0]-bottom_mv[0]) + ABS(top_mv[1]+bottom_mv[1]) < 2) continue; 278 && ABS(top_mv[0]-bottom_mv[0]) + ABS(top_mv[1]+bottom_mv[1]) < 2) continue;
376 int mv_predictor[8][2]={{0}}; 376 int mv_predictor[8][2]={{0}};
377 int pred_count=0; 377 int pred_count=0;
378 int j; 378 int j;
379 int best_score=256*256*256*64; 379 int best_score=256*256*256*64;
380 int best_pred=0; 380 int best_pred=0;
381 const int mot_stride= mb_width*2+2; 381 const int mot_stride= s->b8_stride;
382 const int mot_index= mb_x*2 + 1 + (mb_y*2+1)*mot_stride; 382 const int mot_index= mb_x*2 + mb_y*2*mot_stride;
383 int prev_x= s->current_picture.motion_val[0][mot_index][0]; 383 int prev_x= s->current_picture.motion_val[0][mot_index][0];
384 int prev_y= s->current_picture.motion_val[0][mot_index][1]; 384 int prev_y= s->current_picture.motion_val[0][mot_index][1];
385 385
386 if((mb_x^mb_y^pass)&1) continue; 386 if((mb_x^mb_y^pass)&1) continue;
387 387
670 if(!s->error_resilience || s->error_count==0) return; 670 if(!s->error_resilience || s->error_count==0) return;
671 671
672 av_log(s->avctx, AV_LOG_INFO, "concealing errors\n"); 672 av_log(s->avctx, AV_LOG_INFO, "concealing errors\n");
673 673
674 if(s->current_picture.motion_val[0] == NULL){ 674 if(s->current_picture.motion_val[0] == NULL){
675 int size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); 675 int size = s->b8_stride * 2 * s->mb_height;
676 Picture *pic= s->current_picture_ptr; 676 Picture *pic= s->current_picture_ptr;
677 677
678 av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n"); 678 av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n");
679 679
680 for(i=0; i<2; i++){ 680 for(i=0; i<2; i++){
681 pic->motion_val_base[i]= av_mallocz((size+1) * 2 * sizeof(uint16_t)); //FIXME size 681 pic->motion_val_base[i]= av_mallocz((size+2) * 2 * sizeof(uint16_t));
682 pic->motion_val[i]= pic->motion_val_base[i]+1; 682 pic->motion_val[i]= pic->motion_val_base[i]+2;
683 } 683 }
684 pic->motion_subsample_log2= 3; 684 pic->motion_subsample_log2= 3;
685 s->current_picture= *s->current_picture_ptr; 685 s->current_picture= *s->current_picture_ptr;
686 } 686 }
687 687
843 843
844 s->mv_dir = MV_DIR_FORWARD; 844 s->mv_dir = MV_DIR_FORWARD;
845 s->mb_intra=0; 845 s->mb_intra=0;
846 s->mb_skiped=0; 846 s->mb_skiped=0;
847 if(IS_8X8(mb_type)){ 847 if(IS_8X8(mb_type)){
848 int mb_index= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0]; 848 int mb_index= mb_x*2 + mb_y*2*s->b8_stride;
849 int j; 849 int j;
850 s->mv_type = MV_TYPE_8X8; 850 s->mv_type = MV_TYPE_8X8;
851 for(j=0; j<4; j++){ 851 for(j=0; j<4; j++){
852 s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][0]; 852 s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];
853 s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][1]; 853 s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];
854 } 854 }
855 }else{ 855 }else{
856 s->mv_type = MV_TYPE_16X16; 856 s->mv_type = MV_TYPE_16X16;
857 s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][0]; 857 s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][0];
858 s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][1]; 858 s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][1];
859 } 859 }
860 860
861 s->dsp.clear_blocks(s->block[0]); 861 s->dsp.clear_blocks(s->block[0]);
862 862
863 s->mb_x= mb_x; 863 s->mb_x= mb_x;
868 868
869 /* guess MVs */ 869 /* guess MVs */
870 if(s->pict_type==B_TYPE){ 870 if(s->pict_type==B_TYPE){
871 for(mb_y=0; mb_y<s->mb_height; mb_y++){ 871 for(mb_y=0; mb_y<s->mb_height; mb_y++){
872 for(mb_x=0; mb_x<s->mb_width; mb_x++){ 872 for(mb_x=0; mb_x<s->mb_width; mb_x++){
873 int xy= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0]; 873 int xy= mb_x*2 + mb_y*2*s->b8_stride;
874 const int mb_xy= mb_x + mb_y * s->mb_stride; 874 const int mb_xy= mb_x + mb_y * s->mb_stride;
875 const int mb_type= s->current_picture.mb_type[mb_xy]; 875 const int mb_type= s->current_picture.mb_type[mb_xy];
876 error= s->error_status_table[mb_xy]; 876 error= s->error_status_table[mb_xy];
877 877
878 if(IS_INTRA(mb_type)) continue; 878 if(IS_INTRA(mb_type)) continue;
928 928
929 dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize; 929 dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
930 dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize; 930 dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
931 dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize; 931 dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
932 932
933 dc_ptr= &s->dc_val[0][mb_x*2+1 + (mb_y*2+1)*(s->mb_width*2+2)]; 933 dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];
934 for(n=0; n<4; n++){ 934 for(n=0; n<4; n++){
935 dc=0; 935 dc=0;
936 for(y=0; y<8; y++){ 936 for(y=0; y<8; y++){
937 int x; 937 int x;
938 for(x=0; x<8; x++){ 938 for(x=0; x<8; x++){
939 dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize]; 939 dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize];
940 } 940 }
941 } 941 }
942 dc_ptr[(n&1) + (n>>1)*(s->mb_width*2+2)]= (dc+4)>>3; 942 dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3;
943 } 943 }
944 944
945 dcu=dcv=0; 945 dcu=dcv=0;
946 for(y=0; y<8; y++){ 946 for(y=0; y<8; y++){
947 int x; 947 int x;
948 for(x=0; x<8; x++){ 948 for(x=0; x<8; x++){
949 dcu+=dest_cb[x + y*(s->uvlinesize)]; 949 dcu+=dest_cb[x + y*(s->uvlinesize)];
950 dcv+=dest_cr[x + y*(s->uvlinesize)]; 950 dcv+=dest_cr[x + y*(s->uvlinesize)];
951 } 951 }
952 } 952 }
953 s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcu+4)>>3; 953 s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3;
954 s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcv+4)>>3; 954 s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3;
955 } 955 }
956 } 956 }
957 #if 1 957 #if 1
958 /* guess DC for damaged blocks */ 958 /* guess DC for damaged blocks */
959 guess_dc(s, s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2, 1); 959 guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1);
960 guess_dc(s, s->dc_val[1] + s->mb_width +3, s->mb_width , s->mb_height , s->mb_width +2, 0); 960 guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0);
961 guess_dc(s, s->dc_val[2] + s->mb_width +3, s->mb_width , s->mb_height , s->mb_width +2, 0); 961 guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0);
962 #endif 962 #endif
963 /* filter luma DC */ 963 /* filter luma DC */
964 filter181(s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2); 964 filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride);
965 965
966 #if 1 966 #if 1
967 /* render DC only intra */ 967 /* render DC only intra */
968 for(mb_y=0; mb_y<s->mb_height; mb_y++){ 968 for(mb_y=0; mb_y<s->mb_height; mb_y++){
969 for(mb_x=0; mb_x<s->mb_width; mb_x++){ 969 for(mb_x=0; mb_x<s->mb_width; mb_x++){