Skip to content

Commit

Permalink
Merge pull request #6 from IBM/fix/segfault
Browse files Browse the repository at this point in the history
fix(g729): Fixes encoder segmentation fault
  • Loading branch information
jfmartinez authored Apr 15, 2021
2 parents 52a01dd + efd0cdb commit 3bf74b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('g729-codec-service','c', 'cpp', version: '0.0.2', default_options : ['c_std=c17', 'cpp_std=c++17'])
project('g729-codec-service','c', 'cpp', version: '0.0.5', default_options : ['c_std=c17', 'cpp_std=c++17'])
usockets = subproject('usockets')
rapidjson = subproject('rapidjson')
uwebsockets = subproject('uwebsockets')
Expand Down
17 changes: 9 additions & 8 deletions src/G729Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
# define FRAME_SIZE 80 // 80 samples per frame
# define MAX_ENCODER_OUTPUT 10
//# define
int encode_g729_frame(bcg729EncoderChannelContextStruct *encoderChannelContext, int16_t * pcm, int frameSize, uint8_t * data) {
int numberOfEncodingFrames = frameSize / FRAME_SIZE;
int encode_g729_frame(bcg729EncoderChannelContextStruct *encoderChannelContext, int16_t * pcm, int numberOfEncodingFrames, uint8_t * data) {
int totalSize = 0;

data = new uint8_t[numberOfEncodingFrames * MAX_ENCODER_OUTPUT]();
// 160 samples
// 2 frames to decode
// each frame has 80 samples, each sample is 16 bits (2 bytes)
Expand All @@ -53,17 +50,21 @@ G729Encoder::~G729Encoder() {

void G729Encoder::processFrame(AudioFrame& inputFrame, AudioFrame& outputFrame) {
int frameSize = inputFrame.size / 2;
uint8_t * g729_frames;
int byteSize = encode_g729_frame(encoderContext, (int16_t *) inputFrame.data, frameSize, g729_frames);
int numberOfEncodingFrames = frameSize / FRAME_SIZE;
uint8_t * g729_frames = new uint8_t[numberOfEncodingFrames * MAX_ENCODER_OUTPUT]();

int byteSize = encode_g729_frame(encoderContext, (int16_t *) inputFrame.data, numberOfEncodingFrames, g729_frames);
outputFrame.data = (int8_t *) g729_frames;
outputFrame.size = byteSize;
}


void G729Encoder::processFrame(AudioFrame& inputFrame, AudioFrame& outputFrame, VADEvent &vadEvent) {
int frameSize = inputFrame.size / 2;
uint8_t * g729_frames;
int byteSize = encode_g729_frame(encoderContext, (int16_t *) inputFrame.data, frameSize, g729_frames);
int numberOfEncodingFrames = frameSize / FRAME_SIZE;
uint8_t * g729_frames = new uint8_t[numberOfEncodingFrames * MAX_ENCODER_OUTPUT]();

int byteSize = encode_g729_frame(encoderContext, (int16_t *) inputFrame.data, numberOfEncodingFrames, g729_frames);
vadEvent = VADEvent::NONE;
if (byteSize >= 2 && byteSize <= 12) {
if (voiceActive) {
Expand Down

0 comments on commit 3bf74b3

Please sign in to comment.