Commit dc658842 authored by Michael Niedermayer's avatar 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: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 98247e33
...@@ -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->drop_temp);
free_temp(&s->dither.noise); free_temp(&s->dither.noise);
free_temp(&s->dither.temp); free_temp(&s->dither.temp);
swri_audio_convert_free(&s-> in_convert); swri_audio_convert_free(&s-> in_convert);
...@@ -239,6 +240,7 @@ av_cold int swr_init(struct SwrContext *s){ ...@@ -239,6 +240,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->drop_temp);
free_temp(&s->dither.noise); free_temp(&s->dither.noise);
free_temp(&s->dither.temp); free_temp(&s->dither.temp);
memset(s->in.ch, 0, sizeof(s->in.ch)); memset(s->in.ch, 0, sizeof(s->in.ch));
...@@ -357,6 +359,7 @@ av_assert0(s->out.ch_count); ...@@ -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->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->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){
s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt, 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 ...@@ -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){ if(s->drop_output > 0){
int ret; int ret;
AudioData tmp = s->out;
uint8_t *tmp_arg[SWR_CH_MAX]; uint8_t *tmp_arg[SWR_CH_MAX];
tmp.count = 0; if((ret=swri_realloc_audio(&s->drop_temp, s->drop_output))<0)
tmp.data = NULL;
if((ret=swri_realloc_audio(&tmp, s->drop_output))<0)
return ret; return ret;
reversefill_audiodata(&tmp, tmp_arg); reversefill_audiodata(&s->drop_temp, tmp_arg);
s->drop_output *= -1; //FIXME find a less hackish solution 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 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; s->drop_output *= -1;
if(ret>0) if(ret>0)
s->drop_output -= ret; s->drop_output -= ret;
av_freep(&tmp.data);
if(s->drop_output || !out_arg) if(s->drop_output || !out_arg)
return 0; return 0;
in_count = 0; in_count = 0;
......
...@@ -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 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
int resample_in_constraint; ///< 1 if the input end was reach before the output end, 0 otherwise int resample_in_constraint; ///< 1 if the input end was reach before the output end, 0 otherwise
......
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