From c70720c67056dadfbbef227c89dcb22a37fba036 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 16 Jul 2021 12:19:04 +0200 Subject: [PATCH] avdtp: media config validator is called with preview of media codec configuration event --- CHANGELOG.md | 1 + src/classic/avdtp.c | 12 ++++++++---- src/classic/avdtp.h | 7 +++++-- src/classic/avdtp_acceptor.c | 4 ++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 610fdaad6..6d6f220ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - HFP: removed one parameter from hfp_ag/hf_activate_voice_recognition function, instead introduced hfp_ag/hf_deactivate_voice_recognition - HFP: event HFP_SUBEVENT_VOICE_RECOGNITION_STATUS emitted on (enhanced) voice recognition status change. Field "activated" replaced with "state". Added additional "status" field that indicates if the command was successful. - HFP: streamlined enhanced voice recognition function names +- AVDTP: media config validator is called with preview of media codec configuration event - Run Loop: new functionality for HCI transport drivers and inter-process communication - *btstack_run_loop_poll_data_sources_from_irq*: used to transfer control from IRQ handler to main thread/run loop - *btstack_run_loop_execute_on_main_thread*: schedule code execution on main thread from other thread diff --git a/src/classic/avdtp.c b/src/classic/avdtp.c index 1b489a047..f5d2f32a9 100644 --- a/src/classic/avdtp.c +++ b/src/classic/avdtp.c @@ -47,6 +47,7 @@ #include "btstack_event.h" #include "btstack_memory.h" #include "classic/avdtp.h" +#include "classic/avdtp_util.h" #include "classic/avdtp_acceptor.h" #include "classic/avdtp_initiator.h" #include "classic/avdtp_util.h" @@ -60,7 +61,7 @@ static bool l2cap_registered; static btstack_packet_handler_t avdtp_source_callback; static btstack_packet_handler_t avdtp_sink_callback; static btstack_context_callback_registration_t avdtp_handle_sdp_client_query_request; -static uint8_t (*avdtp_media_config_validator)(const avdtp_stream_endpoint_t * stream_endpoint, avdtp_media_codec_type_t media_codec_type, const uint8_t * media_codec_info, uint16_t media_codec_info_len); +static uint8_t (*avdtp_media_config_validator)(const avdtp_stream_endpoint_t * stream_endpoint, const uint8_t * event, uint16_t size); static uint16_t sdp_query_context_avdtp_cid = 0; @@ -432,15 +433,18 @@ void avdtp_register_media_handler(void (*callback)(uint8_t local_seid, uint8_t * avdtp_sink_handle_media_data = callback; } -void avdtp_register_media_config_validator(uint8_t (*callback)(const avdtp_stream_endpoint_t * stream_endpoint, avdtp_media_codec_type_t media_codec_type, const uint8_t * media_codec_info, uint16_t media_codec_info_len)){ +void avdtp_register_media_config_validator(uint8_t (*callback)(const avdtp_stream_endpoint_t * stream_endpoint, const uint8_t * event, uint16_t size)){ avdtp_media_config_validator = callback; } -uint8_t avdtp_validate_media_configuration(const avdtp_stream_endpoint_t * stream_endpoint, avdtp_media_codec_type_t media_codec_type, const uint8_t * media_codec_info, uint16_t media_codec_info_len){ +uint8_t avdtp_validate_media_configuration(const avdtp_stream_endpoint_t *stream_endpoint, uint16_t avdtp_cid, + uint8_t reconfigure, const adtvp_media_codec_capabilities_t *media_codec) { if (avdtp_media_config_validator == NULL) { return 0; } - return (*avdtp_media_config_validator)(stream_endpoint, media_codec_type, media_codec_info, media_codec_info_len); + uint8_t event[AVDTP_MEDIA_CONFIG_OTHER_EVENT_LEN]; + uint16_t size = avdtp_setup_media_codec_config_event(event, sizeof(event), stream_endpoint, avdtp_cid, reconfigure, media_codec); + return (*avdtp_media_config_validator)(stream_endpoint, event, size); } /* START: tracking can send now requests per l2cap cid */ diff --git a/src/classic/avdtp.h b/src/classic/avdtp.h index be7dfd948..c45e42bd8 100644 --- a/src/classic/avdtp.h +++ b/src/classic/avdtp.h @@ -628,9 +628,11 @@ void avdtp_register_media_handler(void (*callback)(uint8_t local_seid, uint8_t * /** * @brief Register media configuration validator. Can reject insuitable configuration or report stream endpoint as currently busy * @note validator has to return AVDTP error codes like: AVDTP_ERROR_CODE_SEP_IN_USE or AVDTP_ERROR_CODE_UNSUPPORTED_CONFIGURATION + * the callback receives the media configuration in the same format as the existing AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION + * and similar * @param callback */ -void avdtp_register_media_config_validator(uint8_t (*callback)(const avdtp_stream_endpoint_t * stream_endpoint, avdtp_media_codec_type_t media_codec_type, const uint8_t * media_codec_info, uint16_t media_codec_info_len)); +void avdtp_register_media_config_validator(uint8_t (*callback)(const avdtp_stream_endpoint_t * stream_endpoint, const uint8_t * event, uint16_t size)); void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); avdtp_stream_endpoint_t * avdtp_create_stream_endpoint(avdtp_sep_type_t sep_type, avdtp_media_type_t media_type); @@ -653,7 +655,8 @@ uint8_t avdtp_get_all_capabilities(uint16_t avdtp_cid, uint8_t remote_seid); uint8_t avdtp_get_configuration(uint16_t avdtp_cid, uint8_t remote_seid); uint8_t avdtp_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration); uint8_t avdtp_reconfigure(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration); -uint8_t avdtp_validate_media_configuration(const avdtp_stream_endpoint_t * stream_endpoint, avdtp_media_codec_type_t media_codec_type, const uint8_t * media_codec_info, uint16_t media_codec_info_len); +uint8_t avdtp_validate_media_configuration(const avdtp_stream_endpoint_t *stream_endpoint, uint16_t avdtp_cid, + uint8_t reconfigure, const adtvp_media_codec_capabilities_t *media_codec); // frequency will be used by avdtp_choose_sbc_sampling_frequency (if supported by both endpoints) void avdtp_set_preferred_sampling_frequency(avdtp_stream_endpoint_t * stream_endpoint, uint32_t sampling_frequency); diff --git a/src/classic/avdtp_acceptor.c b/src/classic/avdtp_acceptor.c index 770782569..6089cbb3b 100644 --- a/src/classic/avdtp_acceptor.c +++ b/src/classic/avdtp_acceptor.c @@ -111,8 +111,8 @@ avdtp_acceptor_handle_configuration_command(avdtp_connection_t *connection, int // let application validate media configuration as well if (connection->error_code == 0){ if ((sep.configured_service_categories & (1 << AVDTP_MEDIA_CODEC)) != 0){ - adtvp_media_codec_capabilities_t * media = & sep.configuration.media_codec; - uint8_t error_code = avdtp_validate_media_configuration(stream_endpoint, media->media_codec_type, media->media_codec_information, media->media_codec_information_len); + const adtvp_media_codec_capabilities_t * media = &sep.configuration.media_codec; + uint8_t error_code = avdtp_validate_media_configuration(stream_endpoint, connection->avdtp_cid, 0, media); if (error_code != 0){ log_info("media codec rejected by validator, error 0x%02x", error_code); connection->reject_service_category = AVDTP_MEDIA_CODEC;