shithub: opus

Download patch

ref: 85b8e62065b0255786cb0401a0b6f427668e0da6
parent: 07f884042eccd913c1e96c1503cc15dfe6af9d2b
author: Jean-Marc Valin <[email protected]>
date: Mon Aug 29 12:10:08 EDT 2011

Fixes minor issues from the previous allocation wrapper patch

--- a/libcelt/os_support.h
+++ b/libcelt/os_support.h
@@ -43,9 +43,6 @@
 #ifndef OVERRIDE_CELT_ALLOC
 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
-      you will experience strange bugs */
    return malloc(size);
 }
 #endif
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -132,20 +132,20 @@
 OpusDecoder *opus_decoder_create(int Fs, int channels, int *error)
 {
    int ret;
-   char *raw_state = (char*)opus_alloc(opus_decoder_get_size(channels));
-   if (raw_state == NULL)
+   OpusDecoder *st = (OpusDecoder *)opus_alloc(opus_decoder_get_size(channels));
+   if (st == NULL)
    {
       if (error)
          *error = OPUS_ALLOC_FAIL;
       return NULL;
    }
-   ret = opus_decoder_init((OpusDecoder*)raw_state, Fs, channels);
+   ret = opus_decoder_init(st, Fs, channels);
    if (ret != OPUS_OK)
    {
-      opus_free(raw_state);
-      raw_state = NULL;
+      opus_free(st);
+      st = NULL;
    }
-   return (OpusDecoder*)raw_state;
+   return st;
 }
 
 static void smooth_fade(const opus_val16 *in1, const opus_val16 *in2, opus_val16 *out,
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -232,22 +232,22 @@
 OpusEncoder *opus_encoder_create(int Fs, int channels, int mode, int *error)
 {
    int ret;
-   char *raw_state = (char *)opus_alloc(opus_encoder_get_size(channels));
-   if (raw_state == NULL)
+   OpusEncoder *st = (OpusEncoder *)opus_alloc(opus_encoder_get_size(channels));
+   if (st == NULL)
    {
       if (error)
          *error = OPUS_ALLOC_FAIL;
       return NULL;
    }
-   ret = opus_encoder_init((OpusEncoder*)raw_state, Fs, channels, mode);
+   ret = opus_encoder_init(st, Fs, channels, mode);
    if (error)
       *error = ret;
    if (ret != OPUS_OK)
    {
-      opus_free(raw_state);
-      raw_state = NULL;
+      opus_free(st);
+      st = NULL;
    }
-   return (OpusEncoder*)raw_state;
+   return st;
 }
 #ifdef FIXED_POINT
 int opus_encode(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
--- a/src/opus_multistream.c
+++ b/src/opus_multistream.c
@@ -33,11 +33,12 @@
 #include "opus.h"
 #include "opus_private.h"
 #include "stack_alloc.h"
-#include "stdio.h"
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
 #include "float_cast.h"
+#include "os_support.h"
 
 typedef struct ChannelLayout {
    int nb_channels;