blob: d0db96dfb3adb1b1f0d1ba7c5c12dc83c3a59ea3 [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,
48 BTAV_A2DP_CODEC_INDEX_SOURCE_SBC = 0,
49
50 /* Add an entry for each new source codec here */
51
52 BTAV_A2DP_CODEC_INDEX_SOURCE_MAX,
53
54 BTAV_A2DP_CODEC_INDEX_SINK_MIN = BTAV_A2DP_CODEC_INDEX_SOURCE_MAX,
55 BTAV_A2DP_CODEC_INDEX_SINK_SBC = BTAV_A2DP_CODEC_INDEX_SINK_MIN,
56
57 /* Add an entry for each new sink codec here */
58
59 BTAV_A2DP_CODEC_INDEX_SINK_MAX,
60
61 BTAV_A2DP_CODEC_INDEX_MIN = BTAV_A2DP_CODEC_INDEX_SOURCE_MIN,
62 BTAV_A2DP_CODEC_INDEX_MAX = BTAV_A2DP_CODEC_INDEX_SINK_MAX
63} btav_a2dp_codec_index_t;
64
65typedef uint32_t btav_a2dp_codec_priority_t;
66
67typedef enum {
68 BTAV_A2DP_CODEC_SAMPLE_RATE_NONE = 0x0,
69 BTAV_A2DP_CODEC_SAMPLE_RATE_44100 = 0x1 << 0,
70 BTAV_A2DP_CODEC_SAMPLE_RATE_48000 = 0x1 << 1,
71 BTAV_A2DP_CODEC_SAMPLE_RATE_88200 = 0x1 << 2,
72 BTAV_A2DP_CODEC_SAMPLE_RATE_96000 = 0x1 << 3,
73 BTAV_A2DP_CODEC_SAMPLE_RATE_176400 = 0x1 << 4,
74 BTAV_A2DP_CODEC_SAMPLE_RATE_192000 = 0x1 << 5
75} btav_a2dp_codec_sample_rate_t;
76
77typedef enum {
78 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_NONE = 0x0,
79 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_16 = 0x1 << 0,
80 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_24 = 0x1 << 1,
81 BTAV_A2DP_CODEC_BITS_PER_SAMPLE_32 = 0x1 << 2
82} btav_a2dp_codec_bits_per_sample_t;
83
84typedef enum {
85 BTAV_A2DP_CODEC_CHANNEL_MODE_NONE = 0x0,
86 BTAV_A2DP_CODEC_CHANNEL_MODE_MONO = 0x1 << 0,
87 BTAV_A2DP_CODEC_CHANNEL_MODE_STEREO = 0x1 << 1
88} btav_a2dp_codec_channel_mode_t;
89
90/*
91 * Structure for representing codec capability or configuration.
92 * It is used for configuring A2DP codec preference, and for reporting back
93 * current configuration or codec capability.
94 * For codec capability, fields "sample_rate", "bits_per_sample" and
95 * "channel_mode" can contain bit-masks with all supported features.
96 */
97typedef struct {
98 btav_a2dp_codec_index_t codec_type;
99 btav_a2dp_codec_priority_t codec_priority; // Codec selection priority
100 // relative to other codecs: larger value
101 // means higher priority. If 0, reset to
102 // default.
103 btav_a2dp_codec_sample_rate_t sample_rate;
104 btav_a2dp_codec_bits_per_sample_t bits_per_sample;
105 btav_a2dp_codec_channel_mode_t channel_mode;
106 int64_t codec_specific_1; // Codec-specific value 1
107 int64_t codec_specific_2; // Codec-specific value 2
108 int64_t codec_specific_3; // Codec-specific value 3
109 int64_t codec_specific_4; // Codec-specific value 4
110} btav_a2dp_codec_config_t;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700111
112/** Callback for connection state change.
113 * state will have one of the values from btav_connection_state_t
114 */
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530115typedef void (* btav_connection_state_callback)(btav_connection_state_t state,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700116 bt_bdaddr_t *bd_addr);
117
118/** Callback for audiopath state change.
119 * state will have one of the values from btav_audio_state_t
120 */
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530121typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
Andre Eisenbach05f49542012-09-18 12:15:26 -0700122 bt_bdaddr_t *bd_addr);
123
Mike Lockwood21e50b12014-06-07 14:05:22 -0700124/** Callback for audio configuration change.
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800125 * Used only for the A2DP Source interface.
126 */
127typedef void (* btav_audio_source_config_callback)(
128 btav_a2dp_codec_config_t codec_config,
129 std::vector<btav_a2dp_codec_config_t> codec_capabilities);
130
131/** Callback for audio configuration change.
132 * Used only for the A2DP Sink interface.
Mike Lockwood21e50b12014-06-07 14:05:22 -0700133 * sample_rate: sample rate in Hz
134 * channel_count: number of channels (1 for mono, 2 for stereo)
135 */
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800136typedef void (* btav_audio_sink_config_callback)(bt_bdaddr_t *bd_addr,
137 uint32_t sample_rate,
138 uint8_t channel_count);
Mike Lockwood21e50b12014-06-07 14:05:22 -0700139
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800140/** BT-AV A2DP Source callback structure. */
Andre Eisenbach05f49542012-09-18 12:15:26 -0700141typedef struct {
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800142 /** set to sizeof(btav_source_callbacks_t) */
Andre Eisenbach05f49542012-09-18 12:15:26 -0700143 size_t size;
144 btav_connection_state_callback connection_state_cb;
145 btav_audio_state_callback audio_state_cb;
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800146 btav_audio_source_config_callback audio_config_cb;
147} btav_source_callbacks_t;
148
149/** BT-AV A2DP Source callback structure. */
150typedef struct {
151 /** set to sizeof(btav_sink_callbacks_t) */
152 size_t size;
153 btav_connection_state_callback connection_state_cb;
154 btav_audio_state_callback audio_state_cb;
155 btav_audio_sink_config_callback audio_config_cb;
156} btav_sink_callbacks_t;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700157
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530158/**
Andre Eisenbach05f49542012-09-18 12:15:26 -0700159 * NOTE:
160 *
161 * 1. AVRCP 1.0 shall be supported initially. AVRCP passthrough commands
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530162 * shall be handled internally via uinput
Andre Eisenbach05f49542012-09-18 12:15:26 -0700163 *
164 * 2. A2DP data path shall be handled via a socket pipe between the AudioFlinger
165 * android_audio_hw library and the Bluetooth stack.
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530166 *
Andre Eisenbach05f49542012-09-18 12:15:26 -0700167 */
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800168
169/** Represents the standard BT-AV A2DP Source interface.
Mike Lockwood21e50b12014-06-07 14:05:22 -0700170 */
Andre Eisenbach05f49542012-09-18 12:15:26 -0700171typedef struct {
172
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800173 /** set to sizeof(btav_source_interface_t) */
Andre Eisenbach05f49542012-09-18 12:15:26 -0700174 size_t size;
175 /**
176 * Register the BtAv callbacks
177 */
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800178 bt_status_t (*init)( btav_source_callbacks_t* callbacks );
179
180 /** connect to headset */
181 bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
182
183 /** dis-connect from headset */
184 bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
185
186 /** configure the codecs settings preferences */
187 bt_status_t (*config_codec)(std::vector<btav_a2dp_codec_config_t> codec_preferences);
188
189 /** Closes the interface. */
190 void (*cleanup)( void );
191
192} btav_source_interface_t;
193
194/** Represents the standard BT-AV A2DP Sink interface.
195 */
196typedef struct {
197
198 /** set to sizeof(btav_sink_interface_t) */
199 size_t size;
200 /**
201 * Register the BtAv callbacks
202 */
203 bt_status_t (*init)( btav_sink_callbacks_t* callbacks );
Andre Eisenbach05f49542012-09-18 12:15:26 -0700204
205 /** connect to headset */
206 bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
207
208 /** dis-connect from headset */
209 bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
210
211 /** Closes the interface. */
212 void (*cleanup)( void );
AnubhavGuptaa5b557a2015-09-18 14:34:02 +0530213
214 /** Sends Audio Focus State. */
Sanket Agarwalc3ab1d82016-04-08 11:27:53 -0700215 void (*set_audio_focus_state)( int focus_state );
216
217 /** Sets the audio track gain. */
218 void (*set_audio_track_gain)( float gain );
Pavlin Radoslavov3c6e4eb2016-12-05 12:07:32 -0800219} btav_sink_interface_t;
Andre Eisenbach05f49542012-09-18 12:15:26 -0700220
221__END_DECLS
222
223#endif /* ANDROID_INCLUDE_BT_AV_H */