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 ) ...@@ -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; stream_sys_t *sys = s->p_sys;
uint8_t *p_out = p_read;
size_t i_out = 0; 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 ); //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; block = block_FifoGet( sys->p_fifo );
size_t i_copy; if( block == NULL )
if( !p_block )
{ {
p_block = block_FifoGet( p_sys->p_fifo ); s->b_error = true;
if( !p_block ) s->b_error = 1; return -1;
p_sys->p_block = p_block;
} }
sys->p_block = block;
}
if( p_block && i_read ) size_t copy = __MIN( len, block->i_buffer );
{ if( buf != NULL && copy > 0 )
i_copy = __MIN( i_read, p_block->i_buffer ); memcpy( buf, block->p_buffer, copy );
if( p_out && i_copy ) memcpy( p_out, p_block->p_buffer, i_copy );
i_read -= i_copy; block->p_buffer += copy;
if ( p_out ) p_out += i_copy; block->i_buffer -= copy;
i_out += i_copy; if( block->i_buffer == 0 )
p_block->i_buffer -= i_copy; {
p_block->p_buffer += i_copy; block_Release( block );
sys->p_block = NULL;
if( !p_block->i_buffer )
{
block_Release( p_block );
p_sys->p_block = NULL;
}
}
} }
p_sys->i_pos += i_out; sys->i_pos += copy;
return i_out; return copy;
} }
static int DStreamControl( stream_t *s, int i_query, va_list args ) 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