diff options
author | wm4 <nfxjfg@googlemail.com> | 2015-09-08 19:42:22 +0200 |
---|---|---|
committer | Luca Barbato <lu_zero@gentoo.org> | 2015-09-12 12:25:23 +0200 |
commit | b84675d63aaede8f6944b901250a10456c5477e6 (patch) | |
tree | 8084ecf23f56142a064ef8876eff66e04b6f6ea9 | |
parent | 5788623d29c3e806a7879210986110aced758dc2 (diff) | |
download | ffmpeg-b84675d63aaede8f6944b901250a10456c5477e6.tar.gz |
mmaldec: hack against buffering problems on broken input
I can't come up with a nice way to handle this. It's hard to keep the
lock-stepped input/output in this case. You can't predict whether the
MMAL decoder will output a picture (because it's asynchronous), so
you have to assume in general that any packet could produce 0 or 1
frames. You can't continue to write input packets to the decoder,
because then you might get too many output frames, which you can't
get rid of because the lavc decoding API does not allow the decoder
to return an output frame without consuming an input frame (except
when flushing).
The ideal fix is a M:N decoding API (preferably asynchronous), which
would make this code potentially much cleaner. For now, this hack
will do.
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
-rw-r--r-- | libavcodec/mmaldec.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c index 64e5da6324..374bd2f30c 100644 --- a/libavcodec/mmaldec.c +++ b/libavcodec/mmaldec.c @@ -644,12 +644,21 @@ static int ffmmal_read_frame(AVCodecContext *avctx, AVFrame *frame, int *got_fra // We also wait if we sent eos, but didn't receive it yet (think of decoding // stream with a very low number of frames). if (ctx->frames_output || ctx->packets_sent > MAX_DELAYED_FRAMES || ctx->eos_sent) { - buffer = mmal_queue_wait(ctx->queue_decoded_frames); + // MMAL will ignore broken input packets, which means the frame we + // expect here may never arrive. Dealing with this correctly is + // complicated, so here's a hack to avoid that it freezes forever + // in this unlikely situation. + buffer = mmal_queue_timedwait(ctx->queue_decoded_frames, 100); + if (!buffer) { + av_log(avctx, AV_LOG_ERROR, "Did not get output frame from MMAL.\n"); + ret = AVERROR_UNKNOWN; + goto done; + } } else { buffer = mmal_queue_get(ctx->queue_decoded_frames); + if (!buffer) + goto done; } - if (!buffer) - goto done; ctx->eos_received |= !!(buffer->flags & MMAL_BUFFER_HEADER_FLAG_EOS); if (ctx->eos_received) |