Go to the documentation of this file.
84 #include <speex/speex.h>
85 #include <speex/speex_header.h>
86 #include <speex/speex_stereo.h>
115 const char *mode_str =
"unknown";
118 switch (
s->header.mode) {
119 case SPEEX_MODEID_NB: mode_str =
"narrowband";
break;
120 case SPEEX_MODEID_WB: mode_str =
"wideband";
break;
121 case SPEEX_MODEID_UWB: mode_str =
"ultra-wideband";
break;
139 s->frames_per_packet);
151 uint8_t *header_data;
157 case 8000:
mode = speex_lib_get_mode(SPEEX_MODEID_NB);
break;
158 case 16000:
mode = speex_lib_get_mode(SPEEX_MODEID_WB);
break;
159 case 32000:
mode = speex_lib_get_mode(SPEEX_MODEID_UWB);
break;
162 "Resample to 8, 16, or 32 kHz.\n", avctx->
sample_rate);
167 s->enc_state = speex_encoder_init(
mode);
179 speex_encoder_ctl(
s->enc_state, SPEEX_SET_VBR, &
s->header.vbr);
182 speex_encoder_ctl(
s->enc_state, SPEEX_SET_VBR_QUALITY, &
s->vbr_quality);
188 speex_encoder_ctl(
s->enc_state, SPEEX_SET_ABR,
190 speex_encoder_ctl(
s->enc_state, SPEEX_GET_ABR,
193 speex_encoder_ctl(
s->enc_state, SPEEX_SET_BITRATE,
195 speex_encoder_ctl(
s->enc_state, SPEEX_GET_BITRATE,
200 speex_encoder_ctl(
s->enc_state, SPEEX_SET_QUALITY,
202 speex_encoder_ctl(
s->enc_state, SPEEX_GET_BITRATE,
212 speex_encoder_ctl(
s->enc_state, SPEEX_SET_VAD, &
s->vad);
216 speex_encoder_ctl(
s->enc_state, SPEEX_SET_DTX, &
s->dtx);
217 if (!(
s->abr ||
s->vad ||
s->header.vbr))
224 speex_encoder_ctl(
s->enc_state, SPEEX_SET_COMPLEXITY, &complexity);
226 speex_encoder_ctl(
s->enc_state, SPEEX_GET_COMPLEXITY, &complexity);
231 s->header.frames_per_packet =
s->frames_per_packet;
234 speex_encoder_ctl(
s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->
initial_padding);
240 header_data = speex_header_to_packet(&
s->header, &header_size);
245 speex_header_free(header_data);
246 speex_encoder_destroy(
s->enc_state);
252 memcpy(avctx->
extradata, header_data, header_size);
254 speex_header_free(header_data);
257 speex_bits_init(&
s->bits);
273 speex_encode_stereo_int(
samples,
s->header.frame_size, &
s->bits);
274 speex_encode_int(
s->enc_state,
samples, &
s->bits);
275 s->pkt_frame_count++;
280 if (!
s->pkt_frame_count)
283 while (
s->pkt_frame_count <
s->frames_per_packet) {
284 speex_bits_pack(&
s->bits, 15, 5);
285 s->pkt_frame_count++;
290 if (
s->pkt_frame_count ==
s->frames_per_packet) {
291 s->pkt_frame_count = 0;
294 ret = speex_bits_write(&
s->bits, avpkt->
data, avpkt->
size);
295 speex_bits_reset(&
s->bits);
312 speex_bits_destroy(&
s->bits);
313 speex_encoder_destroy(
s->enc_state);
320 #define OFFSET(x) offsetof(LibSpeexEncContext, x)
321 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
324 {
"cbr_quality",
"Set quality value (0 to 10) for CBR",
OFFSET(cbr_quality),
AV_OPT_TYPE_INT, { .i64 = 8 }, 0, 10,
AE },
325 {
"frames_per_packet",
"Number of frames to encode in each packet",
OFFSET(frames_per_packet),
AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 8,
AE },
340 {
"compression_level",
"3" },
345 .
p.
name =
"libspeex",
361 .p.supported_samplerates = (
const int[]){ 8000, 16000, 32000, 0 },
364 .p.wrapper_name =
"libspeex",
int frame_size
Number of samples per channel in an audio frame.
const FFCodec ff_libspeex_encoder
#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.
#define AV_CHANNEL_LAYOUT_STEREO
int sample_rate
samples per second
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
static av_cold void print_enc_params(AVCodecContext *avctx, LibSpeexEncContext *s)
This structure describes decoded (raw) audio or video data.
static av_cold int encode_close(AVCodecContext *avctx)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int nb_channels
Number of channels in this layout.
#define FF_COMPRESSION_DEFAULT
static const FFCodecDefault defaults[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
int initial_padding
Audio only.
int flags
AV_CODEC_FLAG_*.
#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.
int pkt_frame_count
frame count for the current packet
int global_quality
Global quality for codecs which cannot change it per frame.
int vad
flag to enable VAD
int abr
flag to enable ABR
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static const AVOption options[]
#define CODEC_LONG_NAME(str)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
float vbr_quality
VBR quality 0.0 to 10.0.
int64_t bit_rate
the average bitrate
const char * av_default_item_name(void *ptr)
Return the context name.
static const AVClass speex_class
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
An AVChannelLayout holds information about the channel layout of audio data.
AudioFrameQueue afq
frame queue
SpeexHeader header
libspeex header struct
SpeexBits bits
libspeex bitwriter context
int dtx
flag to enable DTX
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int frames_per_packet
number of frames to encode in each packet
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Name of the codec implementation.
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_INPUT_BUFFER_PADDING_SIZE
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
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
void * enc_state
libspeex encoder state
#define AV_CHANNEL_LAYOUT_MONO
This structure stores compressed data.
int cbr_quality
CBR quality 0 to 10.
static av_cold int encode_init(AVCodecContext *avctx)
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.