2009-01-15 18:29:16 +01:00
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
|
|
|
|
|
|
|
|
|
Copyright 2009 Lennart Poettering
|
|
|
|
|
|
|
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2009-03-03 20:23:02 +00:00
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
2009-01-15 18:29:16 +01:00
|
|
|
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
|
2014-11-26 14:14:51 +01:00
|
|
|
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
2009-01-15 18:29:16 +01:00
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <pulse/xmalloc.h>
|
2009-01-22 00:15:19 +01:00
|
|
|
#include <pulse/util.h>
|
2009-01-15 18:29:16 +01:00
|
|
|
|
|
|
|
|
#include <pulsecore/log.h>
|
|
|
|
|
#include <pulsecore/macro.h>
|
|
|
|
|
#include <pulsecore/core-util.h>
|
|
|
|
|
#include <pulsecore/namereg.h>
|
2011-11-25 15:17:13 +01:00
|
|
|
#include <pulsecore/device-port.h>
|
2009-01-15 18:29:16 +01:00
|
|
|
|
|
|
|
|
#include "card.h"
|
|
|
|
|
|
2009-01-17 02:03:35 +01:00
|
|
|
pa_card_profile *pa_card_profile_new(const char *name, const char *description, size_t extra) {
|
2009-01-15 23:44:46 +01:00
|
|
|
pa_card_profile *c;
|
2009-01-15 18:29:16 +01:00
|
|
|
|
|
|
|
|
pa_assert(name);
|
|
|
|
|
|
2015-05-05 17:01:07 +02:00
|
|
|
c = pa_xmalloc0(PA_ALIGN(sizeof(pa_card_profile)) + extra);
|
2009-01-15 18:29:16 +01:00
|
|
|
c->name = pa_xstrdup(name);
|
2009-01-17 02:03:35 +01:00
|
|
|
c->description = pa_xstrdup(description);
|
2013-02-19 18:26:03 +01:00
|
|
|
c->available = PA_AVAILABLE_UNKNOWN;
|
2009-01-20 20:35:18 +01:00
|
|
|
|
2009-01-15 18:29:16 +01:00
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 23:44:46 +01:00
|
|
|
void pa_card_profile_free(pa_card_profile *c) {
|
2009-01-15 18:29:16 +01:00
|
|
|
pa_assert(c);
|
|
|
|
|
|
2015-11-17 15:10:29 +01:00
|
|
|
pa_xfree(c->input_name);
|
|
|
|
|
pa_xfree(c->output_name);
|
2009-01-15 18:29:16 +01:00
|
|
|
pa_xfree(c->name);
|
2009-01-17 02:03:35 +01:00
|
|
|
pa_xfree(c->description);
|
2009-01-15 18:29:16 +01:00
|
|
|
pa_xfree(c);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-18 09:10:31 +01:00
|
|
|
void pa_card_profile_set_available(pa_card_profile *c, pa_available_t available) {
|
|
|
|
|
pa_core *core;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(c->card); /* Modify member variable directly during creation instead of using this function */
|
|
|
|
|
|
|
|
|
|
if (c->available == available)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
c->available = available;
|
|
|
|
|
pa_log_debug("Setting card %s profile %s to availability status %s", c->card->name, c->name,
|
|
|
|
|
available == PA_AVAILABLE_YES ? "yes" : available == PA_AVAILABLE_NO ? "no" : "unknown");
|
|
|
|
|
|
|
|
|
|
/* Post subscriptions to the card which owns us */
|
|
|
|
|
pa_assert_se(core = c->card->core);
|
|
|
|
|
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, c->card->index);
|
|
|
|
|
|
|
|
|
|
pa_hook_fire(&core->hooks[PA_CORE_HOOK_CARD_PROFILE_AVAILABLE_CHANGED], c);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 18:29:16 +01:00
|
|
|
pa_card_new_data* pa_card_new_data_init(pa_card_new_data *data) {
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
|
|
|
|
|
memset(data, 0, sizeof(*data));
|
|
|
|
|
data->proplist = pa_proplist_new();
|
2013-09-14 11:50:10 +05:30
|
|
|
data->profiles = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_card_profile_free);
|
|
|
|
|
data->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_device_port_unref);
|
2009-01-15 18:29:16 +01:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_card_new_data_set_name(pa_card_new_data *data, const char *name) {
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
|
|
|
|
|
pa_xfree(data->name);
|
|
|
|
|
data->name = pa_xstrdup(name);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 15:23:30 +02:00
|
|
|
void pa_card_new_data_set_preferred_port(pa_card_new_data *data, pa_direction_t direction, pa_device_port *port) {
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
|
|
|
|
|
if (direction == PA_DIRECTION_INPUT)
|
|
|
|
|
data->preferred_input_port = port;
|
|
|
|
|
else
|
|
|
|
|
data->preferred_output_port = port;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 18:29:16 +01:00
|
|
|
void pa_card_new_data_done(pa_card_new_data *data) {
|
|
|
|
|
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
|
|
|
|
|
pa_proplist_free(data->proplist);
|
|
|
|
|
|
2013-02-12 21:36:53 +02:00
|
|
|
if (data->profiles)
|
2013-09-14 11:50:10 +05:30
|
|
|
pa_hashmap_free(data->profiles);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
2011-11-25 15:17:13 +01:00
|
|
|
if (data->ports)
|
2013-09-14 11:50:10 +05:30
|
|
|
pa_hashmap_free(data->ports);
|
2011-11-25 15:17:13 +01:00
|
|
|
|
2009-01-15 18:29:16 +01:00
|
|
|
pa_xfree(data->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
|
|
|
|
|
pa_card *c;
|
|
|
|
|
const char *name;
|
2012-06-29 18:04:55 +03:00
|
|
|
void *state;
|
|
|
|
|
pa_card_profile *profile;
|
2013-01-17 20:55:14 +01:00
|
|
|
pa_device_port *port;
|
2009-01-15 18:29:16 +01:00
|
|
|
|
|
|
|
|
pa_core_assert_ref(core);
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
pa_assert(data->name);
|
2012-06-08 21:49:10 +03:00
|
|
|
pa_assert(data->profiles);
|
|
|
|
|
pa_assert(!pa_hashmap_isempty(data->profiles));
|
2009-01-15 18:29:16 +01:00
|
|
|
|
2015-09-28 14:37:49 +02:00
|
|
|
c = pa_xnew0(pa_card, 1);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
|
|
|
|
if (!(name = pa_namereg_register(core, data->name, PA_NAMEREG_CARD, c, data->namereg_fail))) {
|
|
|
|
|
pa_xfree(c);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_card_new_data_set_name(data, name);
|
2016-06-07 16:51:00 +03:00
|
|
|
pa_hook_fire(&core->hooks[PA_CORE_HOOK_CARD_NEW], data);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
|
|
|
|
c->core = core;
|
|
|
|
|
c->name = pa_xstrdup(data->name);
|
|
|
|
|
c->proplist = pa_proplist_copy(data->proplist);
|
2009-01-22 00:15:19 +01:00
|
|
|
c->driver = pa_xstrdup(pa_path_get_filename(data->driver));
|
2009-01-15 18:29:16 +01:00
|
|
|
c->module = data->module;
|
|
|
|
|
|
2009-01-15 18:38:20 +01:00
|
|
|
c->sinks = pa_idxset_new(NULL, NULL);
|
|
|
|
|
c->sources = pa_idxset_new(NULL, NULL);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
2009-01-21 02:46:36 +01:00
|
|
|
/* As a minor optimization we just steal the list instead of
|
|
|
|
|
* copying it here */
|
2013-01-22 08:54:57 +02:00
|
|
|
pa_assert_se(c->profiles = data->profiles);
|
2009-01-15 23:44:46 +01:00
|
|
|
data->profiles = NULL;
|
2013-01-22 08:54:57 +02:00
|
|
|
pa_assert_se(c->ports = data->ports);
|
2011-11-25 15:17:13 +01:00
|
|
|
data->ports = NULL;
|
2009-01-20 20:35:18 +01:00
|
|
|
|
2013-01-22 08:54:57 +02:00
|
|
|
PA_HASHMAP_FOREACH(profile, c->profiles, state)
|
|
|
|
|
profile->card = c;
|
2012-06-29 18:04:55 +03:00
|
|
|
|
2013-01-22 08:54:57 +02:00
|
|
|
PA_HASHMAP_FOREACH(port, c->ports, state)
|
|
|
|
|
port->card = c;
|
2013-01-17 20:55:14 +01:00
|
|
|
|
2016-03-04 15:23:30 +02:00
|
|
|
c->preferred_input_port = data->preferred_input_port;
|
|
|
|
|
c->preferred_output_port = data->preferred_output_port;
|
|
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
pa_device_init_description(c->proplist, c);
|
|
|
|
|
pa_device_init_icon(c->proplist, true);
|
|
|
|
|
pa_device_init_intended_roles(c->proplist);
|
2009-01-21 02:46:36 +01:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
return c;
|
|
|
|
|
}
|
2013-11-03 15:05:34 +02:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
void pa_card_choose_initial_profile(pa_card *card) {
|
|
|
|
|
pa_card_profile *profile;
|
|
|
|
|
void *state;
|
|
|
|
|
pa_card_profile *best = NULL;
|
|
|
|
|
|
|
|
|
|
pa_assert(card);
|
|
|
|
|
|
|
|
|
|
/* By default, pick the highest priority profile that is not unavailable,
|
|
|
|
|
* or if all profiles are unavailable, pick the profile with the highest
|
|
|
|
|
* priority regardless of its availability. */
|
|
|
|
|
|
|
|
|
|
PA_HASHMAP_FOREACH(profile, card->profiles, state) {
|
|
|
|
|
if (profile->available == PA_AVAILABLE_NO)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!best || profile->priority > best->priority)
|
|
|
|
|
best = profile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!best) {
|
|
|
|
|
PA_HASHMAP_FOREACH(profile, card->profiles, state) {
|
|
|
|
|
if (!best || profile->priority > best->priority)
|
|
|
|
|
best = profile;
|
2013-11-15 09:33:37 +01:00
|
|
|
}
|
2009-01-21 02:46:36 +01:00
|
|
|
}
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
pa_assert(best);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
card->active_profile = best;
|
|
|
|
|
card->save_profile = false;
|
2009-03-01 21:34:01 +01:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
/* Let policy modules override the default. */
|
|
|
|
|
pa_hook_fire(&card->core->hooks[PA_CORE_HOOK_CARD_CHOOSE_INITIAL_PROFILE], card);
|
|
|
|
|
}
|
2009-01-15 18:29:16 +01:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
void pa_card_put(pa_card *card) {
|
|
|
|
|
pa_assert(card);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
pa_assert_se(pa_idxset_put(card->core->cards, card, &card->index) >= 0);
|
|
|
|
|
card->linked = true;
|
|
|
|
|
|
|
|
|
|
pa_log_info("Created %u \"%s\"", card->index, card->name);
|
|
|
|
|
pa_hook_fire(&card->core->hooks[PA_CORE_HOOK_CARD_PUT], card);
|
|
|
|
|
pa_subscription_post(card->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_NEW, card->index);
|
2009-01-15 18:29:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_card_free(pa_card *c) {
|
|
|
|
|
pa_core *core;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(c->core);
|
|
|
|
|
|
|
|
|
|
core = c->core;
|
|
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
if (c->linked) {
|
|
|
|
|
pa_hook_fire(&core->hooks[PA_CORE_HOOK_CARD_UNLINK], c);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
pa_idxset_remove_by_data(c->core->cards, c, NULL);
|
|
|
|
|
pa_log_info("Freed %u \"%s\"", c->index, c->name);
|
|
|
|
|
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
|
|
|
|
|
}
|
2009-01-15 18:29:16 +01:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
pa_namereg_unregister(core, c->name);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
2009-01-15 18:38:20 +01:00
|
|
|
pa_assert(pa_idxset_isempty(c->sinks));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->sinks, NULL);
|
2009-01-15 18:38:20 +01:00
|
|
|
pa_assert(pa_idxset_isempty(c->sources));
|
2013-02-12 21:36:55 +02:00
|
|
|
pa_idxset_free(c->sources, NULL);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
2013-09-14 11:50:10 +05:30
|
|
|
pa_hashmap_free(c->ports);
|
2011-11-25 15:17:13 +01:00
|
|
|
|
2013-02-12 21:36:53 +02:00
|
|
|
if (c->profiles)
|
2013-09-14 11:50:10 +05:30
|
|
|
pa_hashmap_free(c->profiles);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
|
|
|
|
pa_proplist_free(c->proplist);
|
|
|
|
|
pa_xfree(c->driver);
|
|
|
|
|
pa_xfree(c->name);
|
|
|
|
|
pa_xfree(c);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 18:56:39 +02:00
|
|
|
void pa_card_add_profile(pa_card *c, pa_card_profile *profile) {
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(profile);
|
|
|
|
|
|
|
|
|
|
/* take ownership of the profile */
|
|
|
|
|
pa_assert_se(pa_hashmap_put(c->profiles, profile->name, profile) >= 0);
|
|
|
|
|
profile->card = c;
|
|
|
|
|
|
|
|
|
|
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
|
|
|
|
|
|
|
|
|
|
pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], profile);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 15:10:32 +01:00
|
|
|
static const char* profile_name_for_dir(pa_card_profile *cp, pa_direction_t dir) {
|
|
|
|
|
if (dir == PA_DIRECTION_OUTPUT && cp->output_name)
|
|
|
|
|
return cp->output_name;
|
|
|
|
|
if (dir == PA_DIRECTION_INPUT && cp->input_name)
|
|
|
|
|
return cp->input_name;
|
|
|
|
|
return cp->name;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 14:29:23 +01:00
|
|
|
static void update_port_preferred_profile(pa_card *c) {
|
2015-11-17 15:10:32 +01:00
|
|
|
pa_sink *sink;
|
|
|
|
|
pa_source *source;
|
|
|
|
|
uint32_t state;
|
2012-06-08 21:49:10 +03:00
|
|
|
|
2015-11-26 14:29:23 +01:00
|
|
|
PA_IDXSET_FOREACH(sink, c->sinks, state)
|
|
|
|
|
if (sink->active_port)
|
|
|
|
|
pa_device_port_set_preferred_profile(sink->active_port, profile_name_for_dir(c->active_profile, PA_DIRECTION_OUTPUT));
|
|
|
|
|
PA_IDXSET_FOREACH(source, c->sources, state)
|
|
|
|
|
if (source->active_port)
|
|
|
|
|
pa_device_port_set_preferred_profile(source->active_port, profile_name_for_dir(c->active_profile, PA_DIRECTION_INPUT));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pa_card_set_profile(pa_card *c, pa_card_profile *profile, bool save) {
|
|
|
|
|
int r;
|
|
|
|
|
|
2009-01-15 18:29:16 +01:00
|
|
|
pa_assert(c);
|
2013-11-20 15:42:26 +02:00
|
|
|
pa_assert(profile);
|
|
|
|
|
pa_assert(profile->card == c);
|
2009-01-15 18:29:16 +01:00
|
|
|
|
2009-01-15 23:44:46 +01:00
|
|
|
if (!c->set_profile) {
|
2009-06-17 03:15:56 +02:00
|
|
|
pa_log_debug("set_profile() operation not implemented for card %u \"%s\"", c->index, c->name);
|
|
|
|
|
return -PA_ERR_NOTIMPLEMENTED;
|
2009-01-15 18:29:16 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-23 19:31:36 +01:00
|
|
|
if (c->active_profile == profile) {
|
2015-11-26 14:29:23 +01:00
|
|
|
if (save && !c->save_profile) {
|
|
|
|
|
update_port_preferred_profile(c);
|
|
|
|
|
c->save_profile = true;
|
|
|
|
|
}
|
2009-01-17 02:03:35 +01:00
|
|
|
return 0;
|
2009-03-23 19:31:36 +01:00
|
|
|
}
|
2009-01-17 02:03:35 +01:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
/* If we're setting the initial profile, we shouldn't call set_profile(),
|
|
|
|
|
* because the implementations don't expect that (for historical reasons).
|
|
|
|
|
* We should just set c->active_profile, and the implementations will
|
|
|
|
|
* properly set up that profile after pa_card_put() has returned. It would
|
|
|
|
|
* be probably good to change this so that also the initial profile can be
|
|
|
|
|
* set up in set_profile(), but if set_profile() fails, that would need
|
|
|
|
|
* some better handling than what we do here currently. */
|
|
|
|
|
if (c->linked && (r = c->set_profile(c, profile)) < 0)
|
2009-06-17 03:15:56 +02:00
|
|
|
return r;
|
2009-01-15 18:29:16 +01:00
|
|
|
|
2009-01-21 01:59:15 +01:00
|
|
|
c->active_profile = profile;
|
2009-03-23 19:31:36 +01:00
|
|
|
c->save_profile = save;
|
2009-01-21 01:59:15 +01:00
|
|
|
|
2015-11-26 14:29:23 +01:00
|
|
|
if (save)
|
|
|
|
|
update_port_preferred_profile(c);
|
2015-11-17 15:10:32 +01:00
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
if (c->linked) {
|
|
|
|
|
pa_log_info("Changed profile of card %u \"%s\" to %s", c->index, c->name, profile->name);
|
|
|
|
|
pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], c);
|
|
|
|
|
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
|
|
|
|
|
}
|
2011-02-25 10:27:23 +00:00
|
|
|
|
2009-01-15 18:29:16 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2009-01-22 00:17:11 +01:00
|
|
|
|
2016-03-04 15:23:30 +02:00
|
|
|
void pa_card_set_preferred_port(pa_card *c, pa_direction_t direction, pa_device_port *port) {
|
|
|
|
|
pa_device_port *old_port;
|
|
|
|
|
const char *old_port_str;
|
|
|
|
|
const char *new_port_str;
|
|
|
|
|
pa_card_preferred_port_changed_hook_data data;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
|
|
|
|
|
if (direction == PA_DIRECTION_INPUT) {
|
|
|
|
|
old_port = c->preferred_input_port;
|
|
|
|
|
old_port_str = c->preferred_input_port ? c->preferred_input_port->name : "(unset)";
|
|
|
|
|
} else {
|
|
|
|
|
old_port = c->preferred_output_port;
|
|
|
|
|
old_port_str = c->preferred_output_port ? c->preferred_output_port->name : "(unset)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (port == old_port)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
new_port_str = port ? port->name : "(unset)";
|
|
|
|
|
|
|
|
|
|
if (direction == PA_DIRECTION_INPUT) {
|
|
|
|
|
c->preferred_input_port = port;
|
|
|
|
|
pa_log_debug("%s: preferred_input_port: %s -> %s", c->name, old_port_str, new_port_str);
|
|
|
|
|
} else {
|
|
|
|
|
c->preferred_output_port = port;
|
|
|
|
|
pa_log_debug("%s: preferred_output_port: %s -> %s", c->name, old_port_str, new_port_str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.card = c;
|
|
|
|
|
data.direction = direction;
|
|
|
|
|
pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CARD_PREFERRED_PORT_CHANGED], &data);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
int pa_card_suspend(pa_card *c, bool suspend, pa_suspend_cause_t cause) {
|
2009-01-22 00:17:11 +01:00
|
|
|
pa_sink *sink;
|
|
|
|
|
pa_source *source;
|
2016-05-09 15:09:57 +05:30
|
|
|
pa_suspend_cause_t suspend_cause;
|
2009-01-22 00:17:11 +01:00
|
|
|
uint32_t idx;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
2009-06-05 19:05:07 +02:00
|
|
|
pa_assert(cause != 0);
|
2009-01-22 00:17:11 +01:00
|
|
|
|
2016-05-09 15:09:57 +05:30
|
|
|
suspend_cause = c->suspend_cause;
|
|
|
|
|
|
2016-04-20 15:35:13 +03:00
|
|
|
if (suspend)
|
2016-05-09 15:09:57 +05:30
|
|
|
suspend_cause |= cause;
|
2016-04-20 15:35:13 +03:00
|
|
|
else
|
2016-05-09 15:09:57 +05:30
|
|
|
suspend_cause &= ~cause;
|
|
|
|
|
|
|
|
|
|
if (c->suspend_cause != suspend_cause) {
|
|
|
|
|
pa_log_debug("Card suspend causes/state changed");
|
|
|
|
|
c->suspend_cause = suspend_cause;
|
|
|
|
|
pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CARD_SUSPEND_CHANGED], c);
|
|
|
|
|
}
|
2016-04-20 15:35:13 +03:00
|
|
|
|
2012-05-29 17:58:12 +05:30
|
|
|
PA_IDXSET_FOREACH(sink, c->sinks, idx) {
|
2009-06-17 03:15:56 +02:00
|
|
|
int r;
|
2009-01-22 00:17:11 +01:00
|
|
|
|
2009-06-17 03:15:56 +02:00
|
|
|
if ((r = pa_sink_suspend(sink, suspend, cause)) < 0)
|
|
|
|
|
ret = r;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 17:58:12 +05:30
|
|
|
PA_IDXSET_FOREACH(source, c->sources, idx) {
|
2009-06-17 03:15:56 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
if ((r = pa_source_suspend(source, suspend, cause)) < 0)
|
|
|
|
|
ret = r;
|
|
|
|
|
}
|
2009-01-22 00:17:11 +01:00
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|