comparison g726.c @ 7061:3e51aa540377 libavcodec

Remove the truncated bitstream handling from our g726 decoder. The stuff belongs in a parser.
author michael
date Wed, 18 Jun 2008 19:18:32 +0000
parents 54e5978dd41a
children fb6038ffd2a9
comparison
equal deleted inserted replaced
7060:9e5b6bf87f76 7061:3e51aa540377
299 299
300 /* Interfacing to the libavcodec */ 300 /* Interfacing to the libavcodec */
301 301
302 typedef struct AVG726Context { 302 typedef struct AVG726Context {
303 G726Context c; 303 G726Context c;
304 int bits_left;
305 int bit_buffer;
306 int code_size; 304 int code_size;
307 } AVG726Context; 305 } AVG726Context;
308 306
309 static av_cold int g726_init(AVCodecContext * avctx) 307 static av_cold int g726_init(AVCodecContext * avctx)
310 { 308 {
323 av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); 321 av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2);
324 return -1; 322 return -1;
325 } 323 }
326 g726_reset(&c->c, index); 324 g726_reset(&c->c, index);
327 c->code_size = c->c.tbls->bits; 325 c->code_size = c->c.tbls->bits;
328 c->bit_buffer = 0;
329 c->bits_left = 0;
330 326
331 avctx->coded_frame = avcodec_alloc_frame(); 327 avctx->coded_frame = avcodec_alloc_frame();
332 if (!avctx->coded_frame) 328 if (!avctx->coded_frame)
333 return AVERROR(ENOMEM); 329 return AVERROR(ENOMEM);
334 avctx->coded_frame->key_frame = 1; 330 avctx->coded_frame->key_frame = 1;
365 void *data, int *data_size, 361 void *data, int *data_size,
366 const uint8_t *buf, int buf_size) 362 const uint8_t *buf, int buf_size)
367 { 363 {
368 AVG726Context *c = avctx->priv_data; 364 AVG726Context *c = avctx->priv_data;
369 short *samples = data; 365 short *samples = data;
370 uint8_t code;
371 uint8_t mask;
372 GetBitContext gb; 366 GetBitContext gb;
373 367
374 mask = (1<<c->code_size) - 1;
375 init_get_bits(&gb, buf, buf_size * 8); 368 init_get_bits(&gb, buf, buf_size * 8);
376 if (c->bits_left) {
377 int s = c->code_size - c->bits_left;
378 code = (c->bit_buffer << s) | get_bits(&gb, s);
379 *samples++ = g726_decode(&c->c, code & mask);
380 }
381 369
382 while (get_bits_count(&gb) + c->code_size <= buf_size*8) 370 while (get_bits_count(&gb) + c->code_size <= buf_size*8)
383 *samples++ = g726_decode(&c->c, get_bits(&gb, c->code_size)); 371 *samples++ = g726_decode(&c->c, get_bits(&gb, c->code_size));
384 372
385 c->bits_left = buf_size*8 - get_bits_count(&gb); 373 if(buf_size*8 != get_bits_count(&gb))
386 c->bit_buffer = get_bits(&gb, c->bits_left); 374 av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n");
387 375
388 *data_size = (uint8_t*)samples - (uint8_t*)data; 376 *data_size = (uint8_t*)samples - (uint8_t*)data;
389 return buf_size; 377 return buf_size;
390 } 378 }
391 379