Revision 46b4feec libavcodec/h263dec.c

View differences:

libavcodec/h263dec.c
144 144
}
145 145

  
146 146
static int decode_slice(MpegEncContext *s){
147
    const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
147 148
    s->last_resync_gb= s->gb;
148 149
    s->first_slice_line= 1;
149 150
        
......
174 175
        /* per-row end of slice checks */
175 176
        if(s->msmpeg4_version){
176 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
                s->error_status_table[xy-1]|= AC_END|DC_END|MV_END;
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);
179

  
179 180
                return 0;
180 181
            }
181 182
        }
......
211 212
                const int xy= s->mb_x + s->mb_y*s->mb_width;
212 213
                if(ret==SLICE_END){
213 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
                    if(!s->partitioned_frame)
216
                        s->error_status_table[xy]|= MV_END|DC_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);
217 216

  
218 217
                    s->padding_bug_score--;
219 218
                        
......
225 224
                    return 0; 
226 225
                }else if(ret==SLICE_NOEND){
227 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 228
                    return -1;
229 229
                }
230 230
                fprintf(stderr,"Error at MB: %d\n", xy);
231
                s->error_status_table[xy]|= AC_ERROR;
232
                if(!s->partitioned_frame)
233
                    s->error_status_table[xy]|= DC_ERROR|MV_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);
234 232
    
235 233
                return -1;
236 234
            }
......
290 288
        else if(left<0){
291 289
            fprintf(stderr, "overreading %d bits\n", -left);
292 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 293
        return 0;
296 294
    }
......
298 296
    fprintf(stderr, "slice end not reached but screenspace end (%d left %06X)\n", 
299 297
            s->gb.size_in_bits - get_bits_count(&s->gb),
300 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 302
    return -1;
302 303
}
303 304

  
......
596 597
        || ABS(new_aspect - avctx->aspect_ratio) > 0.001) {
597 598
        /* H.263 could change picture size any time */
598 599
        MPV_common_end(s);
599
        s->context_initialized=0;
600 600
    }
601 601
    if (!s->context_initialized) {
602 602
        avctx->width = s->width;
......
641 641
    printf("qscale=%d\n", s->qscale);
642 642
#endif
643 643

  
644
    if(s->error_resilience)
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));
644
    ff_er_frame_start(s);
646 645
    
647 646
    /* decode each macroblock */
648 647
    s->block_wrap[0]=
......
655 654
    s->mb_y=0;
656 655
    
657 656
    decode_slice(s);
658
    s->error_status_table[0]|= VP_START;
659 657
    while(s->mb_y<s->mb_height && s->gb.size_in_bits - get_bits_count(&s->gb)>16){
660 658
        if(s->msmpeg4_version){
661 659
            if(s->mb_x!=0 || (s->mb_y%s->slice_height)!=0)
......
669 667
            ff_mpeg4_clean_buffers(s);
670 668

  
671 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 672
    if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE)
......
699 695
        }
700 696
    }
701 697

  
702
    if(s->error_resilience){
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
    }
698
    ff_er_frame_end(s);
731 699

  
732 700
    MPV_frame_end(s);
733 701

  

Also available in: Unified diff