From 926900ffc2a1dd97236a3a5154f2dbad3cb813ec Mon Sep 17 00:00:00 2001 From: Duc Pham Date: Tue, 21 Feb 2017 15:15:20 +0700 Subject: [PATCH 1/3] Fix incorrect timeReplacement when large timescale The current code essentially does this timeReplacement = (startTime / timescale + presentationTimeOffset) * timescale When timescale is large enough (e.g. 10 MHz in order to support MS Smooth Streaming as well), "startTime / timescale * timescale" may not always be exactly "startTime" because of floating point precision, which could produce incorrect segment URLs. Keep startTime and presentationTimeOffset unchanged in the timeline just to avoid the multiply/divide dance. --- lib/dash/mpd_utils.js | 9 +++++++-- lib/dash/segment_template.js | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/dash/mpd_utils.js b/lib/dash/mpd_utils.js index d1e710cfa5..7fc733bb1c 100644 --- a/lib/dash/mpd_utils.js +++ b/lib/dash/mpd_utils.js @@ -269,8 +269,12 @@ shaka.dash.MpdUtils.createTimeline = function( for (var j = 0; j <= repeat; ++j) { var endTime = startTime + d; - timeline.push( - {start: (startTime / timescale), end: (endTime / timescale)}); + var item = { + start: startTime / timescale, + end: endTime / timescale, + unscaledStart: startTime + }; + timeline.push(item); startTime = endTime; lastEndTime = endTime; @@ -398,6 +402,7 @@ shaka.dash.MpdUtils.parseSegmentInfo = function(context, callback) { segmentDuration: segmentDuration, startNumber: startNumber, presentationTimeOffset: pto, + unscaledPresentationTimeOffset: Number(presentationTimeOffset), timeline: timeline }; }; diff --git a/lib/dash/segment_template.js b/lib/dash/segment_template.js index b474fa1a52..b32e9f1bc7 100644 --- a/lib/dash/segment_template.js +++ b/lib/dash/segment_template.js @@ -174,6 +174,7 @@ shaka.dash.SegmentTemplate.parseSegmentTemplateInfo_ = function(context) { timescale: segmentInfo.timescale, startNumber: segmentInfo.startNumber, presentationTimeOffset: segmentInfo.presentationTimeOffset, + unscaledPresentationTimeOffset: segmentInfo.unscaledPresentationTimeOffset, timeline: segmentInfo.timeline, mediaTemplate: media, indexTemplate: index @@ -357,6 +358,7 @@ shaka.dash.SegmentTemplate.createFromTimeline_ = function(context, info) { var references = []; for (var i = 0; i < info.timeline.length; i++) { var start = info.timeline[i].start; + var unscaledStart = info.timeline[i].unscaledStart; var end = info.timeline[i].end; // Note: i = k - 1, where k indicates the k'th segment listed in the MPD. @@ -364,9 +366,8 @@ shaka.dash.SegmentTemplate.createFromTimeline_ = function(context, info) { var segmentReplacement = i + info.startNumber; // Consider the presentation time offset in segment uri computation - var timeReplacement = (start + info.presentationTimeOffset) * - info.timescale; - + var timeReplacement = unscaledStart + + info.unscaledPresentationTimeOffset; var createUris = (function( template, repId, bandwidth, baseUris, segmentId, time) { var mediaUri = MpdUtils.fillUriTemplate( From bd162db06e317a8056581db8d5c3d50427889280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Einarsson?= Date: Wed, 22 Feb 2017 13:09:06 +0100 Subject: [PATCH 2/3] Added contributor. --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 35a52d31b9..75db7a0b2a 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -26,6 +26,7 @@ Andy Hochhaus Chad Assareh Costel Madalin Grecu Donato Borrello +Duc Pham Esteban Dosztal Itay Kinnrot Jacob Trimble From 279e82b4d5448da26df613b53b6f70e8da3108c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Einarsson?= Date: Wed, 22 Feb 2017 21:09:32 +0100 Subject: [PATCH 3/3] Add declaration of new unscaled timing fields. --- lib/dash/mpd_utils.js | 6 ++++++ lib/dash/segment_template.js | 3 +++ 2 files changed, 9 insertions(+) diff --git a/lib/dash/mpd_utils.js b/lib/dash/mpd_utils.js index 7fc733bb1c..a0d50a7f48 100644 --- a/lib/dash/mpd_utils.js +++ b/lib/dash/mpd_utils.js @@ -44,6 +44,7 @@ shaka.dash.MpdUtils.GAP_OVERLAP_TOLERANCE_SECONDS = 1 / 15; /** * @typedef {{ * start: number, + * unscaledStart: number, * end: number * }} * @@ -52,6 +53,8 @@ shaka.dash.MpdUtils.GAP_OVERLAP_TOLERANCE_SECONDS = 1 / 15; * * @property {number} start * The start time of the range. + * @property {number} unscaledStart + * The start time of the range in representation timescale units. * @property {number} end * The end time (exclusive) of the range. */ @@ -64,6 +67,7 @@ shaka.dash.MpdUtils.TimeRange; * segmentDuration: ?number, * startNumber: number, * presentationTimeOffset: number, + * unscaledPresentationTimeOffset: number, * timeline: Array. * }} * @@ -78,6 +82,8 @@ shaka.dash.MpdUtils.TimeRange; * The start number of the segments; 1 or greater. * @property {number} presentationTimeOffset * The presentationTimeOffset of the representation, in seconds. + * @property {number} unscaledPresentationTimeOffset + * The presentationTimeOffset of the representation, in timescale units. * @property {Array.} timeline * The timeline of the representation, if given. Times in seconds. */ diff --git a/lib/dash/segment_template.js b/lib/dash/segment_template.js index b32e9f1bc7..7d81c411da 100644 --- a/lib/dash/segment_template.js +++ b/lib/dash/segment_template.js @@ -114,6 +114,7 @@ shaka.dash.SegmentTemplate.createStream = function( * segmentDuration: ?number, * startNumber: number, * presentationTimeOffset: number, + * unscaledPresentationTimeOffset: number, * timeline: Array., * mediaTemplate: ?string, * indexTemplate: ?string @@ -131,6 +132,8 @@ shaka.dash.SegmentTemplate.createStream = function( * The start number of the segments; 1 or greater. * @property {number} presentationTimeOffset * The presentationTimeOffset of the representation, in seconds. + * @property {number} unscaledPresentationTimeOffset + * The presentationTimeOffset of the representation, in timescale units. * @property {Array.} timeline * The timeline of the representation, if given. Times in seconds. * @property {?string} mediaTemplate