Skip to content

From play to sound

This page follows one request, “play this album on that speaker”, through the server until audio comes out. It helps you see which controller does which step, so you know where a playback problem or a change belongs.

flowchart TD
  PM["player_queues/play_media"] --> RES["Queue items<br/>queue_loader, media_resolver"]
  RES --> SD["get_stream_details<br/>music provider returns StreamDetails"]
  SD --> SRC["get_media_stream<br/>ffmpeg decodes to raw PCM"]
  SRC --> BUF["AudioBuffer<br/>raw PCM"]
  RES --> PLAY["mass.players.play_media<br/>picks the output protocol"]
  PLAY -->|"speaker fetches a URL"| URL["resolve_stream_url<br/>/single or /flow"]
  PLAY -->|"provider takes PCM"| GS["mass.streams.get_stream"]
  BUF --> ITEM["Per-item processing<br/>normalization, fades, crossfade"]
  URL --> ITEM
  GS --> ITEM
  ITEM -->|"HTTP"| ENC["ffmpeg output step<br/>DSP, encode, pacing"]
  ITEM -->|"PCM"| PROV["Player provider<br/>DSP, own transport"]
  ENC --> DEV1["Chromecast, DLNA, Sonos ..."]
  PROV --> DEV2["AirPlay, Sendspin ..."]
  1. The queue. The player_queues/play_media command resolves the album into tracks and loads them into the player’s queue as QueueItems. Before it tells the player to play, it loads the first item: it gets its stream details and starts filling its buffer.
  2. Stream details. get_stream_details asks the music provider for StreamDetails: where the audio comes from and in which format. A track in the library can have several copies (a local file, two streaming services). The streams controller ranks them and tries them in order.
  3. To raw PCM. get_media_stream opens the source and runs ffmpeg to decode it to raw PCM. Every stream from a music provider holds one of its stream slots (acquire_stream_slot), so the server never opens more streams than the service allows (max_concurrent_streams).
  4. The buffer. The PCM goes into an AudioBuffer. It holds unprocessed audio, so a reconnect, or a seek within what is buffered, does not fetch it from the service again. A live audio source bypasses the buffer. Analysis providers read the same buffer, for example to measure loudness.
  5. Per-item processing. When audio is read from the buffer, the filters for that item are applied: volume normalization, a fade-in, playback speed. Crossfade and smart fades mix the end of one track into the next.
  6. Output. Here the path splits on the protocol the player controller picked:
    • A speaker that fetches a URL gets one from resolve_stream_url, on the stream server of the streams controller. When it asks for that URL, a final ffmpeg step applies the player’s DSP, encodes to the format the speaker wants, and paces the output.
    • A provider that takes PCM calls mass.streams.get_stream and gets processed PCM without the output step. It applies the player’s DSP itself (get_player_output_plan) and sends the audio over its own protocol.

The stream server is a separate HTTP server (port 8097 by default) without authentication or TLS, because many speakers cannot handle either. Each stream URL carries a session id that the server checks instead.

A speaker either plays one track per stream, or one long stream for the whole queue.

  • Single item. Each track has its own URL (/single/...). While a track plays, the queue hands the player the track that follows (enqueue_next_media), so the speaker can play on without a gap.
  • Flow mode. One continuous stream (/flow/...) in which the server joins the tracks and does the crossfades. The stream itself pulls the next queue item.

The streams controller decides per stream request, in resolve_stream_url and get_stream. It uses flow mode when the protocol’s flow_mode is on (by default when the player has no ENQUEUE feature, and the user can override it), when crossfade is on and the player cannot play gapless, when an audio overlay is active, or when a plugin requires it. Radio and live audio sources never use flow mode.

All ffmpeg processes go through music_assistant/helpers/ffmpeg.py (FFMpeg, get_ffmpeg_stream). It runs to decode a source to PCM, to apply the per-item filters, to mix smart fades and crossfades, and for the final encode of every HTTP stream. Some player providers, such as AirPlay and Sendspin, run their own ffmpeg for the player’s DSP.

WARNING

The output pacing (PacingProfile and output_pacing_args in controllers/streams/constants.py) and the stream limits of a music provider (max_concurrent_streams, acquire_stream_slot in models/music_provider.py) exist because of the usage policy. Music Assistant serves audio for listening, not for collecting. Do not remove or loosen them to fix slow buffering. The server’s AGENTS.md lists these guards.

Music Assistant is a project of the Open Home Foundation.