From adbcdb5b886738319c3818b1bf7de416b8e4d8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Erik=20Alr=C3=A6k?= Date: Mon, 18 Jul 2016 21:45:22 +1000 Subject: [PATCH] Rewrote timeline performance workaround with deferred segment URL construction. --- lib/dash/timeline_segment_index_source.js | 14 +--- lib/util/failover_uri.js | 10 +-- vimond/deferred-uri.js | 96 +++++++++++++++++++++++ 3 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 vimond/deferred-uri.js diff --git a/lib/dash/timeline_segment_index_source.js b/lib/dash/timeline_segment_index_source.js index 4b8f4b07e8..3e75bc2f4b 100644 --- a/lib/dash/timeline_segment_index_source.js +++ b/lib/dash/timeline_segment_index_source.js @@ -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'); @@ -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 diff --git a/lib/util/failover_uri.js b/lib/util/failover_uri.js index a6435059b4..a7c09cdf40 100644 --- a/lib/util/failover_uri.js +++ b/lib/util/failover_uri.js @@ -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.} */ + /** @public {!Array.} */ 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} */ diff --git a/vimond/deferred-uri.js b/vimond/deferred-uri.js new file mode 100644 index 0000000000..5bcdfa2ba0 --- /dev/null +++ b/vimond/deferred-uri.js @@ -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.} */ + 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; +};