From 0c9f0210ed77ac990b16d7ecaab223c32df13169 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sun, 11 Jul 2021 16:43:17 +0300 Subject: [PATCH] bluez5: sco-io: start writing only after the packet size is known The kernel-provided SCO write MTU is currently never the correct packet size for writing, so don't try to use it. Some adapter firmware (eg. BCM20702A0 0b05:17cb) appears in practice sensitive to the alignment of the msbc frames, and writes with wrong packet size break things but only on certain headsets. For other adapters, this doesn't appear to matter. --- spa/plugins/bluez5/sco-io.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spa/plugins/bluez5/sco-io.c b/spa/plugins/bluez5/sco-io.c index ece0e9d67..0b399e910 100644 --- a/spa/plugins/bluez5/sco-io.c +++ b/spa/plugins/bluez5/sco-io.c @@ -186,8 +186,12 @@ int spa_bt_sco_io_write(struct spa_bt_sco_io *io, uint8_t *buf, int size) uint16_t packet_size; uint8_t *buf_start = buf; - packet_size = (io->read_size > 0) ? SPA_MIN(io->write_mtu, io->read_size) : (io->write_mtu / 2) * 2; - spa_assert(packet_size > 0); + if (io->read_size == 0) { + /* The proper write packet size is not known yet */ + return 0; + } + + packet_size = SPA_MIN(io->write_mtu, io->read_size); if (size < packet_size) { return 0;