summaryrefslogtreecommitdiff
path: root/audio_codec/libraac/buffers.c (plain)
blob: 1e730781958aeaca86f34cebd3fee5b28ceb2498
1/* ***** BEGIN LICENSE BLOCK *****
2 * Source last modified: $Id: buffers.c,v 1.1 2005/02/26 01:47:34 jrecker Exp $
3 *
4 * Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
5 *
6 * The contents of this file, and the files included with this file,
7 * are subject to the current version of the RealNetworks Public
8 * Source License (the "RPSL") available at
9 * http://www.helixcommunity.org/content/rpsl unless you have licensed
10 * the file under the current version of the RealNetworks Community
11 * Source License (the "RCSL") available at
12 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
13 * will apply. You may also obtain the license terms directly from
14 * RealNetworks. You may not use this file except in compliance with
15 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
16 * to this file, the RCSL. Please see the applicable RPSL or RCSL for
17 * the rights, obligations and limitations governing use of the
18 * contents of the file.
19 *
20 * This file is part of the Helix DNA Technology. RealNetworks is the
21 * developer of the Original Code and owns the copyrights in the
22 * portions it created.
23 *
24 * This file, and the files included with this file, is distributed
25 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
26 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
27 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
28 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
29 * ENJOYMENT OR NON-INFRINGEMENT.
30 *
31 * Technology Compatibility Kit Test Suite(s) Location:
32 * http://www.helixcommunity.org/content/tck
33 *
34 * Contributor(s):
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/**************************************************************************************
39 * Fixed-point HE-AAC decoder
40 * Jon Recker (jrecker@real.com)
41 * February 2005
42 *
43 * buffers.c - allocation and deallocation of internal AAC decoder buffers
44 **************************************************************************************/
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48#include <fcntl.h>
49#include "aaccommon.h"
50//#include <core/dsp.h>
51#include "coder.h"
52
53/**************************************************************************************
54 * Function: ClearBuffer
55 *
56 * Description: fill buffer with 0's
57 *
58 * Inputs: pointer to buffer
59 * number of bytes to fill with 0
60 *
61 * Outputs: cleared buffer
62 *
63 * Return: none
64 *
65 * Notes: slow, platform-independent equivalent to memset(buf, 0, nBytes)
66 **************************************************************************************/
67void ClearBuffer(void *buf, int nBytes)
68{
69 unsigned char *cbuf = (unsigned char *)buf;
70 memset(cbuf, 0, nBytes);
71 return;
72}
73
74
75/**************************************************************************************
76 * Function: AllocateBuffers
77 *
78 * Description: allocate all the memory needed for the AAC decoder
79 *
80 * Inputs: none
81 *
82 * Outputs: none
83 *
84 * Return: pointer to AACDecInfo structure, cleared to all 0's (except for
85 * pointer to platform-specific data structure)
86 *
87 * Notes: if one or more mallocs fail, function frees any buffers already
88 * allocated before returning
89 **************************************************************************************/
90AACDecInfo *AllocateBuffers(void)
91{
92 AACDecInfo *gi;
93 /* create new Gecko2Info structure */
94 gi = (AACDecInfo *)malloc(sizeof(AACDecInfo));
95 if (!gi) {
96 return 0;
97 }
98 ClearBuffer(gi, sizeof(AACDecInfo));
99 gi->psInfoBase = (PSInfoBase *)malloc(sizeof(PSInfoBase));
100 if (!gi->psInfoBase) {
101 return 0;
102 }
103 ClearBuffer(gi->psInfoBase , sizeof(PSInfoBase));
104
105 return gi;
106}
107
108#define SAFE_FREE(x) {if (x) free(x); (x) = 0;} /* helper macro */
109
110/**************************************************************************************
111 * Function: FreeBuffers
112 *
113 * Description: frees all the memory used by the AAC decoder
114 *
115 * Inputs: pointer to initialized AACDecInfo structure
116 *
117 * Outputs: none
118 *
119 * Return: none
120 *
121 * Notes: safe to call even if some buffers were not allocated (uses SAFE_FREE)
122 **************************************************************************************/
123void FreeBuffers(AACDecInfo *aacDecInfo)
124{
125 if (!aacDecInfo) {
126 return;
127 }
128
129 SAFE_FREE(aacDecInfo->psInfoBase);
130 SAFE_FREE(aacDecInfo);
131}
132
133