Skip to content

Commit

Permalink
fix(android): ensure maxbitrate & selectedVideoTrack interact correct…
Browse files Browse the repository at this point in the history
…ly (#4155)
  • Loading branch information
freeboub authored Sep 17, 2024
1 parent 1ef2b3a commit 7f6b500
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,11 @@ private void reLayoutControls() {
reLayout(playerControlView);
}

/// returns true is adaptive bitrate shall be used
public boolean isUsingVideoABR() {
return videoTrackType == null || "auto".equals(videoTrackType);
}

public void setDebug(boolean enableDebug) {
this.enableDebug = enableDebug;
refreshDebugState();
Expand Down Expand Up @@ -2041,16 +2046,21 @@ public void setSelectedTrack(int trackType, String type, String value) {

TrackSelectionOverride selectionOverride = new TrackSelectionOverride(groups.get(groupIndex), tracks);

DefaultTrackSelector.Parameters selectionParameters = trackSelector.getParameters()
DefaultTrackSelector.Parameters.Builder selectionParameters = trackSelector.getParameters()
.buildUpon()
.setExceedAudioConstraintsIfNecessary(true)
.setExceedRendererCapabilitiesIfNecessary(true)
.setExceedVideoConstraintsIfNecessary(true)
.setRendererDisabled(rendererIndex, false)
.clearOverridesOfType(selectionOverride.getType())
.addOverride(selectionOverride)
.build();
trackSelector.setParameters(selectionParameters);
.clearOverridesOfType(selectionOverride.getType());

if (trackType == C.TRACK_TYPE_VIDEO && isUsingVideoABR()) {
selectionParameters.setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate);
} else {
selectionParameters.addOverride(selectionOverride);
}

trackSelector.setParameters(selectionParameters.build());
}

private boolean isFormatSupported(Format format) {
Expand Down Expand Up @@ -2181,7 +2191,8 @@ public void setRateModifier(float newRate) {

public void setMaxBitRateModifier(int newMaxBitRate) {
maxBitRate = newMaxBitRate;
if (player != null) {
if (player != null && isUsingVideoABR()) {
// do not apply yet if not auto
trackSelector.setParameters(trackSelector.buildUponParameters()
.setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate));
}
Expand Down
3 changes: 3 additions & 0 deletions docs/pages/component/props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ Sets the desired limit, in bits per second, of network bandwidth consumption whe

Default: 0. Don't limit the maxBitRate.

Note: This property can interact with selectedVideoTrack.
To use `maxBitrate`, selectedVideoTrack shall be undefined or `{type: SelectedVideoTrackType.AUTO}`.

Example:

```javascript
Expand Down

0 comments on commit 7f6b500

Please sign in to comment.