FFmpeg
libopencore-amr.c
Go to the documentation of this file.
1 /*
2  * AMR Audio decoder stub
3  * Copyright (c) 2003 The FFmpeg project
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config_components.h"
23 
24 #include <inttypes.h>
25 
26 #include "libavutil/avstring.h"
28 #include "libavutil/common.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/opt.h"
31 #include "avcodec.h"
32 #include "audio_frame_queue.h"
33 #include "codec_internal.h"
34 #include "decode.h"
35 #include "encode.h"
36 
37 #if CONFIG_LIBOPENCORE_AMRNB_DECODER || CONFIG_LIBOPENCORE_AMRWB_DECODER
38 static int amr_decode_fix_avctx(AVCodecContext *avctx)
39 {
40  const int is_amr_wb = 1 + (avctx->codec_id == AV_CODEC_ID_AMR_WB);
41 
42  if (!avctx->sample_rate)
43  avctx->sample_rate = 8000 * is_amr_wb;
44 
45  if (avctx->ch_layout.nb_channels > 1) {
46  avpriv_report_missing_feature(avctx, "multi-channel AMR");
47  return AVERROR_PATCHWELCOME;
48  }
49 
53  return 0;
54 }
55 #endif
56 
57 #if CONFIG_LIBOPENCORE_AMRNB
58 
59 #include <opencore-amrnb/interf_dec.h>
60 #include <opencore-amrnb/interf_enc.h>
61 
62 typedef struct AMRContext {
64  void *dec_state;
65  void *enc_state;
66  int enc_bitrate;
67  int enc_mode;
68  int enc_dtx;
69  int enc_last_frame;
70  AudioFrameQueue afq;
71 } AMRContext;
72 
73 #if CONFIG_LIBOPENCORE_AMRNB_DECODER
74 static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
75 {
76  AMRContext *s = avctx->priv_data;
77  int ret;
78 
79  if ((ret = amr_decode_fix_avctx(avctx)) < 0)
80  return ret;
81 
82  s->dec_state = Decoder_Interface_init();
83  if (!s->dec_state) {
84  av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\n");
85  return -1;
86  }
87 
88  return 0;
89 }
90 
91 static av_cold int amr_nb_decode_close(AVCodecContext *avctx)
92 {
93  AMRContext *s = avctx->priv_data;
94 
95  Decoder_Interface_exit(s->dec_state);
96 
97  return 0;
98 }
99 
100 static int amr_nb_decode_frame(AVCodecContext *avctx, AVFrame *frame,
101  int *got_frame_ptr, AVPacket *avpkt)
102 {
103  const uint8_t *buf = avpkt->data;
104  int buf_size = avpkt->size;
105  AMRContext *s = avctx->priv_data;
106  static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
107  enum Mode dec_mode;
108  int packet_size, ret;
109 
110  ff_dlog(avctx, "amr_decode_frame buf=%p buf_size=%d frame_count=%"PRId64"!!\n",
111  buf, buf_size, avctx->frame_num);
112 
113  /* get output buffer */
114  frame->nb_samples = 160;
115  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
116  return ret;
117 
118  dec_mode = (buf[0] >> 3) & 0x000F;
119  packet_size = block_size[dec_mode] + 1;
120 
121  if (packet_size > buf_size) {
122  av_log(avctx, AV_LOG_ERROR, "AMR frame too short (%d, should be %d)\n",
123  buf_size, packet_size);
124  return AVERROR_INVALIDDATA;
125  }
126 
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]);
129  /* call decoder */
130  Decoder_Interface_Decode(s->dec_state, buf, (short *)frame->data[0], 0);
131 
132  *got_frame_ptr = 1;
133 
134  return packet_size;
135 }
136 
138  .p.name = "libopencore_amrnb",
139  CODEC_LONG_NAME("OpenCORE AMR-NB (Adaptive Multi-Rate Narrow-Band)"),
140  .p.type = AVMEDIA_TYPE_AUDIO,
141  .p.id = AV_CODEC_ID_AMR_NB,
142  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE,
143  .priv_data_size = sizeof(AMRContext),
144  .init = amr_nb_decode_init,
145  .close = amr_nb_decode_close,
146  FF_CODEC_DECODE_CB(amr_nb_decode_frame),
147  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
148 };
149 #endif /* CONFIG_LIBOPENCORE_AMRNB_DECODER */
150 
151 #if CONFIG_LIBOPENCORE_AMRNB_ENCODER
152 /* Common code for fixed and float version*/
153 typedef struct AMR_bitrates {
154  int rate;
155  enum Mode mode;
156 } AMR_bitrates;
157 
158 /* Match desired bitrate */
159 static int get_bitrate_mode(int bitrate, void *log_ctx)
160 {
161  /* make the correspondence between bitrate and mode */
162  static const AMR_bitrates rates[] = {
163  { 4750, MR475 }, { 5150, MR515 }, { 5900, MR59 }, { 6700, MR67 },
164  { 7400, MR74 }, { 7950, MR795 }, { 10200, MR102 }, { 12200, MR122 }
165  };
166  int i, best = -1, min_diff = 0;
167  char log_buf[200];
168 
169  for (i = 0; i < 8; i++) {
170  if (rates[i].rate == bitrate)
171  return rates[i].mode;
172  if (best < 0 || abs(rates[i].rate - bitrate) < min_diff) {
173  best = i;
174  min_diff = abs(rates[i].rate - bitrate);
175  }
176  }
177  /* no bitrate matching exactly, log a warning */
178  snprintf(log_buf, sizeof(log_buf), "bitrate not supported: use one of ");
179  for (i = 0; i < 8; i++)
180  av_strlcatf(log_buf, sizeof(log_buf), "%.2fk, ", rates[i].rate / 1000.f);
181  av_strlcatf(log_buf, sizeof(log_buf), "using %.2fk", rates[best].rate / 1000.f);
182  av_log(log_ctx, AV_LOG_WARNING, "%s\n", log_buf);
183 
184  return best;
185 }
186 
187 static const AVOption options[] = {
188  { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRContext, enc_dtx), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
189  { NULL }
190 };
191 
192 static const AVClass amrnb_class = {
193  .class_name = "libopencore_amrnb",
194  .item_name = av_default_item_name,
195  .option = options,
196  .version = LIBAVUTIL_VERSION_INT,
197 };
198 
199 static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
200 {
201  AMRContext *s = avctx->priv_data;
202 
203  if (avctx->sample_rate != 8000 && avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
204  av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
205  return AVERROR(ENOSYS);
206  }
207 
208  if (avctx->ch_layout.nb_channels != 1) {
209  av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
210  return AVERROR(ENOSYS);
211  }
212 
213  avctx->frame_size = 160;
214  avctx->initial_padding = 50;
215  ff_af_queue_init(avctx, &s->afq);
216 
217  s->enc_state = Encoder_Interface_init(s->enc_dtx);
218  if (!s->enc_state) {
219  av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n");
220  return -1;
221  }
222 
223  s->enc_mode = get_bitrate_mode(avctx->bit_rate, avctx);
224  s->enc_bitrate = avctx->bit_rate;
225 
226  return 0;
227 }
228 
229 static av_cold int amr_nb_encode_close(AVCodecContext *avctx)
230 {
231  AMRContext *s = avctx->priv_data;
232 
233  Encoder_Interface_exit(s->enc_state);
234  ff_af_queue_close(&s->afq);
235  return 0;
236 }
237 
238 static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
239  const AVFrame *frame, int *got_packet_ptr)
240 {
241  AMRContext *s = avctx->priv_data;
242  int written, ret;
243  int16_t *flush_buf = NULL;
244  const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;
245 
246  if (s->enc_bitrate != avctx->bit_rate) {
247  s->enc_mode = get_bitrate_mode(avctx->bit_rate, avctx);
248  s->enc_bitrate = avctx->bit_rate;
249  }
250 
251  if ((ret = ff_alloc_packet(avctx, avpkt, 32)) < 0)
252  return ret;
253 
254  if (frame) {
255  if (frame->nb_samples < avctx->frame_size) {
256  flush_buf = av_calloc(avctx->frame_size, sizeof(*flush_buf));
257  if (!flush_buf)
258  return AVERROR(ENOMEM);
259  memcpy(flush_buf, samples, frame->nb_samples * sizeof(*flush_buf));
260  samples = flush_buf;
261  if (frame->nb_samples < avctx->frame_size - avctx->initial_padding)
262  s->enc_last_frame = -1;
263  }
264  if ((ret = ff_af_queue_add(&s->afq, frame)) < 0) {
265  av_freep(&flush_buf);
266  return ret;
267  }
268  } else {
269  if (s->enc_last_frame < 0)
270  return 0;
271  flush_buf = av_calloc(avctx->frame_size, sizeof(*flush_buf));
272  if (!flush_buf)
273  return AVERROR(ENOMEM);
274  samples = flush_buf;
275  s->enc_last_frame = -1;
276  }
277 
278  written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, samples,
279  avpkt->data, 0);
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]);
282 
283  /* Get the next frame pts/duration */
284  ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,
285  &avpkt->duration);
286 
287  avpkt->size = written;
288  *got_packet_ptr = 1;
289  av_freep(&flush_buf);
290  return 0;
291 }
292 
294  .p.name = "libopencore_amrnb",
295  CODEC_LONG_NAME("OpenCORE AMR-NB (Adaptive Multi-Rate Narrow-Band)"),
296  .p.type = AVMEDIA_TYPE_AUDIO,
297  .p.id = AV_CODEC_ID_AMR_NB,
298  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
300  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE,
301  .priv_data_size = sizeof(AMRContext),
302  .init = amr_nb_encode_init,
303  FF_CODEC_ENCODE_CB(amr_nb_encode_frame),
304  .close = amr_nb_encode_close,
305  .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
307  .p.priv_class = &amrnb_class,
308 };
309 #endif /* CONFIG_LIBOPENCORE_AMRNB_ENCODER */
310 
311 #endif /* CONFIG_LIBOPENCORE_AMRNB */
312 
313 /* -----------AMR wideband ------------*/
314 #if CONFIG_LIBOPENCORE_AMRWB_DECODER
315 
316 #include <opencore-amrwb/dec_if.h>
317 #include <opencore-amrwb/if_rom.h>
318 
319 typedef struct AMRWBContext {
320  void *state;
321 } AMRWBContext;
322 
323 static av_cold int amr_wb_decode_init(AVCodecContext *avctx)
324 {
325  AMRWBContext *s = avctx->priv_data;
326  int ret;
327 
328  if ((ret = amr_decode_fix_avctx(avctx)) < 0)
329  return ret;
330 
331  s->state = D_IF_init();
332 
333  return 0;
334 }
335 
336 static int amr_wb_decode_frame(AVCodecContext *avctx, AVFrame *frame,
337  int *got_frame_ptr, AVPacket *avpkt)
338 {
339  const uint8_t *buf = avpkt->data;
340  int buf_size = avpkt->size;
341  AMRWBContext *s = avctx->priv_data;
342  int mode, ret;
343  int packet_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};
345 
346  /* get output buffer */
347  frame->nb_samples = 320;
348  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
349  return ret;
350 
351  mode = (buf[0] >> 3) & 0x000F;
352  packet_size = block_size[mode];
353 
354  if (packet_size > buf_size) {
355  av_log(avctx, AV_LOG_ERROR, "AMR frame too short (%d, should be %d)\n",
356  buf_size, packet_size + 1);
357  return AVERROR_INVALIDDATA;
358  }
359  if (!packet_size) {
360  av_log(avctx, AV_LOG_ERROR, "amr packet_size invalid\n");
361  return AVERROR_INVALIDDATA;
362  }
363 
364  D_IF_decode(s->state, buf, (short *)frame->data[0], _good_frame);
365 
366  *got_frame_ptr = 1;
367 
368  return packet_size;
369 }
370 
371 static int amr_wb_decode_close(AVCodecContext *avctx)
372 {
373  AMRWBContext *s = avctx->priv_data;
374 
375  D_IF_exit(s->state);
376  return 0;
377 }
378 
380  .p.name = "libopencore_amrwb",
381  CODEC_LONG_NAME("OpenCORE AMR-WB (Adaptive Multi-Rate Wide-Band)"),
382  .p.type = AVMEDIA_TYPE_AUDIO,
383  .p.id = AV_CODEC_ID_AMR_WB,
384  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
385  .p.wrapper_name = "libopencore_amrwb",
386  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE,
387  .priv_data_size = sizeof(AMRWBContext),
388  .init = amr_wb_decode_init,
389  .close = amr_wb_decode_close,
390  FF_CODEC_DECODE_CB(amr_wb_decode_frame),
391 };
392 
393 #endif /* CONFIG_LIBOPENCORE_AMRWB_DECODER */
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1083
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
AVERROR
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
opt.h
ff_af_queue_remove
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
Definition: audio_frame_queue.c:75
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1056
ff_af_queue_close
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
Definition: audio_frame_queue.c:36
ff_af_queue_init
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
Definition: audio_frame_queue.c:28
mode
Definition: swscale.c:52
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AVPacket::data
uint8_t * data
Definition: packet.h:539
AVOption
AVOption.
Definition: opt.h:429
encode.h
AV_CODEC_ID_AMR_NB
@ AV_CODEC_ID_AMR_NB
Definition: codec_id.h:427
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:35
FFCodec
Definition: codec_internal.h:127
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:557
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:327
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
AV_CODEC_ID_AMR_WB
@ AV_CODEC_ID_AMR_WB
Definition: codec_id.h:428
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1071
audio_frame_queue.h
AVCodecContext::initial_padding
int initial_padding
Audio only.
Definition: avcodec.h:1128
ff_libopencore_amrnb_decoder
const FFCodec ff_libopencore_amrnb_decoder
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
ff_af_queue_add
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
Definition: audio_frame_queue.c:44
AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:357
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
Mode
Mode
Frame type (Table 1a in 3GPP TS 26.101)
Definition: amrnbdata.h:39
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:311
s
#define s(width, name)
Definition: cbs_vp9.c:198
bitrate
int64_t bitrate
Definition: av1_levels.c:47
ff_libopencore_amrnb_encoder
const FFCodec ff_libopencore_amrnb_encoder
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AudioFrameQueue
Definition: audio_frame_queue.h:32
decode.h
av_class
static const AVClass av_class
Definition: options.c:133
AMRWBContext::state
void * state
Definition: libvo-amrwbenc.c:37
AMRContext
Definition: amrnbdec.c:100
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:461
if
if(ret)
Definition: filter_design.txt:179
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:501
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
options
Definition: swscale.c:42
abs
#define abs(x)
Definition: cuda_runtime.h:35
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:352
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:106
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
options
const OptionDef options[]
f
f
Definition: af_crystalizer.c:122
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1697
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:540
ff_libopencore_amrwb_decoder
const FFCodec ff_libopencore_amrwb_decoder
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:317
codec_internal.h
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1063
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
FF_COMPLIANCE_UNOFFICIAL
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: defs.h:61
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
common.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
avcodec.h
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:2041
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:80
frame
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
Definition: filter_design.txt:264
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1389
AVCodecContext
main external API structure.
Definition: avcodec.h:451
channel_layout.h
AMRWBContext
Definition: amrwbdec.c:52
rates
static const int rates[]
Definition: swresample.c:103
mode
mode
Definition: ebur128.h:83
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:440
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
mem.h
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:392
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
avstring.h
AV_CODEC_CAP_SMALL_LAST_FRAME
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: codec.h:81
snprintf
#define snprintf
Definition: snprintf.h:34
ff_alloc_packet
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition: encode.c:62