Skip to content

Clarify buffer handling when an in-place stream/start changes the player codec or sample rate #276

Closed

Description

@chrisuthe

messaging.md ("Server → Client: stream/start") says a stream/start for a role with an active stream "updates the stream configuration without clearing buffers", and that if a parameter change requires rebuffering the receiver "handles this internally: it does not clear buffers unless its implementation requires it".

For a change of codec, sample_rate, channels or bit_depth on the player role this leaves the timeline ambiguous. The already-buffered chunks are in the old format and run to their own tail; chunks after the new stream/start are in the new format. A client that follows the text literally holds both and must decode two formats against one timeline. A server that assumes the client flushes on the new stream/start (aiosendspin does, and re-sends from now + lead in the new format) produces a gap for a client that does not flush, and a client that flushes produces a gap for a server that continues the old timeline.

Suggested clarification: state which side owns the transition. Either (a) the server MUST continue the existing timeline and MAY only change format at a chunk boundary such that the first new-format chunk's timestamp follows the last old-format chunk, and the client keeps both queued; or (b) a format change on an active stream is treated like stream/clear for the player role: the client drops buffered audio and the server re-applies the startup lead. Option (b) matches "Track transitions ... stream/start to update the existing stream configuration" only if gapless is not expected across a format change.

Reference implementation behaviour today: aiosendspin server/push_stream.py on_role_format_changed and server/roles/player/v1.py _begin_format_transition assume (b).

Activity

  1. added
    question
    on Sep 16, 2026
  2. kahrendt commented on Sep 16, 2026

    @kahrendt
    Contributor

    I think most of the language in the spec describes (a) the server MUST continue the existing timeline. I think the flushing in aiosendspin is relatively new, I could have sworn I tested it out awhile back with sendspin-cpp with a codec change mid-track and it was just concatenated.

    We have 2 cases:

    1. Client requests a new codec mid-stream; i.e., FLAC to Opus. Presumably that uses the same sample rate and channel configuration, and a client should be able to easily do this gapless.
    2. The server tries to match the source material sample rate. This means on a track transition the sample rate can jump from, let's say, 44.1 kHz to 96 kHz. If a client can't do this gapless, then I think they should just not advertise supported formats with different sample rates (or channels if they can't adapt to that).
  3. added a commit that references this issue on Sep 16, 2026
    1fa845b
  4. added a commit that references this issue on Sep 22, 2026
    f7960f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions