From 219b85f136d5cc446605af9fd4220df2f9d81e82 Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Wed, 2 Aug 2017 13:43:44 -0700 Subject: [PATCH] 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) --- stack/a2dp/a2dp_aac.cc | 6 ++++-- stack/a2dp/a2dp_codec_config.cc | 20 ++++++++++++++++++++ stack/a2dp/a2dp_sbc.cc | 6 ++++-- stack/a2dp/a2dp_vendor.cc | 26 ++++++++++++++++++++++++++ stack/a2dp/a2dp_vendor_aptx.cc | 6 ++++-- stack/a2dp/a2dp_vendor_aptx_hd.cc | 6 ++++-- stack/a2dp/a2dp_vendor_ldac.cc | 6 ++++-- stack/include/a2dp_aac.h | 5 +++-- stack/include/a2dp_codec_api.h | 5 +++++ stack/include/a2dp_sbc.h | 5 +++-- stack/include/a2dp_vendor.h | 5 +++++ stack/include/a2dp_vendor_aptx.h | 5 +++-- stack/include/a2dp_vendor_aptx_hd.h | 5 +++-- stack/include/a2dp_vendor_ldac.h | 5 +++-- 14 files changed, 91 insertions(+), 20 deletions(-) diff --git a/stack/a2dp/a2dp_aac.cc b/stack/a2dp/a2dp_aac.cc index ce5431b3e..7027df7af 100644 --- a/stack/a2dp/a2dp_aac.cc +++ b/stack/a2dp/a2dp_aac.cc @@ -529,7 +529,7 @@ bool A2DP_BuildCodecHeaderAac(UNUSED_ATTR const uint8_t* p_codec_info, 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 @@ void A2DP_DumpCodecInfoAac(const uint8_t* p_codec_info) { 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 @@ void A2DP_DumpCodecInfoAac(const uint8_t* p_codec_info) { (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 d060e53c7..0bf5985b5 100644 --- a/stack/a2dp/a2dp_codec_config.cc +++ b/stack/a2dp/a2dp_codec_config.cc @@ -1258,3 +1258,23 @@ bool A2DP_InitCodecConfig(btav_a2dp_codec_index_t codec_index, 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 f8b95e915..ce3934ac3 100644 --- a/stack/a2dp/a2dp_sbc.cc +++ b/stack/a2dp/a2dp_sbc.cc @@ -867,7 +867,7 @@ bool A2DP_BuildCodecHeaderSbc(UNUSED_ATTR const uint8_t* p_codec_info, 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 @@ void A2DP_DumpCodecInfoSbc(const uint8_t* p_codec_info) { 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 @@ void A2DP_DumpCodecInfoSbc(const uint8_t* p_codec_info) { 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 9b9eb0070..f0fc2778c 100644 --- a/stack/a2dp/a2dp_vendor.cc +++ b/stack/a2dp/a2dp_vendor.cc @@ -543,3 +543,29 @@ bool A2DP_VendorInitCodecConfig(btav_a2dp_codec_index_t codec_index, 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 + + return false; +} diff --git a/stack/a2dp/a2dp_vendor_aptx.cc b/stack/a2dp/a2dp_vendor_aptx.cc index c624af2b1..9d4d0e184 100644 --- a/stack/a2dp/a2dp_vendor_aptx.cc +++ b/stack/a2dp/a2dp_vendor_aptx.cc @@ -332,7 +332,7 @@ bool A2DP_VendorBuildCodecHeaderAptx(UNUSED_ATTR const uint8_t* p_codec_info, 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 @@ void A2DP_VendorDumpCodecInfoAptx(const uint8_t* p_codec_info) { 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 @@ void A2DP_VendorDumpCodecInfoAptx(const uint8_t* p_codec_info) { 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 4f1c8d26f..90027292c 100644 --- a/stack/a2dp/a2dp_vendor_aptx_hd.cc +++ b/stack/a2dp/a2dp_vendor_aptx_hd.cc @@ -348,7 +348,7 @@ bool A2DP_VendorBuildCodecHeaderAptxHd(UNUSED_ATTR const uint8_t* p_codec_info, 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 @@ void A2DP_VendorDumpCodecInfoAptxHd(const uint8_t* p_codec_info) { 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 @@ void A2DP_VendorDumpCodecInfoAptxHd(const uint8_t* p_codec_info) { 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 eace8b949..08d436291 100644 --- a/stack/a2dp/a2dp_vendor_ldac.cc +++ b/stack/a2dp/a2dp_vendor_ldac.cc @@ -398,7 +398,7 @@ bool A2DP_VendorBuildCodecHeaderLdac(UNUSED_ATTR const uint8_t* p_codec_info, 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 @@ void A2DP_VendorDumpCodecInfoLdac(const uint8_t* p_codec_info) { 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 @@ void A2DP_VendorDumpCodecInfoLdac(const uint8_t* p_codec_info) { 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 88bb1d941..43f7965c3 100644 --- a/stack/include/a2dp_aac.h +++ b/stack/include/a2dp_aac.h @@ -195,9 +195,10 @@ bool A2DP_GetPacketTimestampAac(const uint8_t* p_codec_info, 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 a13e4aaa8..cdc4721cf 100644 --- a/stack/include/a2dp_codec_api.h +++ b/stack/include/a2dp_codec_api.h @@ -643,6 +643,11 @@ const char* A2DP_CodecIndexStr(btav_a2dp_codec_index_t codec_index); 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 ea06312e6..a19dd2062 100644 --- a/stack/include/a2dp_sbc.h +++ b/stack/include/a2dp_sbc.h @@ -220,9 +220,10 @@ bool A2DP_GetPacketTimestampSbc(const uint8_t* p_codec_info, 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 ad6a52f67..2b900419a 100644 --- a/stack/include/a2dp_vendor.h +++ b/stack/include/a2dp_vendor.h @@ -195,4 +195,9 @@ const char* A2DP_VendorCodecIndexStr(btav_a2dp_codec_index_t codec_index); 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 1fba23af8..b1bebf0a4 100644 --- a/stack/include/a2dp_vendor_aptx.h +++ b/stack/include/a2dp_vendor_aptx.h @@ -111,9 +111,10 @@ bool A2DP_VendorGetPacketTimestampAptx(const uint8_t* p_codec_info, 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 0250ca018..5a4a748b6 100644 --- a/stack/include/a2dp_vendor_aptx_hd.h +++ b/stack/include/a2dp_vendor_aptx_hd.h @@ -112,9 +112,10 @@ bool A2DP_VendorBuildCodecHeaderAptxHd(const uint8_t* p_codec_info, 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 a4dd48db3..5302c079b 100644 --- a/stack/include/a2dp_vendor_ldac.h +++ b/stack/include/a2dp_vendor_ldac.h @@ -118,9 +118,10 @@ bool A2DP_VendorGetPacketTimestampLdac(const uint8_t* p_codec_info, 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|. -- 2.11.0