From 63ccd466873b0863d466f5846a305eb908fe3b80 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 28 Nov 2011 00:31:52 +0100 Subject: lavc: introduce ER_MB_END and ER_MB_ERROR Simplify a little error resilience calls Signed-off-by: Luca Barbato --- libavcodec/error_resilience.c | 26 +++++++++++++------------- libavcodec/h263dec.c | 14 +++++++------- libavcodec/h264.c | 16 ++++++++-------- libavcodec/intrax8.c | 2 +- libavcodec/mpegvideo.h | 3 +++ libavcodec/rv10.c | 2 +- libavcodec/rv34.c | 4 ++-- libavcodec/vc1dec.c | 18 +++++++++--------- 8 files changed, 44 insertions(+), 41 deletions(-) diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index 5c5fc44606..fe28f469f9 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -250,8 +250,8 @@ static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int st int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]; int left_intra = IS_INTRA(s->current_picture.f.mb_type[( b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]); int right_intra = IS_INTRA(s->current_picture.f.mb_type[((b_x + 1) >> is_luma) + (b_y >> is_luma) * s->mb_stride]); - int left_damage = left_status&(ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR); - int right_damage= right_status&(ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR); + int left_damage = left_status&ER_MB_ERROR; + int right_damage= right_status&ER_MB_ERROR; int offset= b_x*8 + b_y*stride*8; int16_t *left_mv= s->current_picture.f.motion_val[0][mvy_stride*b_y + mvx_stride* b_x ]; int16_t *right_mv= s->current_picture.f.motion_val[0][mvy_stride*b_y + mvx_stride*(b_x+1)]; @@ -313,8 +313,8 @@ static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int st int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]; int top_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ( b_y >> is_luma) * s->mb_stride]); int bottom_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ((b_y + 1) >> is_luma) * s->mb_stride]); - int top_damage = top_status&(ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR); - int bottom_damage= bottom_status&(ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR); + int top_damage = top_status&ER_MB_ERROR; + int bottom_damage= bottom_status&ER_MB_ERROR; int offset= b_x*8 + b_y*stride*8; int16_t *top_mv = s->current_picture.f.motion_val[0][mvy_stride * b_y + mvx_stride * b_x]; int16_t *bottom_mv = s->current_picture.f.motion_val[0][mvy_stride * (b_y + 1) + mvx_stride * b_x]; @@ -705,7 +705,7 @@ static int is_intra_more_likely(MpegEncContext *s){ void ff_er_frame_start(MpegEncContext *s){ if(!s->err_recognition) return; - memset(s->error_status_table, ER_MV_ERROR|ER_AC_ERROR|ER_DC_ERROR|VP_START|ER_AC_END|ER_DC_END|ER_MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t)); + memset(s->error_status_table, ER_MB_ERROR|VP_START|ER_MB_END, s->mb_stride*s->mb_height*sizeof(uint8_t)); s->error_count= 3*s->mb_num; s->error_occurred = 0; } @@ -747,7 +747,7 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en s->error_count -= end_i - start_i + 1; } - if(status & (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)) { + if(status & ER_MB_ERROR) { s->error_occurred = 1; s->error_count= INT_MAX; } @@ -870,14 +870,14 @@ void ff_er_frame_end(MpegEncContext *s){ if(error1&VP_START) end_ok=1; - if( error2==(VP_START|ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR|ER_AC_END|ER_DC_END|ER_MV_END) - && error1!=(VP_START|ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR|ER_AC_END|ER_DC_END|ER_MV_END) + if( error2==(VP_START|ER_MB_ERROR|ER_MB_END) + && error1!=(VP_START|ER_MB_ERROR|ER_MB_END) && ((error1&ER_AC_END) || (error1&ER_DC_END) || (error1&ER_MV_END))){ //end & uninit end_ok=0; } if(!end_ok) - s->error_status_table[mb_xy]|= ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR; + s->error_status_table[mb_xy]|= ER_MB_ERROR; } } @@ -913,9 +913,9 @@ void ff_er_frame_end(MpegEncContext *s){ int old_error= s->error_status_table[mb_xy]; if(old_error&VP_START) - error= old_error& (ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR); + error= old_error& ER_MB_ERROR; else{ - error|= old_error& (ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR); + error|= old_error& ER_MB_ERROR; s->error_status_table[mb_xy]|= error; } } @@ -925,8 +925,8 @@ void ff_er_frame_end(MpegEncContext *s){ for(i=0; imb_num; i++){ const int mb_xy= s->mb_index2xy[i]; error= s->error_status_table[mb_xy]; - if(error&(ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)) - error|= ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR; + if(error&ER_MB_ERROR) + error|= ER_MB_ERROR; s->error_status_table[mb_xy]= error; } } diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 06986fff6f..84a2fda79c 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -184,7 +184,7 @@ static int decode_slice(MpegEncContext *s){ /* per-row end of slice checks */ if(s->msmpeg4_version){ if(s->resync_mb_y + s->slice_height == s->mb_y){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_AC_END|ER_DC_END|ER_MV_END); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); return 0; } @@ -225,7 +225,7 @@ static int decode_slice(MpegEncContext *s){ ff_h263_loop_filter(s); //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)); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); s->padding_bug_score--; @@ -238,11 +238,11 @@ static int decode_slice(MpegEncContext *s){ return 0; }else if(ret==SLICE_NOEND){ av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, ER_MB_END&part_mask); return -1; } av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); return -1; } @@ -321,7 +321,7 @@ static int decode_slice(MpegEncContext *s){ else if(left<0){ av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left); }else - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_AC_END|ER_DC_END|ER_MV_END); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); return 0; } @@ -330,7 +330,7 @@ static int decode_slice(MpegEncContext *s){ get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); return -1; } @@ -661,7 +661,7 @@ retry: if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I) if(!CONFIG_MSMPEG4_DECODER || msmpeg4_decode_ext_header(s, buf_size) < 0){ - s->error_status_table[s->mb_num-1]= ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR; + s->error_status_table[s->mb_num-1]= ER_MB_ERROR; } assert(s->bitstream_buffer_size==0); diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 03850285c7..109a109530 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -3595,13 +3595,13 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ eos = get_cabac_terminate( &h->cabac ); if((s->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask); if (s->mb_x >= lf_x_start) loop_filter(h, lf_x_start, s->mb_x + 1); return 0; } if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) { av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); return -1; } @@ -3619,7 +3619,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ if( eos || s->mb_y >= s->mb_height ) { tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask); if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x); return 0; } @@ -3641,7 +3641,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ if(ret<0){ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); return -1; } @@ -3659,11 +3659,11 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); if(get_bits_count(&s->gb) == s->gb.size_in_bits ) { - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask); return 0; }else{ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); return -1; } @@ -3673,12 +3673,12 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){ tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); if(get_bits_count(&s->gb) == s->gb.size_in_bits ){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask); if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x); return 0; }else{ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)&part_mask); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); return -1; } diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c index 7dbc242087..0dc33e2596 100644 --- a/libavcodec/intrax8.c +++ b/libavcodec/intrax8.c @@ -784,6 +784,6 @@ int ff_intrax8_decode_picture(IntraX8Context * const w, int dquant, int quant_of error: ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, (s->mb_x>>1)-1, (s->mb_y>>1)-1, - (ER_AC_END|ER_DC_END|ER_MV_END) ); + ER_MB_END ); return 0; } diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 704535d073..38bbd123ee 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -481,6 +481,9 @@ typedef struct MpegEncContext { #define ER_DC_END 32 #define ER_MV_END 64 +#define ER_MB_ERROR (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR) +#define ER_MB_END (ER_AC_END|ER_DC_END|ER_MV_END) + int resync_mb_x; ///< x position of last resync marker int resync_mb_y; ///< y position of last resync marker GetBitContext last_resync_gb; ///< used to search for the next resync marker diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 8d8d2d5829..1d78c92c46 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -609,7 +609,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, if(ret == SLICE_END) break; } - ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_AC_END|ER_DC_END|ER_MV_END); + ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); return s->gb.size_in_bits; } diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index b22398ac51..1a126be2f9 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -1278,7 +1278,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int s->dsp.clear_blocks(s->block[0]); if(rv34_decode_macroblock(r, r->intra_types + s->mb_x * 4 + 4) < 0){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_ERROR); return -1; } if (++s->mb_x == s->mb_width) { @@ -1296,7 +1296,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int s->first_slice_line=0; s->mb_num_left--; } - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_AC_END|ER_DC_END|ER_MV_END); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); return s->mb_y == s->mb_height; } diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index d28a8b7375..fd67feb116 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -4548,7 +4548,7 @@ static void vc1_decode_i_blocks(VC1Context *v) if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq); if (get_bits_count(&s->gb) > v->bits) { - ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)); + ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, ER_MB_END); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); return; @@ -4563,7 +4563,7 @@ static void vc1_decode_i_blocks(VC1Context *v) } if (v->s.loop_filter) ff_draw_horiz_band(s, (s->mb_height - 1) * 16, 16); - ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (ER_AC_END|ER_DC_END|ER_MV_END)); + ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, ER_MB_END); } /** Decode blocks of I-frame for advanced profile @@ -4673,7 +4673,7 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) if (get_bits_count(&s->gb) > v->bits) { // TODO: may need modification to handle slice coding - ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_END); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); return; @@ -4698,7 +4698,7 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) if (v->s.loop_filter) ff_draw_horiz_band(s, (s->end_mb_y-1)*16, 16); ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1, - (s->end_mb_y << v->field_mode) - 1, (ER_AC_END|ER_DC_END|ER_MV_END)); + (s->end_mb_y << v->field_mode) - 1, ER_MB_END); } static void vc1_decode_p_blocks(VC1Context *v) @@ -4749,7 +4749,7 @@ static void vc1_decode_p_blocks(VC1Context *v) vc1_apply_p_loop_filter(v); if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { // TODO: may need modification to handle slice coding - ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_END); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y); return; @@ -4773,7 +4773,7 @@ static void vc1_decode_p_blocks(VC1Context *v) if (s->end_mb_y >= s->start_mb_y) ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16); ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1, - (s->end_mb_y << v->field_mode) - 1, (ER_AC_END|ER_DC_END|ER_MV_END)); + (s->end_mb_y << v->field_mode) - 1, ER_MB_END); } static void vc1_decode_b_blocks(VC1Context *v) @@ -4818,7 +4818,7 @@ static void vc1_decode_b_blocks(VC1Context *v) vc1_decode_b_mb(v); if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { // TODO: may need modification to handle slice coding - ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_END)); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_END); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y); return; @@ -4834,14 +4834,14 @@ static void vc1_decode_b_blocks(VC1Context *v) if (v->s.loop_filter) ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16); ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1, - (s->end_mb_y << v->field_mode) - 1, (ER_AC_END|ER_DC_END|ER_MV_END)); + (s->end_mb_y << v->field_mode) - 1, ER_MB_END); } static void vc1_decode_skip_blocks(VC1Context *v) { MpegEncContext *s = &v->s; - ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, (ER_AC_END|ER_DC_END|ER_MV_END)); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, ER_MB_END); s->first_slice_line = 1; for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; -- cgit v1.2.3