[pulseaudio-discuss] [PATCH] format: Expose pa_format_info convenience getters in API
Arun Raghavan
arun at arunraghavan.net
Sat May 26 03:28:26 UTC 2018
We move over helper functions to get rate, channels, channel map and
sample format (if PCM) in the public API, so users of the extended API
are more easily able to pull out these values from pa_format_info.
---
src/map-file | 4 ++
src/pulse/format.c | 89 +++++++++++++++++++++++++++++++++++++
src/pulse/format.h | 16 +++++++
src/pulsecore/core-format.c | 89 -------------------------------------
src/pulsecore/core-format.h | 20 ---------
5 files changed, 109 insertions(+), 109 deletions(-)
diff --git a/src/map-file b/src/map-file
index 902ce2fd9..aaa1a424f 100644
--- a/src/map-file
+++ b/src/map-file
@@ -177,12 +177,16 @@ pa_format_info_copy;
pa_format_info_free;
pa_format_info_from_string;
pa_format_info_from_sample_spec;
+pa_format_info_get_channel_map;
+pa_format_info_get_channels;
pa_format_info_get_prop_type;
pa_format_info_get_prop_int;
pa_format_info_get_prop_int_range;
pa_format_info_get_prop_int_array;
pa_format_info_get_prop_string;
pa_format_info_get_prop_string_array;
+pa_format_info_get_rate;
+pa_format_info_get_sample_format;
pa_format_info_free_string_array;
pa_format_info_is_compatible;
pa_format_info_is_pcm;
diff --git a/src/pulse/format.c b/src/pulse/format.c
index 07b4420e7..2e90821b9 100644
--- a/src/pulse/format.c
+++ b/src/pulse/format.c
@@ -515,6 +515,95 @@ void pa_format_info_free_string_array(char **values, int n_values) {
pa_xfree(values);
}
+int pa_format_info_get_sample_format(const 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_get_rate(const 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_get_channels(const 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_get_channel_map(const pa_format_info *f, pa_channel_map *map) {
+ int r;
+ char *map_str;
+
+ pa_assert(f);
+ pa_assert(map);
+
+ r = pa_format_info_get_prop_string(f, PA_PROP_FORMAT_CHANNEL_MAP, &map_str);
+ if (r < 0)
+ return r;
+
+ map = pa_channel_map_parse(map, map_str);
+ pa_xfree(map_str);
+
+ if (!map) {
+ pa_log_debug("Failed to parse channel map.");
+ return -PA_ERR_INVALID;
+ }
+
+ return 0;
+}
+
void pa_format_info_set_sample_format(pa_format_info *f, pa_sample_format_t sf) {
pa_format_info_set_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, pa_sample_format_to_string(sf));
}
diff --git a/src/pulse/format.h b/src/pulse/format.h
index 584032fb6..812454b9c 100644
--- a/src/pulse/format.h
+++ b/src/pulse/format.h
@@ -213,6 +213,22 @@ int pa_format_info_get_prop_string_array(const pa_format_info *f, const char *ke
/** Frees a string array returned by \ref pa_format_info_get_prop_string_array. \since 2.0 */
void pa_format_info_free_string_array(char **values, int n_values);
+/** 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 a negative integer. \since 13.0 */
+int pa_format_info_get_sample_format(const 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 a negative integer. \since 13.0 */
+int pa_format_info_get_rate(const 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 a negative integer. \since 13.0 */
+int pa_format_info_get_channels(const pa_format_info *f, uint8_t *channels);
+
+/** Gets the channel map stored in the format info. Returns a negative error code on failure. If the channel map property is not
+ * set at all, returns a negative integer. \since 13.0 */
+int pa_format_info_get_channel_map(const pa_format_info *f, pa_channel_map *map);
+
/** Sets an integer property on the given format info. \since 1.0 */
void pa_format_info_set_prop_int(pa_format_info *f, const char *key, int value);
/** Sets a property with a list of integer values on the given format info. \since 1.0 */
diff --git a/src/pulsecore/core-format.c b/src/pulsecore/core-format.c
index 096acc3a2..403fb2a32 100644
--- a/src/pulsecore/core-format.c
+++ b/src/pulsecore/core-format.c
@@ -26,95 +26,6 @@
#include <pulsecore/macro.h>
-int pa_format_info_get_sample_format(const 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_get_rate(const 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_get_channels(const 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_get_channel_map(const pa_format_info *f, pa_channel_map *map) {
- int r;
- char *map_str;
-
- pa_assert(f);
- pa_assert(map);
-
- r = pa_format_info_get_prop_string(f, PA_PROP_FORMAT_CHANNEL_MAP, &map_str);
- if (r < 0)
- return r;
-
- map = pa_channel_map_parse(map, map_str);
- pa_xfree(map_str);
-
- if (!map) {
- pa_log_debug("Failed to parse channel map.");
- return -PA_ERR_INVALID;
- }
-
- return 0;
-}
-
pa_format_info *pa_format_info_from_sample_spec2(const pa_sample_spec *ss, const pa_channel_map *map, bool set_format,
bool set_rate, bool set_channels) {
pa_format_info *format = NULL;
diff --git a/src/pulsecore/core-format.h b/src/pulsecore/core-format.h
index 37503041b..e2e02fe75 100644
--- a/src/pulsecore/core-format.h
+++ b/src/pulsecore/core-format.h
@@ -22,26 +22,6 @@
#include <stdbool.h>
-/* 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(const 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(const 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(const pa_format_info *f, uint8_t *channels);
-
-/* Gets the channel map stored in the format info. Returns a negative error
- * code on failure. If the channel map property is not set at all, returns
- * -PA_ERR_NOENTITY. */
-int pa_format_info_get_channel_map(const pa_format_info *f, pa_channel_map *map);
-
/* Convert a sample spec and an optional channel map to a new PCM format info
* object (remember to free it). If map is NULL, then the channel map will be
* left unspecified. If some fields of the sample spec should be ignored, pass
--
2.17.0
More information about the pulseaudio-discuss
mailing list