Skip to content

Commit

Permalink
Rewrote timeline performance workaround with deferred segment URL con…
Browse files Browse the repository at this point in the history
…struction.
  • Loading branch information
torerikal committed Jul 18, 2016
1 parent 61f9a2d commit adbcdb5
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 16 deletions.
14 changes: 3 additions & 11 deletions lib/dash/timeline_segment_index_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ goog.require('shaka.asserts');
goog.require('shaka.dash.LiveSegmentIndex');
goog.require('shaka.features');
goog.require('shaka.log');
goog.require('shaka.vimond.DeferredUri');
goog.require('shaka.media.ISegmentIndexSource');
goog.require('shaka.media.SegmentIndex');
goog.require('shaka.media.SegmentReference');
Expand Down Expand Up @@ -127,19 +128,10 @@ shaka.dash.TimelineSegmentIndexSource.prototype.create = function() {
var timeReplacement = bigStartTime ? bigStartTime.toString() : startTime;

// Generate the media URL.
var mediaUrl = shaka.dash.MpdUtils.createFromTemplate(
var mediaUrl = new shaka.vimond.DeferredUri(
this.networkCallback_, this.representation_, segmentReplacement,
timeReplacement, 0, null);
//if (bigStartTime) {
// shaka.log.info('Applied big integer timecode,', mediaUrl);
//}
timeReplacement);

if (!mediaUrl) {
var error = new Error('Failed to generate media URL.');
error.type = 'dash';
return Promise.reject(error);
}

// The time points within a SegmentTimeline correspond to the timestamps
// within the media segments. So, if @presentationTimeOffset is non-zero
// then we must offset the SegmentReferences' start and end times by PTO so
Expand Down
10 changes: 5 additions & 5 deletions lib/util/failover_uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ shaka.util.FailoverUri = function(callback, urls, opt_startByte, opt_endByte) {
shaka.asserts.assert(urls);
shaka.asserts.assert(urls.length > 0);

/** @const {!Array.<!goog.Uri>} */
/** @public {!Array.<!goog.Uri>} */
this.urls = urls;

/** @const {number} */
/** @public {number} */
this.startByte = opt_startByte || 0;

/** @const {?number} */
/** @public {?number} */
this.endByte = opt_endByte != null ? opt_endByte : null;

/** @private {?Promise} */
/** @protected {?Promise} */
this.requestPromise_ = null;

/** @private {shaka.util.AjaxRequest} */
/** @protected {shaka.util.AjaxRequest} */
this.request_ = null;

/** @private {shaka.util.FailoverUri.NetworkCallback} */
Expand Down
96 changes: 96 additions & 0 deletions vimond/deferred-uri.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @license
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

goog.provide('shaka.vimond.DeferredUri');

goog.require('shaka.util.FailoverUri');
goog.require('goog.Uri');
goog.require('shaka.asserts');
goog.require('shaka.log');
goog.require('shaka.util.AjaxRequest');



/**
* Creates a FailoverUri, which handles requests to multiple URLs in case of
* failure.
*
* @param {shaka.util.FailoverUri.NetworkCallback} callback
* @param {!shaka.dash.mpd.Representation} representation
* @param {number} segmentReplacement
* @param {number} timeReplacement
* @extends {shaka.util.FailoverUri}
* @constructor
*/
shaka.vimond.DeferredUri = function(callback, representation, segmentReplacement, timeReplacement) {

/** @private {!shaka.dash.mpd.Representation} */
this.representation_ = representation;

/** @const {number} */
this.segmentReplacement_ = segmentReplacement;

/** @const {number} */
this.timeReplacement_ = timeReplacement;

/** @const {!Array.<!goog.Uri>} */
this.urls = [];

/** @const {number} */
this.startByte = 0;

/** @const {?number} */
this.endByte = null;

/** @private {?Promise} */
this.requestPromise_ = null;

/** @private {shaka.util.AjaxRequest} */
this.request_ = null;

/** @private {shaka.util.FailoverUri.NetworkCallback} */
this.callback2_ = callback;

/** @type {goog.Uri} */
this.currentUrl = null;
};

goog.inherits(shaka.vimond.DeferredUri, shaka.util.FailoverUri);

/**
* Constructs and returns the Uri when needed.
* @private
* @returns {shaka.util.FailoverUri}
*/
shaka.vimond.DeferredUri.prototype.getUri_ = function() {
"use strict";
return shaka.dash.MpdUtils.createFromTemplate(
this.callback2_, this.representation_, this.segmentReplacement_,
this.timeReplacement_, 0, null);
};

/** @override */
shaka.vimond.DeferredUri.prototype.fetch = function(opt_parameters, opt_estimator) {
"use strict";
this.urls.push(this.getUri_().urls[0]);
return shaka.util.FailoverUri.prototype.fetch.call(this, opt_parameters, opt_estimator);
};

/** @override */
shaka.vimond.DeferredUri.prototype.isOfflineUri = function() {
return false;
};

0 comments on commit adbcdb5

Please sign in to comment.