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

Commit 8cde70ee authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add Delay reporting for Hearing Aids"

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

@@ -79,10 +80,14 @@ class HearingAidTransport
                               timespec* data_position) override {
    VLOG(2) << __func__ << ": data=" << total_bytes_read_
            << " byte(s), timestamp=" << data_position_.tv_sec << "."
            << data_position_.tv_nsec << "s";
    if (remote_delay_report_ns != nullptr) *remote_delay_report_ns = 0;
            << data_position_.tv_nsec
            << "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 (data_position != nullptr) *data_position = data_position_;

    return true;
  }

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

  void ResetPresentationPosition() override {
    VLOG(2) << __func__ << ": called.";
    remote_delay_report_ms_ = 0;
    total_bytes_read_ = 0;
    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:
  StreamCallbacks stream_cb_;
  uint16_t remote_delay_report_ms_;
  uint64_t total_bytes_read_;
  timespec data_position_;
};
@@ -134,6 +147,10 @@ bluetooth::audio::BluetoothAudioClientInterface*
bool btaudio_hearing_aid_disabled = 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() {
  if (!is_configured) {
    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;
    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;
}

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

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);
}

// 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 audio
}  // namespace bluetooth
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ void cleanup();
void start_session();
void end_session();

void set_remote_delay(uint16_t delay_report_ms);

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

+19 −2
Original line number 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_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 {

// clang-format off
@@ -987,7 +994,14 @@ class HearingAidImpl : public HearingAid {
      codec.bit_rate = 16;
      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;

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

    hearingDevice->playback_started = false;

@@ -1455,6 +1470,8 @@ class HearingAidImpl : public HearingAid {
              << loghex(conn_id);
      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
    std::vector<uint8_t> inform_disconn_state(
+3 −1
Original line number Diff line number Diff line
@@ -367,7 +367,8 @@ bool hearing_aid_on_suspend_req() {
}  // namespace

void HearingAidAudioSource::Start(const CodecConfiguration& codecConfiguration,
                                  HearingAidAudioReceiver* audioReceiver) {
                                  HearingAidAudioReceiver* audioReceiver,
                                  uint16_t remote_delay_ms) {
  localAudioReceiver = audioReceiver;
  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()) {
    bluetooth::audio::hearing_aid::start_session();
    bluetooth::audio::hearing_aid::set_remote_delay(remote_delay_ms);
  }
}

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