50 #if CONFIG_LIBOPENCORE_AMRNB 52 #include <opencore-amrnb/interf_dec.h> 53 #include <opencore-amrnb/interf_enc.h> 66 #if CONFIG_LIBOPENCORE_AMRNB_DECODER 75 s->dec_state = Decoder_Interface_init();
88 Decoder_Interface_exit(s->dec_state);
98 int buf_size = avpkt->
size;
100 static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
102 int packet_size, ret;
104 ff_dlog(avctx,
"amr_decode_frame buf=%p buf_size=%d frame_count=%d!!\n",
112 dec_mode = (buf[0] >> 3) & 0x000F;
113 packet_size = block_size[dec_mode] + 1;
115 if (packet_size > buf_size) {
117 buf_size, packet_size);
121 ff_dlog(avctx,
"packet_size=%d buf= 0x%"PRIx8
" %"PRIx8
" %"PRIx8
" %"PRIx8
"\n",
122 packet_size, buf[0], buf[1], buf[2], buf[3]);
124 Decoder_Interface_Decode(s->dec_state, buf, (
short *)frame->
data[0], 0);
132 .
name =
"libopencore_amrnb",
137 .
init = amr_nb_decode_init,
138 .close = amr_nb_decode_close,
139 .
decode = amr_nb_decode_frame,
144 #if CONFIG_LIBOPENCORE_AMRNB_ENCODER 146 typedef struct AMR_bitrates {
152 static int get_bitrate_mode(
int bitrate,
void *log_ctx)
155 static const AMR_bitrates
rates[] = {
156 { 4750, MR475 }, { 5150, MR515 }, { 5900, MR59 }, { 6700, MR67 },
157 { 7400, MR74 }, { 7950, MR795 }, { 10200, MR102 }, { 12200, MR122 }
159 int i, best = -1, min_diff = 0;
162 for (i = 0; i < 8; i++) {
163 if (rates[i].rate == bitrate)
164 return rates[i].mode;
165 if (best < 0 || abs(rates[i].rate - bitrate) < min_diff) {
167 min_diff = abs(rates[i].rate - bitrate);
171 snprintf(log_buf,
sizeof(log_buf),
"bitrate not supported: use one of ");
172 for (i = 0; i < 8; i++)
173 av_strlcatf(log_buf,
sizeof(log_buf),
"%.2fk, ", rates[i].rate / 1000.f);
174 av_strlcatf(log_buf,
sizeof(log_buf),
"using %.2fk", rates[best].rate / 1000.f);
185 static const AVClass amrnb_class = {
210 s->enc_state = Encoder_Interface_init(s->enc_dtx);
216 s->enc_mode = get_bitrate_mode(avctx->
bit_rate, avctx);
226 Encoder_Interface_exit(s->enc_state);
236 int16_t *flush_buf =
NULL;
237 const int16_t *samples = frame ? (
const int16_t *)frame->
data[0] :
NULL;
240 s->enc_mode = get_bitrate_mode(avctx->
bit_rate, avctx);
252 memcpy(flush_buf, samples, frame->
nb_samples *
sizeof(*flush_buf));
255 s->enc_last_frame = -1;
262 if (s->enc_last_frame < 0)
268 s->enc_last_frame = -1;
271 written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, samples,
273 ff_dlog(avctx,
"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",
274 written, s->enc_mode, avpkt->
data[0]);
280 avpkt->
size = written;
287 .
name =
"libopencore_amrnb",
292 .
init = amr_nb_encode_init,
293 .encode2 = amr_nb_encode_frame,
294 .close = amr_nb_encode_close,
298 .priv_class = &amrnb_class,
305 #if CONFIG_LIBOPENCORE_AMRWB_DECODER 307 #include <opencore-amrwb/dec_if.h> 308 #include <opencore-amrwb/if_rom.h> 322 s->
state = D_IF_init();
328 int *got_frame_ptr,
AVPacket *avpkt)
332 int buf_size = avpkt->
size;
336 static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
343 mode = (buf[0] >> 3) & 0x000F;
344 packet_size = block_size[
mode];
346 if (packet_size > buf_size) {
348 buf_size, packet_size + 1);
356 D_IF_decode(s->
state, buf, (
short *)frame->
data[0], _good_frame);
372 .
name =
"libopencore_amrwb",
377 .
init = amr_wb_decode_init,
378 .close = amr_wb_decode_close,
379 .
decode = amr_wb_decode_frame,
381 .wrapper_name =
"libopencore_amrwb",
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
#define AV_OPT_FLAG_AUDIO_PARAM
const char * av_default_item_name(void *ptr)
Return the context name.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
enum AVSampleFormat sample_fmt
audio sample format
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Mode
Frame type (Table 1a in 3GPP TS 26.101)
AMRNBFrame frame
decoded AMR parameters (lsf coefficients, codebook indexes, etc)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int amr_decode_fix_avctx(AVCodecContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int initial_padding
Audio only.
const char * name
Name of the codec implementation.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
uint64_t channel_layout
Audio channel layout.
audio channel layout utility functions
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
AVCodec ff_libopencore_amrnb_decoder
AVCodec ff_libopencore_amrnb_encoder
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int frame_size
Number of samples per channel in an audio frame.
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
int sample_rate
samples per second
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static const AVClass av_class
Describe the class of an AVClass context structure.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const OptionDef options[]
AVCodec ff_libopencore_amrwb_decoder
common internal api header.
common internal and external API header
int channels
number of audio channels
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
static enum AVSampleFormat sample_fmts[]
int frame_number
Frame counter, set by libavcodec.
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
mode
Use these values in ebur128_init (or'ed).
int nb_samples
number of audio samples (per channel) described by this frame
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().