mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-01 10:13:29 +00:00
a2dp_source: use local stream endpoint reference in connection struct
This commit is contained in:
parent
7d99e5e205
commit
855fce2d38
@ -78,8 +78,6 @@ static uint16_t sep_discovery_index;
|
||||
static avdtp_sep_t sep_discovery_seps[AVDTP_MAX_SEP_NUM];
|
||||
static btstack_timer_source_t a2dp_source_set_config_timer;
|
||||
|
||||
static avdtp_stream_endpoint_t * local_stream_endpoint;
|
||||
|
||||
static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
static void a2dp_discover_seps_with_next_waiting_connection(void);
|
||||
|
||||
@ -272,9 +270,8 @@ static void a2dp_handle_received_configuration(const uint8_t *packet, uint8_t lo
|
||||
avdtp_connection_t * avdtp_connection = avdtp_get_connection_for_avdtp_cid(cid);
|
||||
btstack_assert(avdtp_connection != NULL);
|
||||
avdtp_connection->a2dp_source_local_stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid);
|
||||
local_stream_endpoint = avdtp_connection->a2dp_source_local_stream_endpoint;
|
||||
// bail out if local seid invalid
|
||||
if (!local_stream_endpoint) return;
|
||||
if (!avdtp_connection->a2dp_source_local_stream_endpoint) return;
|
||||
|
||||
// stop timer
|
||||
if (sep_discovery_cid == cid) {
|
||||
@ -295,10 +292,10 @@ static void a2dp_handle_received_configuration(const uint8_t *packet, uint8_t lo
|
||||
}
|
||||
|
||||
static void a2dp_source_set_config(avdtp_connection_t * connection){
|
||||
uint8_t remote_seid = local_stream_endpoint->set_config_remote_seid;
|
||||
log_info("A2DP initiate set configuration locally and wait for response ... local seid 0x%02x, remote seid 0x%02x", avdtp_stream_endpoint_seid(local_stream_endpoint), remote_seid);
|
||||
uint8_t remote_seid = connection->a2dp_source_local_stream_endpoint->set_config_remote_seid;
|
||||
log_info("A2DP initiate set configuration locally and wait for response ... local seid 0x%02x, remote seid 0x%02x", avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint), remote_seid);
|
||||
connection->a2dp_source_state = A2DP_W4_SET_CONFIGURATION;
|
||||
avdtp_source_set_configuration(connection->avdtp_cid, avdtp_stream_endpoint_seid(local_stream_endpoint), remote_seid, local_stream_endpoint->remote_configuration_bitmap, local_stream_endpoint->remote_configuration);
|
||||
avdtp_source_set_configuration(connection->avdtp_cid, avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint), remote_seid, connection->a2dp_source_local_stream_endpoint->remote_configuration_bitmap, connection->a2dp_source_local_stream_endpoint->remote_configuration);
|
||||
}
|
||||
|
||||
static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
@ -619,28 +616,28 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
return;
|
||||
|
||||
case A2DP_W2_OPEN_STREAM_WITH_SEID:
|
||||
log_info("A2DP open stream ... local seid 0x%02x, active remote seid 0x%02x", avdtp_stream_endpoint_seid(local_stream_endpoint), local_stream_endpoint->remote_sep.seid);
|
||||
log_info("A2DP open stream ... local seid 0x%02x, active remote seid 0x%02x", avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint), connection->a2dp_source_local_stream_endpoint->remote_sep.seid);
|
||||
connection->a2dp_source_state = A2DP_W4_OPEN_STREAM_WITH_SEID;
|
||||
avdtp_source_open_stream(cid, avdtp_stream_endpoint_seid(local_stream_endpoint), local_stream_endpoint->remote_sep.seid);
|
||||
avdtp_source_open_stream(cid, avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint), connection->a2dp_source_local_stream_endpoint->remote_sep.seid);
|
||||
break;
|
||||
|
||||
case A2DP_W2_RECONFIGURE_WITH_SEID:
|
||||
log_info("A2DP reconfigured ... local seid 0x%02x, active remote seid 0x%02x", avdtp_stream_endpoint_seid(local_stream_endpoint), local_stream_endpoint->remote_sep.seid);
|
||||
a2dp_signaling_emit_reconfigured(cid, avdtp_stream_endpoint_seid(local_stream_endpoint), ERROR_CODE_SUCCESS);
|
||||
log_info("A2DP reconfigured ... local seid 0x%02x, active remote seid 0x%02x", avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint), connection->a2dp_source_local_stream_endpoint->remote_sep.seid);
|
||||
a2dp_signaling_emit_reconfigured(cid, avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint), ERROR_CODE_SUCCESS);
|
||||
connection->a2dp_source_state = A2DP_STREAMING_OPENED;
|
||||
break;
|
||||
|
||||
case A2DP_STREAMING_OPENED:
|
||||
switch (signal_identifier){
|
||||
case AVDTP_SI_START:
|
||||
a2dp_emit_stream_event(a2dp_source_packet_handler_user, cid, avdtp_stream_endpoint_seid(local_stream_endpoint), A2DP_SUBEVENT_STREAM_STARTED);
|
||||
a2dp_emit_stream_event(a2dp_source_packet_handler_user, cid, avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint), A2DP_SUBEVENT_STREAM_STARTED);
|
||||
break;
|
||||
case AVDTP_SI_SUSPEND:
|
||||
a2dp_emit_stream_event(a2dp_source_packet_handler_user, cid, avdtp_stream_endpoint_seid(local_stream_endpoint), A2DP_SUBEVENT_STREAM_SUSPENDED);
|
||||
a2dp_emit_stream_event(a2dp_source_packet_handler_user, cid, avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint), A2DP_SUBEVENT_STREAM_SUSPENDED);
|
||||
break;
|
||||
case AVDTP_SI_ABORT:
|
||||
case AVDTP_SI_CLOSE:
|
||||
a2dp_emit_stream_event(a2dp_source_packet_handler_user, cid, avdtp_stream_endpoint_seid(local_stream_endpoint), A2DP_SUBEVENT_STREAM_STOPPED);
|
||||
a2dp_emit_stream_event(a2dp_source_packet_handler_user, cid, avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint), A2DP_SUBEVENT_STREAM_STOPPED);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -693,7 +690,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
a2dp_source_set_config_timer_stop();
|
||||
connection->a2dp_source_stream_endpoint_configured = false;
|
||||
connection->a2dp_source_local_stream_endpoint = NULL;
|
||||
local_stream_endpoint = NULL;
|
||||
|
||||
connection->a2dp_source_state = A2DP_IDLE;
|
||||
sep_discovery_cid = 0;
|
||||
@ -713,7 +709,6 @@ void a2dp_source_register_packet_handler(btstack_packet_handler_t callback){
|
||||
}
|
||||
|
||||
void a2dp_source_init(void){
|
||||
local_stream_endpoint = NULL;
|
||||
avdtp_source_init();
|
||||
}
|
||||
|
||||
@ -863,7 +858,6 @@ static uint8_t a2dp_source_config_init(avdtp_connection_t *connection, uint8_t l
|
||||
|
||||
// suitable Sink stream endpoint found, configure it
|
||||
connection->a2dp_source_local_stream_endpoint = stream_endpoint;
|
||||
local_stream_endpoint = stream_endpoint;
|
||||
connection->a2dp_source_have_config = true;
|
||||
|
||||
#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
|
||||
@ -887,9 +881,9 @@ uint8_t a2dp_source_set_config_sbc(uint16_t a2dp_cid, uint8_t local_seid, uint8_
|
||||
return status;
|
||||
}
|
||||
// set config in reserved buffer
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *) local_stream_endpoint->media_codec_info;
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 4;
|
||||
avdtp_config_sbc_store(local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *) connection->a2dp_source_local_stream_endpoint->media_codec_info;
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 4;
|
||||
avdtp_config_sbc_store(connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);
|
||||
|
||||
#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
|
||||
a2dp_source_set_config(connection);
|
||||
@ -910,9 +904,9 @@ uint8_t a2dp_source_set_config_mpeg_audio(uint16_t a2dp_cid, uint8_t local_seid,
|
||||
}
|
||||
|
||||
// set config in reserved buffer
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *)local_stream_endpoint->media_codec_info;
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 4;
|
||||
avdtp_config_mpeg_audio_store( local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *)connection->a2dp_source_local_stream_endpoint->media_codec_info;
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 4;
|
||||
avdtp_config_mpeg_audio_store( connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);
|
||||
|
||||
#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
|
||||
a2dp_source_set_config(connection);
|
||||
@ -931,9 +925,9 @@ uint8_t a2dp_source_set_config_mpeg_aac(uint16_t a2dp_cid, uint8_t local_seid,
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *) local_stream_endpoint->media_codec_info;
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 6;
|
||||
avdtp_config_mpeg_aac_store( local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *) connection->a2dp_source_local_stream_endpoint->media_codec_info;
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 6;
|
||||
avdtp_config_mpeg_aac_store( connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);
|
||||
|
||||
#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
|
||||
a2dp_source_set_config(connection);
|
||||
@ -953,9 +947,9 @@ uint8_t a2dp_source_set_config_atrac(uint16_t a2dp_cid, uint8_t local_seid, uint
|
||||
return status;
|
||||
}
|
||||
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *) local_stream_endpoint->media_codec_info;
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 7;
|
||||
avdtp_config_atrac_store( local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *) connection->a2dp_source_local_stream_endpoint->media_codec_info;
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = 7;
|
||||
avdtp_config_atrac_store( connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information, configuration);
|
||||
|
||||
#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
|
||||
a2dp_source_set_config(connection);
|
||||
@ -976,8 +970,8 @@ uint8_t a2dp_source_set_config_other(uint16_t a2dp_cid, uint8_t local_seid, uin
|
||||
return status;
|
||||
}
|
||||
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *) media_codec_information;
|
||||
local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = media_codec_information_len;
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information = (uint8_t *) media_codec_information;
|
||||
connection->a2dp_source_local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = media_codec_information_len;
|
||||
|
||||
#ifdef ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG
|
||||
a2dp_source_set_config(connection);
|
||||
@ -996,32 +990,32 @@ uint8_t a2dp_source_reconfigure_stream_sampling_frequency(uint16_t avdtp_cid, ui
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
btstack_assert(local_stream_endpoint != NULL);
|
||||
btstack_assert(connection->a2dp_source_local_stream_endpoint != NULL);
|
||||
|
||||
log_info("Reconfigure avdtp_cid 0x%02x", avdtp_cid);
|
||||
|
||||
avdtp_media_codec_type_t codec_type = local_stream_endpoint->sep.capabilities.media_codec.media_codec_type;
|
||||
avdtp_media_codec_type_t codec_type = connection->a2dp_source_local_stream_endpoint->sep.capabilities.media_codec.media_codec_type;
|
||||
uint8_t codec_info_len;
|
||||
switch (codec_type){
|
||||
case AVDTP_CODEC_SBC:
|
||||
codec_info_len = 4;
|
||||
(void)memcpy(local_stream_endpoint->media_codec_info, local_stream_endpoint->remote_sep.configuration.media_codec.media_codec_information, codec_info_len);
|
||||
avdtp_config_sbc_set_sampling_frequency(local_stream_endpoint->media_codec_info, sampling_frequency);
|
||||
(void)memcpy(connection->a2dp_source_local_stream_endpoint->media_codec_info, connection->a2dp_source_local_stream_endpoint->remote_sep.configuration.media_codec.media_codec_information, codec_info_len);
|
||||
avdtp_config_sbc_set_sampling_frequency(connection->a2dp_source_local_stream_endpoint->media_codec_info, sampling_frequency);
|
||||
break;
|
||||
case AVDTP_CODEC_MPEG_1_2_AUDIO:
|
||||
codec_info_len = 4;
|
||||
(void)memcpy(local_stream_endpoint->media_codec_info, local_stream_endpoint->remote_sep.configuration.media_codec.media_codec_information, codec_info_len);
|
||||
avdtp_config_mpeg_audio_set_sampling_frequency(local_stream_endpoint->media_codec_info, sampling_frequency);
|
||||
(void)memcpy(connection->a2dp_source_local_stream_endpoint->media_codec_info, connection->a2dp_source_local_stream_endpoint->remote_sep.configuration.media_codec.media_codec_information, codec_info_len);
|
||||
avdtp_config_mpeg_audio_set_sampling_frequency(connection->a2dp_source_local_stream_endpoint->media_codec_info, sampling_frequency);
|
||||
break;
|
||||
case AVDTP_CODEC_MPEG_2_4_AAC:
|
||||
codec_info_len = 6;
|
||||
(void)memcpy(local_stream_endpoint->media_codec_info, local_stream_endpoint->remote_sep.configuration.media_codec.media_codec_information, codec_info_len);
|
||||
avdtp_config_mpeg_aac_set_sampling_frequency(local_stream_endpoint->media_codec_info, sampling_frequency);
|
||||
(void)memcpy(connection->a2dp_source_local_stream_endpoint->media_codec_info, connection->a2dp_source_local_stream_endpoint->remote_sep.configuration.media_codec.media_codec_information, codec_info_len);
|
||||
avdtp_config_mpeg_aac_set_sampling_frequency(connection->a2dp_source_local_stream_endpoint->media_codec_info, sampling_frequency);
|
||||
break;
|
||||
case AVDTP_CODEC_ATRAC_FAMILY:
|
||||
codec_info_len = 7;
|
||||
(void)memcpy(local_stream_endpoint->media_codec_info, local_stream_endpoint->remote_sep.configuration.media_codec.media_codec_information, codec_info_len);
|
||||
avdtp_config_atrac_set_sampling_frequency(local_stream_endpoint->media_codec_info, sampling_frequency);
|
||||
(void)memcpy(connection->a2dp_source_local_stream_endpoint->media_codec_info, connection->a2dp_source_local_stream_endpoint->remote_sep.configuration.media_codec.media_codec_information, codec_info_len);
|
||||
avdtp_config_atrac_set_sampling_frequency(connection->a2dp_source_local_stream_endpoint->media_codec_info, sampling_frequency);
|
||||
break;
|
||||
default:
|
||||
return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
|
||||
@ -1031,15 +1025,15 @@ uint8_t a2dp_source_reconfigure_stream_sampling_frequency(uint16_t avdtp_cid, ui
|
||||
new_configuration.media_codec.media_type = AVDTP_AUDIO;
|
||||
new_configuration.media_codec.media_codec_type = codec_type;
|
||||
new_configuration.media_codec.media_codec_information_len = codec_info_len;
|
||||
new_configuration.media_codec.media_codec_information = local_stream_endpoint->media_codec_info;
|
||||
new_configuration.media_codec.media_codec_information = connection->a2dp_source_local_stream_endpoint->media_codec_info;
|
||||
|
||||
// start reconfigure
|
||||
connection->a2dp_source_state = A2DP_W2_RECONFIGURE_WITH_SEID;
|
||||
|
||||
return avdtp_source_reconfigure(
|
||||
avdtp_cid,
|
||||
avdtp_stream_endpoint_seid(local_stream_endpoint),
|
||||
local_stream_endpoint->remote_sep.seid,
|
||||
avdtp_stream_endpoint_seid(connection->a2dp_source_local_stream_endpoint),
|
||||
connection->a2dp_source_local_stream_endpoint->remote_sep.seid,
|
||||
1 << AVDTP_MEDIA_CODEC,
|
||||
new_configuration
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user