-
Notifications
You must be signed in to change notification settings - Fork 2
/
sink_audio_routing.h
414 lines (317 loc) · 11.7 KB
/
sink_audio_routing.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004 - 2015.
FILE NAME
sink_audio.h
DESCRIPTION
*/
#ifndef _SINK_AUDIO_ROUTING_H_
#define _SINK_AUDIO_ROUTING_H_
#include "sink_private.h"
/* structure of audio sources statuses, used once by audio routing to reduce
stack usage */
typedef struct
{
Sink audio_routed; /* currently routed audio */
Sink sinkAG1; /* SCO sink of AG1 */
Sink sinkAG2; /* SCO sink of AG2 */
hfp_call_state stateAG1; /* call state of AG1 */
hfp_call_state stateAG2; /* call state of AG2 */
Sink a2dpSinkPri; /* A2dp primary audio sink */
Sink a2dpSinkSec; /* A2dp secondary audio sink */
a2dp_stream_state a2dpStatePri; /* A2dp primary audio state */
a2dp_stream_state a2dpStateSec; /* A2dp secondary audio state */
a2dp_role_type a2dpRolePri; /* Role (source/sink) of A2DP primary sink */
a2dp_role_type a2dpRoleSec; /* Role (source/sink) of A2DP secondary sink */
}audio_source_status;
typedef enum
{
audio_source_none = 0,
audio_source_FM,
audio_source_ANALOG,
audio_source_SPDIF,
audio_source_USB,
audio_source_AG1,
audio_source_AG2,
audio_source_end_of_list
}audio_sources;
typedef enum
{
audio_gate_none = 0x00,
audio_gate_call = 0x01,
audio_gate_party = 0x02,
audio_gate_a2dp = 0x04,
audio_gate_usb = 0x08,
audio_gate_wired = 0x10,
audio_gate_fm = 0x20,
audio_gate_multimedia = 0x3E, /* All but audio_gate_call, audio_gate_sco and audio_gate_relay */
audio_gate_sco = 0x40,
audio_gate_relay = 0x80,
audio_gate_noncall = 0x8E, /* All but audio_gate_call */
audio_gate_all = 0xFF
}audio_gating;
/* intended as a clean mechanism to determine what audio is routed */
typedef enum
{
audio_route_none = 0x00,
audio_route_a2dp_primary = 0x01,
audio_route_a2dp_secondary = 0x02,
audio_route_hfp_primary = 0x04,
audio_route_hfp_secondary = 0x08,
audio_route_usb = 0x10,
audio_route_analog = 0x20,
audio_route_spdif = 0x40,
audio_route_fm = 0x80
} audio_route_available;
audio_gating audioGateAudio (uint16 audio_gated_mask);
audio_gating audioUngateAudio (uint16 audio_ungated_mask);
#ifdef ENABLE_SOUNDBAR
/****************************************************************************
NAME
audioSwitchToAudioSource
DESCRIPTION
Switch audio routing to the source passed in, it may not be possible
to actually route the audio at that point until the audio sink becomes
available.
If the audio is not routed, it will be queued for routing unless cancelled,
un-comment line to cancel the queuing feature
RETURNS
TRUE if audio routed, FALSE id not possible to route audio
*/
bool audioSwitchToAudioSource(audio_sources source);
/****************************************************************************
NAME
audioSwitchToNextAudioSource
DESCRIPTION
attempt to cycle to the next available audio source, if a source
isn't available then cycle round until one is found, if no audio sources
are available then stop
RETURNS
none
*/
void audioSwitchToNextAudioSource(void);
#endif
/****************************************************************************
NAME
audioHandleRouting
DESCRIPTION
Handle the routing of the audio connections or connection based on
sco priority level, can specify a required source for soundbar type apps
RETURNS
TRUE if audio routed correctly, FALSE if no audio available to route
*/
bool audioHandleRouting (audio_sources required_source);
/****************************************************************************
NAME
audioRouteSource
DESCRIPTION
attempt to route the audio for the passed in source
RETURNS
TRUE if audio routed correctly, FALSE if no audio available yet to route
*/
bool audioRouteSource(audio_sources source, audio_source_status * lAudioStatus);
#ifdef ENABLE_SUBWOOFER
/****************************************************************************
NAME
audioCheckSubwooferConnection
DESCRIPTION
check the sub woofer connection and streaming status and reconnect it if necessary
RETURNS
TRUE if sub woofer reconnected, FALSE if no action has been taken
*/
bool audioCheckSubwooferConnection(bool okToConnectSub);
#endif
/****************************************************************************
NAME
audioRouteUsbIfAvailable
DESCRIPTION
checks for a usb stream being present and routes it if present
RETURNS
true if usb routed, false if no usb routable
*/
bool audioRouteUsbIfAvailable(audio_source_status * lAudioStatus);
/****************************************************************************
NAME
audioRouteA2dpStreamIfAvailable
DESCRIPTION
checks for any a2dp streams being present and routes them if present, if no
streaming connections check for suspended streams and resume them
RETURNS
true if a2dp routed, false if no a2dp routable
*/
bool audioRouteA2dpStreamIfAvailable(audio_source_status * lAudioStatus, a2dp_link_priority priority);
/****************************************************************************
NAME
audioRouteActiveCallScoIfAvailable
DESCRIPTION
checks for any sco being present, check whether there is a corresponding
active call and route it based on its priority. check whether sco is already
routed or whether a different audio source needs to be suspended/disconnected
RETURNS
true if sco routed, false if no sco routable
*/
bool audioRouteActiveCallScoIfAvailable(audio_source_status * lAudioStatus, hfp_link_priority priority);
/****************************************************************************
NAME
audioRelaySourceStream
DESCRIPTION
Checks for a Peer relay (source) stream and asks DSP to relay audio from any active AV Source
RETURNS
true if audio relayed, false otherwise
*/
bool audioRelaySourceStream (void);
/****************************************************************************
NAME
audioRouteFMIfAvailable
DESCRIPTION
checks for an fm audio stream being present and routes it if present
RETURNS
true if fm routed, false if no fm routed
*/
bool audioRouteFMIfAvailable(audio_source_status * lAudioStatus);
/****************************************************************************
NAME
audioRouteScoIfAvailable
DESCRIPTION
checks for any sco being present without any call indications
RETURNS
true if sco routed, false if no sco routable
*/
bool audioRouteScoIfAvailable(audio_source_status * lAudioStatus);
/****************************************************************************
NAME
audioSuspendDisconnectSource
DESCRIPTION
determines source of sink passed in and decides whether to issue a suspend or
not based on source type, an audio disconnect is performed thereafter regardless
of wether or not the source requires a suspend
RETURNS
none
*/
bool audioSuspendDisconnectSource(audio_source_status * lAudioStatus);
/****************************************************************************
NAME
audioConnectScoSink
DESCRIPTION
Route audio from a given SCO sink
RETURNS
*/
void audioConnectScoSink(hfp_link_priority priority, Sink sink);
/****************************************************************************
NAME
audioDisconnectActiveSink
DESCRIPTION
Disconnect the active audio sink
RETURNS
*/
void audioDisconnectActiveSink(void);
/****************************************************************************
NAME
audioUpdateDisplayAmp
DESCRIPTION
update the display if applicable and control the audio amp pio
RETURNS
none
*/
void audioUpdateDisplayAmp(Sink audio_routed, audio_source_status * lAudioStatus);
/****************************************************************************
NAME
audioGetStatus
DESCRIPTION
malloc slot and get status of sco/calls and a2do links, significantly
reduces stack usage at the expense of a temporary slot use
RETURNS
ptr to structure containing audio statuses
*/
audio_source_status * audioGetStatus(Sink routed_audio);
/****************************************************************************
NAME
audioRouteAnalogIfAvailable
DESCRIPTION
checks for an analog audio stream being present and routes it if present
RETURNS
true if analog audio routed, false if no analog audio routable
*/
bool audioRouteAnalogIfAvailable(audio_source_status * lAudioStatus);
/****************************************************************************
NAME
audioRouteSpdifIfAvailable
DESCRIPTION
checks for an spdif audio stream being present and routes it if present
RETURNS
true if spdif audio routed, false if no spdif audio routable
*/
bool audioRouteSpdifIfAvailable(audio_source_status * lAudioStatus);
/****************************************************************************
NAME
sinkAudioRouteAvailable
DESCRIPTION
returns which audio source is routed. Only the route of highest priority is
returned. The priority starting at the top of the enum audio_route_available
RETURNS
audio_route_available
*/
audio_route_available sinkAudioRouteAvailable(void);
#ifdef ENABLE_SOUNDBAR
#ifdef ENABLE_SUBWOOFER
/****************************************************************************
NAME
audioSuspendDisconnectAllA2dpMedia
DESCRIPTION
called when the SUB link wants to use an ESCO link, there is not enough
link bandwidth to support a2dp media and esco links so suspend or disconnect
all a2dp media streams
RETURNS
true if audio disconnected, false if no action taken
*/
bool audioSuspendDisconnectAllA2dpMedia(audio_source_status * lAudioStatus);
#endif
#endif
#ifdef ENABLE_SOUNDBAR
#ifdef ENABLE_AVRCP
/****************************************************************************
NAME
SetSoundbarAVRCPActiveSource
DESCRIPTION
called when manually selecting AG1 or AG2 input, this function determines
if it is possible to ascertain which AVRCP connections are tied to which
AG and sets the active AVRCP instance if it is able to do so based on the
selected audio source
RETURNS
none
*/
void SetSoundbarAVRCPActiveSource(audio_sources source);
#endif
#endif
/****************************************************************************
NAME
audioRouteAncIfAvailable
DESCRIPTION
Checks for an ANC stream being present and routes it if present
RETURNS
TRUE if ANC routed, FALSE otherwise
*/
bool audioRouteAncIfAvailable(audio_source_status * lAudioStatus);
/****************************************************************************
NAME
audioA2dpStartStream
DESCRIPTION
Start the A2DP Audio stream request from the application.
RETURNS
None
*/
void audioA2dpStartStream(void);
/****************************************************************************
NAME
audioRouteSelectedSource
DESCRIPTION
attempts to process a button press request to change source, to prevent multiple
source change requests from being generated and consuming resources ultimately
leading to failure, if user presses buttons excessively quickly extra source change
requests will be discarded until the current one has completed
RETURNS
success or failure status, false if discarded
*/
#ifdef ENABLE_SOUNDBAR
bool audioRouteSelectedSource(audio_sources source);
#endif
#endif /* _SINK_AUDIO_ROUTING_H_ */