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
ea95db23
authored
Feb 25, 2015
by
ojw28
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge pull request #316 from jeoliva/blackplaylist_management
Better management of blacklisted playlists
parents
006986cc
2ac7046f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java
library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java
View file @
ea95db23
...
...
@@ -106,6 +106,12 @@ public class HlsChunkSource {
*/
public
static
final
long
DEFAULT_MAX_BUFFER_TO_SWITCH_DOWN_MS
=
20000
;
/**
* The default maximum time a media playlist is blacklisted without
* rechecking if it is alive again (because an encoder reset, for example)
*/
public
static
final
long
DEFAULT_MAX_TIME_MEDIA_PLAYLIST_BLACKLISTED_MS
=
60000
;
private
static
final
String
TAG
=
"HlsChunkSource"
;
private
static
final
String
AAC_FILE_EXTENSION
=
".aac"
;
private
static
final
float
BANDWIDTH_FRACTION
=
0.8f
;
...
...
@@ -127,6 +133,7 @@ public class HlsChunkSource {
/* package */
byte
[]
scratchSpace
;
/* package */
final
HlsMediaPlaylist
[]
mediaPlaylists
;
/* package */
final
boolean
[]
mediaPlaylistBlacklistFlags
;
/* package */
final
long
[]
mediaPlaylistBlacklistedTimeMs
;
/* package */
final
long
[]
lastMediaPlaylistLoadTimesMs
;
/* package */
boolean
live
;
/* package */
long
durationUs
;
...
...
@@ -182,6 +189,7 @@ public class HlsChunkSource {
enabledVariants
=
new
Variant
[]
{
new
Variant
(
0
,
playlistUrl
,
0
,
null
,
-
1
,
-
1
)};
mediaPlaylists
=
new
HlsMediaPlaylist
[
1
];
mediaPlaylistBlacklistFlags
=
new
boolean
[
1
];
mediaPlaylistBlacklistedTimeMs
=
new
long
[
1
];
lastMediaPlaylistLoadTimesMs
=
new
long
[
1
];
setMediaPlaylist
(
0
,
(
HlsMediaPlaylist
)
playlist
);
}
else
{
...
...
@@ -189,6 +197,7 @@ public class HlsChunkSource {
enabledVariants
=
filterVariants
((
HlsMasterPlaylist
)
playlist
,
variantIndices
);
mediaPlaylists
=
new
HlsMediaPlaylist
[
enabledVariants
.
length
];
mediaPlaylistBlacklistFlags
=
new
boolean
[
enabledVariants
.
length
];
mediaPlaylistBlacklistedTimeMs
=
new
long
[
enabledVariants
.
length
];
lastMediaPlaylistLoadTimesMs
=
new
long
[
enabledVariants
.
length
];
}
...
...
@@ -362,6 +371,7 @@ public class HlsChunkSource {
if
(
responseCode
==
404
||
responseCode
==
410
)
{
MediaPlaylistChunk
playlistChunk
=
(
MediaPlaylistChunk
)
chunk
;
mediaPlaylistBlacklistFlags
[
playlistChunk
.
variantIndex
]
=
true
;
mediaPlaylistBlacklistedTimeMs
[
playlistChunk
.
variantIndex
]
=
SystemClock
.
elapsedRealtime
();
if
(!
allPlaylistsBlacklisted
())
{
// We've handled the 404/410 by blacklisting the playlist.
Log
.
w
(
TAG
,
"Blacklisted playlist ("
+
responseCode
+
"): "
...
...
@@ -372,6 +382,7 @@ public class HlsChunkSource {
Log
.
w
(
TAG
,
"Final playlist not blacklisted ("
+
responseCode
+
"): "
+
playlistChunk
.
dataSpec
.
uri
);
mediaPlaylistBlacklistFlags
[
playlistChunk
.
variantIndex
]
=
false
;
mediaPlaylistBlacklistedTimeMs
[
playlistChunk
.
variantIndex
]
=
0
;
return
false
;
}
}
...
...
@@ -380,6 +391,7 @@ public class HlsChunkSource {
}
private
int
getNextVariantIndex
(
TsChunk
previousTsChunk
,
long
playbackPositionUs
)
{
clearStaleBlacklistedPlaylists
();
int
idealVariantIndex
=
getVariantIndexForBandwdith
(
(
int
)
(
bandwidthMeter
.
getBitrateEstimate
()
*
BANDWIDTH_FRACTION
));
if
(
idealVariantIndex
==
variantIndex
)
{
...
...
@@ -541,6 +553,17 @@ public class HlsChunkSource {
return
true
;
}
private
void
clearStaleBlacklistedPlaylists
()
{
long
currentTime
=
SystemClock
.
elapsedRealtime
();
for
(
int
i
=
0
;
i
<
mediaPlaylistBlacklistFlags
.
length
;
i
++)
{
if
(
mediaPlaylistBlacklistFlags
[
i
]
&&
currentTime
-
mediaPlaylistBlacklistedTimeMs
[
i
]
>
DEFAULT_MAX_TIME_MEDIA_PLAYLIST_BLACKLISTED_MS
)
{
mediaPlaylistBlacklistFlags
[
i
]
=
false
;
mediaPlaylistBlacklistedTimeMs
[
i
]
=
0
;
}
}
}
private
class
MediaPlaylistChunk
extends
DataChunk
{
@SuppressWarnings
(
"hiding"
)
...
...
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