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_audiostreambuilder.h 30 * 31 * @brief Declare audio stream builder related interfaces. 32 * 33 * @library libohaudio.so 34 * @syscap SystemCapability.Multimedia.Audio.Core 35 * @kit AudioKit 36 * @since 10 37 * @version 1.0 38 */ 39 40 #ifndef NATIVE_AUDIOSTREAM_BUILDER_H 41 #define NATIVE_AUDIOSTREAM_BUILDER_H 42 43 #include "native_audiostream_base.h" 44 #include "native_audiorenderer.h" 45 #include "native_audiocapturer.h" 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /** 51 * Create a stremBuilder can be used to open a renderer or capturer client. 52 * 53 * OH_AudioStreamBuilder_Destroy() must be called when you are done using the builder. 54 * 55 * @since 10 56 * 57 * @param builder The builder reference to the created result. 58 * @param type The stream type to be created. {@link #AUDIOSTREAM_TYPE_RENDERER} or {@link #AUDIOSTREAM_TYPE_CAPTURER} 59 * @return Function result code: 60 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 61 */ 62 OH_AudioStream_Result OH_AudioStreamBuilder_Create(OH_AudioStreamBuilder** builder, OH_AudioStream_Type type); 63 64 /** 65 * Destroy a streamBulder. 66 * 67 * This function must be called when you are done using the builder. 68 * 69 * @since 10 70 * 71 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 72 * @return Function result code: 73 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 74 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of builder is nullptr. 75 * {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE} Execution status exception. 76 */ 77 OH_AudioStream_Result OH_AudioStreamBuilder_Destroy(OH_AudioStreamBuilder* builder); 78 79 /** 80 * Set the channel count of the capturer client 81 * 82 * @since 10 83 * 84 * @param builder Reference created by OH_AudioStreamBuilder 85 * @param rate Pointer to a variable that will be set for the channel count. 86 * @return Function result code: 87 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 88 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 89 * 1.The param of builder is nullptr; 90 * 2.The param of rate invalid. 91 */ 92 OH_AudioStream_Result OH_AudioStreamBuilder_SetSamplingRate(OH_AudioStreamBuilder* builder, int32_t rate); 93 94 /** 95 * Set the channel count of the stream client 96 * 97 * @since 10 98 * 99 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 100 * @param channelCount The channel count. 101 * @return Function result code: 102 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 103 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 104 * 1.The param of builder is nullptr; 105 * 2.The param of channelCount invalid. 106 */ 107 OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelCount(OH_AudioStreamBuilder* builder, int32_t channelCount); 108 109 /** 110 * Set the sample format of the stream client 111 * 112 * @since 10 113 * 114 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 115 * @param format Sample data format. 116 * @return Function result code: 117 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 118 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of builder is nullptr. 119 */ 120 OH_AudioStream_Result OH_AudioStreamBuilder_SetSampleFormat(OH_AudioStreamBuilder* builder, 121 OH_AudioStream_SampleFormat format); 122 123 /** 124 * Set the encoding type of the stream client 125 * 126 * @since 10 127 * 128 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 129 * @param encodingType Encoding type for the stream client, {@link #AUDIOSTREAM_ENCODING_PCM} 130 * @return Function result code: 131 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 132 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of builder is nullptr. 133 */ 134 OH_AudioStream_Result OH_AudioStreamBuilder_SetEncodingType(OH_AudioStreamBuilder* builder, 135 OH_AudioStream_EncodingType encodingType); 136 137 /** 138 * Set the latency mode of the stream client 139 * 140 * @since 10 141 * 142 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 143 * @param latencyMode Latency mode for the stream client. 144 * @return Function result code: 145 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 146 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of builder is nullptr. 147 */ 148 OH_AudioStream_Result OH_AudioStreamBuilder_SetLatencyMode(OH_AudioStreamBuilder* builder, 149 OH_AudioStream_LatencyMode latencyMode); 150 151 /** 152 * @brief Set the channel layout to the stream client 153 * 154 * @since 12 155 * 156 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 157 * @param channelLayout is the layout of the speaker. 158 * @return Function result code: 159 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 160 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of builder is nullptr. 161 */ 162 OH_AudioStream_Result OH_AudioStreamBuilder_SetChannelLayout(OH_AudioStreamBuilder* builder, 163 OH_AudioChannelLayout channelLayout); 164 165 /** 166 * Set the renderer information of the stream client 167 * 168 * @since 10 169 * 170 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 171 * @param usage Set the stream usage for the renderer client. 172 * @return Function result code: 173 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 174 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 175 * 1.The param of builder is nullptr; 176 * 2.The param of usage invalid. 177 */ 178 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInfo(OH_AudioStreamBuilder* builder, 179 OH_AudioStream_Usage usage); 180 181 /** 182 * Set the capturer information of the stream client 183 * 184 * @since 10 185 * 186 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 187 * @param sourceType Set the source type for the capturer client. 188 * @return Function result code: 189 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 190 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 191 * 1.The param of builder is nullptr; 192 * 2.The param of sourceType invalid. 193 */ 194 OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInfo(OH_AudioStreamBuilder* builder, 195 OH_AudioStream_SourceType sourceType); 196 197 /** 198 * Set the callbacks for the renderer client 199 * 200 * @deprecated since 20 201 * @useinstead Set the callback functions separately using OH_AudioStreamBuilder_SetRendererWriteDataCallback, 202 * OH_AudioStreamBuilder_SetRendererInterruptCallback, OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback 203 * and OH_AudioStreamBuilder_SetRendererErrorCallback. 204 * @since 10 205 * 206 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 207 * @param callbacks Callbacks to the functions that will process renderer stream. 208 * @param userData Pointer to an application data structure that will be passed to the callback functions. 209 * @return Function result code: 210 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 211 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 212 * 1.The param of builder is nullptr; 213 * 2.StreamType invalid. 214 */ 215 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererCallback(OH_AudioStreamBuilder* builder, 216 OH_AudioRenderer_Callbacks callbacks, void* userData); 217 218 /** 219 * @brief Set the callback when the output device of an audio renderer changed. 220 * 221 * @since 11 222 * 223 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 224 * @param callback Callback to the function that will process this device change event. 225 * @param userData Pointer to an application data structure that will be passed to the callback functions. 226 * @return Function result code: 227 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 228 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 229 * 1.The param of builder is nullptr; 230 * 2.StreamType invalid. 231 */ 232 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererOutputDeviceChangeCallback(OH_AudioStreamBuilder* builder, 233 OH_AudioRenderer_OutputDeviceChangeCallback callback, void* userData); 234 235 /** 236 * @brief Set the privacy of audio render. 237 * 238 * @since 12 239 * 240 * @param builder Builder provided by OH_AudioStreamBuilder_Create() 241 * @param privacy Privacy type. 242 * @return Function result code: 243 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 244 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 245 * 1.The param of builder is nullptr; 246 * 2.StreamType invalid. 247 */ 248 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererPrivacy(OH_AudioStreamBuilder* builder, 249 OH_AudioStream_PrivacyType privacy); 250 251 /** 252 * Set the callbacks for the capturer client 253 * 254 * @deprecated since 20 255 * @useinstead Set the callback functions separately using OH_AudioStreamBuilder_SetCapturerReadDataCallback, 256 * OH_AudioStreamBuilder_SetCapturerDeviceChangeCallback, OH_AudioStreamBuilder_SetCapturerInterruptCallback 257 * and OH_AudioStreamBuilder_SetCapturerErrorCallback. 258 * @since 10 259 * 260 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 261 * @param callbacks Callbacks to the functions that will process capturer stream. 262 * @param userData Pointer to an application data structure that will be passed to the callback functions. 263 * @return Function result code: 264 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 265 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 266 * 1.The param of builder is nullptr; 267 * 2.StreamType invalid. 268 */ 269 OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerCallback(OH_AudioStreamBuilder* builder, 270 OH_AudioCapturer_Callbacks callbacks, void* userData); 271 272 /** 273 * Create the audio renderer client. 274 * 275 * The AudioRenderer instance is used to play streaming audio data. 276 * When using AudioRenderer apis, there are many instructions for application 277 * to achieve better performance and lower power consumption: 278 * In music or audiobook background playback situation, you can have low power 279 * consumption by following this best practices document **Low-Power Rules in Music Playback Scenarios**. 280 * And for navigation situation, you can follow **Low-Power Rules in Navigation and Positioning Scenarios**. 281 * 282 * Application developer should also be careful when app goes to background, please check if your audio playback 283 * is still needed, see **Audio Resources** in best practices document. 284 * And avoiding to send silence audio data continuously to waste system resources, otherwise system will take 285 * control measures when this behavior is detected, see **Audio Playback** in best practices document. 286 * 287 * If you want to use AudioRenderer api to implement a music playback application, there are also many interactive 288 * scenes to consider, see **Developing an Audio Application** in best practices document. 289 * 290 * @since 10 291 * 292 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 293 * @param audioRenderer Pointer to a viriable to receive the stream client. 294 * @return Function result code: 295 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 296 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 297 * 1.The param of builder is nullptr; 298 * 2.StreamType invalid; 299 * 3.Create OHAudioRenderer failed. 300 */ 301 OH_AudioStream_Result OH_AudioStreamBuilder_GenerateRenderer(OH_AudioStreamBuilder* builder, 302 OH_AudioRenderer** audioRenderer); 303 304 /** 305 * Create the audio capturer client. 306 * 307 * @since 10 308 * 309 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 310 * @param audioCapturer Pointer to a viriable to receive the stream client. 311 * @return Function result code: 312 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 313 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 314 * 1.The param of builder is nullptr; 315 * 2.StreamType invalid; 316 * 3.Create OHAudioCapturer failed. 317 */ 318 OH_AudioStream_Result OH_AudioStreamBuilder_GenerateCapturer(OH_AudioStreamBuilder* builder, 319 OH_AudioCapturer** audioCapturer); 320 321 /** 322 * Set the data frame size for each callback, use this function if the application requires a specific number 323 * of frames for processing. 324 * The frame size should be at least the size device process at one time, and less than half the internal 325 * buffer capacity. 326 * 327 * @since 11 328 * 329 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 330 * @param frameSize The data frame size for each callback. 331 * @return Function result code: 332 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 333 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} The param of builder is nullptr. 334 */ 335 OH_AudioStream_Result OH_AudioStreamBuilder_SetFrameSizeInCallback(OH_AudioStreamBuilder* builder, 336 int32_t frameSize); 337 338 /** 339 * @brief Set the callback of writing metadata to the renderer client 340 * 341 * @since 12 342 * 343 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 344 * @param callback Callback to the functions that will write audio data with metadata to the renderer. 345 * @param userData Pointer to an application data structure that will be passed to the callback functions. 346 * @return Function result code: 347 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 348 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 349 * 1.The param of builder is nullptr; 350 * 2.StreamType invalid. 351 */ 352 OH_AudioStream_Result OH_AudioStreamBuilder_SetWriteDataWithMetadataCallback(OH_AudioStreamBuilder* builder, 353 OH_AudioRenderer_WriteDataWithMetadataCallback callback, void* userData); 354 355 /** 356 * @brief Set the interrupt mode of the stream client 357 * 358 * @since 12 359 * 360 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 361 * @param mode The audio interrupt mode 362 * @return Function result code: 363 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 364 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 365 * 1.The param of builder is nullptr; 366 * 2.The param of mode invalid; 367 * 3.StreamType invalid. 368 */ 369 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptMode(OH_AudioStreamBuilder* builder, 370 OH_AudioInterrupt_Mode mode); 371 372 /** 373 * @brief Set the callback of writing data to renderer client. 374 * 375 * This function is similar with {@link OH_AudioStreamBuilder_SetRendererCallback}. Only the last callback set by 376 * OH_AudioStreamBuilder_SetRendererCallback or this function will become effective. 377 * 378 * @param builder Builder provided by OH_AudioStreamBuilder_Create() 379 * @param callback Callback to functions that will write audio data to renderer client. 380 * @param userData Pointer to an application data structure that will be passed to the callback functions. 381 * @return Result code. 382 * {@link AUDIOSTREAM_SUCCESS} Success. 383 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} Parameter is invalid, e.g. builder is nullptr, e.t.c. 384 * @since 12 385 */ 386 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallback(OH_AudioStreamBuilder* builder, 387 OH_AudioRenderer_OnWriteDataCallback callback, void* userData); 388 389 /** 390 * @brief Set the callback of writing data to renderer client. 391 * 392 * This function is similar with {@link OH_AudioStreamBuilder_SetRendererWriteDataCallback}. Only the last callback set 393 * by OH_AudioStreamBuilder_SetRendererWriteDataCallback or this function will become effective. Different with 394 * OH_AudioStreamBuilder_SetRendererWriteDataCallback, the callback in this function can return audio data of any 395 * length. 396 * 397 * @param builder Builder provided by OH_AudioStreamBuilder_Create() 398 * @param callback Callback to functions that will write audio data to renderer client. 399 * @param userData Pointer to an application data structure that will be passed to the callback functions. 400 * @return Result code. 401 * {@link AUDIOSTREAM_SUCCESS} Success. 402 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} Parameter is invalid, e.g. builder is nullptr, e.t.c. 403 * @since 20 404 */ 405 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallbackAdvanced(OH_AudioStreamBuilder* builder, 406 OH_AudioRenderer_OnWriteDataCallbackAdvanced callback, void* userData); 407 408 /** 409 * Set the renderer volume mode of the stream client 410 * 411 * @param builder Reference provided by OH_AudioStreamBuilder_Create() 412 * @param volumeMode Set the volume mode for the renderer client. 413 * @return Function result code: 414 * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. 415 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: 416 * 1.The param of builder is nullptr; 417 * 2.The param of volumeMode invalid. 418 * @since 19 419 */ 420 OH_AudioStream_Result OH_AudioStreamBuilder_SetVolumeMode(OH_AudioStreamBuilder* builder, 421 OH_AudioStream_VolumeMode volumeMode); 422 423 /** 424 * @brief Sets a callback to handle interrupt events for an AudioRenderer instance. This function is similar to 425 * {@link OH_AudioStreamBuilder_SetRendererCallback}. If both OH_AudioStreamBuilder_SetRendererCallback and this 426 * function are called, the most recently set callback takes effect. 427 * 428 * @param builder Builder instance, which is generated by OH_AudioStreamBuilder_Create(). 429 * @param callback Callback used to handle the interrupt events. 430 * @param userData Pointer to user-defined data, which will be passed back to the application in the callback. 431 * @return Result code. 432 * {@link AUDIOSTREAM_SUCCESS} is returned if the operation is successful. 433 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} is returned if a parameter is invalid, for example, if builder 434 * is nullptr. 435 * @since 20 436 */ 437 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptCallback(OH_AudioStreamBuilder* builder, 438 OH_AudioRenderer_OnInterruptCallback callback, void* userData); 439 440 /** 441 * @brief Sets a callback to handle error events for an AudioRenderer instance. 442 * This function is similar to {@link OH_AudioStreamBuilder_SetRendererCallback}. If both 443 * OH_AudioStreamBuilder_SetRendererCallback and this function are called, the most recently set callback takes 444 * effect. 445 * 446 * @param builder Builder instance, which is generated by OH_AudioStreamBuilder_Create(). 447 * @param callback Callback used to handle the error events. 448 * @param userData Pointer to user-defined data, which will be passed back to the application in the callback. 449 * @return Result code. 450 * {@link AUDIOSTREAM_SUCCESS} is returned if the operation is successful. 451 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} is returned if a parameter is invalid, for example, if builder 452 * is nullptr. 453 * @since 20 454 */ 455 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererErrorCallback(OH_AudioStreamBuilder* builder, 456 OH_AudioRenderer_OnErrorCallback callback, void* userData); 457 458 /** 459 * @brief Sets a callback to handle audio data read events for an AudioCapturer instance. This function is 460 * similar to {@link OH_AudioStreamBuilder_SetCapturerCallback}. If both {@link 461 * OH_AudioStreamBuilder_SetCapturerCallback} and this function are called, the most recently set callback takes 462 * effect. 463 * 464 * @param builder Builder instance, which is generated by OH_AudioStreamBuilder_Create(). 465 * @param callback Callback used to handle incoming audio data. 466 * @param userData Pointer to user-defined data, which will be passed back to the application in the callback. 467 * @return Result code. 468 * {@link AUDIOSTREAM_SUCCESS} is returned if the operation is successful. 469 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} is returned if a parameter is invalid, for example, if builder 470 * is nullptr. 471 * @since 20 472 */ 473 OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerReadDataCallback(OH_AudioStreamBuilder* builder, 474 OH_AudioCapturer_OnReadDataCallback callback, void* userData); 475 476 /** 477 * @brief Sets a callback to handle device change events for an AudioCapturer instance. This function is 478 * similar to {@link OH_AudioStreamBuilder_SetCapturerCallback}. If both OH_AudioStreamBuilder_SetCapturerCallback 479 * and this function are called, the most recently set callback takes effect. 480 * 481 * @param builder Builder instance, which is generated by OH_AudioStreamBuilder_Create(). 482 * @param callback Callback used to handle the device change events. 483 * @param userData Pointer to user-defined data, which will be passed back to the application in the callback. 484 * @return Result code. 485 * {@link AUDIOSTREAM_SUCCESS} is returned if the operation is successful. 486 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} is returned if a parameter is invalid, for example, if builder 487 * is nullptr. 488 * @since 20 489 */ 490 OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerDeviceChangeCallback(OH_AudioStreamBuilder* builder, 491 OH_AudioCapturer_OnDeviceChangeCallback callback, void* userData); 492 493 /** 494 * @brief Sets a callback to handle interrupt events for an AudioCapturer instance. 495 * This function is similar to {@link OH_AudioStreamBuilder_SetCapturerCallback}. If both 496 * OH_AudioStreamBuilder_SetCapturerCallback and this function are called, the most recently set callback takes 497 * effect. 498 * 499 * @param builder Builder instance, which is generated by OH_AudioStreamBuilder_Create(). 500 * @param callback Callback used to handle the interrupt events. 501 * @param userData Pointer to user-defined data, which will be passed back to the application in the callback. 502 * @return Result code. 503 * {@link AUDIOSTREAM_SUCCESS} is returned if the operation is successful. 504 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} is returned if a parameter is invalid, for example, if builder 505 * is nullptr. 506 * @since 20 507 */ 508 OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerInterruptCallback(OH_AudioStreamBuilder* builder, 509 OH_AudioCapturer_OnInterruptCallback callback, void* userData); 510 511 /** 512 * @brief Sets a callback to handle error events for an AudioCapturer instance. This function is similar to 513 * {@link OH_AudioStreamBuilder_SetCapturerCallback}. If both OH_AudioStreamBuilder_SetCapturerCallback and this 514 * function are called, the most recently set callback takes effect. 515 * 516 * @param builder Builder instance, which is generated by OH_AudioStreamBuilder_Create(). 517 * @param callback Callback used to handle the error events. 518 * @param userData Pointer to user-defined data, which will be passed back to the application in the callback. 519 * @return Result code. 520 * {@link AUDIOSTREAM_SUCCESS} is returned if the operation is successful. 521 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} is returned if a parameter is invalid, for example, if builder 522 * is nullptr. 523 * @since 20 524 */ 525 OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerErrorCallback(OH_AudioStreamBuilder* builder, 526 OH_AudioCapturer_OnErrorCallback callback, void* userData); 527 528 /** 529 * @brief Set audio capturer configuration, if app want its recorder only to be muted instead of interrupted. 530 * 531 * @param builder reference provided by OH_AudioStreamBuilder_Create() 532 * @param muteWhenInterrupted use {@code true} if application want to be muted instead of interrupted. 533 * @return function result code: 534 * {@link AUDIOSTREAM_SUCCESS} if the execution is successful. 535 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} the param of builder is nullptr. 536 * @since 20 537 */ 538 OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerWillMuteWhenInterrupted(OH_AudioStreamBuilder* builder, 539 bool muteWhenInterrupted); 540 541 /** 542 * @brief Set the callback of fast status change event for audio renderer. 543 * 544 * @param builder Builder provided by OH_AudioStreamBuilder_Create() 545 * @param callback Callback function that will recevie the fast status change event. 546 * @param userData Pointer to an application data structure that will be passed to the callback functions. 547 * @return 548 * {@link AUDIOSTREAM_SUCCESS} if the execution is successful. 549 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} the param of builder or callback is nullptr. 550 * @since 20 551 */ 552 OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererFastStatusChangeCallback(OH_AudioStreamBuilder* builder, 553 OH_AudioRenderer_OnFastStatusChange callback, void* userData); 554 555 /** 556 * @brief Set the callback of fast status change event for audio capturer. 557 * 558 * @param builder Builder provided by OH_AudioStreamBuilder_Create() 559 * @param callback Callback function that will recevie the fast status change event. 560 * @param userData Pointer to an application data structure that will be passed to the callback functions. 561 * @return 562 * {@link AUDIOSTREAM_SUCCESS} if the execution is successful. 563 * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} the param of builder or callback is nullptr. 564 * @since 20 565 */ 566 OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerFastStatusChangeCallback(OH_AudioStreamBuilder* builder, 567 OH_AudioCapturer_OnFastStatusChange callback, void* userData); 568 569 570 #ifdef __cplusplus 571 } 572 #endif 573 574 #endif // NATIVE_AUDIOSTREAM_BUILDER_H 575 /** @} */