Search code examples
androidm3u8http-live-streaming

HLS Live Broadcast: Keeping track of multiple client


I am trying to write a HLS server with on the fly segmentation.

I am facing issues with figuring out when to delete a old media segment and how to keep track of starting sequence number for multiple client connections and reloads.

Multiple clients may request the same stream at different points in time. For each client, the starting sequence number may be different. An this has to be tracked so that on subsequent reloads, the starting sequence number of the segments is correct.

Has anyone in the community got experience with HLS live broadcast? Any pointers would be helpful.


Solution

  • When NOT to delete an old media segment from the playlist:

    The server MUST NOT remove a media segment from the Playlist file if the duration of the Playlist file minus the duration of the segment is less than three times the target duration.

    Delete old segment from disk: TTL double the playlist length

    For LIVE playlists where the media sequence increments with 1 for each removed segment in the playlist (sliding window) the value is the same for all clients of the same stream. You should never wrap the media sequence, use a UINT64.

    Source: https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-13