From eae16f41a4d75ab4d35ddf5045b2fd7c83430754 Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Mon, 25 Nov 2013 16:15:54 +0200 Subject: [PATCH] core-format: Add pa_format_info_get_sample_format() --- src/pulse/format.c | 9 ++------- src/pulsecore/core-format.c | 26 ++++++++++++++++++++++++++ src/pulsecore/core-format.h | 5 +++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/pulse/format.c b/src/pulse/format.c index 9c7e13e0..0b87560e 100644 --- a/src/pulse/format.c +++ b/src/pulse/format.c @@ -218,7 +218,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 *sf = NULL, *m = NULL; + char *m = NULL; int rate, channels; int ret = -PA_ERR_INVALID; @@ -228,16 +228,13 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan if (!pa_format_info_is_pcm(f)) return pa_format_info_to_sample_spec_fake(f, ss, map); - if (pa_format_info_get_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, &sf)) + 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)) goto out; if (pa_format_info_get_prop_int(f, PA_PROP_FORMAT_CHANNELS, &channels)) goto out; - if ((ss->format = pa_parse_sample_format(sf)) == PA_SAMPLE_INVALID) - goto out; - ss->rate = (uint32_t) rate; ss->channels = (uint8_t) channels; @@ -252,8 +249,6 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan ret = 0; out: - if (sf) - pa_xfree(sf); if (m) pa_xfree(m); diff --git a/src/pulsecore/core-format.c b/src/pulsecore/core-format.c index 6e7c1fb5..cb65e9e0 100644 --- a/src/pulsecore/core-format.c +++ b/src/pulsecore/core-format.c @@ -24,9 +24,35 @@ #include "core-format.h" #include +#include #include +int pa_format_info_get_sample_format(pa_format_info *f, pa_sample_format_t *sf) { + int r; + char *sf_str; + pa_sample_format_t sf_local; + + pa_assert(f); + pa_assert(sf); + + r = pa_format_info_get_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, &sf_str); + if (r < 0) + return r; + + sf_local = pa_parse_sample_format(sf_str); + pa_xfree(sf_str); + + if (!pa_sample_format_valid(sf_local)) { + pa_log_debug("Invalid sample format."); + return -PA_ERR_INVALID; + } + + *sf = sf_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 ef2c8dc5..82997305 100644 --- a/src/pulsecore/core-format.h +++ b/src/pulsecore/core-format.h @@ -22,6 +22,11 @@ #include +/* Gets the sample format stored in the format info. Returns a negative error + * code on failure. If the sample format property is not set at all, returns + * -PA_ERR_NOENTITY. */ +int pa_format_info_get_sample_format(pa_format_info *f, pa_sample_format_t *sf); + /* 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 -- 2.39.2