84 #include <speex/speex.h>
85 #include <speex/speex_header.h>
86 #include <speex/speex_stereo.h>
113 const char *mode_str =
"unknown";
117 case SPEEX_MODEID_NB: mode_str =
"narrowband";
break;
118 case SPEEX_MODEID_WB: mode_str =
"wideband";
break;
119 case SPEEX_MODEID_UWB: mode_str =
"ultra-wideband";
break;
147 const SpeexMode *mode;
155 "mono are supported\n", avctx->
channels);
161 case 8000: mode = &speex_nb_mode;
break;
162 case 16000: mode = &speex_wb_mode;
break;
163 case 32000: mode = &speex_uwb_mode;
break;
166 "Resample to 8, 16, or 32 kHz.\n", avctx->
sample_rate);
192 speex_encoder_ctl(s->
enc_state, SPEEX_SET_ABR,
194 speex_encoder_ctl(s->
enc_state, SPEEX_GET_ABR,
197 speex_encoder_ctl(s->
enc_state, SPEEX_SET_BITRATE,
199 speex_encoder_ctl(s->
enc_state, SPEEX_GET_BITRATE,
204 speex_encoder_ctl(s->
enc_state, SPEEX_SET_QUALITY,
206 speex_encoder_ctl(s->
enc_state, SPEEX_GET_BITRATE,
216 speex_encoder_ctl(s->
enc_state, SPEEX_SET_VAD, &s->
vad);
220 speex_encoder_ctl(s->
enc_state, SPEEX_SET_DTX, &s->
dtx);
228 speex_encoder_ctl(s->
enc_state, SPEEX_SET_COMPLEXITY, &complexity);
230 speex_encoder_ctl(s->
enc_state, SPEEX_GET_COMPLEXITY, &complexity);
238 speex_encoder_ctl(s->
enc_state, SPEEX_GET_LOOKAHEAD, &avctx->
delay);
244 header_data = speex_header_to_packet(&s->
header, &header_size);
249 speex_header_free(header_data);
254 #if FF_API_OLD_ENCODE_AUDIO
258 speex_header_free(header_data);
266 memcpy(avctx->
extradata, header_data, header_size);
268 speex_header_free(header_data);
271 speex_bits_init(&s->
bits);
278 const AVFrame *frame,
int *got_packet_ptr)
287 speex_encode_stereo_int(samples, s->
header.frame_size, &s->
bits);
298 speex_bits_pack(&s->
bits, 15, 5);
310 ret = speex_bits_write(&s->
bits, avpkt->
data, avpkt->
size);
311 speex_bits_reset(&s->
bits);
328 speex_bits_destroy(&s->
bits);
332 #if FF_API_OLD_ENCODE_AUDIO
340 #define OFFSET(x) offsetof(LibSpeexEncContext, x)
341 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
344 {
"cbr_quality",
"Set quality value (0 to 10) for CBR",
OFFSET(cbr_quality),
AV_OPT_TYPE_INT, { .i64 = 8 }, 0, 10,
AE },
345 {
"frames_per_packet",
"Number of frames to encode in each packet",
OFFSET(frames_per_packet),
AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 8,
AE },
360 {
"compression_level",
"3" },
378 .supported_samplerates = (
const int[]){ 8000, 16000, 32000, 0 },
380 .priv_class = &
class,
int pkt_frame_count
frame count for the current packet
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static av_cold int encode_init(AVCodecContext *avctx)
This structure describes decoded (raw) audio or video data.
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
AVFrame * coded_frame
the picture in the bitstream
int cbr_quality
CBR quality 0 to 10.
int vad
flag to enable VAD
SpeexBits bits
libspeex bitwriter context
static av_cold int encode_close(AVCodecContext *avctx)
#define AV_CH_LAYOUT_STEREO
int dtx
flag to enable DTX
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AudioFrameQueue afq
frame queue
#define CODEC_FLAG_QSCALE
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVCodec ff_libspeex_encoder
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int init(AVCodecParserContext *s)
int frames_per_packet
number of frames to encode in each packet
static const AVCodecDefault defaults[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
#define FF_COMPRESSION_DEFAULT
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
int bit_rate
the average bitrate
audio channel layout utility functions
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
int frame_size
Number of samples per channel in an audio frame.
void * enc_state
libspeex encoder state
int sample_rate
samples per second
main external API structure.
static void close(AVCodecParserContext *s)
Describe the class of an AVClass context structure.
#define FF_INPUT_BUFFER_PADDING_SIZE
int global_quality
Global quality for codecs which cannot change it per frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
common internal and external API header
static av_cold void print_enc_params(AVCodecContext *avctx, LibSpeexEncContext *s)
AVSampleFormat
Audio Sample Formats.
SpeexHeader header
libspeex header struct
static const AVOption options[]
void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int *duration)
Remove frame(s) from the queue.
int channels
number of audio channels
int abr
flag to enable ABR
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
float vbr_quality
VBR quality 0.0 to 10.0.
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)