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

Commit ad741014 authored by Grzegorz Kołodziejczyk's avatar Grzegorz Kołodziejczyk Committed by Łukasz Rymanowski
Browse files

le_audio: Initial implementation of updating metadata

Patch adds initial implementation for updating metadata of ASEs

Bug: 150670922
Tag: #feature
Sponsor: jpawlowski@
Test: atest --host bluetooth_le_audio_test bluetooth_le_audio_client_test

Change-Id: I4163fec7579997ad0e5eaa08cc02970ed445f223
parent 3e620855
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -216,6 +216,8 @@ bool ParseAseStatusTransientStateParams(struct ase_transient_state_params& rsp,
    return false;
  }

  STREAM_TO_UINT8(rsp.cig_id, value);
  STREAM_TO_UINT8(rsp.cis_id, value);
  STREAM_TO_UINT8(metadata_len, value);
  len -= kAseStatusTransMinLen;

@@ -227,7 +229,9 @@ bool ParseAseStatusTransientStateParams(struct ase_transient_state_params& rsp,
  if (metadata_len > 0)
    rsp.metadata = std::vector<uint8_t>(value, value + metadata_len);

  LOG(INFO) << __func__ << ", Status enabling/streaming/disabling metadata:"
  LOG(INFO) << __func__ << ", Status enabling/streaming/disabling"
            << "\n\tCIG: " << loghex(rsp.cig_id)
            << "\n\tCIS: " << loghex(rsp.cis_id) << "\n\tMetadata: "
            << base::HexEncode(rsp.metadata.data(), rsp.metadata.size());

  return true;
+3 −1
Original line number Diff line number Diff line
@@ -115,8 +115,10 @@ struct ase_qos_configured_state_params {
  uint32_t pres_delay;
};

constexpr uint16_t kAseStatusTransMinLen = 1;
constexpr uint16_t kAseStatusTransMinLen = 3;
struct ase_transient_state_params {
  uint8_t cig_id;
  uint8_t cis_id;
  std::vector<uint8_t> metadata;
};

+4 −0
Original line number Diff line number Diff line
@@ -913,6 +913,10 @@ TEST(LeAudioClientParserTest, testParseAseStatusTransientStateParams) {
      0x01,
      // ASE State
      0x03,  // 'Enabling' state
      // CIG_ID
      0x03,
      // CIS_ID
      0x04,
      // Metadata length
      0x03,
      // Metadata
+30 −11
Original line number Diff line number Diff line
@@ -951,17 +951,7 @@ bool LeAudioDevice::ConfigureAses(
    ase->max_sdu_size = codec_spec_caps::GetAudioChannelCounts(
                            ase->codec_config.audio_channel_allocation) *
                        ase->codec_config.octets_per_codec_frame;

    /* Append additional metadata */
    std::vector<uint8_t> metadata;
    metadata.resize(3 + 1);
    uint8_t* metadata_buf = metadata.data();
    UINT8_TO_STREAM(metadata_buf, 3);
    UINT8_TO_STREAM(metadata_buf,
                    types::kLeAudioMetadataTypeStreamingAudioContext);
    UINT16_TO_STREAM(metadata_buf, static_cast<uint16_t>(context_type));

    ase->metadata = std::move(metadata);
    ase->metadata = GetMetadata(context_type);

    DLOG(INFO) << __func__ << " device=" << address_
               << ", activated ASE id=" << +ase->id
@@ -1100,6 +1090,16 @@ LeAudioDeviceGroup::GetCodecConfigurationByDirection(
  return group_config;
}

bool LeAudioDeviceGroup::IsMetadataChanged(
    types::LeAudioContextType context_type) {
  for (auto* leAudioDevice = GetFirstActiveDevice(); leAudioDevice;
       leAudioDevice = GetNextActiveDevice(leAudioDevice)) {
    if (leAudioDevice->IsMetadataChanged(context_type)) return true;
  }

  return false;
}

types::LeAudioContextType LeAudioDeviceGroup::GetCurrentContextType(void) {
  return active_context_type_;
}
@@ -1618,6 +1618,25 @@ void LeAudioDevice::DeactivateAllAses(void) {
  }
}

std::vector<uint8_t> LeAudioDevice::GetMetadata(
    LeAudioContextType context_type) {
  std::vector<uint8_t> metadata;

  AppendMetadataLtvEntryForStreamingContext(metadata, context_type);
  AppendMetadataLtvEntryForCcidList(metadata, context_type);

  return std::move(metadata);
}

bool LeAudioDevice::IsMetadataChanged(types::LeAudioContextType context_type) {
  for (auto* ase = this->GetFirstActiveAse(); ase;
       ase = this->GetNextActiveAse(ase)) {
    if (this->GetMetadata(context_type) != ase->metadata) return true;
  }

  return false;
}

LeAudioDeviceGroup* LeAudioDeviceGroups::Add(int group_id) {
  /* Get first free group id */
  if (FindById(group_id)) {
+3 −0
Original line number Diff line number Diff line
@@ -140,6 +140,8 @@ class LeAudioDevice {
                                            types::AudioContexts src_cont_val);
  void DeactivateAllAses(void);
  void Dump(int fd);
  std::vector<uint8_t> GetMetadata(types::LeAudioContextType context_type);
  bool IsMetadataChanged(types::LeAudioContextType context_type);

 private:
  types::AudioContexts avail_snk_contexts_;
@@ -250,6 +252,7 @@ class LeAudioDeviceGroup {
  types::AudioContexts GetActiveContexts(void);
  std::optional<LeAudioCodecConfiguration> GetCodecConfigurationByDirection(
      types::LeAudioContextType group_context_type, uint8_t direction);
  bool IsMetadataChanged(types::LeAudioContextType group_context_type);

  inline types::AseState GetState(void) const { return current_state_; }
  void SetState(types::AseState state) {
Loading