shithub: libopusenc

Download patch

ref: ac6b2112da610f474389a53628d86c545821fe69
parent: 17f9d3dab46e02b3389f69d3e015544fe18a90da
author: miv <miv@ableton.com>
date: Fri Jul 14 08:25:22 EDT 2017

Fix pull_api mode

ope_encoder_create_pull calls ope_encoder_create_callbacks with a
NULL callbacks argument, which causes the function to crash. Test
for NULL to prevent this.

As well, we try and call the close callback when flushing the stream,
which also leads to a crash when the callbacks are not set. Don't call
the callback in pull mode.

Signed-off-by: Jean-Marc Valin <jmvalin@jmvalin.ca>

--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -344,7 +344,10 @@
   }
   enc->buffer_start = enc->buffer_end = 0;
   enc->st = st;
-  enc->callbacks = *callbacks;
+  if (callbacks != NULL)
+  {
+    enc->callbacks = *callbacks;
+  }
   enc->streams->user_data = user_data;
   if (error) *error = OPE_OK;
   return enc;
@@ -473,7 +476,7 @@
       if (e_o_s) {
         EncStream *tmp;
         tmp = enc->streams->next;
-        if (enc->streams->close_at_end) enc->callbacks.close(enc->streams->user_data);
+        if (enc->streams->close_at_end && !enc->pull_api) enc->callbacks.close(enc->streams->user_data);
         stream_destroy(enc->streams);
         enc->streams = tmp;
         if (!tmp) enc->last_stream = NULL;