summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanu Kaskinen <tanu.kaskinen@linux.intel.com>2013-11-25 14:51:37 +0200
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>2014-01-08 21:26:39 +0200
commit066dd942aa1855f1a05d1352b13dd540fa0c033f (patch)
treecda1f423aaa6d85193788f199db5578270de946f
parent85a3f560d1089ad595cde6181a88cb1e72423e49 (diff)
core-format: Add pa_format_info_get_channels()
This also fixes an issue in pa_format_info_to_sample_spec(): it did no validation for the channels value. Now the validation is taken care of in pa_format_info_get_channels().
-rw-r--r--src/pulse/format.c5
-rw-r--r--src/pulsecore/core-format.c21
-rw-r--r--src/pulsecore/core-format.h5
3 files changed, 27 insertions, 4 deletions
diff --git a/src/pulse/format.c b/src/pulse/format.c
index 1b4a1549..424df0e6 100644
--- a/src/pulse/format.c
+++ b/src/pulse/format.c
@@ -219,7 +219,6 @@ 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 channels;
int ret = -PA_ERR_INVALID;
pa_assert(f);
@@ -232,11 +231,9 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan
goto out;
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))
+ if (pa_format_info_get_channels(f, &ss->channels) < 0)
goto out;
- ss->channels = (uint8_t) channels;
-
if (map) {
pa_channel_map_init(map);
diff --git a/src/pulsecore/core-format.c b/src/pulsecore/core-format.c
index 43ad4683..c2457199 100644
--- a/src/pulsecore/core-format.c
+++ b/src/pulsecore/core-format.c
@@ -74,6 +74,27 @@ int pa_format_info_get_rate(pa_format_info *f, uint32_t *rate) {
return 0;
}
+int pa_format_info_get_channels(pa_format_info *f, uint8_t *channels) {
+ int r;
+ int channels_local;
+
+ pa_assert(f);
+ pa_assert(channels);
+
+ r = pa_format_info_get_prop_int(f, PA_PROP_FORMAT_CHANNELS, &channels_local);
+ if (r < 0)
+ return r;
+
+ if (!pa_channels_valid(channels_local)) {
+ pa_log_debug("Invalid channel count: %i", channels_local);
+ return -PA_ERR_INVALID;
+ }
+
+ *channels = channels_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 7e5d9829..06fb51f3 100644
--- a/src/pulsecore/core-format.h
+++ b/src/pulsecore/core-format.h
@@ -32,6 +32,11 @@ int pa_format_info_get_sample_format(pa_format_info *f, pa_sample_format_t *sf);
* -PA_ERR_NOENTITY. */
int pa_format_info_get_rate(pa_format_info *f, uint32_t *rate);
+/* Gets the channel count stored in the format info. Returns a negative error
+ * code on failure. If the channels property is not set at all, returns
+ * -PA_ERR_NOENTITY. */
+int pa_format_info_get_channels(pa_format_info *f, uint8_t *channels);
+
/* 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