FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
swresample.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2013 Michael Niedermayer (michaelni@gmx.at)
3  *
4  * This file is part of libswresample
5  *
6  * libswresample is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * libswresample is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with libswresample; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef SWRESAMPLE_SWRESAMPLE_H
22 #define SWRESAMPLE_SWRESAMPLE_H
23 
24 /**
25  * @file
26  * @ingroup lswr
27  * libswresample public header
28  */
29 
30 /**
31  * @defgroup lswr libswresample
32  * @{
33  *
34  * Audio resampling, sample format conversion and mixing library.
35  *
36  * Interaction with lswr is done through SwrContext, which is
37  * allocated with swr_alloc() or swr_alloc_set_opts(). It is opaque, so all parameters
38  * must be set with the @ref avoptions API.
39  *
40  * The first thing you will need to do in order to use lswr is to allocate
41  * SwrContext. This can be done with swr_alloc() or swr_alloc_set_opts(). If you
42  * are using the former, you must set options through the @ref avoptions API.
43  * The latter function provides the same feature, but it allows you to set some
44  * common options in the same statement.
45  *
46  * For example the following code will setup conversion from planar float sample
47  * format to interleaved signed 16-bit integer, downsampling from 48kHz to
48  * 44.1kHz and downmixing from 5.1 channels to stereo (using the default mixing
49  * matrix). This is using the swr_alloc() function.
50  * @code
51  * SwrContext *swr = swr_alloc();
52  * av_opt_set_channel_layout(swr, "in_channel_layout", AV_CH_LAYOUT_5POINT1, 0);
53  * av_opt_set_channel_layout(swr, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
54  * av_opt_set_int(swr, "in_sample_rate", 48000, 0);
55  * av_opt_set_int(swr, "out_sample_rate", 44100, 0);
56  * av_opt_set_sample_fmt(swr, "in_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
57  * av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
58  * @endcode
59  *
60  * The same job can be done using swr_alloc_set_opts() as well:
61  * @code
62  * SwrContext *swr = swr_alloc_set_opts(NULL, // we're allocating a new context
63  * AV_CH_LAYOUT_STEREO, // out_ch_layout
64  * AV_SAMPLE_FMT_S16, // out_sample_fmt
65  * 44100, // out_sample_rate
66  * AV_CH_LAYOUT_5POINT1, // in_ch_layout
67  * AV_SAMPLE_FMT_FLTP, // in_sample_fmt
68  * 48000, // in_sample_rate
69  * 0, // log_offset
70  * NULL); // log_ctx
71  * @endcode
72  *
73  * Once all values have been set, it must be initialized with swr_init(). If
74  * you need to change the conversion parameters, you can change the parameters
75  * using @ref AVOptions, as described above in the first example; or by using
76  * swr_alloc_set_opts(), but with the first argument the allocated context.
77  * You must then call swr_init() again.
78  *
79  * The conversion itself is done by repeatedly calling swr_convert().
80  * Note that the samples may get buffered in swr if you provide insufficient
81  * output space or if sample rate conversion is done, which requires "future"
82  * samples. Samples that do not require future input can be retrieved at any
83  * time by using swr_convert() (in_count can be set to 0).
84  * At the end of conversion the resampling buffer can be flushed by calling
85  * swr_convert() with NULL in and 0 in_count.
86  *
87  * The samples used in the conversion process can be managed with the libavutil
88  * @ref lavu_sampmanip "samples manipulation" API, including av_samples_alloc()
89  * function used in the following example.
90  *
91  * The delay between input and output, can at any time be found by using
92  * swr_get_delay().
93  *
94  * The following code demonstrates the conversion loop assuming the parameters
95  * from above and caller-defined functions get_input() and handle_output():
96  * @code
97  * uint8_t **input;
98  * int in_samples;
99  *
100  * while (get_input(&input, &in_samples)) {
101  * uint8_t *output;
102  * int out_samples = av_rescale_rnd(swr_get_delay(swr, 48000) +
103  * in_samples, 44100, 48000, AV_ROUND_UP);
104  * av_samples_alloc(&output, NULL, 2, out_samples,
105  * AV_SAMPLE_FMT_S16, 0);
106  * out_samples = swr_convert(swr, &output, out_samples,
107  * input, in_samples);
108  * handle_output(output, out_samples);
109  * av_freep(&output);
110  * }
111  * @endcode
112  *
113  * When the conversion is finished, the conversion
114  * context and everything associated with it must be freed with swr_free().
115  * A swr_close() function is also available, but it exists mainly for
116  * compatibility with libavresample, and is not required to be called.
117  *
118  * There will be no memory leak if the data is not completely flushed before
119  * swr_free().
120  */
121 
122 #include <stdint.h>
123 #include "libavutil/frame.h"
124 #include "libavutil/samplefmt.h"
125 
126 #include "libswresample/version.h"
127 
128 #if LIBSWRESAMPLE_VERSION_MAJOR < 1
129 #define SWR_CH_MAX 32 ///< Maximum number of channels
130 #endif
131 
132 /**
133  * @name Option constants
134  * These constants are used for the @ref avoptions interface for lswr.
135  * @{
136  *
137  */
138 
139 #define SWR_FLAG_RESAMPLE 1 ///< Force resampling even if equal sample rate
140 //TODO use int resample ?
141 //long term TODO can we enable this dynamically?
142 
143 /** Dithering algorithms */
149 
150  SWR_DITHER_NS = 64, ///< not part of API/ABI
158  SWR_DITHER_NB, ///< not part of API/ABI
159 };
160 
161 /** Resampling Engines */
162 enum SwrEngine {
163  SWR_ENGINE_SWR, /**< SW Resampler */
164  SWR_ENGINE_SOXR, /**< SoX Resampler */
165  SWR_ENGINE_NB, ///< not part of API/ABI
166 };
167 
168 /** Resampling Filter Types */
170  SWR_FILTER_TYPE_CUBIC, /**< Cubic */
171  SWR_FILTER_TYPE_BLACKMAN_NUTTALL, /**< Blackman Nuttall windowed sinc */
172  SWR_FILTER_TYPE_KAISER, /**< Kaiser windowed sinc */
173 };
174 
175 /**
176  * @}
177  */
178 
179 /**
180  * The libswresample context. Unlike libavcodec and libavformat, this structure
181  * is opaque. This means that if you would like to set options, you must use
182  * the @ref avoptions API and cannot directly set values to members of the
183  * structure.
184  */
185 typedef struct SwrContext SwrContext;
186 
187 /**
188  * Get the AVClass for SwrContext. It can be used in combination with
189  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
190  *
191  * @see av_opt_find().
192  * @return the AVClass of SwrContext
193  */
194 const AVClass *swr_get_class(void);
195 
196 /**
197  * @name SwrContext constructor functions
198  * @{
199  */
200 
201 /**
202  * Allocate SwrContext.
203  *
204  * If you use this function you will need to set the parameters (manually or
205  * with swr_alloc_set_opts()) before calling swr_init().
206  *
207  * @see swr_alloc_set_opts(), swr_init(), swr_free()
208  * @return NULL on error, allocated context otherwise
209  */
210 struct SwrContext *swr_alloc(void);
211 
212 /**
213  * Initialize context after user parameters have been set.
214  * @note The context must be configured using the AVOption API.
215  *
216  * @see av_opt_set_int()
217  * @see av_opt_set_dict()
218  *
219  * @param[in,out] s Swr context to initialize
220  * @return AVERROR error code in case of failure.
221  */
222 int swr_init(struct SwrContext *s);
223 
224 /**
225  * Check whether an swr context has been initialized or not.
226  *
227  * @param[in] s Swr context to check
228  * @see swr_init()
229  * @return positive if it has been initialized, 0 if not initialized
230  */
231 int swr_is_initialized(struct SwrContext *s);
232 
233 /**
234  * Allocate SwrContext if needed and set/reset common parameters.
235  *
236  * This function does not require s to be allocated with swr_alloc(). On the
237  * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters
238  * on the allocated context.
239  *
240  * @param s existing Swr context if available, or NULL if not
241  * @param out_ch_layout output channel layout (AV_CH_LAYOUT_*)
242  * @param out_sample_fmt output sample format (AV_SAMPLE_FMT_*).
243  * @param out_sample_rate output sample rate (frequency in Hz)
244  * @param in_ch_layout input channel layout (AV_CH_LAYOUT_*)
245  * @param in_sample_fmt input sample format (AV_SAMPLE_FMT_*).
246  * @param in_sample_rate input sample rate (frequency in Hz)
247  * @param log_offset logging level offset
248  * @param log_ctx parent logging context, can be NULL
249  *
250  * @see swr_init(), swr_free()
251  * @return NULL on error, allocated context otherwise
252  */
253 struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
256  int log_offset, void *log_ctx);
257 
258 /**
259  * @}
260  *
261  * @name SwrContext destructor functions
262  * @{
263  */
264 
265 /**
266  * Free the given SwrContext and set the pointer to NULL.
267  *
268  * @param[in] s a pointer to a pointer to Swr context
269  */
270 void swr_free(struct SwrContext **s);
271 
272 /**
273  * Closes the context so that swr_is_initialized() returns 0.
274  *
275  * The context can be brought back to life by running swr_init(),
276  * swr_init() can also be used without swr_close().
277  * This function is mainly provided for simplifying the usecase
278  * where one tries to support libavresample and libswresample.
279  *
280  * @param[in,out] s Swr context to be closed
281  */
282 void swr_close(struct SwrContext *s);
283 
284 /**
285  * @}
286  *
287  * @name Core conversion functions
288  * @{
289  */
290 
291 /** Convert audio.
292  *
293  * in and in_count can be set to 0 to flush the last few samples out at the
294  * end.
295  *
296  * If more input is provided than output space, then the input will be buffered.
297  * You can avoid this buffering by using swr_get_out_samples() to retrieve an
298  * upper bound on the required number of output samples for the given number of
299  * input samples. Conversion will run directly without copying whenever possible.
300  *
301  * @param s allocated Swr context, with parameters set
302  * @param out output buffers, only the first one need be set in case of packed audio
303  * @param out_count amount of space available for output in samples per channel
304  * @param in input buffers, only the first one need to be set in case of packed audio
305  * @param in_count number of input samples available in one channel
306  *
307  * @return number of samples output per channel, negative value on error
308  */
309 int swr_convert(struct SwrContext *s, uint8_t **out, int out_count,
310  const uint8_t **in , int in_count);
311 
312 /**
313  * Convert the next timestamp from input to output
314  * timestamps are in 1/(in_sample_rate * out_sample_rate) units.
315  *
316  * @note There are 2 slightly differently behaving modes.
317  * @li When automatic timestamp compensation is not used, (min_compensation >= FLT_MAX)
318  * in this case timestamps will be passed through with delays compensated
319  * @li When automatic timestamp compensation is used, (min_compensation < FLT_MAX)
320  * in this case the output timestamps will match output sample numbers.
321  * See ffmpeg-resampler(1) for the two modes of compensation.
322  *
323  * @param s[in] initialized Swr context
324  * @param pts[in] timestamp for the next input sample, INT64_MIN if unknown
325  * @see swr_set_compensation(), swr_drop_output(), and swr_inject_silence() are
326  * function used internally for timestamp compensation.
327  * @return the output timestamp for the next output sample
328  */
329 int64_t swr_next_pts(struct SwrContext *s, int64_t pts);
330 
331 /**
332  * @}
333  *
334  * @name Low-level option setting functions
335  * These functons provide a means to set low-level options that is not possible
336  * with the AVOption API.
337  * @{
338  */
339 
340 /**
341  * Activate resampling compensation ("soft" compensation). This function is
342  * internally called when needed in swr_next_pts().
343  *
344  * @param[in,out] s allocated Swr context. If it is not initialized,
345  * or SWR_FLAG_RESAMPLE is not set, swr_init() is
346  * called with the flag set.
347  * @param[in] sample_delta delta in PTS per sample
348  * @param[in] compensation_distance number of samples to compensate for
349  * @return >= 0 on success, AVERROR error codes if:
350  * @li @c s is NULL,
351  * @li @c compensation_distance is less than 0,
352  * @li @c compensation_distance is 0 but sample_delta is not,
353  * @li compensation unsupported by resampler, or
354  * @li swr_init() fails when called.
355  */
356 int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance);
357 
358 /**
359  * Set a customized input channel mapping.
360  *
361  * @param[in,out] s allocated Swr context, not yet initialized
362  * @param[in] channel_map customized input channel mapping (array of channel
363  * indexes, -1 for a muted channel)
364  * @return >= 0 on success, or AVERROR error code in case of failure.
365  */
366 int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
367 
368 /**
369  * Set a customized remix matrix.
370  *
371  * @param s allocated Swr context, not yet initialized
372  * @param matrix remix coefficients; matrix[i + stride * o] is
373  * the weight of input channel i in output channel o
374  * @param stride offset between lines of the matrix
375  * @return >= 0 on success, or AVERROR error code in case of failure.
376  */
377 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride);
378 
379 /**
380  * @}
381  *
382  * @name Sample handling functions
383  * @{
384  */
385 
386 /**
387  * Drops the specified number of output samples.
388  *
389  * This function, along with swr_inject_silence(), is called by swr_next_pts()
390  * if needed for "hard" compensation.
391  *
392  * @param s allocated Swr context
393  * @param count number of samples to be dropped
394  *
395  * @return >= 0 on success, or a negative AVERROR code on failure
396  */
397 int swr_drop_output(struct SwrContext *s, int count);
398 
399 /**
400  * Injects the specified number of silence samples.
401  *
402  * This function, along with swr_drop_output(), is called by swr_next_pts()
403  * if needed for "hard" compensation.
404  *
405  * @param s allocated Swr context
406  * @param count number of samples to be dropped
407  *
408  * @return >= 0 on success, or a negative AVERROR code on failure
409  */
410 int swr_inject_silence(struct SwrContext *s, int count);
411 
412 /**
413  * Gets the delay the next input sample will experience relative to the next output sample.
414  *
415  * Swresample can buffer data if more input has been provided than available
416  * output space, also converting between sample rates needs a delay.
417  * This function returns the sum of all such delays.
418  * The exact delay is not necessarily an integer value in either input or
419  * output sample rate. Especially when downsampling by a large value, the
420  * output sample rate may be a poor choice to represent the delay, similarly
421  * for upsampling and the input sample rate.
422  *
423  * @param s swr context
424  * @param base timebase in which the returned delay will be:
425  * @li if it's set to 1 the returned delay is in seconds
426  * @li if it's set to 1000 the returned delay is in milliseconds
427  * @li if it's set to the input sample rate then the returned
428  * delay is in input samples
429  * @li if it's set to the output sample rate then the returned
430  * delay is in output samples
431  * @li if it's the least common multiple of in_sample_rate and
432  * out_sample_rate then an exact rounding-free delay will be
433  * returned
434  * @returns the delay in 1 / @c base units.
435  */
436 int64_t swr_get_delay(struct SwrContext *s, int64_t base);
437 
438 /**
439  * Find an upper bound on the number of samples that the next swr_convert
440  * call will output, if called with in_samples of input samples. This
441  * depends on the internal state, and anything changing the internal state
442  * (like further swr_convert() calls) will may change the number of samples
443  * swr_get_out_samples() returns for the same number of input samples.
444  *
445  * @param in_samples number of input samples.
446  * @note any call to swr_inject_silence(), swr_convert(), swr_next_pts()
447  * or swr_set_compensation() invalidates this limit
448  * @note it is recommended to pass the correct available buffer size
449  * to all functions like swr_convert() even if swr_get_out_samples()
450  * indicates that less would be used.
451  * @returns an upper bound on the number of samples that the next swr_convert
452  * will output or a negative value to indicate an error
453  */
454 int swr_get_out_samples(struct SwrContext *s, int in_samples);
455 
456 /**
457  * @}
458  *
459  * @name Configuration accessors
460  * @{
461  */
462 
463 /**
464  * Return the @ref LIBSWRESAMPLE_VERSION_INT constant.
465  *
466  * This is useful to check if the build-time libswresample has the same version
467  * as the run-time one.
468  *
469  * @returns the unsigned int-typed version
470  */
471 unsigned swresample_version(void);
472 
473 /**
474  * Return the swr build-time configuration.
475  *
476  * @returns the build-time @c ./configure flags
477  */
478 const char *swresample_configuration(void);
479 
480 /**
481  * Return the swr license.
482  *
483  * @returns the license of libswresample, determined at build-time
484  */
485 const char *swresample_license(void);
486 
487 /**
488  * @}
489  *
490  * @name AVFrame based API
491  * @{
492  */
493 
494 /**
495  * Convert the samples in the input AVFrame and write them to the output AVFrame.
496  *
497  * Input and output AVFrames must have channel_layout, sample_rate and format set.
498  *
499  * If the output AVFrame does not have the data pointers allocated the nb_samples
500  * field will be set using av_frame_get_buffer()
501  * is called to allocate the frame.
502  *
503  * The output AVFrame can be NULL or have fewer allocated samples than required.
504  * In this case, any remaining samples not written to the output will be added
505  * to an internal FIFO buffer, to be returned at the next call to this function
506  * or to swr_convert().
507  *
508  * If converting sample rate, there may be data remaining in the internal
509  * resampling delay buffer. swr_get_delay() tells the number of
510  * remaining samples. To get this data as output, call this function or
511  * swr_convert() with NULL input.
512  *
513  * If the SwrContext configuration does not match the output and
514  * input AVFrame settings the conversion does not take place and depending on
515  * which AVFrame is not matching AVERROR_OUTPUT_CHANGED, AVERROR_INPUT_CHANGED
516  * or the result of a bitwise-OR of them is returned.
517  *
518  * @see swr_delay()
519  * @see swr_convert()
520  * @see swr_get_delay()
521  *
522  * @param swr audio resample context
523  * @param output output AVFrame
524  * @param input input AVFrame
525  * @return 0 on success, AVERROR on failure or nonmatching
526  * configuration.
527  */
529  AVFrame *output, const AVFrame *input);
530 
531 /**
532  * Configure or reconfigure the SwrContext using the information
533  * provided by the AVFrames.
534  *
535  * The original resampling context is reset even on failure.
536  * The function calls swr_close() internally if the context is open.
537  *
538  * @see swr_close();
539  *
540  * @param swr audio resample context
541  * @param output output AVFrame
542  * @param input input AVFrame
543  * @return 0 on success, AVERROR on failure.
544  */
545 int swr_config_frame(SwrContext *swr, const AVFrame *out, const AVFrame *in);
546 
547 /**
548  * @}
549  * @}
550  */
551 
552 #endif /* SWRESAMPLE_SWRESAMPLE_H */
const char * s
Definition: avisynth_c.h:768
void swr_close(struct SwrContext *s)
Closes the context so that swr_is_initialized() returns 0.
Definition: swresample.c:151
int out_sample_rate
output sample rate
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
SoX Resampler.
Definition: swresample.h:164
SwrFilterType
Resampling Filter Types.
Definition: swresample.h:169
int64_t swr_next_pts(struct SwrContext *s, int64_t pts)
Convert the next timestamp from input to output timestamps are in 1/(in_sample_rate * out_sample_rate...
Definition: swresample.c:910
const int * channel_map
channel index (or -1 if muted channel) map
int swr_get_out_samples(struct SwrContext *s, int in_samples)
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.
Definition: swresample.c:868
int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance)
Activate resampling compensation ("soft" compensation).
Definition: swresample.c:890
uint8_t
struct SwrContext * swr_alloc(void)
Allocate SwrContext.
Definition: options.c:149
SwrDitherType
Dithering algorithms.
Definition: swresample.h:144
void * log_ctx
parent logging context
int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in, int in_count)
Convert audio.
Kaiser windowed sinc.
Definition: swresample.h:172
enum AVSampleFormat out_sample_fmt
output sample format
SwrEngine
Resampling Engines.
Definition: swresample.h:162
Blackman Nuttall windowed sinc.
Definition: swresample.h:171
The libswresample context.
int64_t swr_get_delay(struct SwrContext *s, int64_t base)
Gets the delay the next input sample will experience relative to the next output sample.
Definition: swresample.c:860
GLsizei count
Definition: opengl_enc.c:109
not part of API/ABI
Definition: swresample.h:165
reference-counted frame API
not part of API/ABI
Definition: swresample.h:158
int swr_drop_output(struct SwrContext *s, int count)
Drops the specified number of output samples.
Definition: swresample.c:821
int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
Set a customized remix matrix.
Definition: rematrix.c:64
int64_t out_ch_layout
output channel layout
struct SwrContext * swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)
Allocate SwrContext if needed and set/reset common parameters.
Definition: swresample.c:59
not part of API/ABI
Definition: swresample.h:150
int in_sample_rate
input sample rate
const AVClass * swr_get_class(void)
Get the AVClass for SwrContext.
Definition: options.c:144
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
void swr_free(struct SwrContext **s)
Free the given SwrContext and set the pointer to NULL.
Definition: swresample.c:140
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map)
Set a customized input channel mapping.
Definition: swresample.c:52
Describe the class of an AVClass context structure.
Definition: log.h:67
const char * swresample_license(void)
Return the swr license.
Definition: swresample.c:46
enum AVSampleFormat in_sample_fmt
input sample format
Libswresample version macros.
static int64_t pts
Global timestamp for the audio frames.
SW Resampler.
Definition: swresample.h:163
int64_t in_ch_layout
input channel layout
int swr_convert_frame(SwrContext *swr, AVFrame *output, const AVFrame *input)
Convert the samples in the input AVFrame and write them to the output AVFrame.
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
int swr_config_frame(SwrContext *swr, const AVFrame *out, const AVFrame *in)
Configure or reconfigure the SwrContext using the information provided by the AVFrames.
unsigned swresample_version(void)
Return the LIBSWRESAMPLE_VERSION_INT constant.
Definition: swresample.c:35
float matrix[SWR_CH_MAX][SWR_CH_MAX]
floating point rematrixing coefficients
FILE * out
Definition: movenc.c:54
int swr_is_initialized(struct SwrContext *s)
Check whether an swr context has been initialized or not.
Definition: swresample.c:703
const char * swresample_configuration(void)
Return the swr build-time configuration.
Definition: swresample.c:41
int swr_inject_silence(struct SwrContext *s, int count)
Injects the specified number of silence samples.
Definition: swresample.c:832
int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
Definition: swresample.c:155