142 const float *in1,
const float *in2,
155 (uint8_t**)
s->cur_out, nb_samples,
159 else if (ret != nb_samples) {
166 if (celt_size != nb_samples) {
171 for (
i = 0;
i <
s->output_channels;
i++) {
172 s->fdsp->vector_fmac_scalar(
s->cur_out[
i],
173 s->celt_output[
i], 1.0,
178 if (
s->redundancy_idx) {
179 for (
i = 0;
i <
s->output_channels;
i++)
181 s->redundancy_output[
i] + 120 +
s->redundancy_idx,
183 s->redundancy_idx = 0;
186 s->cur_out[0] += nb_samples;
187 s->cur_out[1] += nb_samples;
188 s->remaining_out_size -= nb_samples *
sizeof(
float);
195 static const float delay[16] = { 0.0 };
196 const uint8_t *delayptr[2] = { (uint8_t*)delay, (uint8_t*)delay };
211 "Error feeding initial silence to the resampler.\n");
226 s->redundancy_output,
227 s->packet.stereo + 1, 240,
240 int samples =
s->packet.frame_duration;
242 int redundancy_size, redundancy_pos;
243 int ret,
i, consumed;
260 s->packet.stereo + 1,
267 (uint8_t**)
s->cur_out,
s->packet.frame_duration,
268 (
const uint8_t**)
s->silk_output, samples);
274 s->delayed_samples +=
s->packet.frame_duration - samples;
291 redundancy_size =
size - (consumed + 7) / 8;
292 size -= redundancy_size;
298 if (redundancy_pos) {
308 float *out_tmp[2] = {
s->cur_out[0],
s->cur_out[1] };
310 out_tmp :
s->celt_output;
311 int celt_output_samples = samples;
318 for (
i = 0;
i <
s->output_channels;
i++) {
319 s->fdsp->vector_fmac_scalar(out_tmp[
i],
s->celt_output[
i], 1.0,
321 out_tmp[
i] += delay_samples;
323 celt_output_samples -= delay_samples;
326 "Spurious CELT delay samples present.\n");
336 s->packet.stereo + 1,
337 s->packet.frame_duration,
344 int celt_delay =
s->packet.frame_duration - celt_output_samples;
345 void *delaybuf[2] = {
s->celt_output[0] + celt_output_samples,
346 s->celt_output[1] + celt_output_samples };
348 for (
i = 0;
i <
s->output_channels;
i++) {
349 s->fdsp->vector_fmac_scalar(out_tmp[
i],
350 s->celt_output[
i], 1.0,
351 celt_output_samples);
361 if (
s->redundancy_idx) {
362 for (
i = 0;
i <
s->output_channels;
i++)
364 s->redundancy_output[
i] + 120 +
s->redundancy_idx,
366 s->redundancy_idx = 0;
369 if (!redundancy_pos) {
375 for (
i = 0;
i <
s->output_channels;
i++) {
378 s->redundancy_output[
i] + 120,
384 for (
i = 0;
i <
s->output_channels;
i++) {
387 s->redundancy_output[
i] + 120,
399 int output_samples = 0;
400 int flush_needed = 0;
403 s->cur_out[0] =
s->out[0];
404 s->cur_out[1] =
s->out[1];
405 s->remaining_out_size =
s->out_size;
412 flush_needed = (
s->packet.mode ==
OPUS_MODE_CELT) || (cur_samplerate !=
s->silk_samplerate);
414 flush_needed = !!
s->delayed_samples;
418 if (!buf && !flush_needed)
422 if (!
s->cur_out[0] ||
423 (
s->output_channels == 2 && !
s->cur_out[1])) {
425 s->remaining_out_size);
429 s->cur_out[0] =
s->out_dummy;
431 s->cur_out[1] =
s->out_dummy;
442 output_samples +=
s->delayed_samples;
443 s->delayed_samples = 0;
450 for (
i = 0;
i <
s->packet.frame_count;
i++) {
451 int size =
s->packet.frame_size[
i];
459 for (j = 0; j <
s->output_channels; j++)
460 memset(
s->cur_out[j], 0,
s->packet.frame_duration *
sizeof(
float));
461 samples =
s->packet.frame_duration;
463 output_samples += samples;
465 for (j = 0; j <
s->output_channels; j++)
466 s->cur_out[j] += samples;
467 s->remaining_out_size -= samples *
sizeof(
float);
471 s->cur_out[0] =
s->cur_out[1] =
NULL;
472 s->remaining_out_size = 0;
474 return output_samples;
478 int *got_frame_ptr,
AVPacket *avpkt)
481 const uint8_t *buf = avpkt->
data;
482 int buf_size = avpkt->
size;
483 int coded_samples = 0;
489 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
495 s->delayed_samples + fifo_samples);
506 coded_samples +=
pkt->frame_count *
pkt->frame_duration;
513 if (!
frame->nb_samples) {
522 frame->nb_samples = 0;
527 c->streams[
map->stream_idx].out[
map->channel_idx] = (
float*)
frame->extended_data[
i];
531 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
533 float **
out =
s->out;
536 float sync_dummy[32];
559 s->out_size =
frame->linesize[0] - ret *
sizeof(
float);
563 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
572 if (coded_samples !=
s->packet.frame_count *
s->packet.frame_duration) {
574 "Mismatching coded sample count in substream %d.\n",
i);
584 s->decoded_samples = ret;
590 buf +=
s->packet.packet_size;
591 buf_size -=
s->packet.packet_size;
595 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
598 if (buffer_samples) {
599 float *buf[2] = {
s->out[0] ?
s->out[0] : (
float*)
frame->extended_data[0],
600 s->out[1] ?
s->out[1] : (
float*)
frame->extended_data[0] };
614 memcpy(
frame->extended_data[
i],
615 frame->extended_data[
map->copy_idx],
617 }
else if (
map->silence) {
618 memset(
frame->extended_data[
i], 0,
frame->linesize[0]);
622 c->fdsp->vector_fmul_scalar((
float*)
frame->extended_data[
i],
623 (
float*)
frame->extended_data[
i],
638 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
641 memset(&
s->packet, 0,
sizeof(
s->packet));
642 s->delayed_samples = 0;
658 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
665 s->out_dummy_allocated_size = 0;
699 c->gain =
ff_exp10(
c->p.gain_i / (20.0 * 256));
702 c->streams =
av_calloc(
c->p.nb_streams,
sizeof(*
c->streams));
708 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
712 s->output_channels = (
i <
c->p.nb_stereo_streams) ? 2 : 1;
716 for (
int j = 0; j <
s->output_channels; j++) {
717 s->silk_output[j] =
s->silk_buf[j];
718 s->celt_output[j] =
s->celt_buf[j];
719 s->redundancy_output[j] =
s->redundancy_buf[j];
746 s->output_channels, 1024);
751 s->output_channels, 32);
759#define OFFSET(x) offsetof(OpusContext, x)
760#define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
762 {
"apply_phase_inv",
"Apply intensity stereo phase inversion",
OFFSET(apply_phase_inv),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
AD },
767 .class_name =
"Opus Decoder",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_opus_decoder
static av_cold void close(AVCodecParserContext *s)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
void ff_celt_free(CeltFrame **f)
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, int apply_phase_inv)
int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int coded_channels, int frame_size, int startband, int endband)
void ff_celt_flush(CeltFrame *f)
Public libavutil channel layout APIs header.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_EF_EXPLODE
abort decoding on minor error detection
int(* init)(AVBSFContext *ctx)
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
static SDL_Window * window
reference-counted frame API
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#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
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
void av_audio_fifo_reset(AVAudioFifo *af)
Reset the AVAudioFifo buffer.
int av_audio_fifo_write(AVAudioFifo *af, void *const *data, int nb_samples)
Write data to an AVAudioFifo.
int av_audio_fifo_read(AVAudioFifo *af, void *const *data, int nb_samples)
Read data from an AVAudioFifo.
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#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.
const char * av_default_item_name(void *ptr)
Return the context name.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
@ AV_SAMPLE_FMT_FLTP
float, planar
#define LIBAVUTIL_VERSION_INT
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
av_cold void swr_close(SwrContext *s)
Closes the context so that swr_is_initialized() returns 0.
int swr_is_initialized(struct SwrContext *s)
Check whether an swr context has been initialized or not.
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *const *out_arg, int out_count, const uint8_t *const *in_arg, int in_count)
Convert audio.
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *channel_layout, int search_flags)
const VDPAUPixFmtMap * map
Macro definitions for various function/variable attributes.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static int opus_decode_subpacket(OpusStreamContext *s, const uint8_t *buf)
static int get_silk_samplerate(int config)
static int opus_decode_redundancy(OpusStreamContext *s, const uint8_t *data, int size)
static const AVClass opus_class
static const int silk_resample_delay[]
static const AVOption opus_options[]
static int opus_init_resample(OpusStreamContext *s)
static const uint16_t silk_frame_duration_ms[16]
static int opus_flush_resample(OpusStreamContext *s, int nb_samples)
static av_cold int opus_decode_init(AVCodecContext *avctx)
static void opus_fade(float *out, const float *in1, const float *in2, const float *window, int len)
static av_cold void opus_decode_flush(AVCodecContext *ctx)
static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static av_cold int opus_decode_close(AVCodecContext *avctx)
static int opus_decode_frame(OpusStreamContext *s, const uint8_t *data, int size)
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.
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, OpusParseContext *s)
@ OPUS_BANDWIDTH_WIDEBAND
uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size)
CELT: read a uniform distribution.
void ff_opus_rc_dec_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, uint32_t bytes)
int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size)
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
static av_always_inline uint32_t opus_rc_tell(const OpusRangeCoder *rc)
CELT: estimate bits of entropy that have thus far been consumed for the current CELT frame,...
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).
int ff_silk_init(void *logctx, SilkContext **ps, int output_channels)
void ff_silk_flush(SilkContext *s)
void ff_silk_free(SilkContext **ps)
#define FF_ARRAY_ELEMS(a)
Context for an Audio FIFO Buffer.
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
struct OpusStreamContext * streams
float * redundancy_output[2]
OpusRangeCoder redundancy_rc
int out_dummy_allocated_size
float redundancy_buf[2][960]
AVAudioFifo * sync_buffer
The libswresample context.
libswresample public header
const uint8_t ff_celt_band_end[]
const float ff_celt_window2[120]
static AVFormatContext * ctx