67 #include <speex/speex.h>
68 #include <speex/speex_header.h>
69 #include <speex/speex_stereo.h>
93 const char *mode_str =
"unknown";
97 case SPEEX_MODEID_NB: mode_str =
"narrowband";
break;
98 case SPEEX_MODEID_WB: mode_str =
"wideband";
break;
99 case SPEEX_MODEID_UWB: mode_str =
"ultra-wideband";
break;
125 const SpeexMode *mode;
126 uint8_t *header_data;
133 "mono are supported\n", avctx->
channels);
139 case 8000: mode = &speex_nb_mode;
break;
140 case 16000: mode = &speex_wb_mode;
break;
141 case 32000: mode = &speex_uwb_mode;
break;
144 "Resample to 8, 16, or 32 kHz.\n", avctx->
sample_rate);
169 speex_encoder_ctl(s->
enc_state, SPEEX_SET_ABR,
171 speex_encoder_ctl(s->
enc_state, SPEEX_GET_ABR,
174 speex_encoder_ctl(s->
enc_state, SPEEX_SET_BITRATE,
176 speex_encoder_ctl(s->
enc_state, SPEEX_GET_BITRATE,
181 speex_encoder_ctl(s->
enc_state, SPEEX_SET_QUALITY,
183 speex_encoder_ctl(s->
enc_state, SPEEX_GET_BITRATE,
194 speex_encoder_ctl(s->
enc_state, SPEEX_SET_COMPLEXITY, &complexity);
196 speex_encoder_ctl(s->
enc_state, SPEEX_GET_COMPLEXITY, &complexity);
210 header_data = speex_header_to_packet(&s->
header, &header_size);
216 speex_header_free(header_data);
223 memcpy(avctx->
extradata, header_data, header_size);
225 speex_header_free(header_data);
228 speex_bits_init(&s->
bits);
243 speex_encode_stereo_int(samples, s->
header.frame_size, &s->
bits);
253 speex_bits_pack(&s->
bits, 15, 5);
266 if (buf_size > speex_bits_nbytes(&s->
bits)) {
267 int ret = speex_bits_write(&s->
bits, frame, buf_size);
268 speex_bits_reset(&s->
bits);
282 speex_bits_destroy(&s->
bits);
291 #define OFFSET(x) offsetof(LibSpeexEncContext, x)
292 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
295 {
"cbr_quality",
"Set quality value (0 to 10) for CBR",
OFFSET(cbr_quality),
AV_OPT_TYPE_INT, { 8 }, 0, 10,
AE },
296 {
"frames_per_packet",
"Number of frames to encode in each packet",
OFFSET(frames_per_packet),
AV_OPT_TYPE_INT, { 1 }, 1, 8,
AE },
309 {
"compression_level",
"3" },
324 .priv_class = &
class,
int pkt_frame_count
frame count for the current packet
#define FF_COMPRESSION_DEFAULT
static av_cold int encode_init(AVCodecContext *avctx)
AVFrame * coded_frame
the picture in the bitstream
static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, void *data)
int cbr_quality
CBR quality 0 to 10.
SpeexBits bits
libspeex bitwriter context
static av_cold int encode_close(AVCodecContext *avctx)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
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...
int lookahead
encoder delay
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVCodec ff_libspeex_encoder
static int init(AVCodecParserContext *s)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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.
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
int bit_rate
the average bitrate
int pkt_sample_count
sample count in the current packet
int frame_size
Samples per packet, initialized when calling 'init'.
void * enc_state
libspeex encoder state
int sample_rate
samples per second
main external API structure.
static void close(AVCodecParserContext *s)
#define CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
rational number numerator/denominator
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int global_quality
Global quality for codecs which cannot change it per frame.
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_cold void print_enc_params(AVCodecContext *avctx, LibSpeexEncContext *s)
SpeexHeader header
libspeex header struct
static const AVOption options[]
int channels
number of audio channels
int abr
flag to enable ABR
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int64_t next_pts
next pts, in sample_rate time base
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
float vbr_quality
VBR quality 0.0 to 10.0.