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
6b03d4bc
authored
Jan 23, 2020
by
andrewlewis
Committed by
Ian Baker
Jan 24, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Make resolveSeekPositionUs an instance method
PiperOrigin-RevId: 291125686
parent
a0f6bc87
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
46 deletions
library/core/src/main/java/com/google/android/exoplayer2/SeekParameters.java
library/core/src/main/java/com/google/android/exoplayer2/source/ProgressiveMediaPeriod.java
library/core/src/main/java/com/google/android/exoplayer2/util/Util.java
library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java
library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/DefaultSsChunkSource.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeChunkSource.java
library/core/src/main/java/com/google/android/exoplayer2/SeekParameters.java
View file @
6b03d4bc
...
...
@@ -17,6 +17,7 @@ package com.google.android.exoplayer2;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Util
;
/**
* Parameters that apply to seeking.
...
...
@@ -71,6 +72,41 @@ public final class SeekParameters {
this
.
toleranceAfterUs
=
toleranceAfterUs
;
}
/**
* Resolves a seek based on the parameters, given the requested seek position and two candidate
* sync points.
*
* @param positionUs The requested seek position, in microseocnds.
* @param firstSyncUs The first candidate seek point, in micrseconds.
* @param secondSyncUs The second candidate seek point, in microseconds. May equal {@code
* firstSyncUs} if there's only one candidate.
* @return The resolved seek position, in microseconds.
*/
public
long
resolveSeekPositionUs
(
long
positionUs
,
long
firstSyncUs
,
long
secondSyncUs
)
{
if
(
toleranceBeforeUs
==
0
&&
toleranceAfterUs
==
0
)
{
return
positionUs
;
}
long
minPositionUs
=
Util
.
subtractWithOverflowDefault
(
positionUs
,
toleranceBeforeUs
,
Long
.
MIN_VALUE
);
long
maxPositionUs
=
Util
.
addWithOverflowDefault
(
positionUs
,
toleranceAfterUs
,
Long
.
MAX_VALUE
);
boolean
firstSyncPositionValid
=
minPositionUs
<=
firstSyncUs
&&
firstSyncUs
<=
maxPositionUs
;
boolean
secondSyncPositionValid
=
minPositionUs
<=
secondSyncUs
&&
secondSyncUs
<=
maxPositionUs
;
if
(
firstSyncPositionValid
&&
secondSyncPositionValid
)
{
if
(
Math
.
abs
(
firstSyncUs
-
positionUs
)
<=
Math
.
abs
(
secondSyncUs
-
positionUs
))
{
return
firstSyncUs
;
}
else
{
return
secondSyncUs
;
}
}
else
if
(
firstSyncPositionValid
)
{
return
firstSyncUs
;
}
else
if
(
secondSyncPositionValid
)
{
return
secondSyncUs
;
}
else
{
return
minPositionUs
;
}
}
@Override
public
boolean
equals
(
@Nullable
Object
obj
)
{
if
(
this
==
obj
)
{
...
...
library/core/src/main/java/com/google/android/exoplayer2/source/ProgressiveMediaPeriod.java
View file @
6b03d4bc
...
...
@@ -446,8 +446,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
return
0
;
}
SeekPoints
seekPoints
=
seekMap
.
getSeekPoints
(
positionUs
);
return
Util
.
resolveSeekPositionUs
(
positionUs
,
seekP
arameters
,
seekP
oints
.
first
.
timeUs
,
seekPoints
.
second
.
timeUs
);
return
seekParameters
.
resolveSeekPositionUs
(
positionUs
,
seekPoints
.
first
.
timeUs
,
seekPoints
.
second
.
timeUs
);
}
// SampleStream methods.
...
...
library/core/src/main/java/com/google/android/exoplayer2/util/Util.java
View file @
6b03d4bc
...
...
@@ -51,7 +51,6 @@ import com.google.android.exoplayer2.C;
import
com.google.android.exoplayer2.ExoPlayerLibraryInfo
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.ParserException
;
import
com.google.android.exoplayer2.SeekParameters
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
java.io.ByteArrayOutputStream
;
import
java.io.Closeable
;
...
...
@@ -1141,44 +1140,6 @@ public final class Util {
}
/**
* Resolves a seek given the requested seek position, a {@link SeekParameters} and two candidate
* sync points.
*
* @param positionUs The requested seek position, in microseocnds.
* @param seekParameters The {@link SeekParameters}.
* @param firstSyncUs The first candidate seek point, in micrseconds.
* @param secondSyncUs The second candidate seek point, in microseconds. May equal {@code
* firstSyncUs} if there's only one candidate.
* @return The resolved seek position, in microseconds.
*/
public
static
long
resolveSeekPositionUs
(
long
positionUs
,
SeekParameters
seekParameters
,
long
firstSyncUs
,
long
secondSyncUs
)
{
if
(
SeekParameters
.
EXACT
.
equals
(
seekParameters
))
{
return
positionUs
;
}
long
minPositionUs
=
subtractWithOverflowDefault
(
positionUs
,
seekParameters
.
toleranceBeforeUs
,
Long
.
MIN_VALUE
);
long
maxPositionUs
=
addWithOverflowDefault
(
positionUs
,
seekParameters
.
toleranceAfterUs
,
Long
.
MAX_VALUE
);
boolean
firstSyncPositionValid
=
minPositionUs
<=
firstSyncUs
&&
firstSyncUs
<=
maxPositionUs
;
boolean
secondSyncPositionValid
=
minPositionUs
<=
secondSyncUs
&&
secondSyncUs
<=
maxPositionUs
;
if
(
firstSyncPositionValid
&&
secondSyncPositionValid
)
{
if
(
Math
.
abs
(
firstSyncUs
-
positionUs
)
<=
Math
.
abs
(
secondSyncUs
-
positionUs
))
{
return
firstSyncUs
;
}
else
{
return
secondSyncUs
;
}
}
else
if
(
firstSyncPositionValid
)
{
return
firstSyncUs
;
}
else
if
(
secondSyncPositionValid
)
{
return
secondSyncUs
;
}
else
{
return
minPositionUs
;
}
}
/**
* Converts a list of integers to a primitive array.
*
* @param list A list of integers.
...
...
library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java
View file @
6b03d4bc
...
...
@@ -198,7 +198,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
firstSyncUs
<
positionUs
&&
segmentNum
<
representationHolder
.
getSegmentCount
()
-
1
?
representationHolder
.
getSegmentStartTimeUs
(
segmentNum
+
1
)
:
firstSyncUs
;
return
Util
.
resolveSeekPositionUs
(
positionUs
,
seekParameter
s
,
firstSyncUs
,
secondSyncUs
);
return
seekParameters
.
resolveSeekPositionUs
(
positionU
s
,
firstSyncUs
,
secondSyncUs
);
}
}
// We don't have a segment index to adjust the seek position with yet.
...
...
library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/DefaultSsChunkSource.java
View file @
6b03d4bc
...
...
@@ -38,7 +38,6 @@ import com.google.android.exoplayer2.upstream.DataSource;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.LoaderErrorThrower
;
import
com.google.android.exoplayer2.upstream.TransferListener
;
import
com.google.android.exoplayer2.util.Util
;
import
java.io.IOException
;
import
java.util.List
;
...
...
@@ -129,7 +128,7 @@ public class DefaultSsChunkSource implements SsChunkSource {
firstSyncUs
<
positionUs
&&
chunkIndex
<
streamElement
.
chunkCount
-
1
?
streamElement
.
getStartTimeUs
(
chunkIndex
+
1
)
:
firstSyncUs
;
return
Util
.
resolveSeekPositionUs
(
positionUs
,
seekParameter
s
,
firstSyncUs
,
secondSyncUs
);
return
seekParameters
.
resolveSeekPositionUs
(
positionU
s
,
firstSyncUs
,
secondSyncUs
);
}
@Override
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeChunkSource.java
View file @
6b03d4bc
...
...
@@ -32,7 +32,6 @@ import com.google.android.exoplayer2.upstream.DataSource;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.TransferListener
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.Util
;
import
java.io.IOException
;
import
java.util.List
;
...
...
@@ -90,7 +89,7 @@ public final class FakeChunkSource implements ChunkSource {
firstSyncUs
<
positionUs
&&
chunkIndex
<
dataSet
.
getChunkCount
()
-
1
?
dataSet
.
getStartTime
(
chunkIndex
+
1
)
:
firstSyncUs
;
return
Util
.
resolveSeekPositionUs
(
positionUs
,
seekParameter
s
,
firstSyncUs
,
secondSyncUs
);
return
seekParameters
.
resolveSeekPositionUs
(
positionU
s
,
firstSyncUs
,
secondSyncUs
);
}
@Override
...
...
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