Skip to content

Add public encoder API#117

Merged
FrantaBOT merged 6 commits into
pion:mainfrom
thomas-vilte:feat/opus-public-encoder
Jun 9, 2026
Merged

Add public encoder API#117
FrantaBOT merged 6 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

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.13253% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.66%. Comparing base (1b1e053) to head (eb6cb11).
⚠️ Report is 4 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.66%   -0.23%     
==========================================
  Files          26       28       +2     
  Lines        5540     6046     +506     
==========================================
+ Hits         4592     4998     +406     
- Misses        726      812      +86     
- Partials      222      236      +14     
Flag Coverage Δ
go 82.66% <83.13%> (-0.23%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown

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
@FrantaBOT FrantaBOT self-requested a review June 6, 2026 13:04
@thomas-vilte thomas-vilte requested a review from Sean-Der June 9, 2026 02:06
Comment thread encoder.go Outdated
@FrantaBOT FrantaBOT merged commit 4a3f1a6 into pion:main Jun 9, 2026
19 checks passed
@JoTurk

JoTurk commented Jun 9, 2026

Copy link
Copy Markdown
Member

@thomas-vilte @FrantaBOT Should have squash merged or rebased before merge as we usually do a single commit per PR, unless they are standalone commits, if we merge multiple commits in a single PR.

@FrantaBOT

Copy link
Copy Markdown

@thomas-vilte @FrantaBOT Should have squash merged or rebased before merge as we usually do a single commit per PR, unless they are standalone commits, if we merge multiple commits in a single PR.

😓 Sorry, clicked the wrong button

@JoTurk

JoTurk commented Jun 9, 2026

Copy link
Copy Markdown
Member

npnp.

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?

4 participants