Mercurial > libavcodec.hg
comparison atrac3.c @ 12199:d66dc6f9cc55 libavcodec
Fix memory leak in ATRAC3 decoder
author | vitor |
---|---|
date | Tue, 20 Jul 2010 15:08:54 +0000 |
parents | 8b28e74de2c0 |
children | e402b74c4b62 |
comparison
equal
deleted
inserted
replaced
12198:677570e65a75 | 12199:d66dc6f9cc55 |
---|---|
116 int atrac3version; | 116 int atrac3version; |
117 int delay; | 117 int delay; |
118 int scrambled_stream; | 118 int scrambled_stream; |
119 int frame_factor; | 119 int frame_factor; |
120 //@} | 120 //@} |
121 | |
122 FFTContext mdct_ctx; | |
121 } ATRAC3Context; | 123 } ATRAC3Context; |
122 | 124 |
123 static DECLARE_ALIGNED(16, float,mdct_window)[512]; | 125 static DECLARE_ALIGNED(16, float,mdct_window)[512]; |
124 static VLC spectral_coeff_tab[7]; | 126 static VLC spectral_coeff_tab[7]; |
125 static float gain_tab1[16]; | 127 static float gain_tab1[16]; |
126 static float gain_tab2[31]; | 128 static float gain_tab2[31]; |
127 static FFTContext mdct_ctx; | |
128 static DSPContext dsp; | 129 static DSPContext dsp; |
129 | 130 |
130 | 131 |
131 /** | 132 /** |
132 * Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands | 133 * Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands |
135 * @param pInput float input | 136 * @param pInput float input |
136 * @param pOutput float output | 137 * @param pOutput float output |
137 * @param odd_band 1 if the band is an odd band | 138 * @param odd_band 1 if the band is an odd band |
138 */ | 139 */ |
139 | 140 |
140 static void IMLT(float *pInput, float *pOutput, int odd_band) | 141 static void IMLT(ATRAC3Context *q, float *pInput, float *pOutput, int odd_band) |
141 { | 142 { |
142 int i; | 143 int i; |
143 | 144 |
144 if (odd_band) { | 145 if (odd_band) { |
145 /** | 146 /** |
153 | 154 |
154 for (i=0; i<128; i++) | 155 for (i=0; i<128; i++) |
155 FFSWAP(float, pInput[i], pInput[255-i]); | 156 FFSWAP(float, pInput[i], pInput[255-i]); |
156 } | 157 } |
157 | 158 |
158 ff_imdct_calc(&mdct_ctx,pOutput,pInput); | 159 ff_imdct_calc(&q->mdct_ctx,pOutput,pInput); |
159 | 160 |
160 /* Perform windowing on the output. */ | 161 /* Perform windowing on the output. */ |
161 dsp.vector_fmul(pOutput,mdct_window,512); | 162 dsp.vector_fmul(pOutput,mdct_window,512); |
162 | 163 |
163 } | 164 } |
205 mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]); | 206 mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]); |
206 mdct_window[511-i] = mdct_window[i]; | 207 mdct_window[511-i] = mdct_window[i]; |
207 } | 208 } |
208 | 209 |
209 /* Initialize the MDCT transform. */ | 210 /* Initialize the MDCT transform. */ |
210 ff_mdct_init(&mdct_ctx, 9, 1, 1.0); | 211 ff_mdct_init(&q->mdct_ctx, 9, 1, 1.0); |
211 } | 212 } |
212 | 213 |
213 /** | 214 /** |
214 * Atrac3 uninit, free all allocated memory | 215 * Atrac3 uninit, free all allocated memory |
215 */ | 216 */ |
218 { | 219 { |
219 ATRAC3Context *q = avctx->priv_data; | 220 ATRAC3Context *q = avctx->priv_data; |
220 | 221 |
221 av_free(q->pUnits); | 222 av_free(q->pUnits); |
222 av_free(q->decoded_bytes_buffer); | 223 av_free(q->decoded_bytes_buffer); |
224 ff_mdct_end(&q->mdct_ctx); | |
223 | 225 |
224 return 0; | 226 return 0; |
225 } | 227 } |
226 | 228 |
227 /** | 229 /** |
692 | 694 |
693 /* Reconstruct time domain samples. */ | 695 /* Reconstruct time domain samples. */ |
694 for (band=0; band<4; band++) { | 696 for (band=0; band<4; band++) { |
695 /* Perform the IMDCT step without overlapping. */ | 697 /* Perform the IMDCT step without overlapping. */ |
696 if (band <= numBands) { | 698 if (band <= numBands) { |
697 IMLT(&(pSnd->spectrum[band*256]), pSnd->IMDCT_buf, band&1); | 699 IMLT(q, &(pSnd->spectrum[band*256]), pSnd->IMDCT_buf, band&1); |
698 } else | 700 } else |
699 memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float)); | 701 memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float)); |
700 | 702 |
701 /* gain compensation and overlapping */ | 703 /* gain compensation and overlapping */ |
702 gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]), | 704 gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]), |