Mercurial > libavcodec.hg
comparison g726.c @ 7062:fb6038ffd2a9 libavcodec
Get rid of the redundant AVG726Context.
author | michael |
---|---|
date | Wed, 18 Jun 2008 20:51:12 +0000 |
parents | 3e51aa540377 |
children | cd085c1c5103 |
comparison
equal
deleted
inserted
replaced
7061:3e51aa540377 | 7062:fb6038ffd2a9 |
---|---|
87 int td; /**< tone detect */ | 87 int td; /**< tone detect */ |
88 | 88 |
89 int se; /**< estimated signal for the next iteration */ | 89 int se; /**< estimated signal for the next iteration */ |
90 int sez; /**< estimated second order prediction */ | 90 int sez; /**< estimated second order prediction */ |
91 int y; /**< quantizer scaling factor for the next iteration */ | 91 int y; /**< quantizer scaling factor for the next iteration */ |
92 int code_size; | |
92 } G726Context; | 93 } G726Context; |
93 | 94 |
94 static const int quant_tbl16[] = /**< 16kbit/s 2bits per sample */ | 95 static const int quant_tbl16[] = /**< 16kbit/s 2bits per sample */ |
95 { 260, INT_MAX }; | 96 { 260, INT_MAX }; |
96 static const int16_t iquant_tbl16[] = | 97 static const int16_t iquant_tbl16[] = |
297 } | 298 } |
298 #endif | 299 #endif |
299 | 300 |
300 /* Interfacing to the libavcodec */ | 301 /* Interfacing to the libavcodec */ |
301 | 302 |
302 typedef struct AVG726Context { | |
303 G726Context c; | |
304 int code_size; | |
305 } AVG726Context; | |
306 | |
307 static av_cold int g726_init(AVCodecContext * avctx) | 303 static av_cold int g726_init(AVCodecContext * avctx) |
308 { | 304 { |
309 AVG726Context* c = (AVG726Context*)avctx->priv_data; | 305 G726Context* c = avctx->priv_data; |
310 unsigned int index= (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; | 306 unsigned int index= (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; |
311 | 307 |
312 if (avctx->bit_rate % avctx->sample_rate && avctx->codec->encode) { | 308 if (avctx->bit_rate % avctx->sample_rate && avctx->codec->encode) { |
313 av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); | 309 av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); |
314 return -1; | 310 return -1; |
319 } | 315 } |
320 if(index>3){ | 316 if(index>3){ |
321 av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); | 317 av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); |
322 return -1; | 318 return -1; |
323 } | 319 } |
324 g726_reset(&c->c, index); | 320 g726_reset(c, index); |
325 c->code_size = c->c.tbls->bits; | 321 c->code_size = c->tbls->bits; |
326 | 322 |
327 avctx->coded_frame = avcodec_alloc_frame(); | 323 avctx->coded_frame = avcodec_alloc_frame(); |
328 if (!avctx->coded_frame) | 324 if (!avctx->coded_frame) |
329 return AVERROR(ENOMEM); | 325 return AVERROR(ENOMEM); |
330 avctx->coded_frame->key_frame = 1; | 326 avctx->coded_frame->key_frame = 1; |
340 | 336 |
341 #ifdef CONFIG_ENCODERS | 337 #ifdef CONFIG_ENCODERS |
342 static int g726_encode_frame(AVCodecContext *avctx, | 338 static int g726_encode_frame(AVCodecContext *avctx, |
343 uint8_t *dst, int buf_size, void *data) | 339 uint8_t *dst, int buf_size, void *data) |
344 { | 340 { |
345 AVG726Context *c = avctx->priv_data; | 341 G726Context *c = avctx->priv_data; |
346 short *samples = data; | 342 short *samples = data; |
347 PutBitContext pb; | 343 PutBitContext pb; |
348 | 344 |
349 init_put_bits(&pb, dst, 1024*1024); | 345 init_put_bits(&pb, dst, 1024*1024); |
350 | 346 |
351 for (; buf_size; buf_size--) | 347 for (; buf_size; buf_size--) |
352 put_bits(&pb, c->code_size, g726_encode(&c->c, *samples++)); | 348 put_bits(&pb, c->code_size, g726_encode(c, *samples++)); |
353 | 349 |
354 flush_put_bits(&pb); | 350 flush_put_bits(&pb); |
355 | 351 |
356 return put_bits_count(&pb)>>3; | 352 return put_bits_count(&pb)>>3; |
357 } | 353 } |
359 | 355 |
360 static int g726_decode_frame(AVCodecContext *avctx, | 356 static int g726_decode_frame(AVCodecContext *avctx, |
361 void *data, int *data_size, | 357 void *data, int *data_size, |
362 const uint8_t *buf, int buf_size) | 358 const uint8_t *buf, int buf_size) |
363 { | 359 { |
364 AVG726Context *c = avctx->priv_data; | 360 G726Context *c = avctx->priv_data; |
365 short *samples = data; | 361 short *samples = data; |
366 GetBitContext gb; | 362 GetBitContext gb; |
367 | 363 |
368 init_get_bits(&gb, buf, buf_size * 8); | 364 init_get_bits(&gb, buf, buf_size * 8); |
369 | 365 |
370 while (get_bits_count(&gb) + c->code_size <= buf_size*8) | 366 while (get_bits_count(&gb) + c->code_size <= buf_size*8) |
371 *samples++ = g726_decode(&c->c, get_bits(&gb, c->code_size)); | 367 *samples++ = g726_decode(c, get_bits(&gb, c->code_size)); |
372 | 368 |
373 if(buf_size*8 != get_bits_count(&gb)) | 369 if(buf_size*8 != get_bits_count(&gb)) |
374 av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n"); | 370 av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n"); |
375 | 371 |
376 *data_size = (uint8_t*)samples - (uint8_t*)data; | 372 *data_size = (uint8_t*)samples - (uint8_t*)data; |
380 #ifdef CONFIG_ENCODERS | 376 #ifdef CONFIG_ENCODERS |
381 AVCodec adpcm_g726_encoder = { | 377 AVCodec adpcm_g726_encoder = { |
382 "g726", | 378 "g726", |
383 CODEC_TYPE_AUDIO, | 379 CODEC_TYPE_AUDIO, |
384 CODEC_ID_ADPCM_G726, | 380 CODEC_ID_ADPCM_G726, |
385 sizeof(AVG726Context), | 381 sizeof(G726Context), |
386 g726_init, | 382 g726_init, |
387 g726_encode_frame, | 383 g726_encode_frame, |
388 g726_close, | 384 g726_close, |
389 NULL, | 385 NULL, |
390 .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), | 386 .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), |
393 | 389 |
394 AVCodec adpcm_g726_decoder = { | 390 AVCodec adpcm_g726_decoder = { |
395 "g726", | 391 "g726", |
396 CODEC_TYPE_AUDIO, | 392 CODEC_TYPE_AUDIO, |
397 CODEC_ID_ADPCM_G726, | 393 CODEC_ID_ADPCM_G726, |
398 sizeof(AVG726Context), | 394 sizeof(G726Context), |
399 g726_init, | 395 g726_init, |
400 NULL, | 396 NULL, |
401 g726_close, | 397 g726_close, |
402 g726_decode_frame, | 398 g726_decode_frame, |
403 .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), | 399 .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), |