From a0cc24730eafe91021643b9b36889d61728f58f0 Mon Sep 17 00:00:00 2001 From: Cheney Ni Date: Thu, 29 Jul 2021 00:50:03 +0800 Subject: [PATCH] BluetoothAudio: Refine the FMQ size for A2DP software encoding For those high-resolution codecs, they are 24 or 32 bits per sample, so the buffer size must be the LCM of 16, 24, and 32. Bug: 194980528 Test: A2DP playing with aptX and / or LDAC Change-Id: I788e185496dea4a1b40fa369e032a4f8491b835b --- bluetooth/audio/2.0/default/A2dpSoftwareAudioProvider.cpp | 8 ++++++-- bluetooth/audio/2.1/default/A2dpSoftwareAudioProvider.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bluetooth/audio/2.0/default/A2dpSoftwareAudioProvider.cpp b/bluetooth/audio/2.0/default/A2dpSoftwareAudioProvider.cpp index f71a73e233..0c0b85fdf3 100644 --- a/bluetooth/audio/2.0/default/A2dpSoftwareAudioProvider.cpp +++ b/bluetooth/audio/2.0/default/A2dpSoftwareAudioProvider.cpp @@ -32,10 +32,14 @@ namespace implementation { using ::android::bluetooth::audio::BluetoothAudioSessionReport; using ::android::hardware::Void; +// Here the buffer size is based on SBC static constexpr uint32_t kPcmFrameSize = 4; // 16 bits per sample / stereo -static constexpr uint32_t kPcmFrameCount = 128; +// SBC is 128, and here choose the LCM of 16, 24, and 32 +static constexpr uint32_t kPcmFrameCount = 96; static constexpr uint32_t kRtpFrameSize = kPcmFrameSize * kPcmFrameCount; -static constexpr uint32_t kRtpFrameCount = 7; // max counts by 1 tick (20ms) +// The max counts by 1 tick (20ms) for SBC is about 7. Since using 96 for the +// PCM counts, here we just choose a greater number +static constexpr uint32_t kRtpFrameCount = 10; static constexpr uint32_t kBufferSize = kRtpFrameSize * kRtpFrameCount; static constexpr uint32_t kBufferCount = 2; // double buffer static constexpr uint32_t kDataMqSize = kBufferSize * kBufferCount; diff --git a/bluetooth/audio/2.1/default/A2dpSoftwareAudioProvider.cpp b/bluetooth/audio/2.1/default/A2dpSoftwareAudioProvider.cpp index a37176ba4d..4928cea66d 100644 --- a/bluetooth/audio/2.1/default/A2dpSoftwareAudioProvider.cpp +++ b/bluetooth/audio/2.1/default/A2dpSoftwareAudioProvider.cpp @@ -34,10 +34,14 @@ using ::android::bluetooth::audio::BluetoothAudioSessionReport_2_1; using ::android::hardware::Void; using ::android::hardware::bluetooth::audio::V2_0::AudioConfiguration; +// Here the buffer size is based on SBC static constexpr uint32_t kPcmFrameSize = 4; // 16 bits per sample / stereo -static constexpr uint32_t kPcmFrameCount = 128; +// SBC is 128, and here we choose the LCM of 16, 24, and 32 +static constexpr uint32_t kPcmFrameCount = 96; static constexpr uint32_t kRtpFrameSize = kPcmFrameSize * kPcmFrameCount; -static constexpr uint32_t kRtpFrameCount = 7; // max counts by 1 tick (20ms) +// The max counts by 1 tick (20ms) for SBC is about 7. Since using 96 for the +// PCM counts, here we just choose a greater number +static constexpr uint32_t kRtpFrameCount = 10; static constexpr uint32_t kBufferSize = kRtpFrameSize * kRtpFrameCount; static constexpr uint32_t kBufferCount = 2; // double buffer static constexpr uint32_t kDataMqSize = kBufferSize * kBufferCount;