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

Commit 184d3f94 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Łukasz Rymanowski
Browse files

LeAudio: Reafactor data path data structure

This is needed for the codec extensibility and the
new AIDL configuration provider data.

Bug: 340400084
Test: atest bluetooth_le_audio_test bluetooth_le_audio_client_test
Flag: EXEMPT; Refactor for the multi-codec, covered by the unit tests
Change-Id: I16f986f49cb8c53c04071e2d7ae092e54268f444
parent 35ddefcd
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -319,8 +319,7 @@ bool LeAudioDevice::ConfigureAses(
    auto const& ase_cfg = ase_configs.at(i);
    ase->active = true;
    ase->configured_for_context_type = context_type;
    ase->is_codec_in_controller = ase_cfg.is_codec_in_controller;
    ase->data_path_id = ase_cfg.data_path_id;
    ase->data_path_configuration = ase_cfg.data_path_configuration;
    active_ases++;

    /* In case of late connect, we could be here for STREAMING ase.
+29 −6
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "audio_hal_client/audio_hal_client.h"
#include "audio_set_configurations_generated.h"
#include "audio_set_scenarios_generated.h"
#include "btm_iso_api_types.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/util.h"
#include "le_audio/le_audio_types.h"
@@ -215,18 +216,40 @@ struct AudioSetConfigurationProviderJson {
    // common configuration source for all the codec locations.
    switch (location) {
      case types::CodecLocation::ADSP:
        config.is_codec_in_controller = false;
        config.data_path_id =
        config.data_path_configuration.dataPathId =
            bluetooth::hci::iso_manager::kIsoDataPathPlatformDefault;
        config.data_path_configuration.dataPathConfig = {};
        config.data_path_configuration.isoDataPathConfig.isTransparent = true;
        config.data_path_configuration.isoDataPathConfig.controllerDelayUs = 0;
        config.data_path_configuration.isoDataPathConfig.codecId = {
            .coding_format = bluetooth::hci::kIsoCodingFormatTransparent,
            .vendor_company_id = 0,
            .vendor_codec_id = 0};
        config.data_path_configuration.isoDataPathConfig.configuration = {};
        break;
      case types::CodecLocation::HOST:
        config.is_codec_in_controller = false;
        config.data_path_id = bluetooth::hci::iso_manager::kIsoDataPathHci;
        config.data_path_configuration.dataPathId =
            bluetooth::hci::iso_manager::kIsoDataPathHci;
        config.data_path_configuration.dataPathConfig = {};
        config.data_path_configuration.isoDataPathConfig.isTransparent = true;
        config.data_path_configuration.isoDataPathConfig.codecId = {
            .coding_format = bluetooth::hci::kIsoCodingFormatTransparent,
            .vendor_company_id = 0,
            .vendor_codec_id = 0};
        config.data_path_configuration.isoDataPathConfig.controllerDelayUs = 0;
        config.data_path_configuration.isoDataPathConfig.configuration = {};
        break;
      case types::CodecLocation::CONTROLLER:
        config.is_codec_in_controller = true;
        config.data_path_id =
        config.data_path_configuration.dataPathId =
            bluetooth::hci::iso_manager::kIsoDataPathPlatformDefault;
        config.data_path_configuration.dataPathConfig = {};
        config.data_path_configuration.isoDataPathConfig.isTransparent = false;
        // Note: The data path codecId matches the used codec, but for now there
        //       is no support for the custom path configuration data buffer.
        config.data_path_configuration.isoDataPathConfig.codecId =
            codec_config.id;
        config.data_path_configuration.isoDataPathConfig.controllerDelayUs = 0;
        config.data_path_configuration.isoDataPathConfig.configuration = {};
        break;
    }

+15 −24
Original line number Diff line number Diff line
@@ -956,17 +956,18 @@ constexpr LeAudioCodecId kLeAudioCodecHeadtracking = {
    kLeAudioVendorCodecIdHeadtracking};

struct IsoDataPathConfiguration {
  types::LeAudioCodecId codecId;
  bool isTransparent;
  uint32_t controllerDelayUs;
  std::vector<uint8_t> configuration;
  types::LeAudioCodecId codecId = {0, 0, 0};
  bool isTransparent = true;
  uint32_t controllerDelayUs = 0;
  std::vector<uint8_t> configuration = {};

  bool operator==(const IsoDataPathConfiguration& other) const {
    if (codecId != other.codecId) return false;
    if (isTransparent != other.isTransparent) return false;
    if (controllerDelayUs != other.controllerDelayUs) return false;
    if (configuration.size() != other.configuration.size()) return false;
    if (memcmp(configuration.data(), other.configuration.data(),
    if ((!other.configuration.empty()) &&
        memcmp(configuration.data(), other.configuration.data(),
               other.configuration.size())) {
      return false;
    }
@@ -982,15 +983,16 @@ std::ostream& operator<<(
    std::ostream& os, const le_audio::types::IsoDataPathConfiguration& config);

struct DataPathConfiguration {
  uint8_t dataPathId;
  std::vector<uint8_t> dataPathConfig;
  uint8_t dataPathId = 0;
  std::vector<uint8_t> dataPathConfig = {};
  IsoDataPathConfiguration isoDataPathConfig;

  bool operator==(const DataPathConfiguration& other) const {
    if (dataPathId != other.dataPathId) return false;
    if (isoDataPathConfig != other.isoDataPathConfig) return false;
    if (dataPathConfig.size() != other.dataPathConfig.size()) return false;
    if (memcmp(dataPathConfig.data(), other.dataPathConfig.data(),
    if ((!other.dataPathConfig.empty()) &&
        memcmp(dataPathConfig.data(), other.dataPathConfig.data(),
               other.dataPathConfig.size())) {
      return false;
    }
@@ -1049,8 +1051,6 @@ struct ase {
        cis_state(CisState::IDLE),
        data_path_state(DataPathState::IDLE),
        configured_for_context_type(LeAudioContextType::UNINITIALIZED),
        is_codec_in_controller(false),
        data_path_id(bluetooth::hci::iso_manager::kIsoDataPathDisabled),
        autonomous_operation_timer_(nullptr),
        autonomous_target_state_(AseState::BTA_LE_AUDIO_ASE_STATE_IDLE),
        state(AseState::BTA_LE_AUDIO_ASE_STATE_IDLE) {}
@@ -1074,12 +1074,8 @@ struct ase {
  std::vector<uint8_t> vendor_codec_config;
  uint8_t channel_count;

  /* Set to true, if the codec is implemented in BT controller, false if it's
   * implemented in host, or in separate DSP
   */
  bool is_codec_in_controller;
  /* Datapath ID used to configure an ISO channel for these ASEs */
  uint8_t data_path_id;
  /* Data path configuration */
  DataPathConfiguration data_path_configuration;

  /* Qos configuration */
  AseQosConfiguration qos_config;
@@ -1184,20 +1180,15 @@ struct AseConfiguration {
                                           .retransmission_number = 0,
                                           .max_transport_latency = 0})
      : codec(codec), qos(qos) {}
  /* Whether the codec location is transparent to the controller */
  bool is_codec_in_controller = false;
  /* Datapath ID used to configure an ISO channel for these ASEs */
  uint8_t data_path_id = bluetooth::hci::iso_manager::kIsoDataPathHci;

  types::DataPathConfiguration data_path_configuration;
  CodecConfigSetting codec;
  QosConfigSetting qos;

  bool operator!=(const AseConfiguration& other) { return !(*this == other); }

  bool operator==(const AseConfiguration& other) const {
    return ((is_codec_in_controller == other.is_codec_in_controller) &&
            (data_path_id == other.data_path_id) && (codec == other.codec) &&
            (qos == other.qos));
    return ((data_path_configuration == other.data_path_configuration) &&
            (codec == other.codec) && (qos == other.qos));
  }
};

+13 −9
Original line number Diff line number Diff line
@@ -1721,20 +1721,24 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
            ase->direction == bluetooth::le_audio::types::kLeAudioDirectionSink
                ? bluetooth::hci::iso_manager::kIsoDataPathDirectionIn
                : bluetooth::hci::iso_manager::kIsoDataPathDirectionOut,
        .data_path_id = ase->data_path_id,
        .codec_id_format = ase->is_codec_in_controller
                               ? ase->codec_id.coding_format
                               : bluetooth::hci::kIsoCodingFormatTransparent,
        .codec_id_company = ase->codec_id.vendor_company_id,
        .codec_id_vendor = ase->codec_id.vendor_codec_id,
        .controller_delay = 0x00000000,
        .codec_conf = std::vector<uint8_t>(),
        .data_path_id = ase->data_path_configuration.dataPathId,
        .codec_id_format = ase->data_path_configuration.isoDataPathConfig
                               .codecId.coding_format,
        .codec_id_company = ase->data_path_configuration.isoDataPathConfig
                                .codecId.vendor_company_id,
        .codec_id_vendor = ase->data_path_configuration.isoDataPathConfig
                               .codecId.vendor_codec_id,
        .controller_delay =
            ase->data_path_configuration.isoDataPathConfig.controllerDelayUs,
        .codec_conf =
            ase->data_path_configuration.isoDataPathConfig.configuration,
    };

    LeAudioLogHistory::Get()->AddLogHistory(
        kLogStateMachineTag, group_id, RawAddress::kEmpty,
        kLogSetDataPathOp + "cis_h:" + loghex(ase->cis_conn_hdl),
        "direction: " + loghex(param.data_path_dir));
        "direction: " + loghex(param.data_path_dir) + ", codecId: " +
            ToString(ase->data_path_configuration.isoDataPathConfig.codecId));

    ase->data_path_state = DataPathState::CONFIGURING;
    IsoManager::GetInstance()->SetupIsoDataPath(ase->cis_conn_hdl,