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 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 10 25 * @version 1.0 26 */ 27 28 /** 29 * @file native_audiocapturer.h 30 * 31 * @brief Declare audio stream related interfaces for input type. 32 * 33 * @syscap SystemCapability.Multimedia.Audio.Core 34 * @since 10 35 * @version 1.0 36 */ 37 38 #ifndef NATIVE_AUDIOCAPTURER_H 39 #define NATIVE_AUDIOCAPTURER_H 40 41 #include <time.h> 42 #include "native_audiostream_base.h" 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 /* 47 * Request to release the capturer stream. 48 * 49 * @since 10 50 * @permission ohos.permission.MICROPHONE 51 * 52 * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer() 53 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 54 */ 55 OH_AudioStream_Result OH_AudioCapturer_Release(OH_AudioCapturer* capturer); 56 57 /* 58 * Request to start the capturer stream. 59 * 60 * @since 10 61 * @permission ohos.permission.MICROPHONE 62 * 63 * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer() 64 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 65 */ 66 OH_AudioStream_Result OH_AudioCapturer_Start(OH_AudioCapturer* capturer); 67 68 /* 69 * Request to pause the capturer stream. 70 * 71 * @since 10 72 * @permission ohos.permission.MICROPHONE 73 * 74 * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer() 75 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 76 */ 77 OH_AudioStream_Result OH_AudioCapturer_Pause(OH_AudioCapturer* capturer); 78 79 /* 80 * Request to stop the capturer stream. 81 * 82 * @since 10 83 * @permission ohos.permission.MICROPHONE 84 * 85 * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer() 86 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 87 */ 88 OH_AudioStream_Result OH_AudioCapturer_Stop(OH_AudioCapturer* capturer); 89 90 /* 91 * Request to flush the capturer stream. 92 * 93 * @since 10 94 * 95 * @param capturer reference created by OH_AudioStreamBuilder_GenerateCapturer() 96 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 97 */ 98 OH_AudioStream_Result OH_AudioCapturer_Flush(OH_AudioCapturer* capturer); 99 100 /* 101 * Query the current state of the capturer client. 102 * 103 * This function will return the capturer state without updating the state. 104 * 105 * @since 10 106 * 107 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 108 * @param state Pointer to a variable that will be set for the state value. 109 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 110 */ 111 OH_AudioStream_Result OH_AudioCapturer_GetCurrentState(OH_AudioCapturer* capturer, OH_AudioStream_State* state); 112 113 /* 114 * Query the latency mode of the capturer client. 115 * 116 * @since 10 117 * 118 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 119 * @param latencyMode Pointer to a variable that will be set for the latency mode. 120 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 121 */ 122 OH_AudioStream_Result OH_AudioCapturer_GetLatencyMode(OH_AudioCapturer* capturer, 123 OH_AudioStream_LatencyMode* latencyMode); 124 125 /* 126 * Query the stream id of the capturer client. 127 * 128 * @since 10 129 * 130 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 131 * @param stramId Pointer to a variable that will be set for the stream id. 132 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 133 */ 134 OH_AudioStream_Result OH_AudioCapturer_GetStreamId(OH_AudioCapturer* capturer, uint32_t* streamId); 135 136 /* 137 * Query the sample rate value of the capturer client. 138 * 139 * This function will return the capturer sample rate value without updating the state. 140 * 141 * @since 10 142 * 143 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 144 * @param rate The state value to be updated 145 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 146 */ 147 OH_AudioStream_Result OH_AudioCapturer_GetSamplingRate(OH_AudioCapturer* capturer, int32_t* rate); 148 149 /* 150 * Query the channel count of the capturer client. 151 * 152 * @since 10 153 * 154 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 155 * @param channelCount Pointer to a variable that will be set for the channel count. 156 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 157 */ 158 OH_AudioStream_Result OH_AudioCapturer_GetChannelCount(OH_AudioCapturer* capturer, int32_t* channelCount); 159 160 /* 161 * Query the sample format of the capturer client. 162 * 163 * @since 10 164 * 165 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 166 * @param sampleFormat Pointer to a variable that will be set for the sample format. 167 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 168 */ 169 OH_AudioStream_Result OH_AudioCapturer_GetSampleFormat(OH_AudioCapturer* capturer, 170 OH_AudioStream_SampleFormat* sampleFormat); 171 172 /* 173 * Query the encoding type of the capturer client. 174 * 175 * @since 10 176 * 177 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 178 * @param encodingType Pointer to a variable that will be set for the encoding type. 179 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 180 */ 181 OH_AudioStream_Result OH_AudioCapturer_GetEncodingType(OH_AudioCapturer* capturer, 182 OH_AudioStream_EncodingType* encodingType); 183 184 /* 185 * Query the capturer info of the capturer client. 186 * 187 * @since 10 188 * 189 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 190 * @param sourceType Pointer to a variable that will be set for the stream sourceType. 191 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 192 */ 193 OH_AudioStream_Result OH_AudioCapturer_GetCapturerInfo(OH_AudioCapturer* capturer, 194 OH_AudioStream_SourceType* sourceType); 195 196 /* 197 * Query the frame size in callback, it is a fixed length of the buffer returned by each callback. 198 * 199 * @since 10 200 * 201 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 202 * @param frameSize Pointer to a variable that will be set for the frame size. 203 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 204 */ 205 OH_AudioStream_Result OH_AudioCapturer_GetFrameSizeInCallback(OH_AudioCapturer* capturer, int32_t* frameSize); 206 207 /* 208 * Query the the time at which a particular frame was presented 209 * 210 * @since 10 211 * 212 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 213 * @param clockId {@link #CLOCK_MONOTONIC} 214 * @param framePosition Pointer to a variable to receive the position 215 * @param timestamp Pointer to a variable to receive the timestamp 216 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 217 */ 218 OH_AudioStream_Result OH_AudioCapturer_GetTimestamp(OH_AudioCapturer* capturer, 219 clockid_t clockId, int64_t* framePosition, int64_t* timestamp); 220 221 /* 222 * Query the the number of frames that have been read since the stream was created. 223 * 224 * @since 10 225 * 226 * @param capturer Reference created by OH_AudioStreamBuilder_GenerateCapturer() 227 * @param frames Pointer to a variable that will be set for the frame count number. 228 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 229 */ 230 OH_AudioStream_Result OH_AudioCapturer_GetFramesRead(OH_AudioCapturer* capturer, int64_t* frames); 231 232 /** 233 * @brief Gets the overflow count on this stream. 234 * 235 * @since 12 236 * 237 * @param capturer Capturer generated by OH_AudioStreamBuilder_GenerateCapturer() 238 * @param count Pointer to a variable that will be set for the overflow count number. 239 * @return {@link #AUDIOSTREAM_SUCCESS} or an undesired error. 240 */ 241 OH_AudioStream_Result OH_AudioCapturer_GetOverflowCount(OH_AudioCapturer* capturer, uint32_t* count); 242 243 #ifdef __cplusplus 244 } 245 #endif 246 #endif // NATIVE_AUDIOCAPTURER_H 247