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

Commit 4e20eac4 authored by Łukasz Rymanowski (xWF)'s avatar Łukasz Rymanowski (xWF) Committed by Automerger Merge Worker
Browse files

Merge changes Icd1a589e,I4638242f into main am: 47cbaf5a am: d66bf908

parents d22297a2 d66bf908
Loading
Loading
Loading
Loading
+33 −25
Original line number Original line Diff line number Diff line
@@ -249,7 +249,7 @@ public:
        stream_setup_time_(0) {}
        stream_setup_time_(0) {}


  void Init(int group_id, LeAudioContextType context_type, int num_of_devices) {
  void Init(int group_id, LeAudioContextType context_type, int num_of_devices) {
    Reset();
    Reset(bluetooth::groups::kGroupUnknown);
    group_id_ = group_id;
    group_id_ = group_id;
    context_type_ = context_type;
    context_type_ = context_type;
    num_of_devices_ = num_of_devices;
    num_of_devices_ = num_of_devices;
@@ -257,7 +257,13 @@ public:
                 ToString(context_type_), num_of_devices);
                 ToString(context_type_), num_of_devices);
  }
  }


  void Reset(void) {
  void Reset(int group_id) {
    if (group_id != bluetooth::groups::kGroupUnknown && group_id != group_id_) {
      log::verbose("StreamSpeedTracker Reset called for invalid group_id: {} != {}", group_id,
                   group_id_);
      return;
    }

    log::verbose("StreamSpeedTracker group_id: {}", group_id_);
    log::verbose("StreamSpeedTracker group_id: {}", group_id_);
    is_started_ = false;
    is_started_ = false;
    group_id_ = bluetooth::groups::kGroupUnknown;
    group_id_ = bluetooth::groups::kGroupUnknown;
@@ -300,14 +306,15 @@ public:
                 ToString(context_type_), total_time_);
                 ToString(context_type_), total_time_);
  }
  }


  bool IsStarted(void) {
  bool IsStarted(int group_id) {
    if (is_started_) {
    if (is_started_ && group_id_ == group_id) {
      log::verbose("StreamSpeedTracker group_id: {}, {} is_started_: {} ", group_id_,
      log::verbose("StreamSpeedTracker group_id: {}, {} is_started_: {} ", group_id_,
                   ToString(context_type_), is_started_);
                   ToString(context_type_), is_started_);
    } else {
      return true;
      log::verbose("StreamSpeedTracker not started ");
    }
    }
    return is_started_;
    log::verbose("StreamSpeedTracker not started {} or group_id does not match ({} ! = {}) ",
                 is_started_, group_id, group_id_);
    return false;
  }
  }


  void Dump(std::stringstream& stream) {
  void Dump(std::stringstream& stream) {
@@ -1705,7 +1712,7 @@ public:
    /* If group become active while phone call, let's configure it right away,
    /* If group become active while phone call, let's configure it right away,
     * so when audio framework resumes the stream, it will be almost there.
     * so when audio framework resumes the stream, it will be almost there.
     */
     */
    if (IsInCall()) {
    if (IsInCall() || IsInVoipCall()) {
      PrepareStreamForAConversational(group);
      PrepareStreamForAConversational(group);
    }
    }
  }
  }
@@ -5846,9 +5853,9 @@ public:


  void speed_start_setup(int group_id, LeAudioContextType context_type, int num_of_connected,
  void speed_start_setup(int group_id, LeAudioContextType context_type, int num_of_connected,
                         bool is_reconfig = false) {
                         bool is_reconfig = false) {
    log::verbose("is_started {} is_reconfig {} num_of_connected {}", speed_tracker_.IsStarted(),
    log::verbose("is_started {} is_reconfig {} num_of_connected {}",
                 is_reconfig, num_of_connected);
                 speed_tracker_.IsStarted(group_id), is_reconfig, num_of_connected);
    if (!speed_tracker_.IsStarted()) {
    if (!speed_tracker_.IsStarted(group_id)) {
      speed_tracker_.Init(group_id, context_type, num_of_connected);
      speed_tracker_.Init(group_id, context_type, num_of_connected);
    }
    }
    if (is_reconfig) {
    if (is_reconfig) {
@@ -5858,26 +5865,27 @@ public:
    }
    }
  }
  }


  void speed_stop_reconfig(void) {
  void speed_stop_reconfig(int group_id) {
    log::verbose("");
    log::verbose("");
    if (!speed_tracker_.IsStarted()) {
    if (!speed_tracker_.IsStarted(group_id)) {
      return;
      return;
    }
    }

    speed_tracker_.ReconfigurationComplete();
    speed_tracker_.ReconfigurationComplete();
  }
  }


  void speed_stream_created() {
  void speed_stream_created(int group_id) {
    log::verbose("");
    log::verbose("");
    if (!speed_tracker_.IsStarted()) {
    if (!speed_tracker_.IsStarted(group_id)) {
      return;
      return;
    }
    }


    speed_tracker_.StreamCreated();
    speed_tracker_.StreamCreated();
  }
  }


  void speed_stop_setup() {
  void speed_stop_setup(int group_id) {
    log::verbose("");
    log::verbose("");
    if (!speed_tracker_.IsStarted()) {
    if (!speed_tracker_.IsStarted(group_id)) {
      return;
      return;
    }
    }


@@ -5887,7 +5895,7 @@ public:


    speed_tracker_.StopStreamSetup();
    speed_tracker_.StopStreamSetup();
    stream_speed_history_.emplace_front(speed_tracker_);
    stream_speed_history_.emplace_front(speed_tracker_);
    speed_tracker_.Reset();
    speed_tracker_.Reset(group_id);
  }
  }


  void notifyGroupStreamStatus(int group_id, GroupStreamStatus groupStreamStatus) {
  void notifyGroupStreamStatus(int group_id, GroupStreamStatus groupStreamStatus) {
@@ -5942,7 +5950,7 @@ public:
     */
     */
    CancelStreamingRequest();
    CancelStreamingRequest();
    ReconfigurationComplete(previously_active_directions);
    ReconfigurationComplete(previously_active_directions);
    speed_stop_reconfig();
    speed_stop_reconfig(active_group_id_);
  }
  }


  void OnStateMachineStatusReportCb(int group_id, GroupStreamStatus status) {
  void OnStateMachineStatusReportCb(int group_id, GroupStreamStatus status) {
@@ -5961,7 +5969,7 @@ public:
          return;
          return;
        }
        }


        speed_stream_created();
        speed_stream_created(group_id);
        bluetooth::le_audio::MetricsCollector::Get()->OnStreamStarted(active_group_id_,
        bluetooth::le_audio::MetricsCollector::Get()->OnStreamStarted(active_group_id_,
                                                                      configuration_context_type_);
                                                                      configuration_context_type_);


@@ -5983,7 +5991,7 @@ public:
           * Just stop streaming
           * Just stop streaming
           */
           */
          log::warn("Stopping stream for group {} as AF not interested.", group_id);
          log::warn("Stopping stream for group {} as AF not interested.", group_id);
          speed_stop_setup();
          speed_stop_setup(group_id);
          groupStateMachine_->StopStream(group);
          groupStateMachine_->StopStream(group);
          return;
          return;
        }
        }
@@ -5998,7 +6006,7 @@ public:
                  "reconfigure to {}",
                  "reconfigure to {}",
                  ToString(group->GetConfigurationContextType()),
                  ToString(group->GetConfigurationContextType()),
                  ToString(configuration_context_type_));
                  ToString(configuration_context_type_));
          speed_stop_setup();
          speed_stop_setup(group_id);
          initReconfiguration(group, group->GetConfigurationContextType());
          initReconfiguration(group, group->GetConfigurationContextType());
          return;
          return;
        }
        }
@@ -6020,11 +6028,11 @@ public:
          StartReceivingAudio(group_id);
          StartReceivingAudio(group_id);
        }
        }


        speed_stop_setup();
        speed_stop_setup(group_id);
        break;
        break;
      }
      }
      case GroupStreamStatus::SUSPENDED:
      case GroupStreamStatus::SUSPENDED:
        speed_tracker_.Reset();
        speed_tracker_.Reset(group_id);
        /** Stop Audio but don't release all the Audio resources */
        /** Stop Audio but don't release all the Audio resources */
        SuspendAudio();
        SuspendAudio();
        break;
        break;
@@ -6098,7 +6106,7 @@ public:
          }
          }
        }
        }


        speed_tracker_.Reset();
        speed_tracker_.Reset(group_id);
        CancelStreamingRequest();
        CancelStreamingRequest();


        if (group) {
        if (group) {
+75 −1
Original line number Original line Diff line number Diff line
@@ -2693,6 +2693,7 @@ protected:
  LeAudioSinkAudioHalClient::Callbacks* unicast_sink_hal_cb_ = nullptr;
  LeAudioSinkAudioHalClient::Callbacks* unicast_sink_hal_cb_ = nullptr;
  uint8_t default_channel_cnt = 0x03;
  uint8_t default_channel_cnt = 0x03;
  uint8_t default_src_channel_cnt = default_channel_cnt;
  uint8_t default_ase_cnt = 1;
  uint8_t default_ase_cnt = 1;
  NiceMock<MockCsisClient> mock_csis_client_module_;
  NiceMock<MockCsisClient> mock_csis_client_module_;
@@ -2989,7 +2990,7 @@ TEST_F(UnicastTest, CleanupWhenUserConnecting) {
  uint16_t conn_id = 1;
  uint16_t conn_id = 1;
  SetSampleDatabaseEarbudsValid(1, test_address0, codec_spec_conf::kLeAudioLocationStereo,
  SetSampleDatabaseEarbudsValid(1, test_address0, codec_spec_conf::kLeAudioLocationStereo,
                                codec_spec_conf::kLeAudioLocationStereo, default_channel_cnt,
                                codec_spec_conf::kLeAudioLocationStereo, default_channel_cnt,
                                default_channel_cnt, 0x0004,
                                default_src_channel_cnt, 0x0004,
                                /* source sample freq 16khz */ true, /*add_csis*/
                                /* source sample freq 16khz */ true, /*add_csis*/
                                true,                                /*add_cas*/
                                true,                                /*add_cas*/
                                true,                                /*add_pacs*/
                                true,                                /*add_pacs*/
@@ -5004,6 +5005,79 @@ TEST_F(UnicastTest, GroupSetActive_and_InactiveDuringStreamConfiguration) {
  Mock::VerifyAndClearExpectations(&mock_state_machine_);
  Mock::VerifyAndClearExpectations(&mock_state_machine_);
}
}
TEST_F(UnicastTest, AnotherGroupSetActive_DuringVoip) {
  com::android::bluetooth::flags::provider_->leaudio_improve_switch_during_phone_call(true);
  const RawAddress test_address0 = GetTestAddress(0);
  const RawAddress test_address1 = GetTestAddress(1);
  int group_id_1 = 1;
  int group_id_2 = 2;
  int group_size = 1;
  default_channel_cnt = 2;
  default_src_channel_cnt = 1;
  /**
   * Scenario:
   * 1. Voip is started
   * 2. Group 1 is set active - no fast configuration is expected
   * 3. Audio HAL resumse the stream and Group 1 is streaming
   * 3. Group 2 is set to active - it is expected that stream to Group 1 is stopped and Group 2
   * configuration goes to QoS configured
   */
  // Report working CSIS
  ON_CALL(mock_csis_client_module_, IsCsisClientRunning()).WillByDefault(Return(true));
  ON_CALL(mock_csis_client_module_, GetDesiredSize(_)).WillByDefault(Return(group_size));
  log::info("Connecting first Group with device {}", test_address0);
  ConnectCsisDevice(
          test_address0, 1 /* conn_id*/,
          codec_spec_conf::kLeAudioLocationFrontLeft | codec_spec_conf::kLeAudioLocationFrontRight,
          codec_spec_conf::kLeAudioLocationFrontLeft, group_size, group_id_1, 1 /* rank*/);
  SyncOnMainLoop();
  log::info("Connecting second Group with device {}", test_address1);
  ConnectCsisDevice(
          test_address1, 2 /* conn_id*/,
          codec_spec_conf::kLeAudioLocationFrontLeft | codec_spec_conf::kLeAudioLocationFrontRight,
          codec_spec_conf::kLeAudioLocationFrontLeft, group_size, group_id_2, 1 /* rank*/);
  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, _)).Times(0);
  EXPECT_CALL(mock_state_machine_, ConfigureStream(_, _, _, _, _)).Times(0);
  log::info("Group is getting Active");
  LeAudioClient::Get()->GroupSetActive(group_id_1);
  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_state_machine_);
  log::info("Audio HAL opens for Converstational");
  // VOIP not using Telecom API has no ccids.
  types::BidirectionalPair<std::vector<uint8_t>> ccids = {.sink = {}, .source = {}};
  EXPECT_CALL(mock_state_machine_,
              StartStream(_, types::LeAudioContextType::CONVERSATIONAL, _, ccids))
          .Times(AtLeast(1));
  StartStreaming(AUDIO_USAGE_VOICE_COMMUNICATION, AUDIO_CONTENT_TYPE_SPEECH, group_id_1);
  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  log::info("Set group 2 as active one ");
  EXPECT_CALL(mock_state_machine_, StopStream(_)).Times(1);
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, _)).Times(0);
  EXPECT_CALL(mock_state_machine_, ConfigureStream(_, _, _, _, true)).Times(1);
  LeAudioClient::Get()->GroupSetActive(group_id_2);
  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_state_machine_);
}
TEST_F(UnicastTest, GroupSetActive_and_GroupSetInactive_DuringPhoneCall) {
TEST_F(UnicastTest, GroupSetActive_and_GroupSetInactive_DuringPhoneCall) {
  com::android::bluetooth::flags::provider_->leaudio_improve_switch_during_phone_call(true);
  com::android::bluetooth::flags::provider_->leaudio_improve_switch_during_phone_call(true);
  const RawAddress test_address0 = GetTestAddress(0);
  const RawAddress test_address0 = GetTestAddress(0);