Skip to content

Commit

Permalink
RingBuffer: Optimize readahead buffer to completely fill if readblock…
Browse files Browse the repository at this point in the history
…size > totfree.

This allows the readahead buffer to fill if the readblocksize is greater than buffer free by temporarily reducing the read size to a size that will fit. With this change the buffers reach 99% for all videos.
  • Loading branch information
tralph committed Jun 9, 2011
1 parent 5e86576 commit d950637
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions mythtv/libs/libmythtv/ringbuffer.cpp
Expand Up @@ -734,8 +734,7 @@ void RingBuffer::run(void)

// These are conditions where we don't want to go through
// the loop if they are true.
if (((totfree < readblocksize) && readsallowed) ||
(ignorereadpos >= 0) || commserror || stopreads)
if ((ignorereadpos >= 0) || commserror || stopreads)
{
ignore_for_read_timing |=
(ignorereadpos >= 0) || commserror || stopreads;
Expand All @@ -752,12 +751,16 @@ void RingBuffer::run(void)
totfree = ReadBufFree();
}

const uint KB32 = 32*1024;
int read_return = -1;
if (totfree >= readblocksize && !commserror &&
if (totfree >= KB32 && !commserror &&
!ateof && !setswitchtonext)
{
// limit the read size
totfree = readblocksize;
if (readblocksize > totfree)
totfree = (int)(totfree / KB32) * KB32; // must be multiple of 32KB
else
totfree = readblocksize;

// adapt blocksize
gettimeofday(&now, NULL);
Expand Down Expand Up @@ -792,7 +795,7 @@ void RingBuffer::run(void)
readtimeavg = 225;
}
}
ignore_for_read_timing = false;
ignore_for_read_timing = (totfree < readblocksize) ? true : false;
lastread = now;

rbwlock.lockForRead();
Expand Down

0 comments on commit d950637

Please sign in to comment.