Go to the documentation of this file.
   77                       const float *in1, 
const float *in2,
 
   90                       (uint8_t**)
s->cur_out, nb_samples,
 
   94     else if (
ret != nb_samples) {
 
  101         if (celt_size != nb_samples) {
 
  106         for (
i = 0; 
i < 
s->output_channels; 
i++) {
 
  107             s->fdsp->vector_fmac_scalar(
s->cur_out[
i],
 
  108                                         s->celt_output[
i], 1.0,
 
  113     if (
s->redundancy_idx) {
 
  114         for (
i = 0; 
i < 
s->output_channels; 
i++)
 
  116                       s->redundancy_output[
i] + 120 + 
s->redundancy_idx,
 
  118         s->redundancy_idx = 0;
 
  121     s->cur_out[0]         += nb_samples;
 
  122     s->cur_out[1]         += nb_samples;
 
  123     s->remaining_out_size -= nb_samples * 
sizeof(float);
 
  130     static const float delay[16] = { 0.0 };
 
  131     const uint8_t *delayptr[2] = { (uint8_t*)delay, (uint8_t*)delay };
 
  146                "Error feeding initial silence to the resampler.\n");
 
  161                                s->redundancy_output,
 
  162                                s->packet.stereo + 1, 240,
 
  175     int samples    = 
s->packet.frame_duration;
 
  177     int redundancy_size, redundancy_pos;
 
  178     int ret, 
i, consumed;
 
  179     int delayed_samples = 
s->delayed_samples;
 
  195                                             s->packet.stereo + 1,
 
  202                               (uint8_t**)
s->cur_out, 
s->packet.frame_duration,
 
  203                               (
const uint8_t**)
s->silk_output, 
samples);
 
  209         s->delayed_samples += 
s->packet.frame_duration - 
samples;
 
  226             redundancy_size = 
size - (consumed + 7) / 8;
 
  227         size -= redundancy_size;
 
  233         if (redundancy_pos) {
 
  243         float *out_tmp[2] = { 
s->cur_out[0], 
s->cur_out[1] };
 
  245                       out_tmp : 
s->celt_output;
 
  246         int celt_output_samples = 
samples;
 
  253                 for (
i = 0; 
i < 
s->output_channels; 
i++) {
 
  254                     s->fdsp->vector_fmac_scalar(out_tmp[
i], 
s->celt_output[
i], 1.0,
 
  256                     out_tmp[
i] += delay_samples;
 
  258                 celt_output_samples -= delay_samples;
 
  261                        "Spurious CELT delay samples present.\n");
 
  271                                    s->packet.stereo + 1,
 
  272                                    s->packet.frame_duration,
 
  279             int celt_delay = 
s->packet.frame_duration - celt_output_samples;
 
  280             void *delaybuf[2] = { 
s->celt_output[0] + celt_output_samples,
 
  281                                   s->celt_output[1] + celt_output_samples };
 
  283             for (
i = 0; 
i < 
s->output_channels; 
i++) {
 
  284                 s->fdsp->vector_fmac_scalar(out_tmp[
i],
 
  285                                             s->celt_output[
i], 1.0,
 
  286                                             celt_output_samples);
 
  296     if (
s->redundancy_idx) {
 
  297         for (
i = 0; 
i < 
s->output_channels; 
i++)
 
  299                       s->redundancy_output[
i] + 120 + 
s->redundancy_idx,
 
  301         s->redundancy_idx = 0;
 
  304         if (!redundancy_pos) {
 
  310             for (
i = 0; 
i < 
s->output_channels; 
i++) {
 
  312                           s->cur_out[
i] + 
samples - 120 + delayed_samples,
 
  313                           s->redundancy_output[
i] + 120,
 
  316                     s->redundancy_idx = 120 - delayed_samples;
 
  319             for (
i = 0; 
i < 
s->output_channels; 
i++) {
 
  320                 memcpy(
s->cur_out[
i] + delayed_samples, 
s->redundancy_output[
i], 120 * 
sizeof(
float));
 
  322                           s->redundancy_output[
i] + 120,
 
  323                           s->cur_out[
i] + 120 + delayed_samples,
 
  333                                  const uint8_t *buf, 
int buf_size,
 
  336     int output_samples = 0;
 
  337     int flush_needed   = 0;
 
  340     s->cur_out[0]         = 
s->out[0];
 
  341     s->cur_out[1]         = 
s->out[1];
 
  342     s->remaining_out_size = 
s->out_size;
 
  347             int64_t cur_samplerate;
 
  349             flush_needed = (
s->packet.mode == 
OPUS_MODE_CELT) || (cur_samplerate != 
s->silk_samplerate);
 
  351             flush_needed = !!
s->delayed_samples;
 
  355     if (!buf && !flush_needed)
 
  359     if (!
s->cur_out[0] ||
 
  360         (
s->output_channels == 2 && !
s->cur_out[1])) {
 
  362                        s->remaining_out_size);
 
  366             s->cur_out[0] = 
s->out_dummy;
 
  368             s->cur_out[1] = 
s->out_dummy;
 
  379         output_samples += 
s->delayed_samples;
 
  380         s->delayed_samples = 0;
 
  387     for (
i = 0; 
i < 
s->packet.frame_count; 
i++) {
 
  388         int size = 
s->packet.frame_size[
i];
 
  396             for (j = 0; j < 
s->output_channels; j++)
 
  397                 memset(
s->cur_out[j], 0, 
s->packet.frame_duration * 
sizeof(
float));
 
  402         for (j = 0; j < 
s->output_channels; j++)
 
  404         s->remaining_out_size -= 
samples * 
sizeof(
float);
 
  408     s->cur_out[0] = 
s->cur_out[1] = 
NULL;
 
  409     s->remaining_out_size = 0;
 
  411     return output_samples;
 
  415                               int *got_frame_ptr, 
AVPacket *avpkt)
 
  419     const uint8_t *buf  = avpkt->
data;
 
  420     int buf_size        = avpkt->
size;
 
  421     int coded_samples   = 0;
 
  422     int decoded_samples = INT_MAX;
 
  423     int delayed_samples = 0;
 
  427     for (
i = 0; 
i < 
c->nb_streams; 
i++) {
 
  431         delayed_samples = 
FFMAX(delayed_samples,
 
  443         coded_samples += 
pkt->frame_count * 
pkt->frame_duration;
 
  447     frame->nb_samples = coded_samples + delayed_samples;
 
  450     if (!
frame->nb_samples) {
 
  459     frame->nb_samples = 0;
 
  464             c->streams[
map->stream_idx].out[
map->channel_idx] = (
float*)
frame->extended_data[
i];
 
  468     for (
i = 0; 
i < 
c->nb_streams; 
i++) {
 
  470         float          **
out = 
s->out;
 
  473         float sync_dummy[32];
 
  474         int out_dummy = (!
out[0]) | ((!
out[1]) << 1);
 
  496         s->out_size = 
frame->linesize[0] - 
ret * 
sizeof(float);
 
  500     for (
i = 0; 
i < 
c->nb_streams; 
i++) {
 
  509             if (coded_samples != 
s->packet.frame_count * 
s->packet.frame_duration) {
 
  511                        "Mismatching coded sample count in substream %d.\n", 
i);
 
  522         s->decoded_samples = 
ret;
 
  523         decoded_samples       = 
FFMIN(decoded_samples, 
ret);
 
  525         buf      += 
s->packet.packet_size;
 
  526         buf_size -= 
s->packet.packet_size;
 
  530     for (
i = 0; 
i < 
c->nb_streams; 
i++) {
 
  532         int   buffer_samples = 
s->decoded_samples - decoded_samples;
 
  533         if (buffer_samples) {
 
  534             float *buf[2] = { 
s->out[0] ? 
s->out[0] : (
float*)
frame->extended_data[0],
 
  535                               s->out[1] ? 
s->out[1] : (
float*)
frame->extended_data[0] };
 
  536             buf[0] += decoded_samples;
 
  537             buf[1] += decoded_samples;
 
  549             memcpy(
frame->extended_data[
i],
 
  550                    frame->extended_data[
map->copy_idx],
 
  552         } 
else if (
map->silence) {
 
  553             memset(
frame->extended_data[
i], 0, 
frame->linesize[0]);
 
  556         if (
c->gain_i && decoded_samples > 0) {
 
  557             c->fdsp->vector_fmul_scalar((
float*)
frame->extended_data[
i],
 
  558                                        (
float*)
frame->extended_data[
i],
 
  559                                        c->gain, 
FFALIGN(decoded_samples, 8));
 
  563     frame->nb_samples = decoded_samples;
 
  564     *got_frame_ptr    = !!decoded_samples;
 
  574     for (
i = 0; 
i < 
c->nb_streams; 
i++) {
 
  577         memset(&
s->packet, 0, 
sizeof(
s->packet));
 
  578         s->delayed_samples = 0;
 
  595     for (
i = 0; 
i < 
c->nb_streams; 
i++) {
 
  602         s->out_dummy_allocated_size = 0;
 
  637     c->streams = 
av_calloc(
c->nb_streams, 
sizeof(*
c->streams));
 
  643     for (
i = 0; 
i < 
c->nb_streams; 
i++) {
 
  647         s->output_channels = (
i < 
c->nb_stereo_streams) ? 2 : 1;
 
  651         for (j = 0; j < 
s->output_channels; j++) {
 
  652             s->silk_output[j]       = 
s->silk_buf[j];
 
  653             s->celt_output[j]       = 
s->celt_buf[j];
 
  654             s->redundancy_output[j] = 
s->redundancy_buf[j];
 
  680                                             s->output_channels, 1024);
 
  685                                              s->output_channels, 32);
 
  693 #define OFFSET(x) offsetof(OpusContext, x) 
  694 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM 
  696     { 
"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.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
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 sample_rate
samples per second
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, OpusContext *s)
void ff_celt_flush(CeltFrame *f)
#define AV_CH_LAYOUT_MONO
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 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 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 uint16_t silk_frame_duration_ms[16]
static const AVOption opus_options[]
static SDL_Window * window
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.
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)
#define AV_CH_LAYOUT_STEREO
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, int apply_phase_inv)
#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.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
const uint8_t ff_celt_band_end[]
uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size)
CELT: read a uniform distribution.
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
int ff_silk_init(AVCodecContext *avctx, SilkContext **ps, int output_channels)
static int opus_flush_resample(OpusStreamContext *s, int nb_samples)
void ff_silk_flush(SilkContext *s)
@ OPUS_BANDWIDTH_WIDEBAND
#define LIBAVUTIL_VERSION_INT
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).
Describe the class of an AVClass context structure.
static void flush(AVCodecContext *avctx)
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 av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
#define AV_EF_EXPLODE
abort decoding on minor error detection
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.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int get_silk_samplerate(int config)
enum AVSampleFormat sample_fmt
audio sample format
void ff_celt_free(CeltFrame **f)
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t **out_arg, int out_count, const uint8_t **in_arg, int in_count)
Convert audio.
const float ff_celt_window2[120]
int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size)
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
int channels
number of audio channels
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
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define i(width, name, range_min, range_max)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int channels, int frame_size, int start_band, int end_band)
static int opus_decode_subpacket(OpusStreamContext *s, const uint8_t *buf, int buf_size, int nb_samples)
main external API structure.
static int opus_decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
const AVCodec ff_opus_decoder
#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
This structure stores compressed data.
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.
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
void ff_silk_free(SilkContext **ps)
void * priv_data
Format private data.