mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-17 16:26:39 +03:00
Refactor ManifestParser.start to accept an object.
Rather than accepting multiple callback methods as separate arguments, now start() will accept an object. This will allow us to add new callbacks without breaking backwards compatibility or adding additional arguments. Change-Id: I839cbb12e71c2e7270aa218802c79440c458e964
This commit is contained in:
@@ -35,6 +35,32 @@
|
||||
shakaExtern.ManifestParser = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* networkingEngine: !shaka.net.NetworkingEngine,
|
||||
* filterPeriod: function(shakaExtern.Period),
|
||||
* onEvent: function(!Event),
|
||||
* onError: function(!shaka.util.Error)
|
||||
* }}
|
||||
*
|
||||
* Defines the interface of the Player to the manifest parser. This defines
|
||||
* fields and callback methods that the parser will use to interact with the
|
||||
* Player. The callback methods do not to be called as member functions (i.e.
|
||||
* they can be called as "free" functions).
|
||||
*
|
||||
* @property {!shaka.net.NetworkingEngine} networkingEngine
|
||||
* The networking engine to use for network requests.
|
||||
* @property {function(shakaExtern.Period)} filterPeriod
|
||||
* Should be called on all new Periods so that they can be filtered.
|
||||
* @property {function(!Event)} onEvent
|
||||
* Should be called to raise events.
|
||||
* @property {function(!shaka.util.Error)} onError
|
||||
* Should be called when an error occurs.
|
||||
* @exportDoc
|
||||
*/
|
||||
shakaExtern.ManifestParser.PlayerInterface;
|
||||
|
||||
|
||||
/**
|
||||
* A factory for creating the manifest parser. This will be called with 'new'.
|
||||
* This function is registered with shaka.media.ManifestParser to create parser
|
||||
@@ -61,19 +87,12 @@ shakaExtern.ManifestParser.prototype.configure = function(config) {};
|
||||
* background timers that are needed. This will only be called once.
|
||||
*
|
||||
* @param {string} uri The URI of the manifest.
|
||||
* @param {!shaka.net.NetworkingEngine} networkingEngine The networking engine
|
||||
* to use for network requests.
|
||||
* @param {function(shakaExtern.Period)} filterPeriod A callback to be invoked
|
||||
* on all new Periods so that they can be filtered.
|
||||
* @param {function(!shaka.util.Error)} onError A callback to be invoked on
|
||||
* errors.
|
||||
* @param {function(!Event)} onEvent A callback to be invoked to dispatch events
|
||||
* to the application.
|
||||
* @param {shakaExtern.ManifestParser.PlayerInterface} playerInterface Contains
|
||||
* the interface to the Player.
|
||||
* @return {!Promise.<shakaExtern.Manifest>}
|
||||
* @exportDoc
|
||||
*/
|
||||
shakaExtern.ManifestParser.prototype.start =
|
||||
function(uri, networkingEngine, filterPeriod, onError, onEvent) {};
|
||||
shakaExtern.ManifestParser.prototype.start = function(uri, playerInterface) {};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+36
-49
@@ -51,20 +51,11 @@ goog.require('shaka.util.XmlUtils');
|
||||
* @export
|
||||
*/
|
||||
shaka.dash.DashParser = function() {
|
||||
/** @private {shaka.net.NetworkingEngine} */
|
||||
this.networkingEngine_ = null;
|
||||
|
||||
/** @private {?shakaExtern.ManifestConfiguration} */
|
||||
this.config_ = null;
|
||||
|
||||
/** @private {?function(shakaExtern.Period)} */
|
||||
this.filterPeriod_ = null;
|
||||
|
||||
/** @private {?function(!shaka.util.Error)} */
|
||||
this.onError_ = null;
|
||||
|
||||
/** @private {?function(!shaka.util.FakeEvent)} */
|
||||
this.onEvent_ = null;
|
||||
/** @private {?shakaExtern.ManifestParser.PlayerInterface} */
|
||||
this.playerInterface_ = null;
|
||||
|
||||
/** @private {!Array.<string>} */
|
||||
this.manifestUris_ = [];
|
||||
@@ -354,16 +345,12 @@ shaka.dash.DashParser.prototype.configure = function(config) {
|
||||
|
||||
|
||||
/** @override */
|
||||
shaka.dash.DashParser.prototype.start =
|
||||
function(uri, networkingEngine, filterPeriod, onError, onEvent) {
|
||||
shaka.dash.DashParser.prototype.start = function(uri, playerInterface) {
|
||||
goog.asserts.assert(this.config_, 'Must call configure() before start()!');
|
||||
this.manifestUris_ = [uri];
|
||||
this.networkingEngine_ = networkingEngine;
|
||||
this.filterPeriod_ = filterPeriod;
|
||||
this.onError_ = onError;
|
||||
this.onEvent_ = onEvent;
|
||||
this.playerInterface_ = playerInterface;
|
||||
return this.requestManifest_().then(function() {
|
||||
if (this.networkingEngine_)
|
||||
if (this.playerInterface_)
|
||||
this.setUpdateTimer_(0);
|
||||
return this.manifest_;
|
||||
}.bind(this));
|
||||
@@ -372,12 +359,11 @@ shaka.dash.DashParser.prototype.start =
|
||||
|
||||
/** @override */
|
||||
shaka.dash.DashParser.prototype.stop = function() {
|
||||
if (this.networkingEngine_)
|
||||
this.networkingEngine_.unregisterResponseFilter(this.emsgResponseFilter_);
|
||||
this.networkingEngine_ = null;
|
||||
this.filterPeriod_ = null;
|
||||
this.onError_ = null;
|
||||
this.onEvent_ = null;
|
||||
if (this.playerInterface_) {
|
||||
this.playerInterface_.networkingEngine.unregisterResponseFilter(
|
||||
this.emsgResponseFilter_);
|
||||
}
|
||||
this.playerInterface_ = null;
|
||||
this.config_ = null;
|
||||
|
||||
this.manifestUris_ = [];
|
||||
@@ -403,10 +389,10 @@ shaka.dash.DashParser.prototype.requestManifest_ = function() {
|
||||
var requestType = shaka.net.NetworkingEngine.RequestType.MANIFEST;
|
||||
var request = shaka.net.NetworkingEngine.makeRequest(
|
||||
this.manifestUris_, this.config_.retryParameters);
|
||||
return this.networkingEngine_.request(requestType, request)
|
||||
return this.playerInterface_.networkingEngine.request(requestType, request)
|
||||
.then(function(response) {
|
||||
// Detect calls to stop().
|
||||
if (!this.networkingEngine_)
|
||||
if (!this.playerInterface_)
|
||||
return;
|
||||
|
||||
// This may throw; but it will result in a failed promise.
|
||||
@@ -544,13 +530,15 @@ shaka.dash.DashParser.prototype.parseManifest_ =
|
||||
|
||||
// if any of the periods had an emsg box indicator,
|
||||
// register a response filter to look for an EMSG box in segments
|
||||
if (periodsAndDuration.containsInband)
|
||||
this.networkingEngine_.registerResponseFilter(this.emsgResponseFilter_);
|
||||
if (periodsAndDuration.containsInband) {
|
||||
this.playerInterface_.networkingEngine.registerResponseFilter(
|
||||
this.emsgResponseFilter_);
|
||||
}
|
||||
|
||||
return this.parseUtcTiming_(
|
||||
baseUris, timingElements, isLive).then(function(offset) {
|
||||
// Detect calls to stop().
|
||||
if (!this.networkingEngine_)
|
||||
if (!this.playerInterface_)
|
||||
return;
|
||||
|
||||
presentationTimeline.setClockOffset(offset);
|
||||
@@ -628,7 +616,7 @@ shaka.dash.DashParser.prototype.parsePeriods_ = function(
|
||||
// manifest. If this is the first parse, it will see all of them as new.
|
||||
var periodId = context.period.id;
|
||||
if (this.periodIds_.every(Functional.isNotEqualFunc(periodId))) {
|
||||
this.filterPeriod_(period);
|
||||
this.playerInterface_.filterPeriod(period);
|
||||
this.periodIds_.push(periodId);
|
||||
if (this.manifest_)
|
||||
this.manifest_.periods.push(period);
|
||||
@@ -1105,7 +1093,7 @@ shaka.dash.DashParser.prototype.onUpdate_ = function() {
|
||||
|
||||
this.requestManifest_().then(function() {
|
||||
// Detect a call to stop()
|
||||
if (!this.networkingEngine_)
|
||||
if (!this.playerInterface_)
|
||||
return;
|
||||
|
||||
// Ensure the next update occurs within |updatePeriod_| seconds by taking
|
||||
@@ -1115,10 +1103,10 @@ shaka.dash.DashParser.prototype.onUpdate_ = function() {
|
||||
}.bind(this)).catch(function(error) {
|
||||
goog.asserts.assert(error instanceof shaka.util.Error,
|
||||
'Should only receive a Shaka error');
|
||||
this.onError_(error);
|
||||
this.playerInterface_.onError(error);
|
||||
|
||||
// Try updating again, but ensure we haven't been destroyed.
|
||||
if (this.networkingEngine_) {
|
||||
if (this.playerInterface_) {
|
||||
this.setUpdateTimer_(0);
|
||||
}
|
||||
}.bind(this));
|
||||
@@ -1269,20 +1257,20 @@ shaka.dash.DashParser.prototype.requestForTiming_ =
|
||||
requestUris, this.config_.retryParameters);
|
||||
request.method = method;
|
||||
var type = shaka.net.NetworkingEngine.RequestType.MANIFEST;
|
||||
return this.networkingEngine_.request(type, request).then(function(response) {
|
||||
var text;
|
||||
if (method == 'HEAD') {
|
||||
if (!response.headers || !response.headers['date'])
|
||||
return 0;
|
||||
return this.playerInterface_.networkingEngine.request(type, request)
|
||||
.then(function(response) {
|
||||
var text;
|
||||
if (method == 'HEAD') {
|
||||
if (!response.headers || !response.headers['date']) return 0;
|
||||
|
||||
text = response.headers['date'];
|
||||
} else {
|
||||
text = shaka.util.StringUtils.fromUTF8(response.data);
|
||||
}
|
||||
text = response.headers['date'];
|
||||
} else {
|
||||
text = shaka.util.StringUtils.fromUTF8(response.data);
|
||||
}
|
||||
|
||||
var date = Date.parse(text);
|
||||
return isNaN(date) ? 0 : (date - Date.now());
|
||||
});
|
||||
var date = Date.parse(text);
|
||||
return isNaN(date) ? 0 : (date - Date.now());
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1375,7 +1363,7 @@ shaka.dash.DashParser.prototype.requestInitSegment_ = function(
|
||||
request.headers['Range'] = 'bytes=' + startByte + '-' + end;
|
||||
}
|
||||
|
||||
return this.networkingEngine_.request(requestType, request)
|
||||
return this.playerInterface_.networkingEngine.request(requestType, request)
|
||||
.then(function(response) { return response.data; });
|
||||
};
|
||||
|
||||
@@ -1429,9 +1417,8 @@ shaka.dash.DashParser.prototype.emsgResponseFilter_ = function(type, response) {
|
||||
messageData: messageData
|
||||
};
|
||||
|
||||
var event = new shaka.util.FakeEvent(
|
||||
'emsg', { 'detail': emsg });
|
||||
this.onEvent_(event);
|
||||
var event = new shaka.util.FakeEvent('emsg', { 'detail': emsg });
|
||||
this.playerInterface_.onEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ shaka.offline.OfflineManifestParser.prototype.configure = function(config) {
|
||||
|
||||
/** @override */
|
||||
shaka.offline.OfflineManifestParser.prototype.start =
|
||||
function(uri, networkingEngine, filterPeriod, onError) {
|
||||
function(uri, playerInterface) {
|
||||
var parts = /^offline:([0-9]+)$/.exec(uri);
|
||||
if (!parts) {
|
||||
return Promise.reject(new shaka.util.Error(
|
||||
|
||||
+21
-6
@@ -414,12 +414,27 @@ shaka.Player.prototype.load = function(manifestUri, opt_startTime,
|
||||
this.parser_ = new factory();
|
||||
this.parser_.configure(this.config_.manifest);
|
||||
goog.asserts.assert(this.networkingEngine_, 'Must not be destroyed');
|
||||
return this.parser_.start(
|
||||
manifestUri,
|
||||
this.networkingEngine_,
|
||||
this.filterPeriod_.bind(this),
|
||||
this.onError_.bind(this),
|
||||
this.onEvent_.bind(this));
|
||||
var playerInterface = {
|
||||
networkingEngine: this.networkingEngine_,
|
||||
filterPeriod: this.filterPeriod_.bind(this),
|
||||
onEvent: this.onEvent_.bind(this),
|
||||
onError: this.onError_.bind(this)
|
||||
};
|
||||
|
||||
if (this.parser_.start.length > 2) {
|
||||
goog.asserts.assert(false, 'Old ManifestParser interface is deprecated');
|
||||
shaka.log.warning(
|
||||
'The ManifestParser interface has changed. Please upgrade your ' +
|
||||
'plugin to accept the PlayerInterface structure. See the ' +
|
||||
'ManifestParser documentation for details.');
|
||||
// Use a string index here so the compiler doesn't complain about the
|
||||
// incorrect arguments.
|
||||
return this.parser_['start'](
|
||||
manifestUri, this.networkingEngine_, playerInterface.filterPeriod,
|
||||
playerInterface.onError, playerInterface.onEvent);
|
||||
}
|
||||
|
||||
return this.parser_.start(manifestUri, playerInterface);
|
||||
}.bind(this)).then(function(manifest) {
|
||||
|
||||
if (manifest.periods.length == 0) {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
// Test DRM-related parsing.
|
||||
describe('DashParser ContentProtection', function() {
|
||||
var Dash;
|
||||
var filterPeriod = function() {};
|
||||
|
||||
/**
|
||||
* Tests that the parser produces the correct results.
|
||||
@@ -39,7 +38,14 @@ describe('DashParser ContentProtection', function() {
|
||||
retryParameters: retry,
|
||||
dash: { clockSyncUri: '', customScheme: callback }
|
||||
});
|
||||
dashParser.start('http://example.com', netEngine, filterPeriod, fail, fail)
|
||||
var playerEvents = {
|
||||
networkingEngine: netEngine,
|
||||
filterPeriod: function() {},
|
||||
onEvent: fail,
|
||||
onError: fail
|
||||
};
|
||||
|
||||
dashParser.start('http://example.com', playerEvents)
|
||||
.then(function(actual) { expect(actual).toEqual(expected); })
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
|
||||
describe('DashParser Live', function() {
|
||||
var Dash;
|
||||
var errorCallback;
|
||||
var fakeNetEngine;
|
||||
var newPeriod;
|
||||
var oldNow;
|
||||
var parser;
|
||||
var realTimeout;
|
||||
var updateTime = 5;
|
||||
var playerInterface;
|
||||
var Util;
|
||||
|
||||
beforeAll(function() {
|
||||
@@ -39,13 +38,17 @@ describe('DashParser Live', function() {
|
||||
beforeEach(function() {
|
||||
var retry = shaka.net.NetworkingEngine.defaultRetryParameters();
|
||||
fakeNetEngine = new shaka.test.FakeNetworkingEngine();
|
||||
newPeriod = jasmine.createSpy('newPeriod');
|
||||
errorCallback = jasmine.createSpy('error callback');
|
||||
parser = new shaka.dash.DashParser();
|
||||
parser.configure({
|
||||
retryParameters: retry,
|
||||
dash: { clockSyncUri: '', customScheme: function(node) { return null; } }
|
||||
});
|
||||
playerInterface = {
|
||||
networkingEngine: fakeNetEngine,
|
||||
filterPeriod: function() {},
|
||||
onEvent: fail,
|
||||
onError: fail
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
@@ -128,7 +131,7 @@ describe('DashParser Live', function() {
|
||||
var secondManifest = makeSimpleLiveManifestText(secondLines, updateTime);
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': firstManifest});
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
Dash.verifySegmentIndex(manifest, firstReferences, 0);
|
||||
|
||||
@@ -169,7 +172,7 @@ describe('DashParser Live', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': text});
|
||||
Date.now = function() { return 0; };
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBeTruthy();
|
||||
var stream = manifest.periods[0].variants[0].video;
|
||||
@@ -227,7 +230,7 @@ describe('DashParser Live', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': text});
|
||||
Date.now = function() { return 0; };
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
Dash.verifySegmentIndex(manifest, basicRefs, 0);
|
||||
Dash.verifySegmentIndex(manifest, basicRefs, 1);
|
||||
@@ -270,7 +273,7 @@ describe('DashParser Live', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': text});
|
||||
Date.now = function() { return 0; };
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods.length).toBe(1);
|
||||
var timeline = manifest.presentationTimeline;
|
||||
@@ -308,7 +311,7 @@ describe('DashParser Live', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': text});
|
||||
Date.now = function() { return 0; };
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods.length).toBe(2);
|
||||
expect(manifest.periods[1].startTime).toBe(60);
|
||||
@@ -341,18 +344,21 @@ describe('DashParser Live', function() {
|
||||
sprintf(template, {updateTime: updateTime, contents: lines.join('\n')});
|
||||
var firstManifest = makeSimpleLiveManifestText(lines, updateTime);
|
||||
|
||||
var filterPeriod = jasmine.createSpy('filterPeriod');
|
||||
playerInterface.filterPeriod = filterPeriod;
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': firstManifest});
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods.length).toBe(1);
|
||||
expect(newPeriod.calls.count()).toBe(1);
|
||||
expect(filterPeriod.calls.count()).toBe(1);
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': secondManifest});
|
||||
delayForUpdatePeriod();
|
||||
|
||||
// Should update the same manifest object.
|
||||
expect(manifest.periods.length).toBe(2);
|
||||
expect(newPeriod.calls.count()).toBe(2);
|
||||
expect(filterPeriod.calls.count()).toBe(2);
|
||||
}).catch(fail).then(done);
|
||||
shaka.polyfill.Promise.flush();
|
||||
});
|
||||
@@ -386,7 +392,7 @@ describe('DashParser Live', function() {
|
||||
fakeNetEngine.request.and.returnValue(
|
||||
Promise.resolve({uri: redirectedUri, data: manifestData}));
|
||||
|
||||
parser.start(originalUri, fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start(originalUri, playerInterface)
|
||||
.then(function(manifest) {
|
||||
// The manifest request was made to the original URL.
|
||||
expect(fakeNetEngine.request.calls.count()).toBe(1);
|
||||
@@ -407,9 +413,10 @@ describe('DashParser Live', function() {
|
||||
'<SegmentTemplate startNumber="1" media="s$Number$.mp4" duration="2" />'
|
||||
];
|
||||
var manifest = makeSimpleLiveManifestText(lines, updateTime);
|
||||
playerInterface.onError = jasmine.createSpy('onError');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifest});
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(fakeNetEngine.request.calls.count()).toBe(1);
|
||||
|
||||
@@ -420,7 +427,7 @@ describe('DashParser Live', function() {
|
||||
fakeNetEngine.request.and.returnValue(promise);
|
||||
|
||||
delayForUpdatePeriod();
|
||||
expect(errorCallback.calls.count()).toBe(1);
|
||||
expect(playerInterface.onError.calls.count()).toBe(1);
|
||||
}).catch(fail).then(done);
|
||||
shaka.polyfill.Promise.flush();
|
||||
});
|
||||
@@ -433,7 +440,7 @@ describe('DashParser Live', function() {
|
||||
var manifest = makeSimpleLiveManifestText(lines, updateTime);
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifest});
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(fakeNetEngine.request.calls.count()).toBe(1);
|
||||
expect(manifest).toBeTruthy();
|
||||
@@ -455,7 +462,7 @@ describe('DashParser Live', function() {
|
||||
});
|
||||
|
||||
it('uses Mpd.Location', function(done) {
|
||||
var manifest = [
|
||||
var manifestText = [
|
||||
'<MPD type="dynamic" availabilityStartTime="1970-01-01T00:00:00Z"',
|
||||
' suggestedPresentationDelay="PT5S"',
|
||||
' minimumUpdatePeriod="PT' + updateTime + 'S">',
|
||||
@@ -470,10 +477,10 @@ describe('DashParser Live', function() {
|
||||
' </Period>',
|
||||
'</MPD>'
|
||||
].join('\n');
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifest});
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText});
|
||||
|
||||
var manifestRequest = shaka.net.NetworkingEngine.RequestType.MANIFEST;
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(fakeNetEngine.request.calls.count()).toBe(1);
|
||||
fakeNetEngine.expectRequest('dummy://foo', manifestRequest);
|
||||
@@ -483,7 +490,7 @@ describe('DashParser Live', function() {
|
||||
fakeNetEngine.request.and.callFake(function(type, request) {
|
||||
expect(type).toBe(manifestRequest);
|
||||
expect(request.uris).toEqual(['http://foobar', 'http://foobar2']);
|
||||
var data = shaka.util.StringUtils.toUTF8(manifest);
|
||||
var data = shaka.util.StringUtils.toUTF8(manifestText);
|
||||
return Promise.resolve(
|
||||
{uri: request.uris[0], data: data, headers: {}});
|
||||
});
|
||||
@@ -514,7 +521,7 @@ describe('DashParser Live', function() {
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifest});
|
||||
|
||||
Date.now = function() { return 600000; /* 10 minutes */ };
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBeTruthy();
|
||||
var timeline = manifest.presentationTimeline;
|
||||
@@ -554,7 +561,7 @@ describe('DashParser Live', function() {
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifest});
|
||||
|
||||
Date.now = function() { return 600000; /* 10 minutes */ };
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBeTruthy();
|
||||
var timeline = manifest.presentationTimeline;
|
||||
@@ -630,7 +637,7 @@ describe('DashParser Live', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifest});
|
||||
Date.now = function() { return 600000; /* 10 minutes */ };
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBeTruthy();
|
||||
var timeline = manifest.presentationTimeline;
|
||||
@@ -683,7 +690,7 @@ describe('DashParser Live', function() {
|
||||
});
|
||||
|
||||
it('stops updates', function(done) {
|
||||
parser.start(manifestUri, fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start(manifestUri, playerInterface)
|
||||
.then(function(manifest) {
|
||||
fakeNetEngine.expectRequest(manifestUri, manifestRequestType);
|
||||
fakeNetEngine.request.calls.reset();
|
||||
@@ -696,7 +703,7 @@ describe('DashParser Live', function() {
|
||||
});
|
||||
|
||||
it('stops initial parsing', function(done) {
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBe(null);
|
||||
fakeNetEngine.expectRequest(manifestUri, manifestRequestType);
|
||||
@@ -714,7 +721,7 @@ describe('DashParser Live', function() {
|
||||
});
|
||||
|
||||
it('interrupts manifest updates', function(done) {
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBeTruthy();
|
||||
fakeNetEngine.expectRequest(manifestUri, manifestRequestType);
|
||||
@@ -766,8 +773,7 @@ describe('DashParser Live', function() {
|
||||
expect(fakeNetEngine.request).not.toHaveBeenCalled();
|
||||
}).catch(fail).then(done);
|
||||
|
||||
parser.start('dummy://foo', fakeNetEngine, newPeriod, errorCallback)
|
||||
.catch(fail);
|
||||
parser.start('dummy://foo', playerInterface).catch(fail);
|
||||
shaka.polyfill.Promise.flush();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,13 +20,19 @@ describe('DashParser Manifest', function() {
|
||||
var Dash;
|
||||
var fakeNetEngine;
|
||||
var parser;
|
||||
var filterPeriod = function() {};
|
||||
var onEventSpy;
|
||||
var playerInterface;
|
||||
|
||||
beforeEach(function() {
|
||||
fakeNetEngine = new shaka.test.FakeNetworkingEngine();
|
||||
parser = shaka.test.Dash.makeDashParser();
|
||||
onEventSpy = jasmine.createSpy('onEvent');
|
||||
playerInterface = {
|
||||
networkingEngine: fakeNetEngine,
|
||||
filterPeriod: function() {},
|
||||
onEvent: onEventSpy,
|
||||
onError: fail
|
||||
};
|
||||
});
|
||||
|
||||
beforeAll(function() {
|
||||
@@ -59,7 +65,7 @@ describe('DashParser Manifest', function() {
|
||||
*/
|
||||
function testDashParser(done, manifestText) {
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(actual) { expect(actual).toEqual(expected); })
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
@@ -203,7 +209,7 @@ describe('DashParser Manifest', function() {
|
||||
var source = sprintf(template, {periodContents: periodContents});
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods.length).toBe(1);
|
||||
})
|
||||
@@ -237,7 +243,7 @@ describe('DashParser Manifest', function() {
|
||||
var source = sprintf(template, {periodContents: periodContents});
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods.length).toBe(3);
|
||||
expect(manifest.periods[0].startTime).toBe(10);
|
||||
@@ -260,7 +266,7 @@ describe('DashParser Manifest', function() {
|
||||
]);
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
var stream = manifest.periods[0].variants[0].video;
|
||||
expect(stream.presentationTimeOffset).toBe(1);
|
||||
@@ -285,7 +291,7 @@ describe('DashParser Manifest', function() {
|
||||
]);
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
var stream = manifest.periods[0].variants[0].video;
|
||||
expect(stream.presentationTimeOffset).toBe(2);
|
||||
@@ -315,18 +321,21 @@ describe('DashParser Manifest', function() {
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
|
||||
var stream;
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
stream = manifest.periods[0].textStreams[0];
|
||||
return stream.createSegmentIndex();
|
||||
}).then(function() {
|
||||
})
|
||||
.then(function() {
|
||||
expect(stream.initSegmentReference).toBe(null);
|
||||
expect(stream.findSegmentPosition(0)).toBe(1);
|
||||
expect(stream.getSegmentReference(1))
|
||||
.toEqual(new shaka.media.SegmentReference(1, 0, 30, function() {
|
||||
return ['http://example.com/de.vtt'];
|
||||
}, 0, null));
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('correctly parses UTF-8', function(done) {
|
||||
@@ -346,14 +355,16 @@ describe('DashParser Manifest', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
var variant = manifest.periods[0].variants[0];
|
||||
var stream = manifest.periods[0].variants[0].audio;
|
||||
expect(stream.initSegmentReference.getUris()[0])
|
||||
.toBe('http://example.com/%C8%A7.mp4');
|
||||
expect(variant.language).toBe('\u2603');
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
describe('supports UTCTiming', function() {
|
||||
@@ -398,12 +409,7 @@ describe('DashParser Manifest', function() {
|
||||
* @param {number} expectedTime
|
||||
*/
|
||||
function runTest(done, expectedTime) {
|
||||
parser.start(
|
||||
'http://foo.bar/manifest',
|
||||
fakeNetEngine,
|
||||
filterPeriod,
|
||||
fail,
|
||||
onEventSpy)
|
||||
parser.start('http://foo.bar/manifest', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.presentationTimeline).toBeTruthy();
|
||||
expect(manifest.presentationTimeline.getSegmentAvailabilityEnd())
|
||||
@@ -522,13 +528,15 @@ describe('DashParser Manifest', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
// First Representation should be dropped.
|
||||
var period = manifest.periods[0];
|
||||
expect(period.variants.length).toBe(1);
|
||||
expect(period.variants[0].bandwidth).toBe(200);
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
describe('allows missing Segment* elements for text', function() {
|
||||
@@ -550,10 +558,12 @@ describe('DashParser Manifest', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods[0].textStreams.length).toBe(1);
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('specified via AdaptationSet@mimeType', function(done) {
|
||||
@@ -574,10 +584,12 @@ describe('DashParser Manifest', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods[0].textStreams.length).toBe(1);
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('specified via Representation@mimeType', function(done) {
|
||||
@@ -598,10 +610,12 @@ describe('DashParser Manifest', function() {
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods[0].textStreams.length).toBe(1);
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -620,7 +634,7 @@ describe('DashParser Manifest', function() {
|
||||
shaka.util.Error.Code.BAD_HTTP_STATUS);
|
||||
|
||||
fakeNetEngine.request.and.returnValue(Promise.reject(expectedError));
|
||||
parser.start('', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('', playerInterface)
|
||||
.then(fail)
|
||||
.catch(function(error) { expect(error).toEqual(expectedError); })
|
||||
.then(done);
|
||||
@@ -705,10 +719,12 @@ describe('DashParser Manifest', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
.then(function() {
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function() {
|
||||
expect(fakeNetEngine.registerResponseFilter).toHaveBeenCalled();
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('updates manifest when emsg box is present', function(done) {
|
||||
@@ -726,8 +742,8 @@ describe('DashParser Manifest', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
.then(function() {
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function() {
|
||||
expect(fakeNetEngine.registerResponseFilter).toHaveBeenCalled();
|
||||
var filter =
|
||||
fakeNetEngine.registerResponseFilter.calls.mostRecent().args[0];
|
||||
@@ -736,7 +752,9 @@ describe('DashParser Manifest', function() {
|
||||
fakeNetEngine.request.calls.reset();
|
||||
filter(type, response);
|
||||
expect(fakeNetEngine.request).toHaveBeenCalled();
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('dispatches an event on non-typical emsg content', function(done) {
|
||||
@@ -754,9 +772,8 @@ describe('DashParser Manifest', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText});
|
||||
parser.start(
|
||||
'dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
.then(function() {
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function() {
|
||||
expect(fakeNetEngine.registerResponseFilter).toHaveBeenCalled();
|
||||
var filter =
|
||||
fakeNetEngine.registerResponseFilter.calls.mostRecent().args[0];
|
||||
@@ -765,7 +782,7 @@ describe('DashParser Manifest', function() {
|
||||
fakeNetEngine.request.calls.reset();
|
||||
filter(type, response);
|
||||
expect(onEventSpy)
|
||||
.toHaveBeenCalledWith(jasmine.any(shaka.util.FakeEvent));
|
||||
.toHaveBeenCalledWith(jasmine.any(shaka.util.FakeEvent));
|
||||
var event =
|
||||
onEventSpy.calls.mostRecent().args[0];
|
||||
var emsg = event.detail;
|
||||
@@ -777,7 +794,9 @@ describe('DashParser Manifest', function() {
|
||||
expect(emsg.id).toBe(1);
|
||||
expect(emsg.messageData).toEqual(
|
||||
new Uint8Array([116, 101, 115, 116]));
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('does not update manifest when emsg box is not present', function(done) {
|
||||
@@ -795,8 +814,8 @@ describe('DashParser Manifest', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
.then(function() {
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function() {
|
||||
expect(fakeNetEngine.registerResponseFilter).toHaveBeenCalled();
|
||||
var filter =
|
||||
fakeNetEngine.registerResponseFilter.calls.mostRecent().args[0];
|
||||
@@ -806,7 +825,9 @@ describe('DashParser Manifest', function() {
|
||||
filter(type, response);
|
||||
expect(fakeNetEngine.request).not.toHaveBeenCalled();
|
||||
expect(onEventSpy).not.toHaveBeenCalled();
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -831,7 +852,7 @@ describe('DashParser Manifest', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods.length).toBe(1);
|
||||
expect(manifest.periods[0].variants.length).toBe(1);
|
||||
@@ -844,7 +865,9 @@ describe('DashParser Manifest', function() {
|
||||
id: 2,
|
||||
type: 'video'
|
||||
}));
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('skips unrecognized EssentialProperty elements', function(done) {
|
||||
@@ -867,7 +890,7 @@ describe('DashParser Manifest', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods.length).toBe(1);
|
||||
|
||||
@@ -880,7 +903,9 @@ describe('DashParser Manifest', function() {
|
||||
var trickModeVideo = variant && variant.video &&
|
||||
variant.video.trickModeVideo;
|
||||
expect(trickModeVideo).toBe(null);
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('sets contentType to text for embedded text mime types', function(done) {
|
||||
@@ -909,13 +934,15 @@ describe('DashParser Manifest', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': manifestText});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, onEventSpy)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest.periods.length).toBe(1);
|
||||
expect(manifest.periods[0].textStreams.length).toBe(2);
|
||||
// At one time, these came out as 'application' rather than 'text'.
|
||||
expect(manifest.periods[0].textStreams[0].type).toBe('text');
|
||||
expect(manifest.periods[0].textStreams[1].type).toBe('text');
|
||||
}).catch(fail).then(done);
|
||||
})
|
||||
.catch(fail)
|
||||
.then(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('DashParser SegmentBase', function() {
|
||||
var Dash;
|
||||
var fakeNetEngine;
|
||||
var parser;
|
||||
var filterPeriod = function() {};
|
||||
var playerInterface;
|
||||
|
||||
beforeAll(function() {
|
||||
Dash = shaka.test.Dash;
|
||||
@@ -28,6 +28,13 @@ describe('DashParser SegmentBase', function() {
|
||||
beforeEach(function() {
|
||||
fakeNetEngine = new shaka.test.FakeNetworkingEngine();
|
||||
parser = shaka.test.Dash.makeDashParser();
|
||||
|
||||
playerInterface = {
|
||||
networkingEngine: fakeNetEngine,
|
||||
filterPeriod: function() {},
|
||||
onEvent: fail,
|
||||
onError: fail
|
||||
};
|
||||
});
|
||||
|
||||
it('requests init data for WebM', function(done) {
|
||||
@@ -50,7 +57,7 @@ describe('DashParser SegmentBase', function() {
|
||||
'http://example.com': '',
|
||||
'http://example.com/init.webm': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('init.webm', 201, 300));
|
||||
@@ -84,7 +91,7 @@ describe('DashParser SegmentBase', function() {
|
||||
'dummy://foo': source,
|
||||
'http://example.com': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('init.mp4', 201, 300));
|
||||
@@ -116,7 +123,7 @@ describe('DashParser SegmentBase', function() {
|
||||
'dummy://foo': source,
|
||||
'http://example.com': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('init.mp4', 201, 300));
|
||||
@@ -149,7 +156,7 @@ describe('DashParser SegmentBase', function() {
|
||||
'dummy://foo': source,
|
||||
'http://example.com/stream.mp4': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('stream.mp4', 201, 300));
|
||||
@@ -189,7 +196,7 @@ describe('DashParser SegmentBase', function() {
|
||||
'dummy://foo': source,
|
||||
'http://example.com/index.mp4': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('init.mp4', 201, 300, 10));
|
||||
@@ -227,7 +234,7 @@ describe('DashParser SegmentBase', function() {
|
||||
'dummy://foo': source,
|
||||
'http://example.com': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('special.mp4', 0, null, 20));
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('DashParser SegmentList', function() {
|
||||
var Dash;
|
||||
var fakeNetEngine;
|
||||
var parser;
|
||||
var filterPeriod = function() {};
|
||||
var playerInterface;
|
||||
|
||||
beforeAll(function() {
|
||||
Dash = shaka.test.Dash;
|
||||
@@ -28,6 +28,13 @@ describe('DashParser SegmentList', function() {
|
||||
beforeEach(function() {
|
||||
fakeNetEngine = new shaka.test.FakeNetworkingEngine();
|
||||
parser = shaka.test.Dash.makeDashParser();
|
||||
|
||||
playerInterface = {
|
||||
networkingEngine: fakeNetEngine,
|
||||
filterPeriod: function() {},
|
||||
onEvent: fail,
|
||||
onError: fail
|
||||
};
|
||||
});
|
||||
|
||||
shaka.test.Dash.makeTimelineTests('SegmentList', '', [
|
||||
@@ -168,7 +175,7 @@ describe('DashParser SegmentList', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
var timeline = manifest.presentationTimeline;
|
||||
expect(timeline.getEarliestStart()).toBe(4);
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('DashParser SegmentTemplate', function() {
|
||||
var Dash;
|
||||
var fakeNetEngine;
|
||||
var parser;
|
||||
var filterPeriod = function() {};
|
||||
var playerInterface;
|
||||
|
||||
beforeAll(function() {
|
||||
Dash = shaka.test.Dash;
|
||||
@@ -28,6 +28,13 @@ describe('DashParser SegmentTemplate', function() {
|
||||
beforeEach(function() {
|
||||
fakeNetEngine = new shaka.test.FakeNetworkingEngine();
|
||||
parser = shaka.test.Dash.makeDashParser();
|
||||
|
||||
playerInterface = {
|
||||
networkingEngine: fakeNetEngine,
|
||||
filterPeriod: function() {},
|
||||
onEvent: fail,
|
||||
onError: fail
|
||||
};
|
||||
});
|
||||
|
||||
shaka.test.Dash.makeTimelineTests(
|
||||
@@ -75,7 +82,7 @@ describe('DashParser SegmentTemplate', function() {
|
||||
'dummy://foo': source,
|
||||
'http://example.com/index-500.mp4': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('init-500.mp4', 0, null));
|
||||
@@ -104,7 +111,7 @@ describe('DashParser SegmentTemplate', function() {
|
||||
'dummy://foo': source,
|
||||
'http://example.com/index-500.mp4': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('init-500.mp4', 0, null));
|
||||
@@ -140,7 +147,7 @@ describe('DashParser SegmentTemplate', function() {
|
||||
'http://example.com/index-500.webm': '',
|
||||
'http://example.com/init-500.webm': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('init-500.webm', 0, null));
|
||||
@@ -175,7 +182,7 @@ describe('DashParser SegmentTemplate', function() {
|
||||
'dummy://foo': source,
|
||||
'http://example.com/index-500.mp4': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('init-500.mp4', 0, null));
|
||||
@@ -208,7 +215,7 @@ describe('DashParser SegmentTemplate', function() {
|
||||
'dummy://foo': source,
|
||||
'http://example.com/index-500.mp4': ''
|
||||
});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toEqual(
|
||||
Dash.makeManifestFromInit('init-500.mp4', 0, null));
|
||||
@@ -311,7 +318,7 @@ describe('DashParser SegmentTemplate', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(actual) {
|
||||
expect(actual).toBeTruthy();
|
||||
|
||||
@@ -367,7 +374,7 @@ describe('DashParser SegmentTemplate', function() {
|
||||
].join('\n');
|
||||
|
||||
fakeNetEngine.setResponseMapAsText({'dummy://foo': source});
|
||||
parser.start('dummy://foo', fakeNetEngine, filterPeriod, fail)
|
||||
parser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
var timeline = manifest.presentationTimeline;
|
||||
expect(timeline.getEarliestStart()).toBe(4);
|
||||
|
||||
@@ -55,7 +55,7 @@ describe('OfflineManifestParser', function() {
|
||||
appMetadata: null
|
||||
}));
|
||||
|
||||
parser.start(uri, null, null, null)
|
||||
parser.start(uri, /* playerInterface */ null)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBeTruthy();
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('OfflineManifestParser', function() {
|
||||
var uri = 'offline:123';
|
||||
dbEngine.get.and.returnValue(Promise.resolve(null));
|
||||
|
||||
parser.start(uri, null, null, null)
|
||||
parser.start(uri, /* playerInterface */ null)
|
||||
.then(fail)
|
||||
.catch(function(err) {
|
||||
shaka.test.Util.expectToEqualError(
|
||||
@@ -95,7 +95,7 @@ describe('OfflineManifestParser', function() {
|
||||
var uri = 'offline:123';
|
||||
dbEngine.get.and.returnValue(Promise.reject());
|
||||
|
||||
parser.start(uri, null, null, null)
|
||||
parser.start(uri, /* playerInterface */ null)
|
||||
.then(fail)
|
||||
.catch(function(err) {
|
||||
expect(fakeDbEngineCtor).toHaveBeenCalledTimes(1);
|
||||
@@ -107,7 +107,7 @@ describe('OfflineManifestParser', function() {
|
||||
|
||||
it('will fail for invalid URI', function(done) {
|
||||
var uri = 'offline:abc';
|
||||
parser.start(uri, null, null, null)
|
||||
parser.start(uri, /* playerInterface */ null)
|
||||
.then(fail)
|
||||
.catch(function(err) {
|
||||
shaka.test.Util.expectToEqualError(
|
||||
@@ -144,7 +144,7 @@ describe('OfflineManifestParser', function() {
|
||||
};
|
||||
dbEngine.get.and.returnValue(Promise.resolve(data));
|
||||
|
||||
parser.start(uri, null, null, null)
|
||||
parser.start(uri, /* playerInterface */ null)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBeTruthy();
|
||||
expect(manifest.minBufferTime).toEqual(jasmine.any(Number));
|
||||
@@ -190,7 +190,7 @@ describe('OfflineManifestParser', function() {
|
||||
var spy = jasmine.createSpy('reconstructPeriod');
|
||||
shaka.offline.OfflineUtils.reconstructPeriod = spy;
|
||||
|
||||
parser.start(uri, null, null, null)
|
||||
parser.start(uri, /* playerInterface */ null)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBeTruthy();
|
||||
|
||||
@@ -218,7 +218,7 @@ describe('OfflineManifestParser', function() {
|
||||
var spy = jasmine.createSpy('reconstructPeriod');
|
||||
shaka.offline.OfflineUtils.reconstructPeriod = spy;
|
||||
|
||||
parser.start(uri, null, null, null)
|
||||
parser.start(uri, /* playerInterface */ null)
|
||||
.then(function(manifest) {
|
||||
expect(manifest).toBeTruthy();
|
||||
|
||||
|
||||
@@ -85,11 +85,15 @@ shaka.test.Dash.verifySegmentIndex = function(
|
||||
*/
|
||||
shaka.test.Dash.testSegmentIndex = function(done, manifestText, references) {
|
||||
var buffer = shaka.util.StringUtils.toUTF8(manifestText);
|
||||
var fakeNetEngine =
|
||||
new shaka.test.FakeNetworkingEngine({'dummy://foo': buffer});
|
||||
var dashParser = shaka.test.Dash.makeDashParser();
|
||||
var filterPeriod = function() {};
|
||||
dashParser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, fail)
|
||||
var playerInterface = {
|
||||
networkingEngine:
|
||||
new shaka.test.FakeNetworkingEngine({'dummy://foo': buffer}),
|
||||
filterPeriod: function() {},
|
||||
onEvent: fail,
|
||||
onError: fail
|
||||
};
|
||||
dashParser.start('dummy://foo', playerInterface)
|
||||
.then(function(manifest) {
|
||||
shaka.test.Dash.verifySegmentIndex(manifest, references, 0);
|
||||
})
|
||||
@@ -107,11 +111,15 @@ shaka.test.Dash.testSegmentIndex = function(done, manifestText, references) {
|
||||
*/
|
||||
shaka.test.Dash.testFails = function(done, manifestText, expectedError) {
|
||||
var manifestData = shaka.util.StringUtils.toUTF8(manifestText);
|
||||
var fakeNetEngine =
|
||||
new shaka.test.FakeNetworkingEngine({'dummy://foo': manifestData});
|
||||
var dashParser = shaka.test.Dash.makeDashParser();
|
||||
var filterPeriod = function() {};
|
||||
dashParser.start('dummy://foo', fakeNetEngine, filterPeriod, fail, fail)
|
||||
var playerInterface = {
|
||||
networkingEngine:
|
||||
new shaka.test.FakeNetworkingEngine({'dummy://foo': manifestData}),
|
||||
filterPeriod: function() {},
|
||||
onEvent: fail,
|
||||
onError: fail
|
||||
};
|
||||
dashParser.start('dummy://foo', playerInterface)
|
||||
.then(fail)
|
||||
.catch(function(error) {
|
||||
shaka.test.Util.expectToEqualError(error, expectedError);
|
||||
|
||||
Reference in New Issue
Block a user