- if (ctx->frames_output || ctx->packets_sent > MAX_DELAYED_FRAMES || ctx->eos_sent) {
- buffer = mmal_queue_wait(ctx->queue_decoded_frames);
+ if (ctx->frames_output || ctx->packets_sent > MAX_DELAYED_FRAMES ||
+ (ctx->packets_sent && ctx->eos_sent)) {
+ // 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;
+ }