1 /*
2  * Copyright (C) 2020 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 #pragma once
18 
19 #include <stdbool.h>
20 
21 #include "utils.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef struct {
28     aafc_audio_usage_t audio_usage;
29     aafc_zone_id_t zone_id;
30     bool allow_duck;
31     bool is_transient;
32     bool is_exclusive;
33 } aafc_audio_focus_request_t;
34 
35 /* Initialize the audio focus controller before using, return 0 when success.
36  * Otherwise return value will be -ERROR_CODE
37  *
38  * This should be called before starting sending any audio focus requests
39  * (mandatory and the only recommended usage),
40  * or it may be called to update the address when the caller is absolutely
41  * sure that there are no existing sessions or any concurrent focus requests
42  * in this process (NOT RECOMMENDED because it is error-prone). Its behavior
43  * is undefined if running concurrently with other requests or active sessions
44  * in the same process. */
45 int aafc_init_audio_focus_controller(const char* audio_control_server_addr);
46 
47 /* Acquire audio focus from Android AudioControl HAL.
48  * This call will return immediately with a globally unique
49  * session ID. Return AAFC_SESSION_ID_INVALID when error.
50  */
51 aafc_session_id_t aafc_acquire_audio_focus(aafc_audio_focus_request_t);
52 
53 /* Release the audio focus of the specified session.
54  * This call will return immediately. Invalid session ID will be ignored.
55  */
56 void aafc_release_audio_focus(aafc_session_id_t session_id);
57 
58 #ifdef __cplusplus
59 }  // extern "C"
60 #endif
61