2011-09-19 04:13:30 +00:00
|
|
|
/*
|
2013-01-09 17:30:01 +00:00
|
|
|
* Copyright (C) 2011-2013 Michael Niedermayer (michaelni@gmx.at)
|
2011-09-19 04:13:30 +00:00
|
|
|
*
|
|
|
|
* This file is part of libswresample
|
|
|
|
*
|
|
|
|
* libswresample is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* libswresample is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with libswresample; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2012-11-19 22:46:34 +00:00
|
|
|
#ifndef SWRESAMPLE_SWRESAMPLE_H
|
|
|
|
#define SWRESAMPLE_SWRESAMPLE_H
|
|
|
|
|
2011-11-17 10:20:29 +00:00
|
|
|
/**
|
|
|
|
* @file
|
2012-12-11 00:53:01 +00:00
|
|
|
* @ingroup lswr
|
2011-11-17 10:20:29 +00:00
|
|
|
* libswresample public header
|
|
|
|
*/
|
|
|
|
|
2012-11-19 22:46:34 +00:00
|
|
|
/**
|
2016-08-03 05:05:27 +00:00
|
|
|
* @defgroup lswr libswresample
|
2012-11-19 22:46:34 +00:00
|
|
|
* @{
|
|
|
|
*
|
2016-08-03 05:05:27 +00:00
|
|
|
* Audio resampling, sample format conversion and mixing library.
|
2012-11-19 22:46:34 +00:00
|
|
|
*
|
|
|
|
* Interaction with lswr is done through SwrContext, which is
|
2021-08-27 03:37:53 +00:00
|
|
|
* allocated with swr_alloc() or swr_alloc_set_opts2(). It is opaque, so all parameters
|
2012-11-19 22:46:34 +00:00
|
|
|
* must be set with the @ref avoptions API.
|
|
|
|
*
|
2014-07-06 16:53:55 +00:00
|
|
|
* The first thing you will need to do in order to use lswr is to allocate
|
2021-08-27 03:37:53 +00:00
|
|
|
* SwrContext. This can be done with swr_alloc() or swr_alloc_set_opts2(). If you
|
2014-07-06 16:53:55 +00:00
|
|
|
* are using the former, you must set options through the @ref avoptions API.
|
|
|
|
* The latter function provides the same feature, but it allows you to set some
|
|
|
|
* common options in the same statement.
|
|
|
|
*
|
2012-11-19 22:46:34 +00:00
|
|
|
* 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
|
2014-07-06 16:53:55 +00:00
|
|
|
* matrix). This is using the swr_alloc() function.
|
2012-11-19 22:46:34 +00:00
|
|
|
* @code
|
|
|
|
* SwrContext *swr = swr_alloc();
|
2024-07-02 04:42:14 +00:00
|
|
|
* av_opt_set_chlayout(swr, "in_chlayout", &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1, 0);
|
|
|
|
* av_opt_set_chlayout(swr, "out_chlayout", &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO, 0);
|
2012-11-19 22:46:34 +00:00
|
|
|
* av_opt_set_int(swr, "in_sample_rate", 48000, 0);
|
|
|
|
* av_opt_set_int(swr, "out_sample_rate", 44100, 0);
|
2012-12-16 20:04:54 +00:00
|
|
|
* av_opt_set_sample_fmt(swr, "in_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
|
|
|
|
* av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
|
2012-11-19 22:46:34 +00:00
|
|
|
* @endcode
|
|
|
|
*
|
2021-08-27 03:37:53 +00:00
|
|
|
* The same job can be done using swr_alloc_set_opts2() as well:
|
2014-07-06 16:53:55 +00:00
|
|
|
* @code
|
2021-08-27 03:37:53 +00:00
|
|
|
* SwrContext *swr = NULL;
|
|
|
|
* int ret = swr_alloc_set_opts2(&swr, // we're allocating a new context
|
|
|
|
* &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO, // out_ch_layout
|
2014-07-06 16:53:55 +00:00
|
|
|
* AV_SAMPLE_FMT_S16, // out_sample_fmt
|
|
|
|
* 44100, // out_sample_rate
|
2021-08-27 03:37:53 +00:00
|
|
|
* &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1, // in_ch_layout
|
2014-07-06 16:53:55 +00:00
|
|
|
* AV_SAMPLE_FMT_FLTP, // in_sample_fmt
|
|
|
|
* 48000, // in_sample_rate
|
|
|
|
* 0, // log_offset
|
|
|
|
* NULL); // log_ctx
|
|
|
|
* @endcode
|
|
|
|
*
|
2012-11-19 22:46:34 +00:00
|
|
|
* 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
|
2022-09-24 18:55:28 +00:00
|
|
|
* using @ref avoptions, as described above in the first example; or by using
|
2021-08-27 03:37:53 +00:00
|
|
|
* swr_alloc_set_opts2(), but with the first argument the allocated context.
|
2014-07-06 16:53:55 +00:00
|
|
|
* You must then call swr_init() again.
|
2012-11-19 22:46:34 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2014-07-06 16:53:55 +00:00
|
|
|
* The samples used in the conversion process can be managed with the libavutil
|
|
|
|
* @ref lavu_sampmanip "samples manipulation" API, including av_samples_alloc()
|
|
|
|
* function used in the following example.
|
|
|
|
*
|
2012-11-19 22:46:34 +00:00
|
|
|
* 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():
|
|
|
|
* @code
|
|
|
|
* uint8_t **input;
|
|
|
|
* int in_samples;
|
|
|
|
*
|
|
|
|
* while (get_input(&input, &in_samples)) {
|
2012-11-20 19:29:05 +00:00
|
|
|
* uint8_t *output;
|
2012-11-19 22:46:34 +00:00
|
|
|
* int out_samples = av_rescale_rnd(swr_get_delay(swr, 48000) +
|
|
|
|
* in_samples, 44100, 48000, AV_ROUND_UP);
|
|
|
|
* av_samples_alloc(&output, NULL, 2, out_samples,
|
|
|
|
* AV_SAMPLE_FMT_S16, 0);
|
|
|
|
* out_samples = swr_convert(swr, &output, out_samples,
|
|
|
|
* input, in_samples);
|
|
|
|
* handle_output(output, out_samples);
|
|
|
|
* av_freep(&output);
|
2013-09-29 21:37:46 +00:00
|
|
|
* }
|
|
|
|
* @endcode
|
2012-11-19 22:46:34 +00:00
|
|
|
*
|
|
|
|
* When the conversion is finished, the conversion
|
|
|
|
* context and everything associated with it must be freed with swr_free().
|
2014-07-06 16:53:55 +00:00
|
|
|
* A swr_close() function is also available, but it exists mainly for
|
|
|
|
* compatibility with libavresample, and is not required to be called.
|
|
|
|
*
|
2012-11-19 22:46:34 +00:00
|
|
|
* There will be no memory leak if the data is not completely flushed before
|
|
|
|
* swr_free().
|
|
|
|
*/
|
2011-09-19 04:13:30 +00:00
|
|
|
|
2012-11-20 20:51:25 +00:00
|
|
|
#include <stdint.h>
|
2016-08-17 23:08:50 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2014-08-10 23:43:26 +00:00
|
|
|
#include "libavutil/frame.h"
|
2011-09-19 04:13:30 +00:00
|
|
|
#include "libavutil/samplefmt.h"
|
|
|
|
|
2022-02-23 12:29:24 +00:00
|
|
|
#include "libswresample/version_major.h"
|
2022-03-18 08:13:27 +00:00
|
|
|
#ifndef HAVE_AV_CONFIG_H
|
|
|
|
/* When included as part of the ffmpeg build, only include the major version
|
|
|
|
* to avoid unnecessary rebuilds. When included externally, keep including
|
|
|
|
* the full version information. */
|
|
|
|
#include "libswresample/version.h"
|
|
|
|
#endif
|
2011-12-23 22:26:02 +00:00
|
|
|
|
2014-07-06 16:53:51 +00:00
|
|
|
/**
|
|
|
|
* @name Option constants
|
|
|
|
* These constants are used for the @ref avoptions interface for lswr.
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-11-17 10:20:29 +00:00
|
|
|
#define SWR_FLAG_RESAMPLE 1 ///< Force resampling even if equal sample rate
|
2011-09-19 04:13:30 +00:00
|
|
|
//TODO use int resample ?
|
|
|
|
//long term TODO can we enable this dynamically?
|
|
|
|
|
2014-07-06 16:53:52 +00:00
|
|
|
/** Dithering algorithms */
|
2012-04-10 17:52:42 +00:00
|
|
|
enum SwrDitherType {
|
|
|
|
SWR_DITHER_NONE = 0,
|
|
|
|
SWR_DITHER_RECTANGULAR,
|
2012-04-10 19:10:14 +00:00
|
|
|
SWR_DITHER_TRIANGULAR,
|
2012-04-11 11:27:22 +00:00
|
|
|
SWR_DITHER_TRIANGULAR_HIGHPASS,
|
2013-01-09 17:03:49 +00:00
|
|
|
|
|
|
|
SWR_DITHER_NS = 64, ///< not part of API/ABI
|
|
|
|
SWR_DITHER_NS_LIPSHITZ,
|
|
|
|
SWR_DITHER_NS_F_WEIGHTED,
|
|
|
|
SWR_DITHER_NS_MODIFIED_E_WEIGHTED,
|
|
|
|
SWR_DITHER_NS_IMPROVED_E_WEIGHTED,
|
|
|
|
SWR_DITHER_NS_SHIBATA,
|
|
|
|
SWR_DITHER_NS_LOW_SHIBATA,
|
|
|
|
SWR_DITHER_NS_HIGH_SHIBATA,
|
2012-04-10 17:52:42 +00:00
|
|
|
SWR_DITHER_NB, ///< not part of API/ABI
|
|
|
|
};
|
2011-09-19 04:13:30 +00:00
|
|
|
|
2012-12-11 17:36:58 +00:00
|
|
|
/** Resampling Engines */
|
|
|
|
enum SwrEngine {
|
|
|
|
SWR_ENGINE_SWR, /**< SW Resampler */
|
2012-12-11 20:43:42 +00:00
|
|
|
SWR_ENGINE_SOXR, /**< SoX Resampler */
|
2012-12-11 17:36:58 +00:00
|
|
|
SWR_ENGINE_NB, ///< not part of API/ABI
|
|
|
|
};
|
|
|
|
|
2012-05-26 18:50:02 +00:00
|
|
|
/** Resampling Filter Types */
|
|
|
|
enum SwrFilterType {
|
|
|
|
SWR_FILTER_TYPE_CUBIC, /**< Cubic */
|
2015-10-10 16:48:08 +00:00
|
|
|
SWR_FILTER_TYPE_BLACKMAN_NUTTALL, /**< Blackman Nuttall windowed sinc */
|
|
|
|
SWR_FILTER_TYPE_KAISER, /**< Kaiser windowed sinc */
|
2012-05-26 18:50:02 +00:00
|
|
|
};
|
|
|
|
|
2014-07-06 16:53:51 +00:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2014-07-06 16:53:53 +00:00
|
|
|
/**
|
|
|
|
* The libswresample context. Unlike libavcodec and libavformat, this structure
|
|
|
|
* is opaque. This means that if you would like to set options, you must use
|
|
|
|
* the @ref avoptions API and cannot directly set values to members of the
|
|
|
|
* structure.
|
|
|
|
*/
|
2012-03-24 21:56:24 +00:00
|
|
|
typedef struct SwrContext SwrContext;
|
2011-09-19 04:13:30 +00:00
|
|
|
|
2012-04-11 11:25:56 +00:00
|
|
|
/**
|
2014-07-06 16:53:50 +00:00
|
|
|
* Get the AVClass for SwrContext. It can be used in combination with
|
2012-04-11 11:25:56 +00:00
|
|
|
* AV_OPT_SEARCH_FAKE_OBJ for examining options.
|
|
|
|
*
|
|
|
|
* @see av_opt_find().
|
2014-07-07 22:23:49 +00:00
|
|
|
* @return the AVClass of SwrContext
|
2012-04-11 11:25:56 +00:00
|
|
|
*/
|
|
|
|
const AVClass *swr_get_class(void);
|
|
|
|
|
2014-07-06 16:53:56 +00:00
|
|
|
/**
|
|
|
|
* @name SwrContext constructor functions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-09-19 04:13:30 +00:00
|
|
|
/**
|
|
|
|
* Allocate SwrContext.
|
2011-11-17 10:20:29 +00:00
|
|
|
*
|
|
|
|
* If you use this function you will need to set the parameters (manually or
|
2021-08-27 03:37:53 +00:00
|
|
|
* with swr_alloc_set_opts2()) before calling swr_init().
|
2011-11-17 10:20:29 +00:00
|
|
|
*
|
2021-08-27 03:37:53 +00:00
|
|
|
* @see swr_alloc_set_opts2(), swr_init(), swr_free()
|
2011-11-17 10:20:29 +00:00
|
|
|
* @return NULL on error, allocated context otherwise
|
2011-09-19 04:13:30 +00:00
|
|
|
*/
|
|
|
|
struct SwrContext *swr_alloc(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize context after user parameters have been set.
|
2014-08-10 22:35:19 +00:00
|
|
|
* @note The context must be configured using the AVOption API.
|
|
|
|
*
|
|
|
|
* @see av_opt_set_int()
|
|
|
|
* @see av_opt_set_dict()
|
2011-11-17 10:20:29 +00:00
|
|
|
*
|
2014-07-07 22:23:49 +00:00
|
|
|
* @param[in,out] s Swr context to initialize
|
2011-11-17 10:20:29 +00:00
|
|
|
* @return AVERROR error code in case of failure.
|
2011-09-19 04:13:30 +00:00
|
|
|
*/
|
|
|
|
int swr_init(struct SwrContext *s);
|
|
|
|
|
2014-02-22 21:28:24 +00:00
|
|
|
/**
|
|
|
|
* Check whether an swr context has been initialized or not.
|
|
|
|
*
|
2014-07-07 22:23:49 +00:00
|
|
|
* @param[in] s Swr context to check
|
|
|
|
* @see swr_init()
|
2014-02-22 21:28:24 +00:00
|
|
|
* @return positive if it has been initialized, 0 if not initialized
|
|
|
|
*/
|
|
|
|
int swr_is_initialized(struct SwrContext *s);
|
|
|
|
|
2021-08-27 03:37:53 +00:00
|
|
|
/**
|
|
|
|
* Allocate SwrContext if needed and set/reset common parameters.
|
|
|
|
*
|
|
|
|
* This function does not require *ps to be allocated with swr_alloc(). On the
|
|
|
|
* other hand, swr_alloc() can use swr_alloc_set_opts2() to set the parameters
|
|
|
|
* on the allocated context.
|
|
|
|
*
|
|
|
|
* @param ps Pointer to an existing Swr context if available, or to NULL if not.
|
|
|
|
* On success, *ps will be set to the allocated context.
|
|
|
|
* @param out_ch_layout output channel layout (e.g. AV_CHANNEL_LAYOUT_*)
|
|
|
|
* @param out_sample_fmt output sample format (AV_SAMPLE_FMT_*).
|
|
|
|
* @param out_sample_rate output sample rate (frequency in Hz)
|
|
|
|
* @param in_ch_layout input channel layout (e.g. AV_CHANNEL_LAYOUT_*)
|
|
|
|
* @param in_sample_fmt input sample format (AV_SAMPLE_FMT_*).
|
|
|
|
* @param in_sample_rate input sample rate (frequency in Hz)
|
|
|
|
* @param log_offset logging level offset
|
|
|
|
* @param log_ctx parent logging context, can be NULL
|
|
|
|
*
|
|
|
|
* @see swr_init(), swr_free()
|
|
|
|
* @return 0 on success, a negative AVERROR code on error.
|
|
|
|
* On error, the Swr context is freed and *ps set to NULL.
|
|
|
|
*/
|
|
|
|
int swr_alloc_set_opts2(struct SwrContext **ps,
|
2022-08-05 20:57:31 +00:00
|
|
|
const AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
|
|
|
|
const AVChannelLayout *in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
|
2021-08-27 03:37:53 +00:00
|
|
|
int log_offset, void *log_ctx);
|
2014-07-06 16:53:56 +00:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*
|
|
|
|
* @name SwrContext destructor functions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-09-19 04:13:30 +00:00
|
|
|
/**
|
2011-11-17 10:20:29 +00:00
|
|
|
* Free the given SwrContext and set the pointer to NULL.
|
2014-07-07 22:23:49 +00:00
|
|
|
*
|
|
|
|
* @param[in] s a pointer to a pointer to Swr context
|
2011-09-19 04:13:30 +00:00
|
|
|
*/
|
|
|
|
void swr_free(struct SwrContext **s);
|
|
|
|
|
2014-05-15 16:27:23 +00:00
|
|
|
/**
|
|
|
|
* Closes the context so that swr_is_initialized() returns 0.
|
|
|
|
*
|
2014-07-06 16:53:50 +00:00
|
|
|
* The context can be brought back to life by running swr_init(),
|
2014-05-15 16:27:23 +00:00
|
|
|
* swr_init() can also be used without swr_close().
|
|
|
|
* This function is mainly provided for simplifying the usecase
|
2014-07-06 16:53:50 +00:00
|
|
|
* where one tries to support libavresample and libswresample.
|
2014-07-07 22:23:49 +00:00
|
|
|
*
|
|
|
|
* @param[in,out] s Swr context to be closed
|
2014-05-15 16:27:23 +00:00
|
|
|
*/
|
|
|
|
void swr_close(struct SwrContext *s);
|
|
|
|
|
2011-09-19 04:13:30 +00:00
|
|
|
/**
|
2014-07-06 16:53:56 +00:00
|
|
|
* @}
|
|
|
|
*
|
|
|
|
* @name Core conversion functions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Convert audio.
|
2011-11-04 15:34:39 +00:00
|
|
|
*
|
2011-11-17 10:20:29 +00:00
|
|
|
* in and in_count can be set to 0 to flush the last few samples out at the
|
|
|
|
* end.
|
|
|
|
*
|
2015-06-02 23:22:25 +00:00
|
|
|
* If more input is provided than output space, then the input will be buffered.
|
|
|
|
* You can avoid this buffering by using swr_get_out_samples() to retrieve an
|
|
|
|
* upper bound on the required number of output samples for the given number of
|
|
|
|
* input samples. Conversion will run directly without copying whenever possible.
|
2012-03-25 19:04:48 +00:00
|
|
|
*
|
2011-11-17 10:20:29 +00:00
|
|
|
* @param s allocated Swr context, with parameters set
|
|
|
|
* @param out output buffers, only the first one need be set in case of packed audio
|
|
|
|
* @param out_count amount of space available for output in samples per channel
|
|
|
|
* @param in input buffers, only the first one need to be set in case of packed audio
|
|
|
|
* @param in_count number of input samples available in one channel
|
|
|
|
*
|
2012-02-27 18:01:53 +00:00
|
|
|
* @return number of samples output per channel, negative value on error
|
2011-09-19 04:13:30 +00:00
|
|
|
*/
|
2024-02-28 18:58:41 +00:00
|
|
|
int swr_convert(struct SwrContext *s, uint8_t * const *out, int out_count,
|
|
|
|
const uint8_t * const *in , int in_count);
|
2011-09-19 04:13:30 +00:00
|
|
|
|
2012-05-19 16:44:34 +00:00
|
|
|
/**
|
|
|
|
* Convert the next timestamp from input to output
|
2012-11-20 19:29:05 +00:00
|
|
|
* timestamps are in 1/(in_sample_rate * out_sample_rate) units.
|
2012-05-19 16:44:34 +00:00
|
|
|
*
|
|
|
|
* @note There are 2 slightly differently behaving modes.
|
2014-07-07 22:23:49 +00:00
|
|
|
* @li When automatic timestamp compensation is not used, (min_compensation >= FLT_MAX)
|
2012-05-19 16:44:34 +00:00
|
|
|
* in this case timestamps will be passed through with delays compensated
|
2014-07-07 22:23:49 +00:00
|
|
|
* @li When automatic timestamp compensation is used, (min_compensation < FLT_MAX)
|
|
|
|
* in this case the output timestamps will match output sample numbers.
|
|
|
|
* See ffmpeg-resampler(1) for the two modes of compensation.
|
|
|
|
*
|
2022-09-15 00:44:08 +00:00
|
|
|
* @param[in] s initialized Swr context
|
|
|
|
* @param[in] pts timestamp for the next input sample, INT64_MIN if unknown
|
2014-07-07 22:23:49 +00:00
|
|
|
* @see swr_set_compensation(), swr_drop_output(), and swr_inject_silence() are
|
|
|
|
* function used internally for timestamp compensation.
|
2012-11-20 19:29:05 +00:00
|
|
|
* @return the output timestamp for the next output sample
|
2012-05-19 16:44:34 +00:00
|
|
|
*/
|
|
|
|
int64_t swr_next_pts(struct SwrContext *s, int64_t pts);
|
|
|
|
|
2014-07-06 16:53:56 +00:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*
|
|
|
|
* @name Low-level option setting functions
|
|
|
|
* These functons provide a means to set low-level options that is not possible
|
|
|
|
* with the AVOption API.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-11-17 10:20:29 +00:00
|
|
|
/**
|
2014-07-07 22:23:49 +00:00
|
|
|
* Activate resampling compensation ("soft" compensation). This function is
|
|
|
|
* internally called when needed in swr_next_pts().
|
|
|
|
*
|
|
|
|
* @param[in,out] s allocated Swr context. If it is not initialized,
|
|
|
|
* or SWR_FLAG_RESAMPLE is not set, swr_init() is
|
|
|
|
* called with the flag set.
|
|
|
|
* @param[in] sample_delta delta in PTS per sample
|
|
|
|
* @param[in] compensation_distance number of samples to compensate for
|
|
|
|
* @return >= 0 on success, AVERROR error codes if:
|
|
|
|
* @li @c s is NULL,
|
|
|
|
* @li @c compensation_distance is less than 0,
|
|
|
|
* @li @c compensation_distance is 0 but sample_delta is not,
|
|
|
|
* @li compensation unsupported by resampler, or
|
|
|
|
* @li swr_init() fails when called.
|
2011-11-17 10:20:29 +00:00
|
|
|
*/
|
2012-01-09 00:42:38 +00:00
|
|
|
int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance);
|
2011-09-19 04:13:30 +00:00
|
|
|
|
2011-11-17 14:06:35 +00:00
|
|
|
/**
|
|
|
|
* Set a customized input channel mapping.
|
|
|
|
*
|
2014-07-07 22:23:49 +00:00
|
|
|
* @param[in,out] s allocated Swr context, not yet initialized
|
|
|
|
* @param[in] channel_map customized input channel mapping (array of channel
|
|
|
|
* indexes, -1 for a muted channel)
|
|
|
|
* @return >= 0 on success, or AVERROR error code in case of failure.
|
2011-11-17 14:06:35 +00:00
|
|
|
*/
|
|
|
|
int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
|
|
|
|
|
2021-08-27 03:37:53 +00:00
|
|
|
/**
|
|
|
|
* Generate a channel mixing matrix.
|
|
|
|
*
|
|
|
|
* This function is the one used internally by libswresample for building the
|
|
|
|
* default mixing matrix. It is made public just as a utility function for
|
|
|
|
* building custom matrices.
|
|
|
|
*
|
|
|
|
* @param in_layout input channel layout
|
|
|
|
* @param out_layout output channel layout
|
|
|
|
* @param center_mix_level mix level for the center channel
|
|
|
|
* @param surround_mix_level mix level for the surround channel(s)
|
|
|
|
* @param lfe_mix_level mix level for the low-frequency effects channel
|
|
|
|
* @param rematrix_maxval if 1.0, coefficients will be normalized to prevent
|
|
|
|
* overflow. if INT_MAX, coefficients will not be
|
|
|
|
* normalized.
|
|
|
|
* @param[out] matrix mixing coefficients; matrix[i + stride * o] is
|
|
|
|
* the weight of input channel i in output channel o.
|
|
|
|
* @param stride distance between adjacent input channels in the
|
|
|
|
* matrix array
|
|
|
|
* @param matrix_encoding matrixed stereo downmix mode (e.g. dplii)
|
|
|
|
* @param log_ctx parent logging context, can be NULL
|
|
|
|
* @return 0 on success, negative AVERROR code on failure
|
|
|
|
*/
|
|
|
|
int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
|
|
|
|
double center_mix_level, double surround_mix_level,
|
|
|
|
double lfe_mix_level, double maxval,
|
|
|
|
double rematrix_volume, double *matrix,
|
|
|
|
ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding,
|
|
|
|
void *log_context);
|
2016-08-17 23:08:50 +00:00
|
|
|
|
2012-02-16 10:26:32 +00:00
|
|
|
/**
|
|
|
|
* Set a customized remix matrix.
|
|
|
|
*
|
|
|
|
* @param s allocated Swr context, not yet initialized
|
|
|
|
* @param matrix remix coefficients; matrix[i + stride * o] is
|
|
|
|
* the weight of input channel i in output channel o
|
|
|
|
* @param stride offset between lines of the matrix
|
2014-07-07 22:23:49 +00:00
|
|
|
* @return >= 0 on success, or AVERROR error code in case of failure.
|
2012-02-16 10:26:32 +00:00
|
|
|
*/
|
|
|
|
int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride);
|
|
|
|
|
2014-07-06 16:53:56 +00:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*
|
|
|
|
* @name Sample handling functions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-05-19 16:42:11 +00:00
|
|
|
/**
|
|
|
|
* Drops the specified number of output samples.
|
2014-07-07 22:23:49 +00:00
|
|
|
*
|
|
|
|
* This function, along with swr_inject_silence(), is called by swr_next_pts()
|
|
|
|
* if needed for "hard" compensation.
|
|
|
|
*
|
|
|
|
* @param s allocated Swr context
|
|
|
|
* @param count number of samples to be dropped
|
|
|
|
*
|
|
|
|
* @return >= 0 on success, or a negative AVERROR code on failure
|
2012-05-19 16:42:11 +00:00
|
|
|
*/
|
|
|
|
int swr_drop_output(struct SwrContext *s, int count);
|
|
|
|
|
2012-05-19 16:39:12 +00:00
|
|
|
/**
|
|
|
|
* Injects the specified number of silence samples.
|
2014-07-07 22:23:49 +00:00
|
|
|
*
|
|
|
|
* This function, along with swr_drop_output(), is called by swr_next_pts()
|
|
|
|
* if needed for "hard" compensation.
|
|
|
|
*
|
|
|
|
* @param s allocated Swr context
|
|
|
|
* @param count number of samples to be dropped
|
|
|
|
*
|
|
|
|
* @return >= 0 on success, or a negative AVERROR code on failure
|
2012-05-19 16:39:12 +00:00
|
|
|
*/
|
|
|
|
int swr_inject_silence(struct SwrContext *s, int count);
|
|
|
|
|
2012-05-18 21:02:10 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2012-11-20 19:29:05 +00:00
|
|
|
* The exact delay is not necessarily an integer value in either input or
|
2012-11-20 19:05:08 +00:00
|
|
|
* 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.
|
2012-05-18 21:02:10 +00:00
|
|
|
*
|
|
|
|
* @param s swr context
|
2014-07-07 22:23:49 +00:00
|
|
|
* @param base timebase in which the returned delay will be:
|
|
|
|
* @li if it's set to 1 the returned delay is in seconds
|
|
|
|
* @li if it's set to 1000 the returned delay is in milliseconds
|
|
|
|
* @li if it's set to the input sample rate then the returned
|
|
|
|
* delay is in input samples
|
|
|
|
* @li if it's set to the output sample rate then the returned
|
|
|
|
* delay is in output samples
|
|
|
|
* @li if it's the least common multiple of in_sample_rate and
|
|
|
|
* out_sample_rate then an exact rounding-free delay will be
|
|
|
|
* returned
|
|
|
|
* @returns the delay in 1 / @c base units.
|
2012-05-18 21:02:10 +00:00
|
|
|
*/
|
|
|
|
int64_t swr_get_delay(struct SwrContext *s, int64_t base);
|
|
|
|
|
2015-06-02 23:22:25 +00:00
|
|
|
/**
|
|
|
|
* Find an upper bound on the number of samples that the next swr_convert
|
|
|
|
* call will output, if called with in_samples of input samples. This
|
|
|
|
* depends on the internal state, and anything changing the internal state
|
|
|
|
* (like further swr_convert() calls) will may change the number of samples
|
|
|
|
* swr_get_out_samples() returns for the same number of input samples.
|
|
|
|
*
|
|
|
|
* @param in_samples number of input samples.
|
|
|
|
* @note any call to swr_inject_silence(), swr_convert(), swr_next_pts()
|
|
|
|
* or swr_set_compensation() invalidates this limit
|
|
|
|
* @note it is recommended to pass the correct available buffer size
|
|
|
|
* to all functions like swr_convert() even if swr_get_out_samples()
|
|
|
|
* indicates that less would be used.
|
|
|
|
* @returns an upper bound on the number of samples that the next swr_convert
|
|
|
|
* will output or a negative value to indicate an error
|
|
|
|
*/
|
|
|
|
int swr_get_out_samples(struct SwrContext *s, int in_samples);
|
|
|
|
|
2014-07-06 16:53:56 +00:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*
|
|
|
|
* @name Configuration accessors
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-12-22 02:08:47 +00:00
|
|
|
/**
|
2014-07-06 16:53:54 +00:00
|
|
|
* Return the @ref LIBSWRESAMPLE_VERSION_INT constant.
|
|
|
|
*
|
|
|
|
* This is useful to check if the build-time libswresample has the same version
|
|
|
|
* as the run-time one.
|
|
|
|
*
|
|
|
|
* @returns the unsigned int-typed version
|
2011-12-22 02:08:47 +00:00
|
|
|
*/
|
|
|
|
unsigned swresample_version(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the swr build-time configuration.
|
2014-07-06 16:53:54 +00:00
|
|
|
*
|
|
|
|
* @returns the build-time @c ./configure flags
|
2011-12-22 02:08:47 +00:00
|
|
|
*/
|
|
|
|
const char *swresample_configuration(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the swr license.
|
2014-07-06 16:53:54 +00:00
|
|
|
*
|
|
|
|
* @returns the license of libswresample, determined at build-time
|
2011-12-22 02:08:47 +00:00
|
|
|
*/
|
|
|
|
const char *swresample_license(void);
|
|
|
|
|
2014-08-10 23:43:26 +00:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*
|
|
|
|
* @name AVFrame based API
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the samples in the input AVFrame and write them to the output AVFrame.
|
|
|
|
*
|
|
|
|
* Input and output AVFrames must have channel_layout, sample_rate and format set.
|
|
|
|
*
|
|
|
|
* If the output AVFrame does not have the data pointers allocated the nb_samples
|
|
|
|
* field will be set using av_frame_get_buffer()
|
|
|
|
* is called to allocate the frame.
|
|
|
|
*
|
|
|
|
* The output AVFrame can be NULL or have fewer allocated samples than required.
|
|
|
|
* In this case, any remaining samples not written to the output will be added
|
|
|
|
* to an internal FIFO buffer, to be returned at the next call to this function
|
|
|
|
* or to swr_convert().
|
|
|
|
*
|
|
|
|
* If converting sample rate, there may be data remaining in the internal
|
|
|
|
* resampling delay buffer. swr_get_delay() tells the number of
|
|
|
|
* remaining samples. To get this data as output, call this function or
|
|
|
|
* swr_convert() with NULL input.
|
|
|
|
*
|
|
|
|
* If the SwrContext configuration does not match the output and
|
|
|
|
* input AVFrame settings the conversion does not take place and depending on
|
|
|
|
* which AVFrame is not matching AVERROR_OUTPUT_CHANGED, AVERROR_INPUT_CHANGED
|
|
|
|
* or the result of a bitwise-OR of them is returned.
|
|
|
|
*
|
|
|
|
* @see swr_delay()
|
|
|
|
* @see swr_convert()
|
|
|
|
* @see swr_get_delay()
|
|
|
|
*
|
|
|
|
* @param swr audio resample context
|
|
|
|
* @param output output AVFrame
|
|
|
|
* @param input input AVFrame
|
|
|
|
* @return 0 on success, AVERROR on failure or nonmatching
|
|
|
|
* configuration.
|
|
|
|
*/
|
|
|
|
int swr_convert_frame(SwrContext *swr,
|
|
|
|
AVFrame *output, const AVFrame *input);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure or reconfigure the SwrContext using the information
|
|
|
|
* provided by the AVFrames.
|
|
|
|
*
|
|
|
|
* The original resampling context is reset even on failure.
|
|
|
|
* The function calls swr_close() internally if the context is open.
|
|
|
|
*
|
|
|
|
* @see swr_close();
|
|
|
|
*
|
|
|
|
* @param swr audio resample context
|
2022-09-15 00:44:08 +00:00
|
|
|
* @param out output AVFrame
|
|
|
|
* @param in input AVFrame
|
2014-08-10 23:43:26 +00:00
|
|
|
* @return 0 on success, AVERROR on failure.
|
|
|
|
*/
|
|
|
|
int swr_config_frame(SwrContext *swr, const AVFrame *out, const AVFrame *in);
|
|
|
|
|
2012-11-19 22:46:34 +00:00
|
|
|
/**
|
2014-07-06 16:53:56 +00:00
|
|
|
* @}
|
2012-11-19 22:46:34 +00:00
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2012-11-02 12:04:14 +00:00
|
|
|
#endif /* SWRESAMPLE_SWRESAMPLE_H */
|