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

@ -263,7 +263,7 @@ static int ucm_get_device_property(
/* get rate */
if ((value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_PLAYBACK_RATE)) ||
(value = pa_proplist_gets(verb->proplist, PA_ALSA_PROP_UCM_PLAYBACK_RATE))) {
if (pa_atou(value, &ui) == 0 && ui > 0 && ui < PA_RATE_MAX) {
if (pa_atou(value, &ui) == 0 && pa_sample_rate_valid(ui)) {
pa_log_debug("UCM playback device %s rate %d", device_name, ui);
device->playback_rate = ui;
} else
@ -284,7 +284,7 @@ static int ucm_get_device_property(
/* get rate */
if ((value = pa_proplist_gets(device->proplist, PA_ALSA_PROP_UCM_CAPTURE_RATE)) ||
(value = pa_proplist_gets(verb->proplist, PA_ALSA_PROP_UCM_CAPTURE_RATE))) {
if (pa_atou(value, &ui) == 0 && ui > 0 && ui < PA_RATE_MAX) {
if (pa_atou(value, &ui) == 0 && pa_sample_rate_valid(ui)) {
pa_log_debug("UCM capture device %s rate %d", device_name, ui);
device->capture_rate = ui;
} else