From bad29939851d91ae3c89e81c68a51fc2ce503447 Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Sat, 20 Jan 2024 11:16:11 +0100 Subject: [FileCache] adjust Read Factor algorithm Fixes cache not fills with high bitrate files and "low" read factors. --- xbmc/filesystem/FileCache.cpp | 16 +++++++++++++--- xbmc/filesystem/FileCache.h | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/xbmc/filesystem/FileCache.cpp b/xbmc/filesystem/FileCache.cpp index b872466905..6e28deca19 100644 --- a/xbmc/filesystem/FileCache.cpp +++ b/xbmc/filesystem/FileCache.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include @@ -33,7 +32,6 @@ #endif using namespace XFILE; -using namespace std::chrono_literals; class CWriteRate { @@ -300,7 +298,7 @@ void CFileCache::Process() if (limiter.Rate(m_writePos) < m_writeRate * readFactor) break; - if (m_seekEvent.Wait(100ms)) + if (m_seekEvent.Wait(m_processWait)) { if (!m_bStop) m_seekEvent.Set(); @@ -618,6 +616,18 @@ int CFileCache::IoControl(EIoControl request, void* param) if (request == IOCTRL_CACHE_SETRATE) { m_writeRate = *static_cast(param); + + const double mBits = m_writeRate / 1024.0 / 1024.0 * 8.0; // Mbit/s + + // calculates wait time inversely proportional to the bitrate + // and limited between 30 - 100 ms + const int wait = std::clamp(static_cast(110.0 - mBits), 30, 100); + + m_processWait = std::chrono::milliseconds(wait); + + CLog::Log(LOGDEBUG, + "CFileCache::IoControl - setting maxRate to {:.2f} Mbit/s with processWait of {} ms", + mBits, wait); return 0; } diff --git a/xbmc/filesystem/FileCache.h b/xbmc/filesystem/FileCache.h index 920e747df4..8308ec0dc1 100644 --- a/xbmc/filesystem/FileCache.h +++ b/xbmc/filesystem/FileCache.h @@ -15,8 +15,11 @@ #include "threads/Thread.h" #include +#include #include +using namespace std::chrono_literals; + namespace XFILE { @@ -74,6 +77,7 @@ namespace XFILE std::atomic m_fileSize; unsigned int m_flags; CCriticalSection m_sync; + std::chrono::milliseconds m_processWait{100ms}; }; } -- cgit v1.2.3