Skip to content

Commit

Permalink
SampleStream fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ojw28 committed Nov 22, 2017
1 parent 75b9062 commit 3562fe1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public long seekToUs(long positionUs) {
// SampleStream methods.

/* package */ boolean isReady(int track) {
return loadingFinished || (!isPendingReset() && sampleQueues[track].hasNextSample());
return !suppressRead() && (loadingFinished || sampleQueues[track].hasNextSample());
}

/* package */ void maybeThrowError() throws IOException {
Expand All @@ -370,14 +370,17 @@ public long seekToUs(long positionUs) {

/* package */ int readData(int track, FormatHolder formatHolder, DecoderInputBuffer buffer,
boolean formatRequired) {
if (notifyDiscontinuity || isPendingReset()) {
if (suppressRead()) {
return C.RESULT_NOTHING_READ;
}
return sampleQueues[track].read(formatHolder, buffer, formatRequired, loadingFinished,
lastSeekPositionUs);
}

/* package */ int skipData(int track, long positionUs) {
if (suppressRead()) {
return 0;
}
SampleQueue sampleQueue = sampleQueues[track];
if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) {
return sampleQueue.advanceToEnd();
Expand All @@ -387,6 +390,10 @@ public long seekToUs(long positionUs) {
}
}

private boolean suppressRead() {
return notifyDiscontinuity || isPendingReset();
}

// Loader.Callback implementation.

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,21 @@ public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer,

@Override
public int skipData(long positionUs) {
if (isPendingReset()) {
return 0;
}
int skipCount;
if (loadingFinished && positionUs > primarySampleQueue.getLargestQueuedTimestampUs()) {
primarySampleQueue.advanceToEnd();
skipCount = primarySampleQueue.advanceToEnd();
} else {
skipCount = primarySampleQueue.advanceTo(positionUs, true, true);
if (skipCount == SampleQueue.ADVANCE_FAILED) {
skipCount = 0;
}
}
primarySampleQueue.discardToRead();
if (skipCount > 0) {
primarySampleQueue.discardToRead();
}
return skipCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,35 @@ public int readData(int trackGroupIndex, FormatHolder formatHolder,
if (isPendingReset()) {
return C.RESULT_NOTHING_READ;
}
int result = sampleQueues[trackGroupIndex].read(formatHolder, buffer, requireFormat,
loadingFinished, lastSeekPositionUs);
if (result == C.RESULT_BUFFER_READ) {
discardToRead();
}
return result;
}

public int skipData(int trackGroupIndex, long positionUs) {
if (isPendingReset()) {
return 0;
}
int skipCount;
SampleQueue sampleQueue = sampleQueues[trackGroupIndex];
if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) {
skipCount = sampleQueue.advanceToEnd();
} else {
skipCount = sampleQueue.advanceTo(positionUs, true, true);
if (skipCount == SampleQueue.ADVANCE_FAILED) {
skipCount = 0;
}
}
if (skipCount > 0) {
discardToRead();
}
return skipCount;
}

private void discardToRead() {
if (!mediaChunks.isEmpty()) {
while (mediaChunks.size() > 1 && finishedReadingChunk(mediaChunks.getFirst())) {
mediaChunks.removeFirst();
Expand All @@ -399,19 +427,6 @@ public int readData(int trackGroupIndex, FormatHolder formatHolder,
}
downstreamTrackFormat = trackFormat;
}

return sampleQueues[trackGroupIndex].read(formatHolder, buffer, requireFormat, loadingFinished,
lastSeekPositionUs);
}

public int skipData(int trackGroupIndex, long positionUs) {
SampleQueue sampleQueue = sampleQueues[trackGroupIndex];
if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) {
return sampleQueue.advanceToEnd();
} else {
int skipCount = sampleQueue.advanceTo(positionUs, true, true);
return skipCount == SampleQueue.ADVANCE_FAILED ? 0 : skipCount;
}
}

private boolean finishedReadingChunk(HlsMediaChunk chunk) {
Expand Down

0 comments on commit 3562fe1

Please sign in to comment.