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

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

Merge "le_audio: Add support for max codec frame per SDU" am: fd0d1bd9 am:...

Merge "le_audio: Add support for max codec frame per SDU" am: fd0d1bd9 am: 201f77c6 am: 09a4265b

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1931001

Change-Id: I5af8e3382551d39bb2dfdefab25432391d1e785c
parents 948eaa89 09a4265b
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -1962,7 +1962,7 @@ class LeAudioClientImpl : public LeAudioClient {
      for (; ase != nullptr;
           ase = device->GetNextActiveAseWithSameDirection(ase)) {
        streams.emplace_back(std::make_pair(
            ase->cis_conn_hdl, ase->codec_config.audio_channel_allocation));
            ase->cis_conn_hdl, *ase->codec_config.audio_channel_allocation));
        num_of_channels += ase->codec_config.channel_count;
        if (sample_freq_hz == 0) {
          sample_freq_hz = ase->codec_config.GetSamplingFrequencyHz();
@@ -1983,17 +1983,17 @@ class LeAudioClientImpl : public LeAudioClient {
        }

        if (octets_per_frame == 0) {
          octets_per_frame = ase->codec_config.octets_per_codec_frame;
          octets_per_frame = *ase->codec_config.octets_per_codec_frame;
        } else {
          LOG_ASSERT(octets_per_frame ==
                     ase->codec_config.octets_per_codec_frame)
              << __func__ << " octets per frame mismatch: " << +octets_per_frame
              << " != " << ase->codec_config.octets_per_codec_frame;
              << " != " << *ase->codec_config.octets_per_codec_frame;
        }

        LOG(INFO) << __func__ << " Added CIS: " << +ase->cis_conn_hdl
                  << " to stream. Allocation: "
                  << +ase->codec_config.audio_channel_allocation
                  << +(*ase->codec_config.audio_channel_allocation)
                  << " sample_freq: " << +sample_freq_hz
                  << " frame_duration: " << +frame_duration_us
                  << " octects per frame: " << +octets_per_frame;
@@ -2144,7 +2144,7 @@ class LeAudioClientImpl : public LeAudioClient {
    std::vector<std::pair<uint16_t, uint32_t>> streams;

    stream_conf->source_streams.emplace_back(std::make_pair(
        ase->cis_conn_hdl, ase->codec_config.audio_channel_allocation));
        ase->cis_conn_hdl, *ase->codec_config.audio_channel_allocation));

    stream_conf->source_num_of_devices = 1;
    stream_conf->source_num_of_channels = 1;
@@ -2153,12 +2153,12 @@ class LeAudioClientImpl : public LeAudioClient {
    stream_conf->source_frame_duration_us =
        ase->codec_config.GetFrameDurationUs();
    stream_conf->source_octets_per_codec_frame =
        ase->codec_config.octets_per_codec_frame;
        *ase->codec_config.octets_per_codec_frame;
    stream_conf->valid = true;

    LOG(INFO) << __func__ << " Added CIS: " << +ase->cis_conn_hdl
              << " to stream. Allocation: "
              << +ase->codec_config.audio_channel_allocation
              << +(*ase->codec_config.audio_channel_allocation)
              << " sample_freq: " << +stream_conf->source_sample_frequency_hz
              << " frame_duration: " << +stream_conf->source_frame_duration_us
              << " octects per frame: "
+18 −11
Original line number Diff line number Diff line
@@ -726,7 +726,7 @@ bool LeAudioDeviceGroup::IsConfigurationSupported(

      if (device->ases_.empty()) continue;

      if (!device->IsCodecConfigurationSupported(ent.direction, ent.codec))
      if (!device->GetCodecConfigurationSupportedPac(ent.direction, ent.codec))
        continue;

      int needed_ase = std::min(static_cast<int>(max_required_ase_per_dev),
@@ -915,9 +915,8 @@ bool LeAudioDevice::ConfigureAses(
      ent.ase_cnt / ent.device_cnt + (ent.ase_cnt % ent.device_cnt);
  le_audio::types::LeAudioConfigurationStrategy strategy = ent.strategy;

  bool is_codec_supported =
      IsCodecConfigurationSupported(ent.direction, ent.codec);
  if (!is_codec_supported) return false;
  auto pac = GetCodecConfigurationSupportedPac(ent.direction, ent.codec);
  if (!pac) return false;

  int needed_ase = std::min((int)(max_required_ase_per_dev),
                            (int)(ent.ase_cnt - active_ases));
@@ -948,9 +947,16 @@ bool LeAudioDevice::ConfigureAses(
    ase->codec_config.audio_channel_allocation =
        PickAudioLocation(strategy, audio_locations, group_audio_locations);

    /* Get default value if no requirement for specific frame blocks per sdu */
    if (!ase->codec_config.codec_frames_blocks_per_sdu) {
      ase->codec_config.codec_frames_blocks_per_sdu =
          GetMaxCodecFramesPerSduFromPac(pac);
    }
    ase->max_sdu_size = codec_spec_caps::GetAudioChannelCounts(
                            ase->codec_config.audio_channel_allocation) *
                        ase->codec_config.octets_per_codec_frame;
                            *ase->codec_config.audio_channel_allocation) *
                        *ase->codec_config.octets_per_codec_frame *
                        *ase->codec_config.codec_frames_blocks_per_sdu;

    ase->metadata = GetMetadata(context_type);

    DLOG(INFO) << __func__ << " device=" << address_
@@ -1519,14 +1525,15 @@ uint8_t LeAudioDevice::GetLc3SupportedChannelCount(uint8_t direction) {
  return 0;
}

bool LeAudioDevice::IsCodecConfigurationSupported(
const struct types::acs_ac_record*
LeAudioDevice::GetCodecConfigurationSupportedPac(
    uint8_t direction, const CodecCapabilitySetting& codec_capability_setting) {
  auto& pacs =
      direction == types::kLeAudioDirectionSink ? snk_pacs_ : src_pacs_;

  if (pacs.size() == 0) {
    LOG(ERROR) << __func__ << " missing PAC for direction " << +direction;
    return false;
    return nullptr;
  }

  /* TODO: Validate channel locations */
@@ -1535,16 +1542,16 @@ bool LeAudioDevice::IsCodecConfigurationSupported(
    /* Get PAC records from tuple as second element from tuple */
    auto& pac_recs = std::get<1>(pac_tuple);

    for (const auto pac : pac_recs) {
    for (const auto& pac : pac_recs) {
      if (!IsCodecCapabilitySettingSupported(pac, codec_capability_setting))
        continue;

      return true;
      return &pac;
    };
  }

  /* Doesn't match required configuration with any PAC */
  return false;
  return nullptr;
}

/**
+1 −1
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ class LeAudioDevice {
  bool HaveAllAsesCisDisc(void);
  bool HasCisId(uint8_t id);
  uint8_t GetMatchingBidirectionCisId(const struct types::ase* base_ase);
  bool IsCodecConfigurationSupported(
  const struct types::acs_ac_record* GetCodecConfigurationSupportedPac(
      uint8_t direction, const set_configurations::CodecCapabilitySetting&
                             codec_capability_setting);
  uint8_t GetLc3SupportedChannelCount(uint8_t direction);
+6 −6
Original line number Diff line number Diff line
@@ -351,8 +351,8 @@ class PublishedAudioCapabilitiesBuilder {

    const LeAudioLc3Config config = std::get<LeAudioLc3Config>(setting.config);

    Add(setting.id, config.sampling_frequency, config.frame_duration,
        audio_channel_counts, config.octets_per_codec_frame);
    Add(setting.id, *config.sampling_frequency, *config.frame_duration,
        audio_channel_counts, *config.octets_per_codec_frame);
  }

  void Reset() { pac_records_.clear(); }
@@ -445,10 +445,10 @@ class LeAudioAseConfigurationTest : public Test {
         ase = data.device->GetNextActiveAse(ase)) {
      if (ase->direction == kLeAudioDirectionSink)
        active_channel_num_snk +=
            GetAudioChannelCounts(ase->codec_config.audio_channel_allocation);
            GetAudioChannelCounts(*ase->codec_config.audio_channel_allocation);
      else
        active_channel_num_src +=
            GetAudioChannelCounts(ase->codec_config.audio_channel_allocation);
            GetAudioChannelCounts(*ase->codec_config.audio_channel_allocation);
    }

    ASSERT_EQ(data.active_channel_num_snk, active_channel_num_snk);
@@ -867,9 +867,9 @@ TEST_F(LeAudioAseConfigurationTest, test_reconnection_media) {
  uint8_t number_of_active_ases = 1;  // Right one
  auto* ase = right->GetFirstActiveAseByDirection(kLeAudioDirectionSink);
  ::le_audio::types::AudioLocations group_snk_audio_location =
      ase->codec_config.audio_channel_allocation;
      *ase->codec_config.audio_channel_allocation;
  ::le_audio::types::AudioLocations group_src_audio_location =
      ase->codec_config.audio_channel_allocation;
      *ase->codec_config.audio_channel_allocation;

  /* Get known requirement*/
  auto* configuration = &kDualDev_OneChanStereoSnk_48_4;
+15 −5
Original line number Diff line number Diff line
@@ -31,11 +31,11 @@
#include "client_parser.h"

namespace le_audio {
using types::acs_ac_record;
using types::LeAudioContextType;

namespace set_configurations {
using set_configurations::CodecCapabilitySetting;
using types::acs_ac_record;
using types::kLeAudioCodingFormatLC3;
using types::kLeAudioDirectionSink;
using types::kLeAudioDirectionSource;
@@ -440,14 +440,24 @@ void AppendMetadataLtvEntryForStreamingContext(
                  streaming_context_ltv_entry.end());
}

uint8_t GetMaxCodecFramesPerSduFromPac(const acs_ac_record* pac) {
  auto tlv_ent = pac->codec_spec_caps.Find(
      codec_spec_caps::kLeAudioCodecLC3TypeMaxCodecFramesPerSdu);

  if (tlv_ent) return VEC_UINT8_TO_UINT8(tlv_ent.value());

  return 1;
}

}  // namespace le_audio

std::ostream& operator<<(std::ostream& os,
                         const le_audio::types::LeAudioLc3Config& config) {
  os << " LeAudioLc3Config(SamplFreq=" << loghex(config.sampling_frequency)
     << ", FrameDur=" << loghex(config.frame_duration)
     << ", OctetsPerFrame=" << int(config.octets_per_codec_frame)
     << ", AudioChanLoc=" << loghex(config.audio_channel_allocation) << ")";
  os << " LeAudioLc3Config(SamplFreq=" << loghex(*config.sampling_frequency)
     << ", FrameDur=" << loghex(*config.frame_duration)
     << ", OctetsPerFrame=" << int(*config.octets_per_codec_frame)
     << ", CodecFramesBlocksPerSDU=" << int(*config.codec_frames_blocks_per_sdu)
     << ", AudioChanLoc=" << loghex(*config.audio_channel_allocation) << ")";
  return os;
}

Loading