diff options
Diffstat (limited to 'src/pulse')
-rw-r--r-- | src/pulse/def.h | 4 | ||||
-rw-r--r-- | src/pulse/introspect.c | 7 | ||||
-rw-r--r-- | src/pulse/introspect.h | 5 | ||||
-rw-r--r-- | src/pulse/proplist.c | 21 | ||||
-rw-r--r-- | src/pulse/proplist.h | 17 | ||||
-rw-r--r-- | src/pulse/volume.c | 91 | ||||
-rw-r--r-- | src/pulse/volume.h | 22 |
7 files changed, 151 insertions, 16 deletions
diff --git a/src/pulse/def.h b/src/pulse/def.h index 9e424d46..d43c070e 100644 --- a/src/pulse/def.h +++ b/src/pulse/def.h @@ -234,13 +234,13 @@ typedef enum pa_stream_flags { PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND = 0x8000U, /**< If set this stream won't be taken into account when we it is * checked whether the device this stream is connected to should - * auto-suspend. \ since 0.9.14 */ + * auto-suspend. \ since 0.9.15 */ PA_STREAM_START_UNMUTED = 0x10000U /**< Create in unmuted state. If neither PA_STREAM_START_UNMUTED * nor PA_STREAM_START_MUTED it is left to the server to decide * whether to create the stream in muted or in unmuted - * state. \since 0.9.14 */ + * state. \since 0.9.15 */ } pa_stream_flags_t; diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c index bdc50e29..e7fa6d76 100644 --- a/src/pulse/introspect.c +++ b/src/pulse/introspect.c @@ -480,13 +480,16 @@ static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command, while (!pa_tagstruct_eof(t)) { pa_module_info i; pa_bool_t auto_unload = FALSE; + memset(&i, 0, sizeof(i)); + i.proplist = pa_proplist_new(); if (pa_tagstruct_getu32(t, &i.index) < 0 || pa_tagstruct_gets(t, &i.name) < 0 || pa_tagstruct_gets(t, &i.argument) < 0 || pa_tagstruct_getu32(t, &i.n_used) < 0 || - pa_tagstruct_get_boolean(t, &auto_unload) < 0) { + (o->context->version < 15 && pa_tagstruct_get_boolean(t, &auto_unload) < 0) || + (o->context->version >= 15 && pa_tagstruct_get_proplist(t, i.proplist) < 0)) { pa_context_fail(o->context, PA_ERR_PROTOCOL); goto finish; } @@ -497,6 +500,8 @@ static void context_get_module_info_callback(pa_pdispatch *pd, uint32_t command, pa_module_info_cb_t cb = (pa_module_info_cb_t) o->callback; cb(o->context, &i, 0, o->userdata); } + + pa_proplist_free(i.proplist); } } diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h index ae9bd5bc..a656d1cf 100644 --- a/src/pulse/introspect.h +++ b/src/pulse/introspect.h @@ -211,7 +211,7 @@ typedef struct pa_sink_info { pa_sink_flags_t flags; /**< Flags */ pa_proplist *proplist; /**< Property list \since 0.9.11 */ pa_usec_t configured_latency; /**< The latency this device has been configured to. \since 0.9.11 */ - pa_volume_t base_volume; /**< Some kind of "base" volume that refers to unamplified/unattenuated volume in the context of the output device. \since 0.9.14 */ + pa_volume_t base_volume; /**< Some kind of "base" volume that refers to unamplified/unattenuated volume in the context of the output device. \since 0.9.15 */ } pa_sink_info; /** Callback prototype for pa_context_get_sink_info_by_name() and friends */ @@ -267,7 +267,7 @@ typedef struct pa_source_info { pa_source_flags_t flags; /**< Flags */ pa_proplist *proplist; /**< Property list \since 0.9.11 */ pa_usec_t configured_latency; /**< The latency this device has been configured to. \since 0.9.11 */ - pa_volume_t base_volume; /**< Some kind of "base" volume that refers to unamplified/unattenuated volume in the context of the input device. \since 0.9.14 */ + pa_volume_t base_volume; /**< Some kind of "base" volume that refers to unamplified/unattenuated volume in the context of the input device. \since 0.9.15 */ } pa_source_info; /** Callback prototype for pa_context_get_source_info_by_name() and friends */ @@ -333,6 +333,7 @@ typedef struct pa_module_info { /** \cond fulldocs */ int auto_unload; /**< \deprecated Non-zero if this is an autoloaded module */ /** \endcond */ + pa_proplist *proplist; /**< Property list \since 0.9.15 */ } pa_module_info; /** Callback prototype for pa_context_get_module_info() and firends*/ diff --git a/src/pulse/proplist.c b/src/pulse/proplist.c index 60a92d44..282fe5cc 100644 --- a/src/pulse/proplist.c +++ b/src/pulse/proplist.c @@ -259,21 +259,24 @@ const char *pa_proplist_iterate(pa_proplist *p, void **state) { return prop->key; } -char *pa_proplist_to_string(pa_proplist *p) { +char *pa_proplist_to_string_sep(pa_proplist *p, const char *sep) { const char *key; void *state = NULL; pa_strbuf *buf; pa_assert(p); + pa_assert(sep); buf = pa_strbuf_new(); while ((key = pa_proplist_iterate(p, &state))) { - const char *v; + if (!pa_strbuf_isempty(buf)) + pa_strbuf_puts(buf, sep); + if ((v = pa_proplist_gets(p, key))) - pa_strbuf_printf(buf, "%s = \"%s\"\n", key, v); + pa_strbuf_printf(buf, "%s = \"%s\"", key, v); else { const void *value; size_t nbytes; @@ -283,7 +286,7 @@ char *pa_proplist_to_string(pa_proplist *p) { c = pa_xmalloc(nbytes*2+1); pa_hexstr((const uint8_t*) value, nbytes, c, nbytes*2+1); - pa_strbuf_printf(buf, "%s = hex:%s\n", key, c); + pa_strbuf_printf(buf, "%s = hex:%s", key, c); pa_xfree(c); } } @@ -291,6 +294,16 @@ char *pa_proplist_to_string(pa_proplist *p) { return pa_strbuf_tostring_free(buf); } +char *pa_proplist_to_string(pa_proplist *p) { + char *s, *t; + + s = pa_proplist_to_string_sep(p, "\n"); + t = pa_sprintf_malloc("%s\n", s); + pa_xfree(s); + + return t; +} + /* Remove all whitepsapce from the beginning and the end of *s. *s may * be modified. (from conf-parser.c) */ #define WHITESPACE " \t\n" diff --git a/src/pulse/proplist.h b/src/pulse/proplist.h index 77f0399c..529871f8 100644 --- a/src/pulse/proplist.h +++ b/src/pulse/proplist.h @@ -128,6 +128,10 @@ PA_C_DECL_BEGIN #define PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE "device.buffering.fragment_size" #define PA_PROP_DEVICE_PROFILE_NAME "device.profile.name" #define PA_PROP_DEVICE_PROFILE_DESCRIPTION "device.profile.description" +#define PA_PROP_MODULE_AUTHOR "module.author" +#define PA_PROP_MODULE_DESCRIPTION "module.description" +#define PA_PROP_MODULE_USAGE "module.usage" +#define PA_PROP_MODULE_VERSION "module.version" /** A property list object. Basically a dictionary with UTF-8 strings * as keys and arbitrary data as values. \since 0.9.11 */ @@ -213,12 +217,19 @@ int pa_proplist_unset_many(pa_proplist *p, const char * const keys[]); * have any particular order. \since 0.9.11 */ const char *pa_proplist_iterate(pa_proplist *p, void **state); -/** Format the property list nicely as a human readable string. Call pa_xfree() on the result. \since - * 0.9.11 */ +/** Format the property list nicely as a human readable string. This + * works very much like pa_proplist_to_string_sep() and uses a newline + * as seperator and appends one final one. Call pa_xfree() on the + * result. \since 0.9.11 */ char *pa_proplist_to_string(pa_proplist *p); -/** Allocate a new property list and assign key/value from a human readable string. \since +/** Format the property list nicely as a human readable string and + * choose the seperator. Call pa_xfree() on the result. \since * 0.9.15 */ +char *pa_proplist_to_string_sep(pa_proplist *p, const char *sep); + +/** Allocate a new property list and assign key/value from a human + * readable string. \since 0.9.15 */ pa_proplist *pa_proplist_from_string(const char *str); /** Returns 1 if an entry for the specified key is existant in the diff --git a/src/pulse/volume.c b/src/pulse/volume.c index ace5c4d6..9191a074 100644 --- a/src/pulse/volume.c +++ b/src/pulse/volume.c @@ -402,3 +402,94 @@ int pa_cvolume_compatible(const pa_cvolume *v, const pa_sample_spec *ss) { return v->channels == ss->channels; } + +static void get_avg_lr(const pa_channel_map *map, const pa_cvolume *v, pa_volume_t *l, pa_volume_t *r) { + int c; + pa_volume_t left = 0, right = 0; + unsigned n_left = 0, n_right = 0; + + pa_assert(v); + pa_assert(map); + pa_assert(map->channels == v->channels); + pa_assert(l); + pa_assert(r); + + for (c = 0; c < map->channels; c++) { + if (on_left(map->map[c])) { + left += v->values[c]; + n_left++; + } else if (on_right(map->map[c])) { + right += v->values[c]; + n_right++; + } + } + + *l = left / n_left; + *r = right / n_right; +} + +float pa_cvolume_get_balance(const pa_channel_map *map, const pa_cvolume *v) { + pa_volume_t left, right; + + pa_assert(v); + pa_assert(map); + pa_assert(map->channels == v->channels); + + get_avg_lr(map, v, &left, &right); + + if (left == right) + return 0.0f; + + /* 1.0, 0.0 => -1.0 + 0.0, 1.0 => 1.0 + 0.0, 0.0 => 0.0 + 0.5, 0.5 => 0.0 + 1.0, 0.5 => -0.5 + 1.0, 0.25 => -0.75 + 0.75, 0.25 => -0.66 + 0.5, 0.25 => -0.5 */ + + if (left > right) + return -1.0f + ((float) right / (float) left); + else + return 1.0f - ((float) left / (float) right); +} + +pa_cvolume* pa_cvolume_set_balance(const pa_channel_map *map, pa_cvolume *v, float new_balance) { + pa_volume_t left, nleft, right, nright, m; + unsigned c; + + pa_assert(map->channels == v->channels); + pa_assert(map); + pa_assert(v); + pa_assert(new_balance >= -1.0f); + pa_assert(new_balance <= 1.0f); + + get_avg_lr(map, v, &left, &right); + + m = PA_MAX(left, right); + + if (new_balance <= 0) { + nright = (new_balance + 1.0f) * m; + nleft = m; + } else { + nleft = (1.0f - new_balance) * m; + nright = m; + } + + for (c = 0; c < map->channels; c++) { + if (on_left(map->map[c])) { + if (left == 0) + v->values[c] = 0; + else + v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nleft) / (uint64_t) left); + } else if (on_right(map->map[c])) { + if (right == 0) + v->values[c] = 0; + else + v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nright) / (uint64_t) right); + } + } + + return v; +} diff --git a/src/pulse/volume.h b/src/pulse/volume.h index 5815c906..38da5dfc 100644 --- a/src/pulse/volume.h +++ b/src/pulse/volume.h @@ -154,20 +154,20 @@ char *pa_sw_cvolume_snprint_dB(char *s, size_t l, const pa_cvolume *c); * pa_volume_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 0.9.14 */ + * might become part of an ABI. \since 0.9.15 */ #define PA_VOLUME_SNPRINT_MAX 10 -/** Pretty print a volume \since 0.9.14 */ +/** Pretty print a volume \since 0.9.15 */ char *pa_volume_snprint(char *s, size_t l, pa_volume_t v); /** Maximum length of the strings returned by * pa_volume_snprint_dB(). 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 0.9.14 */ + * might become part of an ABI. \since 0.9.15 */ #define PA_SW_VOLUME_SNPRINT_DB_MAX 10 -/** Pretty print a volume but show dB values. \since 0.9.14 */ +/** Pretty print a volume but show dB values. \since 0.9.15 */ char *pa_sw_volume_snprint_dB(char *s, size_t l, pa_volume_t v); /** Return the average volume of all channels */ @@ -233,6 +233,20 @@ pa_cvolume *pa_cvolume_remap(pa_cvolume *v, pa_channel_map *from, pa_channel_map * the specified sample spec. \since 0.9.13 */ int pa_cvolume_compatible(const pa_cvolume *v, const pa_sample_spec *ss) PA_GCC_PURE; +/** Calculate a 'balance' value for the specified volume with the + * specified channel map. The return value will range from -1.0f + * (left) to +1.0f (right) \since 0.9.15 */ +float pa_cvolume_get_balance(const pa_channel_map *map, const pa_cvolume *v) PA_GCC_PURE; + +/** Adjust the 'balance' value for the specified volume with the + * specified channel map. v will be modified in place and + * returned. The balance is a value between -1.0f and +1.0f. This + * operation might not be reversable! Also, after this call + * pa_cvolume_get_balance() is not guaranteed to actually return the + * requested balance (e.g. when the input volume was zero anyway for + * all channels)- \since 0.9.15 */ +pa_cvolume* pa_cvolume_set_balance(const pa_channel_map *map, pa_cvolume *v, float new_balance); + PA_C_DECL_END #endif |