Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bitrate limit #33

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/player/drm_scheme_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ shaka.player.DrmSchemeInfo.Restrictions = function() {
* @expose
*/
this.maxWidth = null;

/**
* If set, specifies a maximum bandwidth for video tracks.
*
* @type {?number}
* @expose
*/
this.maxBandwidth = null;

/**
* If set, specifies a minimum bandwidth for video tracks.
*
* @type {?number}
* @expose
*/
this.minBandwidth = null;
};


Expand Down
30 changes: 29 additions & 1 deletion lib/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ shaka.player.Player = function(video) {

/** @private {boolean} */
this.adaptationEnabled_ = true;

/** @private {!shaka.player.DrmSchemeInfo.Restrictions} */
this.restrictions_ = new shaka.player.DrmSchemeInfo.Restrictions();
};
goog.inherits(shaka.player.Player, shaka.util.FakeEventTarget);

Expand Down Expand Up @@ -292,6 +295,7 @@ shaka.player.Player.prototype.load = function(videoSource) {
).then(shaka.util.TypedBind(this,
function() {
this.videoSource_ = videoSource;
this.videoSource_.setRestrictions(this.restrictions_);
return this.initializeDrmScheme_();
})
).then(shaka.util.TypedBind(this,
Expand Down Expand Up @@ -724,7 +728,7 @@ shaka.player.Player.prototype.requestLicense_ =
function(response) {
shaka.log.info('onLicenseSuccess_', session);
if (postProcessor) {
var restrictions = new shaka.player.DrmSchemeInfo.Restrictions();
var restrictions = this.restrictions_;
response = postProcessor(response, restrictions);
this.videoSource_.setRestrictions(restrictions);
}
Expand Down Expand Up @@ -1145,6 +1149,30 @@ shaka.player.Player.prototype.setPlaybackRate = function(rate) {
};


/**
* @param {number} max Maximum bandwidth allowed for playback of video tracks
* @export
*/
shaka.player.Player.prototype.setMaxBandwidth = function(max) {
this.restrictions_.maxBandwidth = max;
if (this.videoSource_) {
this.videoSource_.setRestrictions(this.restrictions_);
}
};


/**
* @param {number} min Minimum bandwidth allowed for playback of video tracks
* @export
*/
shaka.player.Player.prototype.setMinBandwidth = function(min) {
this.restrictions_.minBandwidth = min;
if (this.videoSource_) {
this.videoSource_.setRestrictions(this.restrictions_);
}
};


/**
* Cancels the rewind timer, if any.
* @private
Expand Down
10 changes: 10 additions & 0 deletions lib/player/stream_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,16 @@ shaka.player.StreamVideoSource.prototype.setRestrictions =
streamInfo.height > restrictions.maxHeight) {
streamInfo.enabled = false;
}

if (restrictions.maxBandwidth &&
streamInfo.bandwidth > restrictions.maxBandwidth) {
streamInfo.enabled = false;
}

if (restrictions.minBandwidth &&
streamInfo.bandwidth < restrictions.minBandwidth) {
streamInfo.enabled = false;
}
} // for k
} // for j
} // for i
Expand Down