Merge branch 'master' of git://0pointer.de/pulseaudio into dbus-work

This commit is contained in:
Tanu Kaskinen 2009-08-19 09:20:02 +03:00
commit 292d6dcb5f
64 changed files with 6601 additions and 3909 deletions

View file

@ -68,6 +68,8 @@
#define TSCHED_MIN_SLEEP_USEC (10*PA_USEC_PER_MSEC) /* 10ms -- Sleep at least 10ms on each iteration */
#define TSCHED_MIN_WAKEUP_USEC (4*PA_USEC_PER_MSEC) /* 4ms -- Wakeup at least this long before the buffer runs empty*/
#define VOLUME_ACCURACY (PA_VOLUME_NORM/100) /* don't require volume adjustments to be perfectly correct. don't necessarily extend granularity in software unless the differences get greater than this level */
struct userdata {
pa_core *core;
pa_module *module;
@ -1007,7 +1009,7 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
return 0;
if (mask & SND_CTL_EVENT_MASK_VALUE) {
pa_sink_get_volume(u->sink, TRUE, FALSE);
pa_sink_get_volume(u->sink, TRUE);
pa_sink_get_mute(u->sink, TRUE);
}
@ -1034,15 +1036,11 @@ static void sink_get_volume_cb(pa_sink *s) {
if (pa_cvolume_equal(&u->hardware_volume, &r))
return;
s->virtual_volume = u->hardware_volume = r;
s->real_volume = u->hardware_volume = r;
if (u->mixer_path->has_dB) {
pa_cvolume reset;
/* Hmm, so the hardware volume changed, let's reset our software volume */
pa_cvolume_reset(&reset, s->sample_spec.channels);
pa_sink_set_soft_volume(s, &reset);
}
/* Hmm, so the hardware volume changed, let's reset our software volume */
if (u->mixer_path->has_dB)
pa_sink_set_soft_volume(s, NULL);
}
static void sink_set_volume_cb(pa_sink *s) {
@ -1055,7 +1053,7 @@ static void sink_set_volume_cb(pa_sink *s) {
pa_assert(u->mixer_handle);
/* Shift up by the base volume */
pa_sw_cvolume_divide_scalar(&r, &s->virtual_volume, s->base_volume);
pa_sw_cvolume_divide_scalar(&r, &s->real_volume, s->base_volume);
if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
return;
@ -1066,13 +1064,26 @@ static void sink_set_volume_cb(pa_sink *s) {
u->hardware_volume = r;
if (u->mixer_path->has_dB) {
pa_cvolume new_soft_volume;
pa_bool_t accurate_enough;
/* Match exactly what the user requested by software */
pa_sw_cvolume_divide(&s->soft_volume, &s->virtual_volume, &u->hardware_volume);
pa_sw_cvolume_divide(&new_soft_volume, &s->real_volume, &u->hardware_volume);
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->virtual_volume));
/* If the adjustment to do in software is only minimal we
* can skip it. That saves us CPU at the expense of a bit of
* accuracy */
accurate_enough =
(pa_cvolume_min(&new_soft_volume) >= (PA_VOLUME_NORM - VOLUME_ACCURACY)) &&
(pa_cvolume_max(&new_soft_volume) <= (PA_VOLUME_NORM + VOLUME_ACCURACY));
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->real_volume));
pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume));
pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->soft_volume));
pa_log_debug("Calculated software volume: %s (accurate-enough=%s)", pa_cvolume_snprint(t, sizeof(t), &new_soft_volume),
pa_yes_no(accurate_enough));
if (!accurate_enough)
s->soft_volume = new_soft_volume;
} else {
pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
@ -1080,7 +1091,7 @@ static void sink_set_volume_cb(pa_sink *s) {
/* We can't match exactly what the user requested, hence let's
* at least tell the user about it */
s->virtual_volume = r;
s->real_volume = r;
}
}

View file

@ -65,6 +65,8 @@
#define TSCHED_MIN_SLEEP_USEC (10*PA_USEC_PER_MSEC) /* 10ms */
#define TSCHED_MIN_WAKEUP_USEC (4*PA_USEC_PER_MSEC) /* 4ms */
#define VOLUME_ACCURACY (PA_VOLUME_NORM/100)
struct userdata {
pa_core *core;
pa_module *module;
@ -987,15 +989,11 @@ static void source_get_volume_cb(pa_source *s) {
if (pa_cvolume_equal(&u->hardware_volume, &r))
return;
s->virtual_volume = u->hardware_volume = r;
s->volume = u->hardware_volume = r;
if (u->mixer_path->has_dB) {
pa_cvolume reset;
/* Hmm, so the hardware volume changed, let's reset our software volume */
pa_cvolume_reset(&reset, s->sample_spec.channels);
pa_source_set_soft_volume(s, &reset);
}
/* Hmm, so the hardware volume changed, let's reset our software volume */
if (u->mixer_path->has_dB)
pa_source_set_soft_volume(s, NULL);
}
static void source_set_volume_cb(pa_source *s) {
@ -1008,7 +1006,7 @@ static void source_set_volume_cb(pa_source *s) {
pa_assert(u->mixer_handle);
/* Shift up by the base volume */
pa_sw_cvolume_divide_scalar(&r, &s->virtual_volume, s->base_volume);
pa_sw_cvolume_divide_scalar(&r, &s->volume, s->base_volume);
if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
return;
@ -1019,13 +1017,26 @@ static void source_set_volume_cb(pa_source *s) {
u->hardware_volume = r;
if (u->mixer_path->has_dB) {
pa_cvolume new_soft_volume;
pa_bool_t accurate_enough;
/* Match exactly what the user requested by software */
pa_sw_cvolume_divide(&s->soft_volume, &s->virtual_volume, &u->hardware_volume);
pa_sw_cvolume_divide(&new_soft_volume, &s->volume, &u->hardware_volume);
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->virtual_volume));
/* If the adjustment to do in software is only minimal we
* can skip it. That saves us CPU at the expense of a bit of
* accuracy */
accurate_enough =
(pa_cvolume_min(&new_soft_volume) >= (PA_VOLUME_NORM - VOLUME_ACCURACY)) &&
(pa_cvolume_max(&new_soft_volume) <= (PA_VOLUME_NORM + VOLUME_ACCURACY));
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->volume));
pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume));
pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->soft_volume));
pa_log_debug("Calculated software volume: %s (accurate-enough=%s)", pa_cvolume_snprint(t, sizeof(t), &new_soft_volume),
pa_yes_no(accurate_enough));
if (!accurate_enough)
s->soft_volume = new_soft_volume;
} else {
pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
@ -1033,7 +1044,7 @@ static void source_set_volume_cb(pa_source *s) {
/* We can't match exactly what the user requested, hence let's
* at least tell the user about it */
s->virtual_volume = r;
s->volume = r;
}
}

View file

@ -758,7 +758,7 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
if (pa_dbus_add_matches(
pa_dbus_connection_get(y->connection), &err,
"type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged'",
"type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.bluez'",
"type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
"type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
"type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
@ -809,7 +809,7 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
if (y->connection) {
pa_dbus_remove_matches(pa_dbus_connection_get(y->connection),
"type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged'",
"type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.bluez'",
"type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
"type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterRemoved'",
"type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",

View file

@ -1476,12 +1476,12 @@ static void sink_set_volume_cb(pa_sink *s) {
if (u->profile != PROFILE_HSP)
return;
gain = (pa_cvolume_max(&s->virtual_volume) * 15) / PA_VOLUME_NORM;
gain = (pa_cvolume_max(&s->real_volume) * 15) / PA_VOLUME_NORM;
if (gain > 15)
gain = 15;
pa_cvolume_set(&s->virtual_volume, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
pa_cvolume_set(&s->real_volume, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
pa_assert_se(m = dbus_message_new_method_call("org.bluez", u->path, "org.bluez.Headset", "SetSpeakerGain"));
pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_UINT16, &gain, DBUS_TYPE_INVALID));
@ -1500,12 +1500,12 @@ static void source_set_volume_cb(pa_source *s) {
if (u->profile != PROFILE_HSP)
return;
gain = (pa_cvolume_max(&s->virtual_volume) * 15) / PA_VOLUME_NORM;
gain = (pa_cvolume_max(&s->volume) * 15) / PA_VOLUME_NORM;
if (gain > 15)
gain = 15;
pa_cvolume_set(&s->virtual_volume, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
pa_cvolume_set(&s->volume, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
pa_assert_se(m = dbus_message_new_method_call("org.bluez", u->path, "org.bluez.Headset", "SetMicrophoneGain"));
pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_UINT16, &gain, DBUS_TYPE_INVALID));

View file

@ -187,7 +187,6 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
}
add_session(u, path);
return DBUS_HANDLER_RESULT_HANDLED;
} else if (dbus_message_is_signal(message, "org.freedesktop.ConsoleKit.Seat", "SessionRemoved")) {
@ -202,7 +201,6 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
}
remove_session(u, path);
return DBUS_HANDLER_RESULT_HANDLED;
}
finish:

View file

@ -218,7 +218,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
if (sink->save_volume) {
entry.channel_map = sink->channel_map;
entry.volume = *pa_sink_get_volume(sink, FALSE, TRUE);
entry.volume = *pa_sink_get_volume(sink, FALSE);
entry.volume_valid = TRUE;
}

View file

@ -623,8 +623,6 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
}
return DBUS_HANDLER_RESULT_HANDLED;
} else if (dbus_message_is_signal(message, "org.pulseaudio.Server", "DirtyGiveUpMessage")) {
/* We use this message to avoid a dirty race condition when we
get an ACLAdded message before the previously owning PA
@ -668,7 +666,6 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, vo
/* Yes, we don't check the UDI for validity, but hopefully HAL will */
device_added_cb(u->context, udi);
return DBUS_HANDLER_RESULT_HANDLED;
}
finish:

View file

@ -63,6 +63,8 @@ struct userdata {
float mute_toggle_save;
};
#define DELTA (PA_VOLUME_NORM/20)
static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void*userdata) {
struct userdata *u = userdata;
char *name = NULL, *code = NULL;
@ -119,32 +121,17 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
if (!(s = pa_namereg_get(u->module->core, u->sink_name, PA_NAMEREG_SINK)))
pa_log("Failed to get sink '%s'", u->sink_name);
else {
int i;
pa_cvolume cv = *pa_sink_get_volume(s, FALSE, FALSE);
#define DELTA (PA_VOLUME_NORM/20)
pa_cvolume cv = *pa_sink_get_volume(s, FALSE);
switch (volchange) {
case UP:
for (i = 0; i < cv.channels; i++) {
if (cv.values[i] < PA_VOLUME_MAX - DELTA)
cv.values[i] += DELTA;
else
cv.values[i] = PA_VOLUME_MAX;
}
pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
pa_cvolume_inc(&cv, DELTA);
pa_sink_set_volume(s, &cv, TRUE, TRUE);
break;
case DOWN:
for (i = 0; i < cv.channels; i++) {
if (cv.values[i] > DELTA)
cv.values[i] -= DELTA;
else
cv.values[i] = PA_VOLUME_MUTED;
}
pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
pa_cvolume_dec(&cv, DELTA);
pa_sink_set_volume(s, &cv, TRUE, TRUE);
break;
case MUTE:
@ -156,7 +143,6 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
break;
case MUTE_TOGGLE:
pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE), TRUE);
break;

View file

@ -216,7 +216,7 @@ static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, v
pa_cvolume cv;
pa_log_debug("changing volume of sink input '%s' to 0x%03x", n, r->volume);
pa_cvolume_set(&cv, si->sample_spec.channels, r->volume);
pa_sink_input_set_volume(si, &cv, TRUE, TRUE);
pa_sink_input_set_volume(si, &cv, TRUE, FALSE);
}
}
}
@ -243,6 +243,9 @@ int pa__init(pa_module*m) {
if (load_rules(u, pa_modargs_get_value(ma, "table", NULL)) < 0)
goto fail;
/* FIXME: Doing this asynchronously is just broken. This needs to
* use a hook! */
u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT, callback, u);
pa_modargs_free(ma);

View file

@ -65,6 +65,8 @@ struct userdata {
pa_module *module;
};
#define DELTA (PA_VOLUME_NORM/20)
static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void*userdata) {
struct userdata *u = userdata;
@ -85,14 +87,27 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
}
if (ev.type == EV_KEY && (ev.value == 1 || ev.value == 2)) {
enum { INVALID, UP, DOWN, MUTE_TOGGLE } volchange = INVALID;
enum {
INVALID,
UP,
DOWN,
MUTE_TOGGLE
} volchange = INVALID;
pa_log_debug("Key code=%u, value=%u", ev.code, ev.value);
switch (ev.code) {
case KEY_VOLUMEDOWN: volchange = DOWN; break;
case KEY_VOLUMEUP: volchange = UP; break;
case KEY_MUTE: volchange = MUTE_TOGGLE; break;
case KEY_VOLUMEDOWN:
volchange = DOWN;
break;
case KEY_VOLUMEUP:
volchange = UP;
break;
case KEY_MUTE:
volchange = MUTE_TOGGLE;
break;
}
if (volchange != INVALID) {
@ -101,36 +116,20 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
if (!(s = pa_namereg_get(u->module->core, u->sink_name, PA_NAMEREG_SINK)))
pa_log("Failed to get sink '%s'", u->sink_name);
else {
int i;
pa_cvolume cv = *pa_sink_get_volume(s, FALSE, FALSE);
#define DELTA (PA_VOLUME_NORM/20)
pa_cvolume cv = *pa_sink_get_volume(s, FALSE);
switch (volchange) {
case UP:
for (i = 0; i < cv.channels; i++) {
if (cv.values[i] < PA_VOLUME_MAX - DELTA)
cv.values[i] += DELTA;
else
cv.values[i] = PA_VOLUME_MAX;
}
pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
pa_cvolume_inc(&cv, DELTA);
pa_sink_set_volume(s, &cv, TRUE, TRUE);
break;
case DOWN:
for (i = 0; i < cv.channels; i++) {
if (cv.values[i] > DELTA)
cv.values[i] -= DELTA;
else
cv.values[i] = PA_VOLUME_MUTED;
}
pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
pa_cvolume_dec(&cv, DELTA);
pa_sink_set_volume(s, &cv, TRUE, TRUE);
break;
case MUTE_TOGGLE:
pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE), TRUE);
break;

View file

@ -1162,7 +1162,7 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag
pa_assert(u->sink);
if ((u->version < 11 || !!mute == !!u->sink->muted) &&
pa_cvolume_equal(&volume, &u->sink->virtual_volume))
pa_cvolume_equal(&volume, &u->sink->real_volume))
return;
pa_sink_volume_changed(u->sink, &volume);
@ -1763,7 +1763,7 @@ static void sink_set_volume(pa_sink *sink) {
pa_tagstruct_putu32(t, PA_COMMAND_SET_SINK_INPUT_VOLUME);
pa_tagstruct_putu32(t, tag = u->ctag++);
pa_tagstruct_putu32(t, u->device_index);
pa_tagstruct_put_cvolume(t, &sink->virtual_volume);
pa_tagstruct_put_cvolume(t, &sink->real_volume);
pa_pstream_send_tagstruct(u->pstream, t);
}

View file

@ -39,6 +39,9 @@ PA_MODULE_AUTHOR("Lennart Poettering");
PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers");
PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_LOAD_ONCE(TRUE);
PA_MODULE_USAGE(
"tsched=<enable system timer based scheduling mode?> "
"ignore_dB=<ignore dB information from the device?>");
struct device {
char *path;
@ -50,7 +53,9 @@ struct device {
struct userdata {
pa_core *core;
pa_hashmap *devices;
pa_bool_t use_tsched;
pa_bool_t use_tsched:1;
pa_bool_t ignore_dB:1;
struct udev* udev;
struct udev_monitor *monitor;
@ -62,6 +67,7 @@ struct userdata {
static const char* const valid_modargs[] = {
"tsched",
"ignore_dB",
NULL
};
@ -140,12 +146,14 @@ static void card_changed(struct userdata *u, struct udev_device *dev) {
args = pa_sprintf_malloc("device_id=\"%s\" "
"name=\"%s\" "
"card_name=\"%s\" "
"tsched=%i "
"tsched=%s "
"ignore_dB=%s "
"card_properties=\"module-udev-detect.discovered=1\"",
path_get_card_id(path),
n,
card_name,
(int) u->use_tsched);
pa_yes_no(u->use_tsched),
pa_yes_no(u->ignore_dB));
pa_log_debug("Loading module-alsa-card with arguments '%s'", args);
m = pa_module_load(u->core, "module-alsa-card", args);
@ -364,6 +372,7 @@ int pa__init(pa_module *m) {
struct udev_enumerate *enumerate = NULL;
struct udev_list_entry *item = NULL, *first = NULL;
int fd;
pa_bool_t use_tsched = TRUE, ignore_dB = FALSE;
pa_assert(m);
@ -375,13 +384,19 @@ int pa__init(pa_module *m) {
m->userdata = u = pa_xnew0(struct userdata, 1);
u->core = m->core;
u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
u->use_tsched = TRUE;
u->inotify_fd = -1;
if (pa_modargs_get_value_boolean(ma, "tsched", &u->use_tsched) < 0) {
pa_log("Failed to parse tsched argument.");
if (pa_modargs_get_value_boolean(ma, "tsched", &use_tsched) < 0) {
pa_log("Failed to parse tsched= argument.");
goto fail;
}
u->use_tsched = use_tsched;
if (pa_modargs_get_value_boolean(ma, "ignore_dB", &ignore_dB) < 0) {
pa_log("Failed to parse ignore_dB= argument.");
goto fail;
}
u->ignore_dB = ignore_dB;
if (!(u->udev = udev_new())) {
pa_log("Failed to initialize udev library.");

View file

@ -812,11 +812,11 @@ static void sink_get_volume(pa_sink *s) {
pa_assert(u->mixer_devmask & (SOUND_MASK_VOLUME|SOUND_MASK_PCM));
if (u->mixer_devmask & SOUND_MASK_VOLUME)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_VOLUME, &s->sample_spec, &s->virtual_volume) >= 0)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_VOLUME, &s->sample_spec, &s->real_volume) >= 0)
return;
if (u->mixer_devmask & SOUND_MASK_PCM)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_PCM, &s->sample_spec, &s->virtual_volume) >= 0)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_PCM, &s->sample_spec, &s->real_volume) >= 0)
return;
pa_log_info("Device doesn't support reading mixer settings: %s", pa_cstrerror(errno));
@ -830,11 +830,11 @@ static void sink_set_volume(pa_sink *s) {
pa_assert(u->mixer_devmask & (SOUND_MASK_VOLUME|SOUND_MASK_PCM));
if (u->mixer_devmask & SOUND_MASK_VOLUME)
if (pa_oss_set_volume(u->mixer_fd, SOUND_MIXER_WRITE_VOLUME, &s->sample_spec, &s->virtual_volume) >= 0)
if (pa_oss_set_volume(u->mixer_fd, SOUND_MIXER_WRITE_VOLUME, &s->sample_spec, &s->real_volume) >= 0)
return;
if (u->mixer_devmask & SOUND_MASK_PCM)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_WRITE_PCM, &s->sample_spec, &s->virtual_volume) >= 0)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_WRITE_PCM, &s->sample_spec, &s->real_volume) >= 0)
return;
pa_log_info("Device doesn't support writing mixer settings: %s", pa_cstrerror(errno));
@ -848,11 +848,11 @@ static void source_get_volume(pa_source *s) {
pa_assert(u->mixer_devmask & (SOUND_MASK_IGAIN|SOUND_MASK_RECLEV));
if (u->mixer_devmask & SOUND_MASK_IGAIN)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_IGAIN, &s->sample_spec, &s->virtual_volume) >= 0)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_IGAIN, &s->sample_spec, &s->volume) >= 0)
return;
if (u->mixer_devmask & SOUND_MASK_RECLEV)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_RECLEV, &s->sample_spec, &s->virtual_volume) >= 0)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_RECLEV, &s->sample_spec, &s->volume) >= 0)
return;
pa_log_info("Device doesn't support reading mixer settings: %s", pa_cstrerror(errno));
@ -866,11 +866,11 @@ static void source_set_volume(pa_source *s) {
pa_assert(u->mixer_devmask & (SOUND_MASK_IGAIN|SOUND_MASK_RECLEV));
if (u->mixer_devmask & SOUND_MASK_IGAIN)
if (pa_oss_set_volume(u->mixer_fd, SOUND_MIXER_WRITE_IGAIN, &s->sample_spec, &s->virtual_volume) >= 0)
if (pa_oss_set_volume(u->mixer_fd, SOUND_MIXER_WRITE_IGAIN, &s->sample_spec, &s->volume) >= 0)
return;
if (u->mixer_devmask & SOUND_MASK_RECLEV)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_WRITE_RECLEV, &s->sample_spec, &s->virtual_volume) >= 0)
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_WRITE_RECLEV, &s->sample_spec, &s->volume) >= 0)
return;
pa_log_info("Device doesn't support writing mixer settings: %s", pa_cstrerror(errno));

View file

@ -283,15 +283,15 @@ static void sink_set_volume_cb(pa_sink *s) {
/* Calculate the max volume of all channels.
We'll use this as our (single) volume on the APEX device and emulate
any variation in channel volumes in software */
v = pa_cvolume_max(&s->virtual_volume);
v = pa_cvolume_max(&s->real_volume);
/* Create a pa_cvolume version of our single value */
pa_cvolume_set(&hw, s->sample_spec.channels, v);
/* Perform any software manipulation of the volume needed */
pa_sw_cvolume_divide(&s->soft_volume, &s->virtual_volume, &hw);
pa_sw_cvolume_divide(&s->soft_volume, &s->real_volume, &hw);
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->virtual_volume));
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->real_volume));
pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &hw));
pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->soft_volume));

View file

@ -38,6 +38,7 @@ struct rm_monitor {
char *device_name;
char *service_name;
char *match;
DBusConnection *connection;
@ -51,12 +52,18 @@ struct rm_monitor {
#define SERVICE_PREFIX "org.freedesktop.ReserveDevice1."
#define SERVICE_FILTER \
"type='signal'," \
"sender='" DBUS_SERVICE_DBUS "'," \
"interface='" DBUS_INTERFACE_DBUS "'," \
"member='NameOwnerChanged'," \
"arg0='%s'"
static DBusHandlerResult filter_handler(
DBusConnection *c,
DBusMessage *s,
void *userdata) {
DBusMessage *reply;
rm_monitor *m;
DBusError error;
@ -97,31 +104,10 @@ static DBusHandlerResult filter_handler(
}
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
invalid:
if (!(reply = dbus_message_new_error(
s,
DBUS_ERROR_INVALID_ARGS,
"Invalid arguments")))
goto oom;
if (!dbus_connection_send(c, reply, NULL))
goto oom;
dbus_message_unref(reply);
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_HANDLED;
oom:
if (reply)
dbus_message_unref(reply);
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
int rm_watch(
@ -175,11 +161,13 @@ int rm_watch(
m->filtering = 1;
dbus_bus_add_match(m->connection,
"type='signal',"
"sender='" DBUS_SERVICE_DBUS "',"
"interface='" DBUS_INTERFACE_DBUS "',"
"member='NameOwnerChanged'", error);
if (!(m->match = malloc(sizeof(SERVICE_FILTER) - 2 + strlen(m->service_name)))) {
r = -ENOMEM;
goto fail;
}
sprintf(m->match, SERVICE_FILTER, m->service_name);
dbus_bus_add_match(m->connection, m->match, error);
if (dbus_error_is_set(error)) {
r = -EIO;
@ -220,10 +208,8 @@ void rm_release(rm_monitor *m) {
if (m->matching)
dbus_bus_remove_match(
m->connection,
"type='signal',"
"sender='" DBUS_SERVICE_DBUS "',"
"interface='" DBUS_INTERFACE_DBUS "',"
"member='NameOwnerChanged'", NULL);
m->match,
NULL);
if (m->filtering)
dbus_connection_remove_filter(
@ -233,6 +219,7 @@ void rm_release(rm_monitor *m) {
free(m->device_name);
free(m->service_name);
free(m->match);
if (m->connection)
dbus_connection_unref(m->connection);

View file

@ -291,7 +291,6 @@ static DBusHandlerResult filter_handler(
DBusMessage *m,
void *userdata) {
DBusMessage *reply;
rd_device *d;
DBusError error;
@ -323,35 +322,13 @@ static DBusHandlerResult filter_handler(
rd_release(d);
}
return DBUS_HANDLER_RESULT_HANDLED;
}
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
invalid:
if (!(reply = dbus_message_new_error(
m,
DBUS_ERROR_INVALID_ARGS,
"Invalid arguments")))
goto oom;
if (!dbus_connection_send(c, reply, NULL))
goto oom;
dbus_message_unref(reply);
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_HANDLED;
oom:
if (reply)
dbus_message_unref(reply);
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}