150 const float *in1,
const float *in2,
163 (uint8_t**)
s->cur_out, nb_samples,
167 else if (
ret != nb_samples) {
174 if (celt_size != nb_samples) {
179 for (
i = 0;
i <
s->output_channels;
i++) {
180 s->fdsp->vector_fmac_scalar(
s->cur_out[
i],
181 s->celt_output[
i], 1.0,
186 if (
s->redundancy_idx) {
187 for (
i = 0;
i <
s->output_channels;
i++)
189 s->redundancy_output[
i] + 120 +
s->redundancy_idx,
191 s->redundancy_idx = 0;
194 for (
i = 0;
i <
s->output_channels;
i++)
195 s->cur_out[
i] += nb_samples;
196 s->remaining_out_size -= nb_samples *
sizeof(
float);
203 static const float delay[16] = { 0.0 };
204 const uint8_t *delayptr[2] = { (uint8_t*)delay, (uint8_t*)delay };
221 "Error feeding initial silence to the resampler.\n");
236 s->redundancy_output,
237 s->packet.stereo + 1, 240,
250 int samples =
s->packet.frame_duration;
252 int redundancy_size, redundancy_pos;
253 int ret,
i, consumed;
270 s->packet.stereo + 1,
277 (uint8_t**)
s->cur_out,
s->packet.frame_duration,
278 (
const uint8_t**)
s->silk_output, samples);
284 s->delayed_samples +=
s->packet.frame_duration - samples;
301 redundancy_size =
size - (consumed + 7) / 8;
302 size -= redundancy_size;
308 if (redundancy_pos) {
318 float *out_tmp[2] = {
s->cur_out[0],
s->cur_out[1] };
320 out_tmp :
s->celt_output;
321 int celt_output_samples = samples;
328 for (
i = 0;
i <
s->output_channels;
i++) {
329 s->fdsp->vector_fmac_scalar(out_tmp[
i],
s->celt_output[
i], 1.0,
331 out_tmp[
i] += delay_samples;
333 celt_output_samples -= delay_samples;
336 "Spurious CELT delay samples present.\n");
346 s->packet.stereo + 1,
347 s->packet.frame_duration,
354 int celt_delay =
s->packet.frame_duration - celt_output_samples;
357 for (
i = 0;
i <
s->output_channels;
i++) {
358 delaybuf[
i] =
s->celt_output[
i] + celt_output_samples;
359 s->fdsp->vector_fmac_scalar(out_tmp[
i],
360 s->celt_output[
i], 1.0,
361 celt_output_samples);
371 if (
s->redundancy_idx) {
372 for (
i = 0;
i <
s->output_channels;
i++)
374 s->redundancy_output[
i] + 120 +
s->redundancy_idx,
376 s->redundancy_idx = 0;
379 if (!redundancy_pos) {
385 for (
i = 0;
i <
s->output_channels;
i++) {
388 s->redundancy_output[
i] + 120,
394 for (
i = 0;
i <
s->output_channels;
i++) {
397 s->redundancy_output[
i] + 120,
409 int output_samples = 0;
410 int flush_needed = 0;
413 s->cur_out[0] =
s->out[0];
414 s->cur_out[1] =
s->out[1];
415 s->remaining_out_size =
s->out_size;
422 flush_needed = (
s->packet.mode ==
OPUS_MODE_CELT) || (cur_samplerate !=
s->silk_samplerate);
424 flush_needed = !!
s->delayed_samples;
428 if (!buf && !flush_needed)
432 if (!
s->cur_out[0] ||
433 (
s->output_channels == 2 && !
s->cur_out[1])) {
435 s->remaining_out_size);
439 s->cur_out[0] =
s->out_dummy;
441 s->cur_out[1] =
s->out_dummy;
452 output_samples +=
s->delayed_samples;
453 s->delayed_samples = 0;
460 for (
i = 0;
i <
s->packet.frame_count;
i++) {
461 int size =
s->packet.frame_size[
i];
469 for (j = 0; j <
s->output_channels; j++)
470 memset(
s->cur_out[j], 0,
s->packet.frame_duration *
sizeof(
float));
471 samples =
s->packet.frame_duration;
473 output_samples += samples;
475 for (j = 0; j <
s->output_channels; j++)
476 s->cur_out[j] += samples;
477 s->remaining_out_size -= samples *
sizeof(
float);
481 s->cur_out[0] =
s->cur_out[1] =
NULL;
482 s->remaining_out_size = 0;
484 return output_samples;
493 float *
out[2] = {
s->out[0],
s->out[1] };
497 for (
int i = 0;
i < 2;
i++)
525 return sd && sd_size >= 8 &&
AV_RL32(sd + 4);
530 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
537 s->out_dummy_allocated_size = 0;
562 const uint8_t *
header,
int header_size)
572 c->gain =
ff_exp10(
c->p.gain_i / (20.0 * 256));
575 c->streams =
av_calloc(
c->p.nb_streams,
sizeof(*
c->streams));
581 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
585 s->output_channels = (
i <
c->p.nb_stereo_streams) ? 2 : 1;
589 for (
int j = 0; j <
s->output_channels; j++) {
590 s->silk_output[j] =
s->silk_buf[j];
591 s->celt_output[j] =
s->celt_buf[j];
592 s->redundancy_output[j] =
s->redundancy_buf[j];
618 s->output_channels, 1024);
623 s->output_channels, 32);
647 int *got_frame_ptr,
AVPacket *avpkt)
650 const uint8_t *buf = avpkt->
data;
651 int buf_size = avpkt->
size;
652 int coded_samples = 0;
655 const uint8_t *new_header;
656 size_t new_header_size;
663 if (new_header_size > INT_MAX)
676 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
682 s->delayed_samples + fifo_samples);
693 coded_samples +=
pkt->frame_count *
pkt->frame_duration;
697 frame->sample_rate = 48000;
701 if (!
frame->nb_samples) {
710 frame->nb_samples = 0;
715 c->streams[
map->stream_idx].out[
map->channel_idx] = (
float*)
frame->extended_data[
i];
719 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
721 float **
out =
s->out;
724 float sync_dummy[32];
751 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
760 if (coded_samples !=
s->packet.frame_count *
s->packet.frame_duration) {
762 "Mismatching coded sample count in substream %d.\n",
i);
774 s->decoded_samples =
ret;
780 buf +=
s->packet.packet_size;
781 buf_size -=
s->packet.packet_size;
785 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
788 if (buffer_samples) {
789 float *buf[2] = {
s->out[0] ?
s->out[0] : (
float*)
frame->extended_data[0],
790 s->out[1] ?
s->out[1] : (
float*)
frame->extended_data[0] };
804 memcpy(
frame->extended_data[
i],
805 frame->extended_data[
map->copy_idx],
807 }
else if (
map->silence) {
808 memset(
frame->extended_data[
i], 0,
frame->linesize[0]);
812 c->fdsp->vector_fmul_scalar((
float*)
frame->extended_data[
i],
813 (
float*)
frame->extended_data[
i],
828 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
831 memset(&
s->packet, 0,
sizeof(
s->packet));
832 s->delayed_samples = 0;
844#define OFFSET(x) offsetof(OpusContext, x)
845#define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
847 {
"apply_phase_inv",
"Apply intensity stereo phase inversion",
OFFSET(apply_phase_inv),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
AD },
852 .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 AVFormatContext * ctx
static int decoded_samples(uint32_t skip, uint32_t discard)
#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.
@ AV_PKT_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
#define AV_PKT_FLAG_EOS
The packet ends a sequence: the next packet, if any, does not continue its decoder state.
#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
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
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 opus_packet_ends_sequence(const AVPacket *pkt)
Whether a packet ends the sequence it belongs to: it is flagged so, or samples are to be discarded fr...
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 int opus_drain_subpacket(OpusStreamContext *s, int decoded_samples)
Append the samples the resampler holds back to the output of the sub-packet that just decoded,...
static const int silk_resample_delay[]
static const int silk_resample_filter_size[]
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)
static av_cold int opus_init_streams(AVCodecContext *avctx, const uint8_t *header, int header_size)
static av_cold void opus_free_streams(OpusContext *c)
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, const uint8_t *header, int header_size)
@ 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,...
static const uint8_t header[24]
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
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.
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]