]> git.sesse.net Git - ffmpeg/blob - libswresample/swresample.h
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libswresample / swresample.h
1 /*
2  * Copyright (C) 2011 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 /**
22  * @file
23  * libswresample public header
24  */
25
26 #ifndef SWR_H
27 #define SWR_H
28
29 #include <inttypes.h>
30 #include "libavutil/samplefmt.h"
31
32 #define LIBSWRESAMPLE_VERSION_MAJOR 0
33 #define LIBSWRESAMPLE_VERSION_MINOR 10
34 #define LIBSWRESAMPLE_VERSION_MICRO 100
35
36 #define LIBSWRESAMPLE_VERSION_INT  AV_VERSION_INT(LIBSWRESAMPLE_VERSION_MAJOR, \
37                                                   LIBSWRESAMPLE_VERSION_MINOR, \
38                                                   LIBSWRESAMPLE_VERSION_MICRO)
39
40 #if LIBSWRESAMPLE_VERSION_MAJOR < 1
41 #define SWR_CH_MAX 32   ///< Maximum number of channels
42 #endif
43
44 #define SWR_FLAG_RESAMPLE 1 ///< Force resampling even if equal sample rate
45 //TODO use int resample ?
46 //long term TODO can we enable this dynamically?
47
48
49 typedef struct SwrContext SwrContext;
50
51 /**
52  * Allocate SwrContext.
53  *
54  * If you use this function you will need to set the parameters (manually or
55  * with swr_alloc_set_opts()) before calling swr_init().
56  *
57  * @see swr_alloc_set_opts(), swr_init(), swr_free()
58  * @return NULL on error, allocated context otherwise
59  */
60 struct SwrContext *swr_alloc(void);
61
62 /**
63  * Initialize context after user parameters have been set.
64  *
65  * @return AVERROR error code in case of failure.
66  */
67 int swr_init(struct SwrContext *s);
68
69 /**
70  * Allocate SwrContext if needed and set/reset common parameters.
71  *
72  * This function does not require s to be allocated with swr_alloc(). On the
73  * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters
74  * on the allocated context.
75  *
76  * @param s               Swr context, can be NULL
77  * @param out_ch_layout   output channel layout (AV_CH_LAYOUT_*)
78  * @param out_sample_fmt  output sample format (AV_SAMPLE_FMT_*).
79  * @param out_sample_rate output sample rate (frequency in Hz)
80  * @param in_ch_layout    input channel layout (AV_CH_LAYOUT_*)
81  * @param in_sample_fmt   input sample format (AV_SAMPLE_FMT_*).
82  * @param in_sample_rate  input sample rate (frequency in Hz)
83  * @param log_offset      logging level offset
84  * @param log_ctx         parent logging context, can be NULL
85  *
86  * @see swr_init(), swr_free()
87  * @return NULL on error, allocated context otherwise
88  */
89 struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
90                                       int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
91                                       int64_t  in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
92                                       int log_offset, void *log_ctx);
93
94 /**
95  * Free the given SwrContext and set the pointer to NULL.
96  */
97 void swr_free(struct SwrContext **s);
98
99 /**
100  * Convert audio.
101  *
102  * in and in_count can be set to 0 to flush the last few samples out at the
103  * end.
104  *
105  * If more input is provided than output space then the input will be buffered.
106  * You can avoid this buffering by providing more output space than input.
107  * Convertion will run directly without copying whenever possible.
108  *
109  * @param s         allocated Swr context, with parameters set
110  * @param out       output buffers, only the first one need be set in case of packed audio
111  * @param out_count amount of space available for output in samples per channel
112  * @param in        input buffers, only the first one need to be set in case of packed audio
113  * @param in_count  number of input samples available in one channel
114  *
115  * @return number of samples output per channel, negative value on error
116  */
117 int swr_convert(struct SwrContext *s, uint8_t **out, int out_count,
118                                 const uint8_t **in , int in_count);
119
120 /**
121  * Activate resampling compensation.
122  */
123 int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance);
124
125 /**
126  * Set a customized input channel mapping.
127  *
128  * @param s           allocated Swr context, not yet initialized
129  * @param channel_map customized input channel mapping (array of channel
130  *                    indexes, -1 for a muted channel)
131  * @return AVERROR error code in case of failure.
132  */
133 int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
134
135 /**
136  * Set a customized remix matrix.
137  *
138  * @param s       allocated Swr context, not yet initialized
139  * @param matrix  remix coefficients; matrix[i + stride * o] is
140  *                the weight of input channel i in output channel o
141  * @param stride  offset between lines of the matrix
142  * @return  AVERROR error code in case of failure.
143  */
144 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride);
145
146 /**
147  * Return the LIBSWRESAMPLE_VERSION_INT constant.
148  */
149 unsigned swresample_version(void);
150
151 /**
152  * Return the swr build-time configuration.
153  */
154 const char *swresample_configuration(void);
155
156 /**
157  * Return the swr license.
158  */
159 const char *swresample_license(void);
160
161 #endif