Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1aff43dd authored by liyong's avatar liyong Committed by Jakub Pawlowski
Browse files

fix audio_bluetooth_hw frame_count overflow

Test: atest audio_bluetooth_hw_test
Bug: 252096083
Change-Id: I19fd747430231be2914c00cf351450ed0b84ed16
parent 9e292d6d
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -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();
+4 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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