Move sample offset application to RollingSampleBuffer.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120123335
This commit is contained in:
olly 2016-04-18 08:02:16 -07:00 committed by Oliver Woodman
parent ffb4aeaa8c
commit 4451be929d
2 changed files with 14 additions and 10 deletions

View file

@ -31,9 +31,6 @@ public class DefaultTrackOutput implements TrackOutput {
private final RollingSampleBuffer rollingBuffer; private final RollingSampleBuffer rollingBuffer;
private final DecoderInputBuffer sampleBuffer; private final DecoderInputBuffer sampleBuffer;
// Accessed only by the loading thread.
private long sampleOffsetUs;
// Accessed only by the consuming thread. // Accessed only by the consuming thread.
private boolean needKeyframe; private boolean needKeyframe;
private long lastReadTimeUs; private long lastReadTimeUs;
@ -219,11 +216,9 @@ public class DefaultTrackOutput implements TrackOutput {
* @param sampleOffsetUs The offset in microseconds. * @param sampleOffsetUs The offset in microseconds.
*/ */
public void setSampleOffsetUs(long sampleOffsetUs) { public void setSampleOffsetUs(long sampleOffsetUs) {
this.sampleOffsetUs = sampleOffsetUs; rollingBuffer.setSampleOffsetUs(sampleOffsetUs);
} }
// TrackOutput implementation. Called by the loading thread.
@Override @Override
public void format(Format format) { public void format(Format format) {
rollingBuffer.format(format); rollingBuffer.format(format);
@ -242,7 +237,6 @@ public class DefaultTrackOutput implements TrackOutput {
@Override @Override
public void sampleMetadata(long timeUs, int flags, int size, int offset, byte[] encryptionKey) { public void sampleMetadata(long timeUs, int flags, int size, int offset, byte[] encryptionKey) {
timeUs += sampleOffsetUs;
largestParsedTimestampUs = Math.max(largestParsedTimestampUs, timeUs); largestParsedTimestampUs = Math.max(largestParsedTimestampUs, timeUs);
rollingBuffer.sampleMetadata(timeUs, flags, size, offset, encryptionKey); rollingBuffer.sampleMetadata(timeUs, flags, size, offset, encryptionKey);
} }

View file

@ -47,6 +47,7 @@ import java.util.concurrent.LinkedBlockingDeque;
private long totalBytesDropped; private long totalBytesDropped;
// Accessed only by the loading thread. // Accessed only by the loading thread.
private long sampleOffsetUs;
private long totalBytesWritten; private long totalBytesWritten;
private Allocation lastAllocation; private Allocation lastAllocation;
private int lastAllocationOffset; private int lastAllocationOffset;
@ -355,6 +356,15 @@ import java.util.concurrent.LinkedBlockingDeque;
// Called by the loading thread. // Called by the loading thread.
/**
* Sets an offset that will be added to the timestamps of subsequently queued samples.
*
* @param sampleOffsetUs The timestamp offset in microseconds.
*/
public void setSampleOffsetUs(long sampleOffsetUs) {
this.sampleOffsetUs = sampleOffsetUs;
}
@Override @Override
public void format(Format format) { public void format(Format format) {
upstreamFormat = format; upstreamFormat = format;
@ -390,10 +400,10 @@ import java.util.concurrent.LinkedBlockingDeque;
} }
@Override @Override
public void sampleMetadata(long sampleTimeUs, int flags, int size, int offset, public void sampleMetadata(long timeUs, int flags, int size, int offset, byte[] encryptionKey) {
byte[] encryptionKey) { timeUs += sampleOffsetUs;
long absoluteOffset = totalBytesWritten - size - offset; long absoluteOffset = totalBytesWritten - size - offset;
infoQueue.commitSample(sampleTimeUs, flags, absoluteOffset, size, encryptionKey); infoQueue.commitSample(timeUs, flags, absoluteOffset, size, encryptionKey);
} }
/** /**