mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Fix position tracking bug for inaccurate audio processors
If audio processors report a drifting position, we currently update the media position parameters to correct this drift. However, this means we pass in the wrong value to audioProcessorChain.getMediaDuration, which reuqires the time since the last flush. To fix this problem, we can instead save the drift seperately and apply it where needed. PiperOrigin-RevId: 692202219 (cherry picked from commit 06718c5df36519bd80f895d7f5a0cedecda5a501)
This commit is contained in:
parent
7839f420ab
commit
caf7c2b7f1
@ -1740,23 +1740,17 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
audioProcessorChain.getMediaDuration(playoutDurationSinceLastCheckpointUs);
|
audioProcessorChain.getMediaDuration(playoutDurationSinceLastCheckpointUs);
|
||||||
long currentMediaPositionUs =
|
long currentMediaPositionUs =
|
||||||
mediaPositionParameters.mediaTimeUs + actualMediaDurationSinceLastCheckpointUs;
|
mediaPositionParameters.mediaTimeUs + actualMediaDurationSinceLastCheckpointUs;
|
||||||
long mediaDurationEstimateDiffUs =
|
mediaPositionParameters.mediaPositionDriftUs =
|
||||||
actualMediaDurationSinceLastCheckpointUs - estimatedMediaDurationSinceLastCheckpointUs;
|
actualMediaDurationSinceLastCheckpointUs - estimatedMediaDurationSinceLastCheckpointUs;
|
||||||
if (Math.abs(mediaDurationEstimateDiffUs) > 10000) {
|
|
||||||
// Update current media position parameters if the estimate drifted from the actual
|
|
||||||
// media duration created by the audio processor chain. This ensures the estimate is always
|
|
||||||
// fairly accurate and we can rely on it once we enter the else-branch below.
|
|
||||||
mediaPositionParameters =
|
|
||||||
new MediaPositionParameters(
|
|
||||||
mediaPositionParameters.playbackParameters, currentMediaPositionUs, positionUs);
|
|
||||||
}
|
|
||||||
return currentMediaPositionUs;
|
return currentMediaPositionUs;
|
||||||
} else {
|
} else {
|
||||||
// The processor chain has been configured with new parameters, but we're still playing audio
|
// The processor chain has been configured with new parameters, but we're still playing audio
|
||||||
// that was processed using previous parameters. We can't scale the playout duration using the
|
// that was processed using previous parameters. We can't scale the playout duration using the
|
||||||
// processor chain in this case, so we fall back to scaling using the previous parameters'
|
// processor chain in this case, so we fall back to scaling using the previous parameters'
|
||||||
// target speed instead.
|
// target speed instead.
|
||||||
return mediaPositionParameters.mediaTimeUs + estimatedMediaDurationSinceLastCheckpointUs;
|
return mediaPositionParameters.mediaTimeUs
|
||||||
|
+ estimatedMediaDurationSinceLastCheckpointUs
|
||||||
|
+ mediaPositionParameters.mediaPositionDriftUs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2100,6 +2094,12 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
/** The audio track position from which the playback parameters apply, in microseconds. */
|
/** The audio track position from which the playback parameters apply, in microseconds. */
|
||||||
public final long audioTrackPositionUs;
|
public final long audioTrackPositionUs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An updatable value for the observed drift between the actual media time and the one that can
|
||||||
|
* be calculated from the other parameters.
|
||||||
|
*/
|
||||||
|
public long mediaPositionDriftUs;
|
||||||
|
|
||||||
private MediaPositionParameters(
|
private MediaPositionParameters(
|
||||||
PlaybackParameters playbackParameters, long mediaTimeUs, long audioTrackPositionUs) {
|
PlaybackParameters playbackParameters, long mediaTimeUs, long audioTrackPositionUs) {
|
||||||
this.playbackParameters = playbackParameters;
|
this.playbackParameters = playbackParameters;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user