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

Commit 3f578a3f authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

LeAudio: Add names to audio set configurations from AIDL

Since there is no name for the audio set configurations in the AIDL
interface, generate a name based on the configuration parameters, e.g.
"AIDL-2-1chan-SinkAse-CodecId_6_0_0-48000hz_120oct_10000us-TargetLatency_3"

Bug: 374933885
Test: m -j
Flag: EXEMPT; No functional change
Change-Id: I822b96b82d79d18e6e46c0dd73a8f6becc343f68
parent 615fdc12
Loading
Loading
Loading
Loading
+68 −0
Original line number Original line Diff line number Diff line
@@ -507,6 +507,73 @@ static ::bluetooth::le_audio::set_configurations::AseConfiguration GetStackAseCo
  return config;
  return config;
}
}


static std::string GenerateNameForConfig(
        const ::bluetooth::le_audio::set_configurations::AudioSetConfiguration& config) {
  auto namegen = [](const std::vector<::bluetooth::le_audio::set_configurations::AseConfiguration>&
                            configs,
                    const char* dir_str) {
    std::stringstream cfg_str;
    if (configs.size() > 0) {
      auto current_config = configs.begin();
      while (current_config != configs.end()) {
        uint8_t cfg_multiplier = 1;
        auto last_equal_config = current_config;
        auto current_codec = current_config->codec;
        while (++last_equal_config != configs.end()) {
          // For the purpose of name generation, ignore the audio channel allocation
          auto current_codec_no_channels = current_codec;
          auto last_codec_no_channels = last_equal_config->codec;
          current_codec_no_channels.params.Add(
                  le_audio::codec_spec_conf::kLeAudioLtvTypeAudioChannelAllocation, (uint32_t)0);
          last_codec_no_channels.params.Add(
                  le_audio::codec_spec_conf::kLeAudioLtvTypeAudioChannelAllocation, (uint32_t)0);

          if (current_codec_no_channels != last_codec_no_channels) {
            break;
          }
          ++cfg_multiplier;
          current_config = last_equal_config;
        }

        // Channel configuration
        cfg_str << +cfg_multiplier << "-" << +current_codec.GetChannelCountPerIsoStream() << "chan";
        cfg_str << "-" << dir_str << "Ase-";
        // Codec Id
        cfg_str << "CodecId_" << +current_codec.id.coding_format << "_"
                << +current_codec.id.vendor_company_id << "_" << +current_codec.id.vendor_codec_id
                << "-";
        // Codec parameters
        cfg_str << current_codec.GetSamplingFrequencyHz() << "hz";
        if (current_codec.id.coding_format ==
            ::bluetooth::le_audio::types::kLeAudioCodingFormatLC3) {
          cfg_str << "_" << current_codec.GetOctetsPerFrame() << "oct";
          cfg_str << "_" << current_codec.GetDataIntervalUs() << "us";
        }
        // QoS
        cfg_str << "-TargetLatency_" << +current_config->qos.target_latency;

        if (last_equal_config == configs.end()) {
          break;
        }

        // Check if there are some different configs left
        ++current_config;
      }
    }
    return cfg_str.str();
  };

  std::stringstream name;
  name << "AIDL";
  if (!config.confs.sink.empty()) {
    name << "-" << namegen(config.confs.sink, "Sink");
  }
  if (!config.confs.source.empty()) {
    name << "-" << namegen(config.confs.source, "Source");
  }
  return name.str();
}

static ::bluetooth::le_audio::set_configurations::AudioSetConfiguration
static ::bluetooth::le_audio::set_configurations::AudioSetConfiguration
GetStackConfigSettingFromAidl(
GetStackConfigSettingFromAidl(
        ::bluetooth::le_audio::types::LeAudioContextType ctx_type,
        ::bluetooth::le_audio::types::LeAudioContextType ctx_type,
@@ -540,6 +607,7 @@ GetStackConfigSettingFromAidl(
    }
    }
  }
  }


  cig_config.name = GenerateNameForConfig(cig_config);
  return cig_config;
  return cig_config;
}
}


+6 −0
Original line number Original line Diff line number Diff line
@@ -918,6 +918,9 @@ TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackUnicastConfigurationFrom
  ASSERT_EQ(stack_config->confs.sink.size(), 2ul);
  ASSERT_EQ(stack_config->confs.sink.size(), 2ul);
  ASSERT_EQ(stack_config->confs.source.size(), 2ul);
  ASSERT_EQ(stack_config->confs.source.size(), 2ul);
  ASSERT_EQ(*stack_config, expected_stack_config);
  ASSERT_EQ(*stack_config, expected_stack_config);
  ASSERT_EQ(stack_config->name,
            "AIDL-2-1chan-SinkAse-CodecId_6_0_0-48000hz_120oct_7500us-TargetLatency_2-"
            "2-1chan-SourceAse-CodecId_6_0_0-24000hz_80oct_7500us-TargetLatency_1");
}
}


TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackUnicastConfigurationFromAidlFormatMonoLoc) {
TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackUnicastConfigurationFromAidlFormatMonoLoc) {
@@ -931,6 +934,9 @@ TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackUnicastConfigurationFrom
  ASSERT_EQ(stack_config->confs.sink.size(), 2ul);
  ASSERT_EQ(stack_config->confs.sink.size(), 2ul);
  ASSERT_EQ(stack_config->confs.source.size(), 1ul);
  ASSERT_EQ(stack_config->confs.source.size(), 1ul);
  ASSERT_EQ(*stack_config, expected_stack_config);
  ASSERT_EQ(*stack_config, expected_stack_config);
  ASSERT_EQ(stack_config->name,
            "AIDL-2-1chan-SinkAse-CodecId_6_0_0-48000hz_120oct_7500us-TargetLatency_2-"
            "1-1chan-SourceAse-CodecId_6_0_0-24000hz_80oct_7500us-TargetLatency_1");
}
}


TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackBisConfigFromAidlFormat) {
TEST(BluetoothAudioClientInterfaceAidlTest, testGetStackBisConfigFromAidlFormat) {