Browse code

libswresample: support directly converting sampleformats and packed/planar in a single pass.

Previously a intermediate planar format was used when both input and output where packed.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/10/06 06:46:50
Showing 2 changed files
... ...
@@ -110,6 +110,7 @@ void swr_free(SwrContext **ss){
110 110
         free_temp(&s->in_buffer);
111 111
         swr_audio_convert_free(&s-> in_convert);
112 112
         swr_audio_convert_free(&s->out_convert);
113
+        swr_audio_convert_free(&s->full_convert);
113 114
         swr_resample_free(&s->resample);
114 115
     }
115 116
 
... ...
@@ -138,6 +139,7 @@ int swr_init(SwrContext *s){
138 138
     free_temp(&s->in_buffer);
139 139
     swr_audio_convert_free(&s-> in_convert);
140 140
     swr_audio_convert_free(&s->out_convert);
141
+    swr_audio_convert_free(&s->full_convert);
141 142
 
142 143
     s-> in.planar= s-> in_sample_fmt >= 0x100;
143 144
     s->out.planar= s->out_sample_fmt >= 0x100;
... ...
@@ -196,6 +198,12 @@ av_assert0(s->out.ch_count);
196 196
     s->int_bps= av_get_bits_per_sample_fmt(s->int_sample_fmt)/8;
197 197
     s->out.bps= av_get_bits_per_sample_fmt(s->out_sample_fmt)/8;
198 198
 
199
+    if(!s->resample && !s->rematrix){
200
+        s->full_convert = swr_audio_convert_alloc(s->out_sample_fmt,
201
+                                                  s-> in_sample_fmt, s-> in.ch_count, 0);
202
+        return 0;
203
+    }
204
+
199 205
     s->in_convert = swr_audio_convert_alloc(s->int_sample_fmt,
200 206
                                             s-> in_sample_fmt, s-> in.ch_count, 0);
201 207
     s->out_convert= swr_audio_convert_alloc(s->out_sample_fmt,
... ...
@@ -291,6 +299,12 @@ int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_coun
291 291
     fill_audiodata(in ,  in_arg);
292 292
     fill_audiodata(out, out_arg);
293 293
 
294
+    if(s->full_convert){
295
+        av_assert0(!s->resample);
296
+        swr_audio_convert(s->full_convert, out, in, in_count);
297
+        return out_count;
298
+    }
299
+
294 300
 //     in_max= out_count*(int64_t)s->in_sample_rate / s->out_sample_rate + resample_filter_taps;
295 301
 //     in_count= FFMIN(in_count, in_in + 2 - s->hist_buffer_count);
296 302
 
... ...
@@ -58,6 +58,7 @@ typedef struct SwrContext {          //FIXME find unused fields
58 58
 
59 59
     struct AVAudioConvert *in_convert;
60 60
     struct AVAudioConvert *out_convert;
61
+    struct AVAudioConvert *full_convert;
61 62
     struct AVResampleContext *resample;
62 63
 
63 64
     float matrix[SWR_CH_MAX][SWR_CH_MAX];