Loading system/stack/btm/btm_sco_hci.cc +5 −1 Original line number Diff line number Diff line Loading @@ -147,6 +147,8 @@ struct tBTM_MSBC_INFO { size_t encode_buf_wo; /* Write offset of the encode buffer */ size_t encode_buf_ro; /* Read offset of the encode buffer */ int16_t decoded_pcm_buf[120]; /* Buffer to store decoded PCM */ uint8_t num_encoded_msbc_pkts; /* Number of the encoded mSBC packets */ static size_t get_supported_packet_size(size_t pkt_size, size_t* buffer_size) { Loading Loading @@ -369,11 +371,13 @@ size_t decode(const uint8_t** out_data) { goto packet_loss; } if (!hfp_msbc_decoder_decode_packet(frame_head, out_data)) { if (!hfp_msbc_decoder_decode_packet(frame_head, msbc_info->decoded_pcm_buf, sizeof(msbc_info->decoded_pcm_buf))) { LOG_DEBUG("Decoding mSBC packet failed"); goto packet_loss; } *out_data = (const uint8_t*)msbc_info->decoded_pcm_buf; msbc_info->mark_pkt_decoded(); return BTM_MSBC_CODE_SIZE; Loading system/stack/btm/hfp_msbc_decoder.cc +14 −11 Original line number Diff line number Diff line Loading @@ -27,11 +27,11 @@ #include "osi/include/log.h" #define HFP_MSBC_PKT_LEN 60 #define HFP_MSBC_PCM_BYTES 240 typedef struct { OI_CODEC_SBC_DECODER_CONTEXT decoder_context; uint32_t context_data[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)]; int16_t decode_buf[120]; } tHFP_MSBC_DECODER; static tHFP_MSBC_DECODER hfp_msbc_decoder; Loading Loading @@ -61,26 +61,29 @@ void hfp_msbc_decoder_cleanup(void) { } // Get the HFP MSBC encoded maximum frame size bool hfp_msbc_decoder_decode_packet(const uint8_t* i_buf, const uint8_t** o_buf) { bool hfp_msbc_decoder_decode_packet(const uint8_t* i_buf, int16_t* o_buf, size_t out_len) { if (out_len < HFP_MSBC_PCM_BYTES) { LOG_ERROR( "Output buffer's size %lu is less than one complete mSBC frame %d", (unsigned long)out_len, HFP_MSBC_PCM_BYTES); return false; } const OI_BYTE* oi_data; uint32_t oi_size, out_avail; int16_t* out_ptr; oi_data = i_buf; oi_size = HFP_MSBC_PKT_LEN; out_avail = sizeof(hfp_msbc_decoder.decode_buf); out_ptr = hfp_msbc_decoder.decode_buf; out_avail = out_len; OI_STATUS status = OI_CODEC_SBC_DecodeFrame(&hfp_msbc_decoder.decoder_context, &oi_data, &oi_size, out_ptr, &out_avail); if (!OI_SUCCESS(status) || out_avail != 240 || oi_size != 0) { OI_STATUS status = OI_CODEC_SBC_DecodeFrame( &hfp_msbc_decoder.decoder_context, &oi_data, &oi_size, o_buf, &out_avail); if (!OI_SUCCESS(status) || out_avail != HFP_MSBC_PCM_BYTES || oi_size != 0) { LOG_ERROR("Decoding failure: %d, %lu, %lu", status, (unsigned long)out_avail, (unsigned long)oi_size); return false; } *o_buf = (const uint8_t*)&hfp_msbc_decoder.decode_buf; return true; } system/stack/include/hfp_msbc_decoder.h +6 −4 Original line number Diff line number Diff line Loading @@ -21,7 +21,8 @@ #ifndef HFP_MSBC_DECODER_H #define HFP_MSBC_DECODER_H #include <stdint.h> #include <cstddef> #include <cstdint> // Initialize the HFP MSBC decoder. bool hfp_msbc_decoder_init(void); Loading @@ -29,8 +30,9 @@ bool hfp_msbc_decoder_init(void); // Cleanup the HFP MSBC decoder. void hfp_msbc_decoder_cleanup(void); // Decodes |i_buf|. |o_buf| will be assigned to the decoded frames if available. bool hfp_msbc_decoder_decode_packet(const uint8_t* i_buf, const uint8_t** o_buf); // Decodes |i_buf| into |o_buf| with size |out_len| in bytes. |i_buf| should // point to a complete mSBC packet with 60 bytes of data including the header. bool hfp_msbc_decoder_decode_packet(const uint8_t* i_buf, int16_t* o_buf, size_t out_len); #endif // HFP_MSBC_DECODER_H Loading
system/stack/btm/btm_sco_hci.cc +5 −1 Original line number Diff line number Diff line Loading @@ -147,6 +147,8 @@ struct tBTM_MSBC_INFO { size_t encode_buf_wo; /* Write offset of the encode buffer */ size_t encode_buf_ro; /* Read offset of the encode buffer */ int16_t decoded_pcm_buf[120]; /* Buffer to store decoded PCM */ uint8_t num_encoded_msbc_pkts; /* Number of the encoded mSBC packets */ static size_t get_supported_packet_size(size_t pkt_size, size_t* buffer_size) { Loading Loading @@ -369,11 +371,13 @@ size_t decode(const uint8_t** out_data) { goto packet_loss; } if (!hfp_msbc_decoder_decode_packet(frame_head, out_data)) { if (!hfp_msbc_decoder_decode_packet(frame_head, msbc_info->decoded_pcm_buf, sizeof(msbc_info->decoded_pcm_buf))) { LOG_DEBUG("Decoding mSBC packet failed"); goto packet_loss; } *out_data = (const uint8_t*)msbc_info->decoded_pcm_buf; msbc_info->mark_pkt_decoded(); return BTM_MSBC_CODE_SIZE; Loading
system/stack/btm/hfp_msbc_decoder.cc +14 −11 Original line number Diff line number Diff line Loading @@ -27,11 +27,11 @@ #include "osi/include/log.h" #define HFP_MSBC_PKT_LEN 60 #define HFP_MSBC_PCM_BYTES 240 typedef struct { OI_CODEC_SBC_DECODER_CONTEXT decoder_context; uint32_t context_data[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)]; int16_t decode_buf[120]; } tHFP_MSBC_DECODER; static tHFP_MSBC_DECODER hfp_msbc_decoder; Loading Loading @@ -61,26 +61,29 @@ void hfp_msbc_decoder_cleanup(void) { } // Get the HFP MSBC encoded maximum frame size bool hfp_msbc_decoder_decode_packet(const uint8_t* i_buf, const uint8_t** o_buf) { bool hfp_msbc_decoder_decode_packet(const uint8_t* i_buf, int16_t* o_buf, size_t out_len) { if (out_len < HFP_MSBC_PCM_BYTES) { LOG_ERROR( "Output buffer's size %lu is less than one complete mSBC frame %d", (unsigned long)out_len, HFP_MSBC_PCM_BYTES); return false; } const OI_BYTE* oi_data; uint32_t oi_size, out_avail; int16_t* out_ptr; oi_data = i_buf; oi_size = HFP_MSBC_PKT_LEN; out_avail = sizeof(hfp_msbc_decoder.decode_buf); out_ptr = hfp_msbc_decoder.decode_buf; out_avail = out_len; OI_STATUS status = OI_CODEC_SBC_DecodeFrame(&hfp_msbc_decoder.decoder_context, &oi_data, &oi_size, out_ptr, &out_avail); if (!OI_SUCCESS(status) || out_avail != 240 || oi_size != 0) { OI_STATUS status = OI_CODEC_SBC_DecodeFrame( &hfp_msbc_decoder.decoder_context, &oi_data, &oi_size, o_buf, &out_avail); if (!OI_SUCCESS(status) || out_avail != HFP_MSBC_PCM_BYTES || oi_size != 0) { LOG_ERROR("Decoding failure: %d, %lu, %lu", status, (unsigned long)out_avail, (unsigned long)oi_size); return false; } *o_buf = (const uint8_t*)&hfp_msbc_decoder.decode_buf; return true; }
system/stack/include/hfp_msbc_decoder.h +6 −4 Original line number Diff line number Diff line Loading @@ -21,7 +21,8 @@ #ifndef HFP_MSBC_DECODER_H #define HFP_MSBC_DECODER_H #include <stdint.h> #include <cstddef> #include <cstdint> // Initialize the HFP MSBC decoder. bool hfp_msbc_decoder_init(void); Loading @@ -29,8 +30,9 @@ bool hfp_msbc_decoder_init(void); // Cleanup the HFP MSBC decoder. void hfp_msbc_decoder_cleanup(void); // Decodes |i_buf|. |o_buf| will be assigned to the decoded frames if available. bool hfp_msbc_decoder_decode_packet(const uint8_t* i_buf, const uint8_t** o_buf); // Decodes |i_buf| into |o_buf| with size |out_len| in bytes. |i_buf| should // point to a complete mSBC packet with 60 bytes of data including the header. bool hfp_msbc_decoder_decode_packet(const uint8_t* i_buf, int16_t* o_buf, size_t out_len); #endif // HFP_MSBC_DECODER_H