From 5cd56e193fd3c9f04075ef95be2d4eade87ca870 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Mon, 12 Dec 2011 10:23:51 -0800 Subject: [PATCH 01/10] aacdec: Use intfloat.h rather than local punning union. --- libavcodec/aacdec.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 8e4b510354..70396b63fa 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -98,6 +98,7 @@ #include "aacsbr.h" #include "mpeg4audio.h" #include "aacadtsdec.h" +#include "libavutil/intfloat.h" #include #include @@ -108,11 +109,6 @@ # include "arm/aac.h" #endif -union float754 { - float f; - uint32_t i; -}; - static VLC vlc_scalefactors; static VLC vlc_spectral[11]; @@ -1004,7 +1000,7 @@ static inline float *VMUL4(float *dst, const float *v, unsigned idx, static inline float *VMUL2S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale) { - union float754 s0, s1; + union av_intfloat32 s0, s1; s0.f = s1.f = *scale; s0.i ^= sign >> 1 << 31; @@ -1022,8 +1018,8 @@ static inline float *VMUL4S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale) { unsigned nz = idx >> 12; - union float754 s = { .f = *scale }; - union float754 t; + union av_intfloat32 s = { .f = *scale }; + union av_intfloat32 t; t.i = s.i ^ (sign & 1U<<31); *dst++ = v[idx & 3] * t.f; @@ -1272,7 +1268,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], static av_always_inline float flt16_round(float pf) { - union float754 tmp; + union av_intfloat32 tmp; tmp.f = pf; tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U; return tmp.f; @@ -1280,7 +1276,7 @@ static av_always_inline float flt16_round(float pf) static av_always_inline float flt16_even(float pf) { - union float754 tmp; + union av_intfloat32 tmp; tmp.f = pf; tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U >> 16)) & 0xFFFF0000U; return tmp.f; @@ -1288,7 +1284,7 @@ static av_always_inline float flt16_even(float pf) static av_always_inline float flt16_trunc(float pf) { - union float754 pun; + union av_intfloat32 pun; pun.f = pf; pun.i &= 0xFFFF0000U; return pun.f; From 40901fc14e1ae1a1074a70931a133b2bc2604a1c Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Mon, 12 Dec 2011 23:21:39 +0000 Subject: [PATCH 02/10] rv34: move 4x4 dequant to RV34DSPContext Signed-off-by: Mans Rullgard --- libavcodec/rv34.c | 18 ++---------------- libavcodec/rv34dsp.c | 16 ++++++++++++++++ libavcodec/rv34dsp.h | 1 + 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 295a633f38..7023ec1223 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -288,20 +288,6 @@ static inline void rv34_decode_block(DCTELEM *dst, GetBitContext *gb, RV34VLC *r } -/** - * Dequantize ordinary 4x4 block. - * @todo optimize - */ -static inline void rv34_dequant4x4(DCTELEM *block, int Qdc, int Q) -{ - int i, j; - - block[0] = (block[0] * Qdc + 8) >> 4; - for(i = 0; i < 4; i++) - for(j = !i; j < 4; j++) - block[j + i*8] = (block[j + i*8] * Q + 8) >> 4; -} - /** * Dequantize 4x4 block of DC values for 16x16 macroblock. * @todo optimize @@ -1159,7 +1145,7 @@ static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types) blkoff = ((i & 1) << 2) + ((i & 4) << 3); if(cbp & 1) rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->luma_vlc, 0); - rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[s->qscale],rv34_qscale_tab[s->qscale]); + r->rdsp.rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[s->qscale],rv34_qscale_tab[s->qscale]); if(r->is16) //FIXME: optimize s->block[blknum][blkoff] = block16[(i & 3) | ((i & 0xC) << 1)]; r->rdsp.rv34_inv_transform_tab[0](s->block[blknum] + blkoff); @@ -1171,7 +1157,7 @@ static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types) blknum = ((i & 4) >> 2) + 4; blkoff = ((i & 1) << 2) + ((i & 2) << 4); rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->chroma_vlc, 1); - rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]],rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]); + r->rdsp.rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]],rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]); r->rdsp.rv34_inv_transform_tab[0](s->block[blknum] + blkoff); } if (IS_INTRA(s->current_picture_ptr->f.mb_type[mb_pos])) diff --git a/libavcodec/rv34dsp.c b/libavcodec/rv34dsp.c index 1f4cea8544..974bf9ec16 100644 --- a/libavcodec/rv34dsp.c +++ b/libavcodec/rv34dsp.c @@ -100,10 +100,26 @@ static void rv34_inv_transform_noround_c(DCTELEM *block){ /** @} */ // transform +/** + * Dequantize ordinary 4x4 block. + */ +void ff_rv34_dequant4x4_neon(DCTELEM *block, int Qdc, int Q); +static void rv34_dequant4x4_c(DCTELEM *block, int Qdc, int Q) +{ + int i, j; + + block[0] = (block[0] * Qdc + 8) >> 4; + for (i = 0; i < 4; i++) + for (j = !i; j < 4; j++) + block[j + i*8] = (block[j + i*8] * Q + 8) >> 4; +} + av_cold void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp) { c->rv34_inv_transform_tab[0] = rv34_inv_transform_c; c->rv34_inv_transform_tab[1] = rv34_inv_transform_noround_c; + c->rv34_dequant4x4 = rv34_dequant4x4_c; + if (HAVE_NEON) ff_rv34dsp_init_neon(c, dsp); } diff --git a/libavcodec/rv34dsp.h b/libavcodec/rv34dsp.h index 695af06970..cf6e14d305 100644 --- a/libavcodec/rv34dsp.h +++ b/libavcodec/rv34dsp.h @@ -48,6 +48,7 @@ typedef struct RV34DSPContext { h264_chroma_mc_func avg_chroma_pixels_tab[3]; rv40_weight_func rv40_weight_pixels_tab[2]; rv34_inv_transform_func rv34_inv_transform_tab[2]; + void (*rv34_dequant4x4)(DCTELEM *block, int Qdc, int Q); rv40_loop_filter_func rv40_h_loop_filter; rv40_loop_filter_func rv40_v_loop_filter; } RV34DSPContext; From 4722a03c75d17d88312b91cd1006776844237349 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Mon, 12 Dec 2011 23:22:04 +0000 Subject: [PATCH 03/10] rv34: NEON optimised 4x4 dequant Signed-off-by: Mans Rullgard --- libavcodec/arm/rv34dsp_init_neon.c | 3 +++ libavcodec/arm/rv34dsp_neon.S | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/libavcodec/arm/rv34dsp_init_neon.c b/libavcodec/arm/rv34dsp_init_neon.c index 9a09fde7a9..acf2a7dcd3 100644 --- a/libavcodec/arm/rv34dsp_init_neon.c +++ b/libavcodec/arm/rv34dsp_init_neon.c @@ -25,9 +25,12 @@ void ff_rv34_inv_transform_neon(DCTELEM *block); void ff_rv34_inv_transform_noround_neon(DCTELEM *block); +void ff_rv34_dequant4x4_neon(DCTELEM *block, int Qdc, int Q); void ff_rv34dsp_init_neon(RV34DSPContext *c, DSPContext* dsp) { c->rv34_inv_transform_tab[0] = ff_rv34_inv_transform_neon; c->rv34_inv_transform_tab[1] = ff_rv34_inv_transform_noround_neon; + + c->rv34_dequant4x4 = ff_rv34_dequant4x4_neon; } diff --git a/libavcodec/arm/rv34dsp_neon.S b/libavcodec/arm/rv34dsp_neon.S index f700f5c321..423b537fb9 100644 --- a/libavcodec/arm/rv34dsp_neon.S +++ b/libavcodec/arm/rv34dsp_neon.S @@ -107,3 +107,27 @@ function ff_rv34_inv_transform_noround_neon, export=1 vst4.16 {d0[3], d1[3], d2[3], d3[3]}, [r2,:64], r1 bx lr endfunc + +function ff_rv34_dequant4x4_neon, export=1 + mov r3, r0 + mov r12, #16 + vdup.16 q0, r2 + vmov.16 d0[0], r1 + vld1.16 {d2}, [r0,:64], r12 + vld1.16 {d4}, [r0,:64], r12 + vld1.16 {d6}, [r0,:64], r12 + vld1.16 {d16}, [r0,:64], r12 + vmull.s16 q1, d2, d0 + vmull.s16 q2, d4, d1 + vmull.s16 q3, d6, d1 + vmull.s16 q8, d16, d1 + vqrshrn.s32 d2, q1, #4 + vqrshrn.s32 d4, q2, #4 + vqrshrn.s32 d6, q3, #4 + vqrshrn.s32 d16, q8, #4 + vst1.16 {d2}, [r3,:64], r12 + vst1.16 {d4}, [r3,:64], r12 + vst1.16 {d6}, [r3,:64], r12 + vst1.16 {d16}, [r3,:64], r12 + bx lr +endfunc From 878dda5db12b6f84cc9fb37c5c88b94a5be61a24 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Tue, 13 Dec 2011 13:28:01 +0000 Subject: [PATCH 04/10] build: move inclusion of subdir.mak to main subdir loop Signed-off-by: Mans Rullgard --- Makefile | 1 + libavcodec/Makefile | 2 -- libavdevice/Makefile | 2 -- libavfilter/Makefile | 2 -- libavformat/Makefile | 2 -- libavutil/Makefile | 2 -- libpostproc/Makefile | 2 -- libswscale/Makefile | 2 -- 8 files changed, 1 insertion(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 04af278b93..3809ece352 100644 --- a/Makefile +++ b/Makefile @@ -113,6 +113,7 @@ define DOSUBDIR $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V)))) SUBDIR := $(1)/ include $(SRC_PATH)/$(1)/Makefile +include $(SRC_PATH)/subdir.mak endef $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D)))) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 383039ac26..07a3048535 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -694,8 +694,6 @@ DIRS = alpha arm bfin mlib ppc ps2 sh4 sparc x86 CLEANFILES = *_tables.c *_tables.h *_tablegen$(HOSTEXESUF) -include $(SRC_PATH)/subdir.mak - $(SUBDIR)dct-test$(EXESUF): $(SUBDIR)dctref.o TRIG_TABLES = cos cos_fixed sin diff --git a/libavdevice/Makefile b/libavdevice/Makefile index 78de08a50e..1a1e2f129d 100644 --- a/libavdevice/Makefile +++ b/libavdevice/Makefile @@ -32,5 +32,3 @@ SKIPHEADERS-$(HAVE_ALSA_ASOUNDLIB_H) += alsa-audio.h SKIPHEADERS-$(HAVE_SNDIO_H) += sndio_common.h TESTPROGS = timefilter - -include $(SRC_PATH)/subdir.mak diff --git a/libavfilter/Makefile b/libavfilter/Makefile index bc05f1ddea..63974d0089 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -74,5 +74,3 @@ OBJS-$(CONFIG_NULLSINK_FILTER) += vsink_nullsink.o DIRS = x86 TOOLS = graph2dot lavfi-showfiltfmts - -include $(SRC_PATH)/subdir.mak diff --git a/libavformat/Makefile b/libavformat/Makefile index 9d2e946b3c..ea28290da8 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -348,6 +348,4 @@ EXAMPLES = metadata output TESTPROGS = seek TOOLS = pktdumper probetest -include $(SRC_PATH)/subdir.mak - $(SUBDIR)output-example$(EXESUF): ELIBS = -lswscale diff --git a/libavutil/Makefile b/libavutil/Makefile index bded2c63c5..6896846081 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -83,6 +83,4 @@ DIRS = arm bfin sh4 x86 ARCH_HEADERS = bswap.h intmath.h intreadwrite.h timer.h -include $(SRC_PATH)/subdir.mak - $(SUBDIR)lzo-test$(EXESUF): ELIBS = -llzo2 diff --git a/libpostproc/Makefile b/libpostproc/Makefile index 11de3d3235..86c9b5f47d 100644 --- a/libpostproc/Makefile +++ b/libpostproc/Makefile @@ -4,5 +4,3 @@ FFLIBS = avutil HEADERS = postprocess.h OBJS = postprocess.o - -include $(SRC_PATH)/subdir.mak diff --git a/libswscale/Makefile b/libswscale/Makefile index 5671b2e1b3..bb9b7d3539 100644 --- a/libswscale/Makefile +++ b/libswscale/Makefile @@ -22,5 +22,3 @@ OBJS-$(HAVE_YASM) += x86/scale.o TESTPROGS = colorspace swscale DIRS = bfin mlib ppc sparc x86 - -include $(SRC_PATH)/subdir.mak From 5bf2ac2b37ae17df7f2bd541801bec8c049b8d2c Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 28 Nov 2011 00:31:51 +0100 Subject: [PATCH 05/10] error_resilience: use the ER_ namespace Add the namespace to {AC_,DC_,MV_}{END,ERROR} macros Signed-off-by: Luca Barbato --- libavcodec/error_resilience.c | 90 +++++++++++++++++------------------ libavcodec/h263dec.c | 16 +++---- libavcodec/h264.c | 18 +++---- libavcodec/h264.h | 4 +- libavcodec/h264_cabac.c | 2 +- libavcodec/intrax8.c | 2 +- libavcodec/mpeg12.c | 8 ++-- libavcodec/mpeg4videodec.c | 8 ++-- libavcodec/mpegvideo.h | 13 +++-- libavcodec/rv10.c | 2 +- libavcodec/rv34.c | 4 +- libavcodec/vc1dec.c | 18 +++---- 12 files changed, 92 insertions(+), 93 deletions(-) diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index caa1a47ebf..5c5fc44606 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -167,14 +167,14 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, i error= s->error_status_table[mb_index]; if(IS_INTER(s->current_picture.f.mb_type[mb_index])) continue; //inter - if(!(error&DC_ERROR)) continue; //dc-ok + if(!(error&ER_DC_ERROR)) continue; //dc-ok /* right block */ for(j=b_x+1; j>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); - if(intra_j==0 || !(error_j&DC_ERROR)){ + if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color[0]= dc[j + b_y*stride]; distance[0]= j-b_x; break; @@ -186,7 +186,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, i int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); - if(intra_j==0 || !(error_j&DC_ERROR)){ + if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color[1]= dc[j + b_y*stride]; distance[1]= b_x-j; break; @@ -198,7 +198,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, i int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); - if(intra_j==0 || !(error_j&DC_ERROR)){ + if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color[2]= dc[b_x + j*stride]; distance[2]= j-b_y; break; @@ -210,7 +210,7 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, i int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride; int error_j= s->error_status_table[mb_index_j]; int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); - if(intra_j==0 || !(error_j&DC_ERROR)){ + if(intra_j==0 || !(error_j&ER_DC_ERROR)){ color[3]= dc[b_x + j*stride]; distance[3]= b_y-j; break; @@ -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&(DC_ERROR|AC_ERROR|MV_ERROR); - int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR); + 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 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&(DC_ERROR|AC_ERROR|MV_ERROR); - int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR); + 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 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]; @@ -377,7 +377,7 @@ static void guess_mv(MpegEncContext *s){ int error= s->error_status_table[mb_xy]; if(IS_INTRA(s->current_picture.f.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check - if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV + if(!(error&ER_MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV fixed[mb_xy]= f; if(f==MV_FROZEN) @@ -390,7 +390,7 @@ static void guess_mv(MpegEncContext *s){ const int mb_xy= mb_x + mb_y*s->mb_stride; if(IS_INTRA(s->current_picture.f.mb_type[mb_xy])) continue; - if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue; + if(!(s->error_status_table[mb_xy]&ER_MV_ERROR)) continue; s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD : MV_DIR_BACKWARD; s->mb_intra=0; @@ -646,7 +646,7 @@ static int is_intra_more_likely(MpegEncContext *s){ for(i=0; imb_num; i++){ const int mb_xy= s->mb_index2xy[i]; const int error= s->error_status_table[mb_xy]; - if(!((error&DC_ERROR) && (error&MV_ERROR))) + if(!((error&ER_DC_ERROR) && (error&ER_MV_ERROR))) undamaged_count++; } @@ -672,7 +672,7 @@ static int is_intra_more_likely(MpegEncContext *s){ const int mb_xy= mb_x + mb_y*s->mb_stride; error= s->error_status_table[mb_xy]; - if((error&DC_ERROR) && (error&MV_ERROR)) + if((error&ER_DC_ERROR) && (error&ER_MV_ERROR)) continue; //skip damaged j++; @@ -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, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t)); + 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)); s->error_count= 3*s->mb_num; s->error_occurred = 0; } @@ -713,7 +713,7 @@ void ff_er_frame_start(MpegEncContext *s){ /** * Add a slice. * @param endx x component of the last macroblock, can be -1 for the last of the previous line - * @param status the status at the end (MV_END, AC_ERROR, ...), it is assumed that no earlier end or + * @param status the status at the end (ER_MV_END, ER_AC_ERROR, ...), it is assumed that no earlier end or * error of the same type occurred */ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){ @@ -734,20 +734,20 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en if(!s->err_recognition) return; mask &= ~VP_START; - if(status & (AC_ERROR|AC_END)){ - mask &= ~(AC_ERROR|AC_END); + if(status & (ER_AC_ERROR|ER_AC_END)){ + mask &= ~(ER_AC_ERROR|ER_AC_END); s->error_count -= end_i - start_i + 1; } - if(status & (DC_ERROR|DC_END)){ - mask &= ~(DC_ERROR|DC_END); + if(status & (ER_DC_ERROR|ER_DC_END)){ + mask &= ~(ER_DC_ERROR|ER_DC_END); s->error_count -= end_i - start_i + 1; } - if(status & (MV_ERROR|MV_END)){ - mask &= ~(MV_ERROR|MV_END); + if(status & (ER_MV_ERROR|ER_MV_END)){ + mask &= ~(ER_MV_ERROR|ER_MV_END); s->error_count -= end_i - start_i + 1; } - if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) { + if(status & (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)) { s->error_occurred = 1; s->error_count= INT_MAX; } @@ -774,7 +774,7 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ]; prev_status &= ~ VP_START; - if(prev_status != (MV_END|DC_END|AC_END)) s->error_count= INT_MAX; + if(prev_status != (ER_MV_END|ER_DC_END|ER_AC_END)) s->error_count= INT_MAX; } } @@ -845,13 +845,13 @@ void ff_er_frame_end(MpegEncContext *s){ const int mb_xy= s->mb_index2xy[i]; int error= s->error_status_table[mb_xy]; - if(error&AC_END) + if(error&ER_AC_END) end_ok=0; - if((error&MV_END) || (error&DC_END) || (error&AC_ERROR)) + if((error&ER_MV_END) || (error&ER_DC_END) || (error&ER_AC_ERROR)) end_ok=1; if(!end_ok) - s->error_status_table[mb_xy]|= AC_ERROR; + s->error_status_table[mb_xy]|= ER_AC_ERROR; if(error&VP_START) end_ok=0; @@ -870,14 +870,14 @@ void ff_er_frame_end(MpegEncContext *s){ if(error1&VP_START) end_ok=1; - if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END) - && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END) - && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninit + 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) + && ((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]|= DC_ERROR|AC_ERROR|MV_ERROR; + s->error_status_table[mb_xy]|= ER_DC_ERROR|ER_AC_ERROR|ER_MV_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& (DC_ERROR|AC_ERROR|MV_ERROR); + error= old_error& (ER_DC_ERROR|ER_AC_ERROR|ER_MV_ERROR); else{ - error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR); + error|= old_error& (ER_DC_ERROR|ER_AC_ERROR|ER_MV_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&(AC_ERROR|DC_ERROR|MV_ERROR)) - error|= AC_ERROR|DC_ERROR|MV_ERROR; + if(error&(ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)) + error|= ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR; s->error_status_table[mb_xy]= error; } } @@ -935,9 +935,9 @@ 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&DC_ERROR) dc_error ++; - if(error&AC_ERROR) ac_error ++; - if(error&MV_ERROR) mv_error ++; + if(error&ER_DC_ERROR) dc_error ++; + if(error&ER_AC_ERROR) ac_error ++; + if(error&ER_MV_ERROR) mv_error ++; } av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\n", dc_error, ac_error, mv_error); @@ -947,7 +947,7 @@ 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&DC_ERROR) && (error&MV_ERROR))) + if(!((error&ER_DC_ERROR) && (error&ER_MV_ERROR))) continue; if(is_intra_likely) @@ -973,8 +973,8 @@ void ff_er_frame_end(MpegEncContext *s){ error= s->error_status_table[mb_xy]; if(IS_INTRA(mb_type)) continue; //intra - if(error&MV_ERROR) continue; //inter with damaged MV - if(!(error&AC_ERROR)) continue; //undamaged inter + if(error&ER_MV_ERROR) continue; //inter with damaged MV + if(!(error&ER_AC_ERROR)) continue; //undamaged inter s->mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD; s->mb_intra=0; @@ -1011,8 +1011,8 @@ void ff_er_frame_end(MpegEncContext *s){ error= s->error_status_table[mb_xy]; if(IS_INTRA(mb_type)) continue; - if(!(error&MV_ERROR)) continue; //inter with undamaged MV - if(!(error&AC_ERROR)) continue; //undamaged inter + if(!(error&ER_MV_ERROR)) continue; //inter with undamaged MV + if(!(error&ER_AC_ERROR)) continue; //undamaged inter s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD; if(!s->last_picture.f.data[0]) s->mv_dir &= ~MV_DIR_FORWARD; @@ -1066,7 +1066,7 @@ void ff_er_frame_end(MpegEncContext *s){ error= s->error_status_table[mb_xy]; if(IS_INTRA(mb_type) && s->partitioned_frame) continue; -// if(error&MV_ERROR) continue; //inter data damaged FIXME is this good? +// if(error&ER_MV_ERROR) continue; //inter data damaged FIXME is this good? dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize; dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize; @@ -1115,7 +1115,7 @@ void ff_er_frame_end(MpegEncContext *s){ error= s->error_status_table[mb_xy]; if(IS_INTER(mb_type)) continue; - if(!(error&AC_ERROR)) continue; //undamaged + if(!(error&ER_AC_ERROR)) continue; //undamaged dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize; dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize; @@ -1143,7 +1143,7 @@ ec_clean: const int mb_xy= s->mb_index2xy[i]; int error= s->error_status_table[mb_xy]; - if(s->pict_type!=AV_PICTURE_TYPE_B && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){ + if(s->pict_type!=AV_PICTURE_TYPE_B && (error&(ER_DC_ERROR|ER_MV_ERROR|ER_AC_ERROR))){ s->mbskip_table[mb_xy]=0; } s->mbintra_table[mb_xy]=1; diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 268f69401a..06986fff6f 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -148,7 +148,7 @@ static int get_consumed_bytes(MpegEncContext *s, int buf_size){ } static int decode_slice(MpegEncContext *s){ - const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F; + const int part_mask= s->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F; const int mb_size= 16>>s->avctx->lowres; s->last_resync_gb= s->gb; s->first_slice_line= 1; @@ -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, AC_END|DC_END|MV_END); + 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); 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, (AC_END|DC_END|MV_END)&part_mask); + 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); 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, (AC_END|DC_END|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_AC_END|ER_DC_END|ER_MV_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, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); + 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); 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, AC_END|DC_END|MV_END); + 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); 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, (AC_END|DC_END|MV_END)&part_mask); + 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); 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]= AC_ERROR|DC_ERROR|MV_ERROR; + s->error_status_table[s->mb_num-1]= ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR; } assert(s->bitstream_buffer_size==0); diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 0d01caa2fd..03850285c7 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -3556,7 +3556,7 @@ static void decode_finish_row(H264Context *h){ static int decode_slice(struct AVCodecContext *avctx, void *arg){ H264Context *h = *(void**)arg; MpegEncContext * const s = &h->s; - const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F; + const int part_mask= s->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F; int lf_x_start = s->mb_x; s->mb_skip_run= -1; @@ -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, (AC_END|DC_END|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_AC_END|ER_DC_END|ER_MV_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, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); + 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); 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, (AC_END|DC_END|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_AC_END|ER_DC_END|ER_MV_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, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); + 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); 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, (AC_END|DC_END|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_AC_END|ER_DC_END|ER_MV_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, (AC_END|DC_END|MV_END)&part_mask); + 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); 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, (AC_END|DC_END|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_AC_END|ER_DC_END|ER_MV_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, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); + 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); return -1; } diff --git a/libavcodec/h264.h b/libavcodec/h264.h index 826b72018c..50255389fa 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -668,13 +668,13 @@ av_cold void ff_h264_decode_init_vlc(void); /** * Decode a macroblock - * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed + * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed */ int ff_h264_decode_mb_cavlc(H264Context *h); /** * Decode a CABAC coded macroblock - * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed + * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed */ int ff_h264_decode_mb_cabac(H264Context *h); diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index c7e46e935f..bb0a0ee732 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -1863,7 +1863,7 @@ static av_always_inline void decode_cabac_luma_residual( H264Context *h, const u /** * Decode a macroblock. - * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed + * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed */ int ff_h264_decode_mb_cabac(H264Context *h) { MpegEncContext * const s = &h->s; diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c index 6b869b7aa5..7dbc242087 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, - (AC_END|DC_END|MV_END) ); + (ER_AC_END|ER_DC_END|ER_MV_END) ); return 0; } diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 4358562389..48860cf33a 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1866,9 +1866,9 @@ static int slice_decode_thread(AVCodecContext *c, void *arg) if (c->err_recognition & AV_EF_EXPLODE) return ret; if (s->resync_mb_x >= 0 && s->resync_mb_y >= 0) - 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); + 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); } else { - 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); + 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); } if (s->mb_y == s->end_mb_y) @@ -2450,9 +2450,9 @@ static int decode_chunks(AVCodecContext *avctx, if (avctx->err_recognition & AV_EF_EXPLODE) return ret; if (s2->resync_mb_x >= 0 && s2->resync_mb_y >= 0) - ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR | DC_ERROR | MV_ERROR); + ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR); } else { - ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END | DC_END | MV_END); + ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, ER_AC_END | ER_DC_END | ER_MV_END); } } } diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index 51985483b6..f5835f3f4d 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -790,8 +790,8 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){ int ff_mpeg4_decode_partitions(MpegEncContext *s) { int mb_num; - const int part_a_error= s->pict_type==AV_PICTURE_TYPE_I ? (DC_ERROR|MV_ERROR) : MV_ERROR; - const int part_a_end = s->pict_type==AV_PICTURE_TYPE_I ? (DC_END |MV_END) : MV_END; + const int part_a_error= s->pict_type==AV_PICTURE_TYPE_I ? (ER_DC_ERROR|ER_MV_ERROR) : ER_MV_ERROR; + const int part_a_end = s->pict_type==AV_PICTURE_TYPE_I ? (ER_DC_END |ER_MV_END) : ER_MV_END; mb_num= mpeg4_decode_partition_a(s); if(mb_num<0){ @@ -826,11 +826,11 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) if( mpeg4_decode_partition_b(s, mb_num) < 0){ if(s->pict_type==AV_PICTURE_TYPE_P) - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, DC_ERROR); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_DC_ERROR); return -1; }else{ if(s->pict_type==AV_PICTURE_TYPE_P) - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, DC_END); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_DC_END); } return 0; diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index d0d1dc7748..704535d073 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -474,13 +474,12 @@ typedef struct MpegEncContext { int error_count, error_occurred; uint8_t *error_status_table; ///< table of the error status of each MB #define VP_START 1 ///< current MB is the first after a resync marker -#define AC_ERROR 2 -#define DC_ERROR 4 -#define MV_ERROR 8 -#define AC_END 16 -#define DC_END 32 -#define MV_END 64 -//FIXME some prefix? +#define ER_AC_ERROR 2 +#define ER_DC_ERROR 4 +#define ER_MV_ERROR 8 +#define ER_AC_END 16 +#define ER_DC_END 32 +#define ER_MV_END 64 int resync_mb_x; ///< x position of last resync marker int resync_mb_y; ///< y position of last resync marker diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 3ba8102b50..8d8d2d5829 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, AC_END|DC_END|MV_END); + 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); return s->gb.size_in_bits; } diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 7023ec1223..b22398ac51 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, AC_ERROR|DC_ERROR|MV_ERROR); + 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); 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, AC_END|DC_END|MV_END); + 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); return s->mb_y == s->mb_height; } diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 0340dc202d..d28a8b7375 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, (AC_END|DC_END|MV_END)); + ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (ER_AC_END|ER_DC_END|ER_MV_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, (AC_END|DC_END|MV_END)); + ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (ER_AC_END|ER_DC_END|ER_MV_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, (AC_END|DC_END|MV_END)); + 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)); 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, (AC_END|DC_END|MV_END)); + (s->end_mb_y << v->field_mode) - 1, (ER_AC_END|ER_DC_END|ER_MV_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, (AC_END|DC_END|MV_END)); + 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)); 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, (AC_END|DC_END|MV_END)); + (s->end_mb_y << v->field_mode) - 1, (ER_AC_END|ER_DC_END|ER_MV_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, (AC_END|DC_END|MV_END)); + 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)); 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, (AC_END|DC_END|MV_END)); + (s->end_mb_y << v->field_mode) - 1, (ER_AC_END|ER_DC_END|ER_MV_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, (AC_END|DC_END|MV_END)); + 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)); 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; From 63ccd466873b0863d466f5846a305eb908fe3b80 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 28 Nov 2011 00:31:52 +0100 Subject: [PATCH 06/10] 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; From 4f3667ba59750bf7e4c0954394c7c9e164e01c69 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 28 Nov 2011 00:31:53 +0100 Subject: [PATCH 07/10] vc1: mark with ER_MB_ERROR bits overconsumption This patch is a generalization of what Michael Niedermayer fixed in a single case. The wmv8-drm fate test had been updated accordingly. Signed-off-by: Luca Barbato --- libavcodec/vc1dec.c | 8 ++++---- tests/ref/fate/wmv8-drm | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index fd67feb116..3f84df2d6c 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_MB_END); + ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); return; @@ -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_MB_END); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); return; @@ -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_MB_END); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR); 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; @@ -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_MB_END); + ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR); 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; diff --git a/tests/ref/fate/wmv8-drm b/tests/ref/fate/wmv8-drm index 57e9aebfc6..e18309b16a 100644 --- a/tests/ref/fate/wmv8-drm +++ b/tests/ref/fate/wmv8-drm @@ -127,4 +127,4 @@ 0, 472500, 84480, 0x13962590 0, 476250, 84480, 0xde79482f 0, 480000, 84480, 0x7d1ca064 -0, 483750, 84480, 0x7e1de54e +0, 483750, 84480, 0x2676a064 From d32eed5c73744c25625a9fb66c48e57f2d0b433d Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sun, 4 Dec 2011 15:56:41 +0100 Subject: [PATCH 08/10] yadif: support 10bit YUV Signed-off-by: Luca Barbato --- libavfilter/vf_yadif.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index 64b25616ea..ca2adb2906 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -145,7 +145,7 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic, int w = dstpic->video->w; int h = dstpic->video->h; int refs = yadif->cur->linesize[i]; - int df = (yadif->csp->comp[i].depth_minus1+1) / 8; + int df = (yadif->csp->comp[i].depth_minus1 + 8) / 8; if (i == 1 || i == 2) { /* Why is this not part of the per-plane description thing? */ @@ -212,7 +212,7 @@ static void return_frame(AVFilterContext *ctx, int is_second) if (!yadif->csp) yadif->csp = &av_pix_fmt_descriptors[link->format]; - if (yadif->csp->comp[0].depth_minus1 == 15) + if (yadif->csp->comp[0].depth_minus1 / 8 == 1) yadif->filter_line = filter_line_c_16bit; filter(ctx, yadif->out, tff ^ !is_second, tff); @@ -354,6 +354,9 @@ static int query_formats(AVFilterContext *ctx) AV_NE( PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE ), PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, + AV_NE( PIX_FMT_YUV420P10BE, PIX_FMT_YUV420P10LE ), + AV_NE( PIX_FMT_YUV422P10BE, PIX_FMT_YUV422P10LE ), + AV_NE( PIX_FMT_YUV444P10BE, PIX_FMT_YUV444P10LE ), AV_NE( PIX_FMT_YUV420P16BE, PIX_FMT_YUV420P16LE ), AV_NE( PIX_FMT_YUV422P16BE, PIX_FMT_YUV422P16LE ), AV_NE( PIX_FMT_YUV444P16BE, PIX_FMT_YUV444P16LE ), From 4badb386cee42569e2e1a1c6981a33c065ebf2de Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 12 Dec 2011 18:22:22 +0100 Subject: [PATCH 09/10] lavf: dealloc private options in av_write_trailer Fix the iformat/oformat typo. --- libavformat/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index a078d9c88b..f42428563d 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3261,7 +3261,7 @@ fail: av_freep(&s->streams[i]->priv_data); av_freep(&s->streams[i]->index_entries); } - if (s->iformat && s->iformat->priv_class) + if (s->oformat->priv_class) av_opt_free(s->priv_data); av_freep(&s->priv_data); return ret; From a99273ebf328658c183c2d267f1c2b8bfac58bb3 Mon Sep 17 00:00:00 2001 From: Gaurav Narula Date: Tue, 13 Dec 2011 23:11:37 +0530 Subject: [PATCH 10/10] ulti: Fix invalid reads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/ulti.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/libavcodec/ulti.c b/libavcodec/ulti.c index a2802f73a9..52092b5309 100644 --- a/libavcodec/ulti.c +++ b/libavcodec/ulti.c @@ -40,6 +40,14 @@ typedef struct UltimotionDecodeContext { const uint8_t *ulti_codebook; } UltimotionDecodeContext; +#define CHECK_OVERREAD_SIZE(size) \ + do { \ + if (buf_end - buf < (size)) { \ + av_log(avctx, AV_LOG_ERROR, "Insufficient data\n"); \ + return AVERROR_INVALIDDATA; \ + } \ + } while(0) + static av_cold int ulti_decode_init(AVCodecContext *avctx) { UltimotionDecodeContext *s = avctx->priv_data; @@ -223,6 +231,7 @@ static int ulti_decode_frame(AVCodecContext *avctx, int i; int skip; int tmp; + const uint8_t *buf_end = buf + buf_size; s->frame.reference = 1; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; @@ -236,10 +245,12 @@ static int ulti_decode_frame(AVCodecContext *avctx, if(blocks >= s->blocks || y >= s->height) break;//all blocks decoded + CHECK_OVERREAD_SIZE(1); idx = *buf++; if((idx & 0xF8) == 0x70) { switch(idx) { case 0x70: //change modifier + CHECK_OVERREAD_SIZE(1); modifier = *buf++; if(modifier>1) av_log(avctx, AV_LOG_INFO, "warning: modifier must be 0 or 1, got %i\n", modifier); @@ -254,6 +265,7 @@ static int ulti_decode_frame(AVCodecContext *avctx, done = 1; break; case 0x74: //skip some blocks + CHECK_OVERREAD_SIZE(1); skip = *buf++; if ((blocks + skip) >= s->blocks) break; @@ -280,19 +292,24 @@ static int ulti_decode_frame(AVCodecContext *avctx, chroma = 0; } else { cf = 0; - if (idx) + if (idx) { + CHECK_OVERREAD_SIZE(1); chroma = *buf++; + } } for (i = 0; i < 4; i++) { // for every subblock code = (idx >> (6 - i*2)) & 3; //extract 2 bits if(!code) //skip subblock continue; - if(cf) + if(cf) { + CHECK_OVERREAD_SIZE(1); chroma = *buf++; + } tx = x + block_coords[i * 2]; ty = y + block_coords[(i * 2) + 1]; switch(code) { case 1: + CHECK_OVERREAD_SIZE(1); tmp = *buf++; angle = angle_by_index[(tmp >> 6) & 0x3]; @@ -313,6 +330,7 @@ static int ulti_decode_frame(AVCodecContext *avctx, case 2: if (modifier) { // unpack four luma samples + CHECK_OVERREAD_SIZE(3); tmp = bytestream_get_be24(&buf); Y[0] = (tmp >> 18) & 0x3F; @@ -321,6 +339,7 @@ static int ulti_decode_frame(AVCodecContext *avctx, Y[3] = tmp & 0x3F; angle = 16; } else { // retrieve luma samples from codebook + CHECK_OVERREAD_SIZE(2); tmp = bytestream_get_be16(&buf); angle = (tmp >> 12) & 0xF; @@ -337,6 +356,8 @@ static int ulti_decode_frame(AVCodecContext *avctx, if (modifier) { // all 16 luma samples uint8_t Luma[16]; + CHECK_OVERREAD_SIZE(12); + tmp = bytestream_get_be24(&buf); Luma[0] = (tmp >> 18) & 0x3F; Luma[1] = (tmp >> 12) & 0x3F; @@ -363,6 +384,7 @@ static int ulti_decode_frame(AVCodecContext *avctx, ulti_convert_yuv(&s->frame, tx, ty, Luma, chroma); } else { + CHECK_OVERREAD_SIZE(4); tmp = *buf++; if(tmp & 0x80) { angle = (tmp >> 4) & 0x7;