diff mbox

[FFmpeg-devel] hevc: fix race condition in max_ra/seq_decode.

Message ID 1495640100-36856-1-git-send-email-rsbultje@gmail.com
State Accepted
Commit ca2209d67af0a73fe0edb2fce1cea2445dbfd8db
Headers show

Commit Message

Ronald S. Bultje May 24, 2017, 3:35 p.m. UTC
These variables are shared between frame threads, but they are updated
post-setup_finished() if a EOB/EOS slice type occurs. Moving the EOB/EOS
slices to the next frame thread instance (by parsing them leading into
the next picture instead of trailing behind the last picture) effectively
prevents this race condition.

Tthis fixes tsan failures on hevc-conformance-NoOutPrior_A_Qualcomm_1.
---
 libavcodec/hevc_parser.c |  2 +-
 libavcodec/hevcdec.c     | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c
index c72b146..2b58eb6 100644
--- a/libavcodec/hevc_parser.c
+++ b/libavcodec/hevc_parser.c
@@ -267,7 +267,7 @@  static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf,
 
         nut = (pc->state64 >> 2 * 8 + 1) & 0x3F;
         // Beginning of access unit
-        if ((nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_AUD) || nut == HEVC_NAL_SEI_PREFIX ||
+        if ((nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_EOB_NUT) || nut == HEVC_NAL_SEI_PREFIX ||
             (nut >= 41 && nut <= 44) || (nut >= 48 && nut <= 55)) {
             if (pc->frame_start_found) {
                 pc->frame_start_found = 0;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index ee001fd..fc9a5b7 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2890,6 +2890,7 @@  fail:
 static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
 {
     int i, ret = 0;
+    int eos_at_start = 1;
 
     s->ref = NULL;
     s->last_eos = s->eos;
@@ -2907,8 +2908,15 @@  static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
 
     for (i = 0; i < s->pkt.nb_nals; i++) {
         if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT ||
-            s->pkt.nals[i].type == HEVC_NAL_EOS_NUT)
-            s->eos = 1;
+            s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) {
+            if (eos_at_start) {
+                s->last_eos = 1;
+            } else {
+                s->eos = 1;
+            }
+        } else {
+            eos_at_start = 0;
+        }
     }
 
     /* decode the NAL units */