From f6f7d1504134683c435e2c7d804279d982e52bb4 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 3 Oct 2012 16:25:14 -0700 Subject: h264: don't touch H264Context->ref_count[] during MB decoding The variable is copied to subsequent threads at the same time, so this may cause wrong ref_count[] values to be copied to subsequent threads. This bug was found using TSAN. Signed-off-by: Luca Barbato --- libavcodec/h264_cavlc.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'libavcodec/h264_cavlc.c') diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index c4159e241c..8996057c31 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -784,11 +784,6 @@ decode_intra_mb: return 0; } - if(MB_MBAFF){ - h->ref_count[0] <<= 1; - h->ref_count[1] <<= 1; - } - fill_decode_neighbors(h, mb_type); fill_decode_caches(h, mb_type); @@ -868,7 +863,7 @@ decode_intra_mb: } for(list=0; listlist_count; list++){ - int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; + int ref_count = IS_REF0(mb_type) ? 1 : h->ref_count[list] << MB_MBAFF; for(i=0; i<4; i++){ if(IS_DIRECT(h->sub_mb_type[i])) continue; if(IS_DIR(h->sub_mb_type[i], 0, list)){ @@ -948,13 +943,14 @@ decode_intra_mb: for(list=0; listlist_count; list++){ unsigned int val; if(IS_DIR(mb_type, 0, list)){ - if(h->ref_count[list]==1){ + int rc = h->ref_count[list] << MB_MBAFF; + if (rc == 1) { val= 0; - }else if(h->ref_count[list]==2){ + } else if (rc == 2) { val= get_bits1(&s->gb)^1; }else{ val= get_ue_golomb_31(&s->gb); - if(val >= h->ref_count[list]){ + if (val >= rc) { av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } @@ -978,13 +974,14 @@ decode_intra_mb: for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ - if(h->ref_count[list] == 1){ + int rc = h->ref_count[list] << MB_MBAFF; + if (rc == 1) { val= 0; - }else if(h->ref_count[list] == 2){ + } else if (rc == 2) { val= get_bits1(&s->gb)^1; }else{ val= get_ue_golomb_31(&s->gb); - if(val >= h->ref_count[list]){ + if (val >= rc) { av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } @@ -1015,13 +1012,14 @@ decode_intra_mb: for(i=0; i<2; i++){ unsigned int val; if(IS_DIR(mb_type, i, list)){ //FIXME optimize - if(h->ref_count[list]==1){ + int rc = h->ref_count[list] << MB_MBAFF; + if (rc == 1) { val= 0; - }else if(h->ref_count[list]==2){ + } else if (rc == 2) { val= get_bits1(&s->gb)^1; }else{ val= get_ue_golomb_31(&s->gb); - if(val >= h->ref_count[list]){ + if (val >= rc) { av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } @@ -1180,10 +1178,5 @@ decode_intra_mb: s->current_picture.f.qscale_table[mb_xy] = s->qscale; write_back_non_zero_count(h); - if(MB_MBAFF){ - h->ref_count[0] >>= 1; - h->ref_count[1] >>= 1; - } - return 0; } -- cgit v1.2.3