shithub: opus

Download patch

ref: 7cfb7305f4bbf950aba2be8c6f864fa3a84c9032
parent: ca8b9928c9ffe41d3cded442a86d8c8b65f97b78
author: Jean-Marc Valin <[email protected]>
date: Fri Aug 27 12:54:33 EDT 2010

Adds _init() functions that do not allocate the states themselves

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -106,8 +106,13 @@
 
 CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error)
 {
-   CELTEncoder *st;
+   return celt_encoder_init(
+         (CELTEncoder *)celt_alloc(celt_encoder_get_size(mode, channels)),
+         mode, channels, error);
+}
 
+CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels, int *error)
+{
    if (channels < 0 || channels > 2)
    {
       celt_warning("Only mono and stereo supported");
@@ -116,7 +121,7 @@
       return NULL;
    }
 
-   st = celt_alloc(celt_encoder_get_size(mode, channels));
+   CELT_MEMSET((char*)st, 0, celt_encoder_get_size(mode, channels));
    
    if (st==NULL)
    {
@@ -1151,9 +1156,13 @@
 
 CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error)
 {
-   int C;
-   CELTDecoder *st;
+   return celt_decoder_init(
+         (CELTDecoder *)celt_alloc(celt_decoder_get_size(mode, channels)),
+         mode, channels, error);
+}
 
+CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channels, int *error)
+{
    if (channels < 0 || channels > 2)
    {
       celt_warning("Only mono and stereo supported");
@@ -1162,8 +1171,7 @@
       return NULL;
    }
 
-   C = CHANNELS(channels);
-   st = celt_alloc(celt_decoder_get_size(mode, channels));
+   CELT_MEMSET((char*)st, 0, celt_decoder_get_size(mode, channels));
 
    if (st==NULL)
    {
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -156,6 +156,7 @@
 
 /* Encoder stuff */
 
+EXPORT int celt_encoder_get_size(const CELTMode *mode, int channels);
 
 /** Creates a new encoder state. Each stream needs its own encoder 
     state (can't be shared across simultaneous streams).
@@ -168,6 +169,8 @@
 */
 EXPORT CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error);
 
+EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels, int *error);
+
 /** Destroys a an encoder state.
  @param st Encoder state to be destroyed
  */
@@ -263,6 +266,7 @@
 
 /* Decoder stuff */
 
+EXPORT int celt_decoder_get_size(const CELTMode *mode, int channels);
 
 /** Creates a new decoder state. Each stream needs its own decoder state (can't
     be shared across simultaneous streams).
@@ -273,6 +277,8 @@
  @return Newly created decoder state.
  */
 EXPORT CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error);
+
+EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channels, int *error);
 
 /** Destroys a a decoder state.
  @param st Decoder state to be destroyed