Adding processing support for the mSBC codec is somewhat problematic, because, although it is a SBC codec, the a2dp handling can't simply be reused because the codec is used on an eSCO link with transparent data, meaning the transmission unit has to be 48 bytes (fragmenting the codec packets) and reassembly and boundary detection is required to be done by the implementation. Therefore we have to implement separate render and push routines for msbc that do this fragmentation.
Fragmentation is done by emulating circular buffers. The receive (push) buffer is easy, since the mSBC packet size is 60, simply have a buffer of this size in the sbc_info area where the fragments are reassembled. Once we have a full 60 bytes, decode and restart from zero. The send (render) buffer is more problematic, since the transmit must be done from contiguous memory. This means that the buffer must be the lowest common multiple of the transmission unit and the packet size. This value is 240 since 240/48 == 5 and 240/60 == 4. So the buffer pointers are reset at 240 which is a whole number of both rendered packets and eSCO transmission units.
f22cfa8f8 bluetooth: add support for mSBC codec
meson.build | 1 +
src/modules/bluetooth/a2dp-codec-util.c | 2 +
src/modules/bluetooth/bt-codec-msbc.c | 290 ++++++++++++++++++++++++++++++++
src/modules/bluetooth/bt-codec-msbc.h | 35 ++++
src/modules/bluetooth/meson.build | 1 +
5 files changed, 329 insertions(+)