mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 22:20:37 +00:00
a2dp_source: remove global a2dp_source_state
This commit is contained in:
parent
1da2869325
commit
5d747e2271
@ -80,7 +80,6 @@ static btstack_timer_source_t a2dp_source_set_config_timer;
|
||||
static bool outgoing_active;
|
||||
|
||||
// discover remote seps
|
||||
static a2dp_state_t a2dp_source_state;
|
||||
static uint16_t a2dp_source_cid;
|
||||
static uint16_t num_remote_seps;
|
||||
static avdtp_sep_t remote_seps[AVDTP_MAX_SEP_NUM];
|
||||
@ -242,7 +241,6 @@ static void a2dp_source_set_config_timer_stop(void){
|
||||
|
||||
static void a2dp_start_discovering_seps(avdtp_connection_t * connection){
|
||||
connection->a2dp_source_state = A2DP_DISCOVER_SEPS;
|
||||
a2dp_source_state = A2DP_DISCOVER_SEPS;
|
||||
sc.active_remote_sep_index = 0;
|
||||
num_remote_seps = 0;
|
||||
memset(remote_seps, 0, sizeof(avdtp_sep_t) * AVDTP_MAX_SEP_NUM);
|
||||
@ -259,10 +257,7 @@ static void a2dp_start_discovering_seps(avdtp_connection_t * connection){
|
||||
}
|
||||
|
||||
static void a2dp_discover_seps_with_next_waiting_connection(void){
|
||||
// ok: all callers set state in connection struct
|
||||
a2dp_source_state = A2DP_IDLE;
|
||||
|
||||
btstack_linked_list_iterator_t it;
|
||||
btstack_linked_list_iterator_t it;
|
||||
btstack_linked_list_iterator_init(&it, avdtp_get_connections());
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
avdtp_connection_t * next_connection = (avdtp_connection_t *)btstack_linked_list_iterator_next(&it);
|
||||
@ -278,14 +273,12 @@ static void a2dp_handle_received_configuration(const uint8_t *packet, uint8_t lo
|
||||
if ((a2dp_source_cid == cid) && (avdtp_connection->a2dp_source_state == A2DP_W4_SET_CONFIGURATION)){
|
||||
// outgoing: discovery and config of remote sink sep successful, trigger stream open
|
||||
avdtp_connection->a2dp_source_state = A2DP_W2_OPEN_STREAM_WITH_SEID;
|
||||
a2dp_source_state = A2DP_W2_OPEN_STREAM_WITH_SEID;
|
||||
} else {
|
||||
// incoming: accept cid, lookup local stream endpoint and wait for stream open
|
||||
a2dp_source_cid = cid;
|
||||
sc.local_stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid);
|
||||
btstack_assert(sc.local_stream_endpoint != NULL);
|
||||
avdtp_connection->a2dp_source_state = A2DP_W4_OPEN_STREAM_WITH_SEID;
|
||||
a2dp_source_state = A2DP_W4_OPEN_STREAM_WITH_SEID;
|
||||
}
|
||||
|
||||
// config set: stop timer
|
||||
@ -376,7 +369,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
if (connection->a2dp_source_state != A2DP_DISCOVER_SEPS) break;
|
||||
|
||||
if (num_remote_seps > 0){
|
||||
a2dp_source_state = A2DP_GET_CAPABILITIES;
|
||||
connection->a2dp_source_state = A2DP_GET_CAPABILITIES;
|
||||
sc.active_remote_sep_index = 0;
|
||||
a2dp_source_have_config = false;
|
||||
@ -390,7 +382,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
|
||||
// continue
|
||||
connection->a2dp_source_state = A2DP_CONNECTED;
|
||||
a2dp_source_state = A2DP_CONNECTED;
|
||||
a2dp_discover_seps_with_next_waiting_connection();
|
||||
}
|
||||
break;
|
||||
@ -517,7 +508,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
|
||||
// do we have a valid config?
|
||||
if (a2dp_source_have_config){
|
||||
a2dp_source_state = A2DP_SET_CONFIGURATION;
|
||||
connection->a2dp_source_state = A2DP_SET_CONFIGURATION;
|
||||
a2dp_source_have_config = false;
|
||||
break;
|
||||
@ -595,7 +585,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
avdtp_subevent_streaming_connection_established_get_local_seid(packet),
|
||||
avdtp_subevent_streaming_connection_established_get_remote_seid(packet));
|
||||
connection->a2dp_source_state = A2DP_STREAMING_OPENED;
|
||||
a2dp_source_state = A2DP_STREAMING_OPENED;
|
||||
a2dp_replace_subevent_id_and_emit_cmd(a2dp_source_packet_handler_user, packet, size, A2DP_SUBEVENT_STREAM_ESTABLISHED);
|
||||
break;
|
||||
|
||||
@ -630,14 +619,12 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
remote_seid = sc.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(sc.local_stream_endpoint), remote_seid);
|
||||
connection->a2dp_source_state = A2DP_W4_SET_CONFIGURATION;
|
||||
a2dp_source_state = A2DP_W4_SET_CONFIGURATION;
|
||||
avdtp_source_set_configuration(cid, avdtp_stream_endpoint_seid(sc.local_stream_endpoint), remote_seid, sc.local_stream_endpoint->remote_configuration_bitmap, sc.local_stream_endpoint->remote_configuration);
|
||||
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(sc.local_stream_endpoint), sc.local_stream_endpoint->remote_sep.seid);
|
||||
connection->a2dp_source_state = A2DP_W4_OPEN_STREAM_WITH_SEID;
|
||||
a2dp_source_state = A2DP_W4_OPEN_STREAM_WITH_SEID;
|
||||
avdtp_source_open_stream(cid, avdtp_stream_endpoint_seid(sc.local_stream_endpoint), sc.local_stream_endpoint->remote_sep.seid);
|
||||
break;
|
||||
|
||||
@ -645,7 +632,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
log_info("A2DP reconfigured ... local seid 0x%02x, active remote seid 0x%02x", avdtp_stream_endpoint_seid(sc.local_stream_endpoint), sc.local_stream_endpoint->remote_sep.seid);
|
||||
a2dp_signaling_emit_reconfigured(cid, avdtp_stream_endpoint_seid(sc.local_stream_endpoint), ERROR_CODE_SUCCESS);
|
||||
connection->a2dp_source_state = A2DP_STREAMING_OPENED;
|
||||
a2dp_source_state = A2DP_STREAMING_OPENED;
|
||||
break;
|
||||
|
||||
case A2DP_STREAMING_OPENED:
|
||||
@ -679,7 +665,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
if (avdtp_subevent_signaling_reject_get_is_initiator(packet) == 0) break;
|
||||
|
||||
connection->a2dp_source_state = A2DP_CONNECTED;
|
||||
a2dp_source_state = A2DP_CONNECTED;
|
||||
a2dp_replace_subevent_id_and_emit_cmd(a2dp_source_packet_handler_user, packet, size, A2DP_SUBEVENT_COMMAND_REJECTED);
|
||||
break;
|
||||
|
||||
@ -692,7 +677,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
if (avdtp_subevent_signaling_general_reject_get_is_initiator(packet) == 0) break;
|
||||
|
||||
connection->a2dp_source_state = A2DP_CONNECTED;
|
||||
a2dp_source_state = A2DP_CONNECTED;
|
||||
a2dp_replace_subevent_id_and_emit_cmd(a2dp_source_packet_handler_user, packet, size, A2DP_SUBEVENT_COMMAND_REJECTED);
|
||||
break;
|
||||
|
||||
@ -704,7 +688,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
if (a2dp_source_cid != cid) break;
|
||||
|
||||
connection->a2dp_source_state = A2DP_CONFIGURED;
|
||||
a2dp_source_state = A2DP_CONFIGURED;
|
||||
a2dp_replace_subevent_id_and_emit_cmd(a2dp_source_packet_handler_user, packet, size, A2DP_SUBEVENT_STREAM_RELEASED);
|
||||
break;
|
||||
|
||||
@ -719,7 +702,6 @@ static void a2dp_source_packet_handler_internal(uint8_t packet_type, uint16_t ch
|
||||
sc.local_stream_endpoint = NULL;
|
||||
|
||||
connection->a2dp_source_state = A2DP_IDLE;
|
||||
a2dp_source_state = A2DP_IDLE;
|
||||
a2dp_source_cid = 0;
|
||||
}
|
||||
a2dp_replace_subevent_id_and_emit_cmd(a2dp_source_packet_handler_user, packet, size, A2DP_SUBEVENT_SIGNALING_CONNECTION_RELEASED);
|
||||
@ -737,8 +719,6 @@ void a2dp_source_register_packet_handler(btstack_packet_handler_t callback){
|
||||
}
|
||||
|
||||
void a2dp_source_init(void){
|
||||
// ok: does not matter
|
||||
a2dp_source_state = A2DP_IDLE;
|
||||
(void) memset(&sc, 0, sizeof(avdtp_stream_endpoint_context_t));
|
||||
|
||||
avdtp_source_init();
|
||||
@ -798,7 +778,6 @@ uint8_t a2dp_source_establish_stream(bd_addr_t remote_addr, uint16_t *avdtp_cid)
|
||||
|
||||
// setup state
|
||||
connection->a2dp_source_state = A2DP_W4_CONNECTED;
|
||||
a2dp_source_state = A2DP_W4_CONNECTED;
|
||||
a2dp_source_cid = outgoing_cid;
|
||||
*avdtp_cid = outgoing_cid;
|
||||
|
||||
@ -810,7 +789,6 @@ uint8_t a2dp_source_establish_stream(bd_addr_t remote_addr, uint16_t *avdtp_cid)
|
||||
// restart process e.g. if there no suitable stream endpoints or they had been in use
|
||||
outgoing_active = true;
|
||||
connection->a2dp_source_state = A2DP_DISCOVER_SEPS;
|
||||
a2dp_source_state = A2DP_DISCOVER_SEPS;
|
||||
*avdtp_cid = connection->avdtp_cid;
|
||||
a2dp_start_discovering_seps(connection);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user