Cache Calculations - User option to set to automatic or specific seconds to buffer?
#1
Lightbulb 
We need more intelligent cache system for XBMC. Currenlty in XBMC that value is fixed ( CACHE_BUFFER_SIZE (1048576 * 5) ) found in CacheMemBuffer.cpp

In Windows Media Player, user is allowed two options:

1) Automatic
2) Enter Number of seconds to buffer

To calculate automatically ( posted by jmarshal ):

If you know the duration and filesize, then you have to keep buffering until time to download the rest of the file is less than the time to play the rest of the file.

The only tricky bit is where you don't know the duration and/or filesize, and in this case, you have to use some sort of moving average of bitrate, plus some suitable safety margin, in order to predict the future. The moving average and the size of the safety margin can be adjusted (upwards) if and when you don't meet the target.

Quite a few requests on Trac address this issue:
http://trac.xbmc.org/ticket/4636
http://trac.xbmc.org/ticket/4519
http://trac.xbmc.org/ticket/3128
http://trac.xbmc.org/ticket/4640
and forum threads:
http://forum.xbmc.org/showthread.php?tid=36225
Reply
#2
CrashX Wrote:I noticed that cache is calculated based on fix value instead of % of file size ? Is their any reason for this ? Can we change to % ?

% of the file size means you know the file size, it's not always true, like for continuous stream.

But why would you change? any lack with the fixed value?
Reply
#3
Fixed is not accurate ? You can cache too much or two little ..

Most of our stuff in our plugins use fixed streams in which case we should be able to know the size of it.
Reply
#4
CrashX Wrote:Fixed is not accurate ? You can cache too much or two little ..

Most of our stuff in our plugins use fixed streams in which case we should be able to know the size of it.

Yes & No...

Caching is mainly to prevent Network or I/O error during playback.

What % should be acceptable? 5%?

For one big Full HD video file ~10Gb it's 500Mo to cache!

For a very short video, 10s and 10Mo it's 500Ko to cache, about 1/2s of playback

Maybe an hybrid solution with a % with a fixed minimum should be better.
Reply
#5
How about if the user input number of seconds to cache ?
Reply
#6
CrashX Wrote:How about if the user input number of seconds to cache ?

Why not, It's easy to calculate when the media is in fixate bitrate:

Code:
Total Size / Length in sec * Number of second for cache

But how to calculate with variable bitrate video/audio?
Reply
#7
In Windows Media Player, user is allowed two options:

1) Automatic
2) Enter Number of seconds to buffer

We should support both option in XBMC.

What are you trying to calculate with variable bitrate video/ audio ?

We already have the following values in XBMC Total Size, Length in sec.

Don't we need connection speed in your calculations ?
Reply
#8
CrashX Wrote:In Windows Media Player, user is allowed two options:

1) Automatic
2) Enter Number of seconds to buffer

We should support both option in XBMC.

What are you trying to calculate with variable bitrate video/ audio ?

We already have the following values in XBMC Total Size, Length in sec.

Don't we need connection speed in your calculations ?

There is no need to know the connection speed to know the cache size.

The time to cache will be "slower/faster" regarding the connection speed but the size of the cache should be the same assuming the link speed is greater than the bitrate of the media played!

About a variable bitrate media, to make it simple, 10% of the media size isn't 10% of the length since the "size" of a "second" of playback (video + audio) is variable.

Plus, for media with one or more audio/video track, the size of the played audio/video couple isn't the size of all the file.
Reply
#9
Actually we do need to take in account connection speed if we want uninterrupted playback ( no buffering during video playback).

File_Duration = 100 sec
File_Size = 60,000KB
Connection_Speed = 100KB/s

Download_Time = File_Size / Connection_Speed = 600 sec

We either calculate this value as below or getting from the user:
Buffer_Time = Download_Time / File_Duration = 6 sec

Cache_Size = Buffer_Time / File_Duration * FileSize = 6 / 100 * 60,000 = 3600KB ( * )

As you menioned above, this won't work for variable bit rate, hence where I am stuck.
Reply
#10
If you know the duration and filesize, then you have to keep buffering until time to download the rest of the file is less than the time to play the rest of the file.

The only tricky bit is where you don't know the duration and/or filesize, and in this case, you have to use some sort of moving average of bitrate, plus some suitable safety margin, in order to predict the future. The moving average and the size of the safety margin can be adjusted (upwards) if and when you don't meet the target.

I see no reason why you'd need to specify the buffersizes in the UI.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#11
jmarshall Wrote:If you know the duration and filesize, then you have to keep buffering until time to download the rest of the file is less than the time to play the rest of the file.

The only tricky bit is where you don't know the duration and/or filesize, and in this case, you have to use some sort of moving average of bitrate, plus some suitable safety margin, in order to predict the future. The moving average and the size of the safety margin can be adjusted (upwards) if and when you don't meet the target.

I see no reason why you'd need to specify the buffersizes in the UI.

Maybe you're right jmarshall, user doesn't care about buffersizes.
Here my idea:
  • A general Algorithm to calculate the buffersize
  • A option set by user to qualify his connection speed

Connection speed could be:
  • High Speed Link
  • Normal Link
  • Low Link

And use this setting to determine the safety margin for buffersize
Reply
#12
What's the point of that setting? amount_to_cache = what_we_need * safety_factor.

A safety factor of 1.2 or so will probably suffice, given that what_we_need would auto-adjust (moving average of passed info) based on how fast we're downloading the file (in terms of seconds/second).

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#13
Jmarshall:

I was trying figure what was causing the following issue:
http://forum.xbmc.org/showthread.php?tid=46289

I thought it had something to do with caching the file but can't really figure where the cache values were coming from. I first thought it was coming from GUI Setting "cachevideo.internet", hence why I started this post but now it looks like that value isn't used at all ?

Also I am bit unclear why you felt that connection speed doesn't matter in the calculation of the cache size if we had a fixed stream ? Don't we need a determine an optimal cache size at the beginning to avoid Buffering ..

I actually want the cache to be calculated automatically for all cases if possible.

As always thanks for taking your time to help ..
Reply
#14
CrashX Wrote:Also I am bit unclear why you felt that connection speed doesn't matter in the calculation of the cache size if we had a fixed stream ? Don't we need a determine an optimal cache size at the beginning to avoid Buffering

The windowed running average will take care of that. So long as the safety factor is sufficient there shouldn't be any problems unless connection speed < bitrate. In which case you're screwed either way.
Reply
#15
Update First post with trac considering this issue.
Reply

Logout Mark Read Team Forum Stats Members Help
Cache Calculations - User option to set to automatic or specific seconds to buffer?0