diff mbox series

[FFmpeg-devel] avfilter/af_amix: fix amix decreased sound output

Message ID 20240612101016.2023960-1-hiccupzhu@gmail.com
State New
Headers show
Series [FFmpeg-devel] avfilter/af_amix: fix amix decreased sound output | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Shiqi Zhu June 12, 2024, 10:10 a.m. UTC
fix he issue of decreased sound output when one or more input of the amix settings is set to EOF.

Signed-off-by: Shiqi Zhu <hiccupzhu@gmail.com>
---
 libavfilter/af_amix.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index ade4ef76a8..3ff85650a7 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -216,11 +216,11 @@  static void calculate_scales(MixContext *s, int nb_samples)
     int i;
 
     for (i = 0; i < s->nb_inputs; i++)
-        if (s->input_state[i] & INPUT_ON)
+        if ((s->input_state[i] & INPUT_ON) && av_audio_fifo_size(s->fifos[i]) > 0)
             weight_sum += FFABS(s->weights[i]);
 
     for (i = 0; i < s->nb_inputs; i++) {
-        if (s->input_state[i] & INPUT_ON) {
+        if ((s->input_state[i] & INPUT_ON) && av_audio_fifo_size(s->fifos[i]) > 0) {
             if (s->scale_norm[i] > weight_sum / FFABS(s->weights[i])) {
                 s->scale_norm[i] -= ((s->weight_sum / FFABS(s->weights[i])) / s->nb_inputs) *
                                     nb_samples / (s->dropout_transition * s->sample_rate);
@@ -230,7 +230,7 @@  static void calculate_scales(MixContext *s, int nb_samples)
     }
 
     for (i = 0; i < s->nb_inputs; i++) {
-        if (s->input_state[i] & INPUT_ON) {
+        if ((s->input_state[i] & INPUT_ON) && av_audio_fifo_size(s->fifos[i]) > 0) {
             if (!s->normalize)
                 s->input_scale[i] = FFABS(s->weights[i]);
             else