mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-11 13:30:02 -05:00
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:
parent
1cda717252
commit
a67318f8af
12 changed files with 24 additions and 21 deletions
|
|
@ -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)))
|
||||
|
|
|
|||
|
|
@ -292,6 +292,9 @@ pa_sample_spec* pa_sample_spec_init(pa_sample_spec *spec);
|
|||
/** Return non-zero if the given integer is a valid sample format. \since 5.0 */
|
||||
int pa_sample_format_valid(unsigned format) PA_GCC_PURE;
|
||||
|
||||
/** Return non-zero if the rate is within the supported range. \since 5.0 */
|
||||
int pa_sample_rate_valid(uint32_t rate) PA_GCC_PURE;
|
||||
|
||||
/** Return non-zero when the sample type specification is valid */
|
||||
int pa_sample_spec_valid(const pa_sample_spec *spec) PA_GCC_PURE;
|
||||
|
||||
|
|
|
|||
|
|
@ -2785,7 +2785,7 @@ pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_strea
|
|||
pa_assert(PA_REFCNT_VALUE(s) >= 1);
|
||||
|
||||
PA_CHECK_VALIDITY_RETURN_NULL(s->context, !pa_detect_fork(), PA_ERR_FORKED);
|
||||
PA_CHECK_VALIDITY_RETURN_NULL(s->context, rate > 0 && rate <= PA_RATE_MAX, PA_ERR_INVALID);
|
||||
PA_CHECK_VALIDITY_RETURN_NULL(s->context, pa_sample_rate_valid(rate), PA_ERR_INVALID);
|
||||
PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->state == PA_STREAM_READY, PA_ERR_BADSTATE);
|
||||
PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->direction != PA_STREAM_UPLOAD, PA_ERR_BADSTATE);
|
||||
PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->flags & PA_STREAM_VARIABLE_RATE, PA_ERR_BADSTATE);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue