[FFmpeg-devel] [PATCH] VP8 : Avoid race condition on segment map.

Aaron Colwell acolwell at chromium.org
Wed Mar 7 00:57:13 CET 2012


Hi,

This patch fixes a race condition that was detected by Chromium's TSAN
tool. This change avoids accessing the segment map of the previous frame if
segmentation is not enabled for the current frame. This is needed because
if you look at the caller of decode_mb_mode() you'll see that the
ff_thread_await_progress() call is skipped if segmentation is enabled. This
means that the current frame doesn't gate its progress on the progress of
the previous frame. This causes a race on the segment map if the current
frame's thread happens to progress farther in the frame than the previous
frame's thread.

Aaron

---
 libavcodec/vp8.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index dab26a6..9b12aa8 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -642,7 +642,7 @@ void decode_mb_mode(VP8Context *s, VP8Macroblock *mb,
int mb_x, int mb_y, uint8_
     if (s->segmentation.update_map) {
         int bit  = vp56_rac_get_prob(c, s->prob->segmentid[0]);
         *segment = vp56_rac_get_prob(c, s->prob->segmentid[1+bit]) + 2*bit;
-    } else
+    } else if (s->segmentation.enabled)
         *segment = ref ? *ref : *segment;
     s->segment = *segment;

-- 
1.7.7.3


More information about the ffmpeg-devel mailing list