Commit db51e7a1 authored by Jean-Paul Saman's avatar Jean-Paul Saman

davinci: save one memcpy per audio encoding pass

Write directly into the special DSP buffer and only copy the remainder to a temporarily buffer.
parent 003d3088
......@@ -79,6 +79,8 @@ struct xdm_sys_t
/* remainder buffer management */
uint8_t *p_tmp;
size_t i_tmp;
size_t i_nb_bytes;
uint32_t i_nb_samples;
mtime_t start_date;
......@@ -558,8 +560,6 @@ static block_t *EncodeAudio1( encoder_t *p_enc, aout_buffer_t *p_buffer )
}
else
{
// FIXME: optimize by using xdm->in.descs[0].buf for filling and xdm->p_tmp as overflow
// This will save several memcpy's
uint32_t i_nb_delayed_samples = 0;
size_t i_size = 0;
......@@ -567,9 +567,16 @@ static block_t *EncodeAudio1( encoder_t *p_enc, aout_buffer_t *p_buffer )
if( xdm->start_date == 0 )
xdm->start_date = p_buffer->start_date;
if( xdm->i_tmp > 0 )
{
memcpy( (uint8_t*)xdm->in.descs[0].buf + xdm->i_nb_bytes, xdm->p_tmp, xdm->i_tmp );
xdm->i_nb_bytes += xdm->i_tmp;
xdm->i_tmp = 0;
}
if( xdm->i_nb_bytes + p_buffer->i_nb_bytes <= (size_t)xdm->in.descs[0].bufSize )
{
memcpy( xdm->p_tmp + xdm->i_nb_bytes, p_buffer->p_buffer, p_buffer->i_nb_bytes );
memcpy( (uint8_t*)xdm->in.descs[0].buf + xdm->i_nb_bytes, p_buffer->p_buffer, p_buffer->i_nb_bytes );
xdm->i_nb_bytes += p_buffer->i_nb_bytes;
xdm->i_nb_samples += p_buffer->i_nb_samples;
......@@ -586,7 +593,7 @@ static block_t *EncodeAudio1( encoder_t *p_enc, aout_buffer_t *p_buffer )
{
i_size = xdm->in.descs[0].bufSize - xdm->i_nb_bytes;
i_size = __MIN(i_size, p_buffer->i_nb_bytes);
memcpy( xdm->p_tmp + xdm->i_nb_bytes, p_buffer->p_buffer, i_size );
memcpy( (uint8_t*)xdm->in.descs[0].buf + xdm->i_nb_bytes, p_buffer->p_buffer, i_size );
i_nb_delayed_samples = p_buffer->i_nb_samples - (xdm->i_frames - xdm->i_nb_samples);
xdm->i_nb_samples += (p_buffer->i_nb_samples - i_nb_delayed_samples);
......@@ -601,7 +608,6 @@ static block_t *EncodeAudio1( encoder_t *p_enc, aout_buffer_t *p_buffer )
/* always fill entire encoder bufer */
assert( (uint32_t)xdm->in.descs[0].bufSize == xdm->i_nb_bytes );
memcpy( (uint8_t*)xdm->in.descs[0].buf, xdm->p_tmp, xdm->i_nb_bytes );
/* samples in DSP buffer */
i_nb_samples = xdm->i_nb_samples;
......@@ -614,8 +620,9 @@ static block_t *EncodeAudio1( encoder_t *p_enc, aout_buffer_t *p_buffer )
{
memset( xdm->p_tmp, 0, (uint32_t)xdm->in.descs[0].bufSize );
memcpy( xdm->p_tmp, p_buffer->p_buffer + i_size, p_buffer->i_nb_bytes - i_size );
xdm->i_tmp = p_buffer->i_nb_bytes - i_size;
xdm->i_nb_bytes = p_buffer->i_nb_bytes - i_size;
xdm->i_nb_bytes = 0;
xdm->i_nb_samples = i_nb_delayed_samples;
xdm->start_date = i_pts_end;
......
......@@ -74,6 +74,8 @@ struct xdm_sys_t
/* remainder buffer management */
uint8_t *p_tmp;
size_t i_tmp;
size_t i_nb_bytes;
uint32_t i_nb_samples;
mtime_t start_date;
......@@ -316,8 +318,6 @@ static block_t *EncodeAudio( encoder_t *p_enc, aout_buffer_t *p_buffer )
}
else
{
// FIXME: optimize by using xdm->in.bufs[0] for filling and xdm->p_tmp as overflow
// This will save several memcpy's
uint32_t i_nb_delayed_samples = 0;
size_t i_size = 0;
......@@ -325,9 +325,16 @@ static block_t *EncodeAudio( encoder_t *p_enc, aout_buffer_t *p_buffer )
if( xdm->start_date == 0 )
xdm->start_date = p_buffer->start_date;
if( xdm->i_tmp > 0 )
{
memcpy( (uint8_t*)xdm->in.bufs[0] + xdm->i_nb_bytes, xdm->p_tmp, xdm->i_tmp );
xdm->i_nb_bytes += xdm->i_tmp;
xdm->i_tmp = 0;
}
if( xdm->i_nb_bytes + p_buffer->i_nb_bytes <= (size_t)xdm->in.bufSizes[0] )
{
memcpy( xdm->p_tmp + xdm->i_nb_bytes, p_buffer->p_buffer, p_buffer->i_nb_bytes );
memcpy( (uint8_t*)xdm->in.bufs[0] + xdm->i_nb_bytes, p_buffer->p_buffer, p_buffer->i_nb_bytes );
xdm->i_nb_bytes += p_buffer->i_nb_bytes;
xdm->i_nb_samples += p_buffer->i_nb_samples;
......@@ -344,7 +351,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, aout_buffer_t *p_buffer )
{
i_size = xdm->in.bufSizes[0] - xdm->i_nb_bytes;
i_size = __MIN(i_size, p_buffer->i_nb_bytes);
memcpy( xdm->p_tmp + xdm->i_nb_bytes, p_buffer->p_buffer, i_size );
memcpy( (uint8_t*)xdm->in.bufs[0] + xdm->i_nb_bytes, p_buffer->p_buffer, i_size );
i_nb_delayed_samples = p_buffer->i_nb_samples - (xdm->i_frames - xdm->i_nb_samples);
xdm->i_nb_samples += (p_buffer->i_nb_samples - i_nb_delayed_samples);
......@@ -359,7 +366,6 @@ static block_t *EncodeAudio( encoder_t *p_enc, aout_buffer_t *p_buffer )
/* always fill entire encoder bufer */
assert( (uint32_t)xdm->in.bufSizes[0] == xdm->i_nb_bytes );
memcpy( (uint8_t*)xdm->in.bufs[0], xdm->p_tmp, xdm->i_nb_bytes );
/* samples in DSP buffer */
i_nb_samples = xdm->i_nb_samples;
......@@ -372,8 +378,9 @@ static block_t *EncodeAudio( encoder_t *p_enc, aout_buffer_t *p_buffer )
{
memset( xdm->p_tmp, 0, (uint32_t)xdm->in.bufSizes[0] );
memcpy( xdm->p_tmp, p_buffer->p_buffer + i_size, p_buffer->i_nb_bytes - i_size );
xdm->i_tmp = p_buffer->i_nb_bytes - i_size;
xdm->i_nb_bytes = p_buffer->i_nb_bytes - i_size;
xdm->i_nb_bytes = 0;
xdm->i_nb_samples = i_nb_delayed_samples;
xdm->start_date = i_pts_end;
......
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