- if (!q->available && !ctx->inputs[i]->status_out)
- return 0;
- if (q->available) {
- frame = ff_bufqueue_peek(q, 0);
- if (frame->pts < pts_min) {
- pts_min = frame->pts;
- queue_idx = i;
+ nb_eofs += is_eof;
+ if (i == 0)
+ first_eof = is_eof;
+ }
+
+ if ((nb_eofs > 0 && s->duration_mode == DURATION_SHORTEST) ||
+ (nb_eofs == ctx->nb_inputs && s->duration_mode == DURATION_LONGEST) ||
+ (first_eof && s->duration_mode == DURATION_FIRST)) {
+ ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
+ return 0;
+ }
+
+ for (i = 0; i < ctx->nb_inputs; i++) {
+ if (!ff_inlink_queued_frames(ctx->inputs[i]))
+ continue;
+ nb_inputs_with_frames++;
+ }
+
+ if (nb_inputs_with_frames >= ctx->nb_inputs - nb_eofs) {
+ for (i = 0; i < ctx->nb_inputs; i++) {
+ AVFrame *frame;
+
+ if (ff_inlink_queued_frames(ctx->inputs[i]) == 0)
+ continue;
+
+ frame = ff_inlink_peek_frame(ctx->inputs[i], 0);
+ if (frame->pts == AV_NOPTS_VALUE) {
+ int ret;
+
+ av_log(ctx, AV_LOG_WARNING,
+ "NOPTS value for input frame cannot be accepted, frame discarded\n");
+ ret = ff_inlink_consume_frame(ctx->inputs[i], &frame);
+ if (ret < 0)
+ return ret;
+ av_frame_free(&frame);
+ return AVERROR_INVALIDDATA;
+ }
+
+ q_pts = av_rescale_q(frame->pts, ctx->inputs[i]->time_base, AV_TIME_BASE_Q);
+ if (q_pts < pts) {
+ pts = q_pts;
+ input_idx = i;