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

Commit 8556cba5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add Delay reporting for Hearing Aids" into qt-dev

parents c80a1e74 08626fe4
Loading
Loading
Loading
Loading
+39 −2
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ class HearingAidTransport
      : IBluetoothTransportInstance(
      : IBluetoothTransportInstance(
            SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH, {}),
            SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH, {}),
        stream_cb_(std::move(stream_cb)),
        stream_cb_(std::move(stream_cb)),
        remote_delay_report_ms_(0),
        total_bytes_read_(0),
        total_bytes_read_(0),
        data_position_({}){};
        data_position_({}){};


@@ -79,10 +80,14 @@ class HearingAidTransport
                               timespec* data_position) override {
                               timespec* data_position) override {
    VLOG(2) << __func__ << ": data=" << total_bytes_read_
    VLOG(2) << __func__ << ": data=" << total_bytes_read_
            << " byte(s), timestamp=" << data_position_.tv_sec << "."
            << " byte(s), timestamp=" << data_position_.tv_sec << "."
            << data_position_.tv_nsec << "s";
            << data_position_.tv_nsec
    if (remote_delay_report_ns != nullptr) *remote_delay_report_ns = 0;
            << "s, delay report=" << remote_delay_report_ms_ << " msec.";
    if (remote_delay_report_ns != nullptr) {
      *remote_delay_report_ns = remote_delay_report_ms_ * 1000000u;
    }
    if (total_bytes_read != nullptr) *total_bytes_read = total_bytes_read_;
    if (total_bytes_read != nullptr) *total_bytes_read = total_bytes_read_;
    if (data_position != nullptr) *data_position = data_position_;
    if (data_position != nullptr) *data_position = data_position_;

    return true;
    return true;
  }
  }


@@ -100,6 +105,8 @@ class HearingAidTransport
  }
  }


  void ResetPresentationPosition() override {
  void ResetPresentationPosition() override {
    VLOG(2) << __func__ << ": called.";
    remote_delay_report_ms_ = 0;
    total_bytes_read_ = 0;
    total_bytes_read_ = 0;
    data_position_ = {};
    data_position_ = {};
  }
  }
@@ -111,8 +118,14 @@ class HearingAidTransport
    }
    }
  }
  }


  void SetRemoteDelay(uint16_t delay_report_ms) {
    LOG(INFO) << __func__ << ": delay_report=" << delay_report_ms << " msec";
    remote_delay_report_ms_ = delay_report_ms;
  }

 private:
 private:
  StreamCallbacks stream_cb_;
  StreamCallbacks stream_cb_;
  uint16_t remote_delay_report_ms_;
  uint64_t total_bytes_read_;
  uint64_t total_bytes_read_;
  timespec data_position_;
  timespec data_position_;
};
};
@@ -134,6 +147,10 @@ bluetooth::audio::BluetoothAudioClientInterface*
bool btaudio_hearing_aid_disabled = false;
bool btaudio_hearing_aid_disabled = false;
bool is_configured = false;
bool is_configured = false;


// Save the value if the remote reports its delay before hearing_aid_sink is
// initialized
uint16_t remote_delay_ms = 0;

bool is_hal_2_0_force_disabled() {
bool is_hal_2_0_force_disabled() {
  if (!is_configured) {
  if (!is_configured) {
    btaudio_hearing_aid_disabled = osi_property_get_bool(BLUETOOTH_AUDIO_HAL_PROP_DISABLED, false);
    btaudio_hearing_aid_disabled = osi_property_get_bool(BLUETOOTH_AUDIO_HAL_PROP_DISABLED, false);
@@ -171,6 +188,13 @@ bool init(StreamCallbacks stream_cb,
    hearing_aid_sink = nullptr;
    hearing_aid_sink = nullptr;
    return false;
    return false;
  }
  }

  if (remote_delay_ms != 0) {
    LOG(INFO) << __func__ << ": restore DELAY " << remote_delay_ms << " ms";
    hearing_aid_sink->SetRemoteDelay(remote_delay_ms);
    remote_delay_ms = 0;
  }

  return true;
  return true;
}
}


@@ -182,6 +206,7 @@ void cleanup() {
  hearing_aid_hal_clientinterface = nullptr;
  hearing_aid_hal_clientinterface = nullptr;
  delete hearing_aid_sink;
  delete hearing_aid_sink;
  hearing_aid_sink = nullptr;
  hearing_aid_sink = nullptr;
  remote_delay_ms = 0;
}
}


void start_session() {
void start_session() {
@@ -212,6 +237,18 @@ size_t read(uint8_t* p_buf, uint32_t len) {
  return hearing_aid_hal_clientinterface->ReadAudioData(p_buf, len);
  return hearing_aid_hal_clientinterface->ReadAudioData(p_buf, len);
}
}


// Update Hearing Aids delay report to BluetoothAudio HAL
void set_remote_delay(uint16_t delay_report_ms) {
  if (!is_hal_2_0_enabled()) {
    LOG(INFO) << __func__ << ":  not ready for DelayReport " << delay_report_ms
              << " ms";
    remote_delay_ms = delay_report_ms;
    return;
  }
  LOG(INFO) << __func__ << ": delay_report_ms=" << delay_report_ms << " ms";
  hearing_aid_sink->SetRemoteDelay(delay_report_ms);
}

}  // namespace hearing_aid
}  // namespace hearing_aid
}  // namespace audio
}  // namespace audio
}  // namespace bluetooth
}  // namespace bluetooth
+2 −0
Original line number Original line Diff line number Diff line
@@ -42,6 +42,8 @@ void cleanup();
void start_session();
void start_session();
void end_session();
void end_session();


void set_remote_delay(uint16_t delay_report_ms);

// Read from the FMQ of BluetoothAudio HAL
// Read from the FMQ of BluetoothAudio HAL
size_t read(uint8_t* p_buf, uint32_t len);
size_t read(uint8_t* p_buf, uint32_t len);


+19 −2
Original line number Original line Diff line number Diff line
@@ -72,6 +72,13 @@ constexpr uint8_t AUDIOTYPE_UNKNOWN = 0x00;
constexpr uint8_t OTHER_SIDE_NOT_STREAMING = 0x00;
constexpr uint8_t OTHER_SIDE_NOT_STREAMING = 0x00;
constexpr uint8_t OTHER_SIDE_IS_STREAMING = 0x01;
constexpr uint8_t OTHER_SIDE_IS_STREAMING = 0x01;


// This ADD_RENDER_DELAY_INTERVALS is the number of connection intervals when
// the audio data packet is send by Audio Engine to when the Hearing Aids device
// received it from the air. We assumed that there is 2 data buffer queued from
// audio subsystem to bluetooth chip. Then the estimated OTA delay is two
// connnection intervals.
constexpr uint16_t ADD_RENDER_DELAY_INTERVALS = 4;

namespace {
namespace {


// clang-format off
// clang-format off
@@ -987,7 +994,14 @@ class HearingAidImpl : public HearingAid {
      codec.bit_rate = 16;
      codec.bit_rate = 16;
      codec.data_interval_ms = default_data_interval_ms;
      codec.data_interval_ms = default_data_interval_ms;


      HearingAidAudioSource::Start(codec, audioReceiver);
      uint16_t delay_report_ms = 0;
      if (hearingDevice.render_delay != 0) {
        delay_report_ms =
            hearingDevice.render_delay +
            (ADD_RENDER_DELAY_INTERVALS * default_data_interval_ms);
      }

      HearingAidAudioSource::Start(codec, audioReceiver, delay_report_ms);
    }
    }
  }
  }


@@ -1421,7 +1435,8 @@ class HearingAidImpl : public HearingAid {
    bool connected = hearingDevice->accepting_audio;
    bool connected = hearingDevice->accepting_audio;


    LOG(INFO) << "GAP_EVT_CONN_CLOSED: " << hearingDevice->address
    LOG(INFO) << "GAP_EVT_CONN_CLOSED: " << hearingDevice->address
              << ", playback_started=" << hearingDevice->playback_started;
              << ", playback_started=" << hearingDevice->playback_started
              << ", accepting_audio=" << hearingDevice->accepting_audio;


    if (hearingDevice->connecting_actively) {
    if (hearingDevice->connecting_actively) {
      // cancel pending direct connect
      // cancel pending direct connect
@@ -1453,6 +1468,8 @@ class HearingAidImpl : public HearingAid {
              << loghex(conn_id);
              << loghex(conn_id);
      return;
      return;
    }
    }
    VLOG(2) << __func__ << ": conn_id=" << loghex(conn_id)
            << ", reason=" << loghex(reason) << ", remote_bda=" << remote_bda;


    // Inform the other side (if any) of this disconnection
    // Inform the other side (if any) of this disconnection
    std::vector<uint8_t> inform_disconn_state(
    std::vector<uint8_t> inform_disconn_state(
+3 −1
Original line number Original line Diff line number Diff line
@@ -367,7 +367,8 @@ bool hearing_aid_on_suspend_req() {
}  // namespace
}  // namespace


void HearingAidAudioSource::Start(const CodecConfiguration& codecConfiguration,
void HearingAidAudioSource::Start(const CodecConfiguration& codecConfiguration,
                                  HearingAidAudioReceiver* audioReceiver) {
                                  HearingAidAudioReceiver* audioReceiver,
                                  uint16_t remote_delay_ms) {
  localAudioReceiver = audioReceiver;
  localAudioReceiver = audioReceiver;
  VLOG(2) << "Hearing Aid UIPC Open";
  VLOG(2) << "Hearing Aid UIPC Open";


@@ -379,6 +380,7 @@ void HearingAidAudioSource::Start(const CodecConfiguration& codecConfiguration,


  if (bluetooth::audio::hearing_aid::is_hal_2_0_enabled()) {
  if (bluetooth::audio::hearing_aid::is_hal_2_0_enabled()) {
    bluetooth::audio::hearing_aid::start_session();
    bluetooth::audio::hearing_aid::start_session();
    bluetooth::audio::hearing_aid::set_remote_delay(remote_delay_ms);
  }
  }
}
}


+2 −1
Original line number Original line Diff line number Diff line
@@ -241,7 +241,8 @@ struct CodecConfiguration {
class HearingAidAudioSource {
class HearingAidAudioSource {
 public:
 public:
  static void Start(const CodecConfiguration& codecConfiguration,
  static void Start(const CodecConfiguration& codecConfiguration,
                    HearingAidAudioReceiver* audioReceiver);
                    HearingAidAudioReceiver* audioReceiver,
                    uint16_t remote_delay_ms);
  static void Stop();
  static void Stop();
  static void Initialize();
  static void Initialize();
  static void CleanUp();
  static void CleanUp();
Loading