diff --git a/build/test/js/dash/TimeLineConverterSpec.js b/build/test/js/dash/TimeLineConverterSpec.js index 482a481aba..7d9ed57684 100644 --- a/build/test/js/dash/TimeLineConverterSpec.js +++ b/build/test/js/dash/TimeLineConverterSpec.js @@ -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); }); }); diff --git a/src/streaming/MediaPlayer.js b/src/streaming/MediaPlayer.js index c82170d264..a3e0aa9417 100644 --- a/src/streaming/MediaPlayer.js +++ b/src/streaming/MediaPlayer.js @@ -83,6 +83,7 @@ MediaPlayer = function (context) { autoPlay = true, scheduleWhilePaused = false, bufferMax = MediaPlayer.dependencies.BufferController.BUFFER_SIZE_REQUIRED, + useManifestDateHeaderTimeSource = true, UTCTimingSources = [], isReady = function () { @@ -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"); @@ -589,7 +590,7 @@ MediaPlayer = function (context) { /** *

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.

- *

If you have exposed the Date header, use the method {@link MediaPlayer#clearAllUTCTimingSources clearAllUTCTimingSources()}. + *

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

* * @param {string} schemeIdUri - @@ -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){ @@ -655,12 +656,19 @@ MediaPlayer = function (context) { * @memberof MediaPlayer# * @see {@link MediaPlayer#restoreDefaultUTCTimingSources restoreDefaultUTCTimingSources()} */ - clearAllUTCTimingSources: function() { + clearDefaultUTCTimingSources: function() { UTCTimingSources = []; }, /** - *

Allows you to restore the default time sources after calling {@link MediaPlayer#clearAllUTCTimingSources clearAllUTCTimingSources()}

+ *

Allows you to restore the default time sources after calling {@link MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}

+ * + * @default + * + * * @memberof MediaPlayer# * @see {@link MediaPlayer#addUTCTimingSource addUTCTimingSource()} */ @@ -668,6 +676,20 @@ MediaPlayer = function (context) { this.addUTCTimingSource(DEFAULT_TIME_SOURCE_SCHEME, DEFAULT_TIME_SERVER); }, + + /** + *

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()}

+ * + * @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. * diff --git a/src/streaming/TimeSyncController.js b/src/streaming/TimeSyncController.js index e2ba76641b..fef52d7052 100644 --- a/src/streaming/TimeSyncController.js +++ b/src/streaming/TimeSyncController.js @@ -39,6 +39,7 @@ MediaPlayer.dependencies.TimeSyncController = function () { offsetToDeviceTimeMs = 0, isSynchronizing = false, isInitialised = false, + useManifestDateHeaderTimeSource, setIsSynchronizing = function (value) { isSynchronizing = value; @@ -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 { @@ -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); diff --git a/src/streaming/controllers/StreamController.js b/src/streaming/controllers/StreamController.js index 0407ba5c8e..4dba7fad49 100644 --- a/src/streaming/controllers/StreamController.js +++ b/src/streaming/controllers/StreamController.js @@ -48,6 +48,7 @@ hasMediaError = false, mediaSource, UTCTimingSources, + useManifestDateHeaderTimeSource, attachEvents = function (stream) { stream.subscribe(MediaPlayer.dependencies.Stream.eventList.ENAME_STREAM_UPDATED, this.liveEdgeFinder); @@ -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(); } @@ -451,8 +452,9 @@ return (activeStream.getId() === streamInfo.id); }, - setUTCTimingSources: function(value) { + setUTCTimingSources: function(value, value2) { UTCTimingSources = value; + useManifestDateHeaderTimeSource = value2; }, /**