FFmpeg
libspeexenc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Justin Ruggles
3  * Copyright (c) 2009 Xuggle Incorporated
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 /**
23  * @file
24  * libspeex Speex audio encoder
25  *
26  * Usage Guide
27  * This explains the values that need to be set prior to initialization in
28  * order to control various encoding parameters.
29  *
30  * Channels
31  * Speex only supports mono or stereo, so avctx->ch_layout.nb_channels must
32  * be set to 1 or 2.
33  *
34  * Sample Rate / Encoding Mode
35  * Speex has 3 modes, each of which uses a specific sample rate.
36  * narrowband : 8 kHz
37  * wideband : 16 kHz
38  * ultra-wideband : 32 kHz
39  * avctx->sample_rate must be set to one of these 3 values. This will be
40  * used to set the encoding mode.
41  *
42  * Rate Control
43  * VBR mode is turned on by setting AV_CODEC_FLAG_QSCALE in avctx->flags.
44  * avctx->global_quality is used to set the encoding quality.
45  * For CBR mode, avctx->bit_rate can be used to set the constant bitrate.
46  * Alternatively, the 'cbr_quality' option can be set from 0 to 10 to set
47  * a constant bitrate based on quality.
48  * For ABR mode, set avctx->bit_rate and set the 'abr' option to 1.
49  * Approx. Bitrate Range:
50  * narrowband : 2400 - 25600 bps
51  * wideband : 4000 - 43200 bps
52  * ultra-wideband : 4400 - 45200 bps
53  *
54  * Complexity
55  * Encoding complexity is controlled by setting avctx->compression_level.
56  * The valid range is 0 to 10. A higher setting gives generally better
57  * quality at the expense of encoding speed. This does not affect the
58  * bit rate.
59  *
60  * Frames-per-Packet
61  * The encoder defaults to using 1 frame-per-packet. However, it is
62  * sometimes desirable to use multiple frames-per-packet to reduce the
63  * amount of container overhead. This can be done by setting the
64  * 'frames_per_packet' option to a value 1 to 8.
65  *
66  *
67  * Optional features
68  * Speex encoder supports several optional features, which can be useful
69  * for some conditions.
70  *
71  * Voice Activity Detection
72  * When enabled, voice activity detection detects whether the audio
73  * being encoded is speech or silence/background noise. VAD is always
74  * implicitly activated when encoding in VBR, so the option is only useful
75  * in non-VBR operation. In this case, Speex detects non-speech periods and
76  * encodes them with just enough bits to reproduce the background noise.
77  *
78  * Discontinuous Transmission (DTX)
79  * DTX is an addition to VAD/VBR operation, that makes it possible to stop transmitting
80  * completely when the background noise is stationary.
81  * In file-based operation only 5 bits are used for such frames.
82  */
83 
84 #include <speex/speex.h>
85 #include <speex/speex_header.h>
86 #include <speex/speex_stereo.h>
87 
89 #include "libavutil/common.h"
90 #include "libavutil/mem.h"
91 #include "libavutil/opt.h"
92 #include "avcodec.h"
93 #include "codec_internal.h"
94 #include "encode.h"
95 #include "audio_frame_queue.h"
96 
97 /* TODO: Think about converting abr, vad, dtx and such flags to a bit field */
98 typedef struct LibSpeexEncContext {
99  AVClass *class; ///< AVClass for private options
100  SpeexBits bits; ///< libspeex bitwriter context
101  SpeexHeader header; ///< libspeex header struct
102  void *enc_state; ///< libspeex encoder state
103  int frames_per_packet; ///< number of frames to encode in each packet
104  float vbr_quality; ///< VBR quality 0.0 to 10.0
105  int cbr_quality; ///< CBR quality 0 to 10
106  int abr; ///< flag to enable ABR
107  int vad; ///< flag to enable VAD
108  int dtx; ///< flag to enable DTX
109  int pkt_frame_count; ///< frame count for the current packet
110  AudioFrameQueue afq; ///< frame queue
112 
115 {
116  const char *mode_str = "unknown";
117 
118  av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", avctx->ch_layout.nb_channels);
119  switch (s->header.mode) {
120  case SPEEX_MODEID_NB: mode_str = "narrowband"; break;
121  case SPEEX_MODEID_WB: mode_str = "wideband"; break;
122  case SPEEX_MODEID_UWB: mode_str = "ultra-wideband"; break;
123  }
124  av_log(avctx, AV_LOG_DEBUG, "mode: %s\n", mode_str);
125  if (s->header.vbr) {
126  av_log(avctx, AV_LOG_DEBUG, "rate control: VBR\n");
127  av_log(avctx, AV_LOG_DEBUG, " quality: %f\n", s->vbr_quality);
128  } else if (s->abr) {
129  av_log(avctx, AV_LOG_DEBUG, "rate control: ABR\n");
130  av_log(avctx, AV_LOG_DEBUG, " bitrate: %"PRId64" bps\n", avctx->bit_rate);
131  } else {
132  av_log(avctx, AV_LOG_DEBUG, "rate control: CBR\n");
133  av_log(avctx, AV_LOG_DEBUG, " bitrate: %"PRId64" bps\n", avctx->bit_rate);
134  }
135  av_log(avctx, AV_LOG_DEBUG, "complexity: %d\n",
136  avctx->compression_level);
137  av_log(avctx, AV_LOG_DEBUG, "frame size: %d samples\n",
138  avctx->frame_size);
139  av_log(avctx, AV_LOG_DEBUG, "frames per packet: %d\n",
140  s->frames_per_packet);
141  av_log(avctx, AV_LOG_DEBUG, "packet size: %d\n",
142  avctx->frame_size * s->frames_per_packet);
143  av_log(avctx, AV_LOG_DEBUG, "voice activity detection: %d\n", s->vad);
144  av_log(avctx, AV_LOG_DEBUG, "discontinuous transmission: %d\n", s->dtx);
145 }
146 
148 {
149  LibSpeexEncContext *s = avctx->priv_data;
150  int channels = avctx->ch_layout.nb_channels;
151  const SpeexMode *mode;
152  uint8_t *header_data;
153  int header_size;
154  int32_t complexity;
155 
156  /* sample rate and encoding mode */
157  switch (avctx->sample_rate) {
158  case 8000: mode = speex_lib_get_mode(SPEEX_MODEID_NB); break;
159  case 16000: mode = speex_lib_get_mode(SPEEX_MODEID_WB); break;
160  case 32000: mode = speex_lib_get_mode(SPEEX_MODEID_UWB); break;
161  default:
162  av_log(avctx, AV_LOG_ERROR, "Sample rate of %d Hz is not supported. "
163  "Resample to 8, 16, or 32 kHz.\n", avctx->sample_rate);
164  return AVERROR(EINVAL);
165  }
166 
167  /* initialize libspeex */
168  s->enc_state = speex_encoder_init(mode);
169  if (!s->enc_state) {
170  av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex\n");
171  return -1;
172  }
173  speex_init_header(&s->header, avctx->sample_rate, channels, mode);
174 
175  /* rate control method and parameters */
176  if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
177  /* VBR */
178  s->header.vbr = 1;
179  s->vad = 1; /* VAD is always implicitly activated for VBR */
180  speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR, &s->header.vbr);
181  s->vbr_quality = av_clipf(avctx->global_quality / (float)FF_QP2LAMBDA,
182  0.0f, 10.0f);
183  speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR_QUALITY, &s->vbr_quality);
184  } else {
185  s->header.bitrate = avctx->bit_rate;
186  if (avctx->bit_rate > 0) {
187  /* CBR or ABR by bitrate */
188  if (s->abr) {
189  speex_encoder_ctl(s->enc_state, SPEEX_SET_ABR,
190  &s->header.bitrate);
191  speex_encoder_ctl(s->enc_state, SPEEX_GET_ABR,
192  &s->header.bitrate);
193  } else {
194  speex_encoder_ctl(s->enc_state, SPEEX_SET_BITRATE,
195  &s->header.bitrate);
196  speex_encoder_ctl(s->enc_state, SPEEX_GET_BITRATE,
197  &s->header.bitrate);
198  }
199  } else {
200  /* CBR by quality */
201  speex_encoder_ctl(s->enc_state, SPEEX_SET_QUALITY,
202  &s->cbr_quality);
203  speex_encoder_ctl(s->enc_state, SPEEX_GET_BITRATE,
204  &s->header.bitrate);
205  }
206  /* stereo side information adds about 800 bps to the base bitrate */
207  /* TODO: this should be calculated exactly */
208  avctx->bit_rate = s->header.bitrate + (channels == 2 ? 800 : 0);
209  }
210 
211  /* VAD is activated with VBR or can be turned on by itself */
212  if (s->vad)
213  speex_encoder_ctl(s->enc_state, SPEEX_SET_VAD, &s->vad);
214 
215  /* Activating Discontinuous Transmission */
216  if (s->dtx) {
217  speex_encoder_ctl(s->enc_state, SPEEX_SET_DTX, &s->dtx);
218  if (!(s->abr || s->vad || s->header.vbr))
219  av_log(avctx, AV_LOG_WARNING, "DTX is not much of use without ABR, VAD or VBR\n");
220  }
221 
222  /* set encoding complexity */
224  complexity = av_clip(avctx->compression_level, 0, 10);
225  speex_encoder_ctl(s->enc_state, SPEEX_SET_COMPLEXITY, &complexity);
226  }
227  speex_encoder_ctl(s->enc_state, SPEEX_GET_COMPLEXITY, &complexity);
228  avctx->compression_level = complexity;
229 
230  /* set packet size */
231  avctx->frame_size = s->header.frame_size;
232  s->header.frames_per_packet = s->frames_per_packet;
233 
234  /* set encoding delay */
235  speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->initial_padding);
236  ff_af_queue_init(avctx, &s->afq);
237 
238  /* create header packet bytes from header struct */
239  /* note: libspeex allocates the memory for header_data, which is freed
240  below with speex_header_free() */
241  header_data = speex_header_to_packet(&s->header, &header_size);
242 
243  /* allocate extradata */
244  avctx->extradata = av_malloc(header_size + AV_INPUT_BUFFER_PADDING_SIZE);
245  if (!avctx->extradata) {
246  speex_header_free(header_data);
247  speex_encoder_destroy(s->enc_state);
248  av_log(avctx, AV_LOG_ERROR, "memory allocation error\n");
249  return AVERROR(ENOMEM);
250  }
251 
252  /* copy header packet to extradata */
253  memcpy(avctx->extradata, header_data, header_size);
254  avctx->extradata_size = header_size;
255  speex_header_free(header_data);
256 
257  /* init libspeex bitwriter */
258  speex_bits_init(&s->bits);
259 
260  print_enc_params(avctx, s);
261  return 0;
262 }
263 
264 static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
265  const AVFrame *frame, int *got_packet_ptr)
266 {
267  LibSpeexEncContext *s = avctx->priv_data;
268  int16_t *samples = frame ? (int16_t *)frame->data[0] : NULL;
269  int ret;
270 
271  if (samples) {
272  /* encode Speex frame */
273  if (avctx->ch_layout.nb_channels == 2)
274  speex_encode_stereo_int(samples, s->header.frame_size, &s->bits);
275  speex_encode_int(s->enc_state, samples, &s->bits);
276  s->pkt_frame_count++;
277  if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
278  return ret;
279  } else {
280  /* handle end-of-stream */
281  if (!s->pkt_frame_count)
282  return 0;
283  /* add extra terminator codes for unused frames in last packet */
284  while (s->pkt_frame_count < s->frames_per_packet) {
285  speex_bits_pack(&s->bits, 15, 5);
286  s->pkt_frame_count++;
287  }
288  }
289 
290  /* write output if all frames for the packet have been encoded */
291  if (s->pkt_frame_count == s->frames_per_packet) {
292  s->pkt_frame_count = 0;
293  if ((ret = ff_alloc_packet(avctx, avpkt, speex_bits_nbytes(&s->bits))) < 0)
294  return ret;
295  ret = speex_bits_write(&s->bits, avpkt->data, avpkt->size);
296  speex_bits_reset(&s->bits);
297 
298  /* Get the next frame pts/duration */
299  ff_af_queue_remove(&s->afq, s->frames_per_packet * avctx->frame_size,
300  &avpkt->pts, &avpkt->duration);
301 
302  avpkt->size = ret;
303  *got_packet_ptr = 1;
304  return 0;
305  }
306  return 0;
307 }
308 
310 {
311  LibSpeexEncContext *s = avctx->priv_data;
312 
313  speex_bits_destroy(&s->bits);
314  speex_encoder_destroy(s->enc_state);
315 
316  ff_af_queue_close(&s->afq);
317 
318  return 0;
319 }
320 
321 #define OFFSET(x) offsetof(LibSpeexEncContext, x)
322 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
323 static const AVOption options[] = {
324  { "abr", "Use average bit rate", OFFSET(abr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE },
325  { "cbr_quality", "Set quality value (0 to 10) for CBR", OFFSET(cbr_quality), AV_OPT_TYPE_INT, { .i64 = 8 }, 0, 10, AE },
326  { "frames_per_packet", "Number of frames to encode in each packet", OFFSET(frames_per_packet), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 8, AE },
327  { "vad", "Voice Activity Detection", OFFSET(vad), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE },
328  { "dtx", "Discontinuous Transmission", OFFSET(dtx), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE },
329  { NULL },
330 };
331 
332 static const AVClass speex_class = {
333  .class_name = "libspeex",
334  .item_name = av_default_item_name,
335  .option = options,
336  .version = LIBAVUTIL_VERSION_INT,
337 };
338 
339 static const FFCodecDefault defaults[] = {
340  { "b", "0" },
341  { "compression_level", "3" },
342  { NULL },
343 };
344 
346  .p.name = "libspeex",
347  CODEC_LONG_NAME("libspeex Speex"),
348  .p.type = AVMEDIA_TYPE_AUDIO,
349  .p.id = AV_CODEC_ID_SPEEX,
350  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
351  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE,
352  .priv_data_size = sizeof(LibSpeexEncContext),
353  .init = encode_init,
355  .close = encode_close,
356  .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
358  .p.ch_layouts = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
360  { 0 },
361  },
362  .p.supported_samplerates = (const int[]){ 8000, 16000, 32000, 0 },
363  .p.priv_class = &speex_class,
364  .defaults = defaults,
365  .p.wrapper_name = "libspeex",
366 };
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1083
ff_libspeex_encoder
const FFCodec ff_libspeex_encoder
Definition: libspeexenc.c:345
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
av_clip
#define av_clip
Definition: common.h:100
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
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:393
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
AV_CODEC_FLAG_QSCALE
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
Definition: avcodec.h:224
ff_af_queue_init
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
Definition: audio_frame_queue.c:28
print_enc_params
static av_cold void print_enc_params(AVCodecContext *avctx, LibSpeexEncContext *s)
Definition: libspeexenc.c:113
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
encode_close
static av_cold int encode_close(AVCodecContext *avctx)
Definition: libspeexenc.c:309
AVOption
AVOption.
Definition: opt.h:429
encode.h
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
FF_COMPRESSION_DEFAULT
#define FF_COMPRESSION_DEFAULT
Definition: avcodec.h:1256
defaults
static const FFCodecDefault defaults[]
Definition: libspeexenc.c:339
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
FFCodecDefault
Definition: codec_internal.h:97
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AV_CODEC_ID_SPEEX
@ AV_CODEC_ID_SPEEX
Definition: codec_id.h:481
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
AE
#define AE
Definition: libspeexenc.c:322
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:508
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_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
LibSpeexEncContext::pkt_frame_count
int pkt_frame_count
frame count for the current packet
Definition: libspeexenc.c:109
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:530
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVCodecContext::global_quality
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:1249
LibSpeexEncContext::vad
int vad
flag to enable VAD
Definition: libspeexenc.c:107
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AudioFrameQueue
Definition: audio_frame_queue.h:32
LibSpeexEncContext::abr
int abr
flag to enable ABR
Definition: libspeexenc.c:106
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
channels
channels
Definition: aptx.h:31
options
static const AVOption options[]
Definition: libspeexenc.c:323
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
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
LibSpeexEncContext::vbr_quality
float vbr_quality
VBR quality 0.0 to 10.0.
Definition: libspeexenc.c:104
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
av_clipf
av_clipf
Definition: af_crystalizer.c:122
speex_class
static const AVClass speex_class
Definition: libspeexenc.c:332
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
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:317
codec_internal.h
LibSpeexEncContext::afq
AudioFrameQueue afq
frame queue
Definition: libspeexenc.c:110
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
LibSpeexEncContext::header
SpeexHeader header
libspeex header struct
Definition: libspeexenc.c:101
LibSpeexEncContext::bits
SpeexBits bits
libspeex bitwriter context
Definition: libspeexenc.c:100
LibSpeexEncContext::dtx
int dtx
flag to enable DTX
Definition: libspeexenc.c:108
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
LibSpeexEncContext::frames_per_packet
int frames_per_packet
number of frames to encode in each packet
Definition: libspeexenc.c:103
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:529
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
avcodec.h
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
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
encode_frame
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: libspeexenc.c:264
AVCodecContext
main external API structure.
Definition: avcodec.h:451
channel_layout.h
OFFSET
#define OFFSET(x)
Definition: libspeexenc.c:321
mode
mode
Definition: ebur128.h:83
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
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
LibSpeexEncContext::enc_state
void * enc_state
libspeex encoder state
Definition: libspeexenc.c:102
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
LibSpeexEncContext::cbr_quality
int cbr_quality
CBR quality 0 to 10.
Definition: libspeexenc.c:105
int32_t
int32_t
Definition: audioconvert.c:56
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
LibSpeexEncContext
Definition: libspeexenc.c:98
encode_init
static av_cold int encode_init(AVCodecContext *avctx)
Definition: libspeexenc.c:147
FF_QP2LAMBDA
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
ff_alloc_packet
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition: encode.c:62
AVCodecContext::compression_level
int compression_level
Definition: avcodec.h:1255
SpeexMode
Definition: speexdec.c:169