[pulseaudio-discuss] [PATCH 21/23] Introduce pa_router

David Henningsson david.henningsson at canonical.com
Sun Nov 24 19:50:41 PST 2013


On 11/20/2013 10:26 AM, Tanu Kaskinen wrote:
> Router modules will create a pa_router object, and extend its
> functionality with callbacks. There can be only one router in the
> system at a time. At this first stage, the only functionality the base
> pa_router is to notify the router modules about new and removed nodes.

Then there is another concept we can take away to keep it simple atm -
there is no need to have a "base pa_router", you can just notify the
router implementation through hooks instead.

> ---
>  src/Makefile.am        |  1 +
>  src/pulsecore/core.c   | 18 ++++++++++
>  src/pulsecore/core.h   |  6 ++++
>  src/pulsecore/router.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/pulsecore/router.h | 47 ++++++++++++++++++++++++++
>  5 files changed, 163 insertions(+)
>  create mode 100644 src/pulsecore/router.c
>  create mode 100644 src/pulsecore/router.h
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 168415e..4e71af8 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -890,6 +890,7 @@ libpulsecore_ at PA_MAJORMINOR@_la_SOURCES = \
>  		pulsecore/remap.c pulsecore/remap.h \
>  		pulsecore/remap_mmx.c pulsecore/remap_sse.c \
>  		pulsecore/resampler.c pulsecore/resampler.h \
> +		pulsecore/router.c pulsecore/router.h \
>  		pulsecore/rtpoll.c pulsecore/rtpoll.h \
>  		pulsecore/mix.c pulsecore/mix.h \
>  		pulsecore/cpu.h \
> diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
> index cc8915c..40f754c 100644
> --- a/src/pulsecore/core.c
> +++ b/src/pulsecore/core.c
> @@ -217,6 +217,24 @@ static void core_free(pa_object *o) {
>      pa_xfree(c);
>  }
>  
> +int pa_core_set_router(pa_core *c, pa_router *router) {
> +    pa_assert(c);
> +
> +    if (c->router && router) {
> +        pa_log("Tried to set the router when the router was already set.");
> +        return -1;
> +    }
> +
> +    c->router = router;
> +
> +    if (c->router)
> +        pa_log_info("Router set.");
> +    else
> +        pa_log_info("Router unset.");
> +
> +    return 0;
> +}
> +
>  static void exit_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
>      pa_core *c = userdata;
>      pa_assert(c->exit_event == e);
> diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
> index b2df5b5..b555608 100644
> --- a/src/pulsecore/core.h
> +++ b/src/pulsecore/core.h
> @@ -53,6 +53,8 @@ typedef enum pa_suspend_cause {
>  #include <pulsecore/core-subscribe.h>
>  #include <pulsecore/msgobject.h>
>  
> +typedef struct pa_router pa_router;
> +
>  typedef enum pa_server_type {
>      PA_SERVER_TYPE_UNSET,
>      PA_SERVER_TYPE_USER,
> @@ -185,6 +187,8 @@ struct pa_core {
>      pa_server_type_t server_type;
>      pa_cpu_info cpu_info;
>  
> +    pa_router *router;
> +
>      /* hooks */
>      pa_hook hooks[PA_CORE_HOOK_MAX];
>  };
> @@ -199,6 +203,8 @@ enum {
>  
>  pa_core* pa_core_new(pa_mainloop_api *m, bool shared, size_t shm_size);
>  
> +int pa_core_set_router(pa_core *c, pa_router *router);
> +
>  /* Check whether no one is connected to this core */
>  void pa_core_check_idle(pa_core *c);
>  
> diff --git a/src/pulsecore/router.c b/src/pulsecore/router.c
> new file mode 100644
> index 0000000..5d51f66
> --- /dev/null
> +++ b/src/pulsecore/router.c
> @@ -0,0 +1,91 @@
> +/***
> +  This file is part of PulseAudio.
> +
> +  Copyright 2013 Intel Corporation
> +
> +  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 "router.h"
> +
> +static void router_unlink(pa_router *router);
> +
> +pa_router *pa_router_new(pa_core *core) {
> +    pa_router *router;
> +
> +    pa_assert(core);
> +
> +    router = pa_xnew0(pa_router, 1);
> +    router->core = core;
> +
> +    return router;
> +}
> +
> +int pa_router_put(pa_router *router) {
> +    int r;
> +
> +    pa_assert(router);
> +
> +    r = pa_core_set_router(router->core, router);
> +
> +    if (r < 0)
> +        goto fail;
> +
> +    router->registered = true;
> +
> +    return 0;
> +
> +fail:
> +    router_unlink(router);
> +
> +    return -1;
> +}
> +
> +static void router_unlink(pa_router *router) {
> +    pa_assert(router);
> +
> +    if (router->registered)
> +        pa_core_set_router(router->core, NULL);
> +
> +    router->registered = false;
> +}
> +
> +void pa_router_free(pa_router *router) {
> +    pa_assert(router);
> +
> +    router_unlink(router);
> +    pa_xfree(router);
> +}
> +
> +void pa_router_add_node(pa_router *router, pa_node *node) {
> +    pa_assert(router);
> +    pa_assert(node);
> +
> +    if (router->add_node)
> +        router->add_node(router, node);
> +}
> +
> +void pa_router_remove_node(pa_router *router, pa_node *node) {
> +    pa_assert(router);
> +    pa_assert(node);
> +
> +    if (router->remove_node)
> +        router->remove_node(router, node);
> +}
> diff --git a/src/pulsecore/router.h b/src/pulsecore/router.h
> new file mode 100644
> index 0000000..e8e7546
> --- /dev/null
> +++ b/src/pulsecore/router.h
> @@ -0,0 +1,47 @@
> +#ifndef foorouterhfoo
> +#define foorouterhfoo
> +
> +/***
> +  This file is part of PulseAudio.
> +
> +  Copyright 2013 Intel Corporation
> +
> +  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.
> +***/
> +
> +#include <pulsecore/core.h>
> +
> +typedef struct pa_router pa_router;
> +
> +struct pa_router {
> +    pa_core *core;
> +    bool registered;
> +
> +    /* Called when a new node appears. May be NULL. */
> +    void (*add_node)(pa_router *router, pa_node *node);
> +
> +    /* Called when a node goes away. May be NULL. */
> +    void (*remove_node)(pa_router *router, pa_node *node);
> +};
> +
> +pa_router *pa_router_new(pa_core *core);
> +int pa_router_put(pa_router *router);
> +void pa_router_free(pa_router *router);
> +
> +void pa_router_add_node(pa_router *router, pa_node *node);
> +void pa_router_remove_node(pa_router *router, pa_node *node);
> +
> +#endif
> 



-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic


More information about the pulseaudio-discuss mailing list