{"body":"diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c\nindex 41118383b2..dfb8c54668 100644\n--- a/libavcodec/h264dec.c\n+++ b/libavcodec/h264dec.c\n@@ -605,7 +605,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)\n {\n     AVCodecContext *const avctx = h->avctx;\n     int nals_needed = 0; ///< number of NALs that need decoding before the next frame thread starts\n-    int idr_cleared=0;\n+    int slice_run = 0;\n     int i, ret = 0;\n \n     h->has_slice = 0;\n@@ -660,19 +660,23 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)\n                 ret = -1;\n                 goto end;\n             }\n-            if(!idr_cleared) {\n-                if (h->current_slice && (avctx->active_thread_type & FF_THREAD_SLICE)) {\n-                    av_log(h, AV_LOG_ERROR, \"invalid mixed IDR / non IDR frames cannot be decoded in slice multithreading mode\\n\");\n-                    ret = AVERROR_INVALIDDATA;\n-                    goto end;\n-                }\n-                idr(h); // FIXME ensure we don't lose some frames if there is reordering\n+            if (slice_run >= 0)\n+                slice_run++;\n+            if (slice_run < 0) {\n+                av_log(h, AV_LOG_ERROR, \"invalid mixed IDR / non IDR slices between PPS, missing PPS?\\n\");\n             }\n-            idr_cleared = 1;\n+\n+            idr(h); // FIXME ensure we don't lose some frames if there is reordering\n             h->has_recovery_point = 1;\n         case H264_NAL_SLICE:\n             h->has_slice = 1;\n \n+            if (slice_run <= 0)\n+                slice_run--;\n+            if (slice_run > 0) {\n+                av_log(h, AV_LOG_ERROR, \"invalid mixed IDR / non IDR slices between PPS, missing PPS?\\n\");\n+            }\n+\n             if ((err = ff_h264_queue_decode_slice(h, nal))) {\n                 H264SliceContext *sl = h->slice_ctx + h->nb_slice_ctx_queued;\n                 sl->ref_count[0] = sl->ref_count[1] = 0;\n@@ -750,6 +754,7 @@ FF_ENABLE_DEPRECATION_WARNINGS\n             break;\n         }\n         case H264_NAL_PPS:\n+            slice_run = 0;\n             ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps,\n                                                        nal->size_bits);\n             if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n","name":"slice.diff","extension":"diff","url":"https://www.irccloud.com/pastebin/3PlPoAG8/slice.diff","modified":1536061481,"id":"3PlPoAG8","size":2328,"lines":53,"own_paste":false,"theme":"","date":1536061481}