mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
alsa: rework mixer logic
Completely rework mixer logic. This now allows controlling a full set of elements from a single sink's volume slider/mute button. This also introduces sink and source "ports" that can be used to choose different input or output ports with the UI. (i.e. "mic"/"line-in" or "speaker"/"headphones". The mixer paths and device maps are now configered in external configuration files and can be tweaked as necessary.
This commit is contained in:
parent
e9c70ac41b
commit
31575f7766
54 changed files with 7029 additions and 1694 deletions
|
|
@ -93,11 +93,29 @@ void pa_source_new_data_set_muted(pa_source_new_data *data, pa_bool_t mute) {
|
|||
data->muted = !!mute;
|
||||
}
|
||||
|
||||
void pa_source_new_data_set_port(pa_source_new_data *data, const char *port) {
|
||||
pa_assert(data);
|
||||
|
||||
pa_xfree(data->active_port);
|
||||
data->active_port = pa_xstrdup(port);
|
||||
}
|
||||
|
||||
void pa_source_new_data_done(pa_source_new_data *data) {
|
||||
pa_assert(data);
|
||||
|
||||
pa_xfree(data->name);
|
||||
pa_proplist_free(data->proplist);
|
||||
|
||||
if (data->ports) {
|
||||
pa_device_port *p;
|
||||
|
||||
while ((p = pa_hashmap_steal_first(data->ports)))
|
||||
pa_device_port_free(p);
|
||||
|
||||
pa_hashmap_free(data->ports, NULL, NULL);
|
||||
}
|
||||
|
||||
pa_xfree(data->name);
|
||||
pa_xfree(data->active_port);
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
|
|
@ -110,6 +128,7 @@ static void reset_callbacks(pa_source *s) {
|
|||
s->get_mute = NULL;
|
||||
s->set_mute = NULL;
|
||||
s->update_requested_latency = NULL;
|
||||
s->set_port = NULL;
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
|
|
@ -142,6 +161,8 @@ pa_source* pa_source_new(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* FIXME, need to free s here on failure */
|
||||
|
||||
pa_return_null_if_fail(!data->driver || pa_utf8_valid(data->driver));
|
||||
pa_return_null_if_fail(data->name && pa_utf8_valid(data->name) && data->name[0]);
|
||||
|
||||
|
|
@ -210,6 +231,30 @@ pa_source* pa_source_new(
|
|||
s->asyncmsgq = NULL;
|
||||
s->rtpoll = NULL;
|
||||
|
||||
/* As a minor optimization we just steal the list instead of
|
||||
* copying it here */
|
||||
s->ports = data->ports;
|
||||
data->ports = NULL;
|
||||
|
||||
s->active_port = NULL;
|
||||
s->save_port = FALSE;
|
||||
|
||||
if (data->active_port && s->ports)
|
||||
if ((s->active_port = pa_hashmap_get(s->ports, data->active_port)))
|
||||
s->save_port = data->save_port;
|
||||
|
||||
if (!s->active_port && s->ports) {
|
||||
void *state;
|
||||
pa_device_port *p;
|
||||
|
||||
PA_HASHMAP_FOREACH(p, s->ports, state)
|
||||
if (!s->active_port || p->priority > s->active_port->priority)
|
||||
s->active_port = p;
|
||||
}
|
||||
|
||||
s->save_volume = data->save_volume;
|
||||
s->save_muted = data->save_muted;
|
||||
|
||||
pa_silence_memchunk_get(
|
||||
&core->silence_cache,
|
||||
core->mempool,
|
||||
|
|
@ -400,6 +445,15 @@ static void source_free(pa_object *o) {
|
|||
if (s->proplist)
|
||||
pa_proplist_free(s->proplist);
|
||||
|
||||
if (s->ports) {
|
||||
pa_device_port *p;
|
||||
|
||||
while ((p = pa_hashmap_steal_first(s->ports)))
|
||||
pa_device_port_free(p);
|
||||
|
||||
pa_hashmap_free(s->ports, NULL, NULL);
|
||||
}
|
||||
|
||||
pa_xfree(s);
|
||||
}
|
||||
|
||||
|
|
@ -472,15 +526,15 @@ int pa_source_sync_suspend(pa_source *s) {
|
|||
}
|
||||
|
||||
/* Called from main context */
|
||||
pa_queue *pa_source_move_all_start(pa_source *s) {
|
||||
pa_queue *q;
|
||||
pa_queue *pa_source_move_all_start(pa_source *s, pa_queue *q) {
|
||||
pa_source_output *o, *n;
|
||||
uint32_t idx;
|
||||
|
||||
pa_source_assert_ref(s);
|
||||
pa_assert(PA_SOURCE_IS_LINKED(s->state));
|
||||
|
||||
q = pa_queue_new();
|
||||
if (!q)
|
||||
q = pa_queue_new();
|
||||
|
||||
for (o = PA_SOURCE_OUTPUT(pa_idxset_first(s->outputs, &idx)); o; o = n) {
|
||||
n = PA_SOURCE_OUTPUT(pa_idxset_next(s->outputs, &idx));
|
||||
|
|
@ -667,7 +721,7 @@ pa_usec_t pa_source_get_latency_within_thread(pa_source *s) {
|
|||
}
|
||||
|
||||
/* Called from main thread */
|
||||
void pa_source_set_volume(pa_source *s, const pa_cvolume *volume) {
|
||||
void pa_source_set_volume(pa_source *s, const pa_cvolume *volume, pa_bool_t save) {
|
||||
pa_cvolume old_virtual_volume;
|
||||
pa_bool_t virtual_volume_changed;
|
||||
|
||||
|
|
@ -680,6 +734,7 @@ void pa_source_set_volume(pa_source *s, const pa_cvolume *volume) {
|
|||
old_virtual_volume = s->virtual_volume;
|
||||
s->virtual_volume = *volume;
|
||||
virtual_volume_changed = !pa_cvolume_equal(&old_virtual_volume, &s->virtual_volume);
|
||||
s->save_volume = (!virtual_volume_changed && s->save_volume) || save;
|
||||
|
||||
if (s->set_volume) {
|
||||
pa_cvolume_reset(&s->soft_volume, s->sample_spec.channels);
|
||||
|
|
@ -725,20 +780,24 @@ const pa_cvolume *pa_source_get_volume(pa_source *s, pa_bool_t force_refresh) {
|
|||
}
|
||||
|
||||
/* Called from main thread */
|
||||
void pa_source_volume_changed(pa_source *s, const pa_cvolume *new_volume) {
|
||||
void pa_source_volume_changed(pa_source *s, const pa_cvolume *new_volume, pa_bool_t save) {
|
||||
pa_source_assert_ref(s);
|
||||
|
||||
/* The source implementor may call this if the volume changed to make sure everyone is notified */
|
||||
|
||||
if (pa_cvolume_equal(&s->virtual_volume, new_volume))
|
||||
if (pa_cvolume_equal(&s->virtual_volume, new_volume)) {
|
||||
s->save_volume = s->save_volume || save;
|
||||
return;
|
||||
}
|
||||
|
||||
s->virtual_volume = *new_volume;
|
||||
s->save_volume = save;
|
||||
|
||||
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
|
||||
}
|
||||
|
||||
/* Called from main thread */
|
||||
void pa_source_set_mute(pa_source *s, pa_bool_t mute) {
|
||||
void pa_source_set_mute(pa_source *s, pa_bool_t mute, pa_bool_t save) {
|
||||
pa_bool_t old_muted;
|
||||
|
||||
pa_source_assert_ref(s);
|
||||
|
|
@ -746,6 +805,7 @@ void pa_source_set_mute(pa_source *s, pa_bool_t mute) {
|
|||
|
||||
old_muted = s->muted;
|
||||
s->muted = mute;
|
||||
s->save_muted = (old_muted == s->muted && s->save_muted) || save;
|
||||
|
||||
if (s->set_mute)
|
||||
s->set_mute(s);
|
||||
|
|
@ -781,15 +841,19 @@ pa_bool_t pa_source_get_mute(pa_source *s, pa_bool_t force_refresh) {
|
|||
}
|
||||
|
||||
/* Called from main thread */
|
||||
void pa_source_mute_changed(pa_source *s, pa_bool_t new_muted) {
|
||||
void pa_source_mute_changed(pa_source *s, pa_bool_t new_muted, pa_bool_t save) {
|
||||
pa_source_assert_ref(s);
|
||||
|
||||
/* The source implementor may call this if the mute state changed to make sure everyone is notified */
|
||||
|
||||
if (s->muted == new_muted)
|
||||
if (s->muted == new_muted) {
|
||||
s->save_muted = s->save_muted || save;
|
||||
return;
|
||||
}
|
||||
|
||||
s->muted = new_muted;
|
||||
s->save_muted = save;
|
||||
|
||||
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
|
||||
}
|
||||
|
||||
|
|
@ -866,7 +930,7 @@ unsigned pa_source_check_suspend(pa_source *s) {
|
|||
|
||||
ret = 0;
|
||||
|
||||
for (o = PA_SOURCE_OUTPUT(pa_idxset_first(s->outputs, &idx)); o; o = PA_SOURCE_OUTPUT(pa_idxset_next(s->outputs, &idx))) {
|
||||
PA_IDXSET_FOREACH(o, s->outputs, idx) {
|
||||
pa_source_output_state_t st;
|
||||
|
||||
st = pa_source_output_get_state(o);
|
||||
|
|
@ -1323,3 +1387,38 @@ size_t pa_source_get_max_rewind(pa_source *s) {
|
|||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
int pa_source_set_port(pa_source *s, const char *name, pa_bool_t save) {
|
||||
pa_device_port *port;
|
||||
|
||||
pa_assert(s);
|
||||
|
||||
if (!s->set_port) {
|
||||
pa_log_debug("set_port() operation not implemented for sink %u \"%s\"", s->index, s->name);
|
||||
return -PA_ERR_NOTIMPLEMENTED;
|
||||
}
|
||||
|
||||
if (!s->ports)
|
||||
return -PA_ERR_NOENTITY;
|
||||
|
||||
if (!(port = pa_hashmap_get(s->ports, name)))
|
||||
return -PA_ERR_NOENTITY;
|
||||
|
||||
if (s->active_port == port) {
|
||||
s->save_port = s->save_port || save;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((s->set_port(s, port)) < 0)
|
||||
return -PA_ERR_NOENTITY;
|
||||
|
||||
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
|
||||
|
||||
pa_log_info("Changed port of source %u \"%s\" to %s", s->index, s->name, port->name);
|
||||
|
||||
s->active_port = port;
|
||||
s->save_port = save;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue