mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Use current position code when checking if AudioTrack has pending data
We currently rely on the raw playback head position to check if any data is pending in the AudioTrack (e.g. to know if the renderer is still ready). We can use the value returned from getCurrentPositionUs instead to align the "isReady" logic with the playback position logic. This has the side effect that getPlaybackHeadPosition position is called less often when the position is obtained via getTimestamp. PiperOrigin-RevId: 514747613
This commit is contained in:
parent
82ab327e02
commit
fe710871aa
@ -420,7 +420,8 @@ import java.lang.reflect.Method;
|
||||
* @return Whether the audio track has any pending data to play out.
|
||||
*/
|
||||
public boolean hasPendingData(long writtenFrames) {
|
||||
return writtenFrames > getPlaybackHeadPosition() || forceHasPendingData();
|
||||
return writtenFrames > durationUsToFrames(getCurrentPositionUs(/* sourceEnded= */ false))
|
||||
|| forceHasPendingData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -542,6 +543,10 @@ import java.lang.reflect.Method;
|
||||
return (frameCount * C.MICROS_PER_SECOND) / outputSampleRate;
|
||||
}
|
||||
|
||||
private long durationUsToFrames(long durationUs) {
|
||||
return (durationUs * outputSampleRate) / C.MICROS_PER_SECOND;
|
||||
}
|
||||
|
||||
private void resetSyncParams() {
|
||||
smoothedPlayheadOffsetUs = 0;
|
||||
playheadOffsetCount = 0;
|
||||
@ -591,7 +596,7 @@ import java.lang.reflect.Method;
|
||||
long elapsedTimeSinceStopUs = (currentTimeMs * 1000) - stopTimestampUs;
|
||||
long mediaTimeSinceStopUs =
|
||||
Util.getMediaDurationForPlayoutDuration(elapsedTimeSinceStopUs, audioTrackPlaybackSpeed);
|
||||
long framesSinceStop = (mediaTimeSinceStopUs * outputSampleRate) / C.MICROS_PER_SECOND;
|
||||
long framesSinceStop = durationUsToFrames(mediaTimeSinceStopUs);
|
||||
return min(endPlaybackHeadPosition, stopPlaybackHeadPosition + framesSinceStop);
|
||||
}
|
||||
if (currentTimeMs - lastRawPlaybackHeadPositionSampleTimeMs
|
||||
|
Loading…
x
Reference in New Issue
Block a user