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

Commit 9bcfbdcb authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Fix update metadata

Update Metadata can be done on ASEs in Enabling and Streaming state.
It metadata update happen when 1st earbud was streaming and second was
joining the stream, stack could incorrectly send Metadata Update in
invalid ASE state.

Note, this patch also removes dead code, which is a loop never executed.

Bug: 261538915
Test: atest bluetooth_le_audio_test
Test: atest BluetoothInstrumentationTests
Tag: #feature
Change-Id: I07b6152d6f1672dc8efb77054bb7ff147fcc2a80
parent 32b81cf9
Loading
Loading
Loading
Loading
+38 −32
Original line number Diff line number Diff line
@@ -227,8 +227,8 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
        }

        while (leAudioDevice) {
          PrepareAndSendUpdateMetadata(group, leAudioDevice,
                                       metadata_context_type, ccid_list);
          PrepareAndSendUpdateMetadata(leAudioDevice, metadata_context_type,
                                       ccid_list);
          leAudioDevice = group->GetNextActiveDevice(leAudioDevice);
        }
        break;
@@ -2020,16 +2020,13 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
                                      GATT_WRITE_NO_RSP, NULL, NULL);
  }

  void PrepareAndSendUpdateMetadata(LeAudioDeviceGroup* group,
                                    LeAudioDevice* leAudioDevice,
  void PrepareAndSendUpdateMetadata(LeAudioDevice* leAudioDevice,
                                    le_audio::types::AudioContexts context_type,
                                    const std::vector<uint8_t>& ccid_list) {
    std::vector<struct le_audio::client_parser::ascs::ctp_update_metadata>
        confs;

    for (; leAudioDevice;
         leAudioDevice = group->GetNextActiveDevice(leAudioDevice)) {
      if (!leAudioDevice->IsMetadataChanged(context_type, ccid_list)) continue;
    if (!leAudioDevice->IsMetadataChanged(context_type, ccid_list)) return;

    /* Request server to update ASEs with new metadata */
    for (struct ase* ase = leAudioDevice->GetFirstActiveAse(); ase != nullptr;
@@ -2038,6 +2035,16 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
                ADDRESS_TO_LOGGABLE_CSTR(leAudioDevice->address_), ase->id,
                ase->cis_id, ToString(ase->state).c_str());

      if (ase->state != AseState::BTA_LE_AUDIO_ASE_STATE_ENABLING &&
          ase->state != AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
        /* This might happen when update metadata happens on late connect */
        LOG_DEBUG(
            "Metadata for ase_id %d cannot be updated due to invalid ase state "
            "- see log above",
            ase->id);
        continue;
      }

      /* Filter multidirectional audio context for each ase direction */
      auto directional_audio_context =
          context_type & leAudioDevice->GetAvailableContexts(ase->direction);
@@ -2058,14 +2065,13 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
      confs.push_back(conf);
    }

    if (confs.size() != 0) {
      std::vector<uint8_t> value;
      le_audio::client_parser::ascs::PrepareAseCtpUpdateMetadata(confs, value);

      BtaGattQueue::WriteCharacteristic(leAudioDevice->conn_id_,
                                        leAudioDevice->ctp_hdls_.val_hdl, value,
                                        GATT_WRITE_NO_RSP, NULL, NULL);

      return;
    }
  }