Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 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 | |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
| 22 | #include <hardware/bluetooth.h> |
| 23 | |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 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 | |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 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, |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 48 | |
Pavlin Radoslavov | b2543a2 | 2017-01-04 16:12:47 -0800 | [diff] [blame] | 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_APTX, |
| 54 | BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD, |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 55 | |
| 56 | BTAV_A2DP_CODEC_INDEX_SOURCE_MAX, |
| 57 | |
| 58 | BTAV_A2DP_CODEC_INDEX_SINK_MIN = BTAV_A2DP_CODEC_INDEX_SOURCE_MAX, |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 59 | |
Pavlin Radoslavov | b2543a2 | 2017-01-04 16:12:47 -0800 | [diff] [blame] | 60 | // Add an entry for each sink codec here |
| 61 | BTAV_A2DP_CODEC_INDEX_SINK_SBC = BTAV_A2DP_CODEC_INDEX_SINK_MIN, |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 62 | |
| 63 | BTAV_A2DP_CODEC_INDEX_SINK_MAX, |
| 64 | |
| 65 | BTAV_A2DP_CODEC_INDEX_MIN = BTAV_A2DP_CODEC_INDEX_SOURCE_MIN, |
| 66 | BTAV_A2DP_CODEC_INDEX_MAX = BTAV_A2DP_CODEC_INDEX_SINK_MAX |
| 67 | } btav_a2dp_codec_index_t; |
| 68 | |
| 69 | typedef uint32_t btav_a2dp_codec_priority_t; |
| 70 | |
| 71 | typedef enum { |
| 72 | BTAV_A2DP_CODEC_SAMPLE_RATE_NONE = 0x0, |
| 73 | BTAV_A2DP_CODEC_SAMPLE_RATE_44100 = 0x1 << 0, |
| 74 | BTAV_A2DP_CODEC_SAMPLE_RATE_48000 = 0x1 << 1, |
| 75 | BTAV_A2DP_CODEC_SAMPLE_RATE_88200 = 0x1 << 2, |
| 76 | BTAV_A2DP_CODEC_SAMPLE_RATE_96000 = 0x1 << 3, |
| 77 | BTAV_A2DP_CODEC_SAMPLE_RATE_176400 = 0x1 << 4, |
| 78 | BTAV_A2DP_CODEC_SAMPLE_RATE_192000 = 0x1 << 5 |
| 79 | } btav_a2dp_codec_sample_rate_t; |
| 80 | |
| 81 | typedef enum { |
| 82 | BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE = 0x0, |
| 83 | BTAV_A2DP_CODEC_BITS_PER_SAMPLE_16 = 0x1 << 0, |
| 84 | BTAV_A2DP_CODEC_BITS_PER_SAMPLE_24 = 0x1 << 1, |
| 85 | BTAV_A2DP_CODEC_BITS_PER_SAMPLE_32 = 0x1 << 2 |
| 86 | } btav_a2dp_codec_bits_per_sample_t; |
| 87 | |
| 88 | typedef enum { |
| 89 | BTAV_A2DP_CODEC_CHANNEL_MODE_NONE = 0x0, |
| 90 | BTAV_A2DP_CODEC_CHANNEL_MODE_MONO = 0x1 << 0, |
| 91 | BTAV_A2DP_CODEC_CHANNEL_MODE_STEREO = 0x1 << 1 |
| 92 | } btav_a2dp_codec_channel_mode_t; |
| 93 | |
| 94 | /* |
| 95 | * Structure for representing codec capability or configuration. |
| 96 | * It is used for configuring A2DP codec preference, and for reporting back |
| 97 | * current configuration or codec capability. |
| 98 | * For codec capability, fields "sample_rate", "bits_per_sample" and |
| 99 | * "channel_mode" can contain bit-masks with all supported features. |
| 100 | */ |
| 101 | typedef struct { |
| 102 | btav_a2dp_codec_index_t codec_type; |
| 103 | btav_a2dp_codec_priority_t codec_priority; // Codec selection priority |
| 104 | // relative to other codecs: larger value |
| 105 | // means higher priority. If 0, reset to |
| 106 | // default. |
| 107 | btav_a2dp_codec_sample_rate_t sample_rate; |
| 108 | btav_a2dp_codec_bits_per_sample_t bits_per_sample; |
| 109 | btav_a2dp_codec_channel_mode_t channel_mode; |
| 110 | int64_t codec_specific_1; // Codec-specific value 1 |
| 111 | int64_t codec_specific_2; // Codec-specific value 2 |
| 112 | int64_t codec_specific_3; // Codec-specific value 3 |
| 113 | int64_t codec_specific_4; // Codec-specific value 4 |
| 114 | } btav_a2dp_codec_config_t; |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 115 | |
| 116 | /** Callback for connection state change. |
| 117 | * state will have one of the values from btav_connection_state_t |
| 118 | */ |
AnubhavGupta | a5b557a | 2015-09-18 14:34:02 +0530 | [diff] [blame] | 119 | typedef void (* btav_connection_state_callback)(btav_connection_state_t state, |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 120 | bt_bdaddr_t *bd_addr); |
| 121 | |
| 122 | /** Callback for audiopath state change. |
| 123 | * state will have one of the values from btav_audio_state_t |
| 124 | */ |
AnubhavGupta | a5b557a | 2015-09-18 14:34:02 +0530 | [diff] [blame] | 125 | typedef void (* btav_audio_state_callback)(btav_audio_state_t state, |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 126 | bt_bdaddr_t *bd_addr); |
| 127 | |
Mike Lockwood | 21e50b1 | 2014-06-07 14:05:22 -0700 | [diff] [blame] | 128 | /** Callback for audio configuration change. |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 129 | * Used only for the A2DP Source interface. |
| 130 | */ |
| 131 | typedef void (* btav_audio_source_config_callback)( |
| 132 | btav_a2dp_codec_config_t codec_config, |
| 133 | std::vector<btav_a2dp_codec_config_t> codec_capabilities); |
| 134 | |
| 135 | /** Callback for audio configuration change. |
| 136 | * Used only for the A2DP Sink interface. |
Mike Lockwood | 21e50b1 | 2014-06-07 14:05:22 -0700 | [diff] [blame] | 137 | * sample_rate: sample rate in Hz |
| 138 | * channel_count: number of channels (1 for mono, 2 for stereo) |
| 139 | */ |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 140 | typedef void (* btav_audio_sink_config_callback)(bt_bdaddr_t *bd_addr, |
| 141 | uint32_t sample_rate, |
| 142 | uint8_t channel_count); |
Mike Lockwood | 21e50b1 | 2014-06-07 14:05:22 -0700 | [diff] [blame] | 143 | |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 144 | /** BT-AV A2DP Source callback structure. */ |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 145 | typedef struct { |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 146 | /** set to sizeof(btav_source_callbacks_t) */ |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 147 | size_t size; |
| 148 | btav_connection_state_callback connection_state_cb; |
| 149 | btav_audio_state_callback audio_state_cb; |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 150 | btav_audio_source_config_callback audio_config_cb; |
| 151 | } btav_source_callbacks_t; |
| 152 | |
| 153 | /** BT-AV A2DP Source callback structure. */ |
| 154 | typedef struct { |
| 155 | /** set to sizeof(btav_sink_callbacks_t) */ |
| 156 | size_t size; |
| 157 | btav_connection_state_callback connection_state_cb; |
| 158 | btav_audio_state_callback audio_state_cb; |
| 159 | btav_audio_sink_config_callback audio_config_cb; |
| 160 | } btav_sink_callbacks_t; |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 161 | |
AnubhavGupta | a5b557a | 2015-09-18 14:34:02 +0530 | [diff] [blame] | 162 | /** |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 163 | * NOTE: |
| 164 | * |
| 165 | * 1. AVRCP 1.0 shall be supported initially. AVRCP passthrough commands |
AnubhavGupta | a5b557a | 2015-09-18 14:34:02 +0530 | [diff] [blame] | 166 | * shall be handled internally via uinput |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 167 | * |
| 168 | * 2. A2DP data path shall be handled via a socket pipe between the AudioFlinger |
| 169 | * android_audio_hw library and the Bluetooth stack. |
AnubhavGupta | a5b557a | 2015-09-18 14:34:02 +0530 | [diff] [blame] | 170 | * |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 171 | */ |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 172 | |
| 173 | /** Represents the standard BT-AV A2DP Source interface. |
Mike Lockwood | 21e50b1 | 2014-06-07 14:05:22 -0700 | [diff] [blame] | 174 | */ |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 175 | typedef struct { |
| 176 | |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 177 | /** set to sizeof(btav_source_interface_t) */ |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 178 | size_t size; |
| 179 | /** |
| 180 | * Register the BtAv callbacks |
| 181 | */ |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 182 | bt_status_t (*init)( btav_source_callbacks_t* callbacks ); |
| 183 | |
| 184 | /** connect to headset */ |
| 185 | bt_status_t (*connect)( bt_bdaddr_t *bd_addr ); |
| 186 | |
| 187 | /** dis-connect from headset */ |
| 188 | bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr ); |
| 189 | |
| 190 | /** configure the codecs settings preferences */ |
| 191 | bt_status_t (*config_codec)(std::vector<btav_a2dp_codec_config_t> codec_preferences); |
| 192 | |
| 193 | /** Closes the interface. */ |
| 194 | void (*cleanup)( void ); |
| 195 | |
| 196 | } btav_source_interface_t; |
| 197 | |
| 198 | /** Represents the standard BT-AV A2DP Sink interface. |
| 199 | */ |
| 200 | typedef struct { |
| 201 | |
| 202 | /** set to sizeof(btav_sink_interface_t) */ |
| 203 | size_t size; |
| 204 | /** |
| 205 | * Register the BtAv callbacks |
| 206 | */ |
| 207 | bt_status_t (*init)( btav_sink_callbacks_t* callbacks ); |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 208 | |
| 209 | /** connect to headset */ |
| 210 | bt_status_t (*connect)( bt_bdaddr_t *bd_addr ); |
| 211 | |
| 212 | /** dis-connect from headset */ |
| 213 | bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr ); |
| 214 | |
| 215 | /** Closes the interface. */ |
| 216 | void (*cleanup)( void ); |
AnubhavGupta | a5b557a | 2015-09-18 14:34:02 +0530 | [diff] [blame] | 217 | |
| 218 | /** Sends Audio Focus State. */ |
Sanket Agarwal | c3ab1d8 | 2016-04-08 11:27:53 -0700 | [diff] [blame] | 219 | void (*set_audio_focus_state)( int focus_state ); |
| 220 | |
| 221 | /** Sets the audio track gain. */ |
| 222 | void (*set_audio_track_gain)( float gain ); |
Pavlin Radoslavov | 3c6e4eb | 2016-12-05 12:07:32 -0800 | [diff] [blame] | 223 | } btav_sink_interface_t; |
Andre Eisenbach | 05f4954 | 2012-09-18 12:15:26 -0700 | [diff] [blame] | 224 | |
| 225 | __END_DECLS |
| 226 | |
| 227 | #endif /* ANDROID_INCLUDE_BT_AV_H */ |