- ret = ff_request_frame(ctx->inputs[0]);
-
- /* flush the fifo */
- if (ret == AVERROR_EOF && av_fifo_size(s->fifo)) {
- int i;
- for (i = 0; av_fifo_size(s->fifo); i++) {
- AVFrame *buf;
-
- av_fifo_generic_read(s->fifo, &buf, sizeof(buf), NULL);
- if (av_fifo_size(s->fifo)) {
- buf->pts = av_rescale_q(s->first_pts, ctx->inputs[0]->time_base,
- outlink->time_base) + s->frames_out;
-
- if ((ret = ff_filter_frame(outlink, buf)) < 0)
- return ret;
-
- s->frames_out++;
- } else {
- /* This is the last frame, we may have to duplicate it to match
- * the last frame duration */
- int j;
- int eof_rounding = (s->eof_action == EOF_ACTION_PASS) ? AV_ROUND_UP : s->rounding;
- int delta = av_rescale_q_rnd(ctx->inputs[0]->current_pts - s->first_pts,
- ctx->inputs[0]->time_base,
- outlink->time_base, eof_rounding) - s->frames_out;
- av_log(ctx, AV_LOG_DEBUG, "EOF frames_out:%d delta:%d\n", s->frames_out, delta);
- /* if the delta is equal to 1, it means we just need to output
- * the last frame. Greater than 1 means we will need duplicate
- * delta-1 frames */
- if (delta > 0 ) {
- for (j = 0; j < delta; j++) {
- AVFrame *dup = av_frame_clone(buf);
-
- av_log(ctx, AV_LOG_DEBUG, "Duplicating frame.\n");
- dup->pts = av_rescale_q(s->first_pts, ctx->inputs[0]->time_base,
- outlink->time_base) + s->frames_out;
-
- if ((ret = ff_filter_frame(outlink, dup)) < 0)
- return ret;
-
- s->frames_out++;
- if (j > 0) s->dup++;
- }
- av_frame_free(&buf);
- } else {
- /* for delta less or equal to 0, we should drop the frame,
- * otherwise, we will have one or more extra frames */
- av_frame_free(&buf);
- s->drop++;
- }
- }
- }
- return 0;
- }