[pulseaudio-discuss] [PATCH v2] bluetooth: Read SCO MTU from socket options

Tanu Kaskinen tanuk at iki.fi
Fri Mar 22 02:29:57 PDT 2013


On Thu, 2013-03-21 at 14:15 +0100, Mikel Astiz wrote:
> From: Mikel Astiz <mikel.astiz at bmw-carit.de>
> 
> If a non-default value was set to the socket option, override the value
> provided by the Media API and set the MTU size accordingly.
> ---
> [WAS: bluetooth: Dynamically change outgoing MTU]
> 
> This third proposal rethinks the whole approach and instead of trying
> to change the MTU dynamically, we read the setting from the socket
> option.
> 
> After all, anybody trying to setup two SCO streams (e.g. two
> simultaneous headsets) will have to configure this setting anyway.
> 
>  src/Makefile.am                        |  4 ++--
>  src/modules/bluetooth/bluetooth-util.c | 27 +++++++++++++++++++++++++++
>  2 files changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index fc787c2..60bc61c 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -2004,8 +2004,8 @@ libbluetooth_util_la_SOURCES = \
>  		modules/bluetooth/bluetooth-util.c \
>  		modules/bluetooth/bluetooth-util.h
>  libbluetooth_util_la_LDFLAGS = -avoid-version
> -libbluetooth_util_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS)
> -libbluetooth_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
> +libbluetooth_util_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) $(BLUEZ_LIBS)
> +libbluetooth_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) $(BLUEZ_CFLAGS)
>  
>  module_bluetooth_device_la_SOURCES = modules/bluetooth/module-bluetooth-device.c modules/bluetooth/rtp.h
>  module_bluetooth_device_la_LDFLAGS = $(MODULE_LDFLAGS)
> diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
> index 5e4b77b..00db24e 100644
> --- a/src/modules/bluetooth/bluetooth-util.c
> +++ b/src/modules/bluetooth/bluetooth-util.c
> @@ -29,6 +29,9 @@
>  #include <pulsecore/shared.h>
>  #include <pulsecore/dbus-shared.h>
>  
> +#include <bluetooth/bluetooth.h>
> +#include <bluetooth/sco.h>
> +
>  #include "bluetooth-util.h"
>  #include "a2dp-codecs.h"
>  
> @@ -37,6 +40,8 @@
>  #define A2DP_SOURCE_ENDPOINT "/MediaEndpoint/A2DPSource"
>  #define A2DP_SINK_ENDPOINT "/MediaEndpoint/A2DPSink"
>  
> +#define DEFAULT_KERNEL_SCO_MTU 64
> +
>  #define ENDPOINT_INTROSPECT_XML                                         \
>      DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                           \
>      "<node>"                                                            \
> @@ -1163,6 +1168,28 @@ int pa_bluetooth_transport_acquire(pa_bluetooth_transport *t, bool optional, siz
>          goto fail;
>      }
>  
> +    /* For SCO sockets, read the MTU from the socket options and if necessary
> +     * override the value provided by the Media API */
> +    if (t->profile == PROFILE_HSP || t->profile == PROFILE_HFGW) {
> +        struct sco_options opts;
> +        socklen_t size = sizeof(opts);
> +
> +        memset(&opts, 0, size);
> +
> +        if (getsockopt(ret, SOL_SCO, SCO_OPTIONS, &opts, &size) == 0 && size >= sizeof(opts)) {
> +            if (opts.mtu == DEFAULT_KERNEL_SCO_MTU)
> +                pa_log_debug("Ignoring default kernel SCO MTU");
> +            else if (opts.mtu < i || opts.mtu < o)
> +                pa_log_warn("Ignoring socket option SCO MTU size %u because it's too small", opts.mtu);
> +            else {
> +                pa_log_info("Overriding MediaTransport MTU (%u, %u) with socket option SCO MTU size %u", i, o, opts.mtu);
> +
> +                i = opts.mtu;
> +                o = opts.mtu;
> +            }

Shouldn't the else block be executed only if opts.mtu doesn't match the
MTUs given by the Media API?

-- 
Tanu



More information about the pulseaudio-discuss mailing list