Go to the documentation of this file.
141 const float *in1,
const float *in2,
154 (uint8_t**)
s->cur_out, nb_samples,
158 else if (
ret != nb_samples) {
165 if (celt_size != nb_samples) {
170 for (
i = 0;
i <
s->output_channels;
i++) {
171 s->fdsp->vector_fmac_scalar(
s->cur_out[
i],
172 s->celt_output[
i], 1.0,
177 if (
s->redundancy_idx) {
178 for (
i = 0;
i <
s->output_channels;
i++)
180 s->redundancy_output[
i] + 120 +
s->redundancy_idx,
182 s->redundancy_idx = 0;
185 s->cur_out[0] += nb_samples;
186 s->cur_out[1] += nb_samples;
187 s->remaining_out_size -= nb_samples *
sizeof(
float);
194 static const float delay[16] = { 0.0 };
195 const uint8_t *delayptr[2] = { (uint8_t*)delay, (uint8_t*)delay };
210 "Error feeding initial silence to the resampler.\n");
225 s->redundancy_output,
226 s->packet.stereo + 1, 240,
239 int samples =
s->packet.frame_duration;
241 int redundancy_size, redundancy_pos;
242 int ret,
i, consumed;
259 s->packet.stereo + 1,
266 (uint8_t**)
s->cur_out,
s->packet.frame_duration,
267 (
const uint8_t**)
s->silk_output,
samples);
273 s->delayed_samples +=
s->packet.frame_duration -
samples;
290 redundancy_size =
size - (consumed + 7) / 8;
291 size -= redundancy_size;
297 if (redundancy_pos) {
307 float *out_tmp[2] = {
s->cur_out[0],
s->cur_out[1] };
309 out_tmp :
s->celt_output;
310 int celt_output_samples =
samples;
317 for (
i = 0;
i <
s->output_channels;
i++) {
318 s->fdsp->vector_fmac_scalar(out_tmp[
i],
s->celt_output[
i], 1.0,
320 out_tmp[
i] += delay_samples;
322 celt_output_samples -= delay_samples;
325 "Spurious CELT delay samples present.\n");
335 s->packet.stereo + 1,
336 s->packet.frame_duration,
343 int celt_delay =
s->packet.frame_duration - celt_output_samples;
344 void *delaybuf[2] = {
s->celt_output[0] + celt_output_samples,
345 s->celt_output[1] + celt_output_samples };
347 for (
i = 0;
i <
s->output_channels;
i++) {
348 s->fdsp->vector_fmac_scalar(out_tmp[
i],
349 s->celt_output[
i], 1.0,
350 celt_output_samples);
360 if (
s->redundancy_idx) {
361 for (
i = 0;
i <
s->output_channels;
i++)
363 s->redundancy_output[
i] + 120 +
s->redundancy_idx,
365 s->redundancy_idx = 0;
368 if (!redundancy_pos) {
374 for (
i = 0;
i <
s->output_channels;
i++) {
377 s->redundancy_output[
i] + 120,
383 for (
i = 0;
i <
s->output_channels;
i++) {
386 s->redundancy_output[
i] + 120,
397 const uint8_t *buf,
int buf_size,
400 int output_samples = 0;
401 int flush_needed = 0;
404 s->cur_out[0] =
s->out[0];
405 s->cur_out[1] =
s->out[1];
406 s->remaining_out_size =
s->out_size;
413 flush_needed = (
s->packet.mode ==
OPUS_MODE_CELT) || (cur_samplerate !=
s->silk_samplerate);
415 flush_needed = !!
s->delayed_samples;
419 if (!buf && !flush_needed)
423 if (!
s->cur_out[0] ||
424 (
s->output_channels == 2 && !
s->cur_out[1])) {
426 s->remaining_out_size);
430 s->cur_out[0] =
s->out_dummy;
432 s->cur_out[1] =
s->out_dummy;
443 output_samples +=
s->delayed_samples;
444 s->delayed_samples = 0;
451 for (
i = 0;
i <
s->packet.frame_count;
i++) {
452 int size =
s->packet.frame_size[
i];
460 for (j = 0; j <
s->output_channels; j++)
461 memset(
s->cur_out[j], 0,
s->packet.frame_duration *
sizeof(
float));
466 for (j = 0; j <
s->output_channels; j++)
468 s->remaining_out_size -=
samples *
sizeof(
float);
472 s->cur_out[0] =
s->cur_out[1] =
NULL;
473 s->remaining_out_size = 0;
475 return output_samples;
479 int *got_frame_ptr,
AVPacket *avpkt)
482 const uint8_t *buf = avpkt->
data;
483 int buf_size = avpkt->
size;
484 int coded_samples = 0;
490 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
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];
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);
585 s->decoded_samples =
ret;
588 buf +=
s->packet.packet_size;
589 buf_size -=
s->packet.packet_size;
593 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
596 if (buffer_samples) {
597 float *buf[2] = {
s->out[0] ?
s->out[0] : (
float*)
frame->extended_data[0],
598 s->out[1] ?
s->out[1] : (
float*)
frame->extended_data[0] };
612 memcpy(
frame->extended_data[
i],
613 frame->extended_data[
map->copy_idx],
615 }
else if (
map->silence) {
616 memset(
frame->extended_data[
i], 0,
frame->linesize[0]);
620 c->fdsp->vector_fmul_scalar((
float*)
frame->extended_data[
i],
621 (
float*)
frame->extended_data[
i],
636 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
639 memset(&
s->packet, 0,
sizeof(
s->packet));
640 s->delayed_samples = 0;
656 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
663 s->out_dummy_allocated_size = 0;
697 c->gain =
ff_exp10(
c->p.gain_i / (20.0 * 256));
700 c->streams =
av_calloc(
c->p.nb_streams,
sizeof(*
c->streams));
706 for (
int i = 0;
i <
c->p.nb_streams;
i++) {
710 s->output_channels = (
i <
c->p.nb_stereo_streams) ? 2 : 1;
714 for (
int j = 0; j <
s->output_channels; j++) {
715 s->silk_output[j] =
s->silk_buf[j];
716 s->celt_output[j] =
s->celt_buf[j];
717 s->redundancy_output[j] =
s->redundancy_buf[j];
744 s->output_channels, 1024);
749 s->output_channels, 32);
757 #define OFFSET(x) offsetof(OpusContext, x)
758 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
760 {
"apply_phase_inv",
"Apply intensity stereo phase inversion",
OFFSET(apply_phase_inv),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
AD },
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define AV_CHANNEL_LAYOUT_STEREO
int sample_rate
samples per second
int av_audio_fifo_write(AVAudioFifo *af, void *const *data, int nb_samples)
Write data to an AVAudioFifo.
const FFCodec ff_opus_decoder
static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static int opus_decode_frame(OpusStreamContext *s, const uint8_t *data, int size)
This structure describes decoded (raw) audio or video data.
static av_cold int opus_decode_close(AVCodecContext *avctx)
int nb_channels
Number of channels in this layout.
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,...
void ff_celt_flush(CeltFrame *f)
static const uint16_t silk_frame_duration_ms[16]
int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int coded_channels, int frame_size, int startband, int endband)
static const AVOption opus_options[]
static SDL_Window * window
void ff_silk_flush(SilkContext *s)
Context for an Audio FIFO Buffer.
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
int swr_is_initialized(struct SwrContext *s)
Check whether an swr context has been initialized or not.
float redundancy_buf[2][960]
static void opus_fade(float *out, const float *in1, const float *in2, const float *window, int len)
static int opus_decode_redundancy(OpusStreamContext *s, const uint8_t *data, int size)
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
const uint8_t ff_celt_band_end[]
#define FF_CODEC_DECODE_CB(func)
uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size)
CELT: read a uniform distribution.
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
static int opus_flush_resample(OpusStreamContext *s, int nb_samples)
AVAudioFifo * sync_buffer
The libswresample context.
#define CODEC_LONG_NAME(str)
@ OPUS_BANDWIDTH_WIDEBAND
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
const char * av_default_item_name(void *ptr)
Return the context name.
int out_dummy_allocated_size
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
OpusRangeCoder redundancy_rc
int ff_silk_init(void *logctx, SilkContext **ps, int output_channels)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
static const AVClass opus_class
static av_cold int opus_decode_init(AVCodecContext *avctx)
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
An AVChannelLayout holds information about the channel layout of audio data.
#define DECLARE_ALIGNED(n, t, v)
int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *channel_layout, int search_flags)
static int get_silk_samplerate(int config)
enum AVSampleFormat sample_fmt
audio sample format
int av_audio_fifo_read(AVAudioFifo *af, void *const *data, int nb_samples)
Read data from an AVAudioFifo.
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
const float ff_celt_window2[120]
int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size)
struct OpusStreamContext * streams
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define i(width, name, range_min, range_max)
void ff_silk_free(SilkContext **ps)
void ff_opus_rc_dec_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, uint32_t bytes)
static av_cold void opus_decode_flush(AVCodecContext *ctx)
const char * name
Name of the codec implementation.
void * av_calloc(size_t nmemb, size_t size)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static int opus_decode_subpacket(OpusStreamContext *s, const uint8_t *buf, int buf_size, int nb_samples)
main external API structure.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Filter the word “frame” indicates either a video frame or a group of audio samples
static int opus_init_resample(OpusStreamContext *s)
static const int silk_resample_delay[]
const VDPAUPixFmtMap * map
#define AV_CHANNEL_LAYOUT_MONO
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, OpusParseContext *s)
void ff_celt_free(CeltFrame **f)
av_cold void swr_close(SwrContext *s)
Closes the context so that swr_is_initialized() returns 0.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
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).
float * redundancy_output[2]
void * priv_data
Format private data.
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.
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, int apply_phase_inv)