shithub: libopusenc

Download patch

ref: 7c26fa8182c66f56daf278d893a0b346d530280d
parent: 43ce233a3024d4c374d312fdd45e1da37b10e7b8
author: Jean-Marc Valin <[email protected]>
date: Sat Apr 29 20:14:49 EDT 2017

Fixing some bugs (still won't encode a file)

--- a/examples/opusenc_example.c
+++ b/examples/opusenc_example.c
@@ -1,6 +1,8 @@
 #include <stdio.h>
 #include "opusenc.h"
 
+#define READ_SIZE 256
+
 int main(int argc, char **argv) {
   FILE *fin;
   OggOpusEnc *enc;
@@ -21,6 +23,13 @@
   }
   ope_add_comment(enc, "ARTIST", "Someone");
   ope_add_comment(enc, "TITLE", "Some track");
+  while (1) {
+    short buf[2*READ_SIZE];
+    int ret = fread(buf, 2*sizeof(short), READ_SIZE, fin);
+    if (ret > 0) {
+      ope_write(enc, buf, ret);
+    } else break;
+  }
   ope_close_and_free(enc);
   return 0;
 }
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -180,7 +180,7 @@
   {
     opus_int32 tmp;
     int ret;
-    ret = opus_multistream_encoder_ctl(enc->st, OPUS_GET_LOOKAHEAD(&tmp));
+    ret = opus_multistream_encoder_ctl(st, OPUS_GET_LOOKAHEAD(&tmp));
     if (ret == OPUS_OK) enc->curr_granule = -tmp;
     else enc->curr_granule = 0;
   }
@@ -195,6 +195,7 @@
   enc->st = st;
   enc->callbacks = *callbacks;
   enc->user_data = user_data;
+  if (error) *error = OPUS_OK;
   return enc;
 fail:
   if (enc) {
@@ -263,7 +264,7 @@
     nbBytes = opus_multistream_encode_float(enc->st, &enc->buffer[enc->channels*enc->buffer_start],
         enc->buffer_end-enc->buffer_start, packet, MAX_PACKET_SIZE);
     /* FIXME: How do we handle failure here. */
-    assert(nbBytes < 0);
+    assert(nbBytes > 0);
     enc->curr_granule += enc->frame_size;
     op.packet=packet;
     op.bytes=nbBytes;