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

Commit 687a1af5 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Jakub Pawłowski
Browse files

Pass preferred data interval for both audio input and output

Move GetPreferredDataIntervalUs from BluetoothAudioPortOut
into parent class BluetoothAudioPort, it's needed for both In and Out.

Computation of frame_count for input is broken for last couple days,
fix it.

Test: phone call using LE Audio
Bug: 150670922
Change-Id: Ie03d1d7b0d0252626f4a5f891be48f1280d26705
parent 7040a1d0
Loading
Loading
Loading
Loading
+20 −21
Original line number Diff line number Diff line
@@ -280,6 +280,26 @@ bool BluetoothAudioPort::in_use() const {
  return (cookie_ != android::bluetooth::audio::kObserversCookieUndefined);
}

bool BluetoothAudioPort::GetPreferredDataIntervalUs(size_t* interval_us) const {
  if (!in_use()) {
    return false;
  }

  const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration&
      hal_audio_cfg =
          BluetoothAudioSessionControl_2_2::GetAudioConfig(session_type_);
  if (hal_audio_cfg.getDiscriminator() !=
      ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration::
          hidl_discriminator::pcmConfig) {
    return false;
  }

  const ::android::hardware::bluetooth::audio::V2_1::PcmParameters& pcm_cfg =
      hal_audio_cfg.pcmConfig();
  *interval_us = pcm_cfg.dataIntervalUs;
  return true;
}

bool BluetoothAudioPortOut::LoadAudioConfig(audio_config_t* audio_cfg) const {
  if (!in_use()) {
    LOG(ERROR) << __func__ << ": BluetoothAudioPortOut is not in use";
@@ -319,27 +339,6 @@ bool BluetoothAudioPortOut::LoadAudioConfig(audio_config_t* audio_cfg) const {
  return true;
}

bool BluetoothAudioPortOut::GetPreferredDataIntervalUs(
    size_t* interval_us) const {
  if (!in_use()) {
    return false;
  }

  const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration&
      hal_audio_cfg =
          BluetoothAudioSessionControl_2_2::GetAudioConfig(session_type_);
  if (hal_audio_cfg.getDiscriminator() !=
      ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration::
          hidl_discriminator::pcmConfig) {
    return false;
  }

  const ::android::hardware::bluetooth::audio::V2_1::PcmParameters& pcm_cfg =
      hal_audio_cfg.pcmConfig();
  *interval_us = pcm_cfg.dataIntervalUs;
  return true;
}

bool BluetoothAudioPortIn::LoadAudioConfig(audio_config_t* audio_cfg) const {
  if (!in_use()) {
    LOG(ERROR) << __func__ << ": BluetoothAudioPortIn is not in use";
+2 −1
Original line number Diff line number Diff line
@@ -89,6 +89,8 @@ class BluetoothAudioPort {
           session_type_ == SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH;
  }

  bool GetPreferredDataIntervalUs(size_t* interval_us) const;

 protected:
  uint16_t cookie_;
  BluetoothStreamState state_;
@@ -119,7 +121,6 @@ class BluetoothAudioPortOut : public BluetoothAudioPort {
  // The audio data path to the Bluetooth stack (Software encoding)
  size_t WriteData(const void* buffer, size_t bytes) const;
  bool LoadAudioConfig(audio_config_t* audio_cfg) const;
  bool GetPreferredDataIntervalUs(size_t* interval_us) const;
};

class BluetoothAudioPortIn : public BluetoothAudioPort {
+19 −4
Original line number Diff line number Diff line
@@ -755,8 +755,11 @@ int adev_open_output_stream(struct audio_hw_device* dev,
    bluetooth_device->opened_stream_outs_.push_back(out);
  }
  *stream_out = &out->stream_out_;
  LOG(INFO) << __func__ << ": state=" << out->bluetooth_output_.GetState() << ", sample_rate=" << out->sample_rate_
            << ", channels=" << StringPrintf("%#x", out->channel_mask_) << ", format=" << out->format_
  LOG(INFO) << __func__ << ": state=" << out->bluetooth_output_.GetState()
            << ", sample_rate=" << out->sample_rate_
            << ", channels=" << StringPrintf("%#x", out->channel_mask_)
            << ", format=" << out->format_
            << ", preferred_data_interval_us=" << out->preferred_data_interval_us
            << ", frames=" << out->frames_count_;
  return 0;
}
@@ -1197,15 +1200,27 @@ int adev_open_input_stream(struct audio_hw_device* dev,
  in->channel_mask_ = config->channel_mask;
  in->format_ = config->format;
  // frame is number of samples per channel

  size_t preferred_data_interval_us = kBluetoothDefaultOutputBufferMs * 1000;
  if (in->bluetooth_input_.GetPreferredDataIntervalUs(
          &preferred_data_interval_us) &&
      preferred_data_interval_us != 0) {
    in->preferred_data_interval_us = preferred_data_interval_us;
  } else {
    in->preferred_data_interval_us = kBluetoothDefaultOutputBufferMs * 1000;
  }

  in->frames_count_ =
      frame_count(kBluetoothDefaultInputBufferMs, in->sample_rate_);
      frame_count(in->preferred_data_interval_us, in->sample_rate_);
  in->frames_presented_ = 0;

  *stream_in = &in->stream_in_;
  LOG(INFO) << __func__ << ": state=" << in->bluetooth_input_.GetState()
            << ", sample_rate=" << in->sample_rate_
            << ", channels=" << StringPrintf("%#x", in->channel_mask_)
            << ", format=" << in->format_ << ", frames=" << in->frames_count_;
            << ", format=" << in->format_
            << ", preferred_data_interval_us=" << in->preferred_data_interval_us
            << ", frames=" << in->frames_count_;

  return 0;
}
+1 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ struct BluetoothStreamIn {
  uint32_t sample_rate_;
  audio_channel_mask_t channel_mask_;
  audio_format_t format_;
  size_t preferred_data_interval_us;
  // frame is the number of samples per channel
  // frames count per tick
  size_t frames_count_;