diff --git a/libcelt/celt.h b/libcelt/celt.h index 2bbf506603cc648d031b93f5a1b7432d10db4153..7bb9350c4fb6b151d9c40a6ea01db0e3e3419228 100644 --- a/libcelt/celt.h +++ b/libcelt/celt.h @@ -42,11 +42,11 @@ extern "C" { #endif #if defined(__GNUC__) && defined(CELT_BUILD) -#define EXPORT __attribute__ ((visibility ("default"))) +#define CELT_EXPORT __attribute__ ((visibility ("default"))) #elif defined(WIN32) -#define EXPORT __declspec(dllexport) +#define CELT_EXPORT __declspec(dllexport) #else -#define EXPORT +#define CELT_EXPORT #endif #define _celt_check_int(x) (((void)((x) == (celt_int32)0)), (celt_int32)(x)) @@ -157,19 +157,19 @@ typedef struct CELTMode CELTMode; @param error Returned error code (if NULL, no error will be returned) @return A newly created mode */ -EXPORT CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error); +CELT_EXPORT CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error); /** Destroys a mode struct. Only call this after all encoders and decoders using this mode are destroyed as well. @param mode Mode to be destroyed */ -EXPORT void celt_mode_destroy(CELTMode *mode); +CELT_EXPORT void celt_mode_destroy(CELTMode *mode); /* Encoder stuff */ -EXPORT int celt_encoder_get_size(int channels); +CELT_EXPORT int celt_encoder_get_size(int channels); -EXPORT int celt_encoder_get_size_custom(const CELTMode *mode, int channels); +CELT_EXPORT int celt_encoder_get_size_custom(const CELTMode *mode, int channels); /** Creates a new encoder state. Each stream needs its own encoder state (can't be shared across simultaneous streams). @@ -177,7 +177,7 @@ EXPORT int celt_encoder_get_size_custom(const CELTMode *mode, int channels); @param error Returns an error code @return Newly created encoder state. */ -EXPORT CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *error); +CELT_EXPORT CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *error); /** Creates a new encoder state. Each stream needs its own encoder state (can't be shared across simultaneous streams). @@ -188,16 +188,16 @@ EXPORT CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *er @param error Returns an error code @return Newly created encoder state. */ -EXPORT CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error); +CELT_EXPORT CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error); -EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels, int *error); +CELT_EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels, int *error); -EXPORT CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error); +CELT_EXPORT CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error); /** Destroys a an encoder state. @param st Encoder state to be destroyed */ -EXPORT void celt_encoder_destroy(CELTEncoder *st); +CELT_EXPORT void celt_encoder_destroy(CELTEncoder *st); /** Encodes a frame of audio. @param st Encoder state @@ -217,7 +217,7 @@ EXPORT void celt_encoder_destroy(CELTEncoder *st); * the length returned be somehow transmitted to the decoder. Otherwise, no * decoding is possible. */ -EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes); +CELT_EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes); /** Encodes a frame of audio. @param st Encoder state @@ -233,7 +233,7 @@ EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, int frame_size, * the length returned be somehow transmitted to the decoder. Otherwise, no * decoding is possible. */ -EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes); +CELT_EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes); /** Query and set encoder parameters @param st Encoder state @@ -241,13 +241,13 @@ EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, int frame_size, u @param value Pointer to a 32-bit int value @return Error code */ -EXPORT int celt_encoder_ctl(CELTEncoder * st, int request, ...); +CELT_EXPORT int celt_encoder_ctl(CELTEncoder * st, int request, ...); /* Decoder stuff */ -EXPORT int celt_decoder_get_size(int channels); +CELT_EXPORT int celt_decoder_get_size(int channels); -EXPORT int celt_decoder_get_size_custom(const CELTMode *mode, int channels); +CELT_EXPORT int celt_decoder_get_size_custom(const CELTMode *mode, int channels); /** Creates a new decoder state. Each stream needs its own decoder state (can't be shared across simultaneous streams). @@ -257,7 +257,7 @@ EXPORT int celt_decoder_get_size_custom(const CELTMode *mode, int channels); @param error Returns an error code @return Newly created decoder state. */ -EXPORT CELTDecoder *celt_decoder_create(int sampling_rate, int channels, int *error); +CELT_EXPORT CELTDecoder *celt_decoder_create(int sampling_rate, int channels, int *error); /** Creates a new decoder state. Each stream needs its own decoder state (can't be shared across simultaneous streams). @@ -267,16 +267,16 @@ EXPORT CELTDecoder *celt_decoder_create(int sampling_rate, int channels, int *er @param error Returns an error code @return Newly created decoder state. */ -EXPORT CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error); +CELT_EXPORT CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error); -EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels, int *error); +CELT_EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels, int *error); -EXPORT CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error); +CELT_EXPORT CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error); /** Destroys a a decoder state. @param st Decoder state to be destroyed */ -EXPORT void celt_decoder_destroy(CELTDecoder *st); +CELT_EXPORT void celt_decoder_destroy(CELTDecoder *st); /** Decodes a frame of audio. @param st Decoder state @@ -287,7 +287,7 @@ EXPORT void celt_decoder_destroy(CELTDecoder *st); returned here in float format. @return Error code. */ -EXPORT int celt_decode_float(CELTDecoder *st, const unsigned char *data, int len, float *pcm, int frame_size); +CELT_EXPORT int celt_decode_float(CELTDecoder *st, const unsigned char *data, int len, float *pcm, int frame_size); /** Decodes a frame of audio. @param st Decoder state @@ -298,7 +298,7 @@ EXPORT int celt_decode_float(CELTDecoder *st, const unsigned char *data, int len returned here in 16-bit PCM format (native endian). @return Error code. */ -EXPORT int celt_decode(CELTDecoder *st, const unsigned char *data, int len, celt_int16 *pcm, int frame_size); +CELT_EXPORT int celt_decode(CELTDecoder *st, const unsigned char *data, int len, celt_int16 *pcm, int frame_size); /** Query and set decoder parameters @param st Decoder state @@ -306,14 +306,14 @@ EXPORT int celt_decode(CELTDecoder *st, const unsigned char *data, int len, celt @param value Pointer to a 32-bit int value @return Error code */ -EXPORT int celt_decoder_ctl(CELTDecoder * st, int request, ...); +CELT_EXPORT int celt_decoder_ctl(CELTDecoder * st, int request, ...); /** Returns the English string that corresponds to an error code * @param error Error code (negative for an error, 0 for success * @return Constant string (must NOT be freed) */ -EXPORT const char *celt_strerror(int error); +CELT_EXPORT const char *celt_strerror(int error); /* @} */ diff --git a/src/opus_encoder.c b/src/opus_encoder.c index 12909671c35d1308f1147e2c0e726e25912161b4..f8f6e5cc82e9e74cbe5cf754944f347b2c809b31 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -38,14 +38,15 @@ #include "modes.h" #include "SKP_Silk_SDK_API.h" -/* Transition table for the voice mode */ +/* Transition tables for the voice and audio modes. First column is the + middle (memoriless) threshold. The second column is the hysteresis + (difference with the middle) */ static const int voice_bandwidth_thresholds[10] = { 11500, 1500, /* NB<->MB */ 14500, 1500, /* MB<->WB */ 21000, 2000, /* WB<->SWB */ 29000, 2000, /* SWB<->FB */ }; -/* Transition table for the audio mode */ static const int audio_bandwidth_thresholds[10] = { 30000, 0, /* MB not allowed */ 20000, 2000, /* MB<->WB */ @@ -63,11 +64,12 @@ OpusEncoder *opus_encoder_create(int Fs, int channels) /* Create SILK encoder */ ret = SKP_Silk_SDK_Get_Encoder_Size( &silkEncSizeBytes ); - if( ret ) { - /* Handle error */ - } + if( ret ) + return NULL; celtEncSizeBytes = celt_encoder_get_size(channels); raw_state = calloc(sizeof(OpusEncoder)+silkEncSizeBytes+celtEncSizeBytes, 1); + if (raw_state == NULL) + return NULL; st = (OpusEncoder*)raw_state; st->silk_enc = (void*)(raw_state+sizeof(OpusEncoder)); st->celt_enc = (CELTEncoder*)(raw_state+sizeof(OpusEncoder)+silkEncSizeBytes); @@ -76,9 +78,8 @@ OpusEncoder *opus_encoder_create(int Fs, int channels) st->Fs = Fs; ret = SKP_Silk_SDK_InitEncoder( st->silk_enc, &st->silk_mode ); - if( ret ) { - /* Handle error */ - } + if( ret ) + goto failure; /* default SILK parameters */ st->silk_mode.API_sampleRate = st->Fs; @@ -94,6 +95,8 @@ OpusEncoder *opus_encoder_create(int Fs, int channels) /* Create CELT encoder */ /* Initialize CELT encoder */ st->celt_enc = celt_encoder_init(st->celt_enc, Fs, channels, &err); + if (err != CELT_OK) + goto failure; celt_encoder_ctl(st->celt_enc, CELT_SET_SIGNALLING(0)); st->mode = MODE_HYBRID; @@ -110,6 +113,9 @@ OpusEncoder *opus_encoder_create(int Fs, int channels) if (st->Fs > 16000) st->delay_compensation += 10; return st; +failure: + free(st); + return NULL; } int opus_encode(OpusEncoder *st, const short *pcm, int frame_size, @@ -120,7 +126,7 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size, SKP_int32 nBytes; ec_enc enc; int framerate, period; - int silk_internal_bandwidth; + int silk_internal_bandwidth=-1; int bytes_target; int prefill=0; int start_band = 0;