Commit db4e0eca authored by Michael Niedermayer's avatar Michael Niedermayer

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

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent dc658842
...@@ -217,6 +217,7 @@ av_cold void swr_free(SwrContext **ss){ ...@@ -217,6 +217,7 @@ av_cold void swr_free(SwrContext **ss){
free_temp(&s->midbuf); free_temp(&s->midbuf);
free_temp(&s->preout); free_temp(&s->preout);
free_temp(&s->in_buffer); free_temp(&s->in_buffer);
free_temp(&s->silence);
free_temp(&s->drop_temp); free_temp(&s->drop_temp);
free_temp(&s->dither.noise); free_temp(&s->dither.noise);
free_temp(&s->dither.temp); free_temp(&s->dither.temp);
...@@ -240,6 +241,7 @@ av_cold int swr_init(struct SwrContext *s){ ...@@ -240,6 +241,7 @@ av_cold int swr_init(struct SwrContext *s){
free_temp(&s->midbuf); free_temp(&s->midbuf);
free_temp(&s->preout); free_temp(&s->preout);
free_temp(&s->in_buffer); free_temp(&s->in_buffer);
free_temp(&s->silence);
free_temp(&s->drop_temp); free_temp(&s->drop_temp);
free_temp(&s->dither.noise); free_temp(&s->dither.noise);
free_temp(&s->dither.temp); free_temp(&s->dither.temp);
...@@ -359,6 +361,7 @@ av_assert0(s->out.ch_count); ...@@ -359,6 +361,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->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->in_buffer= s->in;
s->silence = s->in;
s->drop_temp= s->out; s->drop_temp= s->out;
if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){ if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){
...@@ -807,26 +810,22 @@ int swr_drop_output(struct SwrContext *s, int count){ ...@@ -807,26 +810,22 @@ int swr_drop_output(struct SwrContext *s, int count){
int swr_inject_silence(struct SwrContext *s, int count){ int swr_inject_silence(struct SwrContext *s, int count){
int ret, i; int ret, i;
AudioData silence = s->in;
uint8_t *tmp_arg[SWR_CH_MAX]; uint8_t *tmp_arg[SWR_CH_MAX];
if(count <= 0) if(count <= 0)
return 0; return 0;
silence.count = 0; if((ret=swri_realloc_audio(&s->silence, count))<0)
silence.data = NULL;
if((ret=swri_realloc_audio(&silence, count))<0)
return ret; return ret;
if(silence.planar) for(i=0; i<silence.ch_count; i++) { if(s->silence.planar) for(i=0; i<s->silence.ch_count; i++) {
memset(silence.ch[i], silence.bps==1 ? 0x80 : 0, count*silence.bps); memset(s->silence.ch[i], s->silence.bps==1 ? 0x80 : 0, count*s->silence.bps);
} else } else
memset(silence.ch[0], silence.bps==1 ? 0x80 : 0, count*silence.bps*silence.ch_count); memset(s->silence.ch[0], s->silence.bps==1 ? 0x80 : 0, count*s->silence.bps*s->silence.ch_count);
reversefill_audiodata(&silence, tmp_arg); reversefill_audiodata(&s->silence, tmp_arg);
av_log(s, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", count); av_log(s, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", count);
ret = swr_convert(s, NULL, 0, (const uint8_t**)tmp_arg, count); ret = swr_convert(s, NULL, 0, (const uint8_t**)tmp_arg, count);
av_freep(&silence.data);
return ret; return ret;
} }
......
...@@ -113,6 +113,7 @@ struct SwrContext { ...@@ -113,6 +113,7 @@ struct SwrContext {
AudioData preout; ///< pre-output audio data: used for rematrix/resample AudioData preout; ///< pre-output audio data: used for rematrix/resample
AudioData out; ///< converted output audio data AudioData out; ///< converted output audio data
AudioData in_buffer; ///< cached audio data (convert and resample purpose) AudioData in_buffer; ///< cached audio data (convert and resample purpose)
AudioData silence; ///< temporary with silence
AudioData drop_temp; ///< temporary used to discard output AudioData drop_temp; ///< temporary used to discard output
int in_buffer_index; ///< cached buffer position int in_buffer_index; ///< cached buffer position
int in_buffer_count; ///< cached buffer length int in_buffer_count; ///< cached buffer length
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment