aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarnova <arnova@void.org>2014-11-11 13:31:42 +0100
committerarnova <arnova@void.org>2014-11-23 09:50:08 +0100
commit9c4eeec01e65c0138cad5f41dab3f515ad577952 (patch)
treefe69004c457d0adb081574ecb8a8331037186e98
parentf525b9b87a6c919503082d2a929831977bf71bff (diff)
fixed: FileCache-full logic was wrong + implement GetMaxWriteSize() function
-rw-r--r--xbmc/filesystem/CacheStrategy.cpp12
-rw-r--r--xbmc/filesystem/CacheStrategy.h5
-rw-r--r--xbmc/filesystem/CircularCache.cpp14
-rw-r--r--xbmc/filesystem/CircularCache.h3
-rw-r--r--xbmc/filesystem/FileCache.cpp12
-rw-r--r--xbmc/filesystem/MemBufferCache.cpp11
-rw-r--r--xbmc/filesystem/MemBufferCache.h3
7 files changed, 48 insertions, 12 deletions
diff --git a/xbmc/filesystem/CacheStrategy.cpp b/xbmc/filesystem/CacheStrategy.cpp
index cd1940527f..c1d1409840 100644
--- a/xbmc/filesystem/CacheStrategy.cpp
+++ b/xbmc/filesystem/CacheStrategy.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2013 Team XBMC
+ * Copyright (C) 2005-2014 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
@@ -126,6 +126,11 @@ void CSimpleFileCache::Close()
m_filename.clear();
}
+size_t CSimpleFileCache::GetMaxWriteSize(const size_t& iRequestSize)
+{
+ return iRequestSize; // Can always write since it's on disk
+}
+
int CSimpleFileCache::WriteToCache(const char *pBuffer, size_t iSize)
{
size_t written = 0;
@@ -300,6 +305,11 @@ void CDoubleCache::Close()
}
}
+size_t CDoubleCache::GetMaxWriteSize(const size_t& iRequestSize)
+{
+ return m_pCache->GetMaxWriteSize(iRequestSize); // NOTE: Check the active cache only
+}
+
int CDoubleCache::WriteToCache(const char *pBuffer, size_t iSize)
{
return m_pCache->WriteToCache(pBuffer, iSize);
diff --git a/xbmc/filesystem/CacheStrategy.h b/xbmc/filesystem/CacheStrategy.h
index 2adb0fc8bb..5067d01b26 100644
--- a/xbmc/filesystem/CacheStrategy.h
+++ b/xbmc/filesystem/CacheStrategy.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2013 Team XBMC
+ * Copyright (C) 2005-2014 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
@@ -44,6 +44,7 @@ public:
virtual int Open() = 0;
virtual void Close() = 0;
+ virtual size_t GetMaxWriteSize(const size_t& iRequestSize) = 0;
virtual int WriteToCache(const char *pBuffer, size_t iSize) = 0;
virtual int ReadFromCache(char *pBuffer, size_t iMaxSize) = 0;
virtual int64_t WaitForData(unsigned int iMinAvail, unsigned int iMillis) = 0;
@@ -76,6 +77,7 @@ public:
virtual int Open() ;
virtual void Close() ;
+ virtual size_t GetMaxWriteSize(const size_t& iRequestSize) ;
virtual int WriteToCache(const char *pBuffer, size_t iSize) ;
virtual int ReadFromCache(char *pBuffer, size_t iMaxSize) ;
virtual int64_t WaitForData(unsigned int iMinAvail, unsigned int iMillis) ;
@@ -110,6 +112,7 @@ public:
virtual int Open() ;
virtual void Close() ;
+ virtual size_t GetMaxWriteSize(const size_t& iRequestSize) ;
virtual int WriteToCache(const char *pBuffer, size_t iSize) ;
virtual int ReadFromCache(char *pBuffer, size_t iMaxSize) ;
virtual int64_t WaitForData(unsigned int iMinAvail, unsigned int iMillis) ;
diff --git a/xbmc/filesystem/CircularCache.cpp b/xbmc/filesystem/CircularCache.cpp
index b9ae64158a..e78efce283 100644
--- a/xbmc/filesystem/CircularCache.cpp
+++ b/xbmc/filesystem/CircularCache.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2013 Team XBMC
+ * Copyright (C) 2005-2014 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
@@ -76,6 +76,18 @@ void CCircularCache::Close()
m_buf = NULL;
}
+size_t CCircularCache::GetMaxWriteSize(const size_t& iRequestSize)
+{
+ CSingleLock lock(m_sync);
+
+ size_t back = (size_t)(m_cur - m_beg); // Backbuffer size
+ size_t front = (size_t)(m_end - m_cur); // Frontbuffer size
+ size_t limit = m_size - std::min(back, m_size_back) - front;
+
+ // Never return more than limit and size requested by caller
+ return std::min(iRequestSize, limit);
+}
+
/**
* Function will write to m_buf at m_end % m_size location
* it will write at maximum m_size, but it will only write
diff --git a/xbmc/filesystem/CircularCache.h b/xbmc/filesystem/CircularCache.h
index ae9e9b915f..f6aa6a792e 100644
--- a/xbmc/filesystem/CircularCache.h
+++ b/xbmc/filesystem/CircularCache.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2013 Team XBMC
+ * Copyright (C) 2005-2014 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
@@ -36,6 +36,7 @@ public:
virtual int Open() ;
virtual void Close();
+ virtual size_t GetMaxWriteSize(const size_t& iRequestSize) ;
virtual int WriteToCache(const char *buf, size_t len) ;
virtual int ReadFromCache(char *buf, size_t len) ;
virtual int64_t WaitForData(unsigned int minimum, unsigned int iMillis) ;
diff --git a/xbmc/filesystem/FileCache.cpp b/xbmc/filesystem/FileCache.cpp
index 886621ffee..6c88a37911 100644
--- a/xbmc/filesystem/FileCache.cpp
+++ b/xbmc/filesystem/FileCache.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2013 Team XBMC
+ * Copyright (C) 2005-2014 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
@@ -219,7 +219,7 @@ void CFileCache::Process()
{
m_seekEvent.Reset();
int64_t cacheMaxPos = m_pCache->CachedDataEndPosIfSeekTo(m_seekPos);
- cacheReachEOF = cacheMaxPos == m_source.GetLength();
+ cacheReachEOF = (cacheMaxPos == m_source.GetLength());
bool sourceSeekFailed = false;
if (!cacheReachEOF)
{
@@ -239,7 +239,7 @@ void CFileCache::Process()
assert(m_writePos == cacheMaxPos);
average.Reset(m_writePos);
limiter.Reset(m_writePos);
- m_cacheFull = false;
+ m_cacheFull = (m_pCache->GetMaxWriteSize(m_chunkSize) == 0);
m_nSeekResult = m_seekPos;
}
@@ -264,6 +264,9 @@ void CFileCache::Process()
}
}
+ size_t maxWrite = m_pCache->GetMaxWriteSize(m_chunkSize);
+ m_cacheFull = (maxWrite == 0);
+
ssize_t iRead = 0;
if (!cacheReachEOF)
iRead = m_source.Read(buffer.get(), m_chunkSize);
@@ -300,13 +303,10 @@ void CFileCache::Process()
}
else if (iWrite == 0)
{
- m_cacheFull = true;
average.Pause();
m_pCache->m_space.WaitMSec(5);
average.Resume();
}
- else
- m_cacheFull = false;
iTotalWrite += iWrite;
diff --git a/xbmc/filesystem/MemBufferCache.cpp b/xbmc/filesystem/MemBufferCache.cpp
index c430ce811b..7c1c61dad8 100644
--- a/xbmc/filesystem/MemBufferCache.cpp
+++ b/xbmc/filesystem/MemBufferCache.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2013 Team XBMC
+ * Copyright (C) 2005-2014 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
@@ -67,6 +67,15 @@ void MemBufferCache::Close()
m_forwardBuffer.Clear();
}
+size_t MemBufferCache::GetMaxWriteSize(const size_t& iRequestSize)
+{
+ CSingleLock lock(m_sync);
+
+ // must also check the forward buffer.
+ // if we have leftovers from the previous seek - we need not read anymore until they are utilized
+ return (m_forwardBuffer.getMaxReadSize() == 0 && iRequestSize <= m_buffer.getMaxWriteSize()) ? iRequestSize : 0;
+}
+
int MemBufferCache::WriteToCache(const char *pBuffer, size_t iSize)
{
CSingleLock lock(m_sync);
diff --git a/xbmc/filesystem/MemBufferCache.h b/xbmc/filesystem/MemBufferCache.h
index 5574a5bd7b..56b8d9cbf2 100644
--- a/xbmc/filesystem/MemBufferCache.h
+++ b/xbmc/filesystem/MemBufferCache.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2013 Team XBMC
+ * Copyright (C) 2005-2014 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
@@ -40,6 +40,7 @@ public:
virtual int Open() ;
virtual void Close();
+ virtual size_t GetMaxWriteSize(const size_t& iRequestSize) ;
virtual int WriteToCache(const char *pBuffer, size_t iSize) ;
virtual int ReadFromCache(char *pBuffer, size_t iMaxSize) ;
virtual int64_t WaitForData(unsigned int iMinAvail, unsigned int iMillis) ;