[vlc-devel] Stream read algorithm (input/stream.c)

Sébastien Escudier sebastien-devel at celeos.eu
Mon Feb 23 12:21:17 CET 2009


There may be a problem in stream reading.
I noticed that I had some delay when I was reading a network stream. Then I
looked at stream reading in src/intput/stream.c and I noticed that VLC wasn't
reading at the end of the stream cache. It was ok at the beginning, but it was
shifting more and more.

I think the problem is with these lines in AStreamReadStream:
line 1104 in stream.c
why is this needed ? :
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 we are in this case, AStreamRefillStream will read (i_read - i_data) instead
of (i_copy = i_data).
And we are in a loop :  while( i_data < i_read ), so it will read again
i_data-i_read just after (because this is what is left to read).

Finally we refilled (i_read - i_data)*2 but we really read less. Here is the
shift in this cache.

With these two lines I had like 30 secs of delay after several hours of network
stream reading.
When I commented these lines, no delay anymore.

My second question is : why do we refill the cache when we have enough unread
data in it ? The issue above would be ok if we didn't. Unless this should
*never* happen ?


More information about the vlc-devel mailing list