Go to the documentation of this file.
22 #include "config_components.h"
36 #if CONFIG_LIBOPENCORE_AMRNB_DECODER || CONFIG_LIBOPENCORE_AMRWB_DECODER
56 #if CONFIG_LIBOPENCORE_AMRNB
58 #include <opencore-amrnb/interf_dec.h>
59 #include <opencore-amrnb/interf_enc.h>
72 #if CONFIG_LIBOPENCORE_AMRNB_DECODER
78 if ((
ret = amr_decode_fix_avctx(avctx)) < 0)
81 s->dec_state = Decoder_Interface_init();
94 Decoder_Interface_exit(
s->dec_state);
100 int *got_frame_ptr,
AVPacket *avpkt)
102 const uint8_t *buf = avpkt->
data;
103 int buf_size = avpkt->
size;
105 static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
107 int packet_size,
ret;
109 ff_dlog(avctx,
"amr_decode_frame buf=%p buf_size=%d frame_count=%d!!\n",
113 frame->nb_samples = 160;
117 dec_mode = (buf[0] >> 3) & 0x000F;
118 packet_size = block_size[dec_mode] + 1;
120 if (packet_size > buf_size) {
122 buf_size, packet_size);
126 ff_dlog(avctx,
"packet_size=%d buf= 0x%"PRIx8
" %"PRIx8
" %"PRIx8
" %"PRIx8
"\n",
127 packet_size, buf[0], buf[1], buf[2], buf[3]);
129 Decoder_Interface_Decode(
s->dec_state, buf, (
short *)
frame->data[0], 0);
137 .
p.
name =
"libopencore_amrnb",
142 .
init = amr_nb_decode_init,
143 .close = amr_nb_decode_close,
149 #if CONFIG_LIBOPENCORE_AMRNB_ENCODER
151 typedef struct AMR_bitrates {
157 static int get_bitrate_mode(
int bitrate,
void *log_ctx)
160 static const AMR_bitrates
rates[] = {
161 { 4750, MR475 }, { 5150, MR515 }, { 5900, MR59 }, { 6700, MR67 },
162 { 7400, MR74 }, { 7950, MR795 }, { 10200, MR102 }, { 12200, MR122 }
164 int i, best = -1, min_diff = 0;
167 for (
i = 0;
i < 8;
i++) {
176 snprintf(log_buf,
sizeof(log_buf),
"bitrate not supported: use one of ");
177 for (
i = 0;
i < 8;
i++)
190 static const AVClass amrnb_class = {
215 s->enc_state = Encoder_Interface_init(
s->enc_dtx);
221 s->enc_mode = get_bitrate_mode(avctx->
bit_rate, avctx);
231 Encoder_Interface_exit(
s->enc_state);
241 int16_t *flush_buf =
NULL;
245 s->enc_mode = get_bitrate_mode(avctx->
bit_rate, avctx);
257 memcpy(flush_buf,
samples,
frame->nb_samples *
sizeof(*flush_buf));
260 s->enc_last_frame = -1;
267 if (
s->enc_last_frame < 0)
273 s->enc_last_frame = -1;
276 written = Encoder_Interface_Encode(
s->enc_state,
s->enc_mode,
samples,
278 ff_dlog(avctx,
"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",
279 written,
s->enc_mode, avpkt->
data[0]);
285 avpkt->
size = written;
292 .
p.
name =
"libopencore_amrnb",
297 .
init = amr_nb_encode_init,
299 .close = amr_nb_encode_close,
303 .p.priv_class = &amrnb_class,
310 #if CONFIG_LIBOPENCORE_AMRWB_DECODER
312 #include <opencore-amrwb/dec_if.h>
313 #include <opencore-amrwb/if_rom.h>
324 if ((
ret = amr_decode_fix_avctx(avctx)) < 0)
327 s->state = D_IF_init();
333 int *got_frame_ptr,
AVPacket *avpkt)
335 const uint8_t *buf = avpkt->
data;
336 int buf_size = avpkt->
size;
340 static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
343 frame->nb_samples = 320;
347 mode = (buf[0] >> 3) & 0x000F;
348 packet_size = block_size[
mode];
350 if (packet_size > buf_size) {
352 buf_size, packet_size + 1);
360 D_IF_decode(
s->state, buf, (
short *)
frame->data[0], _good_frame);
376 .
p.
name =
"libopencore_amrwb",
381 .p.wrapper_name =
"libopencore_amrwb",
383 .
init = amr_wb_decode_init,
384 .close = amr_wb_decode_close,
int frame_size
Number of samples per channel in an audio frame.
#define AV_LOG_WARNING
Something somehow does not look correct.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
int sample_rate
samples per second
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
This structure describes decoded (raw) audio or video data.
#define AV_CHANNEL_LAYOUT_MONO
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int nb_channels
Number of channels in this layout.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
int initial_padding
Audio only.
const FFCodec ff_libopencore_amrnb_decoder
#define FF_CODEC_ENCODE_CB(func)
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Mode
Frame type (Table 1a in 3GPP TS 26.101)
#define FF_CODEC_DECODE_CB(func)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
const FFCodec ff_libopencore_amrnb_encoder
static const AVClass av_class
#define AV_OPT_FLAG_AUDIO_PARAM
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int64_t bit_rate
the average bitrate
const char * av_default_item_name(void *ptr)
Return the context name.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
const OptionDef options[]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const FFCodec ff_libopencore_amrwb_decoder
An AVChannelLayout holds information about the channel layout of audio data.
enum AVSampleFormat sample_fmt
audio sample format
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Name of the codec implementation.
void * av_calloc(size_t nmemb, size_t size)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
main external API structure.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Filter the word “frame” indicates either a video frame or a group of audio samples
int frame_number
Frame counter, set by libavcodec.
This structure stores compressed data.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.