mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-30 15:32:41 +00:00
avdtp: move helper to set/get configuration into avdtp_util
This commit is contained in:
parent
ea66f9a565
commit
fdd788fee8
@ -778,164 +778,6 @@ uint8_t a2dp_source_stream_send_media_packet(uint16_t a2dp_cid, uint8_t local_se
|
|||||||
return avdtp_source_stream_send_media_packet(a2dp_cid, local_seid, packet, size);
|
return avdtp_source_stream_send_media_packet(a2dp_cid, local_seid, packet, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void avdtp_config_sbc_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz){
|
|
||||||
avdtp_sbc_sampling_frequency_t sampling_frequency;
|
|
||||||
switch (sampling_frequency_hz){
|
|
||||||
case 16000:
|
|
||||||
sampling_frequency = AVDTP_SBC_16000;
|
|
||||||
break;
|
|
||||||
case 32000:
|
|
||||||
sampling_frequency = AVDTP_SBC_32000;
|
|
||||||
break;
|
|
||||||
case 48000:
|
|
||||||
sampling_frequency = AVDTP_SBC_48000;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sampling_frequency = AVDTP_SBC_44100;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
config[0] = (((uint8_t) sampling_frequency) << 4) | (config[0] & 0x0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void avdtp_config_sbc_store(uint8_t * config, uint16_t sampling_frequency_hz, avdtp_channel_mode_t channel_mode, uint8_t block_length, uint8_t subbands,
|
|
||||||
avdtp_sbc_allocation_method_t allocation_method, uint8_t min_bitpool_value, uint8_t max_bitpool_value) {
|
|
||||||
avdtp_sbc_channel_mode_t sbc_channel_mode;
|
|
||||||
switch (channel_mode){
|
|
||||||
case AVDTP_CHANNEL_MODE_MONO:
|
|
||||||
sbc_channel_mode = AVDTP_SBC_MONO;
|
|
||||||
break;
|
|
||||||
case AVDTP_CHANNEL_MODE_DUAL_CHANNEL:
|
|
||||||
sbc_channel_mode = AVDTP_SBC_DUAL_CHANNEL;
|
|
||||||
break;
|
|
||||||
case AVDTP_CHANNEL_MODE_STEREO:
|
|
||||||
sbc_channel_mode = AVDTP_SBC_STEREO;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sbc_channel_mode = AVDTP_SBC_JOINT_STEREO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
config[0] = (uint8_t) sbc_channel_mode;
|
|
||||||
config[1] = (block_length << 4) | (subbands << 2) | allocation_method;
|
|
||||||
config[2] = min_bitpool_value;
|
|
||||||
config[3] = max_bitpool_value;
|
|
||||||
avdtp_config_sbc_set_sampling_frequency(config, sampling_frequency_hz);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void avdtp_config_mpeg_audio_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz) {
|
|
||||||
uint8_t sampling_frequency_index = 0;
|
|
||||||
switch (sampling_frequency_hz){
|
|
||||||
case 16000:
|
|
||||||
sampling_frequency_index = 5;
|
|
||||||
break;
|
|
||||||
case 22040:
|
|
||||||
sampling_frequency_index = 4;
|
|
||||||
break;
|
|
||||||
case 24000:
|
|
||||||
sampling_frequency_index = 3;
|
|
||||||
break;
|
|
||||||
case 32000:
|
|
||||||
sampling_frequency_index = 2;
|
|
||||||
break;
|
|
||||||
case 44100:
|
|
||||||
sampling_frequency_index = 1;
|
|
||||||
break;
|
|
||||||
case 48000:
|
|
||||||
sampling_frequency_index = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
config[1] = (config[1] & 0xC0) | (1 << sampling_frequency_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void avdtp_config_mpeg_audio_store(uint8_t * config, avdtp_mpeg_layer_t layer, uint8_t crc, avdtp_channel_mode_t channel_mode, uint8_t media_payload_format,
|
|
||||||
uint16_t sampling_frequency, uint8_t vbr, uint8_t bit_rate_index){
|
|
||||||
|
|
||||||
config[0] = (((uint8_t) layer) << 5) | ((crc & 0x01) << 4) | (1 << (channel_mode - AVDTP_CHANNEL_MODE_MONO));
|
|
||||||
config[1] = ((media_payload_format & 0x01) << 6) ;
|
|
||||||
uint16_t bit_rate_mask = 1 << bit_rate_index;
|
|
||||||
config[2] = ((vbr & 0x01) << 7) | ((bit_rate_mask >> 8) & 0x3f);
|
|
||||||
config[3] = bit_rate_mask & 0xff;
|
|
||||||
avdtp_config_mpeg_audio_set_sampling_frequency(config, sampling_frequency);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void avdtp_config_mpeg_aac_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz) {
|
|
||||||
uint16_t sampling_frequency_bitmap = 0;
|
|
||||||
uint8_t i;
|
|
||||||
const uint32_t aac_sampling_frequency_table[] = {
|
|
||||||
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000
|
|
||||||
};
|
|
||||||
for (i=0;i<12;i++){
|
|
||||||
if (sampling_frequency_hz == aac_sampling_frequency_table[i]){
|
|
||||||
sampling_frequency_bitmap = 1 << i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
config[1] = sampling_frequency_bitmap >> 4;
|
|
||||||
config[2] = ((sampling_frequency_bitmap & 0x0f) << 4) | (config[2] & 0x0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void avdtp_config_mpeg_aac_store(uint8_t * config, avdtp_aac_object_type_t object_type, uint32_t sampling_frequency, uint8_t channels, uint32_t bit_rate, uint8_t vbr) {
|
|
||||||
config[0] = 1 << (7 -(object_type - AVDTP_AAC_MPEG2_LC));
|
|
||||||
uint8_t channels_bitmap = 0;
|
|
||||||
switch (channels){
|
|
||||||
case 1:
|
|
||||||
channels_bitmap = 0x02;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
channels_bitmap = 0x01;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
config[2] = channels_bitmap << 2;
|
|
||||||
config[3] = ((vbr & 0x01) << 7) | ((bit_rate >> 16) & 0x7f);
|
|
||||||
config[4] = (bit_rate >> 8) & 0xff;
|
|
||||||
config[5] = bit_rate & 0xff;
|
|
||||||
avdtp_config_mpeg_aac_set_sampling_frequency(config, sampling_frequency);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void avdtp_config_atrac_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz) {
|
|
||||||
uint8_t fs_bitmap = 0;
|
|
||||||
switch (sampling_frequency_hz){
|
|
||||||
case 44100:
|
|
||||||
fs_bitmap = 2;
|
|
||||||
break;
|
|
||||||
case 48000:
|
|
||||||
fs_bitmap = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
config[1] = (fs_bitmap << 4) | (config[1] & 0x0F);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void avdtp_config_atrac_store(uint8_t * config, avdtp_atrac_version_t version, avdtp_channel_mode_t channel_mode, uint16_t sampling_frequency, uint8_t vbr,
|
|
||||||
uint8_t bit_rate_index, uint16_t maximum_sul) {
|
|
||||||
uint8_t channel_mode_bitamp = 0;
|
|
||||||
switch (channel_mode){
|
|
||||||
case AVDTP_CHANNEL_MODE_MONO:
|
|
||||||
channel_mode_bitamp = 4;
|
|
||||||
break;
|
|
||||||
case AVDTP_CHANNEL_MODE_DUAL_CHANNEL:
|
|
||||||
channel_mode_bitamp = 2;
|
|
||||||
break;
|
|
||||||
case AVDTP_CHANNEL_MODE_JOINT_STEREO:
|
|
||||||
channel_mode_bitamp = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
config[0] = ((version - AVDTP_ATRAC_VERSION_1 + 1) << 5) | (channel_mode_bitamp << 2);
|
|
||||||
uint32_t bit_rate_bitmap = 1 << (0x18 - bit_rate_index);
|
|
||||||
config[1] = ((vbr & 0x01) << 3) | ((bit_rate_bitmap >> 16) & 0x07);
|
|
||||||
config[2] = (bit_rate_bitmap >> 8) & 0xff;
|
|
||||||
config[3] = bit_rate_bitmap & 0xff;
|
|
||||||
config[4] = maximum_sul >> 8;
|
|
||||||
config[5] = maximum_sul & 0xff;
|
|
||||||
config[6] = 0;
|
|
||||||
avdtp_config_atrac_set_sampling_frequency(config, sampling_frequency);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t a2dp_source_config_init(uint8_t local_seid, uint8_t remote_seid, avdtp_media_codec_type_t codec_type) {
|
static uint8_t a2dp_source_config_init(uint8_t local_seid, uint8_t remote_seid, avdtp_media_codec_type_t codec_type) {
|
||||||
|
|
||||||
// lookup local stream endpoint
|
// lookup local stream endpoint
|
||||||
|
@ -1390,3 +1390,162 @@ void a2dp_emit_stream_event(btstack_packet_handler_t callback, uint16_t cid, uin
|
|||||||
event[pos++] = local_seid;
|
event[pos++] = local_seid;
|
||||||
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper to set/get configuration
|
||||||
|
void avdtp_config_sbc_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz){
|
||||||
|
avdtp_sbc_sampling_frequency_t sampling_frequency;
|
||||||
|
switch (sampling_frequency_hz){
|
||||||
|
case 16000:
|
||||||
|
sampling_frequency = AVDTP_SBC_16000;
|
||||||
|
break;
|
||||||
|
case 32000:
|
||||||
|
sampling_frequency = AVDTP_SBC_32000;
|
||||||
|
break;
|
||||||
|
case 48000:
|
||||||
|
sampling_frequency = AVDTP_SBC_48000;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sampling_frequency = AVDTP_SBC_44100;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
config[0] = (((uint8_t) sampling_frequency) << 4) | (config[0] & 0x0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void avdtp_config_sbc_store(uint8_t * config, uint16_t sampling_frequency_hz, avdtp_channel_mode_t channel_mode, uint8_t block_length, uint8_t subbands,
|
||||||
|
avdtp_sbc_allocation_method_t allocation_method, uint8_t min_bitpool_value, uint8_t max_bitpool_value) {
|
||||||
|
avdtp_sbc_channel_mode_t sbc_channel_mode;
|
||||||
|
switch (channel_mode){
|
||||||
|
case AVDTP_CHANNEL_MODE_MONO:
|
||||||
|
sbc_channel_mode = AVDTP_SBC_MONO;
|
||||||
|
break;
|
||||||
|
case AVDTP_CHANNEL_MODE_DUAL_CHANNEL:
|
||||||
|
sbc_channel_mode = AVDTP_SBC_DUAL_CHANNEL;
|
||||||
|
break;
|
||||||
|
case AVDTP_CHANNEL_MODE_STEREO:
|
||||||
|
sbc_channel_mode = AVDTP_SBC_STEREO;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sbc_channel_mode = AVDTP_SBC_JOINT_STEREO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
config[0] = (uint8_t) sbc_channel_mode;
|
||||||
|
config[1] = (block_length << 4) | (subbands << 2) | allocation_method;
|
||||||
|
config[2] = min_bitpool_value;
|
||||||
|
config[3] = max_bitpool_value;
|
||||||
|
avdtp_config_sbc_set_sampling_frequency(config, sampling_frequency_hz);
|
||||||
|
}
|
||||||
|
|
||||||
|
void avdtp_config_mpeg_audio_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz) {
|
||||||
|
uint8_t sampling_frequency_index = 0;
|
||||||
|
switch (sampling_frequency_hz){
|
||||||
|
case 16000:
|
||||||
|
sampling_frequency_index = 5;
|
||||||
|
break;
|
||||||
|
case 22040:
|
||||||
|
sampling_frequency_index = 4;
|
||||||
|
break;
|
||||||
|
case 24000:
|
||||||
|
sampling_frequency_index = 3;
|
||||||
|
break;
|
||||||
|
case 32000:
|
||||||
|
sampling_frequency_index = 2;
|
||||||
|
break;
|
||||||
|
case 44100:
|
||||||
|
sampling_frequency_index = 1;
|
||||||
|
break;
|
||||||
|
case 48000:
|
||||||
|
sampling_frequency_index = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
config[1] = (config[1] & 0xC0) | (1 << sampling_frequency_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void avdtp_config_mpeg_audio_store(uint8_t * config, avdtp_mpeg_layer_t layer, uint8_t crc, avdtp_channel_mode_t channel_mode, uint8_t media_payload_format,
|
||||||
|
uint16_t sampling_frequency, uint8_t vbr, uint8_t bit_rate_index){
|
||||||
|
|
||||||
|
config[0] = (((uint8_t) layer) << 5) | ((crc & 0x01) << 4) | (1 << (channel_mode - AVDTP_CHANNEL_MODE_MONO));
|
||||||
|
config[1] = ((media_payload_format & 0x01) << 6) ;
|
||||||
|
uint16_t bit_rate_mask = 1 << bit_rate_index;
|
||||||
|
config[2] = ((vbr & 0x01) << 7) | ((bit_rate_mask >> 8) & 0x3f);
|
||||||
|
config[3] = bit_rate_mask & 0xff;
|
||||||
|
avdtp_config_mpeg_audio_set_sampling_frequency(config, sampling_frequency);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void avdtp_config_mpeg_aac_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz) {
|
||||||
|
uint16_t sampling_frequency_bitmap = 0;
|
||||||
|
uint8_t i;
|
||||||
|
const uint32_t aac_sampling_frequency_table[] = {
|
||||||
|
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000
|
||||||
|
};
|
||||||
|
for (i=0;i<12;i++){
|
||||||
|
if (sampling_frequency_hz == aac_sampling_frequency_table[i]){
|
||||||
|
sampling_frequency_bitmap = 1 << i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config[1] = sampling_frequency_bitmap >> 4;
|
||||||
|
config[2] = ((sampling_frequency_bitmap & 0x0f) << 4) | (config[2] & 0x0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void avdtp_config_mpeg_aac_store(uint8_t * config, avdtp_aac_object_type_t object_type, uint32_t sampling_frequency, uint8_t channels, uint32_t bit_rate, uint8_t vbr) {
|
||||||
|
config[0] = 1 << (7 -(object_type - AVDTP_AAC_MPEG2_LC));
|
||||||
|
uint8_t channels_bitmap = 0;
|
||||||
|
switch (channels){
|
||||||
|
case 1:
|
||||||
|
channels_bitmap = 0x02;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
channels_bitmap = 0x01;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
config[2] = channels_bitmap << 2;
|
||||||
|
config[3] = ((vbr & 0x01) << 7) | ((bit_rate >> 16) & 0x7f);
|
||||||
|
config[4] = (bit_rate >> 8) & 0xff;
|
||||||
|
config[5] = bit_rate & 0xff;
|
||||||
|
avdtp_config_mpeg_aac_set_sampling_frequency(config, sampling_frequency);
|
||||||
|
}
|
||||||
|
|
||||||
|
void avdtp_config_atrac_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz) {
|
||||||
|
uint8_t fs_bitmap = 0;
|
||||||
|
switch (sampling_frequency_hz){
|
||||||
|
case 44100:
|
||||||
|
fs_bitmap = 2;
|
||||||
|
break;
|
||||||
|
case 48000:
|
||||||
|
fs_bitmap = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
config[1] = (fs_bitmap << 4) | (config[1] & 0x0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
void avdtp_config_atrac_store(uint8_t * config, avdtp_atrac_version_t version, avdtp_channel_mode_t channel_mode, uint16_t sampling_frequency, uint8_t vbr,
|
||||||
|
uint8_t bit_rate_index, uint16_t maximum_sul) {
|
||||||
|
uint8_t channel_mode_bitamp = 0;
|
||||||
|
switch (channel_mode){
|
||||||
|
case AVDTP_CHANNEL_MODE_MONO:
|
||||||
|
channel_mode_bitamp = 4;
|
||||||
|
break;
|
||||||
|
case AVDTP_CHANNEL_MODE_DUAL_CHANNEL:
|
||||||
|
channel_mode_bitamp = 2;
|
||||||
|
break;
|
||||||
|
case AVDTP_CHANNEL_MODE_JOINT_STEREO:
|
||||||
|
channel_mode_bitamp = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
config[0] = ((version - AVDTP_ATRAC_VERSION_1 + 1) << 5) | (channel_mode_bitamp << 2);
|
||||||
|
uint32_t bit_rate_bitmap = 1 << (0x18 - bit_rate_index);
|
||||||
|
config[1] = ((vbr & 0x01) << 3) | ((bit_rate_bitmap >> 16) & 0x07);
|
||||||
|
config[2] = (bit_rate_bitmap >> 8) & 0xff;
|
||||||
|
config[3] = bit_rate_bitmap & 0xff;
|
||||||
|
config[4] = maximum_sul >> 8;
|
||||||
|
config[5] = maximum_sul & 0xff;
|
||||||
|
config[6] = 0;
|
||||||
|
avdtp_config_atrac_set_sampling_frequency(config, sampling_frequency);
|
||||||
|
}
|
||||||
|
@ -117,6 +117,21 @@ void a2dp_replace_subevent_id_and_emit_cmd(btstack_packet_handler_t callback, ui
|
|||||||
|
|
||||||
void a2dp_emit_stream_event(btstack_packet_handler_t callback, uint16_t cid, uint8_t local_seid, uint8_t subevent_id);
|
void a2dp_emit_stream_event(btstack_packet_handler_t callback, uint16_t cid, uint8_t local_seid, uint8_t subevent_id);
|
||||||
|
|
||||||
|
|
||||||
|
// helper to set/get configuration
|
||||||
|
void avdtp_config_sbc_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz);
|
||||||
|
void avdtp_config_sbc_store(uint8_t * config, uint16_t sampling_frequency_hz, avdtp_channel_mode_t channel_mode, uint8_t block_length, uint8_t subbands,
|
||||||
|
avdtp_sbc_allocation_method_t allocation_method, uint8_t min_bitpool_value, uint8_t max_bitpool_value);
|
||||||
|
void avdtp_config_mpeg_audio_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz);
|
||||||
|
void avdtp_config_mpeg_audio_store(uint8_t * config, avdtp_mpeg_layer_t layer, uint8_t crc, avdtp_channel_mode_t channel_mode, uint8_t media_payload_format,
|
||||||
|
uint16_t sampling_frequency, uint8_t vbr, uint8_t bit_rate_index);
|
||||||
|
void avdtp_config_mpeg_aac_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz);
|
||||||
|
void avdtp_config_mpeg_aac_store(uint8_t * config, avdtp_aac_object_type_t object_type, uint32_t sampling_frequency, uint8_t channels, uint32_t bit_rate, uint8_t vbr);
|
||||||
|
void avdtp_config_atrac_set_sampling_frequency(uint8_t * config, uint16_t sampling_frequency_hz);
|
||||||
|
void avdtp_config_atrac_store(uint8_t * config, avdtp_atrac_version_t version, avdtp_channel_mode_t channel_mode, uint16_t sampling_frequency, uint8_t vbr,
|
||||||
|
uint8_t bit_rate_index, uint16_t maximum_sul);
|
||||||
|
|
||||||
|
|
||||||
#if defined __cplusplus
|
#if defined __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user