alfilter_graph_request_oldest() might return EAGAIN and produce a frame on not the oldest sink. Fixes ticket #11597. Fixes excessive frame buffering in #10959. Fixes excessive frame buffering in #11366.
Unified · Split
| @@ -2669,6 +2669,22 @@ static int read_frames(FilterGraph *fg, FilterGraphThread *fgt, · 2668 unmodified lines | ||
| 2669 | 2669 | while (fgp->nb_outputs_done < fg->nb_outputs) { |
| 2670 | 2670 | int ret; |
| 2671 | 2671 | |
| 2672 | + /* Reap all buffers present in the buffer sinks */ | |
| 2673 | + for (int i = 0; i < fg->nb_outputs; i++) { | |
| 2674 | + OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[i]); | |
| 2675 | + | |
| 2676 | + ret = 0; | |
| 2677 | + while (!ret) { | |
| 2678 | + ret = fg_output_step(ofp, fgt, frame); | |
| 2679 | + if (ret < 0) | |
| 2680 | + return ret; | |
| 2681 | + } | |
| 2682 | + } | |
| 2683 | + | |
| 2684 | + // return after one iteration, so that scheduler can rate-control us | |
| 2685 | + if (did_step && fgp->have_sources) | |
| 2686 | + return 0; | |
| 2687 | + | |
| 2672 | 2688 | ret = avfilter_graph_request_oldest(fgt->graph); |
| 2673 | 2689 | if (ret == AVERROR(EAGAIN)) { |
| 2674 | 2690 | fgt->next_in = choose_input(fg, fgt); |
| @@ -2684,21 +2700,6 @@ static int read_frames(FilterGraph *fg, FilterGraphThread *fgt, · 9 unmodified lines | ||
| 2684 | 2700 | } |
| 2685 | 2701 | fgt->next_in = fg->nb_inputs; |
| 2686 | 2702 | |
| 2687 | − // return after one iteration, so that scheduler can rate-control us | |
| 2688 | − if (did_step && fgp->have_sources) | |
| 2689 | − return 0; | |
| 2690 | − | |
| 2691 | − /* Reap all buffers present in the buffer sinks */ | |
| 2692 | − for (int i = 0; i < fg->nb_outputs; i++) { | |
| 2693 | − OutputFilterPriv *ofp = ofp_from_ofilter(fg->outputs[i]); | |
| 2694 | − | |
| 2695 | − ret = 0; | |
| 2696 | − while (!ret) { | |
| 2697 | − ret = fg_output_step(ofp, fgt, frame); | |
| 2698 | − if (ret < 0) | |
| 2699 | − return ret; | |
| 2700 | − } | |
| 2701 | − } | |
| 2702 | 2703 | did_step = 1; |
| 2703 | 2704 | } |
| 2704 | 2705 | |