History

swr: move silence buffer to context to avoid per use malloc/free

Michael Niedermayer committed 13 years ago

Commit db4e0ec1 parent dc658842 files · +9 −9Browse files

Showing the changes to libswresample (2 of 2 files). Show all

Unified · Split

2 files
  1. libswresample/swresample.c +8 −9
  2. libswresample/swresample_internal.h +1 −0
libswresample/swresample.c+8−9
@@ -217,6 +217,7 @@ av_cold void swr_free(SwrContext **ss){ · 216 unmodified lines
217217 free_temp(&s->midbuf);
218218 free_temp(&s->preout);
219219 free_temp(&s->in_buffer);
220+ free_temp(&s->silence);
220221 free_temp(&s->drop_temp);
221222 free_temp(&s->dither.noise);
222223 free_temp(&s->dither.temp);
@@ -240,6 +241,7 @@ av_cold int swr_init(struct SwrContext *s){ · 17 unmodified lines
240241 free_temp(&s->midbuf);
241242 free_temp(&s->preout);
242243 free_temp(&s->in_buffer);
244+ free_temp(&s->silence);
243245 free_temp(&s->drop_temp);
244246 free_temp(&s->dither.noise);
245247 free_temp(&s->dither.temp);
@@ -359,6 +361,7 @@ av_assert0(s->out.ch_count); · 113 unmodified lines
359361 s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0;
360362
361363 s->in_buffer= s->in;
364+ s->silence = s->in;
362365 s->drop_temp= s->out;
363366
364367 if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){
@@ -807,26 +810,22 @@ int swr_drop_output(struct SwrContext *s, int count){ · 442 unmodified lines
807810
808811 int swr_inject_silence(struct SwrContext *s, int count){
809812 int ret, i;
810− AudioData silence = s->in;
811813 uint8_t *tmp_arg[SWR_CH_MAX];
812814
813815 if(count <= 0)
814816 return 0;
815817
816− silence.count = 0;
817− silence.data = NULL;
818− if((ret=swri_realloc_audio(&silence, count))<0)
818+ if((ret=swri_realloc_audio(&s->silence, count))<0)
819819 return ret;
820820
821− if(silence.planar) for(i=0; i<silence.ch_count; i++) {
822− memset(silence.ch[i], silence.bps==1 ? 0x80 : 0, count*silence.bps);
821+ if(s->silence.planar) for(i=0; i<s->silence.ch_count; i++) {
822+ memset(s->silence.ch[i], s->silence.bps==1 ? 0x80 : 0, count*s->silence.bps);
823823 } else
824− memset(silence.ch[0], silence.bps==1 ? 0x80 : 0, count*silence.bps*silence.ch_count);
824+ memset(s->silence.ch[0], s->silence.bps==1 ? 0x80 : 0, count*s->silence.bps*s->silence.ch_count);
825825
826− reversefill_audiodata(&silence, tmp_arg);
826+ reversefill_audiodata(&s->silence, tmp_arg);
827827 av_log(s, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", count);
828828 ret = swr_convert(s, NULL, 0, (const uint8_t**)tmp_arg, count);
829− av_freep(&silence.data);
830829 return ret;
831830 }
832831
libswresample/swresample_internal.h+1−0
@@ -113,6 +113,7 @@ struct SwrContext { · 112 unmodified lines
113113 AudioData preout; ///< pre-output audio data: used for rematrix/resample
114114 AudioData out; ///< converted output audio data
115115 AudioData in_buffer; ///< cached audio data (convert and resample purpose)
116+ AudioData silence; ///< temporary with silence
116117 AudioData drop_temp; ///< temporary used to discard output
117118 int in_buffer_index; ///< cached buffer position
118119 int in_buffer_count; ///< cached buffer length

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t