summaryrefslogtreecommitdiffstats
path: root/src/pulse
diff options
context:
space:
mode:
authorArun Raghavan <arun.raghavan@collabora.co.uk>2011-03-08 20:15:36 +0530
committerArun Raghavan <arun.raghavan@collabora.co.uk>2011-05-02 11:55:38 +0530
commit8631f4e2c44b47db76795bebdbab54914a1f3ea0 (patch)
tree2f42ff9e46091f41b44864b1a4c512e75d6093ba /src/pulse
parenta3a004214404c6f91a82c1e2164444e5e08c26cf (diff)
format: Add some convenience functions for printing
Diffstat (limited to 'src/pulse')
-rw-r--r--src/pulse/format.c36
-rw-r--r--src/pulse/format.h13
2 files changed, 49 insertions, 0 deletions
diff --git a/src/pulse/format.c b/src/pulse/format.c
index 7ddfa7a1..0c5c24b1 100644
--- a/src/pulse/format.c
+++ b/src/pulse/format.c
@@ -27,12 +27,28 @@
#include <pulse/internal.h>
#include <pulse/xmalloc.h>
+#include <pulse/i18n.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include "format.h"
+const char *pa_encoding_to_string(pa_encoding_t e) {
+ static const char* const table[]= {
+ [PA_ENCODING_PCM] = "pcm",
+ [PA_ENCODING_AC3_IEC61937] = "ac3-iec61937",
+ [PA_ENCODING_EAC3_IEC61937] = "eac3-iec61937",
+ [PA_ENCODING_MPEG_IEC61937] = "mpeg-iec61937",
+ [PA_ENCODING_ANY] = "any",
+ };
+
+ if (e < 0 || e >= PA_ENCODING_MAX)
+ return NULL;
+
+ return table[e];
+}
+
pa_format_info* pa_format_info_new(void) {
pa_format_info *f = pa_xnew(pa_format_info, 1);
@@ -78,6 +94,26 @@ int pa_format_info_is_pcm(const pa_format_info *f) {
return f->encoding == PA_ENCODING_PCM;
}
+char *pa_format_info_snprint(char *s, size_t l, const pa_format_info *f) {
+ char *tmp;
+
+ pa_assert(s);
+ pa_assert(l > 0);
+ pa_assert(f);
+
+ pa_init_i18n();
+
+ if (!pa_format_info_valid(f))
+ pa_snprintf(s, l, _("(invalid)"));
+ else {
+ tmp = pa_proplist_to_string_sep(f->plist, ", ");
+ pa_snprintf(s, l, _("%s, %s"), pa_encoding_to_string(f->encoding), tmp[0] ? tmp : _("(no properties)"));
+ pa_xfree(tmp);
+ }
+
+ return s;
+}
+
pa_bool_t pa_format_info_is_compatible(pa_format_info *first, pa_format_info *second) {
const char *key;
void *state = NULL;
diff --git a/src/pulse/format.h b/src/pulse/format.h
index 03b34059..51c9426c 100644
--- a/src/pulse/format.h
+++ b/src/pulse/format.h
@@ -53,6 +53,9 @@ typedef enum pa_encoding {
/**< Represents an invalid encoding */
} pa_encoding_t;
+/** Returns a printable string representing the given encoding type. \since 1.0 */
+const char *pa_encoding_to_string(pa_encoding_t e) PA_GCC_CONST;
+
/**< Represents the format of data provided in a stream or processed by a sink. \since 1.0 */
typedef struct pa_format_info {
pa_encoding_t encoding;
@@ -77,6 +80,16 @@ int pa_format_info_valid(const pa_format_info *f);
/** Returns non-zero when the format info structure represents a PCM (i.e. uncompressed data) format */
int pa_format_info_is_pcm(const pa_format_info *f);
+/** Maximum required string length for
+ * pa_format_info_snprint(). Please note that this value can change
+ * with any release without warning and without being considered API
+ * or ABI breakage. You should not use this definition anywhere where
+ * it might become part of an ABI. \since 1.0 */
+#define PA_FORMAT_INFO_SNPRINT_MAX 256
+
+/** Return a human-readable string representing the given format. \since 1.0 */
+char *pa_format_info_snprint(char *s, size_t l, const pa_format_info *f);
+
PA_C_DECL_END
#endif