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