Skip to content

Commit

Permalink
Deduplicate reported position discontinuities
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=142257743
  • Loading branch information
ojw28 committed Dec 16, 2016
1 parent e0586a4 commit 4bb8793
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ private static final class PlayerWrapper implements ExoPlayer.EventListener {
private Format expectedFormat;
private ExoPlayer player;
private Exception exception;
private boolean seenPositionDiscontinuity;

public PlayerWrapper() {
endedCountDownLatch = new CountDownLatch(1);
Expand Down Expand Up @@ -121,7 +120,7 @@ public void run() {
player.setPlayWhenReady(true);
player.prepare(new FakeMediaSource(timeline, manifest, format));
} catch (Exception e) {
handlePlayerException(e);
handleError(e);
}
}
});
Expand All @@ -136,7 +135,7 @@ public void run() {
player.release();
}
} catch (Exception e) {
handlePlayerException(e);
handleError(e);
} finally {
playerThread.quit();
}
Expand All @@ -145,7 +144,7 @@ public void run() {
playerThread.join();
}

private void handlePlayerException(Exception exception) {
private void handleError(Exception exception) {
if (this.exception == null) {
this.exception = exception;
}
Expand Down Expand Up @@ -180,20 +179,13 @@ public void onTracksChanged(TrackGroupArray trackGroups,

@Override
public void onPlayerError(ExoPlaybackException exception) {
this.exception = exception;
endedCountDownLatch.countDown();
handleError(exception);
}

@Override
public void onPositionDiscontinuity() {
assertFalse(seenPositionDiscontinuity);
assertEquals(0, player.getCurrentWindowIndex());
assertEquals(0, player.getCurrentPeriodIndex());
assertEquals(0, player.getCurrentPosition());
assertEquals(0, player.getBufferedPosition());
assertEquals(expectedTimeline, player.getCurrentTimeline());
assertEquals(expectedManifest, player.getCurrentManifest());
seenPositionDiscontinuity = true;
// Should never happen.
handleError(new IllegalStateException("Received position discontinuity"));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,10 @@ public Object getCurrentManifest() {
case ExoPlayerImplInternal.MSG_SEEK_ACK: {
if (--pendingSeekAcks == 0) {
playbackInfo = (ExoPlayerImplInternal.PlaybackInfo) msg.obj;
for (EventListener listener : listeners) {
listener.onPositionDiscontinuity();
if (msg.arg1 != 0) {
for (EventListener listener : listeners) {
listener.onPositionDiscontinuity();
}
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ private void seekToInternal(SeekPosition seekPosition) throws ExoPlaybackExcepti
// The seek position was valid for the timeline that it was performed into, but the
// timeline has changed and a suitable seek position could not be resolved in the new one.
playbackInfo = new PlaybackInfo(0, 0);
eventHandler.obtainMessage(MSG_SEEK_ACK, playbackInfo).sendToTarget();
eventHandler.obtainMessage(MSG_SEEK_ACK, 1, 0, playbackInfo).sendToTarget();
// Set the internal position to (0,TIME_UNSET) so that a subsequent seek to (0,0) isn't
// ignored.
playbackInfo = new PlaybackInfo(0, C.TIME_UNSET);
Expand All @@ -569,6 +569,7 @@ private void seekToInternal(SeekPosition seekPosition) throws ExoPlaybackExcepti
return;
}

boolean seekPositionAdjusted = seekPosition.windowPositionUs == C.TIME_UNSET;
int periodIndex = periodPosition.first;
long periodPositionUs = periodPosition.second;

Expand All @@ -578,10 +579,13 @@ private void seekToInternal(SeekPosition seekPosition) throws ExoPlaybackExcepti
// Seek position equals the current position. Do nothing.
return;
}
periodPositionUs = seekToPeriodPosition(periodIndex, periodPositionUs);
long newPeriodPositionUs = seekToPeriodPosition(periodIndex, periodPositionUs);
seekPositionAdjusted |= periodPositionUs != newPeriodPositionUs;
periodPositionUs = newPeriodPositionUs;
} finally {
playbackInfo = new PlaybackInfo(periodIndex, periodPositionUs);
eventHandler.obtainMessage(MSG_SEEK_ACK, playbackInfo).sendToTarget();
eventHandler.obtainMessage(MSG_SEEK_ACK, seekPositionAdjusted ? 1 : 0, 0, playbackInfo)
.sendToTarget();
}
}

Expand Down

0 comments on commit 4bb8793

Please sign in to comment.