Deduplicate reported position discontinuities

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=142257743
This commit is contained in:
olly 2016-12-16 07:24:51 -08:00 committed by Oliver Woodman
parent e0586a48f0
commit 4bb8793203
3 changed files with 17 additions and 19 deletions

View file

@ -84,7 +84,6 @@ public final class ExoPlayerTest extends TestCase {
private Format expectedFormat;
private ExoPlayer player;
private Exception exception;
private boolean seenPositionDiscontinuity;
public PlayerWrapper() {
endedCountDownLatch = new CountDownLatch(1);
@ -121,7 +120,7 @@ public final class ExoPlayerTest extends TestCase {
player.setPlayWhenReady(true);
player.prepare(new FakeMediaSource(timeline, manifest, format));
} catch (Exception e) {
handlePlayerException(e);
handleError(e);
}
}
});
@ -136,7 +135,7 @@ public final class ExoPlayerTest extends TestCase {
player.release();
}
} catch (Exception e) {
handlePlayerException(e);
handleError(e);
} finally {
playerThread.quit();
}
@ -145,7 +144,7 @@ public final class ExoPlayerTest extends TestCase {
playerThread.join();
}
private void handlePlayerException(Exception exception) {
private void handleError(Exception exception) {
if (this.exception == null) {
this.exception = exception;
}
@ -180,20 +179,13 @@ public final class ExoPlayerTest extends TestCase {
@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"));
}
}

View file

@ -332,8 +332,10 @@ import java.util.concurrent.CopyOnWriteArraySet;
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;

View file

@ -559,7 +559,7 @@ import java.io.IOException;
// 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);
@ -569,6 +569,7 @@ import java.io.IOException;
return;
}
boolean seekPositionAdjusted = seekPosition.windowPositionUs == C.TIME_UNSET;
int periodIndex = periodPosition.first;
long periodPositionUs = periodPosition.second;
@ -578,10 +579,13 @@ import java.io.IOException;
// 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();
}
}