comparison ra144.c @ 10776:816067b00019 libavcodec

Use correct context for av_log(), should prevent a crash for malformed files. Patch by Francesco Lavra (francescolavra at interfree dot it).
author vitor
date Tue, 05 Jan 2010 16:25:41 +0000
parents 0dce4fe6e6f3
children e8461dae9672
comparison
equal deleted inserted replaced
10775:35e175942ee2 10776:816067b00019
31 #define BLOCKSIZE 40 ///< subblock size in 16-bit words 31 #define BLOCKSIZE 40 ///< subblock size in 16-bit words
32 #define BUFFERSIZE 146 ///< the size of the adaptive codebook 32 #define BUFFERSIZE 146 ///< the size of the adaptive codebook
33 33
34 34
35 typedef struct { 35 typedef struct {
36 AVCodecContext *avctx;
37
36 unsigned int old_energy; ///< previous frame energy 38 unsigned int old_energy; ///< previous frame energy
37 39
38 unsigned int lpc_tables[2][10]; 40 unsigned int lpc_tables[2][10];
39 41
40 /** LPC coefficients: lpc_coef[0] is the coefficients of the current frame 42 /** LPC coefficients: lpc_coef[0] is the coefficients of the current frame
52 } RA144Context; 54 } RA144Context;
53 55
54 static av_cold int ra144_decode_init(AVCodecContext * avctx) 56 static av_cold int ra144_decode_init(AVCodecContext * avctx)
55 { 57 {
56 RA144Context *ractx = avctx->priv_data; 58 RA144Context *ractx = avctx->priv_data;
59
60 ractx->avctx = avctx;
57 61
58 ractx->lpc_coef[0] = ractx->lpc_tables[0]; 62 ractx->lpc_coef[0] = ractx->lpc_tables[0];
59 ractx->lpc_coef[1] = ractx->lpc_tables[1]; 63 ractx->lpc_coef[1] = ractx->lpc_tables[1];
60 64
61 avctx->sample_fmt = SAMPLE_FMT_S16; 65 avctx->sample_fmt = SAMPLE_FMT_S16;
224 * Does the inverse of the eval_coefs() function. 228 * Does the inverse of the eval_coefs() function.
225 * 229 *
226 * @return 1 if one of the reflection coefficients is greater than 230 * @return 1 if one of the reflection coefficients is greater than
227 * 4095, 0 if not. 231 * 4095, 0 if not.
228 */ 232 */
229 static int eval_refl(int *refl, const int16_t *coefs, RA144Context *ractx) 233 static int eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx)
230 { 234 {
231 int b, i, j; 235 int b, i, j;
232 int buffer1[10]; 236 int buffer1[10];
233 int buffer2[10]; 237 int buffer2[10];
234 int *bp1 = buffer1; 238 int *bp1 = buffer1;
238 buffer2[i] = coefs[i]; 242 buffer2[i] = coefs[i];
239 243
240 refl[9] = bp2[9]; 244 refl[9] = bp2[9];
241 245
242 if ((unsigned) bp2[9] + 0x1000 > 0x1fff) { 246 if ((unsigned) bp2[9] + 0x1000 > 0x1fff) {
243 av_log(ractx, AV_LOG_ERROR, "Overflow. Broken sample?\n"); 247 av_log(avctx, AV_LOG_ERROR, "Overflow. Broken sample?\n");
244 return 1; 248 return 1;
245 } 249 }
246 250
247 for (i=8; i >= 0; i--) { 251 for (i=8; i >= 0; i--) {
248 b = 0x1000-((bp2[i+1] * bp2[i+1]) >> 12); 252 b = 0x1000-((bp2[i+1] * bp2[i+1]) >> 12);
273 // Interpolate block coefficients from the this frame's forth block and 277 // Interpolate block coefficients from the this frame's forth block and
274 // last frame's forth block. 278 // last frame's forth block.
275 for (i=0; i<30; i++) 279 for (i=0; i<30; i++)
276 out[i] = (a * ractx->lpc_coef[0][i] + b * ractx->lpc_coef[1][i])>> 2; 280 out[i] = (a * ractx->lpc_coef[0][i] + b * ractx->lpc_coef[1][i])>> 2;
277 281
278 if (eval_refl(work, out, ractx)) { 282 if (eval_refl(work, out, ractx->avctx)) {
279 // The interpolated coefficients are unstable, copy either new or old 283 // The interpolated coefficients are unstable, copy either new or old
280 // coefficients. 284 // coefficients.
281 int_to_int16(out, ractx->lpc_coef[copyold]); 285 int_to_int16(out, ractx->lpc_coef[copyold]);
282 return rescale_rms(ractx->lpc_refl_rms[copyold], energy); 286 return rescale_rms(ractx->lpc_refl_rms[copyold], energy);
283 } else { 287 } else {