summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author liyong <liyong@allwinnertech.com> 2022-10-08 16:18:52 +0800
committer Jakub Pawlowski <jpawlowski@google.com> 2022-10-20 09:27:57 +0200
commit1aff43dd2bb4cfe190a9a342e5f3b5755638eef9 (patch)
treed0d3e8842aab9ffcfe898e31b2842e6591815232
parent9e292d6d97a19c547fb7022dd6ead3f425ac656e (diff)
fix audio_bluetooth_hw frame_count overflow
Test: atest audio_bluetooth_hw_test Bug: 252096083 Change-Id: I19fd747430231be2914c00cf351450ed0b84ed16
-rw-r--r--system/audio_bluetooth_hw/stream_apis.cc9
-rw-r--r--system/audio_bluetooth_hw/utils.cc4
-rw-r--r--system/audio_bluetooth_hw/utils.h1
-rw-r--r--system/audio_bluetooth_hw/utils_unittest.cc6
4 files changed, 14 insertions, 6 deletions
diff --git a/system/audio_bluetooth_hw/stream_apis.cc b/system/audio_bluetooth_hw/stream_apis.cc
index 1f449fc3cd..5facd12a6b 100644
--- a/system/audio_bluetooth_hw/stream_apis.cc
+++ b/system/audio_bluetooth_hw/stream_apis.cc
@@ -34,6 +34,7 @@
#include "utils.h"
using ::android::base::StringPrintf;
+using ::android::bluetooth::audio::utils::FrameCount;
using ::android::bluetooth::audio::utils::GetAudioParamString;
using ::android::bluetooth::audio::utils::ParseAudioParams;
@@ -691,10 +692,6 @@ static void out_update_source_metadata(
out->bluetooth_output_->UpdateSourceMetadata(source_metadata);
}
-static size_t frame_count(size_t microseconds, uint32_t sample_rate) {
- return (microseconds * sample_rate) / 1000000;
-}
-
int adev_open_output_stream(struct audio_hw_device* dev,
audio_io_handle_t handle, audio_devices_t devices,
audio_output_flags_t flags,
@@ -782,7 +779,7 @@ int adev_open_output_stream(struct audio_hw_device* dev,
}
out->frames_count_ =
- frame_count(out->preferred_data_interval_us, out->sample_rate_);
+ FrameCount(out->preferred_data_interval_us, out->sample_rate_);
out->frames_rendered_ = 0;
out->frames_presented_ = 0;
@@ -1277,7 +1274,7 @@ int adev_open_input_stream(struct audio_hw_device* dev,
}
in->frames_count_ =
- frame_count(in->preferred_data_interval_us, in->sample_rate_);
+ FrameCount(in->preferred_data_interval_us, in->sample_rate_);
in->frames_presented_ = 0;
BluetoothStreamIn* in_ptr = in.release();
diff --git a/system/audio_bluetooth_hw/utils.cc b/system/audio_bluetooth_hw/utils.cc
index b3ac7a51d5..f864fd5016 100644
--- a/system/audio_bluetooth_hw/utils.cc
+++ b/system/audio_bluetooth_hw/utils.cc
@@ -57,6 +57,10 @@ std::string GetAudioParamString(
return sout.str();
}
+size_t FrameCount(uint64_t microseconds, uint32_t sample_rate) {
+ return (microseconds * sample_rate) / 1000000;
+}
+
} // namespace utils
} // namespace audio
} // namespace bluetooth
diff --git a/system/audio_bluetooth_hw/utils.h b/system/audio_bluetooth_hw/utils.h
index 817a432a31..bdd8a9bc3f 100644
--- a/system/audio_bluetooth_hw/utils.h
+++ b/system/audio_bluetooth_hw/utils.h
@@ -42,6 +42,7 @@ std::unordered_map<std::string, std::string> ParseAudioParams(
std::string GetAudioParamString(
std::unordered_map<std::string, std::string>& params_map);
+size_t FrameCount(uint64_t microseconds, uint32_t sample_rate);
} // namespace utils
} // namespace audio
} // namespace bluetooth
diff --git a/system/audio_bluetooth_hw/utils_unittest.cc b/system/audio_bluetooth_hw/utils_unittest.cc
index 665dea63e1..1bcd5ddc66 100644
--- a/system/audio_bluetooth_hw/utils_unittest.cc
+++ b/system/audio_bluetooth_hw/utils_unittest.cc
@@ -21,6 +21,7 @@
namespace {
+using ::android::bluetooth::audio::utils::FrameCount;
using ::android::bluetooth::audio::utils::ParseAudioParams;
class UtilsTest : public testing::Test {
@@ -133,4 +134,9 @@ TEST_F(UtilsTest, HashMapTwoPairsWithFirstKeyEmpty) {
EXPECT_EQ(map_["key1"], "value1");
}
+TEST_F(UtilsTest, FrameCountTest) {
+ EXPECT_EQ(FrameCount(120000, 44100), 5292);
+ EXPECT_EQ(FrameCount(7500, 32000), 240);
+}
+
} // namespace