Go to the documentation of this file.
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));
465 for (j = 0; j <
s->output_channels; j++)
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];
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 },
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
static const int silk_resample_delay[]
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int opus_decode_init(AVCodecContext *avctx)
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
static void opus_fade(float *out, const float *in1, const float *in2, const float *window, int len)
#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
int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int coded_channels, int frame_size, int startband, int endband)
static int opus_decode_subpacket(OpusStreamContext *s, const uint8_t *buf)
#define AV_CHANNEL_LAYOUT_STEREO
int sample_rate
samples per second
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 av_audio_fifo_write(AVAudioFifo *af, void *const *data, int nb_samples)
Write data to an AVAudioFifo.
static av_cold void opus_decode_flush(AVCodecContext *ctx)
This structure describes decoded (raw) audio or video data.
int nb_channels
Number of channels in this layout.
static av_cold void close(AVCodecParserContext *s)
static SDL_Window * window
Context for an Audio FIFO Buffer.
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size)
CELT: read a uniform distribution.
int swr_is_initialized(struct SwrContext *s)
Check whether an swr context has been initialized or not.
float redundancy_buf[2][960]
void ff_silk_free(SilkContext **ps)
static int opus_decode_frame(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.
#define FF_CODEC_DECODE_CB(func)
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, OpusParseContext *s)
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
static AVFormatContext * ctx
AVAudioFifo * sync_buffer
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, int apply_phase_inv)
The libswresample context.
#define CODEC_LONG_NAME(str)
void ff_celt_flush(CeltFrame *f)
static const AVOption opus_options[]
@ OPUS_BANDWIDTH_WIDEBAND
#define LIBAVUTIL_VERSION_INT
static const AVClass opus_class
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.
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
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
void ff_celt_free(CeltFrame **f)
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)
int ff_silk_init(void *logctx, SilkContext **ps, int output_channels)
void ff_silk_flush(SilkContext *s)
static int opus_init_resample(OpusStreamContext *s)
#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.
const FFCodec ff_opus_decoder
An AVChannelLayout holds information about the channel layout of audio data.
#define DECLARE_ALIGNED(n, t, v)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *channel_layout, int search_flags)
#define i(width, name, range_min, range_max)
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.
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.
void ff_opus_rc_dec_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, uint32_t bytes)
static int opus_decode_redundancy(OpusStreamContext *s, const uint8_t *data, int size)
const char * name
Name of the codec implementation.
void * av_calloc(size_t nmemb, size_t size)
int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int 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
main external API structure.
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 const uint16_t silk_frame_duration_ms[16]
#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
const VDPAUPixFmtMap * map
#define AV_CHANNEL_LAYOUT_MONO
static int opus_flush_resample(OpusStreamContext *s, int nb_samples)
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 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.
const uint8_t ff_celt_band_end[]
static int get_silk_samplerate(int config)
static av_cold int opus_decode_close(AVCodecContext *avctx)
float * redundancy_output[2]
void av_audio_fifo_reset(AVAudioFifo *af)
Reset the AVAudioFifo buffer.
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.
void * priv_data
Format private data.
static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
const float ff_celt_window2[120]