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
5f0be427
authored
Oct 20, 2014
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Update HlsSampleSource + correctly propagate error from prepare.
Issue: #81
parent
60d162df
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
32 deletions
library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java
library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java
View file @
5f0be427
...
...
@@ -64,7 +64,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
private
long
downstreamPositionUs
;
private
long
lastSeekPositionUs
;
private
long
pendingReset
Time
;
private
long
pendingReset
PositionUs
;
private
long
lastPerformedBufferOperation
;
private
Loader
loader
;
...
...
@@ -89,7 +89,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
}
@Override
public
boolean
prepare
()
{
public
boolean
prepare
()
throws
IOException
{
if
(
prepared
)
{
return
true
;
}
...
...
@@ -116,6 +116,9 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
prepared
=
true
;
}
if
(!
prepared
&&
currentLoadableException
!=
null
)
{
throw
currentLoadableException
;
}
return
prepared
;
}
...
...
@@ -132,16 +135,16 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
}
@Override
public
void
enable
(
int
track
,
long
time
Us
)
{
public
void
enable
(
int
track
,
long
position
Us
)
{
Assertions
.
checkState
(
prepared
);
Assertions
.
checkState
(!
trackEnabledStates
[
track
]);
enabledTrackCount
++;
trackEnabledStates
[
track
]
=
true
;
downstreamMediaFormats
[
track
]
=
null
;
if
(
enabledTrackCount
==
1
)
{
downstreamPositionUs
=
time
Us
;
lastSeekPositionUs
=
time
Us
;
restartFrom
(
time
Us
);
downstreamPositionUs
=
position
Us
;
lastSeekPositionUs
=
position
Us
;
restartFrom
(
position
Us
);
}
}
...
...
@@ -257,21 +260,21 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
}
@Override
public
void
seekToUs
(
long
time
Us
)
{
public
void
seekToUs
(
long
position
Us
)
{
Assertions
.
checkState
(
prepared
);
Assertions
.
checkState
(
enabledTrackCount
>
0
);
downstreamPositionUs
=
time
Us
;
lastSeekPositionUs
=
time
Us
;
if
(
pendingReset
Time
==
time
Us
)
{
downstreamPositionUs
=
position
Us
;
lastSeekPositionUs
=
position
Us
;
if
(
pendingReset
PositionUs
==
position
Us
)
{
return
;
}
for
(
int
i
=
0
;
i
<
pendingDiscontinuities
.
length
;
i
++)
{
pendingDiscontinuities
[
i
]
=
true
;
}
TsChunk
mediaChunk
=
getHlsChunk
(
time
Us
);
TsChunk
mediaChunk
=
getHlsChunk
(
position
Us
);
if
(
mediaChunk
==
null
)
{
restartFrom
(
time
Us
);
restartFrom
(
position
Us
);
}
else
{
pendingTimestampOffsetUpdate
=
true
;
mediaChunk
.
reset
();
...
...
@@ -280,13 +283,13 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
}
}
private
TsChunk
getHlsChunk
(
long
time
Us
)
{
private
TsChunk
getHlsChunk
(
long
position
Us
)
{
Iterator
<
TsChunk
>
mediaChunkIterator
=
mediaChunks
.
iterator
();
while
(
mediaChunkIterator
.
hasNext
())
{
TsChunk
mediaChunk
=
mediaChunkIterator
.
next
();
if
(
time
Us
<
mediaChunk
.
startTimeUs
)
{
if
(
position
Us
<
mediaChunk
.
startTimeUs
)
{
return
null
;
}
else
if
(
mediaChunk
.
isLastChunk
()
||
time
Us
<
mediaChunk
.
endTimeUs
)
{
}
else
if
(
mediaChunk
.
isLastChunk
()
||
position
Us
<
mediaChunk
.
endTimeUs
)
{
return
mediaChunk
;
}
}
...
...
@@ -298,7 +301,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
Assertions
.
checkState
(
prepared
);
Assertions
.
checkState
(
enabledTrackCount
>
0
);
if
(
isPendingReset
())
{
return
pendingReset
Time
;
return
pendingReset
PositionUs
;
}
TsChunk
mediaChunk
=
mediaChunks
.
getLast
();
HlsChunk
currentLoadable
=
currentLoadableHolder
.
chunk
;
...
...
@@ -357,7 +360,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
}
clearCurrentLoadable
();
if
(
enabledTrackCount
>
0
)
{
restartFrom
(
pendingReset
Time
);
restartFrom
(
pendingReset
PositionUs
);
}
else
{
clearHlsChunks
();
loadControl
.
trimAllocator
();
...
...
@@ -372,8 +375,8 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
updateLoadControl
();
}
private
void
restartFrom
(
long
time
Us
)
{
pendingReset
Time
=
time
Us
;
private
void
restartFrom
(
long
position
Us
)
{
pendingReset
PositionUs
=
position
Us
;
if
(
loader
.
isLoading
())
{
loader
.
cancelLoading
();
}
else
{
...
...
@@ -395,21 +398,23 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
}
private
void
updateLoadControl
()
{
if
(
currentLoadableExceptionFatal
)
{
// We've failed, but we still need to update the control with our current state.
loadControl
.
update
(
this
,
downstreamPositionUs
,
-
1
,
false
,
true
);
return
;
}
long
loadPositionUs
;
if
(
isPendingReset
())
{
loadPositionUs
=
pendingReset
Time
;
loadPositionUs
=
pendingReset
PositionUs
;
}
else
{
TsChunk
lastHlsChunk
=
mediaChunks
.
getLast
();
loadPositionUs
=
lastHlsChunk
.
nextChunkIndex
==
-
1
?
-
1
:
lastHlsChunk
.
endTimeUs
;
}
boolean
isBackedOff
=
currentLoadableException
!=
null
&&
!
currentLoadableExceptionFatal
;
boolean
isBackedOff
=
currentLoadableException
!=
null
;
boolean
nextLoader
=
loadControl
.
update
(
this
,
downstreamPositionUs
,
loadPositionUs
,
isBackedOff
||
loader
.
isLoading
(),
currentLoadableExceptionFatal
);
if
(
currentLoadableExceptionFatal
)
{
return
;
}
isBackedOff
||
loader
.
isLoading
(),
false
);
long
now
=
SystemClock
.
elapsedRealtime
();
...
...
@@ -425,8 +430,8 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
if
(
currentLoadableHolder
.
chunk
==
null
||
now
-
lastPerformedBufferOperation
>
1000
)
{
lastPerformedBufferOperation
=
now
;
currentLoadableHolder
.
queueSize
=
readOnlyHlsChunks
.
size
();
chunkSource
.
getChunkOperation
(
readOnlyHlsChunks
,
pendingReset
Time
,
downstream
PositionUs
,
currentLoadableHolder
);
chunkSource
.
getChunkOperation
(
readOnlyHlsChunks
,
pendingResetPositionUs
,
downstreamPositionUs
,
currentLoadableHolder
);
discardUpstreamHlsChunks
(
currentLoadableHolder
.
queueSize
);
}
if
(
nextLoader
)
{
...
...
@@ -448,7 +453,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
HlsChunk
backedOffChunk
=
currentLoadableHolder
.
chunk
;
if
(!
isTsChunk
(
backedOffChunk
))
{
currentLoadableHolder
.
queueSize
=
readOnlyHlsChunks
.
size
();
chunkSource
.
getChunkOperation
(
readOnlyHlsChunks
,
pendingReset
Time
,
downstreamPositionUs
,
chunkSource
.
getChunkOperation
(
readOnlyHlsChunks
,
pendingReset
PositionUs
,
downstreamPositionUs
,
currentLoadableHolder
);
discardUpstreamHlsChunks
(
currentLoadableHolder
.
queueSize
);
if
(
currentLoadableHolder
.
chunk
==
backedOffChunk
)
{
...
...
@@ -473,7 +478,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
TsChunk
removedChunk
=
mediaChunks
.
removeLast
();
Assertions
.
checkState
(
backedOffChunk
==
removedChunk
);
currentLoadableHolder
.
queueSize
=
readOnlyHlsChunks
.
size
();
chunkSource
.
getChunkOperation
(
readOnlyHlsChunks
,
pendingReset
Time
,
downstreamPositionUs
,
chunkSource
.
getChunkOperation
(
readOnlyHlsChunks
,
pendingReset
PositionUs
,
downstreamPositionUs
,
currentLoadableHolder
);
mediaChunks
.
add
(
removedChunk
);
...
...
@@ -501,7 +506,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
if
(
isPendingReset
())
{
pendingTimestampOffsetUpdate
=
true
;
mediaChunk
.
reset
();
pendingReset
Time
=
NO_RESET_PENDING
;
pendingReset
PositionUs
=
NO_RESET_PENDING
;
}
mediaChunks
.
add
(
mediaChunk
);
}
...
...
@@ -546,7 +551,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback {
}
private
boolean
isPendingReset
()
{
return
pendingReset
Time
!=
NO_RESET_PENDING
;
return
pendingReset
PositionUs
!=
NO_RESET_PENDING
;
}
private
long
getRetryDelayMillis
(
long
errorCount
)
{
...
...
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