Track input/output cleanup.
- Remove special DefaultTrackOutput.sampleData method, and have SingleSampleMediaChunk use the regular one instead. - Make DummyTrackOutput behave correctly is allowEndOfInput is false. - Simplify progress tracking in ExtractorSampleSource. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=117808659
This commit is contained in:
parent
60ba7823e0
commit
1ca5378cda
@ -18,6 +18,8 @@ package com.google.android.exoplayer.chunk;
|
|||||||
import com.google.android.exoplayer.C;
|
import com.google.android.exoplayer.C;
|
||||||
import com.google.android.exoplayer.Format;
|
import com.google.android.exoplayer.Format;
|
||||||
import com.google.android.exoplayer.drm.DrmInitData;
|
import com.google.android.exoplayer.drm.DrmInitData;
|
||||||
|
import com.google.android.exoplayer.extractor.DefaultExtractorInput;
|
||||||
|
import com.google.android.exoplayer.extractor.ExtractorInput;
|
||||||
import com.google.android.exoplayer.upstream.DataSource;
|
import com.google.android.exoplayer.upstream.DataSource;
|
||||||
import com.google.android.exoplayer.upstream.DataSpec;
|
import com.google.android.exoplayer.upstream.DataSpec;
|
||||||
import com.google.android.exoplayer.util.Util;
|
import com.google.android.exoplayer.util.Util;
|
||||||
@ -90,12 +92,16 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk {
|
|||||||
DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
|
DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
|
||||||
try {
|
try {
|
||||||
// Create and open the input.
|
// Create and open the input.
|
||||||
dataSource.open(loadDataSpec);
|
long length = dataSource.open(loadDataSpec);
|
||||||
|
if (length != C.LENGTH_UNBOUNDED) {
|
||||||
|
length += bytesLoaded;
|
||||||
|
}
|
||||||
|
ExtractorInput extractorInput = new DefaultExtractorInput(dataSource, bytesLoaded, length);
|
||||||
// Load the sample data.
|
// Load the sample data.
|
||||||
int result = 0;
|
int result = 0;
|
||||||
while (result != C.RESULT_END_OF_INPUT) {
|
while (result != C.RESULT_END_OF_INPUT) {
|
||||||
bytesLoaded += result;
|
bytesLoaded += result;
|
||||||
result = getOutput().sampleData(dataSource, Integer.MAX_VALUE, true);
|
result = getOutput().sampleData(extractorInput, Integer.MAX_VALUE, true);
|
||||||
}
|
}
|
||||||
int sampleSize = bytesLoaded;
|
int sampleSize = bytesLoaded;
|
||||||
getOutput().sampleMetadata(startTimeUs, C.SAMPLE_FLAG_SYNC, sampleSize, 0, null);
|
getOutput().sampleMetadata(startTimeUs, C.SAMPLE_FLAG_SYNC, sampleSize, 0, null);
|
||||||
|
@ -15,14 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer.extractor;
|
package com.google.android.exoplayer.extractor;
|
||||||
|
|
||||||
import com.google.android.exoplayer.C;
|
|
||||||
import com.google.android.exoplayer.Format;
|
import com.google.android.exoplayer.Format;
|
||||||
import com.google.android.exoplayer.SampleHolder;
|
import com.google.android.exoplayer.SampleHolder;
|
||||||
import com.google.android.exoplayer.upstream.Allocator;
|
import com.google.android.exoplayer.upstream.Allocator;
|
||||||
import com.google.android.exoplayer.upstream.DataSource;
|
|
||||||
import com.google.android.exoplayer.util.ParsableByteArray;
|
import com.google.android.exoplayer.util.ParsableByteArray;
|
||||||
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -225,24 +222,6 @@ public class DefaultTrackOutput implements TrackOutput {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by the loading thread.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invoked to write sample data to the output.
|
|
||||||
*
|
|
||||||
* @param dataSource A {@link DataSource} from which to read the sample data.
|
|
||||||
* @param length The maximum length to read from the input.
|
|
||||||
* @param allowEndOfInput True if encountering the end of the input having read no data is
|
|
||||||
* allowed, and should result in {@link C#RESULT_END_OF_INPUT} being returned. False if it
|
|
||||||
* should be considered an error, causing an {@link EOFException} to be thrown.
|
|
||||||
* @return The number of bytes appended.
|
|
||||||
* @throws IOException If an error occurred reading from the input.
|
|
||||||
*/
|
|
||||||
public int sampleData(DataSource dataSource, int length, boolean allowEndOfInput)
|
|
||||||
throws IOException {
|
|
||||||
return rollingBuffer.appendData(dataSource, length, allowEndOfInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TrackOutput implementation. Called by the loading thread.
|
// TrackOutput implementation. Called by the loading thread.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,9 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer.extractor;
|
package com.google.android.exoplayer.extractor;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer.C;
|
||||||
import com.google.android.exoplayer.Format;
|
import com.google.android.exoplayer.Format;
|
||||||
import com.google.android.exoplayer.util.ParsableByteArray;
|
import com.google.android.exoplayer.util.ParsableByteArray;
|
||||||
|
|
||||||
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +35,14 @@ public final class DummyTrackOutput implements TrackOutput {
|
|||||||
@Override
|
@Override
|
||||||
public int sampleData(ExtractorInput input, int length, boolean allowEndOfInput)
|
public int sampleData(ExtractorInput input, int length, boolean allowEndOfInput)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
return input.skip(length);
|
int bytesSkipped = input.skip(length);
|
||||||
|
if (bytesSkipped == C.RESULT_END_OF_INPUT) {
|
||||||
|
if (allowEndOfInput) {
|
||||||
|
return C.RESULT_END_OF_INPUT;
|
||||||
|
}
|
||||||
|
throw new EOFException();
|
||||||
|
}
|
||||||
|
return bytesSkipped;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -219,14 +219,11 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||||||
private Loader loader;
|
private Loader loader;
|
||||||
private ExtractingLoadable loadable;
|
private ExtractingLoadable loadable;
|
||||||
private IOException currentLoadableException;
|
private IOException currentLoadableException;
|
||||||
// TODO: Set this back to 0 in the correct place (some place indicative of making progress).
|
|
||||||
private int currentLoadableExceptionCount;
|
private int currentLoadableExceptionCount;
|
||||||
private long currentLoadableExceptionTimestamp;
|
private long currentLoadableExceptionTimestamp;
|
||||||
|
private boolean currentLoadableExtractedSamples;
|
||||||
private boolean loadingFinished;
|
private boolean loadingFinished;
|
||||||
|
|
||||||
private int extractedSampleCount;
|
|
||||||
private int extractedSampleCountAtStartOfLoad;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param uri The {@link Uri} of the media stream.
|
* @param uri The {@link Uri} of the media stream.
|
||||||
* @param dataSource A data source to read the media stream.
|
* @param dataSource A data source to read the media stream.
|
||||||
@ -550,7 +547,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||||||
@Override
|
@Override
|
||||||
public void onLoadError(Loadable ignored, IOException e) {
|
public void onLoadError(Loadable ignored, IOException e) {
|
||||||
currentLoadableException = e;
|
currentLoadableException = e;
|
||||||
currentLoadableExceptionCount = extractedSampleCount > extractedSampleCountAtStartOfLoad ? 1
|
currentLoadableExceptionCount = currentLoadableExtractedSamples ? 1
|
||||||
: currentLoadableExceptionCount + 1;
|
: currentLoadableExceptionCount + 1;
|
||||||
currentLoadableExceptionTimestamp = SystemClock.elapsedRealtime();
|
currentLoadableExceptionTimestamp = SystemClock.elapsedRealtime();
|
||||||
notifyLoadError(e);
|
notifyLoadError(e);
|
||||||
@ -635,7 +632,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||||||
// We're playing a seekable on-demand stream. Resume the current loadable, which will
|
// We're playing a seekable on-demand stream. Resume the current loadable, which will
|
||||||
// request data starting from the point it left off.
|
// request data starting from the point it left off.
|
||||||
}
|
}
|
||||||
extractedSampleCountAtStartOfLoad = extractedSampleCount;
|
currentLoadableExtractedSamples = false;
|
||||||
loader.startLoading(loadable, this);
|
loader.startLoading(loadable, this);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -659,7 +656,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||||||
loadable = createLoadableFromPositionUs(pendingResetPositionUs);
|
loadable = createLoadableFromPositionUs(pendingResetPositionUs);
|
||||||
pendingResetPositionUs = NO_RESET_PENDING;
|
pendingResetPositionUs = NO_RESET_PENDING;
|
||||||
}
|
}
|
||||||
extractedSampleCountAtStartOfLoad = extractedSampleCount;
|
currentLoadableExtractedSamples = false;
|
||||||
loader.startLoading(loadable, this);
|
loader.startLoading(loadable, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -765,7 +762,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||||||
@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) {
|
||||||
super.sampleMetadata(timeUs, flags, size, offset, encryptionKey);
|
super.sampleMetadata(timeUs, flags, size, offset, encryptionKey);
|
||||||
extractedSampleCount++;
|
currentLoadableExtractedSamples = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user