diff --git a/aegisub/src/options.cpp b/aegisub/src/options.cpp index 6c914e0de..b52d16f9a 100644 --- a/aegisub/src/options.cpp +++ b/aegisub/src/options.cpp @@ -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); diff --git a/aegisub/src/video_frame.h b/aegisub/src/video_frame.h index 8b8dad5f2..e6d4ab17a 100644 --- a/aegisub/src/video_frame.h +++ b/aegisub/src/video_frame.h @@ -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]; diff --git a/aegisub/src/video_provider_cache.cpp b/aegisub/src/video_provider_cache.cpp index 9cfcb2e00..560a6fde2 100644 --- a/aegisub/src/video_provider_cache.cpp +++ b/aegisub/src/video_provider_cache.cpp @@ -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::iterator i = cache.begin(); i != cache.end(); i++) + sz += i->frame.memSize; + return sz; +} + /// @brief Wrapper methods /// @return diff --git a/aegisub/src/video_provider_cache.h b/aegisub/src/video_provider_cache.h index 927f47046..222f86889 100644 --- a/aegisub/src/video_provider_cache.h +++ b/aegisub/src/video_provider_cache.h @@ -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: