[pulseaudio-discuss] [PATCH 21/56] bluetooth: Create pa_bluetooth_discovery for BlueZ 5

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Thu Jul 18 06:32:01 PDT 2013


On Fri, 2013-07-12 at 15:06 -0300, jprvita at gmail.com wrote:
> From: João Paulo Rechi Vita <jprvita at openbossa.org>
> 
> pa_bluetooth_discovery is the struct that holds information about known
> Bluetooth audio devices and other information about the Bluetooth stack.
> 
> This commit also creates bluez5-util.[ch], which will hold a lot of
> utility functions to help with the BlueZ 5 support.

So there will be bluez4-util.so and bluez5-util.so, and those will
contain identical symbols. It's possible to load both bluez 4 and 5
modules at the same time, so the bluez*-util libraries will conflict in
a way that will cause crashing or weird behavior. Since we lost the
opportunity to have a shared Bluetooth core for all backends, I think it
would be OK to change the generic "pa_bluetooth" prefix (and "pa_bt", if
it's still used somewhere) to "pa_bluez5". That would resolve the symbol
conflict between the two libraries.

Another, perhaps easier solution would be to use symbol versioning in
the libraries. I'm not 100% sure that this works, but I think it should
work.

To be clear, I don't think it's a valid use case to load both versions
at the same time, but we must not crash due to configuration errors.

> ---
>  src/Makefile.am                                | 10 +++-
>  src/modules/bluetooth/bluez5-util.c            | 74 ++++++++++++++++++++++++++
>  src/modules/bluetooth/bluez5-util.h            | 32 +++++++++++
>  src/modules/bluetooth/module-bluez5-discover.c | 33 ++++++++++++
>  4 files changed, 148 insertions(+), 1 deletion(-)
>  create mode 100644 src/modules/bluetooth/bluez5-util.c
>  create mode 100644 src/modules/bluetooth/bluez5-util.h
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 733c338..52cd63f 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -1333,6 +1333,7 @@ endif
>  if HAVE_BLUEZ_5
>  modlibexec_LTLIBRARIES += \
>  		module-bluetooth-policy.la \
> +		libbluez5-util.la \
>  		module-bluez5-discover.la
>  endif
>  
> @@ -2049,9 +2050,16 @@ module_bluez4_device_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) $(SBC_LIBS) libbl
>  module_bluez4_device_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) $(SBC_CFLAGS)
>  
>  # Bluetooth BlueZ 5 sink / source
> +libbluez5_util_la_SOURCES = \
> +		modules/bluetooth/bluez5-util.c \
> +		modules/bluetooth/bluez5-util.h
> +libbluez5_util_la_LDFLAGS = -avoid-version
> +libbluez5_util_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS)
> +libbluez5_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
> +
>  module_bluez5_discover_la_SOURCES = modules/bluetooth/module-bluez5-discover.c
>  module_bluez5_discover_la_LDFLAGS = $(MODULE_LDFLAGS)
> -module_bluez5_discover_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS)
> +module_bluez5_discover_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) libbluez5-util.la
>  module_bluez5_discover_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
>  
>  # Apple Airtunes/RAOP
> diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
> new file mode 100644
> index 0000000..0f23bff
> --- /dev/null
> +++ b/src/modules/bluetooth/bluez5-util.c
> @@ -0,0 +1,74 @@
> +/***
> +  This file is part of PulseAudio.
> +
> +  Copyright 2008-2013 João Paulo Rechi Vita
> +
> +  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 <pulse/xmalloc.h>
> +
> +#include <pulsecore/core.h>
> +#include <pulsecore/macro.h>
> +#include <pulsecore/refcnt.h>
> +#include <pulsecore/shared.h>
> +
> +#include "bluez5-util.h"
> +
> +struct pa_bluetooth_discovery {
> +    PA_REFCNT_DECLARE;
> +
> +    pa_core *core;
> +};
> +
> +pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
> +    pa_bluetooth_discovery *y;
> +
> +    if ((y = pa_shared_get(c, "bluetooth-discovery")))
> +        return pa_bluetooth_discovery_ref(y);

This is another source of crashy conflicts: bluez4-util uses the same
shared name, so you may end up returning bluez4 version of
pa_bluetooth_discovery to bluez5 code, or vice versa.

-- 
Tanu



More information about the pulseaudio-discuss mailing list