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_render.h 29 * 30 * @brief Declares APIs for audio rendering. 31 * 32 * @since 1.0 33 * @version 1.0 34 */ 35 36 #ifndef AUDIO_RENDER_H 37 #define AUDIO_RENDER_H 38 39 #include "audio_types.h" 40 #include "audio_control.h" 41 #include "audio_attribute.h" 42 #include "audio_scene.h" 43 #include "audio_volume.h" 44 45 /** 46 * @brief Provides capabilities for audio rendering, including controlling the rendering, setting audio attributes, 47 * scenes, and volume, obtaining hardware latency, and rendering audio frames. 48 * 49 * @see AudioControl 50 * @see AudioAttribute 51 * @see AudioScene 52 * @see AudioVolume 53 * @since 1.0 54 * @version 1.0 55 */ 56 struct AudioRender { 57 /** 58 * @brief Defines the audio control. For details, see {@link AudioControl}. 59 */ 60 struct AudioControl control; 61 /** 62 * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. 63 */ 64 struct AudioAttribute attr; 65 /** 66 * @brief Defines the audio scene. For details, see {@link AudioScene}. 67 */ 68 struct AudioScene scene; 69 /** 70 * @brief Defines audio volume. For details, see {@link AudioVolume}. 71 */ 72 struct AudioVolume volume; 73 74 /** 75 * @brief Obtains the estimated latency of the audio device driver. 76 * 77 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 78 * @param ms Indicates the pointer to the latency (in milliseconds) to be obtained. 79 * @return Returns <b>0</b> if the latency is obtained; returns a negative value otherwise. 80 */ 81 int32_t (*GetLatency)(struct AudioRender *render, uint32_t *ms); 82 83 /** 84 * @brief Writes a frame of output data (downlink data) into the audio driver for rendering. 85 * 86 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 87 * @param frame Indicates the pointer to the frame to write. 88 * @param requestBytes Indicates the size of the frame, in bytes. 89 * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to write. 90 * @return Returns <b>0</b> if the data is written successfully; returns a negative value otherwise. 91 */ 92 int32_t (*RenderFrame)(struct AudioRender *render, const void *frame, uint64_t requestBytes, uint64_t *replyBytes); 93 94 /** 95 * @brief Obtains the last number of output audio frames. 96 * 97 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 98 * @param frames Indicates the pointer to the last number of output audio frames. 99 * @param time Indicates the pointer to the timestamp associated with the frame. 100 * @return Returns <b>0</b> if the last number is obtained; returns a negative value otherwise. 101 * @see RenderFrame 102 */ 103 int32_t (*GetRenderPosition)(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time); 104 105 /** 106 * @brief Sets the audio rendering speed. 107 * 108 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 109 * @param speed Indicates the rendering speed to set. 110 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 111 * @see GetRenderSpeed 112 */ 113 int32_t (*SetRenderSpeed)(struct AudioRender *render, float speed); 114 115 /** 116 * @brief Obtains the current audio rendering speed. 117 * 118 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 119 * @param speed Indicates the pointer to the current rendering speed to obtain. 120 * @return Returns <b>0</b> if the speed is successfully obtained; returns a negative value otherwise. 121 * @see SetRenderSpeed 122 */ 123 int32_t (*GetRenderSpeed)(struct AudioRender *render, float *speed); 124 125 /** 126 * @brief Sets the channel mode for audio rendering. 127 * 128 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 129 * @param mode Indicates the channel mode to set. 130 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 131 * @see GetChannelMode 132 */ 133 int32_t (*SetChannelMode)(struct AudioRender *render, enum AudioChannelMode mode); 134 135 /** 136 * @brief Obtains the current channel mode for audio rendering. 137 * 138 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 139 * @param mode Indicates the pointer to the channel mode to obtain. 140 * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise. 141 * @see SetChannelMode 142 */ 143 int32_t (*GetChannelMode)(struct AudioRender *render, enum AudioChannelMode *mode); 144 145 /** 146 * @brief Registers an audio callback that will be invoked during playback when buffer data writing or 147 * buffer drain is complete. 148 * 149 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 150 * @param callback Indicates the callback to register. 151 * @param cookie Indicates the pointer to the callback parameters. 152 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 153 * @see RegCallback 154 */ 155 int32_t (*RegCallback)(struct AudioRender *render, RenderCallback callback, void* cookie); 156 157 /** 158 * @brief Drains the buffer. 159 * 160 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 161 * @param type Indicates the pointer to the execution type of this function. For details, 162 * see {@link AudioDrainNotifyType}. 163 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 164 * @see RegCallback 165 */ 166 int32_t (*DrainBuffer)(struct AudioRender *render, enum AudioDrainNotifyType *type); 167 168 /** 169 * @brief query whether the vendor supports draining buffer 170 * 171 * @param render Indicates the pointer to the <b>AudioRender</b> object to operate. 172 * @param support indicates the state whether the vendor supports draining buffer. Value <b>true</b> means that 173 * the vendor supports, and <b>false</b> means the opposite. 174 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 175 * @see IsSupportsDrain 176 */ 177 int32_t (*IsSupportsDrain)(struct AudioRender *render, bool *support); 178 }; 179 180 #endif /* AUDIO_RENDER_H */ 181 /** @} */ 182