Skip to content

Commit

Permalink
IPlayer: properly sync playspeed with application
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Jul 12, 2016
1 parent c414d08 commit a78b5a6
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 111 deletions.
55 changes: 8 additions & 47 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,7 @@ bool CApplication::OnAction(const CAction &action)
if (action.GetID() == ACTION_PREV_ITEM && m_pPlayer->CanSeek())
{
SeekTime(0);
m_pPlayer->SetPlaySpeed(1, g_application.m_muted);
m_pPlayer->SetPlaySpeed(1);
return true;
}

Expand All @@ -2163,7 +2163,7 @@ bool CApplication::OnAction(const CAction &action)
m_pPlayer->Pause();
// go back to normal play speed on unpause
if (!m_pPlayer->IsPaused() && m_pPlayer->GetPlaySpeed() != 1)
m_pPlayer->SetPlaySpeed(1, g_application.m_muted);
m_pPlayer->SetPlaySpeed(1);

g_audioManager.Enable(m_pPlayer->IsPaused());
return true;
Expand All @@ -2176,7 +2176,7 @@ bool CApplication::OnAction(const CAction &action)
return OnAction(CAction(ACTION_PAUSE));
// if we do a FF/RW then go back to normal speed
if (m_pPlayer->GetPlaySpeed() != 1)
m_pPlayer->SetPlaySpeed(1, g_application.m_muted);
m_pPlayer->SetPlaySpeed(1);
return true;
}
if (!m_pPlayer->IsPaused())
Expand All @@ -2198,7 +2198,7 @@ bool CApplication::OnAction(const CAction &action)
if (iPlaySpeed > 32 || iPlaySpeed < -32)
iPlaySpeed = 1;

m_pPlayer->SetPlaySpeed(iPlaySpeed, g_application.m_muted);
m_pPlayer->SetPlaySpeed(iPlaySpeed);
return true;
}
else if ((action.GetAmount() || m_pPlayer->GetPlaySpeed() != 1) && (action.GetID() == ACTION_ANALOG_REWIND || action.GetID() == ACTION_ANALOG_FORWARD))
Expand All @@ -2211,7 +2211,7 @@ bool CApplication::OnAction(const CAction &action)
int iSpeed = 1 << iPower;
if (iSpeed != 1 && action.GetID() == ACTION_ANALOG_REWIND)
iSpeed = -iSpeed;
g_application.m_pPlayer->SetPlaySpeed(iSpeed, g_application.m_muted);
g_application.m_pPlayer->SetPlaySpeed(iSpeed);
if (iSpeed == 1)
CLog::Log(LOGDEBUG,"Resetting playspeed");
return true;
Expand All @@ -2226,7 +2226,7 @@ bool CApplication::OnAction(const CAction &action)
m_pPlayer->Pause();
g_audioManager.Enable(m_pPlayer->IsPaused());

g_application.m_pPlayer->SetPlaySpeed(1, g_application.m_muted);
g_application.m_pPlayer->SetPlaySpeed(1);
return true;
}
}
Expand Down Expand Up @@ -3167,8 +3167,7 @@ PlayBackRet CApplication::PlayFile(CFileItem item, const std::string& player, bo
CMediaSettings::GetInstance().GetCurrentAudioSettings() = CMediaSettings::GetInstance().GetDefaultAudioSettings();
// see if we have saved options in the database

m_pPlayer->SetPlaySpeed(1, g_application.m_muted);
m_pPlayer->m_iPlaySpeed = 1; // Reset both CApp's & Player's speed else we'll get confused
m_pPlayer->SetPlaySpeed(1);

m_itemCurrentFile.reset(new CFileItem(item));

Expand Down Expand Up @@ -3405,15 +3404,8 @@ PlayBackRet CApplication::PlayFile(CFileItem item, const std::string& player, bo
iResult = PLAYBACK_FAIL;
}

if(iResult == PLAYBACK_OK)
if (iResult == PLAYBACK_OK)
{
if (m_pPlayer->GetPlaySpeed() != 1)
{
int iSpeed = m_pPlayer->GetPlaySpeed();
m_pPlayer->m_iPlaySpeed = 1;
m_pPlayer->SetPlaySpeed(iSpeed, g_application.m_muted);
}

// if player has volume control, set it.
if (m_pPlayer->ControlsVolume())
{
Expand Down Expand Up @@ -4246,9 +4238,6 @@ bool CApplication::OnMessage(CGUIMessage& message)
else
{
m_pPlayer->ClosePlayer();

// Reset playspeed
m_pPlayer->m_iPlaySpeed = 1;
}

if (!m_pPlayer->IsPlaying())
Expand Down Expand Up @@ -4421,10 +4410,6 @@ void CApplication::Process()
CApplicationMessenger::GetInstance().ProcessMessages();
if (g_application.m_bStop) return; //we're done, everything has been unloaded

// check how far we are through playing the current item
// and do anything that needs doing (playcount updates etc)
CheckPlayingProgress();

// update sound
m_pPlayer->DoAudioWork();

Expand Down Expand Up @@ -5037,30 +5022,6 @@ void CApplication::StartMusicArtistScan(const std::string& strDirectory,
m_musicInfoScanner->FetchArtistInfo(strDirectory,refresh);
}

void CApplication::CheckPlayingProgress()
{
// check if we haven't rewound past the start of the file
if (m_pPlayer->IsPlaying())
{
int iSpeed = g_application.m_pPlayer->GetPlaySpeed();
if (iSpeed < 1)
{
iSpeed *= -1;
int iPower = 0;
while (iSpeed != 1)
{
iSpeed >>= 1;
iPower++;
}
if (g_infoManager.GetPlayTime() / 1000 < iPower)
{
g_application.m_pPlayer->SetPlaySpeed(1, g_application.m_muted);
g_application.SeekTime(0);
}
}
}
}

bool CApplication::ProcessAndStartPlaylist(const std::string& strPlayList, CPlayList& playlist, int iPlaylist, int track)
{
CLog::Log(LOGDEBUG,"CApplication::ProcessAndStartPlaylist(%s, %i)",strPlayList.c_str(), iPlaylist);
Expand Down
1 change: 0 additions & 1 deletion xbmc/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
bool IsIdleShutdownInhibited() const;
// Checks whether the screensaver and / or DPMS should become active.
void CheckScreenSaverAndDPMS();
void CheckPlayingProgress();
void ActivateScreenSaver(bool forceType = false);
bool SetupNetwork();
void CloseNetworkShares();
Expand Down
53 changes: 18 additions & 35 deletions xbmc/ApplicationPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,11 @@ float CApplicationPlayer::GetCachePercentage() const
return 0.0;
}

void CApplicationPlayer::ToFFRW(int iSpeed)
void CApplicationPlayer::SetSpeed(int iSpeed)
{
std::shared_ptr<IPlayer> player = GetInternal();
if (player)
player->ToFFRW(iSpeed);
player->SetSpeed(iSpeed);
}

void CApplicationPlayer::DoAudioWork()
Expand Down Expand Up @@ -722,51 +722,34 @@ void CApplicationPlayer::GetScalingMethods(std::vector<int> &scalingMethods)
player->OMXGetScalingMethods(scalingMethods);
}

void CApplicationPlayer::SetPlaySpeed(int iSpeed, bool bApplicationMuted)
void CApplicationPlayer::SetPlaySpeed(int iSpeed)
{
std::shared_ptr<IPlayer> player = GetInternal();
if (!player)
return;

if (!IsPlayingAudio() && !IsPlayingVideo())
return ;
if (m_iPlaySpeed == iSpeed)
return ;
if (!CanSeek())
return;
if (IsPaused())
{
if (
((m_iPlaySpeed > 1) && (iSpeed > m_iPlaySpeed)) ||
((m_iPlaySpeed < -1) && (iSpeed < m_iPlaySpeed))
)
{
iSpeed = m_iPlaySpeed; // from pause to ff/rw, do previous ff/rw speed
}
Pause();
}
m_iPlaySpeed = iSpeed;

ToFFRW(m_iPlaySpeed);
SetSpeed(iSpeed);
m_speedUpdate.SetExpired();
}

int CApplicationPlayer::GetPlaySpeed()
{
if (!m_speedUpdate.IsTimePast())
return m_iPlaySpeed;

// if player has volume control, set it.
if (ControlsVolume())
std::shared_ptr<IPlayer> player = GetInternal();
if (player)
{
if (m_iPlaySpeed == 1)
{ // restore volume
player->SetVolume(g_application.GetVolume(false));
}
else
{ // mute volume
player->SetVolume(VOLUME_MINIMUM);
}
player->SetMute(bApplicationMuted);
m_iPlaySpeed = player->GetSpeed();
m_speedUpdate.Set(1000);
return m_iPlaySpeed;
}
}
else
return 0;

int CApplicationPlayer::GetPlaySpeed() const
{
return m_iPlaySpeed;
}

void CApplicationPlayer::FrameMove()
Expand Down
12 changes: 6 additions & 6 deletions xbmc/ApplicationPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ class CApplicationPlayer
int m_iVideoStream;
XbmcThreads::EndTime m_subtitleStreamUpdate;
int m_iSubtitleStream;

XbmcThreads::EndTime m_speedUpdate;
int m_iPlaySpeed;

public:
CApplicationPlayer();

int m_iPlaySpeed;

// player management
void CloseFile(bool reopen = false);
void ClosePlayer();
void ClosePlayerGapless(std::string &playername);
void CreatePlayer(const std::string &player, IPlayerCallback& callback);
std::string GetCurrentPlayer();
int GetPlaySpeed() const;
int GetPlaySpeed();
bool HasPlayer() const;
PlayBackRet OpenFile(const CFileItem& item, const CPlayerOptions& options);
void SetPlaySpeed(int iSpeed, bool bApplicationMuted);
void SetPlaySpeed(int iSpeed);

void FrameMove();
bool HasFrame();
Expand Down Expand Up @@ -179,7 +179,7 @@ class CApplicationPlayer
void SetVideoStream(int iStream);
void SetVolume(float volume);
bool SwitchChannel(const PVR::CPVRChannelPtr &channel);
void ToFFRW(int iSpeed = 0);
void SetSpeed(int iSpeed);

protected:
std::shared_ptr<IPlayer> GetInternal() const;
Expand Down
7 changes: 6 additions & 1 deletion xbmc/cores/ExternalPlayer/ExternalPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,16 @@ int64_t CExternalPlayer::GetTotalTime() // in milliseconds
return (int64_t)m_totalTime * 1000;
}

void CExternalPlayer::ToFFRW(int iSpeed)
void CExternalPlayer::SetSpeed(int iSpeed)
{
m_speed = iSpeed;
}

int CExternalPlayer::GetSpeed()
{
return m_speed;
}

void CExternalPlayer::ShowOSD(bool bOnoff)
{
}
Expand Down
5 changes: 3 additions & 2 deletions xbmc/cores/ExternalPlayer/ExternalPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ class CExternalPlayer : public IPlayer, public CThread
virtual void SeekTime(int64_t iTime);
virtual int64_t GetTime();
virtual int64_t GetTotalTime();
virtual void ToFFRW(int iSpeed);
virtual void SetSpeed(int iSpeed) override;
virtual int GetSpeed() override;
virtual void ShowOSD(bool bOnoff);
virtual void DoAudioWork() {}
virtual void DoAudioWork() {};

virtual std::string GetPlayerState();
virtual bool SetPlayerState(const std::string& state);
Expand Down
3 changes: 2 additions & 1 deletion xbmc/cores/IPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ class IPlayer
virtual void SetTotalTime(int64_t time) { }
virtual int GetSourceBitrate(){ return 0;}
virtual bool GetStreamDetails(CStreamDetails &details){ return false;}
virtual void ToFFRW(int iSpeed = 0){};
virtual void SetSpeed(int iSpeed) = 0;
virtual int GetSpeed() = 0;
// Skip to next track/item inside the current media (if supported).
virtual bool SkipNext(){return false;}

Expand Down
25 changes: 21 additions & 4 deletions xbmc/cores/VideoPlayer/VideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ CVideoPlayer::CVideoPlayer(IPlayerCallback& callback)
m_errorCount = 0;
m_offset_pts = 0.0;
m_playSpeed = DVD_PLAYSPEED_NORMAL;
m_newPlaySpeed = DVD_PLAYSPEED_NORMAL;
m_streamPlayerSpeed = DVD_PLAYSPEED_NORMAL;
m_caching = CACHESTATE_DONE;
m_HasVideo = false;
Expand Down Expand Up @@ -2030,7 +2031,7 @@ void CVideoPlayer::HandlePlaySpeed()
}

// handle ff/rw
if(m_playSpeed != DVD_PLAYSPEED_NORMAL && m_playSpeed != DVD_PLAYSPEED_PAUSE)
if (m_playSpeed != DVD_PLAYSPEED_NORMAL && m_playSpeed != DVD_PLAYSPEED_PAUSE)
{
if (isInMenu)
{
Expand Down Expand Up @@ -2713,7 +2714,7 @@ void CVideoPlayer::HandleMessages()
}

m_OmxPlayerState.av_clock.OMXSetSpeed(speed);
CLog::Log(LOGDEBUG, "%s::%s CDVDMsg::PLAYER_SETSPEED speed : %d (%d)", "CVideoPlayer", __FUNCTION__, speed, m_playSpeed);
CLog::Log(LOGDEBUG, "%s::%s CDVDMsg::PLAYER_SETSPEED speed : %d (%d)", "CVideoPlayer", __FUNCTION__, speed, static_cast<int>(m_playSpeed));
}
else if ((speed == DVD_PLAYSPEED_NORMAL) &&
(m_playSpeed != DVD_PLAYSPEED_NORMAL) &&
Expand All @@ -2732,6 +2733,7 @@ void CVideoPlayer::HandleMessages()
// 1. disable audio
// 2. skip frames and adjust their pts or the clock
m_playSpeed = speed;
m_newPlaySpeed = speed;
m_caching = CACHESTATE_DONE;
m_clock.SetSpeed(speed);
m_VideoPlayerAudio->SetSpeed(speed);
Expand Down Expand Up @@ -2942,6 +2944,7 @@ void CVideoPlayer::SetPlaySpeed(int speed)
else
{
m_playSpeed = speed;
m_newPlaySpeed = speed;
m_streamPlayerSpeed = speed;
}
}
Expand Down Expand Up @@ -3464,14 +3467,28 @@ int64_t CVideoPlayer::GetTotalTime()
return GetTotalTimeInMsec();
}

void CVideoPlayer::ToFFRW(int iSpeed)
void CVideoPlayer::SetSpeed(int iSpeed)
{
// can't rewind in menu as seeking isn't possible
// forward is fine
if (iSpeed < 0 && IsInMenu()) return;
if (iSpeed < 0 && IsInMenu())
return;

if (!CanSeek())
return;

m_newPlaySpeed = iSpeed * DVD_PLAYSPEED_NORMAL;
SetPlaySpeed(iSpeed * DVD_PLAYSPEED_NORMAL);
}

int CVideoPlayer::GetSpeed()
{
if (m_playSpeed != m_newPlaySpeed)
return m_newPlaySpeed / DVD_PLAYSPEED_NORMAL;

return m_playSpeed / DVD_PLAYSPEED_NORMAL;
}

bool CVideoPlayer::OpenStream(CCurrentStream& current, int64_t demuxerId, int iStream, int source, bool reset /*= true*/)
{
CDemuxStream* stream = NULL;
Expand Down
Loading

0 comments on commit a78b5a6

Please sign in to comment.