comparison h263dec.c @ 1144:21c85c4ab2f0 libavcodec

error resilience cleanup (its faster too...)
author michaelni
date Thu, 20 Mar 2003 01:00:57 +0000
parents e10e841c9bf0
children 79e8ed620b17
comparison
equal deleted inserted replaced
1143:a4facfd78935 1144:21c85c4ab2f0
142 return pos; 142 return pos;
143 } 143 }
144 } 144 }
145 145
146 static int decode_slice(MpegEncContext *s){ 146 static int decode_slice(MpegEncContext *s){
147 const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
147 s->last_resync_gb= s->gb; 148 s->last_resync_gb= s->gb;
148 s->first_slice_line= 1; 149 s->first_slice_line= 1;
149 150
150 s->resync_mb_x= s->mb_x; 151 s->resync_mb_x= s->mb_x;
151 s->resync_mb_y= s->mb_y; 152 s->resync_mb_y= s->mb_y;
172 173
173 for(; s->mb_y < s->mb_height; s->mb_y++) { 174 for(; s->mb_y < s->mb_height; s->mb_y++) {
174 /* per-row end of slice checks */ 175 /* per-row end of slice checks */
175 if(s->msmpeg4_version){ 176 if(s->msmpeg4_version){
176 if(s->resync_mb_y + s->slice_height == s->mb_y){ 177 if(s->resync_mb_y + s->slice_height == s->mb_y){
177 const int xy= s->mb_x + s->mb_y*s->mb_width; 178 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);
178 s->error_status_table[xy-1]|= AC_END|DC_END|MV_END; 179
179 return 0; 180 return 0;
180 } 181 }
181 } 182 }
182 183
183 if(s->msmpeg4_version==1){ 184 if(s->msmpeg4_version==1){
209 210
210 if(ret<0){ 211 if(ret<0){
211 const int xy= s->mb_x + s->mb_y*s->mb_width; 212 const int xy= s->mb_x + s->mb_y*s->mb_width;
212 if(ret==SLICE_END){ 213 if(ret==SLICE_END){
213 //printf("%d %d %d %06X\n", s->mb_x, s->mb_y, s->gb.size*8 - get_bits_count(&s->gb), show_bits(&s->gb, 24)); 214 //printf("%d %d %d %06X\n", s->mb_x, s->mb_y, s->gb.size*8 - get_bits_count(&s->gb), show_bits(&s->gb, 24));
214 s->error_status_table[xy]|= AC_END; 215 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
215 if(!s->partitioned_frame)
216 s->error_status_table[xy]|= MV_END|DC_END;
217 216
218 s->padding_bug_score--; 217 s->padding_bug_score--;
219 218
220 if(++s->mb_x >= s->mb_width){ 219 if(++s->mb_x >= s->mb_width){
221 s->mb_x=0; 220 s->mb_x=0;
223 s->mb_y++; 222 s->mb_y++;
224 } 223 }
225 return 0; 224 return 0;
226 }else if(ret==SLICE_NOEND){ 225 }else if(ret==SLICE_NOEND){
227 fprintf(stderr,"Slice mismatch at MB: %d\n", xy); 226 fprintf(stderr,"Slice mismatch at MB: %d\n", xy);
227 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);
228 return -1; 228 return -1;
229 } 229 }
230 fprintf(stderr,"Error at MB: %d\n", xy); 230 fprintf(stderr,"Error at MB: %d\n", xy);
231 s->error_status_table[xy]|= AC_ERROR; 231 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
232 if(!s->partitioned_frame)
233 s->error_status_table[xy]|= DC_ERROR|MV_ERROR;
234 232
235 return -1; 233 return -1;
236 } 234 }
237 } 235 }
238 236
288 fprintf(stderr, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24)); 286 fprintf(stderr, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24));
289 } 287 }
290 else if(left<0){ 288 else if(left<0){
291 fprintf(stderr, "overreading %d bits\n", -left); 289 fprintf(stderr, "overreading %d bits\n", -left);
292 }else 290 }else
293 s->error_status_table[s->mb_num-1]|= AC_END|MV_END|DC_END; 291 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);
294 292
295 return 0; 293 return 0;
296 } 294 }
297 295
298 fprintf(stderr, "slice end not reached but screenspace end (%d left %06X)\n", 296 fprintf(stderr, "slice end not reached but screenspace end (%d left %06X)\n",
299 s->gb.size_in_bits - get_bits_count(&s->gb), 297 s->gb.size_in_bits - get_bits_count(&s->gb),
300 show_bits(&s->gb, 24)); 298 show_bits(&s->gb, 24));
299
300 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
301
301 return -1; 302 return -1;
302 } 303 }
303 304
304 /** 305 /**
305 * finds the end of the current frame in the bitstream. 306 * finds the end of the current frame in the bitstream.
594 595
595 if ( s->width != avctx->width || s->height != avctx->height 596 if ( s->width != avctx->width || s->height != avctx->height
596 || ABS(new_aspect - avctx->aspect_ratio) > 0.001) { 597 || ABS(new_aspect - avctx->aspect_ratio) > 0.001) {
597 /* H.263 could change picture size any time */ 598 /* H.263 could change picture size any time */
598 MPV_common_end(s); 599 MPV_common_end(s);
599 s->context_initialized=0;
600 } 600 }
601 if (!s->context_initialized) { 601 if (!s->context_initialized) {
602 avctx->width = s->width; 602 avctx->width = s->width;
603 avctx->height = s->height; 603 avctx->height = s->height;
604 avctx->aspect_ratio= new_aspect; 604 avctx->aspect_ratio= new_aspect;
639 639
640 #ifdef DEBUG 640 #ifdef DEBUG
641 printf("qscale=%d\n", s->qscale); 641 printf("qscale=%d\n", s->qscale);
642 #endif 642 #endif
643 643
644 if(s->error_resilience) 644 ff_er_frame_start(s);
645 memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_num*sizeof(uint8_t));
646 645
647 /* decode each macroblock */ 646 /* decode each macroblock */
648 s->block_wrap[0]= 647 s->block_wrap[0]=
649 s->block_wrap[1]= 648 s->block_wrap[1]=
650 s->block_wrap[2]= 649 s->block_wrap[2]=
653 s->block_wrap[5]= s->mb_width + 2; 652 s->block_wrap[5]= s->mb_width + 2;
654 s->mb_x=0; 653 s->mb_x=0;
655 s->mb_y=0; 654 s->mb_y=0;
656 655
657 decode_slice(s); 656 decode_slice(s);
658 s->error_status_table[0]|= VP_START;
659 while(s->mb_y<s->mb_height && s->gb.size_in_bits - get_bits_count(&s->gb)>16){ 657 while(s->mb_y<s->mb_height && s->gb.size_in_bits - get_bits_count(&s->gb)>16){
660 if(s->msmpeg4_version){ 658 if(s->msmpeg4_version){
661 if(s->mb_x!=0 || (s->mb_y%s->slice_height)!=0) 659 if(s->mb_x!=0 || (s->mb_y%s->slice_height)!=0)
662 break; 660 break;
663 }else{ 661 }else{
667 665
668 if(s->msmpeg4_version<4 && s->h263_pred) 666 if(s->msmpeg4_version<4 && s->h263_pred)
669 ff_mpeg4_clean_buffers(s); 667 ff_mpeg4_clean_buffers(s);
670 668
671 decode_slice(s); 669 decode_slice(s);
672
673 s->error_status_table[s->resync_mb_x + s->resync_mb_y*s->mb_width]|= VP_START;
674 } 670 }
675 671
676 if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE) 672 if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE)
677 if(msmpeg4_decode_ext_header(s, buf_size) < 0){ 673 if(msmpeg4_decode_ext_header(s, buf_size) < 0){
678 s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR; 674 s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR;
697 s->bitstream_buffer_size= buf_size - current_pos; 693 s->bitstream_buffer_size= buf_size - current_pos;
698 } 694 }
699 } 695 }
700 } 696 }
701 697
702 if(s->error_resilience){ 698 ff_er_frame_end(s);
703 int error=0, num_end_markers=0;
704 for(i=0; i<s->mb_num; i++){
705 int status= s->error_status_table[i];
706 #if 0
707 if(i%s->mb_width == 0) printf("\n");
708 printf("%2X ", status);
709 #endif
710 if(status==0) continue;
711
712 if(status&(DC_ERROR|AC_ERROR|MV_ERROR))
713 error=1;
714 if(status&VP_START){
715 if(num_end_markers)
716 error=1;
717 num_end_markers=3;
718 }
719 if(status&AC_END)
720 num_end_markers--;
721 if(status&DC_END)
722 num_end_markers--;
723 if(status&MV_END)
724 num_end_markers--;
725 }
726 if(num_end_markers || error){
727 fprintf(stderr, "concealing errors\n");
728 ff_error_resilience(s);
729 }
730 }
731 699
732 MPV_frame_end(s); 700 MPV_frame_end(s);
733 701
734 if((avctx->debug&FF_DEBUG_VIS_MV) && s->last_picture_ptr){ 702 if((avctx->debug&FF_DEBUG_VIS_MV) && s->last_picture_ptr){
735 const int shift= 1 + s->quarter_sample; 703 const int shift= 1 + s->quarter_sample;