[vlc-devel] [PATCH] ugly resampler, handle that output data isn't longer than input data
ileoo at videolan.org
ileoo at videolan.org
Sun Apr 20 11:24:49 CEST 2014
From: Ilkka Ollakka <ileoo at videolan.org>
---
modules/audio_filter/resampler/ugly.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/modules/audio_filter/resampler/ugly.c b/modules/audio_filter/resampler/ugly.c
index 796c499..8628429 100644
--- a/modules/audio_filter/resampler/ugly.c
+++ b/modules/audio_filter/resampler/ugly.c
@@ -95,34 +95,33 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
return p_in_buf;
block_t *p_out_buf = p_in_buf;
- unsigned int i_out_nb = p_in_buf->i_nb_samples
- * p_filter->fmt_out.audio.i_rate / p_filter->fmt_in.audio.i_rate;
- const unsigned framesize = (p_filter->fmt_in.audio.i_bitspersample / 8)
+ int i_out_nb = p_in_buf->i_nb_samples
+ * p_filter->fmt_out.audio.i_rate;
+ const uint8_t framesize = (p_filter->fmt_in.audio.i_bitspersample / 8)
* aout_FormatNbChannels( &p_filter->fmt_in.audio );
if( p_filter->fmt_out.audio.i_rate > p_filter->fmt_in.audio.i_rate )
{
- p_out_buf = block_Alloc( i_out_nb * framesize );
+ p_out_buf = block_Alloc( (i_out_nb * framesize) / p_filter->fmt_in.audio.i_rate );
if( !p_out_buf )
goto out;
}
+ msg_Info( p_filter, "input samples %d length %d", p_in_buf->i_nb_samples, p_in_buf->i_length );
- unsigned char *p_out = p_out_buf->p_buffer;
- unsigned char *p_in = p_in_buf->p_buffer;
+ uint8_t *p_out = p_out_buf->p_buffer;
+ uint8_t *p_in = p_in_buf->p_buffer;
unsigned int i_remainder = 0;
- p_out_buf->i_nb_samples = i_out_nb;
- p_out_buf->i_buffer = i_out_nb * framesize;
+ p_out_buf->i_nb_samples = 0;
p_out_buf->i_pts = p_in_buf->i_pts;
- p_out_buf->i_length = p_out_buf->i_nb_samples *
- 1000000 / p_filter->fmt_out.audio.i_rate;
- while( i_out_nb )
+ while( i_out_nb >= p_filter->fmt_in.audio.i_rate )
{
if( p_out != p_in )
memcpy( p_out, p_in, framesize );
p_out += framesize;
- i_out_nb--;
+ i_out_nb -= p_filter->fmt_in.audio.i_rate;
+ p_out_buf->i_nb_samples++;
i_remainder += p_filter->fmt_in.audio.i_rate;
while( i_remainder >= p_filter->fmt_out.audio.i_rate )
@@ -131,6 +130,10 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
i_remainder -= p_filter->fmt_out.audio.i_rate;
}
}
+ p_out_buf->i_buffer = p_out_buf->i_nb_samples * framesize;
+ p_out_buf->i_length = p_out_buf->i_nb_samples *
+ CLOCK_FREQ / p_filter->fmt_out.audio.i_rate;
+ msg_Info( p_filter, "output samples %d length %d", p_out_buf->i_nb_samples, p_out_buf->i_length );
if( p_in_buf != p_out_buf )
out:
--
1.8.4.5
More information about the vlc-devel
mailing list