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
{
&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 */
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;
+}
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);
+}
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;
+}
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
const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterfaceSbc(
const uint8_t* p_codec_info);
+// Adjusts the A2DP SBC 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_AdjustCodecSbc(uint8_t* p_codec_info);
+
#ifdef __cplusplus
}
#endif
const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterface(
const uint8_t* p_codec_info);
+// Adjusts the A2DP vendor-specific 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_VendorAdjustCodec(uint8_t* p_codec_info);
+
#ifdef __cplusplus
}
#endif
// Subbands: A2DP_SBC_IE_SUBBAND_8 |
// Allocation Method: A2DP_SBC_IE_ALLOC_MD_L
2, // MinimumBitpool Value: A2DP_SBC_IE_MIN_BITPOOL
- 53, // Maxium Bitpool Value: A2DP_SBC_MAX_BITPOOL
+ 53, // Maximum Bitpool Value: A2DP_SBC_MAX_BITPOOL
7, // Dummy
8, // Dummy
9 // Dummy
0x02 | 0x01, // Allocation Method: A2DP_SBC_IE_ALLOC_MD_S |
// A2DP_SBC_IE_ALLOC_MD_L
2, // MinimumBitpool Value: A2DP_SBC_IE_MIN_BITPOOL
- 250, // Maxium Bitpool Value: A2DP_SBC_IE_MAX_BITPOOL
+ 250, // Maximum Bitpool Value: A2DP_SBC_IE_MAX_BITPOOL
7, // Dummy
8, // Dummy
9 // Dummy
EXPECT_FALSE(A2DP_BuildCodecHeader(codec_info_non_a2dp, p_buf,
FRAMES_PER_PACKET));
}
+
+TEST(StackA2dpTest, test_a2dp_adjust_codec) {
+ uint8_t codec_info_sbc_test[AVDT_CODEC_SIZE];
+ uint8_t codec_info_non_a2dp_test[AVDT_CODEC_SIZE];
+
+ // Test updating a valid SBC codec that doesn't need adjustment
+ memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test));
+ memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc));
+ EXPECT_TRUE(A2DP_AdjustCodec(codec_info_sbc_test));
+ EXPECT_TRUE(memcmp(codec_info_sbc_test, codec_info_sbc,
+ sizeof(codec_info_sbc)) == 0);
+
+ // Test updating a valid SBC codec that needs adjustment
+ memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test));
+ memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc));
+ codec_info_sbc_test[6] = 54; // A2DP_SBC_MAX_BITPOOL + 1
+ EXPECT_TRUE(A2DP_AdjustCodec(codec_info_sbc_test));
+ EXPECT_TRUE(memcmp(codec_info_sbc_test, codec_info_sbc,
+ sizeof(codec_info_sbc)) == 0);
+
+ // Test updating an invalid SBC codec
+ memset(codec_info_sbc_test, 0xAB, sizeof(codec_info_sbc_test));
+ memcpy(codec_info_sbc_test, codec_info_sbc, sizeof(codec_info_sbc));
+ codec_info_sbc_test[6] = 255; // Invalid MAX_BITPOOL
+ EXPECT_FALSE(A2DP_AdjustCodec(codec_info_sbc_test));
+
+ // Test updating a non-A2DP codec that is not recognized
+ memset(codec_info_non_a2dp_test, 0xAB, sizeof(codec_info_non_a2dp_test));
+ memcpy(codec_info_non_a2dp_test, codec_info_non_a2dp,
+ sizeof(codec_info_non_a2dp));
+ EXPECT_FALSE(A2DP_AdjustCodec(codec_info_non_a2dp_test));
+}