The abstraction provided by edges allows simpler fallback initial routing code. --- src/pulsecore/node.c | 198 +++++++++++---------------------------------------- 1 file changed, 41 insertions(+), 157 deletions(-) diff --git a/src/pulsecore/node.c b/src/pulsecore/node.c index 41e95ee..530c9b2 100644 --- a/src/pulsecore/node.c +++ b/src/pulsecore/node.c @@ -179,202 +179,86 @@ void pa_node_free(pa_node *node) { } static void set_initial_routing_fallback(pa_node_set_initial_routing_hook_data *data) { - int r; - pa_node *node; - pa_sink_input *sink_input; - pa_source_output *source_output; - pa_sink *sink; - pa_source *source; - pa_node *other_node; - pa_device_port *port; + pa_node *routee; + pa_node *routing_target; + pa_node *input; + pa_node *output; pa_assert(data); - node = data->node; + routee = data->node; - if (node->type != PA_NODE_TYPE_SINK_INPUT && node->type != PA_NODE_TYPE_SOURCE_OUTPUT) { + if (routee->type != PA_NODE_TYPE_SINK_INPUT && routee->type != PA_NODE_TYPE_SOURCE_OUTPUT) { if (data->n_requested_connections == 0) data->ret = 0; else { - pa_log_info("Can't set initial routing for node %s, operation not supported for node type %s.", node->name, - pa_node_type_to_string(node->type)); + pa_log_info("Can't set initial routing for node %s, operation not supported for node type %s.", routee->name, + pa_node_type_to_string(routee->type)); data->ret = -PA_ERR_NOTSUPPORTED; } return; } - if (node->type == PA_NODE_TYPE_SINK_INPUT) - sink_input = node->owner; - else - source_output = node->owner; - if (data->n_requested_connections > 1) { - pa_log_info("Can't set initial routing for node %s, multiple connections not supported.", node->name); + pa_log_info("Can't set initial routing for node %s, multiple connections not supported.", routee->name); data->ret = -PA_ERR_NOTSUPPORTED; return; } if (data->n_requested_connections == 0) { - if (node->type == PA_NODE_TYPE_SINK_INPUT) { - sink = pa_namereg_get_default_sink(node->core); - if (!sink) { - pa_log_info("Can't set initial routing for node %s, no sinks available.", node->name); + if (routee->type == PA_NODE_TYPE_SINK_INPUT) { + pa_sink *default_sink; + + default_sink = pa_namereg_get_default_sink(routee->core); + if (default_sink) { + input = routee; + output = pa_sink_get_node(default_sink); + } else { + pa_log_info("No default sink available."); data->ret = -PA_ERR_NOENTITY; return; } - - r = pa_sink_input_set_initial_sink(sink_input, sink); - if (r < 0) { - pa_log_info("Can't set initial routing for node %s, format negotiation with the default sink (%s) failed.", - node->name, sink->name); - data->ret = r; - return; - } - - data->ret = 0; - return; } else { - source = pa_namereg_get_default_source(node->core); - if (!source) { - pa_log_info("Can't set initial routing for node %s, no sources available.", node->name); + pa_source *default_source; + + default_source = pa_namereg_get_default_source(routee->core); + if (default_source) { + input = pa_source_get_node(default_source); + output = routee; + } else { + pa_log_info("No default source available."); data->ret = -PA_ERR_NOENTITY; return; } + } - r = pa_source_output_set_initial_source(source_output, source); - if (r < 0) { - pa_log_info("Can't set initial routing for node %s, format negotiation with the default source (%s) failed.", - node->name, source->name); - data->ret = r; - return; - } + data->ret = pa_core_create_edge(routee->core, input, output, NULL); - data->ret = 0; - return; - } + return; } pa_assert(data->n_requested_connections == 1); - other_node = data->requested_connections[0]; - if (!other_node->active) { + if (routee->type == PA_NODE_TYPE_SINK_INPUT) { + input = routee; + output = routing_target = data->requested_connections[0]; + } else { + input = routing_target = data->requested_connections[0]; + output = routee; + } + + if (!routing_target->active) { /* Let's keep the fallback policy simple, and not try to activate any * inactive nodes. */ - pa_log_info("Can't connect %s to %s, %s is not active.", node->name, other_node->name, other_node->name); + pa_log_info("Can't connect %s to %s, %s is not active.", input->name, output->name, routing_target->name); data->ret = -PA_ERR_INVALID; return; } - if (node->type == PA_NODE_TYPE_SINK_INPUT) { - if (other_node->direction != PA_DIRECTION_OUTPUT) { - pa_log_info("Can't connect %s to %s, both are input nodes.", node->name, other_node->name); - data->ret = -PA_ERR_INVALID; - return; - } - - if (other_node->type == PA_NODE_TYPE_SINK) { - sink = other_node->owner; + data->ret = pa_core_create_edge(routee->core, input, output, NULL); - r = pa_sink_input_set_initial_sink(sink_input, sink); - if (r < 0) { - pa_log_info("Can't connect %s to %s, pa_sink_input_set_initial_sink() failed.", node->name, other_node->name); - data->ret = r; - return; - } - - data->ret = 0; - return; - } - - if (other_node->type == PA_NODE_TYPE_PORT) { - port = other_node->owner; - sink = port->device; - pa_assert(sink); /* We have checked that other_node is active. */ - - r = pa_sink_input_set_initial_sink(sink_input, sink); - if (r < 0) { - pa_log_info("Can't connect %s to %s, pa_sink_input_set_initial_sink() failed.", node->name, other_node->name); - data->ret = r; - return; - } - - data->ret = 0; - return; - } - - pa_log_info("Can't connect %s to %s, connections from type %s to type %s are not supported.", node->name, - other_node->name, pa_node_type_to_string(node->type), pa_node_type_to_string(other_node->type)); - data->ret = -PA_ERR_NOTSUPPORTED; - return; - } - - if (node->type == PA_NODE_TYPE_SOURCE_OUTPUT) { - if (other_node->direction != PA_DIRECTION_INPUT) { - pa_log_info("Can't connect %s to %s, both are output nodes.", node->name, other_node->name); - data->ret = -PA_ERR_INVALID; - return; - } - - if (other_node->type == PA_NODE_TYPE_SOURCE) { - source = other_node->owner; - - r = pa_source_output_set_initial_source(source_output, source); - if (r < 0) { - pa_log_info("Can't connect %s to %s, pa_source_output_set_initial_source() failed.", node->name, - other_node->name); - data->ret = r; - return; - } - - data->ret = 0; - return; - } - - if (other_node->type == PA_NODE_TYPE_PORT || other_node->type == PA_NODE_TYPE_PORT_MONITOR) { - port = other_node->owner; - - if (other_node->type == PA_NODE_TYPE_PORT) - source = port->device; - else - source = ((pa_sink *) port->device)->monitor_source; - - pa_assert(source); /* We have checked that other_node is active. */ - - r = pa_source_output_set_initial_source(source_output, source); - if (r < 0) { - pa_log_info("Can't connect %s to %s, pa_source_output_set_initial_source() failed.", node->name, - other_node->name); - data->ret = r; - return; - } - - data->ret = 0; - return; - } - - if (other_node->type == PA_NODE_TYPE_SINK_INPUT) { - pa_sink_input *input = other_node->owner; - - r = pa_source_output_set_direct_on_input(source_output, input); - if (r < 0) { - pa_log_info("Can't connect %s to %s, pa_source_output_set_direct_on_input() failed.", node->name, - other_node->name); - data->ret = r; - return; - } - - data->ret = 0; - return; - } - - pa_log_info("Can't connect %s to %s, connections from type %s to type %s are not supported.", node->name, - other_node->name, pa_node_type_to_string(node->type), pa_node_type_to_string(other_node->type)); - data->ret = -PA_ERR_NOTSUPPORTED; - return; - } - - pa_assert_not_reached(); + return; } int pa_node_put(pa_node *node, pa_node **requested_connections, unsigned n_requested_connections) { -- 1.8.3.1