parent
c497b78ffe
commit
0414b0d2f6
@ -171,7 +171,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||||||
if (isPendingReset() || extractors.isEmpty()) {
|
if (isPendingReset() || extractors.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean haveSamples = prepared && haveSamplesForEnabledTracks(extractors.getFirst());
|
boolean haveSamples = prepared && haveSamplesForEnabledTracks(getCurrentExtractor());
|
||||||
if (!haveSamples) {
|
if (!haveSamples) {
|
||||||
maybeThrowLoadableException();
|
maybeThrowLoadableException();
|
||||||
}
|
}
|
||||||
@ -194,13 +194,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||||||
return NOTHING_READ;
|
return NOTHING_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
TsExtractor extractor = extractors.getFirst();
|
TsExtractor extractor = getCurrentExtractor();
|
||||||
while (extractors.size() > 1 && !haveSamplesForEnabledTracks(extractor)) {
|
|
||||||
// We're finished reading from the extractor for all tracks, and so can discard it.
|
|
||||||
extractors.removeFirst().release();
|
|
||||||
extractor = extractors.getFirst();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extractors.size() > 1) {
|
if (extractors.size() > 1) {
|
||||||
// If there's more than one extractor, attempt to configure a seamless splice from the
|
// If there's more than one extractor, attempt to configure a seamless splice from the
|
||||||
// current one to the next one.
|
// current one to the next one.
|
||||||
@ -318,7 +312,30 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||||||
maybeStartLoading();
|
maybeStartLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current extractor from which samples should be read.
|
||||||
|
* <p>
|
||||||
|
* Calling this method discards extractors without any samples from the front of the queue. The
|
||||||
|
* last extractor is retained even if it doesn't have any samples.
|
||||||
|
* <p>
|
||||||
|
* This method must not be called unless {@link #extractors} is non-empty.
|
||||||
|
*
|
||||||
|
* @return The current extractor from which samples should be read. Guaranteed to be non-null.
|
||||||
|
*/
|
||||||
|
private TsExtractor getCurrentExtractor() {
|
||||||
|
TsExtractor 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();
|
||||||
|
extractor = extractors.getFirst();
|
||||||
|
}
|
||||||
|
return extractor;
|
||||||
|
}
|
||||||
|
|
||||||
private void discardSamplesForDisabledTracks(TsExtractor extractor, long timeUs) {
|
private void discardSamplesForDisabledTracks(TsExtractor extractor, long timeUs) {
|
||||||
|
if (!extractor.isPrepared()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (int i = 0; i < trackEnabledStates.length; i++) {
|
for (int i = 0; i < trackEnabledStates.length; i++) {
|
||||||
if (!trackEnabledStates[i]) {
|
if (!trackEnabledStates[i]) {
|
||||||
extractor.discardUntil(i, timeUs);
|
extractor.discardUntil(i, timeUs);
|
||||||
@ -327,6 +344,9 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean haveSamplesForEnabledTracks(TsExtractor extractor) {
|
private boolean haveSamplesForEnabledTracks(TsExtractor extractor) {
|
||||||
|
if (!extractor.isPrepared()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (int i = 0; i < trackEnabledStates.length; i++) {
|
for (int i = 0; i < trackEnabledStates.length; i++) {
|
||||||
if (trackEnabledStates[i] && extractor.hasSamples(i)) {
|
if (trackEnabledStates[i] && extractor.hasSamples(i)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -205,6 +205,7 @@ public final class TsExtractor {
|
|||||||
* for the specified track. False otherwise.
|
* for the specified track. False otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean hasSamples(int track) {
|
public boolean hasSamples(int track) {
|
||||||
|
Assertions.checkState(prepared);
|
||||||
return sampleQueues.valueAt(track).peek() != null;
|
return sampleQueues.valueAt(track).peek() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user