48 #if CONFIG_LIBOPENCORE_AMRNB
50 #include <opencore-amrnb/interf_dec.h>
51 #include <opencore-amrnb/interf_enc.h>
65 #if CONFIG_LIBOPENCORE_AMRNB_DECODER
74 s->dec_state = Decoder_Interface_init();
90 Decoder_Interface_exit(s->dec_state);
99 int buf_size = avpkt->
size;
101 static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
103 int packet_size, ret;
105 av_dlog(avctx,
"amr_decode_frame buf=%p buf_size=%d frame_count=%d!!\n",
109 s->
frame.nb_samples = 160;
115 dec_mode = (buf[0] >> 3) & 0x000F;
116 packet_size = block_size[dec_mode] + 1;
118 if (packet_size > buf_size) {
120 buf_size, packet_size);
124 av_dlog(avctx,
"packet_size=%d buf= 0x%X %X %X %X\n",
125 packet_size, buf[0], buf[1], buf[2], buf[3]);
127 Decoder_Interface_Decode(s->dec_state, buf, (
short *)s->
frame.data[0], 0);
135 AVCodec ff_libopencore_amrnb_decoder = {
136 .
name =
"libopencore_amrnb",
140 .
init = amr_nb_decode_init,
141 .
close = amr_nb_decode_close,
142 .
decode = amr_nb_decode_frame,
148 #if CONFIG_LIBOPENCORE_AMRNB_ENCODER
150 typedef struct AMR_bitrates {
156 static int get_bitrate_mode(
int bitrate,
void *log_ctx)
159 static const AMR_bitrates
rates[] = {
160 { 4750, MR475 }, { 5150, MR515 }, { 5900, MR59 }, { 6700, MR67 },
161 { 7400, MR74 }, { 7950, MR795 }, { 10200, MR102 }, { 12200, MR122 }
163 int i, best = -1, min_diff = 0;
166 for (i = 0; i < 8; i++) {
167 if (rates[i].rate == bitrate)
168 return rates[i].mode;
169 if (best < 0 || abs(rates[i].rate - bitrate) < min_diff) {
171 min_diff = abs(rates[i].rate - bitrate);
175 snprintf(log_buf,
sizeof(log_buf),
"bitrate not supported: use one of ");
176 for (i = 0; i < 8; i++)
177 av_strlcatf(log_buf,
sizeof(log_buf),
"%.2fk, ", rates[i].rate / 1000.f);
178 av_strlcatf(log_buf,
sizeof(log_buf),
"using %.2fk", rates[best].rate / 1000.f);
210 #if FF_API_OLD_ENCODE_AUDIO
216 s->enc_state = Encoder_Interface_init(s->enc_dtx);
223 s->enc_mode = get_bitrate_mode(avctx->
bit_rate, avctx);
233 Encoder_Interface_exit(s->enc_state);
235 #if FF_API_OLD_ENCODE_AUDIO
246 int16_t *flush_buf =
NULL;
247 const int16_t *
samples = frame ? (
const int16_t *)frame->
data[0] :
NULL;
250 s->enc_mode = get_bitrate_mode(avctx->
bit_rate, avctx);
262 memcpy(flush_buf, samples, frame->
nb_samples *
sizeof(*flush_buf));
265 s->enc_last_frame = -1;
272 if (s->enc_last_frame < 0)
278 s->enc_last_frame = -1;
281 written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, samples,
283 av_dlog(avctx,
"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",
284 written, s->enc_mode, avpkt->
data[0]);
290 avpkt->
size = written;
296 AVCodec ff_libopencore_amrnb_encoder = {
297 .
name =
"libopencore_amrnb",
301 .
init = amr_nb_encode_init,
302 .encode2 = amr_nb_encode_frame,
303 .
close = amr_nb_encode_close,
308 .priv_class = &
class,
315 #if CONFIG_LIBOPENCORE_AMRWB_DECODER
317 #include <opencore-amrwb/dec_if.h>
318 #include <opencore-amrwb/if_rom.h>
333 s->
state = D_IF_init();
342 int *got_frame_ptr,
AVPacket *avpkt)
345 int buf_size = avpkt->
size;
349 static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
352 s->
frame.nb_samples = 320;
358 mode = (buf[0] >> 3) & 0x000F;
359 packet_size = block_size[
mode];
361 if (packet_size > buf_size) {
363 buf_size, packet_size + 1);
371 D_IF_decode(s->
state, buf, (
short *)s->
frame.data[0], _good_frame);
387 AVCodec ff_libopencore_amrwb_decoder = {
388 .
name =
"libopencore_amrwb",
392 .
init = amr_wb_decode_init,
393 .
close = amr_wb_decode_close,
394 .
decode = amr_wb_decode_frame,