From 4120b99ab6f60e92ac3e1b78aaf4596a0a3d982f Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 6 Mar 2024 17:57:40 +0000 Subject: [PATCH] audio: Align HAL buffer size logic with the framework When the framework uses mixers, it rounds up the buffer size to the frame count which is a multiple of 16. In the HIDL implementation, this adjustment was done after the framework thread was already created, and FMQ was created on the first transfer, using adjusted size. In the AIDL implementation, the FMQ is created together with the stream, using the size suggested by the HAL. Bug: 321233946 Test: verify audio playback over S/W A2DP (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f2f9ae08c2ee4e396bbe4b8c7e955bad725ce545) Merged-In: I35a5479bfc87a290aff09d51415381948857a146 Change-Id: I35a5479bfc87a290aff09d51415381948857a146 --- audio/aidl/default/bluetooth/StreamBluetooth.cpp | 10 ++-------- audio/aidl/default/include/core-impl/Module.h | 6 ++---- audio/aidl/default/include/core-impl/StreamBluetooth.h | 1 - 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/audio/aidl/default/bluetooth/StreamBluetooth.cpp b/audio/aidl/default/bluetooth/StreamBluetooth.cpp index 77e48df26e..f22b7a97d6 100644 --- a/audio/aidl/default/bluetooth/StreamBluetooth.cpp +++ b/audio/aidl/default/bluetooth/StreamBluetooth.cpp @@ -16,16 +16,13 @@ #include -#define ATRACE_TAG ATRACE_TAG_AUDIO #define LOG_TAG "AHAL_StreamBluetooth" #include #include #include -#include #include "core-impl/StreamBluetooth.h" -using aidl::android::hardware::audio::common::frameCountFromDurationUs; using aidl::android::hardware::audio::common::SinkMetadata; using aidl::android::hardware::audio::common::SourceMetadata; using aidl::android::hardware::audio::core::VendorParameter; @@ -67,8 +64,6 @@ StreamBluetooth::StreamBluetooth(StreamContext* context, const Metadata& metadat : (mIsInput ? kBluetoothDefaultInputBufferMs : kBluetoothDefaultOutputBufferMs) * 1000), - mPreferredFrameCount( - frameCountFromDurationUs(mPreferredDataIntervalUs, pcmConfig.sampleRateHz)), mBtDeviceProxy(btDeviceProxy) {} ::android::status_t StreamBluetooth::init() { @@ -77,6 +72,7 @@ StreamBluetooth::StreamBluetooth(StreamContext* context, const Metadata& metadat // This is a normal situation in VTS tests. LOG(INFO) << __func__ << ": no BT HAL proxy, stream is non-functional"; } + LOG(INFO) << __func__ << ": preferred data interval (us): " << mPreferredDataIntervalUs; return ::android::OK; } @@ -108,12 +104,10 @@ StreamBluetooth::StreamBluetooth(StreamContext* context, const Metadata& metadat LOG(ERROR) << __func__ << ": state= " << mBtDeviceProxy->getState() << " failed to start"; return -EIO; } - const size_t fc = std::min(frameCount, mPreferredFrameCount); - const size_t bytesToTransfer = fc * mFrameSizeBytes; + const size_t bytesToTransfer = frameCount * mFrameSizeBytes; const size_t bytesTransferred = mIsInput ? mBtDeviceProxy->readData(buffer, bytesToTransfer) : mBtDeviceProxy->writeData(buffer, bytesToTransfer); *actualFrameCount = bytesTransferred / mFrameSizeBytes; - ATRACE_INT("BTdropped", bytesToTransfer - bytesTransferred); PresentationPosition presentation_position; if (!mBtDeviceProxy->getPresentationPosition(presentation_position)) { presentation_position.remoteDeviceAudioDelayNanos = diff --git a/audio/aidl/default/include/core-impl/Module.h b/audio/aidl/default/include/core-impl/Module.h index ce71d70903..8abf9ef1fe 100644 --- a/audio/aidl/default/include/core-impl/Module.h +++ b/audio/aidl/default/include/core-impl/Module.h @@ -211,10 +211,8 @@ class Module : public BnModule { const int32_t rawSizeFrames = aidl::android::hardware::audio::common::frameCountFromDurationMs(latencyMs, sampleRateHz); - if (latencyMs >= 5) return rawSizeFrames; - int32_t powerOf2 = 1; - while (powerOf2 < rawSizeFrames) powerOf2 <<= 1; - return powerOf2; + // Round up to nearest 16 frames since in the framework this is the size of a mixer burst. + return (rawSizeFrames + 15) & ~15; } ndk::ScopedAStatus bluetoothParametersUpdated(); diff --git a/audio/aidl/default/include/core-impl/StreamBluetooth.h b/audio/aidl/default/include/core-impl/StreamBluetooth.h index 35c3183560..7f4239cfb4 100644 --- a/audio/aidl/default/include/core-impl/StreamBluetooth.h +++ b/audio/aidl/default/include/core-impl/StreamBluetooth.h @@ -63,7 +63,6 @@ class StreamBluetooth : public StreamCommonImpl { const std::weak_ptr mBluetoothA2dp; const std::weak_ptr mBluetoothLe; const size_t mPreferredDataIntervalUs; - const size_t mPreferredFrameCount; mutable std::mutex mLock; // The lock is also used to serialize calls to the proxy. std::shared_ptr<::android::bluetooth::audio::aidl::BluetoothAudioPortAidl> mBtDeviceProxy