Commit da656e6f by Oliver Woodman

More steps towards unified extractors.

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