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

Commit 8923190f authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Fix sending current config to Java

Fix initial value to btle_audio_codec_config_t, sample rate translation
and make sure current config can be send even stream is not yet
configured. For the last point, use latest way of getting configuration
instead of using group->stream_conf which might be invalid.

Bug: 314094343
Test: mmm packages/modules/Bluetooth
Test: atest bluetooth_le_audio_client_test
Flag: Exempt, trivial change, regression tested with unit test, new test
added
Change-Id: I4785dd95e74a44bb73674dcc7e70cd43bfea395c
parent 1cfd65e0
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -3220,8 +3220,10 @@ class LeAudioClientImpl : public LeAudioClient {

  void SendAudioGroupCurrentCodecConfigChanged(LeAudioDeviceGroup* group) {
    // This shall be called when configuration changes
    auto* stream_conf = &group->stream_conf;
    if (stream_conf == nullptr) {
    log::debug(" {} ", group->group_id_);

    auto audio_set_conf = group->GetConfiguration(configuration_context_type_);
    if (!audio_set_conf) {
      log::warn("Stream configuration is not valid for group id {}",
                group->group_id_);
      return;
@@ -3229,12 +3231,11 @@ class LeAudioClientImpl : public LeAudioClient {

    bluetooth::le_audio::btle_audio_codec_config_t input_config{};
    bluetooth::le_audio::utils::fillStreamParamsToBtLeAudioCodecConfig(
        stream_conf->codec_id, &stream_conf->stream_params.source,
        input_config);
        audio_set_conf->confs.source, input_config);

    bluetooth::le_audio::btle_audio_codec_config_t output_config{};
    bluetooth::le_audio::utils::fillStreamParamsToBtLeAudioCodecConfig(
        stream_conf->codec_id, &stream_conf->stream_params.sink, output_config);
        audio_set_conf->confs.sink, output_config);

    callbacks_->OnAudioGroupCurrentCodecConf(group->group_id_, input_config,
                                             output_config);
+26 −0
Original line number Diff line number Diff line
@@ -4842,6 +4842,19 @@ TEST_F(UnicastTest, InactiveDeviceOnInternalStateMachineError) {
                                                          .source = {}};
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, ccids)).Times(1);

  btle_audio_codec_config_t empty_conf{};
  btle_audio_codec_config_t output_config = {
      .codec_type = LE_AUDIO_CODEC_INDEX_SOURCE_LC3,
      .sample_rate = LE_AUDIO_SAMPLE_RATE_INDEX_48000HZ,
      .bits_per_sample = LE_AUDIO_BITS_PER_SAMPLE_INDEX_16,
      .channel_count = LE_AUDIO_CHANNEL_COUNT_INDEX_2,
      .frame_duration = LE_AUDIO_FRAME_DURATION_INDEX_10000US,
      .octets_per_frame = 120};

  EXPECT_CALL(mock_audio_hal_client_callbacks_,
              OnAudioGroupCurrentCodecConf(group_id, empty_conf, output_config))
      .Times(1);

  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id);

  SyncOnMainLoop();
@@ -5861,6 +5874,19 @@ TEST_F(UnicastTest, TwoEarbudsStreaming) {

  Mock::VerifyAndClearExpectations(&mock_le_audio_source_hal_client_);

  /* Make sure configurations are non empty */
  btle_audio_codec_config_t call_config = {
      .codec_type = LE_AUDIO_CODEC_INDEX_SOURCE_LC3,
      .sample_rate = LE_AUDIO_SAMPLE_RATE_INDEX_16000HZ,
      .bits_per_sample = LE_AUDIO_BITS_PER_SAMPLE_INDEX_16,
      .channel_count = LE_AUDIO_CHANNEL_COUNT_INDEX_2,
      .frame_duration = LE_AUDIO_FRAME_DURATION_INDEX_10000US,
      .octets_per_frame = 40};

  EXPECT_CALL(mock_audio_hal_client_callbacks_,
              OnAudioGroupCurrentCodecConf(group_id, call_config, call_config))
      .Times(1);

  StartStreaming(AUDIO_USAGE_VOICE_COMMUNICATION, AUDIO_CONTENT_TYPE_SPEECH,
                 group_id);

+10 −0
Original line number Diff line number Diff line
@@ -245,6 +245,16 @@ bool IsCodecConfigSettingSupported(
  return false;
}

uint16_t CodecConfigSetting::GetOctectsPerFrame() const {
  switch (id.coding_format) {
    case kLeAudioCodingFormatLC3:
      return params.GetAsCoreCodecConfig().GetOctectsPerFrame();
    default:
      log::warn(", invalid codec id: 0x{:02x}", id.coding_format);
      return 0;
  }
};

uint32_t CodecConfigSetting::GetSamplingFrequencyHz() const {
  switch (id.coding_format) {
    case kLeAudioCodingFormatLC3:
+6 −0
Original line number Diff line number Diff line
@@ -570,6 +570,10 @@ struct LeAudioCoreCodecConfig {
               : 0;
  }

  uint16_t GetOctectsPerFrame() const {
    return octets_per_codec_frame.value_or(0);
  }

  /** Returns the sampling frequency representation in Hz */
  uint32_t GetSamplingFrequencyHz() const {
    if (sampling_frequency)
@@ -1133,6 +1137,8 @@ struct CodecConfigSetting {
  /* Channel count per device */
  uint8_t channel_count_per_iso_stream;

  /* Octects per fram for codec */
  uint16_t GetOctectsPerFrame() const;
  /* Sampling freqency requested for codec */
  uint32_t GetSamplingFrequencyHz() const;
  /* Data fetch/feed interval for codec in microseconds */
+37 −13
Original line number Diff line number Diff line
@@ -264,10 +264,24 @@ translateBluetoothCodecFormatToCodecType(uint8_t codec_format) {
}

bluetooth::le_audio::btle_audio_sample_rate_index_t
translateToBtLeAudioCodecConfigSampleRate(uint32_t sample_rate_capa) {
  log::info("{}", sample_rate_capa);
  return (bluetooth::le_audio::btle_audio_sample_rate_index_t)(
      sample_rate_capa);
translateToBtLeAudioCodecConfigSampleRate(uint32_t sample_rate) {
  log::info("{}", sample_rate);
  switch (sample_rate) {
    case LeAudioCodecConfiguration::kSampleRate8000:
      return LE_AUDIO_SAMPLE_RATE_INDEX_8000HZ;
    case LeAudioCodecConfiguration::kSampleRate16000:
      return LE_AUDIO_SAMPLE_RATE_INDEX_16000HZ;
    case LeAudioCodecConfiguration::kSampleRate24000:
      return LE_AUDIO_SAMPLE_RATE_INDEX_24000HZ;
    case LeAudioCodecConfiguration::kSampleRate32000:
      return LE_AUDIO_SAMPLE_RATE_INDEX_32000HZ;
    case LeAudioCodecConfiguration::kSampleRate44100:
      return LE_AUDIO_SAMPLE_RATE_INDEX_44100HZ;
    case LeAudioCodecConfiguration::kSampleRate48000:
      return LE_AUDIO_SAMPLE_RATE_INDEX_48000HZ;
  }

  return LE_AUDIO_SAMPLE_RATE_INDEX_NONE;
}

bluetooth::le_audio::btle_audio_bits_per_sample_index_t
@@ -306,28 +320,36 @@ translateToBtLeAudioCodecConfigFrameDuration(int frame_duration) {
}

void fillStreamParamsToBtLeAudioCodecConfig(
    types::LeAudioCodecId codec_id, const stream_parameters* stream_params,
    const std::vector<struct set_configurations::AseConfiguration>& confs,
    bluetooth::le_audio::btle_audio_codec_config_t& out_config) {
  if (stream_params == nullptr) {
  if (confs.size() == 0) {
    log::warn("Stream params are null");
    return;
  }

  auto config = confs.at(0).codec;

  out_config.codec_type =
      translateBluetoothCodecFormatToCodecType(codec_id.coding_format);
      translateBluetoothCodecFormatToCodecType(config.id.coding_format);
  if (out_config.codec_type !=
      bluetooth::le_audio::LE_AUDIO_CODEC_INDEX_SOURCE_LC3) {
    return;
  }

  out_config.sample_rate = translateToBtLeAudioCodecConfigSampleRate(
      stream_params->sample_frequency_hz);
  out_config.channel_count = translateToBtLeAudioCodecConfigChannelCount(
      stream_params->num_of_channels);
      config.GetSamplingFrequencyHz());
  out_config.bits_per_sample = translateToBtLeAudioCodecConfigBitPerSample(16);
  out_config.frame_duration = translateToBtLeAudioCodecConfigFrameDuration(
      stream_params->frame_duration_us);
  out_config.octets_per_frame = stream_params->octets_per_codec_frame;
  out_config.frame_duration =
      translateToBtLeAudioCodecConfigFrameDuration(config.GetDataIntervalUs());
  out_config.octets_per_frame = config.GetOctectsPerFrame();

  int num_of_channels = 0;
  for (auto const& c : confs) {
    num_of_channels += c.codec.GetChannelCountPerIsoStream();
  }

  out_config.channel_count =
      translateToBtLeAudioCodecConfigChannelCount(num_of_channels);
}

static bool is_known_codec(const types::LeAudioCodecId& codec_id) {
@@ -360,6 +382,8 @@ static void fillRemotePacsCapabitiliesToBtLeAudioCodecConfig(
      if (!capa.IsFrameDurationConfigSupported(fd_bit)) continue;
      if (!capa.HasSupportedAudioChannelCounts()) {
        bluetooth::le_audio::btle_audio_codec_config_t config = {
            .codec_type = utils::translateBluetoothCodecFormatToCodecType(
                record.codec_id.coding_format),
            .sample_rate = utils::translateToBtLeAudioCodecConfigSampleRate(
                types::LeAudioCoreCodecConfig::GetSamplingFrequencyHz(
                    freq_bit)),
Loading