---
 libavcodec/h264.c | 10 +++++++++-
 libavcodec/h264.h |  2 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index f7915a2..36d0e42 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1174,6 +1174,7 @@ static int decode_update_thread_context(AVCodecContext 
*dst,
             av_log(h->s.avctx, AV_LOG_ERROR, "h264_slice_header_init() 
failed");
             return err;
         }
+        h->context_reinitialized = 1;
 
         /* update linesize on resize for h264. The h264 decoder doesn't
          * necessarily call ff_MPV_frame_start in the new thread */
@@ -2730,6 +2731,7 @@ static int decode_slice_header(H264Context *h, 
H264Context *h0)
                    "h264_slice_header_init() failed\n");
             return ret;
         }
+        h->context_reinitialized = 1;
     }
     if (!s->context_initialized) {
         if (h != h0) {
@@ -4057,8 +4059,13 @@ again:
                 context_count = 0;
             }
 
-            if (err < 0)
+            if (err < 0) {
                 av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header 
error\n");
+                if (h->context_reinitialized) {
+                    buf_index = err;
+                    goto end;
+                }
+            }
             else if (err == 1) {
                 /* Slice could not be decoded in parallel mode, copy down
                  * NAL unit stuff to context 0 and restart. Note that
@@ -4165,6 +4172,7 @@ out:
             decode_postinit(h, 1);
 
         field_end(h, 0);
+        h->context_reinitialized = 0;
 
         if (!h->next_output_pic) {
             /* Wait for second field. */
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 3c99030..e4d4ea1 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -447,6 +447,8 @@ typedef struct H264Context {
     int nal_length_size;  ///< Number of bytes used for nal length (1, 2 or 4)
     int got_first;        ///< this flag is != 0 if we've parsed a frame
 
+    int context_reinitialized;
+
     SPS *sps_buffers[MAX_SPS_COUNT];
     PPS *pps_buffers[MAX_PPS_COUNT];
 
-- 
1.7.12.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to