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

Avoid floating point arithmetic when calculating time replacement #1

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Feb 9, 2017

The current code essentially does this

timeReplacement = (startTime / timescale + ...) * 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 unchanged in the timeline just to avoid the multiply/divide dance.

@TobbeEdgeware and @PhamCongDuc this is SHIELD-1235. The code is not exactly pretty, but I want to make sure I get the logic right before worrying about where to save "unscaledStart"

The current code essentially does this

    timeReplacement = (startTime / timescale + ...) * 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 unchanged in the timeline just to avoid the
multiply/divide dance.
@@ -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.

@TobbeEdgeware
Copy link

I think this looks nice, except that there is a potential issue with floating point accuracy from the presentationTimeOffset as well (we use zero, but for multiperiod, we may need other values).
It would be good to check if that part can be improved as well (an complication is that presentationTimeOffset can be defined on different levels with different timescales).

To get the code accepted, the best is to

  1. create an issue on github describing the problem
  2. make sure that current tests go through, and ideally add another test for this
  3. submit a pull request for it.

I can help out with creating the issue. It might help since I've relationship with the main developer since before.

@TobbeEdgeware
Copy link

I looked a bit more at the file lib/dash/mpd_utils.js and the createTimeline function uses integer arithmetic to add presentationTime to the timestamp. However, the parseSegmentInfo sends back a scaled presentationTimeOffset. It might work to add a presentationTimeOffsetUnscaled to the return object and then use that together with the patch.

@ghost
Copy link
Author

ghost commented Feb 9, 2017

Thanks @TobbeEdgeware . @PhamCongDuc I'll leave it to you to handle the rest with help from @TobbeEdgeware. You should also make sure that it does fix the problems for TVB or we're just wasting time fixing something else.

@TobbeEdgeware
Copy link

TobbeEdgeware commented Feb 9, 2017

I've made a shaka player issue shaka-project#690 and we'll wait for response on whether they are open to pull request.

If they are positive, we may need to improve the fix to include presentationTimeOffset and possibly tests. I'll be back to you @duynguyen-ew in that case.

@PhamCongDuc On the TVB side, it would be good if you use your own patched version for the moment. In any case, it will take some time until this is included in a shaka-player release.

@PhamCongDuc
Copy link

PhamCongDuc commented Feb 10, 2017

Thanks @duynguyen-ew , @TobbeEdgeware . I ran Skaka auto tests, nothing failed

@TobbeEdgeware
Copy link

We got an answer to google#690 that they are positive to a patch.

I think one should check that all of "startTime", "endTime", and "presentationTimeOffset" are handled exactly, and not just "startTime".

Will you make one from Vietnam (with an github account Edgeware email address)?

@PhamCongDuc
Copy link

Yes. I'm doing that (checking presentationTimeOffset) and will check endTime. I sent you a message on Slack.

@ghost
Copy link
Author

ghost commented Feb 16, 2017

Closing as #2 covers it too

@ghost ghost closed this Feb 16, 2017
@ghost ghost deleted the time-replacement-avoid-floating-point branch February 16, 2017 07:45
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants