1/* 2 * Copyright (c) 2023 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 HdiAudio 18 * @{ 19 * 20 * @brief Provides unified APIs for audio services to access audio drivers. 21 * 22 * An audio service can obtain an audio driver object or agent and then call APIs provided by this object or agent to 23 * access different types of audio devices based on the audio IDs, thereby obtaining audio information, 24 * subscribing to or unsubscribing from audio data, enabling or disabling an audio, 25 * setting the audio data reporting mode, and setting audio options such as the accuracy and measurement range. 26 * 27 * @since 4.1 28 * @version 2.0 29 */ 30 31package ohos.hdi.audio.v2_0; 32 33import ohos.hdi.audio.v2_0.AudioTypes; 34import ohos.hdi.audio.v2_0.IAudioRender; 35import ohos.hdi.audio.v2_0.IAudioCapture; 36import ohos.hdi.audio.v2_0.IAudioCallback; 37 38/** 39 * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks, 40 * and obtaining the port capability set. 41 * 42 * @see IAudioRender 43 * @see IAudioCapture 44 * @since 4.1 45 * @version 2.0 46 */ 47interface IAudioAdapter { 48 /** 49 * @brief Initializes all ports of an audio adapter. 50 * 51 * Call this function before calling other driver functions to check whether the initialization is complete. 52 * If the initialization is not complete, wait for a while (for example, 100 ms) and perform the check again 53 * until the port initialization is complete. 54 * 55 * @param adapter Indicates the pointer to the audio adapter to operate. 56 * @return Returns <b>0</b> if the initialization is successful; returns a negative value otherwise. 57 */ 58 InitAllPorts(); 59 60 /** 61 * @brief Creates an <b>IAudioRender</b> object. 62 * 63 * @param adapter Indicates the pointer to the audio adapter to operate. 64 * @param desc Indicates the pointer to the descriptor of the audio adapter to start. 65 * @param attrs Indicates the pointer to the audio sampling attributes to open. 66 * @param render Indicates the double pointer to the <b>IAudioRender</b> object. 67 * @return Returns <b>0</b> if the <b>IAudioRender</b> object is created successfully; 68 * returns a negative value otherwise. 69 * @see GetPortCapability 70 * @see DestroyRender 71 */ 72 CreateRender([in] struct AudioDeviceDescriptor desc, [in] struct AudioSampleAttributes attrs, 73 [out] IAudioRender render, [out] unsigned int renderId); 74 75 /** 76 * @brief Destroys an <b>IAudioRender</b> object. 77 * 78 * @attention Do not destroy the object during audio rendering. 79 * 80 * @param adapter Indicates the pointer to the audio adapter to operate. 81 * @param render Indicates the pointer to the <b>IAudioRender</b> object to operate. 82 * @return Returns <b>0</b> if the <b>IAudioRender</b> object is destroyed; returns a negative value otherwise. 83 * @see CreateRender 84 */ 85 DestroyRender([in] unsigned int renderId); 86 87 /** 88 * @brief Creates an <b>IAudioCapture</b> object. 89 * 90 * @param adapter Indicates the pointer to the audio adapter to operate. 91 * @param desc Indicates the pointer to the descriptor of the audio adapter to start. 92 * @param attrs Indicates the pointer to the audio sampling attributes to open. 93 * @param capture Indicates the double pointer to the <b>IAudioCapture</b> object. 94 * @return Returns <b>0</b> if the <b>IAudioCapture</b> object is created successfully; 95 * returns a negative value otherwise. 96 * @see GetPortCapability 97 * @see DestroyCapture 98 */ 99 CreateCapture([in] struct AudioDeviceDescriptor desc, [in] struct AudioSampleAttributes attrs, 100 [out] IAudioCapture capture, [out] unsigned int captureId); 101 102 /** 103 * @brief Destroys an <b>IAudioCapture</b> object. 104 * 105 * @attention Do not destroy the object during audio capturing. 106 * 107 * @param adapter Indicates the pointer to the audio adapter to operate. 108 * @param capture Indicates the pointer to the <b>IAudioCapture</b> object to operate. 109 * @return Returns <b>0</b> if the <b>IAudioCapture</b> object is destroyed; returns a negative value otherwise. 110 * @see CreateCapture 111 */ 112 DestroyCapture([in] unsigned int captureId); 113 114 /** 115 * @brief Obtains the capability set of the port driver for the audio adapter. 116 * 117 * @param adapter Indicates the pointer to the audio adapter to operate. 118 * @param port Indicates the pointer to the port. 119 * @param capability Indicates the pointer to the capability set to obtain. 120 * @return Returns <b>0</b> if the capability set is successfully obtained; returns a negative value otherwise. 121 */ 122 GetPortCapability([in] struct AudioPort port, [out] struct AudioPortCapability capability); 123 124 /** 125 * @brief Sets the passthrough data transmission mode of the audio port driver. 126 * 127 * @param adapter Indicates the pointer to the audio adapter to operate. 128 * @param port Indicates the pointer to the port. 129 * @param mode Indicates the passthrough transmission mode to set. 130 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 131 * @see GetPassthroughMode 132 */ 133 SetPassthroughMode([in] struct AudioPort port, [in] enum AudioPortPassthroughMode mode); 134 135 /** 136 * @brief Obtains the passthrough data transmission mode of the audio port driver. 137 * 138 * @param adapter Indicates the pointer to the audio adapter to operate. 139 * @param port Indicates the pointer to the port. 140 * @param mode Indicates the pointer to the passthrough transmission mode to obtain. 141 * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise. 142 * @see SetPassthroughMode 143 */ 144 GetPassthroughMode([in] struct AudioPort port, [out] enum AudioPortPassthroughMode mode); 145 146 /** 147 * @brief Get the device status of an adapter. 148 * 149 * @param adapter Indicates the audio adapter. 150 * @param status Indicates the status of device . 151 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 152 */ 153 GetDeviceStatus([out] struct AudioDeviceStatus status); 154 155 /** 156 * @brief Update audio route on several source and sink ports. 157 * 158 * @param adapter Indicates the pointer to the audio adapter to operate. 159 * @param route Indicates route information. 160 * @param routeHandle Indicates route handle. 161 * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise. 162 * @see SetPassthroughMode 163 */ 164 UpdateAudioRoute([in] struct AudioRoute route, [out] int routeHandle); 165 166 /** 167 * @brief Release an audio route. 168 * 169 * @param adapter Indicates the pointer to the audio adapter to operate. 170 * @param routeHandle Indicates route handle. 171 * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise. 172 * @see SetPassthroughMode 173 */ 174 ReleaseAudioRoute([in] int routeHandle); 175 176 /** 177 * @brief Sets the mute operation for the audio. 178 * 179 * @param adapter Indicates the pointer to the audio adapter to operate. 180 * @param mute Specifies whether to mute the audio. Value <b>true</b> means to mute the audio, 181 * and <b>false</b> means the opposite. 182 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 183 * @see GetMute 184 */ 185 SetMicMute([in] boolean mute); 186 187 /** 188 * @brief Obtains the mute operation set for the audio. 189 * 190 * @param adapter Indicates the pointer to the audio adapter to operate. 191 * @param mute Indicates the pointer to the mute operation set for the audio. Value <b>true</b> means that 192 * the audio is muted, and <b>false</b> means the opposite. 193 * @return Returns <b>0</b> if the mute operation is obtained; returns a negative value otherwise. 194 * @see SetMute 195 */ 196 GetMicMute([out] boolean mute); 197 198 /** 199 * @brief Sets the audio volume for voice call. 200 * 201 * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, 202 * <b>0.0</b> indicates that the audio is muted, and <b>1.0</b> indicates the maximum volume level (15). 203 * 204 * @param adapter Indicates the pointer to the audio adapter to operate. 205 * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. 206 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 207 * @see GetVolume 208 */ 209 SetVoiceVolume([in] float volume); 210 211 /** 212 * @brief Sets extra audio parameters. 213 * 214 * @param adapter Indicates the audio adapter. 215 * @param key Indicates what kind of parameter type will be set. 216 * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. 217 * @param value Indicates the value of the specified condition. 218 * 219 * The format of condition is <i>key=value</i>. Separate multiple key-value pairs by semicolons (;). 220 * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: 221 * <i>"EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;"</i> 222 * EVENT_TYPE indicates sub volume event type: SetVolume = 1; SetMute = 4; 223 * VOLUME_GROUP_ID indicates which volume group will be set; 224 * AUDIO_VOLUME_TYPE indicates which volume type will be set; 225 * 226 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 227 */ 228 SetExtraParams([in] enum AudioExtParamKey key, [in] String condition, [in] String value); 229 230 /** 231 * @brief Get extra audio parameters. 232 * 233 * @param adapter Indicates the audio adapter. 234 * @param key Indicates what kind of parameter type will be get. 235 * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. 236 * @param value Indicates the value of the specified condition. 237 * @param lenth Indicates the length of the value pointer. 238 * 239 * The format of condition is <i>key=value</i>. Separate multiple key-value pairs by semicolons (;). 240 * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: 241 * <i>"EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;"</i> 242 * EVENT_TYPE indicates sub volume event type: GetVolume = 1; GetMinVolume = 2; GetMaxVolume = 3; IsStreamMute = 4; 243 * VOLUME_GROUP_ID indicates which volume group want get; 244 * AUDIO_VOLUME_TYPE indicates which volume type want get; 245 * 246 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 247 */ 248 GetExtraParams([in] enum AudioExtParamKey key, [in] String condition, [out] String value); 249 250 /** 251 * @brief Register extra audio parameters observer. 252 * 253 * @param adapter Indicates the audio adapter. 254 * @param callback Indicates param observer. 255 * @param cookie Indicates the pointer to the callback parameters; 256 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 257 */ 258 RegExtraParamObserver([in] IAudioCallback audioCallback, [in] byte cookie); 259} 260/** @} */