1 /* 2 * Copyright (C) 2016 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 39 #include <stdint.h> 40 #include <stdio.h> 41 #include <stdlib.h> 42 #include <string.h> 43 44 #include "btstack.h" 45 46 #include "hxcmod.h" 47 #include "mods/mod.h" 48 49 #define NUM_CHANNELS 2 50 #define A2DP_SAMPLE_RATE 44100 51 #define BYTES_PER_AUDIO_SAMPLE (2*NUM_CHANNELS) 52 #define AUDIO_TIMEOUT_MS 10 53 #define TABLE_SIZE_441HZ 100 54 55 typedef enum { 56 STREAM_SINE, 57 STREAM_MOD 58 } stream_data_source_t; 59 60 typedef struct { 61 uint16_t a2dp_cid; 62 uint8_t local_seid; 63 64 uint32_t time_audio_data_sent; // ms 65 uint32_t acc_num_missed_samples; 66 uint32_t samples_ready; 67 btstack_timer_source_t audio_timer; 68 uint8_t streaming; 69 int max_media_payload_size; 70 71 uint8_t sbc_storage[1030]; 72 uint16_t sbc_storage_count; 73 uint8_t sbc_ready_to_send; 74 } a2dp_media_sending_context_t; 75 76 static uint8_t media_sbc_codec_capabilities[] = { 77 (AVDTP_SBC_44100 << 4) | AVDTP_SBC_STEREO, 78 0xFF,//(AVDTP_SBC_BLOCK_LENGTH_16 << 4) | (AVDTP_SBC_SUBBANDS_8 << 2) | AVDTP_SBC_ALLOCATION_METHOD_LOUDNESS, 79 2, 53 80 }; 81 82 static const int16_t sine_int16[] = { 83 0, 2057, 4107, 6140, 8149, 10126, 12062, 13952, 15786, 17557, 84 19260, 20886, 22431, 23886, 25247, 26509, 27666, 28714, 29648, 30466, 85 31163, 31738, 32187, 32509, 32702, 32767, 32702, 32509, 32187, 31738, 86 31163, 30466, 29648, 28714, 27666, 26509, 25247, 23886, 22431, 20886, 87 19260, 17557, 15786, 13952, 12062, 10126, 8149, 6140, 4107, 2057, 88 0, -2057, -4107, -6140, -8149, -10126, -12062, -13952, -15786, -17557, 89 -19260, -20886, -22431, -23886, -25247, -26509, -27666, -28714, -29648, -30466, 90 -31163, -31738, -32187, -32509, -32702, -32767, -32702, -32509, -32187, -31738, 91 -31163, -30466, -29648, -28714, -27666, -26509, -25247, -23886, -22431, -20886, 92 -19260, -17557, -15786, -13952, -12062, -10126, -8149, -6140, -4107, -2057, 93 }; 94 95 static const char * device_name = "A2DP Source BTstack"; 96 97 #ifdef HAVE_BTSTACK_STDIN 98 // mac 2011: static const char * device_addr_string = "04:0C:CE:E4:85:D3"; 99 // pts: static const char * device_addr_string = "00:1B:DC:08:0A:A5"; 100 // mac 2013: static const char * device_addr_string = "84:38:35:65:d1:15"; 101 // phone 2013: static const char * device_addr_string = "D8:BB:2C:DF:F0:F2"; 102 // minijambox: 103 static const char * device_addr_string = "00:21:3C:AC:F7:38"; 104 // head phones: static const char * device_addr_string = "00:18:09:28:50:18"; 105 // bt dongle: static const char * device_addr_string = "00:15:83:5F:9D:46"; 106 #endif 107 108 static bd_addr_t device_addr; 109 static uint8_t sdp_a2dp_source_service_buffer[150]; 110 static uint8_t media_sbc_codec_configuration[4]; 111 static a2dp_media_sending_context_t media_tracker; 112 113 static uint16_t avrcp_cid; 114 115 static stream_data_source_t data_source; 116 117 static int sine_phase; 118 119 static int hxcmod_initialized; 120 static modcontext mod_context; 121 static tracker_buffer_state trkbuf; 122 123 124 /* AVRCP Target context START */ 125 static const uint8_t subunit_info[] = { 126 0,0,0,0, 127 1,1,1,1, 128 2,2,2,2, 129 3,3,3,3, 130 4,4,4,4, 131 5,5,5,5, 132 6,6,6,6, 133 7,7,7,7 134 }; 135 136 static uint32_t company_id = 0x112233; 137 static uint8_t companies_num = 1; 138 static uint8_t companies[] = { 139 0x00, 0x19, 0x58 //BT SIG registered CompanyID 140 }; 141 142 static uint8_t events_num = 13; 143 static uint8_t events[] = { 144 AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED, 145 AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED, 146 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_END, 147 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_START, 148 AVRCP_NOTIFICATION_EVENT_PLAYBACK_POS_CHANGED, 149 AVRCP_NOTIFICATION_EVENT_BATT_STATUS_CHANGED, 150 AVRCP_NOTIFICATION_EVENT_SYSTEM_STATUS_CHANGED, 151 AVRCP_NOTIFICATION_EVENT_PLAYER_APPLICATION_SETTING_CHANGED, 152 AVRCP_NOTIFICATION_EVENT_NOW_PLAYING_CONTENT_CHANGED, 153 AVRCP_NOTIFICATION_EVENT_AVAILABLE_PLAYERS_CHANGED, 154 AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED, 155 AVRCP_NOTIFICATION_EVENT_UIDS_CHANGED, 156 AVRCP_NOTIFICATION_EVENT_VOLUME_CHANGED 157 }; 158 159 typedef struct { 160 char title[40]; 161 char artist[40]; 162 char album[40]; 163 char genre[40]; 164 uint32_t song_length_ms; 165 int total_tracks; 166 int track_nr; 167 } avrcp_now_playing_info_t; 168 169 typedef struct { 170 avrcp_play_status_t status; 171 uint32_t song_length_ms; // 0xFFFFFFFF if not supported 172 uint32_t song_position_ms; // 0xFFFFFFFF if not supported 173 } avrcp_play_status_info_t; 174 175 avrcp_now_playing_info_t now_playing_info; 176 avrcp_play_status_info_t play_info; 177 178 /* AVRCP Target context END */ 179 180 static void a2dp_demo_send_media_packet(void){ 181 int num_bytes_in_frame = btstack_sbc_encoder_sbc_buffer_length(); 182 int bytes_in_storage = media_tracker.sbc_storage_count; 183 uint8_t num_frames = bytes_in_storage / num_bytes_in_frame; 184 a2dp_source_stream_send_media_payload(media_tracker.local_seid, media_tracker.sbc_storage, bytes_in_storage, num_frames, 0); 185 media_tracker.sbc_storage_count = 0; 186 media_tracker.sbc_ready_to_send = 0; 187 } 188 189 static void produce_sine_audio(int16_t * pcm_buffer, int num_samples_to_write){ 190 int count; 191 for (count = 0; count < num_samples_to_write ; count++){ 192 pcm_buffer[count * 2] = sine_int16[sine_phase]; 193 pcm_buffer[count * 2 + 1] = sine_int16[sine_phase]; 194 sine_phase++; 195 if (sine_phase >= TABLE_SIZE_441HZ){ 196 sine_phase -= TABLE_SIZE_441HZ; 197 } 198 } 199 } 200 201 static void produce_mod_audio(int16_t * pcm_buffer, int num_samples_to_write){ 202 hxcmod_fillbuffer(&mod_context, (unsigned short *) &pcm_buffer[0], num_samples_to_write, &trkbuf); 203 } 204 205 static void produce_audio(int16_t * pcm_buffer, int num_samples){ 206 switch (data_source){ 207 case STREAM_SINE: 208 produce_sine_audio(pcm_buffer, num_samples); 209 break; 210 case STREAM_MOD: 211 produce_mod_audio(pcm_buffer, num_samples); 212 break; 213 } 214 } 215 216 static int a2dp_demo_fill_sbc_audio_buffer(a2dp_media_sending_context_t * context){ 217 // perform sbc encodin 218 int total_num_bytes_read = 0; 219 unsigned int num_audio_samples_per_sbc_buffer = btstack_sbc_encoder_num_audio_frames(); 220 while (context->samples_ready >= num_audio_samples_per_sbc_buffer 221 && (context->max_media_payload_size - context->sbc_storage_count) >= btstack_sbc_encoder_sbc_buffer_length()){ 222 223 int16_t pcm_frame[256*NUM_CHANNELS]; 224 225 produce_audio(pcm_frame, num_audio_samples_per_sbc_buffer); 226 btstack_sbc_encoder_process_data(pcm_frame); 227 228 uint16_t sbc_frame_size = btstack_sbc_encoder_sbc_buffer_length(); 229 uint8_t * sbc_frame = btstack_sbc_encoder_sbc_buffer(); 230 231 total_num_bytes_read += num_audio_samples_per_sbc_buffer; 232 memcpy(&context->sbc_storage[context->sbc_storage_count], sbc_frame, sbc_frame_size); 233 context->sbc_storage_count += sbc_frame_size; 234 context->samples_ready -= num_audio_samples_per_sbc_buffer; 235 } 236 return total_num_bytes_read; 237 } 238 239 static void a2dp_demo_audio_timeout_handler(btstack_timer_source_t * timer){ 240 a2dp_media_sending_context_t * context = (a2dp_media_sending_context_t *) btstack_run_loop_get_timer_context(timer); 241 btstack_run_loop_set_timer(&context->audio_timer, AUDIO_TIMEOUT_MS); 242 btstack_run_loop_add_timer(&context->audio_timer); 243 uint32_t now = btstack_run_loop_get_time_ms(); 244 245 uint32_t update_period_ms = AUDIO_TIMEOUT_MS; 246 if (context->time_audio_data_sent > 0){ 247 update_period_ms = now - context->time_audio_data_sent; 248 } 249 250 uint32_t num_samples = (update_period_ms * A2DP_SAMPLE_RATE) / 1000; 251 context->acc_num_missed_samples += (update_period_ms * A2DP_SAMPLE_RATE) % 1000; 252 253 while (context->acc_num_missed_samples >= 1000){ 254 num_samples++; 255 context->acc_num_missed_samples -= 1000; 256 } 257 context->time_audio_data_sent = now; 258 context->samples_ready += num_samples; 259 260 if (context->sbc_ready_to_send) return; 261 262 a2dp_demo_fill_sbc_audio_buffer(context); 263 264 if ((context->sbc_storage_count + btstack_sbc_encoder_sbc_buffer_length()) > context->max_media_payload_size){ 265 // schedule sending 266 context->sbc_ready_to_send = 1; 267 a2dp_source_stream_endpoint_request_can_send_now(context->local_seid); 268 } 269 } 270 271 static void a2dp_demo_timer_start(a2dp_media_sending_context_t * context){ 272 context->max_media_payload_size = a2dp_max_media_payload_size(context->local_seid); 273 context->sbc_storage_count = 0; 274 context->sbc_ready_to_send = 0; 275 context->streaming = 1; 276 btstack_run_loop_remove_timer(&context->audio_timer); 277 btstack_run_loop_set_timer_handler(&context->audio_timer, a2dp_demo_audio_timeout_handler); 278 btstack_run_loop_set_timer_context(&context->audio_timer, context); 279 btstack_run_loop_set_timer(&context->audio_timer, AUDIO_TIMEOUT_MS); 280 btstack_run_loop_add_timer(&context->audio_timer); 281 } 282 283 static void a2dp_demo_timer_stop(a2dp_media_sending_context_t * context){ 284 context->time_audio_data_sent = 0; 285 context->acc_num_missed_samples = 0; 286 context->samples_ready = 0; 287 context->streaming = 1; 288 context->sbc_storage_count = 0; 289 context->sbc_ready_to_send = 0; 290 btstack_run_loop_remove_timer(&context->audio_timer); 291 } 292 293 static void a2dp_demo_timer_pause(a2dp_media_sending_context_t * context){ 294 btstack_run_loop_remove_timer(&context->audio_timer); 295 } 296 297 298 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 299 UNUSED(channel); 300 UNUSED(size); 301 uint8_t status; 302 uint8_t local_seid; 303 bd_addr_t address; 304 305 if (packet_type != HCI_EVENT_PACKET) return; 306 if (hci_event_packet_get_type(packet) != HCI_EVENT_A2DP_META) return; 307 308 switch (packet[2]){ 309 case A2DP_SUBEVENT_STREAM_ESTABLISHED: 310 a2dp_subevent_stream_established_get_bd_addr(packet, address); 311 status = a2dp_subevent_stream_established_get_status(packet); 312 if (status){ 313 printf("A2DP: Stream establishment failed: status 0x%02x.\n", status); 314 break; 315 } 316 local_seid = a2dp_subevent_stream_established_get_local_seid(packet); 317 if (local_seid != media_tracker.local_seid){ 318 printf("A2DP: Stream establishment failed: wrong local seid %d, expected %d.\n", local_seid, media_tracker.local_seid); 319 break; 320 } 321 322 media_tracker.a2dp_cid = a2dp_subevent_stream_established_get_a2dp_cid(packet); 323 printf("A2DP: Stream established: address %s, a2dp cid 0x%02x, local seid %d, remote seid %d.\n", bd_addr_to_str(address), 324 media_tracker.a2dp_cid, media_tracker.local_seid, a2dp_subevent_stream_established_get_remote_seid(packet)); 325 break; 326 327 case A2DP_SUBEVENT_STREAM_STARTED: 328 play_info.status = AVRCP_PLAY_STATUS_PLAYING; 329 a2dp_demo_timer_start(&media_tracker); 330 printf("A2DP: Stream started.\n"); 331 break; 332 333 case A2DP_SUBEVENT_STREAMING_CAN_SEND_MEDIA_PACKET_NOW: 334 a2dp_demo_send_media_packet(); 335 break; 336 337 case A2DP_SUBEVENT_STREAM_SUSPENDED: 338 play_info.status = AVRCP_PLAY_STATUS_PAUSED; 339 printf("A2DP: Stream paused.\n"); 340 a2dp_demo_timer_pause(&media_tracker); 341 break; 342 343 case A2DP_SUBEVENT_STREAM_RELEASED: 344 play_info.status = AVRCP_PLAY_STATUS_STOPPED; 345 printf("A2DP: Stream released.\n"); 346 a2dp_demo_timer_stop(&media_tracker); 347 break; 348 default: 349 printf("A2DP: event 0x%02x is not implemented\n", packet[2]); 350 break; 351 } 352 } 353 354 static void avrcp_target_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 355 UNUSED(channel); 356 UNUSED(size); 357 bd_addr_t event_addr; 358 uint16_t local_cid; 359 uint8_t status = 0xFF; 360 361 if (packet_type != HCI_EVENT_PACKET) return; 362 if (hci_event_packet_get_type(packet) != HCI_EVENT_AVRCP_META) return; 363 switch (packet[2]){ 364 case AVRCP_SUBEVENT_CONNECTION_ESTABLISHED: { 365 local_cid = avrcp_subevent_connection_established_get_avrcp_cid(packet); 366 if (avrcp_cid != 0 && avrcp_cid != local_cid) { 367 printf("AVRCP: Connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", avrcp_cid, local_cid); 368 return; 369 } 370 371 status = avrcp_subevent_connection_established_get_status(packet); 372 if (status != ERROR_CODE_SUCCESS){ 373 printf("AVRCP: Connection failed: status 0x%02x\n", status); 374 avrcp_cid = 0; 375 return; 376 } 377 avrcp_cid = local_cid; 378 play_info.song_length_ms = 0xFFFFFFFF; 379 play_info.song_position_ms = 0xFFFFFFFF; 380 play_info.status = AVRCP_PLAY_STATUS_ERROR; 381 382 avrcp_subevent_connection_established_get_bd_addr(packet, event_addr); 383 printf("AVRCP: connected to %s, avrcp_cid 0x%02x\n", bd_addr_to_str(event_addr), local_cid); 384 return; 385 } 386 387 case AVRCP_SUBEVENT_UNIT_INFO_QUERY: 388 avrcp_target_unit_info(avrcp_cid, AVRCP_SUBUNIT_TYPE_AUDIO, company_id); 389 break; 390 case AVRCP_SUBEVENT_SUBUNIT_INFO_QUERY: 391 avrcp_target_subunit_info(avrcp_cid, AVRCP_SUBUNIT_TYPE_UNIT, avrcp_subevent_subunit_info_query_get_offset(packet), (uint8_t *)subunit_info); 392 break; 393 case AVRCP_SUBEVENT_EVENT_IDS_QUERY: 394 avrcp_target_supported_events(avrcp_cid, events_num, events, sizeof(events)); 395 break; 396 case AVRCP_SUBEVENT_COMPANY_IDS_QUERY: 397 avrcp_target_supported_companies(avrcp_cid, companies_num, companies, sizeof(companies)); 398 break; 399 case AVRCP_SUBEVENT_PLAY_STATUS_QUERY: 400 avrcp_target_play_status(avrcp_cid, play_info.song_length_ms, play_info.song_position_ms, play_info.status); 401 break; 402 case AVRCP_SUBEVENT_NOW_PLAYING_INFO_QUERY: 403 avrcp_target_set_now_playing_title(avrcp_cid, now_playing_info.title); 404 avrcp_target_set_now_playing_artist(avrcp_cid, now_playing_info.artist); 405 avrcp_target_set_now_playing_album(avrcp_cid, now_playing_info.album); 406 avrcp_target_set_now_playing_genre(avrcp_cid, now_playing_info.genre); 407 avrcp_target_set_now_playing_track_nr(avrcp_cid, now_playing_info.track_nr); 408 avrcp_target_set_now_playing_total_tracks(avrcp_cid, now_playing_info.total_tracks); 409 avrcp_target_set_now_playing_song_length_ms(avrcp_cid, now_playing_info.song_length_ms); 410 411 avrcp_target_now_playing_info(avrcp_cid); 412 break; 413 case AVRCP_SUBEVENT_CONNECTION_RELEASED: 414 printf("AVRCP: Channel released: avrcp_cid 0x%02x\n", avrcp_subevent_connection_released_get_avrcp_cid(packet)); 415 avrcp_cid = 0; 416 return; 417 default: 418 printf("AVRCP: event not parsed %02x\n", packet[2]); 419 break; 420 } 421 } 422 423 #ifdef HAVE_BTSTACK_STDIN 424 static void show_usage(void){ 425 bd_addr_t iut_address; 426 gap_local_bd_addr(iut_address); 427 printf("\n--- Bluetooth A2DP Source/AVRCP Target Demo %s ---\n", bd_addr_to_str(iut_address)); 428 printf("b - AVDTP Source create connection to addr %s\n", device_addr_string); 429 printf("B - AVDTP Source disconnect\n"); 430 printf("c - AVRCP Target create connection to addr %s\n", device_addr_string); 431 printf("C - AVRCP Target disconnect\n"); 432 433 printf("x - start streaming sine\n"); 434 if (hxcmod_initialized){ 435 printf("z - start streaming '%s'\n", mod_name); 436 } 437 printf("p - pause streaming\n"); 438 439 printf("\n--- Bluetooth AVRCP Target Commands %s ---\n", bd_addr_to_str(iut_address)); 440 printf("---\n"); 441 } 442 443 static void stdin_process(char cmd){ 444 uint8_t status = ERROR_CODE_SUCCESS; 445 switch (cmd){ 446 case 'b': 447 printf(" - Create AVDTP Source connection to addr %s.\n", bd_addr_to_str(device_addr)); 448 status = a2dp_source_establish_stream(device_addr, media_tracker.local_seid, &media_tracker.a2dp_cid); 449 break; 450 case 'B': 451 printf(" - AVDTP Source Disconnect\n"); 452 status = a2dp_source_disconnect(media_tracker.a2dp_cid); 453 break; 454 case 'c': 455 printf(" - Create AVRCP Target connection to addr %s.\n", bd_addr_to_str(device_addr)); 456 status = avrcp_target_connect(device_addr, &avrcp_cid); 457 break; 458 case 'C': 459 printf(" - AVRCP Target disconnect\n"); 460 status = avrcp_target_disconnect(avrcp_cid); 461 break; 462 463 case '\n': 464 case '\r': 465 break; 466 467 case 'x': 468 printf("Playing sine.\n"); 469 data_source = STREAM_SINE; 470 status = a2dp_source_start_stream(media_tracker.a2dp_cid, media_tracker.local_seid); 471 break; 472 case 'z': 473 printf("Playing mod.\n"); 474 data_source = STREAM_MOD; 475 status = a2dp_source_start_stream(media_tracker.a2dp_cid, media_tracker.local_seid); 476 break; 477 case 'p': 478 printf("Pause stream.\n"); 479 status = a2dp_source_pause_stream(media_tracker.a2dp_cid, media_tracker.local_seid); 480 break; 481 482 default: 483 show_usage(); 484 return; 485 } 486 if (status != ERROR_CODE_SUCCESS){ 487 printf("Could not perform command, status 0x%2x\n", status); 488 } 489 } 490 #endif 491 492 493 int btstack_main(int argc, const char * argv[]); 494 int btstack_main(int argc, const char * argv[]){ 495 UNUSED(argc); 496 (void)argv; 497 498 l2cap_init(); 499 // Initialize AVDTP Source 500 a2dp_source_init(); 501 a2dp_source_register_packet_handler(&packet_handler); 502 503 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)); 504 if (!local_stream_endpoint){ 505 printf("A2DP source demo: not enough memory to create local stream endpoint\n"); 506 return 1; 507 } 508 media_tracker.local_seid = avdtp_local_seid(local_stream_endpoint); 509 510 // Initialize AVRCP Target 511 avrcp_target_init(); 512 avrcp_target_register_packet_handler(&avrcp_target_packet_handler); 513 514 // Initialize SDP 515 sdp_init(); 516 memset(sdp_a2dp_source_service_buffer, 0, sizeof(sdp_a2dp_source_service_buffer)); 517 a2dp_source_create_sdp_record(sdp_a2dp_source_service_buffer, 0x10002, 1, NULL, NULL); 518 sdp_register_service(sdp_a2dp_source_service_buffer); 519 520 gap_set_local_name(device_name); 521 gap_discoverable_control(1); 522 gap_set_class_of_device(0x200408); 523 524 hxcmod_initialized = hxcmod_init(&mod_context); 525 if (hxcmod_initialized){ 526 hxcmod_setcfg(&mod_context, A2DP_SAMPLE_RATE, 16, 1, 1, 1); 527 hxcmod_load(&mod_context, (void *) &mod_data, mod_len); 528 printf("loaded mod '%s', size %u\n", mod_name, mod_len); 529 } 530 531 // For PTS test 532 memcpy(now_playing_info.title, "Title 1", 8); 533 memcpy(now_playing_info.artist, "Artist 1", 8); 534 memcpy(now_playing_info.album, "Album 1", 8); 535 memcpy(now_playing_info.genre, "Genre 1", 8); 536 now_playing_info.track_nr = 1; 537 now_playing_info.total_tracks = 10; 538 now_playing_info.song_length_ms = 3655; 539 540 #ifdef HAVE_BTSTACK_STDIN 541 // parse human readable Bluetooth address 542 sscanf_bd_addr(device_addr_string, device_addr); 543 btstack_stdin_setup(stdin_process); 544 #endif 545 // turn on! 546 hci_power_control(HCI_POWER_ON); 547 return 0; 548 } 549