From d8e15394770ca6fe9e4cc8023cf4b894369627eb Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 10 Jul 2020 16:46:58 +0200 Subject: [PATCH] avdtp: remove stream endpoints from context, fix unused param in avdtp_get_stream_endpoint_for_seid --- src/classic/a2dp_sink.c | 2 +- src/classic/a2dp_source.c | 2 +- src/classic/avdtp.c | 28 +++++++++++++++++----------- src/classic/avdtp.h | 7 ++++--- src/classic/avdtp_acceptor.c | 4 ++-- src/classic/avdtp_sink.c | 20 +++++++++----------- src/classic/avdtp_source.c | 24 +++++++++++------------- 7 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/classic/a2dp_sink.c b/src/classic/a2dp_sink.c index 63d7bc4fa..39388f946 100644 --- a/src/classic/a2dp_sink.c +++ b/src/classic/a2dp_sink.c @@ -180,7 +180,7 @@ avdtp_stream_endpoint_t * a2dp_sink_create_stream_endpoint(avdtp_media_type_t m } uint8_t a2dp_sink_establish_stream(bd_addr_t bd_addr, uint8_t local_seid, uint16_t * avdtp_cid){ - sc.local_stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid, &a2dp_sink_context); + sc.local_stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid); if (!sc.local_stream_endpoint){ log_info("No local_stream_endpoint for seid %d", local_seid); return AVDTP_SEID_DOES_NOT_EXIST; diff --git a/src/classic/a2dp_source.c b/src/classic/a2dp_source.c index 053683962..04fe191a7 100644 --- a/src/classic/a2dp_source.c +++ b/src/classic/a2dp_source.c @@ -556,7 +556,7 @@ avdtp_stream_endpoint_t * a2dp_source_create_stream_endpoint(avdtp_media_type_t } uint8_t a2dp_source_establish_stream(bd_addr_t remote_addr, uint8_t loc_seid, uint16_t * a2dp_cid){ - sc.local_stream_endpoint = avdtp_get_stream_endpoint_for_seid(loc_seid, &a2dp_source_context); + sc.local_stream_endpoint = avdtp_get_stream_endpoint_for_seid(loc_seid); if (!sc.local_stream_endpoint){ log_error(" no local_stream_endpoint for seid %d", loc_seid); return AVDTP_SEID_DOES_NOT_EXIST; diff --git a/src/classic/avdtp.c b/src/classic/avdtp.c index 043096e52..ce795ec5d 100644 --- a/src/classic/avdtp.c +++ b/src/classic/avdtp.c @@ -56,6 +56,8 @@ 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; static btstack_packet_handler_t avdtp_sink_callback; @@ -70,6 +72,10 @@ static int record_id = -1; static uint8_t attribute_value[45]; static const unsigned int attribute_value_buffer_size = sizeof(attribute_value); +btstack_linked_list_t * avdtp_get_stream_endpoints(void){ + return &stream_endpoints; +} + // typedef struct { // btstack_linked_list_t * avdtp_connections; // avdtp_connection_t * connection; @@ -110,9 +116,9 @@ static avdtp_connection_t * avdtp_get_connection_for_bd_addr(bd_addr_t addr){ } -avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_seid(uint16_t seid, avdtp_context_t * context){ +avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_seid(uint16_t seid){ btstack_linked_list_iterator_t it; - btstack_linked_list_iterator_init(&it, &context->stream_endpoints); + btstack_linked_list_iterator_init(&it, avdtp_get_stream_endpoints()); while (btstack_linked_list_iterator_has_next(&it)){ avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it); if (stream_endpoint->sep.seid == seid){ @@ -135,7 +141,7 @@ avdtp_connection_t * avdtp_get_connection_for_l2cap_signaling_cid(uint16_t l2cap avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_l2cap_cid(uint16_t l2cap_cid, avdtp_context_t * context){ btstack_linked_list_iterator_t it; - btstack_linked_list_iterator_init(&it, &context->stream_endpoints); + btstack_linked_list_iterator_init(&it, avdtp_get_stream_endpoints()); while (btstack_linked_list_iterator_has_next(&it)){ avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it); if (stream_endpoint->l2cap_media_cid == l2cap_cid){ @@ -153,7 +159,7 @@ avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_l2cap_cid(uint16_t l2cap avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_signaling_cid(uint16_t l2cap_cid, avdtp_context_t * context){ btstack_linked_list_iterator_t it; - btstack_linked_list_iterator_init(&it, &context->stream_endpoints); + btstack_linked_list_iterator_init(&it, avdtp_get_stream_endpoints()); while (btstack_linked_list_iterator_has_next(&it)){ avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it); if (stream_endpoint->connection){ @@ -167,7 +173,7 @@ avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_signaling_cid(uint16_t l avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_with_seid(uint8_t seid, avdtp_context_t * context){ btstack_linked_list_iterator_t it; - btstack_linked_list_iterator_init(&it, &context->stream_endpoints); + btstack_linked_list_iterator_init(&it, avdtp_get_stream_endpoints()); while (btstack_linked_list_iterator_has_next(&it)){ avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it); if (stream_endpoint->sep.seid == seid){ @@ -179,7 +185,7 @@ avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_with_seid(uint8_t seid, avdt avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_associated_with_acp_seid(uint16_t acp_seid, avdtp_context_t * context){ btstack_linked_list_iterator_t it; - btstack_linked_list_iterator_init(&it, &context->stream_endpoints); + btstack_linked_list_iterator_init(&it, avdtp_get_stream_endpoints()); while (btstack_linked_list_iterator_has_next(&it)){ avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it); if (stream_endpoint->remote_sep.seid == acp_seid){ @@ -390,7 +396,7 @@ void avdtp_handle_can_send_now(avdtp_connection_t * connection, uint16_t l2cap_c connection->wait_to_send_self = 0; if (connection->disconnect){ btstack_linked_list_iterator_t it; - btstack_linked_list_iterator_init(&it, &context->stream_endpoints); + btstack_linked_list_iterator_init(&it, avdtp_get_stream_endpoints()); while (btstack_linked_list_iterator_has_next(&it)){ avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it); if (stream_endpoint->connection != connection) continue; @@ -428,7 +434,7 @@ avdtp_stream_endpoint_t * avdtp_create_stream_endpoint(avdtp_sep_type_t sep_type stream_endpoint->sep.seid = avdtp_get_next_local_seid(); stream_endpoint->sep.media_type = media_type; stream_endpoint->sep.type = sep_type; - btstack_linked_list_add(&context->stream_endpoints, (btstack_linked_item_t *) stream_endpoint); + btstack_linked_list_add(avdtp_get_stream_endpoints(), (btstack_linked_item_t *) stream_endpoint); return stream_endpoint; } @@ -896,7 +902,7 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet if (connection){ btstack_linked_list_iterator_t it; - btstack_linked_list_iterator_init(&it, &context->stream_endpoints); + btstack_linked_list_iterator_init(&it, avdtp_get_stream_endpoints()); while (btstack_linked_list_iterator_has_next(&it)){ avdtp_stream_endpoint_t * _stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it); if (_stream_endpoint->connection == connection){ @@ -1188,7 +1194,7 @@ uint8_t avdtp_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t return AVDTP_CONNECTION_IN_WRONG_STATE; } - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid, context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid); if (!stream_endpoint) { log_error("No initiator stream endpoint for seid %d", local_seid); return AVDTP_STREAM_ENDPOINT_DOES_NOT_EXIST; @@ -1230,7 +1236,7 @@ uint8_t avdtp_reconfigure(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote return AVDTP_CONNECTION_IN_WRONG_STATE; } - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid, context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid); if (!stream_endpoint) { log_error("avdtp_reconfigure: no initiator stream endpoint for seid %d", local_seid); return AVDTP_STREAM_ENDPOINT_DOES_NOT_EXIST; diff --git a/src/classic/avdtp.h b/src/classic/avdtp.h index 99cbe7523..7f1e395a2 100644 --- a/src/classic/avdtp.h +++ b/src/classic/avdtp.h @@ -546,8 +546,6 @@ typedef struct { } avdtp_stream_endpoint_context_t; typedef struct { - btstack_linked_list_t stream_endpoints; - btstack_packet_handler_t avdtp_callback; btstack_packet_handler_t a2dp_callback; void (*handle_media_data)(uint8_t local_seid, uint8_t *packet, uint16_t size); @@ -558,11 +556,14 @@ 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); + +avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_seid(uint16_t seid); + avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_l2cap_cid(uint16_t l2cap_cid, avdtp_context_t * context); avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_with_seid(uint8_t seid, avdtp_context_t * context); avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_associated_with_acp_seid(uint16_t acp_seid, avdtp_context_t * context); -avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_seid(uint16_t seid, avdtp_context_t * context); avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_signaling_cid(uint16_t l2cap_cid, avdtp_context_t * context); +btstack_linked_list_t * avdtp_get_stream_endpoints(void); void avdtp_register_media_transport_category(avdtp_stream_endpoint_t * stream_endpoint); diff --git a/src/classic/avdtp_acceptor.c b/src/classic/avdtp_acceptor.c index 51d3046f9..36bc97249 100644 --- a/src/classic/avdtp_acceptor.c +++ b/src/classic/avdtp_acceptor.c @@ -448,7 +448,7 @@ static int avdtp_acceptor_send_response_reject_with_error_code(uint16_t cid, avd void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avdtp_context_t * context){ int sent = 1; - btstack_linked_list_t * stream_endpoints = &context->stream_endpoints; + btstack_linked_list_t * stream_endpoints = avdtp_get_stream_endpoints(); switch (connection->acceptor_connection_state){ case AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_ANSWER_DISCOVER_SEPS: @@ -477,7 +477,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd return; } - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(connection->acceptor_local_seid, context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(connection->acceptor_local_seid); if (!stream_endpoint) return; uint8_t reject_service_category = connection->reject_service_category; diff --git a/src/classic/avdtp_sink.c b/src/classic/avdtp_sink.c index c61dc0d87..305e9e27e 100644 --- a/src/classic/avdtp_sink.c +++ b/src/classic/avdtp_sink.c @@ -53,42 +53,42 @@ #include "classic/avdtp_util.h" void avdtp_sink_register_media_transport_category(uint8_t seid){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_sink_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_media_transport_category(stream_endpoint); } void avdtp_sink_register_reporting_category(uint8_t seid){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_sink_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_reporting_category(stream_endpoint); } void avdtp_sink_register_delay_reporting_category(uint8_t seid){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_sink_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_delay_reporting_category(stream_endpoint); } void avdtp_sink_register_recovery_category(uint8_t seid, uint8_t maximum_recovery_window_size, uint8_t maximum_number_media_packets){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_sink_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_recovery_category(stream_endpoint, maximum_recovery_window_size, maximum_number_media_packets); } void avdtp_sink_register_content_protection_category(uint8_t seid, uint16_t cp_type, const uint8_t * cp_type_value, uint8_t cp_type_value_len){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_sink_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_content_protection_category(stream_endpoint, cp_type, cp_type_value, cp_type_value_len); } void avdtp_sink_register_header_compression_category(uint8_t seid, uint8_t back_ch, uint8_t media, uint8_t recovery){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_sink_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_header_compression_category(stream_endpoint, back_ch, media, recovery); } void avdtp_sink_register_media_codec_category(uint8_t seid, 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){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_sink_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_media_codec_category(stream_endpoint, media_type, media_codec_type, media_codec_info, media_codec_info_len); } void avdtp_sink_register_multiplexing_category(uint8_t seid, uint8_t fragmentation){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_sink_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_multiplexing_category(stream_endpoint, fragmentation); } /* END: tracking can send now requests pro l2cap cid */ @@ -103,9 +103,7 @@ void avdtp_sink_register_packet_handler(btstack_packet_handler_t callback){ void avdtp_sink_init(avdtp_context_t * avdtp_context){ btstack_assert(avdtp_context != NULL); - avdtp_sink_context = avdtp_context; - avdtp_sink_context->stream_endpoints = NULL; - + avdtp_sink_context = avdtp_context; l2cap_register_service(&avdtp_packet_handler, BLUETOOTH_PSM_AVDTP, 0xffff, gap_get_security_level()); } diff --git a/src/classic/avdtp_source.c b/src/classic/avdtp_source.c index 527891d17..63abeac2e 100644 --- a/src/classic/avdtp_source.c +++ b/src/classic/avdtp_source.c @@ -55,42 +55,42 @@ #define AVDTP_MEDIA_PAYLOAD_HEADER_SIZE 12 void avdtp_source_register_media_transport_category(uint8_t seid){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_media_transport_category(stream_endpoint); } void avdtp_source_register_reporting_category(uint8_t seid){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_reporting_category(stream_endpoint); } void avdtp_source_register_delay_reporting_category(uint8_t seid){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_delay_reporting_category(stream_endpoint); } void avdtp_source_register_recovery_category(uint8_t seid, uint8_t maximum_recovery_window_size, uint8_t maximum_number_media_packets){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_recovery_category(stream_endpoint, maximum_recovery_window_size, maximum_number_media_packets); } void avdtp_source_register_content_protection_category(uint8_t seid, uint16_t cp_type, const uint8_t * cp_type_value, uint8_t cp_type_value_len){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_content_protection_category(stream_endpoint, cp_type, cp_type_value, cp_type_value_len); } void avdtp_source_register_header_compression_category(uint8_t seid, uint8_t back_ch, uint8_t media, uint8_t recovery){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_header_compression_category(stream_endpoint, back_ch, media, recovery); } void avdtp_source_register_media_codec_category(uint8_t seid, 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){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_media_codec_category(stream_endpoint, media_type, media_codec_type, media_codec_info, media_codec_info_len); } void avdtp_source_register_multiplexing_category(uint8_t seid, uint8_t fragmentation){ - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(seid); avdtp_register_multiplexing_category(stream_endpoint, fragmentation); } @@ -161,8 +161,6 @@ void avdtp_source_init(avdtp_context_t * avdtp_context){ btstack_assert(avdtp_context != NULL); avdtp_source_context = avdtp_context; - avdtp_source_context->stream_endpoints = NULL; - l2cap_register_service(&avdtp_packet_handler, BLUETOOTH_PSM_AVDTP, 0xffff, gap_get_security_level()); } @@ -213,7 +211,7 @@ static void avdtp_source_copy_media_payload(uint8_t * media_packet, int size, in int avdtp_source_stream_send_media_payload(uint16_t avdtp_cid, uint8_t local_seid, uint8_t * storage, int num_bytes_to_copy, uint8_t num_frames, uint8_t marker){ UNUSED(avdtp_cid); - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid); if (!stream_endpoint) { log_error("avdtp source: no stream_endpoint with seid %d", local_seid); return 0; @@ -240,7 +238,7 @@ int avdtp_source_stream_send_media_payload(uint16_t avdtp_cid, uint8_t local_sei void avdtp_source_stream_endpoint_request_can_send_now(uint16_t avdtp_cid, uint8_t local_seid){ UNUSED(avdtp_cid); - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid); if (!stream_endpoint) { log_error("AVDTP source: no stream_endpoint with seid %d", local_seid); return; @@ -252,7 +250,7 @@ void avdtp_source_stream_endpoint_request_can_send_now(uint16_t avdtp_cid, uint8 int avdtp_max_media_payload_size(uint16_t avdtp_cid, uint8_t local_seid){ UNUSED(avdtp_cid); - avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid, avdtp_source_context); + avdtp_stream_endpoint_t * stream_endpoint = avdtp_get_stream_endpoint_for_seid(local_seid); if (!stream_endpoint) { log_error("A2DP source: no stream_endpoint with seid %d", local_seid); return 0;