Loading system/audio/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -29,8 +29,10 @@ cc_library_static { shared_libs: [ "libchrome", "liblog", "server_configurable_flags", ], static_libs: [ "bluetooth_flags_c_lib", "libbase", "libbluetooth_hci_pdl", "libbluetooth_log", Loading Loading @@ -64,7 +66,11 @@ cc_library_host_shared { header_libs: [ "libbluetooth_headers", ], shared_libs: [ "server_configurable_flags", ], static_libs: [ "bluetooth_flags_c_lib", "libbase", "libbluetooth_hci_pdl", "libbluetooth_log", Loading system/audio/BUILD.gn +1 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ source_set("libbt-audio-asrc") { ] deps = [ "//bt/flags:bluetooth_flags_c_lib", "//bt/system/gd:gd_default_deps" ] } system/audio/asrc/asrc_resampler.cc +34 −18 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <base/strings/stringprintf.h> #include <bluetooth/log.h> #include <com_android_bluetooth_flags.h> #include <algorithm> #include <cmath> Loading Loading @@ -167,7 +168,22 @@ class SourceAudioHalAsrc::ClockRecovery } public: ClockRecovery() : state_{.id = StateId::RESET}, reference_timing_{0, 0, 0} { ClockRecovery(bluetooth::common::MessageLoopThread* thread) : state_{.id = StateId::RESET}, reference_timing_{0, 0, 0} { if (com::android::bluetooth::flags::run_clock_recovery_in_worker_thread()) { read_clock_timer_.SchedulePeriodic( thread->GetWeakPtr(), FROM_HERE, base::BindRepeating( [](void*) { bluetooth::shim::GetHciLayer()->EnqueueCommand( bluetooth::hci::ReadClockBuilder::Create( 0, bluetooth::hci::WhichClock::LOCAL), get_main_thread()->BindOnce( [](bluetooth::hci::CommandCompleteView) {})); }, nullptr), std::chrono::milliseconds(100)); } else { read_clock_timer_.SchedulePeriodic( get_main_thread()->GetWeakPtr(), FROM_HERE, base::BindRepeating( Loading @@ -180,6 +196,7 @@ class SourceAudioHalAsrc::ClockRecovery }, nullptr), std::chrono::milliseconds(100)); } hal::LinkClocker::Register(this); } Loading Loading @@ -411,10 +428,9 @@ inline int32_t SourceAudioHalAsrc::Resampler::Filter(const int32_t* in, #endif SourceAudioHalAsrc::SourceAudioHalAsrc(int channels, int sample_rate, int bit_depth, int interval_us, int num_burst_buffers, int burst_delay_ms) SourceAudioHalAsrc::SourceAudioHalAsrc( bluetooth::common::MessageLoopThread* thread, int channels, int sample_rate, int bit_depth, int interval_us, int num_burst_buffers, int burst_delay_ms) : sample_rate_(sample_rate), bit_depth_(bit_depth), interval_us_(interval_us), Loading Loading @@ -453,7 +469,7 @@ SourceAudioHalAsrc::SourceAudioHalAsrc(int channels, int sample_rate, // Setup modules, the 32 bits resampler is choosed over the 16 bits resampler // when the PCM bit_depth is higher than 16 bits. clock_recovery_ = std::make_unique<ClockRecovery>(); clock_recovery_ = std::make_unique<ClockRecovery>(thread); resamplers_ = std::make_unique<std::vector<Resampler>>(channels, bit_depth_); // Deduct from the PCM stream characteristics, the size of the pool buffers Loading system/audio/asrc/asrc_resampler.h +5 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <memory> #include <vector> #include "common/message_loop_thread.h" namespace bluetooth::audio::asrc { class SourceAudioHalAsrc { Loading @@ -36,9 +38,9 @@ class SourceAudioHalAsrc { // `burst_delay_ms` helps to ensure that the synchronization with the // transmission intervals is done. SourceAudioHalAsrc(int channels, int sample_rate, int bit_depth, int interval_us, int num_burst_buffers = 2, int burst_delay_ms = 500); SourceAudioHalAsrc(bluetooth::common::MessageLoopThread* thread, int channels, int sample_rate, int bit_depth, int interval_us, int num_burst_buffers = 2, int burst_delay_ms = 500); ~SourceAudioHalAsrc(); Loading system/audio/asrc/asrc_resampler_test.cc +2 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,8 @@ namespace bluetooth::audio::asrc { class SourceAudioHalAsrcTest : public SourceAudioHalAsrc { public: SourceAudioHalAsrcTest(int channels, int bitdepth) : SourceAudioHalAsrc(channels, 48000, bitdepth, 10000) {} : SourceAudioHalAsrc(&message_loop_thread, channels, 48000, bitdepth, 10000) {} template <typename T> void Resample(double ratio, const T* in, size_t in_length, size_t* in_count, Loading Loading
system/audio/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -29,8 +29,10 @@ cc_library_static { shared_libs: [ "libchrome", "liblog", "server_configurable_flags", ], static_libs: [ "bluetooth_flags_c_lib", "libbase", "libbluetooth_hci_pdl", "libbluetooth_log", Loading Loading @@ -64,7 +66,11 @@ cc_library_host_shared { header_libs: [ "libbluetooth_headers", ], shared_libs: [ "server_configurable_flags", ], static_libs: [ "bluetooth_flags_c_lib", "libbase", "libbluetooth_hci_pdl", "libbluetooth_log", Loading
system/audio/BUILD.gn +1 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ source_set("libbt-audio-asrc") { ] deps = [ "//bt/flags:bluetooth_flags_c_lib", "//bt/system/gd:gd_default_deps" ] }
system/audio/asrc/asrc_resampler.cc +34 −18 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <base/strings/stringprintf.h> #include <bluetooth/log.h> #include <com_android_bluetooth_flags.h> #include <algorithm> #include <cmath> Loading Loading @@ -167,7 +168,22 @@ class SourceAudioHalAsrc::ClockRecovery } public: ClockRecovery() : state_{.id = StateId::RESET}, reference_timing_{0, 0, 0} { ClockRecovery(bluetooth::common::MessageLoopThread* thread) : state_{.id = StateId::RESET}, reference_timing_{0, 0, 0} { if (com::android::bluetooth::flags::run_clock_recovery_in_worker_thread()) { read_clock_timer_.SchedulePeriodic( thread->GetWeakPtr(), FROM_HERE, base::BindRepeating( [](void*) { bluetooth::shim::GetHciLayer()->EnqueueCommand( bluetooth::hci::ReadClockBuilder::Create( 0, bluetooth::hci::WhichClock::LOCAL), get_main_thread()->BindOnce( [](bluetooth::hci::CommandCompleteView) {})); }, nullptr), std::chrono::milliseconds(100)); } else { read_clock_timer_.SchedulePeriodic( get_main_thread()->GetWeakPtr(), FROM_HERE, base::BindRepeating( Loading @@ -180,6 +196,7 @@ class SourceAudioHalAsrc::ClockRecovery }, nullptr), std::chrono::milliseconds(100)); } hal::LinkClocker::Register(this); } Loading Loading @@ -411,10 +428,9 @@ inline int32_t SourceAudioHalAsrc::Resampler::Filter(const int32_t* in, #endif SourceAudioHalAsrc::SourceAudioHalAsrc(int channels, int sample_rate, int bit_depth, int interval_us, int num_burst_buffers, int burst_delay_ms) SourceAudioHalAsrc::SourceAudioHalAsrc( bluetooth::common::MessageLoopThread* thread, int channels, int sample_rate, int bit_depth, int interval_us, int num_burst_buffers, int burst_delay_ms) : sample_rate_(sample_rate), bit_depth_(bit_depth), interval_us_(interval_us), Loading Loading @@ -453,7 +469,7 @@ SourceAudioHalAsrc::SourceAudioHalAsrc(int channels, int sample_rate, // Setup modules, the 32 bits resampler is choosed over the 16 bits resampler // when the PCM bit_depth is higher than 16 bits. clock_recovery_ = std::make_unique<ClockRecovery>(); clock_recovery_ = std::make_unique<ClockRecovery>(thread); resamplers_ = std::make_unique<std::vector<Resampler>>(channels, bit_depth_); // Deduct from the PCM stream characteristics, the size of the pool buffers Loading
system/audio/asrc/asrc_resampler.h +5 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <memory> #include <vector> #include "common/message_loop_thread.h" namespace bluetooth::audio::asrc { class SourceAudioHalAsrc { Loading @@ -36,9 +38,9 @@ class SourceAudioHalAsrc { // `burst_delay_ms` helps to ensure that the synchronization with the // transmission intervals is done. SourceAudioHalAsrc(int channels, int sample_rate, int bit_depth, int interval_us, int num_burst_buffers = 2, int burst_delay_ms = 500); SourceAudioHalAsrc(bluetooth::common::MessageLoopThread* thread, int channels, int sample_rate, int bit_depth, int interval_us, int num_burst_buffers = 2, int burst_delay_ms = 500); ~SourceAudioHalAsrc(); Loading
system/audio/asrc/asrc_resampler_test.cc +2 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,8 @@ namespace bluetooth::audio::asrc { class SourceAudioHalAsrcTest : public SourceAudioHalAsrc { public: SourceAudioHalAsrcTest(int channels, int bitdepth) : SourceAudioHalAsrc(channels, 48000, bitdepth, 10000) {} : SourceAudioHalAsrc(&message_loop_thread, channels, 48000, bitdepth, 10000) {} template <typename T> void Resample(double ratio, const T* in, size_t in_length, size_t* in_count, Loading