Libswresample (lswr) is a library that handles audio resampling, sample format conversion and mixing. More...
These constants are used for the AVOptions interface for lswr.
These functons provide a means to set low-level options that is not possible with the AVOption API.
Libswresample (lswr) is a library that handles audio resampling, sample format conversion and mixing.
Interaction with lswr is done through SwrContext, which is allocated with swr_alloc() or swr_alloc_set_opts(). It is opaque, so all parameters must be set with the AVOptions API.
The first thing you will need to do in order to use lswr is to allocate SwrContext. This can be done with swr_alloc() or swr_alloc_set_opts(). If you are using the former, you must set options through the AVOptions API. The latter function provides the same feature, but it allows you to set some common options in the same statement.
For example the following code will setup conversion from planar float sample format to interleaved signed 16-bit integer, downsampling from 48kHz to 44.1kHz and downmixing from 5.1 channels to stereo (using the default mixing matrix). This is using the swr_alloc() function.
The same job can be done using swr_alloc_set_opts() as well:
Once all values have been set, it must be initialized with swr_init(). If you need to change the conversion parameters, you can change the parameters using AVOptions, as described above in the first example; or by using swr_alloc_set_opts(), but with the first argument the allocated context. You must then call swr_init() again.
The conversion itself is done by repeatedly calling swr_convert(). Note that the samples may get buffered in swr if you provide insufficient output space or if sample rate conversion is done, which requires "future" samples. Samples that do not require future input can be retrieved at any time by using swr_convert() (in_count can be set to 0). At the end of conversion the resampling buffer can be flushed by calling swr_convert() with NULL in and 0 in_count.
The samples used in the conversion process can be managed with the libavutil samples manipulation API, including av_samples_alloc() function used in the following example.
The delay between input and output, can at any time be found by using swr_get_delay().
The following code demonstrates the conversion loop assuming the parameters from above and caller-defined functions get_input() and handle_output():
When the conversion is finished, the conversion context and everything associated with it must be freed with swr_free(). A swr_close() function is also available, but it exists mainly for compatibility with libavresample, and is not required to be called.
There will be no memory leak if the data is not completely flushed before swr_free().
Maximum number of channels.
Definition at line 129 of file swresample.h.
Referenced by audiogen(), auto_matrix(), config_props(), conv_fltp_to_s16_nch_neon(), filter_frame(), main(), query_formats(), sane_layout(), setup_array(), swr_convert(), swr_init(), swr_inject_silence(), and swri_rematrix_init().
Force resampling even if equal sample rate.
Definition at line 139 of file swresample.h.
Referenced by swr_init(), and swr_set_compensation().
Dithering algorithms.
not part of API/ABI
not part of API/ABI
Definition at line 144 of file swresample.h.
Resampling Engines.
SW Resampler.
SoX Resampler.
not part of API/ABI
Definition at line 162 of file swresample.h.
Resampling Filter Types.
Cubic.
Blackman Nuttall Windowed Sinc.
Kaiser Windowed Sinc.
Definition at line 169 of file swresample.h.
Get the AVClass for SwrContext.
It can be used in combination with AV_OPT_SEARCH_FAKE_OBJ for examining options.
Definition at line 143 of file options.c.
Referenced by opt_default(), resample_child_class_next(), and show_help_default().
Allocate SwrContext.
If you use this function you will need to set the parameters (manually or with swr_alloc_set_opts()) before calling swr_init().
Definition at line 148 of file options.c.
Referenced by config_audio_output(), init_dict(), main(), open_audio(), opt_default(), opus_decode_init(), and swr_alloc_set_opts().
Initialize context after user parameters have been set.
Definition at line 126 of file swresample.c.
Referenced by audio_decode_frame(), config_audio_output(), config_output(), config_props(), init_resampler(), main(), open_audio(), opus_init_resample(), and swr_set_compensation().
Check whether an swr context has been initialized or not.
Definition at line 614 of file swresample.c.
Referenced by opus_decode_frame(), opus_decode_subpacket(), and swr_convert().
Allocate SwrContext if needed and set/reset common parameters.
This function does not require s to be allocated with swr_alloc(). On the other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters on the allocated context.
Definition at line 55 of file swresample.c.
Referenced by audio_decode_frame(), config_output(), config_props(), init_resampler(), and main().
Free the given SwrContext and set the pointer to NULL.
Definition at line 111 of file swresample.c.
Referenced by audio_decode_frame(), init_resampler(), main(), opt_default(), opus_decode_close(), stream_component_close(), and uninit().
Closes the context so that swr_is_initialized() returns 0.
The context can be brought back to life by running swr_init(), swr_init() can also be used without swr_close(). This function is mainly provided for simplifying the usecase where one tries to support libavresample and libswresample.
Definition at line 122 of file swresample.c.
Referenced by opus_decode_flush(), and opus_decode_subpacket().
Convert audio.
in and in_count can be set to 0 to flush the last few samples out at the end.
If more input is provided than output space then the input will be buffered. You can avoid this buffering by providing more output space than input. Conversion will run directly without copying whenever possible.
Convert the next timestamp from input to output timestamps are in 1/(in_sample_rate * out_sample_rate) units.
Definition at line 788 of file swresample.c.
Referenced by filter_frame(), and request_frame().
Activate resampling compensation ("soft" compensation).
This function is internally called when needed in swr_next_pts().
s
is NULL, compensation_distance
is less than 0, compensation_distance
is 0 but sample_delta is not, Definition at line 768 of file swresample.c.
Referenced by audio_decode_frame(), and swr_next_pts().
Set a customized input channel mapping.
Definition at line 48 of file swresample.c.
Referenced by config_props().
Set a customized remix matrix.
Definition at line 60 of file rematrix.c.
Referenced by config_props().
Drops the specified number of output samples.
This function, along with swr_inject_silence(), is called by swr_next_pts() if needed for "hard" compensation.
Definition at line 722 of file swresample.c.
Referenced by swr_next_pts().
Injects the specified number of silence samples.
This function, along with swr_drop_output(), is called by swr_next_pts() if needed for "hard" compensation.
Definition at line 732 of file swresample.c.
Referenced by swr_inject_silence(), and swr_next_pts().
Gets the delay the next input sample will experience relative to the next output sample.
Swresample can buffer data if more input has been provided than available output space, also converting between sample rates needs a delay. This function returns the sum of all such delays. The exact delay is not necessarily an integer value in either input or output sample rate. Especially when downsampling by a large value, the output sample rate may be a poor choice to represent the delay, similarly for upsampling and the input sample rate.
base
units. Definition at line 760 of file swresample.c.
Referenced by filter_frame(), main(), swr_next_pts(), and write_audio_frame().
Return the LIBSWRESAMPLE_VERSION_INT constant.
This is useful to check if the build-time libswresample has the same version as the run-time one.
Definition at line 31 of file swresample.c.
Return the swr build-time configuration.
Definition at line 37 of file swresample.c.
Return the swr license.
Definition at line 42 of file swresample.c.