103 const float *in1,
const float *in2,
104 const float *window,
int len)
107 for (i = 0; i <
len; i++)
108 out[i] = in2[i] * window[i] + in1[i] * (1.0 - window[i]);
120 else if (ret != nb_samples) {
127 if (celt_size != nb_samples) {
147 s->
out[0] += nb_samples;
148 s->
out[1] += nb_samples;
149 s->
out_size -= nb_samples *
sizeof(float);
156 static const float delay[16] = { 0.0 };
172 "Error feeding initial silence to the resampler.\n");
210 int redundancy_size, redundancy_pos;
211 int ret, i, consumed;
259 redundancy_size = size - (consumed + 7) / 8;
260 size -= redundancy_size;
266 if (redundancy_pos) {
276 float *out_tmp[2] = { s->
out[0], s->
out[1] };
279 int celt_output_samples = samples;
289 out_tmp[i] += delay_samples;
291 celt_output_samples -= delay_samples;
294 "Spurious CELT delay samples present.\n");
313 void *delaybuf[2] = { s->
celt_output[0] + celt_output_samples,
319 celt_output_samples);
337 if (!redundancy_pos) {
345 s->
out[i] + samples - 120 + delayed_samples,
356 s->
out[i] + 120 + delayed_samples,
369 int output_samples = 0;
370 int flush_needed = 0;
376 int64_t cur_samplerate;
384 if (!buf && !flush_needed)
428 output_samples += samples;
431 s->
out[j] += samples;
432 s->
out_size -= samples *
sizeof(
float);
439 return output_samples;
443 int *got_frame_ptr,
AVPacket *avpkt)
448 int buf_size = avpkt->
size;
449 int coded_samples = 0;
450 int decoded_samples = 0;
452 int delayed_samples = 0;
473 frame->
nb_samples = coded_samples + delayed_samples;
487 for (i = 0; i < avctx->
channels; i++) {
508 "Mismatching coded sample count in substream %d.\n", i);
519 if (decoded_samples && ret != decoded_samples) {
521 "in a multi-channel stream\n");
524 decoded_samples =
ret;
529 for (i = 0; i < avctx->
channels; i++) {
549 *got_frame_ptr = !!decoded_samples;
int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, int self_delimiting)
Parse Opus packet info from raw packet data.
static const uint8_t celt_band_end[]
static av_cold int opus_decode_close(AVCodecContext *avctx)
void ff_celt_flush(CeltContext *s)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
av_cold void swr_close(SwrContext *s)
Closes the context so that swr_is_initialized() returns 0.
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static const uint16_t silk_frame_duration_ms[16]
int frame_count
frame count
float redundancy_buf[2][960]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static void opus_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, unsigned int bytes)
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
static FFServerConfig config
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
static int opus_decode_redundancy(OpusStreamContext *s, const uint8_t *data, int size)
static av_always_inline unsigned int opus_rc_p2model(OpusRangeCoder *rc, unsigned int bits)
#define AV_CH_LAYOUT_STEREO
Macro definitions for various function/variable attributes.
void(* vector_fmac_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float and add to destination vector.
static int opus_flush_resample(OpusStreamContext *s, int nb_samples)
enum AVSampleFormat sample_fmt
audio sample format
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
unsigned int total_read_bits
static int opus_decode_frame(OpusStreamContext *s, const uint8_t *data, int size)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void ff_celt_free(CeltContext **s)
bitstream reader API header.
static void opus_fade(float *out, const float *in1, const float *in2, const float *window, int len)
const float ff_celt_window2[120]
static av_cold int opus_decode_init(AVCodecContext *avctx)
ChannelMap * channel_maps
libswresample public header
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
const char * name
Name of the codec implementation.
Libavcodec external API header.
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
int ff_celt_init(AVCodecContext *avctx, CeltContext **s, int output_channels)
audio channel layout utility functions
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
int frame_size[MAX_FRAMES]
frame sizes
int frame_duration
frame duration, in samples @ 48kHz
int out_dummy_allocated_size
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
static void flush(AVCodecContext *avctx)
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
static int get_silk_samplerate(int config)
int sample_rate
samples per second
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
void ff_silk_flush(SilkContext *s)
main external API structure.
int ff_silk_init(AVCodecContext *avctx, SilkContext **ps, int output_channels)
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int config
configuration: tells the audio mode, bandwidth, and frame duration
void ff_silk_free(SilkContext **ps)
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static int opus_decode_subpacket(OpusStreamContext *s, const uint8_t *buf, int buf_size, int nb_samples)
int stereo
whether this packet is mono or stereo
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count, const uint8_t *in_arg[SWR_CH_MAX], int in_count)
int data_size
size of the useful data – packet size - padding
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
static int opus_decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
static int opus_init_resample(OpusStreamContext *s)
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
static av_always_inline void opus_rc_normalize(OpusRangeCoder *rc)
common internal api header.
static const int silk_resample_delay[]
int ff_silk_decode_superframe(SilkContext *s, OpusRangeCoder *rc, float *output[2], enum OpusBandwidth bandwidth, int coded_channels, int duration_ms)
Decode the LP layer of one Opus frame (which may correspond to several SILK frames).
static av_always_inline unsigned int opus_rc_unimodel(OpusRangeCoder *rc, unsigned int size)
CELT: read a uniform distribution.
int ff_celt_decode_frame(CeltContext *s, OpusRangeCoder *rc, float **output, int coded_channels, int frame_size, int startband, int endband)
OpusStreamContext * streams
int packet_size
packet size
OpusRangeCoder redundancy_rc
int channels
number of audio channels
int frame_offset[MAX_FRAMES]
frame offsets
static av_always_inline unsigned int opus_rc_tell(const OpusRangeCoder *rc)
CELT: estimate bits of entropy that have thus far been consumed for the current CELT frame...
enum OpusBandwidth bandwidth
bandwidth
static av_cold void opus_decode_flush(AVCodecContext *ctx)
static int opus_rc_init(OpusRangeCoder *rc, const uint8_t *data, int size)
Range decoder.
float * redundancy_output[2]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static void * av_mallocz_array(size_t nmemb, size_t size)
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, OpusContext *s)
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
int swr_is_initialized(struct SwrContext *s)
Check whether an swr context has been initialized or not.
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.