avdtp source demo: fix avdtp cid, use local/remote seid

This commit is contained in:
Milanka Ringwald 2017-07-12 12:55:57 +02:00
parent 36cf8ec8a2
commit 6b0ee1d045
7 changed files with 289 additions and 310 deletions

View File

@ -883,11 +883,11 @@ static void stdin_process(char cmd){
sep.seid = 1;
switch (cmd){
case 'b':
printf("Creating L2CAP Connection to %s, PSM_AVDTP\n", bd_addr_to_str(device_addr));
printf(" - Create AVDTP connection to addr %s.\n", bd_addr_to_str(device_addr));
a2dp_sink_establish_stream(device_addr, local_seid, &a2dp_cid);
break;
case 'B':
printf("Disconnect\n");
printf(" - Disconnect\n");
avdtp_sink_disconnect(a2dp_cid);
break;
case 'c':

View File

@ -41,23 +41,8 @@
#include <stdlib.h>
#include <string.h>
#include "btstack_config.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "gap.h"
#include "hci.h"
#include "hci_cmd.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "btstack_stdin.h"
#include "classic/a2dp_source.h"
#include "classic/avdtp_source.h"
#include "classic/avdtp_util.h"
#include "classic/btstack_sbc.h"
#include "btstack.h"
#include "sbc_encoder.h"
#include "hxcmod.h"
#include "mods/mod.h"
@ -155,7 +140,7 @@ static void a2dp_fill_audio_buffer_timer_pause(a2dp_media_sending_context_t * co
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(channel);
UNUSED(size);
uint8_t status;
switch (packet_type) {
case HCI_EVENT_PACKET:
@ -163,19 +148,17 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
case HCI_EVENT_A2DP_META:
switch (packet[2]){
case A2DP_SUBEVENT_STREAM_ESTABLISHED:
status = a2dp_subevent_stream_established_get_status(packet);
if (status){
printf("Stream establishment failed: status 0x%02x.\n", status);
break;
}
media_tracker.local_seid = a2dp_subevent_stream_established_get_local_seid(packet);
media_tracker.a2dp_cid = a2dp_subevent_stream_established_get_a2dp_cid(packet);
printf(" --- application --- A2DP_SUBEVENT_STREAM_ESTABLISHED, a2dp_cid 0x%02x, local seid %d, remote seid %d\n",
printf("Stream established: a2dp cid 0x%02x, local seid %d, remote seid %d.\n",
media_tracker.a2dp_cid, media_tracker.local_seid, a2dp_subevent_stream_established_get_remote_seid(packet));
break;
case A2DP_SUBEVENT_STREAM_STARTED:
if (local_seid != media_tracker.local_seid) break;
if (!a2dp_source_stream_endpoint_ready(media_tracker.a2dp_cid, media_tracker.local_seid)) break;
a2dp_fill_audio_buffer_timer_start(&media_tracker);
printf(" --- application --- A2DP_SUBEVENT_STREAM_START_ACCEPTED, local seid %d\n", media_tracker.local_seid);
break;
case A2DP_SUBEVENT_STREAMING_CAN_SEND_MEDIA_PACKET_NOW:{
if (local_seid != media_tracker.local_seid) break;
@ -188,17 +171,24 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
media_tracker.sbc_ready_to_send = 0;
break;
}
case A2DP_SUBEVENT_STREAM_STARTED:
if (local_seid != media_tracker.local_seid) break;
if (!a2dp_source_stream_endpoint_ready(media_tracker.a2dp_cid, media_tracker.local_seid)) break;
a2dp_fill_audio_buffer_timer_start(&media_tracker);
printf("Stream started.\n");
break;
case A2DP_SUBEVENT_STREAM_SUSPENDED:
printf(" --- application --- A2DP_SUBEVENT_STREAM_SUSPENDED, local seid %d\n", media_tracker.local_seid);
printf("Stream paused.\n");
a2dp_fill_audio_buffer_timer_pause(&media_tracker);
break;
case A2DP_SUBEVENT_STREAM_RELEASED:
printf(" --- application --- A2DP_SUBEVENT_STREAM_RELEASED, local seid %d\n", media_tracker.local_seid);
printf("Stream released.\n");
a2dp_fill_audio_buffer_timer_stop(&media_tracker);
break;
default:
printf(" --- application --- not implemented\n");
printf("AVDTP Source demo: event 0x%02x is not implemented\n", packet[2]);
break;
}
break;
@ -334,13 +324,12 @@ static void show_usage(void){
gap_local_bd_addr(iut_address);
printf("\n--- Bluetooth AVDTP SOURCE Test Console %s ---\n", bd_addr_to_str(iut_address));
printf("c - create connection to addr %s\n", bd_addr_to_str(remote));
printf("C - disconnect\n");
printf("x - start streaming sine\n");
if (hxcmod_initialized){
printf("z - start streaming '%s'\n", mod_name);
}
printf("p - pause streaming\n");
printf("X - stop streaming\n");
printf("C - disconnect\n");
printf("Ctrl-c - exit\n");
printf("---\n");
}
@ -351,27 +340,23 @@ static void stdin_process(char cmd){
printf("Creating L2CAP Connection to %s, PSM_AVDTP\n", bd_addr_to_str(remote));
a2dp_source_establish_stream(remote, local_seid, &media_tracker.a2dp_cid);
break;
case 'C':
printf("Disconnect\n");
a2dp_source_disconnect(media_tracker.a2dp_cid);
break;
case 'x':
printf("Stream sine, local seid %d\n", media_tracker.local_seid);
printf("Playing sine.\n");
data_source = STREAM_SINE;
a2dp_source_start_stream(media_tracker.a2dp_cid, media_tracker.local_seid);
break;
case 'z':
printf("Stream mode, local seid %d\n", media_tracker.local_seid);
printf("Playing mod.\n");
data_source = STREAM_MOD;
a2dp_source_start_stream(media_tracker.a2dp_cid, media_tracker.local_seid);
break;
case 'p':
printf("Pause stream, local seid %d\n", media_tracker.local_seid);
printf("Pause stream.\n");
a2dp_source_pause_stream(media_tracker.a2dp_cid, media_tracker.local_seid);
break;
case 'X':
printf("Close stream, local seid %d\n", media_tracker.local_seid);
a2dp_source_release_stream(media_tracker.a2dp_cid, media_tracker.local_seid);
case 'C':
printf("Disconnect\n");
a2dp_source_disconnect(media_tracker.a2dp_cid);
break;
default:
show_usage();

View File

@ -147,14 +147,11 @@ static inline uint16_t a2dp_cid(void){
}
static inline uint8_t local_seid(void){
if (!sc.local_stream_endpoint) return 0;
return sc.local_stream_endpoint->sep.seid;
return avdtp_local_seid(sc.local_stream_endpoint);
}
static inline uint8_t remote_seid(void){
if (!sc.local_stream_endpoint) return 0;
if (!sc.local_stream_endpoint->connection) return 0;
return sc.local_stream_endpoint->connection->remote_seps[sc.local_stream_endpoint->remote_sep_index].seid;
return avdtp_remote_seid(sc.local_stream_endpoint);
}
static void a2dp_streaming_emit_connection_established(btstack_packet_handler_t callback, uint16_t cid, uint8_t local_seid, uint8_t remote_seid, uint8_t status){
@ -195,231 +192,226 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
uint8_t loc_seid;
uint8_t rem_seid;
uint16_t cid;
bd_addr_t address;
switch (packet_type) {
case HCI_EVENT_PACKET:
switch (hci_event_packet_get_type(packet)) {
case HCI_EVENT_DISCONNECTION_COMPLETE:
// connection closed -> quit test app
log_info("\n --- a2dp source --- HCI_EVENT_DISCONNECTION_COMPLETE ---");
if (packet_type != HCI_EVENT_PACKET) return;
if (hci_event_packet_get_type(packet) != HCI_EVENT_AVDTP_META) return;
switch (packet[2]){
case AVDTP_SUBEVENT_SIGNALING_CONNECTION_ESTABLISHED:
// TODO cmp bt addr
avdtp_subevent_signaling_connection_established_get_bd_addr(packet, address);
if (memcmp(address, &sc.remote_addr, 6) != 0) break;
cid = avdtp_subevent_signaling_connection_established_get_avdtp_cid(packet);
status = avdtp_subevent_signaling_connection_established_get_status(packet);
if (status != 0){
log_info("AVDTP_SUBEVENT_SIGNALING_CONNECTION failed status %d ---", status);
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, cid, 0, 0, status);
break;
}
sc.active_remote_sep = NULL;
next_remote_sep_index_to_query = 0;
app_state = A2DP_W2_DISCOVER_SEPS;
log_info("AVDTP_SUBEVENT_SIGNALING_CONNECTION_ESTABLISHED, avdtp cid 0x%02x ---", cid);
avdtp_source_discover_stream_endpoints(cid);
break;
case AVDTP_SUBEVENT_SIGNALING_SEP_FOUND:
// TODO check cid
if (app_state != A2DP_W2_DISCOVER_SEPS) return;
sep.seid = avdtp_subevent_signaling_sep_found_get_remote_seid(packet);
sep.in_use = avdtp_subevent_signaling_sep_found_get_in_use(packet);
sep.media_type = (avdtp_media_type_t) avdtp_subevent_signaling_sep_found_get_media_type(packet);
sep.type = (avdtp_sep_type_t) avdtp_subevent_signaling_sep_found_get_sep_type(packet);
log_info("found sep: seid %u, in_use %d, media type %d, sep type %d (1-SNK)", sep.seid, sep.in_use, sep.media_type, sep.type);
break;
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY:{
// TODO check cid
if (!sc.local_stream_endpoint) return;
uint8_t sampling_frequency = avdtp_choose_sbc_sampling_frequency(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_sampling_frequency_bitmap(packet));
uint8_t channel_mode = avdtp_choose_sbc_channel_mode(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_channel_mode_bitmap(packet));
uint8_t block_length = avdtp_choose_sbc_block_length(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_block_length_bitmap(packet));
uint8_t subbands = avdtp_choose_sbc_subbands(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_subbands_bitmap(packet));
uint8_t allocation_method = avdtp_choose_sbc_allocation_method(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_allocation_method_bitmap(packet));
uint8_t max_bitpool_value = avdtp_choose_sbc_max_bitpool_value(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_max_bitpool_value(packet));
uint8_t min_bitpool_value = avdtp_choose_sbc_min_bitpool_value(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_min_bitpool_value(packet));
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_information[0] = (sampling_frequency << 4) | channel_mode;
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_information[1] = (block_length << 4) | (subbands << 2) | allocation_method;
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_information[2] = min_bitpool_value;
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_information[3] = max_bitpool_value;
sc.local_stream_endpoint->remote_configuration_bitmap = store_bit16(sc.local_stream_endpoint->remote_configuration_bitmap, AVDTP_MEDIA_CODEC, 1);
sc.local_stream_endpoint->remote_configuration.media_codec.media_type = AVDTP_AUDIO;
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_type = AVDTP_CODEC_SBC;
app_state = A2DP_W2_SET_CONFIGURATION;
break;
}
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY:
log_info("received non SBC codec. not implemented");
break;
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION:{
// TODO check cid
sc.sampling_frequency = avdtp_subevent_signaling_media_codec_sbc_configuration_get_sampling_frequency(packet);
sc.block_length = avdtp_subevent_signaling_media_codec_sbc_configuration_get_block_length(packet);
sc.subbands = avdtp_subevent_signaling_media_codec_sbc_configuration_get_subbands(packet);
sc.allocation_method = avdtp_subevent_signaling_media_codec_sbc_configuration_get_allocation_method(packet) - 1;
sc.max_bitpool_value = avdtp_subevent_signaling_media_codec_sbc_configuration_get_max_bitpool_value(packet);
// TODO: deal with reconfigure: avdtp_subevent_signaling_media_codec_sbc_configuration_get_reconfigure(packet);
break;
}
case AVDTP_SUBEVENT_STREAMING_CAN_SEND_MEDIA_PACKET_NOW:
a2dp_streaming_emit_can_send_media_packet_now(a2dp_source_context.a2dp_callback, a2dp_cid(), 0);
break;
case AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED:
status = avdtp_subevent_streaming_connection_established_get_status(packet);
cid = avdtp_subevent_streaming_connection_established_get_avdtp_cid(packet);
if (cid != a2dp_cid()){
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), remote_seid(), ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER);
break;
}
loc_seid = avdtp_subevent_streaming_connection_established_get_local_seid(packet);
if (loc_seid != local_seid()){
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), remote_seid(), ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER);
break;
}
rem_seid = avdtp_subevent_streaming_connection_established_get_remote_seid(packet);
if (status != 0){
log_info("AVDTP_SUBEVENT_STREAMING_CONNECTION could not be established, status %d ---", status);
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), rem_seid, status);
break;
}
app_state = A2DP_STREAMING_OPENED;
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), remote_seid(), 0);
log_info("AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED --- avdtp_cid 0x%02x, local seid %d, remote seid %d", a2dp_cid(), local_seid(), remote_seid());
break;
case AVDTP_SUBEVENT_SIGNALING_ACCEPT:
// TODO check cid
signal_identifier = avdtp_subevent_signaling_accept_get_signal_identifier(packet);
cid = avdtp_subevent_signaling_accept_get_avdtp_cid(packet);
log_info("Accepted %d", signal_identifier);
switch (app_state){
case A2DP_W2_DISCOVER_SEPS:
app_state = A2DP_W2_GET_ALL_CAPABILITIES;
sc.active_remote_sep = avdtp_source_remote_sep(cid, next_remote_sep_index_to_query++);
if (!sc.active_remote_sep) {
app_state = A2DP_IDLE;
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, cid, 0, 0, AVDTP_SEID_DOES_NOT_EXIST);
break;
}
log_info("Query get caps for seid %d", sc.active_remote_sep->seid);
avdtp_source_get_capabilities(cid, sc.active_remote_sep->seid);
break;
case HCI_EVENT_AVDTP_META:
switch (packet[2]){
case AVDTP_SUBEVENT_SIGNALING_CONNECTION_ESTABLISHED:
cid = avdtp_subevent_signaling_connection_established_get_avdtp_cid(packet);
if (cid != a2dp_cid()){
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), remote_seid(), ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER);
break;
}
status = avdtp_subevent_signaling_connection_established_get_status(packet);
if (status != 0){
log_info(" --- a2dp source --- AVDTP_SUBEVENT_SIGNALING_CONNECTION could not be established, status %d ---", status);
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), remote_seid(), status);
break;
}
sc.active_remote_sep = NULL;
next_remote_sep_index_to_query = 0;
app_state = A2DP_W2_DISCOVER_SEPS;
log_info(" --- a2dp source --- AVDTP_SUBEVENT_SIGNALING_CONNECTION_ESTABLISHED, avdtp cid 0x%02x ---", a2dp_cid());
avdtp_source_discover_stream_endpoints(a2dp_cid());
break;
case AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED:
status = avdtp_subevent_streaming_connection_established_get_status(packet);
cid = avdtp_subevent_streaming_connection_established_get_avdtp_cid(packet);
if (cid != a2dp_cid()){
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), remote_seid(), ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER);
break;
}
loc_seid = avdtp_subevent_streaming_connection_established_get_local_seid(packet);
if (loc_seid != local_seid()){
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), remote_seid(), ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER);
break;
}
rem_seid = avdtp_subevent_streaming_connection_established_get_remote_seid(packet);
if (status != 0){
log_info(" --- a2dp source --- AVDTP_SUBEVENT_STREAMING_CONNECTION could not be established, status %d ---", status);
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), rem_seid, status);
break;
}
app_state = A2DP_STREAMING_OPENED;
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, a2dp_cid(), local_seid(), remote_seid(), 0);
log_info(" --- a2dp source --- AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED --- avdtp_cid 0x%02x, local seid %d, remote seid %d", a2dp_cid(), local_seid(), remote_seid());
break;
case AVDTP_SUBEVENT_SIGNALING_SEP_FOUND:
// TODO check cid
if (app_state != A2DP_W2_DISCOVER_SEPS) return;
sep.seid = avdtp_subevent_signaling_sep_found_get_remote_seid(packet);
sep.in_use = avdtp_subevent_signaling_sep_found_get_in_use(packet);
sep.media_type = (avdtp_media_type_t) avdtp_subevent_signaling_sep_found_get_media_type(packet);
sep.type = (avdtp_sep_type_t) avdtp_subevent_signaling_sep_found_get_sep_type(packet);
log_info(" --- a2dp source --- Found sep: seid %u, in_use %d, media type %d, sep type %d (1-SNK)", sep.seid, sep.in_use, sep.media_type, sep.type);
break;
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY:{
// TODO check cid
if (!sc.local_stream_endpoint) return;
uint8_t sampling_frequency = avdtp_choose_sbc_sampling_frequency(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_sampling_frequency_bitmap(packet));
uint8_t channel_mode = avdtp_choose_sbc_channel_mode(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_channel_mode_bitmap(packet));
uint8_t block_length = avdtp_choose_sbc_block_length(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_block_length_bitmap(packet));
uint8_t subbands = avdtp_choose_sbc_subbands(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_subbands_bitmap(packet));
uint8_t allocation_method = avdtp_choose_sbc_allocation_method(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_allocation_method_bitmap(packet));
uint8_t max_bitpool_value = avdtp_choose_sbc_max_bitpool_value(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_max_bitpool_value(packet));
uint8_t min_bitpool_value = avdtp_choose_sbc_min_bitpool_value(sc.local_stream_endpoint, avdtp_subevent_signaling_media_codec_sbc_capability_get_min_bitpool_value(packet));
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_information[0] = (sampling_frequency << 4) | channel_mode;
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_information[1] = (block_length << 4) | (subbands << 2) | allocation_method;
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_information[2] = min_bitpool_value;
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_information[3] = max_bitpool_value;
sc.local_stream_endpoint->remote_configuration_bitmap = store_bit16(sc.local_stream_endpoint->remote_configuration_bitmap, AVDTP_MEDIA_CODEC, 1);
sc.local_stream_endpoint->remote_configuration.media_codec.media_type = AVDTP_AUDIO;
sc.local_stream_endpoint->remote_configuration.media_codec.media_codec_type = AVDTP_CODEC_SBC;
app_state = A2DP_W2_SET_CONFIGURATION;
case A2DP_W2_GET_CAPABILITIES:
case A2DP_W2_GET_ALL_CAPABILITIES:
if (next_remote_sep_index_to_query < avdtp_source_remote_seps_num(cid)){
sc.active_remote_sep = avdtp_source_remote_sep(cid, next_remote_sep_index_to_query++);
log_info("Query get caps for seid %d", sc.active_remote_sep->seid);
avdtp_source_get_capabilities(cid, sc.active_remote_sep->seid);
} else {
log_info("No more remote seps found");
app_state = A2DP_IDLE;
a2dp_streaming_emit_connection_established(a2dp_source_context.a2dp_callback, cid, 0, 0, AVDTP_SEID_DOES_NOT_EXIST);
}
break;
case A2DP_W2_SET_CONFIGURATION:{
if (!sc.local_stream_endpoint) return;
app_state = A2DP_W2_GET_CONFIGURATION;
avdtp_source_set_configuration(cid, avdtp_stream_endpoint_seid(sc.local_stream_endpoint), sc.active_remote_sep->seid, sc.local_stream_endpoint->remote_configuration_bitmap, sc.local_stream_endpoint->remote_configuration);
break;
}
case A2DP_W2_GET_CONFIGURATION:
app_state = A2DP_W2_OPEN_STREAM_WITH_SEID;
avdtp_source_get_configuration(cid, sc.active_remote_sep->seid);
break;
case A2DP_W2_OPEN_STREAM_WITH_SEID:{
app_state = A2DP_W4_OPEN_STREAM_WITH_SEID;
btstack_sbc_encoder_init(&sc.sbc_encoder_state, SBC_MODE_STANDARD,
sc.block_length, sc.subbands,
sc.allocation_method, sc.sampling_frequency,
sc.max_bitpool_value);
avdtp_source_open_stream(cid, avdtp_stream_endpoint_seid(sc.local_stream_endpoint), sc.active_remote_sep->seid);
break;
}
case A2DP_STREAMING_OPENED:
if (!a2dp_source_context.a2dp_callback) return;
switch (signal_identifier){
case AVDTP_SI_START:{
uint8_t event[6];
int pos = 0;
event[pos++] = HCI_EVENT_A2DP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = A2DP_SUBEVENT_STREAM_STARTED;
little_endian_store_16(event, pos, a2dp_cid());
pos += 2;
event[pos++] = avdtp_stream_endpoint_seid(sc.local_stream_endpoint);
(*a2dp_source_context.a2dp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
break;
}
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY:
log_info(" --- a2dp source --- received non SBC codec. not implemented");
case AVDTP_SI_SUSPEND:{
uint8_t event[6];
int pos = 0;
event[pos++] = HCI_EVENT_A2DP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = A2DP_SUBEVENT_STREAM_SUSPENDED;
little_endian_store_16(event, pos, a2dp_cid());
pos += 2;
event[pos++] = avdtp_stream_endpoint_seid(sc.local_stream_endpoint);
(*a2dp_source_context.a2dp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
break;
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION:{
// TODO check cid
sc.sampling_frequency = avdtp_subevent_signaling_media_codec_sbc_configuration_get_sampling_frequency(packet);
sc.block_length = avdtp_subevent_signaling_media_codec_sbc_configuration_get_block_length(packet);
sc.subbands = avdtp_subevent_signaling_media_codec_sbc_configuration_get_subbands(packet);
sc.allocation_method = avdtp_subevent_signaling_media_codec_sbc_configuration_get_allocation_method(packet) - 1;
sc.max_bitpool_value = avdtp_subevent_signaling_media_codec_sbc_configuration_get_max_bitpool_value(packet);
// TODO: deal with reconfigure: avdtp_subevent_signaling_media_codec_sbc_configuration_get_reconfigure(packet);
break;
}
case AVDTP_SUBEVENT_STREAMING_CAN_SEND_MEDIA_PACKET_NOW:
a2dp_streaming_emit_can_send_media_packet_now(a2dp_source_context.a2dp_callback, a2dp_cid(), 0);
break;
case AVDTP_SUBEVENT_SIGNALING_ACCEPT:
// TODO check cid
signal_identifier = avdtp_subevent_signaling_accept_get_signal_identifier(packet);
log_info(" --- a2dp source --- Accepted %d", signal_identifier);
switch (app_state){
case A2DP_W2_DISCOVER_SEPS:
app_state = A2DP_W2_GET_ALL_CAPABILITIES;
sc.active_remote_sep = avdtp_source_remote_sep(a2dp_cid(), next_remote_sep_index_to_query++);
log_info(" --- a2dp source --- Query get caps for seid %d", sc.active_remote_sep->seid);
avdtp_source_get_capabilities(a2dp_cid(), sc.active_remote_sep->seid);
break;
case A2DP_W2_GET_CAPABILITIES:
case A2DP_W2_GET_ALL_CAPABILITIES:
if (next_remote_sep_index_to_query < avdtp_source_remote_seps_num(a2dp_cid())){
sc.active_remote_sep = avdtp_source_remote_sep(a2dp_cid(), next_remote_sep_index_to_query++);
log_info(" --- a2dp source --- Query get caps for seid %d", sc.active_remote_sep->seid);
avdtp_source_get_capabilities(a2dp_cid(), sc.active_remote_sep->seid);
} else {
log_info(" --- a2dp source --- No more remote seps found");
app_state = A2DP_IDLE;
}
break;
case A2DP_W2_SET_CONFIGURATION:{
if (!sc.local_stream_endpoint) return;
app_state = A2DP_W2_GET_CONFIGURATION;
avdtp_source_set_configuration(a2dp_cid(), avdtp_stream_endpoint_seid(sc.local_stream_endpoint), sc.active_remote_sep->seid, sc.local_stream_endpoint->remote_configuration_bitmap, sc.local_stream_endpoint->remote_configuration);
break;
}
case A2DP_W2_GET_CONFIGURATION:
app_state = A2DP_W2_OPEN_STREAM_WITH_SEID;
avdtp_source_get_configuration(a2dp_cid(), sc.active_remote_sep->seid);
break;
case A2DP_W2_OPEN_STREAM_WITH_SEID:{
app_state = A2DP_W4_OPEN_STREAM_WITH_SEID;
btstack_sbc_encoder_init(&sc.sbc_encoder_state, SBC_MODE_STANDARD,
sc.block_length, sc.subbands,
sc.allocation_method, sc.sampling_frequency,
sc.max_bitpool_value);
avdtp_source_open_stream(a2dp_cid(), avdtp_stream_endpoint_seid(sc.local_stream_endpoint), sc.active_remote_sep->seid);
break;
}
case A2DP_STREAMING_OPENED:
if (!a2dp_source_context.a2dp_callback) return;
switch (signal_identifier){
case AVDTP_SI_START:{
uint8_t event[6];
int pos = 0;
event[pos++] = HCI_EVENT_A2DP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = A2DP_SUBEVENT_STREAM_STARTED;
little_endian_store_16(event, pos, a2dp_cid());
pos += 2;
event[pos++] = avdtp_stream_endpoint_seid(sc.local_stream_endpoint);
(*a2dp_source_context.a2dp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
break;
}
case AVDTP_SI_SUSPEND:{
uint8_t event[6];
int pos = 0;
event[pos++] = HCI_EVENT_A2DP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = A2DP_SUBEVENT_STREAM_SUSPENDED;
little_endian_store_16(event, pos, a2dp_cid());
pos += 2;
event[pos++] = avdtp_stream_endpoint_seid(sc.local_stream_endpoint);
(*a2dp_source_context.a2dp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
break;
}
case AVDTP_SI_ABORT:
case AVDTP_SI_CLOSE:{
uint8_t event[6];
int pos = 0;
event[pos++] = HCI_EVENT_A2DP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = A2DP_SUBEVENT_STREAM_RELEASED;
little_endian_store_16(event, pos, a2dp_cid());
pos += 2;
log_info("send A2DP_SUBEVENT_STREAM_RELEASED to app");
event[pos++] = avdtp_stream_endpoint_seid(sc.local_stream_endpoint);
(*a2dp_source_context.a2dp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
break;
}
default:
break;
}
break;
default:
app_state = A2DP_IDLE;
break;
}
break;
case AVDTP_SUBEVENT_SIGNALING_REJECT:
app_state = A2DP_IDLE;
signal_identifier = avdtp_subevent_signaling_reject_get_signal_identifier(packet);
log_info(" --- a2dp source --- Rejected %d", signal_identifier);
break;
case AVDTP_SUBEVENT_SIGNALING_GENERAL_REJECT:
app_state = A2DP_IDLE;
signal_identifier = avdtp_subevent_signaling_general_reject_get_signal_identifier(packet);
log_info(" --- a2dp source --- Rejected %d", signal_identifier);
}
case AVDTP_SI_ABORT:
case AVDTP_SI_CLOSE:{
uint8_t event[6];
int pos = 0;
event[pos++] = HCI_EVENT_A2DP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = A2DP_SUBEVENT_STREAM_RELEASED;
little_endian_store_16(event, pos, a2dp_cid());
pos += 2;
log_info("send A2DP_SUBEVENT_STREAM_RELEASED to app");
event[pos++] = avdtp_stream_endpoint_seid(sc.local_stream_endpoint);
(*a2dp_source_context.a2dp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
break;
}
default:
app_state = A2DP_IDLE;
log_info(" --- a2dp source --- not implemented");
break;
break;
}
break;
break;
default:
app_state = A2DP_IDLE;
break;
}
break;
case AVDTP_SUBEVENT_SIGNALING_REJECT:
app_state = A2DP_IDLE;
signal_identifier = avdtp_subevent_signaling_reject_get_signal_identifier(packet);
log_info("Rejected %d", signal_identifier);
break;
case AVDTP_SUBEVENT_SIGNALING_GENERAL_REJECT:
app_state = A2DP_IDLE;
signal_identifier = avdtp_subevent_signaling_general_reject_get_signal_identifier(packet);
log_info("Rejected %d", signal_identifier);
break;
default:
// other packet type
break;
app_state = A2DP_IDLE;
log_info("not implemented");
break;
}
}
void a2dp_source_register_packet_handler(btstack_packet_handler_t callback){
@ -449,13 +441,14 @@ uint8_t a2dp_source_create_stream_endpoint(avdtp_media_type_t media_type, avdtp_
return local_stream_endpoint->sep.seid;
}
uint8_t a2dp_source_establish_stream(bd_addr_t bd_addr, uint8_t local_seid, uint16_t * avdtp_cid){
sc.local_stream_endpoint = avdtp_stream_endpoint_for_seid(local_seid, &a2dp_source_context);
uint8_t a2dp_source_establish_stream(bd_addr_t remote_addr, uint8_t loc_seid, uint16_t * avdtp_cid){
sc.local_stream_endpoint = avdtp_stream_endpoint_for_seid(loc_seid, &a2dp_source_context);
if (!sc.local_stream_endpoint){
log_error(" no local_stream_endpoint for seid %d", local_seid);
log_error(" no local_stream_endpoint for seid %d", loc_seid);
return AVDTP_SEID_DOES_NOT_EXIST;
}
return avdtp_source_connect(bd_addr, avdtp_cid);
memcpy(sc.remote_addr, remote_addr, 6);
return avdtp_source_connect(remote_addr, avdtp_cid);
}
uint8_t a2dp_source_disconnect(uint16_t avdtp_cid){

View File

@ -97,7 +97,6 @@ uint8_t avdtp_connect(bd_addr_t remote, avdtp_sep_type_t query_role, avdtp_conte
*avdtp_cid = avdtp_get_next_avdtp_cid();
connection->avdtp_cid = *avdtp_cid;
connection->state = AVDTP_SIGNALING_W4_SDP_QUERY_COMPLETE;
sdp_query_context.connection = connection;
sdp_query_context.query_role = query_role;
@ -285,13 +284,13 @@ static void stream_endpoint_state_machine(avdtp_connection_t * connection, avdtp
case L2CAP_EVENT_CHANNEL_OPENED:
if (stream_endpoint->l2cap_media_cid == 0){
if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED){
log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED failed - stream endpoint in wrong state %d, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d\n", stream_endpoint->state, connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
// log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED failed - stream endpoint in wrong state %d, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d", stream_endpoint->state, connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
avdtp_streaming_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), AVDTP_STREAM_ENDPOINT_IN_WRONG_STATE);
break;
}
status = l2cap_event_channel_opened_get_status(packet);
if (status){
log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED failed with status %d, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d\n", status, connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
// log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED failed with status %d, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d", status, connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
avdtp_streaming_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), status);
break;
}
@ -300,7 +299,7 @@ static void stream_endpoint_state_machine(avdtp_connection_t * connection, avdtp
stream_endpoint->l2cap_media_cid = l2cap_event_channel_opened_get_local_cid(packet);
stream_endpoint->media_con_handle = l2cap_event_channel_opened_get_handle(packet);
printf(" -> AVDTP_STREAM_ENDPOINT_OPENED, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d\n", connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
// log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d", connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
avdtp_streaming_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), 0);
break;
}
@ -517,9 +516,9 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
break;
}
stream_endpoint = avdtp_stream_endpoint_for_seid(connection->query_seid, context);
stream_endpoint = avdtp_stream_endpoint_for_seid(connection->local_seid, context);
if (!stream_endpoint) {
log_info("L2CAP_EVENT_INCOMING_CONNECTION no streamendpoint found for seid %d", connection->query_seid);
log_info("L2CAP_EVENT_INCOMING_CONNECTION no streamendpoint found for seid %d", connection->local_seid);
break;
}
@ -548,8 +547,8 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
con_handle = l2cap_event_channel_opened_get_handle(packet);
log_info("L2CAP_EVENT_CHANNEL_OPENED: Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x",
bd_addr_to_str(event_addr), con_handle, psm, local_cid, l2cap_event_channel_opened_get_remote_cid(packet));
// log_info("L2CAP_EVENT_CHANNEL_OPENED: Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x",
// bd_addr_to_str(event_addr), con_handle, psm, local_cid, l2cap_event_channel_opened_get_remote_cid(packet));
if (psm != BLUETOOTH_PROTOCOL_AVDTP) break;
@ -559,14 +558,14 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
if (connection->tl2cap_signaling_cid == 0) {
if (connection->state != AVDTP_SIGNALING_CONNECTION_W4_L2CAP_CONNECTED) break;
connection->tl2cap_signaling_cid = local_cid;
connection->query_seid = 0;
connection->local_seid = 0;
connection->state = AVDTP_SIGNALING_CONNECTION_OPENED;
log_info(" -> AVDTP_SIGNALING_CONNECTION_OPENED, connection %p", connection);
log_info(" -> AVDTP_SIGNALING_CONNECTION_OPENED, connection %p, avdtp_cid 0x%02x", connection, connection->avdtp_cid);
avdtp_signaling_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, event_addr, 0);
break;
}
stream_endpoint = avdtp_stream_endpoint_for_seid(connection->query_seid, context);
stream_endpoint = avdtp_stream_endpoint_for_seid(connection->local_seid, context);
if (!stream_endpoint){
log_info("L2CAP_EVENT_CHANNEL_OPENED: stream_endpoint not found");
return;
@ -639,14 +638,14 @@ uint8_t avdtp_disconnect(uint16_t avdtp_cid, avdtp_context_t * context){
return ERROR_CODE_SUCCESS;
}
uint8_t avdtp_open_stream(uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, avdtp_context_t * context){
uint8_t avdtp_open_stream(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, avdtp_context_t * context){
avdtp_connection_t * connection = avdtp_connection_for_avdtp_cid(avdtp_cid, context);
if (!connection){
log_error("avdtp_media_connect: no connection for signaling cid 0x%02x found", avdtp_cid);
return AVDTP_CONNECTION_DOES_NOT_EXIST;
}
if (avdtp_find_remote_sep(connection, acp_seid) == 0xFF){
log_error("avdtp_media_connect: no remote sep for seid %d found", acp_seid);
if (avdtp_find_remote_sep(connection, remote_seid) == 0xFF){
log_error("avdtp_media_connect: no remote sep for seid %d found", remote_seid);
return AVDTP_SEID_DOES_NOT_EXIST;
}
@ -655,9 +654,9 @@ uint8_t avdtp_open_stream(uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid
return AVDTP_CONNECTION_IN_WRONG_STATE;
}
avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_with_seid(int_seid, context);
avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_with_seid(local_seid, context);
if (!stream_endpoint) {
log_error("avdtp_media_connect: no stream_endpoint with seid %d found", int_seid);
log_error("avdtp_media_connect: no stream_endpoint with seid %d found", local_seid);
return AVDTP_SEID_DOES_NOT_EXIST;
}
@ -665,8 +664,8 @@ uint8_t avdtp_open_stream(uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid
if (stream_endpoint->remote_sep_index == AVDTP_INVALID_SEP_INDEX) return AVDTP_SEID_DOES_NOT_EXIST;
connection->initiator_transaction_label++;
connection->acp_seid = acp_seid;
connection->local_seid = stream_endpoint->sep.seid;
connection->acp_seid = remote_seid;
connection->local_seid = local_seid;
stream_endpoint->initiator_config_state = AVDTP_INITIATOR_W2_OPEN_STREAM;
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM;
avdtp_request_can_send_now_initiator(connection, connection->tl2cap_signaling_cid);
@ -743,9 +742,10 @@ uint8_t avdtp_abort_stream(uint16_t avdtp_cid, uint8_t local_seid, avdtp_context
log_error("avdtp_abort_stream: no media connection for stream_endpoint with seid %d found", local_seid);
return AVDTP_MEDIA_CONNECTION_DOES_NOT_EXIST;
}
if (stream_endpoint->remote_sep_index == 0xFF || stream_endpoint->stop_stream) return ERROR_CODE_SUCCESS;
if (stream_endpoint->remote_sep_index == 0xFF || stream_endpoint->abort_stream) return ERROR_CODE_SUCCESS;
stream_endpoint->abort_stream = 1;
connection->local_seid = local_seid;
avdtp_request_can_send_now_initiator(connection, connection->tl2cap_signaling_cid);
return ERROR_CODE_SUCCESS;
}
@ -767,7 +767,7 @@ uint8_t avdtp_suspend_stream(uint16_t avdtp_cid, uint8_t local_seid, avdtp_conte
log_error("avdtp_suspend_stream: no media connection for stream_endpoint with seid %d found", local_seid);
return AVDTP_MEDIA_CONNECTION_DOES_NOT_EXIST;
}
if (stream_endpoint->remote_sep_index == 0xFF || stream_endpoint->stop_stream) return ERROR_CODE_SUCCESS;
if (stream_endpoint->remote_sep_index == 0xFF || stream_endpoint->suspend_stream) return ERROR_CODE_SUCCESS;
stream_endpoint->suspend_stream = 1;
connection->local_seid = local_seid;
@ -796,7 +796,7 @@ void avdtp_discover_stream_endpoints(uint16_t avdtp_cid, avdtp_context_t * conte
}
void avdtp_get_capabilities(uint16_t avdtp_cid, uint8_t acp_seid, avdtp_context_t * context){
void avdtp_get_capabilities(uint16_t avdtp_cid, uint8_t remote_seid, avdtp_context_t * context){
avdtp_connection_t * connection = avdtp_connection_for_avdtp_cid(avdtp_cid, context);
if (!connection){
log_error("avdtp_get_capabilities: no connection for AVDTP cid 0x%02x found", avdtp_cid);
@ -806,12 +806,12 @@ void avdtp_get_capabilities(uint16_t avdtp_cid, uint8_t acp_seid, avdtp_context_
if (connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) return;
connection->initiator_transaction_label++;
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CAPABILITIES;
connection->acp_seid = acp_seid;
connection->acp_seid = remote_seid;
avdtp_request_can_send_now_initiator(connection, connection->tl2cap_signaling_cid);
}
void avdtp_get_all_capabilities(uint16_t avdtp_cid, uint8_t acp_seid, avdtp_context_t * context){
void avdtp_get_all_capabilities(uint16_t avdtp_cid, uint8_t remote_seid, avdtp_context_t * context){
avdtp_connection_t * connection = avdtp_connection_for_avdtp_cid(avdtp_cid, context);
if (!connection){
log_error("avdtp_get_all_capabilities: no connection for AVDTP cid 0x%02x found", avdtp_cid);
@ -821,11 +821,11 @@ void avdtp_get_all_capabilities(uint16_t avdtp_cid, uint8_t acp_seid, avdtp_cont
if (connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) return;
connection->initiator_transaction_label++;
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_ALL_CAPABILITIES;
connection->acp_seid = acp_seid;
connection->acp_seid = remote_seid;
avdtp_request_can_send_now_initiator(connection, connection->tl2cap_signaling_cid);
}
void avdtp_get_configuration(uint16_t avdtp_cid, uint8_t acp_seid, avdtp_context_t * context){
void avdtp_get_configuration(uint16_t avdtp_cid, uint8_t remote_seid, avdtp_context_t * context){
avdtp_connection_t * connection = avdtp_connection_for_avdtp_cid(avdtp_cid, context);
if (!connection){
log_error("avdtp_get_configuration: no connection for AVDTP cid 0x%02x found", avdtp_cid);
@ -835,11 +835,11 @@ void avdtp_get_configuration(uint16_t avdtp_cid, uint8_t acp_seid, avdtp_context
if (connection->initiator_connection_state != AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE) return;
connection->initiator_transaction_label++;
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CONFIGURATION;
connection->acp_seid = acp_seid;
connection->acp_seid = remote_seid;
avdtp_request_can_send_now_initiator(connection, connection->tl2cap_signaling_cid);
}
void avdtp_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t acp_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration, avdtp_context_t * context){
void avdtp_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration, avdtp_context_t * context){
avdtp_connection_t * connection = avdtp_connection_for_avdtp_cid(avdtp_cid, context);
if (!connection){
log_error("avdtp_set_configuration: no connection for AVDTP cid 0x%02x found", avdtp_cid);
@ -855,7 +855,7 @@ void avdtp_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t acp
}
connection->initiator_transaction_label++;
connection->acp_seid = acp_seid;
connection->acp_seid = remote_seid;
connection->local_seid = local_seid;
stream_endpoint->remote_capabilities_bitmap = configured_services_bitmap;
stream_endpoint->remote_capabilities = configuration;
@ -863,7 +863,7 @@ void avdtp_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t acp
avdtp_request_can_send_now_initiator(connection, connection->tl2cap_signaling_cid);
}
void avdtp_reconfigure(uint16_t avdtp_cid, uint8_t local_seid, uint8_t acp_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration, avdtp_context_t * context){
void avdtp_reconfigure(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration, avdtp_context_t * context){
avdtp_connection_t * connection = avdtp_connection_for_avdtp_cid(avdtp_cid, context);
if (!connection){
log_error("avdtp_reconfigure: no connection for AVDTP cid 0x%02x found", avdtp_cid);
@ -885,8 +885,8 @@ void avdtp_reconfigure(uint16_t avdtp_cid, uint8_t local_seid, uint8_t acp_seid,
}
connection->initiator_transaction_label++;
connection->acp_seid = acp_seid;
connection->local_seid = stream_endpoint->sep.seid;
connection->acp_seid = remote_seid;
connection->local_seid = local_seid;
stream_endpoint->remote_capabilities_bitmap = configured_services_bitmap;
stream_endpoint->remote_capabilities = configuration;
stream_endpoint->initiator_config_state = AVDTP_INITIATOR_W2_RECONFIGURE_STREAM_WITH_SEID;

View File

@ -394,7 +394,6 @@ typedef struct {
uint8_t initiator_transaction_label;
uint8_t acceptor_transaction_label;
uint8_t query_seid;
uint8_t local_seid;
uint8_t acp_seid;
@ -471,6 +470,8 @@ typedef struct avdtp_stream_endpoint {
typedef struct {
// to app
bd_addr_t remote_addr;
uint32_t fill_audio_ring_buffer_timeout_ms;
uint32_t time_audio_data_sent; // ms
uint32_t acc_num_missed_samples;

View File

@ -107,8 +107,8 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
case AVDTP_SI_ABORT:
case AVDTP_SI_OPEN:
case AVDTP_SI_RECONFIGURE:
connection->query_seid = packet[offset++] >> 2;
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->query_seid, context);
connection->local_seid = packet[offset++] >> 2;
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context);
if (!stream_endpoint){
log_info(" ACP: cmd %d - RESPONSE REJECT", connection->signaling_packet.signal_identifier);
connection->error_code = BAD_ACP_SEID;
@ -118,7 +118,7 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
connection->acceptor_connection_state = AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_WITH_ERROR_CODE;
if (connection->signaling_packet.signal_identifier == AVDTP_SI_RECONFIGURE){
connection->reject_service_category = connection->query_seid;
connection->reject_service_category = connection->local_seid;
connection->acceptor_connection_state = AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE;
}
connection->reject_signal_identifier = connection->signaling_packet.signal_identifier;
@ -142,19 +142,19 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
if (connection->num_suspended_seids == 0) {
log_info(" ACP: CATEGORY RESPONSE REJECT BAD_ACP_SEID");
connection->error_code = BAD_ACP_SEID;
connection->reject_service_category = connection->query_seid;
connection->reject_service_category = connection->local_seid;
connection->acceptor_connection_state = AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE;
connection->reject_signal_identifier = connection->signaling_packet.signal_identifier;
avdtp_request_can_send_now_acceptor(connection, connection->tl2cap_signaling_cid);
return;
}
// deal with first susspended seid
connection->query_seid = connection->suspended_seids[0];
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->query_seid, context);
connection->local_seid = connection->suspended_seids[0];
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context);
if (!stream_endpoint){
log_info(" ACP: stream_endpoint not found, CATEGORY RESPONSE REJECT BAD_ACP_SEID");
connection->error_code = BAD_ACP_SEID;
connection->reject_service_category = connection->query_seid;
connection->reject_service_category = connection->local_seid;
connection->acceptor_connection_state = AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE;
connection->reject_signal_identifier = connection->signaling_packet.signal_identifier;
connection->num_suspended_seids = 0;
@ -248,10 +248,10 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
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->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acp_seid, sep.configuration.media_codec);
avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), sep.configuration.media_codec);
break;
default:
avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acp_seid, sep.configuration.media_codec);
avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), sep.configuration.media_codec);
break;
}
}
@ -263,7 +263,7 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
connection->reject_service_category = 0;
avdtp_sep_t sep;
sep.seid = connection->query_seid;
sep.seid = connection->local_seid;
log_info(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE seid %d", sep.seid);
// log_info_hexdump(connection->signaling_packet.command, packet_size);
@ -292,10 +292,10 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){
switch (sep.capabilities.media_codec.media_codec_type){
case AVDTP_CODEC_SBC:
avdtp_signaling_emit_media_codec_sbc_reconfiguration(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acp_seid, sep.capabilities.media_codec);
avdtp_signaling_emit_media_codec_sbc_reconfiguration(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), sep.capabilities.media_codec);
break;
default:
avdtp_signaling_emit_media_codec_other_reconfiguration(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acp_seid, sep.capabilities.media_codec);
avdtp_signaling_emit_media_codec_other_reconfiguration(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), sep.capabilities.media_codec);
break;
}
}
@ -318,7 +318,7 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
log_info(" ACP: AVDTP_STREAM_ENDPOINT_W2_ANSWER_OPEN_STREAM");
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_OPEN_STREAM;
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED;
connection->query_seid = stream_endpoint->sep.seid;
connection->local_seid = stream_endpoint->sep.seid;
break;
case AVDTP_SI_START:
if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_OPENED){
@ -483,7 +483,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd
return;
}
avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(connection->query_seid, context);
avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(connection->local_seid, context);
if (!stream_endpoint) return;
uint8_t reject_service_category = connection->reject_service_category;

View File

@ -195,7 +195,7 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_
return;
}
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED;
connection->query_seid = stream_endpoint->sep.seid;
connection->local_seid = stream_endpoint->sep.seid;
l2cap_create_channel(context->packet_handler, connection->remote_addr, BLUETOOTH_PROTOCOL_AVDTP, 0xffff, NULL);
return;
case AVDTP_SI_START: