Skip to content

Commit

Permalink
Added api to enable use of date header so you can bypass that now if …
Browse files Browse the repository at this point in the history
…desired.

Changed api name to make sense.
Change test that broke in previous merge d6130f3
  • Loading branch information
Dan Sparacio committed May 6, 2015
1 parent fcd393d commit bce6a36
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build/test/js/dash/TimeLineConverterSpec.js
Expand Up @@ -100,7 +100,7 @@ describe("TimelineConverter", function () {
range = timelineConverter.calcSegmentAvailabilityRange(representation, isDynamic);

expect(range.start).toEqual(expectedValue);
expectedValue = 10;
expectedValue = 9;
expect(range.end).toEqual(expectedValue);
});
});
Expand Down
32 changes: 27 additions & 5 deletions src/streaming/MediaPlayer.js
Expand Up @@ -83,6 +83,7 @@ MediaPlayer = function (context) {
autoPlay = true,
scheduleWhilePaused = false,
bufferMax = MediaPlayer.dependencies.BufferController.BUFFER_SIZE_REQUIRED,
useManifestDateHeaderTimeSource = true,
UTCTimingSources = [],

isReady = function () {
Expand Down Expand Up @@ -118,7 +119,7 @@ MediaPlayer = function (context) {
} else {
streamController.loadWithManifest(source);
}
streamController.setUTCTimingSources(UTCTimingSources);
streamController.setUTCTimingSources(UTCTimingSources, useManifestDateHeaderTimeSource);
system.mapValue("scheduleWhilePaused", scheduleWhilePaused);
system.mapOutlet("scheduleWhilePaused", "stream");
system.mapOutlet("scheduleWhilePaused", "scheduleController");
Expand Down Expand Up @@ -589,7 +590,7 @@ MediaPlayer = function (context) {
/**
* <p>Allows you to set a scheme and server source for UTC live edge detection for dynamic streams.
* If UTCTiming is defined in the manifest, it will take precedence over any time source manually added.</p>
* <p>If you have exposed the Date header, use the method {@link MediaPlayer#clearAllUTCTimingSources clearAllUTCTimingSources()}.
* <p>If you have exposed the Date header, use the method {@link MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}.
* This will allow the date header on the manifest to be used instead of a time server</p>
*
* @param {string} schemeIdUri -
Expand Down Expand Up @@ -635,7 +636,7 @@ MediaPlayer = function (context) {
* @param {string} schemeIdUri - see {@link MediaPlayer#addUTCTimingSource addUTCTimingSource()}
* @param {string} value - see {@link MediaPlayer#addUTCTimingSource addUTCTimingSource()}
* @memberof MediaPlayer#
* @see {@link MediaPlayer#clearAllUTCTimingSources clearAllUTCTimingSources()}
* @see {@link MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}
*/
removeUTCTimingSource: function(schemeIdUri, value) {
UTCTimingSources.forEach(function(obj, idx){
Expand All @@ -655,19 +656,40 @@ MediaPlayer = function (context) {
* @memberof MediaPlayer#
* @see {@link MediaPlayer#restoreDefaultUTCTimingSources restoreDefaultUTCTimingSources()}
*/
clearAllUTCTimingSources: function() {
clearDefaultUTCTimingSources: function() {
UTCTimingSources = [];
},

/**
* <p>Allows you to restore the default time sources after calling {@link MediaPlayer#clearAllUTCTimingSources clearAllUTCTimingSources()}</p>
* <p>Allows you to restore the default time sources after calling {@link MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}</p>
*
* @default
* <ul>
* <li>schemeIdUri:urn:mpeg:dash:utc:http-xsdate:2014</li>
* <li>value:http://time.akamai.com</li>
* </ul>
*
* @memberof MediaPlayer#
* @see {@link MediaPlayer#addUTCTimingSource addUTCTimingSource()}
*/
restoreDefaultUTCTimingSources: function() {
this.addUTCTimingSource(DEFAULT_TIME_SOURCE_SCHEME, DEFAULT_TIME_SERVER);
},


/**
* <p>Allows you to enable the use of the Date Header, if exposed with CORS, as a timing source for live edge detection. The
* use of the date header will happen only after the other timing source that take precedence fail or are omitted as described.
* {@link MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()} </p>
*
* @default True
* @memberof MediaPlayer#
* @see {@link MediaPlayer#addUTCTimingSource addUTCTimingSource()}
*/
enableManifestDateHeaderTimeSource: function(value) {
useManifestDateHeaderTimeSource = value;
},

/**
* Use this method to attach an HTML5 VideoElement for dash.js to operate upon.
*
Expand Down
6 changes: 4 additions & 2 deletions src/streaming/TimeSyncController.js
Expand Up @@ -39,6 +39,7 @@ MediaPlayer.dependencies.TimeSyncController = function () {
offsetToDeviceTimeMs = 0,
isSynchronizing = false,
isInitialised = false,
useManifestDateHeaderTimeSource,

setIsSynchronizing = function (value) {
isSynchronizing = value;
Expand Down Expand Up @@ -259,7 +260,7 @@ MediaPlayer.dependencies.TimeSyncController = function () {
// callback to emit event to listeners
onComplete = function (time, offset) {
var failed = !time || !offset;
if(failed) {
if(failed && useManifestDateHeaderTimeSource) {
//Before falling back to binary search , check if date header exists on MPD. if so, use for a time source.
checkForDateHeader.call(self);
}else {
Expand Down Expand Up @@ -319,7 +320,8 @@ MediaPlayer.dependencies.TimeSyncController = function () {
return getOffsetMs();
},

initialize: function (timingSources) {
initialize: function (timingSources, useManifestDateHeader) {
useManifestDateHeaderTimeSource = useManifestDateHeader;
if (!getIsSynchronizing()) {
attemptSync.call(this, timingSources);
setIsInitialised(true);
Expand Down
6 changes: 4 additions & 2 deletions src/streaming/controllers/StreamController.js
Expand Up @@ -48,6 +48,7 @@
hasMediaError = false,
mediaSource,
UTCTimingSources,
useManifestDateHeaderTimeSource,

attachEvents = function (stream) {
stream.subscribe(MediaPlayer.dependencies.Stream.eventList.ENAME_STREAM_UPDATED, this.liveEdgeFinder);
Expand Down Expand Up @@ -393,7 +394,7 @@
var manifestUTCTimingSources = this.manifestExt.getUTCTimingSources(e.data.manifest),
allUTCTimingSources = manifestUTCTimingSources.concat(UTCTimingSources); //manifest utc time source(s) take precedence over default or explicitly added sources.

this.timeSyncController.initialize(allUTCTimingSources);
this.timeSyncController.initialize(allUTCTimingSources, useManifestDateHeaderTimeSource);
} else {
this.reset();
}
Expand Down Expand Up @@ -451,8 +452,9 @@
return (activeStream.getId() === streamInfo.id);
},

setUTCTimingSources: function(value) {
setUTCTimingSources: function(value, value2) {
UTCTimingSources = value;
useManifestDateHeaderTimeSource = value2;
},

/**
Expand Down

0 comments on commit bce6a36

Please sign in to comment.