From 32e4e61ca882fc355b4cd5b3d760d9b116279fd2 Mon Sep 17 00:00:00 2001 From: magekkkk Date: Fri, 7 Feb 2025 10:01:02 +0000 Subject: [PATCH 1/3] add new timestamp api for speed change Signed-off-by: magekkkk --- .../audio_renderer/native_audiorenderer.h | 31 +++++++++++++++++++ multimedia/audio_framework/ohaudio.ndk.json | 4 +++ 2 files changed, 35 insertions(+) diff --git a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h index 6bfcb82ae..2ccf0ea32 100644 --- a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h +++ b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h @@ -259,6 +259,37 @@ OH_AudioStream_Result OH_AudioRenderer_GetFramesWritten(OH_AudioRenderer* render OH_AudioStream_Result OH_AudioRenderer_GetTimestamp(OH_AudioRenderer* renderer, clockid_t clockId, int64_t* framePosition, int64_t* timestamp); +/* + * Query the timestamp at which a particular frame was presented in clock monotonic timebase, the frame at + * the returned position was just committed to hardware. This is often used in video synchronization and + * recording stream alignment. + * + * Position is 0 and timestamp is fixed until stream really runs and frame is committed. Position will + * also be reset while flush function is called. When a audio route change happens, like in device or output + * type change situations, the position may also be reset but timestamp remains monotonically increasing. + * So it is better to use the values until they becomes regularly after the change. + * This interface also adapts to playback speed change. For example, the increseing speed for position + * will be double for 2x speed playback. + * + * @since 15 + * + * @param renderer Reference created by OH_AudioStreamBuilder_GenerateRenderer() + * @param framePosition Pointer to a variable to receive the position + * @param timestamp Pointer to a variable to receive the timestamp + * @return Function result code: + * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. + * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: + * 1.The param of renderer is nullptr; + * 2.The param of framePosition or timestamp is nullptr; + * {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE}: + * 1.Stopped state is illegal for getting audio timestamp. + * {@link AUDIOSTREAM_ERROR_SYSTEM}: + * 1.Crash or blocking occurs in system process. + * 2.Other unexpected error from internal system. + */ +OH_AudioStream_Result OH_AudioRenderer_GetAudioTimestampInfo(OH_AudioRenderer* renderer, + int64_t* framePosition, int64_t* timestamp); + /* * Query the frame size in callback, it is a fixed length that the stream want to be filled for each callback. * diff --git a/multimedia/audio_framework/ohaudio.ndk.json b/multimedia/audio_framework/ohaudio.ndk.json index 961c75dae..e6d5a0cd2 100644 --- a/multimedia/audio_framework/ohaudio.ndk.json +++ b/multimedia/audio_framework/ohaudio.ndk.json @@ -378,5 +378,9 @@ { "first_introduced": "13", "name": "OH_AudioRoutingManager_SetMicBlockStatusCallback" + }, + { + "first_introduced": "15", + "name": "OH_AudioRenderer_GetAudioTimestampInfo" } ] -- Gitee From 94432d59ae4eedb57170b92b6148fb1013a8bb38 Mon Sep 17 00:00:00 2001 From: magekkkk Date: Fri, 7 Feb 2025 11:05:26 +0000 Subject: [PATCH 2/3] fix comment mismatch Signed-off-by: magekkkk --- .../audio_framework/audio_renderer/native_audiorenderer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h index 2ccf0ea32..985969595 100644 --- a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h +++ b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h @@ -282,7 +282,7 @@ OH_AudioStream_Result OH_AudioRenderer_GetTimestamp(OH_AudioRenderer* renderer, * 1.The param of renderer is nullptr; * 2.The param of framePosition or timestamp is nullptr; * {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE}: - * 1.Stopped state is illegal for getting audio timestamp. + * 1.Only running state is legal for getting audio timestamp. * {@link AUDIOSTREAM_ERROR_SYSTEM}: * 1.Crash or blocking occurs in system process. * 2.Other unexpected error from internal system. -- Gitee From 1bf7f86d74b7f75ea6e431dea86033a744eef8e6 Mon Sep 17 00:00:00 2001 From: magekkkk Date: Fri, 7 Feb 2025 12:32:15 +0000 Subject: [PATCH 3/3] update doxygen format Signed-off-by: magekkkk --- .../audio_renderer/native_audiorenderer.h | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h index 985969595..18b2daa39 100644 --- a/multimedia/audio_framework/audio_renderer/native_audiorenderer.h +++ b/multimedia/audio_framework/audio_renderer/native_audiorenderer.h @@ -259,37 +259,6 @@ OH_AudioStream_Result OH_AudioRenderer_GetFramesWritten(OH_AudioRenderer* render OH_AudioStream_Result OH_AudioRenderer_GetTimestamp(OH_AudioRenderer* renderer, clockid_t clockId, int64_t* framePosition, int64_t* timestamp); -/* - * Query the timestamp at which a particular frame was presented in clock monotonic timebase, the frame at - * the returned position was just committed to hardware. This is often used in video synchronization and - * recording stream alignment. - * - * Position is 0 and timestamp is fixed until stream really runs and frame is committed. Position will - * also be reset while flush function is called. When a audio route change happens, like in device or output - * type change situations, the position may also be reset but timestamp remains monotonically increasing. - * So it is better to use the values until they becomes regularly after the change. - * This interface also adapts to playback speed change. For example, the increseing speed for position - * will be double for 2x speed playback. - * - * @since 15 - * - * @param renderer Reference created by OH_AudioStreamBuilder_GenerateRenderer() - * @param framePosition Pointer to a variable to receive the position - * @param timestamp Pointer to a variable to receive the timestamp - * @return Function result code: - * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. - * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: - * 1.The param of renderer is nullptr; - * 2.The param of framePosition or timestamp is nullptr; - * {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE}: - * 1.Only running state is legal for getting audio timestamp. - * {@link AUDIOSTREAM_ERROR_SYSTEM}: - * 1.Crash or blocking occurs in system process. - * 2.Other unexpected error from internal system. - */ -OH_AudioStream_Result OH_AudioRenderer_GetAudioTimestampInfo(OH_AudioRenderer* renderer, - int64_t* framePosition, int64_t* timestamp); - /* * Query the frame size in callback, it is a fixed length that the stream want to be filled for each callback. * @@ -535,6 +504,37 @@ OH_AudioStream_Result OH_AudioRenderer_GetSilentModeAndMixWithOthers( OH_AudioStream_Result OH_AudioRenderer_SetDefaultOutputDevice( OH_AudioRenderer* renderer, OH_AudioDevice_Type deviceType); +/** + * @brief Query the timestamp at which a particular frame was presented in clock monotonic timebase, + * the frame at the returned position was just committed to hardware. This is often used in + * video synchronization and recording stream alignment. + * + * Position is 0 and timestamp is fixed until stream really runs and frame is committed. Position + * will also be reset while flush function is called. When a audio route change happens, like in + * device or output type change situations, the position may also be reset but timestamp remains + * monotonically increasing. + * So it is better to use the values until they becomes regularly after the change. + * This interface also adapts to playback speed change. For example, the increseing speed for + * position will be double for 2x speed playback. + * + * @param renderer Reference created by OH_AudioStreamBuilder_GenerateRenderer() + * @param framePosition Pointer to a variable to receive the position + * @param timestamp Pointer to a variable to receive the timestamp + * @return Function result code: + * {@link AUDIOSTREAM_SUCCESS} If the execution is successful. + * {@link AUDIOSTREAM_ERROR_INVALID_PARAM}: + * 1.The param of renderer is nullptr; + * 2.The param of framePosition or timestamp is nullptr; + * {@link AUDIOSTREAM_ERROR_ILLEGAL_STATE}: + * 1.Only running state is legal for getting audio timestamp. + * {@link AUDIOSTREAM_ERROR_SYSTEM}: + * 1.Crash or blocking occurs in system process. + * 2.Other unexpected error from internal system. + * @since 15 + */ +OH_AudioStream_Result OH_AudioRenderer_GetAudioTimestampInfo(OH_AudioRenderer* renderer, + int64_t* framePosition, int64_t* timestamp); + #ifdef __cplusplus } #endif -- Gitee