summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2011-08-29 15:08:51 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2011-08-29 15:08:51 -0400
commit07f884042eccd913c1e96c1503cc15dfe6af9d2b (patch)
tree5b48725b9aafbf2b41e0fffc365a7b85faceb753
parent4a4a54644078f34ce0f9c86a01ec1159579afb48 (diff)
downloadopus-07f884042eccd913c1e96c1503cc15dfe6af9d2b.tar.gz
Wrapping all allocation within opus_alloc() and opus_free()
-rw-r--r--libcelt/celt.c12
-rw-r--r--libcelt/kiss_fft.c7
-rw-r--r--libcelt/kiss_fft.h2
-rw-r--r--libcelt/mdct.c4
-rw-r--r--libcelt/modes.c28
-rw-r--r--libcelt/os_support.h15
-rw-r--r--libcelt/stack_alloc.h4
-rw-r--r--src/opus_decoder.c10
-rw-r--r--src/opus_encoder.c9
-rw-r--r--src/opus_multistream.c12
-rw-r--r--src/repacketizer.c5
11 files changed, 55 insertions, 53 deletions
diff --git a/libcelt/celt.c b/libcelt/celt.c
index 92f896a2..dce42ec3 100644
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -199,7 +199,7 @@ int celt_encoder_get_size_custom(const CELTMode *mode, int channels)
CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *error)
{
CELTEncoder *st;
- st = (CELTEncoder *)celt_alloc(celt_encoder_get_size(channels));
+ st = (CELTEncoder *)opus_alloc(celt_encoder_get_size(channels));
if (st!=NULL && celt_encoder_init(st, sampling_rate, channels, error)==NULL)
{
celt_encoder_destroy(st);
@@ -210,7 +210,7 @@ CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *error)
CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error)
{
- CELTEncoder *st = (CELTEncoder *)celt_alloc(celt_encoder_get_size_custom(mode, channels));
+ CELTEncoder *st = (CELTEncoder *)opus_alloc(celt_encoder_get_size_custom(mode, channels));
if (st!=NULL && celt_encoder_init_custom(st, mode, channels, error)==NULL)
{
celt_encoder_destroy(st);
@@ -280,7 +280,7 @@ CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int
void celt_encoder_destroy(CELTEncoder *st)
{
- celt_free(st);
+ opus_free(st);
}
static inline opus_val16 SIG2WORD16(celt_sig x)
@@ -1923,7 +1923,7 @@ int celt_decoder_get_size_custom(const CELTMode *mode, int channels)
CELTDecoder *celt_decoder_create(int sampling_rate, int channels, int *error)
{
CELTDecoder *st;
- st = (CELTDecoder *)celt_alloc(celt_decoder_get_size(channels));
+ st = (CELTDecoder *)opus_alloc(celt_decoder_get_size(channels));
if (st!=NULL && celt_decoder_init(st, sampling_rate, channels, error)==NULL)
{
celt_decoder_destroy(st);
@@ -1934,7 +1934,7 @@ CELTDecoder *celt_decoder_create(int sampling_rate, int channels, int *error)
CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error)
{
- CELTDecoder *st = (CELTDecoder *)celt_alloc(celt_decoder_get_size_custom(mode, channels));
+ CELTDecoder *st = (CELTDecoder *)opus_alloc(celt_decoder_get_size_custom(mode, channels));
if (st!=NULL && celt_decoder_init_custom(st, mode, channels, error)==NULL)
{
celt_decoder_destroy(st);
@@ -1992,7 +1992,7 @@ CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int
void celt_decoder_destroy(CELTDecoder *st)
{
- celt_free(st);
+ opus_free(st);
}
static void celt_decode_lost(CELTDecoder * restrict st, opus_val16 * restrict pcm, int N, int LM)
diff --git a/libcelt/kiss_fft.c b/libcelt/kiss_fft.c
index ae738bce..4429ba6d 100644
--- a/libcelt/kiss_fft.c
+++ b/libcelt/kiss_fft.c
@@ -40,6 +40,7 @@
#include "os_support.h"
#include "mathops.h"
#include "stack_alloc.h"
+#include "os_support.h"
/* The guts header contains all the multiplication and addition macros that are defined for
complex numbers. It also delares the kf_ internal functions.
@@ -600,10 +601,10 @@ void opus_fft_free(const kiss_fft_state *cfg)
{
if (cfg)
{
- celt_free((opus_int16*)cfg->bitrev);
+ opus_free((opus_int16*)cfg->bitrev);
if (cfg->shift < 0)
- celt_free((kiss_twiddle_cpx*)cfg->twiddles);
- celt_free((kiss_fft_state*)cfg);
+ opus_free((kiss_twiddle_cpx*)cfg->twiddles);
+ opus_free((kiss_fft_state*)cfg);
}
}
diff --git a/libcelt/kiss_fft.h b/libcelt/kiss_fft.h
index cb302e64..95adf055 100644
--- a/libcelt/kiss_fft.h
+++ b/libcelt/kiss_fft.h
@@ -55,7 +55,7 @@ extern "C" {
# define kiss_fft_scalar __m128
#define KISS_FFT_MALLOC(nbytes) memalign(16,nbytes)
#else
-#define KISS_FFT_MALLOC celt_alloc
+#define KISS_FFT_MALLOC opus_alloc
#endif
#ifdef FIXED_POINT
diff --git a/libcelt/mdct.c b/libcelt/mdct.c
index 43af87c0..0d461e30 100644
--- a/libcelt/mdct.c
+++ b/libcelt/mdct.c
@@ -75,7 +75,7 @@ int clt_mdct_init(mdct_lookup *l,int N, int maxshift)
return 0;
#endif
}
- l->trig = trig = (kiss_twiddle_scalar*)celt_alloc((N4+1)*sizeof(kiss_twiddle_scalar));
+ l->trig = trig = (kiss_twiddle_scalar*)opus_alloc((N4+1)*sizeof(kiss_twiddle_scalar));
if (l->trig==NULL)
return 0;
/* We have enough points that sine isn't necessary */
@@ -94,7 +94,7 @@ void clt_mdct_clear(mdct_lookup *l)
int i;
for (i=0;i<=l->maxshift;i++)
opus_fft_free(l->kfft[i]);
- celt_free((kiss_twiddle_scalar*)l->trig);
+ opus_free((kiss_twiddle_scalar*)l->trig);
}
#endif /* CUSTOM_MODES */
diff --git a/libcelt/modes.c b/libcelt/modes.c
index 483f9ee8..df183fb2 100644
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -95,7 +95,7 @@ static opus_int16 *compute_ebands(opus_int32 Fs, int frame_size, int res, int *n
if (Fs == 400*(opus_int32)frame_size)
{
*nbEBands = sizeof(eband5ms)/sizeof(eband5ms[0])-1;
- eBands = celt_alloc(sizeof(opus_int16)*(*nbEBands+1));
+ eBands = opus_alloc(sizeof(opus_int16)*(*nbEBands+1));
for (i=0;i<*nbEBands+1;i++)
eBands[i] = eband5ms[i];
return eBands;
@@ -113,7 +113,7 @@ static opus_int16 *compute_ebands(opus_int32 Fs, int frame_size, int res, int *n
low = (bark_freq[lin]+res/2)/res;
high = nBark-lin;
*nbEBands = low+high;
- eBands = celt_alloc(sizeof(opus_int16)*(*nbEBands+2));
+ eBands = opus_alloc(sizeof(opus_int16)*(*nbEBands+2));
if (eBands==NULL)
return NULL;
@@ -170,7 +170,7 @@ static void compute_allocation_table(CELTMode *mode)
int maxBands = sizeof(eband5ms)/sizeof(eband5ms[0])-1;
mode->nbAllocVectors = BITALLOC_SIZE;
- allocVectors = celt_alloc(sizeof(unsigned char)*(BITALLOC_SIZE*mode->nbEBands));
+ allocVectors = opus_alloc(sizeof(unsigned char)*(BITALLOC_SIZE*mode->nbEBands));
if (allocVectors==NULL)
return;
@@ -303,7 +303,7 @@ CELTMode *celt_mode_create(opus_int32 Fs, int frame_size, int *error)
return NULL;
}
- mode = celt_alloc(sizeof(CELTMode));
+ mode = opus_alloc(sizeof(CELTMode));
if (mode==NULL)
goto failure;
mode->Fs = Fs;
@@ -357,7 +357,7 @@ CELTMode *celt_mode_create(opus_int32 Fs, int frame_size, int *error)
if (mode->allocVectors==NULL)
goto failure;
- window = (opus_val16*)celt_alloc(mode->overlap*sizeof(opus_val16));
+ window = (opus_val16*)opus_alloc(mode->overlap*sizeof(opus_val16));
if (window==NULL)
goto failure;
@@ -370,7 +370,7 @@ CELTMode *celt_mode_create(opus_int32 Fs, int frame_size, int *error)
#endif
mode->window = window;
- logN = (opus_int16*)celt_alloc(mode->nbEBands*sizeof(opus_int16));
+ logN = (opus_int16*)opus_alloc(mode->nbEBands*sizeof(opus_int16));
if (logN==NULL)
goto failure;
@@ -412,17 +412,17 @@ void celt_mode_destroy(CELTMode *mode)
}
}
#endif /* CUSTOM_MODES_ONLY */
- celt_free((opus_int16*)mode->eBands);
- celt_free((opus_int16*)mode->allocVectors);
+ opus_free((opus_int16*)mode->eBands);
+ opus_free((opus_int16*)mode->allocVectors);
- celt_free((opus_val16*)mode->window);
- celt_free((opus_int16*)mode->logN);
+ opus_free((opus_val16*)mode->window);
+ opus_free((opus_int16*)mode->logN);
- celt_free((opus_int16*)mode->cache.index);
- celt_free((unsigned char*)mode->cache.bits);
- celt_free((unsigned char*)mode->cache.caps);
+ opus_free((opus_int16*)mode->cache.index);
+ opus_free((unsigned char*)mode->cache.bits);
+ opus_free((unsigned char*)mode->cache.caps);
clt_mdct_clear(&mode->mdct);
- celt_free((CELTMode *)mode);
+ opus_free((CELTMode *)mode);
#endif
}
diff --git a/libcelt/os_support.h b/libcelt/os_support.h
index 21f1617c..bcc2a5d9 100644
--- a/libcelt/os_support.h
+++ b/libcelt/os_support.h
@@ -39,10 +39,9 @@
#include <stdio.h>
#include <stdlib.h>
-/** CELT wrapper for calloc(). To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_free
- NOTE: celt_alloc needs to CLEAR THE MEMORY */
+/** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */
#ifndef OVERRIDE_CELT_ALLOC
-static inline void *celt_alloc (size_t size)
+static inline void *opus_alloc (size_t size)
{
/* WARNING: this is not equivalent to malloc(). If you want to use malloc()
or your own allocator, YOU NEED TO CLEAR THE MEMORY ALLOCATED. Otherwise
@@ -53,18 +52,18 @@ static inline void *celt_alloc (size_t size)
/** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */
#ifndef OVERRIDE_CELT_ALLOC_SCRATCH
-static inline void *celt_alloc_scratch (size_t size)
+static inline void *opus_alloc_scratch (size_t size)
{
/* Scratch space doesn't need to be cleared */
- return malloc(size);
+ return opus_alloc(size);
}
#endif
-/** CELT wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_alloc */
+/** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */
#ifndef OVERRIDE_CELT_FREE
-static inline void celt_free (void *ptr)
+static inline void opus_free (void *ptr)
{
- free(ptr);
+ opus_free(ptr);
}
#endif
diff --git a/libcelt/stack_alloc.h b/libcelt/stack_alloc.h
index 2d90df4f..512f5292 100644
--- a/libcelt/stack_alloc.h
+++ b/libcelt/stack_alloc.h
@@ -124,14 +124,14 @@ extern char *global_stack_top;
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
#define PUSH(stack, size, type) (VALGRIND_MAKE_MEM_NOACCESS(stack, global_stack_top-stack),ALIGN((stack),sizeof(type)/sizeof(char)),VALGRIND_MAKE_MEM_UNDEFINED(stack, ((size)*sizeof(type)/sizeof(char))),(stack)+=(2*(size)*sizeof(type)/sizeof(char)),(type*)((stack)-(2*(size)*sizeof(type)/sizeof(char))))
#define RESTORE_STACK ((global_stack = _saved_stack),VALGRIND_MAKE_MEM_NOACCESS(global_stack, global_stack_top-global_stack))
-#define ALLOC_STACK char *_saved_stack; ((global_stack = (global_stack==0) ? ((global_stack_top=celt_alloc_scratch(GLOBAL_STACK_SIZE*2)+(GLOBAL_STACK_SIZE*2))-(GLOBAL_STACK_SIZE*2)) : global_stack),VALGRIND_MAKE_MEM_NOACCESS(global_stack, global_stack_top-global_stack)); _saved_stack = global_stack;
+#define ALLOC_STACK char *_saved_stack; ((global_stack = (global_stack==0) ? ((global_stack_top=opus_alloc_scratch(GLOBAL_STACK_SIZE*2)+(GLOBAL_STACK_SIZE*2))-(GLOBAL_STACK_SIZE*2)) : global_stack),VALGRIND_MAKE_MEM_NOACCESS(global_stack, global_stack_top-global_stack)); _saved_stack = global_stack;
#else
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)/sizeof(char)),(stack)+=(size)*(sizeof(type)/sizeof(char)),(type*)((stack)-(size)*(sizeof(type)/sizeof(char))))
#define RESTORE_STACK (global_stack = _saved_stack)
-#define ALLOC_STACK char *_saved_stack; (global_stack = (global_stack==0) ? celt_alloc_scratch(GLOBAL_STACK_SIZE) : global_stack); _saved_stack = global_stack;
+#define ALLOC_STACK char *_saved_stack; (global_stack = (global_stack==0) ? opus_alloc_scratch(GLOBAL_STACK_SIZE) : global_stack); _saved_stack = global_stack;
#endif /*ENABLE_VALGRIND*/
diff --git a/src/opus_decoder.c b/src/opus_decoder.c
index b4501294..8f9774c2 100644
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -41,7 +41,7 @@
#include "stack_alloc.h"
#include "float_cast.h"
#include "opus_private.h"
-
+#include "os_support.h"
#ifdef FIXED_POINT
#define celt_decode_native celt_decode
@@ -125,14 +125,14 @@ int opus_decoder_init(OpusDecoder *st, int Fs, int channels)
st->frame_size = Fs/400;
return OPUS_OK;
failure:
- free(st);
+ opus_free(st);
return OPUS_INTERNAL_ERROR;
}
OpusDecoder *opus_decoder_create(int Fs, int channels, int *error)
{
int ret;
- char *raw_state = (char*)malloc(opus_decoder_get_size(channels));
+ char *raw_state = (char*)opus_alloc(opus_decoder_get_size(channels));
if (raw_state == NULL)
{
if (error)
@@ -142,7 +142,7 @@ OpusDecoder *opus_decoder_create(int Fs, int channels, int *error)
ret = opus_decoder_init((OpusDecoder*)raw_state, Fs, channels);
if (ret != OPUS_OK)
{
- free(raw_state);
+ opus_free(raw_state);
raw_state = NULL;
}
return (OpusDecoder*)raw_state;
@@ -772,7 +772,7 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...)
void opus_decoder_destroy(OpusDecoder *st)
{
- free(st);
+ opus_free(st);
}
diff --git a/src/opus_encoder.c b/src/opus_encoder.c
index dd7487ce..ef1dbe54 100644
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -42,6 +42,7 @@
#include "opus.h"
#include "arch.h"
#include "opus_private.h"
+#include "os_support.h"
#ifdef FIXED_POINT
#define celt_encode_native celt_encode
@@ -193,7 +194,7 @@ int opus_encoder_init(OpusEncoder* st, int Fs, int channels, int application)
return OPUS_OK;
failure:
- free(st);
+ opus_free(st);
return OPUS_INTERNAL_ERROR;
}
@@ -231,7 +232,7 @@ static unsigned char gen_toc(int mode, int framerate, int bandwidth, int channel
OpusEncoder *opus_encoder_create(int Fs, int channels, int mode, int *error)
{
int ret;
- char *raw_state = (char *)malloc(opus_encoder_get_size(channels));
+ char *raw_state = (char *)opus_alloc(opus_encoder_get_size(channels));
if (raw_state == NULL)
{
if (error)
@@ -243,7 +244,7 @@ OpusEncoder *opus_encoder_create(int Fs, int channels, int mode, int *error)
*error = ret;
if (ret != OPUS_OK)
{
- free(raw_state);
+ opus_free(raw_state);
raw_state = NULL;
}
return (OpusEncoder*)raw_state;
@@ -1005,5 +1006,5 @@ bad_arg:
void opus_encoder_destroy(OpusEncoder *st)
{
- free(st);
+ opus_free(st);
}
diff --git a/src/opus_multistream.c b/src/opus_multistream.c
index 9c82dfef..6073c546 100644
--- a/src/opus_multistream.c
+++ b/src/opus_multistream.c
@@ -200,7 +200,7 @@ OpusMSEncoder *opus_multistream_encoder_create(
)
{
int ret;
- OpusMSEncoder *st = malloc(opus_multistream_encoder_get_size(streams, coupled_streams));
+ OpusMSEncoder *st = opus_alloc(opus_multistream_encoder_get_size(streams, coupled_streams));
if (st==NULL)
{
if (error)
@@ -210,7 +210,7 @@ OpusMSEncoder *opus_multistream_encoder_create(
ret = opus_multistream_encoder_init(st, Fs, channels, streams, coupled_streams, mapping, application);
if (ret != OPUS_OK)
{
- free(st);
+ opus_free(st);
st = NULL;
}
if (error)
@@ -440,7 +440,7 @@ int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...)
void opus_multistream_encoder_destroy(OpusMSEncoder *st)
{
- free(st);
+ opus_free(st);
}
@@ -509,7 +509,7 @@ OpusMSDecoder *opus_multistream_decoder_create(
)
{
int ret;
- OpusMSDecoder *st = malloc(opus_multistream_decoder_get_size(streams, coupled_streams));
+ OpusMSDecoder *st = opus_alloc(opus_multistream_decoder_get_size(streams, coupled_streams));
if (st==NULL)
{
if (error)
@@ -521,7 +521,7 @@ OpusMSDecoder *opus_multistream_decoder_create(
*error = ret;
if (ret != OPUS_OK)
{
- free(st);
+ opus_free(st);
st = NULL;
}
return st;
@@ -739,5 +739,5 @@ int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...)
void opus_multistream_decoder_destroy(OpusMSDecoder *st)
{
- free(st);
+ opus_free(st);
}
diff --git a/src/repacketizer.c b/src/repacketizer.c
index 278228fa..55b1dbf1 100644
--- a/src/repacketizer.c
+++ b/src/repacketizer.c
@@ -35,6 +35,7 @@
#include "opus.h"
#include "opus_private.h"
+#include "os_support.h"
struct OpusRepacketizer {
unsigned char toc;
@@ -59,12 +60,12 @@ OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp)
OpusRepacketizer *opus_repacketizer_create(void)
{
- return opus_repacketizer_init(malloc(opus_repacketizer_get_size()));
+ return opus_repacketizer_init(opus_alloc(opus_repacketizer_get_size()));
}
void opus_repacketizer_destroy(OpusRepacketizer *rp)
{
- free(rp);
+ opus_free(rp);
}
int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, int len)