shithub: libopusenc

Download patch

ref: 4fca05b7dc011f7290b94f96ca3bbfa9284cb128
parent: 3d48cc60ccf907122be66a241de799a1f9d15cce
author: Jean-Marc Valin <[email protected]>
date: Mon Apr 24 20:59:29 EDT 2017

allocate buffer

--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -37,6 +37,8 @@
 #include "opusenc.h"
 #include "opus_header.h"
 
+#define BUFFER_SAMPLES 96000
+
 struct StdioObject {
   FILE *file;
 };
@@ -96,6 +98,10 @@
     if (error) *error = OPE_ERROR_UNIMPLEMENTED;
     return NULL;
   }
+  if (channels <= 0 || channels > 255) {
+    if (error) *error = OPE_BAD_ARG;
+    return NULL;
+  }
   header.channels=channels;
   header.channel_mapping=family;
   header.input_sample_rate=rate;
@@ -106,6 +112,7 @@
     goto fail;
   }
   if ( (enc = malloc(sizeof(*enc))) == NULL) goto fail;
+  if ( (enc->buffer = malloc(sizeof(*enc->buffer)*BUFFER_SAMPLES*channels)) == NULL) goto fail;
   enc->st = st;
   enc->callbacks = *callbacks;
   enc->user_data = user_data;
@@ -114,6 +121,7 @@
 fail:
   if (enc) {
     free(enc);
+    if (enc->buffer) free(enc->buffer);
   }
   if (st) {
     opus_multistream_encoder_destroy(st);