Cap AudioTrack latencies at 10 seconds and log a warning if too large.
This commit is contained in:
parent
ac18ac087b
commit
43712ce41c
@ -94,10 +94,18 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AudioTrack timestamps are deemed spurious if they are offset from the system clock by more
|
* 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
|
* than this amount.
|
||||||
* devices.
|
* <p>
|
||||||
|
* 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.
|
||||||
|
* <p>
|
||||||
|
* 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 MAX_PLAYHEAD_OFFSET_COUNT = 10;
|
||||||
private static final int MIN_PLAYHEAD_OFFSET_SAMPLE_INTERVAL_US = 30000;
|
private static final int MIN_PLAYHEAD_OFFSET_SAMPLE_INTERVAL_US = 30000;
|
||||||
@ -515,7 +523,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
|
|||||||
if (audioTimestampUs < audioTrackResumeSystemTimeUs) {
|
if (audioTimestampUs < audioTrackResumeSystemTimeUs) {
|
||||||
// The timestamp corresponds to a time before the track was most recently resumed.
|
// The timestamp corresponds to a time before the track was most recently resumed.
|
||||||
audioTimestampSet = false;
|
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.
|
// The timestamp time base is probably wrong.
|
||||||
audioTimestampSet = false;
|
audioTimestampSet = false;
|
||||||
Log.w(TAG, "Spurious audio timestamp: " + audioTimestampCompat.getFramePosition() + ", "
|
Log.w(TAG, "Spurious audio timestamp: " + audioTimestampCompat.getFramePosition() + ", "
|
||||||
@ -531,6 +539,11 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
|
|||||||
framesToDurationUs(bufferSize / frameSize);
|
framesToDurationUs(bufferSize / frameSize);
|
||||||
// Sanity check that the latency is non-negative.
|
// Sanity check that the latency is non-negative.
|
||||||
audioTrackLatencyUs = Math.max(audioTrackLatencyUs, 0);
|
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) {
|
} catch (Exception e) {
|
||||||
// The method existed, but doesn't work. Don't try again.
|
// The method existed, but doesn't work. Don't try again.
|
||||||
audioTrackGetLatencyMethod = null;
|
audioTrackGetLatencyMethod = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user