mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-30 06:32:43 +00:00
avdtp: remove avdtp_context_t
This commit is contained in:
parent
c69f4ba529
commit
77092f3ebc
@ -52,8 +52,6 @@
|
||||
static const char * default_a2dp_sink_service_name = "BTstack A2DP Sink Service";
|
||||
static const char * default_a2dp_sink_service_provider_name = "BTstack A2DP Sink Service Provider";
|
||||
|
||||
static avdtp_context_t a2dp_sink_context;
|
||||
|
||||
static a2dp_state_t app_state = A2DP_IDLE;
|
||||
static int send_stream_established_for_outgoing_connection;
|
||||
|
||||
@ -162,7 +160,7 @@ void a2dp_sink_register_media_handler(void (*callback)(uint8_t local_seid, uint8
|
||||
}
|
||||
|
||||
void a2dp_sink_init(void){
|
||||
avdtp_sink_init(&a2dp_sink_context);
|
||||
avdtp_sink_init();
|
||||
}
|
||||
|
||||
avdtp_stream_endpoint_t * a2dp_sink_create_stream_endpoint(avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type,
|
||||
|
@ -56,7 +56,6 @@
|
||||
|
||||
static const char * default_a2dp_source_service_name = "BTstack A2DP Source Service";
|
||||
static const char * default_a2dp_source_service_provider_name = "BTstack A2DP Source Service Provider";
|
||||
static avdtp_context_t a2dp_source_context;
|
||||
|
||||
static a2dp_state_t app_state = A2DP_IDLE;
|
||||
static avdtp_stream_endpoint_context_t sc;
|
||||
@ -526,7 +525,7 @@ void a2dp_source_register_packet_handler(btstack_packet_handler_t callback){
|
||||
}
|
||||
|
||||
void a2dp_source_init(void){
|
||||
avdtp_source_init(&a2dp_source_context);
|
||||
avdtp_source_init();
|
||||
}
|
||||
|
||||
avdtp_stream_endpoint_t * a2dp_source_create_stream_endpoint(avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type,
|
||||
|
@ -53,9 +53,6 @@
|
||||
#include "classic/sdp_client.h"
|
||||
#include "classic/sdp_util.h"
|
||||
|
||||
avdtp_context_t * avdtp_source_context = NULL;
|
||||
avdtp_context_t * avdtp_sink_context = NULL;
|
||||
|
||||
btstack_linked_list_t stream_endpoints;
|
||||
|
||||
static btstack_packet_handler_t avdtp_source_callback;
|
||||
@ -582,15 +579,15 @@ void avdtp_register_media_handler(void (*callback)(uint8_t local_seid, uint8_t *
|
||||
}
|
||||
|
||||
/* START: tracking can send now requests pro l2cap cid */
|
||||
void avdtp_handle_can_send_now(avdtp_connection_t * connection, uint16_t l2cap_cid, avdtp_context_t * context){
|
||||
void avdtp_handle_can_send_now(avdtp_connection_t *connection, uint16_t l2cap_cid) {
|
||||
if (connection->wait_to_send_acceptor){
|
||||
log_debug("call avdtp_acceptor_stream_config_subsm_run");
|
||||
connection->wait_to_send_acceptor = 0;
|
||||
avdtp_acceptor_stream_config_subsm_run(connection, context);
|
||||
avdtp_acceptor_stream_config_subsm_run(connection);
|
||||
} else if (connection->wait_to_send_initiator){
|
||||
log_debug("call avdtp_initiator_stream_config_subsm_run");
|
||||
connection->wait_to_send_initiator = 0;
|
||||
avdtp_initiator_stream_config_subsm_run(connection, context);
|
||||
avdtp_initiator_stream_config_subsm_run(connection);
|
||||
}
|
||||
|
||||
// re-register
|
||||
@ -617,7 +614,8 @@ avdtp_stream_endpoint_t * avdtp_create_stream_endpoint(avdtp_sep_type_t sep_type
|
||||
return stream_endpoint;
|
||||
}
|
||||
|
||||
static void handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t * connection, uint8_t *packet, uint16_t size, avdtp_context_t * context){
|
||||
static void
|
||||
handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t *connection, uint8_t *packet, uint16_t size) {
|
||||
if (size < 2) return;
|
||||
|
||||
uint16_t offset;
|
||||
@ -625,11 +623,11 @@ static void handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t
|
||||
switch (message_type){
|
||||
case AVDTP_CMD_MSG:
|
||||
offset = avdtp_read_signaling_header(&connection->acceptor_signaling_packet, packet, size);
|
||||
avdtp_acceptor_stream_config_subsm(connection, packet, size, offset, context);
|
||||
avdtp_acceptor_stream_config_subsm(connection, packet, size, offset);
|
||||
break;
|
||||
default:
|
||||
offset = avdtp_read_signaling_header(&connection->initiator_signaling_packet, packet, size);
|
||||
avdtp_initiator_stream_config_subsm(connection, packet, size, offset, context);
|
||||
avdtp_initiator_stream_config_subsm(connection, packet, size, offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -819,18 +817,6 @@ static avdtp_connection_t * avdtp_handle_incoming_connection(avdtp_connection_t
|
||||
return connection;
|
||||
}
|
||||
|
||||
static avdtp_context_t * avdtp_get_active_contex(void){
|
||||
// assume only one context is active
|
||||
avdtp_context_t * context = NULL;
|
||||
if (avdtp_sink_context != NULL){
|
||||
context = avdtp_sink_context;
|
||||
} else {
|
||||
context = avdtp_source_context;
|
||||
}
|
||||
btstack_assert(context != NULL);
|
||||
return context;
|
||||
}
|
||||
|
||||
static void avdtp_retry_timer_timeout_handler(btstack_timer_source_t * timer){
|
||||
uint16_t avdtp_cid = (uint16_t)(uintptr_t) btstack_run_loop_get_timer_context(timer);
|
||||
|
||||
@ -867,27 +853,25 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
|
||||
|
||||
avdtp_stream_endpoint_t * stream_endpoint = NULL;
|
||||
avdtp_connection_t * connection = NULL;
|
||||
|
||||
avdtp_context_t * context = avdtp_get_active_contex();
|
||||
|
||||
switch (packet_type) {
|
||||
case L2CAP_DATA_PACKET:
|
||||
connection = avdtp_get_connection_for_l2cap_signaling_cid(channel);
|
||||
if (connection){
|
||||
handle_l2cap_data_packet_for_signaling_connection(connection, packet, size, context);
|
||||
handle_l2cap_data_packet_for_signaling_connection(connection, packet, size);
|
||||
break;
|
||||
}
|
||||
|
||||
stream_endpoint = avdtp_get_stream_endpoint_for_l2cap_cid(channel);
|
||||
if (!stream_endpoint){
|
||||
if (!connection) break;
|
||||
handle_l2cap_data_packet_for_signaling_connection(connection, packet, size, context);
|
||||
handle_l2cap_data_packet_for_signaling_connection(connection, packet, size);
|
||||
break;
|
||||
}
|
||||
|
||||
if (stream_endpoint->connection){
|
||||
if (channel == stream_endpoint->connection->l2cap_signaling_cid){
|
||||
handle_l2cap_data_packet_for_signaling_connection(stream_endpoint->connection, packet, size, context);
|
||||
handle_l2cap_data_packet_for_signaling_connection(stream_endpoint->connection, packet, size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1101,7 +1085,7 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
|
||||
if (!stream_endpoint->connection) break;
|
||||
connection = stream_endpoint->connection;
|
||||
}
|
||||
avdtp_handle_can_send_now(connection, channel, context);
|
||||
avdtp_handle_can_send_now(connection, channel);
|
||||
break;
|
||||
default:
|
||||
log_info("Unknown HCI event type %02x", hci_event_packet_get_type(packet));
|
||||
|
@ -542,13 +542,6 @@ typedef struct {
|
||||
avdtp_sep_t * active_remote_sep;
|
||||
} avdtp_stream_endpoint_context_t;
|
||||
|
||||
typedef struct {
|
||||
int dummy;
|
||||
} avdtp_context_t;
|
||||
|
||||
extern avdtp_context_t * avdtp_source_context;
|
||||
extern avdtp_context_t * avdtp_sink_context;
|
||||
|
||||
avdtp_connection_t * avdtp_get_connection_for_avdtp_cid(uint16_t l2cap_cid);
|
||||
avdtp_connection_t * avdtp_get_connection_for_l2cap_signaling_cid(uint16_t l2cap_cid);
|
||||
btstack_linked_list_t * avdtp_get_stream_endpoints(void);
|
||||
@ -568,7 +561,7 @@ void avdtp_register_content_protection_category(avdtp_stream_endpoint_t * stream
|
||||
void avdtp_register_header_compression_category(avdtp_stream_endpoint_t * stream_endpoint, uint8_t back_ch, uint8_t media, uint8_t recovery);
|
||||
void avdtp_register_media_codec_category(avdtp_stream_endpoint_t * stream_endpoint, avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type, uint8_t * media_codec_info, uint16_t media_codec_info_len);
|
||||
void avdtp_register_multiplexing_category(avdtp_stream_endpoint_t * stream_endpoint, uint8_t fragmentation);
|
||||
void avdtp_handle_can_send_now(avdtp_connection_t * connection, uint16_t l2cap_cid, avdtp_context_t * context);
|
||||
void avdtp_handle_can_send_now(avdtp_connection_t *connection, uint16_t l2cap_cid);
|
||||
|
||||
// sink only
|
||||
void avdtp_register_media_handler(void (*callback)(uint8_t local_seid, uint8_t *packet, uint16_t size));
|
||||
|
@ -79,7 +79,8 @@ static int avdtp_acceptor_validate_msg_length(avdtp_signal_identifier_t signal_i
|
||||
return msg_size >= minimal_msg_lenght;
|
||||
}
|
||||
|
||||
static void avdtp_acceptor_handle_configuration_command(avdtp_connection_t *connection, avdtp_context_t *context, int offset, uint16_t packet_size, avdtp_stream_endpoint_t *stream_endpoint) {
|
||||
static void
|
||||
avdtp_acceptor_handle_configuration_command(avdtp_connection_t *connection, int offset, uint16_t packet_size, avdtp_stream_endpoint_t *stream_endpoint) {
|
||||
log_info("ACP: AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION connection %p", connection);
|
||||
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE;
|
||||
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION;
|
||||
@ -132,7 +133,7 @@ static void avdtp_acceptor_handle_configuration_command(avdtp_connection_t *conn
|
||||
connection->acceptor_signaling_packet.signal_identifier, false);
|
||||
}
|
||||
|
||||
void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t * packet, uint16_t size, int offset, avdtp_context_t * context){
|
||||
void avdtp_acceptor_stream_config_subsm(avdtp_connection_t *connection, uint8_t *packet, uint16_t size, int offset) {
|
||||
avdtp_stream_endpoint_t * stream_endpoint = NULL;
|
||||
connection->acceptor_transaction_label = connection->acceptor_signaling_packet.transaction_label;
|
||||
if (!avdtp_acceptor_validate_msg_length(connection->acceptor_signaling_packet.signal_identifier, size)) {
|
||||
@ -255,7 +256,8 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
|
||||
log_info("Received SET_CONFIGURATION cmd: config state %d", connection->configuration_state);
|
||||
switch (connection->configuration_state){
|
||||
case AVDTP_CONFIGURATION_STATE_IDLE:
|
||||
avdtp_acceptor_handle_configuration_command(connection, context, offset, packet_size, stream_endpoint);
|
||||
avdtp_acceptor_handle_configuration_command(connection, offset, packet_size,
|
||||
stream_endpoint);
|
||||
connection->configuration_state = AVDTP_CONFIGURATION_STATE_REMOTE_INITIATED;
|
||||
break;
|
||||
case AVDTP_CONFIGURATION_STATE_LOCAL_INITIATED:
|
||||
@ -447,7 +449,7 @@ static int avdtp_acceptor_send_response_reject_with_error_code(uint16_t cid, avd
|
||||
return l2cap_send(cid, command, sizeof(command));
|
||||
}
|
||||
|
||||
void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avdtp_context_t * context){
|
||||
void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t *connection) {
|
||||
int sent = 1;
|
||||
btstack_linked_list_t * stream_endpoints = avdtp_get_stream_endpoints();
|
||||
|
||||
|
@ -52,8 +52,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t *packet, uint16_t size, int offset, avdtp_context_t * context);
|
||||
void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avdtp_context_t * context);
|
||||
void avdtp_acceptor_stream_config_subsm(avdtp_connection_t *connection, uint8_t *packet, uint16_t size, int offset);
|
||||
void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t *connection);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ static int avdtp_initiator_send_signaling_cmd_delay_report(uint16_t cid, uint8_t
|
||||
return l2cap_send(cid, command, sizeof(command));
|
||||
}
|
||||
|
||||
void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_t *packet, uint16_t size, int offset, avdtp_context_t * context){
|
||||
void avdtp_initiator_stream_config_subsm(avdtp_connection_t *connection, uint8_t *packet, uint16_t size, int offset) {
|
||||
// int status = 0;
|
||||
avdtp_stream_endpoint_t * stream_endpoint = NULL;
|
||||
|
||||
@ -378,7 +378,7 @@ static void avdtp_initiator_stream_config_subsm_run_endpoint(avdtp_connection_t
|
||||
}
|
||||
}
|
||||
|
||||
void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, avdtp_context_t * context){
|
||||
void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t *connection) {
|
||||
|
||||
bool sent = avdtp_initiator_stream_config_subsm_run_signaling(connection);
|
||||
if (sent) return;
|
||||
|
@ -52,8 +52,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_t *packet, uint16_t size, int offset, avdtp_context_t * context);
|
||||
void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, avdtp_context_t * context);
|
||||
void avdtp_initiator_stream_config_subsm(avdtp_connection_t *connection, uint8_t *packet, uint16_t size, int offset);
|
||||
void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t *connection);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
|
@ -99,10 +99,7 @@ void avdtp_sink_register_packet_handler(btstack_packet_handler_t callback){
|
||||
avdtp_register_sink_packet_handler(callback);
|
||||
}
|
||||
|
||||
void avdtp_sink_init(avdtp_context_t * avdtp_context){
|
||||
btstack_assert(avdtp_context != NULL);
|
||||
|
||||
avdtp_sink_context = avdtp_context;
|
||||
void avdtp_sink_init(void) {
|
||||
l2cap_register_service(&avdtp_packet_handler, BLUETOOTH_PSM_AVDTP, 0xffff, gap_get_security_level());
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ extern "C" {
|
||||
/**
|
||||
* @brief Set up AVDTP Sink device.
|
||||
*/
|
||||
void avdtp_sink_init(avdtp_context_t * avdtp_context);
|
||||
void avdtp_sink_init(void);
|
||||
|
||||
// returns avdtp_stream_endpoint_t *
|
||||
avdtp_stream_endpoint_t * avdtp_sink_create_stream_endpoint(avdtp_sep_type_t sep_type, avdtp_media_type_t media_type);
|
||||
|
@ -156,10 +156,7 @@ void avdtp_source_register_packet_handler(btstack_packet_handler_t callback){
|
||||
avdtp_register_source_packet_handler(callback);
|
||||
}
|
||||
|
||||
void avdtp_source_init(avdtp_context_t * avdtp_context){
|
||||
btstack_assert(avdtp_context != NULL);
|
||||
|
||||
avdtp_source_context = avdtp_context;
|
||||
void avdtp_source_init(void) {
|
||||
l2cap_register_service(&avdtp_packet_handler, BLUETOOTH_PSM_AVDTP, 0xffff, gap_get_security_level());
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ void avdtp_source_register_multiplexing_category(uint8_t seid, uint8_t fragmenta
|
||||
/**
|
||||
* @brief Initialize up AVDTP Source device.
|
||||
*/
|
||||
void avdtp_source_init(avdtp_context_t * avdtp_context);
|
||||
void avdtp_source_init(void);
|
||||
|
||||
/**
|
||||
* @brief Register callback for the AVDTP Source client. See btstack_defines.h for AVDTP_SUBEVENT_* events
|
||||
|
Loading…
x
Reference in New Issue
Block a user