Skip to content

Commit

Permalink
get rid of inaccurate seek size percent calculation
Browse files Browse the repository at this point in the history
This removes the inaccurate seek size calculation which relies on percent and uses seconds instead.
As we need the seek size percent for the GUI seek progress bar this calculation is refactored into our CGUIInfoManager.
  • Loading branch information
xhaggi authored and popcornmix committed Apr 27, 2015
1 parent 22f0974 commit 871f963
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 77 deletions.
33 changes: 25 additions & 8 deletions xbmc/GUIInfoManager.cpp
Expand Up @@ -2144,7 +2144,7 @@ bool CGUIInfoManager::GetInt(int &value, int info, int contextWindow, const CGUI
value = (int)(g_application.GetCachePercentage());
break;
case PLAYER_SEEKBAR:
value = (int)CSeekHandler::Get().GetPercent();
value = (int)GetSeekPercent();
break;
case PLAYER_CACHELEVEL:
value = (int)(g_application.m_pPlayer->GetCacheLevel());
Expand Down Expand Up @@ -3276,11 +3276,12 @@ std::string CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextW
}
else if (info.m_info == PLAYER_SEEKSTEPSIZE)
{
std::string seekOffset = StringUtils::SecondsToTimeString(abs(m_seekStepSize), (TIME_FORMAT)info.GetData1());
if (m_seekStepSize < 0)
return "-" + seekOffset;
if (m_seekStepSize > 0)
return "+" + seekOffset;
int seekSize = CSeekHandler::Get().GetSeekSize();
std::string strSeekSize = StringUtils::SecondsToTimeString(abs(seekSize), (TIME_FORMAT)info.GetData1());
if (seekSize < 0)
return "-" + strSeekSize;
if (seekSize > 0)
return "+" + strSeekSize;
}
else if (info.m_info == PLAYER_ITEM_ART)
{
Expand Down Expand Up @@ -4110,8 +4111,7 @@ std::string CGUIInfoManager::GetCurrentSeekTime(TIME_FORMAT format) const
{
if (format == TIME_FORMAT_GUESS && GetTotalPlayTime() >= 3600)
format = TIME_FORMAT_HH_MM_SS;
float time = GetTotalPlayTime() * CSeekHandler::Get().GetPercent() * 0.01f;
return StringUtils::SecondsToTimeString((int)time, format);
return StringUtils::SecondsToTimeString(g_application.GetTime() + CSeekHandler::Get().GetSeekSize(), format);
}

int CGUIInfoManager::GetTotalPlayTime() const
Expand All @@ -4126,6 +4126,23 @@ int CGUIInfoManager::GetPlayTimeRemaining() const
return iReverse > 0 ? iReverse : 0;
}

float CGUIInfoManager::GetSeekPercent() const
{
if (g_infoManager.GetTotalPlayTime() == 0)
return 0.0f;

float percentPlayTime = static_cast<float>(g_infoManager.GetPlayTime()) / g_infoManager.GetTotalPlayTime() * 0.1f;
float percentPerSecond = 100.0f / static_cast<float>(g_infoManager.GetTotalPlayTime());
float percent = percentPlayTime + percentPerSecond * CSeekHandler::Get().GetSeekSize();

if (percent > 100.0f)
percent = 100.0f;
if (percent < 0.0f)
percent = 0.0f;

return percent;
}

std::string CGUIInfoManager::GetCurrentPlayTimeRemaining(TIME_FORMAT format) const
{
if (format == TIME_FORMAT_GUESS && GetTotalPlayTime() >= 3600)
Expand Down
3 changes: 1 addition & 2 deletions xbmc/GUIInfoManager.h
Expand Up @@ -803,6 +803,7 @@ class CGUIInfoManager : public IMsgTargetCallback, public Observable
std::string GetCurrentSeekTime(TIME_FORMAT format = TIME_FORMAT_GUESS) const;
int GetPlayTimeRemaining() const;
int GetTotalPlayTime() const;
float GetSeekPercent() const;
std::string GetCurrentPlayTimeRemaining(TIME_FORMAT format) const;
std::string GetVersionShort(void);
std::string GetAppName();
Expand All @@ -811,7 +812,6 @@ class CGUIInfoManager : public IMsgTargetCallback, public Observable

bool GetDisplayAfterSeek();
void SetDisplayAfterSeek(unsigned int timeOut = 2500, int seekOffset = 0);
void SetSeekStepSize(int seekStepSize) { m_seekStepSize = seekStepSize; };
void SetSeeking(bool seeking) { m_playerSeeking = seeking; };
void SetShowTime(bool showtime) { m_playerShowTime = showtime; };
void SetShowCodec(bool showcodec) { m_playerShowCodec = showcodec; };
Expand Down Expand Up @@ -939,7 +939,6 @@ class CGUIInfoManager : public IMsgTargetCallback, public Observable
//Fullscreen OSD Stuff
unsigned int m_AfterSeekTimeout;
int m_seekOffset;
int m_seekStepSize;
bool m_playerSeeking;
bool m_playerShowTime;
bool m_playerShowCodec;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/dialogs/GUIDialogSeekBar.cpp
Expand Up @@ -76,7 +76,7 @@ void CGUIDialogSeekBar::FrameMove()
}
else
{
CONTROL_SELECT_ITEM(POPUP_SEEK_PROGRESS, (unsigned int)CSeekHandler::Get().GetPercent());
CONTROL_SELECT_ITEM(POPUP_SEEK_PROGRESS, (unsigned int)g_infoManager.GetSeekPercent());
SET_CONTROL_LABEL(POPUP_SEEK_LABEL, g_infoManager.GetCurrentSeekTime());
}

Expand Down
95 changes: 32 additions & 63 deletions xbmc/utils/SeekHandler.cpp
Expand Up @@ -34,9 +34,8 @@
CSeekHandler::CSeekHandler()
: m_seekDelay(500),
m_requireSeek(false),
m_percent(0.0f),
m_percentPlayTime(0.0f),
m_analogSeek(false),
m_seekSize(0),
m_seekStep(0)
{
}
Expand All @@ -57,8 +56,8 @@ CSeekHandler& CSeekHandler::Get()
void CSeekHandler::Reset()
{
m_requireSeek = false;
m_percent = 0;
m_seekStep = 0;
m_seekSize = 0;

m_seekDelays.clear();
m_seekDelays.insert(std::make_pair(SEEK_TYPE_VIDEO, CSettings::Get().GetInt("videoplayer.seekdelay")));
Expand Down Expand Up @@ -121,65 +120,52 @@ int CSeekHandler::GetSeekSeconds(bool forward, SeekType type)
void CSeekHandler::Seek(bool forward, float amount, float duration /* = 0 */, bool analogSeek /* = false */, SeekType type /* = SEEK_TYPE_VIDEO */)
{
// abort if we do not have a play time or already perform a seek
if (g_infoManager.GetTotalPlayTime() == 0 ||
g_infoManager.m_performingSeek)
if (g_infoManager.m_performingSeek)
return;

CSingleLock lock(m_critSection);

// not yet seeking
if (!m_requireSeek)
{
m_percent = static_cast<float>(g_infoManager.GetPlayTime()) / g_infoManager.GetTotalPlayTime() * 0.1f;
m_percentPlayTime = m_percent;

// tell info manager that we have started a seek operation
m_requireSeek = true;
g_infoManager.SetSeeking(true);
m_seekStep = 0;
m_seekSize = 0;
m_analogSeek = analogSeek;
m_seekDelay = analogSeek ? analogSeekDelay : m_seekDelays.at(type);
}

// calculate our seek amount
if (!g_infoManager.m_performingSeek)
if (analogSeek)
{
if (analogSeek)
{
//100% over 1 second.
float speed = 100.0f;
if( duration )
speed *= duration;
else
speed /= g_infoManager.GetFPS();
//100% over 1 second.
float speed = 100.0f;
if( duration )
speed *= duration;
else
speed /= g_infoManager.GetFPS();

if (forward)
m_percent += amount * amount * speed;
else
m_percent -= amount * amount * speed;
int seekSize = (amount * amount * speed) * g_infoManager.GetTotalPlayTime() / 100;
if (forward)
m_seekSize += seekSize;
else
m_seekSize -= seekSize;
}
else
{
int seekSeconds = GetSeekSeconds(forward, type);
if (seekSeconds != 0)
{
m_seekSize = seekSeconds;
}
else
{
int seekSeconds = GetSeekSeconds(forward, type);
if (seekSeconds != 0)
{
float percentPerSecond = 100.0f / static_cast<float>(g_infoManager.GetTotalPlayTime());
m_percent = m_percentPlayTime + percentPerSecond * seekSeconds;

g_infoManager.SetSeekStepSize(seekSeconds);
}
else
{
// nothing to do, abort seeking
m_requireSeek = false;
g_infoManager.SetSeeking(false);
}
// nothing to do, abort seeking
m_requireSeek = false;
g_infoManager.SetSeeking(false);
}

if (m_percent > 100.0f)
m_percent = 100.0f;
if (m_percent < 0.0f)
m_percent = 0.0f;
}

m_timer.StartZero();
Expand All @@ -188,35 +174,22 @@ void CSeekHandler::Seek(bool forward, float amount, float duration /* = 0 */, bo
void CSeekHandler::SeekSeconds(int seconds)
{
// abort if we do not have a play time or already perform a seek
if (seconds == 0 ||
g_infoManager.GetTotalPlayTime() == 0 ||
g_infoManager.m_performingSeek)
if (seconds == 0 || g_infoManager.m_performingSeek)
return;

CSingleLock lock(m_critSection);

m_requireSeek = true;
m_seekDelay = 0;

m_seekSize = seconds;
g_infoManager.SetSeeking(true);
g_infoManager.SetSeekStepSize(seconds);

float percentPlayTime = static_cast<float>(g_infoManager.GetPlayTime()) / g_infoManager.GetTotalPlayTime() * 0.1f;
float percentPerSecond = 100.0f / static_cast<float>(g_infoManager.GetTotalPlayTime());

m_percent = percentPlayTime + percentPerSecond * seconds;

if (m_percent > 100.0f)
m_percent = 100.0f;
if (m_percent < 0.0f)
m_percent = 0.0f;

m_timer.StartZero();
}

float CSeekHandler::GetPercent() const
int CSeekHandler::GetSeekSize() const
{
return m_percent;
return m_seekSize;
}

bool CSeekHandler::InProgress() const
Expand All @@ -230,13 +203,9 @@ void CSeekHandler::Process()
{
g_infoManager.m_performingSeek = true;

// reset seek step size
g_infoManager.SetSeekStepSize(0);

// calculate the seek time
double time = g_infoManager.GetTotalPlayTime() * m_percent * 0.01;
// perform relative seek
g_application.m_pPlayer->SeekTimeRelative(static_cast<int64_t>(m_seekSize * 1000));

g_application.SeekTime(time);
m_requireSeek = false;
g_infoManager.SetSeeking(false);
}
Expand Down
5 changes: 2 additions & 3 deletions xbmc/utils/SeekHandler.h
Expand Up @@ -48,7 +48,7 @@ class CSeekHandler : public ISettingCallback, public IActionListener
void Process();
void Reset();

float GetPercent() const;
int GetSeekSize() const;
bool InProgress() const;

protected:
Expand All @@ -64,9 +64,8 @@ class CSeekHandler : public ISettingCallback, public IActionListener
int m_seekDelay;
std::map<SeekType, int > m_seekDelays;
bool m_requireSeek;
float m_percent;
float m_percentPlayTime;
bool m_analogSeek;
int m_seekSize;
int m_seekStep;
std::map<SeekType, std::vector<int> > m_forwardSeekSteps;
std::map<SeekType, std::vector<int> > m_backwardSeekSteps;
Expand Down

0 comments on commit 871f963

Please sign in to comment.