1 /* 2 * Copyright (c) 2025-2025 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 OHAudio 18 * @{ 19 * 20 * @brief Provide the definition of the C interface for the audio module. 21 * 22 * @syscap SystemCapability.Multimedia.Audio.Core 23 * 24 * @since 20 25 */ 26 27 /** 28 * @file native_audio_resource_manager.h 29 * 30 * @brief Declare audio resource manager related interfaces. 31 * 32 * This file interfaces are used for the creation of AudioResourceManager. 33 * 34 * @library libohaudio.so 35 * @syscap SystemCapability.Multimedia.Audio.Core 36 * @kit AudioKit 37 * @since 20 38 */ 39 40 #ifndef NATIVE_AUDIO_RESOURCE_MANAGER_H 41 #define NATIVE_AUDIO_RESOURCE_MANAGER_H 42 43 #include "native_audio_common.h" 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /** 50 * @brief Declare the audio resource manager. 51 * Audio resource manager provides many functions for developer to manage system resources to avoid 52 * underrun or overrun in audio playback and recording. 53 * 54 * @since 20 55 */ 56 typedef struct OH_AudioResourceManager OH_AudioResourceManager; 57 58 /** 59 * @brief Declare the audio workgroup. 60 * The handle of audio workgroup is used for audio management related functions. 61 * 62 * @since 20 63 */ 64 typedef struct OH_AudioWorkgroup OH_AudioWorkgroup; 65 66 /** 67 * @brief Fetch the audio resource manager handle, which is a singleton. 68 * 69 * @param resourceManager output parameter to get {@link #OH_AudioResourceManager}. 70 * @return 71 * {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds 72 * {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if input param is nullptr 73 * @since 20 74 */ 75 OH_AudioCommon_Result OH_AudioManager_GetAudioResourceManager(OH_AudioResourceManager **resourceManager); 76 77 /** 78 * @brief Create a workgroup for audio data processing threads in application. 79 * System manages cpu resources by workgroup configuration. 80 * 81 * @param resourceManager {@link #OH_AudioResourceManager} handle 82 * @param name workgroup name 83 * @param group {@link #OH_AudioWorkgroup} handle for managing audio data processing threads. 84 * @return 85 * {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds 86 * {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if input param is nullptr 87 * {@link #AUDIOCOMMON_RESULT_ERROR_NO_MEMORY} out of workgroup resources 88 * {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} system process error occurs 89 * @since 20 90 */ 91 OH_AudioCommon_Result OH_AudioResourceManager_CreateWorkgroup(OH_AudioResourceManager *resourceManager, 92 const char *name, OH_AudioWorkgroup **group); 93 94 /** 95 * @brief Release the workgroup created before. 96 * 97 * @param resourceManager {@link #OH_AudioResourceManager} handle 98 * @param group {@link #OH_AudioWorkgroup} handle provided by {@link #OH_AudioResourceManager_CreateWorkgroup}. 99 * @return 100 * {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds 101 * {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if input param is nullptr 102 * {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} system process error occurs 103 * @since 20 104 */ 105 OH_AudioCommon_Result OH_AudioResourceManager_ReleaseWorkgroup(OH_AudioResourceManager *resourceManager, 106 OH_AudioWorkgroup *group); 107 108 /** 109 * @brief Add current thread into a specified audio workgroup as audio data processing thread. 110 * 111 * @param group {@link #OH_AudioWorkgroup} handle provided by {@link #OH_AudioResourceManager_CreateWorkgroup}. 112 * @param tokenId a token id that represent the thread added. 113 * @return 114 * {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds 115 * {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if input param is nullptr 116 * {@link #AUDIOCOMMON_RESULT_ERROR_NO_MEMORY} out of resources for the new thread 117 * {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} system process error occurs 118 * @since 20 119 */ 120 OH_AudioCommon_Result OH_AudioWorkgroup_AddCurrentThread(OH_AudioWorkgroup *group, int32_t *tokenId); 121 122 /** 123 * @brief Remove the thread from a specified audio workgroup. 124 * 125 * @param group {@link #OH_AudioWorkgroup} handle provided by {@link #OH_AudioResourceManager_CreateWorkgroup}. 126 * @param tokenId id for thread returned by {@link #OH_AudioWorkgroup_AddCurrentThread}. 127 * @return 128 * {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds 129 * {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if input param is nullptr or token id is invalid 130 * {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} system process error occurs 131 * @since 20 132 */ 133 OH_AudioCommon_Result OH_AudioWorkgroup_RemoveThread(OH_AudioWorkgroup *group, int32_t tokenId); 134 135 /** 136 * @brief Notify system the audio workgroup start working. 137 * 138 * @param group {@link #OH_AudioWorkgroup} handle provided by {@link #OH_AudioResourceManager_CreateWorkgroup}. 139 * @param startTime the time when audio thread start working, using system time. 140 * @param deadlineTime the time before which audio work should be finished, otherwise underrun may happens. 141 * @return 142 * {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds 143 * {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if input param is nullptr, or time is invalid 144 * {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} system process error occurs 145 * @since 20 146 */ 147 OH_AudioCommon_Result OH_AudioWorkgroup_Start(OH_AudioWorkgroup *group, uint64_t startTime, uint64_t deadlineTime); 148 149 /** 150 * @brief Notify system the audio workgroup stop working. 151 * 152 * @param group {@link #OH_AudioWorkgroup} handle provided by {@link #OH_AudioResourceManager_CreateWorkgroup}. 153 * @return 154 * {@link #AUDIOCOMMON_RESULT_SUCCESS} if execution succeeds 155 * {@link #AUDIOCOMMON_RESULT_ERROR_INVALID_PARAM} if input param is nullptr 156 * {@link #AUDIOCOMMON_RESULT_ERROR_SYSTEM} system process error occurs 157 * @since 20 158 */ 159 OH_AudioCommon_Result OH_AudioWorkgroup_Stop(OH_AudioWorkgroup *group); 160 161 #ifdef __cplusplus 162 } 163 #endif 164 165 #endif // NATIVE_AUDIO_RESOURCE_MANAGER_H 166 /** @} */