aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthexai <58434170+thexai@users.noreply.github.com>2024-01-30 15:22:13 +0100
committerGitHub <noreply@github.com>2024-01-30 15:22:13 +0100
commit1c47d15206b12e82c1acd09fc73be7e1a928bb3a (patch)
treef65e92f009ecf2880652d99532011f2c213371e3
parent9a87e4d657d0f39559f56b567db7c6f59492db19 (diff)
parentbad29939851d91ae3c89e81c68a51fc2ce503447 (diff)
Merge pull request #24582 from thexai/fix-read-factor
[FileCache] adjust Read Factor algorithm
-rw-r--r--xbmc/filesystem/FileCache.cpp16
-rw-r--r--xbmc/filesystem/FileCache.h4
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 <algorithm>
#include <cassert>
-#include <chrono>
#include <inttypes.h>
#include <memory>
@@ -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<uint32_t*>(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<int>(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 <atomic>
+#include <chrono>
#include <memory>
+using namespace std::chrono_literals;
+
namespace XFILE
{
@@ -74,6 +77,7 @@ namespace XFILE
std::atomic<int64_t> m_fileSize;
unsigned int m_flags;
CCriticalSection m_sync;
+ std::chrono::milliseconds m_processWait{100ms};
};
}