diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-01-13 15:26:04 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-01-13 15:28:00 +0100 |
commit | db4e0ecaf0e945a8a4688eee8307953d53e9e030 (patch) | |
tree | 4f76bcdab24c3ab8d3cef633052406ce8128ad55 | |
parent | dc6588421e09d755655e5def870b2ebed515bc9d (diff) | |
download | ffmpeg-db4e0ecaf0e945a8a4688eee8307953d53e9e030.tar.gz |
swr: move silence buffer to context to avoid per use malloc/free
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libswresample/swresample.c | 17 | ||||
-rw-r--r-- | libswresample/swresample_internal.h | 1 |
2 files changed, 9 insertions, 9 deletions
diff --git a/libswresample/swresample.c b/libswresample/swresample.c index ad1f16941e..4576d2f431 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->silence); free_temp(&s->drop_temp); free_temp(&s->dither.noise); free_temp(&s->dither.temp); @@ -240,6 +241,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->silence); free_temp(&s->drop_temp); free_temp(&s->dither.noise); free_temp(&s->dither.temp); @@ -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->in_buffer= s->in; + s->silence = s->in; s->drop_temp= s->out; if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){ @@ -807,26 +810,22 @@ int swr_drop_output(struct SwrContext *s, int count){ int swr_inject_silence(struct SwrContext *s, int count){ int ret, i; - AudioData silence = s->in; uint8_t *tmp_arg[SWR_CH_MAX]; if(count <= 0) return 0; - silence.count = 0; - silence.data = NULL; - if((ret=swri_realloc_audio(&silence, count))<0) + if((ret=swri_realloc_audio(&s->silence, count))<0) return ret; - if(silence.planar) for(i=0; i<silence.ch_count; i++) { - memset(silence.ch[i], silence.bps==1 ? 0x80 : 0, count*silence.bps); + if(s->silence.planar) for(i=0; i<s->silence.ch_count; i++) { + memset(s->silence.ch[i], s->silence.bps==1 ? 0x80 : 0, count*s->silence.bps); } 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); ret = swr_convert(s, NULL, 0, (const uint8_t**)tmp_arg, count); - av_freep(&silence.data); return ret; } diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h index cfbad52e90..be332d0039 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 silence; ///< temporary with silence AudioData drop_temp; ///< temporary used to discard output int in_buffer_index; ///< cached buffer position int in_buffer_count; ///< cached buffer length |