Skip to content

Commit

Permalink
Correctly transition to ended state
Browse files Browse the repository at this point in the history
This fixes transitioning into the ended state if we see
endOfStream from the chunk source whilst in the pending
reset state. Prior to this fix we'd still be pending a
reset, and so readData would never allow EOS to be read
by the consuming renderer.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=157101755
  • Loading branch information
ojw28 committed May 25, 2017
1 parent eb3a31c commit c4f7a2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ public boolean continueLoading(long positionUs) {
nextChunkHolder.clear();

if (endOfStream) {
pendingResetPositionUs = C.TIME_UNSET;
loadingFinished = true;
return true;
}
Expand Down Expand Up @@ -389,18 +390,20 @@ private boolean isMediaChunk(Chunk chunk) {
}

private void discardDownstreamMediaChunks(int primaryStreamReadIndex) {
while (mediaChunks.size() > 1
&& mediaChunks.get(1).getFirstSampleIndex(0) <= primaryStreamReadIndex) {
mediaChunks.removeFirst();
}
BaseMediaChunk currentChunk = mediaChunks.getFirst();
Format trackFormat = currentChunk.trackFormat;
if (!trackFormat.equals(primaryDownstreamTrackFormat)) {
eventDispatcher.downstreamFormatChanged(primaryTrackType, trackFormat,
currentChunk.trackSelectionReason, currentChunk.trackSelectionData,
currentChunk.startTimeUs);
if (!mediaChunks.isEmpty()) {
while (mediaChunks.size() > 1
&& mediaChunks.get(1).getFirstSampleIndex(0) <= primaryStreamReadIndex) {
mediaChunks.removeFirst();
}
BaseMediaChunk currentChunk = mediaChunks.getFirst();
Format trackFormat = currentChunk.trackFormat;
if (!trackFormat.equals(primaryDownstreamTrackFormat)) {
eventDispatcher.downstreamFormatChanged(primaryTrackType, trackFormat,
currentChunk.trackSelectionReason, currentChunk.trackSelectionData,
currentChunk.startTimeUs);
}
primaryDownstreamTrackFormat = trackFormat;
}
primaryDownstreamTrackFormat = trackFormat;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,9 @@ private static final class DashTimeline extends Timeline {
private final long windowDefaultStartPositionUs;
private final DashManifest manifest;

public DashTimeline(long presentationStartTimeMs, long windowStartTimeMs,
int firstPeriodId, long offsetInFirstPeriodUs, long windowDurationUs,
long windowDefaultStartPositionUs, DashManifest manifest) {
public DashTimeline(long presentationStartTimeMs, long windowStartTimeMs, int firstPeriodId,
long offsetInFirstPeriodUs, long windowDurationUs, long windowDefaultStartPositionUs,
DashManifest manifest) {
this.presentationStartTimeMs = presentationStartTimeMs;
this.windowStartTimeMs = windowStartTimeMs;
this.firstPeriodId = firstPeriodId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,19 @@ public void onPlaylistBlacklisted(HlsUrl url, long blacklistMs) {
return C.RESULT_NOTHING_READ;
}

while (mediaChunks.size() > 1 && finishedReadingChunk(mediaChunks.getFirst())) {
mediaChunks.removeFirst();
}
HlsMediaChunk currentChunk = mediaChunks.getFirst();
Format trackFormat = currentChunk.trackFormat;
if (!trackFormat.equals(downstreamTrackFormat)) {
eventDispatcher.downstreamFormatChanged(trackType, trackFormat,
currentChunk.trackSelectionReason, currentChunk.trackSelectionData,
currentChunk.startTimeUs);
if (!mediaChunks.isEmpty()) {
while (mediaChunks.size() > 1 && finishedReadingChunk(mediaChunks.getFirst())) {
mediaChunks.removeFirst();
}
HlsMediaChunk currentChunk = mediaChunks.getFirst();
Format trackFormat = currentChunk.trackFormat;
if (!trackFormat.equals(downstreamTrackFormat)) {
eventDispatcher.downstreamFormatChanged(trackType, trackFormat,
currentChunk.trackSelectionReason, currentChunk.trackSelectionData,
currentChunk.startTimeUs);
}
downstreamTrackFormat = trackFormat;
}
downstreamTrackFormat = trackFormat;

return sampleQueues.valueAt(group).readData(formatHolder, buffer, requireFormat,
loadingFinished, lastSeekPositionUs);
Expand Down Expand Up @@ -348,6 +350,7 @@ public boolean continueLoading(long positionUs) {
nextChunkHolder.clear();

if (endOfStream) {
pendingResetPositionUs = C.TIME_UNSET;
loadingFinished = true;
return true;
}
Expand Down

0 comments on commit c4f7a2d

Please sign in to comment.