From fa3052d36b78455c80ce7b23e6526edc092b0561 Mon Sep 17 00:00:00 2001 From: olly Date: Mon, 20 Nov 2017 08:56:23 -0800 Subject: [PATCH] Report additional position discontinuities - Properly report internal discontinuities - Add DISCONTINUITY_REASON_SEEK_ADJUSTMENT to distinguish seek adjustments from other internal discontinuity events ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=176367365 --- RELEASENOTES.md | 4 ++++ .../android/exoplayer2/demo/EventLogger.java | 2 ++ .../google/android/exoplayer2/ExoPlayerImpl.java | 15 ++++++++------- .../android/exoplayer2/ExoPlayerImplInternal.java | 12 ++++++++++-- .../com/google/android/exoplayer2/Player.java | 9 +++++++-- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 13218f073f..579c2a92ac 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -11,6 +11,10 @@ * SimpleExoPlayer: Support for multiple video, text and metadata outputs. * Support for `Renderer`s that don't consume any media ([#3212](https://github.com/google/ExoPlayer/issues/3212)). +* Fix reporting of internal position discontinuities via + `Player.onPositionDiscontinuity`. `DISCONTINUITY_REASON_SEEK_ADJUSTMENT` is + added to disambiguate position adjustments during seeks from other types of + internal position discontinuity. * Fix potential `IndexOutOfBoundsException` when calling `ExoPlayer.getDuration` ([#3362](https://github.com/google/ExoPlayer/issues/3362)). * Fix playbacks involving looping, concatenation and ads getting stuck when diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/EventLogger.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/EventLogger.java index 68f7ddfd21..27a5c68e28 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/EventLogger.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/EventLogger.java @@ -496,6 +496,8 @@ import java.util.Locale; return "PERIOD_TRANSITION"; case Player.DISCONTINUITY_REASON_SEEK: return "SEEK"; + case Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT: + return "SEEK_ADJUSTMENT"; case Player.DISCONTINUITY_REASON_INTERNAL: return "INTERNAL"; default: diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java index 8ee8af5980..349751eb59 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java @@ -473,7 +473,8 @@ import java.util.concurrent.CopyOnWriteArraySet; case ExoPlayerImplInternal.MSG_SOURCE_INFO_REFRESHED: { int prepareAcks = msg.arg1; int seekAcks = msg.arg2; - handlePlaybackInfo((PlaybackInfo) msg.obj, prepareAcks, seekAcks, false); + handlePlaybackInfo((PlaybackInfo) msg.obj, prepareAcks, seekAcks, false, + /* ignored */ DISCONTINUITY_REASON_INTERNAL); break; } case ExoPlayerImplInternal.MSG_TRACKS_CHANGED: { @@ -491,11 +492,13 @@ import java.util.concurrent.CopyOnWriteArraySet; } case ExoPlayerImplInternal.MSG_SEEK_ACK: { boolean seekPositionAdjusted = msg.arg1 != 0; - handlePlaybackInfo((PlaybackInfo) msg.obj, 0, 1, seekPositionAdjusted); + handlePlaybackInfo((PlaybackInfo) msg.obj, 0, 1, seekPositionAdjusted, + DISCONTINUITY_REASON_SEEK_ADJUSTMENT); break; } case ExoPlayerImplInternal.MSG_POSITION_DISCONTINUITY: { - handlePlaybackInfo((PlaybackInfo) msg.obj, 0, 0, true); + @DiscontinuityReason int discontinuityReason = msg.arg1; + handlePlaybackInfo((PlaybackInfo) msg.obj, 0, 0, true, discontinuityReason); break; } case ExoPlayerImplInternal.MSG_PLAYBACK_PARAMETERS_CHANGED: { @@ -521,7 +524,7 @@ import java.util.concurrent.CopyOnWriteArraySet; } private void handlePlaybackInfo(PlaybackInfo playbackInfo, int prepareAcks, int seekAcks, - boolean positionDiscontinuity) { + boolean positionDiscontinuity, @DiscontinuityReason int positionDiscontinuityReason) { Assertions.checkNotNull(playbackInfo.timeline); pendingPrepareAcks -= prepareAcks; pendingSeekAcks -= seekAcks; @@ -542,9 +545,7 @@ import java.util.concurrent.CopyOnWriteArraySet; } if (positionDiscontinuity) { for (Player.EventListener listener : listeners) { - listener.onPositionDiscontinuity( - seekAcks > 0 ? DISCONTINUITY_REASON_INTERNAL : DISCONTINUITY_REASON_PERIOD_TRANSITION - ); + listener.onPositionDiscontinuity(positionDiscontinuityReason); } } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index f00a5ce02d..56e16343ed 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -503,6 +503,10 @@ import java.io.IOException; long periodPositionUs = playingPeriodHolder.mediaPeriod.readDiscontinuity(); if (periodPositionUs != C.TIME_UNSET) { resetRendererPosition(periodPositionUs); + playbackInfo = playbackInfo.fromNewPosition(playbackInfo.periodId, periodPositionUs, + playbackInfo.contentPositionUs); + eventHandler.obtainMessage(MSG_POSITION_DISCONTINUITY, Player.DISCONTINUITY_REASON_INTERNAL, + 0, playbackInfo).sendToTarget(); } else { // Use the standalone clock if there's no renderer clock, or if the providing renderer has // ended or needs the next sample stream to reenter the ready state. The latter case uses the @@ -893,7 +897,10 @@ import java.io.IOException; long periodPositionUs = playingPeriodHolder.updatePeriodTrackSelection( playbackInfo.positionUs, recreateStreams, streamResetFlags); if (periodPositionUs != playbackInfo.positionUs) { - playbackInfo.positionUs = periodPositionUs; + playbackInfo = playbackInfo.fromNewPosition(playbackInfo.periodId, periodPositionUs, + playbackInfo.contentPositionUs); + eventHandler.obtainMessage(MSG_POSITION_DISCONTINUITY, Player.DISCONTINUITY_REASON_INTERNAL, + 0, playbackInfo).sendToTarget(); resetRendererPosition(periodPositionUs); } @@ -1280,7 +1287,8 @@ import java.io.IOException; playbackInfo = playbackInfo.fromNewPosition(playingPeriodHolder.info.id, playingPeriodHolder.info.startPositionUs, playingPeriodHolder.info.contentPositionUs); updatePlaybackPositions(); - eventHandler.obtainMessage(MSG_POSITION_DISCONTINUITY, playbackInfo).sendToTarget(); + eventHandler.obtainMessage(MSG_POSITION_DISCONTINUITY, + Player.DISCONTINUITY_REASON_PERIOD_TRANSITION, 0, playbackInfo).sendToTarget(); } if (readingPeriodHolder.info.isFinal) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/Player.java b/library/core/src/main/java/com/google/android/exoplayer2/Player.java index af653ec2bd..dc703f924a 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/Player.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/Player.java @@ -243,7 +243,7 @@ public interface Player { */ @Retention(RetentionPolicy.SOURCE) @IntDef({DISCONTINUITY_REASON_PERIOD_TRANSITION, DISCONTINUITY_REASON_SEEK, - DISCONTINUITY_REASON_INTERNAL}) + DISCONTINUITY_REASON_SEEK_ADJUSTMENT, DISCONTINUITY_REASON_INTERNAL}) public @interface DiscontinuityReason {} /** * Automatic playback transition from one period in the timeline to the next. The period index may @@ -254,10 +254,15 @@ public interface Player { * Seek within the current period or to another period. */ int DISCONTINUITY_REASON_SEEK = 1; + /** + * Seek adjustment due to being unable to seek to the requested position or because the seek was + * permitted to be inexact. + */ + int DISCONTINUITY_REASON_SEEK_ADJUSTMENT = 2; /** * Discontinuity introduced internally by the source. */ - int DISCONTINUITY_REASON_INTERNAL = 2; + int DISCONTINUITY_REASON_INTERNAL = 3; /** * Register a listener to receive events from the player. The listener's methods will be called on