mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-14 01:27:41 +00:00
move seids and cid into tracker context
This commit is contained in:
parent
a42de5830e
commit
2f869b6e11
@ -108,14 +108,19 @@ static uint8_t media_sbc_codec_configuration[4];
|
||||
static uint8_t sbc_storage[44100*4];
|
||||
|
||||
typedef struct {
|
||||
uint8_t * sbc_samples_storage;
|
||||
btstack_ring_buffer_t sbc_ring_buffer;
|
||||
|
||||
uint16_t a2dp_cid;
|
||||
int start_streaming_timer;
|
||||
uint8_t int_seid;
|
||||
uint8_t acp_seid;
|
||||
|
||||
uint32_t fill_audio_ring_buffer_timeout_ms;
|
||||
uint32_t time_audio_data_sent; // ms
|
||||
uint32_t acc_num_missed_samples;
|
||||
uint32_t samples_ready;
|
||||
btstack_timer_source_t fill_audio_ring_buffer_timer;
|
||||
|
||||
uint8_t * sbc_samples_storage;
|
||||
btstack_ring_buffer_t sbc_ring_buffer;
|
||||
} a2dp_media_sending_context_t;
|
||||
|
||||
static a2dp_media_sending_context_t media_tracker;
|
||||
@ -126,16 +131,14 @@ static int hxcmod_initialized = 0;
|
||||
static modcontext mod_context;
|
||||
static tracker_buffer_state trkbuf;
|
||||
|
||||
static uint8_t int_seid = 0;
|
||||
static uint8_t acp_seid = 0;
|
||||
static uint16_t a2dp_cid = 0;
|
||||
static int start_streaming_timer = 0;
|
||||
|
||||
static uint8_t local_seid = 0;
|
||||
a2dp_state_t app_state = A2DP_IDLE;
|
||||
stream_data_source_t data_source = STREAM_SINE;
|
||||
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
|
||||
static void avdtp_fill_audio_ring_buffer_timer_start(a2dp_media_sending_context_t * context);
|
||||
static void avdtp_fill_audio_ring_buffer_timer_stop(a2dp_media_sending_context_t * context);
|
||||
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
UNUSED(channel);
|
||||
@ -159,24 +162,31 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
case HCI_EVENT_AVDTP_META:
|
||||
switch (packet[2]){
|
||||
case AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED:
|
||||
int_seid = avdtp_subevent_streaming_connection_established_get_int_seid(packet);
|
||||
acp_seid = avdtp_subevent_streaming_connection_established_get_acp_seid(packet);
|
||||
a2dp_cid = avdtp_subevent_streaming_connection_established_get_avdtp_cid(packet);
|
||||
printf(" --- application --- AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED --- a2dp_cid 0x%02x, local seid %d, remote seid %d\n", a2dp_cid, int_seid, acp_seid);
|
||||
media_tracker.int_seid = avdtp_subevent_streaming_connection_established_get_int_seid(packet);
|
||||
media_tracker.acp_seid = avdtp_subevent_streaming_connection_established_get_acp_seid(packet);
|
||||
media_tracker.a2dp_cid = avdtp_subevent_streaming_connection_established_get_avdtp_cid(packet);
|
||||
media_tracker.start_streaming_timer = 0;
|
||||
printf(" --- application --- AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED --- a2dp_cid 0x%02x, local seid %d, remote seid %d\n",
|
||||
media_tracker.a2dp_cid, media_tracker.int_seid, media_tracker.acp_seid);
|
||||
break;
|
||||
|
||||
case AVDTP_SUBEVENT_START_STREAMING:
|
||||
int_seid = avdtp_subevent_start_streaming_get_int_seid(packet);
|
||||
if (!start_streaming_timer) break;
|
||||
if (!avdtp_source_stream_endpoint_ready(int_seid)) break;
|
||||
if (!media_tracker.start_streaming_timer) break;
|
||||
if (!avdtp_source_stream_endpoint_ready(media_tracker.int_seid)) break;
|
||||
|
||||
printf(" --- application --- start streaming : int seid %d\n", int_seid);
|
||||
printf(" --- application --- start streaming : int seid %d\n", media_tracker.int_seid);
|
||||
avdtp_fill_audio_ring_buffer_timer_start(&media_tracker);
|
||||
start_streaming_timer = 0;
|
||||
media_tracker.start_streaming_timer = 0;
|
||||
break;
|
||||
case AVDTP_SUBEVENT_STOP_STREAMING:
|
||||
if (!avdtp_source_stream_endpoint_ready(media_tracker.int_seid)) return;
|
||||
avdtp_fill_audio_ring_buffer_timer_stop(&media_tracker);
|
||||
break;
|
||||
|
||||
case AVDTP_SUBEVENT_STREAMING_CAN_SEND_MEDIA_PACKET_NOW:
|
||||
avdtp_source_stream_send_media_payload(int_seid, &media_tracker.sbc_ring_buffer, 0);
|
||||
avdtp_source_stream_send_media_payload(media_tracker.int_seid, &media_tracker.sbc_ring_buffer, 0);
|
||||
if (btstack_ring_buffer_bytes_available(&media_tracker.sbc_ring_buffer)){
|
||||
avdtp_source_stream_endpoint_request_can_send_now(int_seid);
|
||||
avdtp_source_stream_endpoint_request_can_send_now(media_tracker.int_seid);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -299,7 +309,7 @@ static void avdtp_fill_audio_ring_buffer_timeout_handler(btstack_timer_source_t
|
||||
int total_num_bytes_read = fill_sbc_ring_buffer(context);
|
||||
// schedule sending
|
||||
if (total_num_bytes_read != 0){
|
||||
avdtp_source_stream_endpoint_request_can_send_now(int_seid);
|
||||
avdtp_source_stream_endpoint_request_can_send_now(context->int_seid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,19 +325,6 @@ static void avdtp_fill_audio_ring_buffer_timer_stop(a2dp_media_sending_context_t
|
||||
btstack_run_loop_remove_timer(&context->fill_audio_ring_buffer_timer);
|
||||
}
|
||||
|
||||
static void a2dp_source_stream_data_start(void){
|
||||
printf(" --- application --- a2dp_source_stream_data_start --- local seid %d, remote seid %d\n", int_seid, acp_seid);
|
||||
a2dp_source_start_stream(a2dp_cid, int_seid, acp_seid);
|
||||
start_streaming_timer = 1;
|
||||
}
|
||||
|
||||
static void a2dp_source_stream_data_stop(void){
|
||||
a2dp_source_stop_stream(a2dp_cid, int_seid, acp_seid);
|
||||
if (!avdtp_source_stream_endpoint_ready(int_seid)) return;
|
||||
avdtp_fill_audio_ring_buffer_timer_stop(&media_tracker);
|
||||
}
|
||||
|
||||
|
||||
static void a2dp_init_media_tracker(a2dp_media_sending_context_t * context, uint8_t * storage, int size){
|
||||
context->sbc_samples_storage = storage;
|
||||
memset(&context->sbc_samples_storage[0], 0, size);
|
||||
@ -345,20 +342,19 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
|
||||
switch (cmd){
|
||||
case 'c':
|
||||
printf("Creating L2CAP Connection to %s, PSM_AVDTP\n", bd_addr_to_str(remote));
|
||||
a2dp_source_connect(remote, int_seid);
|
||||
a2dp_source_connect(remote, local_seid);
|
||||
break;
|
||||
case 'C':
|
||||
printf("Disconnect not implemented\n");
|
||||
a2dp_source_disconnect(a2dp_cid);
|
||||
a2dp_source_disconnect(media_tracker.a2dp_cid);
|
||||
break;
|
||||
case 'x':
|
||||
a2dp_source_stream_data_start();
|
||||
break;
|
||||
case 'z':
|
||||
a2dp_source_stream_data_start();
|
||||
printf(" --- application --- a2dp_source_stream_data_start --- local seid %d, remote seid %d\n", media_tracker.int_seid, media_tracker.acp_seid);
|
||||
a2dp_source_start_stream(media_tracker.a2dp_cid, media_tracker.int_seid, media_tracker.acp_seid);
|
||||
media_tracker.start_streaming_timer = 1;
|
||||
break;
|
||||
case 'X':
|
||||
a2dp_source_stream_data_stop();
|
||||
a2dp_source_stop_stream(media_tracker.a2dp_cid, media_tracker.int_seid, media_tracker.acp_seid);
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
@ -381,7 +377,7 @@ int btstack_main(int argc, const char * argv[]){
|
||||
a2dp_source_register_packet_handler(&packet_handler);
|
||||
|
||||
//#ifndef SMG_BI
|
||||
int_seid = 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));
|
||||
local_seid = 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));
|
||||
|
||||
// Initialize SDP
|
||||
sdp_init();
|
||||
|
Loading…
x
Reference in New Issue
Block a user