summaryrefslogtreecommitdiff
path: root/libswresample/audioconvert.c
diff options
context:
space:
mode:
authorClément Bœsch <ubitux@gmail.com>2011-11-04 18:54:01 +0100
committerClément Bœsch <ubitux@gmail.com>2011-11-04 19:40:32 +0100
commitf5cd136f2bcdb69abbd5b8335b247be41259da31 (patch)
tree14cf22ac81fd14ef0c89a2ba49cb7705fc9fbd6c /libswresample/audioconvert.c
parent682e0eaf148db9479bedb981910aea21ad1827dd (diff)
downloadffmpeg-f5cd136f2bcdb69abbd5b8335b247be41259da31.tar.gz
ffmpeg: add -map_channel option.
Based on an initial work by Baptiste Coudurier.
Diffstat (limited to 'libswresample/audioconvert.c')
-rw-r--r--libswresample/audioconvert.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c
index a1fa3eb10c..ba90348b89 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -35,11 +35,13 @@
struct AVAudioConvert {
int channels;
int fmt_pair;
+ const int *ch_map;
};
AVAudioConvert *swr_audio_convert_alloc(enum AVSampleFormat out_fmt,
enum AVSampleFormat in_fmt,
- int channels, int flags)
+ int channels, const int *ch_map,
+ int flags)
{
AVAudioConvert *ctx;
ctx = av_malloc(sizeof(AVAudioConvert));
@@ -47,6 +49,7 @@ AVAudioConvert *swr_audio_convert_alloc(enum AVSampleFormat out_fmt,
return NULL;
ctx->channels = channels;
ctx->fmt_pair = out_fmt + AV_SAMPLE_FMT_NB*in_fmt;
+ ctx->ch_map = ch_map;
return ctx;
}
@@ -58,15 +61,17 @@ void swr_audio_convert_free(AVAudioConvert **ctx)
int swr_audio_convert(AVAudioConvert *ctx, AudioData *out, AudioData*in, int len)
{
int ch;
+ const uint8_t null_input[8] = {0};
av_assert0(ctx->channels == out->ch_count);
//FIXME optimize common cases
for(ch=0; ch<ctx->channels; ch++){
- const int is= (in ->planar ? 1 : in->ch_count) * in->bps;
+ const int ich= ctx->ch_map ? ctx->ch_map[ch] : ch;
+ const int is= ich < 0 ? 0 : (in->planar ? 1 : in->ch_count) * in->bps;
const int os= (out->planar ? 1 :out->ch_count) *out->bps;
- const uint8_t *pi= in ->ch[ch];
+ const uint8_t *pi= ich < 0 ? null_input : in->ch[ich];
uint8_t *po= out->ch[ch];
uint8_t *end= po + os*len;
if(!po)