pa_port_node takes care of things that are common to all port nodes. The port device class is used in the node name for some extra user-friendliness. The goal is to avoid the long and cryptic names that are currently generated for sinks, sources and cards. --- src/Makefile.am | 1 + src/pulsecore/port-node.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++ src/pulsecore/port-node.h | 40 ++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 src/pulsecore/port-node.c create mode 100644 src/pulsecore/port-node.h diff --git a/src/Makefile.am b/src/Makefile.am index 22245c4..5a7b817 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -887,6 +887,7 @@ libpulsecore_ at PA_MAJORMINOR@_la_SOURCES = \ pulsecore/object.c pulsecore/object.h \ pulsecore/play-memblockq.c pulsecore/play-memblockq.h \ pulsecore/play-memchunk.c pulsecore/play-memchunk.h \ + pulsecore/port-node.c pulsecore/port-node.h \ pulsecore/remap.c pulsecore/remap.h \ pulsecore/remap_mmx.c pulsecore/remap_sse.c \ pulsecore/resampler.c pulsecore/resampler.h \ diff --git a/src/pulsecore/port-node.c b/src/pulsecore/port-node.c new file mode 100644 index 0000000..4b1997518 --- /dev/null +++ b/src/pulsecore/port-node.c @@ -0,0 +1,80 @@ +/*** + This file is part of PulseAudio. + + Copyright (c) 2013 Intel Corporation + Author: Tanu Kaskinen <tanu.kaskinen at intel.com> + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + 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 + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <pulsecore/core-util.h> + +#include "port-node.h" + +pa_port_node *pa_port_node_new(pa_device_port *port, const char *fallback_name) { + char *name; + pa_node_new_data data; + pa_node *node; + pa_port_node *port_node; + + pa_assert(port); + pa_assert(fallback_name); + + if (port->device_class != PA_DEVICE_CLASS_UNKNOWN) + name = pa_sprintf_malloc("%s-%s", pa_device_class_to_string(port->device_class), + port->direction == PA_DIRECTION_OUTPUT ? "output" : "input"); + else + name = pa_xstrdup(fallback_name); + + pa_node_new_data_init(&data); + pa_node_new_data_set_name(&data, name); + pa_xfree(name); + pa_node_new_data_set_description(&data, port->description); + pa_node_new_data_set_direction(&data, port->direction); + + node = pa_node_new(port->core, &data); + pa_node_new_data_done(&data); + + if (!node) { + pa_log("Failed to create a node for port %s.", port->name); + return NULL; + } + + port_node = pa_xnew0(pa_port_node, 1); + port_node->core = port->core; + port_node->node = node; + port_node->port = port; + + node->userdata = port_node; + + /* We may need to move this to pa_port_node_put() at some point. */ + pa_node_put(node); + + return port_node; +} + +void pa_port_node_free(pa_port_node *port_node) { + pa_assert(port_node); + + if (port_node->node) + pa_node_free(port_node->node); + + pa_xfree(port_node); +} diff --git a/src/pulsecore/port-node.h b/src/pulsecore/port-node.h new file mode 100644 index 0000000..f70181c --- /dev/null +++ b/src/pulsecore/port-node.h @@ -0,0 +1,40 @@ +#ifndef foopulseportnodehfoo +#define foopulseportnodehfoo + +/*** + This file is part of PulseAudio. + + Copyright (c) 2013 Intel Corporation + Author: Tanu Kaskinen <tanu.kaskinen at intel.com> + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + 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 + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +typedef struct pa_port_node pa_port_node; + +#include <pulsecore/core.h> +#include <pulsecore/node.h> + +struct pa_port_node { + pa_core *core; + pa_node *node; + pa_device_port *port; +}; + +pa_port_node *pa_port_node_new(pa_device_port *port, const char *fallback_name); +void pa_port_node_free(pa_port_node *port_node); + +#endif -- 1.8.1.2