Skip to content

Commit

Permalink
Add FEC and PLP support for Opus encoding (#1264)
Browse files Browse the repository at this point in the history
* Add FEC and PLP support for Opus encoding

* Silently fail if the Opus engine doesn't support CTL

* Fixed inversed max/min functions
  • Loading branch information
aemino authored and iCrawl committed Apr 2, 2017
1 parent 2ff1f3d commit 8716702
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/client/voice/opus/BaseOpusEngine.js
@@ -1,6 +1,23 @@
class BaseOpus {
constructor(player) {
this.player = player;

this.ctl = {
FEC: 4012,
PLP: 4014,
};
}

init() {
try {
// enable FEC (forward error correction)
this.setFEC(true);

// set PLP (expected packet loss percentage) to 15%
this.setPLP(0.15);
} catch (err) {
// Opus engine likely has no support for libopus CTL
}
}

encode(buffer) {
Expand Down
9 changes: 9 additions & 0 deletions src/client/voice/opus/NodeOpusEngine.js
Expand Up @@ -11,6 +11,15 @@ class NodeOpusEngine extends OpusEngine {
throw err;
}
this.encoder = new opus.OpusEncoder(48000, 2);
super.init();
}

setFEC(enabled) {
this.encoder.applyEncoderCTL(this.ctl.FEC, enabled ? 1 : 0);
}

setPLP(percent) {
this.encoder.applyEncoderCTL(this.ctl.PLP, Math.min(100, Math.max(0, percent * 100)));
}

encode(buffer) {
Expand Down
9 changes: 9 additions & 0 deletions src/client/voice/opus/OpusScriptEngine.js
Expand Up @@ -11,6 +11,15 @@ class OpusScriptEngine extends OpusEngine {
throw err;
}
this.encoder = new OpusScript(48000, 2);
super.init();
}

setFEC(enabled) {
this.encoder.encoderCTL(this.ctl.FEC, enabled ? 1 : 0);
}

setPLP(percent) {
this.encoder.encoderCTL(this.ctl.PLP, Math.min(100, Math.max(0, percent * 100)));
}

encode(buffer) {
Expand Down

0 comments on commit 8716702

Please sign in to comment.