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 * avdtp.h 40 * 41 * Audio/Video Distribution Transport Protocol 42 * 43 * This protocol defines A/V stream negotiation, establishment, and transmission 44 * procedures. Also specified are the message formats that are exchanged between 45 * such devices to transport their A/V streams in A/V distribution applications. 46 * 47 * Media packets are unidirectional, they travel downstream from AVDTP Source to AVDTP Sink. 48 */ 49 50 #ifndef AVDTP_H 51 #define AVDTP_H 52 53 #include <stdint.h> 54 #include "hci.h" 55 #include "btstack_ring_buffer.h" 56 57 #if defined __cplusplus 58 extern "C" { 59 #endif 60 61 #define AVDTP_MAX_NUM_SEPS 10 62 #define AVDTP_MAX_CSRC_NUM 15 63 #define AVDTP_MAX_CONTENT_PROTECTION_TYPE_VALUE_LEN 10 64 65 // Supported Features 66 #define AVDTP_SOURCE_FEATURE_MASK_PLAYER 0x0001u 67 #define AVDTP_SOURCE_FEATURE_MASK_MICROPHONE 0x0002u 68 #define AVDTP_SOURCE_FEATURE_MASK_TUNER 0x0004u 69 #define AVDTP_SOURCE_FEATURE_MASK_MIXER 0x0008u 70 71 #define AVDTP_SINK_FEATURE_MASK_HEADPHONE 0x0001u 72 #define AVDTP_SINK_FEATURE_MASK_SPEAKER 0x0002u 73 #define AVDTP_SINK_FEATURE_MASK_RECORDER 0x0004u 74 #define AVDTP_SINK_FEATURE_MASK_AMPLIFIER 0x0008u 75 76 // ACP to INT, Signal Response Header Error Codes 77 #define BAD_HEADER_FORMAT 0x01 78 79 // ACP to INT, Signal Response Payload Format Error Codes 80 #define BAD_LENGTH 0x11 81 #define BAD_ACP_SEID 0x12 82 #define SEP_IN_USE 0x13 83 #define SEP_NOT_IN_USE 0x14 84 #define BAD_SERV_CATEGORY 0x17 85 #define BAD_PAYLOAD_FORMAT 0x18 86 #define NOT_SUPPORTED_COMMAND 0x19 87 #define INVALID_CAPABILITIES 0x1A 88 89 // ACP to INT, Signal Response Transport Service Capabilities Error Codes 90 #define BAD_RECOVERY_TYPE 0x22 91 #define BAD_MEDIA_TRANSPORT_FORMAT 0x23 92 #define BAD_RECOVERY_FORMAT 0x25 93 #define BAD_ROHC_FORMAT 0x26 94 #define BAD_CP_FORMAT 0x27 95 #define BAD_MULTIPLEXING_FORMAT 0x28 96 #define UNSUPPORTED_CONFIGURATION 0x29 97 98 // ACP to INT, Procedure Error Codes 99 #define BAD_STATE 0x31 100 101 #define AVDTP_INVALID_SEP_SEID 0xFF 102 103 104 // Signal Identifier fields 105 typedef enum { 106 AVDTP_SI_NONE = 0x00, 107 AVDTP_SI_DISCOVER = 0x01, 108 AVDTP_SI_GET_CAPABILITIES, 109 AVDTP_SI_SET_CONFIGURATION, 110 AVDTP_SI_GET_CONFIGURATION, 111 AVDTP_SI_RECONFIGURE, //5 112 AVDTP_SI_OPEN, //6 113 AVDTP_SI_START, //7 114 AVDTP_SI_CLOSE, 115 AVDTP_SI_SUSPEND, 116 AVDTP_SI_ABORT, //10 117 AVDTP_SI_SECURITY_CONTROL, 118 AVDTP_SI_GET_ALL_CAPABILITIES, //12 119 AVDTP_SI_DELAYREPORT 120 } avdtp_signal_identifier_t; 121 122 typedef enum { 123 AVDTP_SINGLE_PACKET = 0, 124 AVDTP_START_PACKET , 125 AVDTP_CONTINUE_PACKET , 126 AVDTP_END_PACKET 127 } avdtp_packet_type_t; 128 129 typedef enum { 130 AVDTP_CMD_MSG = 0, 131 AVDTP_GENERAL_REJECT_MSG , 132 AVDTP_RESPONSE_ACCEPT_MSG , 133 AVDTP_RESPONSE_REJECT_MSG 134 } avdtp_message_type_t; 135 136 typedef enum { 137 AVDTP_AUDIO = 0, 138 AVDTP_VIDEO, 139 AVDTP_MULTIMEDIA 140 } avdtp_media_type_t; 141 142 typedef enum { 143 AVDTP_CODEC_SBC = 0x00, 144 AVDTP_CODEC_MPEG_1_2_AUDIO = 0x01, 145 AVDTP_CODEC_MPEG_2_4_AAC = 0x02, 146 AVDTP_CODEC_ATRAC_FAMILY = 0x04, 147 AVDTP_CODEC_NON_A2DP = 0xFF 148 } avdtp_media_codec_type_t; 149 150 typedef enum { 151 AVDTP_CONTENT_PROTECTION_DTCP = 0x0001, 152 AVDTP_CONTENT_PROTECTION_SCMS_T = 0x0002 153 } avdtp_content_protection_type_t; 154 155 typedef enum { 156 AVDTP_SOURCE = 0, 157 AVDTP_SINK 158 } avdtp_sep_type_t; 159 160 typedef enum { 161 AVDTP_ROLE_SOURCE = 0, 162 AVDTP_ROLE_SINK 163 } avdtp_role_t; 164 165 typedef enum { 166 AVDTP_SERVICE_CATEGORY_INVALID_0 = 0x00, 167 AVDTP_MEDIA_TRANSPORT = 0X01, 168 AVDTP_REPORTING, 169 AVDTP_RECOVERY, 170 AVDTP_CONTENT_PROTECTION, //4 171 AVDTP_HEADER_COMPRESSION, //5 172 AVDTP_MULTIPLEXING, //6 173 AVDTP_MEDIA_CODEC, //7 174 AVDTP_DELAY_REPORTING, //8 175 AVDTP_SERVICE_CATEGORY_INVALID_FF = 0xFF 176 } avdtp_service_category_t; 177 178 typedef struct { 179 uint8_t recovery_type; // 0x01 = RFC2733 180 uint8_t maximum_recovery_window_size; // 0x01 to 0x18, for a Transport Packet 181 uint8_t maximum_number_media_packets; // 0x01 to 0x18, The maximum number of media packets a specific parity code covers 182 } avdtp_recovery_capabilities_t; 183 184 typedef struct { 185 avdtp_media_type_t media_type; 186 avdtp_media_codec_type_t media_codec_type; 187 uint16_t media_codec_information_len; 188 uint8_t * media_codec_information; 189 } adtvp_media_codec_capabilities_t; 190 191 192 typedef struct { 193 uint16_t cp_type; 194 uint16_t cp_type_value_len; 195 uint8_t cp_type_value[AVDTP_MAX_CONTENT_PROTECTION_TYPE_VALUE_LEN]; 196 } adtvp_content_protection_t; 197 198 typedef struct{ 199 uint8_t back_ch; // byte0 - bit 8; 0=Not Available/Not Used; 1=Available/In Use 200 uint8_t media; // byte0 - bit 7 201 uint8_t recovery; // byte0 - bit 6 202 } avdtp_header_compression_capabilities_t; 203 204 typedef struct{ 205 uint8_t fragmentation; // byte0 - bit 8, Allow Adaptation Layer Fragmentation, 0 no, 1 yes 206 // Request/indicate value of the Transport Session Identifier for a media, reporting, or recovery transport sessions, respectively 207 uint8_t transport_identifiers_num; 208 uint8_t transport_session_identifiers[3]; // byte1, upper 5bits, 0x01 to 0x1E 209 // Request/indicate value for TCID for a media, reporting, or transport session 210 uint8_t tcid[3]; // byte2 0x01 to 0x1E 211 } avdtp_multiplexing_mode_capabilities_t; 212 213 typedef struct{ 214 avdtp_recovery_capabilities_t recovery; 215 adtvp_media_codec_capabilities_t media_codec; 216 adtvp_content_protection_t content_protection; 217 avdtp_header_compression_capabilities_t header_compression; 218 avdtp_multiplexing_mode_capabilities_t multiplexing_mode; 219 } avdtp_capabilities_t; 220 221 typedef enum{ 222 AVDTP_SBC_48000 = 1, 223 AVDTP_SBC_44100 = 2, 224 AVDTP_SBC_32000 = 4, 225 AVDTP_SBC_16000 = 8 226 } avdtp_sbc_sampling_frequency_t; 227 228 typedef enum{ 229 AVDTP_SBC_JOINT_STEREO = 1, 230 AVDTP_SBC_STEREO = 2, 231 AVDTP_SBC_DUAL_CHANNEL = 4, 232 AVDTP_SBC_MONO = 8 233 } avdtp_sbc_channel_mode_t; 234 235 typedef enum{ 236 AVDTP_SBC_BLOCK_LENGTH_16 = 1, 237 AVDTP_SBC_BLOCK_LENGTH_12 = 2, 238 AVDTP_SBC_BLOCK_LENGTH_8 = 4, 239 AVDTP_SBC_BLOCK_LENGTH_4 = 8 240 } avdtp_sbc_block_length_t; 241 242 typedef enum{ 243 AVDTP_SBC_SUBBANDS_8 = 1, 244 AVDTP_SBC_SUBBANDS_4 = 2 245 } avdtp_sbc_subbands_t; 246 247 typedef enum{ 248 AVDTP_SBC_ALLOCATION_METHOD_LOUDNESS = 1, 249 AVDTP_SBC_ALLOCATION_METHOD_SNR = 2 250 } avdtp_sbc_allocation_method_t; 251 252 typedef struct { 253 uint8_t fragmentation; 254 uint8_t starting_packet; // of fragmented SBC frame 255 uint8_t last_packet; // of fragmented SBC frame 256 uint8_t num_frames; 257 } avdtp_sbc_codec_header_t; 258 259 typedef enum { 260 AVDTP_MPEG_LAYER_1 = 1, 261 AVDTP_MPEG_LAYER_2, 262 AVDTP_MPEG_LAYER_3, 263 } avdtp_mpeg_layer_t; 264 265 266 typedef enum { 267 AVDTP_AAC_MPEG2_LC = 1, 268 AVDTP_AAC_MPEG4_LC, 269 AVDTP_AAC_MPEG4_LTP, 270 AVDTP_AAC_MPEG4_SCALABLE 271 } avdtp_aac_object_type_t; 272 273 typedef enum { 274 AVDTP_ATRAC_VERSION_1 = 1, 275 AVDTP_ATRAC_VERSION_2, 276 AVDTP_ATRAC_VERSION_3 277 } avdtp_atrac_version_t; 278 279 // used for MPEG1/2 Audio, ATRAC (no stereo mode) 280 typedef enum { 281 AVDTP_CHANNEL_MODE_MONO = 1, 282 AVDTP_CHANNEL_MODE_DUAL_CHANNEL, 283 AVDTP_CHANNEL_MODE_STEREO, 284 AVDTP_CHANNEL_MODE_JOINT_STEREO, 285 } avdtp_channel_mode_t; 286 287 typedef struct { 288 uint8_t version; 289 uint8_t padding; 290 uint8_t extension; 291 uint8_t csrc_count; 292 uint8_t marker; 293 uint8_t payload_type; 294 295 uint16_t sequence_number; 296 uint32_t timestamp; 297 uint32_t synchronization_source; 298 299 uint32_t csrc_list[AVDTP_MAX_CSRC_NUM]; 300 } avdtp_media_packet_header_t; 301 302 typedef enum { 303 AVDTP_BASIC_SERVICE_MODE = 0, 304 AVDTP_MULTIPLEXING_SERVICE_MODE 305 } avdtp_service_mode_t; 306 307 typedef enum { 308 AVDTP_STREAM_ENDPOINT_IDLE = 0, 309 AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE, 310 AVDTP_STREAM_ENDPOINT_CONFIGURED, 311 312 AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM, 313 AVDTP_STREAM_ENDPOINT_W4_ACCEPT_OPEN_STREAM, 314 AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED, 315 316 AVDTP_STREAM_ENDPOINT_OPENED, 317 AVDTP_STREAM_ENDPOINT_STREAMING, 318 319 AVDTP_STREAM_ENDPOINT_CLOSING, 320 AVDTP_STREAM_ENDPOINT_ABORTING, 321 AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_DISCONNECTED 322 } avdtp_stream_endpoint_state_t; 323 324 typedef enum { 325 AVDTP_INITIATOR_STREAM_CONFIG_IDLE = 0, 326 AVDTP_INITIATOR_W2_SET_CONFIGURATION, 327 AVDTP_INITIATOR_W2_SUSPEND_STREAM_WITH_SEID, 328 AVDTP_INITIATOR_W2_RECONFIGURE_STREAM_WITH_SEID, 329 330 AVDTP_INITIATOR_W2_OPEN_STREAM, 331 332 AVDTP_INITIATOR_W2_STREAMING_ABORT, 333 AVDTP_INITIATOR_FRAGMENTATED_COMMAND, 334 AVDTP_INITIATOR_W4_ANSWER 335 } avdtp_initiator_stream_endpoint_state_t; 336 337 typedef enum { 338 AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE = 0, 339 AVDTP_ACCEPTOR_W2_ANSWER_GET_CAPABILITIES, 340 AVDTP_ACCEPTOR_W2_ANSWER_GET_ALL_CAPABILITIES, 341 AVDTP_ACCEPTOR_W2_ANSWER_DELAY_REPORT, 342 AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION, 343 AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE, 344 AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION, 345 AVDTP_ACCEPTOR_W2_ANSWER_OPEN_STREAM, 346 AVDTP_ACCEPTOR_W2_ANSWER_START_STREAM, 347 AVDTP_ACCEPTOR_W2_ANSWER_CLOSE_STREAM, 348 AVDTP_ACCEPTOR_W2_ANSWER_ABORT_STREAM, 349 AVDTP_ACCEPTOR_W2_SUSPEND_STREAM_WITH_SEID, 350 AVDTP_ACCEPTOR_W2_ANSWER_SUSPEND_STREAM, 351 AVDTP_ACCEPTOR_W2_REJECT_WITH_ERROR_CODE, 352 AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE, 353 AVDTP_ACCEPTOR_W2_REJECT_UNKNOWN_CMD, 354 AVDTP_ACCEPTOR_STREAMING 355 } avdtp_acceptor_stream_endpoint_state_t; 356 357 typedef struct { 358 uint8_t seid; // 0x01 – 0x3E, 6bit 359 uint8_t in_use; // 1 bit, 0 - not in use, 1 - in use 360 avdtp_media_type_t media_type; // 4 bit 361 avdtp_sep_type_t type; // 1 bit, 0 - SRC, 1 - SNK 362 363 uint16_t registered_service_categories; 364 avdtp_capabilities_t capabilities; 365 366 uint16_t configured_service_categories; 367 avdtp_capabilities_t configuration; 368 } avdtp_sep_t; 369 370 371 typedef enum { 372 AVDTP_SIGNALING_CONNECTION_IDLE = 0, 373 AVDTP_SIGNALING_W2_SEND_SDP_QUERY_FOR_REMOTE_SINK, 374 AVDTP_SIGNALING_W4_SDP_QUERY_FOR_REMOTE_SINK_COMPLETE, 375 AVDTP_SIGNALING_W2_SEND_SDP_QUERY_FOR_REMOTE_SOURCE, 376 AVDTP_SIGNALING_W4_SDP_QUERY_FOR_REMOTE_SOURCE_COMPLETE, 377 AVDTP_SIGNALING_CONNECTION_W4_L2CAP_CONNECTED, 378 AVDTP_SIGNALING_CONNECTION_W2_L2CAP_RETRY, 379 AVDTP_SIGNALING_CONNECTION_OPENED, 380 AVDTP_SIGNALING_CONNECTION_W4_L2CAP_DISCONNECTED 381 } avdtp_connection_state_t; 382 383 typedef enum { 384 AVDTP_SIGNALING_CONNECTION_ACCEPTOR_IDLE = 0, 385 AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_ANSWER_DISCOVER_SEPS, 386 AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_WITH_ERROR_CODE, 387 AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE, 388 AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_GENERAL_REJECT_WITH_ERROR_CODE 389 } avdtp_acceptor_connection_state_t; 390 391 typedef enum { 392 AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE = 0, 393 AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_DISCOVER_SEPS, 394 AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_SEND_SDP_QUERY_THEN_GET_ALL_CAPABILITIES, 395 AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_SDP_QUERY_COMPLETE_THEN_GET_ALL_CAPABILITIES, 396 AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CAPABILITIES, 397 AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_ALL_CAPABILITIES, 398 AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CONFIGURATION, 399 AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_SEND_DELAY_REPORT, 400 AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER 401 } avdtp_initiator_connection_state_t; 402 403 typedef struct { 404 uint8_t command[200]; 405 uint16_t size; 406 uint16_t offset; 407 uint8_t acp_seid; 408 uint8_t int_seid; 409 uint16_t transaction_label; 410 uint16_t num_packets; 411 avdtp_signal_identifier_t signal_identifier; 412 avdtp_message_type_t message_type; 413 avdtp_packet_type_t packet_type; 414 } avdtp_signaling_packet_t; 415 416 typedef enum { 417 AVDTP_CONFIGURATION_STATE_IDLE = 0, 418 AVDTP_CONFIGURATION_STATE_LOCAL_INITIATED, 419 AVDTP_CONFIGURATION_STATE_LOCAL_CONFIGURED, 420 AVDTP_CONFIGURATION_STATE_REMOTE_INITIATED, 421 AVDTP_CONFIGURATION_STATE_REMOTE_CONFIGURED, 422 } avtdp_configuration_state_t; 423 424 typedef enum { 425 A2DP_IDLE = 0, 426 A2DP_W4_CONNECTED, 427 A2DP_CONNECTED, 428 A2DP_DISCOVER_SEPS, 429 A2DP_GET_CAPABILITIES, 430 A2DP_W2_GET_ALL_CAPABILITIES, //5 431 A2DP_SET_CONFIGURATION, 432 A2DP_W4_GET_CONFIGURATION, 433 A2DP_W4_SET_CONFIGURATION, 434 A2DP_CONFIGURED, 435 A2DP_W2_SUSPEND_STREAM_WITH_SEID, //10 436 A2DP_W2_RECONFIGURE_WITH_SEID, 437 A2DP_W2_OPEN_STREAM_WITH_SEID, 438 A2DP_W4_OPEN_STREAM_WITH_SEID, 439 A2DP_W2_START_STREAM_WITH_SEID, 440 A2DP_W2_ABORT_STREAM_WITH_SEID, //15 441 A2DP_W2_STOP_STREAM_WITH_SEID, 442 A2DP_STREAMING_OPENED 443 } a2dp_state_t; 444 445 446 typedef struct { 447 btstack_linked_item_t item; 448 bd_addr_t remote_addr; 449 450 uint16_t avdtp_cid; 451 hci_con_handle_t con_handle; 452 453 // SDP results 454 uint16_t avdtp_l2cap_psm; 455 uint16_t avdtp_version; 456 bool sink_supported; 457 bool source_supported; 458 459 uint16_t l2cap_signaling_cid; 460 uint16_t l2cap_mtu; 461 462 avdtp_connection_state_t state; 463 avdtp_acceptor_connection_state_t acceptor_connection_state; 464 avdtp_initiator_connection_state_t initiator_connection_state; 465 466 // used to reassemble fragmented commands 467 avdtp_signaling_packet_t acceptor_signaling_packet; 468 469 // used to prepare outgoing signaling packets 470 avdtp_signaling_packet_t initiator_signaling_packet; 471 472 uint8_t initiator_local_seid; 473 uint8_t initiator_remote_seid; 474 475 uint8_t acceptor_local_seid; 476 477 uint16_t delay_ms; 478 479 // for repeating the set_configuration 480 void * active_stream_endpoint; 481 482 uint8_t initiator_transaction_label; 483 uint8_t acceptor_transaction_label; 484 bool wait_to_send_acceptor; 485 bool wait_to_send_initiator; 486 487 uint8_t suspended_seids[AVDTP_MAX_NUM_SEPS]; 488 uint8_t num_suspended_seids; 489 490 uint8_t reject_service_category; 491 avdtp_signal_identifier_t reject_signal_identifier; 492 uint8_t error_code; 493 494 // configuration state machine 495 avtdp_configuration_state_t configuration_state; 496 // btstack_timer_source_t configuration_timer; 497 498 bool incoming_declined; 499 btstack_timer_source_t retry_timer; 500 501 bool a2dp_source_discover_seps; 502 503 } avdtp_connection_t; 504 505 506 typedef struct avdtp_stream_endpoint { 507 btstack_linked_item_t item; 508 509 // original capabilities configured via avdtp_register_x_category 510 avdtp_sep_t sep; 511 512 // media codec configuration - provided by user 513 uint16_t media_codec_configuration_len; 514 uint8_t * media_codec_configuration_info; 515 516 avdtp_sep_t remote_sep; 517 hci_con_handle_t media_con_handle; 518 uint16_t l2cap_media_cid; 519 uint16_t l2cap_reporting_cid; 520 uint16_t l2cap_recovery_cid; 521 522 avdtp_stream_endpoint_state_t state; 523 avdtp_acceptor_stream_endpoint_state_t acceptor_config_state; 524 avdtp_initiator_stream_endpoint_state_t initiator_config_state; 525 a2dp_state_t a2dp_state; 526 // active connection 527 avdtp_connection_t * connection; 528 529 // currently active remote seid 530 avdtp_capabilities_t remote_capabilities; 531 uint16_t remote_capabilities_bitmap; 532 533 uint16_t remote_configuration_bitmap; 534 avdtp_capabilities_t remote_configuration; 535 536 // temporary codec config used by A2DP Source 537 uint8_t set_config_remote_seid; 538 avdtp_media_codec_type_t media_codec_type; 539 avdtp_media_type_t media_type; 540 uint8_t media_codec_info[8]; 541 542 // preferred SBC codec settings 543 uint32_t preferred_sampling_frequency; 544 uint8_t preferred_channel_mode; 545 546 // register request for media L2cap connection release 547 uint8_t media_disconnect; 548 uint8_t media_connect; 549 uint8_t start_stream; 550 uint8_t close_stream; 551 uint8_t request_can_send_now; 552 uint8_t abort_stream; 553 uint8_t suspend_stream; 554 uint16_t sequence_number; 555 } avdtp_stream_endpoint_t; 556 557 void avdtp_init(void); 558 void avdtp_deinit(void); 559 560 avdtp_connection_t * avdtp_get_connection_for_avdtp_cid(uint16_t avdtp_cid); 561 avdtp_connection_t * avdtp_get_connection_for_l2cap_signaling_cid(uint16_t l2cap_cid); 562 btstack_linked_list_t * avdtp_get_connections(void); 563 btstack_linked_list_t * avdtp_get_stream_endpoints(void); 564 565 avdtp_stream_endpoint_t * avdtp_get_stream_endpoint_for_seid(uint16_t seid); 566 avdtp_stream_endpoint_t * avdtp_get_source_stream_endpoint_for_media_codec(avdtp_media_codec_type_t codec_type); 567 568 btstack_packet_handler_t avdtp_packet_handler_for_stream_endpoint(const avdtp_stream_endpoint_t *stream_endpoint); 569 void avdtp_emit_sink_and_source(uint8_t * packet, uint16_t size); 570 void avdtp_emit_source(uint8_t * packet, uint16_t size); 571 572 void avdtp_register_media_transport_category(avdtp_stream_endpoint_t * stream_endpoint); 573 void avdtp_register_reporting_category(avdtp_stream_endpoint_t * stream_endpoint); 574 void avdtp_register_delay_reporting_category(avdtp_stream_endpoint_t * stream_endpoint); 575 void avdtp_register_recovery_category(avdtp_stream_endpoint_t * stream_endpoint, uint8_t maximum_recovery_window_size, uint8_t maximum_number_media_packets); 576 void avdtp_register_content_protection_category(avdtp_stream_endpoint_t * stream_endpoint, uint16_t cp_type, const uint8_t * cp_type_value, uint8_t cp_type_value_len); 577 void avdtp_register_header_compression_category(avdtp_stream_endpoint_t * stream_endpoint, uint8_t back_ch, uint8_t media, uint8_t recovery); 578 void avdtp_register_media_codec_category(avdtp_stream_endpoint_t * stream_endpoint, avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type, uint8_t * media_codec_info, uint16_t media_codec_info_len); 579 void avdtp_register_multiplexing_category(avdtp_stream_endpoint_t * stream_endpoint, uint8_t fragmentation); 580 581 // sink only 582 void avdtp_register_media_handler(void (*callback)(uint8_t local_seid, uint8_t *packet, uint16_t size)); 583 584 void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); 585 avdtp_stream_endpoint_t * avdtp_create_stream_endpoint(avdtp_sep_type_t sep_type, avdtp_media_type_t media_type); 586 void avdtp_finalize_stream_endpoint(avdtp_stream_endpoint_t * stream_endpoint); 587 588 uint8_t avdtp_connect(bd_addr_t remote, avdtp_role_t role, uint16_t * avdtp_cid); 589 uint8_t avdtp_disconnect(uint16_t avdtp_cid); 590 void avdtp_register_sink_packet_handler(btstack_packet_handler_t callback); 591 void avdtp_register_source_packet_handler(btstack_packet_handler_t callback); 592 593 uint8_t avdtp_open_stream(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid); 594 uint8_t avdtp_start_stream(uint16_t avdtp_cid, uint8_t local_seid); 595 uint8_t avdtp_stop_stream (uint16_t avdtp_cid, uint8_t local_seid); 596 uint8_t avdtp_abort_stream(uint16_t avdtp_cid, uint8_t local_seid); 597 uint8_t avdtp_suspend_stream(uint16_t avdtp_cid, uint8_t local_seid); 598 599 uint8_t avdtp_discover_stream_endpoints(uint16_t avdtp_cid); 600 uint8_t avdtp_get_capabilities(uint16_t avdtp_cid, uint8_t remote_seid); 601 uint8_t avdtp_get_all_capabilities(uint16_t avdtp_cid, uint8_t remote_seid); 602 uint8_t avdtp_get_configuration(uint16_t avdtp_cid, uint8_t remote_seid); 603 uint8_t avdtp_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration); 604 uint8_t avdtp_reconfigure(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration); 605 606 // frequency will be used by avdtp_choose_sbc_sampling_frequency (if supported by both endpoints) 607 void avdtp_set_preferred_sampling_frequeny(avdtp_stream_endpoint_t * stream_endpoint, uint32_t sampling_frequency); 608 609 // channel_mode will be used by avdtp_choose_sbc_channel_mode (if supported by both endpoints) 610 void avdtp_set_preferred_channel_mode(avdtp_stream_endpoint_t * stream_endpoint, uint8_t channel_mode); 611 612 void avdtp_set_preferred_sbc_channel_mode(avdtp_stream_endpoint_t * stream_endpoint, uint32_t sampling_frequency); 613 614 avdtp_channel_mode_t avdtp_choose_sbc_channel_mode(avdtp_stream_endpoint_t * stream_endpoint, uint8_t remote_channel_mode_bitmap); 615 avdtp_sbc_allocation_method_t avdtp_choose_sbc_allocation_method(avdtp_stream_endpoint_t * stream_endpoint, uint8_t remote_allocation_method_bitmap); 616 uint16_t avdtp_choose_sbc_sampling_frequency(avdtp_stream_endpoint_t * stream_endpoint, uint8_t remote_sampling_frequency_bitmap); 617 uint8_t avdtp_choose_sbc_subbands(avdtp_stream_endpoint_t * stream_endpoint, uint8_t remote_subbands_bitmap); 618 uint8_t avdtp_choose_sbc_block_length(avdtp_stream_endpoint_t * stream_endpoint, uint8_t remote_block_length_bitmap); 619 uint8_t avdtp_choose_sbc_max_bitpool_value(avdtp_stream_endpoint_t * stream_endpoint, uint8_t remote_max_bitpool_value); 620 uint8_t avdtp_choose_sbc_min_bitpool_value(avdtp_stream_endpoint_t * stream_endpoint, uint8_t remote_min_bitpool_value); 621 622 uint8_t avdtp_stream_endpoint_seid(avdtp_stream_endpoint_t * stream_endpoint); 623 624 uint8_t is_avdtp_remote_seid_registered(avdtp_stream_endpoint_t * stream_endpoint); 625 626 uint16_t avdtp_get_next_transaction_label(void); 627 628 #if defined __cplusplus 629 } 630 #endif 631 632 #endif // AVDTP_H 633