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

fix(HLS): Only offset segment ref times when needed w/ EXT-X-MEDIA-SEQUENCE #6378

Conversation

JulianDomingo
Copy link
Collaborator

@JulianDomingo JulianDomingo commented Mar 30, 2024

Fixes #6377

When choosing to synchronize HLS streams using EXT-X-MEDIA-SEQUENCE instead of EXT-X-PROGRAM-DATE-TIME during LIVE playlist variant switches, Shaka unnecessarily drops 'old' segments and offsets the segment references of the new playlist so that the earliest reference represents media time 0:

// Now adjust timestamps back to begin at 0.
const segmentN = segmentIndex.earliestReference();
if (segmentN) {
const streamOffset = -segmentN.startTime;

This is problematic, as the StreamingEngine's media time used to download new segments is based off the latest segment references:

// Get the next timestamp we need.
const timeNeeded = this.getTimeNeeded_(mediaState, presentationTime);
shaka.log.v2(logPrefix, 'timeNeeded=' + timeNeeded);

return mediaState.lastSegmentReference.endTime;

For example:

            Playlist download #1         
EXT-X-MEDIA-SEQUENCE       Media Time
           0                   0
           1                   6
           2                   12
           3                   18

           Playlist download #2 (what happens now)
EXT-X-MEDIA-SEQUENCE       Media Time
          6                   0
          7                   6
          8                   12
          9                   18

           Playlist download #2 (desired behavior)
EXT-X-MEDIA-SEQUENCE       Media Time
          6                   36
          7                   42
          8                   48
          9                   54

Without this fix, and given the above example, if Shaka tries to request the segment at time=36, it will fail because the media state only has segment references up to time=18. Until the manifests, 'catch up', the player freezes; this can be especially problematic when a large amount of time accumulates before a variant switch occurs.

This has been confirmed by Pluto TV to fix their freezing issues.

@JulianDomingo JulianDomingo added component: HLS The issue involves Apple's HLS manifest format priority: P1 Big impact or workaround impractical; resolve before feature release platform: Cast Issues affecting Cast devices labels Mar 30, 2024
@JulianDomingo JulianDomingo self-assigned this Mar 30, 2024
@JulianDomingo JulianDomingo marked this pull request as draft March 30, 2024 00:22
@shaka-bot
Copy link
Collaborator

Incremental code coverage: 100.00%

Copy link
Collaborator

@avelad avelad left a comment

Choose a reason for hiding this comment

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

Please, add a test to avoid regressions in the future! Thanks!

@avelad avelad added this to the v5.0 milestone Mar 30, 2024
@joeyparrish
Copy link
Member

Looks simple enough. But please add tests, and please add more detail in the PR description to help others understand the problem and how this solves it. Thanks!

@avelad
Copy link
Collaborator

avelad commented Apr 5, 2024

@JulianDomingo can you fix the build errors? Thanks!

@JulianDomingo
Copy link
Collaborator Author

Please, add a test to avoid regressions in the future! Thanks!

Looks simple enough. But please add tests, and please add more detail in the PR description to help others understand the problem and how this solves it. Thanks!

@JulianDomingo can you fix the build errors? Thanks!

Done, I've updated the PR description and added unit tests. Fixed lint errors as well.

@JulianDomingo JulianDomingo marked this pull request as ready for review April 5, 2024 07:35
@avelad avelad added type: bug Something isn't working correctly and removed platform: Cast Issues affecting Cast devices labels Apr 5, 2024
test/hls/hls_live_unit.js Outdated Show resolved Hide resolved
@avelad
Copy link
Collaborator

avelad commented Apr 5, 2024

@JulianDomingo Please, fix the tests

@JulianDomingo
Copy link
Collaborator Author

@JulianDomingo Please, fix the tests

Done; I mistakenly placed the initial assertion after the live playlist update occurs, which was not the intention.

@avelad avelad requested a review from theodab April 5, 2024 19:11
@theodab theodab merged commit bca6252 into shaka-project:main Apr 5, 2024
15 of 16 checks passed
avelad pushed a commit that referenced this pull request Apr 8, 2024
…QUENCE (#6378)

Fixes #6377

When choosing to synchronize HLS streams using `EXT-X-MEDIA-SEQUENCE` instead of `EXT-X-PROGRAM-DATE-TIME` during LIVE playlist variant switches, Shaka unnecessarily drops 'old' segments and offsets the segment references of the new playlist so that the earliest reference represents media time `0`: https://github.com/shaka-project/shaka-player/blob/ea740ba2468f3b035d463ea9933aa7eeccf5c748/lib/hls/hls_parser.js#L610-L613

This is problematic, as the `StreamingEngine`'s media time used to download new segments is based off the latest segment references:
https://github.com/shaka-project/shaka-player/blob/ea740ba2468f3b035d463ea9933aa7eeccf5c748/lib/media/streaming_engine.js#L1248-L1250
https://github.com/shaka-project/shaka-player/blob/ea740ba2468f3b035d463ea9933aa7eeccf5c748/lib/media/streaming_engine.js#L1385

For example:

```
            Playlist download #1         
EXT-X-MEDIA-SEQUENCE       Media Time
           0                   0
           1                   6
           2                   12
           3                   18

           Playlist download #2 (what happens now)
EXT-X-MEDIA-SEQUENCE       Media Time
          6                   0
          7                   6
          8                   12
          9                   18

           Playlist download #2 (desired behavior)
EXT-X-MEDIA-SEQUENCE       Media Time
          6                   36
          7                   42
          8                   48
          9                   54

```

Without this fix, and given the above example, if Shaka tries to request the segment at `time=36`, it will fail because the media state only has segment references up to `time=18`. Until the manifests, 'catch up', the player freezes; this can be especially problematic when a large amount of time accumulates before a variant switch occurs.

This has been confirmed by Pluto TV to fix their freezing issues.
avelad pushed a commit that referenced this pull request Apr 8, 2024
…QUENCE (#6378)

Fixes #6377

When choosing to synchronize HLS streams using `EXT-X-MEDIA-SEQUENCE` instead of `EXT-X-PROGRAM-DATE-TIME` during LIVE playlist variant switches, Shaka unnecessarily drops 'old' segments and offsets the segment references of the new playlist so that the earliest reference represents media time `0`: https://github.com/shaka-project/shaka-player/blob/ea740ba2468f3b035d463ea9933aa7eeccf5c748/lib/hls/hls_parser.js#L610-L613

This is problematic, as the `StreamingEngine`'s media time used to download new segments is based off the latest segment references:
https://github.com/shaka-project/shaka-player/blob/ea740ba2468f3b035d463ea9933aa7eeccf5c748/lib/media/streaming_engine.js#L1248-L1250
https://github.com/shaka-project/shaka-player/blob/ea740ba2468f3b035d463ea9933aa7eeccf5c748/lib/media/streaming_engine.js#L1385

For example:

```
            Playlist download #1         
EXT-X-MEDIA-SEQUENCE       Media Time
           0                   0
           1                   6
           2                   12
           3                   18

           Playlist download #2 (what happens now)
EXT-X-MEDIA-SEQUENCE       Media Time
          6                   0
          7                   6
          8                   12
          9                   18

           Playlist download #2 (desired behavior)
EXT-X-MEDIA-SEQUENCE       Media Time
          6                   36
          7                   42
          8                   48
          9                   54

```

Without this fix, and given the above example, if Shaka tries to request the segment at `time=36`, it will fail because the media state only has segment references up to `time=18`. Until the manifests, 'catch up', the player freezes; this can be especially problematic when a large amount of time accumulates before a variant switch occurs.

This has been confirmed by Pluto TV to fix their freezing issues.
joeyparrish pushed a commit that referenced this pull request May 7, 2024
…QUENCE (#6378)

Fixes #6377

When choosing to synchronize HLS streams using `EXT-X-MEDIA-SEQUENCE` instead of `EXT-X-PROGRAM-DATE-TIME` during LIVE playlist variant switches, Shaka unnecessarily drops 'old' segments and offsets the segment references of the new playlist so that the earliest reference represents media time `0`: https://github.com/shaka-project/shaka-player/blob/ea740ba2468f3b035d463ea9933aa7eeccf5c748/lib/hls/hls_parser.js#L610-L613

This is problematic, as the `StreamingEngine`'s media time used to download new segments is based off the latest segment references:
https://github.com/shaka-project/shaka-player/blob/ea740ba2468f3b035d463ea9933aa7eeccf5c748/lib/media/streaming_engine.js#L1248-L1250
https://github.com/shaka-project/shaka-player/blob/ea740ba2468f3b035d463ea9933aa7eeccf5c748/lib/media/streaming_engine.js#L1385

For example:

```
            Playlist download #1         
EXT-X-MEDIA-SEQUENCE       Media Time
           0                   0
           1                   6
           2                   12
           3                   18

           Playlist download #2 (what happens now)
EXT-X-MEDIA-SEQUENCE       Media Time
          6                   0
          7                   6
          8                   12
          9                   18

           Playlist download #2 (desired behavior)
EXT-X-MEDIA-SEQUENCE       Media Time
          6                   36
          7                   42
          8                   48
          9                   54

```

Without this fix, and given the above example, if Shaka tries to request the segment at `time=36`, it will fail because the media state only has segment references up to `time=18`. Until the manifests, 'catch up', the player freezes; this can be especially problematic when a large amount of time accumulates before a variant switch occurs.

This has been confirmed by Pluto TV to fix their freezing issues.
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Jun 4, 2024
@shaka-project shaka-project locked as resolved and limited conversation to collaborators Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: HLS The issue involves Apple's HLS manifest format priority: P1 Big impact or workaround impractical; resolve before feature release status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Live HLS streams freeze on variant switches when ignoreManifestProgramDateTime is true.
5 participants