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

Commit 6af9621d authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Abstract the adjustment of A2DP codec parameters

Replaced hard-coded SBC-specific hack for updating some
of its parameters with an API abstraction: A2DP_AdjustCodec()
Also, added the corresponding unit tests.

Bug: 30958229
Test: manual A2DP testing, added new unit tests
Change-Id: I51a0a019d107362f9c24829408d426a5403b0a8e
parent 5b24bc5d
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -66,9 +66,6 @@

static void bta_av_st_rc_timer(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);

static const size_t SBC_MAX_BITPOOL_OFFSET = 6;
static const size_t SBC_MAX_BITPOOL = 53;

/* state machine states */
enum
{
@@ -1930,13 +1927,8 @@ void bta_av_getcap_results (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
                        &av_sink_codec_info);
        }

        if ((uuid_int == UUID_SERVCLASS_AUDIO_SOURCE) &&
            (cfg.codec_info[SBC_MAX_BITPOOL_OFFSET] > SBC_MAX_BITPOOL))
        {
            APPL_TRACE_WARNING("%s: max bitpool length received for SBC is out of range."
                    "Clamping the codec bitpool configuration from %d to %d.", __func__,
                    cfg.codec_info[SBC_MAX_BITPOOL_OFFSET], SBC_MAX_BITPOOL);
            cfg.codec_info[SBC_MAX_BITPOOL_OFFSET] = SBC_MAX_BITPOOL;
        if (uuid_int == UUID_SERVCLASS_AUDIO_SOURCE) {
            A2DP_AdjustCodec(cfg.codec_info);
        }

        /* open the stream */
+16 −0
Original line number Diff line number Diff line
@@ -968,3 +968,19 @@ const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterface(
  LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
  return NULL;
}

bool A2DP_AdjustCodec(uint8_t* p_codec_info) {
  tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);

  switch (codec_type) {
    case A2DP_MEDIA_CT_SBC:
      return A2DP_AdjustCodecSbc(p_codec_info);
    case A2DP_MEDIA_CT_NON_A2DP:
      return A2DP_VendorAdjustCodec(p_codec_info);
    default:
      break;
  }

  LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
  return false;
}
+17 −0
Original line number Diff line number Diff line
@@ -1149,3 +1149,20 @@ const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterfaceSbc(

  return &a2dp_encoder_interface_sbc;
}

bool A2DP_AdjustCodecSbc(uint8_t* p_codec_info) {
  tA2DP_SBC_CIE cfg_cie;

  if (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, false) != A2DP_SUCCESS)
    return false;

  // Updated the max bitpool
  if (cfg_cie.max_bitpool > A2DP_SBC_MAX_BITPOOL) {
    LOG_WARN(LOG_TAG, "Updated the SBC codec max bitpool from %d to %d",
             cfg_cie.max_bitpool, A2DP_SBC_MAX_BITPOOL);
    cfg_cie.max_bitpool = A2DP_SBC_MAX_BITPOOL;
  }

  return (A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &cfg_cie,
                          p_codec_info) == A2DP_SUCCESS);
}
+9 −0
Original line number Diff line number Diff line
@@ -364,3 +364,12 @@ const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterface(

  return NULL;
}

bool A2DP_VendorAdjustCodec(uint8_t* p_codec_info) {
  // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
  // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);

  // Add checks based on <vendor_id, codec_id>

  return false;
}
+5 −0
Original line number Diff line number Diff line
@@ -608,6 +608,11 @@ bool A2DP_BuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf,
const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterface(
    const uint8_t* p_codec_info);

// Adjusts the A2DP codec, based on local support and Bluetooth specification.
// |p_codec_info| contains the codec information to adjust.
// Returns true if |p_codec_info| is valid and supported, otherwise false.
bool A2DP_AdjustCodec(uint8_t* p_codec_info);

#ifdef __cplusplus
}
#endif
Loading