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

Commit 9e1a2a36 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Gerrit Code Review
Browse files

Merge changes Id7e08594,Ib13b0c51,I71188b63 into main

* changes:
  leaudio: Notify Offloader about disconnected CIS
  leaudio: Fix for "Unable to get free Uni-Directional Sink CIS ID"
  leaudio: Minor test clean up
parents c89f484e cfa71c56
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -1313,14 +1313,15 @@ void LeAudioDeviceGroup::AssignCisConnHandlesToAses(void) {
  }
}

void LeAudioDeviceGroup::CigConfiguration::UnassignCis(LeAudioDevice* leAudioDevice) {
void LeAudioDeviceGroup::CigConfiguration::UnassignCis(LeAudioDevice* leAudioDevice,
                                                       uint16_t conn_handle) {
  log::assert_that(leAudioDevice, "Invalid device");

  log::info("Group {}, group_id {}, device: {}", fmt::ptr(group_), group_->group_id_,
            leAudioDevice->address_);
  log::info("Group {}, group_id {}, device: {}, conn_handle: {:#x}", fmt::ptr(group_),
            group_->group_id_, leAudioDevice->address_, conn_handle);

  for (struct bluetooth::le_audio::types::cis& cis_entry : cises) {
    if (cis_entry.addr == leAudioDevice->address_) {
    if (cis_entry.conn_handle == conn_handle && cis_entry.addr == leAudioDevice->address_) {
      cis_entry.addr = RawAddress::kEmpty;
    }
  }
@@ -1707,6 +1708,7 @@ void LeAudioDeviceGroup::RemoveCisFromStreamIfNeeded(LeAudioDevice* leAudioDevic
  log::info("CIS Connection Handle: {}", cis_conn_hdl);

  if (!IsCisPartOfCurrentStream(cis_conn_hdl)) {
    cig.UnassignCis(leAudioDevice, cis_conn_hdl);
    return;
  }

@@ -1763,7 +1765,7 @@ void LeAudioDeviceGroup::RemoveCisFromStreamIfNeeded(LeAudioDevice* leAudioDevic
            bluetooth::le_audio::types::kLeAudioDirectionSource);
  }

  cig.UnassignCis(leAudioDevice);
  cig.UnassignCis(leAudioDevice, cis_conn_hdl);
}

bool LeAudioDeviceGroup::IsPendingConfiguration(void) const {
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public:
    void GenerateCisIds(types::LeAudioContextType context_type);
    bool AssignCisIds(LeAudioDevice* leAudioDevice);
    void AssignCisConnHandles(const std::vector<uint16_t>& conn_handles);
    void UnassignCis(LeAudioDevice* leAudioDevice);
    void UnassignCis(LeAudioDevice* leAudioDevice, uint16_t conn_handle);

    std::vector<struct types::cis> cises;

+4 −2
Original line number Diff line number Diff line
@@ -2000,7 +2000,8 @@ TEST_P(LeAudioAseConfigurationTest, test_reconnection_media) {
  left->DeactivateAllAses();

  /* Unassign from the group*/
  group_->cig.UnassignCis(left);
  group_->cig.UnassignCis(left, 0x0012);
  group_->cig.UnassignCis(left, 0x0013);

  TestAsesInactivated(left);

@@ -2137,7 +2138,8 @@ TEST_P(LeAudioAseConfigurationTest, test_reactivation_conversational) {
  TestActiveAses();

  /* Simulate stopping stream with caching codec configuration in ASEs */
  group_->cig.UnassignCis(tws_headset);
  group_->cig.UnassignCis(tws_headset, 0x0012);
  group_->cig.UnassignCis(tws_headset, 0x0013);
  SetAsesToCachedConfiguration(tws_headset, LeAudioContextType::CONVERSATIONAL,
                               kLeAudioDirectionSink | kLeAudioDirectionSource);

+5 −48
Original line number Diff line number Diff line
@@ -1202,54 +1202,11 @@ protected:
              if (!group) {
                return;
              }
              auto* stream_conf = &group->stream_conf;
              if (!stream_conf->stream_params.sink.stream_locations.empty() ||
                  !stream_conf->stream_params.source.stream_locations.empty()) {
                stream_conf->stream_params.sink.stream_locations.erase(
                        std::remove_if(
                                stream_conf->stream_params.sink.stream_locations.begin(),
                                stream_conf->stream_params.sink.stream_locations.end(),
                                [leAudioDevice, &stream_conf](auto& pair) {
                                  auto ases = leAudioDevice->GetAsesByCisConnHdl(pair.first);
                                  if (ases.sink) {
                                    stream_conf->stream_params.sink.num_of_devices--;
                                    stream_conf->stream_params.sink.num_of_channels -=
                                            ases.sink->channel_count;

                                    log::info(
                                            ", Source Number Of Devices: {}"
                                            ", Source Number Of Channels: {}",
                                            stream_conf->stream_params.source.num_of_devices,
                                            stream_conf->stream_params.source.num_of_channels);
                                  }
                                  return ases.sink;
                                }),
                        stream_conf->stream_params.sink.stream_locations.end());

                stream_conf->stream_params.source.stream_locations.erase(
                        std::remove_if(
                                stream_conf->stream_params.source.stream_locations.begin(),
                                stream_conf->stream_params.source.stream_locations.end(),
                                [leAudioDevice, &stream_conf](auto& pair) {
                                  auto ases = leAudioDevice->GetAsesByCisConnHdl(pair.first);
                                  if (ases.source) {
                                    stream_conf->stream_params.source.num_of_devices--;
                                    stream_conf->stream_params.source.num_of_channels -=
                                            ases.source->channel_count;

                                    log::info(
                                            ", Source Number Of Devices: {}, Source Number Of "
                                            "Channels: {}",
                                            stream_conf->stream_params.source.num_of_devices,
                                            stream_conf->stream_params.source.num_of_channels);
                                  }
                                  return ases.source;
                                }),
                        stream_conf->stream_params.source.stream_locations.end());
              for (auto& ase : leAudioDevice->ases_) {
                group->RemoveCisFromStreamIfNeeded(leAudioDevice, ase.cis_conn_hdl);
              }

              group->cig.UnassignCis(leAudioDevice);

              if (group->IsEmpty()) {
                group->cig.SetState(bluetooth::le_audio::types::CigState::NONE);
                InjectCigRemoved(group->group_id_);
@@ -1326,7 +1283,7 @@ protected:
                        stream_conf->stream_params.source.stream_locations.end());
              }

              group->cig.UnassignCis(leAudioDevice);
              group->cig.UnassignCis(leAudioDevice, event->cis_conn_hdl);
            });

    ON_CALL(mock_state_machine_, StopStream(_)).WillByDefault([this](LeAudioDeviceGroup* group) {
@@ -1387,9 +1344,9 @@ protected:
                  stream_conf->stream_params.source.stream_locations.end());
        }

        group->cig.UnassignCis(device);

        for (auto& ase : device->ases_) {
          group->cig.UnassignCis(device, ase.cis_conn_hdl);

          ase.cis_state = types::CisState::IDLE;
          ase.data_path_state = types::DataPathState::IDLE;
          ase.active = false;
+22 −12
Original line number Diff line number Diff line
@@ -716,6 +716,26 @@ public:
    group->ClearAllCises();
  }

  void SendStreamingStatusCbIfNeeded(LeAudioDeviceGroup* group) {
    /* This function should be called when some of the set members got disconnected but there are
     * still other CISes connected. When state machine is in STREAMING state, status will be sent up
     * to the user, so it can update encoder or offloader.
     */
    log::info("group_id: {}", group->group_id_);
    if (group->HaveAllCisesDisconnected()) {
      log::info("All cises disconnected;");
      return;
    }

    if ((group->GetState() == AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) &&
        (group->GetTargetState() == AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING)) {
      state_machine_callbacks_->StatusReportCb(group->group_id_, GroupStreamStatus::STREAMING);
    } else {
      log::warn("group_id {} not in streaming, CISes are still there", group->group_id_);
      group->PrintDebugState();
    }
  }

  void RemoveCigForGroup(LeAudioDeviceGroup* group) {
    log::debug("Group: {}, id: {} cig state: {}", fmt::ptr(group), group->group_id_,
               ToString(group->cig.GetState()));
@@ -792,18 +812,7 @@ public:
       */
      if (!group->HaveAllCisesDisconnected()) {
        /* some CISes are connected */

        if ((group->GetState() == AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) &&
            (group->GetTargetState() == AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING)) {
          /* We keep streaming but want others to let know user that it might
           * be need to update CodecManager with new CIS configuration
           */
          state_machine_callbacks_->StatusReportCb(group->group_id_, GroupStreamStatus::STREAMING);
        } else {
          log::warn("group_id {} not in streaming, CISes are still there", group->group_id_);
          group->PrintDebugState();
        }

        SendStreamingStatusCbIfNeeded(group);
        return;
      }
    }
@@ -1101,6 +1110,7 @@ public:
         */
        if (!group->HaveAllCisesDisconnected()) {
          /* There is ASE streaming for some device. Continue streaming. */
          SendStreamingStatusCbIfNeeded(group);
          log::warn("Group member disconnected during streaming. Cis handle 0x{:04x}",
                    event->cis_conn_hdl);
          return;
Loading