Snapcast.Ogg (Snapcast v0.4.0)

Copy Markdown View Source

Minimal Ogg page parser for extracting Opus packets for Snapcast's opus transport.

ffmpeg emits Opus inside an Ogg container, but Snapcast wants the raw Opus packets — one packet per WireChunk (the client runs opus_decode over each chunk payload). This peels Ogg pages and reassembles their segment-laced packets, which may span pages.

Page CRCs are not verified: the bytes come straight from our own ffmpeg over a pipe, not an untrusted source, and the segment table already delimits everything exactly (no sync-scanning needed, unlike Snapcast.Flac).

Summary

Functions

Reassemble the packets in a page, given any partial packet carry continued from the previous page. Returns {complete_packets, new_carry}.

Peel one Ogg page off the front of data.

Functions

split_page(map, carry)

Reassemble the packets in a page, given any partial packet carry continued from the previous page. Returns {complete_packets, new_carry}.

A segment with a lacing value < 255 ends a packet; a value of 255 means it continues into the next segment (and, as the last segment of a page, into the next page).

take_page(bin)

Peel one Ogg page off the front of data.

  • {:ok, %{continued?: boolean, lacing: [byte], data: binary}, rest}
  • :incomplete — the whole page is not present yet
  • :errordata is not at an Ogg page boundary