mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
format: Add some convenience functions for printing
This commit is contained in:
parent
a3a0042144
commit
8631f4e2c4
3 changed files with 51 additions and 0 deletions
|
|
@ -146,6 +146,7 @@ pa_cvolume_set_fade;
|
|||
pa_cvolume_set_position;
|
||||
pa_cvolume_snprint;
|
||||
pa_cvolume_valid;
|
||||
pa_encoding_to_string;
|
||||
pa_ext_device_manager_delete;
|
||||
pa_ext_device_manager_enable_role_device_priority_routing;
|
||||
pa_ext_device_manager_read;
|
||||
|
|
@ -164,6 +165,7 @@ pa_format_info_copy;
|
|||
pa_format_info_free;
|
||||
pa_format_info_is_pcm;
|
||||
pa_format_info_new;
|
||||
pa_format_info_snprint;
|
||||
pa_format_info_valid;
|
||||
pa_frame_size;
|
||||
pa_get_binary_name;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue