188 "resample_out_buffer");
313 }
else if (converted) {
334 int in_plane_size,
int in_samples)
339 int ret, direct_output;
378 current_buffer = &input_buffer;
390 current_buffer = &output_buffer;
392 (!direct_output || out_samples < in_samples)) {
437 current_buffer =
NULL;
444 resample_out = &output_buffer;
448 current_buffer ? current_buffer->
name :
"null",
461 current_buffer = resample_out;
472 if (current_buffer == &output_buffer) {
478 if (direct_output && out_samples >= current_buffer->
nb_samples) {
555 int out_linesize = 0, in_linesize = 0;
556 int out_nb_samples = 0, in_nb_samples = 0;
572 in_data, in_linesize,
591 if (!bytes_per_sample)
594 samples = out->
linesize[0] / bytes_per_sample;
640 int in_channels, out_channels,
i, o;
659 for (o = 0; o < out_channels; o++)
660 for (i = 0; i < in_channels; i++)
661 matrix[o * stride + i] = avr->
mix_matrix[o * in_channels + i];
669 int in_channels, out_channels,
i, o;
690 for (o = 0; o < out_channels; o++)
691 for (i = 0; i < in_channels; i++)
692 avr->
mix_matrix[o * in_channels + i] = matrix[o * stride + i];
698 const int *channel_map)
701 int in_channels, ch,
i;
709 memset(info, 0,
sizeof(*info));
712 for (ch = 0; ch < in_channels; ch++) {
713 if (channel_map[ch] >= in_channels) {
717 if (channel_map[ch] < 0) {
721 }
else if (info->
input_map[channel_map[ch]] >= 0) {
734 for (ch = 0, i = 0; ch < in_channels && i < in_channels; ch++, i++) {
735 while (ch < in_channels && info->input_map[ch] >= 0)
737 while (i < in_channels && info->channel_map[i] >= 0)
739 if (ch >= in_channels || i >= in_channels)
766 if (samples > INT_MAX)
786 #define LICENSE_PREFIX "libavresample license: " 792 return FFMPEG_CONFIGURATION;
const char * avresample_license(void)
int in_channels
number of input channels
int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix, int stride)
AudioConvert * ac_in
input sample format conversion context
const char * name
name for debug logging
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
int ff_audio_data_realloc(AudioData *a, int nb_samples)
Reallocate AudioData.
This structure describes decoded (raw) audio or video data.
int avresample_open(AVAudioResampleContext *avr)
#define LIBAVRESAMPLE_VERSION_INT
int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
int input_map[AVRESAMPLE_MAX_CHANNELS]
dest index of each input channel
AudioData * out_buffer
buffer for converted output
Audio buffer used for intermediate storage between conversion phases.
attribute_deprecated int avresample_get_delay(AVAudioResampleContext *avr)
static int config_changed(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
Memory handling functions.
int ff_audio_data_add_to_fifo(AVAudioFifo *af, AudioData *a, int offset, int nb_samples)
Add samples in AudioData to an AVAudioFifo.
int do_zero
zeroing needed
AudioData * ff_audio_data_alloc(int channels, int nb_samples, enum AVSampleFormat sample_fmt, const char *name)
Allocate AudioData.
static int convert_frame(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
double * mix_matrix
mix matrix only used if avresample_set_matrix() is called before avresample_open() ...
uint64_t out_channel_layout
output channel layout
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
int attribute_align_arg avresample_convert(AVAudioResampleContext *avr, uint8_t **output, int out_plane_size, int out_samples, uint8_t *const *input, int in_plane_size, int in_samples)
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in)
Convert audio data from one sample format to another.
static void error(const char *err)
int ff_audio_mix(AudioMix *am, AudioData *src)
Apply channel mixing to audio data using the current mixing matrix.
int avresample_convert_frame(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
int channel_zero[AVRESAMPLE_MAX_CHANNELS]
dest index to zero
int nb_samples
current number of samples
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AudioData * in_buffer
buffer for converted input
int allocated_channels
allocated channel count
int out_channels
number of output channels
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
static int handle_buffered_output(AVAudioResampleContext *avr, AudioData *output, AudioData *converted)
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
Set the current mixing matrix.
int ff_sample_fmt_is_planar(enum AVSampleFormat sample_fmt, int channels)
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples)
AudioConvert * ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map)
Allocate and initialize AudioConvert context for sample format conversion.
void avresample_close(AVAudioResampleContext *avr)
AudioMix * am
channel mixing context
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
int ff_audio_data_set_channels(AudioData *a, int channels)
int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
Resample audio data.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int out_convert_needed
output sample format conversion is needed
int ff_audio_data_init(AudioData *a, uint8_t *const *src, int plane_size, int channels, int nb_samples, enum AVSampleFormat sample_fmt, int read_only, const char *name)
Initialize AudioData using a given source.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
void ff_audio_convert_free(AudioConvert **ac)
Free AudioConvert.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
AudioConvert * ac_out
output sample format conversion context
int ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples)
Read samples from an AVAudioFifo to AudioData.
int avresample_available(AVAudioResampleContext *avr)
reference-counted frame API
int channel_copy[AVRESAMPLE_MAX_CHANNELS]
dest index to copy from
uint64_t channel_layout
Channel layout of the audio data.
int upmix_needed
upmixing is needed
ResampleContext * resample
resampling context
int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix, int stride)
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
enum RemapPoint remap_point
const char * avresample_configuration(void)
unsigned avresample_version(void)
#define AVERROR_INPUT_CHANGED
Input changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_OUTPUT_CHANGED) ...
ChannelMapInfo ch_map_info
uint64_t in_channel_layout
input channel layout
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
int in_sample_rate
input sample rate
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int avresample_is_open(AVAudioResampleContext *avr)
void ff_audio_resample_free(ResampleContext **c)
Free a ResampleContext.
AVSampleFormat
Audio sample formats.
AVAudioFifo * out_fifo
FIFO for output samples.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int avresample_set_channel_mapping(AVAudioResampleContext *avr, const int *channel_map)
#define AVRESAMPLE_MAX_CHANNELS
enum AVSampleFormat internal_sample_fmt
internal sample format
int force_resampling
force resampling
void ff_audio_mix_free(AudioMix **am_p)
Free an AudioMix context.
int in_copy_needed
input data copy is needed
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
int sample_rate
Sample rate of the audio data.
ResampleContext * ff_audio_resample_init(AVAudioResampleContext *avr)
Allocate and initialize a ResampleContext.
enum AVSampleFormat in_sample_fmt
input sample format
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted then it is pulled from the input slice through the input converter and horizontal scaler The result is also stored in the ring buffer to serve future vertical scaler requests When no more output can be generated because lines from a future slice would be then all remaining lines in the current slice are converted
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
int in_convert_needed
input sample format conversion is needed
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
int channel_map[AVRESAMPLE_MAX_CHANNELS]
source index of each output channel, -1 if not remapped
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
#define AVERROR_OUTPUT_CHANGED
Output changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_INPUT_CHANGED) ...
enum AVSampleFormat out_sample_fmt
output sample format
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
int ff_audio_data_copy(AudioData *dst, AudioData *src, ChannelMapInfo *map)
Copy data from one AudioData to another.
GLint GLenum GLboolean GLsizei stride
void av_opt_free(void *obj)
Free all allocated objects in obj.
common internal and external API header
int resample_channels
number of channels used for resampling
AudioData * resample_out_buffer
buffer for output from resampler
int resample_needed
resampling is needed
AudioMix * ff_audio_mix_alloc(AVAudioResampleContext *avr)
Allocate and initialize an AudioMix context.
void avresample_free(AVAudioResampleContext **avr)
int allocated_samples
number of samples the buffer can hold
Filter the word “frame” indicates either a video frame or a group of audio samples
int out_sample_rate
output sample rate
void ff_audio_data_free(AudioData **a)
Free AudioData.
int downmix_needed
downmixing is needed
static int available_samples(AVFrame *out)
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
uint8_t ** extended_data
pointers to the data planes/channels.
int nb_samples
number of audio samples (per channel) described by this frame
int mixing_needed
either upmixing or downmixing is needed
int ff_audio_mix_get_matrix(AudioMix *am, double *matrix, int stride)
Get the current mixing matrix.