Skip to content

Commit

Permalink
Merge pull request xbmc#21450 from notspiff/application_player_constness
Browse files Browse the repository at this point in the history
Application player constness
  • Loading branch information
fuzzard authored Sep 6, 2022
2 parents 5fcf172 + 8769ddb commit 4f8febe
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 42 deletions.
62 changes: 34 additions & 28 deletions xbmc/ApplicationPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@

using namespace std::chrono_literals;

std::shared_ptr<IPlayer> CApplicationPlayer::GetInternal() const
std::shared_ptr<const IPlayer> CApplicationPlayer::GetInternal() const
{
std::unique_lock<CCriticalSection> lock(m_playerLock);
return m_pPlayer;
}

std::shared_ptr<IPlayer> CApplicationPlayer::GetInternal()
{
std::unique_lock<CCriticalSection> lock(m_playerLock);
return m_pPlayer;
Expand Down Expand Up @@ -66,9 +72,9 @@ void CApplicationPlayer::CreatePlayer(const CPlayerCoreFactory &factory, const s
}
}

std::string CApplicationPlayer::GetCurrentPlayer()
std::string CApplicationPlayer::GetCurrentPlayer() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
{
return player->m_name;
Expand Down Expand Up @@ -162,8 +168,8 @@ void CApplicationPlayer::OpenNext(const CPlayerCoreFactory &factory)

bool CApplicationPlayer::HasPlayer() const
{
std::shared_ptr<IPlayer> player = GetInternal();
return player != NULL;
std::shared_ptr<const IPlayer> player = GetInternal();
return player != nullptr;
}

int CApplicationPlayer::GetChapter()
Expand Down Expand Up @@ -203,19 +209,19 @@ int64_t CApplicationPlayer::GetChapterPos(int chapterIdx)

bool CApplicationPlayer::HasAudio() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
return (player && player->HasAudio());
}

bool CApplicationPlayer::HasVideo() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
return (player && player->HasVideo());
}

bool CApplicationPlayer::HasGame() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
return (player && player->HasGame());
}

Expand All @@ -232,7 +238,7 @@ int CApplicationPlayer::GetPreferredPlaylist() const

bool CApplicationPlayer::HasRDS() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
return (player && player->HasRDS());
}

Expand All @@ -243,7 +249,7 @@ bool CApplicationPlayer::IsPaused()

bool CApplicationPlayer::IsPlaying() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
return (player && player->IsPlaying());
}

Expand Down Expand Up @@ -311,7 +317,7 @@ void CApplicationPlayer::SeekPercentage(float fPercent)

bool CApplicationPlayer::IsPassthrough() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
return (player && player->IsPassthrough());
}

Expand Down Expand Up @@ -350,7 +356,7 @@ void CApplicationPlayer::SeekTimeRelative(int64_t iTime)

int64_t CApplicationPlayer::GetTime() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
return CDataCacheCore::GetInstance().GetPlayTime();
else
Expand All @@ -359,7 +365,7 @@ int64_t CApplicationPlayer::GetTime() const

int64_t CApplicationPlayer::GetMinTime() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
return CDataCacheCore::GetInstance().GetMinTime();
else
Expand All @@ -368,7 +374,7 @@ int64_t CApplicationPlayer::GetMinTime() const

int64_t CApplicationPlayer::GetMaxTime() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
return CDataCacheCore::GetInstance().GetMaxTime();
else
Expand All @@ -377,7 +383,7 @@ int64_t CApplicationPlayer::GetMaxTime() const

time_t CApplicationPlayer::GetStartTime() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
return CDataCacheCore::GetInstance().GetStartTime();
else
Expand All @@ -386,7 +392,7 @@ time_t CApplicationPlayer::GetStartTime() const

int64_t CApplicationPlayer::GetTotalTime() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
{
int64_t total = CDataCacheCore::GetInstance().GetMaxTime() - CDataCacheCore::GetInstance().GetMinTime();
Expand All @@ -398,19 +404,19 @@ int64_t CApplicationPlayer::GetTotalTime() const

bool CApplicationPlayer::IsCaching() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
return (player && player->IsCaching());
}

bool CApplicationPlayer::IsInMenu() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
return (player && player->IsInMenu());
}

MenuType CApplicationPlayer::GetSupportedMenuType() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (!player)
{
return MenuType::NONE;
Expand All @@ -420,7 +426,7 @@ MenuType CApplicationPlayer::GetSupportedMenuType() const

int CApplicationPlayer::GetCacheLevel() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
return player->GetCacheLevel();
else
Expand Down Expand Up @@ -491,7 +497,7 @@ std::shared_ptr<TextCacheStruct_t> CApplicationPlayer::GetTeletextCache()

float CApplicationPlayer::GetPercentage() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
{
float fPercent = CDataCacheCore::GetInstance().GetPlayPercentage();
Expand All @@ -503,7 +509,7 @@ float CApplicationPlayer::GetPercentage() const

float CApplicationPlayer::GetCachePercentage() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
return player->GetCachePercentage();
else
Expand Down Expand Up @@ -787,9 +793,9 @@ void CApplicationPlayer::SetPlaySpeed(float speed)
SetSpeed(speed);
}

float CApplicationPlayer::GetPlaySpeed()
float CApplicationPlayer::GetPlaySpeed() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
{
return CDataCacheCore::GetInstance().GetSpeed();
Expand All @@ -798,9 +804,9 @@ float CApplicationPlayer::GetPlaySpeed()
return 0;
}

float CApplicationPlayer::GetPlayTempo()
float CApplicationPlayer::GetPlayTempo() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
{
return CDataCacheCore::GetInstance().GetTempo();
Expand Down Expand Up @@ -983,9 +989,9 @@ bool CApplicationPlayer::IsRemotePlaying()
return false;
}

CVideoSettings CApplicationPlayer::GetVideoSettings()
CVideoSettings CApplicationPlayer::GetVideoSettings() const
{
std::shared_ptr<IPlayer> player = GetInternal();
std::shared_ptr<const IPlayer> player = GetInternal();
if (player)
{
return player->GetVideoSettings();
Expand Down
11 changes: 6 additions & 5 deletions xbmc/ApplicationPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class CApplicationPlayer
// player management
void ClosePlayer();
void ResetPlayer();
std::string GetCurrentPlayer();
float GetPlaySpeed();
float GetPlayTempo();
std::string GetCurrentPlayer() const;
float GetPlaySpeed() const;
float GetPlayTempo() const;
bool HasPlayer() const;
bool OpenFile(const CFileItem& item, const CPlayerOptions& options,
const CPlayerCoreFactory &factory,
Expand Down Expand Up @@ -160,7 +160,7 @@ class CApplicationPlayer
void SetSpeed(float speed);
bool SupportsTempo();

CVideoSettings GetVideoSettings();
CVideoSettings GetVideoSettings() const;
void SetVideoSettings(CVideoSettings& settings);

CSeekHandler& GetSeekHandler();
Expand All @@ -173,7 +173,8 @@ class CApplicationPlayer
bool HasGameAgent();

private:
std::shared_ptr<IPlayer> GetInternal() const;
std::shared_ptr<const IPlayer> GetInternal() const;
std::shared_ptr<IPlayer> GetInternal();
void CreatePlayer(const CPlayerCoreFactory &factory, const std::string &player, IPlayerCallback& callback);
void CloseFile(bool reopen = false);

Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/IPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class IPlayer
virtual void Seek(bool bPlus = true, bool bLargeStep = false, bool bChapterOverride = false) = 0;
virtual bool SeekScene(bool bPlus = true) {return false;}
virtual void SeekPercentage(float fPercent = 0){}
virtual float GetCachePercentage(){ return 0;}
virtual float GetCachePercentage() const { return 0; }
virtual void SetMute(bool bOnOff){}
virtual void SetVolume(float volume){}
virtual void SetDynamicRangeCompression(long drc){}
Expand Down Expand Up @@ -253,7 +253,7 @@ class IPlayer
}

// video and audio settings
virtual CVideoSettings GetVideoSettings() { return CVideoSettings(); }
virtual CVideoSettings GetVideoSettings() const { return CVideoSettings(); }
virtual void SetVideoSettings(CVideoSettings& settings) {}

/*!
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/RetroPlayer/RetroPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void CRetroPlayer::SeekPercentage(float fPercent /* = 0 */)
SeekTime(static_cast<int64_t>(totalTime * fPercent / 100.0f));
}

float CRetroPlayer::GetCachePercentage()
float CRetroPlayer::GetCachePercentage() const
{
const float cacheMs = static_cast<float>(m_playback->GetCacheTimeMs());
const float totalMs = static_cast<float>(m_playback->GetTotalTimeMs());
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/RetroPlayer/RetroPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CRetroPlayer : public IPlayer,
bool CanSeek() override;
void Seek(bool bPlus = true, bool bLargeStep = false, bool bChapterOverride = false) override;
void SeekPercentage(float fPercent = 0) override;
float GetCachePercentage() override;
float GetCachePercentage() const override;
void SetMute(bool bOnOff) override;
void SeekTime(int64_t iTime = 0) override;
bool SeekTimeRelative(int64_t iTime) override;
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/VideoPlayer/VideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@ float CVideoPlayer::GetPercentage()
return GetTime() * 100 / (float)iTotalTime;
}

float CVideoPlayer::GetCachePercentage()
float CVideoPlayer::GetCachePercentage() const
{
std::unique_lock<CCriticalSection> lock(m_StateSection);
return (float) (m_State.cache_offset * 100); // NOTE: Percentage returned is relative
Expand Down Expand Up @@ -4876,7 +4876,7 @@ void CVideoPlayer::SetDynamicRangeCompression(long drc)
m_VideoPlayerAudio->SetDynamicRangeCompression(drc);
}

CVideoSettings CVideoPlayer::GetVideoSettings()
CVideoSettings CVideoPlayer::GetVideoSettings() const
{
return m_processInfo->GetVideoSettings();
}
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/VideoPlayer/VideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class CVideoPlayer : public IPlayer, public CThread, public IVideoPlayer,
void Seek(bool bPlus, bool bLargeStep, bool bChapterOverride) override;
bool SeekScene(bool bPlus = true) override;
void SeekPercentage(float iPercent) override;
float GetCachePercentage() override;
float GetCachePercentage() const override;

void SetDynamicRangeCompression(long drc) override;
bool CanPause() override;
Expand Down Expand Up @@ -352,7 +352,7 @@ class CVideoPlayer : public IPlayer, public CThread, public IVideoPlayer,
int OnDiscNavResult(void* pData, int iMessage) override;
void GetVideoResolution(unsigned int &width, unsigned int &height) override;

CVideoSettings GetVideoSettings() override;
CVideoSettings GetVideoSettings() const override;
void SetVideoSettings(CVideoSettings& settings) override;

void SetUpdateStreamDetails();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class IRenderMsg
virtual void UpdateRenderBuffers(int queued, int discard, int free) = 0;
virtual void UpdateGuiRender(bool gui) = 0;
virtual void UpdateVideoRender(bool video) = 0;
virtual CVideoSettings GetVideoSettings() = 0;
virtual CVideoSettings GetVideoSettings() const = 0;
};

class CRenderManager
Expand Down

0 comments on commit 4f8febe

Please sign in to comment.