forked from mia/Aegisub
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:
parent
0c34323b5d
commit
6b04f5ee8f
4 changed files with 17 additions and 5 deletions
|
@ -184,6 +184,7 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) {
|
||||||
#else
|
#else
|
||||||
SetText(_T("Subtitles Provider"),_T(DEFAULT_PROVIDER_SUBTITLE));
|
SetText(_T("Subtitles Provider"),_T(DEFAULT_PROVIDER_SUBTITLE));
|
||||||
#endif
|
#endif
|
||||||
|
SetInt(_T("Video cache size"), 32);
|
||||||
SetInt(_T("FFmpegSource max cache size"),42);
|
SetInt(_T("FFmpegSource max cache size"),42);
|
||||||
SetInt(_T("FFmpegSource max cache files"),20);
|
SetInt(_T("FFmpegSource max cache files"),20);
|
||||||
SetInt(_T("FFmpegSource always index all tracks"), true);
|
SetInt(_T("FFmpegSource always index all tracks"), true);
|
||||||
|
|
|
@ -77,7 +77,6 @@ enum VideoFrameFormat {
|
||||||
/// DOCME
|
/// DOCME
|
||||||
class AegiVideoFrame {
|
class AegiVideoFrame {
|
||||||
private:
|
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
|
/// Whether the object owns its buffer. If this is false, **data should never be modified
|
||||||
bool ownMem;
|
bool ownMem;
|
||||||
void Reset();
|
void Reset();
|
||||||
|
@ -85,6 +84,8 @@ private:
|
||||||
public:
|
public:
|
||||||
void Allocate();
|
void Allocate();
|
||||||
|
|
||||||
|
unsigned int memSize; /// The size in bytes of the frame buffer
|
||||||
|
|
||||||
/// Pointers to the data planes. Interleaved formats only use data[0]
|
/// Pointers to the data planes. Interleaved formats only use data[0]
|
||||||
unsigned char *data[4];
|
unsigned char *data[4];
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
///////////
|
///////////
|
||||||
// Headers
|
// Headers
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
#include "video_provider_cache.h"
|
#include "video_provider_cache.h"
|
||||||
|
|
||||||
|
@ -92,8 +93,10 @@ const AegiVideoFrame VideoProviderCache::GetFrame(int n) {
|
||||||
/// @param n
|
/// @param n
|
||||||
///
|
///
|
||||||
void VideoProviderCache::SetCacheMax(int n) {
|
void VideoProviderCache::SetCacheMax(int n) {
|
||||||
if (n < 0) n = 0;
|
if (n <= 0)
|
||||||
cacheMax = n;
|
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;
|
if (cacheMax == 0) return;
|
||||||
|
|
||||||
// Cache full, use frame at front
|
// Cache full, use frame at front
|
||||||
if (cache.size() >= cacheMax) {
|
if (GetCurCacheSize() >= cacheMax) {
|
||||||
cache.push_back(cache.front());
|
cache.push_back(cache.front());
|
||||||
cache.pop_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
|
/// @brief Wrapper methods
|
||||||
/// @return
|
/// @return
|
||||||
|
|
|
@ -63,7 +63,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
/// @class VideoProviderCache
|
/// @class VideoProviderCache
|
||||||
/// @brief DOCME
|
/// @brief DOCME
|
||||||
|
@ -90,6 +89,7 @@ private:
|
||||||
protected:
|
protected:
|
||||||
// Cache functions
|
// Cache functions
|
||||||
void SetCacheMax(int n_frames);
|
void SetCacheMax(int n_frames);
|
||||||
|
unsigned GetCurCacheSize();
|
||||||
void ClearCache();
|
void ClearCache();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue