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
39d5867c
authored
Jul 30, 2019
by
tonihei
Committed by
Oliver Woodman
Aug 01, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Make blocking fixed track bandwidth the default and remove experimental flag.
PiperOrigin-RevId: 260682878
parent
40926618
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
47 deletions
library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java
library/core/src/test/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelectionTest.java
library/core/src/main/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelection.java
View file @
39d5867c
...
@@ -49,7 +49,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -49,7 +49,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
private
final
Clock
clock
;
private
final
Clock
clock
;
private
TrackBitrateEstimator
trackBitrateEstimator
;
private
TrackBitrateEstimator
trackBitrateEstimator
;
private
boolean
blockFixedTrackSelectionBandwidth
;
/** Creates an adaptive track selection factory with default parameters. */
/** Creates an adaptive track selection factory with default parameters. */
public
Factory
()
{
public
Factory
()
{
...
@@ -218,15 +217,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -218,15 +217,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
this
.
trackBitrateEstimator
=
trackBitrateEstimator
;
this
.
trackBitrateEstimator
=
trackBitrateEstimator
;
}
}
/**
* Enables blocking of the total fixed track selection bandwidth.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*/
public
final
void
experimental_enableBlockFixedTrackSelectionBandwidth
()
{
this
.
blockFixedTrackSelectionBandwidth
=
true
;
}
@Override
@Override
public
final
@NullableType
TrackSelection
[]
createTrackSelections
(
public
final
@NullableType
TrackSelection
[]
createTrackSelections
(
@NullableType
Definition
[]
definitions
,
BandwidthMeter
bandwidthMeter
)
{
@NullableType
Definition
[]
definitions
,
BandwidthMeter
bandwidthMeter
)
{
...
@@ -234,20 +224,11 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -234,20 +224,11 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
bandwidthMeter
=
this
.
bandwidthMeter
;
bandwidthMeter
=
this
.
bandwidthMeter
;
}
}
TrackSelection
[]
selections
=
new
TrackSelection
[
definitions
.
length
];
TrackSelection
[]
selections
=
new
TrackSelection
[
definitions
.
length
];
List
<
AdaptiveTrackSelection
>
adaptiveSelections
=
new
ArrayList
<>();
int
totalFixedBandwidth
=
0
;
int
totalFixedBandwidth
=
0
;
for
(
int
i
=
0
;
i
<
definitions
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
definitions
.
length
;
i
++)
{
Definition
definition
=
definitions
[
i
];
Definition
definition
=
definitions
[
i
];
if
(
definition
==
null
)
{
if
(
definition
!=
null
&&
definition
.
tracks
.
length
==
1
)
{
continue
;
// Make fixed selections first to know their total bandwidth.
}
if
(
definition
.
tracks
.
length
>
1
)
{
AdaptiveTrackSelection
adaptiveSelection
=
createAdaptiveTrackSelection
(
definition
.
group
,
bandwidthMeter
,
definition
.
tracks
);
adaptiveSelection
.
experimental_setTrackBitrateEstimator
(
trackBitrateEstimator
);
adaptiveSelections
.
add
(
adaptiveSelection
);
selections
[
i
]
=
adaptiveSelection
;
}
else
{
selections
[
i
]
=
selections
[
i
]
=
new
FixedTrackSelection
(
new
FixedTrackSelection
(
definition
.
group
,
definition
.
tracks
[
0
],
definition
.
reason
,
definition
.
data
);
definition
.
group
,
definition
.
tracks
[
0
],
definition
.
reason
,
definition
.
data
);
...
@@ -257,9 +238,16 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -257,9 +238,16 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
}
}
}
}
}
}
if
(
blockFixedTrackSelectionBandwidth
)
{
List
<
AdaptiveTrackSelection
>
adaptiveSelections
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
adaptiveSelections
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
definitions
.
length
;
i
++)
{
adaptiveSelections
.
get
(
i
).
experimental_setNonAllocatableBandwidth
(
totalFixedBandwidth
);
Definition
definition
=
definitions
[
i
];
if
(
definition
!=
null
&&
definition
.
tracks
.
length
>
1
)
{
AdaptiveTrackSelection
adaptiveSelection
=
createAdaptiveTrackSelection
(
definition
.
group
,
bandwidthMeter
,
definition
.
tracks
,
totalFixedBandwidth
);
adaptiveSelection
.
experimental_setTrackBitrateEstimator
(
trackBitrateEstimator
);
adaptiveSelections
.
add
(
adaptiveSelection
);
selections
[
i
]
=
adaptiveSelection
;
}
}
}
}
if
(
adaptiveSelections
.
size
()
>
1
)
{
if
(
adaptiveSelections
.
size
()
>
1
)
{
...
@@ -288,14 +276,19 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -288,14 +276,19 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* @param group The {@link TrackGroup}.
* @param group The {@link TrackGroup}.
* @param bandwidthMeter A {@link BandwidthMeter} which can be used to select tracks.
* @param bandwidthMeter A {@link BandwidthMeter} which can be used to select tracks.
* @param tracks The indices of the selected tracks in the track group.
* @param tracks The indices of the selected tracks in the track group.
* @param totalFixedTrackBandwidth The total bandwidth used by all non-adaptive tracks, in bits
* per second.
* @return An {@link AdaptiveTrackSelection} for the specified tracks.
* @return An {@link AdaptiveTrackSelection} for the specified tracks.
*/
*/
protected
AdaptiveTrackSelection
createAdaptiveTrackSelection
(
protected
AdaptiveTrackSelection
createAdaptiveTrackSelection
(
TrackGroup
group
,
BandwidthMeter
bandwidthMeter
,
int
[]
tracks
)
{
TrackGroup
group
,
BandwidthMeter
bandwidthMeter
,
int
[]
tracks
,
int
totalFixedTrackBandwidth
)
{
return
new
AdaptiveTrackSelection
(
return
new
AdaptiveTrackSelection
(
group
,
group
,
tracks
,
tracks
,
new
DefaultBandwidthProvider
(
bandwidthMeter
,
bandwidthFraction
),
new
DefaultBandwidthProvider
(
bandwidthMeter
,
bandwidthFraction
,
totalFixedTrackBandwidth
),
minDurationForQualityIncreaseMs
,
minDurationForQualityIncreaseMs
,
maxDurationForQualityDecreaseMs
,
maxDurationForQualityDecreaseMs
,
minDurationToRetainAfterDiscardMs
,
minDurationToRetainAfterDiscardMs
,
...
@@ -341,6 +334,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -341,6 +334,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
group
,
group
,
tracks
,
tracks
,
bandwidthMeter
,
bandwidthMeter
,
/* reservedBandwidth= */
0
,
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_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS
,
...
@@ -355,6 +349,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -355,6 +349,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
* @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
* empty. May be in any order.
* empty. May be in any order.
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.
* @param reservedBandwidth The reserved bandwidth, which shouldn't be considered available for
* use, in bits per second.
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
* selected track to switch to one of higher quality.
* selected track to switch to one of higher quality.
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
...
@@ -381,6 +377,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -381,6 +377,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
TrackGroup
group
,
TrackGroup
group
,
int
[]
tracks
,
int
[]
tracks
,
BandwidthMeter
bandwidthMeter
,
BandwidthMeter
bandwidthMeter
,
long
reservedBandwidth
,
long
minDurationForQualityIncreaseMs
,
long
minDurationForQualityIncreaseMs
,
long
maxDurationForQualityDecreaseMs
,
long
maxDurationForQualityDecreaseMs
,
long
minDurationToRetainAfterDiscardMs
,
long
minDurationToRetainAfterDiscardMs
,
...
@@ -391,7 +388,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -391,7 +388,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
this
(
this
(
group
,
group
,
tracks
,
tracks
,
new
DefaultBandwidthProvider
(
bandwidthMeter
,
bandwidthFraction
),
new
DefaultBandwidthProvider
(
bandwidthMeter
,
bandwidthFraction
,
reservedBandwidth
),
minDurationForQualityIncreaseMs
,
minDurationForQualityIncreaseMs
,
maxDurationForQualityDecreaseMs
,
maxDurationForQualityDecreaseMs
,
minDurationToRetainAfterDiscardMs
,
minDurationToRetainAfterDiscardMs
,
...
@@ -446,18 +443,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -446,18 +443,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
}
}
/**
/**
* Sets the non-allocatable bandwidth, which shouldn't be considered available.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param nonAllocatableBandwidth The non-allocatable bandwidth in bits per second.
*/
public
void
experimental_setNonAllocatableBandwidth
(
long
nonAllocatableBandwidth
)
{
((
DefaultBandwidthProvider
)
bandwidthProvider
)
.
experimental_setNonAllocatableBandwidth
(
nonAllocatableBandwidth
);
}
/**
* Sets checkpoints to determine the allocation bandwidth based on the total bandwidth.
* Sets checkpoints to determine the allocation bandwidth based on the total bandwidth.
*
*
* @param allocationCheckpoints List of checkpoints. Each element must be a long[2], with [0]
* @param allocationCheckpoints List of checkpoints. Each element must be a long[2], with [0]
...
@@ -666,20 +651,21 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -666,20 +651,21 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
private
final
BandwidthMeter
bandwidthMeter
;
private
final
BandwidthMeter
bandwidthMeter
;
private
final
float
bandwidthFraction
;
private
final
float
bandwidthFraction
;
private
final
long
reservedBandwidth
;
private
long
nonAllocatableBandwidth
;
@Nullable
private
long
[][]
allocationCheckpoints
;
@Nullable
private
long
[][]
allocationCheckpoints
;
/* package */
DefaultBandwidthProvider
(
BandwidthMeter
bandwidthMeter
,
float
bandwidthFraction
)
{
/* package */
DefaultBandwidthProvider
(
BandwidthMeter
bandwidthMeter
,
float
bandwidthFraction
,
long
reservedBandwidth
)
{
this
.
bandwidthMeter
=
bandwidthMeter
;
this
.
bandwidthMeter
=
bandwidthMeter
;
this
.
bandwidthFraction
=
bandwidthFraction
;
this
.
bandwidthFraction
=
bandwidthFraction
;
this
.
reservedBandwidth
=
reservedBandwidth
;
}
}
@Override
@Override
public
long
getAllocatedBandwidth
()
{
public
long
getAllocatedBandwidth
()
{
long
totalBandwidth
=
(
long
)
(
bandwidthMeter
.
getBitrateEstimate
()
*
bandwidthFraction
);
long
totalBandwidth
=
(
long
)
(
bandwidthMeter
.
getBitrateEstimate
()
*
bandwidthFraction
);
long
allocatableBandwidth
=
Math
.
max
(
0L
,
totalBandwidth
-
nonAllocatable
Bandwidth
);
long
allocatableBandwidth
=
Math
.
max
(
0L
,
totalBandwidth
-
reserved
Bandwidth
);
if
(
allocationCheckpoints
==
null
)
{
if
(
allocationCheckpoints
==
null
)
{
return
allocatableBandwidth
;
return
allocatableBandwidth
;
}
}
...
@@ -695,10 +681,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
...
@@ -695,10 +681,6 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
return
previous
[
1
]
+
(
long
)
(
fractionBetweenCheckpoints
*
(
next
[
1
]
-
previous
[
1
]));
return
previous
[
1
]
+
(
long
)
(
fractionBetweenCheckpoints
*
(
next
[
1
]
-
previous
[
1
]));
}
}
/* package */
void
experimental_setNonAllocatableBandwidth
(
long
nonAllocatableBandwidth
)
{
this
.
nonAllocatableBandwidth
=
nonAllocatableBandwidth
;
}
/* package */
void
experimental_setBandwidthAllocationCheckpoints
(
/* package */
void
experimental_setBandwidthAllocationCheckpoints
(
long
[][]
allocationCheckpoints
)
{
long
[][]
allocationCheckpoints
)
{
Assertions
.
checkArgument
(
allocationCheckpoints
.
length
>=
2
);
Assertions
.
checkArgument
(
allocationCheckpoints
.
length
>=
2
);
...
...
library/core/src/test/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelectionTest.java
View file @
39d5867c
...
@@ -392,6 +392,7 @@ public final class AdaptiveTrackSelectionTest {
...
@@ -392,6 +392,7 @@ public final class AdaptiveTrackSelectionTest {
trackGroup
,
trackGroup
,
selectedAllTracksInGroup
(
trackGroup
),
selectedAllTracksInGroup
(
trackGroup
),
mockBandwidthMeter
,
mockBandwidthMeter
,
/* reservedBandwidth= */
0
,
minDurationForQualityIncreaseMs
,
minDurationForQualityIncreaseMs
,
AdaptiveTrackSelection
.
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS
,
AdaptiveTrackSelection
.
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS
,
AdaptiveTrackSelection
.
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS
,
AdaptiveTrackSelection
.
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS
,
...
@@ -408,6 +409,7 @@ public final class AdaptiveTrackSelectionTest {
...
@@ -408,6 +409,7 @@ public final class AdaptiveTrackSelectionTest {
trackGroup
,
trackGroup
,
selectedAllTracksInGroup
(
trackGroup
),
selectedAllTracksInGroup
(
trackGroup
),
mockBandwidthMeter
,
mockBandwidthMeter
,
/* reservedBandwidth= */
0
,
AdaptiveTrackSelection
.
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS
,
AdaptiveTrackSelection
.
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS
,
maxDurationForQualityDecreaseMs
,
maxDurationForQualityDecreaseMs
,
AdaptiveTrackSelection
.
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS
,
AdaptiveTrackSelection
.
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS
,
...
@@ -426,6 +428,7 @@ public final class AdaptiveTrackSelectionTest {
...
@@ -426,6 +428,7 @@ public final class AdaptiveTrackSelectionTest {
trackGroup
,
trackGroup
,
selectedAllTracksInGroup
(
trackGroup
),
selectedAllTracksInGroup
(
trackGroup
),
mockBandwidthMeter
,
mockBandwidthMeter
,
/* reservedBandwidth= */
0
,
AdaptiveTrackSelection
.
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS
,
AdaptiveTrackSelection
.
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS
,
AdaptiveTrackSelection
.
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS
,
AdaptiveTrackSelection
.
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS
,
durationToRetainAfterDiscardMs
,
durationToRetainAfterDiscardMs
,
...
...
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