22#include "config_components.h"
37#if CONFIG_LIBOPENCORE_AMRNB_DECODER || CONFIG_LIBOPENCORE_AMRWB_DECODER
57#if CONFIG_LIBOPENCORE_AMRNB
59#include <opencore-amrnb/interf_dec.h>
60#include <opencore-amrnb/interf_enc.h>
73#if CONFIG_LIBOPENCORE_AMRNB_DECODER
79 if ((ret = amr_decode_fix_avctx(avctx)) < 0)
82 s->dec_state = Decoder_Interface_init();
95 Decoder_Interface_exit(
s->dec_state);
101 int *got_frame_ptr,
AVPacket *avpkt)
103 const uint8_t *buf = avpkt->
data;
104 int buf_size = avpkt->
size;
106 static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
108 int packet_size, ret;
110 ff_dlog(avctx,
"amr_decode_frame buf=%p buf_size=%d frame_count=%"PRId64
"!!\n",
114 frame->nb_samples = 160;
118 dec_mode = (buf[0] >> 3) & 0x000F;
119 packet_size = block_size[dec_mode] + 1;
121 if (packet_size > buf_size) {
123 buf_size, packet_size);
127 ff_dlog(avctx,
"packet_size=%d buf= 0x%"PRIx8
" %"PRIx8
" %"PRIx8
" %"PRIx8
"\n",
128 packet_size, buf[0], buf[1], buf[2], buf[3]);
130 Decoder_Interface_Decode(
s->dec_state, buf, (
short *)
frame->data[0], 0);
138 .p.name =
"libopencore_amrnb",
144 .
init = amr_nb_decode_init,
145 .
close = amr_nb_decode_close,
151#if CONFIG_LIBOPENCORE_AMRNB_ENCODER
153typedef struct AMR_bitrates {
159static int get_bitrate_mode(
int bitrate,
void *log_ctx)
162 static const AMR_bitrates
rates[] = {
163 { 4750, MR475 }, { 5150, MR515 }, { 5900, MR59 }, { 6700, MR67 },
164 { 7400, MR74 }, { 7950, MR795 }, { 10200, MR102 }, { 12200, MR122 }
166 int i, best = -1, min_diff = 0;
169 for (
i = 0;
i < 8;
i++) {
178 snprintf(log_buf,
sizeof(log_buf),
"bitrate not supported: use one of ");
179 for (
i = 0;
i < 8;
i++)
181 av_strlcatf(log_buf,
sizeof(log_buf),
"using %.2fk",
rates[best].rate / 1000.f);
192static const AVClass amrnb_class = {
193 .class_name =
"libopencore_amrnb",
217 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);
243 int16_t *flush_buf =
NULL;
244 const int16_t *samples =
frame ? (
const int16_t *)
frame->data[0] :
NULL;
247 s->enc_mode = get_bitrate_mode(avctx->
bit_rate, avctx);
259 memcpy(flush_buf, samples,
frame->nb_samples *
sizeof(*flush_buf));
262 s->enc_last_frame = -1;
269 if (
s->enc_last_frame < 0)
275 s->enc_last_frame = -1;
278 written = Encoder_Interface_Encode(
s->enc_state,
s->enc_mode, samples,
280 ff_dlog(avctx,
"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",
281 written,
s->enc_mode, avpkt->
data[0]);
288 avpkt->
size = written;
295 .p.name =
"libopencore_amrnb",
303 .
init = amr_nb_encode_init,
305 .close = amr_nb_encode_close,
307 .p.priv_class = &amrnb_class,
314#if CONFIG_LIBOPENCORE_AMRWB_DECODER
316#include <opencore-amrwb/dec_if.h>
317#include <opencore-amrwb/if_rom.h>
328 if ((ret = amr_decode_fix_avctx(avctx)) < 0)
331 s->state = D_IF_init();
337 int *got_frame_ptr,
AVPacket *avpkt)
339 const uint8_t *buf = avpkt->
data;
340 int buf_size = avpkt->
size;
344 static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
347 frame->nb_samples = 320;
351 mode = (buf[0] >> 3) & 0x000F;
352 packet_size = block_size[
mode];
354 if (packet_size > buf_size) {
356 buf_size, packet_size + 1);
364 D_IF_decode(
s->state, buf, (
short *)
frame->data[0], _good_frame);
380 .p.name =
"libopencore_amrwb",
385 .p.wrapper_name =
"libopencore_amrwb",
388 .
init = amr_wb_decode_init,
389 .
close = amr_wb_decode_close,
const FFCodec ff_libopencore_amrnb_encoder
const FFCodec ff_libopencore_amrnb_decoder
const FFCodec ff_libopencore_amrwb_decoder
Mode
Frame type (Table 1a in 3GPP TS 26.101)
static av_cold void close(AVCodecParserContext *s)
av_cold void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
int ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, AVPacket *pkt)
Remove frame(s) from the queue.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
Libavcodec external API header.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_DECODE_CB(func)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
common internal and external API header
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
int(* init)(AVBSFContext *ctx)
mode
Use these values in ebur128_init (or'ed).
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
#define AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
#define AV_CHANNEL_LAYOUT_MONO
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define LIBAVUTIL_VERSION_INT
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static const AVClass av_class
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
int64_t frame_num
Frame counter, set by libavcodec.
int64_t bit_rate
the average bitrate
int initial_padding
Audio only.
int sample_rate
samples per second
int frame_size
Number of samples per channel in an audio frame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.