shithub: libopusenc

Download patch

ref: 2a9299d0be91db23b8f4304be808c55dd4bed2b8
parent: af9c532f7dc7fe59315250ca370358007bc55c9a
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Thu Apr 27 10:52:13 EDT 2017

writing some example code

--- a/examples/opusenc_example.c
+++ b/examples/opusenc_example.c
@@ -1,3 +1,23 @@
+#include <stdio.h>
+#include "opusenc.h"
+
 int main(int argc, char **argv) {
+  FILE *fin;
+  OggOpusEnc *enc;
+  int error;
+  if (argc != 3) {
+    fprintf(stderr, "usage: %s <raw pcm input> <Ogg Opus output>\n", argv[0]);
+    return 1;
+  }
+  fin = fopen(argv[1], "r");
+  if (!fin) {
+    printf("cannout open input file: %s\n", argv[1]);
+    return 1;
+  }
+  enc = ope_create_file(argv[2], 48000, 2, 0, &error);
+  if (!enc) {
+    printf("cannout open output file: %s\n", argv[2]);
+    return 1;
+  }
   return 0;
 }
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -135,6 +135,7 @@
     if (error) *error = OPE_BAD_ARG;
     return NULL;
   }
+  if ( (enc = malloc(sizeof(*enc))) == NULL) goto fail;
   enc->header.channels=channels;
   enc->header.channel_mapping=family;
   enc->header.input_sample_rate=rate;
@@ -145,7 +146,6 @@
   if (! (ret == OPUS_OK && st != NULL) ) {
     goto fail;
   }
-  if ( (enc = malloc(sizeof(*enc))) == NULL) goto fail;
   enc->os_allocated = 0;
   enc->comment = NULL;
   comment_init(&enc->comment, &enc->comment_length, opus_get_version_string());