mirror of
https://github.com/samsonjs/media.git
synced 2026-04-07 11:35:46 +00:00
Fix two issues related to seeking with AC-3 output.
When a passthrough AudioTrack is replaced (due to seeking) the new one behaves as if it is still emptying data from the old one, with its playback position advancing until it runs out of data. Data written while the 'old' AudioTrack was emptying would be discarded, so avoid writing to the new AudioTrack while the old one is still emptying. Also avoid using AudioTrack.getTimestamp with passthrough tracks, as this causes the playback position to jump to a position that breaks audio/video synchronization.
This commit is contained in:
parent
79c7798d84
commit
166c2f7cc0
1 changed files with 17 additions and 7 deletions
|
|
@ -423,12 +423,21 @@ public final class AudioTrack {
|
|||
return RESULT_BUFFER_CONSUMED;
|
||||
}
|
||||
|
||||
// As a workaround for an issue on platform API versions 21/22 where an an AC-3 audio track
|
||||
// continues to play data written while it is paused, stop writing so its buffer empties. See
|
||||
// [Internal: b/18899620].
|
||||
if (Util.SDK_INT <= 22 && isAc3
|
||||
&& audioTrack.getPlayState() == android.media.AudioTrack.PLAYSTATE_PAUSED) {
|
||||
return 0;
|
||||
// Workarounds for issues with AC-3 passthrough AudioTracks on API versions 21/22:
|
||||
if (Util.SDK_INT <= 22 && isAc3) {
|
||||
// An AC-3 audio track continues to play data written while it is paused. Stop writing so its
|
||||
// buffer empties. See [Internal: b/18899620].
|
||||
if (audioTrack.getPlayState() == android.media.AudioTrack.PLAYSTATE_PAUSED) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// A new AC-3 audio track's playback position continues to increase from the old track's
|
||||
// position for a short time after is has been released. Avoid writing data until the playback
|
||||
// head position actually returns to zero.
|
||||
if (audioTrack.getPlayState() == android.media.AudioTrack.PLAYSTATE_STOPPED
|
||||
&& audioTrackUtil.getPlaybackHeadPosition() != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
|
|
@ -639,7 +648,8 @@ public final class AudioTrack {
|
|||
}
|
||||
|
||||
if (systemClockUs - lastTimestampSampleTimeUs >= MIN_TIMESTAMP_SAMPLE_INTERVAL_US) {
|
||||
audioTimestampSet = audioTrackUtil.updateTimestamp();
|
||||
// Don't use AudioTrack.getTimestamp() on AC-3 tracks, as it gives an incorrect timestamp.
|
||||
audioTimestampSet = !isAc3 && audioTrackUtil.updateTimestamp();
|
||||
if (audioTimestampSet) {
|
||||
// Perform sanity checks on the timestamp.
|
||||
long audioTimestampUs = audioTrackUtil.getTimestampNanoTime() / 1000;
|
||||
|
|
|
|||
Loading…
Reference in a new issue