diff --git a/multimedia/audio_framework/common/native_audiostream_base.h b/multimedia/audio_framework/common/native_audiostream_base.h index c47def15b5a9291e74d9aa48a716b9466faffac0..efe0c97863d35d965ecf8b6f556f104e8b9a4684 100644 --- a/multimedia/audio_framework/common/native_audiostream_base.h +++ b/multimedia/audio_framework/common/native_audiostream_base.h @@ -510,7 +510,7 @@ typedef struct OH_AudioRenderer_Callbacks_Struct { OH_AudioRenderer* renderer, void* userData, void* buffer, - int32_t lenth); + int32_t length); /** * This function pointer will point to the callback function that @@ -563,7 +563,7 @@ typedef struct OH_AudioCapturer_Callbacks_Struct { OH_AudioCapturer* capturer, void* userData, void* buffer, - int32_t lenth); + int32_t length); /** * This function pointer will point to the callback function that @@ -669,6 +669,36 @@ typedef enum { */ AUDIO_STREAM_PRIVACY_TYPE_PRIVATE = 1, } OH_AudioStream_PrivacyType; + +/** + * @brief Defines enumeration of audio data callback result. + * + * @since 12 + */ +typedef enum { + /** Result of audio data callabck is invalid. */ + AUDIO_DATA_CALLBACK_RESULT_INVALID = -1, + /** Result of audio data callabck is valid. */ + AUDIO_DATA_CALLBACK_RESULT_VALID = 0, +} OH_AudioData_Callback_Result; + +/** + * @brief Callback function of write data. + * + * This function is similar with OH_AudioRenderer_Callbacks_Struct.OH_AudioRenderer_OnWriteData instead of the return + * value. The return result of this function indicates whether the data filled in the buffer is valid or invalid. If + * result is invalid, the data filled by user will not be played. + * + * @param renderer AudioRenderer where this callback occurs. + * @param userData User data which is passed by user. + * @param audioData Audio data pointer, where user should fill in audio data. + * @param audioDataSize Size of audio data that user should fill in. + * @return Audio Data callback result. + * @see OH_AudioRenderer_Callbacks_Struct.OH_AudioRenderer_OnWriteData + * @since 12 + */ +typedef OH_AudioData_Callback_Result (*OH_AudioRenderer_OnWriteDataCallback)(OH_AudioRenderer* renderer, void* userData, + void* audioData, int32_t audioDataSize); #ifdef __cplusplus } #endif diff --git a/multimedia/audio_framework/common/native_audiostreambuilder.h b/multimedia/audio_framework/common/native_audiostreambuilder.h index 0fdb40557d9b25e222b4ccc5b4a23b2a07ca6f38..da4658fda25e4107ce45db0b9cf611226879cd6d 100644 --- a/multimedia/audio_framework/common/native_audiostreambuilder.h +++ b/multimedia/audio_framework/common/native_audiostreambuilder.h @@ -274,6 +274,22 @@ OH_AudioStream_Result OH_AudioStreamBuilder_SetWriteDataWithMetadataCallback(OH_ OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptMode(OH_AudioStreamBuilder* builder, OH_AudioInterrupt_Mode mode); +/** + * @brief Set the callback of writing data to renderer client. + * + * This function is similar with {@link OH_AudioStreamBuilder_SetRendererCallback}. Only the last callback set by + * OH_AudioStreamBuilder_SetRendererCallback or this function will become effective. + * + * @param builder Builder provided by OH_AudioStreamBuilder_Create() + * @param callback Callback to functions that will write audio data to renderer client. + * @param userData Pointer to an application data structure that will be passed to the callback functions. + * @return Result code. + * {@link AUDIOSTREAM_SUCCESS} Success. + * {@link AUDIOSTREAM_ERROR_INVALID_PARAM} Parameter is invalid, e.g. builder is nullptr, e.t.c. + * @since 12 + */ +OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallback(OH_AudioStreamBuilder* builder, + OH_AudioRenderer_OnWriteDataCallback callback, void* userData); #ifdef __cplusplus } #endif diff --git a/multimedia/audio_framework/ohaudio.ndk.json b/multimedia/audio_framework/ohaudio.ndk.json index 6799fa457de5c1b1485fc27ca1402aa2629db9e4..81a75495f57598750c01e75120b938b9477dc309 100644 --- a/multimedia/audio_framework/ohaudio.ndk.json +++ b/multimedia/audio_framework/ohaudio.ndk.json @@ -310,5 +310,9 @@ { "first_introduced": "12", "name": "OH_AudioRenderer_GetRendererPrivacy" + }, + { + "first_introduced": "12", + "name":"OH_AudioStreamBuilder_SetRendererWriteDataCallback" } ]