Commit bbb02213 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

stream_demux: simplify pf_read()

parent 776959f7
......@@ -173,46 +173,45 @@ static void DStreamDelete( stream_t *s )
}
static ssize_t DStreamRead( stream_t *s, void *p_read, size_t i_read )
static ssize_t DStreamRead( stream_t *s, void *buf, size_t len )
{
stream_sys_t *p_sys = s->p_sys;
uint8_t *p_out = p_read;
size_t i_out = 0;
stream_sys_t *sys = s->p_sys;
if( !atomic_load( &sys->active ) )
return -1;
if( s->b_error )
return -1;
if( len == 0 )
return 0;
//msg_Dbg( s, "DStreamRead: wanted %d bytes", i_read );
while( atomic_load( &p_sys->active ) && !s->b_error && i_read )
block_t *block = sys->p_block;
if( block == NULL )
{
block_t *p_block = p_sys->p_block;
size_t i_copy;
if( !p_block )
block = block_FifoGet( sys->p_fifo );
if( block == NULL )
{
p_block = block_FifoGet( p_sys->p_fifo );
if( !p_block ) s->b_error = 1;
p_sys->p_block = p_block;
s->b_error = true;
return -1;
}
sys->p_block = block;
}
if( p_block && i_read )
{
i_copy = __MIN( i_read, p_block->i_buffer );
if( p_out && i_copy ) memcpy( p_out, p_block->p_buffer, i_copy );
i_read -= i_copy;
if ( p_out ) p_out += i_copy;
i_out += i_copy;
p_block->i_buffer -= i_copy;
p_block->p_buffer += i_copy;
if( !p_block->i_buffer )
size_t copy = __MIN( len, block->i_buffer );
if( buf != NULL && copy > 0 )
memcpy( buf, block->p_buffer, copy );
block->p_buffer += copy;
block->i_buffer -= copy;
if( block->i_buffer == 0 )
{
block_Release( p_block );
p_sys->p_block = NULL;
}
}
block_Release( block );
sys->p_block = NULL;
}
p_sys->i_pos += i_out;
return i_out;
sys->i_pos += copy;
return copy;
}
static int DStreamControl( stream_t *s, int i_query, va_list args )
......
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