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

Commit 6c741b7c authored by Jack He's avatar Jack He Committed by Gerrit Code Review
Browse files

Merge changes I8cd946e3,I9c124318,Ibcea4ddf,I276108e6

* changes:
  Add more configuration for single device with 2 ASEs
  Allow ringtone, media context type as input device for PTS mode
  Add more configurations support for PTS CAP test
  leaudio: Improve some unit tests
parents 340f6f28 b43a2d3e
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -633,7 +633,11 @@ public class LeAudioService extends ProfileService {
    private Integer getAudioDirectionsFromActiveContextsMap(Integer activeContexts) {
        Integer supportedAudioDirections = 0;

        if ((activeContexts & mContextSupportingInputAudio) != 0) {
        if (((activeContexts & mContextSupportingInputAudio) != 0)
                || (Utils.isPtsTestMode()
                && (activeContexts
                & (BluetoothLeAudio.CONTEXT_TYPE_RINGTONE
                | BluetoothLeAudio.CONTEXT_TYPE_MEDIA)) != 0)) {
            supportedAudioDirections |= AUDIO_DIRECTION_INPUT_BIT;
        }
        if ((activeContexts & mContextSupportingOutputAudio) != 0) {
+72 −0
Original line number Diff line number Diff line
@@ -167,6 +167,11 @@
            "codec_config_name": "SingleDev_OneChanMonoSnk_16_1",
            "qos_config_name": ["QoS_Config_16_1_2"]
        },
        {
            "name": "DualDev_OneChanMonoSnk_16_2_Server_Preferred",
            "codec_config_name": "DualDev_OneChanMonoSnk_16_2",
            "qos_config_name": ["QoS_Config_Server_Preferred"]
        },
        {
            "name": "SingleDev_OneChanMonoSnk_16_2_Server_Preferred",
            "codec_config_name": "SingleDev_OneChanMonoSnk_16_2",
@@ -1693,6 +1698,73 @@
                }
            ]
        },
        {
            "name": "DualDev_OneChanMonoSnk_16_2",
            "subconfigurations": [
                {
                    "device_cnt": 2,
                    "ase_cnt": 2,
                    "direction": "SINK",
                    "configuration_strategy": "MONO_ONE_CIS_PER_DEVICE",
                    "codec_id": {
                        "coding_format": 6,
                        "vendor_company_id": 0,
                        "vendor_codec_id": 0
                    },
                    "codec_configuration": [
                        {
                            "name": "sampling_frequency",
                            "type": 1,
                            "compound_value": {
                                "value": [
                                    3
                                ]
                            }
                        },
                        {
                            "name": "frame_duration",
                            "type": 2,
                            "compound_value": {
                                "value": [
                                    1
                                ]
                            }
                        },
                        {
                            "name": "audio_channel_allocation",
                            "type": 3,
                            "compound_value": {
                                "value": [
                                    1,
                                    0,
                                    0,
                                    0
                                ]
                            }
                        },
                        {
                            "name": "octets_per_codec_frame",
                            "type": 4,
                            "compound_value": {
                                "value": [
                                    40,
                                    0
                                ]
                            }
                        },
                        {
                            "name": "codec_frame_blocks_per_sdu",
                            "type": 5,
                            "compound_value": {
                                "value": [
                                    1
                                ]
                            }
                        }
                    ]
                }
            ]
        },
        {
            "name": "SingleDev_OneChanMonoSnk_16_2",
            "subconfigurations": [
+12 −3
Original line number Diff line number Diff line
@@ -37,7 +37,10 @@
                "SingleDev_OneChanMonoSnk_16_2_Server_Preferred",
                "SingleDev_OneChanMonoSnk_16_2_1",
                "SingleDev_OneChanMonoSnk_16_1_Server_Preferred",
                "SingleDev_OneChanMonoSnk_16_1_1"
                "SingleDev_OneChanMonoSnk_16_1_1",
                "DualDev_OneChanMonoSrc_16_2_Server_Preferred",
                "SingleDev_OneChanStereoSrc_16_2_Server_Preferred",
                "SingleDev_OneChanMonoSrc_16_2_Server_Preferred"
            ]
        },
        {
@@ -102,7 +105,10 @@
                "SingleDev_OneChanMonoSrc_16_2_Server_Preferred",
                "SingleDev_OneChanMonoSrc_16_1_Server_Preferred",
                "VND_SingleDev_TwoChanStereoSnk_TwoChanStereoSrc_32khz_Server_Prefered_1",
                "VND_SingleDev_TwoChanStereoSnk_TwoChanStereoSrc_32khz_60oct_R3_L22_1"
                "VND_SingleDev_TwoChanStereoSnk_TwoChanStereoSrc_32khz_60oct_R3_L22_1",
                "DualDev_OneChanMonoSnk_16_2_Server_Preferred",
                "SingleDev_OneChanStereoSnk_16_2_Server_Preferred",
                "SingleDev_OneChanMonoSnk_16_2_Server_Preferred"
            ]
        },
        {
@@ -175,7 +181,10 @@
                "VND_SingleDev_TwoChanStereoSnk_48khz_100octs_Server_Preferred_1",
                "VND_SingleDev_TwoChanStereoSnk_48khz_100octs_R15_L70_1",
                "VND_SingleDev_OneChanStereoSnk_48khz_100octs_Server_Preferred_1",
                "VND_SingleDev_OneChanStereoSnk_48khz_100octs_R15_L70_1"
                "VND_SingleDev_OneChanStereoSnk_48khz_100octs_R15_L70_1",
                "DualDev_OneChanMonoSrc_16_2_Server_Preferred",
                "SingleDev_OneChanStereoSrc_16_2_Server_Preferred",
                "SingleDev_OneChanMonoSrc_16_2_Server_Preferred"
            ]
        },
        {
+68 −49
Original line number Diff line number Diff line
@@ -388,8 +388,8 @@ struct TestGroupAseConfigurationData {
  uint8_t audio_channel_counts_snk;
  uint8_t audio_channel_counts_src;

  uint8_t active_channel_num_snk;
  uint8_t active_channel_num_src;
  uint8_t expected_active_channel_num_snk;
  uint8_t expected_active_channel_num_src;
};

class LeAudioAseConfigurationTest : public Test {
@@ -458,9 +458,9 @@ class LeAudioAseConfigurationTest : public Test {
    uint8_t active_channel_num_snk = 0;
    uint8_t active_channel_num_src = 0;

    bool have_active_ase =
        data.active_channel_num_snk + data.active_channel_num_src;
    ASSERT_EQ(have_active_ase, data.device->HaveActiveAse());
    bool expected_active_ase = data.expected_active_channel_num_snk +
                               data.expected_active_channel_num_src;
    ASSERT_EQ(expected_active_ase, data.device->HaveActiveAse());

    for (ase* ase = data.device->GetFirstActiveAse(); ase;
         ase = data.device->GetNextActiveAse(ase)) {
@@ -472,8 +472,8 @@ class LeAudioAseConfigurationTest : public Test {
            GetAudioChannelCounts(*ase->codec_config.audio_channel_allocation);
    }

    ASSERT_EQ(data.active_channel_num_snk, active_channel_num_snk);
    ASSERT_EQ(data.active_channel_num_src, active_channel_num_src);
    ASSERT_EQ(data.expected_active_channel_num_snk, active_channel_num_snk);
    ASSERT_EQ(data.expected_active_channel_num_src, active_channel_num_src);
  }

  void SetCisInformationToActiveAse(void) {
@@ -497,8 +497,8 @@ class LeAudioAseConfigurationTest : public Test {
    // the configuration should fail if there are no active ases expected
    bool success_expected = data_size > 0;
    for (int i = 0; i < data_size; i++) {
      success_expected &=
          (data[i].active_channel_num_snk + data[i].active_channel_num_src) > 0;
      success_expected &= (data[i].expected_active_channel_num_snk +
                           data[i].expected_active_channel_num_src) > 0;

      /* Prepare PAC's */
      PublishedAudioCapabilitiesBuilder snk_pac_builder, src_pac_builder;
@@ -523,71 +523,90 @@ class LeAudioAseConfigurationTest : public Test {
    }
  }

  int getNumOfAses(LeAudioDevice* device, uint8_t direction) {
    return std::count_if(
        device->ases_.begin(), device->ases_.end(),
        [direction](auto& a) { return a.direction == direction; });
  }

  void TestGroupAseConfiguration(LeAudioContextType context_type,
                                 TestGroupAseConfigurationData* data,
                                 uint8_t data_size) {
    const auto* configurations =
        ::le_audio::AudioSetConfigurationProvider::Get()->GetConfigurations(
            context_type);

    int num_of_matching_configurations = 0;
    bool success_expected = data_size > 0;
    for (const auto& audio_set_conf : *configurations) {
      bool interesting_configuration = true;
      // the configuration should fail if there are no active ases expected
      bool success_expected = data_size > 0;
      bool not_matching_scenario = false;
      uint8_t snk_ases_cnt = 0;
      uint8_t src_ases_cnt = 0;
      PublishedAudioCapabilitiesBuilder snk_pac_builder, src_pac_builder;
      snk_pac_builder.Reset();
      src_pac_builder.Reset();

      /* Let's go thru devices in the group and configure them*/
      for (int i = 0; i < data_size; i++) {
        success_expected &= (data[i].active_channel_num_snk +
                             data[i].active_channel_num_src) > 0;
        success_expected &= (data[i].expected_active_channel_num_snk +
                             data[i].expected_active_channel_num_src) > 0;
        int num_of_ase_snk_per_dev = 0;
        int num_of_ase_src_per_dev = 0;

        /* Prepare PAC's */
        /* Note this test requires that reach TwoStereoChan configuration
         * version has similar version for OneStereoChan (both SingleDev,
         * DualDev). This is just how the test is created and this limitation
         * should be removed b/230107540
         */
        /* Prepare PAC's for each device. Also make sure configuration is in our
         * interest to test */
        for (const auto& entry : (*audio_set_conf).confs) {
          /* Configuration requires more devices than are supplied */
          if (entry.device_cnt > data_size) {
            not_matching_scenario = true;
            break;
          /* We are interested in the configurations which contains exact number
           * of devices and number of ases is same the number of expected ases
           * to active
           */
          if (entry.device_cnt != data_size) {
            interesting_configuration = false;
          }

          if (entry.direction == kLeAudioDirectionSink) {
            snk_ases_cnt += entry.ase_cnt;
            num_of_ase_snk_per_dev = entry.ase_cnt / data_size;
            snk_pac_builder.Add(entry.codec, data[i].audio_channel_counts_snk);
          } else {
            num_of_ase_src_per_dev = entry.ase_cnt / data_size;
            src_pac_builder.Add(entry.codec, data[i].audio_channel_counts_src);
          }
        }

        /* Scenario requires more ASEs than defined requirement */
        if (snk_ases_cnt < data[i].audio_channel_counts_snk ||
            src_ases_cnt < data[i].audio_channel_counts_src) {
          not_matching_scenario = true;
        }

        if (not_matching_scenario) break;

          data[i].device->snk_pacs_ = snk_pac_builder.Get();
          data[i].device->src_pacs_ = src_pac_builder.Get();
        }

      if (not_matching_scenario) continue;
        /* Make sure configuration can satisfy number of expected active ASEs*/
        if (num_of_ase_snk_per_dev != data[i].expected_active_channel_num_snk) {
          interesting_configuration = false;
        }

        if (num_of_ase_src_per_dev != data[i].expected_active_channel_num_src) {
          interesting_configuration = false;
        }
      }
      /* Stimulate update of active context map */
      group_->UpdateActiveContextsMap(static_cast<uint16_t>(context_type));
      ASSERT_EQ(success_expected, group_->Configure(context_type));

      auto configuration_result = group_->Configure(context_type);

      /* In case of configuration #ase is same as the one we expected to be
       * activated verify, ASEs are actually active */
      if (interesting_configuration) {
        ASSERT_TRUE(configuration_result);
        num_of_matching_configurations++;
        /* Check if each of the devices has activated ASEs as expected */
        for (int i = 0; i < data_size; i++) {
          TestGroupAseConfigurationVerdict(data[i]);
        }

      }
      group_->Deactivate();
      TestAsesInactive();
    }

    if (success_expected) {
      ASSERT_TRUE((num_of_matching_configurations > 0));
    } else {
      ASSERT_TRUE(num_of_matching_configurations == 0);
    }
  }

  void TestAsesActive(LeAudioCodecId codec_id, uint8_t sampling_frequency,
@@ -703,7 +722,7 @@ TEST_F(LeAudioAseConfigurationTest, test_mono_speaker_ringtone) {
  LeAudioDevice* mono_speaker = AddTestDevice(1, 1);
  TestGroupAseConfigurationData data(
      {mono_speaker, kLeAudioCodecLC3ChannelCountSingleChannel,
       kLeAudioCodecLC3ChannelCountSingleChannel, 1, 0});
       kLeAudioCodecLC3ChannelCountSingleChannel, 1, 1});

  TestGroupAseConfiguration(LeAudioContextType::RINGTONE, &data, 1);
}
@@ -730,7 +749,7 @@ TEST_F(LeAudioAseConfigurationTest, test_bounded_headphones_ringtone) {
  LeAudioDevice* bounded_headphones = AddTestDevice(2, 1);
  TestGroupAseConfigurationData data(
      {bounded_headphones, kLeAudioCodecLC3ChannelCountTwoChannel,
       kLeAudioCodecLC3ChannelCountSingleChannel, 2, 0});
       kLeAudioCodecLC3ChannelCountSingleChannel, 2, 1});

  TestGroupAseConfiguration(LeAudioContextType::RINGTONE, &data, 1);
}
@@ -757,7 +776,7 @@ TEST_F(LeAudioAseConfigurationTest, test_bounded_headset_ringtone) {
  LeAudioDevice* bounded_headset = AddTestDevice(2, 1);
  TestGroupAseConfigurationData data(
      {bounded_headset, kLeAudioCodecLC3ChannelCountTwoChannel,
       kLeAudioCodecLC3ChannelCountSingleChannel, 2, 0});
       kLeAudioCodecLC3ChannelCountSingleChannel, 2, 1});

  TestGroupAseConfiguration(LeAudioContextType::RINGTONE, &data, 1);
}
@@ -785,9 +804,9 @@ TEST_F(LeAudioAseConfigurationTest, test_earbuds_ringtone) {
  LeAudioDevice* right = AddTestDevice(1, 1);
  TestGroupAseConfigurationData data[] = {
      {left, kLeAudioCodecLC3ChannelCountSingleChannel,
       kLeAudioCodecLC3ChannelCountSingleChannel, 1, 0},
       kLeAudioCodecLC3ChannelCountSingleChannel, 1, 1},
      {right, kLeAudioCodecLC3ChannelCountSingleChannel,
       kLeAudioCodecLC3ChannelCountSingleChannel, 1, 0}};
       kLeAudioCodecLC3ChannelCountSingleChannel, 1, 1}};

  TestGroupAseConfiguration(LeAudioContextType::RINGTONE, data, 2);
}
@@ -820,7 +839,7 @@ TEST_F(LeAudioAseConfigurationTest, test_handsfree_ringtone) {
  LeAudioDevice* handsfree = AddTestDevice(1, 1);
  TestGroupAseConfigurationData data(
      {handsfree, kLeAudioCodecLC3ChannelCountSingleChannel,
       kLeAudioCodecLC3ChannelCountSingleChannel, 1, 0});
       kLeAudioCodecLC3ChannelCountSingleChannel, 1, 1});

  TestGroupAseConfiguration(LeAudioContextType::RINGTONE, &data, 1);
}