Repository navigation
feat: add Opus streaming encoder (item 8's Opus sub-item) - #118
Merged
Merged
Conversation
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>
This was referenced Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docs/streaming-plan.mditem 8:OpusStreamingEncoderis the secondIStreamingEncoderimplementation, reusingOpusEncoderSession'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.AacStreamingEncoder, both because Opus's own codec characteristics genuinely differ from AAC-LC's:EncoderDelaySamplesis a per-instance property reading the underlying encoder's ownLookaheaddirectly, since Opus's lookahead isn't architecturally fixed at one value the way AAC-LC's one-MDCT-frame delay is.SampleCountis always the full960— 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 — unlikeOpusEncoderSession.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.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
OpusStreamingEncoderTest: construction validation (null callback, unsupported channels/sample rate), every frame including the final one reportsSampleCount == 960, monotonic frame indices,Complete()with zero samples emits nothing, idempotentComplete()/safe doubleDispose(),WriteafterComplete()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 internalOggPageWriter/OpusHeaderPackets) and decodes it through the project's own publicOpusDecoder— proving the raw packets are genuinely valid Opus without new decode-side test infrastructure.dotnet test, net10.0 locally): 1686 passed, 1 pre-existing unrelated skip, 0 failed.🤖 Generated with Claude Code