]> git.sesse.net Git - ffmpeg/commitdiff
resample: fix avresample_get_delay() return value
authorAnton Khirnov <anton@khirnov.net>
Tue, 4 Mar 2014 20:18:27 +0000 (21:18 +0100)
committerAnton Khirnov <anton@khirnov.net>
Fri, 11 Apr 2014 14:21:25 +0000 (16:21 +0200)
The correct "next" input sample is not the first sample of the
resampling buffer, but the center sample of the filter_length-sized
block at the beginning.

CC:libav-stable@libav.org

libavresample/resample.c

index 69c9bab89329989d874523a8591137e93d549f3a..d9c4e019ecae14ff19a981d0b32aec15d3803fa8 100644 (file)
@@ -47,6 +47,7 @@ struct ResampleContext {
     void (*resample_one)(struct ResampleContext *c, int no_filter, void *dst0,
                          int dst_index, const void *src0, int src_size,
                          int index, int frac);
+    int padding_size;
 };
 
 
@@ -212,6 +213,7 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr)
         goto error;
     c->ideal_dst_incr = c->dst_incr;
 
+    c->padding_size   = (c->filter_length - 1) / 2;
     c->index = -phase_count * ((c->filter_length - 1) / 2);
     c->frac  = 0;
 
@@ -462,8 +464,10 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
 
 int avresample_get_delay(AVAudioResampleContext *avr)
 {
+    ResampleContext *c = avr->resample;
+
     if (!avr->resample_needed || !avr->resample)
         return 0;
 
-    return avr->resample->buffer->nb_samples;
+    return FFMAX(c->buffer->nb_samples - c->padding_size, 0);
 }