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

Add bFrameAdjustment configuration option to address PTS/DTS bug #731

Closed

Conversation

baconz
Copy link
Contributor

@baconz baconz commented Mar 22, 2017

I know you guys have been working on gap jumping as a workaround for the PTS/DTS bug, which should go a long way for many use cases. We have our own gap jumping implementation, but it has some limitations. Specifically: transitions to new periods are not smooth, and content with a correctly set base_media_decode_time (DTS) will not start because it ends up with a negative presentation start time.

This approach fixes the underlying problem, but requires uniform and predictable frame rates and bframe counts.

I think it is a relatively unobtrusive solution that goes a long way towards achieving smooth multi-period playback for most use cases.

Take a look and let me know what you think. If it is something you'd consider I can clean it up and fix tests.


WIP: pending discussion, will add/fix tests

This change introduces a configuration option that adjusts the timestampOffset and appendWindowEnd to address the PTS/DTS bug in Chrome. It assumes that the number of bframes is known, and constant. It also assumes that the manifest provides an accurate framerate.

Full explanation at: https://github.com/baconz/shaka-player/blob/bframe-adjustment-for-chrome/externs/shaka/player.js#L474

WIP: pending discussion, will add/fix tests

This change introduces a configuration option that adjusts
the timestampOffset and appendWindowEnd to address the PTS/DTS
bug in Chrome. It assumes that the number of bframes is known,
and constant. It also assumes that the manifest provides an
accurate framerate.

See the full writeup in externs/shaka/player.js
@joeyparrish
Copy link
Member

@baconz, this is very interesting. I'm glad that this is a workable approach for you, but I would like to defer consideration of this PR until we are done with #555. At that point, if our solution does not meet your needs, we can reconsider this PR or something based on it. In the mean time, I'm glad you are not stuck waiting on us!

@baconz
Copy link
Contributor Author

baconz commented Mar 22, 2017

Sounds good @joeyparrish. Let me know if/when you'd like to discuss this further.

@joeyparrish
Copy link
Member

@baconz, we recently landed gap jumping in #555. Is this PR still applicable? Or does gap jumping solve the same problem this PR is meant to solve?

@baconz
Copy link
Contributor Author

baconz commented Apr 25, 2017 via email

@baconz
Copy link
Contributor Author

baconz commented May 5, 2017

@joeyparrish unfortunately #555 doesn't solve the whole picture for us. There are two problems:

(1) Chrome sees negative start times because we use PTS as the the PTO, and Chrome uses the DTS as the timestamp of the first sample.
(2) Chrome sees gaps because Chrome sees periods as shorter than they should be.

#555 solves (2), but not (1).

With (1) Shaka will throw a 3016 and you'll get an error along these lines in media-internals:

video frame with PTS 0us has negative DTS -66734us after applying timestampOffset, handling any discontinuity, and filtering against append window

Here's a diagram that represents the problem for a single segment:

   PTO
   PTS
   6006
      |

 |
 0
DTS

Here the PTO would be set to 6006, and Chrome would see the first timestamp as -6006.

This PR allows you to mitigate this problem by adjusting the PTO based on the maximum number of concurrent b frames in the underlying content.

@joeyparrish
Copy link
Member

Okay, I see now.

I understand the need for this, but I am still hesitant because this feels like a lot of code to work around a Chrome bug. I don't know when, but this will get fixed in Chrome at some point.

How would a user of this feature employ it only on Chrome, and only on affected versions of Chrome?

@baconz
Copy link
Contributor Author

baconz commented May 11, 2017

I agree that it is a lot of code to work around this bug, but given that the bug has been open 3 years, we're not holding out hope that it will be fixed. To us it seemed cleaner to push the workaround as close as possible to the client instead of branching off somewhere further up the video pipeline.

We make the decision on whether or not to enable the flag when we call player.configure() based on out-of-band browser information (I think we use bowser).

If we really wanted to be fancy, we could embed a very simple fragment with a single frame and a known PTS. When we initialize the player, we could pass it to a test SourceBuffer and read back the buffered range to find out if the browser has this bug.

If we wanted to be really fancy, I think we could detect the number of consecutive b-frames by using the num_ref_frames parameter in the SPS, but that would require parsing the init.mp4 and parsing the SPS, which seems like a lot of code.

@joeyparrish
Copy link
Member

@baconz, I've been informed by the Chrome team that they are actively working on this and hope to land something soon.

Since you have this workaround implemented in your fork, there's no urgency to merge it, correct? If so, I propose we defer for a couple more weeks to see what Chrome team can accomplish in terms of a fix in that time.

@baconz
Copy link
Contributor Author

baconz commented May 12, 2017

@joeyparrish sounds good, it would be awesome if they push a fix!

@joeyparrish joeyparrish self-assigned this Jun 5, 2017
@joeyparrish joeyparrish added the type: enhancement New feature or request label Jul 17, 2017
@joeyparrish joeyparrish added the zzz-outdated: Chrome PTS/DTS bug Related to the Chrome PTS/DTS bugs that were present from 2016 - 2019; do not use for new issues label Aug 15, 2017
@joeyparrish
Copy link
Member

@baconz, I know this has dragged on for quite some time, but would you be willing to test another round of Chrome fixes with regard to this issue?

In particular, you should use Chrome beta (63) with the MseBufferByPts feature turned on via the command-line:

google-chrome-beta --user-data-dir=/tmp/user-data --enable-features=MseBufferByPts

I only recently became aware of the fact that Chrome team is experimenting with PTS-based buffering behind this flag, to avoid accidentally breaking any media sites that may only work with the buggy behavior they are trying to fix.

@joeyparrish
Copy link
Member

Alternately, a test case or demo page that showcases the problem would be allow us to go directly to Chrome team with your specific use case, and allow them to iterate more quickly toward fixing the issues that are affecting you.

@joeyparrish joeyparrish modified the milestones: Backlog, v2.5 Mar 4, 2018
@joeyparrish joeyparrish removed this from the v2.5 milestone Nov 21, 2018
@joeyparrish
Copy link
Member

I believe the Chrome DTS/PTS bug has now been fixed, so I'm closing this PR. If you still have issues with the latest stable release of Chrome, please file a new issue/PR. Thanks!

@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: enhancement New feature or request zzz-outdated: Chrome PTS/DTS bug Related to the Chrome PTS/DTS bugs that were present from 2016 - 2019; do not use for new issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants