summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanu Kaskinen <tanu.kaskinen@linux.intel.com>2013-11-18 19:58:37 +0200
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>2014-01-08 21:26:39 +0200
commit30a32d35c8b91cafc004961828a7d0acbce74f1f (patch)
treec3bb5aff548abe0d263696b8cf65723dea048b2c
parentdfa3c507001d583574a04cf87ed1f0123553ddac (diff)
core-format: Add pa_format_info_to_sample_spec2()
The function will be used in pa_sink_input_new() and pa_source_output_new(). The fallback parameters are used to merge the data in the format info with the sink/source sample spec and channel map, when the format info is lacking some information.
-rw-r--r--src/pulsecore/core-format.c64
-rw-r--r--src/pulsecore/core-format.h12
2 files changed, 76 insertions, 0 deletions
diff --git a/src/pulsecore/core-format.c b/src/pulsecore/core-format.c
index 799b2dae..ce1cab3c 100644
--- a/src/pulsecore/core-format.c
+++ b/src/pulsecore/core-format.c
@@ -117,6 +117,70 @@ int pa_format_info_get_channel_map(pa_format_info *f, pa_channel_map *map) {
return 0;
}
+int pa_format_info_to_sample_spec2(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map, pa_sample_spec *fallback_ss,
+ pa_channel_map *fallback_map) {
+ int r, r2;
+ pa_sample_spec ss_local;
+ pa_channel_map map_local;
+
+ pa_assert(f);
+ pa_assert(ss);
+ pa_assert(map);
+ pa_assert(fallback_ss);
+ pa_assert(fallback_map);
+
+ if (!pa_format_info_is_pcm(f))
+ return pa_format_info_to_sample_spec_fake(f, ss, map);
+
+ r = pa_format_info_get_sample_format(f, &ss_local.format);
+ if (r == -PA_ERR_NOENTITY)
+ ss_local.format = fallback_ss->format;
+ else if (r < 0)
+ return r;
+
+ pa_assert(pa_sample_format_valid(ss_local.format));
+
+ r = pa_format_info_get_rate(f, &ss_local.rate);
+ if (r == -PA_ERR_NOENTITY)
+ ss_local.rate = fallback_ss->rate;
+ else if (r < 0)
+ return r;
+
+ pa_assert(pa_sample_rate_valid(ss_local.rate));
+
+ r = pa_format_info_get_channels(f, &ss_local.channels);
+ r2 = pa_format_info_get_channel_map(f, &map_local);
+ if (r == -PA_ERR_NOENTITY && r2 >= 0)
+ ss_local.channels = map_local.channels;
+ else if (r == -PA_ERR_NOENTITY)
+ ss_local.channels = fallback_ss->channels;
+ else if (r < 0)
+ return r;
+
+ pa_assert(pa_channels_valid(ss_local.channels));
+
+ if (r2 >= 0 && map_local.channels != ss_local.channels) {
+ pa_log_debug("Channel map is not compatible with the sample spec.");
+ return -PA_ERR_INVALID;
+ }
+
+ if (r2 == -PA_ERR_NOENTITY) {
+ if (fallback_map->channels == ss_local.channels)
+ map_local = *fallback_map;
+ else
+ pa_channel_map_init_extend(&map_local, ss_local.channels, PA_CHANNEL_MAP_DEFAULT);
+ } else if (r2 < 0)
+ return r2;
+
+ pa_assert(pa_channel_map_valid(&map_local));
+ pa_assert(ss_local.channels == map_local.channels);
+
+ *ss = ss_local;
+ *map = map_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 086cbed8..9342acc3 100644
--- a/src/pulsecore/core-format.h
+++ b/src/pulsecore/core-format.h
@@ -42,6 +42,18 @@ int pa_format_info_get_channels(pa_format_info *f, uint8_t *channels);
* -PA_ERR_NOENTITY. */
int pa_format_info_get_channel_map(pa_format_info *f, pa_channel_map *map);
+/* Convert the format info into a sample spec and a channel map. If the format
+ * info doesn't contain some information, the fallback sample spec and channel
+ * map are used to populate the output.
+ *
+ * pa_format_info_to_sample_spec() exists too. This "version 2" was created,
+ * because the original function doesn't provide the possibility of specifying
+ * a fallback sample spec and channel map. That functionality can't be added to
+ * the original function, because the function is part of the public API and
+ * adding parameters to it would break the API. */
+int pa_format_info_to_sample_spec2(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map, pa_sample_spec *fallback_ss,
+ pa_channel_map *fallback_map);
+
/* 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