Skip to content

Commit

Permalink
a2dp: use ENABLE_A2DP_EXPLICIT_CONFIG instead of individual source + …
Browse files Browse the repository at this point in the history
…sink flags
  • Loading branch information
mringwal committed Mar 16, 2022
1 parent 5d2ab25 commit 72237cc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 76 deletions.
2 changes: 1 addition & 1 deletion doc/manual/docs-template/how_to.md
Expand Up @@ -118,7 +118,7 @@ ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY | Let application trigger sending IO Capab
ENABLE_EXPLICIT_LINK_KEY_REPLY | Let application trigger sending Link Key (Negative) Response, allows for asynchronous link key lookup
ENABLE_EXPLICIT_BR_EDR_SECURITY_MANAGER | Report BR/EDR Security Manager support in L2CAP Information Response
ENABLE_CLASSIC_OOB_PAIRING | Enable support for classic Out-of-Band (OOB) pairing
ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG | Let application configure stream endpoint (skip auto-config of SBC endpoint)
ENABLE_A2DP_EXPLICIT_CONFIG | Let application configure stream endpoint (skip auto-config of SBC endpoint)
ENABLE_AVDTP_ACCEPTOR_EXPLICIT_START_STREAM_CONFIRMATION | allow accept or reject of stream start on A2DP_SUBEVENT_START_STREAM_REQUESTED


Expand Down
95 changes: 22 additions & 73 deletions src/classic/a2dp.c
Expand Up @@ -54,6 +54,11 @@
#include "classic/avdtp_util.h"
#include "btstack_debug.h"

// ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG has been replaced by ENABLE_A2DP_EXPLICIT_CONFIG which is valid for both roles
#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
#error "Please define ENABLE_A2DP_EXPLICIT_CONFIG instead of ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG"
#endif

#define AVDTP_MAX_SEP_NUM 10
#define A2DP_SET_CONFIG_DELAY_MS 200

Expand Down Expand Up @@ -480,15 +485,8 @@ uint8_t a2dp_config_process_config_init(avdtp_role_t role, avdtp_connection_t *c
config_process->local_stream_endpoint = stream_endpoint;
config_process->have_config = true;

#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
// continue outgoing configuration
if ((role == AVDTP_ROLE_SOURCE) && (config_process->state == A2DP_DISCOVERY_DONE)){
config_process->state = A2DP_SET_CONFIGURATION;
}
#endif
#ifdef ENABLE_A2DP_SINK_EXPLICIT_CONFIG
// continue outgoing configuration
if ((role == AVDTP_ROLE_SINK) && (config_process->state == A2DP_DISCOVERY_DONE)){
#ifdef ENABLE_A2DP_EXPLICIT_CONFIG
if (config_process->state == A2DP_DISCOVERY_DONE)
config_process->state = A2DP_SET_CONFIGURATION;
}
#endif
Expand Down Expand Up @@ -605,13 +603,7 @@ void a2dp_config_process_avdtp_event_handler(avdtp_role_t role, uint8_t *packet,
// forward codec capability
a2dp_replace_subevent_id_and_emit_for_role(role, packet, size, A2DP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY);

#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
if (role == AVDTP_ROLE_SOURCE) break;
#endif
#ifdef ENABLE_A2DP_SINK_EXPLICIT_CONFIG
if (role == AVDTP_ROLE_SINK) break;
#endif

#ifndef ENABLE_A2DP_EXPLICIT_CONFIG
// select SEP if none configured yet
if (config_process->have_config == false){
// find SBC stream endpoint
Expand All @@ -634,6 +626,7 @@ void a2dp_config_process_avdtp_event_handler(avdtp_role_t role, uint8_t *packet,
a2dp_config_process_set_sbc(role, cid, local_seid, remote_seid, &configuration);
}
}
#endif
break;
// forward codec capability
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_MPEG_AUDIO_CAPABILITY:
Expand Down Expand Up @@ -717,19 +710,10 @@ void a2dp_config_process_avdtp_event_handler(avdtp_role_t role, uint8_t *packet,
break;
}

#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
if (role == AVDTP_ROLE_SOURCE){
config_process->state = A2DP_DISCOVERY_DONE;
// TODO call a2dp_discover_seps_with_next_waiting_connection?
break;
}
#endif
#ifdef ENABLE_A2DP_SINK_EXPLICIT_CONFIG
if (role == AVDTP_ROLE_SINK){
config_process->state = A2DP_DISCOVERY_DONE;
// TODO call a2dp_discover_seps_with_next_waiting_connection?
break;
}
#ifdef ENABLE_A2DP_EXPLICIT_CONFIG
config_process->state = A2DP_DISCOVERY_DONE;
// TODO call a2dp_discover_seps_with_next_waiting_connection?
break;
#endif

// we didn't find a suitable SBC stream endpoint, sorry.
Expand Down Expand Up @@ -960,15 +944,8 @@ uint8_t a2dp_config_process_set_sbc(avdtp_role_t role, uint16_t a2dp_cid, uint8_
config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 4;
avdtp_config_sbc_store(config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);

#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
if (role == AVDP_SOURCE){
a2dp_config_process_set_config(role, connection);
}
#endif
#ifdef ENABLE_A2DP_SINK_EXPLICIT_CONFIG
if (role == AVDP_SINK){
a2dp_config_process_set_config(role, connection);
}
#ifdef ENABLE_A2DP_EXPLICIT_CONFIG
a2dp_config_process_set_config(role, connection);
#endif

return ERROR_CODE_SUCCESS;
Expand All @@ -991,15 +968,8 @@ uint8_t a2dp_config_process_set_mpeg_audio(avdtp_role_t role, uint16_t a2dp_cid,
config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 4;
avdtp_config_mpeg_audio_store(config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);

#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
if (role == AVDP_SOURCE){
a2dp_config_process_set_config(role, connection);
}
#endif
#ifdef ENABLE_A2DP_SINK_EXPLICIT_CONFIG
if (role == AVDP_SINK){
a2dp_config_process_set_config(role, connection);
}
#ifdef ENABLE_A2DP_EXPLICIT_CONFIG
a2dp_config_process_set_config(role, connection);
#endif

return ERROR_CODE_SUCCESS;
Expand All @@ -1021,15 +991,8 @@ uint8_t a2dp_config_process_set_mpeg_aac(avdtp_role_t role, uint16_t a2dp_cid,
config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 6;
avdtp_config_mpeg_aac_store(config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);

#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
if (role == AVDP_SOURCE){
a2dp_config_process_set_config(role, connection);
}
#endif
#ifdef ENABLE_A2DP_SINK_EXPLICIT_CONFIG
if (role == AVDP_SINK){
a2dp_config_process_set_config(role, connection);
}
#ifdef ENABLE_A2DP_EXPLICIT_CONFIG
a2dp_config_process_set_config(role, connection);
#endif

return ERROR_CODE_SUCCESS;
Expand All @@ -1052,15 +1015,8 @@ uint8_t a2dp_config_process_set_atrac(avdtp_role_t role, uint16_t a2dp_cid, uint
config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 7;
avdtp_config_atrac_store(config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);

#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
if (role == AVDP_SOURCE){
a2dp_config_process_set_config(role, connection);
}
#endif
#ifdef ENABLE_A2DP_SINK_EXPLICIT_CONFIG
if (role == AVDP_SINK){
a2dp_config_process_set_config(role, connection);
}
#ifdef ENABLE_A2DP_EXPLICIT_CONFIG
a2dp_config_process_set_config(role, connection);
#endif

return ERROR_CODE_SUCCESS;
Expand All @@ -1083,15 +1039,8 @@ uint8_t a2dp_config_process_set_other(avdtp_role_t role, uint16_t a2dp_cid, uin
config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *) media_codec_information;
config_process->local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = media_codec_information_len;

#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
if (role == AVDP_SOURCE){
#ifdef ENABLE_A2DP_EXPLICIT_CONFIG
a2dp_config_process_set_config(role, connection);
}
#endif
#ifdef ENABLE_A2DP_SINK_EXPLICIT_CONFIG
if (role == AVDP_SINK){
a2dp_config_process_set_config(role, connection);
}
#endif

return status;
Expand Down
4 changes: 2 additions & 2 deletions test/classic-oob-pairing/btstack_config.h
Expand Up @@ -59,8 +59,8 @@
#define ENABLE_CLASSIC_PAIRING_OOB
/// Handle IOCAP by application
#define ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY
/// Enable A2DP source codec config
#define ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
/// Enable A2DP codec config
#define ENABLE_A2DP_EXPLICIT_CONFIG
/// Allow defer of LINK Key Reply
#define ENABLE_EXPLICIT_LINK_KEY_REPLY
// Trigger L2CAP Information Requests to get supported fixed channels
Expand Down

0 comments on commit 72237cc

Please sign in to comment.