Lines Matching refs:port
27 #include <pulsecore/device-port.h>
65 static bool profile_good_for_output(pa_card_profile *profile, pa_device_port *port) {
86 if (port == card->preferred_output_port)
93 if ((sink->active_port->available != PA_AVAILABLE_NO) && (sink->active_port->priority >= port->priority))
100 static bool profile_good_for_input(pa_card_profile *profile, pa_device_port *port) {
121 if (port == card->preferred_input_port)
128 if ((source->active_port->available != PA_AVAILABLE_NO) && (source->active_port->priority >= port->priority))
135 static int try_to_switch_profile(pa_device_port *port) {
140 if (port->card->profile_is_sticky) {
141 pa_log_info("Keeping sticky card profile '%s'", port->card->active_profile->name);
145 pa_log_debug("Finding best profile for port %s, preferred = %s",
146 port->name, pa_strnull(port->preferred_profile));
148 PA_HASHMAP_FOREACH(profile, port->profiles, state) {
154 switch (port->direction) {
157 good = profile_good_for_output(profile, port);
162 good = profile_good_for_input(profile, port);
170 if (pa_safe_streq(name ? name : profile->name, port->preferred_profile))
185 if (pa_card_set_profile(port->card, best_profile, false) != 0) {
194 pa_device_port *port;
210 static struct port_pointers find_port_pointers(pa_device_port *port) {
211 struct port_pointers pp = { .port = port };
215 pa_assert(port);
216 pa_assert_se(card = port->card);
218 switch (port->direction) {
221 if (port == pa_hashmap_get(pp.sink->ports, port->name))
227 if (port == pa_hashmap_get(pp.source->ports, port->name))
233 card->active_profile == pa_hashmap_get(port->profiles, card->active_profile->name);
234 pp.is_preferred_profile_active = pp.is_possible_profile_active && (!port->preferred_profile ||
235 pa_safe_streq(port->preferred_profile, profile_name_for_dir(card->active_profile, port->direction)));
236 pp.is_port_active = (pp.sink && pp.sink->active_port == port) || (pp.source && pp.source->active_port == port);
241 /* Switches to a port, switching profiles if necessary or preferred */
242 static void switch_to_port(pa_device_port *port, struct port_pointers pp) {
246 pa_log_debug("Trying to switch to port %s", port->name);
248 if (try_to_switch_profile(port) < 0) {
254 pp = find_port_pointers(port);
258 pa_source_set_port(pp.source, port->name, false);
260 pa_sink_set_port(pp.sink, port->name, false);
263 /* Switches away from a port, switching profiles if necessary or preferred */
264 static void switch_from_port(pa_device_port *port, struct port_pointers pp) {
271 /* Try to find a good enough port to switch to */
272 PA_HASHMAP_FOREACH(p, port->card->ports, state) {
273 if (p == port)
279 if (p->direction != port->direction)
286 pa_log_debug("Trying to switch away from port %s, found %s", port->name, best_port ? best_port->name : "no better option");
288 /* If there is no available port to switch to we need check if the active
299 static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port *port, void* userdata) {
300 struct port_pointers pp = find_port_pointers(port);
302 if (!port->card) {
303 pa_log_warn("Port %s does not have a card", port->name);
311 * module-switch-on-port-available. */
312 if (pa_safe_streq(pa_proplist_gets(port->card->proplist, PA_PROP_DEVICE_BUS), "bluetooth"))
315 switch (port->available) {
317 /* If a port availability became unknown, let's see if it's part of
323 * the headphone port at least, so that we have don't break
339 /* Not part of a group of ports, so likely not a combination port */
340 if (!port->availability_group) {
341 pa_log_debug("Not switching to port %s, its availability is unknown and it's not in any availability group.", port->name);
345 /* Switch the headphone port, the input ports without source and the
348 if (port->direction == PA_DIRECTION_INPUT && pp.source && !pp.source->active_port->availability_group) {
349 pa_log_debug("Not switching to input port %s, its availability is unknown.", port->name);
353 switch_to_port(port, pp);
357 switch_to_port(port, pp);
360 switch_from_port(port, pp);
416 pa_device_port *port;
419 PA_HASHMAP_FOREACH(port, card->ports, state2) {
420 if (port->available == PA_AVAILABLE_NO)
421 port_available_hook_callback(core, port, NULL);
453 pa_log_debug("Switching initial port for sink '%s' to '%s'", new_data->name, p->name);
464 pa_log_debug("Switching initial port for source '%s' to '%s'", new_data->name, p->name);
486 * the user's input port preference. */
499 * whether the user wanted to activate some specific input port, or was the
511 * wanted to activate the port that was selected by default, but if that's
512 * the case, the user will change the port manually, and we'll update the
513 * port preference at that time. If no port change occurs, we can assume
514 * that the user likes the port that is now active. */
522 * the user's output port preference. */
535 * whether the user wanted to activate some specific output port, or was
547 * wanted to activate the port that was selected by default, but if that's
548 * the case, the user will change the port manually, and we'll update the
549 * port preference at that time. If no port change occurs, we can assume
550 * that the user likes the port that is now active. */
565 * a change in the user's port preferences. */