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

Commit 7122b183 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

LeAudio: Stream configuration improvements

 - document struct members
 - remove unused `is_active` member
 - reduce utility functions dependency by passing only the
   necessary internal `stream_configuration.stream_params`
   member

Bug: 295972694
Test: atest --host bluetooth_le_audio_test bluetooth_le_audio_client_test bluetooth_test_broadcaster bluetooth_test_broadcaster_state_machine bluetooth_le_audio_codec_manager_test
Change-Id: Ic225eb3fa7b11a36432fa3f2860aaabfbef2b4e5
parent 3d7137cc
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -3074,7 +3074,7 @@ class LeAudioClientImpl : public LeAudioClient {

  void PrepareAndSendToTwoCises(
      const std::vector<uint8_t>& data,
      struct le_audio::stream_configuration* stream_conf) {
      const struct le_audio::stream_parameters& stream_params) {
    uint16_t left_cis_handle = 0;
    uint16_t right_cis_handle = 0;

@@ -3090,16 +3090,14 @@ class LeAudioClientImpl : public LeAudioClient {
      return;
    }

    for (auto [cis_handle, audio_location] :
         stream_conf->stream_params.sink.stream_locations) {
    for (auto [cis_handle, audio_location] : stream_params.stream_locations) {
      if (audio_location & le_audio::codec_spec_conf::kLeAudioLocationAnyLeft)
        left_cis_handle = cis_handle;
      if (audio_location & le_audio::codec_spec_conf::kLeAudioLocationAnyRight)
        right_cis_handle = cis_handle;
    }

    uint16_t byte_count =
        stream_conf->stream_params.sink.octets_per_codec_frame;
    uint16_t byte_count = stream_params.octets_per_codec_frame;
    bool mix_to_mono = (left_cis_handle == 0) || (right_cis_handle == 0);
    if (mix_to_mono) {
      std::vector<uint8_t> mono = mono_blend(
@@ -3134,10 +3132,9 @@ class LeAudioClientImpl : public LeAudioClient {

  void PrepareAndSendToSingleCis(
      const std::vector<uint8_t>& data,
      struct le_audio::stream_configuration* stream_conf) {
    uint16_t num_channels = stream_conf->stream_params.sink.num_of_channels;
    uint16_t cis_handle =
        stream_conf->stream_params.sink.stream_locations.front().first;
      const struct le_audio::stream_parameters& stream_params) {
    uint16_t num_channels = stream_params.num_of_channels;
    uint16_t cis_handle = stream_params.stream_locations.front().first;

    uint16_t number_of_required_samples_per_channel =
        sw_enc_left->GetNumOfSamplesPerChannel();
@@ -3148,8 +3145,7 @@ class LeAudioClientImpl : public LeAudioClient {
      return;
    }

    uint16_t byte_count =
        stream_conf->stream_params.sink.octets_per_codec_frame;
    uint16_t byte_count = stream_params.octets_per_codec_frame;
    bool mix_to_mono = (num_channels == 1);
    if (mix_to_mono) {
      /* Since we always get two channels from framework, lets make it mono here
@@ -3204,10 +3200,10 @@ class LeAudioClientImpl : public LeAudioClient {
    if ((stream_conf.stream_params.sink.num_of_devices == 2) ||
        (stream_conf.stream_params.sink.stream_locations.size() == 2)) {
      /* Streaming to two devices or one device with 2 CISes */
      PrepareAndSendToTwoCises(data, &stream_conf);
      PrepareAndSendToTwoCises(data, stream_conf.stream_params.sink);
    } else {
      /* Streaming to one device and 1 CIS */
      PrepareAndSendToSingleCis(data, &stream_conf);
      PrepareAndSendToSingleCis(data, stream_conf.stream_params.sink);
    }
  }

@@ -3413,7 +3409,8 @@ class LeAudioClientImpl : public LeAudioClient {
        LOG(WARNING)
            << " The encoder instance should have been already released.";
      }
      sw_enc_left = le_audio::CodecInterface::CreateInstance(stream_conf->id);
      sw_enc_left =
          le_audio::CodecInterface::CreateInstance(stream_conf->codec_id);
      auto codec_status = sw_enc_left->InitEncoder(
          audio_framework_source_config, current_source_codec_config);
      if (codec_status != le_audio::CodecInterface::Status::STATUS_OK) {
@@ -3421,7 +3418,8 @@ class LeAudioClientImpl : public LeAudioClient {
        return false;
      }

      sw_enc_right = le_audio::CodecInterface::CreateInstance(stream_conf->id);
      sw_enc_right =
          le_audio::CodecInterface::CreateInstance(stream_conf->codec_id);
      codec_status = sw_enc_right->InitEncoder(audio_framework_source_config,
                                               current_source_codec_config);
      if (codec_status != le_audio::CodecInterface::Status::STATUS_OK) {
@@ -3485,7 +3483,8 @@ class LeAudioClientImpl : public LeAudioClient {
        LOG(WARNING)
            << " The decoder instance should have been already released.";
      }
      sw_dec_left = le_audio::CodecInterface::CreateInstance(stream_conf->id);
      sw_dec_left =
          le_audio::CodecInterface::CreateInstance(stream_conf->codec_id);
      auto codec_status = sw_dec_left->InitDecoder(current_sink_codec_config,
                                                   audio_framework_sink_config);
      if (codec_status != le_audio::CodecInterface::Status::STATUS_OK) {
@@ -3493,7 +3492,8 @@ class LeAudioClientImpl : public LeAudioClient {
        return;
      }

      sw_dec_right = le_audio::CodecInterface::CreateInstance(stream_conf->id);
      sw_dec_right =
          le_audio::CodecInterface::CreateInstance(stream_conf->codec_id);
      codec_status = sw_dec_right->InitDecoder(current_sink_codec_config,
                                               audio_framework_sink_config);
      if (codec_status != le_audio::CodecInterface::Status::STATUS_OK) {
+1 −1
Original line number Diff line number Diff line
@@ -1949,7 +1949,7 @@ void LeAudioDeviceGroup::Dump(int fd, int active_group_id) const {
         << "      stream configuration: "
         << (stream_conf.conf != nullptr ? stream_conf.conf->name : " unknown ")
         << "\n"
         << "      codec id: " << +(stream_conf.id.coding_format)
         << "      codec id: " << +(stream_conf.codec_id.coding_format)
         << ",\tpending_configuration: " << stream_conf.pending_configuration
         << "\n"
         << "      num of devices(connected): " << Size() << "("
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ class LeAudioDeviceGroup {
    types::CigState state_;
  } cig;

  /* Current audio stream configuration */
  struct stream_configuration stream_conf;

  uint8_t audio_directions_;
+6 −6
Original line number Diff line number Diff line
@@ -898,17 +898,17 @@ struct stream_parameters {
};

struct stream_configuration {
  /* Whether the group should be reconfigured once the streaming stops */
  bool pending_configuration;

  types::LeAudioCodecId id;

  /* Pointer to chosen req */
  /* Currently selected remote device set configuration */
  const le_audio::set_configurations::AudioSetConfiguration* conf;

  /* Sink & Source configuration */
  types::BidirectionalPair<stream_parameters> stream_params;
  /* Currently selected local audio codec */
  types::LeAudioCodecId codec_id;

  bool is_active;
  /* Currently selected local Sink & Source configuration */
  types::BidirectionalPair<stream_parameters> stream_params;
};

void AppendMetadataLtvEntryForCcidList(std::vector<uint8_t>& metadata,
+1 −1
Original line number Diff line number Diff line
@@ -1171,7 +1171,7 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {

  void AddCisToStreamConfiguration(LeAudioDeviceGroup* group,
                                   const struct ase* ase) {
    group->stream_conf.id = ase->codec_id;
    group->stream_conf.codec_id = ase->codec_id;

    auto cis_conn_hdl = ase->cis_conn_hdl;
    auto& params = group->stream_conf.stream_params.get(ase->direction);