[vlc-commits] access: old http: Do not read all requested data
Marvin Scholz
git at videolan.org
Tue May 15 19:24:04 CEST 2018
vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Sun May 6 01:29:22 2018 +0200| [84bcad6bc3481fa9399682ec291dcba16cc46c88] | committer: Rémi Denis-Courmont
access: old http: Do not read all requested data
The old http module Read function would try to read the full amount of
requested data, which would result in a long loading time for some
streams.
Instead return early with the actual amount of data read.
Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=84bcad6bc3481fa9399682ec291dcba16cc46c88
---
modules/access/http.c | 73 +++++++++++++++++++++++----------------------------
1 file changed, 33 insertions(+), 40 deletions(-)
diff --git a/modules/access/http.c b/modules/access/http.c
index a09a7ff74a..88be5aafb3 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -408,61 +408,54 @@ static int ReadICYMeta( stream_t *p_access );
static ssize_t Read( stream_t *p_access, void *p_buffer, size_t i_len )
{
access_sys_t *p_sys = p_access->p_sys;
- int i_total_read = 0;
- int i_remain_toread = i_len;
if( p_sys->fd == -1 )
return 0;
- while( i_remain_toread > 0 )
- {
- int i_chunk = i_remain_toread;
+ int i_chunk = i_len;
- if( p_sys->i_icy_meta > 0 )
- {
- if( UINT64_MAX - i_chunk < p_sys->offset )
- i_chunk = i_remain_toread = UINT64_MAX - p_sys->offset;
+ if( p_sys->i_icy_meta > 0 )
+ {
+ if( UINT64_MAX - i_chunk < p_sys->offset )
+ i_chunk = UINT64_MAX - p_sys->offset;
- if( p_sys->offset + i_chunk > p_sys->i_icy_offset )
- i_chunk = p_sys->i_icy_offset - p_sys->offset;
- }
+ if( p_sys->offset + i_chunk > p_sys->i_icy_offset )
+ i_chunk = p_sys->i_icy_offset - p_sys->offset;
+ }
- int i_read = 0;
- if( ReadData( p_access, &i_read, &((uint8_t*)p_buffer)[i_total_read], i_chunk ) )
- return 0;
+ int i_read = 0;
+ if( ReadData( p_access, &i_read, (uint8_t*)p_buffer, i_chunk ) )
+ return 0;
- if( i_read < 0 )
- return -1; /* EINTR / EAGAIN */
+ if( i_read < 0 )
+ return -1; /* EINTR / EAGAIN */
- if( i_read == 0 )
+ if( i_read == 0 )
+ {
+ Disconnect( p_access );
+ if( p_sys->b_reconnect )
{
- Disconnect( p_access );
- if( p_sys->b_reconnect )
- {
- msg_Dbg( p_access, "got disconnected, trying to reconnect" );
- if( Connect( p_access ) )
- msg_Dbg( p_access, "reconnection failed" );
- else
- return -1;
- }
- return 0;
+ msg_Dbg( p_access, "got disconnected, trying to reconnect" );
+ if( Connect( p_access ) )
+ msg_Dbg( p_access, "reconnection failed" );
+ else
+ return -1;
}
+ return 0;
+ }
- assert( i_read >= 0 );
- p_sys->offset += i_read;
- i_total_read += i_read;
- i_remain_toread -= i_read;
+ assert( i_read >= 0 );
+ p_sys->offset += i_read;
- if( p_sys->i_icy_meta > 0 &&
- p_sys->offset == p_sys->i_icy_offset )
- {
- if( ReadICYMeta( p_access ) )
- return 0;
- p_sys->i_icy_offset = p_sys->offset + p_sys->i_icy_meta;
- }
+ if( p_sys->i_icy_meta > 0 &&
+ p_sys->offset == p_sys->i_icy_offset )
+ {
+ if( ReadICYMeta( p_access ) )
+ return 0;
+ p_sys->i_icy_offset = p_sys->offset + p_sys->i_icy_meta;
}
- return i_total_read;
+ return i_read;
}
static int ReadICYMeta( stream_t *p_access )
More information about the vlc-commits
mailing list