libgsmenc: use AVCodec.encode2()
This commit is contained in:
parent
d1afb2f94e
commit
1987a940b7
@ -30,6 +30,7 @@
|
|||||||
#include <gsm/gsm.h>
|
#include <gsm/gsm.h>
|
||||||
|
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
|
#include "internal.h"
|
||||||
#include "gsm.h"
|
#include "gsm.h"
|
||||||
|
|
||||||
static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
|
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();
|
avctx->coded_frame= avcodec_alloc_frame();
|
||||||
if (!avctx->coded_frame) {
|
if (!avctx->coded_frame) {
|
||||||
gsm_destroy(avctx->priv_data);
|
gsm_destroy(avctx->priv_data);
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int libgsm_encode_close(AVCodecContext *avctx) {
|
static av_cold int libgsm_encode_close(AVCodecContext *avctx) {
|
||||||
|
#if FF_API_OLD_ENCODE_AUDIO
|
||||||
av_freep(&avctx->coded_frame);
|
av_freep(&avctx->coded_frame);
|
||||||
|
#endif
|
||||||
gsm_destroy(avctx->priv_data);
|
gsm_destroy(avctx->priv_data);
|
||||||
avctx->priv_data = NULL;
|
avctx->priv_data = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int libgsm_encode_frame(AVCodecContext *avctx,
|
static int libgsm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
|
||||||
unsigned char *frame, int buf_size, void *data) {
|
const AVFrame *frame, int *got_packet_ptr)
|
||||||
// we need a full block
|
{
|
||||||
if(buf_size < avctx->block_align) return 0;
|
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) {
|
switch(avctx->codec_id) {
|
||||||
case CODEC_ID_GSM:
|
case CODEC_ID_GSM:
|
||||||
gsm_encode(avctx->priv_data,data,frame);
|
gsm_encode(state, samples, avpkt->data);
|
||||||
break;
|
break;
|
||||||
case CODEC_ID_GSM_MS:
|
case CODEC_ID_GSM_MS:
|
||||||
gsm_encode(avctx->priv_data,data,frame);
|
gsm_encode(state, samples, avpkt->data);
|
||||||
gsm_encode(avctx->priv_data,((short*)data)+GSM_FRAME_SIZE,frame+32);
|
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,
|
.type = AVMEDIA_TYPE_AUDIO,
|
||||||
.id = CODEC_ID_GSM,
|
.id = CODEC_ID_GSM,
|
||||||
.init = libgsm_encode_init,
|
.init = libgsm_encode_init,
|
||||||
.encode = libgsm_encode_frame,
|
.encode2 = libgsm_encode_frame,
|
||||||
.close = libgsm_encode_close,
|
.close = libgsm_encode_close,
|
||||||
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
|
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"),
|
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"),
|
||||||
@ -118,7 +132,7 @@ AVCodec ff_libgsm_ms_encoder = {
|
|||||||
.type = AVMEDIA_TYPE_AUDIO,
|
.type = AVMEDIA_TYPE_AUDIO,
|
||||||
.id = CODEC_ID_GSM_MS,
|
.id = CODEC_ID_GSM_MS,
|
||||||
.init = libgsm_encode_init,
|
.init = libgsm_encode_init,
|
||||||
.encode = libgsm_encode_frame,
|
.encode2 = libgsm_encode_frame,
|
||||||
.close = libgsm_encode_close,
|
.close = libgsm_encode_close,
|
||||||
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
|
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
|
.long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user