1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Audio
18  * @{
19  *
20  * @brief Defines audio-related APIs, including custom data types and functions for loading drivers,
21  * accessing a driver adapter, and rendering and capturing audios.
22  *
23  * @since 1.0
24  * @version 1.0
25  */
26 
27 /**
28  * @file audio_manager.h
29  *
30  * @brief Declares APIs for audio adapter management and loading.
31  *
32  * @since 1.0
33  * @version 1.0
34  */
35 
36 #ifndef AUDIO_MANAGER_H
37 #define AUDIO_MANAGER_H
38 
39 #include "audio_types.h"
40 #include "audio_adapter.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Manages audio adapters through a specific adapter driver program loaded based on the given audio
48  * adapter descriptor.
49  *
50  * @see AudioAdapter
51  * @since 1.0
52  * @version 1.0
53  */
54 struct AudioManager {
55     /**
56      * @brief Obtains the list of all adapters supported by an audio driver.
57      *
58      * @param manager Indicates the pointer to the audio adapter manager to operate.
59      * @param descs Indicates the double pointer to the audio adapter list.
60      * @param size Indicates the pointer to the length of the list.
61      * @return Returns <b>0</b> if the list is obtained successfully; returns a negative value otherwise.
62      * @see LoadAdapter
63      */
64     int32_t (*GetAllAdapters)(struct AudioManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size);
65 
66     /**
67      * @brief Loads the driver for an audio adapter.
68      *
69      * For example, to load a USB driver, you may need to load a dynamic-link library (*.so) in specific implementation.
70      *
71      * @param manager Indicates the pointer to the audio adapter manager to operate.
72      * @param desc Indicates the pointer to the descriptor of the audio adapter.
73      * @param adapter Indicates the double pointer to the audio adapter.
74      * @return Returns <b>0</b> if the driver is loaded successfully; returns a negative value otherwise.
75      * @see GetAllAdapters
76      * @see UnloadAdapter
77      */
78     int32_t (*LoadAdapter)(struct AudioManager *manager, const struct AudioAdapterDescriptor *desc,
79                            struct AudioAdapter **adapter);
80 
81     /**
82      * @brief Unloads the driver of an audio adapter.
83      *
84      * @param manager Indicates the pointer to the audio adapter manager to operate.
85      * @param adapter Indicates the pointer to the audio adapter whose driver will be unloaded.
86      * @see LoadAdapter
87      */
88     void (*UnloadAdapter)(struct AudioManager *manager, struct AudioAdapter *adapter);
89 
90     /**
91      * @brief Release the AudioManager Object.
92      *
93      * @param object Indicates the pointer to the audio adapter manager to operate.
94      * @return Returns <b>true</b> if the Object is released; returns <b>false</b> otherwise.
95      */
96     bool (*ReleaseAudioManagerObject)(struct AudioManager *object);
97 };
98 
99 /**
100  * @brief Obtains the operation function list of the {@link AudioManager} class.
101  *
102  * @return Returns the pointer to the <b>AudioManager</b> object if the list is obtained; returns <b>NULL</b> otherwise.
103  */
104 struct AudioManager *GetAudioManagerFuncs(void);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* AUDIO_MANAGER_H */
111 /** @} */
112