diff --git a/src/classic/avdtp.h b/src/classic/avdtp.h index 27c60742a..0daea16f5 100644 --- a/src/classic/avdtp.h +++ b/src/classic/avdtp.h @@ -449,9 +449,6 @@ typedef struct avdtp_stream_endpoint { uint8_t media_disconnect; uint8_t media_connect; uint16_t sequence_number; - - // to app - btstack_sbc_encoder_state_t sbc_encoder_state; } avdtp_stream_endpoint_t; typedef struct { diff --git a/src/classic/avdtp_acceptor.c b/src/classic/avdtp_acceptor.c index 33b647795..e6c1ca28a 100644 --- a/src/classic/avdtp_acceptor.c +++ b/src/classic/avdtp_acceptor.c @@ -248,7 +248,6 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; printf(" ACP: add seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); } - if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){ switch (sep.configuration.media_codec.media_codec_type){ case AVDTP_CODEC_SBC: @@ -541,10 +540,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd printf(" -> AVDTP_STREAM_ENDPOINT_CONFIGURED\n"); stream_endpoint->connection = connection; stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED; - // TODO: use actual config // TODO: consider reconfiguration - btstack_sbc_encoder_init(&stream_endpoint->sbc_encoder_state, SBC_MODE_STANDARD, 16, 8, 2, 44100, 53); - avdtp_acceptor_send_accept_response(cid, trid, AVDTP_SI_SET_CONFIGURATION); break; case AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE: diff --git a/src/classic/avdtp_initiator.c b/src/classic/avdtp_initiator.c index 070bc05d3..5fd7ca99d 100644 --- a/src/classic/avdtp_initiator.c +++ b/src/classic/avdtp_initiator.c @@ -65,32 +65,6 @@ static int avdtp_initiator_send_signaling_cmd_with_seid(uint16_t cid, avdtp_sign return l2cap_send(cid, command, sizeof(command)); } -static void avdtp_signaling_emit_media_codec_capability(btstack_packet_handler_t callback, uint16_t con_handle, avdtp_sep_t sep){ - if (get_bit16(sep.registered_service_categories, AVDTP_MEDIA_CODEC)){ - switch (sep.capabilities.media_codec.media_codec_type){ - case AVDTP_CODEC_SBC: - avdtp_signaling_emit_media_codec_sbc_capability(callback, con_handle, sep.capabilities.media_codec); - break; - default: - avdtp_signaling_emit_media_codec_other_capability(callback, con_handle, sep.capabilities.media_codec); - break; - } - } -} - -static void avdtp_signaling_emit_media_codec_configuration(btstack_packet_handler_t callback, uint16_t con_handle, avdtp_sep_t sep){ - if (get_bit16(sep.registered_service_categories, AVDTP_MEDIA_CODEC)){ - switch (sep.capabilities.media_codec.media_codec_type){ - case AVDTP_CODEC_SBC: - avdtp_signaling_emit_media_codec_sbc_configuration(callback, con_handle, sep.capabilities.media_codec); - break; - default: - avdtp_signaling_emit_media_codec_other_configuration(callback, con_handle, sep.capabilities.media_codec); - break; - } - } -} - void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_t *packet, uint16_t size, int offset, avdtp_context_t * context){ int status = 0; avdtp_stream_endpoint_t * stream_endpoint = NULL; @@ -151,14 +125,31 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_ case AVDTP_SI_GET_ALL_CAPABILITIES: printf("AVDTP_SI_GET(_ALL)_CAPABILITIES\n"); sep.registered_service_categories = avdtp_unpack_service_capabilities(connection, &sep.capabilities, packet+offset, size-offset); - avdtp_signaling_emit_media_codec_capability(context->avdtp_callback, connection->con_handle, sep); + if (get_bit16(sep.registered_service_categories, AVDTP_MEDIA_CODEC)){ + switch (sep.capabilities.media_codec.media_codec_type){ + case AVDTP_CODEC_SBC: + avdtp_signaling_emit_media_codec_sbc_capability(context->avdtp_callback, connection->con_handle, sep.capabilities.media_codec); + break; + default: + avdtp_signaling_emit_media_codec_other_capability(context->avdtp_callback, connection->con_handle, sep.capabilities.media_codec); + break; + } + } break; case AVDTP_SI_GET_CONFIGURATION: printf("AVDTP_SI_GET_CONFIGURATION\n"); sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, packet+offset, size-offset); - - avdtp_signaling_emit_media_codec_configuration(context->avdtp_callback, connection->con_handle, sep); + if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){ + switch (sep.configuration.media_codec.media_codec_type){ + case AVDTP_CODEC_SBC: + avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->con_handle, sep.configuration.media_codec); + break; + default: + avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->con_handle, sep.configuration.media_codec); + break; + } + } break; case AVDTP_SI_RECONFIGURE: @@ -193,10 +184,6 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_ stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; printf(" INT: configured remote seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED; - - // TODO: use actual config - // TODO: consider reconfiguration - btstack_sbc_encoder_init(&stream_endpoint->sbc_encoder_state, SBC_MODE_STANDARD, 16, 8, 2, 44100, 53); break; } diff --git a/test/avdtp/avdtp_sink_test.c b/test/avdtp/avdtp_sink_test.c index 9f05090ed..e482f759c 100644 --- a/test/avdtp/avdtp_sink_test.c +++ b/test/avdtp/avdtp_sink_test.c @@ -477,7 +477,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe sbc_configuration.max_bitpool_value = avdtp_subevent_signaling_media_codec_sbc_configuration_get_max_bitpool_value(packet); sbc_configuration.frames_per_buffer = sbc_configuration.subbands * sbc_configuration.block_length; dump_sbc_configuration(sbc_configuration); - + // // TODO: use actual config + // btstack_sbc_encoder_init(&local_stream_endpoint->sbc_encoder_state, SBC_MODE_STANDARD, 16, 8, 2, 44100, 53); + if (sbc_configuration.reconfigure){ close_media_processing(); init_media_processing(sbc_configuration); diff --git a/test/avdtp/avdtp_source_demo.c b/test/avdtp/avdtp_source_demo.c index beebb4fac..6ebec2743 100644 --- a/test/avdtp/avdtp_source_demo.c +++ b/test/avdtp/avdtp_source_demo.c @@ -83,6 +83,7 @@ typedef struct { uint32_t acc_num_missed_samples; btstack_timer_source_t fill_audio_ring_buffer_timer; btstack_ring_buffer_t sbc_ring_buffer; + btstack_sbc_encoder_state_t sbc_encoder_state; } avdtp_stream_endpoint_context_t; typedef struct { @@ -170,6 +171,7 @@ typedef enum { AVDTP_APPLICATION_W2_GET_CAPABILITIES, AVDTP_APPLICATION_W2_GET_ALL_CAPABILITIES, AVDTP_APPLICATION_W2_SET_CONFIGURATION, + AVDTP_APPLICATION_W4_GET_CONFIGURATION, AVDTP_APPLICATION_W4_SET_CONFIGURATION, AVDTP_APPLICATION_W2_SUSPEND_STREAM_WITH_SEID, AVDTP_APPLICATION_W2_RECONFIGURE_WITH_SEID, @@ -359,7 +361,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe break; case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION:{ - app_state = AVDTP_APPLICATION_IDLE; sbc_configuration.reconfigure = avdtp_subevent_signaling_media_codec_sbc_configuration_get_reconfigure(packet); sbc_configuration.num_channels = avdtp_subevent_signaling_media_codec_sbc_configuration_get_num_channels(packet); sbc_configuration.sampling_frequency = avdtp_subevent_signaling_media_codec_sbc_configuration_get_sampling_frequency(packet); @@ -378,7 +379,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe case AVDTP_SUBEVENT_SIGNALING_ACCEPT: signal_identifier = avdtp_subevent_signaling_accept_get_signal_identifier(packet); status = avdtp_subevent_signaling_accept_get_status(packet); - printf(" --- avdtp source --- Accepted %d %s\n", signal_identifier, avdtp_si2str(signal_identifier)); + printf(" --- avdtp source --- Accepted %d %s, app state %d\n", signal_identifier, avdtp_si2str(signal_identifier), app_state); + switch (app_state){ case AVDTP_APPLICATION_W2_DISCOVER_SEPS: app_state = AVDTP_APPLICATION_W2_GET_ALL_CAPABILITIES; @@ -398,11 +400,17 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe } break; case AVDTP_APPLICATION_W2_SET_CONFIGURATION: - app_state = AVDTP_APPLICATION_W4_SET_CONFIGURATION; + app_state = AVDTP_APPLICATION_W2_GET_CONFIGURATION; avdtp_source_set_configuration(con_handle, local_stream_endpoint->sep.seid, active_remote_sep->seid, remote_configuration_bitmap, remote_configuration); break; - case AVDTP_APPLICATION_W4_SET_CONFIGURATION: + case AVDTP_APPLICATION_W2_GET_CONFIGURATION: + app_state = AVDTP_APPLICATION_W2_OPEN_STREAM_WITH_SEID; + avdtp_source_get_configuration(con_handle, active_remote_sep->seid); + break; + case AVDTP_APPLICATION_W2_OPEN_STREAM_WITH_SEID: app_state = AVDTP_APPLICATION_W4_OPEN_STREAM_WITH_SEID; + btstack_sbc_encoder_init(&streaming_context.sbc_encoder_state, SBC_MODE_STANDARD, sbc_configuration.block_length, sbc_configuration.subbands, sbc_configuration.num_channels, sbc_configuration.sampling_frequency, 53); + dump_sbc_configuration(sbc_configuration); avdtp_source_open_stream(con_handle, active_remote_sep->seid); break; case AVDTP_APPLICATION_STREAMING_OPENED: