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

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

Merge changes I1c7fec7e,I16d65f52,I4d31acbf am: ca502e66 am: 45419ac5 am: 8857ee62

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2002294

Change-Id: Ie766b82c87ea5d78a056350f34e0a887fb8a0c15
parents 9608db87 8857ee62
Loading
Loading
Loading
Loading
+84 −46
Original line number Diff line number Diff line
@@ -1063,6 +1063,17 @@ class LeAudioClientImpl : public LeAudioClient {
         * Group would be assigned once service search is completed.
         */
        if (group) {
          /* Update of available context may happen during state transition
           * or while streaming. Don't bother current transition or streaming
           * process. Update configuration once group became idle.
           */
          if (group->IsInTransition() ||
              (group->GetState() ==
               AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING)) {
            group->SetPendingUpdateAvailableContexts(updated_avail_contexts);
            return;
          }

          std::optional<AudioContexts> updated_contexts =
              group->UpdateActiveContextsMap(updated_avail_contexts);
          if (updated_contexts) {
@@ -1955,14 +1966,16 @@ class LeAudioClientImpl : public LeAudioClient {
                                           chan_encoded.size());
  }

  struct le_audio::stream_configuration* GetStreamSinkConfiguration(
      LeAudioDeviceGroup* group) {
  struct le_audio::stream_configuration* GetStreamConfigurationByDirection(
      LeAudioDeviceGroup* group, uint8_t direction) {
    struct le_audio::stream_configuration* stream_conf = &group->stream_conf;
    int num_of_devices = 0;
    int num_of_channels = 0;
    uint32_t sample_freq_hz = 0;
    uint32_t frame_duration_us = 0;
    uint32_t audio_channel_allocation = 0;
    uint16_t octets_per_frame = 0;
    uint16_t codec_frames_blocks_per_sdu = 0;

    LOG(INFO) << __func__ << " group_id: " << group->group_id_;

@@ -1971,8 +1984,7 @@ class LeAudioClientImpl : public LeAudioClient {

    for (auto* device = group->GetFirstActiveDevice(); device != nullptr;
         device = group->GetNextActiveDevice(device)) {
      auto* ase = device->GetFirstActiveAseByDirection(
          le_audio::types::kLeAudioDirectionSink);
      auto* ase = device->GetFirstActiveAseByDirection(direction);

      if (ase) {
        LOG(INFO) << __func__ << "device: " << device->address_;
@@ -1983,6 +1995,7 @@ class LeAudioClientImpl : public LeAudioClient {
           ase = device->GetNextActiveAseWithSameDirection(ase)) {
        streams.emplace_back(std::make_pair(
            ase->cis_conn_hdl, *ase->codec_config.audio_channel_allocation));
        audio_channel_allocation |= *ase->codec_config.audio_channel_allocation;
        num_of_channels += ase->codec_config.channel_count;
        if (sample_freq_hz == 0) {
          sample_freq_hz = ase->codec_config.GetSamplingFrequencyHz();
@@ -2011,29 +2024,63 @@ class LeAudioClientImpl : public LeAudioClient {
              << " != " << *ase->codec_config.octets_per_codec_frame;
        }

        if (codec_frames_blocks_per_sdu == 0) {
          codec_frames_blocks_per_sdu =
              *ase->codec_config.codec_frames_blocks_per_sdu;
        } else {
          LOG_ASSERT(codec_frames_blocks_per_sdu ==
                     ase->codec_config.codec_frames_blocks_per_sdu)
              << __func__ << " codec_frames_blocks_per_sdu: "
              << +codec_frames_blocks_per_sdu
              << " != " << *ase->codec_config.codec_frames_blocks_per_sdu;
        }

        LOG(INFO) << __func__ << " Added CIS: " << +ase->cis_conn_hdl
                  << " to stream. Allocation: "
                  << +(*ase->codec_config.audio_channel_allocation)
                  << " sample_freq: " << +sample_freq_hz
                  << " frame_duration: " << +frame_duration_us
                  << " octects per frame: " << +octets_per_frame;
                  << " octects per frame: " << +octets_per_frame
                  << " codec_frame_blocks_per_sdu: "
                  << +codec_frames_blocks_per_sdu;
      }
    }

    if (streams.empty()) return nullptr;

    if (direction == le_audio::types::kLeAudioDirectionSource) {
      stream_conf->source_streams = std::move(streams);
      stream_conf->source_num_of_devices = num_of_devices;
      stream_conf->source_num_of_channels = num_of_channels;
      stream_conf->source_sample_frequency_hz = sample_freq_hz;
      stream_conf->source_frame_duration_us = frame_duration_us;
      stream_conf->source_audio_channel_allocation = audio_channel_allocation;
      stream_conf->source_octets_per_codec_frame = octets_per_frame;
      stream_conf->source_codec_frames_blocks_per_sdu =
          codec_frames_blocks_per_sdu;
    } else if (direction == le_audio::types::kLeAudioDirectionSink) {
      stream_conf->sink_streams = std::move(streams);
      stream_conf->sink_num_of_devices = num_of_devices;
      stream_conf->sink_num_of_channels = num_of_channels;
      stream_conf->sink_sample_frequency_hz = sample_freq_hz;
      stream_conf->sink_frame_duration_us = frame_duration_us;
      stream_conf->sink_audio_channel_allocation = audio_channel_allocation;
      stream_conf->sink_octets_per_codec_frame = octets_per_frame;
      stream_conf->sink_codec_frames_blocks_per_sdu =
          codec_frames_blocks_per_sdu;
    }

    LOG(INFO) << __func__ << " configuration: " << stream_conf->conf->name;

    return stream_conf;
  }

  struct le_audio::stream_configuration* GetStreamSinkConfiguration(
      LeAudioDeviceGroup* group) {
    return GetStreamConfigurationByDirection(
        group, le_audio::types::kLeAudioDirectionSink);
  }

  void OnAudioDataReady(const std::vector<uint8_t>& data) {
    if ((active_group_id_ == bluetooth::groups::kGroupUnknown) ||
        (audio_sender_state_ != AudioState::STARTED))
@@ -2182,41 +2229,8 @@ class LeAudioClientImpl : public LeAudioClient {

  struct le_audio::stream_configuration* GetStreamSourceConfiguration(
      LeAudioDeviceGroup* group) {
    LeAudioDevice* device = group->GetFirstActiveDevice();
    LOG_ASSERT(device) << __func__
                       << " Shouldn't be called without an active device.";

    ase* ase = device->GetFirstActiveAseByDirection(
        le_audio::types::kLeAudioDirectionSource);

    if (!ase) return nullptr;

    /* For now we support one microphone only*/

    auto* stream_conf = &group->stream_conf;
    std::vector<std::pair<uint16_t, uint32_t>> streams;

    stream_conf->source_streams.emplace_back(std::make_pair(
        ase->cis_conn_hdl, *ase->codec_config.audio_channel_allocation));

    stream_conf->source_num_of_devices = 1;
    stream_conf->source_num_of_channels = 1;
    stream_conf->source_sample_frequency_hz =
        ase->codec_config.GetSamplingFrequencyHz();
    stream_conf->source_frame_duration_us =
        ase->codec_config.GetFrameDurationUs();
    stream_conf->source_octets_per_codec_frame =
        *ase->codec_config.octets_per_codec_frame;

    LOG(INFO) << __func__ << " Added CIS: " << +ase->cis_conn_hdl
              << " to stream. Allocation: "
              << +(*ase->codec_config.audio_channel_allocation)
              << " sample_freq: " << +stream_conf->source_sample_frequency_hz
              << " frame_duration: " << +stream_conf->source_frame_duration_us
              << " octects per frame: "
              << +stream_conf->source_octets_per_codec_frame;

    return stream_conf;
    return GetStreamConfigurationByDirection(
        group, le_audio::types::kLeAudioDirectionSource);
  }

  void StartReceivingAudio(int group_id) {
@@ -3071,6 +3085,30 @@ class LeAudioClientImpl : public LeAudioClient {
        if (!RestartStreamingAfterReconfiguration(group_id))
          CancelStreamingRequest();

        LeAudioDeviceGroup* group = aseGroups_.FindById(active_group_id_);
        if (!group) {
          LOG(ERROR) << __func__ << ", Failed to update pending available "
                     << "contexts for group: " << group_id;
          return;
        }

        /* Update group configuration with pending available context */
        std::optional<AudioContexts> pending_update_available_contexts =
            group->GetPendingUpdateAvailableContexts();
        if (pending_update_available_contexts) {
          std::optional<AudioContexts> updated_contexts =
              group->UpdateActiveContextsMap(*pending_update_available_contexts);

          if (updated_contexts) {
            callbacks_->OnAudioConf(group->audio_directions_, group->group_id_,
                                    group->snk_audio_locations_.to_ulong(),
                                    group->src_audio_locations_.to_ulong(),
                                    updated_contexts->to_ulong());
          }

          group->SetPendingUpdateAvailableContexts(std::nullopt);
        }

        break;
      }
      case GroupStreamStatus::RELEASING:
+10 −0
Original line number Diff line number Diff line
@@ -264,6 +264,15 @@ class LeAudioDeviceGroup {
    target_state_ = state;
  }

  inline std::optional<types::AudioContexts> GetPendingUpdateAvailableContexts()
      const {
    return pending_update_available_contexts_;
  }
  inline void SetPendingUpdateAvailableContexts(
      std::optional<types::AudioContexts> audio_contexts) {
    pending_update_available_contexts_ = audio_contexts;
  }

  bool IsInTransition(void);
  bool IsReleasing(void);
  void Dump(int fd);
@@ -285,6 +294,7 @@ class LeAudioDeviceGroup {
  /* Mask and table of currently supported contexts */
  types::LeAudioContextType active_context_type_;
  types::AudioContexts active_contexts_mask_;
  std::optional<types::AudioContexts> pending_update_available_contexts_;
  std::map<types::LeAudioContextType,
           const set_configurations::AudioSetConfiguration*>
      active_context_to_configuration_map;
+4 −0
Original line number Diff line number Diff line
@@ -660,6 +660,8 @@ struct stream_configuration {
  uint32_t sink_sample_frequency_hz;
  uint32_t sink_frame_duration_us;
  uint16_t sink_octets_per_codec_frame;
  uint32_t sink_audio_channel_allocation;
  uint8_t sink_codec_frames_blocks_per_sdu;
  /* Number of channels is what we will request from audio framework */
  uint8_t sink_num_of_channels;
  int sink_num_of_devices;
@@ -671,6 +673,8 @@ struct stream_configuration {
  uint32_t source_sample_frequency_hz;
  uint32_t source_frame_duration_us;
  uint16_t source_octets_per_codec_frame;
  uint32_t source_audio_channel_allocation;
  uint8_t source_codec_frames_blocks_per_sdu;
  /* Number of channels is what we will request from audio framework */
  uint8_t source_num_of_channels;
  int source_num_of_devices;
+4 −6
Original line number Diff line number Diff line
@@ -868,14 +868,12 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
            group->GetPhyBitmask(le_audio::types::kLeAudioDirectionSource);

        if (ases_pair.sink) {
          /* TODO: config should be previously adopted */
          cis_cfg.max_sdu_size_mtos = ase->max_sdu_size;
          cis_cfg.rtn_mtos = ase->retrans_nb;
          cis_cfg.max_sdu_size_mtos = ases_pair.sink->max_sdu_size;
          cis_cfg.rtn_mtos = ases_pair.sink->retrans_nb;
        }
        if (ases_pair.source) {
          /* TODO: config should be previously adopted */
          cis_cfg.max_sdu_size_stom = ase->max_sdu_size;
          cis_cfg.rtn_stom = ase->retrans_nb;
          cis_cfg.max_sdu_size_stom = ases_pair.source->max_sdu_size;
          cis_cfg.rtn_stom = ases_pair.source->retrans_nb;
        }

        cis_cfgs.push_back(cis_cfg);