diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2012-02-15 19:20:30 -0500 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2012-03-20 18:55:39 -0400 |
commit | 1987a940b730415e39c6568ea2dbab02aa12742b (patch) | |
tree | efa1944a1f02194630177e32aabe79d17d3134bc /libavcodec/libgsm.c | |
parent | d1afb2f94e7070cca7c62dcbc258efc85f267249 (diff) | |
download | ffmpeg-1987a940b730415e39c6568ea2dbab02aa12742b.tar.gz |
libgsmenc: use AVCodec.encode2()
Diffstat (limited to 'libavcodec/libgsm.c')
-rw-r--r-- | libavcodec/libgsm.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/libavcodec/libgsm.c b/libavcodec/libgsm.c index fb7b196022..8b0a13ba1a 100644 --- a/libavcodec/libgsm.c +++ b/libavcodec/libgsm.c @@ -30,6 +30,7 @@ #include <gsm/gsm.h> #include "avcodec.h" +#include "internal.h" #include "gsm.h" static av_cold int libgsm_encode_init(AVCodecContext *avctx) { @@ -69,36 +70,49 @@ static av_cold int libgsm_encode_init(AVCodecContext *avctx) { } } +#if FF_API_OLD_ENCODE_AUDIO avctx->coded_frame= avcodec_alloc_frame(); if (!avctx->coded_frame) { gsm_destroy(avctx->priv_data); return AVERROR(ENOMEM); } +#endif return 0; } static av_cold int libgsm_encode_close(AVCodecContext *avctx) { +#if FF_API_OLD_ENCODE_AUDIO av_freep(&avctx->coded_frame); +#endif gsm_destroy(avctx->priv_data); avctx->priv_data = NULL; return 0; } -static int libgsm_encode_frame(AVCodecContext *avctx, - unsigned char *frame, int buf_size, void *data) { - // we need a full block - if(buf_size < avctx->block_align) return 0; +static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, + const AVFrame *frame, int *got_packet_ptr) +{ + int ret; + gsm_signal *samples = (gsm_signal *)frame->data[0]; + struct gsm_state *state = avctx->priv_data; + + if ((ret = ff_alloc_packet(avpkt, avctx->block_align))) { + av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + return ret; + } switch(avctx->codec_id) { case CODEC_ID_GSM: - gsm_encode(avctx->priv_data,data,frame); + gsm_encode(state, samples, avpkt->data); break; case CODEC_ID_GSM_MS: - gsm_encode(avctx->priv_data,data,frame); - gsm_encode(avctx->priv_data,((short*)data)+GSM_FRAME_SIZE,frame+32); + gsm_encode(state, samples, avpkt->data); + gsm_encode(state, samples + GSM_FRAME_SIZE, avpkt->data + 32); } - return avctx->block_align; + + *got_packet_ptr = 1; + return 0; } @@ -107,7 +121,7 @@ AVCodec ff_libgsm_encoder = { .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_GSM, .init = libgsm_encode_init, - .encode = libgsm_encode_frame, + .encode2 = libgsm_encode_frame, .close = libgsm_encode_close, .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"), @@ -118,7 +132,7 @@ AVCodec ff_libgsm_ms_encoder = { .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_GSM_MS, .init = libgsm_encode_init, - .encode = libgsm_encode_frame, + .encode2 = libgsm_encode_frame, .close = libgsm_encode_close, .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"), |