diff --git a/lib/media/eme_manager.js b/lib/media/eme_manager.js index eba1cc68e2..2f0d348b2e 100644 --- a/lib/media/eme_manager.js +++ b/lib/media/eme_manager.js @@ -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. * @@ -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; @@ -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); diff --git a/lib/player/drm_scheme_info.js b/lib/player/drm_scheme_info.js index 30c7d89d92..22b8554e1f 100644 --- a/lib/player/drm_scheme_info.js +++ b/lib/player/drm_scheme_info.js @@ -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; }; diff --git a/lib/player/player.js b/lib/player/player.js index c64458c860..a7abc6166c 100644 --- a/lib/player/player.js +++ b/lib/player/player.js @@ -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); @@ -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, @@ -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 diff --git a/lib/player/stream_video_source.js b/lib/player/stream_video_source.js index 51a98f9847..7a7357ec64 100644 --- a/lib/player/stream_video_source.js +++ b/lib/player/stream_video_source.js @@ -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