diff --git a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h index be7722f07aded3b7db0c85a2f8675e0c39372327..33e168c83e378eec0cba4b18fc0b2d805c56fb5e 100644 --- a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h +++ b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h @@ -564,6 +564,26 @@ typedef void (*OH_AudioRenderer_OnInterruptCallback)(OH_AudioRenderer* renderer, typedef void (*OH_AudioRenderer_OnErrorCallback)(OH_AudioRenderer* renderer, void* userData, OH_AudioStream_Result error); +/** + * @brief Callback function of write data on Render. + * + * Different with OH_AudioRenderer_OnWriteDataCallback, this function allows the caller to write partial data which + * ranges from 0 to the callback buffer size. If 0 is returned, the callback thread will sleep for a while. Otherwise, + * the system may callback again immediately. + * + * @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 Length of the valid data that has written into audioData buffer. The return value must be in range of + * [0, audioDataSize]. If the return value is less than 0, the system changes it to 0. And, if the return value is + * greater than audioDataSize, the system changes it to audioDataSize. + * @see OH_AudioRenderer_OnWriteDataCallback + * @since 20 + */ +typedef int32_t (*OH_AudioRenderer_OnWriteDataCallbackAdvanced)(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 5fb946d8186ec1649a6d77d79588d82893d23aa6..01c2805e9287efa0ea37d0e41007feca237a69e6 100644 --- a/multimedia/audio_framework/common/native_audiostreambuilder.h +++ b/multimedia/audio_framework/common/native_audiostreambuilder.h @@ -371,6 +371,25 @@ OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererInterruptMode(OH_AudioStr OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallback(OH_AudioStreamBuilder* builder, OH_AudioRenderer_OnWriteDataCallback callback, void* userData); +/** + * @brief Set the callback of writing data to renderer client. + * + * This function is similar with {@link OH_AudioStreamBuilder_SetRendererWriteDataCallback}. Only the last callback set + * by OH_AudioStreamBuilder_SetRendererWriteDataCallback or this function will become effective. Different with + * OH_AudioStreamBuilder_SetRendererWriteDataCallback, the callback in this function can return audio data of any + * length. + * + * @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 20 + */ +OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererWriteDataCallbackAdvanced(OH_AudioStreamBuilder* builder, + OH_AudioRenderer_OnWriteDataCallbackAdvanced callback, void* userData); + /** * Set the renderer volume mode of the stream client * diff --git a/multimedia/audio_framework/ohaudio.ndk.json b/multimedia/audio_framework/ohaudio.ndk.json index 9366ddd759a8f380fc8fb8d784be308e011e562a..66cc6a35dd13b747a65b2a0ee75d082f88ffc33e 100644 --- a/multimedia/audio_framework/ohaudio.ndk.json +++ b/multimedia/audio_framework/ohaudio.ndk.json @@ -410,5 +410,9 @@ { "first_introduced": "18", "name": "OH_AudioStreamBuilder_SetCapturerErrorCallback" + }, + { + "first_introduced": "20", + "name": "OH_AudioStreamBuilder_SetRendererWriteDataCallbackAdvanced" } ]