Skip to content

Add public encoder API#117

Open
thomas-vilte wants to merge 5 commits into
pion:mainfrom
thomas-vilte:feat/opus-public-encoder
Open

Add public encoder API#117
thomas-vilte wants to merge 5 commits into
pion:mainfrom
thomas-vilte:feat/opus-public-encoder

Conversation

@thomas-vilte
Copy link
Copy Markdown
Contributor

Description

Adds the public Opus encoder API as a wrapper around the internal CELT encoder.

Exposes NewEncoder, Encode (S16LE), EncodeFloat32, SetBitrate, and
SetComplexity at the package root, mirroring the existing Decoder API.

Current scope: 48 kHz, mono, 20 ms CELT-only frames. Stereo, transient
detection, and SILK encoding will land in follow-up PRs.

Round-trip tested against the existing decoder.

Reference issue

Fixes #34

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 83.13253% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.11%. Comparing base (1b1e053) to head (7c3f22b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
encoder.go 82.71% 7 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #117      +/-   ##
==========================================
- Coverage   82.88%   82.11%   -0.78%     
==========================================
  Files          26       27       +1     
  Lines        5540     5703     +163     
==========================================
+ Hits         4592     4683      +91     
- Misses        726      791      +65     
- Partials      222      229       +7     
Flag Coverage Δ
go 82.11% <83.13%> (-0.78%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a first public Opus encoder API at the package root, implemented as a thin wrapper around the internal CELT encoder, to complement the existing public decoder API and address #34 (PCM → Opus encoding support).

Changes:

  • Introduces Encoder with NewEncoder, Init, Encode (S16LE), and EncodeFloat32 for 48 kHz mono 20 ms CELT-only packets.
  • Adds encoder controls SetBitrate and SetComplexity plus new internal sentinel errors for validation.
  • Adds round-trip tests that encode then decode back using the existing decoder.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
errors.go Adds new encoder-related sentinel errors (bitrate/complexity/input/frame validation).
encoder.go Implements the public encoder wrapper API around the internal CELT encoder and constructs a valid Opus packet (TOC + one frame).
encoder_test.go Adds round-trip and validation tests for the new encoder API.
Comments suppressed due to low confidence (1)

encoder.go:90

  • Doc comment says "CELT encoder slice"; this appears to be a typo/incorrect term (likely meant "encoder implementation" or "API surface"). Consider adjusting wording to avoid confusion.
// SetComplexity stores the requested encoder complexity.
//
// The initial CELT encoder slice does not yet vary behavior by complexity,
// but the public API accepts the standard Opus 0..10 range for future
// expansion.
func (e *Encoder) SetComplexity(complexity int) error {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread encoder.go Outdated
Comment thread encoder.go Outdated
Comment thread encoder.go
Comment thread encoder.go
Comment thread encoder_test.go
Comment thread encoder.go Outdated
@thomas-vilte thomas-vilte requested a review from JoTurk May 26, 2026 17:36
@thomas-vilte thomas-vilte removed the request for review from JoTurk May 27, 2026 21:02
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.

Is there a plan to support pcm->opus encoding?

3 participants