summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/bluetooth/module-bluetooth-discover.c55
-rw-r--r--src/modules/module-alsa-sink.c10
-rw-r--r--src/modules/module-alsa-source.c10
-rw-r--r--src/modules/module-flat-volume.c224
-rw-r--r--src/modules/module-stream-restore.c2
5 files changed, 281 insertions, 20 deletions
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index 0601e9a3..a33ca648 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -91,6 +91,16 @@ static void module_free(struct module *m) {
pa_xfree(m);
}
+static struct module* module_find(struct device *d, const char *profile) {
+ struct module *m;
+
+ for (m = d->module_list; d; d = d->next)
+ if (pa_streq(m->profile, profile))
+ return m;
+
+ return NULL;
+}
+
static struct uuid *uuid_new(const char *uuid) {
struct uuid *node;
@@ -345,6 +355,21 @@ static void load_module_for_device(struct userdata *u, struct device *d, const c
PA_LLIST_PREPEND(struct module, d->module_list, m);
}
+static void unload_module_for_device(struct userdata *u, struct device *d, const char *profile) {
+ struct module *m;
+
+ pa_assert(u);
+ pa_assert(d);
+
+ if (!(m = module_find(d, profile)))
+ return;
+
+ pa_module_unload_request(m->pa_m, TRUE);
+
+ PA_LLIST_REMOVE(struct module, d->module_list, m);
+ module_free(m);
+}
+
static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *userdata) {
DBusMessageIter arg_i;
DBusError err;
@@ -387,6 +412,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *
struct device *d;
const char *profile;
DBusMessageIter variant_i;
+ dbus_bool_t connected;
if (!dbus_message_iter_init(msg, &arg_i)) {
pa_log("dbus: message has no parameters");
@@ -400,6 +426,9 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *
dbus_message_iter_get_basic(&arg_i, &value);
+ if (!pa_streq(value, "Connected"))
+ goto done;
+
if (!dbus_message_iter_next(&arg_i)) {
pa_log("Property value missing");
goto done;
@@ -412,25 +441,29 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *
dbus_message_iter_recurse(&arg_i, &variant_i);
- if (dbus_message_iter_get_arg_type(&variant_i) == DBUS_TYPE_BOOLEAN) {
- dbus_bool_t connected;
- dbus_message_iter_get_basic(&variant_i, &connected);
-
- if (!pa_streq(value, "Connected") || !connected)
- goto done;
+ if (dbus_message_iter_get_arg_type(&variant_i) != DBUS_TYPE_BOOLEAN) {
+ pa_log("Property value not a boolean.");
+ goto done;
}
- if (!(d = device_find(u, dbus_message_get_path(msg)))) {
- d = device_new(dbus_message_get_path(msg));
- PA_LLIST_PREPEND(struct device, u->device_list, d);
- }
+ dbus_message_iter_get_basic(&variant_i, &connected);
if (dbus_message_is_signal(msg, "org.bluez.Headset", "PropertyChanged"))
profile = "hsp";
else
profile = "a2dp";
- load_module_for_device(u, d, profile);
+ d = device_find(u, dbus_message_get_path(msg));
+
+ if (connected) {
+ if (!d) {
+ d = device_new(dbus_message_get_path(msg));
+ PA_LLIST_PREPEND(struct device, u->device_list, d);
+ }
+
+ load_module_for_device(u, d, profile);
+ } else if (d)
+ unload_module_for_device(u, d, profile);
}
done:
diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c
index 0e15da3c..4044de13 100644
--- a/src/modules/module-alsa-sink.c
+++ b/src/modules/module-alsa-sink.c
@@ -796,7 +796,7 @@ static int sink_get_volume_cb(pa_sink *s) {
VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
#endif
- r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0);
+ r.values[i] = pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0);
} else {
if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
@@ -818,7 +818,7 @@ static int sink_get_volume_cb(pa_sink *s) {
VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
#endif
- pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0));
+ pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
} else {
@@ -875,6 +875,7 @@ static int sink_set_volume_cb(pa_sink *s) {
if (u->hw_dB_supported) {
alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
+ alsa_vol += u->hw_dB_max;
alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
if ((err = snd_mixer_selem_set_playback_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, 1)) < 0)
@@ -883,7 +884,7 @@ static int sink_set_volume_cb(pa_sink *s) {
if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
goto fail;
- r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0);
+ r.values[i] = pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0);
} else {
alsa_vol = to_alsa_volume(u, vol);
@@ -906,6 +907,7 @@ static int sink_set_volume_cb(pa_sink *s) {
if (u->hw_dB_supported) {
alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
+ alsa_vol += u->hw_dB_max;
alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
if ((err = snd_mixer_selem_set_playback_dB_all(u->mixer_elem, alsa_vol, 1)) < 0)
@@ -914,7 +916,7 @@ static int sink_set_volume_cb(pa_sink *s) {
if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
goto fail;
- pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0));
+ pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
} else {
alsa_vol = to_alsa_volume(u, vol);
diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c
index 2827ecfe..a7437767 100644
--- a/src/modules/module-alsa-source.c
+++ b/src/modules/module-alsa-source.c
@@ -742,7 +742,7 @@ static int source_get_volume_cb(pa_source *s) {
VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
#endif
- r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0);
+ r.values[i] = pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0);
} else {
if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
@@ -764,7 +764,7 @@ static int source_get_volume_cb(pa_source *s) {
VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
#endif
- pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0));
+ pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
} else {
@@ -821,6 +821,7 @@ static int source_set_volume_cb(pa_source *s) {
if (u->hw_dB_supported) {
alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
+ alsa_vol += u->hw_dB_max;
alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
if ((err = snd_mixer_selem_set_capture_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, 1)) < 0)
@@ -829,7 +830,7 @@ static int source_set_volume_cb(pa_source *s) {
if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0)
goto fail;
- r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0);
+ r.values[i] = pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0);
} else {
alsa_vol = to_alsa_volume(u, vol);
@@ -852,6 +853,7 @@ static int source_set_volume_cb(pa_source *s) {
if (u->hw_dB_supported) {
alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
+ alsa_vol += u->hw_dB_max;
alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max);
if ((err = snd_mixer_selem_set_capture_dB_all(u->mixer_elem, alsa_vol, 1)) < 0)
@@ -860,7 +862,7 @@ static int source_set_volume_cb(pa_source *s) {
if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0)
goto fail;
- pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0));
+ pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
} else {
alsa_vol = to_alsa_volume(u, vol);
diff --git a/src/modules/module-flat-volume.c b/src/modules/module-flat-volume.c
new file mode 100644
index 00000000..9bc8055a
--- /dev/null
+++ b/src/modules/module-flat-volume.c
@@ -0,0 +1,224 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+ Copyright 2004-2006, 2008 Lennart Poettering
+
+ Contact: Marc-Andre Lureau <marc-andre.lureau@nokia.com>
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <regex.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/core-error.h>
+#include <pulsecore/module.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/log.h>
+#include <pulsecore/sink-input.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
+
+#include "module-flat-volume-symdef.h"
+
+PA_MODULE_AUTHOR("Marc-Andre Lureau");
+PA_MODULE_DESCRIPTION("Flat volume");
+PA_MODULE_VERSION(PACKAGE_VERSION);
+PA_MODULE_LOAD_ONCE(TRUE);
+PA_MODULE_USAGE("");
+
+struct userdata {
+ pa_subscription *subscription;
+ pa_hook_slot *sink_input_set_volume_hook_slot;
+ pa_hook_slot *sink_input_fixate_hook_slot;
+};
+
+static void process_input_volume_change(
+ pa_cvolume *dest_volume,
+ const pa_cvolume *dest_virtual_volume,
+ pa_channel_map *dest_channel_map,
+ pa_sink_input *this,
+ pa_sink *sink) {
+
+ pa_sink_input *i;
+ uint32_t idx;
+ pa_cvolume max_volume, sink_volume;
+
+ pa_assert(dest_volume);
+ pa_assert(dest_virtual_volume);
+ pa_assert(dest_channel_map);
+ pa_assert(sink);
+
+ if (!(sink->flags & PA_SINK_DECIBEL_VOLUME))
+ return;
+
+ pa_log_debug("Sink input volume changed");
+
+ max_volume = *dest_virtual_volume;
+ pa_cvolume_remap(&max_volume, dest_channel_map, &sink->channel_map);
+
+ for (i = PA_SINK_INPUT(pa_idxset_first(sink->inputs, &idx)); i; i = PA_SINK_INPUT(pa_idxset_next(sink->inputs, &idx))) {
+ /* skip this sink-input if we are processing a volume change request */
+ if (this && this == i)
+ continue;
+
+ if (pa_cvolume_max(&i->virtual_volume) > pa_cvolume_max(&max_volume)) {
+ max_volume = i->virtual_volume;
+ pa_cvolume_remap(&max_volume, &i->channel_map, &sink->channel_map);
+ }
+ }
+
+ /* Set the master volume, and normalize inputs */
+ if (!pa_cvolume_equal(&max_volume, &sink->volume)) {
+
+ pa_sink_set_volume(sink, &max_volume);
+
+ pa_log_debug("sink = %.2f (changed)", (double)pa_cvolume_avg(&sink->volume)/PA_VOLUME_NORM);
+
+ /* Now, normalize each of the internal volume (client sink-input volume / sink master volume) */
+ for (i = PA_SINK_INPUT(pa_idxset_first(sink->inputs, &idx)); i; i = PA_SINK_INPUT(pa_idxset_next(sink->inputs, &idx))) {
+ /* skip this sink-input if we are processing a volume change request */
+ if (this && this == i)
+ continue;
+
+ sink_volume = max_volume;
+ pa_cvolume_remap(&sink_volume, &sink->channel_map, &i->channel_map);
+ pa_sw_cvolume_divide(&i->volume, &i->virtual_volume, &sink_volume);
+ pa_log_debug("sink input { id = %d, flat = %.2f, true = %.2f }",
+ i->index,
+ (double)pa_cvolume_avg(&i->virtual_volume)/PA_VOLUME_NORM,
+ (double)pa_cvolume_avg(&i->volume)/PA_VOLUME_NORM);
+ pa_asyncmsgq_post(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_VOLUME, pa_xnewdup(struct pa_cvolume, &i->volume, 1), 0, NULL, pa_xfree);
+ }
+ } else
+ pa_log_debug("sink = %.2f", (double)pa_cvolume_avg(&sink->volume)/PA_VOLUME_NORM);
+
+ /* and this one */
+
+ sink_volume = max_volume;
+ pa_cvolume_remap(&sink_volume, &sink->channel_map, dest_channel_map);
+ pa_sw_cvolume_divide(dest_volume, dest_virtual_volume, &sink_volume);
+ pa_log_debug("caller sink input: { id = %d, flat = %.2f, true = %.2f }",
+ this ? (int)this->index : -1,
+ (double)pa_cvolume_avg(dest_virtual_volume)/PA_VOLUME_NORM,
+ (double)pa_cvolume_avg(dest_volume)/PA_VOLUME_NORM);
+}
+
+static pa_hook_result_t sink_input_set_volume_hook_callback(pa_core *c, pa_sink_input_set_volume_data *this, struct userdata *u) {
+ pa_assert(this);
+ pa_assert(this->sink_input);
+
+ process_input_volume_change(&this->volume, &this->virtual_volume, &this->sink_input->channel_map,
+ this->sink_input, this->sink_input->sink);
+
+ return PA_HOOK_OK;
+}
+
+static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *core, pa_sink_input_new_data *this, struct userdata *u) {
+ pa_assert(this);
+ pa_assert(this->sink);
+
+ process_input_volume_change(&this->volume, &this->virtual_volume, &this->channel_map,
+ NULL, this->sink);
+
+ return PA_HOOK_OK;
+}
+
+static void subscribe_callback(pa_core *core, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
+ struct userdata *u = userdata;
+ pa_sink *sink;
+ pa_sink_input *i;
+ uint32_t iidx;
+ pa_cvolume sink_volume;
+
+ pa_assert(core);
+ pa_assert(u);
+
+ if (t != (PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_NEW) &&
+ t != (PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE))
+ return;
+
+ if (!(sink = pa_idxset_get_by_index(core->sinks, idx)))
+ return;
+
+ if (!(sink->flags & PA_SINK_DECIBEL_VOLUME))
+ return;
+
+ pa_log_debug("Sink volume changed");
+ pa_log_debug("sink = %.2f", (double)pa_cvolume_avg(pa_sink_get_volume(sink, FALSE)) / PA_VOLUME_NORM);
+
+ sink_volume = *pa_sink_get_volume(sink, FALSE);
+
+ for (i = PA_SINK_INPUT(pa_idxset_first(sink->inputs, &iidx)); i; i = PA_SINK_INPUT(pa_idxset_next(sink->inputs, &iidx))) {
+ pa_cvolume si_volume;
+
+ si_volume = sink_volume;
+ pa_cvolume_remap(&si_volume, &sink->channel_map, &i->channel_map);
+ pa_sw_cvolume_multiply(&i->virtual_volume, &i->volume, &si_volume);
+ pa_log_debug("sink input = { id = %d, flat = %.2f, true = %.2f }",
+ i->index,
+ (double)pa_cvolume_avg(&i->virtual_volume)/PA_VOLUME_NORM,
+ (double)pa_cvolume_avg(&i->volume)/PA_VOLUME_NORM);
+ pa_subscription_post(i->sink->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+ }
+}
+
+int pa__init(pa_module*m) {
+ struct userdata *u;
+
+ pa_assert(m);
+
+ u = pa_xnew(struct userdata, 1);
+ m->userdata = u;
+
+ u->sink_input_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_fixate_hook_callback, u);
+ u->sink_input_set_volume_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_SET_VOLUME], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_set_volume_hook_callback, u);
+
+ u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK, subscribe_callback, u);
+
+ return 0;
+}
+
+void pa__done(pa_module*m) {
+ struct userdata* u;
+
+ pa_assert(m);
+
+ if (!(u = m->userdata))
+ return;
+
+ if (u->subscription)
+ pa_subscription_free(u->subscription);
+
+ if (u->sink_input_set_volume_hook_slot)
+ pa_hook_slot_free(u->sink_input_set_volume_hook_slot);
+ if (u->sink_input_fixate_hook_slot)
+ pa_hook_slot_free(u->sink_input_fixate_hook_slot);
+
+ pa_xfree(u);
+}
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index fe79291e..e1381a5e 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -134,7 +134,7 @@ static char *get_name(pa_proplist *p, const char *prefix) {
else if ((r = pa_proplist_gets(p, PA_PROP_MEDIA_NAME)))
return pa_sprintf_malloc("%s-by-media-name:%s", prefix, r);
- return NULL;
+ return pa_sprintf_malloc("%s-fallback:%s", prefix);
}
static struct entry* read_entry(struct userdata *u, char *name) {