summaryrefslogtreecommitdiff
path: root/libavcodec/libopencore-amr.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-03-05 00:02:58 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-03-05 00:15:55 +0100
commit2af8f2cea6c94eba3a15820194cb7374b366976a (patch)
tree634d34b8adf1c35cc1bb7c3eb1f2b49775ffbb56 /libavcodec/libopencore-amr.c
parent33a183df46355e4b281517e14c9b3c7e2b558dcf (diff)
parent3faa141d15bf9945fa54331e51b3f10b9970d5d2 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (27 commits) cmdutils: use new avcodec_is_decoder/encoder() functions. lavc: make codec_is_decoder/encoder() public. lavc: deprecate AVCodecContext.sub_id. libcdio: add a forgotten AVClass to the private context. swscale: remove "cpu flags" from -sws_flags description. proresenc: give user a possibility to alter some encoding parameters vorbisenc: add output buffer overwrite protection libopencore-amrnbenc: fix end-of-stream handling ra144enc: fix end-of-stream handling nellymoserenc: zero any leftover packet bytes nellymoserenc: use proper MDCT overlap delay qpeg: Use bytestream2 functions to prevent buffer overreads. swscale: make %rep unconditional. vp8: convert simple loopfilter x86 assembly to use named arguments. vp8: convert idct x86 assembly to use named arguments. vp8: convert mc x86 assembly to use named arguments. vp8: convert loopfilter x86 assembly to use cpuflags(). vp8: convert idct/mc x86 assembly to use cpuflags(). swscale: remove now unnecessary hack. x86inc: don't "bake" stack_offset in named arguments. ... Conflicts: cmdutils.c doc/APIchanges libavcodec/mpeg12.c libavcodec/options.c libavcodec/qpeg.c libavcodec/utils.c libavcodec/version.h libavdevice/libcdio.c tests/lavf-regression.sh Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/libopencore-amr.c')
-rw-r--r--libavcodec/libopencore-amr.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 7a0555e6c5..90a8c651e2 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -85,6 +85,7 @@ typedef struct AMRContext {
int enc_bitrate;
int enc_mode;
int enc_dtx;
+ int enc_last_frame;
} AMRContext;
static const AVOption options[] = {
@@ -195,6 +196,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
}
avctx->frame_size = 160;
+ avctx->delay = 50;
avctx->coded_frame = avcodec_alloc_frame();
if (!avctx->coded_frame)
return AVERROR(ENOMEM);
@@ -227,17 +229,40 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
{
AMRContext *s = avctx->priv_data;
int written;
+ int16_t *flush_buf = NULL;
+ const int16_t *samples = data;
if (s->enc_bitrate != avctx->bit_rate) {
s->enc_mode = get_bitrate_mode(avctx->bit_rate, avctx);
s->enc_bitrate = avctx->bit_rate;
}
- written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, data,
+ if (data) {
+ if (avctx->frame_size < 160) {
+ flush_buf = av_mallocz(160 * sizeof(*flush_buf));
+ if (!flush_buf)
+ return AVERROR(ENOMEM);
+ memcpy(flush_buf, samples, avctx->frame_size * sizeof(*flush_buf));
+ samples = flush_buf;
+ if (avctx->frame_size < 110)
+ s->enc_last_frame = -1;
+ }
+ } else {
+ if (s->enc_last_frame < 0)
+ return 0;
+ flush_buf = av_mallocz(160 * sizeof(*flush_buf));
+ if (!flush_buf)
+ return AVERROR(ENOMEM);
+ samples = flush_buf;
+ s->enc_last_frame = -1;
+ }
+
+ written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, samples,
frame, 0);
av_dlog(avctx, "amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",
written, s->enc_mode, frame[0]);
+ av_freep(&flush_buf);
return written;
}
@@ -249,6 +274,7 @@ AVCodec ff_libopencore_amrnb_encoder = {
.init = amr_nb_encode_init,
.encode = amr_nb_encode_frame,
.close = amr_nb_encode_close,
+ .capabilities = CODEC_CAP_DELAY | CODEC_CAP_SMALL_LAST_FRAME,
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"),
.priv_class = &class,