Add pa_sample_rate_valid()

I think this makes the code a bit nicer to read and write. This also
reduces the chances of off-by-one errors when checking the bounds of
sample rate values.
This commit is contained in:
Tanu Kaskinen 2013-12-04 09:50:10 +02:00 committed by Peter Meerwald
parent 1cda717252
commit a67318f8af
12 changed files with 24 additions and 21 deletions

View file

@ -107,11 +107,14 @@ int pa_sample_format_valid(unsigned format) {
return format < PA_SAMPLE_MAX;
}
int pa_sample_rate_valid(uint32_t rate) {
return rate > 0 && rate <= PA_RATE_MAX;
}
int pa_sample_spec_valid(const pa_sample_spec *spec) {
pa_assert(spec);
if (PA_UNLIKELY (spec->rate <= 0 ||
spec->rate > PA_RATE_MAX ||
if (PA_UNLIKELY(!pa_sample_rate_valid(spec->rate) ||
spec->channels <= 0 ||
spec->channels > PA_CHANNELS_MAX ||
!pa_sample_format_valid(spec->format)))