From 9d48deb89985d6e88895fe6596850f9287da35b8 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Mon, 29 Aug 2011 09:56:14 -0400 Subject: [PATCH] Adds error code to multistream API --- src/opus_multistream.c | 40 ++++++++++++++++++++++++++++++++++------ src/opus_multistream.h | 6 ++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/opus_multistream.c b/src/opus_multistream.c index 69ba8dfa..9c82dfef 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 32adb2bf..665ff6d5 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(