Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 302 redirect #266

Merged
merged 4 commits into from
Jan 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Jesper Haug Karsrud <jesper.karsrud@gmail.com>
Nick Desaulniers <nick@mozilla.com>
Oskar Arvidsson <oskar@irock.se>
Philo Inc. <*@philo.com>
Robert Colantuoni <rgc@colantuoni.com>
Roi Lipman <roilipman@gmail.com>
Sanborn Hilland <sanbornh@rogers.com>
TalkTalk Plc <*@talktalkplc.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Jono Ward <jonoward@gmail.com>
Natalie Harris <natalieharris@google.com>
Nick Desaulniers <nick@mozilla.com>
Oskar Arvidsson <oskar@irock.se>
Robert Colantuoni <rgc@colantuoni.com>
Rohit Makasana <rohitbm@google.com>
Roi Lipman <roilipman@gmail.com>
Sanborn Hilland <sanbornh@rogers.com>
Expand Down
12 changes: 8 additions & 4 deletions lib/dash/mpd_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ goog.require('shaka.util.Uint8ArrayUtils');
* Numbers, times, and byte ranges are set to null if they cannot be parsed.
*
* @param {string} source The MPD XML text.
* @param {!Array.<!goog.Uri>} url The MPD URL for relative BaseURL resolution.
* @param {!Array.<!goog.Uri>} origUrl MPD URL for original download location.
* @param {!Array.<!goog.Uri>} baseUrl MPD URL for relative BaseURL resolution.
* @return {shaka.dash.mpd.Mpd}
*
* @see ISO/IEC 23009-1
*/
shaka.dash.mpd.parseMpd = function(source, url) {
shaka.dash.mpd.parseMpd = function(source, origUrl, baseUrl) {
var parser = new DOMParser();
var xml = parser.parseFromString(source, 'text/xml');

Expand All @@ -51,7 +52,7 @@ shaka.dash.mpd.parseMpd = function(source, url) {
}

// Construct a virtual parent for the MPD to use in resolving relative URLs.
var parent = { baseUrl: url };
var parent = { origUrl: origUrl, baseUrl: baseUrl };

return shaka.dash.mpd.parseChild_(parent, xml, shaka.dash.mpd.Mpd);
};
Expand Down Expand Up @@ -89,6 +90,9 @@ shaka.dash.mpd.Mpd = function() {
/** @type {string} */
this.type = 'static';

/** @type {Array.<!goog.Uri>} */
this.origUrl = null;

/** @type {Array.<!goog.Uri>} */
this.baseUrl = null;

Expand Down Expand Up @@ -869,7 +873,7 @@ shaka.dash.mpd.Mpd.prototype.parse = function(parent, elem) {
var mpd = shaka.dash.mpd;

// Parse attributes.
this.url = parent.baseUrl;
this.url = parent.origUrl;
this.id = mpd.parseAttr_(elem, 'id', mpd.parseString_);
this.type = mpd.parseAttr_(elem, 'type', mpd.parseString_) || 'static';
this.mediaPresentationDuration = mpd.parseAttr_(
Expand Down
2 changes: 1 addition & 1 deletion lib/dash/mpd_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ shaka.dash.MpdRequest.prototype.send = function() {
/** @param {!ArrayBuffer|string} data */
function(data) {
var mpd = shaka.dash.mpd.parseMpd(
/** @type {string} */ (data), url.urls);
/** @type {string} */ (data), url.urls, [url.currentUrl]);
if (mpd) {
return Promise.resolve(mpd);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/util/failover_uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ shaka.util.FailoverUri = function(callback, urls, opt_startByte, opt_endByte) {

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

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


Expand Down Expand Up @@ -134,6 +137,7 @@ shaka.util.FailoverUri.prototype.abortFetch = function() {
this.requestPromise_ = null;
this.request_.abort();
this.request_ = null;
this.currentUrl = null;
}
};

Expand Down Expand Up @@ -168,6 +172,12 @@ shaka.util.FailoverUri.prototype.createRequest_ =
// effectively cache every response.
this.requestPromise_ = null;
this.request_ = null;
this.currentUrl = null;
if (xhr.responseURL) {
this.currentUrl = new goog.Uri(xhr.responseURL);
} else {
this.currentUrl = this.urls[i];
}
return Promise.resolve(xhr.response);
}));

Expand Down
4 changes: 3 additions & 1 deletion spec/mpd_parser_base_url_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ describe('mpd.BaseUrl', function() {
'</MPD>'].join('\n');
var mpdUrl = 'http://example.com/dash/test.mpd';

var mpd = shaka.dash.mpd.parseMpd(source, createFailover(mpdUrl).urls);
var mpd = shaka.dash.mpd.parseMpd(source,
createFailover(mpdUrl).urls,
createFailover(mpdUrl).urls);
expect(mpd).toBeTruthy();
expect(mpd.baseUrl.toString()).toBe(mpdUrl);
expect(mpd.periods.length).toBe(1);
Expand Down
5 changes: 3 additions & 2 deletions spec/mpd_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,9 @@ describe('mpd', function() {
' <Location>updated_mpd</Location>',
'</MPD>'].join('\n');

var mpd = shaka.dash.mpd.parseMpd(source, createFailover(
'http://example.com/mpd').urls);
var mpd = shaka.dash.mpd.parseMpd(source,
createFailover('http://example.com/mpd').urls,
createFailover('http://example.com/mpd').urls);
expect(mpd.updateLocation.toString()).toBe(
'http://example.com/updated_mpd');
});
Expand Down