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

Commit f82ec2bf authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Add a check whether an A2DP codec is supported before including it

Some of the A2DP SRC or SNK codecs might not be supported if the
corresponding shared library is not included.
Don't include such codecs when configuring and registering
the stream end points on the local device.

Bug: 112839060
Test: Manual - remove A2DP codec shared libraries and check the
      returned AVDTP Capabilities
Change-Id: Ia8fbdac915b208f9950ef7c9f50e3e0dc87e9111
parent 1e582d90
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -635,6 +635,9 @@ static void bta_av_api_register(tBTA_AV_DATA* p_data) {
    for (int i = codec_index_min; i < codec_index_max; i++) {
      btav_a2dp_codec_index_t codec_index =
          static_cast<btav_a2dp_codec_index_t>(i);
      if (!bta_av_co_is_supported_codec(codec_index)) {
        continue;
      }
      if (!(*bta_av_a2dp_cos.init)(codec_index, &avdtp_stream_config.cfg)) {
        continue;
      }
+20 −0
Original line number Diff line number Diff line
@@ -178,6 +178,14 @@ class BtaAvCo {
   */
  void Init(const std::vector<btav_a2dp_codec_config_t>& codec_priorities);

  /**
   * Checks whether a codec is supported.
   *
   * @param codec_index the index of the codec to check
   * @return true if the codec is supported, otherwise false
   */
  bool IsSupportedCodec(btav_a2dp_codec_index_t codec_index);

  /**
   * Get the current codec configuration for the active peer.
   *
@@ -769,6 +777,14 @@ void BtaAvCo::Reset() {
  }
}

bool BtaAvCo::IsSupportedCodec(btav_a2dp_codec_index_t codec_index) {
  // All peer state is initialized with the same local codec config,
  // hence we check only the first peer.
  A2dpCodecs* codecs = peers_[0].GetCodecs();
  CHECK(codecs != nullptr);
  return codecs->isSupportedCodec(codec_index);
}

A2dpCodecConfig* BtaAvCo::GetActivePeerCurrentCodec() {
  std::lock_guard<std::recursive_mutex> lock(codec_lock_);

@@ -2026,6 +2042,10 @@ void bta_av_co_init(
  bta_av_co_cb.Init(codec_priorities);
}

bool bta_av_co_is_supported_codec(btav_a2dp_codec_index_t codec_index) {
  return bta_av_co_cb.IsSupportedCodec(codec_index);
}

A2dpCodecConfig* bta_av_get_a2dp_current_codec(void) {
  return bta_av_co_cb.GetActivePeerCurrentCodec();
}
+4 −0
Original line number Diff line number Diff line
@@ -65,6 +65,10 @@ bool bta_av_co_set_codec_audio_config(
void bta_av_co_init(
    const std::vector<btav_a2dp_codec_config_t>& codec_priorities);

// Checks whether the codec for |codec_index| is supported.
// Returns true if the codec is supported, otherwise false.
bool bta_av_co_is_supported_codec(btav_a2dp_codec_index_t codec_index);

// Gets the current A2DP codec for the active peer.
// Returns a pointer to the current |A2dpCodecConfig| if valid, otherwise
// nullptr.
+5 −0
Original line number Diff line number Diff line
@@ -668,6 +668,11 @@ A2dpCodecConfig* A2dpCodecs::findSinkCodecConfig(const uint8_t* p_codec_info) {
  return iter->second;
}

bool A2dpCodecs::isSupportedCodec(btav_a2dp_codec_index_t codec_index) {
  std::lock_guard<std::recursive_mutex> lock(codec_mutex_);
  return indexed_codecs_.find(codec_index) != indexed_codecs_.end();
}

bool A2dpCodecs::setCodecConfig(const uint8_t* p_peer_codec_info,
                                bool is_capability,
                                uint8_t* p_result_codec_config,
+4 −0
Original line number Diff line number Diff line
@@ -301,6 +301,10 @@ class A2dpCodecs {
  // Returns the Sink codec if found, otherwise nullptr.
  A2dpCodecConfig* findSinkCodecConfig(const uint8_t* p_codec_info);

  // Checks whether the codec for |codec_index| is supported.
  // Returns true if the codec is supported, otherwise false.
  bool isSupportedCodec(btav_a2dp_codec_index_t codec_index);

  // Gets the codec config that is currently selected.
  // Returns the codec config that is currently selected, or nullptr if
  // no codec is selected.