diff mbox

[FFmpeg-devel] swresample/resample: Fix flush refelction length

Message ID 20170815151749.17024-1-michael@niedermayer.cc
State Accepted
Commit 0ac8fce2679e76e7caffde091141d6834405dbc1
Headers show

Commit Message

Michael Niedermayer Aug. 15, 2017, 3:17 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libswresample/resample.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Rostislav Pehlivanov Aug. 15, 2017, 8:45 p.m. UTC | #1
On 15 August 2017 at 16:17, Michael Niedermayer <michael@niedermayer.cc>
wrote:

> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libswresample/resample.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/libswresample/resample.c b/libswresample/resample.c
> index 39c242bf41..df49505bf9 100644
> --- a/libswresample/resample.c
> +++ b/libswresample/resample.c
> @@ -544,18 +544,21 @@ static int64_t get_out_samples(struct SwrContext *s,
> int in_samples) {
>  }
>
>  static int resample_flush(struct SwrContext *s) {
> +    ResampleContext *c = s->resample;
>      AudioData *a= &s->in_buffer;
>      int i, j, ret;
> -    if((ret = swri_realloc_audio(a, s->in_buffer_index +
> 2*s->in_buffer_count)) < 0)
> +    int reflection = (FFMIN(s->in_buffer_count, c->filter_length) + 1) /
> 2;
> +
> +    if((ret = swri_realloc_audio(a, s->in_buffer_index +
> s->in_buffer_count + reflection)) < 0)
>          return ret;
>      av_assert0(a->planar);
>      for(i=0; i<a->ch_count; i++){
> -        for(j=0; j<s->in_buffer_count; j++){
> +        for(j=0; j<reflection; j++){
>              memcpy(a->ch[i] + (s->in_buffer_index+s->in_buffer_count+j
> )*a->bps,
>                  a->ch[i] + (s->in_buffer_index+s->in_buffer_count-j-1)*a->bps,
> a->bps);
>          }
>      }
> -    s->in_buffer_count += (s->in_buffer_count+1)/2;
> +    s->in_buffer_count += reflection;
>      return 0;
>  }
>
> --
> 2.14.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

LGTM, patch tested

Thanks, I'll send a patch to have a FATE test for this.
Michael Niedermayer Aug. 15, 2017, 10:33 p.m. UTC | #2
On Tue, Aug 15, 2017 at 09:45:47PM +0100, Rostislav Pehlivanov wrote:
> On 15 August 2017 at 16:17, Michael Niedermayer <michael@niedermayer.cc>
> wrote:
> 
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libswresample/resample.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/libswresample/resample.c b/libswresample/resample.c
> > index 39c242bf41..df49505bf9 100644
> > --- a/libswresample/resample.c
> > +++ b/libswresample/resample.c
> > @@ -544,18 +544,21 @@ static int64_t get_out_samples(struct SwrContext *s,
> > int in_samples) {
> >  }
> >
> >  static int resample_flush(struct SwrContext *s) {
> > +    ResampleContext *c = s->resample;
> >      AudioData *a= &s->in_buffer;
> >      int i, j, ret;
> > -    if((ret = swri_realloc_audio(a, s->in_buffer_index +
> > 2*s->in_buffer_count)) < 0)
> > +    int reflection = (FFMIN(s->in_buffer_count, c->filter_length) + 1) /
> > 2;
> > +
> > +    if((ret = swri_realloc_audio(a, s->in_buffer_index +
> > s->in_buffer_count + reflection)) < 0)
> >          return ret;
> >      av_assert0(a->planar);
> >      for(i=0; i<a->ch_count; i++){
> > -        for(j=0; j<s->in_buffer_count; j++){
> > +        for(j=0; j<reflection; j++){
> >              memcpy(a->ch[i] + (s->in_buffer_index+s->in_buffer_count+j
> > )*a->bps,
> >                  a->ch[i] + (s->in_buffer_index+s->in_buffer_count-j-1)*a->bps,
> > a->bps);
> >          }
> >      }
> > -    s->in_buffer_count += (s->in_buffer_count+1)/2;
> > +    s->in_buffer_count += reflection;
> >      return 0;
> >  }
> >
> > --
> > 2.14.1
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> 
> LGTM, patch tested

will apply


> 
> Thanks, I'll send a patch to have a FATE test for this.

thanks

[...]
diff mbox

Patch

diff --git a/libswresample/resample.c b/libswresample/resample.c
index 39c242bf41..df49505bf9 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -544,18 +544,21 @@  static int64_t get_out_samples(struct SwrContext *s, int in_samples) {
 }
 
 static int resample_flush(struct SwrContext *s) {
+    ResampleContext *c = s->resample;
     AudioData *a= &s->in_buffer;
     int i, j, ret;
-    if((ret = swri_realloc_audio(a, s->in_buffer_index + 2*s->in_buffer_count)) < 0)
+    int reflection = (FFMIN(s->in_buffer_count, c->filter_length) + 1) / 2;
+
+    if((ret = swri_realloc_audio(a, s->in_buffer_index + s->in_buffer_count + reflection)) < 0)
         return ret;
     av_assert0(a->planar);
     for(i=0; i<a->ch_count; i++){
-        for(j=0; j<s->in_buffer_count; j++){
+        for(j=0; j<reflection; j++){
             memcpy(a->ch[i] + (s->in_buffer_index+s->in_buffer_count+j  )*a->bps,
                 a->ch[i] + (s->in_buffer_index+s->in_buffer_count-j-1)*a->bps, a->bps);
         }
     }
-    s->in_buffer_count += (s->in_buffer_count+1)/2;
+    s->in_buffer_count += reflection;
     return 0;
 }