diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java index f0613bc82c..b59744d893 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java @@ -94,10 +94,18 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer { /** * AudioTrack timestamps are deemed spurious if they are offset from the system clock by more - * than this amount. This is a fail safe that should not be required on correctly functioning - * devices. + * than this amount. + *

+ * This is a fail safe that should not be required on correctly functioning devices. */ - private static final long MAX_AUDIO_TIMSTAMP_OFFSET_US = 10 * MICROS_PER_SECOND; + private static final long MAX_AUDIO_TIMESTAMP_OFFSET_US = 10 * MICROS_PER_SECOND; + + /** + * AudioTrack latencies are deemed impossibly large if they are greater than this amount. + *

+ * This is a fail safe that should not be required on correctly functioning devices. + */ + private static final long MAX_AUDIO_TRACK_LATENCY_US = 10 * MICROS_PER_SECOND; private static final int MAX_PLAYHEAD_OFFSET_COUNT = 10; private static final int MIN_PLAYHEAD_OFFSET_SAMPLE_INTERVAL_US = 30000; @@ -515,7 +523,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer { if (audioTimestampUs < audioTrackResumeSystemTimeUs) { // The timestamp corresponds to a time before the track was most recently resumed. audioTimestampSet = false; - } else if (Math.abs(audioTimestampUs - systemClockUs) > MAX_AUDIO_TIMSTAMP_OFFSET_US) { + } else if (Math.abs(audioTimestampUs - systemClockUs) > MAX_AUDIO_TIMESTAMP_OFFSET_US) { // The timestamp time base is probably wrong. audioTimestampSet = false; Log.w(TAG, "Spurious audio timestamp: " + audioTimestampCompat.getFramePosition() + ", " @@ -531,6 +539,11 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer { framesToDurationUs(bufferSize / frameSize); // Sanity check that the latency is non-negative. audioTrackLatencyUs = Math.max(audioTrackLatencyUs, 0); + // Sanity check that the latency isn't too large. + if (audioTrackLatencyUs > MAX_AUDIO_TRACK_LATENCY_US) { + Log.w(TAG, "Ignoring impossibly large audio latency: " + audioTrackLatencyUs); + audioTrackLatencyUs = 0; + } } catch (Exception e) { // The method existed, but doesn't work. Don't try again. audioTrackGetLatencyMethod = null;