[FFmpeg-cvslog] swr: move buffer used to discard sample to context

Michael Niedermayer git at videolan.org
Sun Jan 13 15:32:22 CET 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Jan 13 15:21:33 2013 +0100| [dc6588421e09d755655e5def870b2ebed515bc9d] | committer: Michael Niedermayer

swr: move buffer used to discard sample to context

This avoids the need to allocate & free to repeatly

Fixes Ticket2122

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

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

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

diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index badba7b..ad1f169 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -217,6 +217,7 @@ av_cold void swr_free(SwrContext **ss){
         free_temp(&s->midbuf);
         free_temp(&s->preout);
         free_temp(&s->in_buffer);
+        free_temp(&s->drop_temp);
         free_temp(&s->dither.noise);
         free_temp(&s->dither.temp);
         swri_audio_convert_free(&s-> in_convert);
@@ -239,6 +240,7 @@ av_cold int swr_init(struct SwrContext *s){
     free_temp(&s->midbuf);
     free_temp(&s->preout);
     free_temp(&s->in_buffer);
+    free_temp(&s->drop_temp);
     free_temp(&s->dither.noise);
     free_temp(&s->dither.temp);
     memset(s->in.ch, 0, sizeof(s->in.ch));
@@ -357,6 +359,7 @@ av_assert0(s->out.ch_count);
     s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0;
 
     s->in_buffer= s->in;
+    s->drop_temp= s->out;
 
     if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){
         s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt,
@@ -703,21 +706,17 @@ int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_coun
 
     if(s->drop_output > 0){
         int ret;
-        AudioData tmp = s->out;
         uint8_t *tmp_arg[SWR_CH_MAX];
-        tmp.count = 0;
-        tmp.data  = NULL;
-        if((ret=swri_realloc_audio(&tmp, s->drop_output))<0)
+        if((ret=swri_realloc_audio(&s->drop_temp, s->drop_output))<0)
             return ret;
 
-        reversefill_audiodata(&tmp, tmp_arg);
+        reversefill_audiodata(&s->drop_temp, tmp_arg);
         s->drop_output *= -1; //FIXME find a less hackish solution
         ret = swr_convert(s, tmp_arg, -s->drop_output, in_arg, in_count); //FIXME optimize but this is as good as never called so maybe it doesnt matter
         s->drop_output *= -1;
         if(ret>0)
             s->drop_output -= ret;
 
-        av_freep(&tmp.data);
         if(s->drop_output || !out_arg)
             return 0;
         in_count = 0;
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index 5046c6b..cfbad52 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -113,6 +113,7 @@ struct SwrContext {
     AudioData preout;                               ///< pre-output audio data: used for rematrix/resample
     AudioData out;                                  ///< converted output audio data
     AudioData in_buffer;                            ///< cached audio data (convert and resample purpose)
+    AudioData drop_temp;                            ///< temporary used to discard output
     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



More information about the ffmpeg-cvslog mailing list