mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-24 15:02:43 +00:00
avrcp: drop con_handle from connection struct, use avrcp_cid in events, free memory on disconnect
This commit is contained in:
parent
7c03fe59ad
commit
6f43fcd768
@ -327,14 +327,14 @@ void avrcp_target_create_sdp_record(uint8_t * service, uint32_t service_record_h
|
|||||||
avrcp_create_sdp_record(0, service, service_record_handle, browsing, supported_features, service_name, service_provider_name);
|
avrcp_create_sdp_record(0, service, service_record_handle, browsing, supported_features, service_name, service_provider_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void avrcp_emit_connection_established(btstack_packet_handler_t callback, uint8_t ctype, bd_addr_t addr, uint16_t con_handle, uint16_t avrcp_cid){
|
static void avrcp_emit_connection_established(btstack_packet_handler_t callback, uint8_t status, bd_addr_t addr, uint16_t con_handle, uint16_t avrcp_cid){
|
||||||
if (!callback) return;
|
if (!callback) return;
|
||||||
uint8_t event[14];
|
uint8_t event[14];
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
event[pos++] = HCI_EVENT_AVRCP_META;
|
event[pos++] = HCI_EVENT_AVRCP_META;
|
||||||
event[pos++] = sizeof(event) - 2;
|
event[pos++] = sizeof(event) - 2;
|
||||||
event[pos++] = AVRCP_SUBEVENT_CONNECTION_ESTABLISHED;
|
event[pos++] = AVRCP_SUBEVENT_CONNECTION_ESTABLISHED;
|
||||||
event[pos++] = ctype;
|
event[pos++] = status;
|
||||||
reverse_bd_addr(addr,&event[pos]);
|
reverse_bd_addr(addr,&event[pos]);
|
||||||
pos += 6;
|
pos += 6;
|
||||||
little_endian_store_16(event, pos, con_handle);
|
little_endian_store_16(event, pos, con_handle);
|
||||||
@ -626,7 +626,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
avrcp_emit_repeat_and_shuffle_mode(avrcp_callback, connection->con_handle, ctype, repeat_mode, shuffle_mode);
|
avrcp_emit_repeat_and_shuffle_mode(avrcp_callback, connection->avrcp_cid, ctype, repeat_mode, shuffle_mode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AVRCP_PDU_ID_SetPlayerApplicationSettingValue:{
|
case AVRCP_PDU_ID_SetPlayerApplicationSettingValue:{
|
||||||
@ -635,7 +635,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
event[offset++] = HCI_EVENT_AVRCP_META;
|
event[offset++] = HCI_EVENT_AVRCP_META;
|
||||||
event[offset++] = sizeof(event) - 2;
|
event[offset++] = sizeof(event) - 2;
|
||||||
event[offset++] = AVRCP_SUBEVENT_PLAYER_APPLICATION_VALUE_RESPONSE;
|
event[offset++] = AVRCP_SUBEVENT_PLAYER_APPLICATION_VALUE_RESPONSE;
|
||||||
little_endian_store_16(event, offset, connection->con_handle);
|
little_endian_store_16(event, offset, connection->avrcp_cid);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
event[offset++] = ctype;
|
event[offset++] = ctype;
|
||||||
(*avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
(*avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
@ -647,7 +647,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
event[offset++] = HCI_EVENT_AVRCP_META;
|
event[offset++] = HCI_EVENT_AVRCP_META;
|
||||||
event[offset++] = sizeof(event) - 2;
|
event[offset++] = sizeof(event) - 2;
|
||||||
event[offset++] = AVRCP_SUBEVENT_SET_ABSOLUTE_VOLUME_RESPONSE;
|
event[offset++] = AVRCP_SUBEVENT_SET_ABSOLUTE_VOLUME_RESPONSE;
|
||||||
little_endian_store_16(event, offset, connection->con_handle);
|
little_endian_store_16(event, offset, connection->avrcp_cid);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
event[offset++] = ctype;
|
event[offset++] = ctype;
|
||||||
event[offset++] = packet[pos++];
|
event[offset++] = packet[pos++];
|
||||||
@ -690,7 +690,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
event[offset++] = HCI_EVENT_AVRCP_META;
|
event[offset++] = HCI_EVENT_AVRCP_META;
|
||||||
event[offset++] = sizeof(event) - 2;
|
event[offset++] = sizeof(event) - 2;
|
||||||
event[offset++] = AVRCP_SUBEVENT_PLAY_STATUS;
|
event[offset++] = AVRCP_SUBEVENT_PLAY_STATUS;
|
||||||
little_endian_store_16(event, offset, connection->con_handle);
|
little_endian_store_16(event, offset, connection->avrcp_cid);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
event[offset++] = ctype;
|
event[offset++] = ctype;
|
||||||
little_endian_store_32(event, offset, song_length);
|
little_endian_store_32(event, offset, song_length);
|
||||||
@ -737,7 +737,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
event[offset++] = HCI_EVENT_AVRCP_META;
|
event[offset++] = HCI_EVENT_AVRCP_META;
|
||||||
event[offset++] = sizeof(event) - 2;
|
event[offset++] = sizeof(event) - 2;
|
||||||
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_PLAYBACK_STATUS_CHANGED;
|
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_PLAYBACK_STATUS_CHANGED;
|
||||||
little_endian_store_16(event, offset, connection->con_handle);
|
little_endian_store_16(event, offset, connection->avrcp_cid);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
event[offset++] = ctype;
|
event[offset++] = ctype;
|
||||||
event[offset++] = packet[pos];
|
event[offset++] = packet[pos];
|
||||||
@ -750,7 +750,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
event[offset++] = HCI_EVENT_AVRCP_META;
|
event[offset++] = HCI_EVENT_AVRCP_META;
|
||||||
event[offset++] = sizeof(event) - 2;
|
event[offset++] = sizeof(event) - 2;
|
||||||
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_TRACK_CHANGED;
|
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_TRACK_CHANGED;
|
||||||
little_endian_store_16(event, offset, connection->con_handle);
|
little_endian_store_16(event, offset, connection->avrcp_cid);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
event[offset++] = ctype;
|
event[offset++] = ctype;
|
||||||
(*avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
(*avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
@ -762,7 +762,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
event[offset++] = HCI_EVENT_AVRCP_META;
|
event[offset++] = HCI_EVENT_AVRCP_META;
|
||||||
event[offset++] = sizeof(event) - 2;
|
event[offset++] = sizeof(event) - 2;
|
||||||
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_NOW_PLAYING_CONTENT_CHANGED;
|
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_NOW_PLAYING_CONTENT_CHANGED;
|
||||||
little_endian_store_16(event, offset, connection->con_handle);
|
little_endian_store_16(event, offset, connection->avrcp_cid);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
event[offset++] = ctype;
|
event[offset++] = ctype;
|
||||||
(*avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
(*avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
@ -774,7 +774,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
event[offset++] = HCI_EVENT_AVRCP_META;
|
event[offset++] = HCI_EVENT_AVRCP_META;
|
||||||
event[offset++] = sizeof(event) - 2;
|
event[offset++] = sizeof(event) - 2;
|
||||||
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_AVAILABLE_PLAYERS_CHANGED;
|
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_AVAILABLE_PLAYERS_CHANGED;
|
||||||
little_endian_store_16(event, offset, connection->con_handle);
|
little_endian_store_16(event, offset, connection->avrcp_cid);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
event[offset++] = ctype;
|
event[offset++] = ctype;
|
||||||
(*avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
(*avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
@ -786,7 +786,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
event[offset++] = HCI_EVENT_AVRCP_META;
|
event[offset++] = HCI_EVENT_AVRCP_META;
|
||||||
event[offset++] = sizeof(event) - 2;
|
event[offset++] = sizeof(event) - 2;
|
||||||
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_VOLUME_CHANGED;
|
event[offset++] = AVRCP_SUBEVENT_NOTIFICATION_VOLUME_CHANGED;
|
||||||
little_endian_store_16(event, offset, connection->con_handle);
|
little_endian_store_16(event, offset, connection->avrcp_cid);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
event[offset++] = ctype;
|
event[offset++] = ctype;
|
||||||
event[offset++] = packet[pos++] & 0x7F;
|
event[offset++] = packet[pos++] & 0x7F;
|
||||||
@ -895,7 +895,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
event[0] = HCI_EVENT_AVRCP_META;
|
event[0] = HCI_EVENT_AVRCP_META;
|
||||||
pos = 2;
|
pos = 2;
|
||||||
event[pos++] = AVRCP_SUBEVENT_NOW_PLAYING_INFO;
|
event[pos++] = AVRCP_SUBEVENT_NOW_PLAYING_INFO;
|
||||||
little_endian_store_16(event, pos, connection->con_handle);
|
little_endian_store_16(event, pos, connection->avrcp_cid);
|
||||||
pos += 2;
|
pos += 2;
|
||||||
event[pos++] = ctype;
|
event[pos++] = ctype;
|
||||||
for (i = 0; i < sizeof(attribute_order); i++){
|
for (i = 0; i < sizeof(attribute_order); i++){
|
||||||
@ -967,12 +967,12 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (connection->state == AVCTP_W4_STOP){
|
if (connection->state == AVCTP_W4_STOP){
|
||||||
avrcp_emit_operation_status(avrcp_callback, AVRCP_SUBEVENT_OPERATION_START, connection->con_handle, ctype, operation_id);
|
avrcp_emit_operation_status(avrcp_callback, AVRCP_SUBEVENT_OPERATION_START, connection->avrcp_cid, ctype, operation_id);
|
||||||
}
|
}
|
||||||
if (connection->state == AVCTP_CONNECTION_OPENED) {
|
if (connection->state == AVCTP_CONNECTION_OPENED) {
|
||||||
// RELEASE response
|
// RELEASE response
|
||||||
operation_id = operation_id & 0x7F;
|
operation_id = operation_id & 0x7F;
|
||||||
avrcp_emit_operation_status(avrcp_callback, AVRCP_SUBEVENT_OPERATION_COMPLETE, connection->con_handle, ctype, operation_id);
|
avrcp_emit_operation_status(avrcp_callback, AVRCP_SUBEVENT_OPERATION_COMPLETE, connection->avrcp_cid, ctype, operation_id);
|
||||||
}
|
}
|
||||||
if (connection->state == AVCTP_W2_SEND_RELEASE_COMMAND){
|
if (connection->state == AVCTP_W2_SEND_RELEASE_COMMAND){
|
||||||
// PRESS response
|
// PRESS response
|
||||||
@ -1030,6 +1030,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
bd_addr_t event_addr;
|
bd_addr_t event_addr;
|
||||||
uint16_t local_cid;
|
uint16_t local_cid;
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
|
hci_con_handle_t con_handle;
|
||||||
avrcp_connection_t * connection = NULL;
|
avrcp_connection_t * connection = NULL;
|
||||||
|
|
||||||
switch (packet_type) {
|
switch (packet_type) {
|
||||||
@ -1071,6 +1072,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
avrcp_emit_connection_established(avrcp_callback, status, event_addr, HCI_CON_HANDLE_INVALID, local_cid);
|
avrcp_emit_connection_established(avrcp_callback, status, event_addr, HCI_CON_HANDLE_INVALID, local_cid);
|
||||||
}
|
}
|
||||||
// free connection
|
// free connection
|
||||||
|
btstack_linked_list_remove(&avrcp_connections, (btstack_linked_item_t*) connection);
|
||||||
btstack_memory_avrcp_connection_free(connection);
|
btstack_memory_avrcp_connection_free(connection);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1085,9 +1087,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
}
|
}
|
||||||
|
|
||||||
connection->l2cap_signaling_cid = local_cid;
|
connection->l2cap_signaling_cid = local_cid;
|
||||||
connection->con_handle = l2cap_event_channel_opened_get_handle(packet);
|
con_handle = l2cap_event_channel_opened_get_handle(packet);
|
||||||
connection->state = AVCTP_CONNECTION_OPENED;
|
connection->state = AVCTP_CONNECTION_OPENED;
|
||||||
avrcp_emit_connection_established(avrcp_callback, ERROR_CODE_SUCCESS, event_addr, connection->con_handle, local_cid);
|
avrcp_emit_connection_established(avrcp_callback, ERROR_CODE_SUCCESS, event_addr, con_handle, local_cid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L2CAP_EVENT_CAN_SEND_NOW:
|
case L2CAP_EVENT_CAN_SEND_NOW:
|
||||||
@ -1101,8 +1103,10 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
local_cid = l2cap_event_channel_closed_get_local_cid(packet);
|
local_cid = l2cap_event_channel_closed_get_local_cid(packet);
|
||||||
connection = get_avrcp_connection_for_l2cap_signaling_cid(local_cid);
|
connection = get_avrcp_connection_for_l2cap_signaling_cid(local_cid);
|
||||||
if (connection){
|
if (connection){
|
||||||
avrcp_emit_connection_closed(avrcp_callback, connection->con_handle);
|
avrcp_emit_connection_closed(avrcp_callback, connection->avrcp_cid);
|
||||||
|
// free connection
|
||||||
btstack_linked_list_remove(&avrcp_connections, (btstack_linked_item_t*) connection);
|
btstack_linked_list_remove(&avrcp_connections, (btstack_linked_item_t*) connection);
|
||||||
|
btstack_memory_avrcp_connection_free(connection);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user