Mercurial > libavcodec.hg
comparison g726.c @ 12488:351a81a23343 libavcodec
Set a constant frame size for encoding G.726 audio.
author | jbr |
---|---|
date | Sat, 11 Sep 2010 19:52:09 +0000 |
parents | dde20597f15e |
children |
comparison
equal
deleted
inserted
replaced
12487:6cecfd898626 | 12488:351a81a23343 |
---|---|
332 avctx->coded_frame->key_frame = 1; | 332 avctx->coded_frame->key_frame = 1; |
333 | 333 |
334 if (avctx->codec->decode) | 334 if (avctx->codec->decode) |
335 avctx->sample_fmt = SAMPLE_FMT_S16; | 335 avctx->sample_fmt = SAMPLE_FMT_S16; |
336 | 336 |
337 /* select a frame size that will end on a byte boundary and have a size of | |
338 approximately 1024 bytes */ | |
339 if (avctx->codec->encode) | |
340 avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[index]; | |
341 | |
337 return 0; | 342 return 0; |
338 } | 343 } |
339 | 344 |
340 static av_cold int g726_close(AVCodecContext *avctx) | 345 static av_cold int g726_close(AVCodecContext *avctx) |
341 { | 346 { |
348 uint8_t *dst, int buf_size, void *data) | 353 uint8_t *dst, int buf_size, void *data) |
349 { | 354 { |
350 G726Context *c = avctx->priv_data; | 355 G726Context *c = avctx->priv_data; |
351 const short *samples = data; | 356 const short *samples = data; |
352 PutBitContext pb; | 357 PutBitContext pb; |
358 int i; | |
353 | 359 |
354 init_put_bits(&pb, dst, 1024*1024); | 360 init_put_bits(&pb, dst, 1024*1024); |
355 | 361 |
356 for (; buf_size; buf_size--) | 362 for (i = 0; i < avctx->frame_size; i++) |
357 put_bits(&pb, c->code_size, g726_encode(c, *samples++)); | 363 put_bits(&pb, c->code_size, g726_encode(c, *samples++)); |
358 | 364 |
359 flush_put_bits(&pb); | 365 flush_put_bits(&pb); |
360 | 366 |
361 return put_bits_count(&pb)>>3; | 367 return put_bits_count(&pb)>>3; |
392 sizeof(G726Context), | 398 sizeof(G726Context), |
393 g726_init, | 399 g726_init, |
394 g726_encode_frame, | 400 g726_encode_frame, |
395 g726_close, | 401 g726_close, |
396 NULL, | 402 NULL, |
403 .capabilities = CODEC_CAP_SMALL_LAST_FRAME, | |
397 .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, | 404 .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, |
398 .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), | 405 .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), |
399 }; | 406 }; |
400 #endif | 407 #endif |
401 | 408 |