diff --git a/example/a2dp_source_demo.c b/example/a2dp_source_demo.c index 93f5e1c7a..b201427b1 100644 --- a/example/a2dp_source_demo.c +++ b/example/a2dp_source_demo.c @@ -245,12 +245,12 @@ static int a2dp_source_and_avrcp_services_init(void){ a2dp_source_register_packet_handler(&a2dp_source_packet_handler); // Create stream endpoint. - uint8_t status = a2dp_source_create_stream_endpoint(AVDTP_AUDIO, AVDTP_CODEC_SBC, media_sbc_codec_capabilities, sizeof(media_sbc_codec_capabilities), media_sbc_codec_configuration, sizeof(media_sbc_codec_configuration), &media_tracker.local_seid); - if (status != ERROR_CODE_SUCCESS){ + avdtp_stream_endpoint_t * local_stream_endpoint = a2dp_source_create_stream_endpoint(AVDTP_AUDIO, AVDTP_CODEC_SBC, media_sbc_codec_capabilities, sizeof(media_sbc_codec_capabilities), media_sbc_codec_configuration, sizeof(media_sbc_codec_configuration)); + if (!local_stream_endpoint){ printf("A2DP Source: not enough memory to create local stream endpoint\n"); return 1; } - + media_tracker.local_seid = avdtp_local_seid(local_stream_endpoint); // Initialize AVRCP Target. avrcp_target_init(); diff --git a/src/classic/a2dp_source.c b/src/classic/a2dp_source.c index 5e45ae9fc..b15ed35b6 100644 --- a/src/classic/a2dp_source.c +++ b/src/classic/a2dp_source.c @@ -444,21 +444,20 @@ void a2dp_source_init(void){ avdtp_source_init(&a2dp_source_context); } -uint8_t a2dp_source_create_stream_endpoint(avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type, +avdtp_stream_endpoint_t * a2dp_source_create_stream_endpoint(avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type, uint8_t * codec_capabilities, uint16_t codec_capabilities_len, - uint8_t * media_codec_info, uint16_t media_codec_info_len, uint8_t * local_seid){ - *local_seid = 0; + uint8_t * media_codec_info, uint16_t media_codec_info_len){ avdtp_stream_endpoint_t * local_stream_endpoint = avdtp_source_create_stream_endpoint(AVDTP_SOURCE, media_type); if (!local_stream_endpoint){ - return BTSTACK_MEMORY_ALLOC_FAILED; + return NULL; } - *local_seid = avdtp_local_seid(local_stream_endpoint); avdtp_source_register_media_transport_category(avdtp_stream_endpoint_seid(local_stream_endpoint)); avdtp_source_register_media_codec_category(avdtp_stream_endpoint_seid(local_stream_endpoint), media_type, media_codec_type, codec_capabilities, codec_capabilities_len); local_stream_endpoint->remote_configuration.media_codec.media_codec_information = media_codec_info; local_stream_endpoint->remote_configuration.media_codec.media_codec_information_len = media_codec_info_len; - return ERROR_CODE_SUCCESS; + sc.local_stream_endpoint = local_stream_endpoint; + return local_stream_endpoint; } uint8_t a2dp_source_establish_stream(bd_addr_t remote_addr, uint8_t loc_seid, uint16_t * a2dp_cid){ diff --git a/src/classic/a2dp_source.h b/src/classic/a2dp_source.h index a36143475..7dcdd71ce 100644 --- a/src/classic/a2dp_source.h +++ b/src/classic/a2dp_source.h @@ -81,9 +81,9 @@ void a2dp_source_init(void); * * @return status ERROR_CODE_SUCCESS if sucessful. */ -uint8_t a2dp_source_create_stream_endpoint(avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type, - uint8_t * codec_capabilities, uint16_t codec_capabilities_len, - uint8_t * media_codec_info, uint16_t media_codec_info_len, uint8_t * local_seid); +avdtp_stream_endpoint_t * a2dp_source_create_stream_endpoint(avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type, + uint8_t * codec_capabilities, uint16_t codec_capabilities_len, + uint8_t * codec_configuration, uint16_t codec_configuration_len); /** * @brief Register callback for the A2DP Source client. It will receive following subevents of HCI_EVENT_A2DP_META HCI event type: diff --git a/test/pts/avdtp_source_test.c b/test/pts/avdtp_source_test.c index 8e4baea1e..6d88059df 100644 --- a/test/pts/avdtp_source_test.c +++ b/test/pts/avdtp_source_test.c @@ -774,9 +774,11 @@ int btstack_main(int argc, const char * argv[]){ avdtp_source_init(&a2dp_source_context); avdtp_source_register_packet_handler(&packet_handler); - a2dp_source_create_stream_endpoint(AVDTP_AUDIO, AVDTP_CODEC_SBC, (uint8_t *) media_sbc_codec_capabilities, sizeof(media_sbc_codec_capabilities), (uint8_t*) media_sbc_codec_configuration, sizeof(media_sbc_codec_configuration), &media_tracker.local_seid); + sc.local_stream_endpoint = a2dp_source_create_stream_endpoint(AVDTP_AUDIO, AVDTP_CODEC_SBC, (uint8_t *) media_sbc_codec_capabilities, sizeof(media_sbc_codec_capabilities), (uint8_t*) media_sbc_codec_configuration, sizeof(media_sbc_codec_configuration)); + media_tracker.local_seid = avdtp_local_seid(sc.local_stream_endpoint); media_tracker.remote_seid = 1; + // Initialize SDP sdp_init(); memset(sdp_avdtp_source_service_buffer, 0, sizeof(sdp_avdtp_source_service_buffer));