hfp: move hfp_h2_framing into hfp_codec

This commit is contained in:
Matthias Ringwald 2023-03-02 11:45:52 +01:00
parent 360d44f609
commit bcdbf70421
4 changed files with 48 additions and 47 deletions

View File

@ -2105,29 +2105,6 @@ void hfp_register_custom_ag_command(hfp_custom_at_command_t * custom_at_command)
btstack_linked_list_add(&hfp_custom_commands_ag, (btstack_linked_item_t *) custom_at_command);
}
// HFP H2 Framing - might get moved into a hfp_h2.c
// const
static const uint8_t hfp_h2_header_h2_byte_0 = 1;
static const uint8_t hfp_h2_header_h2_byte_1_table[] = {0x08, 0x38, 0xc8, 0xf8 };
void hfp_h2_framing_init(hfp_h2_framing_t * hfp_h2_framing){
hfp_h2_framing->sequence_number = 0;
}
/**
* @brief Add next H2 Header
* @param hfp_h2_framing
* @param buffer [2]
*/
void hfp_h2_framing_add_header(hfp_h2_framing_t * hfp_h2_framing, uint8_t * buffer){
// Synchronization Header H2
buffer[0] = hfp_h2_header_h2_byte_0;
buffer[1] = hfp_h2_header_h2_byte_1_table[hfp_h2_framing->sequence_number];
hfp_h2_framing->sequence_number = (hfp_h2_framing->sequence_number + 1) & 3;
}
// HFP H2 Synchronization - might get moved into a hfp_h2.c
// find position of h2 sync header, returns -1 if not found, or h2 sync position

View File

@ -760,29 +760,7 @@ int get_bit(uint16_t bitmap, int position);
int store_bit(uint32_t bitmap, int position, uint8_t value);
// UTILS_END
// HFP H2
#define HFP_H2_SYNC_FRAME_SIZE 60
// HFP H2 Framing
typedef struct {
uint8_t sequence_number;
} hfp_h2_framing_t;
/**
* @brief Init HFP H2 Framing state
* @param hfp_h2_framing
*/
void hfp_h2_framing_init(hfp_h2_framing_t * hfp_h2_framing);
/**
* @brief Add next H2 Header
* @param hfp_h2_framing
* @param buffer [2]
*/
void hfp_h2_framing_add_header(hfp_h2_framing_t * hfp_h2_framing, uint8_t * buffer);
// HFP H2 Synchronization
typedef struct {
// callback returns true if data was valid

View File

@ -64,6 +64,28 @@ static void hfp_codec_encode_msbc(hfp_codec_t * hfp_codec, int16_t * pcm_samples
static void hfp_codec_encode_lc3swb(hfp_codec_t * hfp_codec, int16_t * pcm_samples);
#endif
// HFP H2 Framing - might get moved into a hfp_h2.c
// const
static const uint8_t hfp_h2_header_h2_byte_0 = 1;
static const uint8_t hfp_h2_header_h2_byte_1_table[] = {0x08, 0x38, 0xc8, 0xf8 };
void hfp_h2_framing_init(hfp_h2_framing_t * hfp_h2_framing){
hfp_h2_framing->sequence_number = 0;
}
/**
* @brief Add next H2 Header
* @param hfp_h2_framing
* @param buffer [2]
*/
void hfp_h2_framing_add_header(hfp_h2_framing_t * hfp_h2_framing, uint8_t * buffer){
// Synchronization Header H2
buffer[0] = hfp_h2_header_h2_byte_0;
buffer[1] = hfp_h2_header_h2_byte_1_table[hfp_h2_framing->sequence_number];
hfp_h2_framing->sequence_number = (hfp_h2_framing->sequence_number + 1) & 3;
}
void hfp_codec_init(hfp_codec_t * hfp_codec, uint8_t codec_id){
memset(hfp_codec, 0, sizeof(hfp_codec_t));

View File

@ -44,9 +44,8 @@
#define HFP_CODEC_H
#include "btstack_config.h"
#include "hfp.h" // hfp_h2_framing
#include <stdint.h>
#include "hfp.h" // HFP_CODEC_xxx
#ifdef ENABLE_HFP_WIDE_BAND_SPEECH
#include "btstack_sbc.h"
@ -56,12 +55,37 @@
#include "btstack_lc3_google.h"
#endif
#include <stdint.h>
#if defined __cplusplus
extern "C" {
#endif
#define SCO_FRAME_SIZE 60
// HFP H2
#define HFP_H2_SYNC_FRAME_SIZE 60
// HFP H2 Framing
typedef struct {
uint8_t sequence_number;
} hfp_h2_framing_t;
/**
* @brief Init HFP H2 Framing state
* @param hfp_h2_framing
*/
void hfp_h2_framing_init(hfp_h2_framing_t * hfp_h2_framing);
/**
* @brief Add next H2 Header
* @param hfp_h2_framing
* @param buffer [2]
*/
void hfp_h2_framing_add_header(hfp_h2_framing_t * hfp_h2_framing, uint8_t * buffer);
struct hfp_codec {
// to allow for 24 byte USB payloads, we encode up to two SCO packets
uint8_t sco_packet[2*SCO_FRAME_SIZE];