22
22
#include <vo-amrwbenc/enc_if.h>
25
26
#include "libavutil/avstring.h"
27
#include "libavutil/internal.h"
28
#include "libavutil/mem.h"
26
29
#include "libavutil/opt.h"
33
#define MAX_PACKET_SIZE (1 + (477 + 7) / 8)
28
35
typedef struct AMRWBContext {
36
43
static const AVOption options[] = {
37
{ "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRWBContext, allow_dtx), AV_OPT_TYPE_INT, { 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
44
{ "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRWBContext, allow_dtx), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
105
static int amr_wb_encode_frame(AVCodecContext *avctx,
106
unsigned char *frame/*out*/,
107
int buf_size, void *data/*in*/)
117
static int amr_wb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
118
const AVFrame *frame, int *got_packet_ptr)
109
120
AMRWBContext *s = avctx->priv_data;
121
const int16_t *samples = (const int16_t *)frame->data[0];
124
if ((ret = ff_alloc_packet(avpkt, MAX_PACKET_SIZE))) {
125
av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
112
129
if (s->last_bitrate != avctx->bit_rate) {
113
130
s->mode = get_wb_bitrate_mode(avctx->bit_rate, avctx);
114
131
s->last_bitrate = avctx->bit_rate;
116
size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx);
133
size = E_IF_encode(s->state, s->mode, samples, avpkt->data, s->allow_dtx);
134
if (size <= 0 || size > MAX_PACKET_SIZE) {
135
av_log(avctx, AV_LOG_ERROR, "Error encoding frame\n");
136
return AVERROR(EINVAL);
139
if (frame->pts != AV_NOPTS_VALUE)
140
avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
120
147
AVCodec ff_libvo_amrwbenc_encoder = {
121
148
.name = "libvo_amrwbenc",
122
149
.type = AVMEDIA_TYPE_AUDIO,
123
.id = CODEC_ID_AMR_WB,
150
.id = AV_CODEC_ID_AMR_WB,
124
151
.priv_data_size = sizeof(AMRWBContext),
125
152
.init = amr_wb_encode_init,
126
.encode = amr_wb_encode_frame,
153
.encode2 = amr_wb_encode_frame,
127
154
.close = amr_wb_encode_close,
128
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
129
.long_name = NULL_IF_CONFIG_SMALL("Android VisualOn Adaptive Multi-Rate "
131
.priv_class = &class,
155
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
156
AV_SAMPLE_FMT_NONE },
157
.long_name = NULL_IF_CONFIG_SMALL("Android VisualOn AMR-WB "
158
"(Adaptive Multi-Rate Wide-Band)"),
159
.priv_class = &class,