blob: 66a8643d7b82f6a24255783b46ce40477be12db7 [file] [log] [blame]
Andre Eisenbach05f49542012-09-18 12:15:26 -07001/*
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 Radoslavov3c6e4eb2016-12-05 12:07:32 -080020#include <vector>
21
22#include <hardware/bluetooth.h>
23
Andre Eisenbach05f49542012-09-18 12:15:26 -070024__BEGIN_DECLS
25
26/* Bluetooth AV connection states */
27typedef 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 */
35typedef 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 Radoslavov3c6e4eb2016-12-05 12:07:32 -080041/*
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 */
46typedef enum {
47 BTAV_A2DP_CODEC_INDEX_SOURCE_MIN = 0,
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -080048
Pavlin Radoslavovb2543a22017-01-04 16:12:47 -080049 // 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,
Pavlin Radoslavovf9b17fe2017-01-14 00:42:22 -080053 BTAV_A2DP_CODEC_INDEX_SOURCE_AAC,
Pavlin Radoslavovb2543a22017-01-04 16:12:47 -080054 BTAV_A2DP_CODEC_INDEX_SOURCE_APTX,
55 BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD,
Pavlin Radoslavovbe1bfce2017-01-04 16:50:01 -080056 BTAV_A2DP_CODEC_INDEX_SOURCE_LDAC,
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -080057
58 BTAV_A2DP_CODEC_INDEX_SOURCE_MAX,
59
60 BTAV_A2DP_CODEC_INDEX_SINK_MIN = BTAV_A2DP_CODEC_INDEX_SOURCE_MAX,
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -080061
Pavlin Radoslavovb2543a22017-01-04 16:12:47 -080062 // Add an entry for each sink codec here
63 BTAV_A2DP_CODEC_INDEX_SINK_SBC = BTAV_A2DP_CODEC_INDEX_SINK_MIN,
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -080064
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
Pavlin Radoslavov1f103a42017-01-26 09:44:29 -080071typedef enum {
72 BTAV_A2DP_CODEC_PRIORITY_DEFAULT = 0,
73 BTAV_A2DP_CODEC_PRIORITY_HIGHEST = 1000 * 1000
74} btav_a2dp_codec_priority_t;
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -080075
76typedef enum {
77 BTAV_A2DP_CODEC_SAMPLE_RATE_NONE = 0x0,
78 BTAV_A2DP_CODEC_SAMPLE_RATE_44100 = 0x1 << 0,
79 BTAV_A2DP_CODEC_SAMPLE_RATE_48000 = 0x1 << 1,
80 BTAV_A2DP_CODEC_SAMPLE_RATE_88200 = 0x1 << 2,
81 BTAV_A2DP_CODEC_SAMPLE_RATE_96000 = 0x1 << 3,
82 BTAV_A2DP_CODEC_SAMPLE_RATE_176400 = 0x1 << 4,
83 BTAV_A2DP_CODEC_SAMPLE_RATE_192000 = 0x1 << 5
84} btav_a2dp_codec_sample_rate_t;
85
86typedef enum {
87 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE = 0x0,
88 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_16 = 0x1 << 0,
89 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_24 = 0x1 << 1,
90 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_32 = 0x1 << 2
91} btav_a2dp_codec_bits_per_sample_t;
92
93typedef enum {
94 BTAV_A2DP_CODEC_CHANNEL_MODE_NONE = 0x0,
95 BTAV_A2DP_CODEC_CHANNEL_MODE_MONO = 0x1 << 0,
96 BTAV_A2DP_CODEC_CHANNEL_MODE_STEREO = 0x1 << 1
97} btav_a2dp_codec_channel_mode_t;
98
99/*
100 * Structure for representing codec capability or configuration.
101 * It is used for configuring A2DP codec preference, and for reporting back
102 * current configuration or codec capability.
103 * For codec capability, fields "sample_rate", "bits_per_sample" and
104 * "channel_mode" can contain bit-masks with all supported features.
105 */
106typedef struct {
107 btav_a2dp_codec_index_t codec_type;
108 btav_a2dp_codec_priority_t codec_priority; // Codec selection priority
109 // relative to other codecs: larger value
110 // means higher priority. If 0, reset to
111 // default.
112 btav_a2dp_codec_sample_rate_t sample_rate;
113 btav_a2dp_codec_bits_per_sample_t bits_per_sample;
114 btav_a2dp_codec_channel_mode_t channel_mode;
115 int64_t codec_specific_1; // Codec-specific value 1
116 int64_t codec_specific_2; // Codec-specific value 2
117 int64_t codec_specific_3; // Codec-specific value 3
118 int64_t codec_specific_4; // Codec-specific value 4
119} btav_a2dp_codec_config_t;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700120
121/** Callback for connection state change.
122 * state will have one of the values from btav_connection_state_t
123 */
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530124typedef void (* btav_connection_state_callback)(btav_connection_state_t state,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700125 bt_bdaddr_t *bd_addr);
126
127/** Callback for audiopath state change.
128 * state will have one of the values from btav_audio_state_t
129 */
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530130typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700131 bt_bdaddr_t *bd_addr);
132
Mike Lockwood21e50b12014-06-07 14:05:22 -0700133/** Callback for audio configuration change.
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800134 * Used only for the A2DP Source interface.
135 */
136typedef void (* btav_audio_source_config_callback)(
137 btav_a2dp_codec_config_t codec_config,
Pavlin Radoslavov1f103a42017-01-26 09:44:29 -0800138 std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities,
139 std::vector<btav_a2dp_codec_config_t> codecs_selectable_capabilities);
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800140
141/** Callback for audio configuration change.
142 * Used only for the A2DP Sink interface.
Mike Lockwood21e50b12014-06-07 14:05:22 -0700143 * sample_rate: sample rate in Hz
144 * channel_count: number of channels (1 for mono, 2 for stereo)
145 */
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800146typedef void (* btav_audio_sink_config_callback)(bt_bdaddr_t *bd_addr,
147 uint32_t sample_rate,
148 uint8_t channel_count);
Mike Lockwood21e50b12014-06-07 14:05:22 -0700149
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800150/** BT-AV A2DP Source callback structure. */
Andre Eisenbach05f49542012-09-18 12:15:26 -0700151typedef struct {
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800152 /** set to sizeof(btav_source_callbacks_t) */
Andre Eisenbach05f49542012-09-18 12:15:26 -0700153 size_t size;
154 btav_connection_state_callback connection_state_cb;
155 btav_audio_state_callback audio_state_cb;
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800156 btav_audio_source_config_callback audio_config_cb;
157} btav_source_callbacks_t;
158
159/** BT-AV A2DP Source callback structure. */
160typedef struct {
161 /** set to sizeof(btav_sink_callbacks_t) */
162 size_t size;
163 btav_connection_state_callback connection_state_cb;
164 btav_audio_state_callback audio_state_cb;
165 btav_audio_sink_config_callback audio_config_cb;
166} btav_sink_callbacks_t;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700167
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530168/**
Andre Eisenbach05f49542012-09-18 12:15:26 -0700169 * NOTE:
170 *
171 * 1. AVRCP 1.0 shall be supported initially. AVRCP passthrough commands
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530172 * shall be handled internally via uinput
Andre Eisenbach05f49542012-09-18 12:15:26 -0700173 *
174 * 2. A2DP data path shall be handled via a socket pipe between the AudioFlinger
175 * android_audio_hw library and the Bluetooth stack.
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530176 *
Andre Eisenbach05f49542012-09-18 12:15:26 -0700177 */
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800178
179/** Represents the standard BT-AV A2DP Source interface.
Mike Lockwood21e50b12014-06-07 14:05:22 -0700180 */
Andre Eisenbach05f49542012-09-18 12:15:26 -0700181typedef struct {
182
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800183 /** set to sizeof(btav_source_interface_t) */
Andre Eisenbach05f49542012-09-18 12:15:26 -0700184 size_t size;
185 /**
186 * Register the BtAv callbacks
187 */
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800188 bt_status_t (*init)( btav_source_callbacks_t* callbacks );
189
190 /** connect to headset */
191 bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
192
193 /** dis-connect from headset */
194 bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
195
196 /** configure the codecs settings preferences */
197 bt_status_t (*config_codec)(std::vector<btav_a2dp_codec_config_t> codec_preferences);
198
199 /** Closes the interface. */
200 void (*cleanup)( void );
201
202} btav_source_interface_t;
203
204/** Represents the standard BT-AV A2DP Sink interface.
205 */
206typedef struct {
207
208 /** set to sizeof(btav_sink_interface_t) */
209 size_t size;
210 /**
211 * Register the BtAv callbacks
212 */
213 bt_status_t (*init)( btav_sink_callbacks_t* callbacks );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700214
215 /** connect to headset */
216 bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
217
218 /** dis-connect from headset */
219 bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
220
221 /** Closes the interface. */
222 void (*cleanup)( void );
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530223
224 /** Sends Audio Focus State. */
Sanket Agarwalc3ab1d82016-04-08 11:27:53 -0700225 void (*set_audio_focus_state)( int focus_state );
226
227 /** Sets the audio track gain. */
228 void (*set_audio_track_gain)( float gain );
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800229} btav_sink_interface_t;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700230
231__END_DECLS
232
233#endif /* ANDROID_INCLUDE_BT_AV_H */