pts/avdtp_source: make ldac encoder optional

This commit is contained in:
Matthias Ringwald 2021-02-23 17:57:12 +01:00
parent e67b3e71a7
commit e73f3fda19

View File

@ -50,7 +50,10 @@
#include <fdk-aac/aacenc_lib.h> #include <fdk-aac/aacenc_lib.h>
#endif #endif
#ifdef HAVE_LDAC_ENCODER
#include <ldac/ldacBT.h> #include <ldac/ldacBT.h>
#endif
#define A2DP_CODEC_VENDOR_ID_SONY 0x12d #define A2DP_CODEC_VENDOR_ID_SONY 0x12d
#define A2DP_SONY_CODEC_LDAC 0xaa #define A2DP_SONY_CODEC_LDAC 0xaa
@ -154,7 +157,9 @@ static HANDLE_AACENCODER handleAAC;
static AACENC_InfoStruct aacinf; static AACENC_InfoStruct aacinf;
#endif #endif
#ifdef HAVE_LDAC_ENCODER
HANDLE_LDAC_BT handleLDAC; HANDLE_LDAC_BT handleLDAC;
#endif
static a2dp_media_sending_context_t media_tracker; static a2dp_media_sending_context_t media_tracker;
@ -313,6 +318,7 @@ static void a2dp_demo_send_media_packet(void) {
case AVDTP_CODEC_MPEG_2_4_AAC: case AVDTP_CODEC_MPEG_2_4_AAC:
a2dp_demo_send_media_packet_aac(); a2dp_demo_send_media_packet_aac();
break; break;
#ifdef ENABLE_LDAC_ENCODER
case AVDTP_CODEC_NON_A2DP: case AVDTP_CODEC_NON_A2DP:
local_cap = sc.local_stream_endpoint->sep.capabilities.media_codec; local_cap = sc.local_stream_endpoint->sep.capabilities.media_codec;
uint32_t local_vendor_id = get_vendor_id(local_cap.media_codec_information); uint32_t local_vendor_id = get_vendor_id(local_cap.media_codec_information);
@ -320,6 +326,7 @@ static void a2dp_demo_send_media_packet(void) {
if (local_vendor_id == A2DP_CODEC_VENDOR_ID_SONY && local_codec_id == A2DP_SONY_CODEC_LDAC) if (local_vendor_id == A2DP_CODEC_VENDOR_ID_SONY && local_codec_id == A2DP_SONY_CODEC_LDAC)
a2dp_demo_send_media_packet_ldac(); a2dp_demo_send_media_packet_ldac();
break; break;
#endif
default: default:
// TODO: // TODO:
printf("Send media payload for %s not implemented yet\n", codec_name_for_type(sc.local_stream_endpoint->media_codec_type)); printf("Send media payload for %s not implemented yet\n", codec_name_for_type(sc.local_stream_endpoint->media_codec_type));
@ -420,6 +427,7 @@ static int fill_aac_audio_buffer(a2dp_media_sending_context_t *context) {
} }
#endif #endif
#ifdef ENABLE_LDAC_ENCODER
static int a2dp_demo_fill_ldac_audio_buffer(a2dp_media_sending_context_t *context) { static int a2dp_demo_fill_ldac_audio_buffer(a2dp_media_sending_context_t *context) {
int total_samples_read = 0; int total_samples_read = 0;
unsigned int num_audio_samples_per_ldac_buffer = LDACBT_ENC_LSU; unsigned int num_audio_samples_per_ldac_buffer = LDACBT_ENC_LSU;
@ -446,6 +454,7 @@ static int a2dp_demo_fill_ldac_audio_buffer(a2dp_media_sending_context_t *contex
} }
return total_samples_read; return total_samples_read;
} }
#endif
static void avdtp_audio_timeout_handler(btstack_timer_source_t * timer){ static void avdtp_audio_timeout_handler(btstack_timer_source_t * timer){
adtvp_media_codec_capabilities_t local_cap; adtvp_media_codec_capabilities_t local_cap;
@ -498,6 +507,7 @@ static void avdtp_audio_timeout_handler(btstack_timer_source_t * timer){
#endif #endif
case AVDTP_CODEC_ATRAC_FAMILY: case AVDTP_CODEC_ATRAC_FAMILY:
break; break;
#ifdef ENABLE_LDAC_ENCODER
case AVDTP_CODEC_NON_A2DP: case AVDTP_CODEC_NON_A2DP:
local_cap = sc.local_stream_endpoint->sep.capabilities.media_codec; local_cap = sc.local_stream_endpoint->sep.capabilities.media_codec;
uint32_t local_vendor_id = get_vendor_id(local_cap.media_codec_information); uint32_t local_vendor_id = get_vendor_id(local_cap.media_codec_information);
@ -515,6 +525,7 @@ static void avdtp_audio_timeout_handler(btstack_timer_source_t * timer){
} }
} }
break; break;
#endif
default: default:
break; break;
} }
@ -1090,6 +1101,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
vendor_id = get_vendor_id(codec_info); vendor_id = get_vendor_id(codec_info);
codec_id = get_codec_id(codec_info); codec_id = get_codec_id(codec_info);
#ifdef HAVE_LDAC_ENCODER
// LDAC // LDAC
if (vendor_id == A2DP_CODEC_VENDOR_ID_SONY && codec_id == A2DP_SONY_CODEC_LDAC) { if (vendor_id == A2DP_CODEC_VENDOR_ID_SONY && codec_id == A2DP_SONY_CODEC_LDAC) {
ldac_configuration.reconfigure = a2dp_subevent_signaling_media_codec_other_configuration_get_reconfigure(packet); ldac_configuration.reconfigure = a2dp_subevent_signaling_media_codec_other_configuration_get_reconfigure(packet);
@ -1115,7 +1127,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
} }
current_sample_rate = ldac_configuration.sampling_frequency; current_sample_rate = ldac_configuration.sampling_frequency;
} else { } else
#endif
{
printf("Config not handled for %s\n", codec_name_for_type(remote_seps[selected_remote_sep_index].sep.capabilities.media_codec.media_codec_type)); printf("Config not handled for %s\n", codec_name_for_type(remote_seps[selected_remote_sep_index].sep.capabilities.media_codec.media_codec_type));
} }
break; break;
@ -1407,12 +1421,14 @@ int btstack_main(int argc, const char * argv[]){
// - MPEG1/2 Layer 3 // - MPEG1/2 Layer 3
// .. // ..
#ifdef HAVE_LDAC_ENCODER
// - LDAC // - LDAC
stream_endpoint = a2dp_source_create_stream_endpoint(AVDTP_AUDIO, AVDTP_CODEC_NON_A2DP, (uint8_t *) media_ldac_codec_capabilities, sizeof(media_ldac_codec_capabilities), (uint8_t*) local_stream_endpoint_ldac_media_codec_configuration, sizeof(local_stream_endpoint_ldac_media_codec_configuration)); stream_endpoint = a2dp_source_create_stream_endpoint(AVDTP_AUDIO, AVDTP_CODEC_NON_A2DP, (uint8_t *) media_ldac_codec_capabilities, sizeof(media_ldac_codec_capabilities), (uint8_t*) local_stream_endpoint_ldac_media_codec_configuration, sizeof(local_stream_endpoint_ldac_media_codec_configuration));
btstack_assert(stream_endpoint != NULL); btstack_assert(stream_endpoint != NULL);
stream_endpoint->media_codec_configuration_info = local_stream_endpoint_ldac_media_codec_configuration; stream_endpoint->media_codec_configuration_info = local_stream_endpoint_ldac_media_codec_configuration;
stream_endpoint->media_codec_configuration_len = sizeof(local_stream_endpoint_ldac_media_codec_configuration); stream_endpoint->media_codec_configuration_len = sizeof(local_stream_endpoint_ldac_media_codec_configuration);
avdtp_source_register_delay_reporting_category(avdtp_local_seid(stream_endpoint)); avdtp_source_register_delay_reporting_category(avdtp_local_seid(stream_endpoint));
#endif
// Initialize SDP // Initialize SDP
sdp_init(); sdp_init();