OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
buffers.c
Go to the documentation of this file.
1/* ***** BEGIN LICENSE BLOCK *****
2 * Version: RCSL 1.0/RPSL 1.0
3 *
4 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
5 *
6 * The contents of this file, and the files included with this file, are
7 * subject to the current version of the RealNetworks Public Source License
8 * Version 1.0 (the "RPSL") available at
9 * http://www.helixcommunity.org/content/rpsl unless you have licensed
10 * the file under the RealNetworks Community Source License Version 1.0
11 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
12 * in which case the RCSL will apply. You may also obtain the license terms
13 * directly from RealNetworks. You may not use this file except in
14 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
15 * applicable to this file, the RCSL. Please see the applicable RPSL or
16 * RCSL for the rights, obligations and limitations governing use of the
17 * contents of the file.
18 *
19 * This file is part of the Helix DNA Technology. RealNetworks is the
20 * developer of the Original Code and owns the copyrights in the portions
21 * it created.
22 *
23 * This file, and the files included with this file, is distributed and made
24 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
25 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
26 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
27 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
28 *
29 * Technology Compatibility Kit Test Suite(s) Location:
30 * http://www.helixcommunity.org/content/tck
31 *
32 * Contributor(s):
33 *
34 * ***** END LICENSE BLOCK ***** */
35
36/**************************************************************************************
37 * Fixed-point MP3 decoder
38 * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com)
39 * June 2003
40 *
41 * buffers.c - allocation and freeing of internal MP3 decoder buffers
42 *
43 * All memory allocation for the codec is done in this file, so if you don't want
44 * to use other the default system malloc() and free() for heap management this is
45 * the only file you'll need to change.
46 **************************************************************************************/
47
48#include "mp3compat.h" /* for malloc, free */
49#include "coder.h"
50
51/**************************************************************************************
52 * Function: ClearBuffer
53 *
54 * Description: fill buffer with 0's
55 *
56 * Inputs: pointer to buffer
57 * number of bytes to fill with 0
58 *
59 * Outputs: cleared buffer
60 *
61 * Return: none
62 *
63 * Notes: slow, platform-independent equivalent to memset(buf, 0, nBytes)
64 **************************************************************************************/
65static void ClearBuffer(void *buf, int nBytes)
66{
67 int i;
68 unsigned char *cbuf = (unsigned char *)buf;
69
70 for (i = 0; i < nBytes; i++)
71 cbuf[i] = 0;
72
73 return;
74}
75
76/**************************************************************************************
77 * Function: AllocateBuffers
78 *
79 * Description: allocate all the memory needed for the MP3 decoder
80 *
81 * Inputs: none
82 *
83 * Outputs: none
84 *
85 * Return: pointer to MP3DecInfo structure (initialized with pointers to all
86 * the internal buffers needed for decoding, all other members of
87 * MP3DecInfo structure set to 0)
88 *
89 * Notes: if one or more mallocs fail, function frees any buffers already
90 * allocated before returning
91 **************************************************************************************/
93{
94 MP3DecInfo *mp3DecInfo;
95 FrameHeader *fh;
96 SideInfo *si;
97 ScaleFactorInfo *sfi;
98 HuffmanInfo *hi;
99 DequantInfo *di;
100 IMDCTInfo *mi;
101 SubbandInfo *sbi;
102
103 mp3DecInfo = (MP3DecInfo *)malloc(sizeof(MP3DecInfo));
104 if (!mp3DecInfo)
105 return 0;
106 ClearBuffer(mp3DecInfo, sizeof(MP3DecInfo));
107
108 fh = (FrameHeader *) malloc(sizeof(FrameHeader));
109 si = (SideInfo *) malloc(sizeof(SideInfo));
110 sfi = (ScaleFactorInfo *) malloc(sizeof(ScaleFactorInfo));
111 hi = (HuffmanInfo *) malloc(sizeof(HuffmanInfo));
112 di = (DequantInfo *) malloc(sizeof(DequantInfo));
113 mi = (IMDCTInfo *) malloc(sizeof(IMDCTInfo));
114 sbi = (SubbandInfo *) malloc(sizeof(SubbandInfo));
115
116 mp3DecInfo->FrameHeaderPS = (void *)fh;
117 mp3DecInfo->SideInfoPS = (void *)si;
118 mp3DecInfo->ScaleFactorInfoPS = (void *)sfi;
119 mp3DecInfo->HuffmanInfoPS = (void *)hi;
120 mp3DecInfo->DequantInfoPS = (void *)di;
121 mp3DecInfo->IMDCTInfoPS = (void *)mi;
122 mp3DecInfo->SubbandInfoPS = (void *)sbi;
123
124 if (!fh || !si || !sfi || !hi || !di || !mi || !sbi) {
125 FreeBuffers(mp3DecInfo); /* safe to call - only frees memory that was successfully allocated */
126 return 0;
127 }
128
129 /* important to do this - DSP primitives assume a bunch of state variables are 0 on first use */
130 ClearBuffer(fh, sizeof(FrameHeader));
131 ClearBuffer(si, sizeof(SideInfo));
132 ClearBuffer(sfi, sizeof(ScaleFactorInfo));
133 ClearBuffer(hi, sizeof(HuffmanInfo));
134 ClearBuffer(di, sizeof(DequantInfo));
135 ClearBuffer(mi, sizeof(IMDCTInfo));
136 ClearBuffer(sbi, sizeof(SubbandInfo));
137
138 return mp3DecInfo;
139}
140
141#define SAFE_FREE(x) {if (x) free(x); (x) = 0;} /* helper macro */
142
143/**************************************************************************************
144 * Function: FreeBuffers
145 *
146 * Description: frees all the memory used by the MP3 decoder
147 *
148 * Inputs: pointer to initialized MP3DecInfo structure
149 *
150 * Outputs: none
151 *
152 * Return: none
153 *
154 * Notes: safe to call even if some buffers were not allocated (uses SAFE_FREE)
155 **************************************************************************************/
156void FreeBuffers(MP3DecInfo *mp3DecInfo)
157{
158 if (!mp3DecInfo)
159 return;
160
161 SAFE_FREE(mp3DecInfo->FrameHeaderPS);
162 SAFE_FREE(mp3DecInfo->SideInfoPS);
163 SAFE_FREE(mp3DecInfo->ScaleFactorInfoPS);
164 SAFE_FREE(mp3DecInfo->HuffmanInfoPS);
165 SAFE_FREE(mp3DecInfo->DequantInfoPS);
166 SAFE_FREE(mp3DecInfo->IMDCTInfoPS);
167 SAFE_FREE(mp3DecInfo->SubbandInfoPS);
168
169 SAFE_FREE(mp3DecInfo);
170}
MP3DecInfo * AllocateBuffers(void)
Definition buffers.c:92
#define SAFE_FREE(x)
Definition buffers.c:141
#define malloc(Size)
Definition lzss.h:49
#define FreeBuffers
Definition statname.h:67
void * IMDCTInfoPS
Definition mp3common.h:71
void * FrameHeaderPS
Definition mp3common.h:66
void * DequantInfoPS
Definition mp3common.h:70
void * ScaleFactorInfoPS
Definition mp3common.h:68
void * SideInfoPS
Definition mp3common.h:67
void * HuffmanInfoPS
Definition mp3common.h:69
void * SubbandInfoPS
Definition mp3common.h:72