]> git.sesse.net Git - casparcg/blob - ffmpeg 0.8/include/libswresample/swresample.h
(no commit message)
[casparcg] / ffmpeg 0.8 / include / 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 4
34 #define LIBSWRESAMPLE_VERSION_MICRO 0
35
36 #define SWR_CH_MAX 16   ///< Maximum number of channels
37
38 #define SWR_FLAG_RESAMPLE 1 ///< Force resampling even if equal sample rate
39 //TODO use int resample ?
40 //long term TODO can we enable this dynamically?
41
42
43 struct SwrContext;
44
45 /**
46  * Allocate SwrContext.
47  *
48  * If you use this function you will need to set the parameters (manually or
49  * with swr_alloc_set_opts()) before calling swr_init().
50  *
51  * @see swr_alloc_set_opts(), swr_init(), swr_free()
52  * @return NULL on error, allocated context otherwise
53  */
54 struct SwrContext *swr_alloc(void);
55
56 /**
57  * Initialize context after user parameters have been set.
58  *
59  * @return AVERROR error code in case of failure.
60  */
61 int swr_init(struct SwrContext *s);
62
63 /**
64  * Allocate SwrContext if needed and set/reset common parameters.
65  *
66  * This function does not require s to be allocated with swr_alloc(). On the
67  * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters
68  * on the allocated context.
69  *
70  * @param s               Swr context, can be NULL
71  * @param out_ch_layout   output channel layout (AV_CH_LAYOUT_*)
72  * @param out_sample_fmt  output sample format (AV_SAMPLE_FMT_*). Use +0x100 for planar audio
73  * @param out_sample_rate output sample rate (frequency in Hz)
74  * @param in_ch_layout    input channel layout (AV_CH_LAYOUT_*)
75  * @param in_sample_fmt   input sample format (AV_SAMPLE_FMT_*). Use +0x100 for planar audio
76  * @param in_sample_rate  input sample rate (frequency in Hz)
77  * @param log_offset      logging level offset
78  * @param log_ctx         parent logging context, can be NULL
79  *
80  * @see swr_init(), swr_free()
81  * @return NULL on error, allocated context otherwise
82  */
83 struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
84                                       int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
85                                       int64_t  in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
86                                       int log_offset, void *log_ctx);
87
88 /**
89  * Free the given SwrContext and set the pointer to NULL.
90  */
91 void swr_free(struct SwrContext **s);
92
93 /**
94  * Convert audio.
95  *
96  * in and in_count can be set to 0 to flush the last few samples out at the
97  * end.
98  *
99  * @param s         allocated Swr context, with parameters set
100  * @param out       output buffers, only the first one need be set in case of packed audio
101  * @param out_count amount of space available for output in samples per channel
102  * @param in        input buffers, only the first one need to be set in case of packed audio
103  * @param in_count  number of input samples available in one channel
104  *
105  * @return number of samples output per channel
106  */
107 int swr_convert(struct SwrContext *s, uint8_t *out[SWR_CH_MAX], int out_count,
108                                 const uint8_t *in [SWR_CH_MAX], int in_count);
109
110 /**
111  * Activate resampling compensation.
112  */
113 void swr_compensate(struct SwrContext *s, int sample_delta, int compensation_distance);
114
115 /**
116  * Set a customized input channel mapping.
117  *
118  * @param s           allocated Swr context, not yet initialized
119  * @param channel_map customized input channel mapping (array of channel
120  *                    indexes, -1 for a muted channel)
121  * @return AVERROR error code in case of failure.
122  */
123 int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
124
125 #endif