Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5c2f6186
authored
Dec 07, 2021
by
ibaker
Committed by
Ian Baker
Dec 08, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Migrate usages of Timeline#getPeriodPosition to getPeriodPositionUs
#minor-release PiperOrigin-RevId: 414671861
parent
07352a45
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
124 additions
and
95 deletions
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java
library/common/src/main/java/com/google/android/exoplayer2/Timeline.java
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java
library/core/src/main/java/com/google/android/exoplayer2/MediaPeriodQueue.java
library/core/src/main/java/com/google/android/exoplayer2/source/MaskingMediaSource.java
library/core/src/test/java/com/google/android/exoplayer2/source/SinglePeriodTimelineTest.java
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java
View file @
5c2f6186
...
...
@@ -700,7 +700,7 @@ public final class ImaAdsLoader implements Player.Listener, AdsLoader {
return
;
}
long
periodPositionUs
=
timeline
.
getPeriodPosition
(
timeline
.
getPeriodPosition
Us
(
window
,
period
,
period
.
windowIndex
,
/* windowPositionUs= */
C
.
TIME_UNSET
)
.
second
;
nextAdTagLoader
.
maybePreloadAds
(
Util
.
usToMs
(
periodPositionUs
),
Util
.
usToMs
(
period
.
durationUs
));
...
...
library/common/src/main/java/com/google/android/exoplayer2/Timeline.java
View file @
5c2f6186
...
...
@@ -1190,13 +1190,13 @@ public abstract class Timeline implements Bundleable {
}
/**
* Calls {@link #getPeriodPosition
(Window, Period, int, long
, long)} with a zero default position
* Calls {@link #getPeriodPosition
Us(Window, Period, int
, long)} with a zero default position
* projection.
*/
public
final
Pair
<
Object
,
Long
>
getPeriodPositionUs
(
Window
window
,
Period
period
,
int
windowIndex
,
long
windowPositionUs
)
{
return
Assertions
.
checkNotNull
(
getPeriodPosition
(
getPeriodPosition
Us
(
window
,
period
,
windowIndex
,
windowPositionUs
,
/* defaultPositionProjectionUs= */
0
));
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java
View file @
5c2f6186
...
...
@@ -499,7 +499,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
maskTimelineAndPosition
(
playbackInfo
,
newTimeline
,
getPeriodPositionAfterTimelineChanged
(
oldTimeline
,
newTimeline
));
getPeriodPosition
Us
AfterTimelineChanged
(
oldTimeline
,
newTimeline
));
internalPlayer
.
addMediaSources
(
index
,
holders
,
shuffleOrder
);
updatePlaybackInfo
(
newPlaybackInfo
,
...
...
@@ -543,7 +543,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
maskTimelineAndPosition
(
playbackInfo
,
newTimeline
,
getPeriodPositionAfterTimelineChanged
(
oldTimeline
,
newTimeline
));
getPeriodPosition
Us
AfterTimelineChanged
(
oldTimeline
,
newTimeline
));
internalPlayer
.
moveMediaSources
(
fromIndex
,
toIndex
,
newFromIndex
,
shuffleOrder
);
updatePlaybackInfo
(
newPlaybackInfo
,
...
...
@@ -562,7 +562,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
maskTimelineAndPosition
(
playbackInfo
,
timeline
,
getPeriodPositionOrMaskWindowPosition
(
maskWindowPositionMsOrGetPeriodPositionUs
(
timeline
,
getCurrentMediaItemIndex
(),
getCurrentPosition
()));
pendingOperationAcks
++;
this
.
shuffleOrder
=
shuffleOrder
;
...
...
@@ -680,7 +680,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
maskTimelineAndPosition
(
newPlaybackInfo
,
timeline
,
getPeriodPositionOrMaskWindowPosition
(
timeline
,
mediaItemIndex
,
positionMs
));
maskWindowPositionMsOrGetPeriodPositionUs
(
timeline
,
mediaItemIndex
,
positionMs
));
internalPlayer
.
seekTo
(
timeline
,
mediaItemIndex
,
Util
.
msToUs
(
positionMs
));
updatePlaybackInfo
(
newPlaybackInfo
,
...
...
@@ -1441,7 +1441,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
maskTimelineAndPosition
(
playbackInfo
,
timeline
,
getPeriodPositionOrMaskWindowPosition
(
timeline
,
startWindowIndex
,
startPositionMs
));
maskWindowPositionMsOrGetPeriodPositionUs
(
timeline
,
startWindowIndex
,
startPositionMs
));
// Mask the playback state.
int
maskingPlaybackState
=
newPlaybackInfo
.
playbackState
;
if
(
startWindowIndex
!=
C
.
INDEX_UNSET
&&
newPlaybackInfo
.
playbackState
!=
STATE_IDLE
)
{
...
...
@@ -1499,7 +1499,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
maskTimelineAndPosition
(
playbackInfo
,
newTimeline
,
getPeriodPositionAfterTimelineChanged
(
oldTimeline
,
newTimeline
));
getPeriodPosition
Us
AfterTimelineChanged
(
oldTimeline
,
newTimeline
));
// Player transitions to STATE_ENDED if the current index is part of the removed tail.
final
boolean
transitionsToEnded
=
newPlaybackInfo
.
playbackState
!=
STATE_IDLE
...
...
@@ -1526,8 +1526,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
}
private
PlaybackInfo
maskTimelineAndPosition
(
PlaybackInfo
playbackInfo
,
Timeline
timeline
,
@Nullable
Pair
<
Object
,
Long
>
periodPosition
)
{
Assertions
.
checkArgument
(
timeline
.
isEmpty
()
||
periodPosition
!=
null
);
PlaybackInfo
playbackInfo
,
Timeline
timeline
,
@Nullable
Pair
<
Object
,
Long
>
periodPosition
Us
)
{
Assertions
.
checkArgument
(
timeline
.
isEmpty
()
||
periodPosition
Us
!=
null
);
Timeline
oldTimeline
=
playbackInfo
.
timeline
;
// Mask the timeline.
playbackInfo
=
playbackInfo
.
copyWithTimeline
(
timeline
);
...
...
@@ -1552,10 +1552,10 @@ import java.util.concurrent.CopyOnWriteArraySet;
}
Object
oldPeriodUid
=
playbackInfo
.
periodId
.
periodUid
;
boolean
playingPeriodChanged
=
!
oldPeriodUid
.
equals
(
castNonNull
(
periodPosition
).
first
);
boolean
playingPeriodChanged
=
!
oldPeriodUid
.
equals
(
castNonNull
(
periodPosition
Us
).
first
);
MediaPeriodId
newPeriodId
=
playingPeriodChanged
?
new
MediaPeriodId
(
periodPosition
.
first
)
:
playbackInfo
.
periodId
;
long
newContentPositionUs
=
periodPosition
.
second
;
playingPeriodChanged
?
new
MediaPeriodId
(
periodPosition
Us
.
first
)
:
playbackInfo
.
periodId
;
long
newContentPositionUs
=
periodPosition
Us
.
second
;
long
oldContentPositionUs
=
Util
.
msToUs
(
getContentPosition
());
if
(!
oldTimeline
.
isEmpty
())
{
oldContentPositionUs
-=
...
...
@@ -1631,25 +1631,25 @@ import java.util.concurrent.CopyOnWriteArraySet;
}
@Nullable
private
Pair
<
Object
,
Long
>
getPeriodPositionAfterTimelineChanged
(
private
Pair
<
Object
,
Long
>
getPeriodPosition
Us
AfterTimelineChanged
(
Timeline
oldTimeline
,
Timeline
newTimeline
)
{
long
currentPositionMs
=
getContentPosition
();
if
(
oldTimeline
.
isEmpty
()
||
newTimeline
.
isEmpty
())
{
boolean
isCleared
=
!
oldTimeline
.
isEmpty
()
&&
newTimeline
.
isEmpty
();
return
getPeriodPositionOrMaskWindowPosition
(
return
maskWindowPositionMsOrGetPeriodPositionUs
(
newTimeline
,
isCleared
?
C
.
INDEX_UNSET
:
getCurrentWindowIndexInternal
(),
isCleared
?
C
.
TIME_UNSET
:
currentPositionMs
);
}
int
currentMediaItemIndex
=
getCurrentMediaItemIndex
();
@Nullable
Pair
<
Object
,
Long
>
oldPeriodPosition
=
oldTimeline
.
getPeriodPosition
(
Pair
<
Object
,
Long
>
oldPeriodPosition
Us
=
oldTimeline
.
getPeriodPosition
Us
(
window
,
period
,
currentMediaItemIndex
,
Util
.
msToUs
(
currentPositionMs
));
Object
periodUid
=
castNonNull
(
oldPeriodPosition
).
first
;
Object
periodUid
=
castNonNull
(
oldPeriodPosition
Us
).
first
;
if
(
newTimeline
.
getIndexOfPeriod
(
periodUid
)
!=
C
.
INDEX_UNSET
)
{
// The old period position is still available in the new timeline.
return
oldPeriodPosition
;
return
oldPeriodPosition
Us
;
}
// Period uid not found in new timeline. Try to get subsequent period.
@Nullable
...
...
@@ -1659,19 +1659,19 @@ import java.util.concurrent.CopyOnWriteArraySet;
if
(
nextPeriodUid
!=
null
)
{
// Reset position to the default position of the window of the subsequent period.
newTimeline
.
getPeriodByUid
(
nextPeriodUid
,
period
);
return
getPeriodPositionOrMaskWindowPosition
(
return
maskWindowPositionMsOrGetPeriodPositionUs
(
newTimeline
,
period
.
windowIndex
,
newTimeline
.
getWindow
(
period
.
windowIndex
,
window
).
getDefaultPositionMs
());
}
else
{
// No subsequent period found and the new timeline is not empty. Use the default position.
return
getPeriodPositionOrMaskWindowPosition
(
return
maskWindowPositionMsOrGetPeriodPositionUs
(
newTimeline
,
/* windowIndex= */
C
.
INDEX_UNSET
,
/* windowPositionMs= */
C
.
TIME_UNSET
);
}
}
@Nullable
private
Pair
<
Object
,
Long
>
getPeriodPositionOrMaskWindowPosition
(
private
Pair
<
Object
,
Long
>
maskWindowPositionMsOrGetPeriodPositionUs
(
Timeline
timeline
,
int
windowIndex
,
long
windowPositionMs
)
{
if
(
timeline
.
isEmpty
())
{
// If empty we store the initial seek in the masking variables.
...
...
@@ -1686,7 +1686,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
windowIndex
=
timeline
.
getFirstWindowIndex
(
shuffleModeEnabled
);
windowPositionMs
=
timeline
.
getWindow
(
windowIndex
,
window
).
getDefaultPositionMs
();
}
return
timeline
.
getPeriodPosition
(
window
,
period
,
windowIndex
,
Util
.
msToUs
(
windowPositionMs
));
return
timeline
.
getPeriodPosition
Us
(
window
,
period
,
windowIndex
,
Util
.
msToUs
(
windowPositionMs
));
}
private
long
periodPositionUsToWindowPositionUs
(
...
...
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java
View file @
5c2f6186
...
...
@@ -1123,7 +1123,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
boolean
seekPositionAdjusted
;
@Nullable
Pair
<
Object
,
Long
>
resolvedSeekPosition
=
resolveSeekPosition
(
resolveSeekPosition
Us
(
playbackInfo
.
timeline
,
seekPosition
,
/* trySubsequentPeriods= */
true
,
...
...
@@ -1134,10 +1134,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
if
(
resolvedSeekPosition
==
null
)
{
// The seek position was valid for the timeline that it was performed into, but the
// timeline has changed or is not ready and a suitable seek position could not be resolved.
Pair
<
MediaPeriodId
,
Long
>
firstPeriodAndPosition
=
getPlaceholderFirstMediaPeriodPosition
(
playbackInfo
.
timeline
);
periodId
=
firstPeriodAndPosition
.
first
;
periodPositionUs
=
firstPeriodAndPosition
.
second
;
Pair
<
MediaPeriodId
,
Long
>
firstPeriodAndPosition
Us
=
getPlaceholderFirstMediaPeriodPosition
Us
(
playbackInfo
.
timeline
);
periodId
=
firstPeriodAndPosition
Us
.
first
;
periodPositionUs
=
firstPeriodAndPosition
Us
.
second
;
requestedContentPositionUs
=
C
.
TIME_UNSET
;
seekPositionAdjusted
=
!
playbackInfo
.
timeline
.
isEmpty
();
}
else
{
...
...
@@ -1412,10 +1412,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
boolean
resetTrackInfo
=
false
;
if
(
resetPosition
)
{
pendingInitialSeekPosition
=
null
;
Pair
<
MediaPeriodId
,
Long
>
firstPeriodAndPosition
=
getPlaceholderFirstMediaPeriodPosition
(
playbackInfo
.
timeline
);
mediaPeriodId
=
firstPeriodAndPosition
.
first
;
startPositionUs
=
firstPeriodAndPosition
.
second
;
Pair
<
MediaPeriodId
,
Long
>
firstPeriodAndPosition
Us
=
getPlaceholderFirstMediaPeriodPosition
Us
(
playbackInfo
.
timeline
);
mediaPeriodId
=
firstPeriodAndPosition
Us
.
first
;
startPositionUs
=
firstPeriodAndPosition
Us
.
second
;
requestedContentPositionUs
=
C
.
TIME_UNSET
;
if
(!
mediaPeriodId
.
equals
(
playbackInfo
.
periodId
))
{
resetTrackInfo
=
true
;
...
...
@@ -1451,19 +1451,19 @@ import java.util.concurrent.atomic.AtomicBoolean;
}
}
private
Pair
<
MediaPeriodId
,
Long
>
getPlaceholderFirstMediaPeriodPosition
(
Timeline
timeline
)
{
private
Pair
<
MediaPeriodId
,
Long
>
getPlaceholderFirstMediaPeriodPosition
Us
(
Timeline
timeline
)
{
if
(
timeline
.
isEmpty
())
{
return
Pair
.
create
(
PlaybackInfo
.
getDummyPeriodForEmptyTimeline
(),
0L
);
}
int
firstWindowIndex
=
timeline
.
getFirstWindowIndex
(
shuffleModeEnabled
);
Pair
<
Object
,
Long
>
firstPeriodAndPosition
=
timeline
.
getPeriodPosition
(
Pair
<
Object
,
Long
>
firstPeriodAndPosition
Us
=
timeline
.
getPeriodPosition
Us
(
window
,
period
,
firstWindowIndex
,
/* windowPositionUs= */
C
.
TIME_UNSET
);
// Add ad metadata if any and propagate the window sequence number to new period id.
MediaPeriodId
firstPeriodId
=
queue
.
resolveMediaPeriodIdForAds
(
timeline
,
firstPeriodAndPosition
.
first
,
/* positionUs= */
0
);
long
positionUs
=
firstPeriodAndPosition
.
second
;
timeline
,
firstPeriodAndPosition
Us
.
first
,
/* positionUs= */
0
);
long
positionUs
=
firstPeriodAndPosition
Us
.
second
;
if
(
firstPeriodId
.
isAd
())
{
timeline
.
getPeriodByUid
(
firstPeriodId
.
periodUid
,
period
);
positionUs
=
...
...
@@ -2543,7 +2543,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
// Resolve initial seek position.
@Nullable
Pair
<
Object
,
Long
>
periodPosition
=
resolveSeekPosition
(
resolveSeekPosition
Us
(
timeline
,
pendingInitialSeekPosition
,
/* trySubsequentPeriods= */
true
,
...
...
@@ -2608,10 +2608,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
// at position 0 and don't need to be resolved.
long
windowPositionUs
=
oldContentPositionUs
+
period
.
getPositionInWindowUs
();
int
windowIndex
=
timeline
.
getPeriodByUid
(
newPeriodUid
,
period
).
windowIndex
;
Pair
<
Object
,
Long
>
periodPosition
=
timeline
.
getPeriodPosition
(
window
,
period
,
windowIndex
,
windowPositionUs
);
newPeriodUid
=
periodPosition
.
first
;
newContentPositionUs
=
periodPosition
.
second
;
Pair
<
Object
,
Long
>
periodPosition
Us
=
timeline
.
getPeriodPosition
Us
(
window
,
period
,
windowIndex
,
windowPositionUs
);
newPeriodUid
=
periodPosition
Us
.
first
;
newContentPositionUs
=
periodPosition
Us
.
second
;
}
// Use an explicitly requested content position as new target live offset.
setTargetLiveOffset
=
true
;
...
...
@@ -2620,14 +2620,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
// Set period uid for default positions and resolve position for ad resolution.
long
contentPositionForAdResolutionUs
=
newContentPositionUs
;
if
(
startAtDefaultPositionWindowIndex
!=
C
.
INDEX_UNSET
)
{
Pair
<
Object
,
Long
>
defaultPosition
=
timeline
.
getPeriodPosition
(
Pair
<
Object
,
Long
>
defaultPosition
Us
=
timeline
.
getPeriodPosition
Us
(
window
,
period
,
startAtDefaultPositionWindowIndex
,
/* windowPositionUs= */
C
.
TIME_UNSET
);
newPeriodUid
=
defaultPosition
.
first
;
contentPositionForAdResolutionUs
=
defaultPosition
.
second
;
newPeriodUid
=
defaultPosition
Us
.
first
;
contentPositionForAdResolutionUs
=
defaultPosition
Us
.
second
;
newContentPositionUs
=
C
.
TIME_UNSET
;
}
...
...
@@ -2741,7 +2741,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
:
Util
.
msToUs
(
pendingMessageInfo
.
message
.
getPositionMs
());
@Nullable
Pair
<
Object
,
Long
>
periodPosition
=
resolveSeekPosition
(
resolveSeekPosition
Us
(
newTimeline
,
new
SeekPosition
(
pendingMessageInfo
.
message
.
getTimeline
(),
...
...
@@ -2786,12 +2786,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
pendingMessageInfo
.
resolvedPeriodTimeUs
+
period
.
getPositionInWindowUs
();
int
windowIndex
=
newTimeline
.
getPeriodByUid
(
pendingMessageInfo
.
resolvedPeriodUid
,
period
).
windowIndex
;
Pair
<
Object
,
Long
>
periodPosition
=
newTimeline
.
getPeriodPosition
(
window
,
period
,
windowIndex
,
windowPositionUs
);
Pair
<
Object
,
Long
>
periodPosition
Us
=
newTimeline
.
getPeriodPosition
Us
(
window
,
period
,
windowIndex
,
windowPositionUs
);
pendingMessageInfo
.
setResolvedPosition
(
/* periodIndex= */
newTimeline
.
getIndexOfPeriod
(
periodPosition
.
first
),
/* periodTimeUs= */
periodPosition
.
second
,
/* periodUid= */
periodPosition
.
first
);
/* periodIndex= */
newTimeline
.
getIndexOfPeriod
(
periodPosition
Us
.
first
),
/* periodTimeUs= */
periodPosition
Us
.
second
,
/* periodUid= */
periodPosition
Us
.
first
);
}
return
true
;
}
...
...
@@ -2820,7 +2820,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* bounds of the timeline.
*/
@Nullable
private
static
Pair
<
Object
,
Long
>
resolveSeekPosition
(
private
static
Pair
<
Object
,
Long
>
resolveSeekPosition
Us
(
Timeline
timeline
,
SeekPosition
seekPosition
,
boolean
trySubsequentPeriods
,
...
...
@@ -2839,10 +2839,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
seekTimeline
=
timeline
;
}
// Map the SeekPosition to a position in the corresponding timeline.
Pair
<
Object
,
Long
>
periodPosition
;
Pair
<
Object
,
Long
>
periodPosition
Us
;
try
{
periodPosition
=
seekTimeline
.
getPeriodPosition
(
periodPosition
Us
=
seekTimeline
.
getPeriodPosition
Us
(
window
,
period
,
seekPosition
.
windowIndex
,
seekPosition
.
windowPositionUs
);
}
catch
(
IndexOutOfBoundsException
e
)
{
// The window index of the seek position was outside the bounds of the timeline.
...
...
@@ -2850,24 +2850,24 @@ import java.util.concurrent.atomic.AtomicBoolean;
}
if
(
timeline
.
equals
(
seekTimeline
))
{
// Our internal timeline is the seek timeline, so the mapped position is correct.
return
periodPosition
;
return
periodPosition
Us
;
}
// Attempt to find the mapped period in the internal timeline.
int
periodIndex
=
timeline
.
getIndexOfPeriod
(
periodPosition
.
first
);
int
periodIndex
=
timeline
.
getIndexOfPeriod
(
periodPosition
Us
.
first
);
if
(
periodIndex
!=
C
.
INDEX_UNSET
)
{
// We successfully located the period in the internal timeline.
if
(
seekTimeline
.
getPeriodByUid
(
periodPosition
.
first
,
period
).
isPlaceholder
if
(
seekTimeline
.
getPeriodByUid
(
periodPosition
Us
.
first
,
period
).
isPlaceholder
&&
seekTimeline
.
getWindow
(
period
.
windowIndex
,
window
).
firstPeriodIndex
==
seekTimeline
.
getIndexOfPeriod
(
periodPosition
.
first
))
{
==
seekTimeline
.
getIndexOfPeriod
(
periodPosition
Us
.
first
))
{
// The seek timeline was using a placeholder, so we need to re-resolve using the updated
// timeline in case the resolved position changed. Only resolve the first period in a window
// because subsequent periods must start at position 0 and don't need to be resolved.
int
newWindowIndex
=
timeline
.
getPeriodByUid
(
periodPosition
.
first
,
period
).
windowIndex
;
periodPosition
=
timeline
.
getPeriodPosition
(
int
newWindowIndex
=
timeline
.
getPeriodByUid
(
periodPosition
Us
.
first
,
period
).
windowIndex
;
periodPosition
Us
=
timeline
.
getPeriodPosition
Us
(
window
,
period
,
newWindowIndex
,
seekPosition
.
windowPositionUs
);
}
return
periodPosition
;
return
periodPosition
Us
;
}
if
(
trySubsequentPeriods
)
{
// Try and find a subsequent period from the seek timeline in the internal timeline.
...
...
@@ -2878,12 +2878,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
period
,
repeatMode
,
shuffleModeEnabled
,
periodPosition
.
first
,
periodPosition
Us
.
first
,
seekTimeline
,
timeline
);
if
(
periodUid
!=
null
)
{
// We found one. Use the default position of the corresponding window.
return
timeline
.
getPeriodPosition
(
return
timeline
.
getPeriodPosition
Us
(
window
,
period
,
timeline
.
getPeriodByUid
(
periodUid
,
period
).
windowIndex
,
...
...
library/core/src/main/java/com/google/android/exoplayer2/MediaPeriodQueue.java
View file @
5c2f6186
...
...
@@ -661,18 +661,18 @@ import com.google.common.collect.ImmutableList;
// forward by the duration of the buffer, and start buffering from this point.
contentPositionUs
=
C
.
TIME_UNSET
;
@Nullable
Pair
<
Object
,
Long
>
defaultPosition
=
timeline
.
getPeriodPosition
(
Pair
<
Object
,
Long
>
defaultPosition
Us
=
timeline
.
getPeriodPosition
Us
(
window
,
period
,
nextWindowIndex
,
/* windowPositionUs= */
C
.
TIME_UNSET
,
/* defaultPositionProjectionUs= */
max
(
0
,
bufferedDurationUs
));
if
(
defaultPosition
==
null
)
{
if
(
defaultPosition
Us
==
null
)
{
return
null
;
}
nextPeriodUid
=
defaultPosition
.
first
;
startPositionUs
=
defaultPosition
.
second
;
nextPeriodUid
=
defaultPosition
Us
.
first
;
startPositionUs
=
defaultPosition
Us
.
second
;
MediaPeriodHolder
nextMediaPeriodHolder
=
mediaPeriodHolder
.
getNext
();
if
(
nextMediaPeriodHolder
!=
null
&&
nextMediaPeriodHolder
.
uid
.
equals
(
nextPeriodUid
))
{
windowSequenceNumber
=
nextMediaPeriodHolder
.
info
.
id
.
windowSequenceNumber
;
...
...
@@ -716,17 +716,17 @@ import com.google.common.collect.ImmutableList;
// If we're transitioning from an ad group to content starting from its default position,
// project the start position forward as if this were a transition to a new window.
@Nullable
Pair
<
Object
,
Long
>
defaultPosition
=
timeline
.
getPeriodPosition
(
Pair
<
Object
,
Long
>
defaultPosition
Us
=
timeline
.
getPeriodPosition
Us
(
window
,
period
,
period
.
windowIndex
,
/* windowPositionUs= */
C
.
TIME_UNSET
,
/* defaultPositionProjectionUs= */
max
(
0
,
bufferedDurationUs
));
if
(
defaultPosition
==
null
)
{
if
(
defaultPosition
Us
==
null
)
{
return
null
;
}
startPositionUs
=
defaultPosition
.
second
;
startPositionUs
=
defaultPosition
Us
.
second
;
}
long
minStartPositionUs
=
getMinStartPositionAfterAdGroupUs
(
...
...
library/core/src/main/java/com/google/android/exoplayer2/source/MaskingMediaSource.java
View file @
5c2f6186
...
...
@@ -179,11 +179,11 @@ public final class MaskingMediaSource extends CompositeMediaSource<Void> {
windowStartPositionUs
=
windowPreparePositionUs
;
}
}
Pair
<
Object
,
Long
>
period
Position
=
newTimeline
.
getPeriodPosition
(
Pair
<
Object
,
Long
>
period
UidAndPositionUs
=
newTimeline
.
getPeriodPosition
Us
(
window
,
period
,
/* windowIndex= */
0
,
windowStartPositionUs
);
Object
periodUid
=
period
Position
.
first
;
long
periodPositionUs
=
period
Position
.
second
;
Object
periodUid
=
period
UidAndPositionUs
.
first
;
long
periodPositionUs
=
period
UidAndPositionUs
.
second
;
timeline
=
hasRealTimeline
?
timeline
.
cloneWithUpdatedTimeline
(
newTimeline
)
...
...
library/core/src/test/java/com/google/android/exoplayer2/source/SinglePeriodTimelineTest.java
View file @
5c2f6186
...
...
@@ -45,19 +45,31 @@ public final class SinglePeriodTimelineTest {
public
void
getPeriodPositionDynamicWindowUnknownDuration
()
{
SinglePeriodTimeline
timeline
=
new
SinglePeriodTimeline
(
C
.
TIME_UNSET
,
/* durationUs= */
C
.
TIME_UNSET
,
/* isSeekable= */
false
,
/* isDynamic= */
true
,
/* isLive= */
true
,
/* manifest= */
null
,
MediaItem
.
fromUri
(
Uri
.
EMPTY
));
// Should return null with any positive position projection.
Pair
<
Object
,
Long
>
position
=
timeline
.
getPeriodPosition
(
window
,
period
,
0
,
C
.
TIME_UNSET
,
1
);
assertThat
(
position
).
isNull
();
Pair
<
Object
,
Long
>
positionUs
=
timeline
.
getPeriodPositionUs
(
window
,
period
,
/* windowIndex= */
0
,
/* windowPositionUs= */
C
.
TIME_UNSET
,
/* defaultPositionProjectionUs= */
1
);
assertThat
(
positionUs
).
isNull
();
// Should return (0, 0) without a position projection.
position
=
timeline
.
getPeriodPosition
(
window
,
period
,
0
,
C
.
TIME_UNSET
,
0
);
assertThat
(
position
.
first
).
isEqualTo
(
timeline
.
getUidOfPeriod
(
0
));
assertThat
(
position
.
second
).
isEqualTo
(
0
);
positionUs
=
timeline
.
getPeriodPositionUs
(
window
,
period
,
/* windowIndex= */
0
,
/* windowPositionUs= */
C
.
TIME_UNSET
,
/* defaultPositionProjectionUs= */
0
);
assertThat
(
positionUs
.
first
).
isEqualTo
(
timeline
.
getUidOfPeriod
(
0
));
assertThat
(
positionUs
.
second
).
isEqualTo
(
0
);
}
@Test
...
...
@@ -75,17 +87,34 @@ public final class SinglePeriodTimelineTest {
/* manifest= */
null
,
MediaItem
.
fromUri
(
Uri
.
EMPTY
));
// Should return null with a positive position projection beyond window duration.
Pair
<
Object
,
Long
>
position
=
timeline
.
getPeriodPosition
(
window
,
period
,
0
,
C
.
TIME_UNSET
,
windowDurationUs
+
1
);
assertThat
(
position
).
isNull
();
Pair
<
Object
,
Long
>
positionUs
=
timeline
.
getPeriodPositionUs
(
window
,
period
,
/* windowIndex= */
0
,
/* windowPositionUs= */
C
.
TIME_UNSET
,
/* defaultPositionProjectionUs= */
windowDurationUs
+
1
);
assertThat
(
positionUs
).
isNull
();
// Should return (0, duration) with a projection equal to window duration.
position
=
timeline
.
getPeriodPosition
(
window
,
period
,
0
,
C
.
TIME_UNSET
,
windowDurationUs
-
1
);
assertThat
(
position
.
first
).
isEqualTo
(
timeline
.
getUidOfPeriod
(
0
));
assertThat
(
position
.
second
).
isEqualTo
(
windowDurationUs
-
1
);
positionUs
=
timeline
.
getPeriodPositionUs
(
window
,
period
,
/* windowIndex= */
0
,
/* windowPositionUs= */
C
.
TIME_UNSET
,
/* defaultPositionProjectionUs= */
windowDurationUs
-
1
);
assertThat
(
positionUs
.
first
).
isEqualTo
(
timeline
.
getUidOfPeriod
(
0
));
assertThat
(
positionUs
.
second
).
isEqualTo
(
windowDurationUs
-
1
);
// Should return (0, 0) without a position projection.
position
=
timeline
.
getPeriodPosition
(
window
,
period
,
0
,
C
.
TIME_UNSET
,
0
);
assertThat
(
position
.
first
).
isEqualTo
(
timeline
.
getUidOfPeriod
(
0
));
assertThat
(
position
.
second
).
isEqualTo
(
0
);
positionUs
=
timeline
.
getPeriodPositionUs
(
window
,
period
,
/* windowIndex= */
0
,
/* windowPositionUs= */
C
.
TIME_UNSET
,
/* defaultPositionProjectionUs= */
0
);
assertThat
(
positionUs
.
first
).
isEqualTo
(
timeline
.
getUidOfPeriod
(
0
));
assertThat
(
positionUs
.
second
).
isEqualTo
(
0
);
}
@Test
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment