From b66cb05eaaeaf02c01fac6ee52294360c3ca6d78 Mon Sep 17 00:00:00 2001 From: Thierry Bultel Date: Wed, 23 Jan 2019 16:19:22 +0100 Subject: [PATCH] bluez-alsa: updated patches due to latest bump This updates the needed patches for 4a. The latest bump (version of 2019-01-17) has make one of the previous patch obsolete (SIGSEGV when closing the PCM), thus the patch has simply been removed. Also add a patch for having bluez-alsa request a name on dbus. BUG-AGL: SPEC-2126 Change-Id: I351b55e0d440f8f271ccb14a0d51111570659026 Signed-off-by: Thierry Bultel --- ...0001-build-and-link-with-a-shared-library.patch | 102 +++++------- .../0002-log-add-calling-function-name.patch | 2 +- .../0003-dbus-request-a-name-on-startup.patch | 153 ++++++++++++++++++ ...-increased-the-number-of-connexions-to-16.patch | 25 --- .../0004-Fixed-the-SIGSEGV-at-PCM-close.patch | 180 --------------------- .../bluez-alsa/bluez-alsa_git.bbappend | 18 ++- 6 files changed, 211 insertions(+), 269 deletions(-) create mode 100644 meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch delete mode 100644 meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-increased-the-number-of-connexions-to-16.patch delete mode 100644 meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0004-Fixed-the-SIGSEGV-at-PCM-close.patch diff --git a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0001-build-and-link-with-a-shared-library.patch b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0001-build-and-link-with-a-shared-library.patch index 3d2c4f60..53ee3ad0 100644 --- a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0001-build-and-link-with-a-shared-library.patch +++ b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0001-build-and-link-with-a-shared-library.patch @@ -1,4 +1,4 @@ -From 032917320d339e44a3981c347887b220e98e369e Mon Sep 17 00:00:00 2001 +From 7625b67a687b7a365d9d758a86ed05e84b2b3a61 Mon Sep 17 00:00:00 2001 From: Thierry Bultel Date: Mon, 3 Dec 2018 14:29:07 +0100 Subject: [PATCH 1/3] build and link with a shared library @@ -40,12 +40,11 @@ Signed-off-by: Thierry Bultel test/test-at.c | 1 - test/test-bluealsalib.c | 96 ++++++++++++++++++++++++++ test/test-io.c | 3 - - test/test-pcm.c | 4 +- test/test-utils.c | 8 +-- utils/Makefile.am | 11 ++- utils/aplay.c | 8 +-- utils/rfcomm.c | 4 +- - 40 files changed, 254 insertions(+), 75 deletions(-) + 39 files changed, 252 insertions(+), 73 deletions(-) create mode 100644 includes/bluealsa/bluealsa.h rename {src/shared => includes/bluealsa}/ctl-client.h (98%) rename {src/shared => includes/bluealsa}/ctl-proto.h (100%) @@ -58,10 +57,10 @@ Signed-off-by: Thierry Bultel create mode 100644 test/test-bluealsalib.c diff --git a/configure.ac b/configure.ac -index 734fb59..fc52531 100644 +index 0bb9452..6323d60 100644 --- a/configure.ac +++ b/configure.ac -@@ -158,8 +158,10 @@ AC_CONFIG_FILES([ +@@ -152,8 +152,10 @@ AC_CONFIG_FILES([ Makefile src/Makefile src/asound/Makefile @@ -104,7 +103,7 @@ diff --git a/src/shared/ctl-client.h b/includes/bluealsa/ctl-client.h similarity index 98% rename from src/shared/ctl-client.h rename to includes/bluealsa/ctl-client.h -index 18f724d..36b537c 100644 +index 3dc93a6..b8af154 100644 --- a/src/shared/ctl-client.h +++ b/includes/bluealsa/ctl-client.h @@ -12,7 +12,7 @@ @@ -218,7 +217,7 @@ index 923d884..24618f1 100644 @ALSA_LIBS@ \ @BLUEZ_LIBS@ diff --git a/src/asound/bluealsa-ctl.c b/src/asound/bluealsa-ctl.c -index 76cbe6a..3c931ca 100644 +index f4a0181..1b9d124 100644 --- a/src/asound/bluealsa-ctl.c +++ b/src/asound/bluealsa-ctl.c @@ -19,9 +19,9 @@ @@ -235,7 +234,7 @@ index 76cbe6a..3c931ca 100644 enum ctl_elem_type { diff --git a/src/asound/bluealsa-pcm.c b/src/asound/bluealsa-pcm.c -index 46788f5..2136964 100644 +index 258aebd..42cb61d 100644 --- a/src/asound/bluealsa-pcm.c +++ b/src/asound/bluealsa-pcm.c @@ -23,11 +23,11 @@ @@ -271,18 +270,18 @@ index e3d1703..bda2255 100644 /** diff --git a/src/bluealsa.h b/src/bluealsa.h -index 3249439..b73241e 100644 +index 7968ba9..7eee34f 100644 --- a/src/bluealsa.h +++ b/src/bluealsa.h -@@ -28,7 +28,7 @@ +@@ -27,7 +27,7 @@ #include "bluez.h" #include "bluez-a2dp.h" #include "transport.h" -#include "shared/ctl-proto.h" +#include - /* Maximal number of clients connected to the controller. */ - #define BLUEALSA_MAX_CLIENTS 7 + struct ba_config { + diff --git a/src/bluealsalib/Makefile.am b/src/bluealsalib/Makefile.am new file mode 100644 index 0000000..11d9e00 @@ -371,7 +370,7 @@ index 5f81e6e..4c7b07b 100644 static const a2dp_sbc_t a2dp_sbc = { .frequency = diff --git a/src/bluez.c b/src/bluez.c -index 35f1b36..1478d6f 100644 +index 537f0fe..591fdce 100644 --- a/src/bluez.c +++ b/src/bluez.c @@ -24,7 +24,7 @@ @@ -384,10 +383,10 @@ index 35f1b36..1478d6f 100644 /** diff --git a/src/ctl.c b/src/ctl.c -index b35afc7..82666b9 100644 +index ae2b812..dd3ab45 100644 --- a/src/ctl.c +++ b/src/ctl.c -@@ -31,8 +31,8 @@ +@@ -32,8 +32,8 @@ #include "hfp.h" #include "transport.h" #include "utils.h" @@ -396,10 +395,10 @@ index b35afc7..82666b9 100644 +#include +#include - - /** + /* Special PCM type for internal usage only. */ + #define BA_PCM_TYPE_RFCOMM 0x1F diff --git a/src/ctl.h b/src/ctl.h -index 5fd92ed..7f185a4 100644 +index 0e3c46b..593a9fd 100644 --- a/src/ctl.h +++ b/src/ctl.h @@ -11,7 +11,7 @@ @@ -409,10 +408,10 @@ index 5fd92ed..7f185a4 100644 -#include "shared/ctl-proto.h" +#include - int bluealsa_ctl_thread_init(void); - void bluealsa_ctl_free(void); + /* Indexes of special file descriptors in the poll array. */ + #define CTL_IDX_SRV 0 diff --git a/src/io.c b/src/io.c -index 5b098c4..e567bdb 100644 +index b3d7ac9..f81eeb0 100644 --- a/src/io.c +++ b/src/io.c @@ -44,10 +44,10 @@ @@ -446,10 +445,10 @@ index 35e6702..9cef402 100644 static char *get_a2dp_codecs( diff --git a/src/ofono.c b/src/ofono.c -index 4331e03..63c8685 100644 +index 902d099..bfd4e39 100644 --- a/src/ofono.c +++ b/src/ofono.c -@@ -26,7 +26,7 @@ +@@ -27,7 +27,7 @@ #include "ctl.h" #include "ofono-iface.h" #include "transport.h" @@ -459,7 +458,7 @@ index 4331e03..63c8685 100644 #define OFONO_FAKE_DEV_ID 0xffff diff --git a/src/rfcomm.c b/src/rfcomm.c -index f2a904a..b1edf84 100644 +index a86ae61..2d76725 100644 --- a/src/rfcomm.c +++ b/src/rfcomm.c @@ -17,11 +17,11 @@ @@ -477,7 +476,7 @@ index f2a904a..b1edf84 100644 /** diff --git a/src/shared/ctl-client.c b/src/shared/ctl-client.c -index 121689d..01ceecb 100644 +index 6cf9402..2da9a54 100644 --- a/src/shared/ctl-client.c +++ b/src/shared/ctl-client.c @@ -8,7 +8,7 @@ @@ -547,7 +546,7 @@ index edcbebc..40bd721 100644 #include diff --git a/src/transport.c b/src/transport.c -index aca8038..823316b 100644 +index 7253925..1617dd1 100644 --- a/src/transport.c +++ b/src/transport.c @@ -34,7 +34,7 @@ @@ -573,34 +572,38 @@ index 70d069e..27459d2 100644 /** diff --git a/test/Makefile.am b/test/Makefile.am -index 27a646a..3d67809 100644 +index 104dc63..8f7b2eb 100644 --- a/test/Makefile.am +++ b/test/Makefile.am -@@ -4,7 +4,8 @@ - TESTS = \ - test-at \ +@@ -6,7 +6,8 @@ TESTS = \ + test-ctl \ test-io \ + test-pcm \ - test-utils + test-utils \ + test-bluealsalib - if ENABLE_TEST_PCM - TESTS += test-pcm -@@ -15,10 +16,12 @@ check_PROGRAMS = \ - test-at \ + check_PROGRAMS = \ + server-mock \ +@@ -14,7 +15,8 @@ check_PROGRAMS = \ + test-ctl \ test-io \ test-pcm \ - test-utils + test-utils \ + test-bluealsalib + check_LTLIBRARIES = \ + aloader.la +@@ -25,6 +27,7 @@ aloader_la_LDFLAGS = \ + AM_CFLAGS = \ -I$(top_srcdir)/src \ + -I$(top_srcdir)/includes \ @AAC_CFLAGS@ \ @ALSA_CFLAGS@ \ @APTX_CFLAGS@ \ -@@ -40,4 +43,5 @@ LDADD = \ +@@ -46,4 +49,5 @@ LDADD = \ @GLIB2_LIBS@ \ @LDAC_ABR_LIBS@ \ @LDAC_LIBS@ \ @@ -608,10 +611,10 @@ index 27a646a..3d67809 100644 + @SBC_LIBS@ \ + ../src/bluealsalib/libbluealsa.la diff --git a/test/server-mock.c b/test/server-mock.c -index a27b59d..418e3a0 100644 +index 8c3a90e..c88fa35 100644 --- a/test/server-mock.c +++ b/test/server-mock.c -@@ -33,9 +33,6 @@ +@@ -31,9 +31,6 @@ #include "../src/rfcomm.c" #include "../src/transport.c" #include "../src/utils.c" @@ -622,7 +625,7 @@ index a27b59d..418e3a0 100644 static const a2dp_sbc_t cconfig = { .frequency = SBC_SAMPLING_FREQ_44100, diff --git a/test/test-at.c b/test/test-at.c -index 177cceb..8d5e2f3 100644 +index 8cff264..a847c22 100644 --- a/test/test-at.c +++ b/test/test-at.c @@ -11,7 +11,6 @@ @@ -749,25 +752,8 @@ index d913d2f..8ebb1d8 100644 static const a2dp_sbc_t config_sbc_44100_stereo = { .frequency = SBC_SAMPLING_FREQ_44100, -diff --git a/test/test-pcm.c b/test/test-pcm.c -index 1a4d02d..43e30e1 100644 ---- a/test/test-pcm.c -+++ b/test/test-pcm.c -@@ -18,10 +18,10 @@ - #include - #include - -+#include -+ - #include "inc/server.inc" - #include "inc/sine.inc" --#include "../src/shared/ffb.c" --#include "../src/shared/log.c" - - #define buffer_test_frames 1024 - #define dumprv(fn) fprintf(stderr, #fn " = %d\n", (int)fn) diff --git a/test/test-utils.c b/test/test-utils.c -index 767ca4e..98b5b42 100644 +index b704b42..46475f1 100644 --- a/test/test-utils.c +++ b/test/test-utils.c @@ -10,11 +10,11 @@ @@ -829,7 +815,7 @@ index 256689a..a6d132c 100644 endif diff --git a/utils/aplay.c b/utils/aplay.c -index 7b71860..5211e7f 100644 +index f792ce6..4b1372e 100644 --- a/utils/aplay.c +++ b/utils/aplay.c @@ -25,10 +25,10 @@ @@ -848,7 +834,7 @@ index 7b71860..5211e7f 100644 struct pcm_worker { struct ba_msg_transport transport; diff --git a/utils/rfcomm.c b/utils/rfcomm.c -index 6794fc4..f5f045c 100644 +index cc31f46..38e3b30 100644 --- a/utils/rfcomm.c +++ b/utils/rfcomm.c @@ -24,8 +24,8 @@ diff --git a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0002-log-add-calling-function-name.patch b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0002-log-add-calling-function-name.patch index 756081a9..8ed7e0b6 100644 --- a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0002-log-add-calling-function-name.patch +++ b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0002-log-add-calling-function-name.patch @@ -1,4 +1,4 @@ -From 9f8cca2a4c2efb9d9069e26f2e953cee586d6127 Mon Sep 17 00:00:00 2001 +From 3a7400da79678e749381306e33163ca2c005cb3b Mon Sep 17 00:00:00 2001 From: Thierry Bultel Date: Mon, 3 Dec 2018 14:31:31 +0100 Subject: [PATCH 2/3] log: add calling function name diff --git a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch new file mode 100644 index 00000000..1ef59296 --- /dev/null +++ b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-dbus-request-a-name-on-startup.patch @@ -0,0 +1,153 @@ +From 4c14fffbd20a6dd9e6ceca1eb1726ceaafab7410 Mon Sep 17 00:00:00 2001 +From: Thierry Bultel +Date: Fri, 18 Jan 2019 11:45:29 +0100 +Subject: [PATCH 3/3] dbus: request a name on startup + +When the service thread is ready, ask a name to dbus +The advantage of doing that is that client applications +can check dbus for bluez-alsa presence, without having +to implement any kinf of polling logic. Also, this +way, they can be notified on the service exit, to +perform any needed cleanup. +Since there must be an instance of bluealsa daemon +per hci device, the dbus name will be +'org.bluez-alsa.hci0', 'org.bluez-alsa.hci1' ... +and so on. + +Signed-off-by: Thierry Bultel +--- + configure.ac | 10 ++++++++++ + src/Makefile.am | 3 +++ + src/bluez-alsa.conf | 14 ++++++++++++++ + src/main.c | 32 ++++++++++++++++++++++++++++++++ + 4 files changed, 59 insertions(+) + create mode 100644 src/bluez-alsa.conf + +diff --git a/configure.ac b/configure.ac +index 6323d60..d4ec7d4 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -130,6 +130,16 @@ AC_ARG_WITH([alsaconfdir], + [alsaconfdir="$sysconfdir/alsa/conf.d"], + [alsaconfdir="$datadir/alsa/alsa.conf.d"])]) + ++AC_ARG_WITH(dbusconfdir, AC_HELP_STRING([--with-dbusconfdir=PATH], ++ [path to D-Bus config directory]), [path_dbusconf=${withval}], ++ [path_dbusconf="`$PKG_CONFIG --variable=sysconfdir dbus-1`"]) ++if (test -z "${path_dbusconf}"); then ++ DBUS_CONFDIR="${sysconfdir}/dbus-1/system.d" ++else ++ DBUS_CONFDIR="${path_dbusconf}/dbus-1/system.d" ++fi ++AC_SUBST(DBUS_CONFDIR) ++ + test "x$prefix" = xNONE && prefix=$ac_default_prefix + test "x$exec_prefix" = xNONE && exec_prefix=$prefix + +diff --git a/src/Makefile.am b/src/Makefile.am +index 5626ae5..c501f2e 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -23,6 +23,9 @@ bluealsa_SOURCES += \ + ofono-iface.c + endif + ++dbusconfdir = @DBUS_CONFDIR@ ++dist_dbusconf_DATA = bluez-alsa.conf ++ + AM_CFLAGS = \ + @BLUEZ_CFLAGS@ \ + @GLIB2_CFLAGS@ \ +diff --git a/src/bluez-alsa.conf b/src/bluez-alsa.conf +new file mode 100644 +index 0000000..6b999d6 +--- /dev/null ++++ b/src/bluez-alsa.conf +@@ -0,0 +1,14 @@ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +diff --git a/src/main.c b/src/main.c +index 9cef402..9183978 100644 +--- a/src/main.c ++++ b/src/main.c +@@ -12,6 +12,7 @@ + # include "config.h" + #endif + ++#define _GNU_SOURCE + #include + #include + #include +@@ -58,6 +59,20 @@ static char *get_a2dp_codecs( + return g_strjoinv(", ", (char **)tmp); + } + ++static void name_acquired_handler( ++ GDBusConnection *connection, ++ const gchar *name, ++ gpointer user_data) { ++ debug("Acquired name: %s", name); ++} ++ ++static void name_lost_handler( ++ GDBusConnection *connection, ++ const gchar *name, ++ gpointer user_data) { ++ debug("Lost name: %s", name); ++} ++ + static GMainLoop *loop = NULL; + static void main_loop_stop(int sig) { + /* Call to this handler restores the default action, so on the +@@ -318,6 +333,7 @@ int main(int argc, char **argv) { + GError *err; + + err = NULL; ++ + address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); + if ((config.dbus = g_dbus_connection_new_for_address_sync(address, + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | +@@ -336,6 +352,19 @@ int main(int argc, char **argv) { + ofono_register(); + #endif + ++ char * name_on_bus = NULL; ++ asprintf(&name_on_bus, "org.bluez-alsa.%s", config.hci_dev.name); ++ ++ guint g_dbusid; ++ g_dbusid = g_bus_own_name_on_connection(config.dbus, ++ name_on_bus, ++ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | ++ G_BUS_NAME_OWNER_FLAGS_REPLACE, ++ name_acquired_handler, ++ name_lost_handler, ++ NULL, ++ NULL); ++ + /* In order to receive EPIPE while writing to the pipe whose reading end + * is closed, the SIGPIPE signal has to be handled. For more information + * see the io_thread_write_pcm() function. */ +@@ -359,5 +388,8 @@ int main(int argc, char **argv) { + bluealsa_ctl_free(); + bluealsa_config_free(); + ++ g_bus_unown_name (g_dbusid); ++ free(name_on_bus); ++ + return EXIT_SUCCESS; + } +-- +2.16.4 + diff --git a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-increased-the-number-of-connexions-to-16.patch b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-increased-the-number-of-connexions-to-16.patch deleted file mode 100644 index 0448fabb..00000000 --- a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0003-increased-the-number-of-connexions-to-16.patch +++ /dev/null @@ -1,25 +0,0 @@ -From c13a5d8a00b6a1f1293cf7c4bc493f559b7d2591 Mon Sep 17 00:00:00 2001 -From: Thierry Bultel -Date: Mon, 10 Dec 2018 16:06:23 +0100 -Subject: [PATCH 3/3] increased the number of connexions to 16 - ---- - src/bluealsa.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/bluealsa.h b/src/bluealsa.h -index b73241e..12f3c0a 100644 ---- a/src/bluealsa.h -+++ b/src/bluealsa.h -@@ -31,7 +31,7 @@ - #include - - /* Maximal number of clients connected to the controller. */ --#define BLUEALSA_MAX_CLIENTS 7 -+#define BLUEALSA_MAX_CLIENTS 16 - - /* Indexes of special file descriptors in the poll array. */ - #define CTL_IDX_SRV 0 --- -2.16.4 - diff --git a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0004-Fixed-the-SIGSEGV-at-PCM-close.patch b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0004-Fixed-the-SIGSEGV-at-PCM-close.patch deleted file mode 100644 index 52dbf773..00000000 --- a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa/0004-Fixed-the-SIGSEGV-at-PCM-close.patch +++ /dev/null @@ -1,180 +0,0 @@ -From 23a1f554565c0cb9fade1a8f86ab9a09bf3d04e7 Mon Sep 17 00:00:00 2001 -From: Thierry Bultel -Date: Wed, 26 Dec 2018 10:06:38 +0100 -Subject: [PATCH] Fixed the SIGSEGV at PCM close - -There is a (still not identified) race condition at PCM -close, producing a SIGSEGV when pthread_cancel is called. -Instead of proposing a trick with pthread_setcancelstate, -this fix introduces a cancellation pipe, on which the io_thread -polls. This guaranties a better, safer, exit path. - -Signed-off-by: Thierry Bultel ---- - src/asound/bluealsa-pcm.c | 82 +++++++++++++++++++++++++++++++++++++++++------ - 1 file changed, 72 insertions(+), 10 deletions(-) - -diff --git a/src/asound/bluealsa-pcm.c b/src/asound/bluealsa-pcm.c -index 2136964..013aebb 100644 ---- a/src/asound/bluealsa-pcm.c -+++ b/src/asound/bluealsa-pcm.c -@@ -67,6 +67,8 @@ struct bluealsa_pcm { - snd_pcm_uframes_t io_hw_boundary; - snd_pcm_uframes_t io_hw_ptr; - -+ int cancelPipe[2]; -+ - }; - - -@@ -107,7 +109,9 @@ static void *io_thread(void *arg) { - struct asrsync asrs; - asrsync_init(&asrs, io->rate); - -- debug("Starting IO loop"); -+ const char * type = io->stream== SND_PCM_STREAM_CAPTURE?"CAPTURE":"PLAYBACK"; -+ -+ debug("------------ Starting IO loop (%s)-----------------------", type); - for (;;) { - - int tmp; -@@ -124,6 +128,11 @@ static void *io_thread(void *arg) { - debug("IO thread resumed: %d", io->state); - } - -+ if (pcm->io_started == false) { -+ debug("io_thread not started -> exit"); -+ goto final; -+ } -+ - snd_pcm_uframes_t io_ptr = pcm->io_ptr; - snd_pcm_uframes_t io_buffer_size = io->buffer_size; - snd_pcm_uframes_t io_hw_ptr = pcm->io_hw_ptr; -@@ -152,21 +161,44 @@ static void *io_thread(void *arg) { - if (io_hw_ptr >= io_hw_boundary) - io_hw_ptr -= io_hw_boundary; - -+ struct pollfd fds[2]; -+ -+ fds[0].fd = pcm->pcm_fd; -+ fds[1].fd = pcm->cancelPipe[0]; -+ -+ if (io->stream == SND_PCM_STREAM_CAPTURE) -+ fds[0].events |= POLLIN; -+ else -+ fds[0].events |= POLLOUT; -+ -+ fds[1].events = POLLIN | POLLHUP; -+ - if (io->stream == SND_PCM_STREAM_CAPTURE) { - - /* Read the whole period "atomically". This will assure, that frames - * are not fragmented, so the pointer can be correctly updated. */ -- while (len != 0 && (ret = read(pcm->pcm_fd, head, len)) != 0) { -+ while (len != 0 && -+ pcm->io_started) { -+ -+ int pollres = poll(fds, 2, -1); -+ -+ if ((fds[1].revents & POLLIN) != 0) { -+ debug("io_thread: CANCELLED"); -+ goto final; -+ } -+ -+ ret = read(pcm->pcm_fd, head, len); - if (ret == -1) { -- if (errno == EINTR) -- continue; -+ if (errno == EINTR) { -+ break; -+ } - SNDERR("PCM FIFO read error: %s", strerror(errno)); - goto final; - } - head += ret; - len -= ret; -- } - -+ } - if (ret == 0) - goto final; - -@@ -182,9 +214,18 @@ static void *io_thread(void *arg) { - - /* Perform atomic write - see the explanation above. */ - do { -+ -+ int pollres = poll(fds, 2, -1); -+ -+ if ((fds[1].revents & POLLIN) != 0) { -+ debug("io_thread: CANCELLED"); -+ goto final; -+ } -+ - if ((ret = write(pcm->pcm_fd, head, len)) == -1) { -- if (errno == EINTR) -- continue; -+ if (errno == EINTR) { -+ break; -+ } - SNDERR("PCM FIFO write error: %s", strerror(errno)); - goto final; - } -@@ -251,12 +292,24 @@ static int bluealsa_start(snd_pcm_ioplug_t *io) { - - static int bluealsa_stop(snd_pcm_ioplug_t *io) { - struct bluealsa_pcm *pcm = io->private_data; -- debug("Stopping"); -+ debug("Stopping %p", pcm); -+ if (!pcm) { -+ debug("PCM ALREADY CLOSED !"); -+ return 0; -+ } - if (pcm->io_started) { - pcm->io_started = false; -- pthread_cancel(pcm->io_thread); -+ -+ char dummy = 0; -+ -+ if (write(pcm->cancelPipe[1], &dummy, sizeof(dummy)) < 0) -+ debug("Failed to write to the cancellation pipe"); -+ - pthread_join(pcm->io_thread, NULL); - } -+done: -+ debug("Stop done"); -+ - return 0; - } - -@@ -269,10 +322,14 @@ static snd_pcm_sframes_t bluealsa_pointer(snd_pcm_ioplug_t *io) { - - static int bluealsa_close(snd_pcm_ioplug_t *io) { - struct bluealsa_pcm *pcm = io->private_data; -- debug("Closing plugin"); -+ debug("Closing plugin %p", pcm); - close(pcm->fd); - close(pcm->event_fd); -+ close(pcm->cancelPipe[0]); -+ close(pcm->cancelPipe[1]); - free(pcm); -+ io->private_data = NULL; -+ debug("PCM closed"); - return 0; - } - -@@ -649,6 +706,11 @@ SND_PCM_PLUGIN_DEFINE_FUNC(bluealsa) { - pcm->pcm_fd = -1; - pcm->delay_ex = delay; - -+ if (pipe(pcm->cancelPipe) == -1) { -+ SNDERR("BlueALSA failed to create cancellation pipe: %s", strerror(errno)); -+ ret = -errno; -+ } -+ - if ((pcm->fd = bluealsa_open(interface)) == -1) { - SNDERR("BlueALSA connection failed: %s", strerror(errno)); - ret = -errno; --- -2.16.4 - diff --git a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa_git.bbappend b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa_git.bbappend index 8c67037f..70c731a6 100644 --- a/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa_git.bbappend +++ b/meta-audio-4a-framework/recipes-connectivity/bluez-alsa/bluez-alsa_git.bbappend @@ -1,10 +1,18 @@ -# This brings some mandatory patches for the softmixer. This is not an actual hack, -# because all the 3 patches below have been discussed with the maintainer of bluez-alsa, -# and will be mainlined in the future +# This brings some mandatory patches for the softmixer and hal-manager. +# +# - patch 1 makes a communication library for hal-manager to get +# the list of audio transports from bluez-alsa +# - patch 2 makes the "debug" macro always display the caller name +# - patch 3 asks dbus for a name like 'org.bluez-alsa.hciX' where hciX +# name of the HCI interface that the bluealsa daemon instance is handling +# +# Notice that patch 2 will very likely be replaced by a full dbus interface +# in the future. +# FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" SRC_URI += "file://0001-build-and-link-with-a-shared-library.patch" SRC_URI += "file://0002-log-add-calling-function-name.patch" -SRC_URI += "file://0003-increased-the-number-of-connexions-to-16.patch" -SRC_URI += "file://0004-Fixed-the-SIGSEGV-at-PCM-close.patch" +SRC_URI += "file://0003-dbus-request-a-name-on-startup.patch" + -- 2.16.6