diff options
author | Tanu Kaskinen <tanu.kaskinen@linux.intel.com> | 2013-11-25 14:34:58 +0200 |
---|---|---|
committer | Tanu Kaskinen <tanu.kaskinen@linux.intel.com> | 2014-01-08 21:26:39 +0200 |
commit | 85a3f560d1089ad595cde6181a88cb1e72423e49 (patch) | |
tree | 400b3b2580bd696e41fc658554ed8debad4f2196 | |
parent | eae16f41a4d75ab4d35ddf5045b2fd7c83430754 (diff) |
core-format: Add pa_format_info_get_rate()
This also fixes an issue in pa_format_info_to_sample_spec(): it did
no validation for the rate value. Now the validation is taken care of
in pa_format_info_get_rate().
-rw-r--r-- | src/pulse/format.c | 5 | ||||
-rw-r--r-- | src/pulsecore/core-format.c | 21 | ||||
-rw-r--r-- | src/pulsecore/core-format.h | 5 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/pulse/format.c b/src/pulse/format.c index 0b87560e..1b4a1549 100644 --- a/src/pulse/format.c +++ b/src/pulse/format.c @@ -219,7 +219,7 @@ pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_m /* For PCM streams */ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) { char *m = NULL; - int rate, channels; + int channels; int ret = -PA_ERR_INVALID; pa_assert(f); @@ -230,12 +230,11 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan if (pa_format_info_get_sample_format(f, &ss->format) < 0) goto out; - if (pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate)) + if (pa_format_info_get_rate(f, &ss->rate) < 0) goto out; if (pa_format_info_get_prop_int(f, PA_PROP_FORMAT_CHANNELS, &channels)) goto out; - ss->rate = (uint32_t) rate; ss->channels = (uint8_t) channels; if (map) { diff --git a/src/pulsecore/core-format.c b/src/pulsecore/core-format.c index cb65e9e0..43ad4683 100644 --- a/src/pulsecore/core-format.c +++ b/src/pulsecore/core-format.c @@ -53,6 +53,27 @@ int pa_format_info_get_sample_format(pa_format_info *f, pa_sample_format_t *sf) return 0; } +int pa_format_info_get_rate(pa_format_info *f, uint32_t *rate) { + int r; + int rate_local; + + pa_assert(f); + pa_assert(rate); + + r = pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate_local); + if (r < 0) + return r; + + if (!pa_sample_rate_valid(rate_local)) { + pa_log_debug("Invalid sample rate: %i", rate_local); + return -PA_ERR_INVALID; + } + + *rate = rate_local; + + return 0; +} + int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) { int rate; diff --git a/src/pulsecore/core-format.h b/src/pulsecore/core-format.h index 82997305..7e5d9829 100644 --- a/src/pulsecore/core-format.h +++ b/src/pulsecore/core-format.h @@ -27,6 +27,11 @@ * -PA_ERR_NOENTITY. */ int pa_format_info_get_sample_format(pa_format_info *f, pa_sample_format_t *sf); +/* Gets the sample rate stored in the format info. Returns a negative error + * code on failure. If the sample rate property is not set at all, returns + * -PA_ERR_NOENTITY. */ +int pa_format_info_get_rate(pa_format_info *f, uint32_t *rate); + /* For compressed formats. Converts the format info into a sample spec and a * channel map that an ALSA device can use as its configuration parameters when * playing back the compressed data. That is, the returned sample spec doesn't |