diff --git a/src/opus_multistream.c b/src/opus_multistream.c index 69ba8dfa187555f793a67b0b5bb4f5820e2e3150..9c82dfef6f5187b5264de3fd95df514ee61e8062 100644 --- a/src/opus_multistream.c +++ b/src/opus_multistream.c @@ -195,12 +195,26 @@ OpusMSEncoder *opus_multistream_encoder_create( 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 @@ OpusMSDecoder *opus_multistream_decoder_create( 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; diff --git a/src/opus_multistream.h b/src/opus_multistream.h index 32adb2bf8ec21b2c1c20b95f6c45bf984e180ea9..665ff6d599b875cc5f9968000dfa62ded6f15447 100644 --- a/src/opus_multistream.h +++ b/src/opus_multistream.h @@ -40,7 +40,8 @@ OPUS_EXPORT OpusMSEncoder *opus_multistream_encoder_create( 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 @@ OPUS_EXPORT OpusMSDecoder *opus_multistream_decoder_create( 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(