swr: move buffer used to discard sample to context
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 13 Jan 2013 14:21:33 +0000 (15:21 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 13 Jan 2013 14:28:00 +0000 (15:28 +0100)
This avoids the need to allocate & free to repeatly

Fixes Ticket2122

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libswresample/swresample.c
libswresample/swresample_internal.h

index badba7b..ad1f169 100644 (file)
@@ -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;
index 5046c6b..cfbad52 100644 (file)
@@ -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