summaryrefslogtreecommitdiff
path: root/libavcodec/decode.c
diff options
context:
space:
mode:
authorMuhammad Faiz <mfcc64@gmail.com>2017-04-28 17:19:13 +0700
committerMuhammad Faiz <mfcc64@gmail.com>2017-04-30 05:48:21 +0700
commitd535e0c14004a15bb38ea288fa9a4f2e27d26f6b (patch)
treeef4a714e4d1bdd2ec9839eb36a79e96290756ebf /libavcodec/decode.c
parent399c7ab9c6bc9e683c5a60b34d50290ae563e2f1 (diff)
avcodec/pthread_frame, decode: allow errors to happen on draining
So, all frames and errors are correctly reported in order. Also limit the numbers of error during draining to prevent infinite loop. This fix fate failure with THREADS>=4: make fate-h264-attachment-631 THREADS=4 This also reverts a755b725ec1d657609c8bd726ce37e7cf193d03f. Suggested-by: wm4, Ronald S. Bultje, Marton Balint Reviewed-by: w4 <nfxjfg@googlemail.com> Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
Diffstat (limited to 'libavcodec/decode.c')
-rw-r--r--libavcodec/decode.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6ff3c401ba..edfae5583c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -568,8 +568,24 @@ FF_ENABLE_DEPRECATION_WARNINGS
avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
#endif
- if (avctx->internal->draining && !got_frame)
- avci->draining_done = 1;
+ /* do not stop draining when got_frame != 0 or ret < 0 */
+ if (avctx->internal->draining && !got_frame) {
+ if (ret < 0) {
+ /* prevent infinite loop if a decoder wrongly always return error on draining */
+ /* reasonable nb_errors_max = maximum b frames + thread count */
+ int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
+ avctx->thread_count : 1);
+
+ if (avci->nb_draining_errors++ >= nb_errors_max) {
+ av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
+ "Stop draining and force EOF.\n");
+ avci->draining_done = 1;
+ ret = AVERROR_BUG;
+ }
+ } else {
+ avci->draining_done = 1;
+ }
+ }
avci->compat_decode_consumed += ret;
@@ -1659,6 +1675,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
{
avctx->internal->draining = 0;
avctx->internal->draining_done = 0;
+ avctx->internal->nb_draining_errors = 0;
av_frame_unref(avctx->internal->buffer_frame);
av_frame_unref(avctx->internal->compat_decode_frame);
av_packet_unref(avctx->internal->buffer_pkt);