Use early return to avoid additional indentation

This commit is contained in:
Romain Vimont 2024-02-02 15:02:09 +01:00
parent 8fe2e294f8
commit 16f3246bcf

View file

@ -253,8 +253,11 @@ sc_audio_player_frame_sink_push(struct sc_frame_sink *sink,
}
atomic_store_explicit(&ap->received, true, memory_order_relaxed);
if (!played) {
// Nothing more to do
return true;
}
if (played) {
// Number of samples added (or removed, if negative) for compensation
int32_t instant_compensation = (int32_t) written - frame->nb_samples;
// Inserting silence instantly increases buffering
@ -263,8 +266,7 @@ sc_audio_player_frame_sink_push(struct sc_frame_sink *sink,
int32_t dropped = (int32_t) skipped_samples;
// The compensation must apply instantly, it must not be smoothed
ap->avg_buffering.avg +=
instant_compensation + inserted_silence - dropped;
ap->avg_buffering.avg += instant_compensation + inserted_silence - dropped;
// However, the buffering level must be smoothed
sc_average_push(&ap->avg_buffering, can_read);
@ -292,12 +294,12 @@ sc_audio_player_frame_sink_push(struct sc_frame_sink *sink,
// Do not compensate for small values, the error is just noise
diff = 0;
} else if (diff < 0 && can_read < ap->target_buffering) {
// Do not accelerate if the instant buffering level is below
// the target, this would increase underflow
// Do not accelerate if the instant buffering level is below the
// target, this would increase underflow
diff = 0;
}
// Compensate the diff over 4 seconds (but will be recomputed after
// 1 second)
// Compensate the diff over 4 seconds (but will be recomputed after 1
// second)
int distance = 4 * ap->sample_rate;
// Limit compensation rate to 2%
int abs_max_diff = distance / 50;
@ -315,7 +317,6 @@ sc_audio_player_frame_sink_push(struct sc_frame_sink *sink,
}
}
}
}
return true;
}