Commit 040267e3 authored by Gildas Bazin's avatar Gildas Bazin

* input/input_ext-plugins.c:

   + access plugins are allowed to return less data than requested (mtu size) so we need to make sure input_Peek()/input_SplitBuffer() will still return the required amount of data.
* input/stream.c:
   + optimized stream_Read().
parent ab94829b
......@@ -2,7 +2,7 @@
* input_ext-plugins.c: useful functions for access and demux plug-ins
*****************************************************************************
* Copyright (C) 2001-2004 VideoLAN
* $Id: input_ext-plugins.c,v 1.40 2004/01/25 17:16:06 zorglub Exp $
* $Id$
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -536,9 +536,12 @@ ssize_t input_FillBuffer( input_thread_t * p_input )
* (min. i_size bytes)
* Returns the number of bytes read, or -1 in case of error
*****************************************************************************/
ssize_t input_Peek( input_thread_t * p_input, byte_t ** pp_byte, size_t i_size )
ssize_t input_Peek( input_thread_t * p_input, byte_t ** pp_byte,
size_t i_size )
{
if( p_input->p_last_data - p_input->p_current_data < (ptrdiff_t)i_size )
ssize_t i_data = p_input->p_last_data - p_input->p_current_data;
while( i_data < (ssize_t)i_size )
{
/* Go to the next buffer */
ssize_t i_ret = input_FillBuffer( p_input );
......@@ -548,11 +551,16 @@ ssize_t input_Peek( input_thread_t * p_input, byte_t ** pp_byte, size_t i_size )
return -1;
}
if( i_ret < (ssize_t)i_size )
if( i_ret == i_data )
{
i_size = i_ret;
/* We didn't get anymore data, must be the EOF */
i_size = i_data;
break;
}
i_data = i_ret;
}
*pp_byte = p_input->p_current_data;
return i_size;
}
......@@ -564,7 +572,9 @@ ssize_t input_Peek( input_thread_t * p_input, byte_t ** pp_byte, size_t i_size )
ssize_t input_SplitBuffer( input_thread_t * p_input,
data_packet_t ** pp_data, size_t i_size )
{
if( p_input->p_last_data - p_input->p_current_data < (ptrdiff_t)i_size )
ssize_t i_data = p_input->p_last_data - p_input->p_current_data;
while( i_data < (ssize_t)i_size )
{
/* Go to the next buffer */
ssize_t i_ret = input_FillBuffer( p_input );
......@@ -574,13 +584,17 @@ ssize_t input_SplitBuffer( input_thread_t * p_input,
return -1;
}
if( i_ret < (ssize_t)i_size )
if( i_ret == i_data )
{
i_size = i_ret;
/* We didn't get anymore data, must be the EOF */
i_size = i_data;
break;
}
i_data = i_ret;
}
if ( i_size < 0)
if( i_size < 0)
{
return 0;
}
......
......@@ -2,7 +2,7 @@
* stream.c
*****************************************************************************
* Copyright (C) 1999-2004 VideoLAN
* $Id: stream.c,v 1.15 2004/02/02 13:00:53 fenrir Exp $
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -253,8 +253,7 @@ static int IStreamControl( stream_t *s, int i_query, va_list args )
static int IStreamRead( stream_t *s, void *p_data, int i_data )
{
input_thread_t *p_input = s->p_sys->p_input;
uint8_t *p = (uint8_t*)p_data;
data_packet_t *p_packet;
uint8_t *p = (uint8_t*)p_data;
int i_read = 0;
......@@ -274,33 +273,37 @@ static int IStreamRead( stream_t *s, void *p_data, int i_data )
while( i_data > 0 && !p_input->b_die )
{
int i_count;
i_count = input_SplitBuffer( p_input, &p_packet,
__MIN( i_data, (int)p_input->i_bufsize ) );
ssize_t i_count = p_input->p_last_data - p_input->p_current_data;
if( i_count <= 0 )
{
if( i_count == 0 )
input_DeletePacket( p_input->p_method_data, p_packet );
return i_read;
}
/* Go to the next buffer */
i_count = input_FillBuffer( p_input );
if( p )
{
memcpy( p, p_packet->p_payload_start, i_count );
p += i_count;
if( i_count < 0 ) return -1;
else if( i_count == 0 )
{
/* We reached the EOF */
break;
}
}
input_DeletePacket( p_input->p_method_data, p_packet );
i_count = __MIN( i_data, i_count );
memcpy( p, p_input->p_current_data, i_count );
p_input->p_current_data += i_count;
p += i_count;
i_data -= i_count;
i_read += i_count;
/* Update stream position */
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.p_selected_area->i_tell += i_count;
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
return i_read;
}
/****************************************************************************
* IStreamPeek:
****************************************************************************/
......
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