[vlc-commits] audiotrack: wrap arround AudioTimestamp.framePosition
Thomas Guillem
git at videolan.org
Tue Dec 1 12:16:16 CET 2020
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Nov 23 17:21:26 2020 +0100| [a726098adb1595efb331e808a20c0794346e8a03] | committer: Thomas Guillem
audiotrack: wrap arround AudioTimestamp.framePosition
cf. https://developer.android.com/reference/android/media/AudioTimestamp#framePosition
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a726098adb1595efb331e808a20c0794346e8a03
---
modules/audio_output/audiotrack.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/modules/audio_output/audiotrack.c b/modules/audio_output/audiotrack.c
index ed634beb06..7182f0b8fe 100644
--- a/modules/audio_output/audiotrack.c
+++ b/modules/audio_output/audiotrack.c
@@ -106,7 +106,11 @@ typedef struct
struct {
jobject p_obj; /* AudioTimestamp ref */
vlc_tick_t i_frame_us;
- jlong i_frame_pos;
+
+ jlong i_frame_post_last;
+ uint64_t i_frame_wrap_count;
+ uint64_t i_frame_pos;
+
vlc_tick_t i_play_time; /* time when play was called */
vlc_tick_t i_last_time;
} timestamp;
@@ -612,6 +616,9 @@ AudioTrack_ResetWrapCount( JNIEnv *env, audio_output_t *p_aout )
p_sys->headpos.i_last = 0;
p_sys->headpos.i_wrap_count = 0;
+
+ p_sys->timestamp.i_frame_post_last = 0;
+ p_sys->timestamp.i_frame_wrap_count = 0;
}
/**
@@ -748,7 +755,15 @@ AudioTrack_GetTimestampPositionUs( JNIEnv *env, audio_output_t *p_aout )
if( JNI_AT_CALL_BOOL( getTimestamp, p_sys->timestamp.p_obj ) )
{
p_sys->timestamp.i_frame_us = VLC_TICK_FROM_NS(JNI_AUDIOTIMESTAMP_GET_LONG( nanoTime ));
- p_sys->timestamp.i_frame_pos = JNI_AUDIOTIMESTAMP_GET_LONG( framePosition );
+
+ /* the low-order 32 bits of position is in wrapping frame units
+ * similar to AudioTrack#getPlaybackHeadPosition. */
+ jlong i_frame_post_last = JNI_AUDIOTIMESTAMP_GET_LONG( framePosition );
+ if( p_sys->timestamp.i_frame_post_last > i_frame_post_last )
+ p_sys->timestamp.i_frame_wrap_count++;
+ p_sys->timestamp.i_frame_post_last = i_frame_post_last;
+ p_sys->timestamp.i_frame_pos = i_frame_post_last
+ + (p_sys->timestamp.i_frame_wrap_count << 32);
}
else
{
More information about the vlc-commits
mailing list