summaryrefslogtreecommitdiff
path: root/audio_codec/wfd_aac_decoder/buffers.c (plain)
blob: 24282138a552a1e191b7b0f606a0198c0ac0dade
1/* ***** BEGIN LICENSE BLOCK *****
2 * Source last modified: $Id: buffers.c,v 1.1.2.1 2005/02/26 02:05:12 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
46#ifdef USE_DEFAULT_STDLIB
47#include <stdlib.h>
48#else
49#include "hlxclib/stdlib.h"
50#endif
51
52#include "coder.h"
53
54/**************************************************************************************
55 * Function: ClearBuffer
56 *
57 * Description: fill buffer with 0's
58 *
59 * Inputs: pointer to buffer
60 * number of bytes to fill with 0
61 *
62 * Outputs: cleared buffer
63 *
64 * Return: none
65 *
66 * Notes: slow, platform-independent equivalent to memset(buf, 0, nBytes)
67 **************************************************************************************/
68void ClearBuffer(void *buf, int nBytes)
69{
70 int i;
71 unsigned char *cbuf = (unsigned char *)buf;
72
73 for (i = 0; i < nBytes; i++) {
74 cbuf[i] = 0;
75 }
76
77 return;
78}
79
80/**************************************************************************************
81 * Function: AllocateBuffers
82 *
83 * Description: allocate all the memory needed for the AAC decoder
84 *
85 * Inputs: none
86 *
87 * Outputs: none
88 *
89 * Return: pointer to AACDecInfo structure, cleared to all 0's (except for
90 * pointer to platform-specific data structure)
91 *
92 * Notes: if one or more mallocs fail, function frees any buffers already
93 * allocated before returning
94 **************************************************************************************/
95AACDecInfo *AllocateBuffers(void)
96{
97 AACDecInfo *aacDecInfo;
98
99 aacDecInfo = (AACDecInfo *)malloc(sizeof(AACDecInfo));
100 if (!aacDecInfo) {
101 return 0;
102 }
103 ClearBuffer(aacDecInfo, sizeof(AACDecInfo));
104
105 aacDecInfo->psInfoBase = malloc(sizeof(PSInfoBase));
106 if (!aacDecInfo->psInfoBase) {
107 FreeBuffers(aacDecInfo);
108 return 0;
109 }
110 ClearBuffer(aacDecInfo->psInfoBase, sizeof(PSInfoBase));
111
112 return aacDecInfo;
113}
114
115#ifndef SAFE_FREE
116#define SAFE_FREE(x) {if (x) free(x); (x) = 0;} /* helper macro */
117#endif
118
119/**************************************************************************************
120 * Function: FreeBuffers
121 *
122 * Description: frees all the memory used by the AAC decoder
123 *
124 * Inputs: pointer to initialized AACDecInfo structure
125 *
126 * Outputs: none
127 *
128 * Return: none
129 *
130 * Notes: safe to call even if some buffers were not allocated (uses SAFE_FREE)
131 **************************************************************************************/
132void FreeBuffers(AACDecInfo *aacDecInfo)
133{
134 if (!aacDecInfo) {
135 return;
136 }
137
138 SAFE_FREE(aacDecInfo->psInfoBase);
139 SAFE_FREE(aacDecInfo);
140}
141