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

Commit 5e0bdf96 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Minor cleanup on stream reconfiguration

No functional change as reconfiguration is always scheduled when new
configuration is known and is different from the previous one.
This patch is a preparation for the next patch.

Bug: 323275279
Flag: Exempt, no functional change. Regression tested with unittests
Test: atest bluetooth_le_audio_client_test
Change-Id: I7b45182a7353e3cc924717b3256dad8e7fee3d13
parent ae2a13a3
Loading
Loading
Loading
Loading
+44 −28
Original line number Original line Diff line number Diff line
@@ -979,6 +979,15 @@ public:
    ContentControlIdKeeper::GetInstance()->SetCcid(AudioContexts(context_type), ccid);
    ContentControlIdKeeper::GetInstance()->SetCcid(AudioContexts(context_type), ccid);
  }
  }


  void initReconfiguration(LeAudioDeviceGroup* group, LeAudioContextType previous_context_type) {
    log::debug(" group_id: {}, previous context_type {}", group->group_id_,
               ToString(previous_context_type));
    pre_configuration_context_type_ = previous_context_type;
    group->SetPendingConfiguration();
    groupStateMachine_->StopStream(group);
    stream_setup_start_timestamp_ = bluetooth::common::time_get_os_boottime_us();
  }

  void SetInCall(bool in_call) override {
  void SetInCall(bool in_call) override {
    log::debug("in_call: {}", in_call);
    log::debug("in_call: {}", in_call);
    in_call_ = in_call;
    in_call_ = in_call;
@@ -3005,9 +3014,7 @@ public:


          /* Reconfigure if newly connected member device cannot support
          /* Reconfigure if newly connected member device cannot support
           * current codec configuration */
           * current codec configuration */
          group->SetPendingConfiguration();
          initReconfiguration(group, configuration_context_type_);
          groupStateMachine_->StopStream(group);
          stream_setup_start_timestamp_ = bluetooth::common::time_get_os_boottime_us();
          return;
          return;
        }
        }
      }
      }
@@ -4350,13 +4357,17 @@ public:


  bool SetConfigurationAndStopStreamWhenNeeded(LeAudioDeviceGroup* group,
  bool SetConfigurationAndStopStreamWhenNeeded(LeAudioDeviceGroup* group,
                                               LeAudioContextType new_context_type) {
                                               LeAudioContextType new_context_type) {
    auto previous_context_type = configuration_context_type_;

    auto reconfig_result = UpdateConfigAndCheckIfReconfigurationIsNeeded(group, new_context_type);
    auto reconfig_result = UpdateConfigAndCheckIfReconfigurationIsNeeded(group, new_context_type);
    /* Even though the reconfiguration may not be needed, this has
    /* Even though the reconfiguration may not be needed, this has
     * to be set here as it might be the initial configuration.
     * to be set here as it might be the initial configuration.
     */
     */

    configuration_context_type_ = new_context_type;
    configuration_context_type_ = new_context_type;


    log::info("group_id {}, context type {} ({}), {}", group->group_id_, ToString(new_context_type),
    log::info("group_id {}, previous_context {} context type {} ({}), {}", group->group_id_,
              ToString(previous_context_type), ToString(new_context_type),
              ToHexString(new_context_type), ToString(reconfig_result));
              ToHexString(new_context_type), ToString(reconfig_result));
    if (reconfig_result == AudioReconfigurationResult::RECONFIGURATION_NOT_NEEDED) {
    if (reconfig_result == AudioReconfigurationResult::RECONFIGURATION_NOT_NEEDED) {
      return false;
      return false;
@@ -4375,9 +4386,9 @@ public:
      alarm_cancel(suspend_timeout_);
      alarm_cancel(suspend_timeout_);
    }
    }


    /* Need to reconfigure stream */
    /* Need to reconfigure stream. At this point pre_configuration_context_type shall be set */
    group->SetPendingConfiguration();

    groupStateMachine_->StopStream(group);
    initReconfiguration(group, previous_context_type);
    SendAudioGroupCurrentCodecConfigChanged(group);
    SendAudioGroupCurrentCodecConfigChanged(group);
    return true;
    return true;
  }
  }
@@ -5217,6 +5228,24 @@ public:
    SetAsymmetricBlePhy(group, false);
    SetAsymmetricBlePhy(group, false);
  }
  }


  void reconfigurationComplete(void) {
    // Check which directions were suspended
    uint8_t previously_active_directions = 0;
    if (audio_sender_state_ >= AudioState::READY_TO_START) {
      previously_active_directions |= bluetooth::le_audio::types::kLeAudioDirectionSink;
    }
    if (audio_receiver_state_ >= AudioState::READY_TO_START) {
      previously_active_directions |= bluetooth::le_audio::types::kLeAudioDirectionSource;
    }

    /* We are done with reconfiguration.
     * Clean state and if Audio HAL is waiting, cancel the request
     * so Audio HAL can Resume again.
     */
    CancelStreamingRequest();
    ReconfigurationComplete(previously_active_directions);
  }

  void OnStateMachineStatusReportCb(int group_id, GroupStreamStatus status) {
  void OnStateMachineStatusReportCb(int group_id, GroupStreamStatus status) {
    log::info("status: {},  group_id: {}, audio_sender_state {}, audio_receiver_state {}",
    log::info("status: {},  group_id: {}, audio_sender_state {}, audio_receiver_state {}",
              static_cast<int>(status), group_id, bluetooth::common::ToString(audio_sender_state_),
              static_cast<int>(status), group_id, bluetooth::common::ToString(audio_sender_state_),
@@ -5270,9 +5299,7 @@ public:
                  "reconfigure to {}",
                  "reconfigure to {}",
                  ToString(group->GetConfigurationContextType()),
                  ToString(group->GetConfigurationContextType()),
                  ToString(configuration_context_type_));
                  ToString(configuration_context_type_));
          group->SetPendingConfiguration();
          initReconfiguration(group, group->GetConfigurationContextType());
          groupStateMachine_->StopStream(group);
          stream_setup_start_timestamp_ = bluetooth::common::time_get_os_boottime_us();
          return;
          return;
        }
        }


@@ -5300,23 +5327,9 @@ public:
        /** Stop Audio but don't release all the Audio resources */
        /** Stop Audio but don't release all the Audio resources */
        SuspendAudio();
        SuspendAudio();
        break;
        break;
      case GroupStreamStatus::CONFIGURED_BY_USER: {
      case GroupStreamStatus::CONFIGURED_BY_USER:
        // Check which directions were suspended
        reconfigurationComplete();
        uint8_t previously_active_directions = 0;
        break;
        if (audio_sender_state_ >= AudioState::READY_TO_START) {
          previously_active_directions |= bluetooth::le_audio::types::kLeAudioDirectionSink;
        }
        if (audio_receiver_state_ >= AudioState::READY_TO_START) {
          previously_active_directions |= bluetooth::le_audio::types::kLeAudioDirectionSource;
        }

        /* We are done with reconfiguration.
         * Clean state and if Audio HAL is waiting, cancel the request
         * so Audio HAL can Resume again.
         */
        CancelStreamingRequest();
        ReconfigurationComplete(previously_active_directions);
      } break;
      case GroupStreamStatus::CONFIGURED_AUTONOMOUS:
      case GroupStreamStatus::CONFIGURED_AUTONOMOUS:
        /* This state is notified only when
        /* This state is notified only when
         * groups stays into CONFIGURED state after
         * groups stays into CONFIGURED state after
@@ -5354,12 +5367,14 @@ public:


            auto remote_contexts = DirectionalRealignMetadataAudioContexts(group, remote_direction);
            auto remote_contexts = DirectionalRealignMetadataAudioContexts(group, remote_direction);
            ApplyRemoteMetadataAudioContextPolicy(group, remote_contexts, remote_direction);
            ApplyRemoteMetadataAudioContextPolicy(group, remote_contexts, remote_direction);
            if (GroupStream(group->group_id_, configuration_context_type_, remote_contexts)) {
            if ((configuration_context_type_ != pre_configuration_context_type_) &&
                GroupStream(group->group_id_, configuration_context_type_, remote_contexts)) {
              /* If configuration succeed wait for new status. */
              /* If configuration succeed wait for new status. */
              return;
              return;
            }
            }
            log::info("Clear pending configuration flag for group {}", group->group_id_);
            log::info("Clear pending configuration flag for group {}", group->group_id_);
            group->ClearPendingConfiguration();
            group->ClearPendingConfiguration();
            reconfigurationComplete();
          } else {
          } else {
            if (sink_monitor_mode_) {
            if (sink_monitor_mode_) {
              notifyAudioLocalSink(UnicastMonitorModeStatus::STREAMING_SUSPENDED);
              notifyAudioLocalSink(UnicastMonitorModeStatus::STREAMING_SUSPENDED);
@@ -5435,6 +5450,7 @@ private:
  LeAudioDeviceGroups aseGroups_;
  LeAudioDeviceGroups aseGroups_;
  LeAudioGroupStateMachine* groupStateMachine_;
  LeAudioGroupStateMachine* groupStateMachine_;
  int active_group_id_;
  int active_group_id_;
  LeAudioContextType pre_configuration_context_type_;
  LeAudioContextType configuration_context_type_;
  LeAudioContextType configuration_context_type_;
  static constexpr char kAllowMultipleContextsInMetadata[] =
  static constexpr char kAllowMultipleContextsInMetadata[] =
          "persist.bluetooth.leaudio.allow.multiple.contexts";
          "persist.bluetooth.leaudio.allow.multiple.contexts";
+8 −1
Original line number Original line Diff line number Diff line
@@ -1769,12 +1769,19 @@ void LeAudioDeviceGroup::RemoveCisFromStreamIfNeeded(LeAudioDevice* leAudioDevic
}
}


bool LeAudioDeviceGroup::IsPendingConfiguration(void) const {
bool LeAudioDeviceGroup::IsPendingConfiguration(void) const {
  log::verbose("group {}, is pending: {} ", group_id_, stream_conf.pending_configuration);
  return stream_conf.pending_configuration;
  return stream_conf.pending_configuration;
}
}


void LeAudioDeviceGroup::SetPendingConfiguration(void) { stream_conf.pending_configuration = true; }
void LeAudioDeviceGroup::SetPendingConfiguration(void) {
  log::verbose("group {}, is pending from {} to true", group_id_,
               stream_conf.pending_configuration);
  stream_conf.pending_configuration = true;
}


void LeAudioDeviceGroup::ClearPendingConfiguration(void) {
void LeAudioDeviceGroup::ClearPendingConfiguration(void) {
  log::verbose("group {}, is pending from {} to false", group_id_,
               stream_conf.pending_configuration);
  stream_conf.pending_configuration = false;
  stream_conf.pending_configuration = false;
}
}