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_adapter.h 29 * 30 * @brief Declares APIs for operations related to the audio adapter. 31 * 32 * @since 1.0 33 * @version 1.0 34 */ 35 36 #ifndef AUDIO_ADAPTER_H 37 #define AUDIO_ADAPTER_H 38 39 #include "audio_types.h" 40 #include "audio_render.h" 41 #include "audio_capture.h" 42 43 /** 44 * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks, 45 * and obtaining the port capability set. 46 * 47 * @see AudioRender 48 * @see AudioCapture 49 * @since 1.0 50 * @version 1.0 51 */ 52 struct AudioAdapter { 53 /** 54 * @brief Initializes all ports of an audio adapter. 55 * 56 * Call this function before calling other driver functions to check whether the initialization is complete. 57 * If the initialization is not complete, wait for a while (for example, 100 ms) and perform the check again 58 * until the port initialization is complete. 59 * 60 * @param adapter Indicates the pointer to the audio adapter to operate. 61 * @return Returns <b>0</b> if the initialization is successful; returns a negative value otherwise. 62 */ 63 int32_t (*InitAllPorts)(struct AudioAdapter *adapter); 64 65 /** 66 * @brief Creates an <b>AudioRender</b> object. 67 * 68 * @param adapter Indicates the pointer to the audio adapter to operate. 69 * @param desc Indicates the pointer to the descriptor of the audio adapter to start. 70 * @param attrs Indicates the pointer to the audio sampling attributes to open. 71 * @param render Indicates the double pointer to the <b>AudioRender</b> object. 72 * @return Returns <b>0</b> if the <b>AudioRender</b> object is created successfully; 73 * returns a negative value otherwise. 74 * @see GetPortCapability 75 * @see DestroyRender 76 */ 77 int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, 78 const struct AudioSampleAttributes *attrs, struct AudioRender **render); 79 80 /** 81 * @brief Destroys an <b>AudioRender</b> object. 82 * 83 * @attention Do not destroy the object during audio rendering. 84 * 85 * @param adapter Indicates the pointer to the audio adapter to operate. 86 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 87 * @return Returns <b>0</b> if the <b>AudioRender</b> object is destroyed; returns a negative value otherwise. 88 * @see CreateRender 89 */ 90 int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render); 91 92 /** 93 * @brief Creates an <b>AudioCapture</b> object. 94 * 95 * @param adapter Indicates the pointer to the audio adapter to operate. 96 * @param desc Indicates the pointer to the descriptor of the audio adapter to start. 97 * @param attrs Indicates the pointer to the audio sampling attributes to open. 98 * @param capture Indicates the double pointer to the <b>AudioCapture</b> object. 99 * @return Returns <b>0</b> if the <b>AudioCapture</b> object is created successfully; 100 * returns a negative value otherwise. 101 * @see GetPortCapability 102 * @see DestroyCapture 103 */ 104 int32_t (*CreateCapture)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, 105 const struct AudioSampleAttributes *attrs, struct AudioCapture **capture); 106 107 /** 108 * @brief Destroys an <b>AudioCapture</b> object. 109 * 110 * @attention Do not destroy the object during audio capturing. 111 * 112 * @param adapter Indicates the pointer to the audio adapter to operate. 113 * @param capture Indicates the pointer to the <b>AudioCapture</b> object to operate. 114 * @return Returns <b>0</b> if the <b>AudioCapture</b> object is destroyed; returns a negative value otherwise. 115 * @see CreateCapture 116 */ 117 int32_t (*DestroyCapture)(struct AudioAdapter *adapter, struct AudioCapture *capture); 118 119 /** 120 * @brief Obtains the capability set of the port driver for the audio adapter. 121 * 122 * @param adapter Indicates the pointer to the audio adapter to operate. 123 * @param port Indicates the pointer to the port. 124 * @param capability Indicates the pointer to the capability set to obtain. 125 * @return Returns <b>0</b> if the capability set is successfully obtained; returns a negative value otherwise. 126 */ 127 int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port, 128 struct AudioPortCapability *capability); 129 130 /** 131 * @brief Sets the passthrough data transmission mode of the audio port driver. 132 * 133 * @param adapter Indicates the pointer to the audio adapter to operate. 134 * @param port Indicates the pointer to the port. 135 * @param mode Indicates the passthrough transmission mode to set. 136 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 137 * @see GetPassthroughMode 138 */ 139 int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, 140 enum AudioPortPassthroughMode mode); 141 142 /** 143 * @brief Obtains the passthrough data transmission mode of the audio port driver. 144 * 145 * @param adapter Indicates the pointer to the audio adapter to operate. 146 * @param port Indicates the pointer to the port. 147 * @param mode Indicates the pointer to the passthrough transmission mode to obtain. 148 * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise. 149 * @see SetPassthroughMode 150 */ 151 int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, 152 enum AudioPortPassthroughMode *mode); 153 154 /** 155 * @brief Update audio route on several source and sink ports. 156 * 157 * @param adapter Indicates the pointer to the audio adapter to operate. 158 * @param route Indicates route information. 159 * @param routeHandle Indicates route handle. 160 * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise. 161 * @see SetPassthroughMode 162 */ 163 int32_t (*UpdateAudioRoute)(struct AudioAdapter *adapter, const struct AudioRoute *route, int32_t *routeHandle); 164 165 /** 166 * @brief Release an audio route. 167 * 168 * @param adapter Indicates the pointer to the audio adapter to operate. 169 * @param routeHandle Indicates route handle. 170 * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise. 171 * @see SetPassthroughMode 172 */ 173 int32_t (*ReleaseAudioRoute)(struct AudioAdapter *adapter, int32_t routeHandle); 174 175 /** 176 * @brief Sets the mute operation for the audio. 177 * 178 * @param adapter Indicates the pointer to the audio adapter to operate. 179 * @param mute Specifies whether to mute the audio. Value <b>true</b> means to mute the audio, 180 * and <b>false</b> means the opposite. 181 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 182 * @see GetMute 183 */ 184 int32_t (*SetMicMute)(struct AudioAdapter *adapter, bool mute); 185 186 /** 187 * @brief Obtains the mute operation set for the audio. 188 * 189 * @param adapter Indicates the pointer to the audio adapter to operate. 190 * @param mute Indicates the pointer to the mute operation set for the audio. Value <b>true</b> means that 191 * the audio is muted, and <b>false</b> means the opposite. 192 * @return Returns <b>0</b> if the mute operation is obtained; returns a negative value otherwise. 193 * @see SetMute 194 */ 195 int32_t (*GetMicMute)(struct AudioAdapter *adapter, bool *mute); 196 197 /** 198 * @brief Sets the audio volume for voice call. 199 * 200 * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, 201 * <b>0.0</b> indicates that the audio is muted, and <b>1.0</b> indicates the maximum volume level (15). 202 * 203 * @param adapter Indicates the pointer to the audio adapter to operate. 204 * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. 205 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 206 * @see GetVolume 207 */ 208 int32_t (*SetVoiceVolume)(struct AudioAdapter *adapter, float volume); 209 210 /** 211 * @brief Sets extra audio parameters. 212 * 213 * @param adapter Indicates the audio adapter. 214 * @param key Indicates what kind of parameter type will be set. 215 * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. 216 * @param value Indicates the value of the specified condition. 217 * 218 * The format of condition is <i>key=value</i>. Separate multiple key-value pairs by semicolons (;). 219 * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: 220 * <i>"EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;"</i> 221 * EVENT_TYPE indicates sub volume event type: SetVolume = 1; SetMute = 4; 222 * VOLUME_GROUP_ID indicates which volume group will be set; 223 * AUDIO_VOLUME_TYPE indicates which volume type will be set; 224 * 225 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 226 */ 227 int32_t (*SetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, 228 const char *condition, const char *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 int32_t (*GetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, 249 const char *condition, char *value, int32_t lenth); 250 251 /** 252 * @brief Register extra audio parameters observer. 253 * 254 * @param adapter Indicates the audio adapter. 255 * @param callback Indicates param observer. 256 * @param cookie Indicates the pointer to the callback parameters; 257 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 258 */ 259 int32_t (*RegExtraParamObserver)(struct AudioAdapter *adapter, ParamCallback callback, void* cookie); 260 /** 261 * @brief Get the device status of an adapter. 262 * 263 * @param adapter Indicates the audio adapter. 264 * @param status Indicates the status of device . 265 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 266 */ 267 int32_t (*GetDeviceStatus)(struct AudioAdapter *adapter, struct AudioDeviceStatus *status); 268 }; 269 #endif /* AUDIO_ADAPTER_H */ 270 /** @} */ 271