Skip to content

Commit

Permalink
Make OfflineVideoSource estimator arg nullable.
Browse files Browse the repository at this point in the history
Closes #72.

Change-Id: I73728c85ba8e8641a2a953c3ec11bcabc5ff6b2b
  • Loading branch information
natalieharris committed Apr 29, 2015
1 parent d2bb9cf commit a93a5c6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 39 deletions.
10 changes: 8 additions & 2 deletions lib/player/offline_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ goog.require('shaka.util.TypedBind');
* Creates an OfflineVideoSource.
* @param {?number} groupId The unique ID of the group of streams
* in this source.
* @param {!shaka.util.IBandwidthEstimator} estimator
* @param {shaka.util.IBandwidthEstimator} estimator
* @struct
* @constructor
* @extends {shaka.player.StreamVideoSource}
* @export
*/
shaka.player.OfflineVideoSource = function(groupId, estimator) {
if (!estimator) {
// For backward compatibility, provide an instance of the default
// implementation if none is provided.
estimator = new shaka.util.EWMABandwidthEstimator();
}

shaka.player.StreamVideoSource.call(this, null, estimator);

/** @private {?number} */
Expand Down Expand Up @@ -278,7 +284,7 @@ shaka.player.OfflineVideoSource.prototype.onSessionReady_ = function(event) {
*/
shaka.player.OfflineVideoSource.prototype.insertGroup_ =
function(selectedStreams, drmScheme, duration) {
var contentDatabase = new shaka.util.ContentDatabase(null, this);
var contentDatabase = new shaka.util.ContentDatabase(this.estimator, this);
var p = contentDatabase.setUpDatabase();

// Insert the group of streams into the database and close the connection.
Expand Down
14 changes: 7 additions & 7 deletions lib/player/stream_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ shaka.player.StreamVideoSource = function(manifestInfo, estimator) {
/** @private {boolean} */
this.subsNeeded_ = false;

/** @private {!shaka.util.IBandwidthEstimator} */
this.estimator_ = estimator;
/** @protected {!shaka.util.IBandwidthEstimator} */
this.estimator = estimator;

/** @private {shaka.player.Stats} */
this.stats_ = null;

/** @private {!shaka.media.AbrManager} */
this.abrManager_ = new shaka.media.AbrManager(this.estimator_, this);
this.abrManager_ = new shaka.media.AbrManager(this.estimator, this);
};
goog.inherits(shaka.player.StreamVideoSource, shaka.util.FakeEventTarget);

Expand Down Expand Up @@ -159,7 +159,7 @@ shaka.player.StreamVideoSource.prototype.destroy = function() {
this.mediaSource = null;
this.video = null;
this.attachPromise_ = null;
this.estimator_ = null;
this.estimator = null;

this.parent = null;
};
Expand All @@ -185,7 +185,7 @@ shaka.player.StreamVideoSource.prototype.attach = function(player, video) {
this.onMediaSourceOpen_.bind(this));

this.eventManager.listen(
this.estimator_,
this.estimator,
'bandwidth',
this.onBandwidth_.bind(this));

Expand Down Expand Up @@ -1337,7 +1337,7 @@ shaka.player.StreamVideoSource.prototype.createStream_ = function(
/** @type {!HTMLVideoElement} */ (this.video),
this.mediaSource,
/** @type {!SourceBuffer} */ (buf),
this.estimator_);
this.estimator);
};


Expand Down Expand Up @@ -1606,6 +1606,6 @@ shaka.player.StreamVideoSource.prototype.onSeeking = function() {
*/
shaka.player.StreamVideoSource.prototype.onBandwidth_ = function(event) {
shaka.asserts.assert(this.stats_);
this.stats_.logBandwidth(this.estimator_.getBandwidth());
this.stats_.logBandwidth(this.estimator.getBandwidth());
};

21 changes: 6 additions & 15 deletions tutorials/offline.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ <h3 class="tutorial-heading">
function initialize() {
if (!window.player)
initPlayer();

if (!window.estimator)
window.estimator = new shaka.util.EWMABandwidthEstimator();
}

function chooseTracks(videoSource) {
Expand Down Expand Up @@ -121,7 +118,7 @@ <h3 class="tutorial-heading">
// Construct an OfflineVideoSource.
var offlineSource = new shaka.player.OfflineVideoSource(
null, // groupId, not used when storing content.
window.estimator);
null); // estimator, optional parameter.

// Listen for progress events from the OfflineVideoSource.
offlineSource.addEventListener('progress', function(event) {
Expand Down Expand Up @@ -205,9 +202,6 @@ <h3 class="tutorial-heading">
function initialize() {
if (!window.player)
initPlayer();

if (!window.estimator)
window.estimator = new shaka.util.EWMABandwidthEstimator();
}

function chooseTracks(videoSource) {
Expand Down Expand Up @@ -244,7 +238,7 @@ <h3 class="tutorial-heading">
// Construct an OfflineVideoSource.
var offlineSource = new shaka.player.OfflineVideoSource(
null, // groupId, not used when storing content.
window.estimator);
null); // estimator, optional parameter.

// Listen for progress events from the OfflineVideoSource.
offlineSource.addEventListener('progress', function(event) {
Expand Down Expand Up @@ -272,7 +266,7 @@ <h3 class="tutorial-heading">
<span class="newCode"> function playOfflineContent() {</span>
<span class="newCode"> // Construct an OfflineVideoSource and load with player.</span>
<span class="newCode"> var offlineSource =</span>
<span class="newCode"> new shaka.player.OfflineVideoSource(window.groupId, window.estimator);</span>
<span class="newCode"> new shaka.player.OfflineVideoSource(window.groupId, null);</span>
<span class="newCode"> return window.player.load(offlineSource).then(</span>
<span class="newCode"> function() {</span>
<span class="newCode"> window.player.play();</span>
Expand Down Expand Up @@ -339,9 +333,6 @@ <h3 class="tutorial-heading">
function initialize() {
if (!window.player)
initPlayer();

if (!window.estimator)
window.estimator = new shaka.util.EWMABandwidthEstimator();
}

function chooseTracks(videoSource) {
Expand Down Expand Up @@ -378,7 +369,7 @@ <h3 class="tutorial-heading">
// Construct an OfflineVideoSource.
var offlineSource = new shaka.player.OfflineVideoSource(
null, // groupId, not used when storing content.
window.estimator);
null); // estimator, optional parameter.

// Listen for progress events from the OfflineVideoSource.
offlineSource.addEventListener('progress', function(event) {
Expand Down Expand Up @@ -406,7 +397,7 @@ <h3 class="tutorial-heading">
function playOfflineContent() {
// Construct an OfflineVideoSource and load with player.
var offlineSource =
new shaka.player.OfflineVideoSource(window.groupId, window.estimator);
new shaka.player.OfflineVideoSource(window.groupId, null);
return window.player.load(offlineSource).then(
function() {
window.player.play();
Expand All @@ -417,7 +408,7 @@ <h3 class="tutorial-heading">

<span class="newCode"> function deleteOfflineContent() {</span>
<span class="newCode"> var offlineSource =</span>
<span class="newCode"> new shaka.player.OfflineVideoSource(window.groupId, window.estimator);</span>
<span class="newCode"> new shaka.player.OfflineVideoSource(window.groupId, null);</span>
<span class="newCode"> return offlineSource.deleteGroup().then(</span>
<span class="newCode"> function() {</span>
<span class="newCode"> console.log('Offline content with group ID ' + window.groupId +</span>
Expand Down
5 changes: 1 addition & 4 deletions tutorials/sample7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
function initialize() {
if (!window.player)
initPlayer();

if (!window.estimator)
window.estimator = new shaka.util.EWMABandwidthEstimator();
}

function chooseTracks(videoSource) {
Expand Down Expand Up @@ -73,7 +70,7 @@
// Construct an OfflineVideoSource.
var offlineSource = new shaka.player.OfflineVideoSource(
null, // groupId, not used when storing content.
window.estimator);
null); // estimator, optional parameter.

// Listen for progress events from the OfflineVideoSource.
offlineSource.addEventListener('progress', function(event) {
Expand Down
7 changes: 2 additions & 5 deletions tutorials/sample8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
function initialize() {
if (!window.player)
initPlayer();

if (!window.estimator)
window.estimator = new shaka.util.EWMABandwidthEstimator();
}

function chooseTracks(videoSource) {
Expand Down Expand Up @@ -73,7 +70,7 @@
// Construct an OfflineVideoSource.
var offlineSource = new shaka.player.OfflineVideoSource(
null, // groupId, not used when storing content.
window.estimator);
null); // estimator, optional parameter.

// Listen for progress events from the OfflineVideoSource.
offlineSource.addEventListener('progress', function(event) {
Expand Down Expand Up @@ -101,7 +98,7 @@
function playOfflineContent() {
// Construct an OfflineVideoSource and load with player.
var offlineSource =
new shaka.player.OfflineVideoSource(window.groupId, window.estimator);
new shaka.player.OfflineVideoSource(window.groupId, null);
return window.player.load(offlineSource).then(
function() {
window.player.play();
Expand Down
9 changes: 3 additions & 6 deletions tutorials/sample9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
function initialize() {
if (!window.player)
initPlayer();

if (!window.estimator)
window.estimator = new shaka.util.EWMABandwidthEstimator();
}

function chooseTracks(videoSource) {
Expand Down Expand Up @@ -73,7 +70,7 @@
// Construct an OfflineVideoSource.
var offlineSource = new shaka.player.OfflineVideoSource(
null, // groupId, not used when storing content.
window.estimator);
null); // estimator, optional parameter.

// Listen for progress events from the OfflineVideoSource.
offlineSource.addEventListener('progress', function(event) {
Expand Down Expand Up @@ -101,7 +98,7 @@
function playOfflineContent() {
// Construct an OfflineVideoSource and load with player.
var offlineSource =
new shaka.player.OfflineVideoSource(window.groupId, window.estimator);
new shaka.player.OfflineVideoSource(window.groupId, null);
return window.player.load(offlineSource).then(
function() {
window.player.play();
Expand All @@ -112,7 +109,7 @@

function deleteOfflineContent() {
var offlineSource =
new shaka.player.OfflineVideoSource(window.groupId, window.estimator);
new shaka.player.OfflineVideoSource(window.groupId, null);
return offlineSource.deleteGroup().then(
function() {
console.log('Offline content with group ID ' + window.groupId +
Expand Down

0 comments on commit a93a5c6

Please sign in to comment.