Commit da656e6f by Oliver Woodman

More steps towards unified extractors.

parent 53a47524
......@@ -24,9 +24,8 @@ import com.google.android.exoplayer.util.ParsableByteArray;
import java.io.IOException;
/**
* Wraps a {@link RollingSampleBuffer}, adding higher level functionality such as enforcing that
* the first sample returned from the queue is a keyframe, allowing splicing to another queue, and
* so on.
* A {@link TrackOutput} that buffers extracted samples in a queue, and allows for consumption from
* that queue.
*/
public final class DefaultTrackOutput implements TrackOutput {
......@@ -51,27 +50,60 @@ public final class DefaultTrackOutput implements TrackOutput {
largestParsedTimestampUs = Long.MIN_VALUE;
}
public void release() {
rollingBuffer.release();
// Called by the consuming thread, but only when there is no loading thread.
/**
* Clears the queue, returning all allocations to the allocator.
*/
public void clear() {
rollingBuffer.clear();
needKeyframe = true;
lastReadTimeUs = Long.MIN_VALUE;
spliceOutTimeUs = Long.MIN_VALUE;
largestParsedTimestampUs = Long.MIN_VALUE;
}
/**
* Returns the current absolute write index.
*/
public int getWriteIndex() {
return rollingBuffer.getWriteIndex();
}
// Called by the consuming thread.
/**
* Returns the current absolute read index.
*/
public int getReadIndex() {
return rollingBuffer.getReadIndex();
}
/**
* True if the output has received a format. False otherwise.
*/
public boolean hasFormat() {
return format != null;
}
/**
* The format most recently received by the output, or null if a format has yet to be received.
*/
public MediaFormat getFormat() {
return format;
}
/**
* The largest timestamp of any sample received by the output, or {@link Long#MIN_VALUE} if a
* sample has yet to be received.
*/
public long getLargestParsedTimestampUs() {
return largestParsedTimestampUs;
}
/**
* True if at least one sample can be read from the queue. False otherwise.
*/
public boolean isEmpty() {
return !advanceToEligibleSample();
}
......
......@@ -125,13 +125,11 @@ public final class HlsExtractorWrapper implements ExtractorOutput {
}
/**
* Releases the extractor, recycling any pending or incomplete samples to the sample pool.
* <p>
* This method should not be called whilst {@link #read(ExtractorInput)} is also being invoked.
* Clears queues for all tracks, returning all allocations to the buffer pool.
*/
public void release() {
public void clear() {
for (int i = 0; i < sampleQueues.size(); i++) {
sampleQueues.valueAt(i).release();
sampleQueues.valueAt(i).clear();
}
}
......@@ -140,7 +138,7 @@ public final class HlsExtractorWrapper implements ExtractorOutput {
*
* @return The largest timestamp, or {@link Long#MIN_VALUE} if no samples have been parsed.
*/
public long getLargestSampleTimestamp() {
public long getLargestParsedTimestampUs() {
long largestParsedTimestampUs = Long.MIN_VALUE;
for (int i = 0; i < sampleQueues.size(); i++) {
largestParsedTimestampUs = Math.max(largestParsedTimestampUs,
......
......@@ -261,7 +261,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
} else if (loadingFinished) {
return TrackRenderer.END_OF_TRACK_US;
} else {
long largestSampleTimestamp = extractors.getLast().getLargestSampleTimestamp();
long largestSampleTimestamp = extractors.getLast().getLargestParsedTimestampUs();
return largestSampleTimestamp == Long.MIN_VALUE ? downstreamPositionUs
: largestSampleTimestamp;
}
......@@ -333,7 +333,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
HlsExtractorWrapper extractor = extractors.getFirst();
while (extractors.size() > 1 && !haveSamplesForEnabledTracks(extractor)) {
// We're finished reading from the extractor for all tracks, and so can discard it.
extractors.removeFirst().release();
extractors.removeFirst().clear();
extractor = extractors.getFirst();
}
return extractor;
......@@ -382,7 +382,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
private void clearState() {
for (int i = 0; i < extractors.size(); i++) {
extractors.get(i).release();
extractors.get(i).clear();
}
extractors.clear();
clearCurrentLoadable();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment