Skip to content

Fold stream/request-format into client/state - #195

Merged
kahrendt merged 5 commits into
mainfrom
refactor/drop-stream-request-format
Sep 2, 2026
Merged

kahrendt merged 5 commits into
mainfrom
refactor/drop-stream-request-format

Conversation

@maximmaxim345

Copy link
Copy Markdown
Member

stream/request-format was a request in name only: a decline is invisible (the stream continues and the request MUST NOT be treated as an error), so a client only ever learns the operative configuration from stream/start, and with no stream active the server already had to remember the requested format as de facto state. Per the CONTRIBUTING rule that fields expected to change during a connection belong in client/state, the message is dropped and its fields move there.

Changes

player gains an optional format preference in its state object; absent means the server selects per the supported_formats priority order, a present preference must be one of the listed entries (which also removes the previously undefined partial-request case), and the server may still deviate, for example to match a track's native sample rate or to apply an operator-configured format. artwork moves the per-channel source/format/width/height into a state channels array and artwork@v1_support is removed entirely: the array is positional from channel 0, an uncovered channel is source: 'none' so clients may truncate after their last active channel, an array longer than 4 is a protocol error, and format/width/height are required only when source is not 'none'. visualizer moves types, rate_max and spectrum into state; its hello object keeps only buffer_capacity. stream/start now derives each role's configuration from the hello constants plus the role's current state, answers a state change on an active stream with a new stream/start when the configuration changed, never starts a stream in response, and should wait for the state update a role (re-)activation requires before starting that role's stream.

Breaking changes

The stream/request-format message is removed; clients that send it break, and servers drop the handler. Artwork clients no longer send artwork@v1_support and instead carry their channel configuration in client/state; visualizer clients keep only buffer_capacity in their support object and carry the rest in client/state. Players are affected only if they used stream/request-format; the new format state field is optional.

Conflicts with #177 in the player state object; whichever lands second needs a rebase.

Closes #190

Comment thread messaging.md Resolved
Comment thread roles/artwork/v1.md Resolved
Comment thread roles/visualizer/v1.md Resolved
Comment thread roles/artwork/v1.md Resolved
Comment thread messaging.md Resolved
@marcelveldt marcelveldt added this to the 1.0.0 milestone Sep 2, 2026
@kahrendt
kahrendt merged commit 4a66efd into main Sep 2, 2026
1 check passed
@kahrendt
kahrendt deleted the refactor/drop-stream-request-format branch September 2, 2026 15:18
chrisuthe added a commit to Sendspin/aiosendspin that referenced this pull request Sep 17, 2026
Part of #386. One commit per item.

- [x] **S-3** – The server sends `start` only after the source object
has arrived, the client is available and the role is no longer held.
- `request_start()` now queues the request and sends it as soon as all
three hold; nothing reaches the wire early.
- `request_stop()`, a disconnect or the role's deactivation cancels a
queued start. `can_start` exposes the same check.
- The source role now uses the activation-state hold from #417, plus one
new base hook, `Role.on_hold_released()`.
  - A `client/state` missing the required `source` object is flagged.
- The client SDK now includes the `source` object in every
`client/state` while the role is active, so a player+source client
includes it in its first state.
- [x] **S-7** – `SourceCapture` drops PCM and encoded frames captured
more than `MAX_CAPTURE_BACKLOG_US` (500 ms) ago, then continues from
live capture without resending `client-stream/start`.
  - The drop only works when callers pass `capture_timestamp_us`.
- A frame the encoder was already holding can still span the gap; the
encoder is deliberately not reset.
- [x] **S-9** – `client-stream/start` accepts any channel count ≥ 1 and
any bit depth from 1 to 32.
- The stream is announced at 16, 24 or 32 bits, and 8-bit PCM is widened
to 16.
  - Only PCM depths that are not whole bytes are flagged and refused.
  - Channel counts without a named layout use PyAV's unnamed layout.
- [x] **S-10** – The client SDK sends `signal` only when it advertised
`line_sense`.
- [x] **S C** – The `SourceCapture.feed()` docstring now covers the
clock and default of `capture_timestamp_us`.

## Breaking

- `SendspinConnection.send_source_signal()` now raises `RuntimeError`
unless the client advertised `source@v1_support.features.line_sense`.
Before, it sent the signal anyway.

## Compatibility

- A client following an older spec revision may never send the `source`
object in `client/state`.
- A lenient server (`allow_noncompliant_clients=True`) flags it and
treats the client as startable once its initial `client/state` has
arrived and it is available. This applies to the initial state only.
  - A strict server rejects it.
- The tolerance is marked `DEPRECATED(spec-pr-195)`: the requirement to
send a role's state object on activation comes from Sendspin/spec#195.
Sendspin/spec#274 only reworded that paragraph.
- **For embedders:** a source can now announce a channel count PyAV
cannot downmix (9, 11, 13, 15, 17–23, 25+ channels). Converting such a
source to a different channel count makes `SourceBridge` /
`AsrcSourceBridge` raise `ValueError` when it is created, so Music
Assistant's bridge will fail for those sources. Converting at the same
channel count works.

## Deferred

- S-4, S-5, S-8 and S-12 move to new issues.
- S-6 is tracked separately.
- S-11 is left to the maintainers.
maximmaxim345 added a commit to Sendspin/aiosendspin that referenced this pull request Oct 1, 2026
# What does this implement/fix?

<!-- Quick description and explanation of changes. -->

Older clients that declare their artwork channels in `client/hello`
require `format`, `width` and `height` on every `stream/start` channel,
so they rejected the whole artwork `stream/start` once it contained a
`source: none` channel.
This happened when a disabled channel came before a streamed one, when
every channel was disabled, or when a `stream/request-format` disabled a
channel, and artwork then never started. It affects `sendspin-cpp` up to
0.8.0, `sendspin-rs` up to 0.3.7 and the `aiosendspin` client up to
9.1.1.

These clients now get the format and size they declared on their `none`
channels as well. Clients on the `client/state` wire are unchanged.

**Related issue or spec PR (if applicable):**

- Sendspin/spec#195

## Types of changes

<!--
Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the
matching label, and the release notes use it to sort this change.
-->

- [x] Bugfix (non-breaking change which fixes an issue): `bugfix`
- [ ] New feature (non-breaking change which adds functionality):
`new-feature`
- [ ] Enhancement to an existing feature: `enhancement`
- [ ] Breaking change (changes the public API or the protocol in a way
that is not backwards compatible): `breaking-change`
- [ ] Refactor (no behavior change): `refactor`
- [ ] Documentation only: `documentation`
- [ ] Maintenance / chore: `maintenance`
- [ ] CI / workflow change: `ci`
- [ ] Dependencies bump: `dependencies`
maximmaxim345 added a commit to Sendspin/sendspin-js that referenced this pull request Nov 26, 2026
# What does this implement/fix?

<!-- Quick description and explanation of changes. -->

Apps can now tell the server which format they prefer at runtime with
`setPreferredFormat()`, for example to switch between FLAC and Opus
without reconnecting. It sends the optional `format` field of the
`client/state` player object, which replaced `stream/request-format` in
the spec. `null` clears the preference.

The new `supportedFormats` getter lists the formats the player
advertised, since they depend on the browser.
`MessageType.STREAM_REQUEST_FORMAT` stays, marked deprecated. The sample
player has a dropdown for it.

**Related issue or spec PR (if applicable):**

- Closes #115
- Sendspin/spec#195

## Types of changes

<!--
Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the
matching label, and the release notes use it to sort this change.
-->

- [ ] Bugfix (non-breaking change which fixes an issue): `bugfix`
- [x] New feature (non-breaking change which adds functionality):
`new-feature`
- [ ] Enhancement to an existing feature: `enhancement`
- [ ] Breaking change (changes the public API or the protocol in a way
that is not backwards compatible): `breaking-change`
- [ ] Refactor (no behavior change): `refactor`
- [ ] Documentation only: `documentation`
- [ ] Maintenance / chore: `maintenance`
- [ ] CI / workflow change: `ci`
- [ ] Dependencies bump: `dependencies`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move stream/request-format fields into client/state and drop the message

3 participants