diff mbox series

[FFmpeg-devel,02/24] lavfi/af_amix: make sure the output does not depend on input ordering

Message ID 20231104092125.10213-3-anton@khirnov.net
State Accepted
Commit 7282137f48c3e71734a2aa55c51b3096a1a63b5f
Headers show
Series [FFmpeg-devel,01/24] lavf/mux: do not apply max_interleave_delta to subtitles | expand

Commit Message

Anton Khirnov Nov. 4, 2023, 7:56 a.m. UTC
From: Paul B Mahol <onemda@gmail.com>

Signed-off-by: Anton Khirnov <anton@khirnov.net>
---
 libavfilter/af_amix.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index aa42514106..120a97f48c 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -394,6 +394,8 @@  static int request_samples(AVFilterContext *ctx, int min_samples)
     int i;
 
     av_assert0(s->nb_inputs > 1);
+    if (min_samples == 1 && s->duration_mode == DURATION_FIRST)
+        min_samples = av_audio_fifo_size(s->fifos[0]);
 
     for (i = 1; i < s->nb_inputs; i++) {
         if (!(s->input_state[i] & INPUT_ON) ||
@@ -402,6 +404,7 @@  static int request_samples(AVFilterContext *ctx, int min_samples)
         if (av_audio_fifo_size(s->fifos[i]) >= min_samples)
             continue;
         ff_inlink_request_frame(ctx->inputs[i]);
+        return 0;
     }
     return output_frame(ctx->outputs[0]);
 }
@@ -471,17 +474,13 @@  static int activate(AVFilterContext *ctx)
 
         if (ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts)) {
             if (status == AVERROR_EOF) {
-                if (i == 0) {
-                    s->input_state[i] = 0;
+                s->input_state[i] |= INPUT_EOF;
+                if (av_audio_fifo_size(s->fifos[i]) == 0) {
+                    s->input_state[i] &= ~INPUT_ON;
                     if (s->nb_inputs == 1) {
                         ff_outlink_set_status(outlink, status, pts);
                         return 0;
                     }
-                } else {
-                    s->input_state[i] |= INPUT_EOF;
-                    if (av_audio_fifo_size(s->fifos[i]) == 0) {
-                        s->input_state[i] = 0;
-                    }
                 }
             }
         }