Make the caching video provider use a user-configurable max cache size in bytes instead of a hardcoded number of frames. Defaults to using 32 MB (about 10 frames at 720p) of memory for the cache.

Originally committed to SVN as r3829.
This commit is contained in:
Karl Blomster 2009-11-29 18:59:21 +00:00
parent 0c34323b5d
commit 6b04f5ee8f
4 changed files with 17 additions and 5 deletions

View File

@ -184,6 +184,7 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) {
#else
SetText(_T("Subtitles Provider"),_T(DEFAULT_PROVIDER_SUBTITLE));
#endif
SetInt(_T("Video cache size"), 32);
SetInt(_T("FFmpegSource max cache size"),42);
SetInt(_T("FFmpegSource max cache files"),20);
SetInt(_T("FFmpegSource always index all tracks"), true);

View File

@ -77,7 +77,6 @@ enum VideoFrameFormat {
/// DOCME
class AegiVideoFrame {
private:
unsigned int memSize; /// The size in bytes of the frame buffer
/// Whether the object owns its buffer. If this is false, **data should never be modified
bool ownMem;
void Reset();
@ -85,6 +84,8 @@ private:
public:
void Allocate();
unsigned int memSize; /// The size in bytes of the frame buffer
/// Pointers to the data planes. Interleaved formats only use data[0]
unsigned char *data[4];

View File

@ -38,6 +38,7 @@
///////////
// Headers
#include "config.h"
#include "options.h"
#include "video_provider_cache.h"
@ -92,8 +93,10 @@ const AegiVideoFrame VideoProviderCache::GetFrame(int n) {
/// @param n
///
void VideoProviderCache::SetCacheMax(int n) {
if (n < 0) n = 0;
cacheMax = n;
if (n <= 0)
cacheMax = 0;
else
cacheMax = Options.AsInt(_T("Video cache size")) << 20; // convert MB to bytes
}
@ -108,7 +111,7 @@ void VideoProviderCache::Cache(int n,const AegiVideoFrame frame) {
if (cacheMax == 0) return;
// Cache full, use frame at front
if (cache.size() >= cacheMax) {
if (GetCurCacheSize() >= cacheMax) {
cache.push_back(cache.front());
cache.pop_front();
}
@ -135,6 +138,13 @@ void VideoProviderCache::ClearCache() {
}
unsigned VideoProviderCache::GetCurCacheSize() {
int sz = 0;
for (std::list<CachedFrame>::iterator i = cache.begin(); i != cache.end(); i++)
sz += i->frame.memSize;
return sz;
}
/// @brief Wrapper methods
/// @return

View File

@ -63,7 +63,6 @@ public:
};
/// DOCME
/// @class VideoProviderCache
/// @brief DOCME
@ -90,6 +89,7 @@ private:
protected:
// Cache functions
void SetCacheMax(int n_frames);
unsigned GetCurCacheSize();
void ClearCache();
public: