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

Avoid floating point arithmetic when calculating time replacement #1

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions lib/dash/mpd_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)});
item = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add var item = { in here, rebuild Shaka player with your code and it works fine. I test without your code, the issue appears again. Thanks @duynguyen-ew . How can we propose your change to apply in Shaka player repository.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the var part is important. Otherwise you'll be creating a global variable.

start: startTime / timescale,
end: endTime / timescale,
unscaledStart: startTime
};
timeline.push(item);

startTime = endTime;
lastEndTime = endTime;
Expand Down
5 changes: 3 additions & 2 deletions lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,16 @@ 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.
// (See section 5.3.9.5.3 of the DASH spec.)
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.presentationTimeOffset * info.timescale;

var createUris = (function(
template, repId, bandwidth, baseUris, segmentId, time) {
Expand Down