1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

libgsmenc: use AVCodec.encode2()

This commit is contained in:
Justin Ruggles 2012-02-15 19:20:30 -05:00
parent d1afb2f94e
commit 1987a940b7

View File

@ -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"),