summaryrefslogtreecommitdiff
path: root/src/pulsecore
diff options
context:
space:
mode:
authorTanu Kaskinen <tanu.kaskinen@linux.intel.com>2013-12-04 09:50:10 +0200
committerPeter Meerwald <pmeerw@pmeerw.net>2013-12-15 11:21:56 +0100
commita67318f8affc4973507811946708bc17e63f1ec7 (patch)
tree197125b1e11f01d42d6cb8e3654b17149b5bce03 /src/pulsecore
parent1cda71725240bd4911f0f34c5d384b3966f06369 (diff)
downloadpulseaudio-a67318f8affc4973507811946708bc17e63f1ec7.tar.gz
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.
Diffstat (limited to 'src/pulsecore')
-rw-r--r--src/pulsecore/modargs.c6
-rw-r--r--src/pulsecore/protocol-native.c2
-rw-r--r--src/pulsecore/resampler.c4
-rw-r--r--src/pulsecore/sink.c3
-rw-r--r--src/pulsecore/source.c3
5 files changed, 7 insertions, 11 deletions
diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c
index 51e55018d..a02a3e7a6 100644
--- a/src/pulsecore/modargs.c
+++ b/src/pulsecore/modargs.c
@@ -371,8 +371,7 @@ int pa_modargs_get_sample_rate(pa_modargs *ma, uint32_t *rate) {
rate_local = *rate;
if ((pa_modargs_get_value_u32(ma, "rate", &rate_local)) < 0 ||
- rate_local <= 0 ||
- rate_local > PA_RATE_MAX)
+ !pa_sample_rate_valid(rate_local))
return -1;
*rate = rate_local;
@@ -417,8 +416,7 @@ int pa_modargs_get_alternate_sample_rate(pa_modargs *ma, uint32_t *alternate_rat
rate_local = *alternate_rate;
if ((pa_modargs_get_value_u32(ma, "alternate_rate", &rate_local)) < 0 ||
- rate_local <= 0 ||
- rate_local > PA_RATE_MAX)
+ !pa_sample_rate_valid(*alternate_rate))
return -1;
if (!((rate_local % 4000 == 0) || (rate_local % 11025 == 0)))
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index c1ff04acd..662de9802 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -4112,7 +4112,7 @@ static void command_update_stream_sample_rate(pa_pdispatch *pd, uint32_t command
}
CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
- CHECK_VALIDITY(c->pstream, rate > 0 && rate <= PA_RATE_MAX, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, pa_sample_rate_valid(rate), tag, PA_ERR_INVALID);
if (command == PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE) {
playback_stream *s;
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 6dfee1c02..f0c663fb6 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -202,8 +202,8 @@ static pa_resample_method_t pa_resampler_fix_method(
const uint32_t rate_a,
const uint32_t rate_b) {
- pa_assert(rate_a > 0 && rate_a <= PA_RATE_MAX);
- pa_assert(rate_b > 0 && rate_b <= PA_RATE_MAX);
+ pa_assert(pa_sample_rate_valid(rate_a));
+ pa_assert(pa_sample_rate_valid(rate_b));
pa_assert(method >= 0);
pa_assert(method < PA_RESAMPLER_MAX);
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 95cf9b677..672a884fd 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -1420,8 +1420,7 @@ int pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough) {
}
}
- if (PA_UNLIKELY (desired_rate < 8000 ||
- desired_rate > PA_RATE_MAX))
+ if (PA_UNLIKELY(!pa_sample_rate_valid(desired_rate)))
return -1;
if (!passthrough) {
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index a6dc9bfe9..6073b1d9f 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -1009,8 +1009,7 @@ int pa_source_update_rate(pa_source *s, uint32_t rate, bool passthrough) {
}
}
- if (PA_UNLIKELY (desired_rate < 8000 ||
- desired_rate > PA_RATE_MAX))
+ if (PA_UNLIKELY(!pa_sample_rate_valid(desired_rate)))
return -1;
if (!passthrough) {