Go to the documentation of this file.
188 "resample_out_buffer");
311 output->allocated_samples);
324 return output->nb_samples;
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;
559 out_data =
out->extended_data;
560 out_linesize =
out->linesize[0];
561 out_nb_samples =
out->nb_samples;
565 in_data =
in->extended_data;
566 in_linesize =
in->linesize[0];
567 in_nb_samples =
in->nb_samples;
572 in_data, in_linesize,
591 if (!bytes_per_sample)
594 samples =
out->linesize[0] / bytes_per_sample;
621 if (!
out->linesize[0]) {
629 if (!
out->nb_samples)
640 int in_channels, out_channels,
i, o;
659 for (o = 0; o < out_channels; o++)
660 for (
i = 0;
i < 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++)
698 const int *channel_map)
701 int in_channels, ch,
i;
710 memset(
info->input_map, -1,
sizeof(
info->input_map));
712 for (ch = 0; ch < in_channels; ch++) {
713 if (channel_map[ch] >= in_channels) {
717 if (channel_map[ch] < 0) {
718 info->channel_zero[ch] = 1;
719 info->channel_map[ch] = -1;
721 }
else if (
info->input_map[channel_map[ch]] >= 0) {
722 info->channel_copy[ch] =
info->input_map[channel_map[ch]];
723 info->channel_map[ch] = -1;
726 info->channel_map[ch] = channel_map[ch];
727 info->input_map[channel_map[ch]] = ch;
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)
741 info->input_map[ch] =
i;
786 #define LICENSE_PREFIX "libavresample license: "
792 return FFMPEG_CONFIGURATION;
static void error(const char *err)
enum AVSampleFormat in_sample_fmt
input sample format
double * mix_matrix
mix matrix only used if avresample_set_matrix() is called before avresample_open()
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
@ AV_SAMPLE_FMT_FLTP
float, planar
void ff_audio_convert_free(AudioConvert **ac)
Free AudioConvert.
int in_convert_needed
input sample format conversion is needed
int ff_sample_fmt_is_planar(enum AVSampleFormat sample_fmt, int 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 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 av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
int downmix_needed
downmixing is needed
AudioData * ff_audio_data_alloc(int channels, int nb_samples, enum AVSampleFormat sample_fmt, const char *name)
Allocate AudioData.
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_data_set_channels(AudioData *a, int channels)
#define AVRESAMPLE_MAX_CHANNELS
int ff_audio_data_add_to_fifo(AVAudioFifo *af, AudioData *a, int offset, int nb_samples)
Add samples in AudioData to an AVAudioFifo.
This structure describes decoded (raw) audio or video data.
int out_channels
number of output channels
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
void ff_audio_resample_free(ResampleContext **c)
Free a ResampleContext.
int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
Set the current mixing matrix.
void ff_audio_data_free(AudioData **a)
Free AudioData.
int ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples)
Read samples from an AVAudioFifo to AudioData.
attribute_deprecated int avresample_get_delay(AVAudioResampleContext *avr)
int avresample_convert_frame(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
Audio buffer used for intermediate storage between conversion phases.
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
ChannelMapInfo ch_map_info
@ AV_ROUND_UP
Round toward +infinity.
int ff_audio_mix(AudioMix *am, AudioData *src)
Apply channel mixing to audio data using the current mixing matrix.
int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples)
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AudioData * in_buffer
buffer for converted input
AudioConvert * ac_out
output sample format conversion context
int channel_map[AVRESAMPLE_MAX_CHANNELS]
source index of each output channel, -1 if not remapped
AudioConvert * ac_in
input sample format conversion context
int avresample_open(AVAudioResampleContext *avr)
const char * avresample_license(void)
static int convert_frame(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
int avresample_set_channel_mapping(AVAudioResampleContext *avr, const int *channel_map)
#define AVERROR_INPUT_CHANGED
Input changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_OUTPUT_CHANGED)
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int in_copy_needed
input data copy is needed
int upmix_needed
upmixing is needed
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.
ResampleContext * ff_audio_resample_init(AVAudioResampleContext *avr)
Allocate and initialize a ResampleContext.
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
int out_convert_needed
output sample format conversion is needed
void av_opt_free(void *obj)
Free all allocated objects in obj.
AudioData * resample_out_buffer
buffer for output from resampler
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
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the 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.
void avresample_free(AVAudioResampleContext **avr)
static int handle_buffered_output(AVAudioResampleContext *avr, AudioData *output, AudioData *converted)
ResampleContext * resample
resampling context
int channel_copy[AVRESAMPLE_MAX_CHANNELS]
dest index to copy from
const char * name
name for debug logging
int force_resampling
force resampling
#define AVERROR_OUTPUT_CHANGED
Output changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_INPUT_CHANGED)
#define LIBAVRESAMPLE_VERSION_INT
int out_sample_rate
output sample rate
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)
static int config_changed(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
AudioMix * am
channel mixing context
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
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
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
enum AVSampleFormat out_sample_fmt
output sample format
unsigned avresample_version(void)
void avresample_close(AVAudioResampleContext *avr)
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 av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
uint64_t in_channel_layout
input channel layout
int avresample_available(AVAudioResampleContext *avr)
int in_channels
number of input channels
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
static int available_samples(AVFrame *out)
int allocated_channels
allocated channel count
int in_sample_rate
input sample rate
void ff_audio_mix_free(AudioMix **am_p)
Free an AudioMix context.
int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix, int stride)
AVSampleFormat
Audio sample formats.
int resample_needed
resampling is needed
int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix, int stride)
AudioMix * ff_audio_mix_alloc(AVAudioResampleContext *avr)
Allocate and initialize an AudioMix context.
int avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
int input_map[AVRESAMPLE_MAX_CHANNELS]
dest index of each input channel
int nb_samples
current number of samples
AVAudioFifo * out_fifo
FIFO for output samples
AudioData * out_buffer
buffer for converted output
int ff_audio_data_realloc(AudioData *a, int nb_samples)
Reallocate AudioData.
enum AVSampleFormat internal_sample_fmt
internal sample format
enum RemapPoint remap_point
@ AV_SAMPLE_FMT_DBLP
double, planar
Filter the word “frame” indicates either a video frame or a group of audio 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.
int ff_audio_mix_get_matrix(AudioMix *am, double *matrix, int stride)
Get the current mixing matrix.
int mixing_needed
either upmixing or downmixing is needed
int channel_zero[AVRESAMPLE_MAX_CHANNELS]
dest index to zero
int resample_channels
number of channels used for resampling
int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
Resample audio data.
int do_zero
zeroing needed
int avresample_is_open(AVAudioResampleContext *avr)
const char * avresample_configuration(void)
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.
int ff_audio_data_copy(AudioData *dst, AudioData *src, ChannelMapInfo *map)
Copy data from one AudioData to another.
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in)
Convert audio data from one sample format to another.
uint64_t out_channel_layout
output channel layout