Skip to content

Commit

Permalink
Merge pull request TheWidlarzGroup#1310 from nfb-onf/maximumBitRate-a…
Browse files Browse the repository at this point in the history
…daptive-streaming

Support for maximum bit rate adaptive streaming

(rebased from commit 62f7221)
  • Loading branch information
cobarx authored and Beau Ner committed Oct 10, 2019
1 parent 7bea4f5 commit 17f5b89
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ var styles = StyleSheet.create({
* [hideShutterView](#hideshutterview)
* [id](#id)
* [ignoreSilentSwitch](#ignoresilentswitch)
* [maxBitRate](#maxbitrate)
* [muted](#muted)
* [paused](#paused)
* [playInBackground](#playinbackground)
Expand Down Expand Up @@ -444,6 +445,18 @@ Controls the iOS silent switch behavior

Platforms: iOS

#### maxBitRate
Sets the desired limit, in bits per second, of network bandwidth consumption when multiple video streams are available for a playlist.

Default: 0. Don't limit the maxBitRate.

Example:
```
maxBitRate={2000000} // 2 megabits
```

Platforms: Android ExoPlayer, iOS

#### muted
Controls whether the audio is muted
* **false (default)** - Don't mute audio
Expand Down Expand Up @@ -593,6 +606,7 @@ Sets the media source. You can pass an asset loaded via require or an object wit

The docs for this prop are incomplete and will be updated as each option is investigated and tested.


##### Asset loaded via require

Example:
Expand Down
1 change: 1 addition & 0 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ Video.propTypes = {
// Opaque type returned by require('./video.mp4')
PropTypes.number
]),
maxBitRate: PropTypes.number,
resizeMode: PropTypes.string,
poster: PropTypes.string,
posterResizeMode: Image.propTypes.resizeMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ReactExoplayerView extends FrameLayout implements
private boolean isBuffering;
private float rate = 1f;
private float audioVolume = 1f;
private int maxBitRate = 0;
private long seekTime = C.TIME_UNSET;

private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
Expand Down Expand Up @@ -250,6 +251,9 @@ private void initializePlayer() {
if (player == null) {
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
trackSelector.setParameters(trackSelector.buildUponParameters()
.setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate));

DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
DefaultLoadControl defaultLoadControl = new DefaultLoadControl(allocator, minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs, -1, true);
player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, defaultLoadControl);
Expand Down Expand Up @@ -946,6 +950,14 @@ public void setRateModifier(float newRate) {
}
}

public void setMaxBitRateModifier(int newMaxBitRate) {
maxBitRate = newMaxBitRate;
if (player != null) {
trackSelector.setParameters(trackSelector.buildUponParameters()
.setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate));
}
}


public void setPlayInBackground(boolean playInBackground) {
this.playInBackground = playInBackground;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
private static final String PROP_SEEK = "seek";
private static final String PROP_RATE = "rate";
private static final String PROP_MAXIMUM_BIT_RATE = "maxBitRate";
private static final String PROP_PLAY_IN_BACKGROUND = "playInBackground";
private static final String PROP_DISABLE_FOCUS = "disableFocus";
private static final String PROP_FULLSCREEN = "fullscreen";
Expand Down Expand Up @@ -235,6 +236,11 @@ public void setRate(final ReactExoplayerView videoView, final float rate) {
videoView.setRateModifier(rate);
}

@ReactProp(name = PROP_MAXIMUM_BIT_RATE)
public void setMaxBitRate(final ReactExoplayerView videoView, final int maxBitRate) {
videoView.setMaxBitRateModifier(maxBitRate);
}

@ReactProp(name = PROP_PLAY_IN_BACKGROUND, defaultBoolean = false)
public void setPlayInBackground(final ReactExoplayerView videoView, final boolean playInBackground) {
videoView.setPlayInBackground(playInBackground);
Expand Down
13 changes: 12 additions & 1 deletion ios/Video/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ @implementation RCTVideo
/* Keep track of any modifiers, need to be applied after each play */
float _volume;
float _rate;
float _maxBitRate;

BOOL _muted;
BOOL _paused;
BOOL _repeat;
Expand Down Expand Up @@ -525,7 +527,8 @@ - (void)crankVideo2 {
_playerItem = playerItem;
[self addPlayerItemObservers];
[self setFilter:_filterName];

[self setMaxBitRate:_maxBitRate];

[_player pause];
[_playerViewController.view removeFromSuperview];
_playerViewController = nil;
Expand Down Expand Up @@ -1300,6 +1303,12 @@ - (void)setVolume:(float)volume
[self applyModifiers];
}

- (void)setMaxBitRate:(float) maxBitRate {
_maxBitRate = maxBitRate;
[self applyModifiers];
}


- (void)applyModifiers
{
if (_muted) {
Expand All @@ -1310,6 +1319,8 @@ - (void)applyModifiers
[_player setMuted:NO];
}

_playerItem.preferredPeakBitRate = _maxBitRate;

[self setSelectedAudioTrack:_selectedAudioTrack];
[self setSelectedTextTrack:_selectedTextTrack];
[self setResizeMode:_resizeMode];
Expand Down
1 change: 1 addition & 0 deletions ios/Video/RCTVideoManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ - (dispatch_queue_t)methodQueue
// ZEROLABS end

RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(maxBitRate, float);
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
RCT_EXPORT_VIEW_PROPERTY(allowsExternalPlayback, BOOL);
Expand Down

0 comments on commit 17f5b89

Please sign in to comment.