Skip to content

Commit

Permalink
Merge pull request #36 from sanbornhnewyyz/feature/restrictions
Browse files Browse the repository at this point in the history
Feature/restrictions
  • Loading branch information
joeyparrish committed Mar 17, 2015
2 parents e2f31dd + 5672cae commit a4e9bc3
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/media/eme_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ goog.require('shaka.util.Uint8ArrayUtils');
/**
* Creates the EME manager.
*
* @param {shaka.util.FakeEventTarget} parent The parent for event bubbling.
* @param {!shaka.player.Player} player The player instance.
* @param {!HTMLVideoElement} video The video element.
* @param {!shaka.player.IVideoSource} videoSource The video source.
*
Expand All @@ -44,8 +44,11 @@ goog.require('shaka.util.Uint8ArrayUtils');
* @struct
* @extends {shaka.util.FakeEventTarget}
*/
shaka.media.EmeManager = function(parent, video, videoSource) {
shaka.util.FakeEventTarget.call(this, parent);
shaka.media.EmeManager = function(player, video, videoSource) {
shaka.util.FakeEventTarget.call(this, player);

/** @private {!shaka.player.Player} */
this.player_ = player;

/** @private {!HTMLVideoElement} */
this.video_ = video;
Expand Down Expand Up @@ -470,9 +473,9 @@ shaka.media.EmeManager.prototype.requestLicense_ =
function(response) {
shaka.log.info('onLicenseSuccess_', session);
if (postProcessor) {
var restrictions = new shaka.player.DrmSchemeInfo.Restrictions();
var restrictions = this.player_.getRestrictions();
response = postProcessor(response, restrictions);
this.videoSource_.setRestrictions(restrictions);
this.player_.setRestrictions(restrictions);
}

return session.update(response);
Expand Down
30 changes: 30 additions & 0 deletions lib/player/drm_scheme_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,36 @@ 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;
};


/**
* @return {!shaka.player.DrmSchemeInfo.Restrictions}
* A copy of the current restrictions
*/
shaka.player.DrmSchemeInfo.Restrictions.prototype.clone = function() {
var restrictions = new shaka.player.DrmSchemeInfo.Restrictions();
restrictions.maxHeight = this.maxHeight;
restrictions.maxWidth = this.maxWidth;
restrictions.maxBandwidth = this.maxBandwidth;
restrictions.minBandwidth = this.minBandwidth;
return restrictions;
};


Expand Down
35 changes: 34 additions & 1 deletion lib/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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 @@ -276,8 +279,10 @@ shaka.player.Player.prototype.load = function(videoSource) {
).then(shaka.util.TypedBind(this,
function() {
this.videoSource_ = videoSource;
this.videoSource_.setRestrictions(this.restrictions_);
this.emeManager_ =
new shaka.media.EmeManager(this, this.video_, this.videoSource_);
new shaka.media.EmeManager(
this, this.video_, this.videoSource_);
return this.emeManager_.initialize();
})
).then(shaka.util.TypedBind(this,
Expand Down Expand Up @@ -735,6 +740,34 @@ shaka.player.Player.prototype.setPlaybackRate = function(rate) {
};


/**
* @param {shaka.player.DrmSchemeInfo.Restrictions} restrictions
* Restrictions object instance with custom restricions.
* For example: A Restrictions instance with maxBandwidth = 700000
* and minBandwidth = 200000 will restrict
* playback to video tracks with bandwidth between 700000 and 200000.
* @throws {TypeError} if restrictions argument isn't a Restrictions instance.
* @export
*/
shaka.player.Player.prototype.setRestrictions = function(restrictions) {
if (!(restrictions instanceof shaka.player.DrmSchemeInfo.Restrictions)) {
throw new TypeError('Argument must be a Restrictions instance.');
}
this.restrictions_ = restrictions;
this.videoSource_.setRestrictions(this.restrictions_);
};


/**
* @return {!shaka.player.DrmSchemeInfo.Restrictions}
* A copy of the current restrictions object.
* @export
*/
shaka.player.Player.prototype.getRestrictions = function() {
return this.restrictions_.clone();
};


/**
* 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

0 comments on commit a4e9bc3

Please sign in to comment.