Reset start trim only if input was queued
Before this change we would reset the start trim to zero after initial configuration (at the start of playback) and after seeking to any position. The fact that no trimming was applied at the start of playback meant that after the first period transition we'd see a mismatch between the next buffer timestamp (equal to the duration of the period taking into account edits) and the duration of audio submitted to the sink. This change modifies the behavior so that we reset the start trim to zero only if some audio was queued since configuration. This is incorrect in the case of starting playback at a non-zero position, but fixes the common case of starting at zero. As before, a later seek to any position is handled via a flush and resets the trim as required. Transitions from one period to the next are unaffected by this change. One way to implement start trimming correctly would be to provide the input buffer timestamp to the audio processors and only trim when handling audio from the start of the stream, but that is a larger change so left for later. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=213828511
This commit is contained in:
parent
a5fc7883a6
commit
b58daf8dc5
@ -33,6 +33,7 @@ import java.nio.ByteOrder;
|
||||
private int channelCount;
|
||||
private int sampleRateHz;
|
||||
private int bytesPerFrame;
|
||||
private boolean receivedInputSinceConfigure;
|
||||
|
||||
private int pendingTrimStartBytes;
|
||||
private ByteBuffer buffer;
|
||||
@ -95,6 +96,7 @@ import java.nio.ByteOrder;
|
||||
pendingTrimStartBytes = trimStartFrames * bytesPerFrame;
|
||||
boolean wasActive = isActive;
|
||||
isActive = trimStartFrames != 0 || trimEndFrames != 0;
|
||||
receivedInputSinceConfigure = false;
|
||||
return wasActive != isActive;
|
||||
}
|
||||
|
||||
@ -127,6 +129,7 @@ import java.nio.ByteOrder;
|
||||
if (remaining == 0) {
|
||||
return;
|
||||
}
|
||||
receivedInputSinceConfigure = true;
|
||||
|
||||
// Trim any pending start bytes from the input buffer.
|
||||
int trimBytes = Math.min(remaining, pendingTrimStartBytes);
|
||||
@ -211,9 +214,14 @@ import java.nio.ByteOrder;
|
||||
public void flush() {
|
||||
outputBuffer = EMPTY_BUFFER;
|
||||
inputEnded = false;
|
||||
// It's no longer necessary to trim any media from the start, but it is necessary to clear the
|
||||
// end buffer and refill it.
|
||||
pendingTrimStartBytes = 0;
|
||||
if (receivedInputSinceConfigure) {
|
||||
// Audio processors are flushed after initial configuration, so we leave the pending trim
|
||||
// start byte count unmodified if the processor was just configured. Otherwise we (possibly
|
||||
// incorrectly) assume that this is a seek to a non-zero position. We should instead check the
|
||||
// timestamp of the first input buffer queued after flushing to decide whether to trim (see
|
||||
// also [Internal: b/77292509]).
|
||||
pendingTrimStartBytes = 0;
|
||||
}
|
||||
endBufferSize = 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user