1 /*
2  * Copyright (c) 2022 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 namespace OHOS {
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * @brief Manages audio adapters through a specific adapter driver program loaded based on the given audio
50  * adapter descriptor.
51  *
52  * @see AudioAdapter
53  * @since 1.0
54  * @version 1.0
55  */
56 struct AudioManager {
57     /**
58      * @brief Obtains the list of all adapters supported by an audio driver.
59      *
60      * @param manager Indicates the pointer to the audio adapter manager to operate.
61      * @param descs Indicates the double pointer to the audio adapter list.
62      * @param size Indicates the pointer to the length of the list.
63      * @return Returns <b>0</b> if the list is obtained successfully; returns a negative value otherwise.
64      * @see LoadAdapter
65      */
66     int32_t (*GetAllAdapters)(struct AudioManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size);
67 
68     /**
69      * @brief Loads the driver for an audio adapter.
70      *
71      * For example, to load a USB driver, you may need to load a dynamic-link library (*.so) in specific implementation.
72      *
73      * @param manager Indicates the pointer to the audio adapter manager to operate.
74      * @param desc Indicates the pointer to the descriptor of the audio adapter.
75      * @param adapter Indicates the double pointer to the audio adapter.
76      * @return Returns <b>0</b> if the driver is loaded successfully; returns a negative value otherwise.
77      * @see GetAllAdapters
78      * @see UnloadAdapter
79      */
80     int32_t (*LoadAdapter)(struct AudioManager *manager, const struct AudioAdapterDescriptor *desc,
81                            struct AudioAdapter **adapter);
82 
83     /**
84      * @brief Unloads the driver of an audio adapter.
85      *
86      * @param manager Indicates the pointer to the audio adapter manager to operate.
87      * @param adapter Indicates the pointer to the audio adapter whose driver will be unloaded.
88      * @see LoadAdapter
89      */
90     void (*UnloadAdapter)(struct AudioManager *manager, struct AudioAdapter *adapter);
91 
92     /**
93      * @brief Release the AudioManager Object.
94      *
95      * @param object Indicates the pointer to the audio adapter manager to operate.
96      * @return Returns <b>true</b> if the Object is released; returns <b>false</b> otherwise.
97      */
98     bool (*ReleaseAudioManagerObject)(struct AudioManager *object);
99 };
100 
101 /**
102  * @brief Obtains the operation function list of the {@link AudioManager} class.
103  *
104  * @return Returns the pointer to the <b>AudioManager</b> object if the list is obtained; returns <b>NULL</b> otherwise.
105  */
106 struct AudioManager *GetAudioManagerFuncs(void);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 } /* end of OHOS */
112 #endif /* AUDIO_MANAGER_H */
113 /** @} */
114