diff options
author | thexai <58434170+thexai@users.noreply.github.com> | 2024-01-16 16:42:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-16 16:42:04 +0100 |
commit | 0974c687e415b2c7145e074ed523412baa548367 (patch) | |
tree | 41509fee639575eceee9011aaaa82fd381e451b3 | |
parent | 78a2ef1ef0e2acdcb51bfed10247714485b7a522 (diff) | |
parent | 8a9b0fd9c50be27b4a9a9fbce52206fa10a00d12 (diff) |
Merge pull request #24504 from thexai/stream-buffer
[FileSystem] Refactored and improved logic to use CFileStreamBuffer
-rw-r--r-- | xbmc/filesystem/File.cpp | 22 | ||||
-rw-r--r-- | xbmc/filesystem/File.h | 17 |
2 files changed, 33 insertions, 6 deletions
diff --git a/xbmc/filesystem/File.cpp b/xbmc/filesystem/File.cpp index ed0f30f3f4..f7f228f65a 100644 --- a/xbmc/filesystem/File.cpp +++ b/xbmc/filesystem/File.cpp @@ -364,12 +364,7 @@ bool CFile::Open(const CURL& file, const unsigned int flags) return false; } - constexpr int64_t len = 200 * 1024 * 1024; // 200 MB - - // Use CFileStreamBuffer for all "big" files (audio/video files) when FileCache is not used - // This also makes use of 64K file read chunk size, suitable for localfiles, USB files, etc. - // Also enbles basic cache for Blu-Ray but only big .m2ts files (main audio/video files only) - if ((m_pFile->GetChunkSize() || m_pFile->GetLength() > len) && !(m_flags & READ_CHUNKED)) + if (ShouldUseStreamBuffer(url)) { m_pBuffer = std::make_unique<CFileStreamBuffer>(0); m_pBuffer->Attach(m_pFile.get()); @@ -389,6 +384,21 @@ bool CFile::Open(const CURL& file, const unsigned int flags) return false; } +bool CFile::ShouldUseStreamBuffer(const CURL& url) +{ + if (m_flags & READ_CHUNKED || m_pFile->GetChunkSize() > 0) + return true; + + // file size > 200 MB but not in optical disk + if (m_pFile->GetLength() > 200 * 1024 * 1024 && !URIUtils::IsDVD(url.GetShareName())) + return true; + + if (URIUtils::IsNetworkFilesystem(url.Get())) + return true; + + return false; +} + bool CFile::OpenForWrite(const std::string& strFileName, bool bOverWrite) { const CURL pathToUrl(strFileName); diff --git a/xbmc/filesystem/File.h b/xbmc/filesystem/File.h index a5f991af30..c08b80c5b6 100644 --- a/xbmc/filesystem/File.h +++ b/xbmc/filesystem/File.h @@ -155,6 +155,23 @@ public: double GetDownloadSpeed(); private: + /*! + * \brief Determines if CFileStreamBuffer should be used to read a file. + * + * In general, should be used for ALL media files (only when is not used FileCache) + * and NOT used for non-media files e.g. small local files as config/settings xml files. + * Enables basic buffer that allows read sources with 64K chunk size even if FFmpeg only reads + * data with small 4K chunks or Blu-Ray sector size (6144 bytes): + * + * [FFmpeg] <-----4K chunks----- [CFileStreamBuffer] <-----64K chunks----- [Source file / Network] + * + * NOTE: in case of SMB / NFS default 64K chunk size is replaced with value configured in + * settings for the protocol. + * This improves performance when reads big files through Network. + * \param url Source file info as CULR class. + */ + bool ShouldUseStreamBuffer(const CURL& url); + unsigned int m_flags = 0; CURL m_curl; std::unique_ptr<IFile> m_pFile; |