Skip to content

Commit

Permalink
Merge pull request #7664 from xhaggi/pvr-window-busy-until-manager-st…
Browse files Browse the repository at this point in the history
…arted
  • Loading branch information
jenkins4kodi committed Aug 3, 2015
2 parents 83da59f + b0961a2 commit a59d037
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 68 deletions.
2 changes: 1 addition & 1 deletion addons/skin.confluence/720p/DialogProgress.xml
Expand Up @@ -37,7 +37,7 @@
<font>font13</font>
<autoscroll time="3000" delay="4000" repeat="5000">true</autoscroll>
</control>
<control type="progress">
<control type="progress" id="20">
<description>Progressbar</description>
<left>30</left>
<top>148</top>
Expand Down
30 changes: 11 additions & 19 deletions xbmc/Application.cpp
Expand Up @@ -1194,17 +1194,15 @@ bool CApplication::Initialize()
#endif
ADDON::CAddonMgr::Get().StartServices(false);

// let's start the PVR manager and decide if the PVR manager handle the startup window activation
if (StartPVRManager())
uiInitializationFinished = false;
else
{
int firstWindow = g_SkinInfo->GetFirstWindow();
// the startup window is considered part of the initialization as it most likely switches to the final window
uiInitializationFinished = firstWindow != WINDOW_STARTUP_ANIM;
// start the PVR manager
StartPVRManager();

g_windowManager.ActivateWindow(firstWindow);
}
// activate the configured start window
int firstWindow = g_SkinInfo->GetFirstWindow();
g_windowManager.ActivateWindow(firstWindow);

// the startup window is considered part of the initialization as it most likely switches to the final window
uiInitializationFinished = firstWindow != WINDOW_STARTUP_ANIM;

CStereoscopicsManager::Get().Initialize();
CApplicationMessenger::Get().SendMsg(TMSG_SETAUDIODSPSTATE, ACTIVE_AE_DSP_STATE_ON); // send a blocking message to active AudioDSP engine
Expand Down Expand Up @@ -1312,18 +1310,12 @@ bool CApplication::StartServer(enum ESERVERS eServer, bool bStart, bool bWait/*
return ret;
}

bool CApplication::StartPVRManager()
void CApplication::StartPVRManager()
{
if (!CSettings::Get().GetBool("pvrmanager.enabled"))
return false;

int firstWindowId = 0;
if (g_PVRManager.IsPVRWindow(g_SkinInfo->GetStartWindow()))
firstWindowId = g_SkinInfo->GetFirstWindow();

g_PVRManager.Start(true, firstWindowId);
return;

return (firstWindowId > 0);
g_PVRManager.Start(true);
}

void CApplication::StopPVRManager()
Expand Down
6 changes: 1 addition & 5 deletions xbmc/Application.h
Expand Up @@ -151,11 +151,7 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs

bool StartServer(enum ESERVERS eServer, bool bStart, bool bWait = false);

/*!
* @brief Starts the PVR manager and decide if the manager should handle the startup window activation.
* @return true, if the startup window activation is handled by the pvr manager, otherwise false
*/
bool StartPVRManager();
void StartPVRManager();
void StopPVRManager();
bool IsCurrentThread() const;
void Stop(int exitCode);
Expand Down
30 changes: 5 additions & 25 deletions xbmc/pvr/PVRManager.cpp
Expand Up @@ -94,8 +94,7 @@ CPVRManager::CPVRManager(void) :
m_bFirstStart(true),
m_bEpgsCreated(false),
m_progressHandle(NULL),
m_managerState(ManagerStateStopped),
m_openWindowId(0)
m_managerState(ManagerStateStopped)
{
CAnnouncementManager::Get().AddAnnouncer(this);
ResetProperties();
Expand Down Expand Up @@ -357,7 +356,6 @@ void CPVRManager::Cleanup(void)
m_currentFile = NULL;
m_bIsSwitchingChannels = false;
m_outdatedAddons.clear();
m_openWindowId = 0;
m_bEpgsCreated = false;

for (unsigned int iJobPtr = 0; iJobPtr < m_pendingUpdates.size(); iJobPtr++)
Expand Down Expand Up @@ -391,24 +389,23 @@ void CPVRManager::ResetProperties(void)
class CPVRManagerStartJob : public CJob
{
public:
CPVRManagerStartJob(int openWindowId = 0) :
m_openWindowId(openWindowId) {}
CPVRManagerStartJob() {}
~CPVRManagerStartJob(void) {}

bool DoWork(void)
{
g_PVRManager.Start(false, m_openWindowId);
g_PVRManager.Start(false);
return true;
}
private:
int m_openWindowId;
};

void CPVRManager::Start(bool bAsync /* = false */, int openWindowId /* = 0 */)
void CPVRManager::Start(bool bAsync /* = false */)
{
if (bAsync)
{
CPVRManagerStartJob *job = new CPVRManagerStartJob(openWindowId);
CPVRManagerStartJob *job = new CPVRManagerStartJob();
CJobManager::GetInstance().AddJob(job, NULL);
return;
}
Expand All @@ -424,7 +421,6 @@ void CPVRManager::Start(bool bAsync /* = false */, int openWindowId /* = 0 */)

ResetProperties();
SetState(ManagerStateStarting);
m_openWindowId = openWindowId;

/* create and open database */
if (!m_database)
Expand Down Expand Up @@ -512,17 +508,6 @@ void CPVRManager::Process(void)
CLog::Log(LOGDEBUG, "PVRManager - %s - entering main loop", __FUNCTION__);
g_EpgContainer.Start();

/* activate startup window */
if (m_openWindowId > 0)
{
g_windowManager.ActivateWindow(m_openWindowId);
m_openWindowId = 0;

// let everyone know that the user interface is now ready for usage
CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UI_READY);
g_windowManager.SendThreadMessage(msg);
}

bool bRestart(false);
while (IsStarted() && m_addons && m_addons->HasConnectedClients() && !bRestart)
{
Expand Down Expand Up @@ -566,11 +551,6 @@ void CPVRManager::Process(void)
CLog::Log(LOGNOTICE, "PVRManager - %s - no add-ons enabled anymore. restarting the pvrmanager", __FUNCTION__);
CApplicationMessenger::Get().PostMsg(TMSG_SETPVRMANAGERSTATE, 1);
}
else
{
if (IsPVRWindow(g_windowManager.GetActiveWindow()))
g_windowManager.ActivateWindow(WINDOW_HOME);
}
}

bool CPVRManager::SetWakeupCommand(void)
Expand Down
4 changes: 1 addition & 3 deletions xbmc/pvr/PVRManager.h
Expand Up @@ -149,9 +149,8 @@ namespace PVR
/*!
* @brief Start the PVRManager, which loads all PVR data and starts some threads to update the PVR data.
* @param bAsync True to (re)start the manager from another thread
* @param openWindowId Window id to open after starting
*/
void Start(bool bAsync = false, int openWindowId = 0);
void Start(bool bAsync = false);

/*!
* @brief Stop the PVRManager and destroy all objects it created.
Expand Down Expand Up @@ -669,7 +668,6 @@ namespace PVR
CCriticalSection m_managerStateMutex;
ManagerState m_managerState;
CStopWatch *m_parentalTimer;
int m_openWindowId;
std::map<std::string, std::string> m_outdatedAddons;
static int m_pvrWindowIds[10];
};
Expand Down
83 changes: 68 additions & 15 deletions xbmc/pvr/windows/GUIWindowPVRBase.cpp
Expand Up @@ -27,6 +27,7 @@
#include "dialogs/GUIDialogOK.h"
#include "dialogs/GUIDialogYesNo.h"
#include "dialogs/GUIDialogSelect.h"
#include "dialogs/GUIDialogProgress.h"
#include "filesystem/StackDirectory.h"
#include "input/Key.h"
#include "guilib/GUIMessage.h"
Expand Down Expand Up @@ -125,13 +126,49 @@ void CGUIWindowPVRBase::OnInitWindow(void)
{
if (!g_PVRManager.IsStarted() || !g_PVRClients->HasConnectedClients())
{
g_windowManager.PreviousWindow();
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning,
g_localizeStrings.Get(19045),
g_localizeStrings.Get(19044));
return;
// wait until the PVR manager has been started
CGUIDialogProgress* dialog = static_cast<CGUIDialogProgress*>(g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS));
if (dialog)
{
dialog->SetHeading(CVariant{19235});
dialog->SetText(CVariant{19045});
dialog->ShowProgressBar(false);
dialog->Open();

// do not block the gfx context while waiting
CSingleExit exit(g_graphicsContext);

CEvent event(true);
while(!event.WaitMSec(1))
{
if (g_PVRManager.IsStarted() && g_PVRClients->HasConnectedClients())
event.Set();

if (dialog->IsCanceled())
{
// return to previous window if canceled
dialog->Close();
g_windowManager.PreviousWindow();
return;
}

g_windowManager.ProcessRenderLoop(false);
}

dialog->Close();
}
}

{
// set window group to playing group
CPVRChannelGroupPtr group = g_PVRManager.GetPlayingGroup(m_bRadio);
CSingleLock lock(m_critSection);
if (m_group != group)
m_viewControl.SetSelectedItem(0);
m_group = group;
}
SetProperty("IsRadio", m_bRadio ? "true" : "");

m_vecItems->SetPath(GetDirectoryPath());

CGUIMediaWindow::OnInitWindow();
Expand All @@ -149,16 +186,6 @@ bool CGUIWindowPVRBase::OnMessage(CGUIMessage& message)
{
switch (message.GetMessage())
{
case GUI_MSG_WINDOW_INIT:
{
CPVRChannelGroupPtr group = g_PVRManager.GetPlayingGroup(m_bRadio);
if (m_group != group)
m_viewControl.SetSelectedItem(0);
m_group = group;
SetProperty("IsRadio", m_bRadio ? "true" : "");
}
break;

case GUI_MSG_CLICKED:
{
switch (message.GetSenderId())
Expand All @@ -173,6 +200,32 @@ bool CGUIWindowPVRBase::OnMessage(CGUIMessage& message)
return CGUIMediaWindow::OnMessage(message);
}

bool CGUIWindowPVRBase::IsValidMessage(CGUIMessage& message)
{
bool bReturn = false;

// we need to protect the pvr windows against certain messages
// if the pvr manager is not started yet. we only want to support
// that the window can be loaded to show the user an info about
// the manager startup. Any other interactions with the windows
// would cause access violations.
switch (message.GetMessage())
{
// valid messages
case GUI_MSG_WINDOW_LOAD:
case GUI_MSG_WINDOW_INIT:
case GUI_MSG_WINDOW_DEINIT:
bReturn = true;
break;
default:
if (g_PVRManager.IsStarted())
bReturn = true;
break;
}

return bReturn;
}

bool CGUIWindowPVRBase::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
{
bool bReturn = false;
Expand Down
1 change: 1 addition & 0 deletions xbmc/pvr/windows/GUIWindowPVRBase.h
Expand Up @@ -98,6 +98,7 @@ namespace PVR
virtual void ShowRecordingInfo(CFileItem *item);
virtual bool UpdateEpgForChannel(CFileItem *item);
virtual void UpdateSelectedItemPath();
virtual bool IsValidMessage(CGUIMessage& message);
void CheckResumeRecording(CFileItem *item);

/*!
Expand Down
3 changes: 3 additions & 0 deletions xbmc/pvr/windows/GUIWindowPVRChannels.cpp
Expand Up @@ -168,6 +168,9 @@ bool CGUIWindowPVRChannels::OnAction(const CAction &action)

bool CGUIWindowPVRChannels::OnMessage(CGUIMessage& message)
{
if (!IsValidMessage(message))
return false;

bool bReturn = false;
switch (message.GetMessage())
{
Expand Down
3 changes: 3 additions & 0 deletions xbmc/pvr/windows/GUIWindowPVRGuide.cpp
Expand Up @@ -185,6 +185,9 @@ bool CGUIWindowPVRGuide::OnAction(const CAction &action)

bool CGUIWindowPVRGuide::OnMessage(CGUIMessage& message)
{
if (!IsValidMessage(message))
return false;

bool bReturn = false;
switch (message.GetMessage())
{
Expand Down
3 changes: 3 additions & 0 deletions xbmc/pvr/windows/GUIWindowPVRRecordings.cpp
Expand Up @@ -241,6 +241,9 @@ void CGUIWindowPVRRecordings::UpdateButtons(void)

bool CGUIWindowPVRRecordings::OnMessage(CGUIMessage &message)
{
if (!IsValidMessage(message))
return false;

bool bReturn = false;
switch (message.GetMessage())
{
Expand Down
3 changes: 3 additions & 0 deletions xbmc/pvr/windows/GUIWindowPVRSearch.cpp
Expand Up @@ -173,6 +173,9 @@ void CGUIWindowPVRSearch::OnPrepareFileItems(CFileItemList &items)

bool CGUIWindowPVRSearch::OnMessage(CGUIMessage &message)
{
if (!IsValidMessage(message))
return false;

if (message.GetMessage() == GUI_MSG_CLICKED)
{
if (message.GetSenderId() == m_viewControl.GetCurrentControl())
Expand Down
3 changes: 3 additions & 0 deletions xbmc/pvr/windows/GUIWindowPVRTimers.cpp
Expand Up @@ -168,6 +168,9 @@ void CGUIWindowPVRTimers::UpdateButtons(void)

bool CGUIWindowPVRTimers::OnMessage(CGUIMessage &message)
{
if (!IsValidMessage(message))
return false;

bool bReturn = false;
switch (message.GetMessage())
{
Expand Down

0 comments on commit a59d037

Please sign in to comment.