[FFmpeg-cvslog] swr: allow flushing in multiple steps if the output is too small.

Michael Niedermayer git at videolan.org
Sun Mar 25 04:59:19 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Mar 25 03:33:06 2012 +0200| [4f16153d35920970fededa3a05bbfd9dd3bc69b0] | committer: Michael Niedermayer

swr: allow flushing in multiple steps if the output is too small.

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

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4f16153d35920970fededa3a05bbfd9dd3bc69b0
---

 libswresample/swresample.c          |   25 ++++++++++++++-----------
 libswresample/swresample_internal.h |    1 +
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 44a2917..5ce377f 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -435,19 +435,22 @@ int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_coun
 
     if(!in_arg){
         if(s->in_buffer_count){
-            AudioData *a= &s->in_buffer;
-            int i, j, ret;
-            if((ret=realloc_audio(a, s->in_buffer_index + 2*s->in_buffer_count)) < 0)
-                return ret;
-            av_assert0(a->planar);
-            for(i=0; i<a->ch_count; i++){
-                for(j=0; j<s->in_buffer_count; 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);
+            if (!s->flushed) {
+                AudioData *a= &s->in_buffer;
+                int i, j, ret;
+                if((ret=realloc_audio(a, s->in_buffer_index + 2*s->in_buffer_count)) < 0)
+                    return ret;
+                av_assert0(a->planar);
+                for(i=0; i<a->ch_count; i++){
+                    for(j=0; j<s->in_buffer_count; 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->resample_in_constraint = 0;
+                s->flushed = 1;
             }
-            s->in_buffer_count += (s->in_buffer_count+1)/2;
-            s->resample_in_constraint = 0;
         }else{
             return 0;
         }
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index e3c0b3d..dc7304c 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -64,6 +64,7 @@ struct SwrContext {
     int in_buffer_index;                            ///< cached buffer position
     int in_buffer_count;                            ///< cached buffer length
     int resample_in_constraint;                     ///< 1 if the input end was reach before the output end, 0 otherwise
+    int flushed;                                    ///< 1 if data is to be flushed and no further input is expected
 
     struct AudioConvert *in_convert;                ///< input conversion context
     struct AudioConvert *out_convert;               ///< output conversion context



More information about the ffmpeg-cvslog mailing list