[PATCH 3/7] format: Expose pa_format_info<->pa_sample_spec conversion functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



These utility functions could be handy to clients.
pa_format_info_to_sample_spec_fake() isn't made public, but the return
value is changed to keep in sync with pa_format_info_to_sample_spec().
---
 src/pulse/format.c            |   14 +++++++-------
 src/pulse/format.h            |    7 +++++++
 src/pulse/internal.h          |    4 +---
 src/pulsecore/sink-input.c    |    4 ++--
 src/pulsecore/source-output.c |    4 ++--
 5 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/pulse/format.c b/src/pulse/format.c
index 4de6e89..6e8e707 100644
--- a/src/pulse/format.c
+++ b/src/pulse/format.c
@@ -219,10 +219,10 @@ pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_m
 }
 
 /* For PCM streams */
-pa_bool_t pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
+int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
     char *sf = NULL, *m = NULL;
     int rate, channels;
-    pa_bool_t ret = FALSE;
+    int ret = -PA_ERR_INVALID;
 
     pa_assert(f);
     pa_assert(ss);
@@ -249,7 +249,7 @@ pa_bool_t pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, p
                 goto out;
     }
 
-    ret = TRUE;
+    ret = 0;
 
 out:
     if (sf)
@@ -261,23 +261,23 @@ out:
 }
 
 /* For compressed streams */
-pa_bool_t pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss) {
+int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss) {
     int rate;
 
     pa_assert(f);
     pa_assert(ss);
-    pa_return_val_if_fail(f->encoding != PA_ENCODING_PCM, FALSE);
+    pa_return_val_if_fail(f->encoding != PA_ENCODING_PCM, -PA_ERR_INVALID);
 
     ss->format = PA_SAMPLE_S16LE;
     ss->channels = 2;
 
-    pa_return_val_if_fail(pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate) == 0, FALSE);
+    pa_return_val_if_fail(pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate) == 0, -PA_ERR_INVALID);
     ss->rate = (uint32_t) rate;
 
     if (f->encoding == PA_ENCODING_EAC3_IEC61937)
         ss->rate *= 4;
 
-    return TRUE;
+    return 0;
 }
 
 void pa_format_info_set_sample_format(pa_format_info *f, pa_sample_format_t sf) {
diff --git a/src/pulse/format.h b/src/pulse/format.h
index 2e19e70..fd5727b 100644
--- a/src/pulse/format.h
+++ b/src/pulse/format.h
@@ -115,6 +115,13 @@ char *pa_format_info_snprint(char *s, size_t l, const pa_format_info *f);
  * \a pa_format_info_snprint() into a pa_format_info structure. \since 1.0 */
 pa_format_info* pa_format_info_from_string(const char *str);
 
+/** Utility function to take a \a pa_sample_spec and generate the corresponding \a pa_format_info. \since 2.0 */
+pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_map *map);
+
+/** Utility function to generate a \a pa_sample_spec and \a pa_channel_map corresponding to a given \a pa_format_info. Returns
+ * a negative integer if conversion failed and 0 on success. \since 2.0 */
+int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map);
+
 /** Gets an integer property from the given format info. Returns 0 on success and a negative integer on failure. \since 2.0 */
 int pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v);
 /** Gets a string property from the given format info.  The caller must free the returned string using \ref pa_xfree. Returns
diff --git a/src/pulse/internal.h b/src/pulse/internal.h
index 7ab98b8..e826454 100644
--- a/src/pulse/internal.h
+++ b/src/pulse/internal.h
@@ -304,9 +304,7 @@ void pa_ext_device_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t)
 void pa_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
 
 void pa_format_info_free2(pa_format_info *f, void *userdata);
-pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_map *map);
-pa_bool_t pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map);
-pa_bool_t pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss);
+int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss);
 
 pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m);
 
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 93caa8f..7162c19 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -293,12 +293,12 @@ int pa_sink_input_new(
     /* Now populate the sample spec and format according to the final
      * format that we've negotiated */
     if (PA_LIKELY(data->format->encoding == PA_ENCODING_PCM)) {
-        pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map), -PA_ERR_INVALID);
+        pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map) == 0, -PA_ERR_INVALID);
         pa_sink_input_new_data_set_sample_spec(data, &ss);
         if (pa_channel_map_valid(&map))
             pa_sink_input_new_data_set_channel_map(data, &map);
     } else {
-        pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss), -PA_ERR_INVALID);
+        pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss) == 0, -PA_ERR_INVALID);
         pa_sink_input_new_data_set_sample_spec(data, &ss);
     }
 
diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index 8a35ab0..52fc7f7 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -273,12 +273,12 @@ int pa_source_output_new(
     /* Now populate the sample spec and format according to the final
      * format that we've negotiated */
     if (PA_LIKELY(data->format->encoding == PA_ENCODING_PCM)) {
-        pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map), -PA_ERR_INVALID);
+        pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map) == 0, -PA_ERR_INVALID);
         pa_source_output_new_data_set_sample_spec(data, &ss);
         if (pa_channel_map_valid(&map))
             pa_source_output_new_data_set_channel_map(data, &map);
     } else {
-        pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss), -PA_ERR_INVALID);
+        pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss) == 0, -PA_ERR_INVALID);
         pa_source_output_new_data_set_sample_spec(data, &ss);
     }
 
-- 
1.7.8.4



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux