77 const float *in1,
const float *in2,
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 };
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++) {
311 opus_fade(
s->cur_out[
i] + samples - 120 + delayed_samples,
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;
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));
398 samples =
s->packet.frame_duration;
400 output_samples += samples;
402 for (j = 0; j <
s->output_channels; j++)
403 s->cur_out[j] += samples;
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)
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;
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);
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) {
536 buf[0] += decoded_samples;
537 buf[1] += decoded_samples;
552 }
else if (
map->silence) {
556 if (
c->gain_i && decoded_samples > 0) {
559 c->gain,
FFALIGN(decoded_samples, 8));
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;
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];
675 ret =
ff_celt_init(avctx, &
s->celt,
s->output_channels,
c->apply_phase_inv);
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 },
static void flush(AVCodecContext *avctx)
Macro definitions for various function/variable attributes.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Libavcodec external API header.
#define AV_EF_EXPLODE
abort decoding on minor error detection
static av_cold int init(AVCodecContext *avctx)
audio channel layout utility functions
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static SDL_Window * window
bitstream reader API header.
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
#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.
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
#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.
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
@ AV_SAMPLE_FMT_FLTP
float, planar
#define LIBAVUTIL_VERSION_INT
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.
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
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)
const VDPAUPixFmtMap * map
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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, OpusContext *s)
@ OPUS_BANDWIDTH_WIDEBAND
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).
void ff_silk_flush(SilkContext *s)
void ff_silk_free(SilkContext **ps)
int ff_silk_init(AVCodecContext *avctx, SilkContext **ps, int output_channels)
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 channels, int frame_size, int start_band, int end_band)
void ff_celt_flush(CeltFrame *f)
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 int opus_decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
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 av_cold int opus_decode_close(AVCodecContext *avctx)
static int opus_decode_frame(OpusStreamContext *s, const uint8_t *data, int size)
static int opus_decode_subpacket(OpusStreamContext *s, const uint8_t *buf, int buf_size, int nb_samples)
const uint8_t ff_celt_band_end[]
const float ff_celt_window2[120]
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
int channels
number of audio channels
const char * name
Name of the codec implementation.
void * priv_data
Format private data.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count, const uint8_t *in_arg[SWR_CH_MAX], int in_count)
libswresample public header