Skip to content

No way to initialise Track sequence numbers for pipeline restart continuity #122

@kingdomcoding

Description

@kingdomcoding

Problem

When a Membrane pipeline is restarted (e.g. after a server crash or planned restart), Manifest.Track always initialises current_seq_num and next_segment_id to 0. If the HLS output directory still contains segments from the previous run, the new playlist will emit a #EXT-X-MEDIA-SEQUENCE value lower than what active players last saw. Per RFC 8216 §4.3.3.2 the media sequence number must never decrease between playlist reloads, so this causes players to stall or error out.

Steps to reproduce

  1. Start a live HLS pipeline writing to a directory.
  2. Let it run long enough to produce several segments (e.g. #EXT-X-MEDIA-SEQUENCE:10).
  3. Restart the server / pipeline without clearing the output directory.
  4. Observe the new playlist starts at #EXT-X-MEDIA-SEQUENCE:0 while the directory still contains segments named audio_segment_10_*.m4s etc.
  5. An active HLS player (e.g. hls.js) will treat the sequence regression as a fatal error.

Expected behaviour

Track.Config (or Sink.TrackConfig) should expose initial_seq_num and initial_segment_id fields so that a recovered pipeline can seed the track state from values parsed out of the pre-existing playlist, producing a continuously-increasing sequence without a #EXT-X-DISCONTINUITY marker.

Suggested API

# Track.Config addition
defstruct @enforce_keys ++ [
  ...
  initial_seq_num: 0,
  initial_segment_id: 0
]

# Track.new/1 honours them
%__MODULE__{
  current_seq_num: config.initial_seq_num,
  next_segment_id: config.initial_segment_id,
  segment_sequencer: {config.initial_seq_num, 0},
  ...
}

SinkBin would expose matching options and thread them through to Sink.TrackConfig.

Workaround

Until this is addressed upstream we are maintaining local copies of Sink and SinkBin that apply the initial values via Map.merge after Manifest.add_track/2 creates the track, and parsing the existing playlist ourselves with a small regex-based parser.

Environment

  • membrane_http_adaptive_stream_plugin v0.20.2
  • Elixir 1.x / OTP 26

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions