avrcp_target: only use RFC2978_CHARSET_MIB_UTF8

This commit is contained in:
Matthias Ringwald 2020-01-16 14:27:56 +01:00
parent 5e845fceaf
commit b68ca59f0e

View File

@ -102,31 +102,29 @@ static void avrcp_target_emit_respond_vendor_dependent_query(btstack_packet_hand
}
// returns number of bytes stored
static uint16_t avrcp_target_pack_single_element_header(uint8_t * packet, uint16_t pos, rfc2978_charset_mib_enumid_t mib_enumid, avrcp_media_attribute_id_t attr_id, uint16_t attr_value_size){
static uint16_t avrcp_target_pack_single_element_header(uint8_t * packet, uint16_t pos, avrcp_media_attribute_id_t attr_id, uint16_t attr_value_size){
btstack_assert(attr_id >= 1);
btstack_assert(attr_id <= AVRCP_MEDIA_ATTR_COUNT);
big_endian_store_32(packet, pos, attr_id);
big_endian_store_16(packet, pos+4, mib_enumid);
big_endian_store_16(packet, pos+4, RFC2978_CHARSET_MIB_UTF8);
big_endian_store_16(packet, pos+6, attr_value_size);
return 8;
}
// returns number of bytes stored
static uint16_t avrcp_target_pack_single_element_attribute_number(uint8_t * packet, uint16_t pos, avrcp_media_attribute_id_t attr_id, uint32_t value){
if ((attr_id < 1) || (attr_id > AVRCP_MEDIA_ATTR_COUNT)) return 0;
uint16_t attr_value_length = sprintf((char *)(packet+pos+8), "%0" PRIu32, value);
(void) avrcp_target_pack_single_element_header(packet, pos, RFC2978_CHARSET_MIB_UTF8, attr_id, attr_value_length);
(void) avrcp_target_pack_single_element_header(packet, pos, attr_id, attr_value_length);
return 8 + attr_value_length;
}
// returns number of bytes stored
static uint16_t avrcp_target_pack_single_element_attribute_string_fragment(uint8_t * packet, uint16_t pos, rfc2978_charset_mib_enumid_t mib_enumid, avrcp_media_attribute_id_t attr_id, uint8_t * attr_value, uint16_t attr_value_to_copy, uint16_t attr_value_size, uint8_t header){
static uint16_t avrcp_target_pack_single_element_attribute_string_fragment(uint8_t * packet, uint16_t pos, avrcp_media_attribute_id_t attr_id, uint8_t * attr_value, uint16_t attr_value_to_copy, uint16_t attr_value_size, bool header){
if (attr_value_size == 0) return 0;
if ((attr_id < 1) || (attr_id > AVRCP_MEDIA_ATTR_COUNT)) return 0;
uint16_t bytes_stored = 0;
if (header){
bytes_stored += avrcp_target_pack_single_element_header(packet, pos, mib_enumid, attr_id, attr_value_size);
bytes_stored += avrcp_target_pack_single_element_header(packet, pos, attr_id, attr_value_size);
}
(void)memcpy(packet + pos + bytes_stored, attr_value, attr_value_to_copy);
bytes_stored += attr_value_to_copy;
@ -250,21 +248,21 @@ static int avrcp_target_send_now_playing_info(uint16_t cid, avrcp_connection_t *
connection->attribute_value_offset = 0;
break;
default:{
uint8_t header = (connection->attribute_value_offset == 0);
bool header = connection->attribute_value_offset == 0;
uint8_t * attr_value = (uint8_t *) (connection->now_playing_info[attr_index].value + connection->attribute_value_offset);
uint16_t attr_value_len = connection->now_playing_info[attr_index].len - connection->attribute_value_offset;
num_bytes_to_write = attr_value_len + (header * AVRCP_ATTR_HEADER_LEN);
if (num_bytes_to_write <= num_free_bytes){
connection->attribute_value_offset = 0;
num_written_bytes = num_bytes_to_write;
avrcp_target_pack_single_element_attribute_string_fragment(packet, pos, RFC2978_CHARSET_MIB_UTF8, attr_id, attr_value, attr_value_len, connection->now_playing_info[attr_index].len, header);
avrcp_target_pack_single_element_attribute_string_fragment(packet, pos, attr_id, attr_value, attr_value_len, connection->now_playing_info[attr_index].len, header);
break;
}
fragmented = 1;
num_written_bytes = num_free_bytes;
attr_value_len = num_free_bytes - (header * AVRCP_ATTR_HEADER_LEN);
avrcp_target_pack_single_element_attribute_string_fragment(packet, pos, RFC2978_CHARSET_MIB_UTF8, attr_id, attr_value, attr_value_len, connection->now_playing_info[attr_index].len, header);
avrcp_target_pack_single_element_attribute_string_fragment(packet, pos, attr_id, attr_value, attr_value_len, connection->now_playing_info[attr_index].len, header);
connection->attribute_value_offset += attr_value_len;
break;
}