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
cb0394b9
authored
Jan 12, 2017
by
WeiChungChang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
'improve_far_seek_of_chunkSampleStream'
parent
deefe50a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
4 deletions
library/src/main/java/com/google/android/exoplayer2/extractor/DefaultTrackOutput.java
library/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java
library/src/main/java/com/google/android/exoplayer2/extractor/DefaultTrackOutput.java
View file @
cb0394b9
...
...
@@ -229,10 +229,26 @@ public final class DefaultTrackOutput implements TrackOutput {
* Attempts to skip to the keyframe before the specified time, if it's present in the buffer.
*
* @param timeUs The seek time.
* @param skipToLastKey Skip to last key regardless the seek time is out of range .
* @return Whether the skip was successful.
*/
public
boolean
skipToKeyframeBefore
(
long
timeUs
,
boolean
skipToLastKey
)
{
long
nextOffset
=
infoQueue
.
skipToKeyframeBefore
(
timeUs
,
skipToLastKey
);
if
(
nextOffset
==
C
.
POSITION_UNSET
)
{
return
false
;
}
dropDownstreamTo
(
nextOffset
);
return
true
;
}
/**
* Attempts to skip to the keyframe before the specified time, if it's present in the buffer.
*
* @param timeUs The seek time.
* @return Whether the skip was successful.
*/
public
boolean
skipToKeyframeBefore
(
long
timeUs
)
{
long
nextOffset
=
infoQueue
.
skipToKeyframeBefore
(
timeUs
);
long
nextOffset
=
infoQueue
.
skipToKeyframeBefore
(
timeUs
,
false
);
if
(
nextOffset
==
C
.
POSITION_UNSET
)
{
return
false
;
}
...
...
@@ -781,12 +797,12 @@ public final class DefaultTrackOutput implements TrackOutput {
* @return The offset of the keyframe's data if the keyframe was present.
* {@link C#POSITION_UNSET} otherwise.
*/
public
synchronized
long
skipToKeyframeBefore
(
long
timeUs
)
{
public
synchronized
long
skipToKeyframeBefore
(
long
timeUs
,
boolean
skipToLastKey
)
{
if
(
queueSize
==
0
||
timeUs
<
timesUs
[
relativeReadIndex
])
{
return
C
.
POSITION_UNSET
;
}
if
(
timeUs
>
largestQueuedTimestampUs
)
{
if
(
timeUs
>
largestQueuedTimestampUs
&&
!
skipToLastKey
)
{
return
C
.
POSITION_UNSET
;
}
...
...
library/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java
View file @
cb0394b9
...
...
@@ -115,6 +115,20 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
}
/**
* Check if the input position locates within the chunk we are downloading now.
*
* @param positionUs The target position in microseconds.
* @return Whether the input position locates within the chunk we are downloading now.
*/
public
boolean
isWithinLastChunk
(
long
positionUs
)
{
if
(
isPendingReset
()
||
loadingFinished
)
{
return
false
;
}
else
{
return
((
positionUs
>=
getCurrentLoadPositionUs
())
&&
(
positionUs
<
getNextLoadPositionUs
()));
}
}
/**
* Seeks to the specified position in microseconds.
*
* @param positionUs The seek position in microseconds.
...
...
@@ -122,7 +136,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
public
void
seekToUs
(
long
positionUs
)
{
lastSeekPositionUs
=
positionUs
;
// If we're not pending a reset, see if we can seek within the sample queue.
boolean
seekInsideBuffer
=
!
isPendingReset
()
&&
sampleQueue
.
skipToKeyframeBefore
(
positionUs
);
boolean
seekInsideBuffer
=
!
isPendingReset
()
&&
sampleQueue
.
skipToKeyframeBefore
(
positionUs
,
isWithinLastChunk
(
positionUs
));
if
(
seekInsideBuffer
)
{
// We succeeded. All we need to do is discard any chunks that we've moved past.
while
(
mediaChunks
.
size
()
>
1
...
...
@@ -284,6 +299,14 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
return
true
;
}
public
long
getCurrentLoadPositionUs
()
{
if
(
isPendingReset
())
{
return
pendingResetPositionUs
;
}
else
{
return
loadingFinished
?
C
.
TIME_END_OF_SOURCE
:
mediaChunks
.
getLast
().
startTimeUs
;
}
}
@Override
public
long
getNextLoadPositionUs
()
{
if
(
isPendingReset
())
{
...
...
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