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

Commit 1d8400fb authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Yet another optimisation on max CIS needed

With this patch, Android makes use of requested bidirectional CISes to
cover scenarios which requires only unicast CISes.

This will also help to save controller resources as without this path,
CIG was created with much to more CISes than needed.

eg: CIG create for conversational:

< HCI Command: LE Set Connected Isochronous Group Parameters (0x08|0x0062) plen 51                                                                                                                                                                                      #29966 155.397783
        CIG ID: 0x01
        Master to Slave SDU Interval: 10000 us (0x002710)
        Slave to Master SDU Interval: 10000 us (0x002710)
        SCA: 201 - 500 ppm (0x00)
        Packing: Sequential (0x00)
        Framing: Unframed (0x00)
        Master to Slave Maximum Latency: 10 ms (0x000a)
        Slave to Master Maximum Latency: 10 ms (0x000a)
        Number of CIS: 4
        CIS ID: 0x00
        Master to Slave Maximum SDU Size: 80
        Slave to Master Maximum SDU Size: 80
        Master to Slave PHY: 0x02
          LE 2M
        Slave to Master PHY: 0x02
          LE 2M
        Master to Slave Retransmission attempts: 0x02
        Slave to Master Retransmission attempts: 0x02
        CIS ID: 0x01
        Master to Slave Maximum SDU Size: 80
        Slave to Master Maximum SDU Size: 80
        Master to Slave PHY: 0x02
          LE 2M
        Slave to Master PHY: 0x02
          LE 2M
        Master to Slave Retransmission attempts: 0x02
        Slave to Master Retransmission attempts: 0x02
        CIS ID: 0x02
        Master to Slave Maximum SDU Size: 80
        Slave to Master Maximum SDU Size: 0
        Master to Slave PHY: 0x02
          LE 2M
        Slave to Master PHY: 0x02
          LE 2M
        Master to Slave Retransmission attempts: 0x02
        Slave to Master Retransmission attempts: 0x00
        CIS ID: 0x03
        Master to Slave Maximum SDU Size: 80
        Slave to Master Maximum SDU Size: 0
        Master to Slave PHY: 0x02
          LE 2M
        Slave to Master PHY: 0x02
          LE 2M
        Master to Slave Retransmission attempts: 0x02
        Slave to Master Retransmission attempts: 0x00

Bug: 231084798
Bug: 238961038
Bug: 239651157
Sponsor: @siyuanh
Test: atest BluetoothInstrumentationTests
Tag: #feature
Merged-In: Ie5389b67684e392f92889d263bbae36d22e6edf4
Change-Id: Ie5389b67684e392f92889d263bbae36d22e6edf4
(cherry picked from commit e986aa28)
parent 4805b64f
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -973,10 +973,19 @@ bool LeAudioDeviceGroup::CigAssignCisIds(LeAudioDevice* leAudioDevice) {
        cis_id = GetFirstFreeCisId(CisType::CIS_TYPE_UNIDIRECTIONAL_SINK);
      }

      if (cis_id == kInvalidCisId) {
        LOG_WARN(
            " Unable to get free Uni-Directional Sink CIS ID - maybe there is "
            "bi-directional available");
        /* This could happen when scenarios for given context type allows for
         * Sink and Source configuration but also only Sink configuration.
         */
        cis_id = GetFirstFreeCisId(CisType::CIS_TYPE_BIDIRECTIONAL);
        if (cis_id == kInvalidCisId) {
          LOG_ERROR("Unable to get free Uni-Directional Sink CIS ID");
          return false;
        }
      }

      ase->cis_id = cis_id;
      cises_[cis_id].addr = leAudioDevice->address_;
@@ -993,10 +1002,19 @@ bool LeAudioDeviceGroup::CigAssignCisIds(LeAudioDevice* leAudioDevice) {
      cis_id = GetFirstFreeCisId(CisType::CIS_TYPE_UNIDIRECTIONAL_SOURCE);
    }

    if (cis_id == kInvalidCisId) {
      /* This could happen when scenarios for given context type allows for
       * Sink and Source configuration but also only Sink configuration.
       */
      LOG_WARN(
          "Unable to get free Uni-Directional Source CIS ID - maybe there "
          "is bi-directional available");
      cis_id = GetFirstFreeCisId(CisType::CIS_TYPE_BIDIRECTIONAL);
      if (cis_id == kInvalidCisId) {
        LOG_ERROR("Unable to get free Uni-Directional Source CIS ID");
        return false;
      }
    }

    ase->cis_id = cis_id;
    cises_[cis_id].addr = leAudioDevice->address_;
+28 −0
Original line number Diff line number Diff line
@@ -109,10 +109,38 @@ void get_cis_count(const AudioSetConfigurations* audio_set_confs,
                              : 0;

    *cis_count_bidir = std::max(bidir_count, *cis_count_bidir);

    /* Check if we can reduce a number of unicast CISes in case bidirectional
     * are use in other or this scenario */
    if (bidir_count < *cis_count_bidir) {
      /* Since we already have bidirectional cises available from other
       * scenarios, let's decrease number of unicast sinks in this scenario.
       */
      uint8_t available_bidir = *cis_count_bidir - bidir_count;
      unidir_sink_count =
          unidir_sink_count - std::min(unidir_sink_count, available_bidir);
      unidir_source_count =
          unidir_source_count - std::min(unidir_source_count, available_bidir);
    } else if (bidir_count > *cis_count_bidir) {
      /* Lets decrease number of the unicast cises from previouse scenarios */
      uint8_t available_bidir = bidir_count - *cis_count_bidir;
      *cis_count_unidir_sink =
          *cis_count_unidir_sink -
          std::min(*cis_count_unidir_sink, available_bidir);
      *cis_count_unidir_source =
          *cis_count_unidir_source -
          std::min(*cis_count_unidir_source, available_bidir);
    }

    *cis_count_unidir_sink =
        std::max(unidir_sink_count, *cis_count_unidir_sink);
    *cis_count_unidir_source =
        std::max(unidir_source_count, *cis_count_unidir_source);

    LOG_INFO(
        "Intermediate step:  Bi-Directional: %d,"
        " Uni-Directional Sink: %d, Uni-Directional Source: %d ",
        *cis_count_bidir, *cis_count_unidir_sink, *cis_count_unidir_source);
  }

  LOG_INFO(