[FFmpeg-cvslog] libgsmenc: use AVCodec.encode2()
Justin Ruggles
git at videolan.org
Thu Mar 22 01:33:57 CET 2012
ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Wed Feb 15 19:20:30 2012 -0500| [1987a940b730415e39c6568ea2dbab02aa12742b] | committer: Justin Ruggles
libgsmenc: use AVCodec.encode2()
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1987a940b730415e39c6568ea2dbab02aa12742b
---
libavcodec/libgsm.c | 34 ++++++++++++++++++++++++----------
1 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/libavcodec/libgsm.c b/libavcodec/libgsm.c
index fb7b196..8b0a13b 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"),
More information about the ffmpeg-cvslog
mailing list