[pulseaudio-discuss] Per device volume control?

2019-01-12 Thread Joel Cornuz
Hi Everyone,

I hope this is an appropriate place to ask for a general PA usage question - 
my googleing efforts have proven fruitless :/

I am planning on using PA as part of an interpretation setup (simultaneous 
language translation) for which I need two interpreters to share one audio 
input (both mics are combined to broadcasting the target language) and one 
audio output (both earphones play the same source language). Setting up and 
combining sinks works well, no problem with that.

What I haven't been able to do, however, is to have the USB devices volume 
control work on a per device basis: currently no matter which device's USB 
volume is raised (or lowered), it affects the default / fallback volume. What 
is required is that changing the volume on device A, only affects device A's 
volume (same for device B). In short, I want both interpreters to have 
individual control on the volume level of their USB device.

Is there any way to achieve that?

For testing purposes, and if that matter, I have used "el cheapo" ATR2USB 
devices but I plan to use Jabra-Evolve-20 on the final project.

Any help would be much appreciated. Many thanks in advance!

Joel





___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH v3 4/4] Add A2DP LDAC codec source support

2019-01-12 Thread Pali Rohár
On Saturday 29 December 2018 23:48:08 Huang-Huang Bao wrote:
> diff --git a/src/modules/bluetooth/a2dp/a2dp_ldac.c 
> b/src/modules/bluetooth/a2dp/a2dp_ldac.c
> new file mode 100644
> index 0..8095d2435
> --- /dev/null
> +++ b/src/modules/bluetooth/a2dp/a2dp_ldac.c
> @@ -0,0 +1,605 @@
> +/***
> +  This file is part of PulseAudio.
> +
> +  Copyright 2018 Huang-Huang Bao
> +
> +  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, see .
> +***/
> +
> +#include 
> +#include 
> +
> +#ifdef HAVE_CONFIG_H
> +
> +#include 
> +
> +#endif
> +
> +#include 
> +#include 
> +
> +#include 
> +#include 

This looks like an another license problem. This Sony's LDAC encoder
library is licensed under Apache License Version 2.0 which is not
compatible with above LGPL 2.1.

IIRC Apache License Version 2.0 can be used in GPLv3 projects, so
without relicensing pulseaudio to (L)GPLv3 this looks like a problem.

-- 
Pali Rohár
pali.ro...@gmail.com


signature.asc
Description: PGP signature
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH v3 2/4] Add A2DP AAC codec support

2019-01-12 Thread Pali Rohár
On Saturday 29 December 2018 23:48:06 Huang-Huang Bao wrote:
> diff --git a/src/modules/bluetooth/a2dp/a2dp_aac.c 
> b/src/modules/bluetooth/a2dp/a2dp_aac.c
> new file mode 100644
> index 0..a1d7bf1d2
> --- /dev/null
> +++ b/src/modules/bluetooth/a2dp/a2dp_aac.c
> @@ -0,0 +1,762 @@
> +/***
> +  This file is part of PulseAudio.
> +
> +  Copyright 2018 Huang-Huang Bao
> +
> +  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, see .
> +***/
> +
> +#include 
> +#include 
> +
> +#include 
> +#include 

This looks like license problem... I do not think that fdk-aac is
compatible with above declared LGPL 2.1.

-- 
Pali Rohár
pali.ro...@gmail.com


signature.asc
Description: PGP signature
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] Bluetooth A2DP aptX codec quality

2019-01-12 Thread Pali Rohár
On Friday 14 September 2018 15:28:55 ValdikSS wrote:
> I made a patch for Android LineageOS for Dual Channel support, and thinking 
> on adding this functionality to Pulseaudio.
> https://review.lineageos.org/#/c/LineageOS/android_system_bt/+/228548/

I think this "SBC HD" should be possible to implement via v3 model API
patch series. Looks very promising for increasing bluetooth sound
quality.

-- 
Pali Rohár
pali.ro...@gmail.com


signature.asc
Description: PGP signature
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [PATCH v2 0/2] Bluetooth A2DP aptX codec support

2019-01-12 Thread Pali Rohár
On Friday 03 August 2018 15:32:01 Pali Rohár wrote:
> On Friday 03 August 2018 16:22:05 ValdikSS wrote:
> > When I try to switch to aptX profile from "off" profile, pulseaudio crashes:
> > 
> > E: [pulseaudio] module-bluez5-device.c: Assertion '!u->thread' failed at 
> > modules/bluetooth/module-bluez5-device.c:1491, function start_thread(). 
> > Aborting.
> 
> Try:
> 
> $ pactl unload-module module-bluetooth-policy
> 
> Seems that policy module needs to be fixed for new aptx profiles.
> 
> > Thread 1 "pulseaudio" received signal SIGABRT, Aborted.
> > 0x744edfeb in raise () from /lib64/libc.so.6
> > (gdb) bt
> > #0  0x744edfeb in raise () from /lib64/libc.so.6
> > #1  0x744d85c1 in abort () from /lib64/libc.so.6
> > #2  0x7fff7f3dab45 in start_thread (u=u@entry=0x5593d640) at 
> > modules/bluetooth/module-bluez5-device.c:1491
> > #3  0x7fff7f3dd263 in set_profile_cb (c=, 
> > new_profile=0x559251a0) at modules/bluetooth/module-bluez5-device.c:1859
> > #4  0x77b5148e in pa_card_set_profile (c=c@entry=0x558e4c20, 
> > profile=profile@entry=0x559251a0, save=save@entry=true) at 
> > pulsecore/card.c:318
> > #5  0x7fffe0a0362d in command_set_card_profile (pd=, 
> > command=, tag=127, t=, userdata= > out>) at pulsecore/protocol-native.c:4728
> > #6  0x76d83813 in pa_pdispatch_run (pd=0x55a2e4b0, 
> > packet=packet@entry=0x558a3020, 
> > ancil_data=ancil_data@entry=0x55975bf8, 
> > userdata=userdata@entry=0x558bebf0) at pulsecore/pdispatch.c:346
> > #7  0x7fffe0a0bee9 in pstream_packet_callback (p=0x55975960, 
> > packet=0x558a3020, ancil_data=0x55975bf8, userdata=0x558bebf0) 
> > at pulsecore/protocol-native.c:4951
> > #8  0x76d8629d in do_read (p=p@entry=0x55975960, 
> > re=re@entry=0x55975b28) at pulsecore/pstream.c:1012
> > #9  0x76d890eb in do_pstream_read_write (p=0x55975960) at 
> > pulsecore/pstream.c:248
> > #10 0x76d8949d in srb_callback (srb=0x558b0660, 
> > userdata=0x55975960) at pulsecore/pstream.c:287
> > #11 0x76d89d2a in srbchannel_rwloop (sr=0x558b0660) at 
> > pulsecore/srbchannel.c:190
> > #12 0x778fc8a8 in dispatch_pollfds (m=0x5576f120) at 
> > pulse/mainloop.c:140
> > #13 pa_mainloop_dispatch (m=m@entry=0x5576f120) at pulse/mainloop.c:898
> > #14 0x778fcb80 in pa_mainloop_iterate (m=0x5576f120, 
> > block=, retval=0x7fffdc18) at pulse/mainloop.c:929
> > #15 0x778fcc20 in pa_mainloop_run (m=0x5576f120, 
> > retval=0x7fffdc18) at pulse/mainloop.c:945
> > #16 0xb0c9 in main (argc=, argv=) 
> > at daemon/main.c:1144

This problem in module-bluetooth-policy is fixed in v3.

-- 
Pali Rohár
pali.ro...@gmail.com


signature.asc
Description: PGP signature
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v3 0/7] New API for Bluetooth A2DP codecs

2019-01-12 Thread Pali Rohár
This is 3rd version of my patch series for modular A2DP codec API and
aptX support. v2 link: https://patchwork.freedesktop.org/series/46058/

This patch series provides new modular API for Bluetooth A2DP codecs,
clean up module-bluez5-device and bluez5-util to be codec independent
and convert SBC codec into this new API for A2DP codecs. Also it adds
support for aptX and FastStream A2DP codecs.

New codec API is designed in way, that for adding new codec is not
needed to touch bluez5-util nor module-bluez5-device files. Whole
codec registration is done in a2dp-codec-util.c file, without need
to update any header file.

New codec API is prepared for A2DP codec switching and for A2DP voice
backchannel support, but this is not implemented yet.

For every A2DP codec is created card profile. When using bluez patches
from https://marc.info/?l=linux-bluetooth=154696260401673=2 then
only those profiles codec profiles are created which are supported
by remote headset/endpoint.

In V3 series was fixed problems pointed by Tanu.

With this new modular API it should be easy to add other codec support
like MP3, AAC, aptX HD or LDAC.

API is designed also for ability to register "more variants" or one
A2DP codec. E.g. SBC codec forced to high quality, SBC codec forced
to low quality, SBC codec with automatic quality.

Once we agree on final version of codec API, I can prepare patches
also for choosing above SBC codec quality.

Pali Rohár (7):
  switch-on-port-available: Fix null pointer dereference
  bluetooth: policy: Remove BlueZ 4 related code
  bluetooth: policy: Reflect a2dp profile names
  bluetooth: Update a2dp-codecs.h from upstream bluez project
  bluetooth: Modular API for A2DP codecs
  bluetooth: Add A2DP aptX codec support
  bluetooth: Add A2DP FastStream codec support

 configure.ac|  36 ++
 src/Makefile.am |  20 +-
 src/modules/bluetooth/a2dp-codec-api.h  |  78 +++
 src/modules/bluetooth/a2dp-codec-aptx.c | 330 +++
 src/modules/bluetooth/a2dp-codec-faststream.c   | 401 +
 src/modules/bluetooth/a2dp-codec-sbc.c  | 621 
 src/modules/bluetooth/a2dp-codec-util.c |  64 ++
 src/modules/bluetooth/a2dp-codec-util.h |  34 ++
 src/modules/bluetooth/a2dp-codecs.h | 354 +++-
 src/modules/bluetooth/bluez5-util.c | 702 ++
 src/modules/bluetooth/bluez5-util.h |  38 +-
 src/modules/bluetooth/module-bluetooth-policy.c |  19 +-
 src/modules/bluetooth/module-bluez5-device.c| 740 ++--
 src/modules/module-switch-on-port-available.c   |   2 +-
 14 files changed, 2718 insertions(+), 721 deletions(-)
 create mode 100644 src/modules/bluetooth/a2dp-codec-api.h
 create mode 100644 src/modules/bluetooth/a2dp-codec-aptx.c
 create mode 100644 src/modules/bluetooth/a2dp-codec-faststream.c
 create mode 100644 src/modules/bluetooth/a2dp-codec-sbc.c
 create mode 100644 src/modules/bluetooth/a2dp-codec-util.c
 create mode 100644 src/modules/bluetooth/a2dp-codec-util.h

-- 
2.11.0

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v3 1/7] switch-on-port-available: Fix null pointer dereference

2019-01-12 Thread Pali Rohár
Sometimes on pulseaudio startup card->active_profile is NULL.
---
 src/modules/module-switch-on-port-available.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/modules/module-switch-on-port-available.c 
b/src/modules/module-switch-on-port-available.c
index 2fa7e4d62..9f344d0dc 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -343,7 +343,7 @@ static pa_hook_result_t 
card_profile_available_hook_callback(pa_core *c, pa_card
 if (profile->available != PA_AVAILABLE_NO)
 return PA_HOOK_OK;
 
-if (!pa_streq(profile->name, card->active_profile->name))
+if (!card->active_profile || !pa_streq(profile->name, 
card->active_profile->name))
 return PA_HOOK_OK;
 
 pa_log_debug("Active profile %s on card %s became unavailable, switching 
to another profile", profile->name, card->name);
-- 
2.11.0

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v3 3/7] bluetooth: policy: Reflect a2dp profile names

2019-01-12 Thread Pali Rohár
In next patches, codec name is appended end the end of a2dp profile names.
---
 src/modules/bluetooth/module-bluetooth-policy.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-policy.c 
b/src/modules/bluetooth/module-bluetooth-policy.c
index 0a6d59d28..04313aa84 100644
--- a/src/modules/bluetooth/module-bluetooth-policy.c
+++ b/src/modules/bluetooth/module-bluetooth-policy.c
@@ -85,7 +85,7 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, 
pa_source *source,
 if (!s)
 return PA_HOOK_OK;
 
-if (u->enable_a2dp_source && pa_streq(s, "a2dp_source"))
+if (u->enable_a2dp_source && pa_startswith(s, "a2dp_source"))
 role = "music";
 else if (u->enable_ag && pa_streq(s, "headset_audio_gateway"))
 role = "phone";
@@ -154,7 +154,7 @@ static void card_set_profile(struct userdata *u, pa_card 
*card, bool revert_to_a
 
 /* Check for correct profile based on revert_to_a2dp */
 if (revert_to_a2dp) {
-if (!pa_streq(profile->name, "a2dp_sink"))
+if (!pa_startswith(profile->name, "a2dp_sink"))
 continue;
 } else {
 if (!pa_streq(profile->name, "headset_head_unit"))
@@ -196,11 +196,11 @@ static void switch_profile(pa_card *card, bool 
revert_to_a2dp, void *userdata) {
 return;
 
 /* Skip card if already has active a2dp profile */
-if (pa_streq(card->active_profile->name, "a2dp_sink"))
+if (pa_startswith(card->active_profile->name, "a2dp_sink"))
 return;
 } else {
 /* Skip card if does not have active a2dp profile */
-if (!pa_streq(card->active_profile->name, "a2dp_sink"))
+if (!pa_startswith(card->active_profile->name, "a2dp_sink"))
 return;
 
 /* Skip card if already has active hsp profile */
@@ -307,7 +307,7 @@ static pa_hook_result_t 
card_init_profile_hook_callback(pa_core *c, pa_card *car
 
 /* Ignore card if has already set other initial profile than a2dp */
 if (card->active_profile &&
-!pa_streq(card->active_profile->name, "a2dp_sink"))
+!pa_startswith(card->active_profile->name, "a2dp_sink"))
 return PA_HOOK_OK;
 
 /* Set initial profile to hsp */
@@ -359,7 +359,7 @@ static pa_hook_result_t 
profile_available_hook_callback(pa_core *c, pa_card_prof
 return PA_HOOK_OK;
 
 /* Do not automatically switch profiles for headsets, just in case */
-if (pa_streq(profile->name, "a2dp_sink") || pa_streq(profile->name, 
"headset_head_unit"))
+if (pa_startswith(profile->name, "a2dp_sink") || pa_streq(profile->name, 
"headset_head_unit"))
 return PA_HOOK_OK;
 
 is_active_profile = card->active_profile == profile;
-- 
2.11.0

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v3 2/7] bluetooth: policy: Remove BlueZ 4 related code

2019-01-12 Thread Pali Rohár
---
 src/modules/bluetooth/module-bluetooth-policy.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-policy.c 
b/src/modules/bluetooth/module-bluetooth-policy.c
index 4d3126f65..0a6d59d28 100644
--- a/src/modules/bluetooth/module-bluetooth-policy.c
+++ b/src/modules/bluetooth/module-bluetooth-policy.c
@@ -154,10 +154,10 @@ static void card_set_profile(struct userdata *u, pa_card 
*card, bool revert_to_a
 
 /* Check for correct profile based on revert_to_a2dp */
 if (revert_to_a2dp) {
-if (!pa_streq(profile->name, "a2dp") && !pa_streq(profile->name, 
"a2dp_sink"))
+if (!pa_streq(profile->name, "a2dp_sink"))
 continue;
 } else {
-if (!pa_streq(profile->name, "hsp") && !pa_streq(profile->name, 
"headset_head_unit"))
+if (!pa_streq(profile->name, "headset_head_unit"))
 continue;
 }
 
@@ -192,19 +192,19 @@ static void switch_profile(pa_card *card, bool 
revert_to_a2dp, void *userdata) {
 return;
 
 /* Skip card if does not have active hsp profile */
-if (!pa_streq(card->active_profile->name, "hsp") && 
!pa_streq(card->active_profile->name, "headset_head_unit"))
+if (!pa_streq(card->active_profile->name, "headset_head_unit"))
 return;
 
 /* Skip card if already has active a2dp profile */
-if (pa_streq(card->active_profile->name, "a2dp") || 
pa_streq(card->active_profile->name, "a2dp_sink"))
+if (pa_streq(card->active_profile->name, "a2dp_sink"))
 return;
 } else {
 /* Skip card if does not have active a2dp profile */
-if (!pa_streq(card->active_profile->name, "a2dp") && 
!pa_streq(card->active_profile->name, "a2dp_sink"))
+if (!pa_streq(card->active_profile->name, "a2dp_sink"))
 return;
 
 /* Skip card if already has active hsp profile */
-if (pa_streq(card->active_profile->name, "hsp") || 
pa_streq(card->active_profile->name, "headset_head_unit"))
+if (pa_streq(card->active_profile->name, "headset_head_unit"))
 return;
 }
 
@@ -307,7 +307,6 @@ static pa_hook_result_t 
card_init_profile_hook_callback(pa_core *c, pa_card *car
 
 /* Ignore card if has already set other initial profile than a2dp */
 if (card->active_profile &&
-!pa_streq(card->active_profile->name, "a2dp") &&
 !pa_streq(card->active_profile->name, "a2dp_sink"))
 return PA_HOOK_OK;
 
-- 
2.11.0

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


[pulseaudio-discuss] [PATCH v3 6/7] bluetooth: Add A2DP aptX codec support

2019-01-12 Thread Pali Rohár
This patch provides support for aptX codec in bluetooth A2DP profile. It
uses open source LGPLv2.1+ licensed libopenaptx library which can be found
at https://github.com/pali/libopenaptx.

Only standard aptX codec is supported for now. Support for other variants
like aptX HD or aptX Low Latency may come up later.
---
 configure.ac|  36 
 src/Makefile.am |   6 +
 src/modules/bluetooth/a2dp-codec-aptx.c | 330 
 src/modules/bluetooth/a2dp-codec-util.c |   6 +
 4 files changed, 378 insertions(+)
 create mode 100644 src/modules/bluetooth/a2dp-codec-aptx.c

diff --git a/configure.ac b/configure.ac
index 2512d3c95..ae5c3210e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1104,6 +1104,40 @@ AC_SUBST(HAVE_BLUEZ_5_NATIVE_HEADSET)
 AM_CONDITIONAL([HAVE_BLUEZ_5_NATIVE_HEADSET], [test 
"x$HAVE_BLUEZ_5_NATIVE_HEADSET" = x1])
 AS_IF([test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = "x1"], 
AC_DEFINE([HAVE_BLUEZ_5_NATIVE_HEADSET], 1, [Bluez 5 native headset backend 
enabled]))
 
+ Bluetooth A2DP aptX codec (optional) ###
+
+AC_ARG_ENABLE([aptx],
+AS_HELP_STRING([--disable-aptx],[Disable optional bluetooth A2DP aptX 
codec support (via libopenaptx)]))
+AC_ARG_VAR([OPENAPTX_CPPFLAGS], [C preprocessor flags for openaptx])
+AC_ARG_VAR([OPENAPTX_LDFLAGS], [linker flags for openaptx])
+
+CPPFLAGS_SAVE="$CPPFLAGS"
+LDFLAGS_SAVE="$LDFLAGS"
+LIBS_SAVE="$LIBS"
+
+CPPFLAGS="$CPPFLAGS $OPENAPTX_CPPFLAGS"
+LDFLAGS="$LDFLAGS $OPENAPTX_LDFLAGS"
+
+AS_IF([test "x$HAVE_BLUEZ_5" = "x1" && test "x$enable_aptx" != "xno"],
+[AC_CHECK_HEADER([openaptx.h],
+[AC_SEARCH_LIBS([aptx_init], [openaptx],
+[HAVE_OPENAPTX=1; AS_IF([test "x$ac_cv_search_aptx_init" != "xnone 
required"], [OPENAPTX_LDFLAGS="$OPENAPTX_LDFLAGS $ac_cv_search_aptx_init"])],
+[HAVE_OPENAPTX=0])],
+[HAVE_OPENAPTX=0])])
+
+CPPFLAGS="$CPPFLAGS_SAVE"
+LDFLAGS="$LDFLAGS_SAVE"
+LIBS="$LIBS_SAVE"
+
+AS_IF([test "x$HAVE_BLUEZ_5" = "x1" && test "x$enable_aptx" = "xyes" && test 
"x$HAVE_OPENAPTX" = "x0"],
+[AC_MSG_ERROR([*** libopenaptx from https://github.com/pali/libopenaptx 
not found])])
+
+AC_SUBST(OPENAPTX_CPPFLAGS)
+AC_SUBST(OPENAPTX_LDFLAGS)
+AC_SUBST(HAVE_OPENAPTX)
+AM_CONDITIONAL([HAVE_OPENAPTX], [test "x$HAVE_OPENAPTX" = "x1"])
+AS_IF([test "x$HAVE_OPENAPTX" = "x1"], AC_DEFINE([HAVE_OPENAPTX], 1, [Have 
openaptx codec library]))
+
  UDEV support (optional) 
 
 AC_ARG_ENABLE([udev],
@@ -1589,6 +1623,7 @@ AS_IF([test "x$HAVE_SYSTEMD_JOURNAL" = "x1"], 
ENABLE_SYSTEMD_JOURNAL=yes, ENABLE
 AS_IF([test "x$HAVE_BLUEZ_5" = "x1"], ENABLE_BLUEZ_5=yes, ENABLE_BLUEZ_5=no)
 AS_IF([test "x$HAVE_BLUEZ_5_OFONO_HEADSET" = "x1"], 
ENABLE_BLUEZ_5_OFONO_HEADSET=yes, ENABLE_BLUEZ_5_OFONO_HEADSET=no)
 AS_IF([test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = "x1"], 
ENABLE_BLUEZ_5_NATIVE_HEADSET=yes, ENABLE_BLUEZ_5_NATIVE_HEADSET=no)
+AS_IF([test "x$HAVE_OPENAPTX" = "x1"], ENABLE_APTX=yes, ENABLE_APTX=no)
 AS_IF([test "x$HAVE_HAL_COMPAT" = "x1"], ENABLE_HAL_COMPAT=yes, 
ENABLE_HAL_COMPAT=no)
 AS_IF([test "x$HAVE_TCPWRAP" = "x1"], ENABLE_TCPWRAP=yes, ENABLE_TCPWRAP=no)
 AS_IF([test "x$HAVE_LIBSAMPLERATE" = "x1"], ENABLE_LIBSAMPLERATE="yes 
(DEPRECATED)", ENABLE_LIBSAMPLERATE=no)
@@ -1647,6 +1682,7 @@ echo "
   Enable BlueZ 5:  ${ENABLE_BLUEZ_5}
 Enable ofono headsets: ${ENABLE_BLUEZ_5_OFONO_HEADSET}
 Enable native headsets:${ENABLE_BLUEZ_5_NATIVE_HEADSET}
+Enable aptX codec: ${ENABLE_APTX}
 Enable udev:   ${ENABLE_UDEV}
   Enable HAL->udev compat: ${ENABLE_HAL_COMPAT}
 Enable systemd
diff --git a/src/Makefile.am b/src/Makefile.am
index f65783308..7c7f1b564 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2146,6 +2146,12 @@ libbluez5_util_la_SOURCES += 
modules/bluetooth/a2dp-codec-sbc.c
 libbluez5_util_la_LIBADD += $(SBC_LIBS)
 libbluez5_util_la_CFLAGS += $(SBC_CFLAGS)
 
+if HAVE_OPENAPTX
+libbluez5_util_la_SOURCES += modules/bluetooth/a2dp-codec-aptx.c
+libbluez5_util_la_CPPFLAGS += $(OPENAPTX_CPPFLAGS)
+libbluez5_util_la_LDFLAGS += $(OPENAPTX_LDFLAGS)
+endif
+
 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) 
libbluez5-util.la
diff --git a/src/modules/bluetooth/a2dp-codec-aptx.c 
b/src/modules/bluetooth/a2dp-codec-aptx.c
new file mode 100644
index 0..8cde8b908
--- /dev/null
+++ b/src/modules/bluetooth/a2dp-codec-aptx.c
@@ -0,0 +1,330 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2018-2019 Pali Rohár 
+
+  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 

[pulseaudio-discuss] [PATCH v3 4/7] bluetooth: Update a2dp-codecs.h from upstream bluez project

2019-01-12 Thread Pali Rohár
---
 src/modules/bluetooth/a2dp-codecs.h | 354 +++-
 src/modules/bluetooth/bluez5-util.c |   6 +-
 2 files changed, 349 insertions(+), 11 deletions(-)

diff --git a/src/modules/bluetooth/a2dp-codecs.h 
b/src/modules/bluetooth/a2dp-codecs.h
index 8afcfcb24..0bdd29110 100644
--- a/src/modules/bluetooth/a2dp-codecs.h
+++ b/src/modules/bluetooth/a2dp-codecs.h
@@ -4,6 +4,7 @@
  *
  *  Copyright (C) 2006-2010  Nokia Corporation
  *  Copyright (C) 2004-2010  Marcel Holtmann 
+ *  Copyright (C) 2018   Pali Rohár 
  *
  *
  *  This library is free software; you can redistribute it and/or
@@ -17,14 +18,19 @@
  *  Lesser General Public License for more details.
  *
  *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, see 
.
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
 
+#include 
+#include 
+
 #define A2DP_CODEC_SBC 0x00
 #define A2DP_CODEC_MPEG12  0x01
 #define A2DP_CODEC_MPEG24  0x02
-#define A2DP_CODEC_ATRAC   0x03
+#define A2DP_CODEC_ATRAC   0x04
+#define A2DP_CODEC_VENDOR  0xFF
 
 #define SBC_SAMPLING_FREQ_16000(1 << 3)
 #define SBC_SAMPLING_FREQ_32000(1 << 2)
@@ -47,6 +53,9 @@
 #define SBC_ALLOCATION_SNR (1 << 1)
 #define SBC_ALLOCATION_LOUDNESS1
 
+#define SBC_MAX_BITPOOL64
+#define SBC_MIN_BITPOOL2
+
 #define MPEG_CHANNEL_MODE_MONO (1 << 3)
 #define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
 #define MPEG_CHANNEL_MODE_STEREO   (1 << 1)
@@ -63,10 +72,244 @@
 #define MPEG_SAMPLING_FREQ_44100   (1 << 1)
 #define MPEG_SAMPLING_FREQ_48000   1
 
-#define MAX_BITPOOL 64
-#define MIN_BITPOOL 2
+#define MPEG_BIT_RATE_INDEX_0  (1 << 0)
+#define MPEG_BIT_RATE_INDEX_1  (1 << 1)
+#define MPEG_BIT_RATE_INDEX_2  (1 << 2)
+#define MPEG_BIT_RATE_INDEX_3  (1 << 3)
+#define MPEG_BIT_RATE_INDEX_4  (1 << 4)
+#define MPEG_BIT_RATE_INDEX_5  (1 << 5)
+#define MPEG_BIT_RATE_INDEX_6  (1 << 6)
+#define MPEG_BIT_RATE_INDEX_7  (1 << 7)
+#define MPEG_BIT_RATE_INDEX_8  (1 << 8)
+#define MPEG_BIT_RATE_INDEX_9  (1 << 9)
+#define MPEG_BIT_RATE_INDEX_10 (1 << 10)
+#define MPEG_BIT_RATE_INDEX_11 (1 << 11)
+#define MPEG_BIT_RATE_INDEX_12 (1 << 12)
+#define MPEG_BIT_RATE_INDEX_13 (1 << 13)
+#define MPEG_BIT_RATE_INDEX_14 (1 << 14)
+
+#define MPEG_MP1_BIT_RATE_32000MPEG_BIT_RATE_INDEX_1
+#define MPEG_MP1_BIT_RATE_64000MPEG_BIT_RATE_INDEX_2
+#define MPEG_MP1_BIT_RATE_96000MPEG_BIT_RATE_INDEX_3
+#define MPEG_MP1_BIT_RATE_128000   MPEG_BIT_RATE_INDEX_4
+#define MPEG_MP1_BIT_RATE_16   MPEG_BIT_RATE_INDEX_5
+#define MPEG_MP1_BIT_RATE_192000   MPEG_BIT_RATE_INDEX_6
+#define MPEG_MP1_BIT_RATE_224000   MPEG_BIT_RATE_INDEX_7
+#define MPEG_MP1_BIT_RATE_256000   MPEG_BIT_RATE_INDEX_8
+#define MPEG_MP1_BIT_RATE_288000   MPEG_BIT_RATE_INDEX_9
+#define MPEG_MP1_BIT_RATE_32   MPEG_BIT_RATE_INDEX_10
+#define MPEG_MP1_BIT_RATE_352000   MPEG_BIT_RATE_INDEX_11
+#define MPEG_MP1_BIT_RATE_384000   MPEG_BIT_RATE_INDEX_12
+#define MPEG_MP1_BIT_RATE_416000   MPEG_BIT_RATE_INDEX_13
+#define MPEG_MP1_BIT_RATE_448000   MPEG_BIT_RATE_INDEX_14
+
+#define MPEG_MP2_BIT_RATE_32000MPEG_BIT_RATE_INDEX_1
+#define MPEG_MP2_BIT_RATE_48000MPEG_BIT_RATE_INDEX_2
+#define MPEG_MP2_BIT_RATE_56000MPEG_BIT_RATE_INDEX_3
+#define MPEG_MP2_BIT_RATE_64000MPEG_BIT_RATE_INDEX_4
+#define MPEG_MP2_BIT_RATE_8MPEG_BIT_RATE_INDEX_5
+#define MPEG_MP2_BIT_RATE_96000MPEG_BIT_RATE_INDEX_6
+#define MPEG_MP2_BIT_RATE_112000   MPEG_BIT_RATE_INDEX_7
+#define MPEG_MP2_BIT_RATE_128000   MPEG_BIT_RATE_INDEX_8
+#define MPEG_MP2_BIT_RATE_16   MPEG_BIT_RATE_INDEX_9
+#define MPEG_MP2_BIT_RATE_192000   MPEG_BIT_RATE_INDEX_10
+#define MPEG_MP2_BIT_RATE_224000   MPEG_BIT_RATE_INDEX_11
+#define MPEG_MP2_BIT_RATE_256000   MPEG_BIT_RATE_INDEX_12
+#define MPEG_MP2_BIT_RATE_32   MPEG_BIT_RATE_INDEX_13
+#define MPEG_MP2_BIT_RATE_384000   MPEG_BIT_RATE_INDEX_14
+
+#define MPEG_MP3_BIT_RATE_32000MPEG_BIT_RATE_INDEX_1
+#define MPEG_MP3_BIT_RATE_4MPEG_BIT_RATE_INDEX_2
+#define MPEG_MP3_BIT_RATE_48000MPEG_BIT_RATE_INDEX_3
+#define MPEG_MP3_BIT_RATE_56000MPEG_BIT_RATE_INDEX_4
+#define MPEG_MP3_BIT_RATE_64000MPEG_BIT_RATE_INDEX_5
+#define MPEG_MP3_BIT_RATE_8MPEG_BIT_RATE_INDEX_6
+#define MPEG_MP3_BIT_RATE_96000

[pulseaudio-discuss] [PATCH v3 7/7] bluetooth: Add A2DP FastStream codec support

2019-01-12 Thread Pali Rohár
Now only main channel, voice backchannel is not implemented yet.
---
 src/Makefile.am   |   2 +
 src/modules/bluetooth/a2dp-codec-faststream.c | 401 ++
 src/modules/bluetooth/a2dp-codec-util.c   |   2 +
 3 files changed, 405 insertions(+)
 create mode 100644 src/modules/bluetooth/a2dp-codec-faststream.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 7c7f1b564..26c0e0794 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2146,6 +2146,8 @@ libbluez5_util_la_SOURCES += 
modules/bluetooth/a2dp-codec-sbc.c
 libbluez5_util_la_LIBADD += $(SBC_LIBS)
 libbluez5_util_la_CFLAGS += $(SBC_CFLAGS)
 
+libbluez5_util_la_SOURCES += modules/bluetooth/a2dp-codec-faststream.c
+
 if HAVE_OPENAPTX
 libbluez5_util_la_SOURCES += modules/bluetooth/a2dp-codec-aptx.c
 libbluez5_util_la_CPPFLAGS += $(OPENAPTX_CPPFLAGS)
diff --git a/src/modules/bluetooth/a2dp-codec-faststream.c 
b/src/modules/bluetooth/a2dp-codec-faststream.c
new file mode 100644
index 0..8c910ea8b
--- /dev/null
+++ b/src/modules/bluetooth/a2dp-codec-faststream.c
@@ -0,0 +1,401 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2018-2019 Pali Rohár 
+
+  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, see .
+***/
+
+#ifdef HAVE_CONFIG_H
+#include 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "a2dp-codecs.h"
+#include "a2dp-codec-api.h"
+
+#define SBC_BITPOOL_DEC_LIMIT 32
+#define SBC_BITPOOL_DEC_STEP 5
+
+struct faststream_info {
+sbc_t sbc;   /* Codec data */
+size_t codesize, frame_length;   /* SBC Codesize, frame_length. We 
simply cache those values here */
+};
+
+static bool accept_capabilities(const uint8_t *capabilities_buffer, uint8_t 
capabilities_size, bool for_encoding) {
+const a2dp_faststream_t *capabilities = (const a2dp_faststream_t *) 
capabilities_buffer;
+
+if (A2DP_GET_VENDOR_ID(capabilities->info) != FASTSTREAM_VENDOR_ID || 
A2DP_GET_CODEC_ID(capabilities->info) != FASTSTREAM_CODEC_ID)
+return false;
+
+if (!(capabilities->direction & (FASTSTREAM_DIRECTION_SINK | 
FASTSTREAM_DIRECTION_SOURCE)))
+return false;
+
+if (capabilities->direction & FASTSTREAM_DIRECTION_SINK) {
+if (!(capabilities->sink_frequency & 
(FASTSTREAM_SINK_SAMPLING_FREQ_44100 | FASTSTREAM_SINK_SAMPLING_FREQ_48000)))
+return false;
+} else {
+if (capabilities->sink_frequency != 0)
+return false;
+}
+
+if (capabilities->direction & FASTSTREAM_DIRECTION_SOURCE) {
+if (!(capabilities->source_frequency & 
FASTSTREAM_SOURCE_SAMPLING_FREQ_16000))
+return false;
+} else {
+if (capabilities->source_frequency != 0)
+return false;
+}
+
+return true;
+}
+
+static const char *choose_capabilities(const pa_hashmap *capabilities_hashmap, 
bool for_encoding) {
+const pa_a2dp_codec_capabilities *a2dp_capabilities;
+const char *key;
+void *state;
+
+/* There is no preference, just choose random valid entry */
+PA_HASHMAP_FOREACH_KV(key, a2dp_capabilities, capabilities_hashmap, state) 
{
+if (accept_capabilities(a2dp_capabilities->buffer, 
a2dp_capabilities->size, for_encoding))
+return key;
+}
+
+return NULL;
+}
+
+static uint8_t fill_capabilities(uint8_t capabilities_buffer[254]) {
+a2dp_faststream_t *capabilities = (a2dp_faststream_t *) 
capabilities_buffer;
+
+pa_zero(*capabilities);
+
+capabilities->info = A2DP_SET_VENDOR_ID_CODEC_ID(FASTSTREAM_VENDOR_ID, 
FASTSTREAM_CODEC_ID);
+capabilities->direction = FASTSTREAM_DIRECTION_SINK | 
FASTSTREAM_DIRECTION_SOURCE;
+capabilities->sink_frequency = FASTSTREAM_SINK_SAMPLING_FREQ_44100 | 
FASTSTREAM_SINK_SAMPLING_FREQ_48000;
+capabilities->source_frequency = FASTSTREAM_SOURCE_SAMPLING_FREQ_16000;
+
+return sizeof(*capabilities);
+}
+
+static bool validate_configuration(const uint8_t *config_buffer, uint8_t 
config_size) {
+const a2dp_faststream_t *config = (const a2dp_faststream_t *) 
config_buffer;
+
+if (config_size != sizeof(*config)) {
+pa_log_error("Invalid size of config buffer");
+return false;
+}
+
+if (A2DP_GET_VENDOR_ID(config->info) != FASTSTREAM_VENDOR_ID || 
A2DP_GET_CODEC_ID(config->info) != FASTSTREAM_CODEC_ID) {
+

Re: [pulseaudio-discuss] [PATCH v2 2/2] Bluetooth A2DP aptX codec support

2019-01-12 Thread Pali Rohár
On Wednesday 05 September 2018 13:57:08 Tanu Kaskinen wrote:
> On Sat, 2018-07-28 at 17:34 +0200, Pali Rohár wrote:
> > This patch provides support for aptX codec in bluetooth A2DP profile. In
> > pulseaudio it is implemented as a new profile a2dp_aptx_sink. For aptX
> > encoding it uses open source LGPLv2.1+ licensed libopenaptx library which
> > can be found at https://github.com/pali/libopenaptx.
> > 
> > Limitations:
> > 
> > Codec selection (either SBC or aptX) is done by bluez itself and it does
> > not provide API for switching codec. Therefore pulseaudio is not able to
> > change codec and it is up to bluez if it decide to use aptX or not.
> > 
> > Only standard aptX codec is supported for now. Support for other variants
> > like aptX HD, aptX Low Latency, FastStream may come up later.
> > ---
> >  configure.ac |  19 ++
> >  src/Makefile.am  |   5 +
> >  src/modules/bluetooth/a2dp-codecs.h  | 118 ++-
> >  src/modules/bluetooth/bluez5-util.c  |  48 -
> >  src/modules/bluetooth/bluez5-util.h  |   2 +
> >  src/modules/bluetooth/module-bluez5-device.c |  65 +-
> >  src/modules/bluetooth/pa-a2dp-codec-aptx.c   | 297 
> > +++
> >  src/modules/bluetooth/pa-a2dp-codec.h|   1 +
> >  8 files changed, 548 insertions(+), 7 deletions(-)
> >  create mode 100644 src/modules/bluetooth/pa-a2dp-codec-aptx.c
> > 
> > diff --git a/configure.ac b/configure.ac
> > index d2bfab23b..c2d13fa53 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -1094,6 +1094,23 @@ AC_SUBST(HAVE_BLUEZ_5_NATIVE_HEADSET)
> >  AM_CONDITIONAL([HAVE_BLUEZ_5_NATIVE_HEADSET], [test 
> > "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = x1])
> >  AS_IF([test "x$HAVE_BLUEZ_5_NATIVE_HEADSET" = "x1"], 
> > AC_DEFINE([HAVE_BLUEZ_5_NATIVE_HEADSET], 1, [Bluez 5 native headset backend 
> > enabled]))
> >  
> > + Bluetooth A2DP aptX codec (optional) ###
> > +
> > +AC_ARG_ENABLE([aptx],
> > +AS_HELP_STRING([--disable-aptx],[Disable optional bluetooth A2DP aptX 
> > codec support (via libopenaptx)]))
> > +
> > +AS_IF([test "x$HAVE_BLUEZ_5" = "x1" && test "x$enable_aptx" != "xno"],
> > +[AC_CHECK_HEADER([openaptx.h],
> > +[AC_CHECK_LIB([openaptx], [aptx_init], [HAVE_OPENAPTX=1], 
> > [HAVE_OPENAPTX=0])],
> > +[HAVE_OPENAPTX=0])])
> 
> Have you considered providing a .pc file?

I will think about it (again).

> Now we have to hardcode the
> openaptx specific CFLAGS and LIBADD for libbluez5-util.

As a first step, I will remove hardcoded CFLAGS and LIBADD from
libbluez5-util. In autoconf, everything is possible to discover, so
really no need to hardcode and let autoconf find them.

> If you ever need to add new flags,

This is something which is not going to happen.

> all openaptx users need to update their build
> systems. Also, if the library is installed to a non-standard location,
> the .pc file can set the -L and -I flags to point to the right place.

> > diff --git a/src/modules/bluetooth/bluez5-util.c 
> > b/src/modules/bluetooth/bluez5-util.c
> > index 9c4e3367b..c139f7fc3 100644
> > --- a/src/modules/bluetooth/bluez5-util.c
> > +++ b/src/modules/bluetooth/bluez5-util.c
> > @@ -50,7 +50,9 @@
> >  #define BLUEZ_ERROR_NOT_SUPPORTED "org.bluez.Error.NotSupported"
> >  
> >  #define A2DP_SOURCE_SBC_ENDPOINT "/MediaEndpoint/A2DPSourceSBC"
> > +#define A2DP_SOURCE_APTX_ENDPOINT "/MediaEndpoint/A2DPSourceAPTX"
> >  #define A2DP_SINK_SBC_ENDPOINT "/MediaEndpoint/A2DPSinkSBC"
> > +#define A2DP_SINK_APTX_ENDPOINT "/MediaEndpoint/A2DPSinkAPTX"
> >  
> >  #define ENDPOINT_INTROSPECT_XML \
> >  DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE   \
> > @@ -173,8 +175,22 @@ static bool 
> > device_supports_profile(pa_bluetooth_device *device, pa_bluetooth_pr
> >  switch (profile) {
> >  case PA_BLUETOOTH_PROFILE_A2DP_SBC_SINK:
> >  return !!pa_hashmap_get(device->uuids, 
> > PA_BLUETOOTH_UUID_A2DP_SINK);
> > +case PA_BLUETOOTH_PROFILE_A2DP_APTX_SINK:
> > +#ifdef HAVE_OPENAPTX
> > +/* TODO: Implement once bluez provides API to check if codec 
> > is supported */
> > +return !!pa_hashmap_get(device->uuids, 
> > PA_BLUETOOTH_UUID_A2DP_SINK);
> 
> Is someone working on that API?

Yes, Luiz posted patches to bluez mailing list, and I will use this API
in new patch version. Also I will add fallback code, so users of "old"
bluez would be still able to use pulseaudio, just with same limitation
as now (no codec switching).

> > +#else
> > +return false;
> > +#endif
> >  case PA_BLUETOOTH_PROFILE_A2DP_SBC_SOURCE:
> >  return !!pa_hashmap_get(device->uuids, 
> > PA_BLUETOOTH_UUID_A2DP_SOURCE);
> > +case PA_BLUETOOTH_PROFILE_A2DP_APTX_SOURCE:
> > +#ifdef HAVE_OPENAPTX
> > +/* TODO: Implement once bluez provides API to check if codec 
> > is supported */
> > +  

Re: [pulseaudio-discuss] [PATCH v2 1/2] Modular API for Bluetooth A2DP codec

2019-01-12 Thread Pali Rohár
Hi Tanu! I'm working on a new version of this patch series.

Below are comments, I'm fixing problems which you pointed. Thank you for
review.

Also, on bluez mailing list are patches which add support for profile
switching, so I'm implementing it for this patch series.

Once I have implemented it, I will send a new version to pulseaudio
mailing list.

Most important change is removal of all codec specific enums, ifdefs,
etc... from bluez5-util.c and module-bluez5-device.c files. So for
adding new codec it would not be needed to touch these files!

On Tuesday 04 September 2018 11:44:10 Tanu Kaskinen wrote:
> On Sat, 2018-07-28 at 17:34 +0200, Pali Rohár wrote:
> > Move current SBC codec implementation into separate source file and use
> > this new API for providing all needed functionality for Bluetooth A2DP.
> > 
> > Both bluez5-util and module-bluez5-device are changed to use this new
> > modular codec API.
> > ---
> >  src/Makefile.am  |   9 +-
> >  src/modules/bluetooth/a2dp-codecs.h  |   5 +-
> >  src/modules/bluetooth/bluez5-util.c  | 331 +--
> >  src/modules/bluetooth/bluez5-util.h  |  10 +-
> >  src/modules/bluetooth/module-bluez5-device.c | 487 ++
> >  src/modules/bluetooth/pa-a2dp-codec-sbc.c| 579 
> > +++
> >  src/modules/bluetooth/pa-a2dp-codec.h|  40 ++
> 
> The "pa-" prefix doesn't look very good to me. Maybe you didn't want to
> add a2dp-codec.h, because it looks so similar to the existing a2dp-
> codecs.h header? I think we can get rid of a2dp-codecs.h: the SBC stuff
> can be moved to a2dp-codec-sbc.c, and the MPEG stuff can be dropped
> since it's not used anywhere.

I'm going to change/fix it.

a2dp-codec-api.h --> structure definitions for implementing codecs
a2dp-codec-.c --> particular codec implementation
a2dp-codecs.h--> upstream bluez header file for A2DP definitions
a2dp-codec-util.h--> header file for utility functions for working
 with codecs (e.g. listing all codecs, etc.)
a2dp-codec-util.c--> implementation of a2dp-codec-util.h

> > @@ -888,10 +889,21 @@ finish:
> >  static void register_endpoint(pa_bluetooth_discovery *y, const char *path, 
> > const char *endpoint, const char *uuid) {
> >  DBusMessage *m;
> >  DBusMessageIter i, d;
> > -uint8_t codec = 0;
> > +uint8_t capabilities[1024];
> > +size_t capabilities_size;
> > +uint8_t codec_id;
> > +const pa_a2dp_codec_t *codec;
> > +
> > +codec = pa_a2dp_endpoint_to_a2dp_codec(endpoint);
> 
> I think it would be better to change the function parameters so that
> instead of an endpoint path the function would take a codec id.

That is not possible. endpoint is bound to pair (codec + direction).
I'm changing function parameters, so pulseaudio codec structure is
passed too (together with endpoint).

This simplify lot of other things and removal of
pa_a2dp_endpoint_to_a2dp_codec function call from there.

> > +if (!codec)
> > +return;
> 
> As far as I can tell, this should never happen, so an assertion would
> be better (and it could be in the lookup function so that every caller
> doesn't need to add a check).

After above change, yes, so removing it.

> > @@ -1316,6 +1271,38 @@ const char 
> > *pa_bluetooth_profile_to_string(pa_bluetooth_profile_t profile) {
> >  return NULL;
> >  }
> >  
> > +const char *pa_bluetooth_profile_to_a2dp_endpoint(pa_bluetooth_profile_t 
> > profile) {
> 
> This function isn't used outside bluez5-util.c, so it can be made
> static and removed from bluez5-util.h. Then the pa_bluetooth_ prefix
> should be dropped.

Yes, doing it.

> > +switch (profile) {
> > +case PA_BLUETOOTH_PROFILE_A2DP_SBC_SINK:
> > +return A2DP_SOURCE_SBC_ENDPOINT;
> > +case PA_BLUETOOTH_PROFILE_A2DP_SBC_SOURCE:
> > +return A2DP_SINK_SBC_ENDPOINT;
> > +default:
> > +return NULL;
> 
> I think it would be good to use pa_assert_not_reached() here. I assume
> this won't be used in a context where a non-a2dp profile would be
> passed to the function.

The whole bluez5-util.c file does not have any codec specific enums, so
this above profile switch was removed.

> > +}
> > +
> > +return NULL;
> 
> This is redundant.
> 
> > +}
> > +
> > +const pa_a2dp_codec_t 
> > *pa_bluetooth_profile_to_a2dp_codec(pa_bluetooth_profile_t profile) {
> > +switch (profile) {
> > +case PA_BLUETOOTH_PROFILE_A2DP_SBC_SINK:
> > +case PA_BLUETOOTH_PROFILE_A2DP_SBC_SOURCE:
> > +return _a2dp_codec_sbc;
> > +default:
> > +return NULL;
> > +}
> > +
> > +return NULL;
> > +}
> 
> This function seems to be used also for checking whether a profile is
> an a2dp profile. I think it would be clearer to have a separate
> pa_bluetooth_profile_is_a2dp() function. Then this function could also
> have an assertion rather than returning NULL