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