aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthexai <58434170+thexai@users.noreply.github.com>2023-02-27 14:39:00 +0100
committerthexai <58434170+thexai@users.noreply.github.com>2023-02-28 14:49:08 +0100
commitf75b44af032f2ca3ab8dcf54a519229c5757675f (patch)
treed4cf39ecb3d5ce7ccc6785ea6fa367e4224baa15
parent7be83dce9f0d78e65d8fbbe426d87f8bcf36c7f7 (diff)
VideoPlayer: use struct to return values in GetCachingTimes()
-rw-r--r--xbmc/cores/VideoPlayer/VideoPlayer.cpp50
-rw-r--r--xbmc/cores/VideoPlayer/VideoPlayer.h10
2 files changed, 36 insertions, 24 deletions
diff --git a/xbmc/cores/VideoPlayer/VideoPlayer.cpp b/xbmc/cores/VideoPlayer/VideoPlayer.cpp
index 790edb7d20..6730a43ba2 100644
--- a/xbmc/cores/VideoPlayer/VideoPlayer.cpp
+++ b/xbmc/cores/VideoPlayer/VideoPlayer.cpp
@@ -1802,14 +1802,16 @@ void CVideoPlayer::ProcessAudioID3Data(CDemuxStream* pStream, DemuxPacket* pPack
m_VideoPlayerAudioID3->SendMessage(std::make_shared<CDVDMsgDemuxerPacket>(pPacket, drop));
}
-bool CVideoPlayer::GetCachingTimes(double& level, double& delay, double& offset)
+CacheInfo CVideoPlayer::GetCachingTimes()
{
+ CacheInfo info{};
+
if (!m_pInputStream || !m_pDemuxer)
- return false;
+ return info;
XFILE::SCacheStatus status;
if (!m_pInputStream->GetCacheStatus(&status))
- return false;
+ return info;
const uint64_t& cached = status.forward;
const uint32_t& currate = status.currate;
@@ -1820,34 +1822,36 @@ bool CVideoPlayer::GetCachingTimes(double& level, double& delay, double& offset)
int64_t remain = length - m_pInputStream->Seek(0, SEEK_CUR);
if (length <= 0 || remain < 0)
- return false;
+ return info;
double play_sbp = DVD_MSEC_TO_TIME(m_pDemuxer->GetStreamLength()) / length;
double queued = 1000.0 * GetQueueTime() / play_sbp;
- delay = 0.0;
- level = 0.0;
- offset = (cached + queued) / length;
+ info.delay = 0.0;
+ info.level = 0.0;
+ info.offset = (cached + queued) / length;
+ info.valid = true;
if (currate == 0)
- return true;
+ return info;
double cache_sbp = 1.1 * (double)DVD_TIME_BASE / currate; /* underestimate by 10 % */
double play_left = play_sbp * (remain + queued); /* time to play out all remaining bytes */
double cache_left = cache_sbp * (remain - cached); /* time to cache the remaining bytes */
double cache_need = std::max(0.0, remain - play_left / cache_sbp); /* bytes needed until play_left == cache_left */
- delay = cache_left - play_left;
+ info.delay = cache_left - play_left;
if (lowrate > 0)
{
+ // buffer is full & our read rate is too low
CLog::Log(LOGDEBUG, "Readrate {} was too low with {} required", lowrate, maxrate);
- level = -1.0; /* buffer is full & our read rate is too low */
+ info.level = -1.0;
}
else
- level = (cached + queued) / (cache_need + queued);
+ info.level = (cached + queued) / (cache_need + queued);
- return true;
+ return info;
}
void CVideoPlayer::HandlePlaySpeed()
@@ -1861,15 +1865,15 @@ void CVideoPlayer::HandlePlaySpeed()
if (m_caching == CACHESTATE_FULL)
{
- double level, delay, offset;
- if (GetCachingTimes(level, delay, offset))
+ CacheInfo cache = GetCachingTimes();
+ if (cache.valid)
{
- if (level < 0.0)
+ if (cache.level < 0.0)
{
CGUIDialogKaiToast::QueueNotification(g_localizeStrings.Get(21454), g_localizeStrings.Get(21455));
SetCaching(CACHESTATE_INIT);
}
- if (level >= 1.0)
+ if (cache.level >= 1.0)
SetCaching(CACHESTATE_INIT);
}
else
@@ -3068,8 +3072,8 @@ void CVideoPlayer::SetCaching(ECacheState state)
{
if(state == CACHESTATE_FLUSH)
{
- double level, delay, offset;
- if(GetCachingTimes(level, delay, offset))
+ CacheInfo cache = GetCachingTimes();
+ if (cache.valid)
state = CACHESTATE_FULL;
else
state = CACHESTATE_INIT;
@@ -4902,12 +4906,12 @@ void CVideoPlayer::UpdatePlayState(double timeout)
else
state.caching = false;
- double level, delay, offset;
- if (GetCachingTimes(level, delay, offset))
+ CacheInfo cache = GetCachingTimes();
+ if (cache.valid)
{
- state.cache_delay = std::max(0.0, delay);
- state.cache_level = std::max(0.0, std::min(1.0, level));
- state.cache_offset = offset;
+ state.cache_delay = std::max(0.0, cache.delay);
+ state.cache_level = std::max(0.0, std::min(1.0, cache.level));
+ state.cache_offset = cache.offset;
}
else
{
diff --git a/xbmc/cores/VideoPlayer/VideoPlayer.h b/xbmc/cores/VideoPlayer/VideoPlayer.h
index e40fb7aea6..b0373df7ac 100644
--- a/xbmc/cores/VideoPlayer/VideoPlayer.h
+++ b/xbmc/cores/VideoPlayer/VideoPlayer.h
@@ -237,6 +237,14 @@ protected:
// main class
//------------------------------------------------------------------------------
+struct CacheInfo
+{
+ double level;
+ double delay;
+ double offset;
+ bool valid;
+};
+
class CProcessInfo;
class CJobQueue;
@@ -421,7 +429,7 @@ protected:
void SetCaching(ECacheState state);
double GetQueueTime();
- bool GetCachingTimes(double& play_left, double& cache_left, double& file_offset);
+ CacheInfo GetCachingTimes();
void FlushBuffers(double pts, bool accurate, bool sync);