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
ad26085e
authored
Aug 01, 2014
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Finish painful bytes/sec -> bits/sec conversion.
parent
0f57a5f1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
49 deletions
demo/src/main/java/com/google/android/exoplayer/demo/full/EventLogger.java
demo/src/main/java/com/google/android/exoplayer/demo/full/player/DemoPlayer.java
library/src/main/java/com/google/android/exoplayer/chunk/FormatEvaluator.java
library/src/main/java/com/google/android/exoplayer/upstream/BandwidthMeter.java
library/src/main/java/com/google/android/exoplayer/upstream/DefaultBandwidthMeter.java
demo/src/main/java/com/google/android/exoplayer/demo/full/EventLogger.java
View file @
ad26085e
...
@@ -80,9 +80,9 @@ public class EventLogger implements DemoPlayer.Listener, DemoPlayer.InfoListener
...
@@ -80,9 +80,9 @@ public class EventLogger implements DemoPlayer.Listener, DemoPlayer.InfoListener
// DemoPlayer.InfoListener
// DemoPlayer.InfoListener
@Override
@Override
public
void
onBandwidthSample
(
int
elapsedMs
,
long
bytes
,
long
b
andwidth
Estimate
)
{
public
void
onBandwidthSample
(
int
elapsedMs
,
long
bytes
,
long
b
itrate
Estimate
)
{
Log
.
d
(
TAG
,
"bandwidth ["
+
getSessionTimeString
()
+
", "
+
bytes
+
Log
.
d
(
TAG
,
"bandwidth ["
+
getSessionTimeString
()
+
", "
+
bytes
+
", "
+
getTimeString
(
elapsedMs
)
+
", "
+
b
andwidth
Estimate
+
"]"
);
", "
+
getTimeString
(
elapsedMs
)
+
", "
+
b
itrate
Estimate
+
"]"
);
}
}
@Override
@Override
...
...
demo/src/main/java/com/google/android/exoplayer/demo/full/player/DemoPlayer.java
View file @
ad26085e
...
@@ -121,7 +121,7 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
...
@@ -121,7 +121,7 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
void
onVideoFormatEnabled
(
String
formatId
,
int
trigger
,
int
mediaTimeMs
);
void
onVideoFormatEnabled
(
String
formatId
,
int
trigger
,
int
mediaTimeMs
);
void
onAudioFormatEnabled
(
String
formatId
,
int
trigger
,
int
mediaTimeMs
);
void
onAudioFormatEnabled
(
String
formatId
,
int
trigger
,
int
mediaTimeMs
);
void
onDroppedFrames
(
int
count
,
long
elapsed
);
void
onDroppedFrames
(
int
count
,
long
elapsed
);
void
onBandwidthSample
(
int
elapsedMs
,
long
bytes
,
long
b
andwidth
Estimate
);
void
onBandwidthSample
(
int
elapsedMs
,
long
bytes
,
long
b
itrate
Estimate
);
void
onLoadStarted
(
int
sourceId
,
String
formatId
,
int
trigger
,
boolean
isInitialization
,
void
onLoadStarted
(
int
sourceId
,
String
formatId
,
int
trigger
,
boolean
isInitialization
,
int
mediaStartTimeMs
,
int
mediaEndTimeMs
,
long
totalBytes
);
int
mediaStartTimeMs
,
int
mediaEndTimeMs
,
long
totalBytes
);
void
onLoadCompleted
(
int
sourceId
);
void
onLoadCompleted
(
int
sourceId
);
...
@@ -391,9 +391,9 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
...
@@ -391,9 +391,9 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
}
}
@Override
@Override
public
void
onBandwidthSample
(
int
elapsedMs
,
long
bytes
,
long
b
andwidth
Estimate
)
{
public
void
onBandwidthSample
(
int
elapsedMs
,
long
bytes
,
long
b
itrate
Estimate
)
{
if
(
infoListener
!=
null
)
{
if
(
infoListener
!=
null
)
{
infoListener
.
onBandwidthSample
(
elapsedMs
,
bytes
,
b
andwidth
Estimate
);
infoListener
.
onBandwidthSample
(
elapsedMs
,
bytes
,
b
itrate
Estimate
);
}
}
}
}
...
...
library/src/main/java/com/google/android/exoplayer/chunk/FormatEvaluator.java
View file @
ad26085e
...
@@ -164,7 +164,7 @@ public interface FormatEvaluator {
...
@@ -164,7 +164,7 @@ public interface FormatEvaluator {
*/
*/
public
static
class
AdaptiveEvaluator
implements
FormatEvaluator
{
public
static
class
AdaptiveEvaluator
implements
FormatEvaluator
{
public
static
final
int
DEFAULT_MAX_INITIAL_B
YTE_RATE
=
1
00000
;
public
static
final
int
DEFAULT_MAX_INITIAL_B
ITRATE
=
8
00000
;
public
static
final
int
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS
=
10000
;
public
static
final
int
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS
=
10000
;
public
static
final
int
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS
=
25000
;
public
static
final
int
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS
=
25000
;
...
@@ -173,7 +173,7 @@ public interface FormatEvaluator {
...
@@ -173,7 +173,7 @@ public interface FormatEvaluator {
private
final
BandwidthMeter
bandwidthMeter
;
private
final
BandwidthMeter
bandwidthMeter
;
private
final
int
maxInitialB
yteR
ate
;
private
final
int
maxInitialB
itr
ate
;
private
final
long
minDurationForQualityIncreaseUs
;
private
final
long
minDurationForQualityIncreaseUs
;
private
final
long
maxDurationForQualityDecreaseUs
;
private
final
long
maxDurationForQualityDecreaseUs
;
private
final
long
minDurationToRetainAfterDiscardUs
;
private
final
long
minDurationToRetainAfterDiscardUs
;
...
@@ -183,7 +183,7 @@ public interface FormatEvaluator {
...
@@ -183,7 +183,7 @@ public interface FormatEvaluator {
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
*/
*/
public
AdaptiveEvaluator
(
BandwidthMeter
bandwidthMeter
)
{
public
AdaptiveEvaluator
(
BandwidthMeter
bandwidthMeter
)
{
this
(
bandwidthMeter
,
DEFAULT_MAX_INITIAL_B
YTE_
RATE
,
this
(
bandwidthMeter
,
DEFAULT_MAX_INITIAL_B
IT
RATE
,
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS
,
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS
,
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS
,
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS
,
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS
,
DEFAULT_BANDWIDTH_FRACTION
);
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS
,
DEFAULT_BANDWIDTH_FRACTION
);
...
@@ -191,7 +191,7 @@ public interface FormatEvaluator {
...
@@ -191,7 +191,7 @@ public interface FormatEvaluator {
/**
/**
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
* @param maxInitialB
yteRate The maximum bandwidth in byte
s per second that should be assumed
* @param maxInitialB
itrate The maximum bitrate in bit
s per second that should be assumed
* when bandwidthMeter cannot provide an estimate due to playback having only just started.
* when bandwidthMeter cannot provide an estimate due to playback having only just started.
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for
* the evaluator to consider switching to a higher quality format.
* the evaluator to consider switching to a higher quality format.
...
@@ -206,13 +206,13 @@ public interface FormatEvaluator {
...
@@ -206,13 +206,13 @@ public interface FormatEvaluator {
* for inaccuracies in the bandwidth estimator.
* for inaccuracies in the bandwidth estimator.
*/
*/
public
AdaptiveEvaluator
(
BandwidthMeter
bandwidthMeter
,
public
AdaptiveEvaluator
(
BandwidthMeter
bandwidthMeter
,
int
maxInitialB
yteR
ate
,
int
maxInitialB
itr
ate
,
int
minDurationForQualityIncreaseMs
,
int
minDurationForQualityIncreaseMs
,
int
maxDurationForQualityDecreaseMs
,
int
maxDurationForQualityDecreaseMs
,
int
minDurationToRetainAfterDiscardMs
,
int
minDurationToRetainAfterDiscardMs
,
float
bandwidthFraction
)
{
float
bandwidthFraction
)
{
this
.
bandwidthMeter
=
bandwidthMeter
;
this
.
bandwidthMeter
=
bandwidthMeter
;
this
.
maxInitialB
yteRate
=
maxInitialByteR
ate
;
this
.
maxInitialB
itrate
=
maxInitialBitr
ate
;
this
.
minDurationForQualityIncreaseUs
=
minDurationForQualityIncreaseMs
*
1000L
;
this
.
minDurationForQualityIncreaseUs
=
minDurationForQualityIncreaseMs
*
1000L
;
this
.
maxDurationForQualityDecreaseUs
=
maxDurationForQualityDecreaseMs
*
1000L
;
this
.
maxDurationForQualityDecreaseUs
=
maxDurationForQualityDecreaseMs
*
1000L
;
this
.
minDurationToRetainAfterDiscardUs
=
minDurationToRetainAfterDiscardMs
*
1000L
;
this
.
minDurationToRetainAfterDiscardUs
=
minDurationToRetainAfterDiscardMs
*
1000L
;
...
@@ -235,7 +235,7 @@ public interface FormatEvaluator {
...
@@ -235,7 +235,7 @@ public interface FormatEvaluator {
long
bufferedDurationUs
=
queue
.
isEmpty
()
?
0
long
bufferedDurationUs
=
queue
.
isEmpty
()
?
0
:
queue
.
get
(
queue
.
size
()
-
1
).
endTimeUs
-
playbackPositionUs
;
:
queue
.
get
(
queue
.
size
()
-
1
).
endTimeUs
-
playbackPositionUs
;
Format
current
=
evaluation
.
format
;
Format
current
=
evaluation
.
format
;
Format
ideal
=
determineIdealFormat
(
formats
,
bandwidthMeter
.
getEstimate
());
Format
ideal
=
determineIdealFormat
(
formats
,
bandwidthMeter
.
get
Bitrate
Estimate
());
boolean
isHigher
=
ideal
!=
null
&&
current
!=
null
&&
ideal
.
bitrate
>
current
.
bitrate
;
boolean
isHigher
=
ideal
!=
null
&&
current
!=
null
&&
ideal
.
bitrate
>
current
.
bitrate
;
boolean
isLower
=
ideal
!=
null
&&
current
!=
null
&&
ideal
.
bitrate
<
current
.
bitrate
;
boolean
isLower
=
ideal
!=
null
&&
current
!=
null
&&
ideal
.
bitrate
<
current
.
bitrate
;
if
(
isHigher
)
{
if
(
isHigher
)
{
...
@@ -276,11 +276,11 @@ public interface FormatEvaluator {
...
@@ -276,11 +276,11 @@ public interface FormatEvaluator {
/**
/**
* Compute the ideal format ignoring buffer health.
* Compute the ideal format ignoring buffer health.
*/
*/
protected
Format
determineIdealFormat
(
Format
[]
formats
,
long
b
andwidth
Estimate
)
{
protected
Format
determineIdealFormat
(
Format
[]
formats
,
long
b
itrate
Estimate
)
{
long
effectiveB
andwidth
=
computeEffectiveBandwidthEstimate
(
bandwidth
Estimate
);
long
effectiveB
itrate
=
computeEffectiveBitrateEstimate
(
bitrate
Estimate
);
for
(
int
i
=
0
;
i
<
formats
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
formats
.
length
;
i
++)
{
Format
format
=
formats
[
i
];
Format
format
=
formats
[
i
];
if
(
(
format
.
bitrate
/
8
)
<=
effectiveBandwidth
)
{
if
(
format
.
bitrate
<=
effectiveBitrate
)
{
return
format
;
return
format
;
}
}
}
}
...
@@ -291,9 +291,9 @@ public interface FormatEvaluator {
...
@@ -291,9 +291,9 @@ public interface FormatEvaluator {
/**
/**
* Apply overhead factor, or default value in absence of estimate.
* Apply overhead factor, or default value in absence of estimate.
*/
*/
protected
long
computeEffectiveB
andwidthEstimate
(
long
bandwidth
Estimate
)
{
protected
long
computeEffectiveB
itrateEstimate
(
long
bitrate
Estimate
)
{
return
b
andwidth
Estimate
==
BandwidthMeter
.
NO_ESTIMATE
return
b
itrate
Estimate
==
BandwidthMeter
.
NO_ESTIMATE
?
maxInitialB
yteRate
:
(
long
)
(
bandwidth
Estimate
*
bandwidthFraction
);
?
maxInitialB
itrate
:
(
long
)
(
bitrate
Estimate
*
bandwidthFraction
);
}
}
}
}
...
...
library/src/main/java/com/google/android/exoplayer/upstream/BandwidthMeter.java
View file @
ad26085e
...
@@ -26,10 +26,10 @@ public interface BandwidthMeter {
...
@@ -26,10 +26,10 @@ public interface BandwidthMeter {
final
long
NO_ESTIMATE
=
-
1
;
final
long
NO_ESTIMATE
=
-
1
;
/**
/**
* Gets the estimated bandwidth.
* Gets the estimated bandwidth
, in bits/sec
.
*
*
* @return Estimated bandwidth in b
yte
s/sec, or {@link #NO_ESTIMATE} if no estimate is available.
* @return Estimated bandwidth in b
it
s/sec, or {@link #NO_ESTIMATE} if no estimate is available.
*/
*/
long
getEstimate
();
long
get
Bitrate
Estimate
();
}
}
library/src/main/java/com/google/android/exoplayer/upstream/DefaultBandwidthMeter.java
View file @
ad26085e
...
@@ -38,11 +38,11 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
...
@@ -38,11 +38,11 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
*
*
* @param elapsedMs The time taken to transfer the bytes, in milliseconds.
* @param elapsedMs The time taken to transfer the bytes, in milliseconds.
* @param bytes The number of bytes transferred.
* @param bytes The number of bytes transferred.
* @param b
andwidthEstimate The estimated bandwidth in bytes/sec, or {@link #NO_ESTIMATE} if no
* @param b
itrate The estimated bitrate in bits/sec, or {@link #NO_ESTIMATE} if no estimate
*
estimate is available. Note that this estimate is typically derived from more informatio
n
*
is available. Note that this estimate is typically derived from more information tha
n
*
than
{@code bytes} and {@code elapsedMs}.
* {@code bytes} and {@code elapsedMs}.
*/
*/
void
onBandwidthSample
(
int
elapsedMs
,
long
bytes
,
long
b
andwidthEstim
ate
);
void
onBandwidthSample
(
int
elapsedMs
,
long
bytes
,
long
b
itr
ate
);
}
}
...
@@ -53,9 +53,9 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
...
@@ -53,9 +53,9 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
private
final
Clock
clock
;
private
final
Clock
clock
;
private
final
SlidingPercentile
slidingPercentile
;
private
final
SlidingPercentile
slidingPercentile
;
private
long
a
ccumulator
;
private
long
bytesA
ccumulator
;
private
long
startTimeMs
;
private
long
startTimeMs
;
private
long
b
andwidth
Estimate
;
private
long
b
itrate
Estimate
;
private
int
streamCount
;
private
int
streamCount
;
public
DefaultBandwidthMeter
()
{
public
DefaultBandwidthMeter
()
{
...
@@ -80,17 +80,12 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
...
@@ -80,17 +80,12 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
this
.
eventListener
=
eventListener
;
this
.
eventListener
=
eventListener
;
this
.
clock
=
clock
;
this
.
clock
=
clock
;
this
.
slidingPercentile
=
new
SlidingPercentile
(
maxWeight
);
this
.
slidingPercentile
=
new
SlidingPercentile
(
maxWeight
);
b
andwidth
Estimate
=
NO_ESTIMATE
;
b
itrate
Estimate
=
NO_ESTIMATE
;
}
}
/**
* Gets the estimated bandwidth.
*
* @return Estimated bandwidth in bytes/sec, or {@link #NO_ESTIMATE} if no estimate is available.
*/
@Override
@Override
public
synchronized
long
getEstimate
()
{
public
synchronized
long
get
Bitrate
Estimate
()
{
return
b
andwidth
Estimate
;
return
b
itrate
Estimate
;
}
}
@Override
@Override
...
@@ -103,7 +98,7 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
...
@@ -103,7 +98,7 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
@Override
@Override
public
synchronized
void
onBytesTransferred
(
int
bytes
)
{
public
synchronized
void
onBytesTransferred
(
int
bytes
)
{
a
ccumulator
+=
bytes
;
bytesA
ccumulator
+=
bytes
;
}
}
@Override
@Override
...
@@ -112,32 +107,26 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
...
@@ -112,32 +107,26 @@ public class DefaultBandwidthMeter implements BandwidthMeter, TransferListener {
long
nowMs
=
clock
.
elapsedRealtime
();
long
nowMs
=
clock
.
elapsedRealtime
();
int
elapsedMs
=
(
int
)
(
nowMs
-
startTimeMs
);
int
elapsedMs
=
(
int
)
(
nowMs
-
startTimeMs
);
if
(
elapsedMs
>
0
)
{
if
(
elapsedMs
>
0
)
{
float
b
ytesPerSecond
=
accumulator
*
1000
/
elapsedMs
;
float
b
itsPerSecond
=
(
bytesAccumulator
*
8000
)
/
elapsedMs
;
slidingPercentile
.
addSample
(
computeWeight
(
accumulator
),
byte
sPerSecond
);
slidingPercentile
.
addSample
(
(
int
)
Math
.
sqrt
(
bytesAccumulator
),
bit
sPerSecond
);
float
bandwidthEstimateFloat
=
slidingPercentile
.
getPercentile
(
0.5f
);
float
bandwidthEstimateFloat
=
slidingPercentile
.
getPercentile
(
0.5f
);
b
andwidth
Estimate
=
Float
.
isNaN
(
bandwidthEstimateFloat
)
?
NO_ESTIMATE
b
itrate
Estimate
=
Float
.
isNaN
(
bandwidthEstimateFloat
)
?
NO_ESTIMATE
:
(
long
)
bandwidthEstimateFloat
;
:
(
long
)
bandwidthEstimateFloat
;
notifyBandwidthSample
(
elapsedMs
,
accumulator
,
bandwidth
Estimate
);
notifyBandwidthSample
(
elapsedMs
,
bytesAccumulator
,
bitrate
Estimate
);
}
}
streamCount
--;
streamCount
--;
if
(
streamCount
>
0
)
{
if
(
streamCount
>
0
)
{
startTimeMs
=
nowMs
;
startTimeMs
=
nowMs
;
}
}
accumulator
=
0
;
bytesAccumulator
=
0
;
}
// TODO: Use media time (bytes / mediaRate) as weight.
private
int
computeWeight
(
long
mediaBytes
)
{
return
(
int
)
Math
.
sqrt
(
mediaBytes
);
}
}
private
void
notifyBandwidthSample
(
final
int
elapsedMs
,
final
long
bytes
,
private
void
notifyBandwidthSample
(
final
int
elapsedMs
,
final
long
bytes
,
final
long
bitrate
)
{
final
long
bandwidthEstimate
)
{
if
(
eventHandler
!=
null
&&
eventListener
!=
null
)
{
if
(
eventHandler
!=
null
&&
eventListener
!=
null
)
{
eventHandler
.
post
(
new
Runnable
()
{
eventHandler
.
post
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
eventListener
.
onBandwidthSample
(
elapsedMs
,
bytes
,
b
andwidthEstim
ate
);
eventListener
.
onBandwidthSample
(
elapsedMs
,
bytes
,
b
itr
ate
);
}
}
});
});
}
}
...
...
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