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

Commit d779c54f authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Automerger Merge Worker
Browse files

Merge "LeAudio: Fix suspend/resume loop" am: 6a875d9f

parents 5d5094fd 6a875d9f
Loading
Loading
Loading
Loading
+161 −28
Original line number Diff line number Diff line
@@ -3433,14 +3433,56 @@ class LeAudioClientImpl : public LeAudioClient {
            }
            break;
          case AudioState::READY_TO_START:
            audio_sender_state_ = AudioState::READY_TO_START;
            if (!IsDirectionAvailableForCurrentConfiguration(
                    group, le_audio::types::kLeAudioDirectionSink)) {
              LOG_WARN(
                  " sink is not configured. \n audio_receiver_state: %s \n"
                  "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                  "Reconfiguring to %s",
                  ToString(audio_receiver_state_).c_str(),
                  ToString(audio_sender_state_).c_str(),
                  (group->IsPendingConfiguration() ? "true" : "false"),
                  ToString(configuration_context_type_).c_str());
              group->PrintDebugState();
              SetConfigurationAndStopStreamWhenNeeded(
                  group, configuration_context_type_);
            }
            break;
          case AudioState::STARTED:
            audio_sender_state_ = AudioState::READY_TO_START;
            /* If signalling part is completed trigger start receiving audio
            /* If signalling part is completed trigger start sending audio
             * here, otherwise it'll be called on group streaming state callback
             */
            if (group->GetState() ==
                AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
              if (IsDirectionAvailableForCurrentConfiguration(
                      group, le_audio::types::kLeAudioDirectionSink)) {
                StartSendingAudio(active_group_id_);
              } else {
                LOG_WARN(
                    " sink is not configured. \n audio_receiver_state: %s \n"
                    "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                    "Reconfiguring to %s",
                    ToString(audio_receiver_state_).c_str(),
                    ToString(audio_sender_state_).c_str(),
                    (group->IsPendingConfiguration() ? "true" : "false"),
                    ToString(configuration_context_type_).c_str());
                group->PrintDebugState();
                SetConfigurationAndStopStreamWhenNeeded(
                    group, configuration_context_type_);
              }
            } else {
              LOG_ERROR(
                  " called in wrong state. \n audio_receiver_state: %s \n"
                  "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                  "Reconfiguring to %s",
                  ToString(audio_receiver_state_).c_str(),
                  ToString(audio_sender_state_).c_str(),
                  (group->IsPendingConfiguration() ? "true" : "false"),
                  ToString(configuration_context_type_).c_str());
              group->PrintDebugState();
              CancelStreamingRequest();
            }
            break;
          case AudioState::RELEASING:
@@ -3450,21 +3492,50 @@ class LeAudioClientImpl : public LeAudioClient {
            audio_sender_state_ = audio_receiver_state_;
            break;
          case AudioState::READY_TO_RELEASE:
            /* If the other direction is streaming we can start sending audio */
            if (group->GetState() ==
                AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
              if (IsDirectionAvailableForCurrentConfiguration(
                      group, le_audio::types::kLeAudioDirectionSink)) {
                StartSendingAudio(active_group_id_);
              } else {
                LOG_WARN(
                    " sink is not configured. \n audio_receiver_state: %s \n"
                    "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                    "Reconfiguring to %s",
                    ToString(audio_receiver_state_).c_str(),
                    ToString(audio_sender_state_).c_str(),
                    (group->IsPendingConfiguration() ? "true" : "false"),
                    ToString(configuration_context_type_).c_str());
                group->PrintDebugState();
                SetConfigurationAndStopStreamWhenNeeded(
                    group, configuration_context_type_);
              }
            } else {
              LOG_ERROR(
                  " called in wrong state. \n audio_receiver_state: %s \n"
                "audio_sender_state: %s \n",
                  "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                  "Reconfiguring to %s",
                  ToString(audio_receiver_state_).c_str(),
                ToString(audio_sender_state_).c_str());
                  ToString(audio_sender_state_).c_str(),
                  (group->IsPendingConfiguration() ? "true" : "false"),
                  ToString(configuration_context_type_).c_str());
              group->PrintDebugState();
              CancelStreamingRequest();
            }
            break;
        }
        break;
      case AudioState::READY_TO_START:
        LOG_WARN(
        LOG_ERROR(
            " called in wrong state. \n audio_receiver_state: %s \n"
            "audio_sender_state: %s \n",
            "audio_sender_state: %s \n isPendingConfiguration: %s \n "
            "Reconfiguring to %s",
            ToString(audio_receiver_state_).c_str(),
            ToString(audio_sender_state_).c_str());
            ToString(audio_sender_state_).c_str(),
            (group->IsPendingConfiguration() ? "true" : "false"),
            ToString(configuration_context_type_).c_str());
        group->PrintDebugState();
        CancelStreamingRequest();
        break;
      case AudioState::READY_TO_RELEASE:
@@ -3598,24 +3669,56 @@ class LeAudioClientImpl : public LeAudioClient {
            }
            break;
          case AudioState::READY_TO_START:
            audio_receiver_state_ = AudioState::READY_TO_START;
            if (!IsDirectionAvailableForCurrentConfiguration(
                    group, le_audio::types::kLeAudioDirectionSource)) {
              LOG_WARN(
                  " source is not configured. \n audio_receiver_state: %s \n"
                  "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                  "Reconfiguring to %s",
                  ToString(audio_receiver_state_).c_str(),
                  ToString(audio_sender_state_).c_str(),
                  (group->IsPendingConfiguration() ? "true" : "false"),
                  ToString(configuration_context_type_).c_str());
              group->PrintDebugState();
              SetConfigurationAndStopStreamWhenNeeded(
                  group, configuration_context_type_);
            }
            break;
          case AudioState::STARTED:
            audio_receiver_state_ = AudioState::READY_TO_START;
            /* If signalling part is completed trigger start reveivin audio
            /* If signalling part is completed trigger start receiving audio
             * here, otherwise it'll be called on group streaming state callback
             */
            if (group->GetState() ==
                AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
              if (!IsDirectionAvailableForCurrentConfiguration(
              if (IsDirectionAvailableForCurrentConfiguration(
                      group, le_audio::types::kLeAudioDirectionSource)) {
                StartReceivingAudio(active_group_id_);
              } else {
                LOG_WARN(
                    "Local audio sink was resumed when not in a proper "
                    "configuration. This should not happen. Reconfiguring to "
                    "VOICEASSISTANTS.");
                    " source is not configured. \n audio_receiver_state: %s \n"
                    "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                    "Reconfiguring to %s",
                    ToString(audio_receiver_state_).c_str(),
                    ToString(audio_sender_state_).c_str(),
                    (group->IsPendingConfiguration() ? "true" : "false"),
                    ToString(configuration_context_type_).c_str());
                group->PrintDebugState();
                SetConfigurationAndStopStreamWhenNeeded(
                    group, LeAudioContextType::VOICEASSISTANTS);
                break;
                    group, configuration_context_type_);
              }
              StartReceivingAudio(active_group_id_);
            } else {
              LOG_ERROR(
                  " called in wrong state. \n audio_receiver_state: %s \n"
                  "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                  "Reconfiguring to %s",
                  ToString(audio_receiver_state_).c_str(),
                  ToString(audio_sender_state_).c_str(),
                  (group->IsPendingConfiguration() ? "true" : "false"),
                  ToString(configuration_context_type_).c_str());
              group->PrintDebugState();
              CancelStreamingRequest();
            }
            break;
          case AudioState::RELEASING:
@@ -3625,21 +3728,51 @@ class LeAudioClientImpl : public LeAudioClient {
            audio_receiver_state_ = audio_sender_state_;
            break;
          case AudioState::READY_TO_RELEASE:
            /* If the other direction is streaming we can start receiving audio
             */
            if (group->GetState() ==
                AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
              if (IsDirectionAvailableForCurrentConfiguration(
                      group, le_audio::types::kLeAudioDirectionSource)) {
                StartReceivingAudio(active_group_id_);
              } else {
                LOG_WARN(
                    " source is not configured. \n audio_receiver_state: %s \n"
                    "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                    "Reconfiguring to %s",
                    ToString(audio_receiver_state_).c_str(),
                    ToString(audio_sender_state_).c_str(),
                    (group->IsPendingConfiguration() ? "true" : "false"),
                    ToString(configuration_context_type_).c_str());
                group->PrintDebugState();
                SetConfigurationAndStopStreamWhenNeeded(
                    group, configuration_context_type_);
              }
            } else {
              LOG_ERROR(
                  " called in wrong state. \n audio_receiver_state: %s \n"
                "audio_sender_state: %s \n",
                  "audio_sender_state: %s \n isPendingConfiguration: %s \n "
                  "Reconfiguring to %s",
                  ToString(audio_receiver_state_).c_str(),
                ToString(audio_sender_state_).c_str());
                  ToString(audio_sender_state_).c_str(),
                  (group->IsPendingConfiguration() ? "true" : "false"),
                  ToString(configuration_context_type_).c_str());
              group->PrintDebugState();
              CancelStreamingRequest();
            }
            break;
        }
        break;
      case AudioState::READY_TO_START:
        LOG_WARN(
        LOG_ERROR(
            " called in wrong state. \n audio_receiver_state: %s \n"
            "audio_sender_state: %s \n",
            "audio_sender_state: %s \n isPendingConfiguration: %s \n "
            "Reconfiguring to %s",
            ToString(audio_receiver_state_).c_str(),
            ToString(audio_sender_state_).c_str());
            ToString(audio_sender_state_).c_str(),
            (group->IsPendingConfiguration() ? "true" : "false"),
            ToString(configuration_context_type_).c_str());
        group->PrintDebugState();
        CancelStreamingRequest();
        break;
      case AudioState::READY_TO_RELEASE: