question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support different #EXT-X-PROGRAM-DATE-TIME tags for different #EXT-X-DISCONTINUITY sections

See original GitHub issue

Problem

There is a chance that HLS content provider may produce discontinuities in stream. For example, because the server was restarted. In this case, according to the standard (https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-08#section-4.4.4.3), there must be #EXT-X-DISCONTINUITY tag in manifest. As far as I can understand, exoplayer will try to correct the position using the PTS. In general, PTS is not the best source of truth for this because after #EXT-X-DISCONTINUITY tag there may be any timestamp (even descending). But even if the PTS monotonously increased during, for example, a server reboot, there is another problem: seeking. Assume, that we have VOD HLS manifest:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-START:TIME-OFFSET=0
#EXT-X-TARGETDURATION:10
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-PROGRAM-DATE-TIME:2020-12-02T18:33:03.447Z
#EXTINF:7.920,
2020-12-02/18/segment_1.ts
#EXT-X-PROGRAM-DATE-TIME:2020-12-02T18:33:10.887Z
#EXTINF:9.080,
2020-12-02/18/segment_2.ts
#EXT-X-DISCONTINUITY
#EXT-X-PROGRAM-DATE-TIME:2020-12-02T19:33:20.567Z
#EXTINF:9.040,
2020-12-02/18/segment_3.ts
#EXT-X-PROGRAM-DATE-TIME:2020-12-02T19:33:29.607Z
#EXTINF:9.720,
2020-12-02/18/segment_4.ts
#EXT-X-ENDLIST

If we play sequentially, without seeking, then the player, based on the PTS, will jump the gap (that is, getCurrentPosition will return the time one hour later). But if we seek after the gap, then the player will not know anything about the gap and will return the time that we specified in seekTo.

Summation: discontinuities in stream in conjunction with seeking lead to incorrect position.

Proposed solution

Take #EXT-X-PROGRAM-DATE-TIME after #EXT-X-DISCONTINUITY into account if present (especially after seeking).

There is a recommendation in standard: https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-08#section-6.2.1

The server MAY associate an absolute date and time with a Media
Segment by applying an EXT-X-PROGRAM-DATE-TIME tag to it.  This
defines an informative mapping of the (wall-clock) date and time
specified by the tag to the first media timestamp in the segment,
which may be used as a basis for seeking, for display, or for other
purposes. If a server provides this mapping, it SHOULD apply an EXT-X-PROGRAM-DATE-TIME
tag to every segment that has an EXT-X-DISCONTINUITY tag applied to it.

And also:

The Server MUST NOT add any EXT-X-PROGRAM-DATE-TIME tag to a Playlist
that would cause the mapping between program date and Media Segment to become ambiguous.

So it is server-side responsibility to provide correct EXT-X-PROGRAM-DATE-TIME values.

An exemplary algorithm for how this can work

If, during sequential playback, we have reached EXT-X-DISCONTINUITY tag and the next segment starts with EXT-X-PROGRAM-DATE-TIME then correct player’s position and duration. Moreover, it is possible to correct duration earlier, when this tags appear in manifest.

During seek, player should set position considering previous EXT-X-DISCONTINUITY, EXT-X-PROGRAM-DATE-TIME tags. For live playlists player can remember these tags and correct position based on them

ExoPlayer version: 2.12.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
alex3dcommented, Dec 3, 2020

An exemplary algorithm for how this can work

If, during sequential playback, we have reached EXT-X-DISCONTINUITY tag and the next segment starts with EXT-X-PROGRAM-DATE-TIME then correct player’s position and duration. Moreover, it is possible to correct duration earlier, when this tags appear in manifest.

During seek, player should set position considering previous EXT-X-DISCONTINUITY, EXT-X-PROGRAM-DATE-TIME tags. For live playlists player can remember these tags and correct position based on them

I don’t think that’s a good idea because it will confuse window/playlist position and duration with wall clock position/duration based on EXT-X-PROGRAM-DATE-TIME. I suggest:

  1. Ignore PTS diff on EXT-X-DISCONTINUITY (and probably any PTS diff that makes the current segment larger than the duration specified in EXTINF). It will make currentPosition consistent whether we have reached it with or without seek and allow an application to map currentPosition to playlist item and relative position inside this item.
  2. (optional) Provide helper methods to map currentPosition to/from wall clock time based on EXT-X-PROGRAM-DATE-TIME tags. It should probably be left to the application to decide how to map wall clock time to window time because of potential gaps in wall clock time.
0reactions
AquilesCantacommented, Aug 26, 2021

Over to @christosts who’s now maintaining HLS.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RFC 8216: HTTP Live Streaming
This is a contribution to the RFC Series, independently of any other RFC stream. ... RFC 8216 HTTP Live Streaming August 2017 The...
Read more >
draft-pantos-http-live-streaming-13 - IETF Datatracker
1. EXT-X-BYTERANGE The EXT-X-BYTERANGE tag indicates that a media segment is a sub-range of the resource identified by its media URI. · 2....
Read more >
Enabling Low-Latency HTTP Live Streaming (HLS)
You can place other Media Segment Tags (such as EXT-X-DISCONTINUITY ) at Parent Segment boundaries. A Partial Segment must be in one of...
Read more >
How to Insert multiple EXT-X-PROGRAM-DATE-TIME? - Wowza
But there's a problem with that. I would like to add EXT-X-PROGRAM-DATE-TIME to all media segments. For example, I want to do the...
Read more >
FFmpeg HLS streaming - Why the program date time of older ...
When the re-stream happens(in case of restarting the streaming service), the program date time of older segments(before #EXT-X-DISCONTINUITY) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found