Add A2DP_DumpCodecInfo() API
The API can be used to display A2DP codec info when using |LOG_DEBUG|.
Test: Code compilation
Bug: 64128712
Change-Id: I04379b45f24adb7008365d38ccc8aa7f49ed4b73
(cherry picked from commit 81c2234305d4c84eb38f0d5a92605e3b42366f84)
diff --git a/stack/a2dp/a2dp_aac.cc b/stack/a2dp/a2dp_aac.cc
index ce5431b..7027df7 100644
--- a/stack/a2dp/a2dp_aac.cc
+++ b/stack/a2dp/a2dp_aac.cc
@@ -529,7 +529,7 @@
return true;
}
-void A2DP_DumpCodecInfoAac(const uint8_t* p_codec_info) {
+bool A2DP_DumpCodecInfoAac(const uint8_t* p_codec_info) {
tA2DP_STATUS a2dp_status;
tA2DP_AAC_CIE aac_cie;
@@ -538,7 +538,7 @@
a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, true);
if (a2dp_status != A2DP_SUCCESS) {
LOG_ERROR(LOG_TAG, "%s: A2DP_ParseInfoAac fail:%d", __func__, a2dp_status);
- return;
+ return false;
}
LOG_DEBUG(LOG_TAG, "\tobjectType: 0x%x", aac_cie.objectType);
@@ -605,6 +605,8 @@
(aac_cie.variableBitRateSupport != 0) ? "true" : "false");
LOG_DEBUG(LOG_TAG, "\tbitRate: %u", aac_cie.bitRate);
+
+ return true;
}
const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterfaceAac(
diff --git a/stack/a2dp/a2dp_codec_config.cc b/stack/a2dp/a2dp_codec_config.cc
index d060e53..0bf5985 100644
--- a/stack/a2dp/a2dp_codec_config.cc
+++ b/stack/a2dp/a2dp_codec_config.cc
@@ -1258,3 +1258,23 @@
return false;
}
+
+bool A2DP_DumpCodecInfo(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+
+ switch (codec_type) {
+ case A2DP_MEDIA_CT_SBC:
+ return A2DP_DumpCodecInfoSbc(p_codec_info);
+ case A2DP_MEDIA_CT_AAC:
+ return A2DP_DumpCodecInfoAac(p_codec_info);
+ case A2DP_MEDIA_CT_NON_A2DP:
+ return A2DP_VendorDumpCodecInfo(p_codec_info);
+ default:
+ break;
+ }
+
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return false;
+}
diff --git a/stack/a2dp/a2dp_sbc.cc b/stack/a2dp/a2dp_sbc.cc
index f8b95e9..ce3934a 100644
--- a/stack/a2dp/a2dp_sbc.cc
+++ b/stack/a2dp/a2dp_sbc.cc
@@ -867,7 +867,7 @@
return true;
}
-void A2DP_DumpCodecInfoSbc(const uint8_t* p_codec_info) {
+bool A2DP_DumpCodecInfoSbc(const uint8_t* p_codec_info) {
tA2DP_STATUS a2dp_status;
tA2DP_SBC_CIE sbc_cie;
@@ -876,7 +876,7 @@
a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, true);
if (a2dp_status != A2DP_SUCCESS) {
LOG_ERROR(LOG_TAG, "%s: A2DP_ParseInfoSbc fail:%d", __func__, a2dp_status);
- return;
+ return false;
}
LOG_DEBUG(LOG_TAG, "\tsamp_freq: 0x%x", sbc_cie.samp_freq);
@@ -939,6 +939,8 @@
LOG_DEBUG(LOG_TAG, "\tBit pool Min:%d Max:%d", sbc_cie.min_bitpool,
sbc_cie.max_bitpool);
+
+ return true;
}
const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterfaceSbc(
diff --git a/stack/a2dp/a2dp_vendor.cc b/stack/a2dp/a2dp_vendor.cc
index 9b9eb00..f0fc277 100644
--- a/stack/a2dp/a2dp_vendor.cc
+++ b/stack/a2dp/a2dp_vendor.cc
@@ -543,3 +543,29 @@
return false;
}
+
+bool A2DP_VendorDumpCodecInfo(const uint8_t* p_codec_info) {
+ uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+
+ // Check for aptX
+ if (vendor_id == A2DP_APTX_VENDOR_ID &&
+ codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH) {
+ return A2DP_VendorDumpCodecInfoAptx(p_codec_info);
+ }
+
+ // Check for aptX-HD
+ if (vendor_id == A2DP_APTX_HD_VENDOR_ID &&
+ codec_id == A2DP_APTX_HD_CODEC_ID_BLUETOOTH) {
+ return A2DP_VendorDumpCodecInfoAptxHd(p_codec_info);
+ }
+
+ // Check for LDAC
+ if (vendor_id == A2DP_LDAC_VENDOR_ID && codec_id == A2DP_LDAC_CODEC_ID) {
+ return A2DP_VendorDumpCodecInfoLdac(p_codec_info);
+ }
+
+ // Add checks based on <vendor_id, codec_id>
+
+ return false;
+}
diff --git a/stack/a2dp/a2dp_vendor_aptx.cc b/stack/a2dp/a2dp_vendor_aptx.cc
index c624af2..9d4d0e1 100644
--- a/stack/a2dp/a2dp_vendor_aptx.cc
+++ b/stack/a2dp/a2dp_vendor_aptx.cc
@@ -332,7 +332,7 @@
return true;
}
-void A2DP_VendorDumpCodecInfoAptx(const uint8_t* p_codec_info) {
+bool A2DP_VendorDumpCodecInfoAptx(const uint8_t* p_codec_info) {
tA2DP_STATUS a2dp_status;
tA2DP_APTX_CIE aptx_cie;
@@ -341,7 +341,7 @@
a2dp_status = A2DP_ParseInfoAptx(&aptx_cie, p_codec_info, true);
if (a2dp_status != A2DP_SUCCESS) {
LOG_ERROR(LOG_TAG, "%s: A2DP_ParseInfoAptx fail:%d", __func__, a2dp_status);
- return;
+ return false;
}
LOG_DEBUG(LOG_TAG, "\tsamp_freq: 0x%x", aptx_cie.sampleRate);
@@ -359,6 +359,8 @@
if (aptx_cie.channelMode & A2DP_APTX_CHANNELS_STEREO) {
LOG_DEBUG(LOG_TAG, "\tch_mode: (Stereo)");
}
+
+ return true;
}
const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceAptx(
diff --git a/stack/a2dp/a2dp_vendor_aptx_hd.cc b/stack/a2dp/a2dp_vendor_aptx_hd.cc
index 4f1c8d2..9002729 100644
--- a/stack/a2dp/a2dp_vendor_aptx_hd.cc
+++ b/stack/a2dp/a2dp_vendor_aptx_hd.cc
@@ -348,7 +348,7 @@
return true;
}
-void A2DP_VendorDumpCodecInfoAptxHd(const uint8_t* p_codec_info) {
+bool A2DP_VendorDumpCodecInfoAptxHd(const uint8_t* p_codec_info) {
tA2DP_STATUS a2dp_status;
tA2DP_APTX_HD_CIE aptx_hd_cie;
@@ -358,7 +358,7 @@
if (a2dp_status != A2DP_SUCCESS) {
LOG_ERROR(LOG_TAG, "%s: A2DP_ParseInfoAptxHd fail:%d", __func__,
a2dp_status);
- return;
+ return false;
}
LOG_DEBUG(LOG_TAG, "\tsamp_freq: 0x%x", aptx_hd_cie.sampleRate);
@@ -376,6 +376,8 @@
if (aptx_hd_cie.channelMode & A2DP_APTX_HD_CHANNELS_STEREO) {
LOG_DEBUG(LOG_TAG, "\tch_mode: (Stereo)");
}
+
+ return true;
}
const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceAptxHd(
diff --git a/stack/a2dp/a2dp_vendor_ldac.cc b/stack/a2dp/a2dp_vendor_ldac.cc
index eace8b9..08d4362 100644
--- a/stack/a2dp/a2dp_vendor_ldac.cc
+++ b/stack/a2dp/a2dp_vendor_ldac.cc
@@ -398,7 +398,7 @@
return true;
}
-void A2DP_VendorDumpCodecInfoLdac(const uint8_t* p_codec_info) {
+bool A2DP_VendorDumpCodecInfoLdac(const uint8_t* p_codec_info) {
tA2DP_STATUS a2dp_status;
tA2DP_LDAC_CIE ldac_cie;
@@ -407,7 +407,7 @@
a2dp_status = A2DP_ParseInfoLdac(&ldac_cie, p_codec_info, true);
if (a2dp_status != A2DP_SUCCESS) {
LOG_ERROR(LOG_TAG, "%s: A2DP_ParseInfoLdac fail:%d", __func__, a2dp_status);
- return;
+ return false;
}
LOG_DEBUG(LOG_TAG, "\tsamp_freq: 0x%x", ldac_cie.sampleRate);
@@ -440,6 +440,8 @@
if (ldac_cie.channelMode & A2DP_LDAC_CHANNEL_MODE_STEREO) {
LOG_DEBUG(LOG_TAG, "\tch_mode: (Stereo)");
}
+
+ return true;
}
const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceLdac(
diff --git a/stack/include/a2dp_aac.h b/stack/include/a2dp_aac.h
index 88bb1d9..43f7965 100644
--- a/stack/include/a2dp_aac.h
+++ b/stack/include/a2dp_aac.h
@@ -195,9 +195,10 @@
bool A2DP_BuildCodecHeaderAac(const uint8_t* p_codec_info, BT_HDR* p_buf,
uint16_t frames_per_packet);
-// Decodes and displays AAC codec info (for debugging).
+// Decodes and displays A2DP AAC codec info when using |LOG_DEBUG|.
// |p_codec_info| is a pointer to the AAC codec_info to decode and display.
-void A2DP_DumpCodecInfoAac(const uint8_t* p_codec_info);
+// Returns true if the codec information is valid, otherwise false.
+bool A2DP_DumpCodecInfoAac(const uint8_t* p_codec_info);
// Gets the A2DP AAC encoder interface that can be used to encode and prepare
// A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
diff --git a/stack/include/a2dp_codec_api.h b/stack/include/a2dp_codec_api.h
index a13e4aa..cdc4721 100644
--- a/stack/include/a2dp_codec_api.h
+++ b/stack/include/a2dp_codec_api.h
@@ -643,6 +643,11 @@
bool A2DP_InitCodecConfig(btav_a2dp_codec_index_t codec_index,
tAVDT_CFG* p_cfg);
+// Decodes and displays A2DP codec info when using |LOG_DEBUG|.
+// |p_codec_info| is a pointer to the codec_info to decode and display.
+// Returns true if the codec information is valid, otherwise false.
+bool A2DP_DumpCodecInfo(const uint8_t* p_codec_info);
+
// Add enum-based flag operators to the btav_a2dp_codec_config_t fields
#ifndef DEFINE_ENUM_FLAG_OPERATORS
#define DEFINE_ENUM_FLAG_OPERATORS(bitmask) \
diff --git a/stack/include/a2dp_sbc.h b/stack/include/a2dp_sbc.h
index ea06312..a19dd20 100644
--- a/stack/include/a2dp_sbc.h
+++ b/stack/include/a2dp_sbc.h
@@ -220,9 +220,10 @@
bool A2DP_BuildCodecHeaderSbc(const uint8_t* p_codec_info, BT_HDR* p_buf,
uint16_t frames_per_packet);
-// Decodes and displays SBC codec info (for debugging).
+// Decodes and displays A2DP SBC codec info when using |LOG_DEBUG|.
// |p_codec_info| is a pointer to the SBC codec_info to decode and display.
-void A2DP_DumpCodecInfoSbc(const uint8_t* p_codec_info);
+// Returns true if the codec information is valid, otherwise false.
+bool A2DP_DumpCodecInfoSbc(const uint8_t* p_codec_info);
// Gets the A2DP SBC encoder interface that can be used to encode and prepare
// A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
diff --git a/stack/include/a2dp_vendor.h b/stack/include/a2dp_vendor.h
index ad6a52f..2b90041 100644
--- a/stack/include/a2dp_vendor.h
+++ b/stack/include/a2dp_vendor.h
@@ -195,4 +195,9 @@
bool A2DP_VendorInitCodecConfig(btav_a2dp_codec_index_t codec_index,
tAVDT_CFG* p_cfg);
+// Decodes and displays A2DP vendor codec info when using |LOG_DEBUG|.
+// |p_codec_info| is a pointer to the codec_info to decode and display.
+// Returns true if the codec information is valid, otherwise false.
+bool A2DP_VendorDumpCodecInfo(const uint8_t* p_codec_info);
+
#endif // A2DP_VENDOR_H
diff --git a/stack/include/a2dp_vendor_aptx.h b/stack/include/a2dp_vendor_aptx.h
index 1fba23a..b1bebf0 100644
--- a/stack/include/a2dp_vendor_aptx.h
+++ b/stack/include/a2dp_vendor_aptx.h
@@ -111,9 +111,10 @@
bool A2DP_VendorBuildCodecHeaderAptx(const uint8_t* p_codec_info, BT_HDR* p_buf,
uint16_t frames_per_packet);
-// Decodes and displays aptX codec info (for debugging).
+// Decodes and displays A2DP aptX codec info when using |LOG_DEBUG|.
// |p_codec_info| is a pointer to the aptX codec_info to decode and display.
-void A2DP_VendorDumpCodecInfoAptx(const uint8_t* p_codec_info);
+// Returns true if the codec information is valid, otherwise false.
+bool A2DP_VendorDumpCodecInfoAptx(const uint8_t* p_codec_info);
// Gets the A2DP aptX encoder interface that can be used to encode and prepare
// A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
diff --git a/stack/include/a2dp_vendor_aptx_hd.h b/stack/include/a2dp_vendor_aptx_hd.h
index 0250ca0..5a4a748 100644
--- a/stack/include/a2dp_vendor_aptx_hd.h
+++ b/stack/include/a2dp_vendor_aptx_hd.h
@@ -112,9 +112,10 @@
BT_HDR* p_buf,
uint16_t frames_per_packet);
-// Decodes and displays aptX-HD codec info (for debugging).
+// Decodes and displays A2DP aptX-HD codec info when using |LOG_DEBUG|.
// |p_codec_info| is a pointer to the aptX-HD codec_info to decode and display.
-void A2DP_VendorDumpCodecInfoAptxHd(const uint8_t* p_codec_info);
+// Returns true if the codec information is valid, otherwise false.
+bool A2DP_VendorDumpCodecInfoAptxHd(const uint8_t* p_codec_info);
// Gets the A2DP aptX-HD encoder interface that can be used to encode and
// prepare A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
diff --git a/stack/include/a2dp_vendor_ldac.h b/stack/include/a2dp_vendor_ldac.h
index a4dd48d..5302c07 100644
--- a/stack/include/a2dp_vendor_ldac.h
+++ b/stack/include/a2dp_vendor_ldac.h
@@ -118,9 +118,10 @@
bool A2DP_VendorBuildCodecHeaderLdac(const uint8_t* p_codec_info, BT_HDR* p_buf,
uint16_t frames_per_packet);
-// Decodes and displays LDAC codec info (for debugging).
+// Decodes and displays A2DP LDAC codec info when using |LOG_DEBUG|.
// |p_codec_info| is a pointer to the LDAC codec_info to decode and display.
-void A2DP_VendorDumpCodecInfoLdac(const uint8_t* p_codec_info);
+// Returns true if the codec information is valid, otherwise false.
+bool A2DP_VendorDumpCodecInfoLdac(const uint8_t* p_codec_info);
// Gets the A2DP LDAC encoder interface that can be used to encode and prepare
// A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.