Skip to content

feat: add Opus streaming encoder (item 8's Opus sub-item) - #118

Merged
cloud-hai-vo merged 2 commits into
mainfrom
feat/opus-streaming-encoder
Oct 17, 2026
Merged

cloud-hai-vo merged 2 commits into
mainfrom
feat/opus-streaming-encoder

Conversation

@cloud-hai-vo

Copy link
Copy Markdown
Contributor

Summary

  • Implements the Opus sub-item of docs/streaming-plan.md item 8: OpusStreamingEncoder is the second IStreamingEncoder implementation, reusing OpusEncoderSession's own Concentus-backed encode internals unchanged — only how each encoded packet is delivered differs (a callback emitting raw packets instead of Ogg-paged bytes to a file), mirroring the exact approach PR feat: add push-style IStreamingEncoder + AAC-LC streaming session #110 established for AAC-LC.
  • Two differences from AacStreamingEncoder, both because Opus's own codec characteristics genuinely differ from AAC-LC's:
    • EncoderDelaySamples is a per-instance property reading the underlying encoder's own Lookahead directly, since Opus's lookahead isn't architecturally fixed at one value the way AAC-LC's one-MDCT-frame delay is.
    • Every emitted frame's own SampleCount is always the full 960 — Opus has no bitstream-level short-final-frame concept (every encoded Opus packet is exactly one fixed frame duration); the real-vs-padding distinction for a partial tail only matters at the container level, out of scope for this raw packet-level encoder.
  • Complete() drains the encoder's own fixed lookahead through the normal buffering path (the only way to push the genuine tail of real input out of the encoder's internal state), but — unlike OpusEncoderSession.Finish() — does not unconditionally emit one final all-zero frame when nothing remains pending afterward; that behavior exists in the file-based session purely to flag an Ogg page's own end-of-stream bit, a container-level concept this raw-packet encoder has none of.
  • MP3 and FLAC streaming sessions (the other two sub-items of item 8) remain not started.
  • Docs synced: docs/streaming-plan.md (Opus sub-item marked done, item 8 overall marked partially done), CLAUDE.md, README.md, llms.txt, llms-full.txt.

Test plan

  • New OpusStreamingEncoderTest: construction validation (null callback, unsupported channels/sample rate), every frame including the final one reports SampleCount == 960, monotonic frame indices, Complete() with zero samples emits nothing, idempotent Complete()/safe double Dispose(), Write after Complete() throws, and a real round-trip SNR test (both mono and stereo) that reconstructs a full OggOpus file from the streaming encoder's own raw packets (via the existing internal OggPageWriter/OpusHeaderPackets) and decodes it through the project's own public OpusDecoder — proving the raw packets are genuinely valid Opus without new decode-side test infrastructure.
  • Full existing suite (dotnet test, net10.0 locally): 1686 passed, 1 pre-existing unrelated skip, 0 failed.
  • Full solution build (all target frameworks + AotSmokeTest): 0 warnings/errors.

🤖 Generated with Claude Code

cloud-hai-vo and others added 2 commits October 17, 2026 16:01
Implements the Opus sub-item of docs/streaming-plan.md item 8:
OpusStreamingEncoder is the second IStreamingEncoder implementation,
reusing OpusEncoderSession's own Concentus-backed encode internals
unchanged -- only how each encoded packet is delivered differs (a
callback emitting raw packets instead of Ogg-paged bytes to a file).

Two differences from AacStreamingEncoder, both because Opus's own
codec characteristics genuinely differ from AAC-LC's: EncoderDelaySamples
is a per-instance property reading the underlying encoder's own
Lookahead directly, since Opus's lookahead isn't architecturally
fixed at one value; and every emitted frame's own SampleCount is
always the full 960, since Opus has no bitstream-level short-final-
frame concept (unlike AAC-LC, every encoded Opus packet is exactly
one fixed frame duration).

Complete() drains the encoder's own fixed lookahead through the
normal buffering path, but -- unlike OpusEncoderSession.Finish() --
does not unconditionally emit one final all-zero frame when nothing
remains pending afterward; that behavior exists in the file-based
session purely to flag an Ogg page's own end-of-stream bit, a
container-level concept this raw-packet encoder has none of.

MP3 and FLAC streaming sessions (the other two sub-items of item 8)
remain not started.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@cloud-hai-vo
cloud-hai-vo merged commit 2458fc9 into main Oct 17, 2026
9 checks passed
@cloud-hai-vo
cloud-hai-vo deleted the feat/opus-streaming-encoder branch October 17, 2026 09:08
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.

1 participant