diff options
author | 2024-02-07 00:21:34 +0000 | |
---|---|---|
committer | 2024-02-08 22:42:09 +0000 | |
commit | 7bf239adf5cad9a9c74f47ba0a8bc673b73d914a (patch) | |
tree | 3bbd1743d6c5604e2bf956cbedbd131683c675d2 | |
parent | f78034839ee0fc5a8df93d9171113898ddff3029 (diff) |
system/stack/a2dp: Migrate to libbluetooth_log
Test: m com.android.btservices
Bug: 305066880
Flag: EXEMPT, mechanical refactor
Change-Id: Ibddb7b9e8180fd8489b566e2c741e86dd68cf440
35 files changed, 751 insertions, 724 deletions
diff --git a/system/audio_hal_interface/Android.bp b/system/audio_hal_interface/Android.bp index 96d05bf2bc..ffa646d507 100644 --- a/system/audio_hal_interface/Android.bp +++ b/system/audio_hal_interface/Android.bp @@ -101,6 +101,7 @@ cc_test { shared_libs: [ "android.hardware.bluetooth.audio@2.0", "android.hardware.bluetooth.audio@2.1", + "libbase", "libbinder_ndk", "libcutils", "libfmq", @@ -174,6 +175,7 @@ cc_test { ], shared_libs: [ "libbase", + "libbase", "libcutils", "libfmq", "liblog", @@ -182,6 +184,7 @@ cc_test { ], static_libs: [ "bluetooth_flags_c_lib", + "libbluetooth_log", "libbt-common", "libbt_shim_bridge", "libchrome", diff --git a/system/audio_hal_interface/BUILD.gn b/system/audio_hal_interface/BUILD.gn index 93f3de5c7e..2d56ef3356 100644 --- a/system/audio_hal_interface/BUILD.gn +++ b/system/audio_hal_interface/BUILD.gn @@ -28,7 +28,10 @@ static_library("audio_hal_interface") { "//bt/system/gd/rust/shim", ] - configs += [ "//bt/system:target_defaults" ] + configs += [ + "//bt/system:target_defaults", + "//bt/system/log:log_defaults", + ] deps = [ "//bt/system/common", diff --git a/system/common/BUILD.gn b/system/common/BUILD.gn index f5afaf2699..58c3a9d40a 100644 --- a/system/common/BUILD.gn +++ b/system/common/BUILD.gn @@ -37,7 +37,10 @@ static_library("common") { "//bt/system/gd/rust/shim:init_flags_bridge_header", ] - configs += [ "//bt/system:target_defaults" ] + configs += [ + "//bt/system:target_defaults", + "//bt/system/log:log_defaults", + ] } if (use.test) { diff --git a/system/device/BUILD.gn b/system/device/BUILD.gn index 554ef3c51a..1d8c938099 100644 --- a/system/device/BUILD.gn +++ b/system/device/BUILD.gn @@ -30,6 +30,7 @@ static_library("device") { configs += [ "//bt/system:target_defaults", + "//bt/system/log:log_defaults", ] deps = [ diff --git a/system/gd/BUILD.gn b/system/gd/BUILD.gn index c59edb81e4..8b5a0d0c09 100644 --- a/system/gd/BUILD.gn +++ b/system/gd/BUILD.gn @@ -35,7 +35,10 @@ config("gd_defaults") { ] include_dirs = [ "//bt/system/gd" ] - configs = [ "//bt/system:target_defaults" ] + configs = [ + "//bt/system:target_defaults", + "//bt/system/log:log_defaults", + ] } config("rust_defaults") { diff --git a/system/gd/rust/topshim/BUILD.gn b/system/gd/rust/topshim/BUILD.gn index cde636eff0..f9c5aea3dc 100644 --- a/system/gd/rust/topshim/BUILD.gn +++ b/system/gd/rust/topshim/BUILD.gn @@ -48,7 +48,10 @@ cxxbridge_cc("btif_bridge_code") { ":btif_bridge_header", "//bt/system/pdl:BluetoothGeneratedPackets_h", ] - configs = [ "//bt/system/gd:gd_defaults" ] + configs = [ + "//bt/system/gd:gd_defaults", + "//bt/system/log:log_defaults", + ] } source_set("btif_cxx_bridge_code") { @@ -69,7 +72,10 @@ source_set("btif_cxx_bridge_code") { "//bt/system/gd/metrics:BluetoothMetricsSources", "//bt/system/pdl:BluetoothGeneratedPackets_h", ] - configs += [ "//bt/system/gd:gd_defaults" ] + configs += [ + "//bt/system/gd:gd_defaults", + "//bt/system/log:log_defaults", + ] } cxxbridge_libheader("cxxlibheader") { diff --git a/system/include/hardware/bt_av.h b/system/include/hardware/bt_av.h index b878d85e0b..15dcdbc936 100644 --- a/system/include/hardware/bt_av.h +++ b/system/include/hardware/bt_av.h @@ -17,6 +17,7 @@ #ifndef ANDROID_INCLUDE_BT_AV_H #define ANDROID_INCLUDE_BT_AV_H +#include <bluetooth/log.h> #include <hardware/bluetooth.h> #include <raw_address.h> @@ -433,4 +434,22 @@ typedef struct { __END_DECLS +namespace fmt { +template <> +struct formatter<btav_a2dp_codec_bits_per_sample_t> + : enum_formatter<btav_a2dp_codec_bits_per_sample_t> {}; +template <> +struct formatter<btav_a2dp_codec_priority_t> + : enum_formatter<btav_a2dp_codec_priority_t> {}; +template <> +struct formatter<btav_a2dp_codec_index_t> + : enum_formatter<btav_a2dp_codec_index_t> {}; +template <> +struct formatter<btav_a2dp_codec_sample_rate_t> + : enum_formatter<btav_a2dp_codec_sample_rate_t> {}; +template <> +struct formatter<btav_a2dp_codec_channel_mode_t> + : enum_formatter<btav_a2dp_codec_channel_mode_t> {}; +} // namespace fmt + #endif /* ANDROID_INCLUDE_BT_AV_H */ diff --git a/system/main/BUILD.gn b/system/main/BUILD.gn index d2e25f742c..8cc90cb93d 100644 --- a/system/main/BUILD.gn +++ b/system/main/BUILD.gn @@ -95,6 +95,7 @@ target(lib_type, "bluetooth") { configs += [ "//bt/system:target_defaults", + "//bt/system/log:log_defaults", "//bt/system:external_tinyxml2", "//bt/system:external_flatbuffers", ] diff --git a/system/main/shim/BUILD.gn b/system/main/shim/BUILD.gn index 6529f1bd94..6a452ce700 100644 --- a/system/main/shim/BUILD.gn +++ b/system/main/shim/BUILD.gn @@ -61,5 +61,8 @@ source_set("LibBluetoothShimSources") { "//bt/system/types", ] - configs += [ "//bt/system:target_defaults" ] + configs += [ + "//bt/system:target_defaults", + "//bt/system/log:log_defaults", + ] } diff --git a/system/osi/BUILD.gn b/system/osi/BUILD.gn index 1c035064ce..0fc0671670 100644 --- a/system/osi/BUILD.gn +++ b/system/osi/BUILD.gn @@ -61,6 +61,7 @@ static_library("osi") { configs += [ "//bt/system:target_defaults", + "//bt/system/log:log_defaults", ] } diff --git a/system/rust/BUILD.gn b/system/rust/BUILD.gn index 48b94a5286..202e9dff76 100644 --- a/system/rust/BUILD.gn +++ b/system/rust/BUILD.gn @@ -36,7 +36,10 @@ static_library("core_rs") { "//bt/system/types", ] - configs += [ "//bt/system:target_defaults" ] + configs += [ + "//bt/system:target_defaults", + "//bt/system/log:log_defaults", + ] deps = [ ":cxxlibheader", diff --git a/system/stack/Android.bp b/system/stack/Android.bp index 114c62a88e..ad3b95b971 100644 --- a/system/stack/Android.bp +++ b/system/stack/Android.bp @@ -682,6 +682,7 @@ cc_test { "android.hardware.bluetooth.audio@2.1", "libPlatformProperties", "libaaudio", + "libbase", "libbinder_ndk", "libcrypto", "libcutils", @@ -1204,6 +1205,7 @@ cc_test { ], static_libs: [ "libFraunhoferAAC", + "libbase", "libbluetooth-types", "libbluetooth_crypto_toolbox", "libbluetooth_gd", @@ -1260,6 +1262,7 @@ cc_test { "libcutils", ], static_libs: [ + "libbase", "libbluetooth_crypto_toolbox", "libbluetooth_log", "libbt-common", diff --git a/system/stack/BUILD.gn b/system/stack/BUILD.gn index ddf8e05032..07999bc27f 100644 --- a/system/stack/BUILD.gn +++ b/system/stack/BUILD.gn @@ -46,6 +46,7 @@ source_set("nonstandard_codecs") { configs += [ "//bt/system:target_defaults", + "//bt/system/log:log_defaults", ] } } @@ -226,6 +227,7 @@ source_set("stack") { configs += [ "//bt/system:target_defaults", + "//bt/system/log:log_defaults", ] } diff --git a/system/stack/a2dp/a2dp_aac.cc b/system/stack/a2dp/a2dp_aac.cc index 52a14f429c..05b7412aef 100644 --- a/system/stack/a2dp/a2dp_aac.cc +++ b/system/stack/a2dp/a2dp_aac.cc @@ -25,7 +25,7 @@ #include "a2dp_aac.h" -#include <base/logging.h> +#include <bluetooth/log.h> #include <string.h> #include "a2dp_aac_decoder.h" @@ -40,6 +40,8 @@ #define A2DP_AAC_DEFAULT_BITRATE 320000 // 320 kbps #define A2DP_AAC_MIN_BITRATE 64000 // 64 kbps +using namespace bluetooth; + // data type for the AAC Codec Information Element */ // NOTE: bits_per_sample is needed only for AAC encoder initialization. typedef struct { @@ -296,23 +298,22 @@ static tA2DP_STATUS A2DP_CodecInfoMatchesCapabilityAac( /* parse configuration */ status = A2DP_ParseInfoAac(&cfg_cie, p_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: parsing failed %d", __func__, status); + log::error("parsing failed {}", status); return status; } /* verify that each parameter is in range */ - LOG_VERBOSE("%s: Object Type peer: 0x%x, capability 0x%x", __func__, - cfg_cie.objectType, p_cap->objectType); - LOG_VERBOSE("%s: Sample Rate peer: %u, capability %u", __func__, - cfg_cie.sampleRate, p_cap->sampleRate); - LOG_VERBOSE("%s: Channel Mode peer: 0x%x, capability 0x%x", __func__, - cfg_cie.channelMode, p_cap->channelMode); - LOG_VERBOSE("%s: Variable Bit Rate Support peer: 0x%x, capability 0x%x", - __func__, cfg_cie.variableBitRateSupport, - p_cap->variableBitRateSupport); - LOG_VERBOSE("%s: Bit Rate peer: %u, capability %u", __func__, cfg_cie.bitRate, - p_cap->bitRate); + log::verbose("Object Type peer: 0x{:x}, capability 0x{:x}", + cfg_cie.objectType, p_cap->objectType); + log::verbose("Sample Rate peer: {}, capability {}", cfg_cie.sampleRate, + p_cap->sampleRate); + log::verbose("Channel Mode peer: 0x{:x}, capability 0x{:x}", + cfg_cie.channelMode, p_cap->channelMode); + log::verbose("Variable Bit Rate Support peer: 0x{:x}, capability 0x{:x}", + cfg_cie.variableBitRateSupport, p_cap->variableBitRateSupport); + log::verbose("Bit Rate peer: {}, capability {}", cfg_cie.bitRate, + p_cap->bitRate); /* Object Type */ if ((cfg_cie.objectType & p_cap->objectType) == 0) return A2DP_BAD_OBJ_TYPE; @@ -344,12 +345,12 @@ bool A2DP_CodecTypeEqualsAac(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoAac(&aac_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -365,12 +366,12 @@ bool A2DP_CodecEqualsAac(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoAac(&aac_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -388,7 +389,7 @@ int A2DP_GetTrackSampleRateAac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -428,7 +429,7 @@ int A2DP_GetTrackBitsPerSampleAac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -442,7 +443,7 @@ int A2DP_GetTrackChannelCountAac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -462,7 +463,7 @@ int A2DP_GetSinkTrackChannelTypeAac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -482,7 +483,7 @@ int A2DP_GetObjectTypeCodeAac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -505,7 +506,7 @@ int A2DP_GetChannelModeCodeAac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -526,7 +527,7 @@ int A2DP_GetVariableBitRateSupportAac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -547,7 +548,7 @@ int A2DP_GetBitRateAac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -560,7 +561,7 @@ int A2DP_ComputeMaxBitRateAac(const uint8_t* p_codec_info, uint16_t mtu) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAac(&aac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -797,7 +798,7 @@ bool A2dpCodecConfigAacSource::init() { // Load the encoder if (!A2DP_LoadEncoderAac()) { - LOG_ERROR("%s: cannot load the encoder", __func__); + log::error("cannot load the encoder"); return false; } @@ -1033,8 +1034,7 @@ bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, tA2DP_STATUS status = A2DP_ParseInfoAac(&peer_info_cie, p_peer_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } @@ -1171,10 +1171,10 @@ bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.sample_rate == BTAV_A2DP_CODEC_SAMPLE_RATE_NONE) { - LOG_ERROR( - "%s: cannot match sample frequency: source caps = 0x%x " - "peer info = 0x%x", - __func__, p_a2dp_aac_caps->sampleRate, peer_info_cie.sampleRate); + log::error( + "cannot match sample frequency: source caps = 0x{:x} peer info = " + "0x{:x}", + p_a2dp_aac_caps->sampleRate, peer_info_cie.sampleRate); goto fail; } @@ -1246,10 +1246,10 @@ bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.bits_per_sample == BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE) { - LOG_ERROR( - "%s: cannot match bits per sample: default = 0x%x " - "user preference = 0x%x", - __func__, a2dp_aac_default_config.bits_per_sample, + log::error( + "cannot match bits per sample: default = 0x{:x} user preference = " + "0x{:x}", + a2dp_aac_default_config.bits_per_sample, codec_user_config_.bits_per_sample); goto fail; } @@ -1321,10 +1321,9 @@ bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.channel_mode == BTAV_A2DP_CODEC_CHANNEL_MODE_NONE) { - LOG_ERROR( - "%s: cannot match channel mode: source caps = 0x%x " - "peer info = 0x%x", - __func__, p_a2dp_aac_caps->channelMode, peer_info_cie.channelMode); + log::error( + "cannot match channel mode: source caps = 0x{:x} peer info = 0x{:x}", + p_a2dp_aac_caps->channelMode, peer_info_cie.channelMode); goto fail; } @@ -1425,8 +1424,7 @@ bool A2dpCodecConfigAacBase::setPeerCodecCapabilities( tA2DP_STATUS status = A2DP_ParseInfoAac(&peer_info_cie, p_peer_codec_capabilities, true); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } @@ -1501,7 +1499,7 @@ bool A2dpCodecConfigAacSink::init() { // Load the decoder if (!A2DP_LoadDecoderAac()) { - LOG_ERROR("%s: cannot load the decoder", __func__); + log::error("cannot load the decoder"); return false; } diff --git a/system/stack/a2dp/a2dp_aac_decoder.cc b/system/stack/a2dp/a2dp_aac_decoder.cc index 639512b0c1..b45bdce8e4 100644 --- a/system/stack/a2dp/a2dp_aac_decoder.cc +++ b/system/stack/a2dp/a2dp_aac_decoder.cc @@ -19,7 +19,7 @@ #include "a2dp_aac_decoder.h" #include <aacdecoder_lib.h> -#include <base/logging.h> +#include <bluetooth/log.h> #include "os/log.h" #include "osi/include/allocator.h" @@ -27,6 +27,8 @@ #define DECODE_BUF_LEN (8 * 2 * 1024) +using namespace bluetooth; + typedef struct { HANDLE_AACDECODER aac_handle; bool has_aac_handle; // True if aac_handle is valid @@ -70,8 +72,7 @@ bool a2dp_aac_decoder_decode_packet(BT_HDR* p_buf) { AAC_DECODER_ERROR err = aacDecoder_Fill(a2dp_aac_decoder_cb.aac_handle, &pBuffer, &bufferSize, &bytesValid); if (err != AAC_DEC_OK) { - LOG_ERROR("%s: aacDecoder_Fill failed: 0x%x", __func__, - static_cast<unsigned>(err)); + log::error("aacDecoder_Fill failed: 0x{:x}", static_cast<unsigned>(err)); return false; } @@ -83,15 +84,15 @@ bool a2dp_aac_decoder_decode_packet(BT_HDR* p_buf) { break; } if (err != AAC_DEC_OK) { - LOG_ERROR("%s: aacDecoder_DecodeFrame failed: 0x%x", __func__, - static_cast<int>(err)); + log::error("aacDecoder_DecodeFrame failed: 0x{:x}", + static_cast<int>(err)); break; } CStreamInfo* info = aacDecoder_GetStreamInfo(a2dp_aac_decoder_cb.aac_handle); if (!info || info->sampleRate <= 0) { - LOG_ERROR("%s: Invalid stream info", __func__); + log::error("Invalid stream info"); break; } diff --git a/system/stack/a2dp/a2dp_aac_encoder.cc b/system/stack/a2dp/a2dp_aac_encoder.cc index 42311704c6..7cee859064 100644 --- a/system/stack/a2dp/a2dp_aac_encoder.cc +++ b/system/stack/a2dp/a2dp_aac_encoder.cc @@ -19,7 +19,7 @@ #include "a2dp_aac_encoder.h" #include <aacenc_lib.h> -#include <base/logging.h> +#include <bluetooth/log.h> #include <inttypes.h> #include <stdio.h> #include <string.h> @@ -42,6 +42,13 @@ // offset #define A2DP_AAC_OFFSET AVDT_MEDIA_OFFSET +using namespace bluetooth; + +namespace fmt { +template <> +struct formatter<AACENC_ERROR> : enum_formatter<AACENC_ERROR> {}; +} // namespace fmt + typedef struct { uint32_t sample_rate; uint8_t channel_mode; @@ -163,18 +170,15 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, AACENC_ERROR aac_error = aacEncOpen(&a2dp_aac_encoder_cb.aac_handle, 0, 2 /* max 2 channels: stereo */); if (aac_error != AACENC_OK) { - LOG_ERROR("%s: Cannot open AAC encoder handle: AAC error 0x%x", __func__, - aac_error); + log::error("Cannot open AAC encoder handle: AAC error 0x{:x}", aac_error); return; // TODO: Return an error? } a2dp_aac_encoder_cb.has_aac_handle = true; } if (!a2dp_codec_config->copyOutOtaCodecConfig(codec_info)) { - LOG_ERROR( - "%s: Cannot update the codec encoder for %s: " - "invalid codec config", - __func__, a2dp_codec_config->name().c_str()); + log::error("Cannot update the codec encoder for {}: invalid codec config", + a2dp_codec_config->name().c_str()); return; } const uint8_t* p_codec_info = codec_info; @@ -185,9 +189,9 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, p_feeding_params->bits_per_sample = a2dp_codec_config->getAudioBitsPerSample(); p_feeding_params->channel_count = A2DP_GetTrackChannelCountAac(p_codec_info); - LOG_INFO("%s: sample_rate=%u bits_per_sample=%u channel_count=%u", __func__, - p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, - p_feeding_params->channel_count); + log::info("sample_rate={} bits_per_sample={} channel_count={}", + p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, + p_feeding_params->channel_count); // The codec parameters p_encoder_params->sample_rate = @@ -197,10 +201,10 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, const tA2DP_ENCODER_INIT_PEER_PARAMS& peer_params = a2dp_aac_encoder_cb.peer_params; a2dp_aac_encoder_cb.TxAaMtuSize = adjust_effective_mtu(peer_params); - LOG_INFO("%s: MTU=%d, peer_mtu=%d", __func__, a2dp_aac_encoder_cb.TxAaMtuSize, - peer_params.peer_mtu); - LOG_INFO("%s: sample_rate: %d channel_mode: %d ", __func__, - p_encoder_params->sample_rate, p_encoder_params->channel_mode); + log::info("MTU={}, peer_mtu={}", a2dp_aac_encoder_cb.TxAaMtuSize, + peer_params.peer_mtu); + log::info("sample_rate: {} channel_mode: {} ", p_encoder_params->sample_rate, + p_encoder_params->channel_mode); // Set the encoder's parameters: Audio Object Type - MANDATORY // A2DP_AAC_OBJECT_TYPE_MPEG2_LC -> AOT_AAC_LC @@ -223,19 +227,15 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_param_value = AOT_AAC_SCAL; break; default: - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_AOT: " - "invalid object type %d", - __func__, object_type); + log::error("Cannot set AAC parameter AACENC_AOT: invalid object type {}", + object_type); return; // TODO: Return an error? } aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_AOT, aac_param_value); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_AOT to %d: " - "AAC error 0x%x", - __func__, aac_param_value, aac_error); + log::error("Cannot set AAC parameter AACENC_AOT to {}: AAC error 0x{:x}", + aac_param_value, aac_error); return; // TODO: Return an error? } @@ -244,10 +244,9 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_AUDIOMUXVER, aac_param_value); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_AUDIOMUXVER to %d: " - "AAC error 0x%x", - __func__, aac_param_value, aac_error); + log::error( + "Cannot set AAC parameter AACENC_AUDIOMUXVER to {}: AAC error 0x{:x}", + aac_param_value, aac_error); return; // TODO: Return an error? } @@ -256,10 +255,10 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_SIGNALING_MODE, aac_param_value); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_SIGNALING_MODE to %d: " - "AAC error 0x%x", - __func__, aac_param_value, aac_error); + log::error( + "Cannot set AAC parameter AACENC_SIGNALING_MODE to {}: AAC error " + "0x{:x}", + aac_param_value, aac_error); return; // TODO: Return an error? } @@ -268,10 +267,9 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_SAMPLERATE, aac_param_value); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_SAMPLERATE to %d: " - "AAC error 0x%x", - __func__, aac_param_value, aac_error); + log::error( + "Cannot set AAC parameter AACENC_SAMPLERATE to {}: AAC error 0x{:x}", + aac_param_value, aac_error); return; // TODO: Return an error? } aac_sampling_freq = aac_param_value; // Save for extra usage below @@ -282,22 +280,20 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_peak_bit_rate = A2DP_ComputeMaxBitRateAac(p_codec_info, a2dp_aac_encoder_cb.TxAaMtuSize); aac_param_value = std::min(aac_param_value, aac_peak_bit_rate); - LOG_INFO("%s: MTU = %d Sampling Frequency = %d Bit Rate = %d", __func__, - a2dp_aac_encoder_cb.TxAaMtuSize, aac_sampling_freq, aac_param_value); + log::info("MTU = {} Sampling Frequency = {} Bit Rate = {}", + a2dp_aac_encoder_cb.TxAaMtuSize, aac_sampling_freq, + aac_param_value); if (aac_param_value == -1) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_BITRATE: " - "invalid codec bit rate", - __func__); + log::error( + "Cannot set AAC parameter AACENC_BITRATE: invalid codec bit rate"); return; // TODO: Return an error? } aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_BITRATE, aac_param_value); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_BITRATE to %d: " - "AAC error 0x%x", - __func__, aac_param_value, aac_error); + log::error( + "Cannot set AAC parameter AACENC_BITRATE to {}: AAC error 0x{:x}", + aac_param_value, aac_error); return; // TODO: Return an error? } @@ -305,10 +301,9 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_PEAK_BITRATE, aac_peak_bit_rate); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_PEAK_BITRATE to %d: " - "AAC error 0x%x", - __func__, aac_peak_bit_rate, aac_error); + log::error( + "Cannot set AAC parameter AACENC_PEAK_BITRATE to {}: AAC error 0x{:x}", + aac_peak_bit_rate, aac_error); return; // TODO: Return an error? } @@ -321,10 +316,9 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_CHANNELMODE, aac_param_value); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_CHANNELMODE to %d: " - "AAC error 0x%x", - __func__, aac_param_value, aac_error); + log::error( + "Cannot set AAC parameter AACENC_CHANNELMODE to {}: AAC error 0x{:x}", + aac_param_value, aac_error); return; // TODO: Return an error? } @@ -333,10 +327,9 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_TRANSMUX, aac_param_value); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_TRANSMUX to %d: " - "AAC error 0x%x", - __func__, aac_param_value, aac_error); + log::error( + "Cannot set AAC parameter AACENC_TRANSMUX to {}: AAC error 0x{:x}", + aac_param_value, aac_error); return; // TODO: Return an error? } @@ -345,20 +338,18 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_HEADER_PERIOD, aac_param_value); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_HEADER_PERIOD to %d: " - "AAC error 0x%x", - __func__, aac_param_value, aac_error); + log::error( + "Cannot set AAC parameter AACENC_HEADER_PERIOD to {}: AAC error 0x{:x}", + aac_param_value, aac_error); return; // TODO: Return an error? } // Set the encoder's parameters: Variable Bit Rate Support aac_param_value = A2DP_GetVariableBitRateSupportAac(p_codec_info); if (aac_param_value == -1) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_BITRATEMODE: " - "invalid codec bit rate mode", - __func__); + log::error( + "Cannot set AAC parameter AACENC_BITRATEMODE: invalid codec bit rate " + "mode"); return; // TODO: Return an error? } else if (aac_param_value == A2DP_AAC_VARIABLE_BIT_RATE_ENABLED) { // VBR has 5 modes defined in external/aac/libAACenc/src/aacenc.h @@ -382,14 +373,13 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_param_value = static_cast<uint8_t>(bitrate_mode) & ~A2DP_AAC_VARIABLE_BIT_RATE_MASK; } - LOG_INFO("%s: AACENC_BITRATEMODE: %d", __func__, aac_param_value); + log::info("AACENC_BITRATEMODE: {}", aac_param_value); aac_error = aacEncoder_SetParam(a2dp_aac_encoder_cb.aac_handle, AACENC_BITRATEMODE, aac_param_value); if (aac_error != AACENC_OK) { - LOG_ERROR( - "%s: Cannot set AAC parameter AACENC_BITRATEMODE to %d: " - "AAC error 0x%x", - __func__, aac_param_value, aac_error); + log::error( + "Cannot set AAC parameter AACENC_BITRATEMODE to {}: AAC error 0x{:x}", + aac_param_value, aac_error); return; // TODO: Return an error? } @@ -397,8 +387,8 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, aac_error = aacEncEncode(a2dp_aac_encoder_cb.aac_handle, NULL, NULL, NULL, NULL); if (aac_error != AACENC_OK) { - LOG_ERROR("%s: Cannot complete setting the AAC parameters: AAC error 0x%x", - __func__, aac_error); + log::error("Cannot complete setting the AAC parameters: AAC error 0x{:x}", + aac_error); return; // TODO: Return an error? } @@ -406,18 +396,17 @@ static void a2dp_aac_encoder_update(A2dpCodecConfig* a2dp_codec_config, AACENC_InfoStruct aac_info; aac_error = aacEncInfo(a2dp_aac_encoder_cb.aac_handle, &aac_info); if (aac_error != AACENC_OK) { - LOG_ERROR("%s: Cannot retrieve the AAC encoder info: AAC error 0x%x", - __func__, aac_error); + log::error("Cannot retrieve the AAC encoder info: AAC error 0x{:x}", + aac_error); return; // TODO: Return an error? } p_encoder_params->frame_length = aac_info.frameLength; p_encoder_params->input_channels_n = aac_info.inputChannels; p_encoder_params->max_encoded_buffer_bytes = aac_info.maxOutBufBytes; - LOG_INFO( - "%s: AAC frame_length = %u input_channels_n = %u " - "max_encoded_buffer_bytes = %d", - __func__, p_encoder_params->frame_length, - p_encoder_params->input_channels_n, + log::info( + "AAC frame_length = {} input_channels_n = {} max_encoded_buffer_bytes = " + "{}", + p_encoder_params->frame_length, p_encoder_params->input_channels_n, p_encoder_params->max_encoded_buffer_bytes); // After encoder params ready, reset the feeding state and its interval. @@ -434,7 +423,7 @@ void a2dp_aac_feeding_reset(void) { auto frame_length = a2dp_aac_encoder_cb.aac_encoder_params.frame_length; auto sample_rate = a2dp_aac_encoder_cb.feeding_params.sample_rate; if (frame_length == 0 || sample_rate == 0) { - LOG_WARN("%s: AAC encoder is not configured", __func__); + log::warn("AAC encoder is not configured"); a2dp_aac_encoder_interval_ms = A2DP_AAC_ENCODER_INTERVAL_MS; } else { // PCM data size per AAC frame (bits) @@ -459,9 +448,9 @@ void a2dp_aac_feeding_reset(void) { a2dp_aac_encoder_interval_ms) / 1000; - LOG_INFO("%s: PCM bytes %u per tick %u ms", __func__, - a2dp_aac_encoder_cb.aac_feeding_state.bytes_per_tick, - a2dp_aac_encoder_interval_ms); + log::info("PCM bytes {} per tick {} ms", + a2dp_aac_encoder_cb.aac_feeding_state.bytes_per_tick, + a2dp_aac_encoder_interval_ms); } void a2dp_aac_feeding_flush(void) { @@ -481,8 +470,8 @@ void a2dp_aac_send_frames(uint64_t timestamp_us) { uint8_t nb_iterations = 0; a2dp_aac_get_num_frame_iteration(&nb_iterations, &nb_frame, timestamp_us); - LOG_VERBOSE("%s: Sending %d frames per iteration, %d iterations", __func__, - nb_frame, nb_iterations); + log::verbose("Sending {} frames per iteration, {} iterations", nb_frame, + nb_iterations); if (nb_frame == 0) return; for (uint8_t counter = 0; counter < nb_iterations; counter++) { @@ -505,7 +494,7 @@ static void a2dp_aac_get_num_frame_iteration(uint8_t* num_of_iterations, a2dp_aac_encoder_cb.aac_encoder_params.frame_length * a2dp_aac_encoder_cb.feeding_params.channel_count * a2dp_aac_encoder_cb.feeding_params.bits_per_sample / 8; - LOG_VERBOSE("%s: pcm_bytes_per_frame %u", __func__, pcm_bytes_per_frame); + log::verbose("pcm_bytes_per_frame {}", pcm_bytes_per_frame); uint32_t us_this_tick = a2dp_aac_encoder_interval_ms * 1000; uint64_t now_us = timestamp_us; @@ -522,8 +511,7 @@ static void a2dp_aac_get_num_frame_iteration(uint8_t* num_of_iterations, a2dp_aac_encoder_cb.aac_feeding_state.counter -= result * pcm_bytes_per_frame; nof = result; - LOG_VERBOSE("%s: effective num of frames %u, iterations %u", __func__, nof, - noi); + log::verbose("effective num of frames {}, iterations {}", nof, noi); *num_of_frames = nof; *num_of_iterations = noi; @@ -595,7 +583,7 @@ static void a2dp_aac_encode_frames(uint8_t nb_frame) { if (a2dp_aac_read_feeding(read_buffer, &bytes_read)) { uint8_t* packet = (uint8_t*)(p_buf + 1) + p_buf->offset + p_buf->len; if (!a2dp_aac_encoder_cb.has_aac_handle) { - LOG_ERROR("%s: invalid AAC handle", __func__); + log::error("invalid AAC handle"); a2dp_aac_encoder_cb.stats.media_read_total_dropped_packets++; osi_free(p_buf); return; @@ -606,7 +594,7 @@ static void a2dp_aac_encode_frames(uint8_t nb_frame) { aacEncEncode(a2dp_aac_encoder_cb.aac_handle, &in_buf_desc, &out_buf_desc, &aac_in_args, &aac_out_args); if (aac_error != AACENC_OK) { - LOG_ERROR("%s: AAC encoding error: 0x%x", __func__, aac_error); + log::error("AAC encoding error: 0x{:x}", aac_error); a2dp_aac_encoder_cb.stats.media_read_total_dropped_packets++; osi_free(p_buf); return; @@ -617,7 +605,7 @@ static void a2dp_aac_encode_frames(uint8_t nb_frame) { nb_frame--; p_buf->layer_specific++; // added a frame to the buffer } else { - LOG_WARN("%s: underflow %d", __func__, nb_frame); + log::warn("underflow {}", nb_frame); a2dp_aac_encoder_cb.aac_feeding_state.counter += nb_frame * p_encoder_params->frame_length * p_feeding_params->channel_count * @@ -687,16 +675,15 @@ static uint16_t adjust_effective_mtu( if (mtu_size > peer_params.peer_mtu) { mtu_size = peer_params.peer_mtu; } - LOG_VERBOSE("%s: original AVDTP MTU size: %d", __func__, mtu_size); + log::verbose("original AVDTP MTU size: {}", mtu_size); if (peer_params.is_peer_edr && !peer_params.peer_supports_3mbps) { // This condition would be satisfied only if the remote device is // EDR and supports only 2 Mbps, but the effective AVDTP MTU size // exceeds the 2DH5 packet size. - LOG_VERBOSE("%s: The remote device is EDR but does not support 3 Mbps", - __func__); + log::verbose("The remote device is EDR but does not support 3 Mbps"); if (mtu_size > MAX_2MBPS_AVDTP_MTU) { - LOG_WARN("%s: Restricting AVDTP MTU size from %d to %d", __func__, - mtu_size, MAX_2MBPS_AVDTP_MTU); + log::warn("Restricting AVDTP MTU size from {} to {}", mtu_size, + MAX_2MBPS_AVDTP_MTU); mtu_size = MAX_2MBPS_AVDTP_MTU; } } diff --git a/system/stack/a2dp/a2dp_aac_encoder_linux.cc b/system/stack/a2dp/a2dp_aac_encoder_linux.cc index 7c6183072a..f374bcf18d 100644 --- a/system/stack/a2dp/a2dp_aac_encoder_linux.cc +++ b/system/stack/a2dp/a2dp_aac_encoder_linux.cc @@ -16,6 +16,7 @@ #define LOG_TAG "a2dp_aac_encoder" +#include <bluetooth/log.h> #include <inttypes.h> #include <stdio.h> #include <string.h> @@ -29,7 +30,6 @@ #include "internal_include/bt_target.h" #include "mmc/codec_client/codec_client.h" #include "mmc/proto/mmc_config.pb.h" -#include "os/log.h" #include "os/rand.h" #include "osi/include/allocator.h" #include "stack/include/bt_hdr.h" @@ -63,8 +63,7 @@ class FFmpegInterface { int rc = client->init(config); if (rc < 0) { - LOG_ERROR("%s: Init failed with error message, %s", __func__, - strerror(-rc)); + log::error("Init failed with error message, {}", strerror(-rc)); } return rc; } @@ -81,20 +80,19 @@ class FFmpegInterface { // Otherwise returns the length of the encoded frame stored in `o_buf`. int encode_pcm(uint8_t* i_buf, int i_len, uint8_t* o_buf, int o_len) { if (i_buf == nullptr || o_buf == nullptr) { - LOG_ERROR("%s: Buffer is null", __func__); + log::error("Buffer is null"); return -EINVAL; } if (!client) { - LOG_ERROR("%s: CodecClient does not init", __func__); + log::error("CodecClient does not init"); return -ENOENT; } int rc = client->transcode(i_buf, i_len, o_buf, o_len); if (rc < 0) { - LOG_ERROR("%s: Encode failed with error message, %s", __func__, - strerror(-rc)); + log::error("Encode failed with error message, {}", strerror(-rc)); } return rc; } @@ -158,10 +156,8 @@ void a2dp_aac_encoder_init(const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params, a2dp_source_enqueue_callback_t enqueue_callback) { uint8_t codec_info[AVDT_CODEC_SIZE]; if (!a2dp_codec_config->copyOutOtaCodecConfig(codec_info)) { - LOG_ERROR( - "%s: Cannot update the codec encoder for %s: " - "invalid codec config", - __func__, a2dp_codec_config->name().c_str()); + log::error("Cannot update the codec encoder for {}: invalid codec config", + a2dp_codec_config->name().c_str()); return; } @@ -181,8 +177,7 @@ void a2dp_aac_encoder_init(const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params, sample_rate, channel_count, bit_rate, bits_per_sample, mtu); if (pcm_samples_per_frame < 0) { - LOG_ERROR("%s: Failed to prepare context: %d", __func__, - pcm_samples_per_frame); + log::error("Failed to prepare context: {}", pcm_samples_per_frame); codec_intf.clear_context(); return; // TODO(b/294165759): need to return an error } @@ -225,7 +220,7 @@ void a2dp_aac_feeding_reset() { auto frame_length = a2dp_aac_encoder_cb.pcm_samples_per_frame; auto sample_rate = a2dp_aac_encoder_cb.feeding_params.sample_rate; if (sample_rate == 0) { - LOG_WARN("%s: Sample rate is not configured", __func__); + log::warn("Sample rate is not configured"); return; } @@ -239,9 +234,9 @@ void a2dp_aac_feeding_reset() { 1000, }; - LOG_WARN("%s: PCM bytes %d per tick (%dms)", __func__, - a2dp_aac_encoder_cb.aac_feeding_state.bytes_per_tick, - a2dp_aac_encoder_cb.encoder_interval_ms); + log::warn("PCM bytes {} per tick ({}ms)", + a2dp_aac_encoder_cb.aac_feeding_state.bytes_per_tick, + a2dp_aac_encoder_cb.encoder_interval_ms); } void a2dp_aac_feeding_flush() { @@ -282,7 +277,7 @@ static void a2dp_aac_get_num_frame_iteration(uint8_t* num_of_iterations, a2dp_aac_encoder_cb.pcm_samples_per_frame * a2dp_aac_encoder_cb.feeding_params.channel_count * a2dp_aac_encoder_cb.feeding_params.bits_per_sample / 8; - LOG_VERBOSE("%s: pcm_bytes_per_frame %u", __func__, pcm_bytes_per_frame); + log::verbose("pcm_bytes_per_frame {}", pcm_bytes_per_frame); uint32_t us_this_tick = a2dp_aac_encoder_cb.encoder_interval_ms * 1000; uint64_t now_us = timestamp_us; @@ -299,8 +294,7 @@ static void a2dp_aac_get_num_frame_iteration(uint8_t* num_of_iterations, a2dp_aac_encoder_cb.aac_feeding_state.counter -= result * pcm_bytes_per_frame; nof = result; - LOG_VERBOSE("%s: effective num of frames %u, iterations %u", __func__, nof, - noi); + log::verbose("effective num of frames {}, iterations {}", nof, noi); *num_of_frames = nof; *num_of_iterations = noi; @@ -319,7 +313,7 @@ static void a2dp_aac_encode_frames(uint8_t nb_frame) { uint32_t bytes_read = 0; if (!a2dp_aac_read_feeding(read_buffer, &bytes_read)) { - LOG_WARN("%s: Underflow %u", __func__, nb_frame); + log::warn("Underflow {}", nb_frame); a2dp_aac_encoder_cb.aac_feeding_state.counter += nb_frame * a2dp_aac_encoder_cb.pcm_samples_per_frame * a2dp_aac_encoder_cb.feeding_params.channel_count * @@ -343,7 +337,7 @@ static void a2dp_aac_encode_frames(uint8_t nb_frame) { } if (written == 0) { - LOG_INFO("%s: Dropped a frame, likely due to buffering", __func__); + log::info("Dropped a frame, likely due to buffering"); a2dp_aac_encoder_cb.stats.media_read_total_dropped_packets++; osi_free(p_buf); continue; @@ -396,16 +390,15 @@ static uint16_t adjust_effective_mtu( if (mtu_size > peer_params.peer_mtu) { mtu_size = peer_params.peer_mtu; } - LOG_VERBOSE("%s: original AVDTP MTU size: %d", __func__, mtu_size); + log::verbose("original AVDTP MTU size: {}", mtu_size); if (peer_params.is_peer_edr && !peer_params.peer_supports_3mbps) { // This condition would be satisfied only if the remote device is // EDR and supports only 2 Mbps, but the effective AVDTP MTU size // exceeds the 2DH5 packet size. - LOG_VERBOSE("%s: The remote device is EDR but does not support 3 Mbps", - __func__); + log::verbose("The remote device is EDR but does not support 3 Mbps"); if (mtu_size > MAX_2MBPS_AVDTP_MTU) { - LOG_WARN("%s: Restricting AVDTP MTU size from %d to %d", __func__, - mtu_size, MAX_2MBPS_AVDTP_MTU); + log::warn("Restricting AVDTP MTU size from {} to {}", mtu_size, + MAX_2MBPS_AVDTP_MTU); mtu_size = MAX_2MBPS_AVDTP_MTU; } } diff --git a/system/stack/a2dp/a2dp_api.cc b/system/stack/a2dp/a2dp_api.cc index 13bda9fded..bdee82b255 100644 --- a/system/stack/a2dp/a2dp_api.cc +++ b/system/stack/a2dp/a2dp_api.cc @@ -26,12 +26,12 @@ #include "a2dp_api.h" +#include <bluetooth/log.h> #include <string.h> #include "a2dp_int.h" #include "avdt_api.h" #include "internal_include/bt_target.h" -#include "os/log.h" #include "osi/include/allocator.h" #include "osi/include/osi.h" // UNUSED_ATTR #include "sdpdefs.h" @@ -41,6 +41,7 @@ #include "types/bluetooth/uuid.h" #include "types/raw_address.h" +using namespace bluetooth; using namespace bluetooth::legacy::stack::sdp; using bluetooth::Uuid; @@ -79,7 +80,7 @@ static void a2dp_sdp_cback(UNUSED_ATTR const RawAddress& bd_addr, tSDP_PROTOCOL_ELEM elem; RawAddress peer_address = RawAddress::kEmpty; - LOG_INFO("%s: status: %d", __func__, status); + log::info("status: {}", status); if (status == SDP_SUCCESS) { /* loop through all records we found */ @@ -99,10 +100,10 @@ static void a2dp_sdp_cback(UNUSED_ATTR const RawAddress& bd_addr, a2dp_svc.p_service_name = (char*)p_attr->attr_value.v.array; a2dp_svc.service_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type); } else { - LOG_ERROR("ATTR_ID_SERVICE_NAME attr type not STR!!"); + log::error("ATTR_ID_SERVICE_NAME attr type not STR!!"); } } else { - LOG_ERROR("ATTR_ID_SERVICE_NAME attr not found!!"); + log::error("ATTR_ID_SERVICE_NAME attr not found!!"); } /* get provider name */ @@ -112,10 +113,10 @@ static void a2dp_sdp_cback(UNUSED_ATTR const RawAddress& bd_addr, a2dp_svc.p_provider_name = (char*)p_attr->attr_value.v.array; a2dp_svc.provider_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type); } else { - LOG_ERROR("ATTR_ID_PROVIDER_NAME attr type not STR!!"); + log::error("ATTR_ID_PROVIDER_NAME attr type not STR!!"); } } else { - LOG_ERROR("ATTR_ID_PROVIDER_NAME attr not found!!"); + log::error("ATTR_ID_PROVIDER_NAME attr not found!!"); } /* get supported features */ @@ -125,17 +126,17 @@ static void a2dp_sdp_cback(UNUSED_ATTR const RawAddress& bd_addr, SDP_DISC_ATTR_LEN(p_attr->attr_len_type) >= 2) { a2dp_svc.features = p_attr->attr_value.v.u16; } else { - LOG_ERROR("ATTR_ID_SUPPORTED_FEATURES attr type not STR!!"); + log::error("ATTR_ID_SUPPORTED_FEATURES attr type not STR!!"); } } else { - LOG_ERROR("ATTR_ID_SUPPORTED_FEATURES attr not found!!"); + log::error("ATTR_ID_SUPPORTED_FEATURES attr not found!!"); } /* get AVDTP version */ if (get_legacy_stack_sdp_api()->record.SDP_FindProtocolListElemInRec( p_rec, UUID_PROTOCOL_AVDTP, &elem)) { a2dp_svc.avdt_version = elem.params[0]; - LOG_VERBOSE("avdt_version: 0x%x", a2dp_svc.avdt_version); + log::verbose("avdt_version: 0x{:x}", a2dp_svc.avdt_version); } /* we've got everything, we're done */ @@ -208,7 +209,7 @@ tA2DP_STATUS A2DP_AddRecord(uint16_t service_uuid, char* p_service_name, uint8_t* p; tSDP_PROTOCOL_ELEM proto_list[A2DP_NUM_PROTO_ELEMS]; - LOG_VERBOSE("%s: uuid: 0x%x", __func__, service_uuid); + log::verbose("uuid: 0x{:x}", service_uuid); if ((sdp_handle == 0) || (service_uuid != UUID_SERVCLASS_AUDIO_SOURCE && service_uuid != UUID_SERVCLASS_AUDIO_SINK)) @@ -308,16 +309,17 @@ tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, const RawAddress& bd_addr, if ((service_uuid != UUID_SERVCLASS_AUDIO_SOURCE && service_uuid != UUID_SERVCLASS_AUDIO_SINK) || p_db == NULL || p_cback == NULL) { - LOG_ERROR("Cannot find service for peer %s UUID 0x%04x: invalid parameters", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); + log::error( + "Cannot find service for peer {} UUID 0x{:04x}: invalid parameters", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); return A2DP_INVALID_PARAMS; } if (a2dp_cb.find.service_uuid == UUID_SERVCLASS_AUDIO_SOURCE || a2dp_cb.find.service_uuid == UUID_SERVCLASS_AUDIO_SINK || a2dp_cb.find.p_db != NULL) { - LOG_ERROR("Cannot find service for peer %s UUID 0x%04x: busy", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); + log::error("Cannot find service for peer {} UUID 0x{:04x}: busy", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); return A2DP_BUSY; } @@ -333,8 +335,8 @@ tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, const RawAddress& bd_addr, a2dp_cb.find.p_db, p_db->db_len, 1, &uuid_list, p_db->num_attr, p_db->p_attrs)) { osi_free_and_reset((void**)&a2dp_cb.find.p_db); - LOG_ERROR("Unable to initialize SDP discovery for peer %s UUID 0x%04X", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); + log::error("Unable to initialize SDP discovery for peer {} UUID 0x{:04X}", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); return A2DP_FAIL; } @@ -348,12 +350,13 @@ tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, const RawAddress& bd_addr, a2dp_cb.find.service_uuid = 0; a2dp_cb.find.p_cback = NULL; osi_free_and_reset((void**)&a2dp_cb.find.p_db); - LOG_ERROR("Cannot find service for peer %s UUID 0x%04x: SDP error", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); + log::error("Cannot find service for peer {} UUID 0x{:04x}: SDP error", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); return A2DP_FAIL; } - LOG_INFO("A2DP service discovery for peer %s UUID 0x%04x: SDP search started", - ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); + log::info( + "A2DP service discovery for peer {} UUID 0x{:04x}: SDP search started", + ADDRESS_TO_LOGGABLE_CSTR(bd_addr), service_uuid); return A2DP_SUCCESS; } diff --git a/system/stack/a2dp/a2dp_codec_config.cc b/system/stack/a2dp/a2dp_codec_config.cc index 3772c4b80b..da537fbe33 100644 --- a/system/stack/a2dp/a2dp_codec_config.cc +++ b/system/stack/a2dp/a2dp_codec_config.cc @@ -20,7 +20,7 @@ #define LOG_TAG "a2dp_codec" -#include <base/logging.h> +#include <bluetooth/log.h> #include "a2dp_aac.h" #include "a2dp_codec_api.h" @@ -40,7 +40,6 @@ #include "bta/av/bta_av_int.h" #include "device/include/device_iot_config.h" #include "internal_include/bt_trace.h" -#include "os/log.h" #include "osi/include/properties.h" #include "stack/include/bt_hdr.h" @@ -52,6 +51,8 @@ // |codec_index| and |codec_priority| are the codec type and priority to use // for the initialization. +using namespace bluetooth; + static void init_btav_a2dp_codec_config( btav_a2dp_codec_config_t* codec_config, btav_a2dp_codec_index_t codec_index, btav_a2dp_codec_priority_t codec_priority) { @@ -113,7 +114,7 @@ void A2dpCodecConfig::setDefaultCodecPriority() { A2dpCodecConfig* A2dpCodecConfig::createCodec( btav_a2dp_codec_index_t codec_index, btav_a2dp_codec_priority_t codec_priority) { - LOG_INFO("%s", A2DP_CodecIndexStr(codec_index)); + log::info("{}", A2DP_CodecIndexStr(codec_index)); // Hardware offload codec extensibility: // management of the codec is moved under the ProviderInfo @@ -176,7 +177,7 @@ int A2dpCodecConfig::getTrackBitRate() const { memcpy(p_codec_info, ota_codec_config_, sizeof(ota_codec_config_)); tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -191,7 +192,7 @@ int A2dpCodecConfig::getTrackBitRate() const { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return -1; } @@ -261,8 +262,8 @@ bool A2dpCodecConfig::getCodecSpecificConfig(tBT_A2DP_OFFLOAD* p_a2dp_offload) { } p_a2dp_offload->codec_info[7] = codec_config[10]; // LDAC specific channel mode - LOG_VERBOSE("%s: Ldac specific channelmode =%d", __func__, - p_a2dp_offload->codec_info[7]); + log::verbose("Ldac specific channelmode ={}", + p_a2dp_offload->codec_info[7]); } break; #endif @@ -536,7 +537,7 @@ void A2dpCodecConfig::debug_codec_dump(int fd) { int A2DP_IotGetPeerSinkCodecType(const uint8_t* p_codec_info) { int peer_codec_type = 0; tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: peer_codec_type = IOT_CONF_VAL_A2DP_CODECTYPE_SBC; @@ -546,8 +547,8 @@ int A2DP_IotGetPeerSinkCodecType(const uint8_t* p_codec_info) { uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info); uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info); - LOG_VERBOSE("%s codec_id = %d", __func__, codec_id); - LOG_VERBOSE("%s vendor_id = %x", __func__, vendor_id); + log::verbose("codec_id = {}", codec_id); + log::verbose("vendor_id = {:x}", vendor_id); if (codec_id == A2DP_APTX_CODEC_ID_BLUETOOTH && vendor_id == A2DP_APTX_VENDOR_ID) { @@ -605,7 +606,7 @@ A2dpCodecs::~A2dpCodecs() { } bool A2dpCodecs::init() { - LOG_INFO("%s", __func__); + log::info(""); std::lock_guard<std::recursive_mutex> lock(codec_mutex_); bool opus_enabled = @@ -636,8 +637,7 @@ bool A2dpCodecs::init() { // If OPUS is not supported it is disabled if (codec_index == BTAV_A2DP_CODEC_INDEX_SOURCE_OPUS && !opus_enabled) { codec_priority = BTAV_A2DP_CODEC_PRIORITY_DISABLED; - LOG_INFO("%s: OPUS codec disabled, updated priority to %d", __func__, - codec_priority); + log::info("OPUS codec disabled, updated priority to {}", codec_priority); } A2dpCodecConfig* codec_config = @@ -645,8 +645,8 @@ bool A2dpCodecs::init() { if (codec_config == nullptr) continue; if (codec_priority != BTAV_A2DP_CODEC_PRIORITY_DEFAULT) { - LOG_INFO("%s: updated %s codec priority to %d", __func__, - codec_config->name().c_str(), codec_priority); + log::info("updated {} codec priority to {}", codec_config->name().c_str(), + codec_priority); } // Test if the codec is disabled @@ -667,19 +667,19 @@ bool A2dpCodecs::init() { } if (ordered_source_codecs_.empty()) { - LOG_ERROR("%s: no Source codecs were initialized", __func__); + log::error("no Source codecs were initialized"); } else { for (auto iter : ordered_source_codecs_) { - LOG_INFO("%s: initialized Source codec %s, idx %d", __func__, - iter->name().c_str(), iter->codecIndex()); + log::info("initialized Source codec {}, idx {}", iter->name().c_str(), + iter->codecIndex()); } } if (ordered_sink_codecs_.empty()) { - LOG_ERROR("%s: no Sink codecs were initialized", __func__); + log::error("no Sink codecs were initialized"); } else { for (auto iter : ordered_sink_codecs_) { - LOG_INFO("%s: initialized Sink codec %s, idx %d", __func__, - iter->name().c_str(), iter->codecIndex()); + log::info("initialized Sink codec {}, idx {}", iter->name().c_str(), + iter->codecIndex()); } } @@ -768,8 +768,7 @@ bool A2dpCodecs::setCodecUserConfig( *p_restart_output = false; *p_config_updated = false; - LOG_INFO("%s: Configuring: %s", __func__, - codec_user_config.ToString().c_str()); + log::info("Configuring: {}", codec_user_config.ToString().c_str()); if (codec_user_config.codec_type < BTAV_A2DP_CODEC_INDEX_MAX) { auto iter = indexed_codecs_.find(codec_user_config.codec_type); @@ -848,10 +847,9 @@ bool A2dpCodecs::setCodecUserConfig( if (*p_restart_input || *p_restart_output) *p_config_updated = true; - LOG_INFO( - "%s: Configured: restart_input = %d restart_output = %d " - "config_updated = %d", - __func__, *p_restart_input, *p_restart_output, *p_config_updated); + log::info( + "Configured: restart_input = {} restart_output = {} config_updated = {}", + *p_restart_input, *p_restart_output, *p_config_updated); return true; @@ -906,10 +904,10 @@ bool A2dpCodecs::setCodecOtaConfig( if (current_codec_config_ != nullptr) { codec_user_config = current_codec_config_->getCodecUserConfig(); if (!A2dpCodecConfig::isCodecConfigEmpty(codec_user_config)) { - LOG_WARN( - "%s: ignoring peer OTA configuration for codec %s: " - "existing user configuration for current codec %s", - __func__, A2DP_CodecName(p_ota_codec_config), + log::warn( + "ignoring peer OTA configuration for codec {}: existing user " + "configuration for current codec {}", + A2DP_CodecName(p_ota_codec_config), current_codec_config_->name().c_str()); goto fail; } @@ -920,16 +918,13 @@ bool A2dpCodecs::setCodecOtaConfig( // ignored. codec_type = A2DP_SourceCodecIndex(p_ota_codec_config); if (codec_type == BTAV_A2DP_CODEC_INDEX_MAX) { - LOG_WARN( - "%s: ignoring peer OTA codec configuration: " - "invalid codec", - __func__); + log::warn("ignoring peer OTA codec configuration: invalid codec"); goto fail; // Invalid codec } else { auto iter = indexed_codecs_.find(codec_type); if (iter == indexed_codecs_.end()) { - LOG_WARN("%s: cannot find codec configuration for peer OTA codec %s", - __func__, A2DP_CodecName(p_ota_codec_config)); + log::warn("cannot find codec configuration for peer OTA codec {}", + A2DP_CodecName(p_ota_codec_config)); goto fail; } a2dp_codec_config = iter->second; @@ -937,10 +932,10 @@ bool A2dpCodecs::setCodecOtaConfig( if (a2dp_codec_config == nullptr) goto fail; codec_user_config = a2dp_codec_config->getCodecUserConfig(); if (!A2dpCodecConfig::isCodecConfigEmpty(codec_user_config)) { - LOG_WARN( - "%s: ignoring peer OTA configuration for codec %s: " - "existing user configuration for same codec", - __func__, A2DP_CodecName(p_ota_codec_config)); + log::warn( + "ignoring peer OTA configuration for codec {}: existing user " + "configuration for same codec", + A2DP_CodecName(p_ota_codec_config)); goto fail; } current_codec_config_ = a2dp_codec_config; @@ -951,8 +946,8 @@ bool A2dpCodecs::setCodecOtaConfig( codec_user_config, codec_audio_config, p_peer_params, p_ota_codec_config, false, p_result_codec_config, p_restart_input, p_restart_output, p_config_updated)) { - LOG_WARN("%s: cannot set codec configuration for peer OTA codec %s", - __func__, A2DP_CodecName(p_ota_codec_config)); + log::warn("cannot set codec configuration for peer OTA codec {}", + A2DP_CodecName(p_ota_codec_config)); goto fail; } CHECK(current_codec_config_ != nullptr); @@ -1059,7 +1054,7 @@ tA2DP_CODEC_TYPE A2DP_GetCodecType(const uint8_t* p_codec_info) { bool A2DP_IsSourceCodecValid(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1080,7 +1075,7 @@ bool A2DP_IsSourceCodecValid(const uint8_t* p_codec_info) { bool A2DP_IsSinkCodecValid(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1101,7 +1096,7 @@ bool A2DP_IsSinkCodecValid(const uint8_t* p_codec_info) { bool A2DP_IsPeerSourceCodecValid(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1122,7 +1117,7 @@ bool A2DP_IsPeerSourceCodecValid(const uint8_t* p_codec_info) { bool A2DP_IsPeerSinkCodecValid(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1143,7 +1138,7 @@ bool A2DP_IsPeerSinkCodecValid(const uint8_t* p_codec_info) { bool A2DP_IsSinkCodecSupported(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1158,14 +1153,14 @@ bool A2DP_IsSinkCodecSupported(const uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return false; } bool A2DP_IsPeerSourceCodecSupported(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1180,7 +1175,7 @@ bool A2DP_IsPeerSourceCodecSupported(const uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return false; } @@ -1209,7 +1204,7 @@ uint8_t A2DP_GetMediaType(const uint8_t* p_codec_info) { const char* A2DP_CodecName(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1224,7 +1219,7 @@ const char* A2DP_CodecName(const uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return "UNKNOWN CODEC"; } @@ -1248,7 +1243,7 @@ bool A2DP_CodecTypeEquals(const uint8_t* p_codec_info_a, break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type_a); + log::error("unsupported codec type 0x{:x}", codec_type_a); return false; } @@ -1272,14 +1267,14 @@ bool A2DP_CodecEquals(const uint8_t* p_codec_info_a, break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type_a); + log::error("unsupported codec type 0x{:x}", codec_type_a); return false; } int A2DP_GetTrackSampleRate(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1294,14 +1289,14 @@ int A2DP_GetTrackSampleRate(const uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return -1; } int A2DP_GetTrackBitsPerSample(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1316,14 +1311,14 @@ int A2DP_GetTrackBitsPerSample(const uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return -1; } int A2DP_GetTrackChannelCount(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1338,14 +1333,14 @@ int A2DP_GetTrackChannelCount(const uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return -1; } int A2DP_GetSinkTrackChannelType(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1360,7 +1355,7 @@ int A2DP_GetSinkTrackChannelType(const uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return -1; } @@ -1381,7 +1376,7 @@ bool A2DP_GetPacketTimestamp(const uint8_t* p_codec_info, const uint8_t* p_data, break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return false; } @@ -1403,7 +1398,7 @@ bool A2DP_BuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf, break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return false; } @@ -1411,7 +1406,7 @@ const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterface( const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); if (::bluetooth::audio::a2dp::provider::supports_codec( A2DP_SourceCodecIndex(p_codec_info))) { @@ -1431,7 +1426,7 @@ const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterface( break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return NULL; } @@ -1439,7 +1434,7 @@ const tA2DP_DECODER_INTERFACE* A2DP_GetDecoderInterface( const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); switch (codec_type) { case A2DP_MEDIA_CT_SBC: @@ -1454,7 +1449,7 @@ const tA2DP_DECODER_INTERFACE* A2DP_GetDecoderInterface( break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return NULL; } @@ -1474,14 +1469,14 @@ bool A2DP_AdjustCodec(uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return false; } btav_a2dp_codec_index_t A2DP_SourceCodecIndex(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); auto ext_codec_index = bluetooth::audio::a2dp::provider::source_codec_index(p_codec_info); @@ -1502,14 +1497,14 @@ btav_a2dp_codec_index_t A2DP_SourceCodecIndex(const uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return BTAV_A2DP_CODEC_INDEX_MAX; } btav_a2dp_codec_index_t A2DP_SinkCodecIndex(const uint8_t* p_codec_info) { tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); - LOG_VERBOSE("%s: codec_type = 0x%x", __func__, codec_type); + log::verbose("codec_type = 0x{:x}", codec_type); auto ext_codec_index = bluetooth::audio::a2dp::provider::sink_codec_index(p_codec_info); @@ -1530,7 +1525,7 @@ btav_a2dp_codec_index_t A2DP_SinkCodecIndex(const uint8_t* p_codec_info) { break; } - LOG_ERROR("%s: unsupported codec type 0x%x", __func__, codec_type); + log::error("unsupported codec type 0x{:x}", codec_type); return BTAV_A2DP_CODEC_INDEX_MAX; } @@ -1571,7 +1566,7 @@ const char* A2DP_CodecIndexStr(btav_a2dp_codec_index_t codec_index) { bool A2DP_InitCodecConfig(btav_a2dp_codec_index_t codec_index, AvdtpSepConfig* p_cfg) { - LOG_VERBOSE("%s: codec %s", __func__, A2DP_CodecIndexStr(codec_index)); + log::verbose("codec {}", A2DP_CodecIndexStr(codec_index)); /* Default: no content protection info */ p_cfg->num_protect = 0; diff --git a/system/stack/a2dp/a2dp_ext.cc b/system/stack/a2dp/a2dp_ext.cc index 0eec9b6dd5..a0bb2eb51e 100644 --- a/system/stack/a2dp/a2dp_ext.cc +++ b/system/stack/a2dp/a2dp_ext.cc @@ -17,10 +17,13 @@ #include "a2dp_ext.h" #include <base/logging.h> +#include <bluetooth/log.h> #include "a2dp_codec_api.h" #include "audio_hal_interface/a2dp_encoding.h" +using namespace bluetooth; + static uint64_t codec_id(btav_a2dp_codec_index_t codec_index) { uint64_t id = 0; auto result = ::bluetooth::audio::a2dp::provider::codec_info( @@ -62,7 +65,7 @@ bool A2dpCodecConfigExt::setCodecConfig(const uint8_t* p_peer_codec_info, std::vector<provider::a2dp_remote_capabilities>{capabilities}, codec_user_config_); if (!result.has_value()) { - LOG(ERROR) << "Failed to set a configuration for " << name_; + log::error("Failed to set a configuration for {}", name_); return false; } diff --git a/system/stack/a2dp/a2dp_sbc.cc b/system/stack/a2dp/a2dp_sbc.cc index 2928f8e4bf..d50fd5324d 100644 --- a/system/stack/a2dp/a2dp_sbc.cc +++ b/system/stack/a2dp/a2dp_sbc.cc @@ -27,7 +27,7 @@ #include "a2dp_sbc.h" -#include <base/logging.h> +#include <bluetooth/log.h> #include <string.h> #include "a2dp_sbc_decoder.h" @@ -35,12 +35,13 @@ #include "embdrv/sbc/encoder/include/sbc_encoder.h" #include "include/check.h" #include "internal_include/bt_trace.h" -#include "os/log.h" #include "osi/include/osi.h" #include "stack/include/bt_hdr.h" #define A2DP_SBC_MAX_BITPOOL 53 +using namespace bluetooth; + /* data type for the SBC Codec Information Element */ typedef struct { uint8_t samp_freq; /* Sampling frequency */ @@ -335,7 +336,7 @@ bool A2DP_IsPeerSourceCodecSupportedSbc(const uint8_t* p_codec_info) { void A2DP_InitDefaultCodecSbc(uint8_t* p_codec_info) { if (A2DP_BuildInfoSbc(AVDT_MEDIA_TYPE_AUDIO, &a2dp_sbc_default_config, p_codec_info) != A2DP_SUCCESS) { - LOG_ERROR("%s: A2DP_BuildInfoSbc failed", __func__); + log::error("A2DP_BuildInfoSbc failed"); } } @@ -354,26 +355,26 @@ static tA2DP_STATUS A2DP_CodecInfoMatchesCapabilitySbc( /* parse configuration */ status = A2DP_ParseInfoSbc(&cfg_cie, p_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: parsing failed %d", __func__, status); + log::error("parsing failed {}", status); return status; } /* verify that each parameter is in range */ - LOG_VERBOSE("%s: FREQ peer: 0x%x, capability 0x%x", __func__, - cfg_cie.samp_freq, p_cap->samp_freq); - LOG_VERBOSE("%s: CH_MODE peer: 0x%x, capability 0x%x", __func__, - cfg_cie.ch_mode, p_cap->ch_mode); - LOG_VERBOSE("%s: BLOCK_LEN peer: 0x%x, capability 0x%x", __func__, - cfg_cie.block_len, p_cap->block_len); - LOG_VERBOSE("%s: SUB_BAND peer: 0x%x, capability 0x%x", __func__, - cfg_cie.num_subbands, p_cap->num_subbands); - LOG_VERBOSE("%s: ALLOC_METHOD peer: 0x%x, capability 0x%x", __func__, - cfg_cie.alloc_method, p_cap->alloc_method); - LOG_VERBOSE("%s: MIN_BitPool peer: 0x%x, capability 0x%x", __func__, - cfg_cie.min_bitpool, p_cap->min_bitpool); - LOG_VERBOSE("%s: MAX_BitPool peer: 0x%x, capability 0x%x", __func__, - cfg_cie.max_bitpool, p_cap->max_bitpool); + log::verbose("FREQ peer: 0x{:x}, capability 0x{:x}", cfg_cie.samp_freq, + p_cap->samp_freq); + log::verbose("CH_MODE peer: 0x{:x}, capability 0x{:x}", cfg_cie.ch_mode, + p_cap->ch_mode); + log::verbose("BLOCK_LEN peer: 0x{:x}, capability 0x{:x}", cfg_cie.block_len, + p_cap->block_len); + log::verbose("SUB_BAND peer: 0x{:x}, capability 0x{:x}", cfg_cie.num_subbands, + p_cap->num_subbands); + log::verbose("ALLOC_METHOD peer: 0x{:x}, capability 0x{:x}", + cfg_cie.alloc_method, p_cap->alloc_method); + log::verbose("MIN_BitPool peer: 0x{:x}, capability 0x{:x}", + cfg_cie.min_bitpool, p_cap->min_bitpool); + log::verbose("MAX_BitPool peer: 0x{:x}, capability 0x{:x}", + cfg_cie.max_bitpool, p_cap->max_bitpool); /* sampling frequency */ if ((cfg_cie.samp_freq & p_cap->samp_freq) == 0) return A2DP_NS_SAMP_FREQ; @@ -410,12 +411,12 @@ bool A2DP_CodecTypeEqualsSbc(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoSbc(&sbc_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -434,12 +435,12 @@ bool A2DP_CodecEqualsSbc(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoSbc(&sbc_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -463,7 +464,7 @@ int A2DP_GetTrackSampleRateSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -488,7 +489,7 @@ int A2DP_GetTrackBitsPerSampleSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -501,7 +502,7 @@ int A2DP_GetTrackChannelCountSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -524,7 +525,7 @@ int A2DP_GetNumberOfSubbandsSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -545,7 +546,7 @@ int A2DP_GetNumberOfBlocksSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -570,7 +571,7 @@ int A2DP_GetAllocationMethodCodeSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -591,7 +592,7 @@ int A2DP_GetChannelModeCodeSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -616,7 +617,7 @@ int A2DP_GetSamplingFrequencyCodeSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -641,7 +642,7 @@ int A2DP_GetMinBitpoolSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -653,7 +654,7 @@ int A2DP_GetMaxBitpoolSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -666,7 +667,7 @@ int A2DP_GetSinkTrackChannelTypeSbc(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoSbc(&sbc_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -798,8 +799,8 @@ bool A2DP_AdjustCodecSbc(uint8_t* p_codec_info) { // Updated the max bitpool if (cfg_cie.max_bitpool > A2DP_SBC_MAX_BITPOOL) { - LOG_WARN("%s: Updated the SBC codec max bitpool from %d to %d", __func__, - cfg_cie.max_bitpool, A2DP_SBC_MAX_BITPOOL); + log::warn("Updated the SBC codec max bitpool from {} to {}", + cfg_cie.max_bitpool, A2DP_SBC_MAX_BITPOOL); cfg_cie.max_bitpool = A2DP_SBC_MAX_BITPOOL; } @@ -891,7 +892,7 @@ bool A2dpCodecConfigSbcSource::init() { // Load the encoder if (!A2DP_LoadEncoderSbc()) { - LOG_ERROR("%s: cannot load the encoder", __func__); + log::error("cannot load the encoder"); return false; } @@ -1092,8 +1093,7 @@ bool A2dpCodecConfigSbcBase::setCodecConfig(const uint8_t* p_peer_codec_info, tA2DP_STATUS status = A2DP_ParseInfoSbc(&peer_info_cie, p_peer_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } // Try using the prefered peer codec config (if valid), instead of the peer @@ -1195,10 +1195,9 @@ bool A2dpCodecConfigSbcBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.sample_rate == BTAV_A2DP_CODEC_SAMPLE_RATE_NONE) { - LOG_ERROR( - "%s: cannot match sample frequency: local caps = 0x%x " - "peer info = 0x%x", - __func__, p_a2dp_sbc_caps->samp_freq, peer_info_cie.samp_freq); + log::error( + "cannot match sample frequency: local caps = 0x{:x} peer info = 0x{:x}", + p_a2dp_sbc_caps->samp_freq, peer_info_cie.samp_freq); goto fail; } @@ -1250,8 +1249,8 @@ bool A2dpCodecConfigSbcBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.bits_per_sample == BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE) { - LOG_ERROR("%s: cannot match bits per sample: user preference = 0x%x", - __func__, codec_user_config_.bits_per_sample); + log::error("cannot match bits per sample: user preference = 0x{:x}", + codec_user_config_.bits_per_sample); goto fail; } @@ -1343,10 +1342,9 @@ bool A2dpCodecConfigSbcBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.channel_mode == BTAV_A2DP_CODEC_CHANNEL_MODE_NONE) { - LOG_ERROR( - "%s: cannot match channel mode: local caps = 0x%x " - "peer info = 0x%x", - __func__, p_a2dp_sbc_caps->ch_mode, peer_info_cie.ch_mode); + log::error( + "cannot match channel mode: local caps = 0x{:x} peer info = 0x{:x}", + p_a2dp_sbc_caps->ch_mode, peer_info_cie.ch_mode); goto fail; } @@ -1363,10 +1361,9 @@ bool A2dpCodecConfigSbcBase::setCodecConfig(const uint8_t* p_peer_codec_info, } else if (block_len & A2DP_SBC_IE_BLOCKS_4) { result_config_cie.block_len = A2DP_SBC_IE_BLOCKS_4; } else { - LOG_ERROR( - "%s: cannot match block length: local caps = 0x%x " - "peer info = 0x%x", - __func__, p_a2dp_sbc_caps->block_len, peer_info_cie.block_len); + log::error( + "cannot match block length: local caps = 0x{:x} peer info = 0x{:x}", + p_a2dp_sbc_caps->block_len, peer_info_cie.block_len); goto fail; } @@ -1379,10 +1376,10 @@ bool A2dpCodecConfigSbcBase::setCodecConfig(const uint8_t* p_peer_codec_info, } else if (num_subbands & A2DP_SBC_IE_SUBBAND_4) { result_config_cie.num_subbands = A2DP_SBC_IE_SUBBAND_4; } else { - LOG_ERROR( - "%s: cannot match number of sub-bands: local caps = 0x%x " - "peer info = 0x%x", - __func__, p_a2dp_sbc_caps->num_subbands, peer_info_cie.num_subbands); + log::error( + "cannot match number of sub-bands: local caps = 0x{:x} peer info = " + "0x{:x}", + p_a2dp_sbc_caps->num_subbands, peer_info_cie.num_subbands); goto fail; } @@ -1395,10 +1392,10 @@ bool A2dpCodecConfigSbcBase::setCodecConfig(const uint8_t* p_peer_codec_info, } else if (alloc_method & A2DP_SBC_IE_ALLOC_MD_S) { result_config_cie.alloc_method = A2DP_SBC_IE_ALLOC_MD_S; } else { - LOG_ERROR( - "%s: cannot match allocation method: local caps = 0x%x " - "peer info = 0x%x", - __func__, p_a2dp_sbc_caps->alloc_method, peer_info_cie.alloc_method); + log::error( + "cannot match allocation method: local caps = 0x{:x} peer info = " + "0x{:x}", + p_a2dp_sbc_caps->alloc_method, peer_info_cie.alloc_method); goto fail; } @@ -1412,10 +1409,10 @@ bool A2dpCodecConfigSbcBase::setCodecConfig(const uint8_t* p_peer_codec_info, if (result_config_cie.max_bitpool > peer_info_cie.max_bitpool) result_config_cie.max_bitpool = peer_info_cie.max_bitpool; if (result_config_cie.min_bitpool > result_config_cie.max_bitpool) { - LOG_ERROR( - "%s: cannot match min/max bitpool: " - "local caps min/max = 0x%x/0x%x peer info min/max = 0x%x/0x%x", - __func__, p_a2dp_sbc_caps->min_bitpool, p_a2dp_sbc_caps->max_bitpool, + log::error( + "cannot match min/max bitpool: local caps min/max = 0x{:x}/0x{:x} peer " + "info min/max = 0x{:x}/0x{:x}", + p_a2dp_sbc_caps->min_bitpool, p_a2dp_sbc_caps->max_bitpool, peer_info_cie.min_bitpool, peer_info_cie.max_bitpool); goto fail; } @@ -1486,8 +1483,7 @@ bool A2dpCodecConfigSbcBase::setPeerCodecCapabilities( tA2DP_STATUS status = A2DP_ParseInfoSbc(&peer_info_cie, p_peer_codec_capabilities, true); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } @@ -1551,7 +1547,7 @@ bool A2dpCodecConfigSbcSink::init() { // Load the decoder if (!A2DP_LoadDecoderSbc()) { - LOG_ERROR("%s: cannot load the decoder", __func__); + log::error("cannot load the decoder"); return false; } diff --git a/system/stack/a2dp/a2dp_sbc_decoder.cc b/system/stack/a2dp/a2dp_sbc_decoder.cc index da28cacc48..ed3324a3de 100644 --- a/system/stack/a2dp/a2dp_sbc_decoder.cc +++ b/system/stack/a2dp/a2dp_sbc_decoder.cc @@ -18,13 +18,19 @@ #include "a2dp_sbc_decoder.h" -#include <base/logging.h> +#include <bluetooth/log.h> #include "embdrv/sbc/decoder/include/oi_codec_sbc.h" #include "embdrv/sbc/decoder/include/oi_status.h" -#include "os/log.h" #include "stack/include/bt_hdr.h" +using namespace bluetooth; + +namespace fmt { +template <> +struct formatter<OI_STATUS> : enum_formatter<OI_STATUS> {}; +} // namespace fmt + typedef struct { OI_CODEC_SBC_DECODER_CONTEXT decoder_context; uint32_t context_data[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)]; @@ -46,8 +52,7 @@ bool a2dp_sbc_decoder_init(decoded_data_callback_t decode_callback) { &a2dp_sbc_decoder_cb.decoder_context, a2dp_sbc_decoder_cb.context_data, sizeof(a2dp_sbc_decoder_cb.context_data), 2, 2, false); if (!OI_SUCCESS(status)) { - LOG_ERROR("%s: OI_CODEC_SBC_DecoderReset failed with error code %d", - __func__, status); + log::error("OI_CODEC_SBC_DecoderReset failed with error code {}", status); return false; } @@ -64,7 +69,7 @@ bool a2dp_sbc_decoder_decode_packet(BT_HDR* p_buf) { size_t data_size = p_buf->len; if (data_size == 0) { - LOG_ERROR("%s: Empty packet", __func__); + log::error("Empty packet"); return false; } size_t num_frames = data[0] & 0xf; @@ -82,7 +87,7 @@ bool a2dp_sbc_decoder_decode_packet(BT_HDR* p_buf) { OI_CODEC_SBC_DecodeFrame(&a2dp_sbc_decoder_cb.decoder_context, &oi_data, &oi_size, out_ptr, &out_size); if (!OI_SUCCESS(status)) { - LOG_ERROR("%s: Decoding failure: %d", __func__, status); + log::error("Decoding failure: {}", status); return false; } out_avail -= out_size; diff --git a/system/stack/a2dp/a2dp_sbc_encoder.cc b/system/stack/a2dp/a2dp_sbc_encoder.cc index 9771984253..fab6f23bd0 100644 --- a/system/stack/a2dp/a2dp_sbc_encoder.cc +++ b/system/stack/a2dp/a2dp_sbc_encoder.cc @@ -21,6 +21,7 @@ #include "a2dp_sbc_encoder.h" +#include <bluetooth/log.h> #include <limits.h> #include <stdio.h> #include <string.h> @@ -30,7 +31,6 @@ #include "common/time_util.h" #include "embdrv/sbc/encoder/include/sbc_encoder.h" #include "internal_include/bt_target.h" -#include "os/log.h" #include "osi/include/allocator.h" #include "stack/include/bt_hdr.h" @@ -61,6 +61,8 @@ #define A2DP_HDR_SIZE 1 #define A2DP_SBC_OFFSET (AVDT_MEDIA_OFFSET + A2DP_SBC_MPL_HDR_LEN) +using namespace bluetooth; + typedef struct { uint32_t aa_frame_counter; int32_t aa_feed_counter; @@ -169,10 +171,8 @@ static void a2dp_sbc_encoder_update(A2dpCodecConfig* a2dp_codec_config, *p_restart_output = false; *p_config_updated = false; if (!a2dp_codec_config->copyOutOtaCodecConfig(codec_info)) { - LOG_ERROR( - "%s: Cannot update the codec encoder for %s: " - "invalid codec config", - __func__, a2dp_codec_config->name().c_str()); + log::error("Cannot update the codec encoder for {}: invalid codec config", + a2dp_codec_config->name().c_str()); return; } const uint8_t* p_codec_info = codec_info; @@ -185,9 +185,9 @@ static void a2dp_sbc_encoder_update(A2dpCodecConfig* a2dp_codec_config, p_feeding_params->bits_per_sample = a2dp_codec_config->getAudioBitsPerSample(); p_feeding_params->channel_count = A2DP_GetTrackChannelCountSbc(p_codec_info); - LOG_INFO("%s: sample_rate=%u bits_per_sample=%u channel_count=%u", __func__, - p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, - p_feeding_params->channel_count); + log::info("sample_rate={} bits_per_sample={} channel_count={}", + p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, + p_feeding_params->channel_count); a2dp_sbc_feeding_reset(); // The codec parameters @@ -204,18 +204,18 @@ static void a2dp_sbc_encoder_update(A2dpCodecConfig* a2dp_codec_config, // Reset invalid parameters if (!p_encoder_params->s16NumOfSubBands) { - LOG_WARN("%s: SubBands are set to 0, resetting to max (%d)", __func__, - SBC_MAX_NUM_OF_SUBBANDS); + log::warn("SubBands are set to 0, resetting to max ({})", + SBC_MAX_NUM_OF_SUBBANDS); p_encoder_params->s16NumOfSubBands = SBC_MAX_NUM_OF_SUBBANDS; } if (!p_encoder_params->s16NumOfBlocks) { - LOG_WARN("%s: Blocks are set to 0, resetting to max (%d)", __func__, - SBC_MAX_NUM_OF_BLOCKS); + log::warn("Blocks are set to 0, resetting to max ({})", + SBC_MAX_NUM_OF_BLOCKS); p_encoder_params->s16NumOfBlocks = SBC_MAX_NUM_OF_BLOCKS; } if (!p_encoder_params->s16NumOfChannels) { - LOG_WARN("%s: Channels are set to 0, resetting to max (%d)", __func__, - SBC_MAX_NUM_OF_CHANNELS); + log::warn("Channels are set to 0, resetting to max ({})", + SBC_MAX_NUM_OF_CHANNELS); p_encoder_params->s16NumOfChannels = SBC_MAX_NUM_OF_CHANNELS; } @@ -234,16 +234,16 @@ static void a2dp_sbc_encoder_update(A2dpCodecConfig* a2dp_codec_config, p_encoder_params->u16BitRate = a2dp_sbc_source_rate(peer_params.is_peer_edr); a2dp_sbc_encoder_cb.TxAaMtuSize = adjust_effective_mtu(peer_params); - LOG_INFO("%s: MTU=%d, peer_mtu=%d min_bitpool=%d max_bitpool=%d", __func__, - a2dp_sbc_encoder_cb.TxAaMtuSize, peer_params.peer_mtu, min_bitpool, - max_bitpool); - LOG_INFO( - "%s: ChannelMode=%d, NumOfSubBands=%d, NumOfBlocks=%d, " - "AllocationMethod=%d, BitRate=%d, SamplingFreq=%d BitPool=%d", - __func__, p_encoder_params->s16ChannelMode, - p_encoder_params->s16NumOfSubBands, p_encoder_params->s16NumOfBlocks, - p_encoder_params->s16AllocationMethod, p_encoder_params->u16BitRate, - s16SamplingFreq, p_encoder_params->s16BitPool); + log::info("MTU={}, peer_mtu={} min_bitpool={} max_bitpool={}", + a2dp_sbc_encoder_cb.TxAaMtuSize, peer_params.peer_mtu, min_bitpool, + max_bitpool); + log::info( + "ChannelMode={}, NumOfSubBands={}, NumOfBlocks={}, AllocationMethod={}, " + "BitRate={}, SamplingFreq={} BitPool={}", + p_encoder_params->s16ChannelMode, p_encoder_params->s16NumOfSubBands, + p_encoder_params->s16NumOfBlocks, p_encoder_params->s16AllocationMethod, + p_encoder_params->u16BitRate, s16SamplingFreq, + p_encoder_params->s16BitPool); do { if ((p_encoder_params->s16ChannelMode == SBC_JOINT_STEREO) || @@ -293,17 +293,17 @@ static void a2dp_sbc_encoder_update(A2dpCodecConfig* a2dp_codec_config, if (s16BitPool < 0) s16BitPool = 0; - LOG_VERBOSE("%s: bitpool candidate: %d (%d kbps)", __func__, s16BitPool, - p_encoder_params->u16BitRate); + log::verbose("bitpool candidate: {} ({} kbps)", s16BitPool, + p_encoder_params->u16BitRate); if (s16BitPool > max_bitpool) { - LOG_VERBOSE("%s: computed bitpool too large (%d)", __func__, s16BitPool); + log::verbose("computed bitpool too large ({})", s16BitPool); /* Decrease bitrate */ p_encoder_params->u16BitRate -= A2DP_SBC_BITRATE_STEP; /* Record that we have decreased the bitrate */ protect |= 1; } else if (s16BitPool < min_bitpool) { - LOG_WARN("%s: computed bitpool too small (%d)", __func__, s16BitPool); + log::warn("computed bitpool too small ({})", s16BitPool); /* Increase bitrate */ uint16_t previous_u16BitRate = p_encoder_params->u16BitRate; @@ -317,7 +317,7 @@ static void a2dp_sbc_encoder_update(A2dpCodecConfig* a2dp_codec_config, } /* In case we have already increased and decreased the bitrate, just stop */ if (protect == 3) { - LOG_ERROR("%s: could not find bitpool in range", __func__); + log::error("could not find bitpool in range"); break; } } while (true); @@ -325,8 +325,8 @@ static void a2dp_sbc_encoder_update(A2dpCodecConfig* a2dp_codec_config, /* Finally update the bitpool in the encoder structure */ p_encoder_params->s16BitPool = s16BitPool; - LOG_INFO("%s: final bit rate %d, final bit pool %d", __func__, - p_encoder_params->u16BitRate, p_encoder_params->s16BitPool); + log::info("final bit rate {}, final bit pool {}", + p_encoder_params->u16BitRate, p_encoder_params->s16BitPool); /* Reset the SBC encoder */ SBC_Encoder_Init(&a2dp_sbc_encoder_cb.sbc_encoder_params); @@ -349,8 +349,8 @@ void a2dp_sbc_feeding_reset(void) { A2DP_SBC_ENCODER_INTERVAL_MS) / 1000; - LOG_INFO("%s: PCM bytes per tick %u", __func__, - a2dp_sbc_encoder_cb.feeding_state.bytes_per_tick); + log::info("PCM bytes per tick {}", + a2dp_sbc_encoder_cb.feeding_state.bytes_per_tick); } void a2dp_sbc_feeding_flush(void) { @@ -371,8 +371,8 @@ void a2dp_sbc_send_frames(uint64_t timestamp_us) { uint8_t nb_iterations = 0; a2dp_sbc_get_num_frame_iteration(&nb_iterations, &nb_frame, timestamp_us); - LOG_VERBOSE("%s: Sending %d frames per iteration, %d iterations", __func__, - nb_frame, nb_iterations); + log::verbose("Sending {} frames per iteration, {} iterations", nb_frame, + nb_iterations); if (nb_frame == 0) return; for (uint8_t counter = 0; counter < nb_iterations; counter++) { @@ -396,7 +396,7 @@ static void a2dp_sbc_get_num_frame_iteration(uint8_t* num_of_iterations, a2dp_sbc_encoder_cb.sbc_encoder_params.s16NumOfBlocks * a2dp_sbc_encoder_cb.feeding_params.channel_count * a2dp_sbc_encoder_cb.feeding_params.bits_per_sample / 8; - LOG_VERBOSE("%s: pcm_bytes_per_frame %u", __func__, pcm_bytes_per_frame); + log::verbose("pcm_bytes_per_frame {}", pcm_bytes_per_frame); uint32_t us_this_tick = A2DP_SBC_ENCODER_INTERVAL_MS * 1000; uint64_t now_us = timestamp_us; @@ -415,8 +415,8 @@ static void a2dp_sbc_get_num_frame_iteration(uint8_t* num_of_iterations, a2dp_sbc_encoder_cb.stats.media_read_total_expected_frames += projected_nof; if (projected_nof > MAX_PCM_FRAME_NUM_PER_TICK) { - LOG_WARN("%s: limiting frames to be sent from %d to %d", __func__, - projected_nof, MAX_PCM_FRAME_NUM_PER_TICK); + log::warn("limiting frames to be sent from {} to {}", projected_nof, + MAX_PCM_FRAME_NUM_PER_TICK); // Update the stats size_t delta = projected_nof - MAX_PCM_FRAME_NUM_PER_TICK; @@ -425,26 +425,25 @@ static void a2dp_sbc_get_num_frame_iteration(uint8_t* num_of_iterations, projected_nof = MAX_PCM_FRAME_NUM_PER_TICK; } - LOG_VERBOSE("%s: frames for available PCM data %u", __func__, projected_nof); + log::verbose("frames for available PCM data {}", projected_nof); if (a2dp_sbc_encoder_cb.peer_params.is_peer_edr) { if (!a2dp_sbc_encoder_cb.tx_sbc_frames) { - LOG_ERROR("%s: tx_sbc_frames not updated, update from here", __func__); + log::error("tx_sbc_frames not updated, update from here"); a2dp_sbc_encoder_cb.tx_sbc_frames = calculate_max_frames_per_packet(); } nof = a2dp_sbc_encoder_cb.tx_sbc_frames; if (!nof) { - LOG_ERROR("%s: number of frames not updated, set calculated values", - __func__); + log::error("number of frames not updated, set calculated values"); nof = projected_nof; noi = 1; } else { if (nof < projected_nof) { noi = projected_nof / nof; // number of iterations would vary if (noi > A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK) { - LOG_ERROR("%s: Audio Congestion (iterations:%d > max (%d))", __func__, - noi, A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK); + log::error("Audio Congestion (iterations:{} > max ({}))", noi, + A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK); noi = A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK; a2dp_sbc_encoder_cb.feeding_state.counter = noi * nof * (float)pcm_bytes_per_frame; @@ -452,16 +451,16 @@ static void a2dp_sbc_get_num_frame_iteration(uint8_t* num_of_iterations, projected_nof = nof; } else { noi = 1; // number of iterations is 1 - LOG_VERBOSE("%s: reducing frames for available PCM data", __func__); + log::verbose("reducing frames for available PCM data"); nof = projected_nof; } } } else { // For BR cases nof will be same as the value retrieved at projected_nof - LOG_VERBOSE("%s: headset BR, number of frames %u", __func__, nof); + log::verbose("headset BR, number of frames {}", nof); if (projected_nof > MAX_PCM_FRAME_NUM_PER_TICK) { - LOG_ERROR("%s: Audio Congestion (frames: %d > max (%d))", __func__, - projected_nof, MAX_PCM_FRAME_NUM_PER_TICK); + log::error("Audio Congestion (frames: {} > max ({}))", projected_nof, + MAX_PCM_FRAME_NUM_PER_TICK); // Update the stats size_t delta = projected_nof - MAX_PCM_FRAME_NUM_PER_TICK; @@ -475,8 +474,7 @@ static void a2dp_sbc_get_num_frame_iteration(uint8_t* num_of_iterations, } a2dp_sbc_encoder_cb.feeding_state.counter -= noi * nof * (float)pcm_bytes_per_frame; - LOG_VERBOSE("%s: effective num of frames %u, iterations %u", __func__, nof, - noi); + log::verbose("effective num of frames {}, iterations {}", nof, noi); *num_of_frames = nof; *num_of_iterations = noi; @@ -520,8 +518,8 @@ static void a2dp_sbc_encode_frames(uint8_t nb_frame) { bytes_read += num_bytes; } else { - LOG_WARN("%s: underflow %d, %d", __func__, nb_frame, - a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue); + log::warn("underflow {}, {}", nb_frame, + a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue); a2dp_sbc_encoder_cb.feeding_state.counter += nb_frame * p_encoder_params->s16NumOfSubBands * p_encoder_params->s16NumOfBlocks * @@ -719,16 +717,15 @@ static uint16_t adjust_effective_mtu( if (mtu_size > peer_params.peer_mtu) { mtu_size = peer_params.peer_mtu; } - LOG_VERBOSE("%s: original AVDTP MTU size: %d", __func__, mtu_size); + log::verbose("original AVDTP MTU size: {}", mtu_size); if (peer_params.is_peer_edr && !peer_params.peer_supports_3mbps) { // This condition would be satisfied only if the remote device is // EDR and supports only 2 Mbps, but the effective AVDTP MTU size // exceeds the 2DH5 packet size. - LOG_VERBOSE("%s: The remote device is EDR but does not support 3 Mbps", - __func__); + log::verbose("The remote device is EDR but does not support 3 Mbps"); if (mtu_size > MAX_2MBPS_AVDTP_MTU) { - LOG_WARN("%s: Restricting AVDTP MTU size from %d to %d", __func__, - mtu_size, MAX_2MBPS_AVDTP_MTU); + log::warn("Restricting AVDTP MTU size from {} to {}", mtu_size, + MAX_2MBPS_AVDTP_MTU); mtu_size = MAX_2MBPS_AVDTP_MTU; } } @@ -745,49 +742,47 @@ static uint8_t calculate_max_frames_per_packet(void) { const uint16_t& effective_mtu_size = a2dp_sbc_encoder_cb.TxAaMtuSize; if (!p_encoder_params->s16NumOfSubBands) { - LOG_ERROR("%s: SubBands are set to 0, resetting to %d", __func__, - SBC_MAX_NUM_OF_SUBBANDS); + log::error("SubBands are set to 0, resetting to {}", + SBC_MAX_NUM_OF_SUBBANDS); p_encoder_params->s16NumOfSubBands = SBC_MAX_NUM_OF_SUBBANDS; } if (!p_encoder_params->s16NumOfBlocks) { - LOG_ERROR("%s: Blocks are set to 0, resetting to %d", __func__, - SBC_MAX_NUM_OF_BLOCKS); + log::error("Blocks are set to 0, resetting to {}", SBC_MAX_NUM_OF_BLOCKS); p_encoder_params->s16NumOfBlocks = SBC_MAX_NUM_OF_BLOCKS; } if (!p_encoder_params->s16NumOfChannels) { - LOG_ERROR("%s: Channels are set to 0, resetting to %d", __func__, - SBC_MAX_NUM_OF_CHANNELS); + log::error("Channels are set to 0, resetting to {}", + SBC_MAX_NUM_OF_CHANNELS); p_encoder_params->s16NumOfChannels = SBC_MAX_NUM_OF_CHANNELS; } frame_len = a2dp_sbc_frame_length(); - LOG_VERBOSE("%s: Effective Tx MTU to be considered: %d", __func__, - effective_mtu_size); + log::verbose("Effective Tx MTU to be considered: {}", effective_mtu_size); switch (p_encoder_params->s16SamplingFreq) { case SBC_sf44100: if (frame_len == 0) { - LOG_ERROR("%s: Calculating frame length, resetting it to default %d", - __func__, A2DP_SBC_MAX_HQ_FRAME_SIZE_44_1); + log::error("Calculating frame length, resetting it to default {}", + A2DP_SBC_MAX_HQ_FRAME_SIZE_44_1); frame_len = A2DP_SBC_MAX_HQ_FRAME_SIZE_44_1; } result = (effective_mtu_size - A2DP_HDR_SIZE) / frame_len; - LOG_VERBOSE("%s: Max number of SBC frames: %d", __func__, result); + log::verbose("Max number of SBC frames: {}", result); break; case SBC_sf48000: if (frame_len == 0) { - LOG_ERROR("%s: Calculating frame length, resetting it to default %d", - __func__, A2DP_SBC_MAX_HQ_FRAME_SIZE_48); + log::error("Calculating frame length, resetting it to default {}", + A2DP_SBC_MAX_HQ_FRAME_SIZE_48); frame_len = A2DP_SBC_MAX_HQ_FRAME_SIZE_48; } result = (effective_mtu_size - A2DP_HDR_SIZE) / frame_len; - LOG_VERBOSE("%s: Max number of SBC frames: %d", __func__, result); + log::verbose("Max number of SBC frames: {}", result); break; default: - LOG_ERROR("%s: Max number of SBC frames: %d", __func__, result); + log::error("Max number of SBC frames: {}", result); break; } return result; @@ -799,8 +794,7 @@ static uint16_t a2dp_sbc_source_rate(bool is_peer_edr) { /* restrict bitrate if a2dp link is non-edr */ if (!is_peer_edr) { rate = A2DP_SBC_NON_EDR_MAX_RATE; - LOG_VERBOSE("%s: non-edr a2dp sink detected, restrict rate to %d", __func__, - rate); + log::verbose("non-edr a2dp sink detected, restrict rate to {}", rate); } return rate; @@ -810,13 +804,12 @@ static uint32_t a2dp_sbc_frame_length(void) { SBC_ENC_PARAMS* p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params; uint32_t frame_len = 0; - LOG_VERBOSE( - "%s: channel mode: %d, sub-band: %d, number of block: %d, " - "bitpool: %d, sampling frequency: %d, num channels: %d", - __func__, p_encoder_params->s16ChannelMode, - p_encoder_params->s16NumOfSubBands, p_encoder_params->s16NumOfBlocks, - p_encoder_params->s16BitPool, p_encoder_params->s16SamplingFreq, - p_encoder_params->s16NumOfChannels); + log::verbose( + "channel mode: {}, sub-band: {}, number of block: {}, bitpool: {}, " + "sampling frequency: {}, num channels: {}", + p_encoder_params->s16ChannelMode, p_encoder_params->s16NumOfSubBands, + p_encoder_params->s16NumOfBlocks, p_encoder_params->s16BitPool, + p_encoder_params->s16SamplingFreq, p_encoder_params->s16NumOfChannels); switch (p_encoder_params->s16ChannelMode) { case SBC_MONO: @@ -854,17 +847,17 @@ static uint32_t a2dp_sbc_frame_length(void) { CHAR_BIT); break; default: - LOG_VERBOSE("%s: Invalid channel number: %d", __func__, - p_encoder_params->s16ChannelMode); + log::verbose("Invalid channel number: {}", + p_encoder_params->s16ChannelMode); break; } - LOG_VERBOSE("%s: calculated frame length: %d", __func__, frame_len); + log::verbose("calculated frame length: {}", frame_len); return frame_len; } uint32_t a2dp_sbc_get_bitrate() { SBC_ENC_PARAMS* p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params; - LOG_INFO("%s: bit rate %d ", __func__, p_encoder_params->u16BitRate); + log::info("bit rate {} ", p_encoder_params->u16BitRate); return p_encoder_params->u16BitRate * 1000; } diff --git a/system/stack/a2dp/a2dp_vendor_aptx.cc b/system/stack/a2dp/a2dp_vendor_aptx.cc index f718225b3b..7700043d2c 100644 --- a/system/stack/a2dp/a2dp_vendor_aptx.cc +++ b/system/stack/a2dp/a2dp_vendor_aptx.cc @@ -25,7 +25,7 @@ #include "a2dp_vendor_aptx.h" -#include <base/logging.h> +#include <bluetooth/log.h> #include <string.h> #include "a2dp_vendor.h" @@ -33,10 +33,11 @@ #include "btif/include/btif_av_co.h" #include "include/check.h" #include "internal_include/bt_trace.h" -#include "os/log.h" #include "osi/include/osi.h" #include "stack/include/bt_hdr.h" +using namespace bluetooth; + // data type for the aptX Codec Information Element */ typedef struct { uint32_t vendorId; @@ -209,16 +210,16 @@ static tA2DP_STATUS A2DP_CodecInfoMatchesCapabilityAptx( /* parse configuration */ status = A2DP_ParseInfoAptx(&cfg_cie, p_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: parsing failed %d", __func__, status); + log::error("parsing failed {}", status); return status; } /* verify that each parameter is in range */ - LOG_VERBOSE("%s: FREQ peer: 0x%x, capability 0x%x", __func__, - cfg_cie.sampleRate, p_cap->sampleRate); - LOG_VERBOSE("%s: CH_MODE peer: 0x%x, capability 0x%x", __func__, - cfg_cie.channelMode, p_cap->channelMode); + log::verbose("FREQ peer: 0x{:x}, capability 0x{:x}", cfg_cie.sampleRate, + p_cap->sampleRate); + log::verbose("CH_MODE peer: 0x{:x}, capability 0x{:x}", cfg_cie.channelMode, + p_cap->channelMode); /* sampling frequency */ if ((cfg_cie.sampleRate & p_cap->sampleRate) == 0) return A2DP_NS_SAMP_FREQ; @@ -248,12 +249,12 @@ bool A2DP_VendorCodecTypeEqualsAptx(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptx(&aptx_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoAptx(&aptx_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -269,12 +270,12 @@ bool A2DP_VendorCodecEqualsAptx(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptx(&aptx_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoAptx(&aptx_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -295,7 +296,7 @@ int A2DP_VendorGetTrackSampleRateAptx(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptx(&aptx_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -311,7 +312,7 @@ int A2DP_VendorGetTrackBitsPerSampleAptx(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptx(&aptx_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -325,7 +326,7 @@ int A2DP_VendorGetTrackChannelCountAptx(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptx(&aptx_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -451,7 +452,7 @@ bool A2dpCodecConfigAptx::init() { // Load the encoder if (A2DP_VendorLoadEncoderAptx() != LOAD_SUCCESS) { - LOG_ERROR("%s: cannot load the encoder", __func__); + log::error("cannot load the encoder"); return false; } @@ -631,8 +632,7 @@ bool A2dpCodecConfigAptx::setCodecConfig(const uint8_t* p_peer_codec_info, tA2DP_STATUS status = A2DP_ParseInfoAptx(&peer_info_cie, p_peer_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } @@ -715,10 +715,9 @@ bool A2dpCodecConfigAptx::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.sample_rate == BTAV_A2DP_CODEC_SAMPLE_RATE_NONE) { - LOG_ERROR( - "%s: cannot match sample frequency: local caps = 0x%x " - "peer info = 0x%x", - __func__, a2dp_aptx_source_caps.sampleRate, peer_info_cie.sampleRate); + log::error( + "cannot match sample frequency: local caps = 0x{:x} peer info = 0x{:x}", + a2dp_aptx_source_caps.sampleRate, peer_info_cie.sampleRate); goto fail; } @@ -770,8 +769,8 @@ bool A2dpCodecConfigAptx::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.bits_per_sample == BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE) { - LOG_ERROR("%s: cannot match bits per sample: user preference = 0x%x", - __func__, codec_user_config_.bits_per_sample); + log::error("cannot match bits per sample: user preference = 0x{:x}", + codec_user_config_.bits_per_sample); goto fail; } @@ -841,10 +840,9 @@ bool A2dpCodecConfigAptx::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.channel_mode == BTAV_A2DP_CODEC_CHANNEL_MODE_NONE) { - LOG_ERROR( - "%s: cannot match channel mode: local caps = 0x%x " - "peer info = 0x%x", - __func__, a2dp_aptx_source_caps.channelMode, peer_info_cie.channelMode); + log::error( + "cannot match channel mode: local caps = 0x{:x} peer info = 0x{:x}", + a2dp_aptx_source_caps.channelMode, peer_info_cie.channelMode); goto fail; } @@ -921,8 +919,7 @@ bool A2dpCodecConfigAptx::setPeerCodecCapabilities( tA2DP_STATUS status = A2DP_ParseInfoAptx(&peer_info_cie, p_peer_codec_capabilities, true); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } diff --git a/system/stack/a2dp/a2dp_vendor_aptx_encoder.cc b/system/stack/a2dp/a2dp_vendor_aptx_encoder.cc index 3568492f0a..f39b205a04 100644 --- a/system/stack/a2dp/a2dp_vendor_aptx_encoder.cc +++ b/system/stack/a2dp/a2dp_vendor_aptx_encoder.cc @@ -18,6 +18,7 @@ #include "a2dp_vendor_aptx_encoder.h" +#include <bluetooth/log.h> #include <dlfcn.h> #include <inttypes.h> #include <stdio.h> @@ -32,6 +33,8 @@ #include "osi/include/allocator.h" #include "stack/include/bt_hdr.h" +using namespace bluetooth; + // // Encoder for aptX Source Codec // @@ -142,7 +145,7 @@ void a2dp_vendor_aptx_encoder_init( if (a2dp_aptx_encoder_cb.aptx_encoder_state != NULL) { aptx_api.init_func(a2dp_aptx_encoder_cb.aptx_encoder_state, 0); } else { - LOG_ERROR("%s: Cannot allocate aptX encoder state", __func__); + log::error("Cannot allocate aptX encoder state"); // TODO: Return an error? } @@ -167,10 +170,8 @@ static void a2dp_vendor_aptx_encoder_update(A2dpCodecConfig* a2dp_codec_config, *p_restart_output = false; *p_config_updated = false; if (!a2dp_codec_config->copyOutOtaCodecConfig(codec_info)) { - LOG_ERROR( - "%s: Cannot update the codec encoder for %s: " - "invalid codec config", - __func__, a2dp_codec_config->name().c_str()); + log::error("Cannot update the codec encoder for {}: invalid codec config", + a2dp_codec_config->name().c_str()); return; } const uint8_t* p_codec_info = codec_info; @@ -183,9 +184,9 @@ static void a2dp_vendor_aptx_encoder_update(A2dpCodecConfig* a2dp_codec_config, a2dp_codec_config->getAudioBitsPerSample(); p_feeding_params->channel_count = A2DP_VendorGetTrackChannelCountAptx(p_codec_info); - LOG_INFO("%s: sample_rate=%u bits_per_sample=%u channel_count=%u", __func__, - p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, - p_feeding_params->channel_count); + log::info("sample_rate={} bits_per_sample={} channel_count={}", + p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, + p_feeding_params->channel_count); a2dp_vendor_aptx_feeding_reset(); } @@ -220,8 +221,7 @@ static void aptx_init_framing_params(tAPTX_FRAMING_PARAMS* framing_params) { } } - LOG_INFO("%s: sleep_time_ns = %" PRIu64, __func__, - framing_params->sleep_time_ns); + log::info("{}: sleep_time_ns = %", PRIu64); } // @@ -275,12 +275,10 @@ static void aptx_update_framing_params(tAPTX_FRAMING_PARAMS* framing_params) { } } - LOG_VERBOSE("%s: sleep_time_ns = %" PRIu64 - " aptx_bytes = %u " - "pcm_bytes_per_read = %u pcm_reads = %u frame_size_counter = %u", - __func__, framing_params->sleep_time_ns, - framing_params->aptx_bytes, framing_params->pcm_bytes_per_read, - framing_params->pcm_reads, framing_params->frame_size_counter); + log::verbose( + "{}: sleep_time_ns = %", PRIu64 + " aptx_bytes = %u " + "pcm_bytes_per_read = %u pcm_reads = %u frame_size_counter = %u"); } void a2dp_vendor_aptx_feeding_reset(void) { @@ -328,13 +326,13 @@ void a2dp_vendor_aptx_send_frames(uint64_t timestamp_us) { a2dp_aptx_encoder_cb.stats.media_read_total_expected_read_bytes += expected_read_bytes; - LOG_VERBOSE("%s: PCM read of size %u", __func__, expected_read_bytes); + log::verbose("PCM read of size {}", expected_read_bytes); bytes_read = a2dp_aptx_encoder_cb.read_callback((uint8_t*)read_buffer16, expected_read_bytes); a2dp_aptx_encoder_cb.stats.media_read_total_actual_read_bytes += bytes_read; if (bytes_read < expected_read_bytes) { - LOG_WARN("%s: underflow at PCM reading: read %u bytes instead of %u", - __func__, bytes_read, expected_read_bytes); + log::warn("underflow at PCM reading: read {} bytes instead of {}", + bytes_read, expected_read_bytes); a2dp_aptx_encoder_cb.stats.media_read_total_dropped_packets++; osi_free(p_buf); return; @@ -352,8 +350,7 @@ void a2dp_vendor_aptx_send_frames(uint64_t timestamp_us) { const int COMPRESSION_RATIO = 4; size_t encoded_bytes = pcm_bytes_encoded / COMPRESSION_RATIO; p_buf->len += encoded_bytes; - LOG_VERBOSE("%s: encoded %zu PCM bytes to %zu", __func__, pcm_bytes_encoded, - encoded_bytes); + log::verbose("encoded {} PCM bytes to {}", pcm_bytes_encoded, encoded_bytes); // Update the RTP timestamp *((uint32_t*)(p_buf + 1)) = a2dp_aptx_encoder_cb.timestamp; diff --git a/system/stack/a2dp/a2dp_vendor_aptx_hd.cc b/system/stack/a2dp/a2dp_vendor_aptx_hd.cc index a8d0942706..965704cc07 100644 --- a/system/stack/a2dp/a2dp_vendor_aptx_hd.cc +++ b/system/stack/a2dp/a2dp_vendor_aptx_hd.cc @@ -26,6 +26,7 @@ #include "a2dp_vendor_aptx_hd.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <string.h> #include "a2dp_vendor.h" @@ -37,6 +38,8 @@ #include "osi/include/osi.h" #include "stack/include/bt_hdr.h" +using namespace bluetooth; + // data type for the aptX-HD Codec Information Element */ typedef struct { uint32_t vendorId; @@ -227,16 +230,16 @@ static tA2DP_STATUS A2DP_CodecInfoMatchesCapabilityAptxHd( /* parse configuration */ status = A2DP_ParseInfoAptxHd(&cfg_cie, p_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: parsing failed %d", __func__, status); + log::error("parsing failed {}", status); return status; } /* verify that each parameter is in range */ - LOG_VERBOSE("%s: FREQ peer: 0x%x, capability 0x%x", __func__, - cfg_cie.sampleRate, p_cap->sampleRate); - LOG_VERBOSE("%s: CH_MODE peer: 0x%x, capability 0x%x", __func__, - cfg_cie.channelMode, p_cap->channelMode); + log::verbose("FREQ peer: 0x{:x}, capability 0x{:x}", cfg_cie.sampleRate, + p_cap->sampleRate); + log::verbose("CH_MODE peer: 0x{:x}, capability 0x{:x}", cfg_cie.channelMode, + p_cap->channelMode); /* sampling frequency */ if ((cfg_cie.sampleRate & p_cap->sampleRate) == 0) return A2DP_NS_SAMP_FREQ; @@ -266,12 +269,12 @@ bool A2DP_VendorCodecTypeEqualsAptxHd(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptxHd(&aptx_hd_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoAptxHd(&aptx_hd_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -287,12 +290,12 @@ bool A2DP_VendorCodecEqualsAptxHd(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptxHd(&aptx_hd_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoAptxHd(&aptx_hd_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -314,7 +317,7 @@ int A2DP_VendorGetTrackSampleRateAptxHd(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptxHd(&aptx_hd_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -331,7 +334,7 @@ int A2DP_VendorGetTrackBitsPerSampleAptxHd(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptxHd(&aptx_hd_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -346,7 +349,7 @@ int A2DP_VendorGetTrackChannelCountAptxHd(const uint8_t* p_codec_info) { tA2DP_STATUS a2dp_status = A2DP_ParseInfoAptxHd(&aptx_hd_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -474,7 +477,7 @@ bool A2dpCodecConfigAptxHd::init() { // Load the encoder if (A2DP_VendorLoadEncoderAptxHd() != LOAD_SUCCESS) { - LOG_ERROR("%s: cannot load the encoder", __func__); + log::error("cannot load the encoder"); return false; } @@ -651,8 +654,7 @@ bool A2dpCodecConfigAptxHd::setCodecConfig(const uint8_t* p_peer_codec_info, tA2DP_STATUS status = A2DP_ParseInfoAptxHd(&peer_info_cie, p_peer_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } @@ -735,11 +737,9 @@ bool A2dpCodecConfigAptxHd::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.sample_rate == BTAV_A2DP_CODEC_SAMPLE_RATE_NONE) { - LOG_ERROR( - "%s: cannot match sample frequency: local caps = 0x%x " - "peer info = 0x%x", - __func__, a2dp_aptx_hd_source_caps.sampleRate, - peer_info_cie.sampleRate); + log::error( + "cannot match sample frequency: local caps = 0x{:x} peer info = 0x{:x}", + a2dp_aptx_hd_source_caps.sampleRate, peer_info_cie.sampleRate); goto fail; } @@ -791,8 +791,8 @@ bool A2dpCodecConfigAptxHd::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.bits_per_sample == BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE) { - LOG_ERROR("%s: cannot match bits per sample: user preference = 0x%x", - __func__, codec_user_config_.bits_per_sample); + log::error("cannot match bits per sample: user preference = 0x{:x}", + codec_user_config_.bits_per_sample); goto fail; } @@ -863,11 +863,9 @@ bool A2dpCodecConfigAptxHd::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.channel_mode == BTAV_A2DP_CODEC_CHANNEL_MODE_NONE) { - LOG_ERROR( - "%s: cannot match channel mode: local caps = 0x%x " - "peer info = 0x%x", - __func__, a2dp_aptx_hd_source_caps.channelMode, - peer_info_cie.channelMode); + log::error( + "cannot match channel mode: local caps = 0x{:x} peer info = 0x{:x}", + a2dp_aptx_hd_source_caps.channelMode, peer_info_cie.channelMode); goto fail; } @@ -951,8 +949,7 @@ bool A2dpCodecConfigAptxHd::setPeerCodecCapabilities( tA2DP_STATUS status = A2DP_ParseInfoAptxHd(&peer_info_cie, p_peer_codec_capabilities, true); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } diff --git a/system/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc b/system/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc index bfef8c2b5f..a399c2461f 100644 --- a/system/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc +++ b/system/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc @@ -18,6 +18,7 @@ #include "a2dp_vendor_aptx_hd_encoder.h" +#include <bluetooth/log.h> #include <dlfcn.h> #include <inttypes.h> #include <stdio.h> @@ -32,6 +33,8 @@ #include "osi/include/allocator.h" #include "stack/include/bt_hdr.h" +using namespace bluetooth; + // // Encoder for aptX-HD Source Codec // @@ -142,7 +145,7 @@ void a2dp_vendor_aptx_hd_encoder_init( if (a2dp_aptx_hd_encoder_cb.aptx_hd_encoder_state != NULL) { aptx_hd_api.init_func(a2dp_aptx_hd_encoder_cb.aptx_hd_encoder_state, 0); } else { - LOG_ERROR("%s: Cannot allocate aptX-HD encoder state", __func__); + log::error("Cannot allocate aptX-HD encoder state"); // TODO: Return an error? } @@ -166,10 +169,8 @@ static void a2dp_vendor_aptx_hd_encoder_update( *p_restart_output = false; *p_config_updated = false; if (!a2dp_codec_config->copyOutOtaCodecConfig(codec_info)) { - LOG_ERROR( - "%s: Cannot update the codec encoder for %s: " - "invalid codec config", - __func__, a2dp_codec_config->name().c_str()); + log::error("Cannot update the codec encoder for {}: invalid codec config", + a2dp_codec_config->name().c_str()); return; } const uint8_t* p_codec_info = codec_info; @@ -183,9 +184,9 @@ static void a2dp_vendor_aptx_hd_encoder_update( a2dp_codec_config->getAudioBitsPerSample(); p_feeding_params->channel_count = A2DP_VendorGetTrackChannelCountAptxHd(p_codec_info); - LOG_INFO("%s: sample_rate=%u bits_per_sample=%u channel_count=%u", __func__, - p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, - p_feeding_params->channel_count); + log::info("sample_rate={} bits_per_sample={} channel_count={}", + p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, + p_feeding_params->channel_count); a2dp_vendor_aptx_hd_feeding_reset(); } @@ -208,8 +209,7 @@ static void aptx_hd_init_framing_params( framing_params->sleep_time_ns = 9000000; - LOG_INFO("%s: sleep_time_ns = %" PRIu64, __func__, - framing_params->sleep_time_ns); + log::info("{}: sleep_time_ns = %", PRIu64); } // @@ -258,12 +258,10 @@ static void aptx_hd_update_framing_params( framing_params->frame_size_counter = 0; } - LOG_VERBOSE("%s: sleep_time_ns = %" PRIu64 - " aptx_hd_bytes = %u " - "pcm_bytes_per_read = %u pcm_reads = %u frame_size_counter = %u", - __func__, framing_params->sleep_time_ns, - framing_params->aptx_hd_bytes, framing_params->pcm_bytes_per_read, - framing_params->pcm_reads, framing_params->frame_size_counter); + log::verbose( + "{}: sleep_time_ns = %", PRIu64 + " aptx_hd_bytes = %u " + "pcm_bytes_per_read = %u pcm_reads = %u frame_size_counter = %u"); } void a2dp_vendor_aptx_hd_feeding_reset(void) { @@ -313,14 +311,14 @@ void a2dp_vendor_aptx_hd_send_frames(uint64_t timestamp_us) { a2dp_aptx_hd_encoder_cb.stats.media_read_total_expected_read_bytes += expected_read_bytes; - LOG_VERBOSE("%s: PCM read of size %u", __func__, expected_read_bytes); + log::verbose("PCM read of size {}", expected_read_bytes); bytes_read = a2dp_aptx_hd_encoder_cb.read_callback((uint8_t*)read_buffer32, expected_read_bytes); a2dp_aptx_hd_encoder_cb.stats.media_read_total_actual_read_bytes += bytes_read; if (bytes_read < expected_read_bytes) { - LOG_WARN("%s: underflow at PCM reading: read %u bytes instead of %u", - __func__, bytes_read, expected_read_bytes); + log::warn("underflow at PCM reading: read {} bytes instead of {}", + bytes_read, expected_read_bytes); a2dp_aptx_hd_encoder_cb.stats.media_read_total_dropped_packets++; osi_free(p_buf); return; @@ -339,8 +337,7 @@ void a2dp_vendor_aptx_hd_send_frames(uint64_t timestamp_us) { const int COMPRESSION_RATIO = 4; size_t encoded_bytes = pcm_bytes_encoded / COMPRESSION_RATIO; p_buf->len += encoded_bytes; - LOG_VERBOSE("%s: encoded %zu PCM bytes to %zu", __func__, pcm_bytes_encoded, - encoded_bytes); + log::verbose("encoded {} PCM bytes to {}", pcm_bytes_encoded, encoded_bytes); // Update the RTP timestamp *((uint32_t*)(p_buf + 1)) = a2dp_aptx_hd_encoder_cb.timestamp; diff --git a/system/stack/a2dp/a2dp_vendor_ldac.cc b/system/stack/a2dp/a2dp_vendor_ldac.cc index 72a7c7b836..356f5284ae 100644 --- a/system/stack/a2dp/a2dp_vendor_ldac.cc +++ b/system/stack/a2dp/a2dp_vendor_ldac.cc @@ -26,6 +26,7 @@ #include "a2dp_vendor_ldac.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <string.h> #include "a2dp_vendor_ldac_decoder.h" @@ -36,6 +37,8 @@ #include "osi/include/osi.h" #include "stack/include/bt_hdr.h" +using namespace bluetooth; + // data type for the LDAC Codec Information Element */ // NOTE: bits_per_sample is needed only for LDAC encoder initialization. typedef struct { @@ -279,16 +282,16 @@ static tA2DP_STATUS A2DP_CodecInfoMatchesCapabilityLdac( /* parse configuration */ status = A2DP_ParseInfoLdac(&cfg_cie, p_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: parsing failed %d", __func__, status); + log::error("parsing failed {}", status); return status; } /* verify that each parameter is in range */ - LOG_VERBOSE("%s: FREQ peer: 0x%x, capability 0x%x", __func__, - cfg_cie.sampleRate, p_cap->sampleRate); - LOG_VERBOSE("%s: CH_MODE peer: 0x%x, capability 0x%x", __func__, - cfg_cie.channelMode, p_cap->channelMode); + log::verbose("FREQ peer: 0x{:x}, capability 0x{:x}", cfg_cie.sampleRate, + p_cap->sampleRate); + log::verbose("CH_MODE peer: 0x{:x}, capability 0x{:x}", cfg_cie.channelMode, + p_cap->channelMode); /* sampling frequency */ if ((cfg_cie.sampleRate & p_cap->sampleRate) == 0) return A2DP_NS_SAMP_FREQ; @@ -318,12 +321,12 @@ bool A2DP_VendorCodecTypeEqualsLdac(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoLdac(&ldac_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoLdac(&ldac_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -339,12 +342,12 @@ bool A2DP_VendorCodecEqualsLdac(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoLdac(&ldac_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoLdac(&ldac_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -388,7 +391,7 @@ int A2DP_VendorGetTrackSampleRateLdac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoLdac(&ldac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -416,7 +419,7 @@ int A2DP_VendorGetTrackBitsPerSampleLdac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoLdac(&ldac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -444,7 +447,7 @@ int A2DP_VendorGetTrackChannelCountLdac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoLdac(&ldac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -466,7 +469,7 @@ int A2DP_VendorGetSinkTrackChannelTypeLdac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoLdac(&ldac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -488,7 +491,7 @@ int A2DP_VendorGetChannelModeCodeLdac(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoLdac(&ldac_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("%s: cannot decode codec information: %d", __func__, a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -699,7 +702,7 @@ bool A2dpCodecConfigLdacSource::init() { // Load the encoder if (!A2DP_VendorLoadEncoderLdac()) { - LOG_ERROR("%s: cannot load the encoder", __func__); + log::error("cannot load the encoder"); return false; } @@ -967,8 +970,7 @@ bool A2dpCodecConfigLdacBase::setCodecConfig(const uint8_t* p_peer_codec_info, tA2DP_STATUS status = A2DP_ParseInfoLdac(&peer_info_cie, p_peer_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } @@ -1099,10 +1101,9 @@ bool A2dpCodecConfigLdacBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.sample_rate == BTAV_A2DP_CODEC_SAMPLE_RATE_NONE) { - LOG_ERROR( - "%s: cannot match sample frequency: local caps = 0x%x " - "peer info = 0x%x", - __func__, p_a2dp_ldac_caps->sampleRate, peer_info_cie.sampleRate); + log::error( + "cannot match sample frequency: local caps = 0x{:x} peer info = 0x{:x}", + p_a2dp_ldac_caps->sampleRate, peer_info_cie.sampleRate); goto fail; } @@ -1174,10 +1175,10 @@ bool A2dpCodecConfigLdacBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.bits_per_sample == BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE) { - LOG_ERROR( - "%s: cannot match bits per sample: default = 0x%x " - "user preference = 0x%x", - __func__, a2dp_ldac_default_config.bits_per_sample, + log::error( + "cannot match bits per sample: default = 0x{:x} user preference = " + "0x{:x}", + a2dp_ldac_default_config.bits_per_sample, codec_user_config_.bits_per_sample); goto fail; } @@ -1261,10 +1262,9 @@ bool A2dpCodecConfigLdacBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.channel_mode == BTAV_A2DP_CODEC_CHANNEL_MODE_NONE) { - LOG_ERROR( - "%s: cannot match channel mode: local caps = 0x%x " - "peer info = 0x%x", - __func__, p_a2dp_ldac_caps->channelMode, peer_info_cie.channelMode); + log::error( + "cannot match channel mode: local caps = 0x{:x} peer info = 0x{:x}", + p_a2dp_ldac_caps->channelMode, peer_info_cie.channelMode); goto fail; } @@ -1334,8 +1334,7 @@ bool A2dpCodecConfigLdacBase::setPeerCodecCapabilities( tA2DP_STATUS status = A2DP_ParseInfoLdac(&peer_info_cie, p_peer_codec_capabilities, true); if (status != A2DP_SUCCESS) { - LOG_ERROR("%s: can't parse peer's capabilities: error = %d", __func__, - status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } @@ -1411,7 +1410,7 @@ bool A2dpCodecConfigLdacSink::init() { // Load the decoder if (!A2DP_VendorLoadDecoderLdac()) { - LOG_ERROR("%s: cannot load the decoder", __func__); + log::error("cannot load the decoder"); return false; } diff --git a/system/stack/a2dp/a2dp_vendor_ldac_decoder.cc b/system/stack/a2dp/a2dp_vendor_ldac_decoder.cc index 3b734520a5..6327ff42be 100644 --- a/system/stack/a2dp/a2dp_vendor_ldac_decoder.cc +++ b/system/stack/a2dp/a2dp_vendor_ldac_decoder.cc @@ -19,6 +19,7 @@ #include "a2dp_vendor_ldac_decoder.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <dlfcn.h> #include <ldacBT.h> #include <ldacBT_bco_for_fluoride.h> @@ -30,6 +31,13 @@ #include "os/log.h" #include "stack/include/bt_hdr.h" +using namespace bluetooth; + +namespace fmt { +template <> +struct formatter<LDACBT_SMPL_FMT_T> : enum_formatter<LDACBT_SMPL_FMT_T> {}; +} // namespace fmt + // // Decoder for LDAC Source Codec // @@ -100,8 +108,8 @@ static tA2DP_LDAC_DECODER_CB a2dp_ldac_decoder_cb; static void* load_func(const char* func_name) { void* func_ptr = dlsym(ldac_bco_lib_handle, func_name); if (func_ptr == NULL) { - LOG_ERROR("%s: cannot find function '%s' in the decoder library: %s", - __func__, func_name, dlerror()); + log::error("cannot find function '{}' in the decoder library: {}", + func_name, dlerror()); A2DP_VendorUnloadDecoderLdac(); return NULL; } @@ -119,8 +127,8 @@ bool A2DP_VendorLoadDecoderLdac(void) { // Open the decoder library ldac_bco_lib_handle = dlopen(LDAC_BCO_LIB_NAME, RTLD_NOW); if (ldac_bco_lib_handle == NULL) { - LOG_INFO("%s: cannot open LDAC decoder library %s: %s", __func__, - LDAC_BCO_LIB_NAME, dlerror()); + log::info("cannot open LDAC decoder library {}: {}", LDAC_BCO_LIB_NAME, + dlerror()); return false; } @@ -192,7 +200,7 @@ void a2dp_vendor_ldac_decoder_cleanup(void) { bool a2dp_vendor_ldac_decoder_decode_packet(BT_HDR* p_buf) { if (p_buf == nullptr) { - LOG_ERROR("%s Dropping packet with nullptr", __func__); + log::error("Dropping packet with nullptr"); return false; } pthread_mutex_lock(&(a2dp_ldac_decoder_cb.mutex)); @@ -202,7 +210,7 @@ bool a2dp_vendor_ldac_decoder_decode_packet(BT_HDR* p_buf) { unsigned int bytesValid = p_buf->len; if (bytesValid == 0) { pthread_mutex_unlock(&(a2dp_ldac_decoder_cb.mutex)); - LOG_WARN("%s Dropping packet with zero length", __func__); + log::warn("Dropping packet with zero length"); return false; } @@ -211,7 +219,7 @@ bool a2dp_vendor_ldac_decoder_decode_packet(BT_HDR* p_buf) { frame_number = (int)pBuffer[0]; bs_bytes = (int)bytesValid; bytesValid -= 1; - LOG_INFO("%s:INPUT size : %d, frame : %d", __func__, bs_bytes, frame_number); + log::info("INPUT size : {}, frame : {}", bs_bytes, frame_number); if (a2dp_ldac_decoder_cb.has_ldac_handle) ldac_BCO_decode_packet_func(a2dp_ldac_decoder_cb.ldac_handle_bco, pBuffer, @@ -223,7 +231,7 @@ bool a2dp_vendor_ldac_decoder_decode_packet(BT_HDR* p_buf) { void a2dp_vendor_ldac_decoder_start(void) { pthread_mutex_lock(&(a2dp_ldac_decoder_cb.mutex)); - LOG_INFO("%s", __func__); + log::info(""); if (a2dp_ldac_decoder_cb.has_ldac_handle) ldac_BCO_start_func(a2dp_ldac_decoder_cb.ldac_handle_bco); pthread_mutex_unlock(&(a2dp_ldac_decoder_cb.mutex)); @@ -231,7 +239,7 @@ void a2dp_vendor_ldac_decoder_start(void) { void a2dp_vendor_ldac_decoder_suspend(void) { pthread_mutex_lock(&(a2dp_ldac_decoder_cb.mutex)); - LOG_INFO("%s", __func__); + log::info(""); if (a2dp_ldac_decoder_cb.has_ldac_handle) ldac_BCO_suspend_func(a2dp_ldac_decoder_cb.ldac_handle_bco); pthread_mutex_unlock(&(a2dp_ldac_decoder_cb.mutex)); @@ -243,7 +251,7 @@ void a2dp_vendor_ldac_decoder_configure(const uint8_t* p_codec_info) { int32_t channel_mode; if (p_codec_info == NULL) { - LOG_ERROR("%s: p_codec_info is NULL", __func__); + log::error("p_codec_info is NULL"); return; } @@ -252,8 +260,8 @@ void a2dp_vendor_ldac_decoder_configure(const uint8_t* p_codec_info) { bits_per_sample = A2DP_VendorGetTrackBitsPerSampleLdac(p_codec_info); channel_mode = A2DP_VendorGetChannelModeCodeLdac(p_codec_info); - LOG_INFO("%s , sample_rate=%d, bits_per_sample=%d, channel_mode=%d", __func__, - sample_rate, bits_per_sample, channel_mode); + log::info(", sample_rate={}, bits_per_sample={}, channel_mode={}", + sample_rate, bits_per_sample, channel_mode); if (a2dp_ldac_decoder_cb.has_ldac_handle) ldac_BCO_configure_func(a2dp_ldac_decoder_cb.ldac_handle_bco, sample_rate, diff --git a/system/stack/a2dp/a2dp_vendor_ldac_encoder.cc b/system/stack/a2dp/a2dp_vendor_ldac_encoder.cc index 369e10b292..8a88a2d15b 100644 --- a/system/stack/a2dp/a2dp_vendor_ldac_encoder.cc +++ b/system/stack/a2dp/a2dp_vendor_ldac_encoder.cc @@ -22,6 +22,7 @@ #ifdef __ANDROID__ #include <cutils/trace.h> #endif +#include <bluetooth/log.h> #include <dlfcn.h> #include <inttypes.h> #include <ldacBT_abr.h> @@ -50,6 +51,13 @@ // offset #define A2DP_LDAC_OFFSET (AVDT_MEDIA_OFFSET + A2DP_LDAC_MPL_HDR_LEN) +using namespace bluetooth; + +namespace fmt { +template <> +struct formatter<LDACBT_SMPL_FMT_T> : enum_formatter<LDACBT_SMPL_FMT_T> {}; +} // namespace fmt + typedef struct { uint32_t sample_rate; uint8_t channel_mode; @@ -176,7 +184,7 @@ static void a2dp_vendor_ldac_encoder_update(A2dpCodecConfig* a2dp_codec_config, if (!a2dp_ldac_encoder_cb.has_ldac_handle) { a2dp_ldac_encoder_cb.ldac_handle = ldacBT_get_handle(); if (a2dp_ldac_encoder_cb.ldac_handle == NULL) { - LOG_ERROR("%s: Cannot get LDAC encoder handle", __func__); + log::error("Cannot get LDAC encoder handle"); return; // TODO: Return an error? } a2dp_ldac_encoder_cb.has_ldac_handle = true; @@ -184,10 +192,8 @@ static void a2dp_vendor_ldac_encoder_update(A2dpCodecConfig* a2dp_codec_config, CHECK(a2dp_ldac_encoder_cb.ldac_handle != nullptr); if (!a2dp_codec_config->copyOutOtaCodecConfig(codec_info)) { - LOG_ERROR( - "%s: Cannot update the codec encoder for %s: " - "invalid codec config", - __func__, a2dp_codec_config->name().c_str()); + log::error("Cannot update the codec encoder for {}: invalid codec config", + a2dp_codec_config->name().c_str()); return; } const uint8_t* p_codec_info = codec_info; @@ -201,9 +207,9 @@ static void a2dp_vendor_ldac_encoder_update(A2dpCodecConfig* a2dp_codec_config, a2dp_codec_config->getAudioBitsPerSample(); p_feeding_params->channel_count = A2DP_VendorGetTrackChannelCountLdac(p_codec_info); - LOG_INFO("%s: sample_rate=%u bits_per_sample=%u channel_count=%u", __func__, - p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, - p_feeding_params->channel_count); + log::info("sample_rate={} bits_per_sample={} channel_count={}", + p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, + p_feeding_params->channel_count); a2dp_vendor_ldac_feeding_reset(); // The codec parameters @@ -216,35 +222,32 @@ static void a2dp_vendor_ldac_encoder_update(A2dpCodecConfig* a2dp_codec_config, int old_quality_mode_index = p_encoder_params->quality_mode_index; if (codec_config.codec_specific_1 != 0) { p_encoder_params->quality_mode_index = codec_config.codec_specific_1 % 10; - LOG_INFO("%s: setting quality mode to %s", __func__, - quality_mode_index_to_name(p_encoder_params->quality_mode_index) - .c_str()); + log::info("setting quality mode to {}", + quality_mode_index_to_name(p_encoder_params->quality_mode_index) + .c_str()); } else { p_encoder_params->quality_mode_index = A2DP_LDAC_QUALITY_ABR; - LOG_INFO("%s: setting quality mode to default %s", __func__, - quality_mode_index_to_name(p_encoder_params->quality_mode_index) - .c_str()); + log::info("setting quality mode to default {}", + quality_mode_index_to_name(p_encoder_params->quality_mode_index) + .c_str()); } int ldac_eqmid = LDAC_ABR_MODE_EQMID; if (p_encoder_params->quality_mode_index == A2DP_LDAC_QUALITY_ABR) { if (!ldac_abr_loaded) { p_encoder_params->quality_mode_index = A2DP_LDAC_QUALITY_MID; - LOG_WARN( - - "%s: LDAC ABR library is not loaded, resetting quality mode to %s", - __func__, - quality_mode_index_to_name(p_encoder_params->quality_mode_index) - .c_str()); + log::warn("LDAC ABR library is not loaded, resetting quality mode to {}", + quality_mode_index_to_name(p_encoder_params->quality_mode_index) + .c_str()); } else { - LOG_INFO("%s: changing mode from %s to %s", __func__, - quality_mode_index_to_name(old_quality_mode_index).c_str(), - quality_mode_index_to_name(p_encoder_params->quality_mode_index) - .c_str()); + log::info("changing mode from {} to {}", + quality_mode_index_to_name(old_quality_mode_index).c_str(), + quality_mode_index_to_name(p_encoder_params->quality_mode_index) + .c_str()); if (a2dp_ldac_encoder_cb.ldac_abr_handle != NULL) { - LOG_INFO("%s: already in LDAC ABR mode, do nothing.", __func__); + log::info("already in LDAC ABR mode, do nothing."); } else { - LOG_INFO("%s: get and init LDAC ABR handle.", __func__); + log::info("get and init LDAC ABR handle."); a2dp_ldac_encoder_cb.ldac_abr_handle = ldac_ABR_get_handle(); if (a2dp_ldac_encoder_cb.ldac_abr_handle != NULL) { a2dp_ldac_encoder_cb.has_ldac_abr_handle = true; @@ -254,10 +257,8 @@ static void a2dp_vendor_ldac_encoder_update(A2dpCodecConfig* a2dp_codec_config, A2DP_LDAC_ENCODER_INTERVAL_MS); } else { p_encoder_params->quality_mode_index = A2DP_LDAC_QUALITY_MID; - LOG_INFO( - - "%s: get LDAC ABR handle failed, resetting quality mode to %s.", - __func__, + log::info( + "get LDAC ABR handle failed, resetting quality mode to {}.", quality_mode_index_to_name(p_encoder_params->quality_mode_index) .c_str()); } @@ -265,8 +266,8 @@ static void a2dp_vendor_ldac_encoder_update(A2dpCodecConfig* a2dp_codec_config, } } else { ldac_eqmid = p_encoder_params->quality_mode_index; - LOG_INFO("%s: in %s mode, free LDAC ABR handle.", __func__, - quality_mode_index_to_name(ldac_eqmid).c_str()); + log::info("in {} mode, free LDAC ABR handle.", + quality_mode_index_to_name(ldac_eqmid).c_str()); if (a2dp_ldac_encoder_cb.has_ldac_abr_handle) { ldac_ABR_free_handle(a2dp_ldac_encoder_cb.ldac_abr_handle); a2dp_ldac_encoder_cb.ldac_abr_handle = NULL; @@ -293,12 +294,12 @@ static void a2dp_vendor_ldac_encoder_update(A2dpCodecConfig* a2dp_codec_config, const tA2DP_ENCODER_INIT_PEER_PARAMS& peer_params = a2dp_ldac_encoder_cb.peer_params; a2dp_ldac_encoder_cb.TxAaMtuSize = adjust_effective_mtu(peer_params); - LOG_INFO("%s: MTU=%d, peer_mtu=%d", __func__, - a2dp_ldac_encoder_cb.TxAaMtuSize, peer_params.peer_mtu); - LOG_INFO( - "%s: sample_rate: %d channel_mode: %d " - "quality_mode_index: %d pcm_wlength: %d pcm_fmt: %d", - __func__, p_encoder_params->sample_rate, p_encoder_params->channel_mode, + log::info("MTU={}, peer_mtu={}", a2dp_ldac_encoder_cb.TxAaMtuSize, + peer_params.peer_mtu); + log::info( + "sample_rate: {} channel_mode: {} quality_mode_index: {} pcm_wlength: {} " + "pcm_fmt: {}", + p_encoder_params->sample_rate, p_encoder_params->channel_mode, p_encoder_params->quality_mode_index, p_encoder_params->pcm_wlength, p_encoder_params->pcm_fmt); @@ -311,10 +312,10 @@ static void a2dp_vendor_ldac_encoder_update(A2dpCodecConfig* a2dp_codec_config, p_encoder_params->sample_rate); if (result != 0) { int err_code = ldacBT_get_error_code(a2dp_ldac_encoder_cb.ldac_handle); - LOG_ERROR( - "%s: error initializing the LDAC encoder: %d api_error = %d " - "handle_error = %d block_error = %d error_code = 0x%x", - __func__, result, LDACBT_API_ERR(err_code), LDACBT_HANDLE_ERR(err_code), + log::error( + "error initializing the LDAC encoder: {} api_error = {} handle_error = " + "{} block_error = {} error_code = 0x{:x}", + result, LDACBT_API_ERR(err_code), LDACBT_HANDLE_ERR(err_code), LDACBT_BLOCK_ERR(err_code), err_code); } } @@ -341,8 +342,8 @@ void a2dp_vendor_ldac_feeding_reset(void) { A2DP_LDAC_ENCODER_INTERVAL_MS) / 1000; - LOG_INFO("%s: PCM bytes per tick %u", __func__, - a2dp_ldac_encoder_cb.ldac_feeding_state.bytes_per_tick); + log::info("PCM bytes per tick {}", + a2dp_ldac_encoder_cb.ldac_feeding_state.bytes_per_tick); } void a2dp_vendor_ldac_feeding_flush(void) { @@ -362,8 +363,8 @@ void a2dp_vendor_ldac_send_frames(uint64_t timestamp_us) { uint8_t nb_iterations = 0; a2dp_ldac_get_num_frame_iteration(&nb_iterations, &nb_frame, timestamp_us); - LOG_VERBOSE("%s: Sending %d frames per iteration, %d iterations", __func__, - nb_frame, nb_iterations); + log::verbose("Sending {} frames per iteration, {} iterations", nb_frame, + nb_iterations); if (nb_frame == 0) return; for (uint8_t counter = 0; counter < nb_iterations; counter++) { @@ -399,7 +400,7 @@ static void a2dp_ldac_get_num_frame_iteration(uint8_t* num_of_iterations, A2DP_LDAC_MEDIA_BYTES_PER_FRAME * a2dp_ldac_encoder_cb.feeding_params.channel_count * a2dp_ldac_encoder_cb.feeding_params.bits_per_sample / 8; - LOG_VERBOSE("%s: pcm_bytes_per_frame %u", __func__, pcm_bytes_per_frame); + log::verbose("pcm_bytes_per_frame {}", pcm_bytes_per_frame); uint32_t us_this_tick = A2DP_LDAC_ENCODER_INTERVAL_MS * 1000; uint64_t now_us = timestamp_us; @@ -418,8 +419,7 @@ static void a2dp_ldac_get_num_frame_iteration(uint8_t* num_of_iterations, result * pcm_bytes_per_frame; nof = result; - LOG_VERBOSE("%s: effective num of frames %u, iterations %u", __func__, nof, - noi); + log::verbose("effective num of frames {}, iterations {}", nof, noi); *num_of_frames = nof; *num_of_iterations = noi; @@ -471,7 +471,7 @@ static void a2dp_ldac_encode_frames(uint8_t nb_frame) { bytes_read += temp_bytes_read; uint8_t* packet = (uint8_t*)(p_buf + 1) + p_buf->offset + p_buf->len; if (a2dp_ldac_encoder_cb.ldac_handle == NULL) { - LOG_ERROR("%s: invalid LDAC handle", __func__); + log::error("invalid LDAC handle"); a2dp_ldac_encoder_cb.stats.media_read_total_dropped_packets++; osi_free(p_buf); return; @@ -482,12 +482,11 @@ static void a2dp_ldac_encode_frames(uint8_t nb_frame) { if (result != 0) { int err_code = ldacBT_get_error_code(a2dp_ldac_encoder_cb.ldac_handle); - LOG_ERROR( - "%s: LDAC encoding error: %d api_error = %d " - "handle_error = %d block_error = %d error_code = 0x%x", - __func__, result, LDACBT_API_ERR(err_code), - LDACBT_HANDLE_ERR(err_code), LDACBT_BLOCK_ERR(err_code), - err_code); + log::error( + "LDAC encoding error: {} api_error = {} handle_error = {} " + "block_error = {} error_code = 0x{:x}", + result, LDACBT_API_ERR(err_code), LDACBT_HANDLE_ERR(err_code), + LDACBT_BLOCK_ERR(err_code), err_code); a2dp_ldac_encoder_cb.stats.media_read_total_dropped_packets++; osi_free(p_buf); return; @@ -497,7 +496,7 @@ static void a2dp_ldac_encode_frames(uint8_t nb_frame) { nb_frame--; p_buf->layer_specific += out_frames; // added a frame to the buffer } else { - LOG_WARN("%s: underflow %d", __func__, nb_frame); + log::warn("underflow {}", nb_frame); a2dp_ldac_encoder_cb.ldac_feeding_state.counter += nb_frame * LDACBT_ENC_LSU * a2dp_ldac_encoder_cb.feeding_params.channel_count * @@ -566,7 +565,7 @@ static uint16_t adjust_effective_mtu( if (mtu_size > peer_params.peer_mtu) { mtu_size = peer_params.peer_mtu; } - LOG_VERBOSE("%s: original AVDTP MTU size: %d", __func__, mtu_size); + log::verbose("original AVDTP MTU size: {}", mtu_size); return mtu_size; } diff --git a/system/stack/a2dp/a2dp_vendor_opus.cc b/system/stack/a2dp/a2dp_vendor_opus.cc index 7c8c22aac8..5b9c8b895a 100644 --- a/system/stack/a2dp/a2dp_vendor_opus.cc +++ b/system/stack/a2dp/a2dp_vendor_opus.cc @@ -26,6 +26,7 @@ #include "a2dp_vendor_opus.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <string.h> #include "a2dp_vendor_opus_decoder.h" @@ -35,6 +36,8 @@ #include "os/log.h" #include "osi/include/osi.h" +using namespace bluetooth; + // data type for the Opus Codec Information Element */ // NOTE: bits_per_sample and frameSize for Opus encoder initialization. typedef struct { @@ -129,7 +132,7 @@ static tA2DP_STATUS A2DP_BuildInfoOpus(uint8_t media_type, const tA2DP_OPUS_CIE* p_ie, uint8_t* p_result) { if (p_ie == NULL || p_result == NULL) { - LOG_ERROR("invalid information element"); + log::error("invalid information element"); return A2DP_INVALID_PARAMS; } @@ -148,19 +151,19 @@ static tA2DP_STATUS A2DP_BuildInfoOpus(uint8_t media_type, *p_result = 0; *p_result |= (uint8_t)(p_ie->channelMode) & A2DP_OPUS_CHANNEL_MODE_MASK; if ((*p_result & A2DP_OPUS_CHANNEL_MODE_MASK) == 0) { - LOG_ERROR("channelmode 0x%X setting failed", (p_ie->channelMode)); + log::error("channelmode 0x{:X} setting failed", (p_ie->channelMode)); return A2DP_INVALID_PARAMS; } *p_result |= ((uint8_t)(p_ie->future1) & A2DP_OPUS_FRAMESIZE_MASK); if ((*p_result & A2DP_OPUS_FRAMESIZE_MASK) == 0) { - LOG_ERROR("frameSize 0x%X setting failed", (p_ie->future1)); + log::error("frameSize 0x{:X} setting failed", (p_ie->future1)); return A2DP_INVALID_PARAMS; } *p_result |= ((uint8_t)(p_ie->sampleRate) & A2DP_OPUS_SAMPLING_FREQ_MASK); if ((*p_result & A2DP_OPUS_SAMPLING_FREQ_MASK) == 0) { - LOG_ERROR("samplerate 0x%X setting failed", (p_ie->sampleRate)); + log::error("samplerate 0x{:X} setting failed", (p_ie->sampleRate)); return A2DP_INVALID_PARAMS; } @@ -183,14 +186,14 @@ static tA2DP_STATUS A2DP_ParseInfoOpus(tA2DP_OPUS_CIE* p_ie, tA2DP_CODEC_TYPE codec_type; if (p_ie == NULL || p_codec_info == NULL) { - LOG_ERROR("unable to parse information element"); + log::error("unable to parse information element"); return A2DP_INVALID_PARAMS; } // Check the codec capability length losc = *p_codec_info++; if (losc != A2DP_OPUS_CODEC_LEN) { - LOG_ERROR("invalid codec ie length %d", losc); + log::error("invalid codec ie length {}", losc); return A2DP_WRONG_CODEC; } @@ -199,7 +202,7 @@ static tA2DP_STATUS A2DP_ParseInfoOpus(tA2DP_OPUS_CIE* p_ie, /* Check the Media Type and Media Codec Type */ if (media_type != AVDT_MEDIA_TYPE_AUDIO || codec_type != A2DP_MEDIA_CT_NON_A2DP) { - LOG_ERROR("invalid codec"); + log::error("invalid codec"); return A2DP_WRONG_CODEC; } @@ -214,7 +217,7 @@ static tA2DP_STATUS A2DP_ParseInfoOpus(tA2DP_OPUS_CIE* p_ie, p_codec_info += 2; if (p_ie->vendorId != A2DP_OPUS_VENDOR_ID || p_ie->codecId != A2DP_OPUS_CODEC_ID) { - LOG_ERROR("wrong vendor or codec id"); + log::error("wrong vendor or codec id"); return A2DP_WRONG_CODEC; } @@ -227,11 +230,11 @@ static tA2DP_STATUS A2DP_ParseInfoOpus(tA2DP_OPUS_CIE* p_ie, // NOTE: The checks here are very liberal. We should be using more // pedantic checks specific to the SRC or SNK as specified in the spec. if (A2DP_BitsSet(p_ie->sampleRate) == A2DP_SET_ZERO_BIT) { - LOG_ERROR("invalid sample rate 0x%X", p_ie->sampleRate); + log::error("invalid sample rate 0x{:X}", p_ie->sampleRate); return A2DP_BAD_SAMP_FREQ; } if (A2DP_BitsSet(p_ie->channelMode) == A2DP_SET_ZERO_BIT) { - LOG_ERROR("invalid channel mode"); + log::error("invalid channel mode"); return A2DP_BAD_CH_MODE; } @@ -239,11 +242,11 @@ static tA2DP_STATUS A2DP_ParseInfoOpus(tA2DP_OPUS_CIE* p_ie, } if (A2DP_BitsSet(p_ie->sampleRate) != A2DP_SET_ONE_BIT) { - LOG_ERROR("invalid sampling frequency 0x%X", p_ie->sampleRate); + log::error("invalid sampling frequency 0x{:X}", p_ie->sampleRate); return A2DP_BAD_SAMP_FREQ; } if (A2DP_BitsSet(p_ie->channelMode) != A2DP_SET_ONE_BIT) { - LOG_ERROR("invalid channel mode."); + log::error("invalid channel mode."); return A2DP_BAD_CH_MODE; } @@ -328,18 +331,18 @@ static tA2DP_STATUS A2DP_CodecInfoMatchesCapabilityOpus( /* parse configuration */ status = A2DP_ParseInfoOpus(&cfg_cie, p_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("parsing failed %d", status); + log::error("parsing failed {}", status); return status; } /* verify that each parameter is in range */ - LOG_VERBOSE("SAMPLING FREQ peer: 0x%x, capability 0x%x", cfg_cie.sampleRate, - p_cap->sampleRate); - LOG_VERBOSE("CH_MODE peer: 0x%x, capability 0x%x", cfg_cie.channelMode, - p_cap->channelMode); - LOG_VERBOSE("FRAMESIZE peer: 0x%x, capability 0x%x", cfg_cie.future1, - p_cap->future1); + log::verbose("SAMPLING FREQ peer: 0x{:x}, capability 0x{:x}", + cfg_cie.sampleRate, p_cap->sampleRate); + log::verbose("CH_MODE peer: 0x{:x}, capability 0x{:x}", cfg_cie.channelMode, + p_cap->channelMode); + log::verbose("FRAMESIZE peer: 0x{:x}, capability 0x{:x}", cfg_cie.future1, + p_cap->future1); /* sampling frequency */ if ((cfg_cie.sampleRate & p_cap->sampleRate) == 0) return A2DP_NS_SAMP_FREQ; @@ -371,12 +374,12 @@ bool A2DP_VendorCodecTypeEqualsOpus(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoOpus(&Opus_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoOpus(&Opus_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -392,12 +395,12 @@ bool A2DP_VendorCodecEqualsOpus(const uint8_t* p_codec_info_a, tA2DP_STATUS a2dp_status = A2DP_ParseInfoOpus(&Opus_cie_a, p_codec_info_a, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } a2dp_status = A2DP_ParseInfoOpus(&Opus_cie_b, p_codec_info_b, true); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return false; } @@ -431,7 +434,7 @@ int A2DP_VendorGetTrackSampleRateOpus(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoOpus(&Opus_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -449,7 +452,7 @@ int A2DP_VendorGetTrackBitsPerSampleOpus(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoOpus(&Opus_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -462,7 +465,7 @@ int A2DP_VendorGetTrackBitsPerSampleOpus(const uint8_t* p_codec_info) { return 32; case BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE: default: - LOG_ERROR("Invalid bit depth setting"); + log::error("Invalid bit depth setting"); return -1; } } @@ -473,7 +476,7 @@ int A2DP_VendorGetTrackChannelCountOpus(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoOpus(&Opus_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -484,7 +487,7 @@ int A2DP_VendorGetTrackChannelCountOpus(const uint8_t* p_codec_info) { case A2DP_OPUS_CHANNEL_MODE_DUAL_MONO: return 2; default: - LOG_ERROR("Invalid channel setting"); + log::error("Invalid channel setting"); } return -1; @@ -496,7 +499,7 @@ int A2DP_VendorGetSinkTrackChannelTypeOpus(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoOpus(&Opus_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -516,7 +519,7 @@ int A2DP_VendorGetChannelModeCodeOpus(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoOpus(&Opus_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } @@ -537,7 +540,7 @@ int A2DP_VendorGetFrameSizeOpus(const uint8_t* p_codec_info) { // Check whether the codec info contains valid data tA2DP_STATUS a2dp_status = A2DP_ParseInfoOpus(&Opus_cie, p_codec_info, false); if (a2dp_status != A2DP_SUCCESS) { - LOG_ERROR("cannot decode codec information: %d", a2dp_status); + log::error("cannot decode codec information: {}", a2dp_status); return -1; } int samplerate = A2DP_VendorGetTrackSampleRateOpus(p_codec_info); @@ -899,9 +902,8 @@ bool A2dpCodecConfigOpusBase::setCodecConfig(const uint8_t* p_peer_codec_info, btav_a2dp_codec_config_t device_codec_config_ = getCodecConfig(); - LOG_INFO( - "AudioManager stream config %d sample rate %d bit depth %d channel " - "mode", + log::info( + "AudioManager stream config {} sample rate {} bit depth {} channel mode", device_codec_config_.sample_rate, device_codec_config_.bits_per_sample, device_codec_config_.channel_mode); @@ -924,7 +926,7 @@ bool A2dpCodecConfigOpusBase::setCodecConfig(const uint8_t* p_peer_codec_info, tA2DP_STATUS status = A2DP_ParseInfoOpus(&peer_info_cie, p_peer_codec_info, is_capability); if (status != A2DP_SUCCESS) { - LOG_ERROR("can't parse peer's capabilities: error = %d", status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } @@ -996,9 +998,8 @@ bool A2dpCodecConfigOpusBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.sample_rate == BTAV_A2DP_CODEC_SAMPLE_RATE_NONE) { - LOG_ERROR( - "cannot match sample frequency: local caps = 0x%x " - "peer info = 0x%x", + log::error( + "cannot match sample frequency: local caps = 0x{:x} peer info = 0x{:x}", p_a2dp_opus_caps->sampleRate, peer_info_cie.sampleRate); goto fail; } @@ -1071,9 +1072,9 @@ bool A2dpCodecConfigOpusBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.bits_per_sample == BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE) { - LOG_ERROR( - "cannot match bits per sample: default = 0x%x " - "user preference = 0x%x", + log::error( + "cannot match bits per sample: default = 0x{:x} user preference = " + "0x{:x}", a2dp_opus_default_config.bits_per_sample, codec_user_config_.bits_per_sample); goto fail; @@ -1146,9 +1147,8 @@ bool A2dpCodecConfigOpusBase::setCodecConfig(const uint8_t* p_peer_codec_info, } } while (false); if (codec_config_.channel_mode == BTAV_A2DP_CODEC_CHANNEL_MODE_NONE) { - LOG_ERROR( - "cannot match channel mode: local caps = 0x%x " - "peer info = 0x%x", + log::error( + "cannot match channel mode: local caps = 0x{:x} peer info = 0x{:x}", p_a2dp_opus_caps->channelMode, peer_info_cie.channelMode); goto fail; } @@ -1187,16 +1187,15 @@ bool A2dpCodecConfigOpusBase::setCodecConfig(const uint8_t* p_peer_codec_info, result_config_cie.future3 = 0x00; if (codec_config_.codec_specific_1 == BTAV_A2DP_CODEC_FRAME_SIZE_NONE) { - LOG_ERROR( - "cannot match frame size: local caps = 0x%x " - "peer info = 0x%x", + log::error( + "cannot match frame size: local caps = 0x{:x} peer info = 0x{:x}", p_a2dp_opus_caps->future1, peer_info_cie.future1); goto fail; } if (A2DP_BuildInfoOpus(AVDT_MEDIA_TYPE_AUDIO, &result_config_cie, p_result_codec_config) != A2DP_SUCCESS) { - LOG_ERROR("failed to BuildInfoOpus for result_config_cie"); + log::error("failed to BuildInfoOpus for result_config_cie"); goto fail; } @@ -1262,7 +1261,7 @@ bool A2dpCodecConfigOpusBase::setPeerCodecCapabilities( tA2DP_STATUS status = A2DP_ParseInfoOpus(&peer_info_cie, p_peer_codec_capabilities, true); if (status != A2DP_SUCCESS) { - LOG_ERROR("can't parse peer's capabilities: error = %d", status); + log::error("can't parse peer's capabilities: error = {}", status); goto fail; } @@ -1288,7 +1287,7 @@ bool A2dpCodecConfigOpusBase::setPeerCodecCapabilities( BTAV_A2DP_CODEC_CHANNEL_MODE_STEREO; } - LOG_INFO("BuildInfoOpus for peer info cie for ota caps"); + log::info("BuildInfoOpus for peer info cie for ota caps"); status = A2DP_BuildInfoOpus(AVDT_MEDIA_TYPE_AUDIO, &peer_info_cie, ota_codec_peer_capability_); CHECK(status == A2DP_SUCCESS); diff --git a/system/stack/a2dp/a2dp_vendor_opus_decoder.cc b/system/stack/a2dp/a2dp_vendor_opus_decoder.cc index d36112bf0f..986b5b4dbe 100644 --- a/system/stack/a2dp/a2dp_vendor_opus_decoder.cc +++ b/system/stack/a2dp/a2dp_vendor_opus_decoder.cc @@ -19,12 +19,15 @@ #include "a2dp_vendor_opus_decoder.h" #include <base/logging.h> +#include <bluetooth/log.h> #include <opus.h> #include "a2dp_vendor_opus.h" #include "osi/include/allocator.h" #include "osi/include/log.h" +using namespace bluetooth; + typedef struct { OpusDecoder* opus_handle = nullptr; bool has_opus_handle; @@ -60,7 +63,7 @@ bool a2dp_vendor_opus_decoder_init(decoded_data_callback_t decode_callback) { a2dp_opus_decoder_cb.opus_handle = static_cast<OpusDecoder*>(osi_malloc(size)); if (a2dp_opus_decoder_cb.opus_handle == nullptr) { - LOG_ERROR("failed to allocate opus decoder handle"); + log::error("failed to allocate opus decoder handle"); return false; } err_val = opus_decoder_init(a2dp_opus_decoder_cb.opus_handle, @@ -75,10 +78,10 @@ bool a2dp_vendor_opus_decoder_init(decoded_data_callback_t decode_callback) { memset(a2dp_opus_decoder_cb.decode_buf, 0, A2DP_OPUS_DECODE_BUFFER_LENGTH); a2dp_opus_decoder_cb.decode_callback = decode_callback; - LOG_INFO("decoder init success"); + log::info("decoder init success"); return true; } else { - LOG_ERROR("failed to initialize Opus Decoder"); + log::error("failed to initialize Opus Decoder"); a2dp_opus_decoder_cb.has_opus_handle = false; return false; } @@ -96,12 +99,12 @@ bool a2dp_vendor_opus_decoder_decode_packet(BT_HDR* p_buf) { uint32_t frameLen = 0; if (p_buf == nullptr) { - LOG_ERROR("Dropping packet with nullptr"); + log::error("Dropping packet with nullptr"); return false; } if (p_buf->len == 0) { - LOG_ERROR("Empty packet"); + log::error("Empty packet"); return false; } @@ -117,10 +120,10 @@ bool a2dp_vendor_opus_decoder_decode_packet(BT_HDR* p_buf) { A2DP_OPUS_CODEC_DEFAULT_SAMPLERATE); uint32_t num_frames = pBuffer[0] & 0xf; - LOG_ERROR("numframes %d framesize %d framelen %d bufferSize %d", num_frames, - frameSize, frameLen, bufferSize); - LOG_ERROR("numChannels %d numFrames %d offset %d", numChannels, numFrames, - p_buf->offset); + log::error("numframes {} framesize {} framelen {} bufferSize {}", num_frames, + frameSize, frameLen, bufferSize); + log::error("numChannels {} numFrames {} offset {}", numChannels, numFrames, + p_buf->offset); for (uint32_t frame = 0; frame < numFrames; ++frame) { { @@ -132,15 +135,15 @@ bool a2dp_vendor_opus_decoder_decode_packet(BT_HDR* p_buf) { A2DP_OPUS_DECODE_BUFFER_LENGTH, 0 /* flags */); if (ret_val < OPUS_OK) { - LOG_ERROR("Opus DecodeFrame failed %d, applying concealment", ret_val); + log::error("Opus DecodeFrame failed {}, applying concealment", ret_val); ret_val = opus_decode(a2dp_opus_decoder_cb.opus_handle, NULL, 0, a2dp_opus_decoder_cb.decode_buf, A2DP_OPUS_DECODE_BUFFER_LENGTH, 0 /* flags */); } if (ret_val < OPUS_OK) { - LOG_ERROR("Opus DecodeFrame retry failed with %d, dropping packet", - ret_val); + log::error("Opus DecodeFrame retry failed with {}, dropping packet", + ret_val); return false; } @@ -163,7 +166,7 @@ void a2dp_vendor_opus_decoder_suspend(void) { err_val = opus_decoder_ctl(a2dp_opus_decoder_cb.opus_handle, OPUS_RESET_STATE); if (err_val != OPUS_OK) { - LOG_ERROR("failed to reset decoder"); + log::error("failed to reset decoder"); } } return; diff --git a/system/stack/a2dp/a2dp_vendor_opus_encoder.cc b/system/stack/a2dp/a2dp_vendor_opus_encoder.cc index 0be073772d..e8b59d0f84 100644 --- a/system/stack/a2dp/a2dp_vendor_opus_encoder.cc +++ b/system/stack/a2dp/a2dp_vendor_opus_encoder.cc @@ -18,6 +18,7 @@ #include "a2dp_vendor_opus_encoder.h" +#include <bluetooth/log.h> #include <dlfcn.h> #include <opus.h> #include <stdio.h> @@ -32,6 +33,8 @@ #include "osi/include/osi.h" #include "stack/include/bt_hdr.h" +using namespace bluetooth; + typedef struct { uint32_t sample_rate; uint16_t bitrate; @@ -138,7 +141,7 @@ void a2dp_vendor_opus_encoder_init( a2dp_opus_encoder_cb.opus_handle = static_cast<OpusEncoder*>(osi_malloc(size)); if (a2dp_opus_encoder_cb.opus_handle == nullptr) { - LOG_ERROR("failed to allocate opus encoder handle"); + log::error("failed to allocate opus encoder handle"); return; } @@ -147,9 +150,9 @@ void a2dp_vendor_opus_encoder_init( A2DP_OPUS_CODEC_OUTPUT_CHS, OPUS_APPLICATION_AUDIO); if (error_val != OPUS_OK) { - LOG_ERROR( - "failed to init opus encoder (handle size %d, sampling rate %d, " - "output chs %d, error %d)", + log::error( + "failed to init opus encoder (handle size {}, sampling rate {}, output " + "chs {}, error {})", size, A2DP_OPUS_CODEC_DEFAULT_SAMPLERATE, A2DP_OPUS_CODEC_OUTPUT_CHS, error_val); osi_free(a2dp_opus_encoder_cb.opus_handle); @@ -169,10 +172,8 @@ bool A2dpCodecConfigOpusSource::updateEncoderUserConfig( const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params, bool* p_restart_input, bool* p_restart_output, bool* p_config_updated) { if (a2dp_opus_encoder_cb.peer_mtu == 0) { - LOG_ERROR( - "Cannot update the codec encoder for %s: " - "invalid peer MTU", - name().c_str()); + log::error("Cannot update the codec encoder for {}: invalid peer MTU", + name().c_str()); return false; } @@ -197,16 +198,14 @@ static bool a2dp_vendor_opus_encoder_update(uint16_t peer_mtu, if (!a2dp_opus_encoder_cb.has_opus_handle || a2dp_opus_encoder_cb.opus_handle == NULL) { - LOG_ERROR("Cannot get Opus encoder handle"); + log::error("Cannot get Opus encoder handle"); return false; } CHECK(a2dp_opus_encoder_cb.opus_handle != nullptr); if (!a2dp_codec_config->copyOutOtaCodecConfig(codec_info)) { - LOG_ERROR( - "Cannot update the codec encoder for %s: " - "invalid codec config", - a2dp_codec_config->name().c_str()); + log::error("Cannot update the codec encoder for {}: invalid codec config", + a2dp_codec_config->name().c_str()); return false; } const uint8_t* p_codec_info = codec_info; @@ -220,9 +219,9 @@ static bool a2dp_vendor_opus_encoder_update(uint16_t peer_mtu, a2dp_codec_config->getAudioBitsPerSample(); p_feeding_params->channel_count = A2DP_VendorGetTrackChannelCountOpus(p_codec_info); - LOG_INFO("sample_rate=%u bits_per_sample=%u channel_count=%u", - p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, - p_feeding_params->channel_count); + log::info("sample_rate={} bits_per_sample={} channel_count={}", + p_feeding_params->sample_rate, p_feeding_params->bits_per_sample, + p_feeding_params->channel_count); // The codec parameters p_encoder_params->sample_rate = @@ -245,12 +244,12 @@ static bool a2dp_vendor_opus_encoder_update(uint16_t peer_mtu, // Set the bitrate quality mode index if (codec_config.codec_specific_3 != 0) { p_encoder_params->quality_mode_index = codec_config.codec_specific_3 % 10; - LOG_INFO("setting bitrate quality mode to %d", - p_encoder_params->quality_mode_index); + log::info("setting bitrate quality mode to {}", + p_encoder_params->quality_mode_index); } else { p_encoder_params->quality_mode_index = 5; - LOG_INFO("setting bitrate quality mode to default %d", - p_encoder_params->quality_mode_index); + log::info("setting bitrate quality mode to default {}", + p_encoder_params->quality_mode_index); } error = opus_encoder_ctl( @@ -258,19 +257,19 @@ static bool a2dp_vendor_opus_encoder_update(uint16_t peer_mtu, OPUS_SET_COMPLEXITY(p_encoder_params->quality_mode_index)); if (error != OPUS_OK) { - LOG_ERROR("failed to set encoder bitrate quality setting"); + log::error("failed to set encoder bitrate quality setting"); return false; } p_encoder_params->pcm_wlength = a2dp_opus_encoder_cb.feeding_params.bits_per_sample >> 3; - LOG_INFO("setting bitrate to %d", p_encoder_params->bitrate); + log::info("setting bitrate to {}", p_encoder_params->bitrate); error = opus_encoder_ctl(a2dp_opus_encoder_cb.opus_handle, OPUS_SET_BITRATE(p_encoder_params->bitrate)); if (error != OPUS_OK) { - LOG_ERROR("failed to set encoder bitrate"); + log::error("failed to set encoder bitrate"); return false; } @@ -392,7 +391,7 @@ static void a2dp_opus_encode_frames(uint8_t nb_frame) { packet = (unsigned char*)(p_buf + 1) + p_buf->offset + p_buf->len; if (a2dp_opus_encoder_cb.opus_handle == NULL) { - LOG_ERROR("invalid OPUS handle"); + log::error("invalid OPUS handle"); a2dp_opus_encoder_cb.stats.media_read_total_dropped_packets++; osi_free(p_buf); return; @@ -404,7 +403,7 @@ static void a2dp_opus_encode_frames(uint8_t nb_frame) { packet, (BT_DEFAULT_BUFFER_SIZE - p_buf->offset)); if (written <= 0) { - LOG_ERROR("OPUS encoding error"); + log::error("OPUS encoding error"); a2dp_opus_encoder_cb.stats.media_read_total_dropped_packets++; osi_free(p_buf); return; @@ -415,7 +414,7 @@ static void a2dp_opus_encode_frames(uint8_t nb_frame) { nb_frame--; p_buf->layer_specific += out_frames; // added a frame to the buffer } else { - LOG_WARN("Opus src buffer underflow %d", nb_frame); + log::warn("Opus src buffer underflow {}", nb_frame); a2dp_opus_encoder_cb.opus_feeding_state.counter += nb_frame * opus_frame_size * a2dp_opus_encoder_cb.feeding_params.channel_count * diff --git a/system/stack/include/sdp_status.h b/system/stack/include/sdp_status.h index cfb81f8efa..d71922cfdb 100644 --- a/system/stack/include/sdp_status.h +++ b/system/stack/include/sdp_status.h @@ -19,6 +19,7 @@ #pragma once #include <base/strings/stringprintf.h> +#include <bluetooth/log.h> #include <cstdint> @@ -85,3 +86,8 @@ inline std::string sdp_status_text(const tSDP_STATUS& status) { } } const auto sdp_result_text = sdp_status_text; + +namespace fmt { +template <> +struct formatter<tSDP_STATUS> : enum_formatter<tSDP_STATUS> {}; +} // namespace fmt diff --git a/system/udrv/BUILD.gn b/system/udrv/BUILD.gn index 05561b89e2..2c872d6470 100644 --- a/system/udrv/BUILD.gn +++ b/system/udrv/BUILD.gn @@ -28,6 +28,7 @@ source_set("udrv") { configs += [ "//bt/system:target_defaults", + "//bt/system/log:log_defaults", ] deps = [ |