21#include <speex/speex.h>
22#include <speex/speex_header.h>
23#include <speex/speex_stereo.h>
24#include <speex/speex_callbacks.h>
67 s->pktsize = ((
const int[]){5,10,15,20,20,28,28,38,38,46,62})[
quality];
77 case 8000: spx_mode = 0;
break;
78 case 16000: spx_mode = 1;
break;
79 case 32000: spx_mode = 2;
break;
83 "Decoding as 32kHz ultra-wideband\n",
89 mode = speex_lib_get_mode(spx_mode);
94 s->frame_size = 160 << spx_mode;
108 speex_bits_init(&
s->bits);
109 s->dec_state = speex_decoder_init(
mode);
118 callback.func = speex_std_stereo_request_handler;
120 s->stereo = (SpeexStereoState)SPEEX_STEREO_STATE_INIT;
121 speex_decoder_ctl(
s->dec_state, SPEEX_SET_HANDLER, &
callback);
128 int *got_frame_ptr,
AVPacket *avpkt)
130 uint8_t *buf = avpkt->
data;
131 int buf_size = avpkt->
size;
134 int ret, consumed = 0;
138 frame->nb_samples =
s->frame_size;
141 output = (int16_t *)
frame->data[0];
147 if (speex_bits_remaining(&
s->bits) < 5 ||
148 speex_bits_peek_unsigned(&
s->bits, 5) == 0xF) {
150 if (!buf || !buf_size) {
154 if (
s->pktsize && buf_size == 62)
155 buf_size =
s->pktsize;
157 speex_bits_read_from(&
s->bits, buf, buf_size);
158 consumed = avpkt->
size;
162 ret = speex_decode_int(
s->dec_state, &
s->bits, output);
168 speex_decode_stereo_int(output,
s->frame_size, &
s->stereo);
173 speex_decoder_ctl(
s->dec_state, SPEEX_GET_BITRATE, &avctx->
bit_rate);
181 speex_bits_destroy(&
s->bits);
182 speex_decoder_destroy(
s->dec_state);
190 speex_bits_reset(&
s->bits);
194 .p.name =
"libspeex",
199 .p.wrapper_name =
"libspeex",
const FFCodec ff_libspeex_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
Public libavutil channel layout APIs header.
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
common internal and external API header
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType devtype)
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_MONO
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_S16
signed 16 bits
static av_cold int libspeex_decode_close(AVCodecContext *avctx)
static av_cold void libspeex_decode_flush(AVCodecContext *avctx)
static int libspeex_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static av_cold int libspeex_decode_init(AVCodecContext *avctx)
#define MKTAG(a, b, c, d)
static const uint8_t header[24]
#define SPEEX_INBAND_STEREO
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int64_t bit_rate
the average bitrate
int sample_rate
samples per second
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
static const uint8_t quality[]