Skip to content

Commit

Permalink
fire python calbacks OnPlayback.. from main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Mar 28, 2018
1 parent a6ad142 commit d13748e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 87 deletions.
169 changes: 84 additions & 85 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3220,16 +3220,61 @@ bool CApplication::PlayFile(CFileItem item, const std::string& player, bool bRes
return true;
}

void CApplication::PlaybackCleanup()
{
#ifdef TARGET_DARWIN_IOS
CDarwinUtils::SetScheduling(message.GetMessage());
#endif

if (!m_appPlayer.IsPlaying())
{
g_audioManager.Enable(true);
m_appPlayer.OpenNext(m_ServiceManager->GetPlayerCoreFactory());
}

if (!m_appPlayer.IsPlayingVideo())
{
if(g_windowManager.GetActiveWindow() == WINDOW_FULLSCREEN_VIDEO ||
g_windowManager.GetActiveWindow() == WINDOW_FULLSCREEN_GAME)
{
g_windowManager.PreviousWindow();
}
else
{
// resets to res_desktop or look&feel resolution (including refreshrate)
g_graphicsContext.SetFullScreenVideo(false);
}
}

if (!m_appPlayer.IsPlayingAudio() && CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST_NONE && g_windowManager.GetActiveWindow() == WINDOW_VISUALISATION)
{
m_ServiceManager->GetSettings().Save(); // save vis settings
WakeUpScreenSaverAndDPMS();
g_windowManager.PreviousWindow();
}

// DVD ejected while playing in vis ?
if (!m_appPlayer.IsPlayingAudio() && (m_itemCurrentFile->IsCDDA() || m_itemCurrentFile->IsOnDVD()) && !g_mediaManager.IsDiscInDrive() && g_windowManager.GetActiveWindow() == WINDOW_VISUALISATION)
{
// yes, disable vis
m_ServiceManager->GetSettings().Save(); // save vis settings
WakeUpScreenSaverAndDPMS();
g_windowManager.PreviousWindow();
}

if (!m_appPlayer.IsPlaying())
{
m_stackHelper.Clear();
}

if (IsEnableTestMode())
CApplicationMessenger::GetInstance().PostMsg(TMSG_QUIT);
}

void CApplication::OnPlayBackEnded()
{
CLog::LogF(LOGDEBUG ,"CApplication::OnPlayBackEnded");

// informs python script currently running playback has ended
// (does nothing if python is not loaded)
#ifdef HAS_PYTHON
g_pythonParser.OnPlayBackEnded();
#endif

CServiceBroker::GetPVRManager().OnPlaybackEnded(m_itemCurrentFile);

CVariant data(CVariant::VariantTypeObject);
Expand All @@ -3248,12 +3293,6 @@ void CApplication::OnPlayBackStarted(const CFileItem &file)
if (file.GetProperty("get_stream_details_from_player").asBoolean())
m_appPlayer.SetUpdateStreamDetails();

#ifdef HAS_PYTHON
// informs python script currently running playback has started
// (does nothing if python is not loaded)
g_pythonParser.OnPlayBackStarted(file);
#endif

if (m_stackHelper.IsPlayingISOStack() || m_stackHelper.IsPlayingRegularStack())
m_itemCurrentFile.reset(new CFileItem(*m_stackHelper.GetRegisteredStack(file)));
else
Expand Down Expand Up @@ -3350,11 +3389,6 @@ void CApplication::OnPlayBackStopped()
{
CLog::LogF(LOGDEBUG, "CApplication::OnPlayBackStopped");

// informs python script currently running playback has ended
// (does nothing if python is not loaded)
#ifdef HAS_PYTHON
g_pythonParser.OnPlayBackStopped();
#endif
#if defined(TARGET_DARWIN_IOS)
CDarwinUtils::EnableOSScreenSaver(true);
#endif
Expand Down Expand Up @@ -3932,6 +3966,12 @@ bool CApplication::OnMessage(CGUIMessage& message)
g_infoManager.SetCurrentItem(*m_itemCurrentFile);
g_partyModeManager.OnSongChange(true);

#ifdef HAS_PYTHON
// informs python script currently running playback has started
// (does nothing if python is not loaded)
g_pythonParser.OnPlayBackStarted(*m_itemCurrentFile);
#endif

CVariant param;
param["player"]["speed"] = 1;
param["player"]["playerid"] = CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist();
Expand Down Expand Up @@ -4003,80 +4043,39 @@ bool CApplication::OnMessage(CGUIMessage& message)
break;

case GUI_MSG_PLAYBACK_STOPPED:
case GUI_MSG_PLAYBACK_ENDED:
m_playerEvent.Set();
case GUI_MSG_PLAYLISTPLAYER_STOPPED:
{
#ifdef TARGET_DARWIN_IOS
CDarwinUtils::SetScheduling(message.GetMessage());
m_itemCurrentFile->Reset();
g_infoManager.ResetCurrentItem();
PlaybackCleanup();
#ifdef HAS_PYTHON
g_pythonParser.OnPlayBackStopped();
#endif
// first check if we still have items in the stack to play
if (message.GetMessage() == GUI_MSG_PLAYBACK_ENDED)
{
if (m_stackHelper.IsPlayingRegularStack() && m_stackHelper.HasNextStackPartFileItem())
{ // just play the next item in the stack
PlayFile(m_stackHelper.SetNextStackPartCurrentFileItem(), "", true);
return true;
}
}

// reset the current playing file
m_itemCurrentFile->Reset();
g_infoManager.ResetCurrentItem();
return true;

if (message.GetMessage() == GUI_MSG_PLAYBACK_ENDED)
{
if (!CServiceBroker::GetPlaylistPlayer().PlayNext(1, true))
m_appPlayer.ClosePlayer();
}

if (!m_appPlayer.IsPlaying())
{
g_audioManager.Enable(true);
m_appPlayer.OpenNext(m_ServiceManager->GetPlayerCoreFactory());
}

if (!m_appPlayer.IsPlayingVideo())
{
if(g_windowManager.GetActiveWindow() == WINDOW_FULLSCREEN_VIDEO ||
g_windowManager.GetActiveWindow() == WINDOW_FULLSCREEN_GAME)
{
g_windowManager.PreviousWindow();
}
else
{
// resets to res_desktop or look&feel resolution (including refreshrate)
g_graphicsContext.SetFullScreenVideo(false);
}
}

if (!m_appPlayer.IsPlayingAudio() && CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST_NONE && g_windowManager.GetActiveWindow() == WINDOW_VISUALISATION)
{
m_ServiceManager->GetSettings().Save(); // save vis settings
WakeUpScreenSaverAndDPMS();
g_windowManager.PreviousWindow();
}
case GUI_MSG_PLAYBACK_ENDED:
m_playerEvent.Set();
if (m_stackHelper.IsPlayingRegularStack() && m_stackHelper.HasNextStackPartFileItem())
{ // just play the next item in the stack
PlayFile(m_stackHelper.SetNextStackPartCurrentFileItem(), "", true);
return true;
}
m_itemCurrentFile->Reset();
g_infoManager.ResetCurrentItem();
if (!CServiceBroker::GetPlaylistPlayer().PlayNext(1, true))
m_appPlayer.ClosePlayer();

// DVD ejected while playing in vis ?
if (!m_appPlayer.IsPlayingAudio() && (m_itemCurrentFile->IsCDDA() || m_itemCurrentFile->IsOnDVD()) && !g_mediaManager.IsDiscInDrive() && g_windowManager.GetActiveWindow() == WINDOW_VISUALISATION)
{
// yes, disable vis
m_ServiceManager->GetSettings().Save(); // save vis settings
WakeUpScreenSaverAndDPMS();
g_windowManager.PreviousWindow();
}
PlaybackCleanup();

if (!m_appPlayer.IsPlaying())
{
m_itemCurrentFile.reset(new CFileItem());
m_stackHelper.Clear();
}
#ifdef HAS_PYTHON
g_pythonParser.OnPlayBackEnded();
#endif
return true;

if (IsEnableTestMode())
CApplicationMessenger::GetInstance().PostMsg(TMSG_QUIT);
return true;
}
break;
case GUI_MSG_PLAYLISTPLAYER_STOPPED:
m_itemCurrentFile->Reset();
g_infoManager.ResetCurrentItem();
PlaybackCleanup();
return true;

case GUI_MSG_PLAYBACK_AVSTARTED:
m_playerEvent.Set();
Expand Down
3 changes: 1 addition & 2 deletions xbmc/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,16 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs

protected:
bool OnSettingsSaving() const override;

bool Load(const TiXmlNode *settings) override;
bool Save(TiXmlNode *settings) const override;

void OnSettingChanged(std::shared_ptr<const CSetting> setting) override;
void OnSettingAction(std::shared_ptr<const CSetting> setting) override;
bool OnSettingUpdate(std::shared_ptr<CSetting> setting, const char *oldSettingId, const TiXmlNode *oldSettingNode) override;

bool LoadSkin(const std::string& skinID);

void CheckOSScreenSaverInhibitionSetting();
void PlaybackCleanup();

/*!
\brief Delegates the action to all registered action handlers.
Expand Down

0 comments on commit d13748e

Please sign in to comment.