-
Notifications
You must be signed in to change notification settings - Fork 69
feat(OpusEncoder): add opus_decode/encode_float binding #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
480f939
89308ba
0d687fe
d56c7c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,7 +30,9 @@ Object NodeOpusEncoder::Init(Napi::Env env, Object exports) { | |||||||||||||
|
|
||||||||||||||
| Function func = DefineClass(env, "OpusEncoder", { | ||||||||||||||
| InstanceMethod("encode", &NodeOpusEncoder::Encode), | ||||||||||||||
| InstanceMethod("encodeFloat", &NodeOpusEncoder::EncodeFloat), | ||||||||||||||
| InstanceMethod("decode", &NodeOpusEncoder::Decode), | ||||||||||||||
| InstanceMethod("decodeFloat", &NodeOpusEncoder::DecodeFloat), | ||||||||||||||
| InstanceMethod("applyEncoderCTL", &NodeOpusEncoder::ApplyEncoderCTL), | ||||||||||||||
| InstanceMethod("applyDecoderCTL", &NodeOpusEncoder::ApplyDecoderCTL), | ||||||||||||||
| InstanceMethod("setBitrate", &NodeOpusEncoder::SetBitrate), | ||||||||||||||
|
|
@@ -45,6 +47,7 @@ NodeOpusEncoder::NodeOpusEncoder(const CallbackInfo& args): ObjectWrap<NodeOpusE | |||||||||||||
| this->encoder = nullptr; | ||||||||||||||
| this->decoder = nullptr; | ||||||||||||||
| this->outPcm = nullptr; | ||||||||||||||
| this->outFloat = nullptr; | ||||||||||||||
|
|
||||||||||||||
| this->rate = 48000; | ||||||||||||||
| this->channels = 2; | ||||||||||||||
|
|
@@ -67,6 +70,7 @@ NodeOpusEncoder::NodeOpusEncoder(const CallbackInfo& args): ObjectWrap<NodeOpusE | |||||||||||||
|
|
||||||||||||||
| this->application = OPUS_APPLICATION_AUDIO; | ||||||||||||||
| this->outPcm = new opus_int16[this->channels * MAX_FRAME_SIZE]; | ||||||||||||||
| this->outFloat = new float[this->channels * MAX_FRAME_SIZE]; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| NodeOpusEncoder::~NodeOpusEncoder() { | ||||||||||||||
|
|
@@ -77,7 +81,9 @@ NodeOpusEncoder::~NodeOpusEncoder() { | |||||||||||||
| this->decoder = nullptr; | ||||||||||||||
|
|
||||||||||||||
| if (this->outPcm) delete this->outPcm; | ||||||||||||||
| if (this->outFloat) delete this->outFloat; | ||||||||||||||
|
Comment on lines
79
to
+84
|
||||||||||||||
| if (this->outPcm) delete this->outPcm; | |
| if (this->outFloat) delete this->outFloat; | |
| if (this->outPcm) delete[] this->outPcm; | |
| if (this->outFloat) delete[] this->outFloat; |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for the return value of opus_encode_float. According to the Opus API documentation, opus_encode_float can return negative values on error (same error codes as opus_decode_float). This function should check if compressedLength < 0 and throw an appropriate error, similar to how DecodeFloat checks for negative return values on line 243. Without this check, negative error codes could be passed to Buffer::Copy causing undefined behavior.
| if (compressedLength < 0) { | |
| Napi::TypeError::New(env, getDecodeError(compressedLength)).ThrowAsJavaScriptException(); | |
| return env.Null(); | |
| } |
Uh oh!
There was an error while loading. Please reload this page.