FFmpeg
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 
122 #include <stdint.h>
124 #include "libavutil/frame.h"
125 #include "libavutil/samplefmt.h"
126 
127 #include "libswresample/version.h"
128 
136 #define SWR_FLAG_RESAMPLE 1
137 //TODO use int resample ?
138 //long term TODO can we enable this dynamically?
139 
142  SWR_DITHER_NONE = 0,
143  SWR_DITHER_RECTANGULAR,
144  SWR_DITHER_TRIANGULAR,
145  SWR_DITHER_TRIANGULAR_HIGHPASS,
146 
148  SWR_DITHER_NS_LIPSHITZ,
149  SWR_DITHER_NS_F_WEIGHTED,
150  SWR_DITHER_NS_MODIFIED_E_WEIGHTED,
151  SWR_DITHER_NS_IMPROVED_E_WEIGHTED,
152  SWR_DITHER_NS_SHIBATA,
153  SWR_DITHER_NS_LOW_SHIBATA,
154  SWR_DITHER_NS_HIGH_SHIBATA,
156 };
157 
159 enum SwrEngine {
163 };
164 
170 };
171 
182 typedef struct SwrContext SwrContext;
183 
191 const AVClass *swr_get_class(void);
192 
207 struct SwrContext *swr_alloc(void);
208 
219 int swr_init(struct SwrContext *s);
220 
228 int swr_is_initialized(struct SwrContext *s);
229 
250 struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
253  int log_offset, void *log_ctx);
254 
267 void swr_free(struct SwrContext **s);
268 
279 void swr_close(struct SwrContext *s);
280 
306 int swr_convert(struct SwrContext *s, uint8_t **out, int out_count,
307  const uint8_t **in , int in_count);
308 
326 int64_t swr_next_pts(struct SwrContext *s, int64_t pts);
327 
353 int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance);
354 
363 int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
364 
388 int swr_build_matrix(uint64_t in_layout, uint64_t out_layout,
389  double center_mix_level, double surround_mix_level,
390  double lfe_mix_level, double rematrix_maxval,
391  double rematrix_volume, double *matrix,
392  int stride, enum AVMatrixEncoding matrix_encoding,
393  void *log_ctx);
394 
404 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride);
405 
424 int swr_drop_output(struct SwrContext *s, int count);
425 
437 int swr_inject_silence(struct SwrContext *s, int count);
438 
463 int64_t swr_get_delay(struct SwrContext *s, int64_t base);
464 
481 int swr_get_out_samples(struct SwrContext *s, int in_samples);
482 
498 unsigned swresample_version(void);
499 
505 const char *swresample_configuration(void);
506 
512 const char *swresample_license(void);
513 
556  AVFrame *output, const AVFrame *input);
557 
572 int swr_config_frame(SwrContext *swr, const AVFrame *out, const AVFrame *in);
573 
579 #endif /* SWRESAMPLE_SWRESAMPLE_H */
void swr_close(struct SwrContext *s)
Closes the context so that swr_is_initialized() returns 0.
Definition: swresample.c:148
int out_sample_rate
output sample rate
Definition: swresample_internal.h:105
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
SoX Resampler.
Definition: swresample.h:161
SwrFilterType
Resampling Filter Types.
Definition: swresample.h:166
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:909
int swr_build_matrix(uint64_t in_layout, uint64_t out_layout, double center_mix_level, double surround_mix_level, double lfe_mix_level, double rematrix_maxval, double rematrix_volume, double *matrix, int stride, enum AVMatrixEncoding matrix_encoding, void *log_ctx)
Generate a channel mixing matrix.
Definition: rematrix.c:119
const int * channel_map
channel index (or -1 if muted channel) map
Definition: swresample_internal.h:113
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:867
int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance)
Activate resampling compensation ("soft" compensation).
Definition: swresample.c:889
struct SwrContext * swr_alloc(void)
Allocate SwrContext.
Definition: options.c:149
SwrDitherType
Dithering algorithms.
Definition: swresample.h:141
void * log_ctx
parent logging context
Definition: swresample_internal.h:98
AudioData out
converted output audio data
Definition: swresample_internal.h:152
AudioData in
input audio data
Definition: swresample_internal.h:148
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:169
enum AVSampleFormat out_sample_fmt
output sample format
Definition: swresample_internal.h:101
SwrEngine
Resampling Engines.
Definition: swresample.h:159
Blackman Nuttall windowed sinc.
Definition: swresample.h:168
int matrix_encoding
matrixed stereo encoding
Definition: swresample_internal.h:112
Definition: swresample_internal.h:95
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:859
not part of API/ABI
Definition: swresample.h:162
reference-counted frame API
not part of API/ABI
Definition: swresample.h:155
audio channel layout utility functions
int swr_drop_output(struct SwrContext *s, int count)
Drops the specified number of output samples.
Definition: swresample.c:820
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
Definition: swresample_internal.h:103
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:147
int in_sample_rate
input sample rate
Definition: swresample_internal.h:104
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:137
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
Definition: swresample_internal.h:99
Libswresample version macros.
Cubic.
Definition: swresample.h:167
double matrix[SWR_CH_MAX][SWR_CH_MAX]
floating point rematrixing coefficients
Definition: swresample_internal.h:171
SW Resampler.
Definition: swresample.h:160
int64_t in_ch_layout
input channel layout
Definition: swresample_internal.h:102
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.
Definition: swresample_frame.c:123
float lfe_mix_level
LFE mixing level.
Definition: swresample_internal.h:109
int swr_config_frame(SwrContext *swr, const AVFrame *out, const AVFrame *in)
Configure or reconfigure the SwrContext using the information provided by the AVFrames.
Definition: swresample_frame.c:26
unsigned swresample_version(void)
Return the LIBSWRESAMPLE_VERSION_INT constant.
Definition: swresample.c:35
float rematrix_maxval
maximum value for rematrixing output
Definition: swresample_internal.h:111
float rematrix_volume
rematrixing volume coefficient
Definition: swresample_internal.h:110
int swr_is_initialized(struct SwrContext *s)
Check whether an swr context has been initialized or not.
Definition: swresample.c:702
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:831
int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
Definition: swresample.c:152