1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_INCLUDE_BT_AV_H 18 #define ANDROID_INCLUDE_BT_AV_H 19 20 #include <vector> 21 22 #include <hardware/bluetooth.h> 23 24 __BEGIN_DECLS 25 26 /* Bluetooth AV connection states */ 27 typedef enum { 28 BTAV_CONNECTION_STATE_DISCONNECTED = 0, 29 BTAV_CONNECTION_STATE_CONNECTING, 30 BTAV_CONNECTION_STATE_CONNECTED, 31 BTAV_CONNECTION_STATE_DISCONNECTING 32 } btav_connection_state_t; 33 34 /* Bluetooth AV datapath states */ 35 typedef enum { 36 BTAV_AUDIO_STATE_REMOTE_SUSPEND = 0, 37 BTAV_AUDIO_STATE_STOPPED, 38 BTAV_AUDIO_STATE_STARTED, 39 } btav_audio_state_t; 40 41 /* 42 * Enum values for each A2DP supported codec. 43 * There should be a separate entry for each A2DP codec that is supported 44 * for encoding (SRC), and for decoding purpose (SINK). 45 */ 46 typedef enum { 47 BTAV_A2DP_CODEC_INDEX_SOURCE_MIN = 0, 48 49 // Add an entry for each source codec here. 50 // NOTE: The values should be same as those listed in the following file: 51 // BluetoothCodecConfig.java 52 BTAV_A2DP_CODEC_INDEX_SOURCE_SBC = 0, 53 BTAV_A2DP_CODEC_INDEX_SOURCE_AAC, 54 BTAV_A2DP_CODEC_INDEX_SOURCE_APTX, 55 BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD, 56 BTAV_A2DP_CODEC_INDEX_SOURCE_LDAC, 57 58 BTAV_A2DP_CODEC_INDEX_SOURCE_MAX, 59 60 BTAV_A2DP_CODEC_INDEX_SINK_MIN = BTAV_A2DP_CODEC_INDEX_SOURCE_MAX, 61 62 // Add an entry for each sink codec here 63 BTAV_A2DP_CODEC_INDEX_SINK_SBC = BTAV_A2DP_CODEC_INDEX_SINK_MIN, 64 65 BTAV_A2DP_CODEC_INDEX_SINK_MAX, 66 67 BTAV_A2DP_CODEC_INDEX_MIN = BTAV_A2DP_CODEC_INDEX_SOURCE_MIN, 68 BTAV_A2DP_CODEC_INDEX_MAX = BTAV_A2DP_CODEC_INDEX_SINK_MAX 69 } btav_a2dp_codec_index_t; 70 71 typedef enum { 72 // Disable the codec. 73 // NOTE: This value can be used only during initialization when 74 // function btav_source_interface_t::init() is called. 75 BTAV_A2DP_CODEC_PRIORITY_DISABLED = -1, 76 77 // Reset the codec priority to its default value. 78 BTAV_A2DP_CODEC_PRIORITY_DEFAULT = 0, 79 80 // Highest codec priority. 81 BTAV_A2DP_CODEC_PRIORITY_HIGHEST = 1000 * 1000 82 } btav_a2dp_codec_priority_t; 83 84 typedef enum { 85 BTAV_A2DP_CODEC_SAMPLE_RATE_NONE = 0x0, 86 BTAV_A2DP_CODEC_SAMPLE_RATE_44100 = 0x1 << 0, 87 BTAV_A2DP_CODEC_SAMPLE_RATE_48000 = 0x1 << 1, 88 BTAV_A2DP_CODEC_SAMPLE_RATE_88200 = 0x1 << 2, 89 BTAV_A2DP_CODEC_SAMPLE_RATE_96000 = 0x1 << 3, 90 BTAV_A2DP_CODEC_SAMPLE_RATE_176400 = 0x1 << 4, 91 BTAV_A2DP_CODEC_SAMPLE_RATE_192000 = 0x1 << 5 92 } btav_a2dp_codec_sample_rate_t; 93 94 typedef enum { 95 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE = 0x0, 96 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_16 = 0x1 << 0, 97 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_24 = 0x1 << 1, 98 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_32 = 0x1 << 2 99 } btav_a2dp_codec_bits_per_sample_t; 100 101 typedef enum { 102 BTAV_A2DP_CODEC_CHANNEL_MODE_NONE = 0x0, 103 BTAV_A2DP_CODEC_CHANNEL_MODE_MONO = 0x1 << 0, 104 BTAV_A2DP_CODEC_CHANNEL_MODE_STEREO = 0x1 << 1 105 } btav_a2dp_codec_channel_mode_t; 106 107 /* 108 * Structure for representing codec capability or configuration. 109 * It is used for configuring A2DP codec preference, and for reporting back 110 * current configuration or codec capability. 111 * For codec capability, fields "sample_rate", "bits_per_sample" and 112 * "channel_mode" can contain bit-masks with all supported features. 113 */ 114 typedef struct { 115 btav_a2dp_codec_index_t codec_type; 116 btav_a2dp_codec_priority_t codec_priority; // Codec selection priority 117 // relative to other codecs: larger value 118 // means higher priority. If 0, reset to 119 // default. 120 btav_a2dp_codec_sample_rate_t sample_rate; 121 btav_a2dp_codec_bits_per_sample_t bits_per_sample; 122 btav_a2dp_codec_channel_mode_t channel_mode; 123 int64_t codec_specific_1; // Codec-specific value 1 124 int64_t codec_specific_2; // Codec-specific value 2 125 int64_t codec_specific_3; // Codec-specific value 3 126 int64_t codec_specific_4; // Codec-specific value 4 127 } btav_a2dp_codec_config_t; 128 129 /** Callback for connection state change. 130 * state will have one of the values from btav_connection_state_t 131 */ 132 typedef void (* btav_connection_state_callback)(btav_connection_state_t state, 133 RawAddress *bd_addr); 134 135 /** Callback for audiopath state change. 136 * state will have one of the values from btav_audio_state_t 137 */ 138 typedef void (* btav_audio_state_callback)(btav_audio_state_t state, 139 RawAddress *bd_addr); 140 141 /** Callback for audio configuration change. 142 * Used only for the A2DP Source interface. 143 */ 144 typedef void (* btav_audio_source_config_callback)( 145 btav_a2dp_codec_config_t codec_config, 146 std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities, 147 std::vector<btav_a2dp_codec_config_t> codecs_selectable_capabilities); 148 149 /** Callback for audio configuration change. 150 * Used only for the A2DP Sink interface. 151 * sample_rate: sample rate in Hz 152 * channel_count: number of channels (1 for mono, 2 for stereo) 153 */ 154 typedef void (* btav_audio_sink_config_callback)(RawAddress *bd_addr, 155 uint32_t sample_rate, 156 uint8_t channel_count); 157 158 /** BT-AV A2DP Source callback structure. */ 159 typedef struct { 160 /** set to sizeof(btav_source_callbacks_t) */ 161 size_t size; 162 btav_connection_state_callback connection_state_cb; 163 btav_audio_state_callback audio_state_cb; 164 btav_audio_source_config_callback audio_config_cb; 165 } btav_source_callbacks_t; 166 167 /** BT-AV A2DP Sink callback structure. */ 168 typedef struct { 169 /** set to sizeof(btav_sink_callbacks_t) */ 170 size_t size; 171 btav_connection_state_callback connection_state_cb; 172 btav_audio_state_callback audio_state_cb; 173 btav_audio_sink_config_callback audio_config_cb; 174 } btav_sink_callbacks_t; 175 176 /** 177 * NOTE: 178 * 179 * 1. AVRCP 1.0 shall be supported initially. AVRCP passthrough commands 180 * shall be handled internally via uinput 181 * 182 * 2. A2DP data path shall be handled via a socket pipe between the AudioFlinger 183 * android_audio_hw library and the Bluetooth stack. 184 * 185 */ 186 187 /** Represents the standard BT-AV A2DP Source interface. 188 */ 189 typedef struct { 190 191 /** set to sizeof(btav_source_interface_t) */ 192 size_t size; 193 /** 194 * Register the BtAv callbacks. 195 */ 196 bt_status_t (*init)(btav_source_callbacks_t* callbacks, 197 std::vector<btav_a2dp_codec_config_t> codec_priorities); 198 199 /** connect to headset */ 200 bt_status_t (*connect)( RawAddress *bd_addr ); 201 202 /** dis-connect from headset */ 203 bt_status_t (*disconnect)( RawAddress *bd_addr ); 204 205 /** configure the codecs settings preferences */ 206 bt_status_t (*config_codec)(std::vector<btav_a2dp_codec_config_t> codec_preferences); 207 208 /** Closes the interface. */ 209 void (*cleanup)( void ); 210 211 } btav_source_interface_t; 212 213 /** Represents the standard BT-AV A2DP Sink interface. 214 */ 215 typedef struct { 216 217 /** set to sizeof(btav_sink_interface_t) */ 218 size_t size; 219 /** 220 * Register the BtAv callbacks 221 */ 222 bt_status_t (*init)( btav_sink_callbacks_t* callbacks ); 223 224 /** connect to headset */ 225 bt_status_t (*connect)( RawAddress *bd_addr ); 226 227 /** dis-connect from headset */ 228 bt_status_t (*disconnect)( RawAddress *bd_addr ); 229 230 /** Closes the interface. */ 231 void (*cleanup)( void ); 232 233 /** Sends Audio Focus State. */ 234 void (*set_audio_focus_state)( int focus_state ); 235 236 /** Sets the audio track gain. */ 237 void (*set_audio_track_gain)( float gain ); 238 } btav_sink_interface_t; 239 240 __END_DECLS 241 242 #endif /* ANDROID_INCLUDE_BT_AV_H */ 243