Commit f5ba2e36 authored by Laurent Aimar's avatar Laurent Aimar

Removed useless buffering at stream level.

It removed the need of access_t.info.b_prebuffered
It reduces latency (removing the need for stream immediate)
It may increase a little the CPU usage but only for demuxer that
already do too much small stream reads.
parent 4332c070
...@@ -116,8 +116,6 @@ struct access_t ...@@ -116,8 +116,6 @@ struct access_t
int i_title; /* idem, start from 0 (could be menu) */ int i_title; /* idem, start from 0 (could be menu) */
int i_seekpoint;/* idem, start from 0 */ int i_seekpoint;/* idem, start from 0 */
bool b_prebuffered; /* Read only for input */
} info; } info;
access_sys_t *p_sys; access_sys_t *p_sys;
}; };
......
...@@ -147,7 +147,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -147,7 +147,6 @@ static int Open( vlc_object_t *p_this )
/* Set up p_access */ /* Set up p_access */
access_InitFields( p_access ); access_InitFields( p_access );
ACCESS_SET_CALLBACKS( NULL, Block, Control, NULL ); ACCESS_SET_CALLBACKS( NULL, Block, Control, NULL );
p_access->info.b_prebuffered = false;
p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) ); p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
if( !p_sys ) if( !p_sys )
......
...@@ -163,7 +163,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -163,7 +163,6 @@ static int Open( vlc_object_t *p_this )
/* Init p_access */ /* Init p_access */
access_InitFields( p_access ); access_InitFields( p_access );
ACCESS_SET_CALLBACKS( NULL, BlockRead, Control, NULL ); ACCESS_SET_CALLBACKS( NULL, BlockRead, Control, NULL );
p_access->info.b_prebuffered = false;
p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) ); p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) );
if( !p_sys ) if( !p_sys )
return VLC_ENOMEM; return VLC_ENOMEM;
......
...@@ -99,7 +99,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -99,7 +99,6 @@ static int Open( vlc_object_t *p_this )
/* Set up p_access */ /* Set up p_access */
access_InitFields( p_access ); access_InitFields( p_access );
ACCESS_SET_CALLBACKS( NULL, BlockUDP, Control, NULL ); ACCESS_SET_CALLBACKS( NULL, BlockUDP, Control, NULL );
p_access->info.b_prebuffered = true;
if (strlen (p_access->psz_access) > 0) if (strlen (p_access->psz_access) > 0)
{ {
......
...@@ -66,7 +66,6 @@ static access_t *access_InternalNew( vlc_object_t *p_obj, const char *psz_access ...@@ -66,7 +66,6 @@ static access_t *access_InternalNew( vlc_object_t *p_obj, const char *psz_access
p_access->info.i_size = 0; p_access->info.i_size = 0;
p_access->info.i_pos = 0; p_access->info.i_pos = 0;
p_access->info.b_eof = false; p_access->info.b_eof = false;
p_access->info.b_prebuffered = false;
p_access->info.i_title = 0; p_access->info.i_title = 0;
p_access->info.i_seekpoint = 0; p_access->info.i_seekpoint = 0;
......
...@@ -71,10 +71,10 @@ ...@@ -71,10 +71,10 @@
# define STREAM_CACHE_SIZE (4*STREAM_CACHE_TRACK*1024*1024) # define STREAM_CACHE_SIZE (4*STREAM_CACHE_TRACK*1024*1024)
#endif #endif
/* How many data we try to prebuffer */ /* How many data we try to prebuffer
#define STREAM_CACHE_PREBUFFER_SIZE (32767) * XXX it should be small to avoid useless latency but big enough for
/* Maximum time we take to pre-buffer */ * efficient demux probing */
#define STREAM_CACHE_PREBUFFER_LENGTH (100*1000) #define STREAM_CACHE_PREBUFFER_SIZE (128)
/* Method1: Simple, for pf_block. /* Method1: Simple, for pf_block.
* We get blocks and put them in the linked list. * We get blocks and put them in the linked list.
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
* - compute a good value for i_read_size * - compute a good value for i_read_size
* - ? * - ?
*/ */
#define STREAM_READ_ATONCE 32767 #define STREAM_READ_ATONCE 1024
#define STREAM_CACHE_TRACK_SIZE (STREAM_CACHE_SIZE/STREAM_CACHE_TRACK) #define STREAM_CACHE_TRACK_SIZE (STREAM_CACHE_SIZE/STREAM_CACHE_TRACK)
typedef struct typedef struct
...@@ -845,12 +845,11 @@ static void AStreamPrebufferBlock( stream_t *s ) ...@@ -845,12 +845,11 @@ static void AStreamPrebufferBlock( stream_t *s )
i_start = mdate(); i_start = mdate();
for( ;; ) for( ;; )
{ {
int64_t i_date = mdate(); const int64_t i_date = mdate();
bool b_eof; bool b_eof;
block_t *b; block_t *b;
if( s->b_die || p_sys->block.i_size > STREAM_CACHE_PREBUFFER_SIZE || if( s->b_die || p_sys->block.i_size > STREAM_CACHE_PREBUFFER_SIZE )
( i_first > 0 && i_first + STREAM_CACHE_PREBUFFER_LENGTH < i_date ) )
{ {
int64_t i_byterate; int64_t i_byterate;
...@@ -887,20 +886,12 @@ static void AStreamPrebufferBlock( stream_t *s ) ...@@ -887,20 +886,12 @@ static void AStreamPrebufferBlock( stream_t *s )
b = b->p_next; b = b->p_next;
} }
if( p_access->info.b_prebuffered )
{
/* Access has already prebufferred - update stats and exit */
p_sys->stat.i_bytes = p_sys->block.i_size;
p_sys->stat.i_read_time = mdate() - i_start;
break;
}
if( i_first == 0 ) if( i_first == 0 )
{ {
i_first = mdate(); i_first = mdate();
msg_Dbg( s, "received first data for our buffer"); msg_Dbg( s, "received first data after %d ms",
(int)((i_first-i_start)/1000) );
} }
} }
p_sys->block.p_current = p_sys->block.p_first; p_sys->block.p_current = p_sys->block.p_first;
...@@ -1315,6 +1306,9 @@ static int AStreamReadStream( stream_t *s, void *p_read, unsigned int i_read ) ...@@ -1315,6 +1306,9 @@ static int AStreamReadStream( stream_t *s, void *p_read, unsigned int i_read )
if( tk->i_start + p_sys->stream.i_offset >= tk->i_end || if( tk->i_start + p_sys->stream.i_offset >= tk->i_end ||
p_sys->stream.i_used >= p_sys->stream.i_read_size ) p_sys->stream.i_used >= p_sys->stream.i_read_size )
{ {
if( p_sys->stream.i_used < i_read - i_data )
p_sys->stream.i_used = __MIN( i_read - i_data, STREAM_READ_ATONCE * 10 );
if( AStreamRefillStream( s ) ) if( AStreamRefillStream( s ) )
{ {
/* EOF */ /* EOF */
...@@ -1549,10 +1543,10 @@ static int AStreamRefillStream( stream_t *s ) ...@@ -1549,10 +1543,10 @@ static int AStreamRefillStream( stream_t *s )
if( i_toread <= 0 ) return VLC_EGENERIC; /* EOF */ if( i_toread <= 0 ) return VLC_EGENERIC; /* EOF */
#ifdef STREAM_DEBUG //#ifdef STREAM_DEBUG
msg_Dbg( s, "AStreamRefillStream: used=%d toread=%d", msg_Dbg( s, "AStreamRefillStream: used=%d toread=%d",
p_sys->stream.i_used, i_toread ); p_sys->stream.i_used, i_toread );
#endif //#endif
i_start = mdate(); i_start = mdate();
while( i_toread > 0 ) while( i_toread > 0 )
...@@ -1611,11 +1605,8 @@ static void AStreamPrebufferStream( stream_t *s ) ...@@ -1611,11 +1605,8 @@ static void AStreamPrebufferStream( stream_t *s )
int64_t i_first = 0; int64_t i_first = 0;
int64_t i_start; int64_t i_start;
int64_t i_prebuffer = p_sys->b_quick ? STREAM_CACHE_TRACK_SIZE /100 :
( (p_access->info.i_title > 1 || p_access->info.i_seekpoint > 1) ?
STREAM_CACHE_PREBUFFER_SIZE : STREAM_CACHE_TRACK_SIZE / 3 );
msg_Dbg( s, "pre-buffering..." ); msg_Dbg( s, "pre buffering" );
i_start = mdate(); i_start = mdate();
for( ;; ) for( ;; )
{ {
...@@ -1624,8 +1615,7 @@ static void AStreamPrebufferStream( stream_t *s ) ...@@ -1624,8 +1615,7 @@ static void AStreamPrebufferStream( stream_t *s )
int64_t i_date = mdate(); int64_t i_date = mdate();
int i_read; int i_read;
if( s->b_die || tk->i_end >= i_prebuffer || if( s->b_die || tk->i_end >= STREAM_CACHE_PREBUFFER_SIZE )
(i_first > 0 && i_first + STREAM_CACHE_PREBUFFER_LENGTH < i_date) )
{ {
int64_t i_byterate; int64_t i_byterate;
...@@ -1655,7 +1645,8 @@ static void AStreamPrebufferStream( stream_t *s ) ...@@ -1655,7 +1645,8 @@ static void AStreamPrebufferStream( stream_t *s )
if( i_first == 0 ) if( i_first == 0 )
{ {
i_first = mdate(); i_first = mdate();
msg_Dbg( s, "received first data for our buffer"); msg_Dbg( s, "received first data after %d ms",
(int)((i_first-i_start)/1000) );
} }
tk->i_end += i_read; tk->i_end += i_read;
......
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