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

Less than optimal Javascript arithmetic leading to bad segment request URLs #690

Closed
TobbeEdgeware opened this issue Feb 9, 2017 · 5 comments
Labels
flag: seeking PR We are actively seeking PRs for this; we do not currently expect the core team will resolve this status: archived Archived and locked; will not be updated type: enhancement New feature or request

Comments

@TobbeEdgeware
Copy link
Contributor

Javascript has a limitation in the numbers it can represent since all numbers are stored as double-precision floats. In particular, there is a biggest integer that can be accurately represented and it is 2**53 - 1 (Number.MAX_SAFE_INTEGER).

This needs to be considered when delivering live media. In particular, when using the Smooth Streaming default timescale of 10 000 000 the maximum timestamp corresponds to 28.5 years.
This should be enough in most cases, but with the most common live Smooth Streaming offset (availabilityStartTime for DASH), the UNIX Epoch 1970-01-01, the timestamp becomes bigger than the MAX_SAFE_INTEGER and precision is lost.

In particular, this may lead to incorrect URLs when SegmentTimeLine is used, since additions of timestamps and durations don't give the exact timestamp of the next segment.

Some players have extended their calculations using a bigint library, but that has been discussed for Shaka player before (#383), and decided not to be implemented.

We ran into this problem with our live output, but could not change the timescale away from 10 000 000 due client behavior. Instead, we changed the availabilityStartTime to 2000-01-01, which reduced the arithmetic precision needed down to 53 bits. This removed our playback problem in dash.js which uses standard Javascript integer arithmetic.

However, on shaka player we still see a problem, and we have tracked that down to the use of floating-point calculations as startTime is scaled by dividing with the timescale in mpd_utils.js and then multiplied with the timescale in segment_template.js to arrive at the timeReplacement value to be used in the segment URI.

We don't ask to change bigint arithmetic, but we think that there should be a slight change to loose as little precision as possible by keeping unscaled timestamps and use integer arithmetic. We are preparing a pull request, and hope that it is welcome?

#####################

  • What version of Shaka Player are you using?
    2.0.5

    • Can you reproduce the issue with our latest release version?
      Yes

    • Can you reproduce the issue with the latest code from master?
      Yes

  • Are you using the demo app or your own custom app?
    Demo

  • What browser and OS are you using?
    Any, but Chrome and OS X is one example

  • What did you do?
    Tried to stream our own live content. No external test stream available right now.

  • What did you expect to happen?
    Content should play

  • What actually happened?
    Content did not play properly because of missing segments. Server log showed inaccurate timestamps in media URLs

@TheModMaker
Copy link
Contributor

A PR for this would be welcome. The idea for the linked PR looks good, just make sure that all the tests still pass.

@joeyparrish joeyparrish added type: enhancement New feature or request flag: seeking PR We are actively seeking PRs for this; we do not currently expect the core team will resolve this labels Feb 10, 2017
TheModMaker pushed a commit that referenced this issue Feb 24, 2017
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.

Closes #690
@TobbeEdgeware
Copy link
Contributor Author

We should not write that this introduces extra latency, because segments are still generated directly when we have the corresponding data. For HLS, one should notice no difference.
It is rather a possible shift between incoming media time and outgoing media time, to make sure that we don't generate DASH segments too late according to wall-clock.

@joeyparrish
Copy link
Member

@TobbeEdgeware, this issue has been closed for 11 months, and I can't find any mention of the word "latency" in this thread until you brought it up. It also doesn't appear in the commit that fixed the issue.

Did you mean to comment on some other issue?

@TobbeEdgeware
Copy link
Contributor Author

@joeyparrish I'm terribly sorry. The remark was for another project, and somehow I had this old page open and typed it here by mistake. The ticket should remain closed.

@joeyparrish
Copy link
Member

Okay, cool. Just making sure. No harm done!

@shaka-project shaka-project locked and limited conversation to collaborators Mar 22, 2018
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
flag: seeking PR We are actively seeking PRs for this; we do not currently expect the core team will resolve this status: archived Archived and locked; will not be updated type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants