shithub: opus

Download patch

ref: 9d48deb89985d6e88895fe6596850f9287da35b8
parent: 9d8dc3a3cbb50983dade90172c34bd06af9746b2
author: Jean-Marc Valin <[email protected]>
date: Mon Aug 29 05:56:14 EDT 2011

Adds error code to multistream API

--- a/src/opus_multistream.c
+++ b/src/opus_multistream.c
@@ -195,12 +195,26 @@
       int streams,
       int coupled_streams,
       unsigned char *mapping,
-      int application             /* Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */
+      int application,            /* Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */
+      int *error                  /* Error code */
 )
 {
+   int ret;
    OpusMSEncoder *st = malloc(opus_multistream_encoder_get_size(streams, coupled_streams));
-   if (st!=NULL)
-      opus_multistream_encoder_init(st, Fs, channels, streams, coupled_streams, mapping, application);
+   if (st==NULL)
+   {
+      if (error)
+         *error = OPUS_ALLOC_FAIL;
+      return NULL;
+   }
+   ret = opus_multistream_encoder_init(st, Fs, channels, streams, coupled_streams, mapping, application);
+   if (ret != OPUS_OK)
+   {
+      free(st);
+      st = NULL;
+   }
+   if (error)
+      *error = ret;
    return st;
 }
 
@@ -490,12 +504,26 @@
       int channels,               /* Number of channels (1/2) in input signal */
       int streams,
       int coupled_streams,
-      unsigned char *mapping
+      unsigned char *mapping,
+      int *error                  /* Error code */
 )
 {
+   int ret;
    OpusMSDecoder *st = malloc(opus_multistream_decoder_get_size(streams, coupled_streams));
-   if (st!=NULL)
-      opus_multistream_decoder_init(st, Fs, channels, streams, coupled_streams, mapping);
+   if (st==NULL)
+   {
+      if (error)
+         *error = OPUS_ALLOC_FAIL;
+      return NULL;
+   }
+   ret = opus_multistream_decoder_init(st, Fs, channels, streams, coupled_streams, mapping);
+   if (error)
+      *error = ret;
+   if (ret != OPUS_OK)
+   {
+      free(st);
+      st = NULL;
+   }
    return st;
 
 
--- a/src/opus_multistream.h
+++ b/src/opus_multistream.h
@@ -40,7 +40,8 @@
       int streams,
       int coupled_streams,
       unsigned char *mapping,
-      int application             /* Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */
+      int application,            /* Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */
+      int *error                  /* Error code */
 );
 
 OPUS_EXPORT int opus_multistream_encoder_init(
@@ -80,7 +81,8 @@
       int channels,               /* Number of channels (1/2) in input signal */
       int streams,
       int coupled_streams,
-      unsigned char *mapping
+      unsigned char *mapping,
+      int *error                  /* Error code */
 );
 
 OPUS_EXPORT int opus_multistream_decoder_init(