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

Commit 9bbd41b2 authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Automerger Merge Worker
Browse files

Merge "fix audio_bluetooth_hw frame_count overflow" am: ca277374 am: f65fb3b4

parents 9269268d f65fb3b4
Loading
Loading
Loading
Loading
+3 −6
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@
#include "utils.h"
#include "utils.h"


using ::android::base::StringPrintf;
using ::android::base::StringPrintf;
using ::android::bluetooth::audio::utils::FrameCount;
using ::android::bluetooth::audio::utils::GetAudioParamString;
using ::android::bluetooth::audio::utils::GetAudioParamString;
using ::android::bluetooth::audio::utils::ParseAudioParams;
using ::android::bluetooth::audio::utils::ParseAudioParams;


@@ -691,10 +692,6 @@ static void out_update_source_metadata(
  out->bluetooth_output_->UpdateSourceMetadata(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,
int adev_open_output_stream(struct audio_hw_device* dev,
                            audio_io_handle_t handle, audio_devices_t devices,
                            audio_io_handle_t handle, audio_devices_t devices,
                            audio_output_flags_t flags,
                            audio_output_flags_t flags,
@@ -782,7 +779,7 @@ int adev_open_output_stream(struct audio_hw_device* dev,
  }
  }


  out->frames_count_ =
  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_rendered_ = 0;
  out->frames_presented_ = 0;
  out->frames_presented_ = 0;
@@ -1277,7 +1274,7 @@ int adev_open_input_stream(struct audio_hw_device* dev,
  }
  }


  in->frames_count_ =
  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;
  in->frames_presented_ = 0;


  BluetoothStreamIn* in_ptr = in.release();
  BluetoothStreamIn* in_ptr = in.release();
+4 −0
Original line number Original line Diff line number Diff line
@@ -57,6 +57,10 @@ std::string GetAudioParamString(
  return sout.str();
  return sout.str();
}
}


size_t FrameCount(uint64_t microseconds, uint32_t sample_rate) {
  return (microseconds * sample_rate) / 1000000;
}

}  // namespace utils
}  // namespace utils
}  // namespace audio
}  // namespace audio
}  // namespace bluetooth
}  // namespace bluetooth
+1 −0
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ std::unordered_map<std::string, std::string> ParseAudioParams(
std::string GetAudioParamString(
std::string GetAudioParamString(
    std::unordered_map<std::string, std::string>& params_map);
    std::unordered_map<std::string, std::string>& params_map);


size_t FrameCount(uint64_t microseconds, uint32_t sample_rate);
}  // namespace utils
}  // namespace utils
}  // namespace audio
}  // namespace audio
}  // namespace bluetooth
}  // namespace bluetooth
+6 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@


namespace {
namespace {


using ::android::bluetooth::audio::utils::FrameCount;
using ::android::bluetooth::audio::utils::ParseAudioParams;
using ::android::bluetooth::audio::utils::ParseAudioParams;


class UtilsTest : public testing::Test {
class UtilsTest : public testing::Test {
@@ -133,4 +134,9 @@ TEST_F(UtilsTest, HashMapTwoPairsWithFirstKeyEmpty) {
  EXPECT_EQ(map_["key1"], "value1");
  EXPECT_EQ(map_["key1"], "value1");
}
}


TEST_F(UtilsTest, FrameCountTest) {
  EXPECT_EQ(FrameCount(120000, 44100), 5292);
  EXPECT_EQ(FrameCount(7500, 32000), 240);
}

}  // namespace
}  // namespace